import 'package:flutter/material.dart';
import 'package:qhd_prevention/pages/home/scan_page.dart';
import 'package:qhd_prevention/pages/home/work/danger_project_page.dart';
import 'package:qhd_prevention/pages/my_appbar.dart';
import 'package:qhd_prevention/tools/h_colors.dart';
import 'package:qhd_prevention/tools/tools.dart';

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

  @override
  State<riskListPage> createState() => _riskListPageState();
}

class _riskListPageState extends State<riskListPage> {

  final List<Model> _dataList = [
    Model("青椒皮蛋鸡尾酒哦普佛椒皮鸡尾酒哦普佛椒皮鸡尾鸡尾酒哦普佛椒皮鸡尾鸡尾酒哦普佛椒皮鸡尾鸡尾酒哦普佛椒皮鸡尾鸡尾酒哦普佛"),
    Model("dqfiqfjpoqo阿迪王期待期待五千多强大f"),
    Model("dqfiqfjpoqof"),
    Model("dqfiqfjpoqof")
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: h_backGroundColor(),
      appBar: MyAppbar(
        title: "风险点（单元）列表",
        actions: [
          TextButton(
            onPressed: () {
              pushPage(ScanPage(), context);
            },
            child: Text(
              "扫描",
              style: TextStyle(color: Colors.white, fontSize: 16),
            ),
          ),
        ],
      ),
      body: SafeArea(
          child: Column(
            children: [
              Expanded(child: ListView.separated(
                itemCount: _dataList.length,
                separatorBuilder: (_, __) => const SizedBox(),
                itemBuilder: (context, index) {
                  Model item = _dataList[index];
                  return GestureDetector(
                    onTap: () => _selectItem(item),
                    child: _itemCell(item),
                  );
                },
              )),
              Container(
                decoration: BoxDecoration(
                  color: Colors.green,
                  borderRadius: BorderRadius.circular(5)
                ),
                width: screenWidth(context) - 30,
                height: 50,
                child: TextButton(
                    onPressed: () => _nextHandle(), child: Text("下一步", style: TextStyle(color: Colors.white),)),
              )

            ],
          )),
    );
  }

  Widget _itemCell(Model item) {
    return Padding(padding: EdgeInsets.symmetric(vertical: 7, horizontal: 15),
      child: GestureDetector(
        onTap: () => _selectItem(item),
        child: Container(
          height: 100,
          padding: EdgeInsets.symmetric(horizontal: 10),
          decoration: BoxDecoration(
              color: Colors.white,
              borderRadius: BorderRadius.circular(5)
          ),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.start,
            children: [
              Image.asset("assets/images/zt-ing.png", width: 70, height: 70,),
          const SizedBox(width: 10), // 添加间距
          Expanded( // 修复3: 文本过长时自动换行
            child: Text(
              item.title,
              style: const TextStyle(fontSize: 16),
              maxLines: 2, // 限制两行
              overflow: TextOverflow.ellipsis,
            ),
          ),
            ],
          ),
        ),
      ),
    );
  }

  void _nextHandle() {

  }

  void _selectItem(Model Item) {
    pushPage(DangerProjectPage(), context);
  }
}

class Model {
  final String title;

  Model(this.title);
}
