/*
 * @Author       : WuWei
 * @LastEditors: ChenYaJin
 * @Date         : 2021-09-26 16:02:10
 * @LastEditTime: 2023-08-10 14:36:55
 * @Description  : Do not edit
 */
part of '../index.dart';

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

  @override
  Widget build(BuildContext context) {
    final colorScheme = WTheme.of(context).colorScheme;
    final store = Provider.of<PointFormStore>(context, listen: false);

    return Wisdom.column(
      color: Colors.white,
      padding: EdgeInsets.all(15.pt),
      margin: EdgeInsets.only(bottom: 10.pt, right: 15.pt, left: 15.pt),
      borderRadius: BorderRadius.circular(10.pt),
      boxShadow: [
        BoxShadow(
          offset: Offset(0, 2.pt),
          color: Color(0x08000000),
          blurRadius: 10.pt,
          spreadRadius: 2.5.pt,
        ),
      ],
      children: [
        Wisdom.row(
          margin: EdgeInsets.only(
            bottom: 10.pt,
          ),
          children: <Widget>[
            WisText(
              '作业标准',
              color: colorScheme.mainTitle,
              size: 16.pt,
              bold: true,
            ),
          ],
        ),
        Observer(builder: (_) {
          return Wisdom.column(children: [
            for (num i = 0; i < store.formList.length; i++)
              __FormDetailItem(
                item: store.formList[i as int],
                index: i,
              ),
            Container(height: 0),
          ]);
        }),
      ],
    );
  }
}

class __FormDetailItem extends StatelessWidget {
  const __FormDetailItem({Key? key, this.item, this.index}) : super(key: key);
  final item;
  final index;

  @override
  Widget build(BuildContext context) {
    final colorScheme = WTheme.of(context).colorScheme;
    final store = Provider.of<PointFormStore>(context, listen: false);

    ///作业标准表单类型
    final formTypes = {
      'radio': '单选',
      'checkbox': '多选',
      'text': '简答',
      'img': '图片',
      'exception': '异常项'
    };

    return Wisdom.column(
      crossAxisAlignment: CrossAxisAlignment.stretch,
      margin: EdgeInsets.symmetric(
        vertical: 12.5.pt,
      ),
      children: [
        Wisdom.row(crossAxisAlignment: CrossAxisAlignment.center, children: [
          WisText(
            '${item?.required == true ? '*' : ''}',
            color: Color(0XFFFF495E),
          ),
          if (item?.required == true) ...[
            SizedBox(
              width: 10.pt,
            ),
          ],
          Wisdom.row(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Wisdom(
                color: colorScheme.primary,
                padding: EdgeInsets.symmetric(horizontal: 5.pt, vertical: 2.pt),
                margin: EdgeInsets.only(right: 5.pt),
                borderRadius: BorderRadius.circular(5.pt),
                child: WisText(
                  '${formTypes[item.type]}',
                  size: 11.pt,
                  weight: FontWeight.bold,
                  color: Colors.white,
                ),
              ),
              // 作业标准内容标题
              WisText(
                '${item?.title}',
                size: 15.pt,
                weight: FontWeight.w600,
                color: colorScheme.mainTitle,
              ).asExpanded(),
            ],
          ).asExpanded()
        ]),
        if (item?.type == 'text') ...[
          Observer(builder: (_) {
            return Wisdom.row(
              margin: EdgeInsets.only(
                top: 15.pt,
              ),
              children: [
                WisText(
                  store.formDetailList.length > 0 &&
                          store.formDetailList[index] != null
                      ? store.formDetailList[index]?.workStandardRecord ?? '--'
                      : '--',
                  color: colorScheme.minor,
                  size: 15.pt,
                ).asExpanded(),
              ],
            );
          }),
        ],
        if (item?.type == 'img') ...[
          Observer(builder: (_) {
            return _BuildPicList(
              image: store.formDetailList.length > 0 &&
                      store.formDetailList[index] != null
                  ? (store.formDetailList[index]?.workStandardRecord
                          ?.split(',') ??
                      [])
                  : [],
            );
          }),
        ],
        if (item?.type == 'radio' || item?.type == 'checkbox') ...[
          Observer(builder: (_) {
            return _BuildCheckList(
              checkList: item?.workStandardExtends ?? [],
              checkValue: store.formDetailList.length > 0 &&
                      store.formDetailList[index] != null
                  ? store.formDetailList[index]?.workStandardRecord ?? ''
                  : '',
              type: item?.type,
              remark: store.formDetailList.length > 0 &&
                      store.formDetailList[index] != null
                  ? store.formDetailList[index]?.remark ?? null
                  : '',
            );
          }),
        ] else ...[
          Container(height: 0),
        ]
      ],
    );
  }
}

class _BuildCheckList extends StatelessWidget {
  const _BuildCheckList({
    Key? key,
    this.checkList,
    this.checkValue,
    this.type,
    this.remark,
  }) : super(key: key);
  final checkList;
  final checkValue;
  final type;
  final remark;
  @override
  Widget build(BuildContext context) {
    final colorScheme = WTheme.of(context).colorScheme;
    return Wisdom.column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        for (var i = 0; i < checkList.length; i++)
          Wisdom.row(
            crossAxisAlignment: CrossAxisAlignment.center,
            margin: EdgeInsets.only(
              top: 25.pt,
            ),
            children: [
              if (((checkValue is bool == true) &&
                      checkValue == checkList[i]["id"]) ||
                  ((checkValue is bool == false) &&
                      checkValue.contains(checkList[i]["id"]))) ...[
                Image(
                  image: AssetList.$xzh_png_image,
                  width: 10.pt,
                  height: 10.pt,
                ),
                SizedBox(
                  width: 15.pt,
                ),
              ] else ...[
                SizedBox(
                  width: 25.pt,
                ),
              ],
              WisText(
                checkList[i]['content'] ?? '--',
                color: colorScheme.mainTitle,
                weight: FontWeight.w300,
              ),
              if (checkList[i]['exceptionItem'] == true) ...[
                WTag(
                    child: Text(
                      '异常项',
                      style: TextStyle(
                        fontSize: 13.pt,
                      ),
                    ),
                    /// 选中该选项的才是红色
                    color: ((checkValue is bool == true) &&
                                checkValue == checkList[i]["id"]) ||
                            ((checkValue is bool == false) &&
                                checkValue.contains(checkList[i]["id"]))
                        ? colorScheme.danger
                        : colorScheme.grey,
                    margin: EdgeInsets.only(left: 5.pt)),
              ]
            ],
          ),
        if (remark != null && remark != '') ...[
          Wisdom.row(
            border: Border.all(
              color: Color(0xfff0f0f0),
              width: 1,
            ),
            borderRadius: BorderRadius.circular(12.pt),
            padding: EdgeInsets.all(5.pt),
            margin: EdgeInsets.only(top: 15.pt),
            children: [
              WisText(
                '说明：$remark',
                color: colorScheme.grey,
              ).asExpanded(),
            ],
          ),
        ],
      ],
    );
  }
}

/// 图片详情
class _BuildPicList extends StatelessWidget {
  const _BuildPicList({Key? key, this.image}) : super(key: key);
  final image;
  @override
  Widget build(BuildContext context) {
    final store = Provider.of<PointFormStore>(context);
    return Wisdom(
      margin: EdgeInsets.only(top: 15.pt),
      child: Wrap(
        spacing: 10.pt,
        runSpacing: 15.pt,
        children: [
          for (var i = 0; i < image.length; i++)
            Wisdom(
              onTap: () => {store.onShowImage(image[i])},
              child: WImage.network(
                AppParseUtil.image('${image[i]}'),
                width: 90.pt,
                height: 90.pt,
                fit: BoxFit.cover,
                borderRadius: BorderRadius.circular(2.pt),
              ),
            )
        ],
      ),
    );
  }
}
