import {
  MyBetaModalFormProps,
  MyButtons,
  MyColumns,
  MyProTableProps,
} 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 '../../accounts/modals/AccountsGet';

export default function ReceiptAccounts(props: MyBetaModalFormProps) {
  const navigate = useNavigate();
  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,
          )
        }
        headerTitle={
          <Space>
            集团账号信息
            <MyButtons.View
              title="去查看"
              onClick={() => {
                navigate(`/company/accounts`);
              }}
            />
          </Space>
        }
        // tooltip="可在【目录：财务管理】中配置"
        toolBarRender={(action) => [
          <AccountsGet
            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>
            ),
          }),
        ]}
      />
    </>
  );
}
