import { importShared } from './__federation_fn_import-B0FfK6vm.js';
import { j as jsxRuntimeExports } from './jsx-runtime-XI9uIe3W.js';
import { g as get, s as set, c as appendErrors, a as useForm, d as useFieldArray, e as useWatch } from './index.esm-eDWylCkL.js';
import { l as parse, m as parseAsync, K as $ZodError } from './registries-Tz_dluz3.js';
import { S as STORAGE_MODELS } from './model-names-BRVtMdoR.js';
import { s as storageAdapterEntityType, c as createFileCategorySchema, f as fileCategoryEntityType, a as createStoragePluginDefinitionSchema } from './plugin-definition-OkLTrrL5.js';
/* empty css                */

const r=(t,r,o)=>{if(t&&"reportValidity"in t){const s=get(o,r);t.setCustomValidity(s&&s.message||""),t.reportValidity();}},o=(e,t)=>{for(const o in t.fields){const s=t.fields[o];s&&s.ref&&"reportValidity"in s.ref?r(s.ref,o,e):s&&s.refs&&s.refs.forEach(t=>r(t,o,e));}},s$1=(r,s)=>{s.shouldUseNativeValidation&&o(r,s);const n={};for(const o in r){const f=get(s.fields,o),c=Object.assign(r[o]||{},{ref:f&&f.ref});if(i$1(s.names||Object.keys(r),o)){const r=Object.assign({},get(n,o));set(r,"root",c),set(n,o,r);}else set(n,o,c);}return n},i$1=(e,t)=>{const r=n(t);return e.some(e=>n(e).match(`^${r}\\.\\d+`))};function n(e){return e.replace(/\]|\[/g,"")}

function t(r,e){try{var o=r();}catch(r){return e(r)}return o&&o.then?o.then(void 0,e):o}function s(r,e){for(var n={};r.length;){var t=r[0],s=t.code,i=t.message,a=t.path.join(".");if(!n[a])if("unionErrors"in t){var u=t.unionErrors[0].errors[0];n[a]={message:u.message,type:u.code};}else n[a]={message:i,type:s};if("unionErrors"in t&&t.unionErrors.forEach(function(e){return e.errors.forEach(function(e){return r.push(e)})}),e){var c=n[a].types,f=c&&c[t.code];n[a]=appendErrors(a,e,n,s,f?[].concat(f,t.message):t.message);}r.shift();}return n}function i(r,e){for(var n={};r.length;){var t=r[0],s=t.code,i=t.message,a=t.path.join(".");if(!n[a])if("invalid_union"===t.code&&t.errors.length>0){var u=t.errors[0][0];n[a]={message:u.message,type:u.code};}else n[a]={message:i,type:s};if("invalid_union"===t.code&&t.errors.forEach(function(e){return e.forEach(function(e){return r.push(e)})}),e){var c=n[a].types,f=c&&c[t.code];n[a]=appendErrors(a,e,n,s,f?[].concat(f,t.message):t.message);}r.shift();}return n}function a(o$1,a,u){if(void 0===u&&(u={}),function(r){return "_def"in r&&"object"==typeof r._def&&"typeName"in r._def}(o$1))return function(n,i,c){try{return Promise.resolve(t(function(){return Promise.resolve(o$1["sync"===u.mode?"parse":"parseAsync"](n,a)).then(function(e){return c.shouldUseNativeValidation&&o({},c),{errors:{},values:u.raw?Object.assign({},n):e}})},function(r){if(function(r){return Array.isArray(null==r?void 0:r.issues)}(r))return {values:{},errors:s$1(s(r.errors,!c.shouldUseNativeValidation&&"all"===c.criteriaMode),c)};throw r}))}catch(r){return Promise.reject(r)}};if(function(r){return "_zod"in r&&"object"==typeof r._zod}(o$1))return function(s,c,f){try{return Promise.resolve(t(function(){return Promise.resolve(("sync"===u.mode?parse:parseAsync)(o$1,s,a)).then(function(e){return f.shouldUseNativeValidation&&o({},f),{errors:{},values:u.raw?Object.assign({},s):e}})},function(r){if(function(r){return r instanceof $ZodError}(r))return {values:{},errors:s$1(i(r.issues,!f.shouldUseNativeValidation&&"all"===f.criteriaMode),f)};throw r}))}catch(r){return Promise.reject(r)}};throw new Error("Invalid input: not a Zod schema")}

const {FeatureUtils: FeatureUtils$1} = await importShared('@baseplate-dev/project-builder-lib');
function createStoragePartialDefinition(storageFeatureName, userModelName) {
  return {
    features: FeatureUtils$1.createPartialFeatures(storageFeatureName),
    models: [
      {
        name: STORAGE_MODELS.file,
        featureRef: storageFeatureName,
        model: {
          fields: [
            {
              name: "id",
              type: "uuid",
              options: { genUuid: true }
            },
            // Core fields
            {
              name: "filename",
              type: "string"
            },
            {
              name: "mimeType",
              type: "string"
            },
            {
              name: "encoding",
              type: "string",
              isOptional: true
            },
            {
              name: "size",
              type: "int",
              isOptional: true
            },
            // Storage info
            {
              name: "category",
              type: "string"
            },
            {
              name: "adapter",
              type: "string"
            },
            {
              name: "storagePath",
              type: "string"
            },
            // Upload lifecycle
            {
              name: "pendingUpload",
              type: "boolean",
              options: { default: "false" }
            },
            // Relations
            {
              name: "uploaderId",
              type: "uuid",
              isOptional: true
            },
            // Timestamps
            {
              name: "createdAt",
              type: "dateTime",
              options: { defaultToNow: true }
            },
            {
              name: "updatedAt",
              type: "dateTime",
              options: { defaultToNow: true, updatedAt: true }
            }
          ],
          primaryKeyFieldRefs: ["id"],
          relations: [
            {
              name: "uploader",
              references: [{ localRef: "uploaderId", foreignRef: "id" }],
              modelRef: userModelName,
              foreignRelationName: "files",
              onDelete: "Cascade",
              onUpdate: "Restrict"
            }
          ]
        },
        graphql: {
          objectType: {
            enabled: true,
            fields: [{ ref: "id" }, { ref: "filename" }]
          }
        }
      }
    ]
  };
}

const {Button: Button$3,Dialog: Dialog$1,DialogContent: DialogContent$1,DialogDescription: DialogDescription$1,DialogFooter: DialogFooter$1,DialogHeader: DialogHeader$1,DialogTitle: DialogTitle$1,InputFieldController: InputFieldController$1} = await importShared('@baseplate-dev/ui-components');
const {useId: useId$1} = await importShared('react');
const z = await importShared('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()
});
function AdapterDialog({
  open,
  onOpenChange,
  adapter,
  isNew = false,
  onSave
}) {
  const form = useForm({
    resolver: a(adapterSchema),
    values: adapter
  });
  const { control, handleSubmit } = form;
  const onSubmit = handleSubmit((data) => {
    onSave(data);
    onOpenChange?.(false);
  });
  const formId = useId$1();
  return /* @__PURE__ */ jsxRuntimeExports.jsx(Dialog$1, { open, onOpenChange, children: /* @__PURE__ */ jsxRuntimeExports.jsx(DialogContent$1, { children: /* @__PURE__ */ jsxRuntimeExports.jsxs(
    "form",
    {
      id: formId,
      onSubmit: (e) => {
        e.stopPropagation();
        return onSubmit(e);
      },
      children: [
        /* @__PURE__ */ jsxRuntimeExports.jsxs(DialogHeader$1, { children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(DialogTitle$1, { children: isNew ? "Add Adapter" : "Edit Adapter" }),
          /* @__PURE__ */ jsxRuntimeExports.jsx(DialogDescription$1, { children: isNew ? "Enter the details for the new S3 adapter." : "Update the adapter details below." })
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "storage:space-y-4 storage:py-4", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(
            InputFieldController$1,
            {
              label: "Adapter Name",
              name: "name",
              control,
              placeholder: "Enter adapter name"
            }
          ),
          /* @__PURE__ */ jsxRuntimeExports.jsx(
            InputFieldController$1,
            {
              label: "AWS Bucket Name Environment Variable",
              name: "bucketConfigVar",
              control,
              placeholder: "e.g. UPLOADS_BUCKET",
              description: "The environment variable that contains the name of the S3 bucket to use for this adapter."
            }
          ),
          /* @__PURE__ */ jsxRuntimeExports.jsx(
            InputFieldController$1,
            {
              label: "Bucket URL Prefix Environment Variable",
              name: "hostedUrlConfigVar",
              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."
            }
          )
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs(DialogFooter$1, { children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(
            Button$3,
            {
              type: "button",
              variant: "outline",
              onClick: () => {
                onOpenChange?.(false);
              },
              children: "Cancel"
            }
          ),
          /* @__PURE__ */ jsxRuntimeExports.jsxs(Button$3, { form: formId, type: "submit", children: [
            isNew ? "Add" : "Update",
            " Adapter"
          ] })
        ] })
      ]
    }
  ) }) });
}

const {Button: Button$2,RecordView: RecordView$1,RecordViewActions: RecordViewActions$1,RecordViewItem: RecordViewItem$1,RecordViewItemList: RecordViewItemList$1,SectionListSection: SectionListSection$2,SectionListSectionContent: SectionListSectionContent$2,SectionListSectionDescription: SectionListSectionDescription$2,SectionListSectionHeader: SectionListSectionHeader$2,SectionListSectionTitle: SectionListSectionTitle$2,useConfirmDialog: useConfirmDialog$1} = await importShared('@baseplate-dev/ui-components');

const {useState: useState$1} = await importShared('react');
function AdapterEditorForm({ className, control }) {
  const { requestConfirm } = useConfirmDialog$1();
  const { append, update, remove } = useFieldArray({
    control,
    name: "s3Adapters"
  });
  const [adapterToEdit, setAdapterToEdit] = useState$1();
  const [isEditing, setIsEditing] = useState$1(false);
  const adapters = useWatch({ control, name: "s3Adapters" });
  function handleSaveAdapter(newAdapter) {
    const existingIndex = adapters.findIndex(
      (adapter) => adapter.id === newAdapter.id
    );
    if (existingIndex === -1) {
      append(newAdapter);
    } else {
      update(existingIndex, newAdapter);
    }
  }
  function handleDeleteAdapter(adapterIdx) {
    const adapter = adapters[adapterIdx];
    requestConfirm({
      title: "Delete Adapter",
      content: `Are you sure you want to delete the adapter "${adapter.name}"?`,
      onConfirm: () => {
        remove(adapterIdx);
      }
    });
  }
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(SectionListSection$2, { className, children: [
    /* @__PURE__ */ jsxRuntimeExports.jsxs(SectionListSectionHeader$2, { children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(SectionListSectionTitle$2, { children: "S3 Adapters" }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(SectionListSectionDescription$2, { children: "Configure S3 storage adapters for file uploads. Each adapter can have its own bucket and configuration." })
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs(SectionListSectionContent$2, { className: "storage:space-y-4", children: [
      adapters.map((adapter, adapterIdx) => /* @__PURE__ */ jsxRuntimeExports.jsxs(RecordView$1, { children: [
        /* @__PURE__ */ jsxRuntimeExports.jsxs(RecordViewItemList$1, { children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(RecordViewItem$1, { title: "Name", children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "storage:flex storage:items-center storage:gap-2", children: /* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: adapter.name }) }) }),
          /* @__PURE__ */ jsxRuntimeExports.jsx(RecordViewItem$1, { title: "Bucket Config Variable", children: adapter.bucketConfigVar || /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "storage:text-muted-foreground", children: "Not configured" }) }),
          /* @__PURE__ */ jsxRuntimeExports.jsx(RecordViewItem$1, { title: "URL Prefix Config Variable", children: adapter.hostedUrlConfigVar ?? /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "storage:text-muted-foreground", children: "Not configured" }) })
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs(RecordViewActions$1, { children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(
            Button$2,
            {
              variant: "ghost",
              size: "icon",
              title: "Edit",
              "aria-label": "Edit adapter",
              onClick: () => {
                setAdapterToEdit(adapter);
                setIsEditing(true);
              },
              children: "Edit"
            }
          ),
          /* @__PURE__ */ jsxRuntimeExports.jsx(
            Button$2,
            {
              variant: "ghostDestructive",
              size: "icon",
              title: "Delete",
              "aria-label": "Delete adapter",
              onClick: () => {
                handleDeleteAdapter(adapterIdx);
              },
              children: "Delete"
            }
          )
        ] })
      ] }, adapter.id)),
      /* @__PURE__ */ jsxRuntimeExports.jsx(
        AdapterDialog,
        {
          open: isEditing,
          onOpenChange: setIsEditing,
          adapter: adapterToEdit,
          isNew: adapterToEdit ? !adapters.some((a) => a.id === adapterToEdit.id) : true,
          onSave: handleSaveAdapter
        }
      ),
      /* @__PURE__ */ jsxRuntimeExports.jsx(
        Button$2,
        {
          variant: "secondary",
          size: "sm",
          onClick: () => {
            setAdapterToEdit({
              id: storageAdapterEntityType.generateNewId(),
              name: "",
              bucketConfigVar: "",
              hostedUrlConfigVar: ""
            });
            setIsEditing(true);
          },
          children: "Add Adapter"
        }
      )
    ] })
  ] });
}

const {authConfigSpec} = await importShared('@baseplate-dev/project-builder-lib');

const {useDefinitionSchema: useDefinitionSchema$1,useProjectDefinition: useProjectDefinition$1} = await importShared('@baseplate-dev/project-builder-lib/web');

const {Button: Button$1,Dialog,DialogContent,DialogDescription,DialogFooter,DialogHeader,DialogTitle,InputFieldController,MultiComboboxFieldController,SelectFieldController,SwitchFieldController} = await importShared('@baseplate-dev/ui-components');
const {useId} = await importShared('react');
function FileCategoryDialog({
  open,
  onOpenChange,
  category,
  isNew = false,
  onSave,
  parentControl
}) {
  const { definition, pluginContainer } = useProjectDefinition$1();
  const fileCategorySchema = useDefinitionSchema$1(createFileCategorySchema);
  const form = useForm({
    resolver: a(fileCategorySchema),
    values: category
  });
  const { control, handleSubmit } = form;
  const onSubmit = handleSubmit((data) => {
    onSave(data);
    onOpenChange?.(false);
  });
  const formId = useId();
  const roleOptions = pluginContainer.use(authConfigSpec).getAuthConfigOrThrow(definition).roles.map((role) => ({
    label: role.name,
    value: role.id
  }));
  const adapters = useWatch({ control: parentControl, name: "s3Adapters" });
  const adapterOptions = adapters.map((adapter) => ({
    label: adapter.name,
    value: adapter.id
  }));
  return /* @__PURE__ */ jsxRuntimeExports.jsx(Dialog, { open, onOpenChange, children: /* @__PURE__ */ jsxRuntimeExports.jsx(DialogContent, { children: /* @__PURE__ */ jsxRuntimeExports.jsxs(
    "form",
    {
      id: formId,
      onSubmit: (e) => {
        e.stopPropagation();
        return onSubmit(e);
      },
      children: [
        /* @__PURE__ */ jsxRuntimeExports.jsxs(DialogHeader, { children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(DialogTitle, { children: isNew ? "Add File Category" : "Edit File Category" }),
          /* @__PURE__ */ jsxRuntimeExports.jsx(DialogDescription, { children: isNew ? "Enter the details for the new file category." : "Update the file category details below." })
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "storage:space-y-4 storage:py-4", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(
            InputFieldController,
            {
              label: "Category Name",
              name: "name",
              control,
              placeholder: "e.g., USER_PROFILE_AVATAR",
              description: "Must be CONSTANT_CASE format"
            }
          ),
          /* @__PURE__ */ jsxRuntimeExports.jsx(
            InputFieldController,
            {
              label: "Max File Size (MB)",
              name: "maxFileSizeMb",
              control,
              type: "number",
              placeholder: "e.g., 10",
              description: "Maximum file size in megabytes",
              registerOptions: {
                valueAsNumber: true
              }
            }
          ),
          /* @__PURE__ */ jsxRuntimeExports.jsx(
            MultiComboboxFieldController,
            {
              label: "Upload Roles",
              name: "authorize.uploadRoles",
              control,
              options: roleOptions,
              placeholder: "Select roles that can upload...",
              description: "User roles authorized to upload files"
            }
          ),
          /* @__PURE__ */ jsxRuntimeExports.jsx(
            SelectFieldController,
            {
              label: "Storage Adapter",
              name: "adapterRef",
              control,
              options: adapterOptions,
              placeholder: "Select storage adapter...",
              description: "Where files will be stored"
            }
          ),
          /* @__PURE__ */ jsxRuntimeExports.jsx(
            SwitchFieldController,
            {
              label: "Disable Auto-Cleanup",
              name: "disableAutoCleanup",
              control,
              description: "When enabled, files in this category will not be automatically cleaned up"
            }
          )
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs(DialogFooter, { children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(
            Button$1,
            {
              type: "button",
              variant: "outline",
              onClick: () => {
                onOpenChange?.(false);
              },
              children: "Cancel"
            }
          ),
          /* @__PURE__ */ jsxRuntimeExports.jsxs(Button$1, { form: formId, type: "submit", children: [
            isNew ? "Add" : "Update",
            " Category"
          ] })
        ] })
      ]
    }
  ) }) });
}

const {Button,RecordView,RecordViewActions,RecordViewItem,RecordViewItemList,SectionListSection: SectionListSection$1,SectionListSectionContent: SectionListSectionContent$1,SectionListSectionDescription: SectionListSectionDescription$1,SectionListSectionHeader: SectionListSectionHeader$1,SectionListSectionTitle: SectionListSectionTitle$1,useConfirmDialog} = await importShared('@baseplate-dev/ui-components');

const {useState} = await importShared('react');
function FileCategoryEditorForm({
  className,
  control
}) {
  const { requestConfirm } = useConfirmDialog();
  const { append, update, remove } = useFieldArray({
    control,
    name: "fileCategories"
  });
  const [categoryToEdit, setCategoryToEdit] = useState();
  const [isEditing, setIsEditing] = useState(false);
  const categories = useWatch({ control, name: "fileCategories" }) ?? [];
  function handleSaveCategory(newCategory) {
    const existingIndex = categories.findIndex(
      (cat) => cat.id === newCategory.id
    );
    if (existingIndex === -1) {
      append(newCategory);
    } else {
      update(existingIndex, newCategory);
    }
  }
  function handleDeleteCategory(categoryIdx) {
    const category = categories[categoryIdx];
    requestConfirm({
      title: "Delete File Category",
      content: `Are you sure you want to delete the file category "${category.name}"?`,
      onConfirm: () => {
        remove(categoryIdx);
      }
    });
  }
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(SectionListSection$1, { className, children: [
    /* @__PURE__ */ jsxRuntimeExports.jsxs(SectionListSectionHeader$1, { children: [
      /* @__PURE__ */ jsxRuntimeExports.jsx(SectionListSectionTitle$1, { children: "File Categories" }),
      /* @__PURE__ */ jsxRuntimeExports.jsx(SectionListSectionDescription$1, { children: "Configure file categories that define upload constraints, storage adapters, and authorization rules for file uploads." })
    ] }),
    /* @__PURE__ */ jsxRuntimeExports.jsxs(SectionListSectionContent$1, { className: "storage:space-y-4", children: [
      categories.map((category, categoryIdx) => /* @__PURE__ */ jsxRuntimeExports.jsxs(RecordView, { children: [
        /* @__PURE__ */ jsxRuntimeExports.jsxs(RecordViewItemList, { children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(RecordViewItem, { title: "Name", children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "storage:flex storage:items-center storage:gap-2", children: /* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: category.name }) }) }),
          /* @__PURE__ */ jsxRuntimeExports.jsxs(RecordViewItem, { title: "Max File Size", children: [
            category.maxFileSizeMb,
            " MB"
          ] }),
          category.disableAutoCleanup ? /* @__PURE__ */ jsxRuntimeExports.jsx(RecordViewItem, { title: "Auto-Cleanup", children: /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "storage:text-muted-foreground", children: "Disabled" }) }) : null
        ] }),
        /* @__PURE__ */ jsxRuntimeExports.jsxs(RecordViewActions, { children: [
          /* @__PURE__ */ jsxRuntimeExports.jsx(
            Button,
            {
              variant: "ghost",
              size: "icon",
              title: "Edit",
              "aria-label": "Edit file category",
              onClick: () => {
                setCategoryToEdit(category);
                setIsEditing(true);
              },
              children: "Edit"
            }
          ),
          /* @__PURE__ */ jsxRuntimeExports.jsx(
            Button,
            {
              variant: "ghostDestructive",
              size: "icon",
              title: "Delete",
              "aria-label": "Delete file category",
              onClick: () => {
                handleDeleteCategory(categoryIdx);
              },
              children: "Delete"
            }
          )
        ] })
      ] }, category.id)),
      /* @__PURE__ */ jsxRuntimeExports.jsx(
        FileCategoryDialog,
        {
          open: isEditing,
          onOpenChange: setIsEditing,
          category: categoryToEdit,
          isNew: categoryToEdit ? !categories.some((c) => c.id === categoryToEdit.id) : true,
          onSave: handleSaveCategory,
          parentControl: control
        }
      ),
      /* @__PURE__ */ jsxRuntimeExports.jsx(
        Button,
        {
          variant: "secondary",
          size: "sm",
          onClick: () => {
            setCategoryToEdit({
              id: fileCategoryEntityType.generateNewId(),
              name: "",
              maxFileSizeMb: 20,
              authorize: { uploadRoles: [] },
              adapterRef: ""
            });
            setIsEditing(true);
          },
          children: "Add File Category"
        }
      )
    ] })
  ] });
}

const {applyMergedDefinition,authModelsSpec,diffDefinition,FeatureUtils,PluginUtils} = await importShared('@baseplate-dev/project-builder-lib');

const {DefinitionDiffAlert,FeatureComboboxFieldController,useBlockUnsavedChangesNavigate,useDefinitionSchema,useProjectDefinition,useResettableForm} = await importShared('@baseplate-dev/project-builder-lib/web');

const {FormActionBar,SectionList,SectionListSection,SectionListSectionContent,SectionListSectionDescription,SectionListSectionHeader,SectionListSectionTitle} = await importShared('@baseplate-dev/ui-components');
const {useMemo} = await importShared('react');
function StorageDefinitionEditor({
  definition: pluginMetadata,
  metadata,
  onSave
}) {
  const { definition, definitionContainer, saveDefinitionWithFeedback } = useProjectDefinition();
  const storagePluginDefinitionSchema = useDefinitionSchema(
    createStoragePluginDefinitionSchema
  );
  const defaultValues = useMemo(() => {
    if (pluginMetadata?.config) {
      return pluginMetadata.config;
    }
    return {
      storageFeatureRef: FeatureUtils.getFeatureIdByNameOrDefault(
        definition,
        "storage"
      ),
      s3Adapters: []
    };
  }, [definition, pluginMetadata?.config]);
  const form = useResettableForm({
    resolver: a(storagePluginDefinitionSchema),
    defaultValues
  });
  const { control, reset, handleSubmit, watch } = form;
  const storageFeatureRef = watch("storageFeatureRef");
  const authModels = definitionContainer.pluginStore.use(authModelsSpec);
  const userModelName = authModels.getAuthModelsOrThrow(definition).user;
  const storageFeatureName = FeatureUtils.resolveFeatureName(
    definition,
    storageFeatureRef
  );
  const partialDef = useMemo(
    () => createStoragePartialDefinition(storageFeatureName, userModelName),
    [storageFeatureName, userModelName]
  );
  const diff = useMemo(
    () => diffDefinition(
      definitionContainer.schema,
      definitionContainer.definition,
      partialDef
    ),
    [definitionContainer, partialDef]
  );
  const onSubmit = handleSubmit(
    (data) => saveDefinitionWithFeedback(
      (draftConfig) => {
        const featureName = FeatureUtils.resolveFeatureName(
          draftConfig,
          data.storageFeatureRef
        );
        const updatedPartialDef = createStoragePartialDefinition(
          featureName,
          userModelName
        );
        applyMergedDefinition(
          definitionContainer,
          updatedPartialDef
        )(draftConfig);
        PluginUtils.setPluginConfig(
          draftConfig,
          metadata,
          {
            ...data,
            storageFeatureRef: FeatureUtils.getFeatureIdByNameOrThrow(
              draftConfig,
              featureName
            )
          },
          definitionContainer
        );
      },
      {
        successMessage: pluginMetadata ? "Successfully saved storage plugin!" : "Successfully enabled storage plugin!",
        onSuccess: () => {
          onSave();
        }
      }
    )
  );
  useBlockUnsavedChangesNavigate({ control, reset, onSubmit });
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(
    "form",
    {
      onSubmit,
      className: "storage:mb-[--action-bar-height] storage:max-w-6xl",
      children: [
        /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "storage:pb-16", children: /* @__PURE__ */ jsxRuntimeExports.jsxs(SectionList, { children: [
          /* @__PURE__ */ jsxRuntimeExports.jsxs(SectionListSection, { children: [
            /* @__PURE__ */ jsxRuntimeExports.jsxs(SectionListSectionHeader, { children: [
              /* @__PURE__ */ jsxRuntimeExports.jsx(SectionListSectionTitle, { children: "Storage Configuration" }),
              /* @__PURE__ */ jsxRuntimeExports.jsx(SectionListSectionDescription, { children: "Configure your storage settings, file models, and S3 adapters." })
            ] }),
            /* @__PURE__ */ jsxRuntimeExports.jsxs(SectionListSectionContent, { className: "storage:space-y-6", children: [
              /* @__PURE__ */ jsxRuntimeExports.jsx(
                DefinitionDiffAlert,
                {
                  diff,
                  upToDateMessage: "All required models are already configured correctly. No changes needed."
                }
              ),
              /* @__PURE__ */ jsxRuntimeExports.jsx(
                FeatureComboboxFieldController,
                {
                  label: "Storage Feature Path",
                  name: "storageFeatureRef",
                  control,
                  canCreate: true,
                  description: "Specify the feature path where storage endpoints will be generated"
                }
              )
            ] })
          ] }),
          /* @__PURE__ */ jsxRuntimeExports.jsx(AdapterEditorForm, { control }),
          /* @__PURE__ */ jsxRuntimeExports.jsx(FileCategoryEditorForm, { control })
        ] }) }),
        /* @__PURE__ */ jsxRuntimeExports.jsx(
          FormActionBar,
          {
            form,
            allowSaveWithoutDirty: !pluginMetadata || diff.hasChanges
          }
        )
      ]
    }
  );
}

const {createPluginModule,webConfigSpec} = await importShared('@baseplate-dev/project-builder-lib');
const web = createPluginModule({
  name: "web",
  dependencies: {
    webConfig: webConfigSpec
  },
  initialize: ({ webConfig }, { pluginKey }) => {
    webConfig.components.set(pluginKey, StorageDefinitionEditor);
  }
});

export { web as default };
//# sourceMappingURL=__federation_expose_storageCoreWeb-D_lUpkgR.js.map
