"use client";
import { jsx } from "react/jsx-runtime";
import { useRouter } from "next/navigation";
import { EntityFormWrapper } from "../../entities/wrappers/EntityFormWrapper.js";
import { BuilderEditorView } from "../../dashboard/block-editor/builder-editor-view.js";
import { Alert, AlertDescription } from "../../ui/alert.js";
import { useEntityConfig } from "../../../hooks/useEntityConfig.js";
function PatternsCreatePage() {
  var _a;
  const router = useRouter();
  const entitySlug = "patterns";
  const { config: entityConfig, isLoading } = useEntityConfig(entitySlug);
  if (isLoading) {
    return /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center min-h-[400px]", children: /* @__PURE__ */ jsx("div", { className: "animate-spin rounded-full h-8 w-8 border-b-2 border-primary" }) });
  }
  if (!entityConfig || !entityConfig.enabled) {
    return /* @__PURE__ */ jsx(Alert, { children: /* @__PURE__ */ jsx(AlertDescription, { children: "Patterns entity is not configured or not enabled." }) });
  }
  if ((_a = entityConfig.builder) == null ? void 0 : _a.enabled) {
    return /* @__PURE__ */ jsx(
      BuilderEditorView,
      {
        entitySlug,
        entityConfig,
        mode: "create"
      }
    );
  }
  return /* @__PURE__ */ jsx(
    EntityFormWrapper,
    {
      entityType: entitySlug,
      mode: "create",
      onSuccess: (createdId) => {
        if (createdId) {
          router.push(`/dashboard/${entitySlug}/${createdId}`);
        } else {
          router.push(`/dashboard/${entitySlug}`);
        }
      },
      onError: (error) => {
        console.error(`Error creating pattern:`, error);
      }
    }
  );
}
export {
  PatternsCreatePage as default
};
