import { Popover } from '@transferwise/components';
import { AlertCircle } from '@transferwise/icons';
import PropTypes from 'prop-types';
import React from 'react';
import { useIntl } from 'react-intl';
import { t as translate, h as hasDuration, f as formatDeliveryEstimation } from './deliveryEstimationFormatter-9fc5c3af.js';
import { i as isWiseAlias } from './aliasFilter-a7b9c811.js';
import { s as styleInject } from './style-inject.es-1f59c1d0.js';

function isTwPowered(isPartner, alias) {
  return isPartner || isWiseAlias(alias);
}
function getScenarioKey(deliveryEstimation, isPartner, alias, isTravelMoney = false) {
  if (!deliveryEstimation.providerGivesEstimate) {
    return 'provider-does-not-give-estimate';
  }
  if (!hasDuration(deliveryEstimation)) {
    return 'not-yet-collected';
  }
  if (isTravelMoney) {
    if (isTwPowered(false, alias)) {
      return 'tw-travel-money';
    }
    return 'non-tw-travel-money';
  }
  if (isTwPowered(isPartner, alias)) {
    return 'tw-powered';
  }
  return 'non-tw-powered';
}

// eslint-disable-next-line import/prefer-default-export
const getCitationCopy = (deliveryEstimation, isPartner, alias, lang, isTravelMoney) => {
  const scenarioKey = getScenarioKey(deliveryEstimation, isPartner, alias, isTravelMoney);
  const baseTranslationKey = `delivery-estimation.${scenarioKey}.citation`;
  return {
    title: translate(`${baseTranslationKey}.title`, lang),
    body: translate(`${baseTranslationKey}.body`, lang)
  };
};

var css_248z = "@media (--screen-md) {\n}@media (--screen-md) {\n}.cc_delivery-estimation_1579418673 {\n  display: flex;\n  align-items: center;\n}\n.cc_delivery-estimation_1579418673 .cc_tw-icon_1579418673,\n.cc_delivery-estimation_1579418673 [class^='tw-icon '] {\n  display: inline;\n}\n.cc_delivery-estimation_1579418673 .cc_tw-icon_1579418673 svg,\n.cc_delivery-estimation_1579418673 [class^='tw-icon '] svg {\n  display: block;\n}\n.cc_delivery-estimation_1579418673 [data-toggle='popover']:not(.cc_btn_1579418673) {\n  height: var(--size-16);\n  border-bottom: 0 !important;\n}\n@media (max-width: 991px) {\n  .cc_delivery-estimation_1579418673 {\n    margin-top: unset;\n  }\n}\n.cc_delivery-estimation-data_1579418673 {\n  margin-right: var(--size-8);\n  font-size: var(--font-size-14);\n  font-weight: var(--font-weight-semi-bold);\n}\n.cc_delivery-estimation-tool-tip_1579418673 {\n  line-height: 8px;\n  cursor: pointer;\n}\n\n/*# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIm5vZGVfbW9kdWxlcy9AdHJhbnNmZXJ3aXNlL25lcHR1bmUtY3NzL3NyYy9sZXNzL2NvcmUvX3R5cG9ncmFwaHkubGVzcyIsIkRlbGl2ZXJ5RXN0aW1hdGlvbi5tb2R1bGUubGVzcyIsInNyYy9jb21tb24vRGVsaXZlcnlFc3RpbWF0aW9uLm1vZHVsZS5sZXNzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQXFhRTtBQ3BhRixDRGdiRTtBQy9hRixDQ0VBO0VBQ0UsYUFBQTtFQUNBLG1CQUFBO0FEREY7QUNEQTs7RUFNSSxlQUFBO0FEREo7QUNMQTs7RUFTTSxjQUFBO0FEQU47QUNUQTtFQWNJLHNCQUFBO0VBQ0EsMkJBQUE7QURGSjtBQ0tFO0VBQUE7SUFDRSxpQkFBQTtFREZGO0FBQ0Y7QUNLQTtFQUNFLDJCQUFBO0VBQ0EsOEJBQUE7RUFDQSx5Q0FBQTtBREhGO0FDTUE7RUFDRSxnQkFBQTtFQUNBLGVBQUE7QURKRiIsImZpbGUiOiJEZWxpdmVyeUVzdGltYXRpb24ubW9kdWxlLmxlc3MifQ== */";
var componentStyles = {"delivery-estimation":"cc_delivery-estimation_1579418673","deliveryEstimation":"cc_delivery-estimation_1579418673","tw-icon":"cc_tw-icon_1579418673","twIcon":"cc_tw-icon_1579418673","btn":"cc_btn_1579418673","delivery-estimation-data":"cc_delivery-estimation-data_1579418673","deliveryEstimationData":"cc_delivery-estimation-data_1579418673","delivery-estimation-tool-tip":"cc_delivery-estimation-tool-tip_1579418673","deliveryEstimationToolTip":"cc_delivery-estimation-tool-tip_1579418673"};
styleInject(css_248z);

const DeliveryEstimation = ({
  styles,
  deliveryEstimation,
  isPartner,
  alias,
  onClickingDeliveryEstimationTooltip,
  isTravelMoney
}) => {
  const {
    locale
  } = useIntl();
  const derivedStyles = {
    ...componentStyles,
    ...styles
  };
  const citationCopy = getCitationCopy(deliveryEstimation, isPartner, alias, locale, isTravelMoney);
  return /*#__PURE__*/React.createElement("div", {
    className: derivedStyles['delivery-estimation'],
    "data-testid": "delivery-estimation"
  }, /*#__PURE__*/React.createElement("span", {
    className: derivedStyles['delivery-estimation-data']
  }, formatDeliveryEstimation(deliveryEstimation, {
    lang: locale
  })), /*#__PURE__*/React.createElement("span", {
    // eslint-disable-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions
    id: "delivery-estimation-tool-tip",
    onClick: onClickingDeliveryEstimationTooltip
  }, citationCopy && /*#__PURE__*/React.createElement(Popover, {
    classNames: derivedStyles,
    title: citationCopy.title,
    content: citationCopy.body
  }, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(AlertCircle, {
    className: derivedStyles['tw-help-icon'],
    "data-testid": "help-circle-icon",
    size: 16
  })))));
};
DeliveryEstimation.propTypes = {
  styles: PropTypes.shape({
    speed: PropTypes.string
  }),
  deliveryEstimation: PropTypes.shape({
    duration: PropTypes.shape({
      min: PropTypes.string,
      max: PropTypes.string
    }),
    providerGivesEstimate: PropTypes.bool
  }).isRequired,
  isPartner: PropTypes.bool.isRequired,
  alias: PropTypes.string.isRequired,
  onClickingDeliveryEstimationTooltip: PropTypes.func.isRequired,
  isTravelMoney: PropTypes.bool
};
DeliveryEstimation.defaultProps = {
  styles: componentStyles,
  isTravelMoney: false
};

export { DeliveryEstimation as D };
//# sourceMappingURL=DeliveryEstimation-3b7a5a47.js.map
