import {
  MyColumns,
  MyPageContainer,
  MyProTableProps,
  useCurrentPermissions,
} from '@/common';
import { Apis } from '@/gen/Apis';
import { ProTable } from '@ant-design/pro-components';
import HasProjects from './modals/HasProjects';

export default function Index({ title = '组织项目关联' }) {
  const getCurrentPermissions = useCurrentPermissions();
  let toolBarRender = (action: any) => {
    return getCurrentPermissions({
      has: (
        <HasProjects
          key="HasProjects"
          reload={action?.reload}
          title="配置项目"
        />
      ),
    });
  };

  return (
    <MyPageContainer
      title={title}
      enableTabs={true}
      tabKey="company-organization_has_projects"
      tabLabel={title}
    >
      <ProTable
        {...MyProTableProps.props}
        request={async (params, sort) =>
          MyProTableProps.request(
            params,
            sort,
            Apis.Company.OrganizationHasProjects.List,
          )
        }
        toolBarRender={(action) => [toolBarRender(action)]}
        headerTitle="组织项目关联"
        tooltip="组织项目关联关系会影响所在组织员工权限，需在【配置】中进行操作"
        // options={false}
        // search={false}
        columns={[
          {
            title: 'ID',
            dataIndex: 'id',
            search: false,
          },
          {
            title: '组织名称',
            dataIndex: ['organization', 'name'],
            search: {
              transform: (value) => {
                return { organization_name: value };
              },
            },
          },
          {
            title: '项目名称',
            dataIndex: ['asset_project', 'name'],
            search: {
              transform: (value) => {
                return { project_name: value };
              },
            },
          },
          MyColumns.UpdatedAt(),
        ]}
      />
    </MyPageContainer>
  );
}
