import type { LegacyStage } from "../hooks/legacySessionTypes";
import type { LegacyTotals } from "../legacy/interop.js";
import { getLegacyStageLabel } from "./legacy-app/legacyAppConfig";

interface LegacyHomePanelProps {
  canOpenMeta: boolean;
  isLoading: boolean;
  onOpenAchievements: () => void;
  onOpenRun: () => void;
  onOpenThanks: () => void;
  primaryActionLabel: string;
  selectedTalentCount: number;
  stage: LegacyStage;
  totals: LegacyTotals | null;
  trajectoryLength: number;
}

export function LegacyHomePanel({
  canOpenMeta,
  isLoading,
  onOpenAchievements,
  onOpenRun,
  onOpenThanks,
  primaryActionLabel,
  selectedTalentCount,
  stage,
  totals,
  trajectoryLength,
}: LegacyHomePanelProps) {
  return (
    <>
      <div className="panel-head">
        <h2>Index</h2>
        <p>
          The rewrite now restores the original landing rhythm: start from a
          home screen, unlock meta pages after real remakes, and keep one clear
          primary action.
        </p>
      </div>

      <section className="home-hero">
        <div className="home-status-card">
          <span>Current stage</span>
          <strong>{getLegacyStageLabel(stage)}</strong>
          <p>
            {selectedTalentCount > 0
              ? `${selectedTalentCount} talent(s) selected in the current draft.`
              : "No current draft selection yet."}
          </p>
        </div>
        <div className="home-status-card">
          <span>Progress</span>
          <strong>{trajectoryLength} years logged</strong>
          <p>
            {totals
              ? `${totals.times} remakes and ${totals.achievement} achievements in persistent storage.`
              : "Loading persistent totals from the legacy runtime."}
          </p>
        </div>
      </section>

      <div className="home-actions">
        <button
          className="reset-button"
          disabled={isLoading}
          onClick={onOpenRun}
          type="button"
        >
          {primaryActionLabel}
        </button>
        {canOpenMeta ? (
          <>
            <button
              className="secondary-button"
              onClick={onOpenAchievements}
              type="button"
            >
              Open achievements
            </button>
            <button
              className="secondary-button"
              onClick={onOpenThanks}
              type="button"
            >
              Open special thanks
            </button>
          </>
        ) : null}
      </div>

      {!canOpenMeta ? (
        <div className="helper-copy">
          Achievement and special-thanks pages unlock after your first remake,
          matching the original index behavior.
        </div>
      ) : null}

      <section className="signal-section home-shortcuts">
        <div className="section-head">
          <h3>Keyboard Shortcuts</h3>
          <p>
            Enter triggers the primary action on the current page. Escape jumps
            back to this home screen.
          </p>
        </div>
        <div className="shortcut-grid">
          <div className="shortcut-card">
            <strong>Enter</strong>
            <p>Start, continue, advance a year, or remake based on context.</p>
          </div>
          <div className="shortcut-card">
            <strong>Escape</strong>
            <p>Return from run or meta pages to the home screen.</p>
          </div>
          <div className="shortcut-card">
            <strong>Theme</strong>
            <p>
              The current theme is saved to the same `theme` localStorage key.
            </p>
          </div>
        </div>
      </section>
    </>
  );
}
