/*
 * @Author       : WuWei
 * @LastEditors: wuwei
 * @Date         : 2023-03-23 17:11:18
 * @LastEditTime: 2023-12-21 17:24:51
 * @Description  : 收银台
 */

import 'dart:io';

import 'package:flutter/material.dart';
import 'package:bill_package/src/stores/bill_platform_store.dart';
import 'package:wisdom_cli/wisdom_cli.dart';

import '../../models/asset_list.dart';
import '../../models/owe_fee_count.dart';

part 'components/card.dart';
part 'components/bottom.dart';

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

  @override
  Widget build(BuildContext context) {
    final userphone = store.appGlobalStore.currentUserinfo?.phone ?? '';
    final phone = userphone.substring(userphone.length - 4, userphone.length);
    final uname = store.appGlobalStore.currentUserinfo?.name;
    return Scaffold(
      appBar: WAppBar(
        brightness: Brightness.dark,
        title: WisText(
          '收银台',
          size: 19.pt,
          weight: FontWeight.w600,
          color: Colors.white,
        ),
        iconTheme: IconThemeData(
          color: Colors.white,
          size: 19.pt,
        ),
        actions: [
          if (store.assetType != 'owner') ...[
            Wisdom(
              padding: EdgeInsets.only(right: 20.pt),
              onTap: () => store.toUrgeToPay(),
              child: Icon(
                Icons.collections_bookmark_outlined,
                size: 25.pt,
              ),
            ),
          ],
          Wisdom(
            padding: EdgeInsets.only(right: 15.pt),
            onTap: () => store.toRecord(),
            child: Icon(
              Icons.timer_outlined,
              size: 25.pt,
            ),
          ),
        ],
      ),
      body: WisScrollView(
        key: store.scrollViewKey,
        onInit: () => store.getData(),
        onRefresh: () => store.getData(),
        slivers: <Widget>[
          _CardComponent(),
        ],
      ).addWatermark(
        text: '${uname} ${phone}',
        color: Colors.black.withOpacity(0.05),
      ),
      bottomNavigationBar: _BottomComponent().addWatermark(
        text: '${uname} ${phone}',
        color: Colors.black.withOpacity(0.05),
      ),
    );
  }
}
