"use client"; import React, { type ReactNode, useState } from "react"; import { cx } from "../lib/utils"; import { OnboardingButton } from "../primitives/onboarding-button"; import { OnboardingCard } from "../primitives/onboarding-card"; import { OnboardingCheckbox } from "../primitives/onboarding-checkbox"; import { OnboardingLabel } from "../primitives/onboarding-label"; export interface IconOption { /** Unique identifier */ id: string; /** Display name */ name: string; /** Icon or logo - can be a ReactNode (e.g., Iconify icon) */ icon?: ReactNode; /** Optional description text */ description?: string; } export interface IconSelectStepProps { /** Title displayed at the top of the step */ title?: string; /** Description text below the title */ description?: string; /** Array of options to display */ options: IconOption[]; /** Selection mode: single or multiple */ selectionMode?: "single" | "multiple"; /** Initially selected option id(s) */ defaultSelected?: string[]; /** Called when selection changes */ onSelectionChange?: (selectedIds: string[]) => void; /** Called when the user submits the form */ onSubmit: (selectedIds: 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; }; } export function IconSelectStep({ title = "Select an option", description = "Choose the options that apply to you.", options, selectionMode = "multiple", defaultSelected = [], onSelectionChange, onSubmit, submitText = "Continue", loadingText = "Submitting...", backButton, }: IconSelectStepProps) { const [selectedIds, setSelectedIds] = useState(defaultSelected); const [loading, setLoading] = useState(false); const handleToggle = (id: string, checked: boolean) => { let newSelected: string[]; if (selectionMode === "single") { newSelected = checked ? [id] : []; } else { newSelected = checked ? [...selectedIds, id] : selectedIds.filter((selectedId) => selectedId !== id); } setSelectedIds(newSelected); onSelectionChange?.(newSelected); }; const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setLoading(true); try { await onSubmit(selectedIds); } finally { setLoading(false); } }; const isValid = selectedIds.length > 0; return (

{title}

{description}

{title}
{options.map((option, index) => { const isSelected = selectedIds.includes(option.id); return (
handleToggle(option.id, checked === true) } /> {option.icon && (
{option.icon}
)}
{option.name} {option.description && (

{option.description}

)}
); })}
{backButton && ( {backButton.text} )} {loading ? loadingText : submitText}
); }