"use client";

/**
 * The header mega menu promo panel's AI Studio wiring. The panel renders one
 * tall portrait image at a fixed 10:13 frame (see
 * lib/ai-authoring/mega-menu-promo/types.ts), so the studio generates at the
 * closest model size (2:3) and center-crops every result down to that exact
 * frame before it is applied — the same lock-and-crop contract the home-page
 * promo cards use, so the committed image already fits the panel.
 */

import { makeRatioCropPostProcess } from "@/components/ai-authoring/ratio-crop";
import type { AiStudioSurface } from "@/components/ai-authoring/studio-surface";
import type {
  AIAuthoringMediaOptions,
  AIAuthoringMediaResponse,
} from "@/lib/ai-authoring/types";
import {
  MEGA_MENU_PROMO_HEIGHT,
  MEGA_MENU_PROMO_WIDTH,
} from "@/lib/ai-authoring/mega-menu-promo/types";

export type MegaMenuPromoStudio = {
  surface: AiStudioSurface;
  generateDefaults: AIAuthoringMediaOptions;
  promptPlaceholder: string;
  postProcessResult: (
    response: AIAuthoringMediaResponse,
  ) => Promise<AIAuthoringMediaResponse>;
};

export const MEGA_MENU_PROMO_STUDIO: MegaMenuPromoStudio = {
  surface: "mega_menu_promo",
  // Portrait 2:3, the closest the model emits to the 10:13 promo panel.
  generateDefaults: {
    size: "1024x1536",
    outputFormat: "png",
    background: "opaque",
  },
  promptPlaceholder:
    "Describe a tall portrait promo image for this category. Keep the key subject centered.",
  postProcessResult: makeRatioCropPostProcess({
    width: MEGA_MENU_PROMO_WIDTH,
    height: MEGA_MENU_PROMO_HEIGHT,
    filename: "mega-menu-promo.png",
    ratioLabel: "the promo panel frame",
  }),
};
