/* Prototype seed data wired to local project assets in ./assets */

const PROMPTS_BY_BASENAME = {
  img1: "flower gently blowing in the wind",
  img1b: "the boy runs",
  img1c: "the girl walk stoward us",
  img2a: "the camera pans to the right",
  img2b: "the boy looks down",
  img3a: "wind blows gently",
  img3b: "zoom in",
  img3c: "The girl looks down",
  img4: "The boy looks down heartbroken",
};

const VISUAL_ORDER = [
  "img1",
  "img1b",
  "img1c",
  "img2a",
  "img2b",
  "img3a",
  "img3b",
  "img3c",
  "img4",
];
const VISUAL_CLIP_DURATION = 2.5;
const IMG4_VIDEO_DURATION = 5.0;

const IMAGE_MEDIA = VISUAL_ORDER.map((base, idx) => ({
  id: `m_img_${String(idx + 1).padStart(2, "0")}`,
  base,
  name: `${base}.png`,
  type: "image",
  url: `./assets/images/${base}.png`,
  duration: VISUAL_CLIP_DURATION,
}));

const VIDEO_MEDIA = [
  { id: "m_vid_01", base: "img1", name: "img1.mp4", type: "video", url: "./assets/videos/img1.mp4", duration: VISUAL_CLIP_DURATION },
  { id: "m_vid_02", base: "img1b", name: "img1b.mp4", type: "video", url: "./assets/videos/img1b.mp4", duration: VISUAL_CLIP_DURATION },
  { id: "m_vid_03", base: "img1c", name: "img1c.mp4", type: "video", url: "./assets/videos/img1c.mp4", duration: VISUAL_CLIP_DURATION },
  { id: "m_vid_04", base: "img2a", name: "img2a.mp4", type: "video", url: "./assets/videos/img2a.mp4", duration: VISUAL_CLIP_DURATION },
  { id: "m_vid_05", base: "img2b", name: "img2b.mp4", type: "video", url: "./assets/videos/img2b.mp4", duration: VISUAL_CLIP_DURATION },
  { id: "m_vid_06", base: "img3a", name: "img3a.mp4", type: "video", url: "./assets/videos/img3a.mp4", duration: VISUAL_CLIP_DURATION },
  { id: "m_vid_09", base: "img3b", name: "img3b.mp4", type: "video", url: "./assets/videos/img3b.mp4", duration: VISUAL_CLIP_DURATION },
  { id: "m_vid_07", base: "img3c", name: "img3c.mp4", type: "video", url: "./assets/videos/img3c.mp4", duration: VISUAL_CLIP_DURATION },
  { id: "m_vid_08", base: "img4", name: "img4.mp4", type: "video", url: "./assets/videos/img4.mp4", duration: IMG4_VIDEO_DURATION },
];

const DEFAULT_AUDIO_MEDIA = {
  id: "m_audio_01",
  name: "sonicesosmart.mp3",
  type: "audio",
  url: "./assets/audio/sonicesosmart.mp3",
  duration: 24.2,
};

const OPTIONAL_AUDIO_MEDIA = {
  id: "m_audio_02",
  name: "violin-instrumental.mp3",
  type: "audio",
  url: "./assets/audio/violin-instrumental.mp3",
  duration: 60.2,
};

const imageByBase = IMAGE_MEDIA.reduce((acc, item) => {
  acc[item.base] = item;
  return acc;
}, {});

const videoByBase = VIDEO_MEDIA.reduce((acc, item) => {
  acc[item.base] = item;
  return acc;
}, {});

const SEED_MEDIA = [...IMAGE_MEDIA, ...VIDEO_MEDIA, DEFAULT_AUDIO_MEDIA, OPTIONAL_AUDIO_MEDIA];

let visualCursor = 0;
const visualClips = VISUAL_ORDER.map((base, idx) => {
  const imageAsset = imageByBase[base];
  const generatedVideo = videoByBase[base] || null;
  const chosenAsset = generatedVideo || imageAsset;
  const prompt = PROMPTS_BY_BASENAME[base] || `Animate ${base}`;
  const isGenerated = !!generatedVideo;

  const clip = {
    id: `c_${String(idx + 1).padStart(2, "0")}`,
    mediaId: chosenAsset.id,
    name: base,
    type: chosenAsset.type,
    track: 0,
    start: Number(visualCursor.toFixed(2)),
    duration: chosenAsset.duration,
    trimIn: 0,
    effects: isGenerated
      ? [{ id: `e_ai_${base}`, name: "AI Animate", kind: "ai", value: "1.00" }]
      : [],
    chat: isGenerated
      ? [
          { role: "user", text: prompt },
          {
            role: "assistant",
            text: `Animation complete. Using local prototype render ${generatedVideo.name}.`,
            effects: ["AI Animate"],
          },
        ]
      : [
          { role: "user", text: prompt },
          {
            role: "assistant",
            text: "Prototype note: no matching video in /assets/videos yet, so this remains an image clip.",
          },
        ],
  };

  visualCursor += chosenAsset.duration;
  return clip;
});

const SEED_CLIPS = [
  ...visualClips,
  {
    id: "c_audio_01",
    mediaId: DEFAULT_AUDIO_MEDIA.id,
    name: "sonicesosmart",
    type: "audio",
    track: 1,
    start: 0.0,
    duration: Number(Math.max(visualCursor, 18).toFixed(2)),
    trimIn: 0,
    effects: [],
    chat: [],
  },
];

const SEED_TEXT_OVERLAYS = [
  { id: "t_01", start: 18.0, end: null, text: "LAYLA", x: 50, y: 44 },
  { id: "t_02", start: 19.0, end: null, text: "&", x: 50, y: 60 },
  { id: "t_03", start: 20.0, end: null, text: "MAJNUN", x: 50, y: 76 },
];

window.SEED_MEDIA = SEED_MEDIA;
window.SEED_CLIPS = SEED_CLIPS;
window.SEED_TEXT_OVERLAYS = SEED_TEXT_OVERLAYS;
window.PROTOTYPE_PROMPTS_BY_BASENAME = PROMPTS_BY_BASENAME;
window.PROTOTYPE_VIDEO_BY_BASENAME = videoByBase;
