'use client';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useState } from 'react';
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter, } from '../../ui/dialog.js';
import { Button } from '../../ui/button.js';
import { Input } from '../../ui/input.js';
import { Label } from '../../ui/label.js';
import { Textarea } from '../../ui/textarea.js';
import { createPmProject } from '../../../app/actions/create-pm-project.js';
export function CreateProjectDialog({ open, onOpenChange, onCreated }) {
    const [name, setName] = useState('');
    const [prefix, setPrefix] = useState('');
    const [description, setDescription] = useState('');
    const [error, setError] = useState(null);
    const [submitting, setSubmitting] = useState(false);
    const handleSubmit = async () => {
        setError(null);
        setSubmitting(true);
        try {
            const result = await createPmProject({
                name,
                identifierPrefix: prefix,
                description: description || undefined,
            });
            if (result.error) {
                setError(result.error);
            }
            else if (result.project) {
                onCreated(result.project);
                setName('');
                setPrefix('');
                setDescription('');
            }
        }
        finally {
            setSubmitting(false);
        }
    };
    return (_jsx(Dialog, { open: open, onOpenChange: onOpenChange, children: _jsxs(DialogContent, { "data-testid": "create-project-dialog", children: [_jsx(DialogHeader, { children: _jsx(DialogTitle, { children: "Create Project" }) }), _jsxs("div", { className: "space-y-4 py-2", children: [_jsxs("div", { className: "space-y-2", children: [_jsx(Label, { htmlFor: "project-name", children: "Name" }), _jsx(Input, { id: "project-name", value: name, onChange: (e) => setName(e.target.value), placeholder: "My Project", "data-testid": "project-name-input" })] }), _jsxs("div", { className: "space-y-2", children: [_jsx(Label, { htmlFor: "project-prefix", children: "Identifier Prefix" }), _jsx(Input, { id: "project-prefix", value: prefix, onChange: (e) => setPrefix(e.target.value.toUpperCase()), placeholder: "PROJ", maxLength: 5, "data-testid": "project-prefix-input" }), _jsx("p", { className: "text-muted-foreground text-[10px]", children: "1-5 uppercase letters/numbers, used in work item identifiers (e.g., PROJ-42)" })] }), _jsxs("div", { className: "space-y-2", children: [_jsx(Label, { htmlFor: "project-desc", children: "Description (optional)" }), _jsx(Textarea, { id: "project-desc", value: description, onChange: (e) => setDescription(e.target.value), placeholder: "What is this project about?", rows: 3, "data-testid": "project-desc-input" })] }), error ? (_jsx("p", { className: "text-destructive text-xs", "data-testid": "create-project-error", children: error })) : null] }), _jsxs(DialogFooter, { children: [_jsx(Button, { variant: "outline", onClick: () => onOpenChange(false), disabled: submitting, children: "Cancel" }), _jsx(Button, { onClick: handleSubmit, disabled: !name.trim() || !prefix.trim() || submitting, "data-testid": "create-project-submit", children: submitting ? 'Creating...' : 'Create' })] })] }) }));
}
