export type TalentRelation = "gt" | "gte" | "eq"; export interface TalentPriority { type: "NA" | "E" | "Q"; priority: number; level?: string; relationToNext?: TalentRelation; } export function normalizeTalentPriorities(talents: readonly TalentPriority[]): TalentPriority[] { const ordered = [...talents].sort((a, b) => a.priority - b.priority); return ordered.map((talent, index) => ({ ...talent, priority: index + 1, relationToNext: index < ordered.length - 1 ? talent.relationToNext ?? "gt" : undefined, })); } export function reorderTalentPriorities( talents: readonly TalentPriority[], activeType: TalentPriority["type"], overType: TalentPriority["type"], ): TalentPriority[] { const ordered = normalizeTalentPriorities(talents); const from = ordered.findIndex((talent) => talent.type === activeType); const to = ordered.findIndex((talent) => talent.type === overType); if (from < 0 || to < 0 || from === to) return ordered; const relations = ordered.slice(0, -1).map((talent) => talent.relationToNext ?? "gt"); const next = [...ordered]; const [moved] = next.splice(from, 1); next.splice(to, 0, moved); return next.map((talent, index) => ({ ...talent, priority: index + 1, relationToNext: index < next.length - 1 ? relations[index] : undefined, })); } export function talentRelationSymbol(relation?: TalentRelation): ">" | "≥" | "=" { return relation === "gte" ? "≥" : relation === "eq" ? "=" : ">"; } export function talentTypeLabel(type: TalentPriority["type"]): string { return type === "E" ? "สกิลธาตุ" : type === "Q" ? "ท่าไม้ตาย" : "ตีปกติ"; }