/*
 * @Author       : WuWei
 * @LastEditors: ChenYaJin
 * @Date         : 2023-03-13 17:15:13
 * @LastEditTime: 2023-08-16 15:52:46
 * @Description  : Do not edit
 */
part of '../index.dart';

class WorkCard extends StatelessWidget {
  const WorkCard({
    Key? key,
    this.name,
    this.data,
    required this.toRoutes,
  }) : super(key: key);
  final String? name;
  final data;
  final Function() toRoutes;
  @override
  Widget build(BuildContext context) {
    final store = Provider.of<WorkStore>(context, listen: true);
    final colorScheme = WTheme.of(context).colorScheme;
    return Wisdom(
      color: Color(0x000074FF),
      padding: EdgeInsets.only(
        left: 15.pt,
        top: 15.pt,
        right: 15.pt,
      ),
      child: LineCard(
        width: MediaQuery.of(context).size.width - 30.pt,
        child: Wisdom.column(
          crossAxisAlignment: CrossAxisAlignment.start,
          padding: EdgeInsets.all(10.pt),
          children: [
            WisText(
              '$name',
              size: 18.pt,
              color: colorScheme.mainTitle,
              weight: FontWeight.w600,
            ),
            Wisdom.column(
              padding: EdgeInsets.only(
                top: 20.pt,
                bottom: 5.pt,
              ),
              children: [
                for (var item in data.excutivePlatformList)
                  _RouteItem(
                    toRoutes: () => store.toTaskDetail(item),
                    name: '${item.title}',
                    dotline: DotLine(
                      color: Color(0XFF0F67F8),
                      fadeColor: Color(0XFFCCDBFF),
                      isPrimary: true,
                    ),
                    item: item,
                  ),
              ],
            ),
            Wisdom.row(
              margin: EdgeInsets.symmetric(
                horizontal: 5.pt,
              ),
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Row(
                  children: [
                    WisText(
                      '未完成数',
                      size: 13.pt,
                      color: colorScheme.grey,
                    ),
                    SizedBox(width: 10.pt),
                    WisText(
                      '${data.undoneCount > 99 ? '99+' : data?.undoneCount ?? 0}',
                      size: 24.pt,
                      color: colorScheme.primary,
                    ),
                  ],
                ),
                Wisdom.row(
                  onTap: () => toRoutes(),
                  children: [
                    WisText(
                      '查看更多',
                      size: 13.pt,
                      color: colorScheme.grey,
                    ),
                    SizedBox(width: 4.pt),
                    Image.asset(
                      'lib/assets/main/enter2.png',
                      package: 'app_package',
                      width: 14.pt,
                      height: 14.pt,
                    ),
                  ],
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}

class _RouteItem extends StatelessWidget {
  const _RouteItem({
    Key? key,
    this.dotline,
    this.name,
    required this.toRoutes,
    required this.item,
  }) : super(key: key);
  final Widget? dotline;
  final String? name;
  final Future<void> Function() toRoutes;
  final ExcutivePlatformListOfTaskListModel item;

  @override
  Widget build(BuildContext context) {
    final colorScheme = WTheme.of(context).colorScheme;
    return Wisdom.row(
      onTap: () => toRoutes(),
      margin: EdgeInsets.only(bottom: 10.pt),
      children: [
        // dotline,
        Wisdom.row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            padding: EdgeInsets.symmetric(
              horizontal: 15.pt,
              vertical: 10.pt,
            ),
            borderRadius: BorderRadius.circular(12.pt),
            color: colorScheme.background,
            children: [
              Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  WisText(
                    '$name',
                    size: 15.pt,
                    color: colorScheme.mainTitle,
                  ),
                  SizedBox(height: 8.pt),
                  Wisdom.row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    width: MediaQuery.of(context).size.width * .75,
                    children: [
                      Wisdom.row(
                        children: [
                          Wisdom.row(
                            children: [
                              WisText(
                                '总点数：',
                                size: 13.pt,
                              ),
                              WisText(
                                '${item.nodeCount ?? '0'}',
                                size: 14.pt,
                                weight: FontWeight.w500,
                                color: colorScheme.primary,
                              ),
                            ],
                          ),
                          Wisdom.row(
                            margin: EdgeInsets.only(left: 10.pt),
                            children: [
                              WisText(
                                '剩余点数：',
                                size: 13.pt,
                              ),
                              WisText(
                                '${item.notDoneCount ?? '0'}',
                                size: 14.pt,
                                weight: FontWeight.w500,
                                color: colorScheme.danger,
                              ),
                            ],
                          )
                        ],
                      ).asExpanded(),
                      Image.asset(
                        'lib/assets/main/enter.png',
                        package: 'app_package',
                        width: 14.pt,
                        height: 14.pt,
                      ),
                    ],
                  ),
                  SizedBox(height: 8.pt),
                  Row(
                    children: [
                      if ((item.isTimeOut == false &&
                              item.closeTime != null &&
                              item.overdueTime == null) ||
                          (item.isTimeOut == true &&
                              item.closeTime != null &&
                              item.overdueTime == null) ||
                          (item.isTimeOut == false &&
                              item.closeTime != null &&
                              item.overdueTime != null)) ...[
                        WisText(
                          '限${item.closeTime}前完成',
                          color: colorScheme.red,
                          size: 13.pt,
                        )
                      ] else if ((item.isTimeOut == true &&
                              item.overdueTime != null &&
                              item.closeTime != null) ||
                          (item.isTimeOut == false &&
                              item.overdueTime != null &&
                              item.closeTime == null)) ...[
                        WisText(
                          '该任务${item.overdueTime}后到期',
                          color: colorScheme.red,
                          size: 13.pt,
                        ),
                      ] else ...[
                        WisText(
                          '尽快完成该任务',
                          color: colorScheme.grey,
                          size: 13.pt,
                        )
                      ],
                    ],
                  ),
                ],
              ),
            ]).asFlexible(flex: 1),
      ],
    );
  }
}
