"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 NewPostPage() {
  const overrides = context.usePluginOverrides("blog", {
    localization: index.BLOG_LOCALIZATION
  });
  const { localization, navigate } = overrides;
  const basePath = context.useBasePath();
  useRouteLifecycle.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 formRef = React.useRef(null);
  const handleFormReady = React.useCallback((form) => {
    formRef.current = form;
  }, []);
  context$1.useRegisterPageAIContext({
    routeName: "blog-new-post",
    pageDescription: "User is creating a new blog post in the admin editor. IMPORTANT: When asked to write, draft, or create a blog post, you MUST call the fillBlogForm tool to populate the form fields directly \u2014 do NOT just output the text in your response.",
    suggestions: [
      "Write a post about AI trends",
      "Draft an intro paragraph",
      "Suggest 5 tags for this post"
    ],
    clientTools: {
      fillBlogForm: fillBlogFormHandler.createFillBlogFormHandler(
        formRef,
        "Form filled successfully"
      )
    }
  });
  const handleClose = () => {
    navigate(`${basePath}/blog`);
  };
  const handleSuccess = (post) => {
    if (post.published) {
      navigate(`${basePath}/blog`);
    } else {
      navigate(`${basePath}/blog/drafts`);
    }
  };
  return /* @__PURE__ */ jsxRuntime.jsxs(pageWrapper.PageWrapper, { className: "gap-6", testId: "new-post-page", children: [
    /* @__PURE__ */ jsxRuntime.jsx(
      pageHeader.PageHeader,
      {
        title: localization.BLOG_POST_ADD_TITLE,
        description: localization.BLOG_POST_ADD_DESCRIPTION
      }
    ),
    /* @__PURE__ */ jsxRuntime.jsx(
      postForms.AddPostForm,
      {
        onClose: handleClose,
        onSuccess: handleSuccess,
        onFormReady: handleFormReady
      }
    )
  ] });
}

exports.NewPostPage = NewPostPage;
