/*
 * @Author: XianKaiQun
 * @Date: 2020-09-09 11:54:09
 * @LastEditors: ChenYaJin
 * @LastEditTime: 2023-03-27 20:37:28
 * @Description: 
 */
part of '../index.dart';

class _ButtonBarComponent extends StatelessWidget {
  const _ButtonBarComponent({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 list = store.passCardList;
//final textTheme = theme.textTheme;
    if (store.data == null) {
      return SliverToBoxAdapter();
    }

    ///审核通过 且有通行证待下发｜待删除
    if (store.data?.status == 3 &&
        (store.isSomeStatus(1) || store.isSomeStatus(4))) {
      return SliverToBoxAdapter();
    }

    ///拒绝通行弹窗
    showRefuseModal() async {
      String? value;
      WBottomModalUtil.show(
        WNavUtil.instance!.context!,
        bodyConstraints: BoxConstraints(minHeight: 0),
        title: Text('拒绝通行'),
        body: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          mainAxisSize: MainAxisSize.min,
          children: [
            SizedBox(height: 15.pt),
            Text('拒绝理由').asPaddingSymmetric(horizontal: 15.pt),
            TextFormField(
              onChanged: (v) {
                value = v;
              },
              minLines: 4,
              maxLines: 4,
              maxLength: 256,
              decoration: InputDecoration(
                hintText: '输入拒绝通行的理由',
                contentPadding: EdgeInsets.symmetric(vertical: 15.pt),
                fillColor: Colors.transparent,
              ),
            ).asPaddingSymmetric(horizontal: 15.pt),
            SizedBox(height: 15.pt),
            Divider(),
            WLoadingButton(
              onPressed: () => store.onRefuse(value),
              height: 44.pt,
              padding: EdgeInsets.symmetric(horizontal: 10.pt),
              shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(25.pt),
              ),
              child: Text('确定'),
            ).asPaddingSymmetric(horizontal: 15.pt),
          ],
        ),
      );
    }

    List<Widget> children = [];

    ///编辑模式下
    if (store.isEdit) {
      children = [
        WLoadingButton(
          height: 44.pt,
          padding: EdgeInsets.symmetric(horizontal: 10.pt),
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(25.pt),
          ),
          onPressed: () => store.onModify(),
          color: colorScheme.primary,
          child: Text('确认修改'),
        ).nestExpanded(),
      ];
    }

    ///待审核
    else if (store.data?.status == 1) {
      children = [
        WLoadingButton(
          height: 44.pt,
          minWidth: 100.pt,
          padding: EdgeInsets.symmetric(horizontal: 10.pt),
          onPressed: () => showRefuseModal(),
          color: colorScheme.danger,
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(25.pt),
          ),
          child: Text('拒绝'),
        ),
        SizedBox(width: 15.pt),
        WLoadingButton(
          height: 44.pt,
          padding: EdgeInsets.symmetric(horizontal: 10.pt),
          onPressed: () => store.onPassed(),
          color: colorScheme.primary,
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(25.pt),
          ),
          child: Text('通过'),
        ).nestExpanded(),
      ];
    }

    ///已通过
    else if (store.data?.status == 3) {
      if (list.isEmpty) {
        children = [
          if (!store.isOverDate())
            WLoadingButton(
              height: 44.pt,
              padding: EdgeInsets.symmetric(horizontal: 10.pt),
              onPressed: () => store.rePushAllPassCard(),
              color: Color.fromRGBO(11, 190, 211, 1),
              textColor: Colors.white,
              shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(25.pt),
              ),
              child: Text('重新下发'),
            ).nestExpanded(),
          SizedBox(width: 15.pt),
          WButton(
            height: 44.pt,
            padding: EdgeInsets.symmetric(horizontal: 10.pt),
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(25.pt),
            ),
            onPressed: () => store.isEditChange(),
            color: colorScheme.primary,
            child: Text('修改'),
          ).nestExpanded(),
          SizedBox(width: 15.pt),
          WLoadingButton(
            height: 44.pt,
            minWidth: 100.pt,
            padding: EdgeInsets.symmetric(horizontal: 10.pt),
            onPressed: () => showRefuseModal(),
            color: colorScheme.danger,
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(25.pt),
            ),
            child: Text('拒绝通行'),
          ).nestExpanded(),
        ];
      } else if (store.isAllStatus(3)) {
        children = [
          WLoadingButton(
            height: 44.pt,
            padding: EdgeInsets.symmetric(horizontal: 10.pt),
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(25.pt),
            ),
            onPressed: () => store.onDeleteAllPassCard(),
            color: colorScheme.danger,
            child: Text('删除全部通行证'),
          ).nestExpanded(),
        ];
      } else if (store.isAllStatus(2) ||
          (store.isSomeStatus(2) && store.isSomeStatus(3))) {
        final isSome = store.isSomeStatus(2) && store.isSomeStatus(3);
        children = [
          WLoadingButton(
            height: 44.pt,
            padding: EdgeInsets.symmetric(horizontal: 10.pt),
            onPressed: () => store.rePushAllPassCard(),
            color: colorScheme.primary,
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(25.pt),
            ),
            child: Text('重新下发' + (isSome ? '未通过' : '')),
          ).nestExpanded(),
          SizedBox(width: 15.pt),
          WLoadingButton(
            height: 44.pt,
            padding: EdgeInsets.symmetric(horizontal: 10.pt),
            onPressed: () => store.onDeleteAllPassCard(),
            color: colorScheme.danger,
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(25.pt),
            ),
            child: Text('删除全部通行证'),
          ).nestExpanded(),
        ];
      }
    }

    ///被拒绝
    else if (store.data?.status == 5) {
      children = [
        WButton(
          height: 44.pt,
          padding: EdgeInsets.symmetric(horizontal: 10.pt),
          onPressed: () => store.isEditChange(),
          color: colorScheme.primary,
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(25.pt),
          ),
          child: Text('修改'),
        ).nestExpanded(),
        SizedBox(width: 15.pt),
        WButton(
          height: 44.pt,
          padding: EdgeInsets.symmetric(horizontal: 10.pt),
          onPressed: () => store.onDeleteRecord(),
          color: colorScheme.danger,
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(25.pt),
          ),
          child: Text('删除'),
        ).nestExpanded(),
      ];
    }
    return Wisdom.row(
      padding: EdgeInsets.all(15.pt),
      children: children,
    ).nestSliverToBoxAdapter();
  }
}
