import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { authConfigSpec, PluginUtils, } from '@baseplate-dev/project-builder-lib';
import { useProjectDefinition } from '@baseplate-dev/project-builder-lib/web';
import { InputFieldController, MultiComboboxFieldController, SelectFieldController, } from '@baseplate-dev/ui-components';
import { STORAGE_MODELS } from '#src/storage/constants/model-names.js';
import '#src/styles.css';
export function FileTransformerForm({ name, formProps: { control }, originalModel, pluginKey, }) {
    const prefix = name;
    const controlTyped = control;
    const { definition, pluginContainer, definitionContainer } = useProjectDefinition();
    const storageConfig = PluginUtils.configByKeyOrThrow(definition, pluginKey ?? '');
    const fileRelations = originalModel.model.relations?.filter((relation) => definitionContainer.nameFromId(relation.modelRef) ===
        STORAGE_MODELS.file) ?? [];
    const relationOptions = fileRelations.map((relation) => ({
        label: relation.name,
        value: relation.id,
    }));
    // Get available auth roles
    const roleOptions = pluginContainer
        .getPluginSpec(authConfigSpec)
        .getAuthRoles(definition)
        .map((role) => ({
        label: role.name,
        value: role.id,
    }));
    // Get available storage adapters
    const adapterOptions = storageConfig.s3Adapters.map((adapter) => ({
        label: adapter.name,
        value: adapter.id,
    }));
    return (_jsxs("div", { className: "storage:space-y-6", children: [_jsx(SelectFieldController, { className: "storage:w-full", control: controlTyped, label: "File Relation", name: `${prefix}.fileRelationRef`, options: relationOptions, placeholder: "Select a file relation..." }), _jsxs("div", { className: "storage:space-y-4 storage:rounded-lg storage:border storage:p-4", children: [_jsx("h3", { className: "storage:text-lg storage:font-medium storage:text-foreground", children: "File Category Configuration" }), _jsxs("div", { className: "sm:storage:grid-cols-2 storage:grid storage:grid-cols-1 storage:gap-4", children: [_jsx(InputFieldController, { className: "storage:w-full", control: controlTyped, label: "Category Name", name: `${prefix}.category.name`, placeholder: "e.g., USER_PROFILE_AVATAR", description: "Must be CONSTANT_CASE format" }), _jsx(InputFieldController, { className: "storage:w-full", control: controlTyped, label: "Max File Size (MB)", name: `${prefix}.category.maxFileSizeMb`, type: "number", placeholder: "e.g., 10", description: "Maximum file size in megabytes", registerOptions: {
                                    valueAsNumber: true,
                                } })] }), _jsxs("div", { className: "sm:storage:grid-cols-2 storage:grid storage:grid-cols-1 storage:gap-4", children: [_jsx(MultiComboboxFieldController, { className: "storage:w-full", control: controlTyped, label: "Upload Roles", name: `${prefix}.category.authorize.uploadRoles`, options: roleOptions, placeholder: "Select roles that can upload...", description: "User roles authorized to upload files" }), _jsx(SelectFieldController, { className: "storage:w-full", control: controlTyped, label: "Storage Adapter", name: `${prefix}.category.adapterRef`, options: adapterOptions, placeholder: "Select storage adapter...", description: "Where files will be stored" })] })] })] }));
}
//# sourceMappingURL=file-transformer-form.js.map