import type { DomesticOptionsConfig, DomesticQuestionType } from "@/types/participant";

/** Client/server-safe form state for domestic question content. */
export interface DomesticContentValues {
  type: DomesticQuestionType;
  prompt: string;
  helpText: string;
  purpose: string;
  options: Array<{ value?: string; label: string }>;
  min: string;
  max: string;
  minLabel: string;
  maxLabel: string;
}

export function contentValuesFrom(current: {
  type: DomesticQuestionType;
  prompt: string;
  helpText: string | null;
  purpose: string | null;
  optionsConfig: DomesticOptionsConfig | null;
} | null): DomesticContentValues {
  return {
    type: current?.type ?? "single_choice",
    prompt: current?.prompt ?? "",
    helpText: current?.helpText ?? "",
    purpose: current?.purpose ?? "",
    options: current?.optionsConfig?.options?.map((o) => ({ ...o })) ?? [
      { label: "" },
      { label: "" },
    ],
    min: current?.optionsConfig?.min != null ? String(current.optionsConfig.min) : "",
    max: current?.optionsConfig?.max != null ? String(current.optionsConfig.max) : "",
    minLabel: current?.optionsConfig?.minLabel ?? "",
    maxLabel: current?.optionsConfig?.maxLabel ?? "",
  };
}
