"use client";
'use strict';

const jsxRuntime = require('react/jsx-runtime');
const React = require('react');
const reactErrorBoundary = require('react-error-boundary');
const layerRenderer = require('../../../../../../ui/src/components/ui-builder/layer-renderer.cjs');
const uiBuilderHooks = require('../hooks/ui-builder-hooks.cjs');
const registry = require('../registry.cjs');
const index = require('../localization/index.cjs');

function DefaultLoadingComponent() {
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center min-h-[200px]", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "animate-pulse text-muted-foreground", children: index.uiBuilderLocalization.pageRenderer.loading }) });
}
function DefaultErrorComponent({ error }) {
  return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col items-center justify-center min-h-[200px] p-4", children: [
    /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-destructive font-medium", children: index.uiBuilderLocalization.pageRenderer.error }),
    /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-sm text-muted-foreground mt-2", children: error.message })
  ] });
}
function DefaultNotFoundComponent() {
  return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex items-center justify-center min-h-[200px]", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-muted-foreground", children: index.uiBuilderLocalization.pageRenderer.notFound }) });
}
function PageRenderer({
  slug,
  componentRegistry = registry.defaultComponentRegistry,
  variableValues,
  functionRegistry,
  LoadingComponent = DefaultLoadingComponent,
  ErrorComponent = DefaultErrorComponent,
  NotFoundComponent = DefaultNotFoundComponent,
  className
}) {
  return /* @__PURE__ */ jsxRuntime.jsx(
    reactErrorBoundary.ErrorBoundary,
    {
      FallbackComponent: ({ error }) => /* @__PURE__ */ jsxRuntime.jsx(ErrorComponent, { error }),
      children: /* @__PURE__ */ jsxRuntime.jsx(React.Suspense, { fallback: /* @__PURE__ */ jsxRuntime.jsx(LoadingComponent, {}), children: /* @__PURE__ */ jsxRuntime.jsx(
        SuspensePageRendererContent,
        {
          slug,
          componentRegistry,
          variableValues,
          functionRegistry,
          NotFoundComponent,
          className
        }
      ) })
    }
  );
}
function SuspensePageRendererContent({
  slug,
  componentRegistry = registry.defaultComponentRegistry,
  variableValues,
  functionRegistry,
  NotFoundComponent = DefaultNotFoundComponent,
  className
}) {
  const { page, layers, variables } = uiBuilderHooks.useSuspenseUIBuilderPageBySlug(slug);
  if (!page || layers.length === 0) {
    return /* @__PURE__ */ jsxRuntime.jsx(NotFoundComponent, {});
  }
  const rootLayer = layers[0];
  if (!rootLayer) {
    return /* @__PURE__ */ jsxRuntime.jsx(NotFoundComponent, {});
  }
  return /* @__PURE__ */ jsxRuntime.jsx(
    layerRenderer,
    {
      className,
      page: rootLayer,
      componentRegistry,
      variables,
      variableValues,
      functionRegistry
    }
  );
}
function SuspensePageRenderer({
  slug,
  componentRegistry = registry.defaultComponentRegistry,
  variableValues,
  functionRegistry,
  NotFoundComponent = DefaultNotFoundComponent,
  className
}) {
  return /* @__PURE__ */ jsxRuntime.jsx(
    SuspensePageRendererContent,
    {
      slug,
      componentRegistry,
      variableValues,
      functionRegistry,
      NotFoundComponent,
      className
    }
  );
}

exports.PageRenderer = PageRenderer;
exports.SuspensePageRenderer = SuspensePageRenderer;
