"use client"; import type React from "react"; import { useState } from "react"; import { cx } from "../lib/utils"; import { OnboardingButton } from "../primitives/onboarding-button"; import { OnboardingRadioCardGroup, OnboardingRadioCardIndicator, OnboardingRadioCardItem, } from "../primitives/onboarding-radio-card"; export interface SelectOption { value: string; label: string; } export interface SingleSelectStepProps { /** Title displayed at the top of the step */ title?: string; /** Description text below the title */ description?: string; /** Array of options to display */ options: SelectOption[]; /** Initially selected value */ defaultValue?: string; /** Called when selection changes */ onValueChange?: (value: string) => void; /** Called when the user submits the form */ onSubmit: (selectedValue: string) => void | Promise; /** Text for the submit button */ submitText?: string; /** Text shown while submitting */ loadingText?: string; /** Optional back button config */ backButton?: { text: string; onClick: () => void; }; /** Accessible label for the radio group */ ariaLabel?: string; } export function SingleSelectStep({ title = "Select an option", description = "This will help us customize the experience to you.", options, defaultValue = "", onValueChange, onSubmit, submitText = "Continue", loadingText = "Submitting...", backButton, ariaLabel, }: SingleSelectStepProps) { const [selectedValue, setSelectedValue] = useState(defaultValue); const [loading, setLoading] = useState(false); const handleValueChange = (value: string) => { setSelectedValue(value); onValueChange?.(value); }; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setLoading(true); try { await onSubmit(selectedValue); } finally { setLoading(false); } }; return (

{title}

{description}

{title} {options.map((option, index) => (
{option.label}
))}
{backButton && ( {backButton.text} )} {loading ? loadingText : submitText}
); }