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

// import '../login_in/connect/bluetooth_page.dart';
// import '../login_in/connect/connect_type.dart';
// import '../login_in/getx/real_data.dart';
// import 'main.dart';

// final RealController controller1 = Get.find();

class CustomAppBar extends StatelessWidget implements PreferredSizeWidget {
  final double appBarHeight;
  final RxInt _currentIndex;
  final isDarkMode = false.obs;
  final isCardVisible = false.obs;
  final isDataVisible = false.obs;
  CustomAppBar({required this.appBarHeight, required RxInt currentIndex})
      : _currentIndex = currentIndex;

  @override
  Widget build(BuildContext context) {
    const textStyle = TextStyle(fontSize: 16);
    return AppBar(
      toolbarHeight: 40,
      centerTitle: true, // 标题居中
      title: Obx(() {
        if (_currentIndex.value == 0) {
          return const Text("桩点:", style: textStyle);
        } else if (_currentIndex.value == 1) {
          return const Text("设备:", style: textStyle);
        } else {
          return const Text("系统:", style: textStyle);
        }
      }),
      // title: _currentIndex.value == 0
      //     ? Obx(() => Text("桩点:${realController.pileId.value}",
      //         style: textStyle))
      //     : const Text("设备:", style: textStyle),
      // // const Center(
      // //     child: Obx(() => Text("设备:", style: textStyle)),
      // //   ),
      // title: Obx(() {
      //   if (_currentIndex.value == 1) {
      //     return const Text("设备:", style: textStyle);
      //   } else if (_currentIndex.value == 0) {
      //     return Text("桩点:${realController.pileId.value}",
      //         style: textStyle);
      //   } else {
      //     return const Text("系统:", style: textStyle);
      //   }
      // }),

      actions: [
        InkWell(
          onTap: () {
            isDarkMode.value = !isDarkMode.value;
          },
          child: Icon(
            isDarkMode.value ? Icons.dark_mode : Icons.sunny,
            size: 35,
          ),
        ),
        const SizedBox(
          width: 10,
        ),
        InkWell(
          onTap: () {
            // Navigator.push(context,
            //           MaterialPageRoute(builder: (context) => const ScenceMap())),
          },
          child: Image(
            image: const AssetImage('images/satellite.png'),
            // width: 40,
            color: isDarkMode.value
                ? Colors.white70
                : const Color.fromARGB(200, 29, 28, 28),
            height: 40,
          ),
        ),
        const SizedBox(
          width: 10,
        ),
        _currentIndex.value == 1
            ? Row(
                children: [
                  Obx(
                    () => InkWell(
                      onTap: () {
                        // 点击图标时显示对点卡片
                        // sight.isCardVisible.value =
                        //     !sight.isCardVisible.value; // 确保控制器已定义
                      },
                      child: Icon(
                        Icons.my_location_sharp,
                        size: 35,
                        color: isCardVisible.value
                            ? Colors.blue
                            // : const Color.fromARGB(200, 29, 28, 28),
                            : (isDarkMode.value
                                ? Colors.white70
                                : const Color.fromARGB(200, 29, 28, 28)),
                      ), // 新增图标
                    ),
                  ),
                  const SizedBox(
                    width: 10,
                  ),
                  Obx(
                    () => InkWell(
                      onTap: () {
                        // final RealController controller1 = Get.find(); // 获取控制器
                        // controller1.isDataVisible.value =
                        //     !controller1.isDataVisible.value; // 更新控制器中的值
                      },
                      child: Icon(
                        Icons.date_range_rounded,
                        size: 35,
                        color: isDataVisible.value
                            ? Colors.blue
                            : (isDarkMode.value
                                ? Colors.white70
                                : const Color.fromARGB(200, 29, 28, 28)),
                      ), // 新增图标
                    ),
                  ),
                  const SizedBox(
                    width: 10,
                  ),
                  UnconstrainedBox(
                    child: SizedBox(
                      height: 30,
                      child: Builder(
                        builder: (context) => InkWell(
                          child: Icon(
                            Icons.settings_outlined,
                            size: 35,
                            color: isDarkMode.value
                                ? Colors.white70
                                : const Color.fromARGB(200, 29, 28, 28),
                          ),
                          onTap: () => Scaffold.of(context).openEndDrawer(),
                        ),
                      ),
                    ),
                  )
                ],
              )
            : const Text(""),
        // Obx(() => Icon(
        //       blueToothController.connectedType.value == ConnectType.wifi
        //           ? Icons.wifi
        //           : (blueToothController.connectedType.value ==
        //                   ConnectType.bluetooth
        //               ? Icons.bluetooth
        //               : Icons.close),
        //       color: Colors.green,
        //       size: 30,
        //     ))
      ],
    );
  }

  @override
  Size get preferredSize => Size.fromHeight(appBarHeight);
}