/*
 * @Author: ChenYaJin
 * @Date: 2021-10-24 01:08:07
 * @LastEditors: ChenYaJin
 * @LastEditTime: 2023-03-31 10:36:13
 * @Description: 
 */
part of '../index.dart';

class _PassCardListComponent extends StatelessWidget {
  const _PassCardListComponent({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    final store = Provider.of<PrivateDetailStore>(context);
    final style = WTheme.of(context);
    final colorScheme = style.colorScheme;
    final statusColorMap = {
      // 1: '待下发',
      1: colorScheme.orange,
      // 2: '未通过',
      2: colorScheme.danger,
      // 3: '通过'
      3: colorScheme.success,
      // 4: '待设备删除'
      4: colorScheme.orange,
    };
    final statusMap = {
      1: '待下发',
      2: '未通过',
      3: '已通过',
      4: '待设备删除',
    };
    final data = store.data;
    final list = store.passCardList;
    final isDisableOperate = store.isSomeStatus(1) || store.isSomeStatus(4);
    if (store.isEdit || data?.id == null) {
      return SliverToBoxAdapter();
    }
    return WisCard(
      isSliver: true,
      color: Colors.white,
      margin: EdgeInsets.symmetric(horizontal: 15.pt, vertical: 5.pt),
      child: Wisdom.column(
          margin: EdgeInsets.fromLTRB(0.pt, 10.pt, 0.pt, 10.pt),
          color: Colors.white,
          children: <Widget>[
            for (var i = 0; i < list.length; i++)
              Wisdom.column(
                margin: EdgeInsets.symmetric(horizontal: 20.pt),
                children: [
                  Wisdom.row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    height: 44.pt,
                    children: [
                      Text('${list[i].doorControlName}'),
                      Text('${statusMap[list[i].status]}',
                          style: TextStyle(
                            color: statusColorMap[list[i].status],
                          )),
                    ],
                  ),
                  if (i < (list.length - 1)) Divider(),
                ],
              ),
            if (list.isEmpty || isDisableOperate)
              Stack(
                children: [
                  Wisdom.row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    padding: EdgeInsets.fromLTRB(
                        20.pt, list.isEmpty ? 15.pt : 10.pt, 20.pt, 10.pt),
                    color: Colors.white,
                    children: <Widget>[
                      WisText(
                        list.isEmpty
                            ? '无通行证数据'
                            : isDisableOperate
                                ? '温馨提示：有待下发通行证时无法操作审核记录，请等待下发完成后再操作。'
                                : '',
                        color: colorScheme.minor,
                        size: 13.pt,
                        maxLines: 2,
                        textAlign:
                            list.isEmpty ? TextAlign.center : TextAlign.left,
                      ).asExpanded(),
                    ],
                  ),
                ],
              ),
          ]),
    );
  }
}
