import { findImagePlugin } from "../utils/image_plugins/index.js";
/** Type guard: checks if animation value is an object config like { fps: 30 } */
const isAnimationObject = (animation) => {
    return typeof animation === "object" && animation !== null && !Array.isArray(animation);
};
/** Check if a value is a valid animation config (true or non-array object) */
const isAnimationEnabled = (animation) => {
    return animation === true || isAnimationObject(animation);
};
/** Check if movie mode (CDP screencast) is enabled */
const isMovieMode = (animation) => {
    return isAnimationObject(animation) && animation.movie === true;
};
/** Check if a beat has html_tailwind animation enabled */
const isAnimatedHtmlTailwind = (beat) => {
    if (!beat.image || beat.image.type !== "html_tailwind")
        return false;
    const animation = beat.image.animation;
    return isAnimationEnabled(animation);
};
export const MulmoBeatMethods = {
    isAnimationEnabled,
    isAnimationObject,
    isAnimatedHtmlTailwind,
    isMovieMode,
    getHtmlPrompt(beat) {
        if (beat?.htmlPrompt?.data) {
            return beat.htmlPrompt.prompt + "\n\n[data]\n" + JSON.stringify(beat.htmlPrompt.data, null, 2);
        }
        return beat?.htmlPrompt?.prompt;
    },
    getPlugin(beat) {
        const plugin = findImagePlugin(beat?.image?.type);
        if (!plugin) {
            throw new Error(`invalid beat image type: ${beat.image}`); // TODO: cause
        }
        return plugin;
    },
    getImageReferenceForImageGenerator(beat, imageRefs) {
        const imageNames = beat.imageNames ?? Object.keys(imageRefs); // use all images if imageNames is not specified
        const sources = imageNames.map((name) => imageRefs[name]);
        return sources.filter((source) => source !== undefined);
    },
};
