"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);
var fields_exports = {};
__export(fields_exports, {
  authorField: () => authorField,
  descriptionField: () => descriptionField,
  previewField: () => previewField
});
module.exports = __toCommonJS(fields_exports);
var import_jsx_runtime = require("react/jsx-runtime");
var import_clsx = __toESM(require("clsx"));
var import_components = require("@wordpress/components");
var import_i18n = require("@wordpress/i18n");
var import_element = require("@wordpress/element");
var import_html_entities = require("@wordpress/html-entities");
var import_blocks = require("@wordpress/blocks");
var import_block_editor = require("@wordpress/block-editor");
var import_editor = require("@wordpress/editor");
var import_hooks = require("./hooks");
var import_use_pattern_settings = __toESM(require("../page-patterns/use-pattern-settings"));
var import_lock_unlock = require("../../lock-unlock");
const { useGlobalStyle } = (0, import_lock_unlock.unlock)(import_block_editor.privateApis);
function PreviewField({ item }) {
  const settings = (0, import_use_pattern_settings.default)();
  const [backgroundColor = "white"] = useGlobalStyle("color.background");
  const blocks = (0, import_element.useMemo)(() => {
    return (0, import_blocks.parse)(item.content.raw);
  }, [item.content.raw]);
  const isEmpty = !blocks?.length;
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_editor.EditorProvider, { post: item, settings, children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
    "div",
    {
      className: "page-templates-preview-field",
      style: { backgroundColor },
      children: [
        isEmpty && (0, import_i18n.__)("Empty template"),
        !isEmpty && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_block_editor.BlockPreview.Async, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_block_editor.BlockPreview, { blocks }) })
      ]
    }
  ) });
}
const previewField = {
  label: (0, import_i18n.__)("Preview"),
  id: "preview",
  render: PreviewField,
  enableSorting: false
};
const descriptionField = {
  label: (0, import_i18n.__)("Description"),
  id: "description",
  render: ({ item }) => {
    return item.description && (0, import_html_entities.decodeEntities)(item.description);
  },
  enableSorting: false,
  enableGlobalSearch: true
};
function AuthorField({ item }) {
  const [isImageLoaded, setIsImageLoaded] = (0, import_element.useState)(false);
  const { text, icon, imageUrl } = (0, import_hooks.useAddedBy)(item.type, item.id);
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_components.__experimentalHStack, { alignment: "left", spacing: 0, children: [
    imageUrl && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
      "div",
      {
        className: (0, import_clsx.default)("page-templates-author-field__avatar", {
          "is-loaded": isImageLoaded
        }),
        children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
          "img",
          {
            onLoad: () => setIsImageLoaded(true),
            alt: "",
            src: imageUrl
          }
        )
      }
    ),
    !imageUrl && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "page-templates-author-field__icon", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_components.Icon, { icon }) }),
    /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "page-templates-author-field__name", children: text })
  ] });
}
const authorField = {
  label: (0, import_i18n.__)("Author"),
  id: "author",
  getValue: ({ item }) => item.author_text,
  render: AuthorField
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  authorField,
  descriptionField,
  previewField
});
//# sourceMappingURL=fields.js.map
