"use client";
import { jsxs, jsx } from 'react/jsx-runtime';
import { usePluginOverrides, useBasePath } from '@btst/stack/context';
import { EditPostForm } 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 EditPostPage({ slug }) {
  const overrides = usePluginOverrides("blog", {
    localization: BLOG_LOCALIZATION
  });
  const { localization, navigate } = overrides;
  const basePath = useBasePath();
  useRouteLifecycle({
    routeName: "editPost",
    context: {
      path: `/blog/${slug}/edit`,
      params: { slug },
      isSSR: typeof window === "undefined"
    },
    overrides,
    beforeRenderHook: (overrides2, context) => {
      if (overrides2.onBeforeEditPostPageRendered) {
        return overrides2.onBeforeEditPostPageRendered(slug, context);
      }
      return true;
    }
  });
  const handleClose = () => {
    navigate(`${basePath}/blog`);
  };
  const handleSuccess = (post) => {
    navigate(`${basePath}/blog/${post.slug}`);
  };
  const handleDelete = () => {
    navigate(`${basePath}/blog`);
  };
  return /* @__PURE__ */ jsxs(PageWrapper, { className: "gap-6", testId: "edit-post-page", children: [
    /* @__PURE__ */ jsx(
      PageHeader,
      {
        title: localization.BLOG_POST_EDIT_TITLE,
        description: localization.BLOG_POST_EDIT_DESCRIPTION
      }
    ),
    /* @__PURE__ */ jsx(
      EditPostForm,
      {
        postSlug: slug,
        onClose: handleClose,
        onSuccess: handleSuccess,
        onDelete: handleDelete
      }
    )
  ] });
}

export { EditPostPage };
