'use client';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useEffect, useState } from 'react';
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from '../../ui/dialog.js';
import { Input } from '../../ui/input.js';
import { Button } from '../../ui/button.js';
export function WorkspaceNameDialog({ open, onOpenChange, title, description, initialValue = '', confirmLabel, onConfirm, }) {
    const [value, setValue] = useState(initialValue);
    useEffect(() => {
        if (open)
            setValue(initialValue);
    }, [open, initialValue]);
    const handleSubmit = (e) => {
        e.preventDefault();
        const trimmed = value.trim();
        if (!trimmed)
            return;
        onConfirm(trimmed);
        onOpenChange(false);
    };
    return (_jsx(Dialog, { open: open, onOpenChange: onOpenChange, children: _jsx(DialogContent, { className: "max-w-sm", children: _jsxs("form", { onSubmit: handleSubmit, children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { children: title }), description ? _jsx(DialogDescription, { children: description }) : null] }), _jsx("div", { className: "py-4", children: _jsx(Input, { autoFocus: true, value: value, onChange: (e) => setValue(e.target.value), placeholder: "Workspace name", "data-testid": "workspace-name-input" }) }), _jsxs(DialogFooter, { children: [_jsx(Button, { type: "button", variant: "ghost", onClick: () => onOpenChange(false), children: "Cancel" }), _jsx(Button, { type: "submit", disabled: !value.trim(), children: confirmLabel })] })] }) }) }));
}
