// ignore_for_file: unnecessary_null_comparison

/*
 * @Author       : WuWei
 * @LastEditors  : WuWei
 * @Date         : 2023-10-25 10:02:50
 * @LastEditTime : 2023-11-10 16:12:03
 * @Description  : Do not edit
 */
import 'package:get/get.dart';
import 'package:flutter/material.dart';
import 'package:wisdom_cli/wisdom_cli.dart';
import 'package:intl/intl.dart' show DateFormat;
import '../../../stores/owe_filter_store.dart';

class OweFeeFilterPage extends StatelessWidget {
  const OweFeeFilterPage({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<OweFilterStore>();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    final OweFilterStore store = Get.isRegistered<OweFilterStore>()
        ? Get.find<OweFilterStore>()
        : Get.put(OweFilterStore());
    final colorScheme = WTheme.of(context).colorScheme;
    return Scaffold(
      backgroundColor: Color(0xFFF8F8F8),
      appBar: WAppBar(
        title: WisText(
          '筛选',
          color: colorScheme.mainTitle,
          weight: FontWeight.w600,
          size: 18.pt,
        ),
        brightness: Brightness.light,
        backgroundColor: Colors.white,
        leading: IconButton(
          onPressed: () {
            store.back();
          },
          icon: Icon(
            Icons.close,
            color: colorScheme.mainTitle,
            size: 25.pt,
          ),
        ),
      ),
      body: WisScrollView(
        key: store.scrollViewKey,
        onInit: () => store.onInitData(),
        slivers: [
          SliverToBoxAdapter(
            child: Wisdom.column(
              color: Colors.white,
              crossAxisAlignment: CrossAxisAlignment.stretch,
              padding: EdgeInsets.only(
                top: 5.pt,
                left: 15.pt,
                right: 15.pt,
                bottom: 15.pt,
              ),
              children: [
                SizedBox(height: 10.pt),
                WFilterButtons(
                  name: '资产范围',
                  child: Obx(() {
                    return Wrap(
                      spacing: 15.pt,
                      runSpacing: 12.pt,
                      alignment: WrapAlignment.start,
                      children: [
                        for (var item in store.assetList) ...[
                          Obx(() {
                            return WButton(
                              onPressed: () => store.chooseAsset(item),
                              color: Color.fromRGBO(246, 247, 252, 1),
                              shape: RoundedRectangleBorder(
                                borderRadius: BorderRadius.circular(4.pt),
                                side: BorderSide(
                                  width: 1,
                                  color: store.assetItem.value.code == item.code
                                      ? colorScheme.primary.withOpacity(0.5)
                                      : colorScheme.background,
                                  style: BorderStyle.solid,
                                ),
                              ),
                              child: WisText(
                                item.name ?? '',
                                size: 13.pt,
                                color: store.assetItem.value.code == item.code
                                    ? colorScheme.primary
                                    : colorScheme.minor,
                              ),
                            );
                          }),
                        ],
                      ],
                    );
                  }),
                ),
                WFilterButtons(
                  name: '账期范围',
                  child: Wisdom.row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Wisdom.row(
                        borderRadius: BorderRadius.circular(4.pt),
                        padding: EdgeInsets.symmetric(
                          vertical: 10.pt,
                          horizontal: 10.pt,
                        ),
                        color: colorScheme.background4,
                        onTap: () => store.chooseStartMonth(),
                        children: [
                          // Icon(Icons.calendar_month_outlined, size: 18.pt),
                          // SizedBox(
                          //   width: 5.pt,
                          // ),
                          WisText('开始账期'),
                          SizedBox(
                            width: 10.pt,
                          ),
                          Obx(() {
                            return WisText(
                              '${store.chargeYearMonthStart.value.year != 1900 ? DateFormat("yyyy-MM").format(store.chargeYearMonthStart.value) : '账期选择'}',
                              color:
                                  store.chargeYearMonthStart.value.year != 1900
                                      ? colorScheme.primary
                                      : colorScheme.placeholder2,
                            );
                          }),
                          Icon(
                            Icons.chevron_right,
                            color: colorScheme.placeholder2,
                          )
                        ],
                      ).asFlexible(flex: 1),
                      SizedBox(
                        width: 10.pt,
                      ),
                      Wisdom.row(
                        borderRadius: BorderRadius.circular(4.pt),
                        padding: EdgeInsets.symmetric(
                          vertical: 10.pt,
                          horizontal: 10.pt,
                        ),
                        color: colorScheme.background4,
                        onTap: () => store.chooseLastMonth(),
                        children: [
                          // Icon(Icons.calendar_month_outlined, size: 18.pt),
                          // SizedBox(
                          //   width: 5.pt,
                          // ),
                          WisText('结束账期'),
                          SizedBox(
                            width: 10.pt,
                          ),
                          Obx(() {
                            return WisText(
                              '${store.chargeYearMonthEnd.value != null ? DateFormat("yyyy-MM").format(store.chargeYearMonthEnd.value) : '账期结束选择'}',
                              color: store.chargeYearMonthEnd.value != null
                                  ? colorScheme.primary
                                  : colorScheme.placeholder2,
                            );
                          }),

                          Icon(
                            Icons.chevron_right,
                            color: colorScheme.placeholder2,
                          )
                        ],
                      ).asFlexible(flex: 1),
                    ],
                  ),
                ),
                WFilterButtons(
                  name: '收费项目',
                  child: Wisdom.row(
                    children: [
                      Wisdom.row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        borderRadius: BorderRadius.circular(4.pt),
                        padding: EdgeInsets.symmetric(
                          vertical: 10.pt,
                          horizontal: 10.pt,
                        ),
                        color: colorScheme.background4,
                        onTap: () => store.chooseFeeType(),
                        children: [
                          Obx(() {
                            return WisText(
                              '${store.feeTypeItem.value.feeTypeId != null ? store.feeTypeItem.value.feeType : '费用类型选择'}',
                              color: store.feeTypeItem.value.feeTypeId != ''
                                  ? colorScheme.primary
                                  : colorScheme.placeholder2,
                            );
                          }),
                          Icon(
                            Icons.chevron_right,
                            color: colorScheme.placeholder2,
                          )
                        ],
                      ).asFlexible(flex: 1),
                      SizedBox(
                        width: 10.pt,
                      ),
                      Wisdom.row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        borderRadius: BorderRadius.circular(4.pt),
                        padding: EdgeInsets.symmetric(
                          vertical: 10.pt,
                          horizontal: 10.pt,
                        ),
                        color: colorScheme.background4,
                        onTap: () => store.chooseIdentification(),
                        children: [
                          Obx(() {
                            return WisText(
                              '${store.identificationItem.value.identification != null ? store.identificationItem.value.feeName : '收费项目选择'}',
                              color: store.identificationItem.value
                                          .identification !=
                                      ''
                                  ? colorScheme.primary
                                  : colorScheme.placeholder2,
                            );
                          }),
                          Icon(
                            Icons.chevron_right,
                            color: colorScheme.placeholder2,
                          )
                        ],
                      ).asFlexible(flex: 1),
                    ],
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
      bottomNavigationBar: 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.onResetInner(),
              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.submit(),
              child: Text("确认"),
            ),
          ).asExpanded(),
        ],
      ),
    );
  }
}
