import {
  MyBetaModalFormProps,
  MyButtons,
  MyColumns,
  MyProTableProps,
} from '@/common';
import { Apis } from '@/gen/Apis';
import {
  HouseBillsTypeEnum,
  HouseChargeStandardsCalculationMethodEnum,
  HouseChargeStandardsCalculationModeEnum,
  HouseChargeStandardsCalculationPeriodEnum,
} from '@/gen/Enums';
import { ProTable } from '@ant-design/pro-components';
import { Space } from 'antd';
import ChargeStandardCreate from './modals/ChargeStandardCreate';
import ChargeStandardHasHouse from './modals/ChargeStandardHasHouse';
import ChargeStandardUpdate from './modals/ChargeStandardUpdate';

export default function ReceiptAccounts(props: MyBetaModalFormProps) {
  return (
    <>
      <ProTable
        {...MyProTableProps.props}
        search={false}
        request={async (params, sort) =>
          MyProTableProps.request(
            {
              ...params,
              asset_projects_id: props?.item?.id,
            },
            sort,
            Apis.HouseCharage.HouseChargeStandards.List,
          )
        }
        toolBarRender={(action) => [
          <ChargeStandardCreate
            key="Select"
            reload={action?.reload}
            item={props?.item}
            title="添加收款账号"
          />,
        ]}
        // options={false}
        columns={[
          {
            title: 'ID',
            dataIndex: 'id',
          },
          {
            title: '收费标准名称',
            dataIndex: 'name',
            search: false,
          },
          MyColumns.EnumTag({
            title: '收费项目',
            dataIndex: 'charge_type',
            valueEnum: HouseBillsTypeEnum,
            search: false,
          }),
          MyColumns.EnumTag({
            title: '计量单位',
            dataIndex: 'calculation_method',
            valueEnum: HouseChargeStandardsCalculationMethodEnum,
            search: false,
          }),
          MyColumns.EnumTag({
            title: '计费模式',
            dataIndex: 'calculation_mode',
            valueEnum: HouseChargeStandardsCalculationModeEnum,
            search: false,
          }),
          {
            title: '单价',
            dataIndex: 'price',
            search: false,
          },
          MyColumns.EnumTag({
            title: '账单计费周期',
            dataIndex: 'calculation_period',
            valueEnum: HouseChargeStandardsCalculationPeriodEnum,
            search: false,
          }),
          {
            title: '账单自动生成日期',
            dataIndex: 'auto_date',
            search: false,
          },
          {
            title: '是否分摊',
            dataIndex: 'is_apportionment',
            search: false,
            render(_, record) {
              return `${record?.is_apportionment ? '是' : '否'} `;
            },
          },

          // MyColumns.UpdatedAt(),
          // MyColumns.CreatedAt(),
          MyColumns.Option({
            render: (_, item: any, index, action) => (
              <Space key={index}>
                <ChargeStandardUpdate
                  item={item}
                  reload={action?.reload}
                  title="编辑"
                />
                <ChargeStandardHasHouse
                  item={{
                    ...item,
                    asset_projects_id: props?.item?.id, // 使用项目ID
                    size: 'small',
                  }}
                  reload={action?.reload}
                  title={'绑定房屋'}
                />
                <MyButtons.Delete
                  onConfirm={() =>
                    Apis.HouseCharage.HouseChargeStandards.Delete({
                      id: item.id,
                    }).then(() => action?.reload())
                  }
                />
              </Space>
            ),
          }),
        ]}
      />
    </>
  );
}
