export const getDisciplineByRole = (roleCodes: string | string[]) => {
  if (!roleCodes) return [];
  // 统一处理为数组
  const codes = Array.isArray(roleCodes) ? roleCodes : roleCodes.split(',');
  try {
    const values = JSON.parse(localStorage.getItem('ROLE_DISCIPLINE') || '[]');
    const list = values.map((item: any) => JSON.parse(item));
    const allDisciplines: any[] = [];
    const allSimulationType: any[] = [];
    // 收集所有角色的学科、仿真类型
    codes.forEach((roleCode) => {
      const roleData = list.find((item: any) => item.role === roleCode.trim());
      if (roleData?.discipline?.length) {
        allDisciplines.push(...roleData.discipline);
      }
      // if (roleData?.simulationType?.length) {
      //   allSimulationType.push(...roleData.simulationType);
      // }
      if (roleData?.simulationType) {
        allSimulationType.push(roleData.simulationType);
      }
    });
    // 去重
    const uniqueDisciplines = Array.from(new Set(allDisciplines));
    const uniqueSimulationType = Array.from(new Set(allSimulationType));
    return { simulationType: uniqueSimulationType, discipline: uniqueDisciplines };
  } catch (error) {
    console.error('获取失败:', error);
    return { simulationType: [], discipline: [] };
  }
};
