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

export default function Index({ title = '机构管理' }) {
  const navigate = useNavigate();
  return (
    <MyPageContainer title={title}>
      <ProTable
        {...MyProTableProps.props}
        request={async (params, sort) =>
          MyProTableProps.request(params, sort, Apis.Company.Companies.List)
        }
        toolBarRender={(action) => [
          <Create key="Create" reload={action?.reload} title={title} />,
        ]}
        columns={[
          MyColumns.ID(),
          MyColumns.EnumTag({
            title: '类型',
            dataIndex: 'merchant_type',
            valueEnum: CompaniesMerchantTypeEnum,
          }),
          {
            title: '机构名称',
            dataIndex: 'name',
          },
          {
            title: '组织简称',
            dataIndex: 'short_name',
            search: false,
          },

          {
            title: '营业执照号',
            dataIndex: 'business_license_number',
            search: false,
          },
          MyColumns.UpdatedAt(),
          // MyColumns.CreatedAt(),
          MyColumns.Option({
            render: (_, item: any, index, action) => (
              <Space key={index}>
                {/* <Update item={item} reload={action?.reload} title={title} /> */}
                <MyButtons.View
                  title="详情"
                  onClick={() => {
                    navigate(`/company/companies/${item.id}`);
                  }}
                />
                <MyButtons.Delete
                  onConfirm={() =>
                    Apis.Common.Admins.Delete({ id: item.id }).then(() =>
                      action?.reload(),
                    )
                  }
                />
              </Space>
            ),
          }),
        ]}
      />
    </MyPageContainer>
  );
}
