/*
 * @Author: ChenYaJin
 * @Date: 2021-11-08 18:06:51
 * @LastEditors: ChenYaJin
 * @LastEditTime: 2023-03-30 17:50:55
 * @Description: 服务费用添加页
 */
import 'package:flutter/material.dart';
import 'package:report_package/src/models/cascade_house.dart';
import 'package:report_package/src/models/service_project.dart';
import 'package:wisdom_cli/wisdom_cli.dart';
import 'package:flutter/services.dart';
import '../../view_models/private_fee_model.dart';
import '../../models/service_fee_detail.dart';
import './components/list.dart';

part './components/form.dart';

class AddFeePage extends StatelessWidget {
  const AddFeePage({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider(
      create: (_) => FeeIndexStore(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) {
    FeeIndexStore store;
    store = Provider.of<FeeIndexStore>(context);
    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),
      ),
      body: WisScrollView(
        onInit: () => store.initAddData(),
        onRefresh: () => store.initAddData(),
        slivers: <Widget>[
          _ListComponent(),
          _FormComponent(),
          _BottomTipComponent(),
        ],
      ),
      bottomSheet: BottomAppBar(
        child: Wisdom.row(
          padding: EdgeInsets.symmetric(horizontal: 15.pt),
          color: Colors.white,
          children: [
            SafeArea(
              child: WLoadingButton(
                color: Colors.white,
                height: 44.pt,
                minWidth: 120.pt,
                margin: EdgeInsets.symmetric(vertical: 8.pt),
                shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(25.pt),
                  side: BorderSide(
                    width: 1,
                    color: colorScheme.primary.withOpacity(0.5),
                    style: BorderStyle.solid,
                  ),
                ),
                onPressed: () => store.route2FeeDetail(),
                child: WisText('取消', color: colorScheme.primary),
              ),
            ),
            SafeArea(
              child: WLoadingButton(
                height: 44.pt,
                margin: EdgeInsets.only(top: 8.pt, bottom: 8.pt, left: 10.pt),
                shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(25.pt),
                ),
                onPressed: () => store.toCreateFee(),
                child: Text("确认添加"),
              ),
            ).asExpanded(),
          ],
        ),
      ),
    );
  }
}

class _ListComponent extends StatelessWidget {
  const _ListComponent({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    FeeIndexStore store;
    store = Provider.of<FeeIndexStore>(context);
    ServiceFeeDetailModel? detail = store.serviceFeeDetail;
    final listViewItem = ListViewItem(
      detail: detail,
      showCheck: false,
    );
    return Container(
      margin: EdgeInsets.only(top: 10.pt),
      child: listViewItem,
    ).nestSliverToBoxAdapter();
  }
}

class _BottomTipComponent extends StatelessWidget {
  const _BottomTipComponent({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.symmetric(horizontal: 15.pt),
      child: Text(
        '费用一经添加, 不可直接修改, 请经业主确认后再添加费用。',
        style: TextStyle(
          color: Color(0xFFF94F48),
          fontSize: 13.pt,
        ),
      ),
    ).nestSliverToBoxAdapter();
  }
}
