import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
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 z from 'zod';
const adapterSchema = z.object({
    id: z.string(),
    name: z.string().min(1, 'Name is required'),
    bucketConfigVar: z.string().min(1, 'Bucket config variable is required'),
    hostedUrlConfigVar: z.string().optional(),
});
export function AdapterDialog({ open, onOpenChange, adapter, isNew = false, onSave, asChild, children, }) {
    const form = useForm({
        resolver: zodResolver(adapterSchema),
        values: adapter,
    });
    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 Adapter' : 'Edit Adapter' }), _jsx(DialogDescription, { children: isNew
                                        ? 'Enter the details for the new S3 adapter.'
                                        : 'Update the adapter details below.' })] }), _jsxs("div", { className: "storage:space-y-4 storage:py-4", children: [_jsx(InputFieldController, { label: "Adapter Name", name: "name", control: control, placeholder: "Enter adapter name" }), _jsx(InputFieldController, { label: "AWS Bucket Name Environment Variable", name: "bucketConfigVar", control: control, placeholder: "e.g. UPLOADS_BUCKET", description: "The environment variable that contains the name of the S3 bucket to use for this adapter." }), _jsx(InputFieldController, { label: "Bucket URL Prefix Environment Variable", name: "hostedUrlConfigVar", control: control, placeholder: "e.g. UPLOADS_URL_PREFIX", description: "The environment variable that contains the domain of the S3 bucket. Optional if bucket is not publicly accessible." })] }), _jsxs(DialogFooter, { children: [_jsx(Button, { type: "button", variant: "outline", onClick: () => {
                                        onOpenChange?.(false);
                                    }, children: "Cancel" }), _jsxs(Button, { form: formId, type: "submit", children: [isNew ? 'Add' : 'Update', " Adapter"] })] })] }) })] }));
}
//# sourceMappingURL=adapter-dialog.js.map