import 'package:flutter/material.dart';
import 'package:liftmanager/internal/maintenance/model/maintenance_options_item.dart';
import 'package:liftmanager/res/gaps.dart';
import 'package:liftmanager/res/resources.dart';
import 'package:liftmanager/widgets/load_image.dart';
import 'package:liftmanager/widgets/options_item.dart';

class MaintenanceOptions extends StatefulWidget {
  const MaintenanceOptions(
      {Key key, @required this.index,this.items, this.type, this.liftType,this.isEdit = false})
      : super(key: key);

  final int index;
  final List<MaintenanceOptionsItem> items;
  final String type;
  final int liftType;
  final bool isEdit;

  @override
  MaintenanceOptionsState createState() {
    return MaintenanceOptionsState();
  }
}

class MaintenanceOptionsState extends State<MaintenanceOptions>
    with
        AutomaticKeepAliveClientMixin<MaintenanceOptions>,
        SingleTickerProviderStateMixin {

  @override
  void initState() {
    super.initState();
  }



  @override
  Widget build(BuildContext context) {
    super.build(context);
    return ListView.builder(
        physics:widget.index == 4? NeverScrollableScrollPhysics():null,
        shrinkWrap: true, itemCount: widget.items.length+1, itemBuilder: itemWidget);
  }

  Widget itemWidget(BuildContext context, int index) {
    if (index == 0) {
      return Column(
        children: <Widget>[
          Padding(
            padding: EdgeInsets.fromLTRB(15, 10, 15, 10),
            child: Row(
              children: <Widget>[
                Expanded(
                    flex: 1,
                    child: Row(
                      children: <Widget>[
                        LoadAssetImage(
                          "icon_gou_s",
                          width: 15,
                          height: 15,
                        ),
                        Gaps.hGap5,
                        Text("已经保养",style: TextStyle(fontSize: 13,color: Color(0xFF999999)))
                      ],
                    )),
                Expanded(
                  flex: 1,
                  child: Row(
                    children: <Widget>[
                      LoadAssetImage(
                        "icon_cha_s",
                        width: 15,
                        height: 15,
                      ),
                      Gaps.hGap5,
                      Text("需要变更",style: TextStyle(fontSize: 13,color: Color(0xFF999999)),)
                    ],
                  ),
                ),
                Expanded(
                  flex: 1,
                  child: Row(
                    children: <Widget>[
                      LoadAssetImage(
                        "icon_no_s",
                        width: 15,
                        height: 15,
                      ),
                      Gaps.hGap5,
                      Text("无此项",style: TextStyle(fontSize: 13,color: Color(0xFF999999)))
                    ],
                  ),
                ),
              ],
            )
          )

        ],
      );
    }
    return Padding(
      padding: EdgeInsets.fromLTRB(15, 5, 15, 5),
      child:  OptionsItem(
        title: "${widget.items[index-1].item}",
        content: "${widget.items[index-1].content}",
        value: widget.items[index-1].status,
        isEdit: widget.isEdit,
        onTap: (s) {
          if(!widget.isEdit){
            return;
          }
          setState(() {
            widget.items[index-1].status = s;
          });
        },
      ),
    );
  }



  @override
  bool get wantKeepAlive => true;
}
