import 'package:flutter/material.dart';
import 'package:liftmanager/internal/maintenance/model/maintenance_options_item.dart';
import 'package:liftmanager/res/colors.dart';
import 'package:liftmanager/utils/theme_utils.dart';
import 'package:liftmanager/widgets/options_item.dart';

class UnSelectedOptions extends StatefulWidget {
  List<MaintenanceOptionsItem> mList;
  int groupValue = 1;

  UnSelectedOptions(this.mList);

  @override
  State<StatefulWidget> createState() {
    return MRDialogState();
  }
}

class MRDialogState extends State<UnSelectedOptions> {
  ///评价方式
  void updateGroupValue(int v) {
    setState(() {
      widget.groupValue = v;
    });
  }

  void allSelectedAction() {
    for (int i = 0; i < widget.mList.length; i++) {
      widget.mList[i].status = 1;
    }
    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    bool isDark = ThemeUtils.isDark(context);
    return Container(
      color: isDark?Colours.dark_bg_gray:Colors.white,
      width: 295,
      height: 380,
      child: Column(
        children: <Widget>[
          Row(
            children: <Widget>[
              Expanded(
                flex: 1,
                child: Text('以下选项未被选择',
                    style: TextStyle(
                        fontSize: 14,
                        color: Color(0xFF1A1A1A),
                        fontWeight: FontWeight.w500)),
              ),
              GestureDetector(
                onTap: () {
                  allSelectedAction();
                },
                child: Text(
                  "全选",
                  style: TextStyle(
                      fontSize: 14,
                      color: Colours.app_main,
                      fontWeight: FontWeight.w500),
                ),
              ),
              SizedBox(
                width: 5,
              ),
            ],
          ),
          SizedBox(
            height: 10,
          ),
          Container(
            padding: EdgeInsets.only(top: 10, bottom: 10),
            decoration: BoxDecoration(
                color: isDark?Colours.dark_bg_gray:Colors.white,
                borderRadius: BorderRadius.circular(3),
                border: Border.all(width: 0.5, color: Color(0xFFE5E5E5))),
            height: 306,
            child: ListView.separated(
              shrinkWrap: true,
              scrollDirection: Axis.vertical,
              itemBuilder: (context, index) => OptionsItem(
                title: "${widget.mList[index].item}",
                content: "${widget.mList[index].content}",
                value: widget.mList[index].status,
                onTap: (s) {
                  print("${s}");
                  setState(() {
                    widget.mList[index].status = s;
                  });
                },
              ),
              separatorBuilder: (BuildContext context, int index) {
                return Container(
                  height: 0.5,
                  color: Color(0xFFF5F5F5),
                );
              },
              physics: AlwaysScrollableScrollPhysics(),
              itemCount: widget.mList.length,
            ),
          ),
        ],
      ),
    );
  }
}
