import type { HealerClassId, HealerPulseKind, PulseKind } from "./types";

export interface StaffCastGlowProfile {
  color: string;
}

export const STAFF_CAST_GLOW_PROFILES: Record<HealerClassId, StaffCastGlowProfile> = {
  priest: { color: "#ffd66b" },
  druid: { color: "#72df72" },
  shaman: { color: "#62bdff" },
  paladin: { color: "#f2a65a" },
  chronomancer: { color: "#62d4d9" },
};

export const STAFF_CAST_AFTERGLOW_SECONDS = 0.85;

export function isHealerPulseKind(kind: PulseKind): kind is HealerPulseKind {
  return kind === "direct-heal"
    || kind === "periodic-heal"
    || kind === "protective"
    || kind === "cleanse"
    || kind === "group-heal"
    || kind === "field";
}

function clamp01(value: number) {
  return Math.max(0, Math.min(1, value));
}

export function staffCastGlowStrength({
  castingProgress,
  afterglowAge,
}: {
  castingProgress: number | null;
  afterglowAge: number | null;
}) {
  const progress = castingProgress === null ? 0 : clamp01(castingProgress);
  const smoothProgress = progress * progress * (3 - 2 * progress);
  const castingStrength = castingProgress === null ? 0 : 0.42 + smoothProgress * 0.58;
  const afterglowProgress = afterglowAge === null
    ? 1
    : clamp01(afterglowAge / STAFF_CAST_AFTERGLOW_SECONDS);
  const afterglowStrength = afterglowAge === null ? 0 : (1 - afterglowProgress) ** 2;
  return Math.max(castingStrength, afterglowStrength);
}
