import { importShared } from './__federation_fn_import-BmYWUSaq.js';
import { j as jsxRuntimeExports } from './jsx-runtime-XI9uIe3W.js';
import { a, Q as QueueConfigTabs } from './styles-DAH5RtGb.js';
import { c as createBullmqPluginDefinitionSchema } from './plugin-definition-HMzTFa2y.js';

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

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

const {Alert,AlertDescription,AlertTitle,FormActionBar,InputFieldController,SectionList,SectionListSection,SectionListSectionContent,SectionListSectionDescription,SectionListSectionHeader,SectionListSectionTitle} = await importShared('@baseplate-dev/ui-components');
const {Link} = await importShared('@tanstack/react-router');

const {useMemo} = await importShared('react');
function BullmqDefinitionEditor({
  definition: pluginMetadata,
  metadata,
  onSave
}) {
  const { definitionContainer, saveDefinitionWithFeedback } = useProjectDefinition();
  const bullmqPluginDefinitionSchema = useDefinitionSchema(
    createBullmqPluginDefinitionSchema
  );
  const defaultValues = useMemo(() => {
    if (pluginMetadata?.config) {
      return pluginMetadata.config;
    }
    return {
      bullmqOptions: {
        deleteAfterDays: 7
      }
    };
  }, [pluginMetadata?.config]);
  const form = useResettableForm({
    resolver: a(bullmqPluginDefinitionSchema),
    defaultValues
  });
  const { control, reset, handleSubmit } = form;
  const onSubmit = handleSubmit(
    (data) => saveDefinitionWithFeedback(
      (draftConfig) => {
        PluginUtils.setPluginConfig(
          draftConfig,
          metadata,
          data,
          definitionContainer
        );
      },
      {
        successMessage: "Successfully saved BullMQ configuration!",
        onSuccess: () => {
          onSave();
        }
      }
    )
  );
  useBlockUnsavedChangesNavigate({ control, reset, onSubmit });
  const isRedisEnabled = definitionContainer.definition.settings.infrastructure?.redis?.enabled ?? false;
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "queue:relative queue:flex queue:h-full queue:flex-1 queue:flex-col queue:gap-4 queue:overflow-hidden", children: [
    /* @__PURE__ */ jsxRuntimeExports.jsx(QueueConfigTabs, {}),
    /* @__PURE__ */ jsxRuntimeExports.jsx(
      "div",
      {
        className: "queue:mb-[--action-bar-height] queue:flex queue:flex-1 queue:overflow-y-auto",
        style: {
          "--action-bar-height": "52px"
        },
        children: /* @__PURE__ */ jsxRuntimeExports.jsxs("form", { onSubmit, className: "queue:max-w-6xl queue:flex-1", children: [
          /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "queue:pb-16", children: [
            !isRedisEnabled && /* @__PURE__ */ jsxRuntimeExports.jsxs(Alert, { variant: "warning", className: "queue:mb-4", children: [
              /* @__PURE__ */ jsxRuntimeExports.jsx(AlertTitle, { children: "Redis Not Enabled" }),
              /* @__PURE__ */ jsxRuntimeExports.jsx(AlertDescription, { children: /* @__PURE__ */ jsxRuntimeExports.jsxs("p", { children: [
                "BullMQ requires Redis to be enabled. Please",
                " ",
                /* @__PURE__ */ jsxRuntimeExports.jsx(
                  Link,
                  {
                    to: "/settings/infrastructure",
                    className: "queue:inline-block queue:font-medium",
                    children: "enable Redis in infrastructure settings"
                  }
                ),
                " ",
                "before syncing."
              ] }) })
            ] }),
            /* @__PURE__ */ jsxRuntimeExports.jsx(SectionList, { children: /* @__PURE__ */ jsxRuntimeExports.jsxs(SectionListSection, { children: [
              /* @__PURE__ */ jsxRuntimeExports.jsxs(SectionListSectionHeader, { children: [
                /* @__PURE__ */ jsxRuntimeExports.jsx(SectionListSectionTitle, { children: "Queue Behavior" }),
                /* @__PURE__ */ jsxRuntimeExports.jsx(SectionListSectionDescription, { children: "Configure how BullMQ manages jobs and queues." })
              ] }),
              /* @__PURE__ */ jsxRuntimeExports.jsx(SectionListSectionContent, { className: "queue:space-y-6", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
                InputFieldController,
                {
                  label: "Delete After Days",
                  name: "bullmqOptions.deleteAfterDays",
                  control,
                  type: "number",
                  min: 1,
                  description: "Number of days to retain completed jobs before deletion",
                  registerOptions: {
                    valueAsNumber: true
                  }
                }
              ) })
            ] }) })
          ] }),
          /* @__PURE__ */ jsxRuntimeExports.jsx(FormActionBar, { form, allowSaveWithoutDirty: !pluginMetadata })
        ] })
      }
    )
  ] });
}

const {createPlatformPluginExport,webConfigSpec} = await importShared('@baseplate-dev/project-builder-lib');
const web = createPlatformPluginExport({
  dependencies: {
    webConfig: webConfigSpec
  },
  exports: {},
  initialize: ({ webConfig }, { pluginKey }) => {
    webConfig.registerWebConfigComponent(pluginKey, BullmqDefinitionEditor);
    return {};
  }
});

export { web as default };
//# sourceMappingURL=__federation_expose_bullmqCoreWeb-bQqpVYBp.js.map
