"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 ReadOnlyText_exports = {};
__export(ReadOnlyText_exports, {
  BlockElement: () => BlockElement,
  TextElement: () => TextElement,
  default: () => ReadOnlyText_default
});
module.exports = __toCommonJS(ReadOnlyText_exports);
var import_jsx_runtime = require("react/jsx-runtime");
var import_css = require("@emotion/css");
var import_react = require("react");
var import_controls = require("@makeswift/controls");
var import_responsive_style = require("../../../../components/utils/responsive-style");
var import_types = require("../../../../slate/types");
var import_use_style = require("../../use-style");
var import_typography = __toESM(require("../typography"));
var import_Link = require("../../../../components/shared/Link");
const ReadOnlyText = (0, import_react.forwardRef)(function ReadOnlyText2({ id, text, width, margin }, ref) {
  const descendants = text == null ? [] : (0, import_controls.richTextDTOtoDAO)(text);
  const descendantsAsString = getText(descendants);
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
    "div",
    {
      ref,
      id,
      style: {
        /**
         * These are the default styles that Slate uses for its editable div.
         * https://github.com/ianstormtaylor/slate/blob/4bd15ed3950e3a0871f5d0ecb391bb637c05e59d/packages/slate-react/src/components/editable.tsx
         * Search for `disableDefaultStyles`
         */
        position: "relative",
        whiteSpace: "pre-wrap",
        wordWrap: "break-word"
      },
      className: (0, import_css.cx)(width, margin),
      children: descendantsAsString === "" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Placeholder, {}) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Descendants, { descendants })
    }
  );
});
var ReadOnlyText_default = ReadOnlyText;
function Placeholder({ text = "Write some text..." }) {
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
    "span",
    {
      className: (0, import_use_style.useStyle)({
        display: "inline-block",
        width: 0,
        maxWidth: "100%",
        whiteSpace: "nowrap",
        opacity: 0.333,
        verticalAlign: "text-top"
      }),
      children: text
    }
  );
}
function TextElement({ descendant }) {
  const enhancedTypography = (0, import_typography.default)(descendant.typography);
  const typographyClassName = (0, import_typography.useTypographyClassName)(enhancedTypography);
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: typographyClassName, children: descendant.text === "" ? "\uFEFF" : descendant.text });
}
function InlineElement({ descendant }) {
  const linkClassName = (0, import_use_style.useStyle)({ textDecoration: "none" });
  switch (descendant.type) {
    case import_types.InlineType.Code:
      return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("code", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Descendants, { descendants: descendant.children }) });
    case import_types.InlineType.SuperScript:
      return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("sup", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Descendants, { descendants: descendant.children }) });
    case import_types.InlineType.SubScript:
      return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("sub", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Descendants, { descendants: descendant.children }) });
    case import_types.InlineType.Link:
      return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Link.Link, { className: linkClassName, link: descendant.link ?? void 0, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Descendants, { descendants: descendant.children }) });
  }
}
function BlockElement({ descendant }) {
  const blockStyles = [
    (0, import_use_style.useStyle)({ margin: 0 }),
    (0, import_use_style.useStyle)((0, import_responsive_style.useResponsiveStyle)([descendant.textAlign], ([textAlign = "left"]) => ({ textAlign })))
  ];
  const quoteStyle = (0, import_use_style.useStyle)({
    padding: "0.5em 10px",
    fontSize: "1.25em",
    fontWeight: "300",
    borderLeft: "5px solid rgba(0, 0, 0, 0.1)"
  });
  switch (descendant.type) {
    case import_types.BlockType.Default:
    case import_types.BlockType.Paragraph:
      return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: (0, import_css.cx)(...blockStyles), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Descendants, { descendants: descendant.children }) });
    case import_types.BlockType.Heading1:
      return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h1", { className: (0, import_css.cx)(...blockStyles), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Descendants, { descendants: descendant.children }) });
    case import_types.BlockType.Heading2:
      return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", { className: (0, import_css.cx)(...blockStyles), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Descendants, { descendants: descendant.children }) });
    case import_types.BlockType.Heading3:
      return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", { className: (0, import_css.cx)(...blockStyles), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Descendants, { descendants: descendant.children }) });
    case import_types.BlockType.Heading4:
      return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h4", { className: (0, import_css.cx)(...blockStyles), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Descendants, { descendants: descendant.children }) });
    case import_types.BlockType.Heading5:
      return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h5", { className: (0, import_css.cx)(...blockStyles), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Descendants, { descendants: descendant.children }) });
    case import_types.BlockType.Heading6:
      return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h6", { className: (0, import_css.cx)(...blockStyles), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Descendants, { descendants: descendant.children }) });
    case import_types.BlockType.BlockQuote:
      return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("blockquote", { className: (0, import_css.cx)(...blockStyles, quoteStyle), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Descendants, { descendants: descendant.children }) });
    case import_types.BlockType.OrderedList:
      return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("ol", { className: (0, import_css.cx)(...blockStyles), style: { listStylePosition: "inside" }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Descendants, { descendants: descendant.children }) });
    case import_types.BlockType.UnorderedList:
      return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("ul", { className: (0, import_css.cx)(...blockStyles), style: { listStylePosition: "inside" }, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Descendants, { descendants: descendant.children }) });
    case import_types.BlockType.ListItem:
      return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { className: (0, import_css.cx)(...blockStyles), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Descendants, { descendants: descendant.children }) });
    case import_types.BlockType.ListItemChild:
      return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: (0, import_css.cx)(...blockStyles), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Descendants, { descendants: descendant.children }) });
    default:
      return null;
  }
}
function Descendants({ descendants }) {
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children: descendants.map((descendant, index) => {
    if (import_controls.Slate.isText(descendant)) {
      return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TextElement, { descendant }, index);
    }
    switch (descendant.type) {
      case import_types.InlineType.Link:
      case import_types.InlineType.Code:
      case import_types.InlineType.SubScript:
      case import_types.InlineType.SuperScript:
        return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(InlineElement, { descendant }, index);
      case import_types.BlockType.Heading1:
      case import_types.BlockType.Heading2:
      case import_types.BlockType.Heading3:
      case import_types.BlockType.Heading4:
      case import_types.BlockType.Heading5:
      case import_types.BlockType.Heading6:
      case import_types.BlockType.BlockQuote:
      case import_types.BlockType.Paragraph:
      case import_types.BlockType.Default:
      case import_types.BlockType.OrderedList:
      case import_types.BlockType.UnorderedList:
      case import_types.BlockType.ListItem:
      case import_types.BlockType.ListItemChild:
        return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(BlockElement, { descendant }, index);
      default:
        return null;
    }
  }) });
}
function isBlock(descendant) {
  if ("text" in descendant)
    return false;
  switch (descendant.type) {
    case import_types.BlockType.Heading1:
    case import_types.BlockType.Heading2:
    case import_types.BlockType.Heading3:
    case import_types.BlockType.Heading4:
    case import_types.BlockType.Heading5:
    case import_types.BlockType.Heading6:
    case import_types.BlockType.BlockQuote:
    case import_types.BlockType.Paragraph:
    case import_types.BlockType.Default:
    case import_types.BlockType.OrderedList:
    case import_types.BlockType.UnorderedList:
    case import_types.BlockType.ListItem:
    case import_types.BlockType.ListItemChild:
      return true;
    default:
      return false;
  }
}
function getTextByDescendant(descendant) {
  if ("text" in descendant) {
    return descendant.text ?? "";
  }
  switch (descendant.type) {
    case import_types.InlineType.Link:
    case import_types.InlineType.Code:
    case import_types.InlineType.SubScript:
    case import_types.InlineType.SuperScript:
      return descendant.children.map((descendant2) => getTextByDescendant(descendant2)).join("") ?? "";
    case import_types.BlockType.Heading1:
    case import_types.BlockType.Heading2:
    case import_types.BlockType.Heading3:
    case import_types.BlockType.Heading4:
    case import_types.BlockType.Heading5:
    case import_types.BlockType.Heading6:
    case import_types.BlockType.BlockQuote:
    case import_types.BlockType.Paragraph:
    case import_types.BlockType.Default:
    case import_types.BlockType.OrderedList:
    case import_types.BlockType.UnorderedList:
    case import_types.BlockType.ListItem:
    case import_types.BlockType.ListItemChild:
      return descendant.children.map((descendant2) => getTextByDescendant(descendant2)).join(descendant.children.every(isBlock) ? "\n" : "") ?? "";
    default:
      return "";
  }
}
function getText(descendant) {
  return descendant.map(getTextByDescendant).join("\n");
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  BlockElement,
  TextElement
});
//# sourceMappingURL=ReadOnlyText.js.map