Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.platformIcons = exports.formatHTML = exports.formatXML = exports.formatJSON = exports.dateRelative = exports.dateDistance = void 0;

var _dateFns = require("date-fns");

const dateDistance = date => `${(0, _dateFns.formatDistanceToNowStrict)(date)} ago`;

exports.dateDistance = dateDistance;

const dateRelative = date => (0, _dateFns.formatRelative)(date, new Date());

exports.dateRelative = dateRelative;

const formatJSON = source => JSON.stringify(JSON.parse(source), null, 2);

exports.formatJSON = formatJSON;

const formatXML = source => {
  var xmlDoc = new DOMParser().parseFromString(source, "application/xml");
  var xsltDoc = new DOMParser().parseFromString(['<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">', '  <xsl:strip-space elements="*"/>', '  <xsl:template match="para[content-style][not(text())]">', '    <xsl:value-of select="normalize-space(.)"/>', "  </xsl:template>", '  <xsl:template match="node()|@*">', '    <xsl:copy><xsl:apply-templates select="node()|@*"/></xsl:copy>', "  </xsl:template>", '  <xsl:output indent="yes"/>', "</xsl:stylesheet>"].join("\n"), "application/xml");
  const xsltProcessor = new XSLTProcessor();
  xsltProcessor.importStylesheet(xsltDoc);
  const resultDoc = xsltProcessor.transformToDocument(xmlDoc);
  return new XMLSerializer().serializeToString(resultDoc);
};

exports.formatXML = formatXML;

const formatHTML = source => {
  var div = document.createElement("div");
  div.innerHTML = source.trim();
  return formatHTMLProcess(div, 0).innerHTML;
};

exports.formatHTML = formatHTML;

const formatHTMLProcess = (node, level) => {
  let indentBefore = new Array(level++ + 1).join("  "),
      indentAfter = new Array(level - 1).join("  "),
      textNode;

  for (var i = 0; i < node.children.length; i++) {
    textNode = document.createTextNode("\n" + indentBefore);
    node.insertBefore(textNode, node.children[i]);
    formatHTMLProcess(node.children[i], level);

    if (node.lastElementChild === node.children[i]) {
      textNode = document.createTextNode("\n" + indentAfter);
      node.appendChild(textNode);
    }
  }

  return node;
};

const platformIcons = {
  shopify: "https://cdn3.iconfinder.com/data/icons/popular-services-brands-vol-2/512/shopify-512.png",
  klaviyo: "https://d2.alternativeto.net/dist/icons/klaviyo_144349.jpg?width=200&height=200&mode=crop&upscale=false"
};
exports.platformIcons = platformIcons;
//# sourceMappingURL=utils.js.map