"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// packages/editor/src/components/template-actions-panel/classic-theme-content.js
var classic_theme_content_exports = {};
__export(classic_theme_content_exports, {
  default: () => ClassicThemeContent
});
module.exports = __toCommonJS(classic_theme_content_exports);
var import_data = require("@wordpress/data");
var import_core_data = require("@wordpress/core-data");
var import_block_editor = require("@wordpress/block-editor");
var import_components = require("@wordpress/components");
var import_element = require("@wordpress/element");
var import_i18n = require("@wordpress/i18n");
var import_html_entities = require("@wordpress/html-entities");
var import_notices = require("@wordpress/notices");
var import_preferences = require("@wordpress/preferences");
var import_store = require("../../store/index.cjs");
var import_create_new_template_modal = __toESM(require("../post-template/create-new-template-modal.cjs"));
var import_jsx_runtime = require("react/jsx-runtime");
function ClassicThemeContent() {
  const templateId = (0, import_data.useSelect)(
    (select) => select(import_store.store).getCurrentTemplateId(),
    []
  );
  const [isCreateModalOpen, setIsCreateModalOpen] = (0, import_element.useState)(false);
  const {
    onNavigateToEntityRecord,
    canCreateTemplate,
    hasGoBack,
    getEditorSettings
  } = (0, import_data.useSelect)((select) => {
    const { getEditorSettings: _getEditorSettings } = select(import_store.store);
    const editorSettings = _getEditorSettings();
    return {
      onNavigateToEntityRecord: editorSettings.onNavigateToEntityRecord,
      canCreateTemplate: !!select(import_core_data.store).canUser("create", {
        kind: "postType",
        name: "wp_template"
      }) && editorSettings.supportsTemplateMode,
      hasGoBack: editorSettings.hasOwnProperty(
        "onNavigateToPreviousEntityRecord"
      ),
      getEditorSettings: _getEditorSettings
    };
  }, []);
  const { get: getPreference } = (0, import_data.useSelect)(import_preferences.store);
  const { createSuccessNotice } = (0, import_data.useDispatch)(import_notices.store);
  const { editedRecord: template } = (0, import_core_data.useEntityRecord)(
    "postType",
    "wp_template",
    templateId
  );
  const [blocks] = (0, import_core_data.useEntityBlockEditor)("postType", "wp_template", {
    id: templateId
  });
  if (!templateId && !canCreateTemplate) {
    return null;
  }
  const notificationAction = hasGoBack ? [
    {
      label: (0, import_i18n.__)("Go back"),
      onClick: () => getEditorSettings().onNavigateToPreviousEntityRecord()
    }
  ] : void 0;
  const mayShowTemplateEditNotice = () => {
    if (!getPreference("core/edit-site", "welcomeGuideTemplate")) {
      createSuccessNotice(
        (0, import_i18n.__)(
          "Editing template. Changes made here affect all posts and pages that use the template."
        ),
        { type: "snackbar", actions: notificationAction }
      );
    }
  };
  const templateName = template ? (0, import_html_entities.decodeEntities)(template.title) : void 0;
  const previewContent = !!blocks?.length && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_block_editor.BlockPreview.Async, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_block_editor.BlockPreview, { blocks }) });
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
    /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
      import_components.PanelBody,
      {
        title: template ? (0, import_i18n.sprintf)(
          /* translators: %s: template name */
          (0, import_i18n.__)("Template: %s"),
          templateName
        ) : (0, import_i18n.__)("Template"),
        initialOpen: false,
        children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_components.__experimentalVStack, { children: [
          !templateId && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.__experimentalText, { children: (0, import_i18n.__)(
            "This page uses a classic template. To edit this template with blocks, create a block template."
          ) }),
          template && previewContent && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "editor-template-actions-panel__preview", children: previewContent }),
          /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_components.__experimentalHStack, { children: [
            template && onNavigateToEntityRecord && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
              import_components.Button,
              {
                className: "editor-template-actions-panel__action",
                __next40pxDefaultSize: true,
                variant: "secondary",
                onClick: () => {
                  onNavigateToEntityRecord({
                    postId: template.id,
                    postType: "wp_template"
                  });
                  mayShowTemplateEditNotice();
                },
                children: (0, import_i18n.__)("Edit")
              }
            ),
            canCreateTemplate && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
              import_components.Button,
              {
                className: "editor-template-actions-panel__action",
                __next40pxDefaultSize: true,
                variant: "secondary",
                onClick: () => setIsCreateModalOpen(true),
                children: !templateId ? (0, import_i18n.__)("Create block template") : (0, import_i18n.__)("Create new")
              }
            )
          ] })
        ] })
      }
    ),
    isCreateModalOpen && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
      import_create_new_template_modal.default,
      {
        onClose: () => setIsCreateModalOpen(false)
      }
    )
  ] });
}
//# sourceMappingURL=classic-theme-content.cjs.map
