"use strict";

exports.__esModule = true;
exports.mapLabels = void 0;

var _lib = require("@sentecacommerce-theme/lib");

var LabelDTOLocationEnum;

(function (LabelDTOLocationEnum) {
  LabelDTOLocationEnum["TopLeft"] = "top-left";
  LabelDTOLocationEnum["TopRight"] = "top-right";
  LabelDTOLocationEnum["BottomLeft"] = "bottom-left";
  LabelDTOLocationEnum["BottomRight"] = "bottom-right";
})(LabelDTOLocationEnum || (LabelDTOLocationEnum = {}));

var mapLabels = function mapLabels(_ref) {
  var labels = _ref.labels,
      _ref$isListing = _ref.isListing,
      isListing = _ref$isListing === void 0 ? false : _ref$isListing,
      discountedPrice = _ref.discountedPrice;
  var positionCounter = {
    'top-left': 0,
    'top-right': 0,
    'bottom-left': 0,
    'bottom-right': discountedPrice ? 1 : 0
  };
  var mappedLabels = labels.map(function (el, i) {
    return {
      _id: el._id,
      version: el.version,
      key: el.key,
      name: (0, _lib.getTranslatableField)(el.name),
      // getTranslatableField
      description: (0, _lib.getTranslatableField)(el.description),
      // getTranslatableField
      location: getPosition(el.location, positionCounter, isListing),
      isIcon: Boolean(el.icon),
      icon: el.icon,
      appearance: getAppearance(el),
      backgroundColor: el.backgroundColor,
      color: el.color
    };
  });
  return mappedLabels;
};

exports.mapLabels = mapLabels;

var getPosition = function getPosition(location, positionCounter, isListing) {
  var res = '';
  var shift = isListing ? positionCounter[location] * 3 + 1 : positionCounter[location] * 3.5 + 2;

  switch (location) {
    case LabelDTOLocationEnum.BottomLeft:
      res += "bottom: 1rem; left: " + shift + "rem;";
      positionCounter[location]++;
      break;

    case LabelDTOLocationEnum.BottomRight:
      res += "bottom: 1rem; right: " + shift + "rem;";
      positionCounter[location]++;
      break;

    case LabelDTOLocationEnum.TopLeft:
      res += "top: " + (isListing ? 1 : 2) + "rem; left: " + shift + "rem;";
      positionCounter[location]++;
      break;

    case LabelDTOLocationEnum.TopRight:
      res += "top: " + (isListing ? 1 : 2) + "rem; right: " + shift + "rem;";
      positionCounter[location]++;
      break;

    default:
      res += '';
      break;
  }

  return res;
};

var getAppearance = function getAppearance(el) {
  var appearance = "";
  appearance += "width: " + el.size.width + "px; height: " + el.size.height + "px;";

  if (!el.icon) {
    appearance += "color: " + el.color + "; background: " + el.backgroundColor + ";";

    if (el.shape === 'circle') {
      appearance += "border-radius: 50%;";
    }
  }

  return appearance;
};
//# sourceMappingURL=LabelUtils.js.map