/*
 * @Author: ChenYaJin
 * @Date: 2021-10-22 17:31:05
 * @LastEditors: ChenYaJin
 * @LastEditTime: 2023-04-06 09:53:57
 * @Description: 
 */
part of '../index.dart';

class _DeviceListComponent extends StatelessWidget {
  const _DeviceListComponent({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    final store = Provider.of<PrivateIndexStore>(context);
    final list = store.deviceList;
    final style = WTheme.of(context);
    final colorScheme = style.colorScheme;
    final statusColorMap = {
      // 1: '离线',
      0: colorScheme.grey,
      // 2: '在线',
      1: colorScheme.success,
    };
    return Column(
      children: <Widget>[
        Wisdom.row(
          color: Colors.white,
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          margin: EdgeInsets.only(bottom: 10.pt),
          children: <Widget>[
            /// 输入框
            Expanded(
              child: WSearch(
                hintText: '输入门禁名称搜索',
                onSubmitted: (v) => store.onDeviceSearch(v),
                onCancel: () => store.onDeviceSearch(''),
                moonlight: false,
                padding: EdgeInsets.symmetric(vertical: 10.pt),
                isDark: true,
              ),
            ),
          ],
        ),
        WisScrollView(
            key: store.deviceScorllViewListKey,
            onInit: () => store.getDoorDeviceList(),
            slivers: <Widget>[
              WisSliverList.childBuilder(
                childCount: list.length,
                builder: (context, index) {
                  final item = list[index];
                  return WisCard(
                    color: Colors.white,
                    margin: EdgeInsets.only(
                        left: 15.pt, right: 15.pt, bottom: 10.pt),
                    elevation: 0,
                    child: Wisdom.row(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      color: Colors.white,
                      padding: EdgeInsets.all(20.pt),
                      children: [
                        Column(
                          mainAxisAlignment: MainAxisAlignment.spaceAround,
                          crossAxisAlignment: CrossAxisAlignment.stretch,
                          children: [
                            Row(
                              children: [
                                ///设备名
                                WisText(
                                  item.name ?? '',
                                  weight: FontWeight.bold,
                                  size: 16.pt,
                                  maxLines: 2,
                                  overflow: TextOverflow.visible,
                                ).asExpanded(),

                                ///状态
                                if (store.deviceStatusMap[item.networkStatus] !=
                                    null)
                                  WTag(
                                    margin: EdgeInsets.only(left: 5.pt),
                                    child: Text(
                                        '${store.deviceStatusMap[item.networkStatus]}'),
                                    color: statusColorMap[item.networkStatus],
                                  ),
                              ],
                            ),
                            SizedBox(height: 5.pt),

                            ///设备序列号
                            Text(
                              item.deviceCode!,
                              style: TextStyle(
                                color: colorScheme.grey,
                                fontSize: 14.pt,
                              ),
                            ),
                          ],
                        ).nestExpanded(),
                        InkWell(
                            onTap: () => store.openDoorByRemote(item),
                            child: Column(
                              children: [
                                WImage(
                                  image: AssetList.$openDoor_png_image,
                                  width: 20.pt,
                                  height: 30.pt,
                                ),
                                SizedBox(height: 5.pt),
                                Text(
                                  '点击开门',
                                  style: TextStyle(
                                    color: colorScheme.primary,
                                    fontSize: 11.pt,
                                  ),
                                ),
                              ],
                            )),
                      ],
                    ),
                  );
                },
              )
            ]).asExpanded(),
      ],
    );
  }
}
