// (C) 2025-2026 GoodData Corporation
import { breakupSlideTransformer } from "../../_staging/slideshow/breakupSlideTransformer.js";
import { containerSlideTransformer } from "../../_staging/slideshow/containerSlideTransformer.js";
import { containerSwitcherSlideTransformer } from "../../_staging/slideshow/containerSwitcherSlideTransformer.js";
import { itemsSlideTransformer } from "../../_staging/slideshow/itemsSlideTransformer.js";
import { sectionItemsLayoutSection, sectionLayoutSection, } from "../../_staging/slideshow/sectionSlideTransformer.js";
import { switcherSlideTransformer } from "../../_staging/slideshow/switcherSlideTransformer.js";
import { containsVisualizationSwitcher } from "../../_staging/slideshow/utils/index.js";
import { widgetSlideTransformer } from "../../_staging/slideshow/widgetSlideTransformer.js";
export class ExportLayoutCustomizer {
    logger;
    mutationContext;
    transformers = [];
    constructor(logger, mutationContext) {
        this.logger = logger;
        this.mutationContext = mutationContext;
    }
    addTransformer(fn) {
        this.transformers.push(fn);
        return this;
    }
    applyTransformations(layout) {
        const transformers = this.transformers;
        const { exports } = this.mutationContext;
        const sections = layout?.sections.reduce((acc, section) => {
            const created = transformers.reduce((subAcc, transformer) => {
                const res = transformer(section, {
                    defaultSection: sectionLayoutSection,
                    defaultItems: sectionItemsLayoutSection,
                    breakUpSlide: breakupSlideTransformer,
                    widgetSlide: widgetSlideTransformer,
                    switcherSlide: switcherSlideTransformer,
                    containerSlide: containerSlideTransformer,
                    containerSwitcherSlide: containerSwitcherSlideTransformer,
                    itemsSlide: itemsSlideTransformer,
                    containsVisualisationSwitcher: containsVisualizationSwitcher,
                });
                return [...subAcc, ...(res || [])];
            }, []);
            return [...acc, ...created];
        }, []) ?? [];
        if (sections.length === 0) {
            this.logger.warn("Layout has no sections after applying transformations. The layout will be empty.");
        }
        if (transformers.length > 0) {
            exports.push("transformed");
        }
        return {
            ...layout,
            type: "IDashboardLayout",
            sections,
        };
    }
}
