// Shared data + geometry for the "Strategy" 3D scroll-storytelling section.
// The five stages are five DISTRICTS of one continuous logistics world laid out
// along the camera's forward (−Z) axis. As normalized scroll progress (0→1)
// advances, the camera dollies forward through the world: Intake dock → Strategy
// network → City route map → Command center → Winner podium.

export type StageTheme = {
  n: string;        // "01"
  key: string;
  kicker: string;   // short label for the step rail
  theme: string;    // hex accent
};

export const STAGES: StageTheme[] = [
  { n: "01", key: "input", kicker: "Input", theme: "#22C55E" },                  // green
  { n: "02", key: "parallel", kicker: "Parallel Execution", theme: "#8B5CF6" },  // purple
  { n: "03", key: "optimize", kicker: "Smart Optimization", theme: "#3B82F6" },  // blue
  { n: "04", key: "grading", kicker: "Performance Grading", theme: "#F59E0B" },  // orange
  { n: "05", key: "winner", kicker: "Strategy Comparison", theme: "#C01227" },   // red — hero
];

export const N = STAGES.length;

// Forward-journey layout (world units). Each district sits on the floor (y≈0) at
// an increasing depth; a slight alternating x sway gives the dolly some rhythm
// without ever turning the world into a zig-zag of separate panels.
export const D_SPACING = 13;   // depth between districts
export const X_SWAY = 1.4;     // gentle left/right sway between districts

/** Resting world position (floor anchor) of district `i` along the journey. */
export function districtPosition(i: number): [number, number, number] {
  const x = (i % 2 === 0 ? -1 : 1) * X_SWAY;
  const z = -i * D_SPACING;
  return [x, 0, z];
}

/** Continuous floor position sampled at a fractional district index. */
export function samplePath(idx: number): [number, number, number] {
  const clamped = Math.max(0, Math.min(N - 1, idx));
  const f = Math.floor(clamped);
  const c = Math.min(N - 1, f + 1);
  const t = clamped - f;
  const a = districtPosition(f);
  const b = districtPosition(c);
  return [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t, a[2] + (b[2] - a[2]) * t];
}

/**
 * Camera dolly + look target for a fractional district index. The camera rides
 * behind and above the active district and looks slightly forward+down, so the
 * district fills the frame while the next one eases into view ahead.
 */
export function cameraFor(idx: number): {
  pos: [number, number, number];
  look: [number, number, number];
} {
  const [tx, ty, tz] = samplePath(idx);
  // Look target leads a little forward (deeper into −Z) and sits at eye height.
  const look: [number, number, number] = [tx * 0.55, ty + 1.05, tz - 1.6];
  // Camera sits back (+Z) and up (+Y) from the active district.
  const pos: [number, number, number] = [tx * 0.7, ty + 4.0, tz + 8.2];
  return { pos, look };
}
