/*
 * @Author       : WuWei
 * @LastEditors: wuwei
 * @Date         : 2022-10-09 16:07:58
 * @LastEditTime: 2024-04-08 09:51:20
 * @Description  : Do not edit
 */
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:statistics_package/src/view_models/index_store.dart';
import 'package:wisdom_cli/wisdom_cli.dart';
import '../../assets.gen.dart';
import 'components/day.dart';
import 'components/doc.dart';

///
///
///
///
///
//***以下为模板代码谨慎修改***
class StatisticsPage extends StatelessWidget {
  const StatisticsPage({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    final colorScheme = WTheme.of(context).colorScheme;
    return Scaffold(
      appBar: WAppBar(
        brightness: Brightness.light,
        iconTheme: IconThemeData(
          color: colorScheme.mainTitle,
          size: 19.pt,
        ),
        backgroundColor: Colors.white,
        title: WisText('房管动态',
            size: 19.pt, weight: FontWeight.w600, color: colorScheme.mainTitle),
      ),
      body: StatisticsView(),
    );
  }
}

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

  @override
  State<StatisticsView> createState() => _StatisticsViewState();
}

class _StatisticsViewState extends State<StatisticsView> {
  final StatisticsIndexStore _store = Get.isRegistered<StatisticsIndexStore>()
      ? Get.find<StatisticsIndexStore>()
      : Get.put(StatisticsIndexStore());
  @override
  void dispose() {
    Get.delete<StatisticsIndexStore>();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    var date;
    var month;

    final colorScheme = WTheme.of(context).colorScheme;

    return Column(
      children: [
        Wisdom.row(
          color: Colors.white,
          padding: EdgeInsets.all(15.pt),
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Wisdom.row(
              onTap: () => Get.back(),
              children: [
                Image(
                  image: AssetList.$community_png_image,
                  width: 18.pt,
                  height: 15.pt,
                ),
                SizedBox(width: 5.pt),
                Obx(
                  () => WisText(
                      '${_store.communities.length > 0 ? _store.communities[0].communityName : '--'} '),
                ),
                Obx(
                  () => WisText('等${_store.communitys.length}个小区'),
                ),
                SizedBox(width: 5.pt),
                Image(
                  image: AssetList.$right_png_image,
                  width: 6.pt,
                  height: 10.pt,
                ),
              ],
            ),
            Obx(() {
              return Wisdom.row(
                onTap: () async => {
                  if (_store.tabIndex.value == 0) ...[
                    date = await WPickerUtil.date(context,
                        title: WisText('选择日期'),
                        initialDate: DateTime.parse(_store.date.value)),
                    _store.setDate(date),
                  ] else ...[
                    month = await WPickerUtil.month(
                      context,
                      title: WisText('选择日期'),
                      initialDate: DateTime.parse('${_store.month.value}-01'),
                    ),
                    _store.setMonth(month),
                  ],
                },
                children: [
                  if (_store.tabIndex.value == 0) ...[
                    WisText(
                      '${_store.date}',
                      color: colorScheme.placeholder,
                    )
                  ],
                  if (_store.tabIndex.value == 1) ...[
                    WisText(
                      '${_store.month}',
                      color: colorScheme.placeholder,
                    )
                  ],
                  if (_store.tabIndex.value != 2) ...[
                    SizedBox(width: 5.pt),
                    Image(
                      image: AssetList.$right_png_image,
                      width: 6.pt,
                      height: 10.pt,
                    ),
                  ]
                ],
              );
            })
          ],
        ),
        WisTabPage(
          divider: false,
          onChange: (index) => _store.onSetTabIndex(index),
          tabs: [
            WisText('日数据'),
            WisText('月数据'),
            WisText('档案数据'),
          ],
          views: [
            DayPage(key: Key('StatisticDay'),),
            DayPage(key: Key('StatisticMonth'),),
            DocPage(key: Key('StatisticDoc'),),
          ],
          indicator: RoundUnderlineTabIndicator(
            width: 25.pt,
          ),
        ).asExpanded(),
      ],
    );
  }
}
