/*
 * @Author       : WuWei
 * @LastEditors: wuwei
 * @Date         : 2023-10-24 14:53:57
 * @LastEditTime: 2024-02-01 11:52:40
 * @Description  : Do not edit
 */
part of '../index.dart';

class _MonthFeeCard extends StatelessWidget {
  final OweFeeMonthListModel item;
  final String? chooseMonth;
  final Function() onChoose;
  final OweFeeInfoModel? detail;
  final bool isExpand =false;
  const _MonthFeeCard(
      {Key? key, required this.item, this.chooseMonth, required this.onChoose, required this.detail, required isExpand,})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    final colorScheme = WTheme.of(context).colorScheme;
 

    /// 费用项显示
    _BuildFeeItem(fee, String name, Widget? tip) {
      return Wisdom.column(
        crossAxisAlignment: CrossAxisAlignment.center,
        // padding: EdgeInsets.symmetric(
        //   horizontal: 5.pt,
        // ),
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          WisText(
            name,
            size: 12.pt,
            color: colorScheme.minor,
          ),
          tip ?? Container(),
          SizedBox(height: 5.pt),
          WisText(
            '￥${fee ?? 0}',
            size: 14.pt,
            color: colorScheme.mainTitle,
            bold: true,
          ),
        ],
      ).asFlexible(flex: 1);
    }

    /// 判断是否为整数
    bool isInteger(num value) => value is int || value == value.roundToDouble();
    List monthYear = item.chargeYearMonth!.split('-');

    bool isPre = (int.parse(monthYear[0]) > DateTime.now().year) ||
        (int.parse(monthYear[0]) == DateTime.now().year &&
            int.parse(monthYear[1]) > DateTime.now().month);

    return SliverToBoxAdapter(
      child: WisCard(
        margin: EdgeInsets.fromLTRB(
          15.pt,
          12.pt,
          15.pt,
          0,
        ),
        child: Wisdom(
          child: WisExpansionTile(
            initiallyExpanded: chooseMonth == item.chargeYearMonth,
            onExpansionChanged: (flag) => {
              if (flag)
                {
                  onChoose(),
                }
            },
            showIcon: false,
            title: Wisdom.row(
              height: 44.pt,
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Wisdom.row(
                  children: [
                    Icon(
                      Icons.calendar_month_outlined,
                      size: 18.pt,
                      color: colorScheme.grey,
                    ),
                    SizedBox(
                      width: 10.pt,
                    ),
                    WisText(
                      '${item.chargeYearMonth}',
                      color: colorScheme.green,
                      size: 15.pt,
                    ),
                    WisText(
                      '${isPre ? '(预缴)' : '(欠费)'}',
                      size: 13.pt,
                      color: isPre ? colorScheme.green : colorScheme.red,
                    ),
                  ],
                ),
                Wisdom.row(
                  children: [
                    WisText(
                      '展开明细',
                      size: 14.pt,
                      weight: FontWeight.w400,
                      color: colorScheme.grey,
                    ),
                    SizedBox(width: 3.pt),
                    Icon(
                      Icons.keyboard_double_arrow_down_sharp,
                      color: colorScheme.grey,
                      size: 16.pt,
                    ),
                  ],
                ),
              ],
            ),
            expandTitle: Wisdom.row(
              height: 44.pt,
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Wisdom.row(
                  children: [
                    Icon(
                      Icons.calendar_month_outlined,
                      size: 18.pt,
                      color: colorScheme.grey,
                    ),
                    SizedBox(
                      width: 10.pt,
                    ),
                    WisText(
                      '${item.chargeYearMonth}',
                      color: colorScheme.green,
                      size: 15.pt,
                    ),
                    WisText(
                      '${isPre ? '(预缴)' : '(欠费)'}',
                      size: 13.pt,
                      color: isPre ? colorScheme.green : colorScheme.red,
                    ),
                  ],
                ),
                Wisdom.row(
                  children: [
                    WisText(
                      '收起明细',
                      size: 14.pt,
                      weight: FontWeight.w400,
                      color: colorScheme.primary,
                    ),
                    SizedBox(width: 3.pt),
                    Icon(
                      Icons.keyboard_double_arrow_up_sharp,
                      color: colorScheme.primary,
                      size: 16.pt,
                    ),
                  ],
                ),
              ],
            ),
            children: [
              Wisdom(
                height: 0.3.pt,
                color: colorScheme.divider2,
                margin: EdgeInsets.only(bottom: 10.pt),
              ),
              Column(
                children: [
                  Row(
                    children: [
                      _BuildFeeItem(
                          isInteger(detail?.receivableFee ?? 0)
                              ? detail?.receivableFee?.round()
                              : detail?.receivableFee,
                          '应缴',
                          null),
                      Wisdom(
                        width: 1.pt,
                        height: 25.pt,
                        color: colorScheme.divider,
                      ),
                      _BuildFeeItem(
                          isInteger(detail?.receivedFee ?? 0)
                              ? detail?.receivedFee?.round()
                              : detail?.receivedFee,
                          '已缴',
                          null),
                      Wisdom(
                        width: 1.pt,
                        height: 25.pt,
                        color: colorScheme.divider,
                      ),
                      _BuildFeeItem(
                          isInteger(detail?.arrearsFee ?? 0)
                              ? detail?.arrearsFee?.round()
                              : detail?.arrearsFee,
                          '欠费',
                          null),
                    ],
                  )
                ],
              ),
              Wisdom(
                padding: EdgeInsets.symmetric(horizontal: 15.pt),
                child: Wisdom(
                  height: 0.3.pt,
                  color: colorScheme.divider2,
                  margin: EdgeInsets.only(top: 10.pt),
                ),
              ),
              _ListComponent(),
              // if (store.detail != null &&
              //     store.detail?.detailInfos?.isNotEmpty == true) ...[
              //   _ListComponent(),
              // ] else ...[
              //   WEmptyWidget(text: WisText('暂无账单明细')),
              // ],
            ],
          ),
        ),
      ),
    );
  }
}
