import {
  MyBetaModalFormProps,
  MyButtons,
  MyColumns,
  MyProTableProps,
} from '@/common';
import { Apis } from '@/gen/Apis';
import { ProTable } from '@ant-design/pro-components';
import { Space } from 'antd';
import AccountsGet from '../../accounts/modals/AccountsGet';

export default function ReceiptAccounts(props: MyBetaModalFormProps) {
  return (
    <>
      <ProTable
        {...MyProTableProps.props}
        search={false}
        request={async (params, sort) =>
          MyProTableProps.request(
            {
              ...params,
              companies_id: props?.item?.companies_id,
              projects_id: props?.item?.id,
            },
            sort,
            Apis.Company.CompanyProjectReceiptAccounts.List,
          )
        }
        toolBarRender={(action) => [
          <AccountsGet
            key="Select"
            reload={action?.reload}
            item={props?.item}
            title="配置"
          />,
        ]}
        // options={false}
        columns={[
          {
            title: 'ID',
            dataIndex: 'id',
            // width: 360,
          },
          {
            title: '收款账户',
            dataIndex: ['receipt_account', 'company_name'],
            // width: 360,
          },
          {
            title: '开户行',
            dataIndex: ['receipt_account', 'company_bank'],
            search: false,
            // width: 200,
          },
          {
            title: '收款账号',
            dataIndex: ['receipt_account', 'company_account'],
            search: false,
            // width: 200,
          },
          {
            title: '通联商户号',
            dataIndex: ['receipt_account', 'companymerchant_id_account'],
            search: false,
            // width: 200,
          },
          // {
          //   title: '是否默认',
          //   dataIndex: 'is_default',
          //   search: false,
          //   render(_, record) {
          //     return `${record?.is_default ? '是' : '否'} `;
          //   },
          // },
          // MyColumns.UpdatedAt(),
          // MyColumns.CreatedAt(),
          MyColumns.Option({
            render: (_, item: any, index, action) => (
              <Space key={index}>
                <MyButtons.Delete
                  onConfirm={() =>
                    Apis.Company.CompanyProjectReceiptAccounts.Delete({
                      id: item.id,
                    }).then(() => action?.reload())
                  }
                />
              </Space>
            ),
          }),
        ]}
      />
    </>
  );
}
