"use client";

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

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

  const columns: SectionBlockProps["columns"] = [
    { id: `${sectionId}_col_1`, span: 8 },
    { id: `${sectionId}_col_2`, span: 4 },
  ];

  const sectionProps: SectionBlockProps = {
    background: "primary",
    paddingY: "md",
    // CTA 는 강한 색상과 적당한 여백, 비교적 좁은 폭을 사용한다.
    paddingYPx: 64,
    maxWidthPx: 960,
    gapXPx: 24,
    backgroundColorCustom: "#0c4a6e",
    columns,
  } as any;

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

  const leftColumnId = `${sectionId}_col_1`;
  const rightColumnId = `${sectionId}_col_2`;

  const textId = createId();
  const textProps: TextBlockProps = {
    text: messages.body,
    align: "left",
    size: "lg",
  } as any;
  const textBlock: Block = {
    id: textId,
    type: "text",
    props: textProps,
    sectionId,
    columnId: leftColumnId,
  };

  const buttonId = createId();
  const buttonProps: ButtonBlockProps = {
    label: messages.buttonLabel,
    href: "#",
    align: "center",
    size: "lg",
    variant: "solid",
    colorPalette: "primary",
    fullWidth: true,
    borderRadius: "md",
    textColorCustom: "#0b1120",
    fillColorCustom: "#0ea5e9",
    strokeColorCustom: "#0284c7",
  };
  const buttonBlock: Block = {
    id: buttonId,
    type: "button",
    props: buttonProps,
    sectionId,
    columnId: rightColumnId,
  };

  const blocks: Block[] = [sectionBlock, textBlock, buttonBlock];
  const lastSelectedId = buttonId;

  return { blocks, lastSelectedId };
}
