"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.getOrderedListInlineStyles = getOrderedListInlineStyles;
exports.listItemCounterPadding = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var listItemCounterPadding = exports.listItemCounterPadding = 24;
var CSS_VAR_NAMES = /*#__PURE__*/function (CSS_VAR_NAMES) {
  CSS_VAR_NAMES["ITEM_COUNTER_PADDING"] = "--ed--list--item-counter--padding";
  return CSS_VAR_NAMES;
}(CSS_VAR_NAMES || {});
var getItemCounterLeftPadding = function getItemCounterLeftPadding(itemCounterDigitsSize) {
  // Previous padding-left was approximately 24px. We approximate that
  // same value using "ch" units (which represent the width of a "0" digit
  // character). We use "ch" so that this computed padding can now grow if
  //  the font-size ever enlarges.
  var paddingLeft = "2.385ch";
  if (itemCounterDigitsSize >= 2) {
    // When there are 2 or more digits, we use a combination of "ch" units and
    // pixel values so that while the computed padding grows if font-size ever
    // enlarges, it doesn't over-scale with each digit (because of the fixed pixel
    // portion of the computed value). This way, very large item counters will not
    // become overly left-padded.
    var fixedBasePx = 2;
    paddingLeft = "calc(".concat(itemCounterDigitsSize + 1, "ch - ").concat(fixedBasePx, "px)");
  }
  return paddingLeft;
};
var stringifyStyle = function stringifyStyle(style) {
  return Object.entries(style).reduce(function (str, _ref) {
    var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
      key = _ref2[0],
      value = _ref2[1];
    return "".concat(str).concat(key, ":").concat(value, ";");
  }, "");
};

// eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports

// eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports

// eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
function getOrderedListInlineStyles(itemCounterDigitsSize, styleFormat
// Ignored via go/ees005
// eslint-disable-next-line @typescript-eslint/no-explicit-any
) {
  var style = (0, _defineProperty2.default)({}, CSS_VAR_NAMES.ITEM_COUNTER_PADDING, getItemCounterLeftPadding(itemCounterDigitsSize));
  if (styleFormat === 'string') {
    return stringifyStyle(style);
  }
  return style;
}