"use client";
import { jsx } from 'react/jsx-runtime';
import { lazy } from 'react';
import { usePluginOverrides } from '@btst/stack/context';
import { ComposedRoute } from '@btst/stack/client/components';
import { DefaultError } from '../shared/default-error.mjs';
import { NotFoundPage } from './404-page.mjs';
import { EditorSkeleton } from '../loading/editor-skeleton.mjs';

const ContentEditorPageInternal = lazy(
  () => import('./content-editor-page.internal.mjs').then((m) => ({
    default: m.ContentEditorPage
  }))
);
function ContentEditorPageComponent({
  typeSlug,
  id
}) {
  const { onRouteError } = usePluginOverrides("cms");
  const isNew = !id;
  const path = isNew ? `/cms/${typeSlug}/new` : `/cms/${typeSlug}/${id}`;
  return /* @__PURE__ */ jsx(
    ComposedRoute,
    {
      path,
      PageComponent: ContentEditorPageInternal,
      ErrorComponent: DefaultError,
      LoadingComponent: EditorSkeleton,
      NotFoundComponent: NotFoundPage,
      props: { typeSlug, id },
      onError: (error) => {
        if (onRouteError) {
          onRouteError("contentEditor", error, {
            path,
            params: { typeSlug, id: id ?? "" },
            isSSR: typeof window === "undefined"
          });
        }
      }
    }
  );
}

export { ContentEditorPageComponent };
