import 'package:flutter/material.dart';
import 'package:qhd_prevention/http/ApiService.dart';
import 'package:qhd_prevention/pages/home/tap/tabList/work_tab_dh_list.dart';
import 'package:qhd_prevention/pages/home/tap/tabList/work_tab_dl_list.dart';
import 'package:qhd_prevention/pages/home/tap/tabList/work_tab_dt_list.dart';
import 'package:qhd_prevention/pages/home/tap/tabList/work_tab_dz_list.dart';
import 'package:qhd_prevention/pages/home/tap/tabList/work_tab_gc_list.dart';
import 'package:qhd_prevention/pages/home/tap/tabList/work_tab_icon_grid.dart';
import 'package:qhd_prevention/pages/home/tap/tabList/work_tab_lsyd_list.dart';
import 'package:qhd_prevention/pages/home/tap/tabList/work_tab_mbcd_list.dart';
import 'package:qhd_prevention/pages/home/tap/tabList/work_tab_sxkj_list.dart';
import 'package:qhd_prevention/pages/my_appbar.dart';
import 'package:qhd_prevention/tools/tools.dart';

class WorkTabListPage extends StatefulWidget {
  const WorkTabListPage({super.key});

  @override
  State<WorkTabListPage> createState() => _WorkTabListPageState();
}

class _WorkTabListPageState extends State<WorkTabListPage> {
  late List<Map<String, dynamic>> buttonInfos = [];

  @override
  void initState() {
    super.initState();
    _getData();
  }
  Future<void> _getData() async {
    final data = await ApiService.specialCheckWork();
    setState(() {
      final eight_work_count = data['count'] ?? {};
      buttonInfos = [
        {
          "icon": "assets/icon-apps/icon-807.png",
          "title": "动火作业",
          "unreadCount": eight_work_count['HOTWORK_COUNT'],
        },
        {
          "icon": "assets/icon-apps/icon-803.png",
          "title": "高处作业",
          "unreadCount": eight_work_count['HIGHWORK_COUNT'],
        },
        {
          "icon": "assets/icon-apps/icon-806.png",
          "title": "受限空间\n安全作业",
          "unreadCount": eight_work_count['CONFINEDSPACE_COUNT'],
        },
        {
          "icon": "assets/icon-apps/icon-804.png",
          "title": "吊装作业",
          "unreadCount": eight_work_count['HOISTING_COUNT'],
        },
        {
          "icon": "assets/icon-apps/icon-802.png",
          "title": "动土作业",
          "unreadCount": eight_work_count['BREAKGROUND_COUNT'],
        },
        {
          "icon": "assets/icon-apps/icon-805.png",
          "title": "临时用电作业",
          "unreadCount": eight_work_count['ELECTRICITY_COUNT'],
        },
        {
          "icon": "assets/icon-apps/open-circuit.png",
          "title": "断路作业",
          "unreadCount": eight_work_count['OPEN_CIRCUIT_COUNT'],
        },
        {
          "icon": "assets/icon-apps/icon-801.png",
          "title": "盲板抽堵作业",
          "unreadCount": eight_work_count['BLIND_BOARD_COUNT'],
        }
      ];
    });
  }
  void _handleItemPressed(int index) async {
    switch (index) {
      case 0:await pushPage(WorkTabDhList(), context); break;
      case 1:await pushPage(WorkTabGcList(), context); break;
      case 2:await pushPage(WorkTabSxkjList(), context); break;
      case 3:await pushPage(WorkTabDzList(), context); break;
      case 4:await pushPage(WorkTabDtList(), context); break;
      case 5:await pushPage(WorkTabLsydList(), context); break;
      case 6:await pushPage(WorkTabDlList(), context); break;
      case 7:await pushPage(WorkTabMbcdList(), context); break;
    }
    _getData();
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: MyAppbar(title: '特殊作业'),
      body: SafeArea(
        child: WorkTabIconGrid(
          buttonInfos: buttonInfos,
          onItemPressed: _handleItemPressed,
        ),
      ),
    );
  }
}
