import {
  MyButtons,
  MyColumns,
  MyPageContainer,
  MyProTableProps,
  usePageTabs,
} from '@/common';
import { Apis } from '@/gen/Apis';
import { ProTable } from '@ant-design/pro-components';
import { useNavigate } from '@umijs/max';
import { Space } from 'antd';
import ReceiptAccountCreate from './modals/ReceiptAccountCreate';
import ReceiptAccountUpdate from './modals/ReceiptAccountUpdate';

export default function Index({ title = '账号管理' }) {
  const navigate = useNavigate();

  // 注册当前页面为标签页
  usePageTabs({
    tabKey: 'company-receipt_accounts',
    tabLabel: title,
  });

  return (
    <MyPageContainer
      title={title}
      enableTabs={true}
      tabKey="company-receipt_accounts"
      tabLabel={title}
    >
      <ProTable
        {...MyProTableProps.props}
        request={async (params, sort) =>
          MyProTableProps.request(
            params,
            sort,
            Apis.Company.CompanyReceiptAccounts.List,
          )
        }
        // headerTitle="项目可用收款账号，从本页面已添加的收款账号中选择"
        toolBarRender={(action) => [
          <ReceiptAccountCreate
            key="Create"
            reload={action?.reload}
            title={title}
          />,
        ]}
        columns={[
          MyColumns.ID(),
          {
            title: '机构',
            dataIndex: ['company', 'name'],
            search: false,
          },
          {
            title: '收款户名',
            dataIndex: 'company_name',
          },
          {
            title: '开户行',
            dataIndex: 'company_bank',
            search: false,
          },
          {
            title: '收款账号',
            dataIndex: 'company_account',
            // search: false,
          },
          {
            title: '通联商户号',
            dataIndex: 'merchant_id',
            search: false,
          },

          MyColumns.UpdatedAt(),
          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>
            ),
          }),
        ]}
      />
    </MyPageContainer>
  );
}
