/*
 * @Author       : WuWei
 * @LastEditors  : WuWei
 * @Date         : 2023-10-27 10:25:03
 * @LastEditTime : 2023-11-01 20:00:19
 * @Description  : Do not edit
 */
import 'package:get/get.dart';
import 'package:flutter/material.dart';
import 'package:wisdom_cli/wisdom_cli.dart';

import '../../models/deposite_detail.dart';
import '../../stores/deposite_fee_store.dart';

class DepositeFeeIndexPage extends StatelessWidget {
  const DepositeFeeIndexPage({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return _PageView();
  }
}

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

  @override
  State<_PageView> createState() => __PageViewState();
}

class __PageViewState extends State<_PageView> {
  void dispose() {
    Get.delete<DepositeFeeIndexStore>();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    final DepositeFeeIndexStore store =
        Get.isRegistered<DepositeFeeIndexStore>()
            ? Get.find<DepositeFeeIndexStore>()
            : Get.put(DepositeFeeIndexStore());
    final colorScheme = WTheme.of(context).colorScheme;
    return Scaffold(
      appBar: WAppBar(
        title: WisText(
          '押金信息',
          color: colorScheme.mainTitle,
          weight: FontWeight.w600,
          size: 18.pt,
        ),
        brightness: Brightness.light,
        backgroundColor: Colors.white,
      ),
      body: WisScrollView(
        key: store.scrollViewKey,
        onInit: () => store.onInitData(),
        slivers: [
          SliverToBoxAdapter(
            child: Obx(() {
              return Wisdom.column(
                padding:
                    EdgeInsets.symmetric(horizontal: 15.pt, vertical: 15.pt),
                children: [
                  GradientCard(
                    child: Wisdom.row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      padding: EdgeInsets.all(15.pt),
                      children: [
                        Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            WisText(
                              '可用余额',
                              size: 14.pt,
                              bold: true,
                              color: Colors.white,
                            ),
                            SizedBox(height: 15.pt),
                            Obx(() {
                              return WisText(
                                '￥${store.detail.value.balance ?? 0}',
                                size: 23.pt,
                                bold: true,
                                color: Colors.white,
                              );
                            })
                          ],
                        ),
                        Wisdom(
                          onTap: () => store.toRecord(),
                          margin: EdgeInsets.only(
                            top: 10.pt,
                          ),
                          padding: EdgeInsets.symmetric(
                            horizontal: 15.pt,
                            vertical: 8.pt,
                          ),
                          border: Border.all(
                            color: Colors.white,
                          ),
                          borderRadius: BorderRadius.circular(20.pt),
                          child: WisText(
                            '收支记录',
                            color: Colors.white,
                          ),
                        ),
                      ],
                    ),
                    gradient: LinearGradient(
                      colors: [Color(0xFF4D80FF), Color(0xFF0F67F8)],
                      begin: Alignment.centerLeft,
                      end: Alignment.centerRight,
                    ),
                  ),
                  if (store.detail.value.list?.isNotEmpty == true) ...[
                    for (ListOfDepositeDetailModel item
                        in store.detail.value.list ?? []) ...[
                      WisCard(
                        margin: EdgeInsets.fromLTRB(
                          0,
                          15.pt,
                          0,
                          0,
                        ),
                        padding: EdgeInsets.all(15.pt),
                        child: Wisdom.column(
                          children: [
                            Wisdom.row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                WisText(
                                  '${item.assetName}',
                                  size: 15.pt,
                                  bold: true,
                                  color: colorScheme.minor,
                                ),
                                WisText('￥${item.balance ?? 0}'),
                              ],
                            ),
                            SizedBox(height: 15.pt),
                            if (item.detail?.isNotEmpty == true) ...[
                              WisCard(
                                color: colorScheme.background4,
                                padding: EdgeInsets.all(15.pt),
                                child: Column(
                                  children: [
                                    for (DetailOfListOfDepositeDetailModel data
                                        in item.detail ?? []) ...[
                                      Wisdom.row(
                                        margin: EdgeInsets.only(top: 10.pt),
                                        mainAxisAlignment:
                                            MainAxisAlignment.spaceBetween,
                                        children: [
                                          WisText(
                                            '${data.name}',
                                            size: 15.pt,
                                            color: colorScheme.minor,
                                          ),
                                          WisText(
                                            '￥${data.fee ?? 0}',
                                            size: 15.pt,
                                            color: colorScheme.mainTitle,
                                          ),
                                        ],
                                      ),
                                    ]
                                  ],
                                ),
                              )
                            ]
                          ],
                        ),
                      ),
                    ]
                  ]
                ],
              );
            }),
          ),
        ],
      ),
      bottomNavigationBar: Wisdom.row(
        padding: EdgeInsets.symmetric(horizontal: 15.pt),
        color: Colors.white,
        children: [
          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.toSubmit(),
              child: WisText(
                "押金缴费",
                size: 20.pt,
              ),
            ),
          ).asExpanded(),
        ],
      ),
    );
  }
}
