/*
 * @Author       : WuWei
 * @LastEditors  : WuWei
 * @Date         : 2022-11-10 14:50:47
 * @LastEditTime : 2023-06-13 09:46:57
 * @Description  : Do not edit
 */
part of '../index.dart';

class TaskCard extends StatefulWidget {
  TaskCard({Key? key}) : super(key: key);

  @override
  State<TaskCard> createState() => _TaskCardState();
}

class _TaskCardState extends State<TaskCard> {
  @override
  Widget build(BuildContext context) {
    final colorScheme = WTheme.of(context).colorScheme;
    final store = Provider.of<WorkStore>(context, listen: true);
    return Wisdom(
      padding: EdgeInsets.only(
        left: 15.pt,
        right: 15.pt,
        top: 15.pt,
      ),
      child: WisCard(
        child: Wisdom.column(
          padding: EdgeInsets.all(15.pt),
          borderRadius: BorderRadius.circular(12.pt),
          children: [
            Wisdom.row(
              onTap: () => store.toWaitTask(),
              padding: EdgeInsets.all(15.pt),
              borderRadius: BorderRadius.circular(12.pt),
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              color: colorScheme.background,
              children: [
                WisText(
                  '待领取任务数（个）',
                  size: 15.pt,
                  weight: FontWeight.w600,
                ),
                Wisdom.row( children: [
                  // Stack(children: [
                  WisText(
                    '${store.taskStatistics?.waitReceive != null && store.taskStatistics!.waitReceive! > 99 ? '99+' : store.taskStatistics?.waitReceive ?? 0}',
                    color: colorScheme.primary,
                    size: 34.pt,
                    weight: FontWeight.bold,
                  ),
                  // Positioned(
                  //   right: 1.pt,
                  //   top: 1.pt,
                  //   child: Wisdom(
                  //     color: colorScheme.red,
                  //     borderRadius: BorderRadius.circular(100.pt),
                  //     height: 9.pt,
                  //     width: 9.pt,
                  //   ),
                  // )
                  // ]),
                  SizedBox(width: 5.pt),
                  Image.asset(
                    'lib/assets/main/enter.png',
                    package: 'app_package',
                    width: 14.pt,
                    height: 14.pt,
                  ),
                ]),
              ],
            ),
            Wisdom.row(
              padding: EdgeInsets.only(
                top: 15.pt,
              ),
              children: [
                Row(
                  children: [
                    _Number(
                      toRoute: () => store.toNoOpenTask(),
                      number: store.taskStatistics?.noOpenCount ?? 0,
                      text: '未开始',
                      color: colorScheme.orange,
                    ).asFlexible(flex: 1),
                    _Number(
                      toRoute: () => store.toDoingTask(),
                      number: store.taskStatistics?.doingCount ?? 0,
                      text: '进行中',
                      color: colorScheme.green,
                    ).asFlexible(flex: 1),
                  ],
                ).asFlexible(flex: 1),
                Wisdom(
                  margin: EdgeInsets.symmetric(
                    horizontal: 15.pt,
                  ),
                  width: 0.5.pt,
                  height: 34.pt,
                  color: Color(0XFFDCDDE1),
                ),
                Row(
                  children: [
                    Image.asset(
                      'lib/assets/main/icon_rwtj.png',
                      package: 'app_package',
                      width: 18.pt,
                      height: 18.pt,
                    ),
                    SizedBox(
                      width: 5.pt,
                    ),
                    Wisdom(
                      onTap: () => store.toTaskStatistics(),
                      child: WisText(
                        '任务统计',
                        size: 16.pt,
                        color: colorScheme.mainTitle,
                        weight: FontWeight.bold,
                      ),
                    )
                  ],
                )
              ],
            ),
            if (store.taskFee?.isShow == true) ...[
              Wisdom.row(
                border: Border(
                  top: BorderSide(
                    color: colorScheme.divider,
                    width: .5.pt,
                  ),
                ),
                margin: EdgeInsets.only(
                  top: 15.pt,
                ),
                padding: EdgeInsets.only(
                  top: 15.pt,
                ),
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Row(
                    children: [
                      Image.asset(
                        'lib/assets/main/faj.png',
                        package: 'app_package',
                        width: 19.pt,
                        height: 19.pt,
                      ),
                      WisText(
                        '罚金总额',
                        color: colorScheme.mainTitle,
                        size: 15.pt,
                        weight: FontWeight.bold,
                      ),
                    ],
                  ),
                  WisText(
                    '${store.taskFee?.penaltyFee ?? 0}',
                    color: colorScheme.red,
                    size: 19.pt,
                    weight: FontWeight.bold,
                  ),
                ],
              )
            ]
          ],
        ),
      ),
    );
  }
}

class _Number extends StatelessWidget {
  const _Number({
    Key? key,
    this.number,
    this.text,
    this.color,
    required this.toRoute,
  }) : super(key: key);
  final number;
  final text;
  final color;
  final Function() toRoute;

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

    return Wisdom.row(
      onTap: () => toRoute(),
      children: [
        Wisdom(
          borderRadius: BorderRadius.circular(100.pt),
          border: Border.all(
            color: color,
            width: 2.pt,
          ),
          height: 10.pt,
          width: 10.pt,
        ),
        SizedBox(width: 8.pt),
        Column(children: [
          WisText(
            '${number > 99 ? '99+' : number}',
            size: 24.pt,
            color: colorScheme.mainTitle,
          ),
          WisText(
            '$text',
            color: colorScheme.grey,
          ),
        ]),
      ],
    );
  }
}
