/*
 * @Author       : WuWei
 * @LastEditors  : WuWei
 * @Date         : 2021-03-04 16:06:21
 * @LastEditTime : 2023-07-26 10:40:19
 * @FilePath     : /wisdom-huiguanjia-app/oa_package/lib/src/pages/index/components/stat.dart
 * @Description  : Do not edit
 */
part of '../view.dart';

class _StatComponent extends StatelessWidget {
  const _StatComponent({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    final store = Provider.of<IndexStore>(context, listen: false);
    final style = WTheme.of(context);
    final colorScheme = style.colorScheme;

    return SliverToBoxAdapter(
      child: Observer(
        builder: (_) {
          return GradientCard(
            gradient: LinearGradient(
              colors: [Color(0xff4D80FF), Color(0xff0F67F8)],
              begin: Alignment.centerLeft,
              end: Alignment.centerRight,
            ),
            margin: EdgeInsets.only(
              bottom: 10.pt,
              left: 15.pt,
              right: 15.pt,
              top: 15.pt,
            ),
            child: Wisdom.row(
              color: colorScheme.primary,
              mainAxisAlignment: MainAxisAlignment.spaceAround,
              children: [
                _StatItem(
                  item: store.waitingCount,
                  i: 0,
                ),
                _StatItem(
                  item: store.startCount,
                  i: 1,
                ),
                _StatItem(
                  item: store.acceptCount,
                  i: 2,
                ),
              ],
            ),
          );
        },
      ),
    );
  }
}

class _StatItem extends StatelessWidget {
  const _StatItem({Key? key, required this.item, this.i}) : super(key: key);

  final num item;
  final i;

  @override
  Widget build(BuildContext context) {
    final store = Provider.of<IndexStore>(context, listen: false);
    final List names = ['待处理', '我发起的', '已处理'];
    final style = WTheme.of(context);
    final colorScheme = style.colorScheme;
    final images = [
      AssetList.$pending_png_image,
      AssetList.$transact_png_image,
      AssetList.$already_png_image
    ];

    return Container(
      margin: EdgeInsets.only(top: 10.pt),
      child: Stack(clipBehavior: Clip.none, children: [
        Wisdom.column(
          onTap: () => store.toManagement(i),
          padding: EdgeInsets.all(15.pt),
          children: [
            Image(image: images[i], height: 28.pt),
            SizedBox(height: 10.pt),
            Text(
              '${names[i]}',
              style: TextStyle(
                height: 1,
                color: Colors.white,
                fontSize: 12.pt,
                fontWeight: FontWeight.w300,
              ),
            ),
          ],
        ),
        if (item > 0) ...[
          Positioned(
            right: 15.pt,
            top: 3.pt,
            child: Wisdom(
              padding: EdgeInsets.symmetric(horizontal: 5.pt, vertical: 2.pt),
              borderRadius: BorderRadius.circular(item > 99 ? 9.5.pt : 20.pt),
              color: colorScheme.red,
              child: WisText(
                '${item > 99 ? '99+' : item}',
                color: Colors.white,
              ),
            ),
          ),
        ]
      ]),
    );
  }
}
