import { importShared } from './__federation_fn_import-UR7U68uv.js';
import { j as jsxRuntimeExports } from './jsx-runtime-XI9uIe3W.js';
import { s, Q as QueueConfigTabs } from './styles-D4kR8aSb.js';
import { c as createPgBossPluginDefinitionSchema } from './plugin-definition-A18JJ8gP.js';

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

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

const {FormActionBar,InputFieldController,SectionList,SectionListSection,SectionListSectionContent,SectionListSectionDescription,SectionListSectionHeader,SectionListSectionTitle} = await importShared('@baseplate-dev/ui-components');
const {useMemo} = await importShared('react');
function PgBossDefinitionEditor({
  definition: pluginMetadata,
  metadata,
  onSave
}) {
  const { definitionContainer, saveDefinitionWithFeedback } = useProjectDefinition();
  const pgBossPluginDefinitionSchema = useDefinitionSchema(
    createPgBossPluginDefinitionSchema
  );
  const defaultValues = useMemo(() => {
    if (pluginMetadata?.config) {
      return pluginMetadata.config;
    }
    return {
      pgBossOptions: {
        deleteAfterDays: 7
      }
    };
  }, [pluginMetadata?.config]);
  const form = useResettableForm({
    resolver: s(pgBossPluginDefinitionSchema),
    defaultValues
  });
  const { control, reset, handleSubmit } = form;
  const onSubmit = handleSubmit(
    (data) => saveDefinitionWithFeedback(
      (draftConfig) => {
        PluginUtils.setPluginConfig(
          draftConfig,
          metadata,
          data,
          definitionContainer.pluginStore
        );
      },
      {
        successMessage: "Successfully saved pg-boss configuration!",
        onSuccess: () => {
          onSave();
        }
      }
    )
  );
  useBlockUnsavedChangesNavigate({ control, reset, onSubmit });
  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.jsx("div", { className: "queue:pb-16", children: /* @__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 pg-boss manages jobs and queues." })
            ] }),
            /* @__PURE__ */ jsxRuntimeExports.jsx(SectionListSectionContent, { className: "queue:space-y-6", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
              InputFieldController,
              {
                label: "Delete After Days",
                name: "pgBossOptions.deleteAfterDays",
                control,
                type: "number",
                min: 1,
                description: "Number of days to retain completed jobs before deletion"
              }
            ) })
          ] }) }) }),
          /* @__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, PgBossDefinitionEditor);
    return {};
  }
});

export { web as default };
//# sourceMappingURL=__federation_expose_pg-bossCoreWeb-D8i_QuC_.js.map
