"use client";

import type {
  Block,
  SectionBlockProps,
  TextBlockProps,
  ButtonBlockProps,
} from "@/features/editor/state/editorStore";
import type { EditorHeroTemplateMessages } from "@/features/i18n/messages/editorTemplates";

export function createHeroTemplateBlocks(opts: {
  sectionId: string;
  createId: () => string;
  messages: EditorHeroTemplateMessages;
}): { blocks: Block[]; lastSelectedId: string } {
  const { sectionId, createId, messages } = opts;

  const sectionProps: SectionBlockProps = {
    background: "default",
    paddingY: "lg",
    // 히어로는 가장 여백이 넓고 화면 중앙에 집중되도록 설정한다.
    paddingYPx: 96,
    maxWidthPx: 960,
    gapXPx: 40,
    backgroundColorCustom: "#020617", // 다크 히어로 섹션
    columns: [
      {
        id: `${sectionId}_col_1`,
        span: 12,
      },
    ],
  };

  const sectionBlock: Block = {
    id: sectionId,
    type: "section",
    props: sectionProps,
    sectionId: null,
    columnId: null,
  };

  const firstColumnId = `${sectionId}_col_1`;

  const heroHeadlineId = createId();
  const heroHeadlineProps: TextBlockProps = {
    text: messages.headline,
    align: "center",
    size: "lg",
  } as any;
  const heroHeadline: Block = {
    id: heroHeadlineId,
    type: "text",
    props: heroHeadlineProps,
    sectionId,
    columnId: firstColumnId,
  };

  const heroSubId = createId();
  const heroSubProps: TextBlockProps = {
    text: messages.subheadline,
    align: "center",
    size: "base",
  } as any;
  const heroSub: Block = {
    id: heroSubId,
    type: "text",
    props: heroSubProps,
    sectionId,
    columnId: firstColumnId,
  };

  const heroButtonId = createId();
  const heroButtonProps: ButtonBlockProps = {
    label: messages.primaryButtonLabel,
    href: "#",
    align: "center",
    size: "md",
    variant: "solid",
    colorPalette: "primary",
    fullWidth: false,
    borderRadius: "md",
    fontSizeCustom: "14px",
    textColorCustom: "#0b1120",
    fillColorCustom: "#0ea5e9",
    strokeColorCustom: "#0284c7",
  };
  const heroButton: Block = {
    id: heroButtonId,
    type: "button",
    props: heroButtonProps,
    sectionId,
    columnId: firstColumnId,
  };

  const blocks: Block[] = [sectionBlock, heroHeadline, heroSub, heroButton];

  return { blocks, lastSelectedId: heroButtonId };
}
