import {
  MyBetaModalFormProps,
  MyButtons,
  MyColumns,
  MyProTableProps,
} from '@/common';
import { Apis } from '@/gen/Apis';
import { CompanyAppsAppTypeEnum, CompanyAppsModuleEnum } from '@/gen/Enums';
import { ProTable } from '@ant-design/pro-components';
import { Space } from 'antd';
import AppCreate from '../../apps/modals/AppCreate';
import AppUpdate from '../../apps/modals/AppUpdate';

export default function CompanyApps(props: MyBetaModalFormProps) {
  return (
    <>
      <ProTable
        {...MyProTableProps.props}
        bordered
        request={async (params, sort) =>
          MyProTableProps.request(
            { ...params, companies_id: props?.item?.id },
            sort,
            Apis.Company.CompanyApps.List,
          )
        }
        toolBarRender={(action) => [
          <AppCreate
            key="Create"
            reload={action?.reload}
            item={props?.item}
            title="应用配置"
          />,
        ]}
        search={false}
        // options={false}
        columns={[
          MyColumns.ID(),
          {
            title: '机构',
            dataIndex: ['company', 'name'],
          },
          MyColumns.EnumTag({
            title: '应用类型',
            dataIndex: 'app_type',
            valueEnum: CompanyAppsAppTypeEnum,
          }),
          MyColumns.EnumTag({
            title: '模块',
            dataIndex: 'module',
            valueEnum: CompanyAppsModuleEnum,
            search: false,
          }),
          {
            title: '应用ID',
            dataIndex: 'app_id',
            search: false,
            ellipsis: true,
          },

          MyColumns.UpdatedAt(),
          // MyColumns.CreatedAt(),
          MyColumns.Option({
            render: (_, item: any, index, action) => (
              <Space key={index}>
                <AppUpdate
                  item={item}
                  reload={action?.reload}
                  title="应用配置"
                />
                <MyButtons.Delete
                  onConfirm={() =>
                    Apis.Company.CompanyApps.Delete({
                      id: item.id,
                    }).then(() => action?.reload())
                  }
                />
              </Space>
            ),
          }),
        ]}
      />
    </>
  );
}
