/*
 * @Author       : WuWei
 * @LastEditors: wjc
 * @Date         : 2021-08-16 16:06:58
 * @LastEditTime: 2023-01-16 15:08:13
 * @Description  : Do not edit
 */

import 'package:flutter/material.dart';
import 'package:wisdom_cli/wisdom_cli.dart';

class TaskItem extends StatelessWidget {
  const TaskItem({
    Key? key,
    this.item,
    this.isMine = false,
    this.onClick,
  }) : super(key: key);
  final item;
  final bool? isMine;
  final Function(dynamic value)? onClick;

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

    ///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,
      // margin: EdgeInsets.fromLTRB(15.pt, 0, 15.pt, 0),
      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: item?.title ?? '',
                    style: TextStyle(
                      fontSize: 16.pt,
                      fontWeight: FontWeight.w600,
                    ),
                  ),
                ],
              ),
              maxLines: 1,
              overflow: TextOverflow.ellipsis,
            ).asExpanded(),
          ]),
          Wisdom.row(
            mainAxisAlignment: MainAxisAlignment.start,
            margin: EdgeInsets.only(
              top: 7.5.pt,
            ),
            children: [
              Text.rich(
                TextSpan(children: [
                  // 是否是环节任务
                  if (item?.isMultiStep == true)
                    WidgetSpan(
                      child: WTag(
                        color: colorScheme.green,
                        child: WisText(
                          '环节任务',
                          size: 13.pt,
                        ),
                      ),
                    ),
                  // 是否日常任务
                  if (item?.preset == true)
                    WidgetSpan(
                      child: WTag(
                        color: colorScheme.blue,
                        child: WisText(
                          '日常任务',
                          size: 13.pt,
                        ),
                      ),
                    )
                  else
                    WidgetSpan(
                      child: WTag(
                        color: colorScheme.orange,
                        child: WisText(
                          '专项任务',
                          size: 13.pt,
                        ),
                      ),
                    ),
                  if (item?.taskTimeout == true)
                    WidgetSpan(
                      child: WTag(
                        margin: EdgeInsets.only(right: 5.pt),
                        child: WisText(
                          '超时',
                          size: 13.pt,
                        ),
                        color: statusColorMap[4],
                      ),
                    ),
                ]),
                maxLines: 2,
                overflow: TextOverflow.ellipsis,
              ).asExpanded(),
            ],
          ),
          Wisdom.row(
            padding: EdgeInsets.only(
              top: 15.pt,
            ),
            children: [
              Wisdom(
                margin: EdgeInsets.only(right: 10.pt),
                child: Text(
                  "添加人",
                  style: TextStyle(
                    fontWeight: FontWeight.w300,
                    fontSize: 14.pt,
                    color: Color(0xFF616178),
                  ),
                ),
              ).asExpanded(),
              Text(
                item?.createdByName ?? item?.createdBy ?? '--',
                style: TextStyle(
                  fontWeight: FontWeight.w300,
                  fontSize: 14.pt,
                  color: Color(0xFF9FA5B7),
                ),
              )
            ],
          ),
          Wisdom.row(
            padding: EdgeInsets.only(
              top: 10.pt,
              bottom: 10.pt,
            ),
            children: [
              Wisdom(
                margin: EdgeInsets.only(right: 10.pt),
                child: Text(
                  "任务类型",
                  style: TextStyle(
                    fontWeight: FontWeight.w300,
                    fontSize: 14.pt,
                    color: Color(0xFF616178),
                  ),
                ),
              ).asExpanded(),
              Text(
                item?.inventoryName ?? '--',
                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 (item?.status == 'finished')
                    WidgetSpan(
                      child: WTag(
                        margin: EdgeInsets.only(right: 5.pt),
                        child: WisText(
                          '已完成',
                          size: 13.pt,
                        ),
                        color: statusColorMap[3]!,
                      ),
                    ),
                  if (item?.status == 'no_open')
                    WidgetSpan(
                      child: WTag(
                        margin: EdgeInsets.only(right: 5.pt),
                        child: WisText(
                          '未开始',
                          size: 13.pt,
                        ),
                        color: statusColorMap[1]!,
                      ),
                    ),
                  if (item?.status == 'doing')
                    WidgetSpan(
                      child: WTag(
                        margin: EdgeInsets.only(right: 5.pt),
                        child: WisText(
                          '进行中',
                          size: 13.pt,
                        ),
                        color: statusColorMap[2]!,
                      ),
                    ),
                  if (item?.status == 'cancel')
                    WidgetSpan(
                      child: WTag(
                        margin: EdgeInsets.only(right: 5.pt),
                        child: WisText(
                          '终止',
                          size: 13.pt,
                        ),
                        color: statusColorMap[5]!,
                      ),
                    ),
                  if (item?.status == 'overdue')
                    WidgetSpan(
                      child: WTag(
                        margin: EdgeInsets.only(right: 5.pt),
                        child: WisText(
                          '已逾期',
                          size: 13.pt,
                        ),
                        color: statusColorMap[7]!,
                      ),
                    ),
                  if (item?.status == 'waitReceive')
                    WidgetSpan(
                      child: WTag(
                        margin: EdgeInsets.only(right: 5.pt),
                        child: WisText(
                          '待领取',
                          size: 13.pt,
                        ),
                        color: statusColorMap[6]!,
                      ),
                    ),
                  if (item?.examine == true)
                    WidgetSpan(
                      child: WTag(
                        margin: EdgeInsets.only(right: 5.pt),
                        child: WisText(
                          '已审查',
                          size: 13.pt,
                        ),
                        color: colorScheme.success,
                      ),
                    ),
                ]),
                maxLines: 2,
                overflow: TextOverflow.ellipsis,
              ).asExpanded(),
              Text(
                "发布时间:${item.createdAt ?? '--'}",
                style: TextStyle(
                  fontWeight: FontWeight.w300,
                  fontSize: 14.pt,
                  color: Color(0xFF616178),
                ),
              )
            ],
          ),
        ],
      ),
    );
  }
}
