"use client";
'use strict';

const jsxRuntime = require('react/jsx-runtime');
const context = require('@btst/stack/context');
const postForms = require('../forms/post-forms.cjs');
const pageHeader = require('../shared/page-header.cjs');
const pageWrapper = require('../shared/page-wrapper.cjs');
const index = require('../../localization/index.cjs');
const useRouteLifecycle = require('../../../../../../../ui/src/hooks/use-route-lifecycle.cjs');
const context$1 = require('@btst/stack/plugins/ai-chat/client/context');
const React = require('react');
const fillBlogFormHandler = require('./fill-blog-form-handler.cjs');

function EditPostPage({ slug }) {
  const overrides = context.usePluginOverrides("blog", {
    localization: index.BLOG_LOCALIZATION
  });
  const { localization, navigate } = overrides;
  const basePath = context.useBasePath();
  useRouteLifecycle.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 formRef = React.useRef(null);
  const handleFormReady = React.useCallback((form) => {
    formRef.current = form;
  }, []);
  context$1.useRegisterPageAIContext({
    routeName: "blog-edit-post",
    pageDescription: `User is editing a blog post (slug: "${slug}") in the admin editor.`,
    suggestions: [
      "Improve this post's title",
      "Rewrite the intro paragraph",
      "Suggest better tags"
    ],
    clientTools: {
      fillBlogForm: fillBlogFormHandler.createFillBlogFormHandler(
        formRef,
        "Form updated successfully"
      )
    }
  });
  const handleClose = () => {
    navigate(`${basePath}/blog`);
  };
  const handleSuccess = (post) => {
    navigate(`${basePath}/blog/${post.slug}`);
  };
  const handleDelete = () => {
    navigate(`${basePath}/blog`);
  };
  return /* @__PURE__ */ jsxRuntime.jsxs(pageWrapper.PageWrapper, { className: "gap-6", testId: "edit-post-page", children: [
    /* @__PURE__ */ jsxRuntime.jsx(
      pageHeader.PageHeader,
      {
        title: localization.BLOG_POST_EDIT_TITLE,
        description: localization.BLOG_POST_EDIT_DESCRIPTION
      }
    ),
    /* @__PURE__ */ jsxRuntime.jsx(
      postForms.EditPostForm,
      {
        postSlug: slug,
        onClose: handleClose,
        onSuccess: handleSuccess,
        onDelete: handleDelete,
        onFormReady: handleFormReady
      }
    )
  ] });
}

exports.EditPostPage = EditPostPage;
