/*
 * @Author       : WuWei
 * @LastEditors: ChenYaJin
 * @Date         : 2023-08-07 11:01:15
 * @LastEditTime: 2023-08-15 10:35:02
 * @Description  : Do not edit
 */
import 'package:flutter/material.dart';
import 'package:wisdom_cli/wisdom_cli.dart';

import '../../../view_models/statistic_store.dart';

class StatisticFilterPage extends StatelessWidget {
  const StatisticFilterPage({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return MultiProvider(
      providers: [
        ChangeNotifierProvider(create: (_) => StatisticStore(context)),
      ],
      child: _PageView(),
    );
  }
}

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

  @override
  _PageViewState createState() => _PageViewState();
}

class _PageViewState extends State<_PageView> {
  @override
  Widget build(BuildContext context) {
    final style = WTheme.of(context);
    final colorScheme = style.colorScheme;
    final store = Provider.of<StatisticStore>(context, listen: true);

    setState(() {
      store.onInit();
    });

    return Scaffold(
      backgroundColor: Color(0xFFF8F8F8),
      appBar: WAppBar(
        title: WisText(
          '筛选',
          color: colorScheme.mainTitle,
          weight: FontWeight.w600,
          size: 18.pt,
        ),
        brightness: Brightness.light,
        backgroundColor: Colors.white,
        // leading: IconButton(
        //   onPressed: () {
        //     store.back();
        //   },
        //   icon: Icon(
        //     Icons.close,
        //     color: colorScheme.mainTitle,
        //     size: 25.pt,
        //   ),
        // ),
      ),
      body: WisScrollView(
        slivers: [
          SliverToBoxAdapter(
            child: Wisdom.column(
              color: Colors.white,
              crossAxisAlignment: CrossAxisAlignment.stretch,
              padding: EdgeInsets.only(
                top: 5.pt,
                left: 15.pt,
                right: 15.pt,
                bottom: 15.pt,
              ),
              children: [
                WFDatePicker(
                  initialDateTime: store.createdAtStart ?? null,
                  lastDate: store.createdAtEnd,
                  onChanged: (v) => store.onPickBillStartDate(v),
                  title: Text.rich(
                    TextSpan(
                      children: [
                        WidgetSpan(
                          child: Wisdom(
                            margin: EdgeInsets.only(right: 10.pt),
                            child: Image.asset(
                              'lib/assets/rl.png',
                              width: 17.pt,
                              height: 14.pt,
                              package: 'pay_package',
                            ),
                          ),
                        ),
                        TextSpan(
                          text: '起始时间',
                          style: TextStyle(
                            color: colorScheme.mainTitle,
                            fontSize: 15.pt,
                            fontWeight: FontWeight.w300,
                          ),
                        ),
                      ],
                    ),
                  ),
                  hintText: '选择起始时间',
                ),
                SizedBox(height: 10.pt),
                WFDatePicker(
                  initialDateTime: store.createdAtEnd ?? null,
                  firstDate: store.createdAtStart,
                  onChanged: (v) => store.onPickBillEndDate(v),
                  title: Text.rich(
                    TextSpan(
                      children: [
                        WidgetSpan(
                          child: Wisdom(
                            margin: EdgeInsets.only(right: 10.pt),
                            child: Image.asset(
                              'lib/assets/rl.png',
                              width: 17.pt,
                              height: 14.pt,
                              package: 'pay_package',
                            ),
                          ),
                        ),
                        TextSpan(
                          text: '结束时间',
                          style: TextStyle(
                            color: colorScheme.mainTitle,
                            fontSize: 15.pt,
                            fontWeight: FontWeight.w300,
                          ),
                        ),
                      ],
                    ),
                  ),
                  hintText: '选择结束时间',
                ),
              ],
            ),
          ),
        ],
      ),
      bottomNavigationBar: Wisdom.row(
        padding: EdgeInsets.symmetric(horizontal: 15.pt),
        color: Colors.white,
        children: [
          SafeArea(
            child: WLoadingButton(
              color: Colors.white,
              height: 44.pt,
              minWidth: 120.pt,
              margin: EdgeInsets.symmetric(vertical: 8.pt),
              shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(25.pt),
                side: BorderSide(
                  width: 1,
                  color: colorScheme.primary.withOpacity(0.5),
                  style: BorderStyle.solid,
                ),
              ),
              onPressed: () => store.onResetInner(),
              child: WisText('重置', color: colorScheme.primary),
            ),
          ),
          SafeArea(
            child: WLoadingButton(
              height: 44.pt,
              margin: EdgeInsets.only(top: 8.pt, bottom: 8.pt, left: 10.pt),
              shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(25.pt),
              ),
              onPressed: () => store.submit(),
              child: Text("确认"),
            ),
          ).asExpanded(),
        ],
      ),
    );
  }
}
