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 AccountsGet from './modals/AccountsGet';

export default function Index({ title = '项目账户' }) {
  const navigate = useNavigate();

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

  return (
    <MyPageContainer
      title={title}
      enableTabs={true}
      tabKey="company-apps"
      tabLabel={title}
    >
      <ProTable
        {...MyProTableProps.props}
        request={async (params, sort) =>
          MyProTableProps.request(
            params,
            sort,
            Apis.Company.CompanyProjectReceiptAccounts.List,
          )
        }
        toolBarRender={(action) => [
          <AccountsGet key="Select" reload={action?.reload} title={title} />,
        ]}
        columns={[
          MyColumns.ID(),

          {
            title: '机构名称',
            dataIndex: ['company', 'name'],
          },
          {
            title: '项目名称',
            dataIndex: ['project', 'name'],
          },
          {
            title: '收款名称',
            dataIndex: ['receipt_account', 'company_name'],
          },
          {
            title: '开户行',
            dataIndex: ['receipt_account', 'company_bank'],
            search: false,
          },
          {
            title: '收款账号',
            dataIndex: ['receipt_account', 'company_account'],
            search: false,
          },
          // {
          //   title: '是否默认',
          //   dataIndex: 'is_default',
          //   search: false,
          //   render(_, record) {
          //     return `${record?.is_default ? '是' : '否'} `;
          //   },
          // },
          MyColumns.UpdatedAt(),
          MyColumns.Option({
            render: (_, item: any, index, action) => (
              <Space key={index}>
                <MyButtons.Delete
                  onConfirm={() =>
                    Apis.Company.CompanyProjectReceiptAccounts.Delete({
                      id: item.id,
                    }).then(() => action?.reload())
                  }
                />
              </Space>
            ),
          }),
        ]}
      />
    </MyPageContainer>
  );
}
