/*
 * @Author       : WuWei
 * @LastEditors: ChenYaJin
 * @Date         : 2021-10-26 11:05:35
 * @LastEditTime: 2023-05-29 10:00:32
 * @Description  : Do not edit
 */
part of '../index.dart';

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

  @override
  Widget build(BuildContext context) {
    final store = Provider.of<PrivateTaskDetailStore>(context);
    return WisScrollView(
      onInit: () => store.onGetMuitiTaskList(),
      slivers: [
        SliverToBoxAdapter(
          child: Wisdom.column(
            children: [
              if (store.multiList.length > 0) ...[
                _MultiList(),
              ],
            ],
          ),
        ),
      ],
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    final store = Provider.of<PrivateTaskDetailStore>(context);
    final colorScheme = WTheme.of(context).colorScheme;
    final masterData = store.multiList[0][0];

    return Wisdom.column(
      children: [
        _MasterTask(
          masterData: masterData,
        ),
        // 环节任务标题
        Wisdom.column(
          margin: EdgeInsets.only(
            top: 70.pt,
            left: 15.pt,
            right: 15.pt,
          ),
          padding: EdgeInsets.symmetric(
            horizontal: 15.pt,
            vertical: 15.pt,
          ),
          color: Colors.white,
          borderRadius: BorderRadius.circular(12.pt),
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          boxShadow: [
            BoxShadow(
              offset: Offset(0, 2),
              color: Color(0x08000000),
              blurRadius: 10.pt,
              spreadRadius: 2.5.pt,
            ),
          ],
          children: [
            Wisdom.row(children: [
              WisText(
                '环节任务',
                color: colorScheme.mainTitle,
                size: 15.pt,
                weight: FontWeight.w600,
              ),
            ]),
            for (int i = 1; i < store.multiList.length; i++)
              _MultiBlock(
                itemList: store.multiList[i],
                isLast:
                    i == (store.multiList.length - 1) || i == 0 ? true : false,
                index: i,
              ),
          ],
        ),
      ],
    );
  }
}

class _MasterTask extends StatelessWidget {
  const _MasterTask({Key? key, this.masterData}) : super(key: key);
  final masterData;

  @override
  Widget build(BuildContext context) {
    final colorScheme = WTheme.of(context).colorScheme;

    return new Stack(
      clipBehavior: Clip.none,
      children: <Widget>[
        Wisdom.row(
          height: 142.pt,
          color: colorScheme.primary,
          padding: EdgeInsets.only(
            top: 20.pt,
            left: 30.pt,
            right: 15.pt,
            bottom: 15.pt,
          ),
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            WisText(
              '主线任务',
              color: Colors.white,
              size: 18.pt,
              weight: FontWeight.w600,
            ),
          ],
        ),
        // 主线任务内容
        new Positioned(
          top: 50,
          left: 0,
          right: 0,
          child: Wisdom(
            color: Colors.white,
            margin: EdgeInsets.symmetric(vertical: 10.pt, horizontal: 15.pt),
            padding: EdgeInsets.all(15.pt),
            // onTap: () => onClick(item),
            borderRadius: BorderRadius.circular(12.pt),
            boxShadow: [
              BoxShadow(
                offset: Offset(0, 2),
                color: Color(0x08000000),
                blurRadius: 10.pt,
                spreadRadius: 2.5.pt,
              ),
            ],
            child: Wisdom.column(
                crossAxisAlignment: CrossAxisAlignment.stretch,
                padding: EdgeInsets.only(
                  bottom: 7.5.pt,
                ),
                children: <Widget>[
                  Row(children: [
                    Text.rich(
                      TextSpan(
                        children: [
                          TextSpan(
                            text: masterData?.title ?? '',
                            style: TextStyle(
                              fontSize: 16.pt,
                              fontWeight: FontWeight.w600,
                            ),
                          ),
                        ],
                      ),
                      maxLines: 1,
                      overflow: TextOverflow.ellipsis,
                    ).asExpanded(),
                  ]),
                  Wisdom.row(
                    padding: EdgeInsets.only(
                      top: 15.pt,
                    ),
                    children: [
                      Wisdom(
                        margin: EdgeInsets.only(right: 10.pt),
                        padding: EdgeInsets.only(bottom: 15.pt),
                        child: Text(
                          "执行人",
                          style: TextStyle(
                            fontWeight: FontWeight.w300,
                            fontSize: 14.pt,
                            color: Color(0xFF616178),
                          ),
                        ),
                      ).asExpanded(),
                      Text(
                        masterData?.operatorName ?? '--',
                        style: TextStyle(
                          fontWeight: FontWeight.w300,
                          fontSize: 14.pt,
                          color: Color(0xFF9FA5B7),
                        ),
                      )
                    ],
                  ),
                  Wisdom.row(
                    border: Border(
                      top: Divider.createBorderSide(context),
                    ),
                    padding: EdgeInsets.only(top: 15.pt),
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text.rich(
                        TextSpan(children: [
                          if (masterData.taskStatus == 'finished')
                            WidgetSpan(
                              child: WTag(
                                margin: EdgeInsets.only(right: 5.pt),
                                child: WisText(
                                  '已完成',
                                  size: 14.pt,
                                ),
                                color: colorScheme.green,
                              ),
                            ),
                          if (masterData.taskStatus == 'no_open')
                            WidgetSpan(
                              child: WisText(
                                '未开始',
                                size: 14.pt,
                                color: Color(0xffF29B04),
                              ),
                            ),
                          if (masterData.taskStatus == 'doing')
                            WidgetSpan(
                              child: WTag(
                                margin: EdgeInsets.only(right: 5.pt),
                                child: WisText(
                                  '进行中',
                                  size: 14.pt,
                                ),
                                color: Color(0xffFF7531),
                              ),
                            )
                        ]),
                        maxLines: 2,
                        overflow: TextOverflow.ellipsis,
                      ).asExpanded(),
                      Text(
                        "发布时间: ${masterData.createAt ?? '--'}",
                        style: TextStyle(
                          fontWeight: FontWeight.w300,
                          fontSize: 14.pt,
                          color: Color(0xFF616178),
                        ),
                      )
                    ],
                  ),
                ]),
          ),
        ),
      ],
    );
  }
}

class _MultiBlock extends StatelessWidget {
  const _MultiBlock({
    Key? key,
    this.itemList,
    this.isLast,
    this.index,
  }) : super(key: key);
  final itemList;
  final bool? isLast;
  final int? index;

  @override
  Widget build(BuildContext context) {
    final colorScheme = WTheme.of(context).colorScheme;

    return Wisdom.stack(
      clipBehavior: Clip.none,
      children: [
        Wisdom.column(
          color: Colors.white,
          margin: EdgeInsets.symmetric(vertical: 10.pt, horizontal: 15.pt),
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: <Widget>[
            for (int i = 0; i < itemList.length; i++)
              _MultiItem(
                item: itemList[i],
                isLast: i == (itemList.length - 1) ? true : false,
              ),
          ],
        ),
        if (!isLast!)
          Positioned(
            left: 0,
            top: 0,
            bottom: -35.pt,
            child: Container(
              width: 1,
              color: Color(0xffd8d8d8),
            ),
          ),
        Positioned(
          left: -5.pt,
          top: 20.pt,
          child: Wisdom(
            width: 10.pt,
            height: 10.pt,
            color: colorScheme.placeholder,
            borderRadius: BorderRadius.circular(10.pt),
          ),
        ),
      ],
    );
  }
}

class _MultiItem extends StatelessWidget {
  const _MultiItem({Key? key, this.item, this.isLast = false})
      : super(key: key);
  final item;
  final bool isLast;
  @override
  Widget build(BuildContext context) {
    final store = Provider.of<PrivateTaskDetailStore>(context);
    final colorScheme = WTheme.of(context).colorScheme;

    return Wisdom.stack(
      onTap: () => store.toMultiDetail(item),
      margin: EdgeInsets.only(bottom: isLast ? 0 : 15.pt),
      borderRadius: BorderRadius.circular(10.pt),
      color: item?.isTimeout == true ? colorScheme.danger : Colors.white,
      border: Border.all(
        color:
            item?.isTimeout == true ? colorScheme.danger : colorScheme.divider,
      ),
      children: [
        Wisdom.column(
          padding: EdgeInsets.symmetric(
            vertical: 15.pt,
          ),
          margin: EdgeInsets.only(
            left: 23.pt,
            right: 20.pt,
          ),
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Wisdom.row(
              margin: EdgeInsets.only(bottom: 15.pt),
              children: [
                Text.rich(
                  TextSpan(children: [
                    if (item?.isPublic == false)
                      WidgetSpan(
                        child: WTag(
                          margin: EdgeInsets.only(right: 5.pt),
                          child: WisText(
                            '隐藏',
                            size: 12.pt,
                          ),
                          color: colorScheme.minor,
                        ),
                      ),
                    if (item?.isTimeout == true)
                      WidgetSpan(
                        child: WTag(
                          margin: EdgeInsets.only(right: 5.pt),
                          child: WisText(
                            '超时',
                            size: 12.pt,
                          ),
                          color: colorScheme.danger,
                        ),
                      ),
                    TextSpan(
                      text: item?.title ?? '',
                      style: TextStyle(
                        fontSize: 16.pt,
                        fontWeight: FontWeight.w600,
                      ),
                    ),
                  ]),
                  maxLines: 2,
                  overflow: TextOverflow.ellipsis,
                ).asExpanded(),
                if ((item?.relationId == null &&
                        item?.exPlatformId == store.data?.id) ||
                    (item?.relationId != null &&
                        item?.relationId == store.data?.id)) ...[
                  Wisdom.row(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    margin: EdgeInsets.only(right: 5.pt),
                    children: [
                      WisText(
                        '当前',
                        color: Color(0xffFF4949),
                        size: 13.pt,
                        weight: FontWeight.w300,
                      ),
                    ],
                  )
                ],
                Image.asset(
                  'lib/assets/main/enter.png',
                  package: 'app_package',
                  width: 14.pt,
                  height: 14.pt,
                ),
              ],
            ),
            // 分割线
            Wisdom(
              height: 0.5.pt,
              color: colorScheme.divider,
              margin: EdgeInsets.only(bottom: 15.pt),
            ),
            Wisdom.row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Text.rich(
                  TextSpan(children: [
                    if (item?.taskStatus == 'finished')
                      WidgetSpan(
                        child: WTag(
                          margin: EdgeInsets.only(right: 5.pt),
                          child: WisText(
                            '已完成',
                            size: 14.pt,
                          ),
                          color: colorScheme.green,
                        ),
                      ),
                    if (item?.taskStatus == 'no_open')
                      WidgetSpan(
                        child: WisText(
                          '未开始',
                          size: 14.pt,
                          color: Color(0xffF29B04),
                        ),
                      ),
                    if (item?.taskStatus == 'doing')
                      WidgetSpan(
                        child: WTag(
                          margin: EdgeInsets.only(right: 5.pt),
                          child: WisText(
                            '进行中',
                            size: 14.pt,
                          ),
                          color: Color(0xffFF7531),
                        ),
                      )
                  ]),
                  maxLines: 2,
                  overflow: TextOverflow.ellipsis,
                ).asExpanded(),
                WisText(
                  '执行人: ${item?.operatorName ?? '--'}',
                  overflow: TextOverflow.ellipsis,
                  weight: FontWeight.w300,
                  size: 14.pt,
                  color: Color(0xFF616178),
                ),
                if (item?.isAllowUrge == true &&
                    item?.status != 'finished' &&
                    item?.nodeSequenceNumber != null &&
                    item?.isoperator != true) ...[
                  Wisdom.row(
                    onTap: () => store.onPostTaskUrge(item),
                    padding: EdgeInsets.all(4.pt),
                    border: Border.all(
                      color: store.isCheckActiveList(item)
                          ? Color(0xffbbbbbb)
                          : colorScheme.mainTitle,
                    ),
                    borderRadius: BorderRadius.circular(3.pt),
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Image(
                        image: store.isCheckActiveList(item)
                            ? AssetList.$zhcb_png_image
                            : AssetList.$cuiban_h_png_image,
                        height: 14.pt,
                      ),
                      SizedBox(width: 5.pt),
                      WisText(
                        '催办',
                        color: store.isCheckActiveList(item)
                            ? Color(0xffbbbbbb)
                            : colorScheme.mainTitle,
                        size: 13.pt,
                        weight: FontWeight.w300,
                      ),
                    ],
                  ),
                ]
              ],
            ),
          ],
        ),
      ],
    );
  }
}
