"use strict";

exports.__esModule = true;
exports["default"] = void 0;
var _react = _interopRequireDefault(require("react"));
var _mastercardPill = _interopRequireDefault(require("./mastercardPill"));
var _background = require("./mixins/background");
var _styled = require("./styled");
var _excluded = ["children", "data-testid", "height", "normal", "onClick", "pillLeft", "pillRight", "pillEnd", "round", "size", "zIndex", "ref"];
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
var minWidths = {
  "default": "22px",
  large: "37px"
};
var MasterCard = function MasterCard(_ref) {
  var children = _ref.children,
    _ref$dataTestid = _ref["data-testid"],
    testId = _ref$dataTestid === void 0 ? "mastercard" : _ref$dataTestid,
    height = _ref.height,
    normal = _ref.normal,
    onClick = _ref.onClick,
    _ref$pillLeft = _ref.pillLeft,
    pillLeft = _ref$pillLeft === void 0 ? {} : _ref$pillLeft,
    _ref$pillRight = _ref.pillRight,
    pillRight = _ref$pillRight === void 0 ? {} : _ref$pillRight,
    pillEnd = _ref.pillEnd,
    round = _ref.round,
    size = _ref.size,
    zIndex = _ref.zIndex,
    ref = _ref.ref,
    rest = _objectWithoutPropertiesLoose(_ref, _excluded);
  var commonProps = {
    height: height,
    round: round,
    size: size
  };
  var pillProps = _extends({
    normal: normal
  }, commonProps, rest);
  var pillRightBackground = (0, _background.getMasterCardBackground)(pillRight.background, pillRight.flavour || "disabledWarning");
  var pillEndBackground = pillEnd && (0, _background.getMasterCardBackground)(pillEnd.background, pillEnd.flavour || "disabledClear");
  var pillLeftProps = _extends({
    background: (0, _background.getMasterCardBackground)(pillLeft.background, pillLeft.flavour || "disabledError"),
    position: "relative",
    width: {
      min: minWidths[rest.size] || minWidths["default"]
    }
  }, pillProps, pillLeft, {
    zIndex: 3
  });
  var pillRightProps = _extends({
    background: pillRightBackground,
    margin: [0, 0, 0, size === "large" ? -4.5 : -3.5],
    padding: [0, 2, 0, size === "large" ? 5 : 4],
    width: {
      min: minWidths[rest.size] || minWidths["default"]
    }
  }, pillProps, pillRight, {
    zIndex: 2
  });
  var pillEndProps = pillEnd && _extends({
    background: pillEndBackground,
    margin: [0, 0, 0, size === "large" ? -4.5 : -3.5],
    padding: [0, 2, 0, size === "large" ? 5 : 4],
    width: {
      min: minWidths[rest.size] || minWidths["default"]
    }
  }, pillProps, pillEnd, {
    zIndex: 1
  });
  return /*#__PURE__*/_react["default"].createElement(_styled.MasterCardContainer, _extends({
    "data-testid": testId,
    onClick: onClick,
    ref: ref
  }, commonProps), children || /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, /*#__PURE__*/_react["default"].createElement(_mastercardPill["default"], _extends({
    "data-testid": testId + "-left-pill"
  }, pillLeftProps)), /*#__PURE__*/_react["default"].createElement(_mastercardPill["default"], _extends({
    "data-testid": testId + "-right-pill"
  }, pillRightProps)), pillEndProps && /*#__PURE__*/_react["default"].createElement(_mastercardPill["default"], _extends({
    "data-testid": testId + "-end-pill"
  }, pillEndProps))));
};
var _default = exports["default"] = MasterCard;