/*
 * @Author       : WuWei
 * @LastEditors: ChenYaJin
 * @Date         : 2021-05-10 14:16:37
 * @LastEditTime: 2023-08-15 10:45:10
 * @FilePath     : /wisdom-huiguanjia-app/task_package/lib/src/pages/statistic/components/all_stat.dart
 * @Description  : 任务统计-全部任务统计模块
 */

import 'package:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:task_package/src/view_models/statistic_store.dart';
import 'package:wisdom_cli/wisdom_cli.dart';
import 'task_row_item.dart';

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

  @override
  Widget build(BuildContext context) {
    final style = WTheme.of(context);
    final colorScheme = style.colorScheme;
    final store = Provider.of<StatisticStore>(context, listen: false);
    return Wisdom(
      child: Observer(builder: (_) {
        return WisCard(
          margin: EdgeInsets.only(left: 15.pt, right: 15.pt, top: 10.pt),
          child: Column(
            children: [
              Wisdom.row(
                height: 44.pt,
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                padding: EdgeInsets.symmetric(horizontal: 15.pt),
                crossAxisAlignment: CrossAxisAlignment.center,
                children: <Widget>[
                  Wisdom.row(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: <Widget>[
                      Wisdom(
                        borderRadius: BorderRadius.circular(2.5.pt),
                        color: Color(0xFF2D8CF0),
                        width: 3.pt,
                        height: 14.pt,
                        margin: EdgeInsets.only(right: 10.pt),
                      ),
                      WisText.c222(
                        "全部任务",
                        size: 16.pt,
                        bold: true,
                      )
                    ],
                  ),
                  Wisdom.row(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    mainAxisAlignment: MainAxisAlignment.end,
                    children: <Widget>[
                      Wisdom(
                        margin: EdgeInsets.only(right: 10.pt),
                        child: Text(
                          '${store.getDateRange()}',
                          style: TextStyle(
                            fontSize: 13.pt,
                            fontWeight: FontWeight.w300,
                            color: colorScheme.time,
                          ),
                        ),
                      ),
                    ],
                  )
                ],
              ),
              Divider(),
              BuildTaskRowItem(
                item: store.allStat,
                onClick: (status, inventoryId) => store.onToTaskList(
                    status: status, inventoryId: inventoryId),
              ),
              Divider(),
              Wisdom.column(
                padding:
                    EdgeInsets.symmetric(horizontal: 15.pt, vertical: 15.pt),
                children: [
                  Wisdom.row(
                    height: 35.pt,
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: <Widget>[
                      Wisdom(
                        margin: EdgeInsets.only(right: 25.pt),
                        child: Text(
                          '完成率',
                          style: TextStyle(
                            fontSize: 15.pt,
                            fontWeight: FontWeight.w300,
                            color: colorScheme.mainTitle,
                          ),
                        ),
                      ),
                      Wisdom(
                        height: 6.pt,
                        margin: EdgeInsets.only(right: 25.pt),
                        child: ClipRRect(
                          borderRadius: BorderRadius.circular(12.pt),
                          child: Observer(builder: (_) {
                            return LinearProgressIndicator(
                              backgroundColor: colorScheme.background,
                              value:
                                  store.allStat?.finishingRate as double? ?? 0,
                              valueColor: AlwaysStoppedAnimation(
                                colorScheme.primary,
                              ),
                            );
                          }),
                        ),
                      ).asExpanded(),
                      Text(
                        '${store.allStat?.finishingRate == null ? '--' : (store.allStat!.finishingRate! * 100).toStringAsFixed(1)}%',
                        style: TextStyle(
                          fontSize: 15.pt,
                          fontWeight: FontWeight.w600,
                          color: colorScheme.mainTitle,
                        ),
                      ),
                    ],
                  ),
                  Wisdom.row(
                    height: 35.pt,
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: <Widget>[
                      Wisdom(
                        margin: EdgeInsets.only(right: 25.pt),
                        child: Text(
                          '超时率',
                          style: TextStyle(
                            fontSize: 15.pt,
                            fontWeight: FontWeight.w300,
                            color: colorScheme.mainTitle,
                          ),
                        ),
                      ),
                      Wisdom(
                        height: 6.pt,
                        margin: EdgeInsets.only(right: 25.pt),
                        child: ClipRRect(
                          borderRadius: BorderRadius.circular(12.pt),
                          child: Observer(builder: (_) {
                            return LinearProgressIndicator(
                              backgroundColor: colorScheme.background,
                              value:
                                  store.allStat?.timeoutRate as double? ?? .0,
                              valueColor: AlwaysStoppedAnimation(
                                colorScheme.primary,
                              ),
                            );
                          }),
                        ),
                      ).asExpanded(),
                      Text(
                        '${store.allStat?.timeoutRate == null ? '--' : (store.allStat!.timeoutRate! * 100).toStringAsFixed(1)}%',
                        style: TextStyle(
                          fontSize: 15.pt,
                          fontWeight: FontWeight.w600,
                          color: colorScheme.mainTitle,
                        ),
                      ),
                    ],
                  ),
                  Wisdom.row(
                    height: 35.pt,
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: <Widget>[
                      Wisdom(
                        margin: EdgeInsets.only(right: 25.pt),
                        child: Text(
                          '平均用时',
                          style: TextStyle(
                            fontSize: 15.pt,
                            fontWeight: FontWeight.w300,
                            color: colorScheme.mainTitle,
                          ),
                        ),
                      ),
                      Text(
                        '${store.allStat?.avgUseTime ?? '--'}小时',
                        style: TextStyle(
                          fontSize: 15.pt,
                          fontWeight: FontWeight.w600,
                          color: colorScheme.mainTitle,
                        ),
                      ),
                    ],
                  ),
                  Wisdom.row(
                    height: 35.pt,
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: <Widget>[
                      Wisdom(
                        margin: EdgeInsets.only(right: 25.pt),
                        child: Text(
                          '平均持续时长',
                          style: TextStyle(
                            fontSize: 15.pt,
                            fontWeight: FontWeight.w300,
                            color: colorScheme.mainTitle,
                          ),
                        ),
                      ),
                      Text(
                        '${store.allStat?.avgDurationTime ?? '--'}小时',
                        style: TextStyle(
                          fontSize: 15.pt,
                          fontWeight: FontWeight.w600,
                          color: colorScheme.mainTitle,
                        ),
                      ),
                    ],
                  ),
                ],
              )
            ],
          ),
        );
      }),
    );
  }
}
