import { PromoCampaignPageEnum, type PromoCampaignPageRefs, } from "../../../types/promoCampaignPage" import { generateTag, generateTagsFromAssetSystem, generateTagsFromSystem, } from "../../../utils/generateTag" import type { Lang } from "@scandic-hotels/common/constants/language" import type { AssetSystem, System } from "../schemas/system" export function generatePageTags( validatedData: PromoCampaignPageRefs, lang: Lang ): string[] { const { connections, assetConnections } = getConnections(validatedData) return [ generateTagsFromSystem(lang, connections), generateTagsFromAssetSystem(assetConnections), generateTag(lang, validatedData.promo_campaign_page.system.uid), ].flat() } export function getConnections({ promo_campaign_page }: PromoCampaignPageRefs) { const connections: System["system"][] = [promo_campaign_page.system] const assetConnections: AssetSystem[] = [] if (promo_campaign_page.blocks) { promo_campaign_page.blocks.forEach((block) => { switch (block.__typename) { case PromoCampaignPageEnum.ContentStack.blocks.Accordion: if (block.accordion.length) { connections.push(...block.accordion.filter((c) => !!c)) } break case PromoCampaignPageEnum.ContentStack.blocks.Content: if (block?.content?.length) { block.content.forEach((contentBlock) => { if ("system" in contentBlock) { assetConnections.push(contentBlock) } else { connections.push(contentBlock) } }) } break } }) } return { connections, assetConnections } }