import { useSysPermissionsDataSource } from '@/hooks/dataSources';
import { ProFormColumnsType } from '@ant-design/pro-components';

/**
 * 获取权限树形选择器的配置
 * @param guardName 权限守卫名称
 * @returns 权限树形选择器配置
 */
export const PermissionTreeSelect = (
  guardName: string,
): ProFormColumnsType<any, 'treeSelect'> => {
  const { data } = useSysPermissionsDataSource({ guard_name: guardName });

  return {
    key: 'parent_id',
    title: '上级菜单',
    valueType: 'treeSelect',
    request: async () => data || [],
    fieldProps: {
      rowKey: 'id',
      allowClear: true,
      autoClearSearchValue: false,
      bordered: true,
      fieldNames: {
        label: 'name',
        value: 'id',
      },
      filterTreeNode: false,
      showSearch: false,
      treeNodeFilterProp: 'title',
      treeDefaultExpandAll: true,
    },
  };
};
