import { z } from "zod" import { transformedImageVaultAssetSchema } from "@scandic-hotels/common/utils/imageVault" import { CardsEnum } from "../../../../../types/cardsEnum" import { systemSchema } from "../../system" import { getInfoCardThemeFromDeprecatedCardTheme } from "../cardsGrid" import { buttonSchema } from "../utils/buttonLinkSchema" import { linkConnectionRefsSchema } from "../utils/linkConnection" const INFO_CARD_WITH_IMAGE_THEMES = [ "one", "two", "three", "primaryInverted", "primaryStrong", ] as const export const infoCardWithImageBlockSchema = z.object({ __typename: z.literal(CardsEnum.InfoCardWithImage), scripted_top_title: z.string().optional(), heading: z.string().optional().default(""), body_text: z.string().optional().default(""), image: transformedImageVaultAssetSchema, theme: z .enum(INFO_CARD_WITH_IMAGE_THEMES) .nullable() .transform(getInfoCardThemeFromDeprecatedCardTheme), title: z.string().optional(), primary_button: buttonSchema.optional().nullable(), secondary_button: buttonSchema.optional().nullable(), system: systemSchema, }) export function transformInfoCardWithImageBlock( card: typeof infoCardWithImageBlockSchema._type ) { return { __typename: card.__typename, topTitle: card.scripted_top_title, heading: card.heading, bodyText: card.body_text, image: card.image, theme: card.theme, title: card.title, primaryButton: card.primary_button?.href ? { href: card.primary_button.href, text: card.primary_button.title, openInNewTab: card.primary_button.openInNewTab, isExternal: card.primary_button.isExternal, } : undefined, secondaryButton: card.secondary_button?.href ? { href: card.secondary_button.href, text: card.secondary_button.title, openInNewTab: card.secondary_button.openInNewTab, isExternal: card.secondary_button.isExternal, } : undefined, system: card.system, } } export const infoCardWithImageBlockRefsSchema = z.object({ __typename: z.literal(CardsEnum.InfoCardWithImage), primary_button: linkConnectionRefsSchema, secondary_button: linkConnectionRefsSchema, system: systemSchema, })