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

export default function ReceiptAccounts(props: MyBetaModalFormProps) {
  return (
    <>
      <ProTable
        {...MyProTableProps.props}
        search={false}
        request={async (params, sort) =>
          MyProTableProps.request(
            { ...params, companies_id: props?.item?.id },
            sort,
            Apis.Company.CompanyReceiptAccounts.List,
          )
        }
        toolBarRender={(action) => [
          <ReceiptAccountsCreate
            key="Create"
            reload={action?.reload}
            item={props?.item}
            title="收款账号"
          />,
        ]}
        // options={false}
        columns={[
          MyColumns.ID(),

          {
            title: '收款账号名称',
            dataIndex: 'company_name',
            // width: 360,
          },
          {
            title: '开户行',
            dataIndex: 'company_bank',
            search: false,
            // width: 200,
          },
          {
            title: '收款账号',
            dataIndex: 'company_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}>
                <ReceiptAccountsUpdate
                  item={item}
                  reload={action?.reload}
                  title="收款账号"
                />
                <MyButtons.Delete
                  onConfirm={() =>
                    Apis.Company.CompanyReceiptAccounts.Delete({
                      id: item.id,
                    }).then(() => action?.reload())
                  }
                />
              </Space>
            ),
          }),
        ]}
      />
    </>
  );
}
