import type { AppLocale } from "../locale";
import { DEFAULT_LOCALE } from "../locale";

export type EditorFormControllerPanelMessages = {
  introTextPrefix: string;
  introTextSuffix: string;

  submitTargetLabel: string;
  submitTargetOptionInternal: string;
  submitTargetOptionWebhook: string;

  webhookUrlLabel: string;
  webhookUrlPlaceholder: string;

  payloadFormatLabel: string;
  payloadFormatOptionForm: string;
  payloadFormatOptionJson: string;

  httpMethodLabel: string;

  authTokenLabel: string;
  authTokenPlaceholder: string;

  extraParamsLabel: string;
  extraParamsPlaceholder: string;

  layoutSectionTitle: string;
  formWidthModeLabel: string;
  formWidthModeOptionAuto: string;
  formWidthModeOptionFull: string;
  formWidthModeOptionFixed: string;

  formFixedWidthLabel: string;

  formFixedWidthPresetNarrow: string;
  formFixedWidthPresetNormal: string;
  formFixedWidthPresetWide: string;

  marginYLabel: string;
  marginYPresetNone: string;
  marginYPresetCompact: string;
  marginYPresetNormal: string;
  marginYPresetSpacious: string;

  messagesSectionTitle: string;
  successMessageLabel: string;
  successMessagePlaceholder: string;
  errorMessageLabel: string;
  errorMessagePlaceholder: string;

  controllerSectionTitle: string;
  fieldMappingLegend: string;
  fieldMappingAriaLabel: string;
  requiredLabel: string;

  submitButtonLabel: string;
  submitButtonAriaLabel: string;

  submitButtonNoneOptionLabel: string;

  sheetsGuideButtonLabel: string;
  sheetsGuideHeading: string;
  sheetsGuideCloseAriaLabel: string;
  sheetsGuideIntro: string;
  sheetsGuideStep1: string;
  sheetsGuideStep2: string;
  sheetsGuideStep3: string;
  sheetsGuideExampleCodeLabel: string;
};

const EDITOR_FORM_CONTROLLER_PANEL_MESSAGES: Record<AppLocale, EditorFormControllerPanelMessages> = {
  en: {
    introTextPrefix:
      "This form is first submitted to the ",
    introTextSuffix:
      " endpoint on the public page, then processed internally or forwarded to a webhook depending on the settings.",

    submitTargetLabel: "Submit target",
    submitTargetOptionInternal: "Internal only (no webhook)",
    submitTargetOptionWebhook: "Forward to external webhook / Google Sheets",

    webhookUrlLabel: "Webhook URL (e.g. Google Apps Script web app URL)",
    webhookUrlPlaceholder: "e.g. https://script.google.com/macros/s/.../exec",

    payloadFormatLabel: "Payload format",
    payloadFormatOptionForm: "Form data (x-www-form-urlencoded)",
    payloadFormatOptionJson: "JSON (application/json)",

    httpMethodLabel: "HTTP method",

    authTokenLabel: "Authorization token (optional)",
    authTokenPlaceholder: "e.g. Bearer xxxxxx",

    extraParamsLabel: "Additional parameters (key=value lines, separated by line breaks)",
    extraParamsPlaceholder: "e.g.\nsource=landing\nformId=contact-hero",

    layoutSectionTitle: "Form layout",
    formWidthModeLabel: "Form width mode",
    formWidthModeOptionAuto: "Auto",
    formWidthModeOptionFull: "Full width",
    formWidthModeOptionFixed: "Fixed value",

    formFixedWidthLabel: "Form fixed width",

    formFixedWidthPresetNarrow: "Narrow",
    formFixedWidthPresetNormal: "Normal",
    formFixedWidthPresetWide: "Wide",

    marginYLabel: "Form top/bottom margin",
    marginYPresetNone: "None",
    marginYPresetCompact: "Compact",
    marginYPresetNormal: "Normal",
    marginYPresetSpacious: "Spacious",

    messagesSectionTitle: "Form messages",
    successMessageLabel: "Success message",
    successMessagePlaceholder: "e.g. Your message has been sent successfully.",
    errorMessageLabel: "Error message",
    errorMessagePlaceholder: "e.g. An error occurred while submitting.",

    controllerSectionTitle: "Form controller",
    fieldMappingLegend: "Form field mapping",
    fieldMappingAriaLabel: "Form field mapping",
    requiredLabel: "Required",

    submitButtonLabel: "Submit button",
    submitButtonAriaLabel: "Submit button",

    submitButtonNoneOptionLabel: "(None)",

    sheetsGuideButtonLabel: "Google Sheets integration guide",
    sheetsGuideHeading: "Google Sheets integration guide",
    sheetsGuideCloseAriaLabel: "Close Google Sheets integration guide",
    sheetsGuideIntro:
      "You must enter the Google Apps Script web app URL, not the spreadsheet URL itself. Follow the steps below to connect Google Sheets without writing code.",
    sheetsGuideStep1:
      "In Google Sheets, create a new spreadsheet and add headers like name, email, message in the first row.",
    sheetsGuideStep2:
      "From the menu, open \"Extensions → Apps Script\" and paste the example code below.",
    sheetsGuideStep3:
      "From \"Deploy → New deployment\", deploy as a web app and paste the issued web app URL (…/exec) into the Webhook URL field.",
    sheetsGuideExampleCodeLabel: "Example Apps Script code",
  },
  ko: {
    introTextPrefix:
      "이 폼은 퍼블릭 페이지에서 ",
    introTextSuffix:
      " 엔드포인트로 먼저 전송된 뒤, 설정에 따라 내부 처리 또는 Webhook 으로 전달됩니다.",

    submitTargetLabel: "전송 대상",
    submitTargetOptionInternal: "서버 처리 전용 (Webhook 없이 사용)",
    submitTargetOptionWebhook: "외부 Webhook / Google Sheets 로 전달",

    webhookUrlLabel: "Webhook URL (예: Google Apps Script 웹 앱 URL)",
    webhookUrlPlaceholder: "예: https://script.google.com/macros/s/.../exec",

    payloadFormatLabel: "전송 포맷",
    payloadFormatOptionForm: "폼 데이터 (x-www-form-urlencoded)",
    payloadFormatOptionJson: "JSON (application/json)",

    httpMethodLabel: "HTTP 메서드",

    authTokenLabel: "Authorization 토큰 (옵션)",
    authTokenPlaceholder: "예: Bearer xxxxxx",

    extraParamsLabel: "추가 파라미터 (key=value 형식, 줄바꿈으로 구분)",
    extraParamsPlaceholder: "예:\nsource=landing\nformId=contact-hero",

    layoutSectionTitle: "폼 레이아웃",
    formWidthModeLabel: "폼 너비 모드",
    formWidthModeOptionAuto: "자동",
    formWidthModeOptionFull: "전체 폭",
    formWidthModeOptionFixed: "고정 값",

    formFixedWidthLabel: "폼 고정 너비",

    formFixedWidthPresetNarrow: "좁게",
    formFixedWidthPresetNormal: "보통",
    formFixedWidthPresetWide: "넓게",

    marginYLabel: "폼 위/아래 여백",
    marginYPresetNone: "없음",
    marginYPresetCompact: "좁게",
    marginYPresetNormal: "보통",
    marginYPresetSpacious: "넓게",

    messagesSectionTitle: "폼 메시지",
    successMessageLabel: "성공 메시지",
    successMessagePlaceholder: "예: 성공적으로 전송되었습니다.",
    errorMessageLabel: "에러 메시지",
    errorMessagePlaceholder: "예: 전송 중 오류가 발생했습니다.",

    controllerSectionTitle: "폼 컨트롤러",
    fieldMappingLegend: "폼 필드 매핑",
    fieldMappingAriaLabel: "폼 필드 매핑",
    requiredLabel: "필수",

    submitButtonLabel: "Submit 버튼",
    submitButtonAriaLabel: "Submit 버튼",

    submitButtonNoneOptionLabel: "선택 안 함",

    sheetsGuideButtonLabel: "Google Sheets 연동 가이드",
    sheetsGuideHeading: "Google Sheets 연동 가이드",
    sheetsGuideCloseAriaLabel: "Google Sheets 연동 가이드 닫기",
    sheetsGuideIntro:
      "구글 시트 주소를 그대로 입력하는 것이 아니라, 시트에 연결된 Google Apps Script 웹 앱 URL 을 입력해야 합니다. 아래 순서를 따르면 코드를 잘 모르는 사용자도 연동할 수 있습니다.",
    sheetsGuideStep1:
      "Google Sheets 에서 새 스프레드시트를 만들고, 1행에 name, email, message 같은 헤더를 추가합니다.",
    sheetsGuideStep2:
      '시트 메뉴의 "확장 프로그램 → 앱스 스크립트" 를 열고 아래 예제 코드를 붙여넣습니다.',
    sheetsGuideStep3:
      '"배포 → 새 배포" 에서 웹 앱으로 배포한 뒤, 발급된 웹 앱 URL(…/exec) 을 Webhook URL 칸에 붙여넣습니다.',
    sheetsGuideExampleCodeLabel: "예시 Apps Script 코드",
  },
};

export function getEditorFormControllerPanelMessages(
  locale: AppLocale | null | undefined,
): EditorFormControllerPanelMessages {
  const key = (locale ?? DEFAULT_LOCALE) as AppLocale;
  return EDITOR_FORM_CONTROLLER_PANEL_MESSAGES[key] ?? EDITOR_FORM_CONTROLLER_PANEL_MESSAGES[DEFAULT_LOCALE];
}
