"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 text_style_transformer_exports = {};
__export(text_style_transformer_exports, {
  TextStyleTransformer: () => TextStyleTransformer
});
module.exports = __toCommonJS(text_style_transformer_exports);
var A = __toESM(require("fp-ts-esm/Array"));
var import_function = require("fp-ts-esm/function");
var R = __toESM(require("fp-ts-esm/Record"));
var T = __toESM(require("fp-ts-esm/Tuple"));
var import_utils = require("./../ricos-content/lib/utils.js");
var import_decorations = require("./decorations/index.js");
var import_node_style = require("./document-style/node-style.js");
var import_text_style = require("./document-style/text-style.js");
var import_custom_styles = require("./textual-theme/custom-styles.js");
const documentToThemeKeyMap = {
  headerOne: "h1",
  headerTwo: "h2",
  headerThree: "h3",
  headerFour: "h4",
  headerFive: "h5",
  headerSix: "h6",
  paragraph: "p",
  blockquote: "quote",
  codeBlock: "codeBlock"
};
const themeToDocumentKeyMap = (0, import_function.pipe)(
  documentToThemeKeyMap,
  Object.entries,
  A.map(T.swap),
  import_utils.fromEntries
);
const toCustomStyle = (node) => ({
  ...import_decorations.Decorations.of(node?.decorations).toCustomStyle(),
  ...import_node_style.RicosNodeStyle.of(node?.nodeStyle).toCustomStyle(),
  ...import_text_style.RicosTextStyle.of({ lineHeight: node?.lineHeight }).toCustomStyle()
});
const toCustomStyleKey = (nodeType) => documentToThemeKeyMap[nodeType];
const toTuples = (documentStyle) => R.toArray(documentStyle);
const fromTuples = (tuple) => (0, import_utils.fromEntries)(tuple);
const toRicosCustomStyles = (0, import_function.flow)(
  toTuples,
  A.map(T.bimap(toCustomStyle, toCustomStyleKey)),
  fromTuples
);
const toTextNodeStyle = (customStyle) => ({
  decorations: import_decorations.Decorations.fromCustomStyle(customStyle).toDecorationArray(),
  nodeStyle: import_node_style.RicosNodeStyle.fromCustomStyle(customStyle).getNodeStyle(),
  lineHeight: import_text_style.RicosTextStyle.fromCustomStyle(customStyle).getTextStyle().lineHeight
});
const toTextNodeType = (customStyleKey) => themeToDocumentKeyMap[customStyleKey];
const toDocumentStyle = (0, import_function.flow)(
  // @ts-expect-error $TSFixMe
  Object.entries,
  A.map(T.bimap(toTextNodeStyle, toTextNodeType)),
  import_utils.fromEntries,
  JSON.stringify,
  JSON.parse
);
class TextStyleTransformer {
  constructor(theme) {
    this.theme = theme;
  }
  static fromTheme(theme) {
    return new TextStyleTransformer(theme || {});
  }
  static fromDocumentStyle(documentStyle) {
    const customStyles = toRicosCustomStyles(documentStyle);
    return new TextStyleTransformer({ customStyles });
  }
  toTheme() {
    return this.theme;
  }
  toDocumentStyle() {
    return toDocumentStyle(import_custom_styles.CustomStyles.fromTheme(this.theme).toCustomStyles());
  }
}
//# sourceMappingURL=text-style-transformer.js.map
