"use client" import { useEffect, useState } from "react" import { Button } from "@/components/ui/button" import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog" import { Input } from "@/components/ui/input" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select" export type ExportFormat = "drawio" | "png" | "svg" const FORMAT_OPTIONS: { value: ExportFormat label: string extension: string }[] = [ { value: "drawio", label: "Draw.io XML", extension: ".drawio" }, { value: "png", label: "PNG Image", extension: ".png" }, { value: "svg", label: "SVG Image", extension: ".svg" }, ] interface SaveDialogProps { open: boolean onOpenChange: (open: boolean) => void onSave: (filename: string, format: ExportFormat) => void defaultFilename: string } export function SaveDialog({ open, onOpenChange, onSave, defaultFilename, }: SaveDialogProps) { const [filename, setFilename] = useState(defaultFilename) const [format, setFormat] = useState("drawio") useEffect(() => { if (open) { setFilename(defaultFilename) } }, [open, defaultFilename]) const handleSave = () => { const finalFilename = filename.trim() || defaultFilename onSave(finalFilename, format) onOpenChange(false) } const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === "Enter") { e.preventDefault() handleSave() } } const currentFormat = FORMAT_OPTIONS.find((f) => f.value === format) return ( Save Diagram Choose a format and filename to save your diagram.
setFilename(e.target.value)} onKeyDown={handleKeyDown} placeholder="Enter filename" autoFocus onFocus={(e) => e.target.select()} className="rounded-r-none border-r-0 focus-visible:z-10" /> {currentFormat?.extension || ".drawio"}
) }