/*
 * @Author: WuWei
 * @Date: 2020-05-26 15:53:32
 * @LastEditors: ChenYaJin
 * @LastEditTime: 2023-03-31 10:48:22
 * @Description:
 */

import 'package:flutter/material.dart';
import 'package:search_package/src/components/search_input.dart';
import 'package:wisdom_cli/wisdom_cli.dart';
import '../../view_models/search_index_store.dart';
import '../../components/list_empty.dart';

part 'components/house/index.dart';
part 'components/resident/index.dart';
part 'components/car/index.dart';
part 'components/park/index.dart';

class IndexPage extends StatelessWidget {
  const IndexPage({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider(
      create: (_) => SearchIndexStore(context),
      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 colorScheme = WTheme.of(context).colorScheme;
    final store = Provider.of<SearchIndexStore>(context, listen: true);

    return Scaffold(
      appBar: WAppBar(
        iconTheme: IconThemeData(
          color: colorScheme.mainTitle,
          size: 19.pt,
        ),
        backgroundColor: Colors.white,
        brightness: Brightness.light,
        title: WisText('${store.args['appBarTitle'] ?? '档案查询'}',
            size: 19.pt, weight: FontWeight.w600, color: colorScheme.mainTitle),
        // 添加住户按钮
        actions: [
          /// 住户tab才需显示住户添加按钮
          if (store.currentIndex == 0) ...[
            Wisdom(
              onTap: () => store.toAddresident(),
              margin: EdgeInsets.only(right: 15.pt),
              child: Icon(
                Icons.add_circle_outline,
                size: 22,
                color: Colors.black,
              ),
            )
          ]
        ],
      ),
      body: WisTabPage(
        onChange: (index) => store.onSetTabIndex(index),
        divider: false,
        tabs: <Widget>[
          Text('住户'),
          Text('房屋'),
          Text('车辆'),
          Text('车位'),
        ],
        views: <Widget>[
          _TabResidentComponent(),
          _TabHouseComponent(),
          _TabCarComponent(),
          _TabParkComponent(),
        ],
      ),
    );
  }
}
