import ne from "../../../@babel/runtime/helpers/esm/objectWithoutProperties.mjs";
import K from "../../../@babel/runtime/helpers/esm/toConsumableArray.mjs";
import te from "../../../@babel/runtime/helpers/esm/defineProperty.mjs";
import S from "react";
import re from "./create-element.mjs";
import ae from "./checkForListedLanguage.mjs";
var se = ["language", "children", "style", "customStyle", "codeTagProps", "useInlineStyles", "showLineNumbers", "showInlineLineNumbers", "startingLineNumber", "lineNumberContainerStyle", "lineNumberStyle", "wrapLines", "wrapLongLines", "lineProps", "renderer", "PreTag", "CodeTag", "code", "astGenerator"];
function M(e, r) {
  var t = Object.keys(e);
  if (Object.getOwnPropertySymbols) {
    var n = Object.getOwnPropertySymbols(e);
    r && (n = n.filter(function(a) {
      return Object.getOwnPropertyDescriptor(e, a).enumerable;
    })), t.push.apply(t, n);
  }
  return t;
}
function f(e) {
  for (var r = 1; r < arguments.length; r++) {
    var t = arguments[r] != null ? arguments[r] : {};
    r % 2 ? M(Object(t), !0).forEach(function(n) {
      te(e, n, t[n]);
    }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : M(Object(t)).forEach(function(n) {
      Object.defineProperty(e, n, Object.getOwnPropertyDescriptor(t, n));
    });
  }
  return e;
}
var le = /\n/g;
function ie(e) {
  return e.match(le);
}
function oe(e) {
  var r = e.lines, t = e.startingLineNumber, n = e.style;
  return r.map(function(a, s) {
    var o = s + t;
    return /* @__PURE__ */ S.createElement("span", {
      key: "line-".concat(s),
      className: "react-syntax-highlighter-line-number",
      style: typeof n == "function" ? n(o) : n
    }, "".concat(o, `
`));
  });
}
function ue(e) {
  var r = e.codeString, t = e.codeStyle, n = e.containerStyle, a = n === void 0 ? {
    float: "left",
    paddingRight: "10px"
  } : n, s = e.numberStyle, o = s === void 0 ? {} : s, c = e.startingLineNumber;
  return /* @__PURE__ */ S.createElement("code", {
    style: Object.assign({}, t, a)
  }, oe({
    lines: r.replace(/\n$/, "").split(`
`),
    style: o,
    startingLineNumber: c
  }));
}
function ce(e) {
  return "".concat(e.toString().length, ".25em");
}
function Q(e, r) {
  return {
    type: "element",
    tagName: "span",
    properties: {
      key: "line-number--".concat(e),
      className: ["comment", "linenumber", "react-syntax-highlighter-line-number"],
      style: r
    },
    children: [{
      type: "text",
      value: e
    }]
  };
}
function X(e, r, t) {
  var n = {
    display: "inline-block",
    minWidth: ce(t),
    paddingRight: "1em",
    textAlign: "right",
    userSelect: "none"
  }, a = typeof e == "function" ? e(r) : e, s = f(f({}, n), a);
  return s;
}
function H(e) {
  var r = e.children, t = e.lineNumber, n = e.lineNumberStyle, a = e.largestLineNumber, s = e.showInlineLineNumbers, o = e.lineProps, c = o === void 0 ? {} : o, b = e.className, h = b === void 0 ? [] : b, u = e.showLineNumbers, l = e.wrapLongLines, y = e.wrapLines, g = y === void 0 ? !1 : y, p = g ? f({}, typeof c == "function" ? c(t) : c) : {};
  if (p.className = p.className ? [].concat(K(p.className.trim().split(/\s+/)), K(h)) : h, t && s) {
    var w = X(n, t, a);
    r.unshift(Q(t, w));
  }
  return l & u && (p.style = f({
    display: "flex"
  }, p.style)), {
    type: "element",
    tagName: "span",
    properties: p,
    children: r
  };
}
function Y(e) {
  for (var r = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [], t = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : [], n = 0; n < e.length; n++) {
    var a = e[n];
    if (a.type === "text")
      t.push(H({
        children: [a],
        className: K(new Set(r))
      }));
    else if (a.children) {
      var s = r.concat(a.properties.className);
      Y(a.children, s).forEach(function(o) {
        return t.push(o);
      });
    }
  }
  return t;
}
function ge(e, r, t, n, a, s, o, c, b) {
  var h, u = Y(e.value), l = [], y = -1, g = 0;
  function p(d, i) {
    var m = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : [];
    return H({
      children: d,
      lineNumber: i,
      lineNumberStyle: c,
      largestLineNumber: o,
      showInlineLineNumbers: a,
      lineProps: t,
      className: m,
      showLineNumbers: n,
      wrapLongLines: b,
      wrapLines: r
    });
  }
  function w(d, i) {
    if (n && i && a) {
      var m = X(c, i, o);
      d.unshift(Q(i, m));
    }
    return d;
  }
  function N(d, i) {
    var m = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : [];
    return r || m.length > 0 ? p(d, i, m) : w(d, i);
  }
  for (var k = function() {
    var i = u[g], m = i.children[0].value, A = ie(m);
    if (A) {
      var O = m.split(`
`);
      O.forEach(function(T, G) {
        var v = n && l.length + s, I = {
          type: "text",
          value: "".concat(T, `
`)
        };
        if (G === 0) {
          var R = u.slice(y + 1, g).concat(H({
            children: [I],
            className: i.properties.className
          })), D = N(R, v);
          l.push(D);
        } else if (G === O.length - 1) {
          var W = u[g + 1] && u[g + 1].children && u[g + 1].children[0], E = {
            type: "text",
            value: "".concat(T)
          };
          if (W) {
            var j = H({
              children: [E],
              className: i.properties.className
            });
            u.splice(g + 1, 0, j);
          } else {
            var L = [E], x = N(L, v, i.properties.className);
            l.push(x);
          }
        } else {
          var V = [I], F = N(V, v, i.properties.className);
          l.push(F);
        }
      }), y = g;
    }
    g++;
  }; g < u.length; )
    k();
  if (y !== u.length - 1) {
    var P = u.slice(y + 1, u.length);
    if (P && P.length) {
      var C = n && l.length + s, B = N(P, C);
      l.push(B);
    }
  }
  return r ? l : (h = []).concat.apply(h, l);
}
function me(e) {
  var r = e.rows, t = e.stylesheet, n = e.useInlineStyles;
  return r.map(function(a, s) {
    return re({
      node: a,
      stylesheet: t,
      useInlineStyles: n,
      key: "code-segement".concat(s)
    });
  });
}
function Z(e) {
  return e && typeof e.highlightAuto != "undefined";
}
function pe(e) {
  var r = e.astGenerator, t = e.language, n = e.code, a = e.defaultCodeValue;
  if (Z(r)) {
    var s = ae(r, t);
    return t === "text" ? {
      value: a,
      language: "text"
    } : s ? r.highlight(t, n) : r.highlightAuto(n);
  }
  try {
    return t && t !== "text" ? {
      value: r.highlight(n, t)
    } : {
      value: a
    };
  } catch (o) {
    return {
      value: a
    };
  }
}
function Ne(e, r) {
  return function(n) {
    var a = n.language, s = n.children, o = n.style, c = o === void 0 ? r : o, b = n.customStyle, h = b === void 0 ? {} : b, u = n.codeTagProps, l = u === void 0 ? {
      className: a ? "language-".concat(a) : void 0,
      style: f(f({}, c['code[class*="language-"]']), c['code[class*="language-'.concat(a, '"]')])
    } : u, y = n.useInlineStyles, g = y === void 0 ? !0 : y, p = n.showLineNumbers, w = p === void 0 ? !1 : p, N = n.showInlineLineNumbers, k = N === void 0 ? !0 : N, P = n.startingLineNumber, C = P === void 0 ? 1 : P, B = n.lineNumberContainerStyle, d = n.lineNumberStyle, i = d === void 0 ? {} : d, m = n.wrapLines, A = n.wrapLongLines, O = A === void 0 ? !1 : A, T = n.lineProps, G = T === void 0 ? {} : T, v = n.renderer, I = n.PreTag, R = I === void 0 ? "pre" : I, D = n.CodeTag, W = D === void 0 ? "code" : D, E = n.code, j = E === void 0 ? (Array.isArray(s) ? s[0] : s) || "" : E, L = n.astGenerator, x = ne(n, se);
    L = L || e;
    var V = w ? /* @__PURE__ */ S.createElement(ue, {
      containerStyle: B,
      codeStyle: l.style || {},
      numberStyle: i,
      startingLineNumber: C,
      codeString: j
    }) : null, F = c.hljs || c['pre[class*="language-"]'] || {
      backgroundColor: "#fff"
    }, U = Z(L) ? "hljs" : "prismjs", q = g ? Object.assign({}, x, {
      style: Object.assign({}, F, h)
    }) : Object.assign({}, x, {
      className: x.className ? "".concat(U, " ").concat(x.className) : U,
      style: Object.assign({}, h)
    });
    if (O ? l.style = f({
      whiteSpace: "pre-wrap"
    }, l.style) : l.style = f({
      whiteSpace: "pre"
    }, l.style), !L)
      return /* @__PURE__ */ S.createElement(R, q, V, /* @__PURE__ */ S.createElement(W, l, j));
    (m === void 0 && v || O) && (m = !0), v = v || me;
    var z = [{
      type: "text",
      value: j
    }], $ = pe({
      astGenerator: L,
      language: a,
      code: j,
      defaultCodeValue: z
    });
    $.language === null && ($.value = z);
    var J = $.value.length;
    J === 1 && $.value[0].type === "text" && (J = $.value[0].value.split(`
`).length);
    var _ = J + C, ee = ge($, m, G, w, k, C, _, i, O);
    return /* @__PURE__ */ S.createElement(R, q, /* @__PURE__ */ S.createElement(W, l, !k && V, v({
      rows: ee,
      stylesheet: c,
      useInlineStyles: g
    })));
  };
}
export {
  Ne as default
};
