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

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) => [
          <AssetAccountsSelect
            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: '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>
            ),
          }),
        ]}
      />
    </>
  );
}
