/*
 * @Author       : WuWei
 * @LastEditors  : WuWei
 * @Date         : 2021-04-27 16:26:52
 * @LastEditTime : 2023-05-25 15:41:52
 * @FilePath     : /wisdom-huiguanjia-app/task_package/lib/src/pages/schedule/index.dart
 * @Description  : 我的日程-入口页
 */
import 'package:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import '../../../src/pages/common/year_picker.dart';
import '../../../src/view_models/schedule_store.dart';
import 'package:wisdom_cli/wisdom_cli.dart';
part 'components/tabmonth.dart';
part 'components/month_info.dart';
part 'index.g.dart';

///路由传递的参数
class SchedulePageArguments {
  final String? id;
  SchedulePageArguments({this.id});

  ///
  ///
  ///
  ///
  ///
  ///
  ///
//***以下为模板代码谨慎修改***
  factory SchedulePageArguments.fromJson(Map<String, dynamic> json) {
    return _$SchedulePageArgumentsFromJson(json);
  }
  factory SchedulePageArguments.fromRouteArguments(BuildContext context) {
    return _$SchedulePageArgumentsFromJson(
        (ModalRoute.of(context)?.settings.arguments ??
            new Map<String, dynamic>()) as Map<String, dynamic>);
  }
  Map<String, dynamic> toJson() => _$SchedulePageArgumentsToJson(this);
}

///
///
///
///
///
//***以下为模板代码谨慎修改***
class SchedulePage extends StatelessWidget {
  const SchedulePage({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return MultiProvider(
      providers: [
        ChangeNotifierProvider(create: (_) => ScheduleStore(context)),
      ],
      child: SchedulePageView(),
    );
  }
}

class SchedulePageView extends StatelessWidget {
  const SchedulePageView({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final store = Provider.of<ScheduleStore>(context, listen: false);
    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),
        actions: [
          Observer(builder: (_) {
            return Wisdom.row(
              onTap: () => showYearPicker(
                context,
                store.onYearPick,
                initialYear: store.params['year'],
              ),
              children: [
                Text('${store.params['year']}'),
                Icon(Icons.chevron_right),
              ],
            );
          })
        ],
      ),
      body: _BuildBody(),
    );
  }
}

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

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

class __BuildBodyState extends State<_BuildBody> {
  ScheduleStore get store => Provider.of(context, listen: false);
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    /// 使用 FutureBuilder 是为了其中widget渲染加载完毕并绑定好key,再进行滚动操作，不然同步操作会报错
    return FutureBuilder(
      future: store.onGetData(),
      builder: (ctx, snapshot) => Column(
        children: [
          _BuildTabMonth(),
          _BuidlMonthInfo(),
        ],
      ),
    );
  }
}
