"use client"; import { Edit2 } from "lucide-react"; import React, { type ReactNode, useState } from "react"; import { cx } from "../lib/utils"; import { OnboardingButton } from "../primitives/onboarding-button"; import { OnboardingCard } from "../primitives/onboarding-card"; export interface SummarySection { /** Section title */ title: string; /** Icon for the section */ icon?: ReactNode; /** Items in this section */ items: SummaryItem[]; /** Optional edit action */ onEdit?: () => void; } export interface SummaryItem { /** Label for the item */ label: string; /** Value to display */ value: string | string[] | ReactNode; /** Optional icon */ icon?: ReactNode; } export interface SummaryStepProps { /** Title displayed at the top of the step */ title?: string; /** Description text below the title */ description?: string; /** Sections to display */ sections: SummarySection[]; /** Called when the user submits the form */ onSubmit: () => 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 SummaryStep({ title = "Review your selections", description = "Please review your choices before continuing.", sections, onSubmit, submitText = "Confirm & Continue", loadingText = "Submitting...", backButton, }: SummaryStepProps) { const [loading, setLoading] = useState(false); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setLoading(true); try { await onSubmit(); } finally { setLoading(false); } }; const renderValue = (value: string | string[] | ReactNode) => { if (Array.isArray(value)) { return ( ); } if (typeof value === "string") { return ( {value} ); } return value; }; return (

{title}

{description}

{sections.map((section, sectionIndex) => (
{section.icon && (
{section.icon}
)}

{section.title}

{section.onEdit && ( )}
{section.items.map((item, itemIndex) => (
{item.icon} {item.label}
{renderValue(item.value)}
))}
))}
{backButton && ( {backButton.text} )} {loading ? loadingText : submitText}
); }