/*
 * @Author       : WuWei
 * @LastEditors  : WuWei
 * @Date         : 2021-09-27 17:16:52
 * @LastEditTime : 2023-05-25 15:41:28
 * @Description  : Do not edit
 */
import 'package:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:task_package/src/view_models/equipment_store.dart';
import 'package:wisdom_cli/wisdom_cli.dart';
part 'index.g.dart';

///路由传递的参数
class EquipmentListArguments {
  final String? relationIds;
  final String? type;
  final String? relationType;
  final String? id;
  final String? childId;
  final String? detailStatus;
  final bool? seqencing;
  final dynamic route;
  final dynamic detailData;
  EquipmentListArguments({
    this.relationIds,
    this.type,
    this.relationType,
    this.id,
    this.detailStatus,
    this.route,
    this.detailData,
    this.seqencing,
    this.childId,
  });

  ///
  ///
  ///
  ///
  ///
  ///
  ///
//***以下为模板代码谨慎修改***
  factory EquipmentListArguments.fromJson(Map<String, dynamic> json) {
    return _$EquipmentListArgumentsFromJson(json);
  }
  factory EquipmentListArguments.fromRouteArguments(BuildContext context) {
    return _$EquipmentListArgumentsFromJson(
        (ModalRoute.of(context)?.settings.arguments ??
            new Map<String, dynamic>()) as Map<String, dynamic>);
  }
  Map<String, dynamic> toJson() => _$EquipmentListArgumentsToJson(this);
}

///
///
///
///
///
//***以下为模板代码谨慎修改***
class EquipmentListPage extends StatelessWidget {
  const EquipmentListPage({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return MultiProvider(
      providers: [
        ChangeNotifierProvider(create: (_) => EquipmentListStore(context)),
      ],
      child: _PageView(),
    );
  }
}

class _PageView extends StatefulWidget {
  _PageView({Key? key}) : super(key: key);

  @override
  __PageViewState createState() => __PageViewState();
}

class __PageViewState extends State<_PageView> {
  EquipmentListStore get store =>
      Provider.of<EquipmentListStore>(context, listen: false);
  @override
  void initState() {
    super.initState();
    store.onGetList();
  }

  @override
  Widget build(BuildContext context) {
    final colorScheme = WTheme.of(context).colorScheme;
    return Scaffold(
      appBar: WAppBar(
        brightness: Brightness.light,
        iconTheme: IconThemeData(
          color: colorScheme.mainTitle,
          size: 19.pt,
        ),
        backgroundColor: Colors.white,
        title: Text('选择设备'),
      ),
      body: Column(
        children: [
          WSearch(
            hintText: '输入作业指导名称搜索',
            onSubmitted: (v) => store.onSearchList(v),
          ),
          _BuildInstructionsList(),
        ],
      ),
    );
  }
}

class _BuildInstructionsList extends StatelessWidget {
  const _BuildInstructionsList({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final colorScheme = WTheme.of(context).colorScheme;
    final store = Provider.of<EquipmentListStore>(context);
    return SingleChildScrollView(
      child: Observer(builder: (_) {
        return Wisdom.column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          color: Colors.white,
          children: [
            if (store.equipList.length > 0) ...[
              for (var i = 0; i < store.equipList.length; i++)
                Wisdom(
                  onTap: () => store.toEquipDetail(store.equipList[i]),
                  border: Border(
                    bottom: BorderSide(
                      color: colorScheme.divider,
                    ),
                  ),
                  padding: EdgeInsets.all(15.pt),
                  child: Wisdom.row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      WisText(
                        '${store.equipList[i]?.relationName ?? ''}',
                        color: store.equipList[i]?.status == 'finished'
                            ? colorScheme.placeholder
                            : colorScheme.mainTitle,
                        size: 15.pt,
                        weight: FontWeight.w300,
                      ),
                      WisText(
                        '${store.equipList[i]?.status == 'finished' ? '已完成' : '未完成'}',
                        color: store.equipList[i]?.status == 'finished'
                            ? colorScheme.green
                            : colorScheme.minor,
                        size: 13.pt,
                        weight: FontWeight.w300,
                      ),
                    ],
                  ),
                ),
            ] else ...[
              WEmptyWidget(
                text: WisText('暂无设备'),
              ),
            ]
          ],
        );
      }),
    ).asExpanded();
  }
}
