import { classifyLogoShape, resolveAdminBrand, } from '@actuate-media/cms-core/appearance';
export function parseAppearanceAssets(assets) {
    const next = {};
    for (const a of assets ?? []) {
        next[a.id] = {
            id: a.id,
            url: a.publicUrl,
            mimeType: a.mimeType,
            width: a.width ?? undefined,
            height: a.height ?? undefined,
            shape: classifyLogoShape(a.width ?? undefined, a.height ?? undefined),
        };
    }
    return next;
}
export function adminBrandToCache(brand, assets, siteTitle) {
    const map = new Map(Object.values(assets).map((a) => [
        a.id,
        { id: a.id, publicUrl: a.url, mimeType: a.mimeType, width: a.width, height: a.height },
    ]));
    const resolved = resolveAdminBrand(brand, map, siteTitle);
    return {
        primaryUrl: resolved.primary?.url ?? null,
        markUrl: resolved.mark?.url ?? null,
        darkUrl: resolved.dark?.url ?? null,
        initials: resolved.initials,
    };
}
/** Map a stored appearance payload into the ThemeProvider snapshot. */
export function appearanceApiToSnapshot(data) {
    const brand = { ...data.brand, mode: data.brand?.mode ?? 'inheritPublicBrand' };
    const assets = parseAppearanceAssets(data.assets);
    return {
        theme: data.appearance.adminColorModeDefault,
        accent: data.appearance.adminAccentColor,
        density: data.appearance.sidebarDensity,
        font: data.appearance.contentFont,
        reduceMotion: data.appearance.reduceMotion,
        adminBrand: adminBrandToCache(brand, assets, data.siteTitle ?? null),
    };
}
//# sourceMappingURL=appearance-api.js.map