// ─── Floor Helpers ────────────────────────────────────────────────────────────

import { FLOOR_ELEM_CYCLE } from '../constants';
import { getGuardianForFloor } from '../data/guardian-encounters';

export function getFloorMaxHP(floor: number): number {
  const guardian = getGuardianForFloor(floor);
  if (guardian) return guardian.hp;
  // Handle negative or zero floors
  if (floor <= 0) return 100;
  // Improved scaling: slower early game, faster late game
  const baseHP = 100;
  const floorScaling = floor * 50;
  const exponentialScaling = Math.pow(floor, 1.7);
  return Math.floor(baseHP + floorScaling + exponentialScaling);
}

/**
 * Get the primary element for a floor.
 * Guardian floors use the guardian's first element.
 * Non-guardian floors cycle through the base element list.
 */
export function getFloorElement(floor: number): string {
  const guardian = getGuardianForFloor(floor);
  if (guardian && guardian.element.length > 0) {
    return guardian.element[0];
  }
  const len = FLOOR_ELEM_CYCLE.length;
  const idx = ((floor - 1) % len + len) % len;
  return FLOOR_ELEM_CYCLE[idx];
}

/**
 * Get all elements for a floor.
 * Guardian floors return all guardian elements (multi-element guardians).
 * Non-guardian floors return a single-element array with the cycle element.
 */
export function getFloorElements(floor: number): string[] {
  const guardian = getGuardianForFloor(floor);
  if (guardian && guardian.element.length > 0) {
    return [...guardian.element];
  }
  const len = FLOOR_ELEM_CYCLE.length;
  const idx = ((floor - 1) % len + len) % len;
  return [FLOOR_ELEM_CYCLE[idx]];
}

