"use strict";

exports.__esModule = true;
exports["default"] = void 0;
var _react = _interopRequireWildcard(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"];
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
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 ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.indexOf(n) >= 0) continue; t[n] = r[n]; } return t; }
var minWidths = {
  "default": "22px",
  large: "37px"
};
var MasterCard = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, 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,
    rest = _objectWithoutPropertiesLoose(_ref, _excluded);
  var commonProps = {
    height: height,
    round: round,
    size: size
  };
  var pillProps = _objectSpread(_objectSpread({
    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 = _objectSpread(_objectSpread(_objectSpread({
    background: (0, _background.getMasterCardBackground)(pillLeft.background, pillLeft.flavour || "disabledError"),
    position: "relative",
    width: {
      min: minWidths[rest.size] || minWidths["default"]
    }
  }, pillProps), pillLeft), {}, {
    zIndex: 3
  });
  var pillRightProps = _objectSpread(_objectSpread(_objectSpread({
    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 && _objectSpread(_objectSpread(_objectSpread({
    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;