import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useDefinitionSchema } from '@baseplate-dev/project-builder-lib/web';
import { Button, Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, InputFieldController, } from '@baseplate-dev/ui-components';
import { zodResolver } from '@hookform/resolvers/zod';
import { useId } from 'react';
import { useForm } from 'react-hook-form';
import { createAuthRoleSchema } from '../../schema/roles/schema.js';
export function RoleDialog({ open, onOpenChange, role, isNew = false, onSave, asChild, children, }) {
    const authRoleSchema = useDefinitionSchema(createAuthRoleSchema);
    const form = useForm({
        resolver: zodResolver(authRoleSchema),
        values: role,
    });
    const { control, handleSubmit } = form;
    const onSubmit = handleSubmit((data) => {
        onSave(data);
        onOpenChange?.(false);
    });
    const formId = useId();
    return (_jsxs(Dialog, { open: open, onOpenChange: onOpenChange, children: [_jsx(DialogTrigger, { asChild: asChild, children: children }), _jsx(DialogContent, { children: _jsxs("form", { id: formId, onSubmit: (e) => {
                        e.stopPropagation();
                        return onSubmit(e);
                    }, children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { children: isNew ? 'Add Role' : 'Edit Role' }), _jsx(DialogDescription, { children: isNew
                                        ? 'Enter the details for the new role.'
                                        : 'Update the role details below.' })] }), _jsxs("div", { className: "auth:space-y-4 auth:py-4", children: [_jsx(InputFieldController, { label: "Role Name", name: "name", control: control, placeholder: "Enter role name" }), _jsx(InputFieldController, { label: "Description", name: "comment", control: control, placeholder: "Describe this role's purpose" })] }), _jsxs(DialogFooter, { children: [_jsx(Button, { type: "button", variant: "outline", onClick: () => {
                                        onOpenChange?.(false);
                                    }, children: "Cancel" }), _jsxs(Button, { form: formId, type: "submit", children: [isNew ? 'Add' : 'Update', " Role"] })] })] }) })] }));
}
//# sourceMappingURL=role-dialog.js.map