/*
 * @Author: XianKaiQun
 * @Date: 2020-08-06 10:36:38
 * @LastEditors: WuXiangNan
 * @LastEditTime: 2021-07-06 10:14:55
 * @Description: 
 */
import 'package:flutter/material.dart';
import 'package:qrcode_package/src/components/form_item.dart';
import 'package:qrcode_package/src/models/name_id.dart';
import 'package:qrcode_package/src/models/place.dart';
import 'package:qrcode_package/src/view_models/private_register_form_store.dart';
import 'package:wisdom_cli/wisdom_cli.dart';
import 'package:intl/intl.dart';

part 'components/hint.dart';
part 'components/form.dart';

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

    return Scaffold(
      backgroundColor: Colors.white,
      appBar: WAppBar(
        brightness: Brightness.light,
        iconTheme: IconThemeData(
          color: colorScheme.mainTitle,
          size: 19.pt,
        ),
        backgroundColor: Colors.white,
        title: WisText(store.type == 'implement' ? '设备登记' : '二维码登记',
            size: 19.pt, weight: FontWeight.w600, color: colorScheme.mainTitle),
      ),
      body: WisScrollView(
        onInit: () => store.init(),
        slivers: <Widget>[
          _HintComponent(),
          _FormComponent(),
        ],
      ),
      bottomNavigationBar: SafeArea(
        child: WButton(
          onPressed: () => store.submit(),
          height: 44.pt,
          child: Text('完成登记'),
        ),
      ),
    );
  }
}
