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

export default function ReceiptAccounts(props: MyBetaModalFormProps) {
  return (
    <ProCard
      title={
        <Alert
          message="提示：【项目收款账号】，从【机构】已添加的【收款账号】中获取！"
          type="info"
          showIcon
          style={{ margin: 0 }}
        />
      }
    >
      <ProTable
        {...MyProTableProps.props}
        search={false}
        request={async (params, sort) =>
          MyProTableProps.request(
            { ...params, companies_id: props?.item?.id },
            sort,
            Apis.Company.CompanyReceiptAccounts.List,
          )
        }
        toolBarRender={(action) => [
          <ReceiptAccountCreate
            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: 'merchant_id',
            search: false,
          },
          MyColumns.UpdatedAt(),
          // MyColumns.CreatedAt(),
          MyColumns.Option({
            render: (_, item: any, index, action) => (
              <Space key={index}>
                <ReceiptAccountUpdate
                  item={item}
                  reload={action?.reload}
                  title="收款账号"
                />
                <MyButtons.Delete
                  onConfirm={() =>
                    Apis.Company.CompanyReceiptAccounts.Delete({
                      id: item.id,
                    }).then(() => action?.reload())
                  }
                />
              </Space>
            ),
          }),
        ]}
      />
    </ProCard>
  );
}
