"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.RateDetails = void 0;
var _locale = require("@mirai/locale");
var _ui = require("@mirai/ui");
var _propTypes = _interopRequireDefault(require("prop-types"));
var _react = _interopRequireDefault(require("react"));
var _RateDetails = require("./RateDetails.constants");
var style = _interopRequireWildcard(require("./RateDetails.module.css"));
var _helpers = require("../../../../../helpers");
var _Item = require("../../Item.l10n");
var _Countdown = require("../Countdown");
var _TooltipDates = require("../TooltipDates");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
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); }
const RateDetails = _ref => {
  let {
    compacted = false,
    countdown,
    included = [],
    restrictions = [],
    selectedBoard: {
      offerDates = []
    } = {},
    onOfferInfo
  } = _ref;
  const {
    isMobile
  } = (0, _ui.useDevice)();
  const {
    translate
  } = (0, _locale.useLocale)();
  const caption = {
    small: true
  };
  const icon = {
    paragraph: true
  };
  const has = {
    included: included.length > 0,
    restrictions: restrictions.length > 0
  };
  return has.included || has.restrictions || countdown > 0 ? /*#__PURE__*/_react.default.createElement(_ui.View, {
    className: !compacted && style.content
  }, countdown && /*#__PURE__*/_react.default.createElement(_Countdown.Countdown, {
    timestamp: countdown
  }), has.restrictions && restrictions.map(function () {
    let {
      variableOffer,
      value
    } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
    let index = arguments.length > 1 ? arguments[1] : undefined;
    return /*#__PURE__*/_react.default.createElement(_ui.View, {
      key: index,
      row: true,
      className: style.row
    }, /*#__PURE__*/_react.default.createElement(_ui.Text, _extends({
      warning: true
    }, caption), value), variableOffer && offerDates.length > 0 && /*#__PURE__*/_react.default.createElement(_TooltipDates.TooltipDates, {
      captions: offerDates.map(() => translate(_Item.L10N.LABEL_INCLUDED)),
      values: offerDates.map(date => (0, _locale.parseDate)(date)),
      warning: true
    }));
  }), !compacted && has.included && /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, included.slice(0, _RateDetails.LIMIT_INCLUDED).map((item, index) => /*#__PURE__*/_react.default.createElement(_ui.View, {
    key: index,
    row: true,
    className: style.row
  }, /*#__PURE__*/_react.default.createElement(_ui.Icon, _extends({
    light: true,
    value: _helpers.ICON.CHECK
  }, icon)), /*#__PURE__*/_react.default.createElement(_ui.Text, _extends({
    light: !isMobile
  }, caption), item))), included.length > _RateDetails.LIMIT_INCLUDED && /*#__PURE__*/_react.default.createElement(_ui.Action, _extends({}, caption, {
    onPress: onOfferInfo
  }), translate(_Item.L10N.ACTION_VIEW_MORE)))) : null;
};
exports.RateDetails = RateDetails;
RateDetails.displayName = 'Mirai:Core:Rates:Item:RateDetails';
RateDetails.propTypes = {
  compacted: _propTypes.default.bool,
  countdown: _propTypes.default.any,
  included: _propTypes.default.arrayOf(_propTypes.default.any),
  restrictions: _propTypes.default.arrayOf(_propTypes.default.any),
  selectedBoard: _propTypes.default.shape({}),
  onOfferInfo: _propTypes.default.func
};
//# sourceMappingURL=RateDetails.js.map