part of '../index.dart';

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

  @override
  Widget build(BuildContext context) {
    final style = WTheme.of(context);
    final colorScheme = style.colorScheme;
    final store = Provider.of<PrivateDetailStore>(context, listen: true);
    var item = store.routingArgs['item'];
    var device = store.deviceDetail.device;
    var controller = store.deviceDetail.controller;
    dynamic controllerData = {'controllerId': item['controllerId']};
    return Column(
      crossAxisAlignment: CrossAxisAlignment.stretch,
      mainAxisSize: MainAxisSize.min,
      children: [
        Wisdom.column(
          margin: EdgeInsets.only(top: 10.pt, left: 15.pt, right: 15.pt),
          color: Colors.white,
          padding: EdgeInsets.all(15.pt),
          borderRadius: BorderRadius.circular(12.pt),
          boxShadow: [
            BoxShadow(
              offset: Offset(0, 2),
              color: Color(0x08000000),
              blurRadius: 10.pt,
              spreadRadius: 2.5.pt,
            ),
          ],
          children: [
            Wisdom.column(
              mainAxisSize: MainAxisSize.min,
              color: Colors.white,
              children: [
                Wisdom.row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  crossAxisAlignment: CrossAxisAlignment.center,
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    Wisdom.row(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        Wisdom(
                          margin: EdgeInsets.only(left: 5.pt),
                          child: Text(
                            '${item['name'] ?? '--'}',
                            style: TextStyle(
                              color: colorScheme.mainTitle,
                              fontSize: 15.pt,
                              fontWeight: FontWeight.bold,
                            ),
                          ),
                        ),
                      ],
                    ).asExpanded(),
                  ],
                ),
                Wisdom.row(
                  // crossAxisAlignment: CrossAxisAlignment.center,
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  // padding: EdgeInsets.only(bottom: 5.pt),
                  children: [
                    if (controller?.status != null && controller?.status == 1)
                      WTag(
                        child: WisText('已通电'),
                        color: Color(0xFF25B41C),
                        margin: EdgeInsets.only(left: 5.pt),
                      ),
                    if (controller?.status != null && controller?.status == 0)
                      WTag(
                        child: WisText('已断电'),
                        color: colorScheme.danger,
                        margin: EdgeInsets.only(left: 5.pt),
                      ),
                    if (controller?.status != null && controller?.status == 0)
                      Switch(
                        activeColor: colorScheme.primary,
                        value: false,
                        onChanged: (v) => {
                          ShowConfirmMeterDialog(
                              context, controllerData, store, 'OPEN')
                        },
                      ),
                    if (controller?.status != null && controller?.status == 1)
                      Switch(
                        activeColor: colorScheme.primary,
                        value: true,
                        onChanged: (v) => {
                          ShowConfirmMeterDialog(
                              context, controllerData, store, 'CLOSE')
                        },
                      ),
                  ],
                ),
              ],
            ),
            Divider(
              color: Color(0xffE6E6E6),
            ),
            Wisdom.row(
              color: Colors.white,
              padding: EdgeInsets.only(top: 10.pt),
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              mainAxisSize: MainAxisSize.max,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Expanded(
                  child: Wisdom.column(
                    mainAxisSize: MainAxisSize.min,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    padding: EdgeInsets.symmetric(horizontal: 5.pt),
                    border: Border(
                        right: BorderSide(
                      color: Color(0xffE6E6E6),
                      width: 0.5.pt,
                    )),
                    children: [
                      WisText(
                        '设备类型',
                        color: colorScheme.minor,
                        size: 13.pt,
                        weight: FontWeight.w300,
                      ),
                      WisText('${device?.type ?? '--'}'),
                    ],
                  ),
                  flex: 1,
                ),
                Expanded(
                  child: Wisdom.column(
                    mainAxisSize: MainAxisSize.min,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    padding: EdgeInsets.symmetric(horizontal: 5.pt),
                    border: Border(
                        right: BorderSide(
                      color: Color(0xffE6E6E6),
                      width: 0.5.pt,
                    )),
                    children: [
                      WisText(
                        '设备编号',
                        color: colorScheme.minor,
                        size: 13.pt,
                        weight: FontWeight.w300,
                      ),
                      WisText(
                        '${device?.serialNumber ?? '--'}',
                        size: 14.pt,
                      ),
                    ],
                  ),
                  flex: 1,
                ),
                Expanded(
                  child: Wisdom.column(
                    mainAxisSize: MainAxisSize.min,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    padding: EdgeInsets.symmetric(horizontal: 5.pt),
                    children: [
                      WisText(
                        '位置',
                        color: colorScheme.minor,
                        size: 13.pt,
                        weight: FontWeight.w300,
                      ),
                      WisText('${device?.area ?? '--'}'),
                    ],
                  ),
                  flex: 1,
                ),
              ],
            ),
          ],
        ),
        Wisdom.column(
          margin: EdgeInsets.symmetric(vertical: 10.pt, horizontal: 15.pt),
          color: Colors.white,
          padding: EdgeInsets.all(15.pt),
          borderRadius: BorderRadius.circular(12.pt),
          boxShadow: [
            BoxShadow(
              offset: Offset(0, 2),
              color: Color(0x08000000),
              blurRadius: 10.pt,
              spreadRadius: 2.5.pt,
            ),
          ],
          children: [
            Wisdom.row(
              color: Colors.white,
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              mainAxisSize: MainAxisSize.max,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Wisdom(
                  child: WisText(
                    '关联控制器',
                    size: 14.pt,
                    weight: FontWeight.w500,
                  ),
                ),
              ],
            ),
            Wisdom.row(
              color: Colors.white,
              padding: EdgeInsets.symmetric(vertical: 10.pt),
              mainAxisAlignment: MainAxisAlignment.start,
              mainAxisSize: MainAxisSize.max,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Wisdom(
                  child: Text(
                    '控制器名称',
                    style: TextStyle(
                      color: colorScheme.minor,
                      fontSize: 13.pt,
                      fontWeight: FontWeight.w300,
                    ),
                  ),
                ),
                Wisdom(
                  margin: EdgeInsets.only(left: 15.pt),
                  child: Text('${controller?.name ?? '--'}'),
                ),
              ],
            ),
            Divider(
              color: Color(0xffE6E6E6),
            ),
            Wisdom.row(
              color: Colors.white,
              padding: EdgeInsets.only(top: 12.pt),
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              mainAxisSize: MainAxisSize.max,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Expanded(
                  child: Wisdom.column(
                    mainAxisSize: MainAxisSize.min,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    padding: EdgeInsets.symmetric(horizontal: 5.pt),
                    border: Border(
                        right: BorderSide(
                      color: Color(0xffE6E6E6),
                      width: 0.5.pt,
                    )),
                    children: [
                      WisText(
                        '区域位置',
                        color: colorScheme.minor,
                        size: 13.pt,
                        weight: FontWeight.w300,
                      ),
                      WisText('${controller?.location ?? '--'}'),
                    ],
                  ),
                  flex: 1,
                ),
                Expanded(
                  child: Wisdom.column(
                    mainAxisSize: MainAxisSize.min,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    padding: EdgeInsets.symmetric(horizontal: 5.pt),
                    border: Border(
                        right: BorderSide(
                      color: Color(0xffE6E6E6),
                      width: 0.5.pt,
                    )),
                    children: [
                      WisText(
                        '厂商编号',
                        color: colorScheme.minor,
                        size: 13.pt,
                        weight: FontWeight.w300,
                      ),
                      WisText(
                        '${controller?.vendorNo ?? '--'}',
                        size: 14.pt,
                      ),
                      // Text('${controller?.vendorNo ?? '--'}'),
                    ],
                  ),
                  flex: 1,
                ),
                Expanded(
                  child: Wisdom.column(
                    mainAxisSize: MainAxisSize.min,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    padding: EdgeInsets.symmetric(horizontal: 5.pt),
                    children: [
                      WisText(
                        '控制器类型',
                        color: colorScheme.minor,
                        size: 13.pt,
                        weight: FontWeight.w300,
                      ),
                      WisText('${controller?.type ?? '--'}'),
                    ],
                  ),
                  flex: 1,
                ),
              ],
            ),
          ],
        ),
        Wisdom.row(
          padding: EdgeInsets.only(top: 5.pt, bottom: 10.pt),
          children: [
            Wisdom(
              minHeight: 20.pt,
              width: 3.pt,
              margin: EdgeInsets.only(left: 16.pt, right: 6.pt),
              color: Color(0xFF0F67F8),
              // padding: EdgeInsets.all(3.pt),
              borderRadius: BorderRadius.circular(1.5.pt),
            ),
            Wisdom(
              margin: EdgeInsets.only(left: 10.pt),
              child: WisText(
                '变动记录',
                size: 16.pt,
                weight: FontWeight.w500,
              ),
            )
          ],
        ),
        WisScrollView(
          key: store.scorllViewListKeyIndex,
          onInit: () => store.getDetail(),
          onLoad: () => store.getDeviceRecord(isLoad: true),
          slivers: <Widget>[
            WisSliverList.childBuilder(
              childCount: store.detailList.length,
              builder: (context, index) {
                final detail = store.detailList[index];
                return WisCard(
                    margin:
                        EdgeInsets.symmetric(vertical: 5.pt, horizontal: 15.pt),
                    color: Colors.white,
                    padding: EdgeInsets.all(15.pt),
                    child: Column(
                      children: [
                        Wisdom.row(
                          crossAxisAlignment: CrossAxisAlignment.center,
                          margin: EdgeInsets.only(bottom: 2.pt),
                          children: [
                            Wisdom(
                              // margin: EdgeInsets.only(left: 10.pt),
                              child: WisText(
                                '${detail.content ?? '--'}',
                                size: 16.pt,
                                weight: FontWeight.w500,
                              ),
                            )
                          ],
                        ),
                        Wisdom.row(
                          crossAxisAlignment: CrossAxisAlignment.center,
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            WisText(
                              '${detail.time ?? '--'}',
                              color: Color(0xff9A9A9A),
                              size: 13.pt,
                            ),
                            WisText(
                              '${detail.createdBy ?? '--'}',
                              color: Color(0xff9A9A9A),
                              size: 13.pt,
                            ),
                          ],
                        ),
                      ],
                    ));
              },
            ),
          ],
        ).asFlexible(flex: 1),
      ],
    );
  }
}
