import {
  MyButtons,
  MyColumns,
  MyPageContainer,
  MyProTableProps,
} from '@/common';
import { Apis } from '@/gen/Apis';
import { HouseBillsTypeEnum } from '@/gen/Enums';
import { ProTable } from '@ant-design/pro-components';
import { Space } from 'antd';
import Create from './modals/Create';
import Update from './modals/Update';

export default function Index({ title = '账单' }) {
  return (
    <MyPageContainer title={title}>
      <ProTable
        {...MyProTableProps.props}
        request={async (params, sort) =>
          MyProTableProps.request(params, sort, Apis.Bill.HouseBills.List)
        }
        toolBarRender={(action) => [
          <Create key="Create" reload={action?.reload} title={title} />,
        ]}
        columns={[
          MyColumns.ID(),
          {
            title: '金额',
            dataIndex: 'amount',
          },
          {
            title: '优惠金额',
            dataIndex: 'discount_amount',
            search: false,
          },
          {
            title: '滞纳金',
            dataIndex: 'late_fee',
            search: false,
          },
          MyColumns.EnumTag({
            title: '类型',
            dataIndex: 'type',
            valueEnum: HouseBillsTypeEnum,
          }),
          {
            title: '计费开始日期',
            dataIndex: 'start_date',
            search: false,
          },
          {
            title: '计费结束日期',
            dataIndex: 'end_date',
            search: false,
          },
          {
            title: '滞纳金起算日期',
            dataIndex: 'late_start_date',
            search: false,
          },
          {
            title: '已收滞纳金天数',
            dataIndex: 'collected_late_fee_days',
            search: false,
          },
          {
            title: '备注',
            dataIndex: 'remark',
            search: false,
          },
          MyColumns.CreatedAt(),
          MyColumns.Option({
            render: (_, item: any, index, action) => (
              <Space key={index}>
                <Update item={item} reload={action?.reload} title={title} />
                <MyButtons.Delete
                  onConfirm={() =>
                    Apis.Common.Admins.Delete({ id: item.id }).then(() =>
                      action?.reload(),
                    )
                  }
                />
              </Space>
            ),
          }),
        ]}
      />
    </MyPageContainer>
  );
}
