"use client" import * as React from "react" import Script from "next/script" import { cn } from "cn" import { useIsMobile } from "@/hooks/use-mobile" import { Button } from "@/styles/base-nova/ui/button" import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from "@/styles/base-nova/ui/dialog" import { Drawer, DrawerClose, DrawerContent, DrawerDescription, DrawerFooter, DrawerHeader, DrawerTitle, DrawerTrigger, } from "@/styles/base-nova/ui/drawer" import { Field, FieldContent, FieldLabel } from "@/styles/base-nova/ui/field" import { Input } from "@/styles/base-nova/ui/input" import { OPEN_PRESET_FORWARD_TYPE, useOpenPreset, } from "@/app/(app)/(create)/hooks/use-open-preset" import { parsePresetInput } from "@/app/(app)/(create)/lib/parse-preset-input" import { useDesignSystemSearchParams } from "@/app/(app)/(create)/lib/search-params" const PRESET_EXAMPLE = "b2D0wqNxT" const PRESET_TITLE = "Open Preset" const PRESET_DESCRIPTION = "Paste a preset code to load a saved configuration." export function OpenPreset({ className, label = "Open Preset", }: React.ComponentProps & { label?: string }) { const [input, setInput] = React.useState("") const [, setParams] = useDesignSystemSearchParams() const isMobile = useIsMobile() const { open, setOpen } = useOpenPreset() const nextPreset = React.useMemo(() => parsePresetInput(input), [input]) const isInvalid = input.trim().length > 0 && nextPreset === null const handleOpenChange = React.useCallback( (nextOpen: boolean) => { setOpen(nextOpen) if (!nextOpen) { setInput("") } }, [setOpen] ) const handleSubmit = React.useCallback( (event: React.FormEvent) => { event.preventDefault() if (!nextPreset) { return } setParams({ preset: nextPreset }) handleOpenChange(false) }, [handleOpenChange, nextPreset, setParams] ) const triggerClassName = cn( "touch-manipulation bg-transparent! px-2! py-0! text-sm! transition-none select-none hover:bg-muted! pointer-coarse:h-10!", className ) const desktopTrigger = ( } > Cancel ) } return ( {label}
{PRESET_TITLE} {PRESET_DESCRIPTION}
{fields}
}> Cancel
) } export function OpenPresetScript() { return (