import {
  MyButtons,
  MyColumns,
  MyPageContainer,
  MyProTableProps,
  MyTableActions,
  MyToolBarActions,
} from '@/common';
import { Selects } from '@/components/Select';
import { Apis } from '@/gen/Apis';
import { CompanyReceiptAccountsPayChannelEnum } from '@/gen/Enums';
import { ProTable } from '@ant-design/pro-components';
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}
        headerTitle="项目可用账号（关联收费标准）"
        request={async (params, sort) =>
          MyProTableProps.request(
            params,
            sort,
            Apis.Company.CompanyProjectReceiptAccounts.List,
          )
        }
        toolBarRender={(action) => [
          <MyToolBarActions
            key="toolbar"
            actions={{
              select: (
                <AccountsGet
                  key="Select"
                  reload={action?.reload}
                  title={title}
                />
              ),
            }}
          />,
        ]}
        columns={[
          MyColumns.ID({ search: false }),
          Selects?.AssetProjects({
            title: '选择项目',
            key: 'asset_projects_id',
            hidden: true,
          }),
          {
            title: '项目名称',
            dataIndex: ['project', 'name'],
            // search: {
            //   transform: (value) => {
            //     return { project_name: value };
            //   },
            // },
            search: false,
          },
          {
            title: '收款账户',
            dataIndex: ['receipt_account', 'company_name'],
            search: false,
          },
          {
            title: '开户行',
            dataIndex: ['receipt_account', 'company_bank'],
            search: false,
          },

          {
            title: '收款账号',
            dataIndex: ['receipt_account', 'company_account'],
            search: false,
          },
          MyColumns.EnumTag({
            title: '收款渠道',
            dataIndex: ['receipt_account', 'pay_channel'],
            valueEnum: CompanyReceiptAccountsPayChannelEnum,
            search: false,
          }),
          {
            title: '商户ID',
            dataIndex: ['receipt_account', 'merchant_id'],
            search: false,
          },
          // MyColumns.UpdatedAt(),
          MyColumns.Option({
            render: (_, item: any, index, action) => (
              <Space key={index}>
                <MyTableActions
                  actions={{
                    delete: (
                      <MyButtons.Delete
                        onConfirm={() =>
                          Apis.Company.CompanyProjectReceiptAccounts.Delete({
                            id: item.id,
                          }).then(() => action?.reload())
                        }
                      />
                    ),
                  }}
                />
              </Space>
            ),
          }),
        ]}
      />
    </MyPageContainer>
  );
}
