import { Alert } from "@scandic-hotels/design-system/Alert"
import { getAlertPhoneContactData } from "@scandic-hotels/trpc/routers/contentstack/base/utils"

import { serverClient } from "@/lib/trpc/server"

import type { AlertBlock } from "@scandic-hotels/trpc/types/blocks"

interface AlertBlockProps extends Pick<AlertBlock, "alert"> {}

export async function AlertBlock({ alert }: AlertBlockProps) {
  const caller = await serverClient()
  const contactConfig = await caller.contentstack.base.contact()
  if (!alert) {
    return null
  }

  const phoneContact =
    alert.phoneContact && contactConfig
      ? getAlertPhoneContactData(alert, contactConfig)
      : null

  return (
    <Alert
      {...alert}
      phoneContact={phoneContact}
      sidepeekCtaText={alert.sidepeekButton?.cta_text}
    />
  )
}
