export {
  BOSS_DEATH_DESPAWN_SECONDS,
  BOSS_DEATH_FADE_SECONDS,
  BOSS_DEATH_HOLD_SECONDS,
  bossDeathDespawnSeconds,
  bossDeathHoldSeconds,
  bossDeathOpacity,
} from "../../game/bossDeath";

export const BOSS_INDICATOR_DEATH_FADE_MS = 250;

export interface BossIndicatorPatchState {
  defeated: boolean;
  pending: boolean;
}

export function createBossIndicatorPatchState(defeated: boolean): BossIndicatorPatchState {
  return { defeated, pending: defeated };
}

export function updateBossIndicatorPatchState(
  state: BossIndicatorPatchState,
  defeated: boolean,
): BossIndicatorPatchState {
  if (state.defeated === defeated) return state;
  return { defeated, pending: defeated };
}

export function consumeBossIndicatorPatch(state: BossIndicatorPatchState): BossIndicatorPatchState {
  return state.pending ? { ...state, pending: false } : state;
}

export function bossCanTrackTarget(hp: number) {
  return hp > 0;
}

export function advanceBossIndicatorOpacity(current: number, defeated: boolean, deltaSeconds: number) {
  if (!defeated) return 1;
  return Math.max(0, current - (deltaSeconds * 1_000) / BOSS_INDICATOR_DEATH_FADE_MS);
}
