import { MyBetaModalFormProps, renderTextHelper } from '@/common';
import { MyModal } from '@/components/MyModal';
import { Apis } from '@/gen/Apis';
import {
  HouseChargeStandardsApportionmentMethodEnum,
  HouseChargeStandardsCalculationMethodEnum,
  HouseChargeStandardsCalculationModeEnum,
  HouseChargeStandardsCalculationPeriodEnum,
  HouseChargeStandardsPriceAlgorithmEnum,
} from '@/gen/Enums';
import { ProDescriptions } from '@ant-design/pro-components';
import { Space } from 'antd';
import { useState } from 'react';

export default function Index(props: MyBetaModalFormProps) {
  const [data, setData] = useState<any>({});
  return (
    <MyModal
      title={props?.item?.name || '查看'}
      type="link"
      width="1000px"
      onOpen={() => {
        Apis.HouseCharge.HouseChargeStandards.Show({
          id: props.item?.id ?? 0,
        }).then((res) => {
          setData(res?.data || {});
          console.log(res);
        });
      }}
      node={
        <>
          <ProDescriptions bordered column={2}>
            <ProDescriptions.Item label="收费标准名称">
              {data?.name}
            </ProDescriptions.Item>
            <ProDescriptions.Item label="收款帐号">
              {data?.company_receipt_account?.company_bank}：
              {data?.company_receipt_account?.company_account}
            </ProDescriptions.Item>
            {data?.apportionment_method ? (
              <ProDescriptions.Item label="分摊方式">
                <renderTextHelper.Tag
                  Enums={HouseChargeStandardsApportionmentMethodEnum}
                  value={data?.apportionment_method}
                />
              </ProDescriptions.Item>
            ) : (
              ''
            )}

            <ProDescriptions.Item label="计量单位">
              <renderTextHelper.Tag
                Enums={HouseChargeStandardsCalculationMethodEnum}
                value={data?.calculation_method}
              />
            </ProDescriptions.Item>
            {data?.calculation_method !== 'PerUnit' ? (
              <>
                <ProDescriptions.Item label="计费模式">
                  <renderTextHelper.Tag
                    Enums={HouseChargeStandardsCalculationModeEnum}
                    value={data?.calculation_mode}
                  />
                </ProDescriptions.Item>
                <ProDescriptions.Item label="计费算法">
                  <renderTextHelper.Tag
                    Enums={HouseChargeStandardsPriceAlgorithmEnum}
                    value={data?.price_algorithm}
                  />
                </ProDescriptions.Item>

                <ProDescriptions.Item label="阶梯标准">
                  <Space direction="vertical">
                    {data?.tiered_rates?.map((item: any, index: number) => {
                      return (
                        <div key={`item_${index}`}>
                          阶梯范围：{item?.min_quantity}-{item?.max_quantity}{' '}
                          阶梯单价：¥{item?.price}元
                        </div>
                      );
                    })}
                  </Space>
                </ProDescriptions.Item>
              </>
            ) : (
              ''
            )}

            <ProDescriptions.Item label="固定单价">
              ¥{data?.price}元
            </ProDescriptions.Item>
            <ProDescriptions.Item label="计费周期">
              <renderTextHelper.Tag
                Enums={HouseChargeStandardsCalculationPeriodEnum}
                value={data?.calculation_period}
              />
            </ProDescriptions.Item>
            <ProDescriptions.Item label="生成日期">
              {data?.auto_date}
            </ProDescriptions.Item>
            {data?.has_late_fee ? (
              <ProDescriptions.Item label="滞纳金计算">
                <Space direction="vertical">
                  <div>有滞纳金：{data?.has_late_fee ? '是' : '否'}</div>
                  <div>起算天数：生成账单后{data?.late_fee_start_days}天</div>
                  <div>收取费率：每日{data?.late_fee_rate}%</div>
                  <div>封顶天数：最多{data?.late_fee_cap_days}天</div>
                </Space>
              </ProDescriptions.Item>
            ) : (
              ''
            )}

            <ProDescriptions.Item label="备注" span={2}>
              {data?.remark}
            </ProDescriptions.Item>
          </ProDescriptions>
        </>
      }
    />
  );
}
