/*
 * @Author: WuWei
 * @Date: 2020-06-24 11:09:03
 * @LastEditors: wjc
 * @LastEditTime: 2023-01-13 16:58:51
 * @Description: 任务详情-父级任务
 */
part of '../index.dart';

class _FatherComponent extends StatelessWidget {
  const _FatherComponent({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    final store = Provider.of<PrivateTaskDetailStore>(context, listen: true);
    final style = WTheme.of(context);
    final colorScheme = style.colorScheme;
    return SliverToBoxAdapter(
      child: Wisdom.column(
        color: Colors.white,
        margin: EdgeInsets.symmetric(vertical: 10.pt, horizontal: 15.pt),
        padding: EdgeInsets.all(15.pt),
        borderRadius: BorderRadius.circular(12.pt),
        boxShadow: [
          BoxShadow(
            offset: Offset(0, 2),
            color: Color(0x08000000),
            blurRadius: 10.pt,
            spreadRadius: 2.5.pt,
          ),
        ],
        children: [
          Wisdom.row(
            padding: EdgeInsets.only(bottom: 15.pt),
            children: [
              WisText(
                '上级任务',
                size: 15.pt,
                bold: true,
                color: colorScheme.mainTitle,
              ),
            ],
          ),
          if (store.father != null) ...[
            _TaskItemFather(),
          ]
        ],
      ),
    );
  }
}

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

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

    ///tag状态颜色
    final statusColorMap = {
      // 1: '未开始',
      1: colorScheme.orange,
      // 2: '进行中',
      2: colorScheme.blue,
      // 3: '已完成',
      3: colorScheme.success,
      // 4: '超时',
      4: colorScheme.danger,
      // 5: '取消'
      5: colorScheme.minor,
      // 6: '超时'
      6: colorScheme.danger,
      // 7：'已逾期'
      7: colorScheme.minor,
    };

    return Wisdom(
      color: Colors.white,
      padding: EdgeInsets.symmetric(vertical: 15.pt),
      child: Wisdom.column(
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: <Widget>[
          Row(
            mainAxisAlignment: MainAxisAlignment.start,
            children: [
              Text.rich(
                TextSpan(children: [
                  if (store.father?.status == 'finished')
                    WidgetSpan(
                      child: WTag(
                        margin: EdgeInsets.only(right: 5.pt),
                        child: WisText(
                          '已完成',
                          size: 13.pt,
                        ),
                        color: statusColorMap[3]!,
                      ),
                    ),
                  if (store.father?.status == 'no_open')
                    WidgetSpan(
                      child: WTag(
                        margin: EdgeInsets.only(right: 5.pt),
                        child: WisText(
                          '未开始',
                          size: 13.pt,
                        ),
                        color: statusColorMap[1]!,
                      ),
                    ),
                  if (store.father?.status == 'doing')
                    WidgetSpan(
                      child: WTag(
                        margin: EdgeInsets.only(right: 5.pt),
                        child: WisText(
                          '进行中',
                          size: 13.pt,
                        ),
                        color: statusColorMap[2]!,
                      ),
                    ),
                  if (store.father?.status == 'cancel')
                    WidgetSpan(
                      child: WTag(
                        color: statusColorMap[5]!,
                        child: WisText(
                          '取消',
                          size: 13.pt,
                        ),
                      ),
                    ),
                  if (store.father!.isTimeOut == true)
                    WidgetSpan(
                      child: WTag(
                        margin: EdgeInsets.only(right: 5.pt),
                        child: WisText(
                          '超时',
                          size: 13.pt,
                        ),
                        color: statusColorMap[4]!,
                      ),
                    ),
                  TextSpan(
                    text: store.father?.title ?? '',
                    style: TextStyle(
                      fontSize: 15.pt,
                      fontWeight: FontWeight.w600,
                    ),
                  ),
                ]),
                maxLines: 2,
                overflow: TextOverflow.ellipsis,
              ).asExpanded(),
            ],
          ),
          Wisdom.row(
            margin: EdgeInsets.only(
              top: 10.pt,
            ),
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              Text(
                "执行人:${store.father?.operator ?? '--'}",
                style: TextStyle(
                  fontWeight: FontWeight.w300,
                  fontSize: 13.pt,
                  color: colorScheme.time,
                ),
              ),
              Text(
                "发布时间:${store.father?.createdAt ?? ''}",
                style: TextStyle(
                  fontWeight: FontWeight.w300,
                  fontSize: 13.pt,
                  color: colorScheme.time,
                ),
              )
            ],
          ),
        ],
      ),
    );
  }
}
