/*
 * @Author: XianKaiQun
 * @Date: 2020-07-08 15:07:26
 * @LastEditors  : WuWei
 * @LastEditTime : 2023-04-04 11:31:26
 * @Description: 
 */

import 'package:flutter/material.dart';
import 'package:receipt_package/src/view_models/index_store.dart';
import 'package:wisdom_cli/wisdom_cli.dart';

part 'components/house_list.dart';
part 'components/car_list.dart';
part 'components/park_list.dart';

class ReceiptIndexPage extends StatelessWidget {
  const ReceiptIndexPage({Key? key, this.entry}) : super(key: key);
  final String? entry;

  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider(
      create: (_) => IndexStore(context),
      child: _PageView(entry: entry),
      lazy: false,
    );
  }
}

class _PageView extends StatefulWidget {
  _PageView({Key? key, this.entry}) : super(key: key);
  final String? entry;
  @override
  _PageViewState createState() => _PageViewState();
}

class _PageViewState extends State<_PageView> {
  @override
  Widget build(BuildContext context) {
    final colorScheme = WTheme.of(context).colorScheme;
    final store = Provider.of<IndexStore>(context, listen: true);
    return Scaffold(
      appBar: WAppBar(
        brightness: Brightness.light,
        iconTheme: IconThemeData(
          color: colorScheme.mainTitle,
          size: 19.pt,
        ),
        backgroundColor: Colors.white,
        title: WisText('${store.args['appBarTitle']}',
            size: 19.pt, weight: FontWeight.w600, color: colorScheme.mainTitle),
      ),
      body: Column(
        children: <Widget>[
          if (widget.entry != 'car') ...[
            WisTabPage(
              divider: false,
              onChange: (index) {
                store.setIndex(index);
                setState(() {});
                FocusScope.of(context).requestFocus(FocusNode());
              },
              tabs: [
                Text('房屋列表'),
                Text('车辆列表'),
                Text('车位列表'),
              ],
              views: [
                _HouseListComponent(),
                _CarListComponent(),
                _ParkListComponent(),
              ],
            ).asExpanded(),
          ] else ...[
            WisTabPage(
              onChange: (index) {
                store.setIndex(index);
                setState(() {});
                FocusScope.of(context).requestFocus(FocusNode());
              },
              tabs: [
                Text('车辆列表'),
                Text('车位列表'),
              ],
              views: [
                _CarListComponent(),
                _ParkListComponent(),
              ],
            ).asExpanded(),
          ]
        ],
      ),
    );
  }
}
