import 'package:flutter/material.dart';
import 'package:qhd_prevention/customWidget/ItemWidgetFactory.dart';
import 'package:qhd_prevention/http/ApiService.dart';
import 'package:qhd_prevention/pages/home/tap/tabList/special_wrok/dh_work/hotwork_list_page.dart';
import 'package:qhd_prevention/pages/home/tap/tabList/special_wrok/dt_work/breakground_list_page.dart';
import 'package:qhd_prevention/pages/my_appbar.dart';
import 'package:qhd_prevention/tools/tools.dart';
import 'package:qhd_prevention/pages/home/tap/tabList/work_tab_icon_grid.dart';


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

  @override
  State<WorkTabDtList> createState() => _WorkTabDtListState();
}

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

  @override
  void initState() {
    super.initState();
    _getData();
  }
  Future<void> _getData() async {
    final data = await ApiService.specialcheckWorkCount('breakground');
    setState(() {
      final eight_work_count = data['count'] ?? {};
      buttonInfos = [
        {
          "icon": "assets/icon-apps/icon-yxkj-1.png",
          "title": "动土作业\n申请",
          "unreadCount": eight_work_count['CREATE'] ?? '0',
        },
        {
          "icon": "assets/icon-apps/icon-yxkj-2.png",
          "title": "作业人\n意见",
          "unreadCount": eight_work_count['WORK_USER'] ?? '0',
        },

        {
          "icon": "assets/icon-apps/icon-yh-1.png",
          "title": "设置安全\n措施确认人",
          "unreadCount": eight_work_count['MEASURES_SET'] ?? '0',
        },
        {
          "icon": "assets/icon-apps/icon-yh-1.png",
          "title": "安全措施确认",
          "unreadCount": eight_work_count['MEASURES_CONFIRM'] ?? '0',
        },
        {
          "icon": "assets/icon-apps/icon-zl-9.png",
          "title": "监护人\n意见",
          "unreadCount": eight_work_count['GUARDIAN'] ?? '0',
        },
        {
          "icon": "assets/icon-apps/icon-807.png",
          "title": "安全交底人\n意见",
          "unreadCount": eight_work_count['CONFESS'] ?? '0',
        },
        {
          "icon": "assets/icon-apps/icon-yxkj-4.png",
          "title": "接受交底人\n意见",
          "unreadCount": eight_work_count['ACCEPT_CONFESS'] ?? '0',
        },
        {
          "icon": "assets/icon-apps/icon-yxkj-2.png",
          "title": "作业负责人\n意见",
          "unreadCount": eight_work_count['CONFIRM'] ?? '0',
        },
        {
          "icon": "assets/icon-apps/icon-907.png",
          "title": "所在单位\n意见",
          "unreadCount": eight_work_count['LEADER'] ?? '0',
        },
        {
          "icon": "assets/icon-apps/icon-901.png",
          "title": "有关水、电、\n汽、工艺、设\n备、消防安全等部门意见",
          "unreadCount": eight_work_count['SAFETY'] ?? '0',
        },
        {
          "icon": "assets/icon-apps/icon-901.png",
          "title": "审批部门\n意见",
          "unreadCount": eight_work_count['APPROVE'] ?? '0',
        },
        {
          "icon": "assets/icon-apps/icon-aq-1.png",
          "title": "开始作业时间",
          "unreadCount": eight_work_count['WORK_START'] ?? '0',
        },
        {
          "icon": "assets/icon-apps/icon-js-1.png",
          "title": "结束作业时间",
          "unreadCount": eight_work_count['WORK_END'] ?? '0',
        },
        {
          "icon": "assets/icon-apps/icon-js-1.png",
          "title": "验收归档",
          "unreadCount": eight_work_count['ACCEPT'] ?? '0',
        },

      ];
    });
  }
  void _handleItemPressed(int index) async {
    // 根据索引执行不同的导航逻辑
    String title = '';
    switch (index) {
      case 0: title = '提交申请'; break;
      case 1: title = '作业人签字'; break;
      case 2: title = '设置安全措施确认人'; break;
      case 3: title = '安全措施确认'; break;
      case 4: title = '监护人签字'; break;
      case 5: title = '安全交底人签字'; break;
      case 6: title = '接受交底人签字'; break;
      case 7: title = '作业负责人签字'; break;
      case 8: title = '所在单位签字'; break;
      case 9: title = '有关水、电、汽、工艺、设备、消防安全等部门'; break;
      case 10: title = '审批人签字'; break;
      case 11: title = '开始作业'; break;
      case 12: title = '结束作业'; break;
      case 13: title = '验收签字'; break;

      default:
        print("按钮 $index 被点击");
    }
    await pushPage(BreakgroundListPage(flow: title, workTypeTitle: '动土作业',), context);
    _getData();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: MyAppbar(title: '动土作业'),
      body: SafeArea(
          child: Column(
            children: [
              ListItemFactory.createBuildSimpleSection('动土作业审批管理'),
              WorkTabIconGrid(
                buttonInfos: buttonInfos,
                onItemPressed: _handleItemPressed,
              ),
            ],
          )
      ),
    );
  }
}
