import { MyBetaModalFormProps, renderTextHelper } from '@/common';
import { MyModal } from '@/components/MyModal';
import { Apis } from '@/gen/Apis';
import { HouseBillsTypeEnum } from '@/gen/Enums';
import { ProCard, ProDescriptions } from '@ant-design/pro-components';
import { Space, Spin } from 'antd';
import { useState } from 'react';

export default function BillInfo(props: MyBetaModalFormProps) {
  const [loading, setLoading] = useState(true);
  const [data, setData] = useState<any>({});

  return (
    <MyModal
      title={props.title || '查看账单'}
      type={props.item?.type || 'primary'}
      width="600px"
      onOpen={() => {
        if (props?.item?.id) {
          setLoading(true);
          Apis.Bill.HouseBills.Show({ id: props.item.id })
            .then((res) => {
              setData(res?.data || {});
            })
            .finally(() => {
              setLoading(false);
            });
        }
      }}
      node={
        <Space direction="vertical" style={{ width: '100%' }}>
          <ProCard extra={props.extra}>
            <Spin spinning={loading}>
              <ProDescriptions column={2}>
                {/* 项目相关信息 */}
                <ProDescriptions.Item label="房屋名称" span={2}>
                  {data?.asset_house?.full_name || ''}
                </ProDescriptions.Item>

                {/* 账单基本信息 */}
                <ProDescriptions.Item label="账单月份">
                  {data?.year || ''}-{data?.month || ''}
                </ProDescriptions.Item>
                <ProDescriptions.Item label="费用类型">
                  <renderTextHelper.Tag
                    Enums={HouseBillsTypeEnum}
                    value={data?.type}
                    key="type"
                  />
                </ProDescriptions.Item>
                <ProDescriptions.Item label="账单金额">
                  {data?.amount || 0} 元
                </ProDescriptions.Item>
                <ProDescriptions.Item label="优惠金额">
                  {data?.discount_amount || 0} 元
                </ProDescriptions.Item>
                <ProDescriptions.Item label="滞纳金">
                  {data?.late_fee || 0} 元
                </ProDescriptions.Item>
                <ProDescriptions.Item label="应收金额">
                  {data?.total_payable_amount || 0} 元
                </ProDescriptions.Item>
                <ProDescriptions.Item label="已收金额" span={2}>
                  {data?.total_paid_amount || 0} 元
                </ProDescriptions.Item>
                <ProDescriptions.Item label="计费期限" span={2}>
                  {data?.start_date || ''} - {data?.end_date || ''}
                </ProDescriptions.Item>
                {/* 其他信息 */}
                <ProDescriptions.Item label="收款账户" span={2}>
                  {data?.receipt_account?.company_name || ''} |{' '}
                  {data?.receipt_account?.company_bank || ''} |{' '}
                  {data?.receipt_account?.company_account || ''}
                </ProDescriptions.Item>
                <ProDescriptions.Item label="备注" span={3}>
                  {data?.remark || ''}
                </ProDescriptions.Item>
              </ProDescriptions>
            </Spin>
          </ProCard>
        </Space>
      }
    />
  );
}
