/*
 * @Author: WuWei
 * @Date: 2020-08-07 11:19:29
 * @LastEditors: ChenYaJin
 * @LastEditTime: 2023-10-25 20:23:46
 * @Description:
 */
import 'package:get/get.dart';
import 'package:flutter/material.dart';
import 'package:wisdom_cli/wisdom_cli.dart';
import '../../view_models/private_index_store.dart';
import '../../view_models/filter_index_store.dart';
import '../../components/list-item.dart';
part 'components/bill.dart';
part 'components/pre.dart';
part 'components/deposite.dart';

class IndexPage extends StatelessWidget {
  const IndexPage({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider(
      create: (providerContext) => PrivateIndexStore(context, providerContext),
      child: _PageView(),
      lazy: false,
    );
  }
}

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 store = Provider.of<PrivateIndexStore>(context, listen: true);
    final colorScheme = WTheme.of(context).colorScheme;
    return Scaffold(
      appBar: WAppBar(
        brightness: Brightness.light,
        title: WisText("${store.routingArgs['appBarTitle'] ?? '缴费记录'}",
            size: 19.pt, weight: FontWeight.w600, color: colorScheme.mainTitle),
        iconTheme: IconThemeData(
          color: colorScheme.mainTitle,
          size: 19.pt,
        ),
        backgroundColor: Colors.white,
        actions: <Widget>[
          Wisdom(
            padding: EdgeInsets.only(right: 15.pt, left: 15.pt),
            onTap: () => store.toSummaryPage(),
            child: Image.asset(
              'lib/assets/datas.png',
              height: 18.pt,
              width: 18.pt,
              package: 'pay_package',
              color: colorScheme.mainTitle,
            ),
          ),
          Wisdom(
            padding: EdgeInsets.only(right: 15.pt, left: 15.pt),
            onTap: () => store.onSetFilterShow(),
            child: Image.asset(
              'lib/assets/shx.png',
              height: 18.pt,
              width: 18.pt,
              package: 'pay_package',
              color: colorScheme.mainTitle,
            ),
          )
        ],
      ),
      body: _BuildBody(),
    );
  }
}

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

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

class __BuildBodyState extends State<_BuildBody>
    with SingleTickerProviderStateMixin {
  // PrivateIndexStore get store => Provider.of(context, listen: false);

  final FilterIndexStore filterStore = Get.isRegistered<FilterIndexStore>()
      ? Get.find<FilterIndexStore>()
      : Get.put(FilterIndexStore());

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    Get.delete<FilterIndexStore>();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    final store = Provider.of<PrivateIndexStore>(context, listen: true);

    return Stack(
      fit: StackFit.expand,
      children: [
        WisTabPage(
          divider: false,
          initialIndex: store.argtab ?? store.tabNum,
          onChange: (index) {
            store.setTab(index);
            FocusScope.of(context).requestFocus(FocusNode());
          },
          tabs: [
            Text('账单收支'),
            Text('预存收支'),
            Text('押金收支'),
          ],
          views: [
            _BuildBillList(),
            _BuildPreList(),
            _BuildDepositeList(),
          ],
        ),
      ],
    );
  }
}
