/** 대시보드 부문 (3열) */
export const SECTIONS = ['인사관리', '학습성장', '운영관리'] as const;

export type SectionKey = (typeof SECTIONS)[number];

/** DB·레거시 section 값 → 표준 부문 */
export const SECTION_ALIASES: Record<SectionKey, readonly string[]> = {
  인사관리: ['인사관리'],
  학습성장: ['학습성장', '성장지원'],
  운영관리: ['운영관리', '운영지원', '전산관리'],
};

/** 컬럼 설정·cardOrder 조회 시 함께 병합할 레거시 키 */
export const LEGACY_COLUMN_KEYS: Record<SectionKey, readonly string[]> = {
  인사관리: [],
  학습성장: [],
  운영관리: ['운영지원', '전산관리'],
};

export function normalizeSection(section: string | null | undefined): SectionKey | null {
  if (!section) return null;
  for (const key of SECTIONS) {
    if (SECTION_ALIASES[key].includes(section)) return key;
  }
  return null;
}

export function taskBelongsToSection(
  taskSection: string | null | undefined,
  columnSection: SectionKey,
): boolean {
  return normalizeSection(taskSection) === columnSection;
}

/** 화면·듀얼모니터 상세·업무관리 — 4분면 보드 표시명 */
export function formatSectionDisplay(section: string | null | undefined): string {
  if (!section?.trim()) return '—';
  if (section.trim() === '조직문화') return '조직문화';
  const key = normalizeSection(section);
  if (key) return COLUMN_META[key].boardTitle;
  return section.trim();
}

export function canonicalSection(section: string | null | undefined): SectionKey {
  return normalizeSection(section) ?? '인사관리';
}

export const COLUMN_META: Record<
  SectionKey,
  { titleEn: string; accent: string; displayTitle: string; boardTitle: string; routineBg: string }
> = {
  인사관리: {
    titleEn: 'HRM',
    accent: '#07412e',
    displayTitle: '인사관리',
    boardTitle: '인사관리',
    routineBg: 'linear-gradient(180deg, #dce8e3 0%, #e8f0ec 100%)',
  },
  학습성장: {
    titleEn: 'HRD',
    accent: '#29724f',
    displayTitle: '인재육성',
    boardTitle: '인재육성',
    routineBg: 'linear-gradient(180deg, #d8ebe3 0%, #e6f2ec 100%)',
  },
  운영관리: {
    titleEn: 'GA',
    accent: '#36816d',
    displayTitle: '총무관리',
    boardTitle: '총무관리',
    routineBg: 'linear-gradient(180deg, #d4ece4 0%, #e4f3ed 100%)',
  },
};
