"use client";

import { usePathname } from "next/navigation";
import { RootTaleExposureProvider, RootTaleExposureSlot } from "@roottale/cms-renderer-next/exposures";
import { EXPOSURE_HOME_PATHS, EXPOSURE_SLOTS } from "../lib/exposure-slots";
import { GlobalPopup } from "./global-popup";

export function SiteExposures({ children }: { children: React.ReactNode }) {
  const pathname = usePathname();
  return (
    // ROOT-ADMIN의 실제 사이트 미리보기는 이 Provider와 아래 실제 Slot을 재사용한다.
    // 자체 관리자·로컬 검수는 previewOrigins={["https://editor.example.com"]}처럼
    // 정확한 출처를 추가한다. canonical admin.roottale.com은 기본 허용된다.
    <RootTaleExposureProvider endpoint="/api/exposures" pathname={pathname ?? "/"} slots={EXPOSURE_SLOTS} homePaths={EXPOSURE_HOME_PATHS}>
      <RootTaleExposureSlot slotKey="site-banner" placement="top" allowedVariants={["card"]} />
      {children}
      <RootTaleExposureSlot slotKey="site-bottom-banner" placement="bottom" allowedVariants={["card"]} />
      <GlobalPopup />
    </RootTaleExposureProvider>
  );
}

export function HomeBanner() {
  return <RootTaleExposureSlot slotKey="home-banner" placement="inline" allowedVariants={["card", "image-card"]} />;
}
