import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../../../bean/connect.dart';
import '../../../component/sys_app_bar.dart';
import '../controllers/connect_controller.dart';

class ConnectView extends GetView<ConnectController> {

  const ConnectView({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: const BoxDecoration(
        image: DecorationImage(
          image: AssetImage("assets/images/node/nodebg.png"),
          fit: BoxFit.fill,
        ),
      ),
      child: Scaffold(
        backgroundColor: Colors.transparent,
        appBar: SysAppBar(title: const Text(""), actions: [
          Row(
            children: [
                Text("连接状态")
              ]
          ),
        ],),
        body: Obx(() {
          return ListView.builder(
            itemCount: controller.connect.value?.connections.length ?? 0,
            itemBuilder: (context, index) {
              ConnectConnection? metadata = controller.connect.value?.connections[index];
              return Column(
                children: [
                  Container(
                    color: Colors.white70,
                    child: ListTile(
                      subtitle: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Text('${metadata?.metadata.network ?? ""}://${metadata!.metadata.host}${metadata.metadata.destinationIP ?? ""}:${metadata.metadata.destinationPort ?? ""}'),
                          SizedBox(height: 10,),
                          Text('${metadata.start}'),
                        ],
                      ),
                    ),
                  ),
                  Divider(
                    color: Colors.grey,
                    thickness: 1,
                  ),
                ],
              );
            },
          );
        })
      ),
    );
  }
}
