"use client";
import { jsxs, jsx } from 'react/jsx-runtime';
import { usePluginOverrides, useBasePath } from '@btst/stack/context';
import { AddPostForm } from '../forms/post-forms.mjs';
import { PageHeader } from '../shared/page-header.mjs';
import { PageWrapper } from '../shared/page-wrapper.mjs';
import { BLOG_LOCALIZATION } from '../../localization/index.mjs';
import { useRouteLifecycle } from '../../../../../../../ui/src/hooks/use-route-lifecycle.mjs';

function NewPostPage() {
  const overrides = usePluginOverrides("blog", {
    localization: BLOG_LOCALIZATION
  });
  const { localization, navigate } = overrides;
  const basePath = useBasePath();
  useRouteLifecycle({
    routeName: "newPost",
    context: {
      path: "/blog/new",
      isSSR: typeof window === "undefined"
    },
    overrides,
    beforeRenderHook: (overrides2, context) => {
      if (overrides2.onBeforeNewPostPageRendered) {
        return overrides2.onBeforeNewPostPageRendered(context);
      }
      return true;
    }
  });
  const handleClose = () => {
    navigate(`${basePath}/blog`);
  };
  const handleSuccess = (post) => {
    if (post.published) {
      navigate(`${basePath}/blog`);
    } else {
      navigate(`${basePath}/blog/drafts`);
    }
  };
  return /* @__PURE__ */ jsxs(PageWrapper, { className: "gap-6", testId: "new-post-page", children: [
    /* @__PURE__ */ jsx(
      PageHeader,
      {
        title: localization.BLOG_POST_ADD_TITLE,
        description: localization.BLOG_POST_ADD_DESCRIPTION
      }
    ),
    /* @__PURE__ */ jsx(AddPostForm, { onClose: handleClose, onSuccess: handleSuccess })
  ] });
}

export { NewPostPage };
