"use client"; import "./components/ui/tidal.css"; import { useId, useLayoutEffect, useMemo, useRef, useState } from "react"; import { TidalImportWizard, type TidalImportFileSummary, type TidalImportStep } from "./components/ui/import-wizard"; import type { TidalColumnMapping } from "./components/ui/column-mapper"; import "./components/ui/column-mapper.css"; import "./components/ui/import-wizard.css"; import "./components/ui/native-select.css"; const tidalExampleStyles = ".tidal-scope .import-wizard-demo {\n display: grid;\n width: min(100%, 900px);\n min-width: 0;\n gap: 14px;\n}\n\n.tidal-scope .import-wizard-adapter {\n display: flex;\n min-width: 0;\n align-items: center;\n justify-content: center;\n gap: 10px;\n}\n\n.tidal-scope .import-wizard-adapter input {\n position: absolute;\n width: 1px;\n height: 1px;\n overflow: hidden;\n clip-path: inset(50%);\n}\n\n.tidal-scope .import-wizard-adapter > span {\n color: var(--t-muted);\n font-size: 11px;\n}\n\n.tidal-scope .import-wizard-result {\n display: grid;\n justify-items: start;\n gap: 10px;\n padding: 22px;\n border: 1px solid var(--t-line);\n border-radius: 16px;\n background: var(--t-subtle);\n}\n\n.tidal-scope .import-wizard-result strong {\n font-size: 18px;\n line-height: 1.2;\n}\n\n.tidal-scope .import-wizard-result p,\n.tidal-scope .import-wizard-status {\n margin: 0;\n color: var(--t-muted);\n font-size: 12px;\n line-height: 1.55;\n overflow-wrap: anywhere;\n}\n\n.tidal-scope .import-wizard-result button {\n min-width: 44px;\n min-height: 44px;\n padding: 10px 15px;\n border: 1px solid var(--t-ink);\n border-radius: 10px;\n background: var(--t-ink);\n color: var(--t-surface);\n font: inherit;\n font-size: 12px;\n font-weight: 700;\n cursor: pointer;\n}\n\n.tidal-scope .import-wizard-result button:focus-visible {\n outline: 2px solid var(--t-ink);\n outline-offset: 3px;\n}\n\n.tidal-scope .import-wizard-status {\n padding-inline: 4px;\n}\n\n@container tidal-import (max-width: 440px) {\n .tidal-scope .import-wizard-adapter {\n align-items: stretch;\n flex-direction: column;\n }\n\n .tidal-scope .import-wizard-adapter > span {\n text-align: center;\n }\n}"; const sources = [ { id: "full_name", label: "full_name", sample: "Avery Morgan" }, { id: "email", label: "email", sample: "avery@example.test" }, { id: "company", label: "company", sample: "Northstar" }, ]; const fields = [ { id: "name", label: "Name", required: true }, { id: "email", label: "Email address", required: true }, { id: "organization", label: "Company" }, ]; const preview = { columns: [ { id: "name", label: "Name" }, { id: "email", label: "Email address" }, { id: "organization", label: "Company" }, ], rows: [ { id: "row-1", cells: { name: "Avery Morgan", email: "avery@example.test", organization: "Northstar", }, }, { id: "row-2", cells: { name: "Noah Chen", email: "noah@example.test", organization: "Field Office", }, }, { id: "row-3", cells: { name: "Mila Ortiz", email: "missing address", organization: "Studio", }, issue: "Email needs review", }, ], totalRows: 3, }; const sampleFile: TidalImportFileSummary = { id: "sample-contacts-csv", name: "sample-contacts.csv", size: "1.4 KB", type: "CSV sample", rowCount: 3, status: "valid", statusLabel: "Ready for mapping", }; export function ImportWizardDemo() { const nativeId = useId().replace(/:/g, ""); const [step, setStep] = useState("file"); const [file, setFile] = useState(); const [fileError, setFileError] = useState(); const [mapping, setMapping] = useState({ name: "full_name", email: "email", organization: "company", }); const [status, setStatus] = useState( "Choose the fictional sample to prepare an import plan locally.", ); const nativeInputRef = useRef(null); const sampleButtonRef = useRef(null); const resetButtonRef = useRef(null); const focusIntent = useRef<{ expected: TidalImportStep; origin: HTMLButtonElement; } | null>(null); const requiredReady = useMemo( () => Boolean(mapping.name && mapping.email), [mapping], ); const reset = () => { setStep("file"); setFile(undefined); setFileError(undefined); setMapping({ name: "full_name", email: "email", organization: "company" }); if (nativeInputRef.current) nativeInputRef.current.value = ""; setStatus("Sample reset locally."); }; useLayoutEffect(() => { const intent = focusIntent.current; if (!intent || intent.expected !== step) return; const active = intent.origin.ownerDocument.activeElement; if ( active === intent.origin || active === intent.origin.ownerDocument.body || !(active instanceof HTMLElement) || !active.isConnected ) { (step === "result" ? resetButtonRef.current : sampleButtonRef.current )?.focus({ preventScroll: true }); } focusIntent.current = null; }, [step]); return (
{ setStep(next); setStatus(`${next[0].toUpperCase()}${next.slice(1)} step opened.`); }} file={file} fileError={fileError} fileAdapter={
{ const selected = event.currentTarget.files?.[0]; if (!selected) return; setFile({ id: `local-${selected.name}`, name: selected.name, size: `${Math.max(1, Math.ceil(selected.size / 1024))} KB`, type: selected.type || "Unknown file type", status: "invalid", statusLabel: "Not parsed by this demo", }); setFileError( "This preview does not read files. Use the fictional sample to continue.", ); setStatus( "Only local file metadata was read by the native input.", ); }} /> or
} sources={sources} fields={fields} mapping={mapping} onMappingChange={(next) => { setMapping(next); setStatus("Mapping updated locally."); }} preview={preview} canContinue={ step === "file" ? file?.id === sampleFile.id : step === "mapping" ? requiredReady : true } formProps={{ action: "#prepared-import-plan", method: "get", }} submitButtonProps={{ name: "intent", value: "prepare-import-plan", formAction: "#sample-import-plan", }} onImportPlan={(_plan, event) => { event.preventDefault(); setStep("progress"); setStatus("Import plan prepared locally. No rows were imported."); }} onDownloadErrorRows={(event) => { event.preventDefault(); setStatus( "Error-row download requested locally. No file was generated.", ); }} onCancelProgress={() => { setStep("review"); setStatus("Sample preparation cancelled locally."); }} progress={{ value: 3, max: 4, label: "Preparing sample plan", valueLabel: "3 of 4 checks", description: "Local preview state only.", actions: ( ), }} result={
Import plan ready

Three fictional rows and the selected mapping are ready for the consumer callback. Nothing was uploaded or imported.

} />

{status}

); } export default function AgentExample() { return (
); }