/*
 * @Author       : WuWei
 * @LastEditors  : WuWei
 * @Date         : 2022-11-11 11:01:57
 * @LastEditTime : 2023-06-05 10:46:01
 * @Description  : Do not edit
 */
part of '../index.dart';

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

  @override
  State<EngineerWidget> createState() => _EngineerWidgetState();
}

class _EngineerWidgetState extends State<EngineerWidget> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    final colorScheme = WTheme.of(context).colorScheme;
    return Provider<WorkStore>(
        create: (_) => WorkStore(context),
        // we use `builder` to obtain a new `BuildContext` that has access to the provider
        builder: (context, child) {
          // No longer throws
          final store = context.watch<WorkStore>();
          return Wisdom.column(
            // margin: EdgeInsets.only(top: 15.pt),
            children: [
              if (store.isShowMeter) ...[
                WisCard(
                  margin: EdgeInsets.only(
                    left: 15.pt,
                    right: 15.pt,
                    top: 15.pt,
                  ),
                  padding: EdgeInsets.all(15.pt),
                  child: Row(
                    children: [
                      Row(
                        children: [
                          Image.asset(
                            'lib/assets/main/chaobiao.png',
                            package: 'app_package',
                            width: 21.pt,
                            height: 21.pt,
                          ),
                          SizedBox(width: 10.pt),
                          WisText(
                            '抄表',
                            color: colorScheme.mainTitle,
                            size: 16.pt,
                          ),
                        ],
                      ).asFlexible(flex: 1),
                      Row(
                        mainAxisAlignment: MainAxisAlignment.end,
                        children: [
                          Wisdom.column(
                            onTap: () => store.toMeters(),
                            margin: EdgeInsets.only(right: 36.pt),
                            // crossAxisAlignment: CrossAxisAlignment.end,
                            children: [
                              WisText(
                                '${store.meterStatistics?.read ?? '0'}',
                                size: 24.pt,
                                color: colorScheme.primary,
                                weight: FontWeight.bold,
                              ),
                              SizedBox(height: 5.pt),
                              Row(
                                children: [
                                  WisText(
                                    '已抄表',
                                    color: colorScheme.minor,
                                    size: 13.pt,
                                  ),
                                  Image.asset(
                                    'lib/assets/main/enter.png',
                                    package: 'app_package',
                                    width: 14.pt,
                                    height: 14.pt,
                                  ),
                                ],
                              ),
                            ],
                          ),
                          Wisdom.column(
                            onTap: () => store.toMeters(),
                            children: [
                              WisText(
                                '${store.meterStatistics?.unread ?? '0'}',
                                size: 24.pt,
                                color: colorScheme.orange,
                                weight: FontWeight.bold,
                              ),
                              SizedBox(height: 5.pt),
                              Row(
                                children: [
                                  WisText(
                                    '未抄表',
                                    color: colorScheme.minor,
                                    size: 13.pt,
                                  ),
                                  Image.asset(
                                    'lib/assets/main/enter.png',
                                    package: 'app_package',
                                    width: 14.pt,
                                    height: 14.pt,
                                  ),
                                ],
                              ),
                            ],
                          ),
                        ],
                      ),
                    ],
                  ),
                ),
              ],
              if (store.isShowDevices && store.deviceStatistics.length > 0) ...[
                WisCard(
                  margin: EdgeInsets.only(
                    top: 15.pt,
                    left: 15.pt,
                    right: 15.pt,
                  ),
                  padding: EdgeInsets.only(
                      top: 0.pt, left: 15.pt, right: 15.pt, bottom: 15.pt),
                  child: Column(
                    children: [
                      for (var i = 0; i < store.deviceStatistics.length; i++)
                        Wisdom.row(
                          margin: EdgeInsets.only(top: 10.pt),
                          children: [
                            Row(
                              children: [
                                Image.asset(
                                  'lib/assets/main/ludeng.png',
                                  package: 'app_package',
                                  width: 21.pt,
                                  height: 21.pt,
                                ),
                                SizedBox(width: 10.pt),
                                WisText(
                                  '${store.deviceStatistics[i]?.name ?? '--'}',
                                  color: colorScheme.mainTitle,
                                  size: 16.pt,
                                ),
                              ],
                            ).asFlexible(flex: 1),
                            Row(
                              mainAxisAlignment: MainAxisAlignment.end,
                              children: [
                                Wisdom.column(
                                  onTap: () => store.toDevices(),
                                  margin: EdgeInsets.only(right: 36.pt),
                                  children: [
                                    WisText(
                                      '${store.deviceStatistics[i]?.open ?? '0'}',
                                      size: 24.pt,
                                      color: colorScheme.primary,
                                      weight: FontWeight.bold,
                                    ),
                                    SizedBox(height: 5.pt),
                                    Row(
                                      children: [
                                        WisText(
                                          '已开启',
                                          color: colorScheme.minor,
                                          size: 13.pt,
                                        ),
                                        Image.asset(
                                          'lib/assets/main/enter.png',
                                          package: 'app_package',
                                          width: 14.pt,
                                          height: 14.pt,
                                        ),
                                      ],
                                    ),
                                  ],
                                ),
                                Wisdom.column(
                                  onTap: () => store.toDevices(),
                                  children: [
                                    WisText(
                                      '${store.deviceStatistics[i]?.close ?? '0'}',
                                      size: 24.pt,
                                      color: colorScheme.orange,
                                      weight: FontWeight.bold,
                                    ),
                                    SizedBox(height: 5.pt),
                                    Row(
                                      children: [
                                        WisText(
                                          '已关闭',
                                          color: colorScheme.minor,
                                          size: 13.pt,
                                        ),
                                        Image.asset(
                                          'lib/assets/main/enter.png',
                                          package: 'app_package',
                                          width: 14.pt,
                                          height: 14.pt,
                                        ),
                                      ],
                                    ),
                                  ],
                                ),
                              ],
                            ),
                          ],
                        ),
                    ],
                  ),
                ),
              ]
            ],
          );
        });
  }
}
