/*
 * @Author: XianKaiQun
 * @LastEditors  : WuWei
 * @Date: 2020-10-23 16:51:30
 * @LastEditTime : 2023-03-29 10:32:15
 */

import 'package:flutter/material.dart';
import 'package:flutter_mobx/flutter_mobx.dart';
import 'package:oa_package/src/view_models/private_process_store.dart';
import 'package:wisdom_cli/wisdom_cli.dart';
part 'components/record_list.dart';
part 'components/form.dart';
part 'components/tabbar.dart';

class ProcessPageView extends StatelessWidget {
  const ProcessPageView({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    final store = Provider.of<PrivateProcessStore>(context, listen: false);
    final style = WTheme.of(context);
    final colorScheme = style.colorScheme;
    return Scaffold(
      appBar: WAppBar(
        brightness: Brightness.light,
        title: Observer(
          builder: (context) {
            return WisText(
              '${store.barTitle}',
              size: 19.pt,
              weight: FontWeight.w600,
              color: colorScheme.mainTitle,
            );
          },
        ),
        iconTheme: IconThemeData(
          color: colorScheme.mainTitle,
          size: 19.pt,
        ),
        backgroundColor: Colors.white,
      ),
      body: Observer(builder: (_) {
        return Column(
          children: [
            _TabbarComponent(),
            if (store.isForm) _FormComponent() else _RecordListComponent(),
          ],
        );
      }),
      bottomSheet: Observer(builder: (_) {
        return store.isForm ? _BottomComponent() : BottomAppBar();
      }),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    final _store = Provider.of<PrivateProcessStore>(context, listen: false);
    final colorScheme = WTheme.of(context).colorScheme;
    return BottomAppBar(
      child: Wisdom.row(
        height: 60.pt,
        children: <Widget>[
          Expanded(
            child: Wisdom(
              borderRadius: BorderRadius.circular(20.pt),
              margin: EdgeInsets.symmetric(horizontal: 15.pt, vertical: 8.pt),
              onTap: () => _store.onSubmitForm(),
              color: colorScheme.primary,
              child: Wisdom(
                alignment: Alignment.center,
                child: WisText.white('提交', size: 17.pt),
              ),
            ),
          ),
        ],
      ),
    );
  }
}
