"use strict";

function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.PromotionBanner = void 0;
var _react = _interopRequireWildcard(require("react"));
var _styledComponents = _interopRequireDefault(require("styled-components"));
var _ = require("../..");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
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 && Object.prototype.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 _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
var getColor = function getColor(props) {
  var backgroundColor = props.backgroundColor,
    theme = props.theme;
  if (backgroundColor === 'green') {
    return theme.color.infoBarBackgroundSuccess;
  }
  if (backgroundColor === 'white') {
    return theme.color.bubbleBackground;
  }
  if (typeof backgroundColor === 'function') {
    return backgroundColor(theme);
  }
  return theme.color.illustrationBackgroundBlue;
};
var StyledContainer = _styledComponents.default.div.withConfig({
  displayName: "PromotionBanner__StyledContainer",
  componentId: "sc-1ypm7z4-0"
})(["background-color:", ";width:100%;box-shadow:0 2px 2px 0 ", ";border-radius:", ";"], function (p) {
  return getColor(p);
}, function (_ref) {
  var theme = _ref.theme;
  return theme.color.shadowCard;
}, function (_ref2) {
  var theme = _ref2.theme,
    scope = _ref2.scope;
  return scope === 'module' ? theme.borderRadius8 : 0;
});
var StyledBox = (0, _styledComponents.default)(_.Box).withConfig({
  displayName: "PromotionBanner__StyledBox",
  componentId: "sc-1ypm7z4-1"
})(["margin:auto;", "{max-width:720px;}", "{max-width:936px;}", "{max-width:1240px;}", "{max-width:1560px;}"], function (p) {
  return p.theme.media.greaterThan(p.theme.breakpoints.sm);
}, function (p) {
  return p.theme.media.greaterThan(p.theme.breakpoints.md);
}, function (p) {
  return p.theme.media.greaterThan(p.theme.breakpoints.lg);
}, function (p) {
  return p.theme.media.greaterThan(p.theme.breakpoints.xl);
});
var StyledIconCross = (0, _styledComponents.default)(_.Icon.Cross16).withConfig({
  displayName: "PromotionBanner__StyledIconCross",
  componentId: "sc-1ypm7z4-2"
})(["padding-left:4px;"]);
var StyledBadge = (0, _styledComponents.default)(_.Badge.Icon).withConfig({
  displayName: "PromotionBanner__StyledBadge",
  componentId: "sc-1ypm7z4-3"
})(["overflow:hidden;"]);
var PromotionBanner = exports.PromotionBanner = function PromotionBanner(_ref3) {
  var backgroundColor = _ref3.backgroundColor,
    badgeBackground = _ref3.badgeBackground,
    badgeContent = _ref3.badgeContent,
    children = _ref3.children,
    description = _ref3.description,
    dismissible = _ref3.dismissible,
    mobileBadgeContent = _ref3.mobileBadgeContent,
    onClose = _ref3.onClose,
    _ref3$scope = _ref3.scope,
    scope = _ref3$scope === void 0 ? 'module' : _ref3$scope,
    _ref3$justifyContent = _ref3.justifyContent,
    justifyContent = _ref3$justifyContent === void 0 ? 'center' : _ref3$justifyContent,
    title = _ref3.title;
  var isDesktop = (0, _.useMedia)(function (t) {
    return t.media.greaterThan(t.breakpoints.sm);
  });
  var isSmallScreen = (0, _.useMedia)(function (t) {
    return t.media.lessThan(t.breakpoints.lg);
  });
  var _useState = (0, _react.useState)(true),
    _useState2 = _slicedToArray(_useState, 2),
    showPromotion = _useState2[0],
    setShowPromotion = _useState2[1];
  var isPageDesktop = isDesktop && scope === 'page';
  var handleClose = (0, _react.useCallback)(function () {
    setShowPromotion(false);
    if (onClose) {
      onClose();
    }
  }, [onClose]);
  return showPromotion ? _react.default.createElement(StyledContainer, {
    backgroundColor: backgroundColor,
    scope: scope
  }, _react.default.createElement(StyledBox, {
    p: 3,
    sm: {
      p: 5
    }
  }, _react.default.createElement(_.Flexbox, {
    container: true,
    justifyContent: "center"
  }, _react.default.createElement(_.Flexbox, {
    container: true,
    flex: "1",
    item: true,
    direction: "row",
    alignItems: "center",
    justifyContent: justifyContent,
    gap: 3,
    width: "100%",
    sm: {
      gap: 5
    },
    md: {
      gap: 5
    },
    lg: {
      gap: 5,
      justifyContent: justifyContent,
      width: '772px'
    },
    xl: {
      width: '772px'
    }
  }, mobileBadgeContent && badgeContent && _react.default.createElement(_.Flexbox, {
    item: true
  }, _react.default.createElement(StyledBadge, {
    badgeSize: isDesktop ? 24 : 16,
    badgeColor: badgeBackground || function (t) {
      return t.color.accountBadgeBackground;
    }
  }, isDesktop ? badgeContent : mobileBadgeContent)), _react.default.createElement(_.Flexbox, {
    container: true,
    item: true,
    direction: "column",
    gap: 2,
    alignItems: "flex-start",
    sm: {
      gap: 3
    },
    lg: {
      direction: scope === 'page' ? 'row' : 'column',
      gap: isPageDesktop ? 5 : 3,
      width: 'auto'
    }
  }, _react.default.createElement(_.Flexbox, {
    container: true,
    item: true,
    direction: "column",
    gap: 1,
    sm: {
      gap: 2,
      justifyContent: 'center'
    },
    lg: {
      gap: isPageDesktop ? 2 : 1
    }
  }, _react.default.createElement(_.Flexbox, {
    item: true
  }, _react.default.createElement(_.Typography, {
    type: isPageDesktop ? 'title3' : 'primary',
    weight: "extrabold",
    color: function color(t) {
      return t.color.promotionBannerTitle;
    }
  }, title)), _react.default.createElement(_.Flexbox, {
    item: true
  }, _react.default.createElement(_.Typography, {
    type: isPageDesktop ? 'secondary' : 'tertiary',
    color: function color(t) {
      return t.color.promotionBannerDescription;
    }
  }, description))), children && _react.default.createElement(_.Flexbox, {
    item: true,
    alignSelf: isSmallScreen || scope !== 'page' ? 'flex-start' : 'center'
  }, children))), dismissible && _react.default.createElement(_.Flexbox, {
    container: true,
    item: true,
    flex: "0",
    justifyContent: "flex-end",
    alignItems: "flex-start"
  }, _react.default.createElement(_.Button, {
    variant: "neutral",
    onClick: handleClose
  }, _react.default.createElement(StyledIconCross, null)))))) : null;
};