/*
 * @Author: XianKaiQun
 * @Date: 2020-09-09 17:09:54
 * @LastEditors: ChenYaJin
 * @LastEditTime: 2023-04-06 09:57:23
 * @Description: 
 */
part of '../index.dart';

class _FormComponent extends StatelessWidget {
  const _FormComponent({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    // final style = WTheme.of(context);
    // final colorScheme = style.colorScheme;
    final store = Provider.of<PrivateAddStore>(context);
    return WForm(
      key: store.formKey,
      child: WisCard(
        color: Colors.white,
        margin: EdgeInsets.symmetric(horizontal: 15.pt, vertical: 10.pt),
        elevation: 0,
        child: Wisdom.column(
          padding: EdgeInsets.symmetric(horizontal: 15.pt),
          border: Border.symmetric(
            horizontal: Divider.createBorderSide(context),
          ),
          color: Colors.white,
          children: ListTile.divideTiles(
            context: context,
            tiles: [
              WFormTile(
                minWidth: 120.pt,
                required: true,
                leading: Text('通行门禁组'),
                child: WMultiplePickerFormField.textField(
                  field: 'doorGroups',
                  getData: () => store.getDoorGroupList(),
                  buildName: (List<DoorGroupModel>? list) =>
                      (list?.map((e) => e.doorGroupName).toList().join('，')) ??
                      '',
                  title: Text('通行门禁组'),
                  decoration: InputDecoration(
                    hintText: '选择通行门禁组，可多选',
                  ),
                  maxLines: null,
                ),
              ),
              WFormTile(
                minWidth: 120.pt,
                required: true,
                leading: Text('关联住户'),
                child: WInfinityPickerFormField.textField(
                  field: 'resident',
                  title: Text('关联住户'),
                  getData: (List<CascadeModel> list) =>
                      store.getOwnerData(list),
                  buildName: (List<CascadeModel>? list) =>
                      list != null && list.length > 0
                          ? list.last.name ?? ''
                          : '',
                  isLast: (List<CascadeModel> list) async =>
                      list.last.status == 'owner',
                  decoration: InputDecoration(
                    hintText: '请选择住户',
                  ),
                ),
              ),
              WFormTile(
                minWidth: 120.pt,
                leading: Text('失效日期'),
                child: WDatePickerFormField.textField(
                  field: 'expirationTime',
                  title: Text('失效日期'),
                  firstDate: DateTime.now(),
                  lastDate: DateTime(2099),
                  buildName: (DateTime? date) =>
                      date?.toFormat(WisDateTimeFormat.date) ?? '',
                  decoration: InputDecoration(
                    hintText: '请选择日期',
                  ),
                ),
              ),
            ],
          ).toList(),
        ),
      ),
    ).nestSliverToBoxAdapter();
  }
}
