import{_ as t,b as n}from"./style-inject.es-f40f6556.js";import{toDays as e,toHours as i,toMinutes as r,toSeconds as s}from"duration-fns";import{getLangFromLocale as a}from"@transferwise/components";import"react";import{createIntlCache as o,createIntl as c}from"react-intl";import{c as u}from"./index-3b75aa86.js";var m=new Set(["wise.com","dev-wi.se","transferwise.com","trwi.se"]);function l(t){if("undefined"!=typeof window){var n=window.location.hostname;if(m.has(n)||/customenvs.k8stw.com/g.test(n))return"https://".concat(n).concat(t)}return"https://wise.com".concat(t)}var f=function(t){return!(!t||!t.duration||!t.duration.min&&!t.duration.max)};function d(t){return 0===t.filter(function(t){return t.deliveryEstimation.providerGivesEstimate&&!f(t.deliveryEstimation)}).length}function p(t,n){var e=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);n&&(i=i.filter(function(n){return Object.getOwnPropertyDescriptor(t,n).enumerable})),e.push.apply(e,i)}return e}function v(n){for(var e=1;e<arguments.length;e++){var i=null!=arguments[e]?arguments[e]:{};e%2?p(Object(i),!0).forEach(function(e){t(n,e,i[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(i)):p(Object(i)).forEach(function(t){Object.defineProperty(n,t,Object.getOwnPropertyDescriptor(i,t))})}return n}var y=o(),b=function(t,n){var e=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{},i="zh"===a(n)?n:a(n),r=c({locale:i,messages:v(v({},u.en),u[i])||u.en},y);return t&&r.formatMessage({id:t},e)},O="days",g="hours",h="minutes",j="seconds",w="within",$="in";function x(t,n,e,i){const r=`${i?`${i}-`:""}`,s=`${e?"-range":""}`;return t===j?`${i&&i===$?`${r}${t}`:t}`:t===h?`${r}${t}${s}`:t===g?`${r}${t}${s}`:t===O?`${r}${`${n?"business-":""}`}${t}${s}`:"unavailable"}function k(t){const n=e(t),a=i(t);if(n>=1||a>23)return{total:Math.ceil(n),units:O};const o=r(t);if(a>=1||o>59)return{total:Math.ceil(a),units:g};const c=s(t);return o>=1||c>59?{total:Math.ceil(o),units:h}:{total:Math.ceil(c),units:j}}function S(t,n,e,i){const r=k(t);return{key:x(r.units,n,e,i),params:{[r.units]:r.total}}}const P=(t,{lang:e="en",translationOptions:i={}},{showAsBusiness:r=!1,includePrefix:s=!0,isSpeedFormat:a=!1}={})=>{let o;const c=r&&(!f(t)||"BUSINESS"===(null==t?void 0:t.durationType));o=(null==t?void 0:t.providerGivesEstimate)?f(t)?function(t){const n=t.duration||{};if(n.min&&n.max){const t=k(n.min),e=k(n.max);if(t.units===e.units&&t.total===e.total)return!0}return!1}(t)?S(t.duration.min,c,!1,s?$:void 0):t.duration.min&&t.duration.max?function(t,n,e){const i=k(t.min),r=k(t.max);return r.units===i.units?{key:x(r.units,n,!0,e),params:{min:i.total,max:r.total}}:S(t.max,n,!1,w)}(t.duration,c,s?$:void 0):t.duration.max?S(t.duration.max,c,!1,w):S(t.duration.min,c,!1,s?$:void 0):{key:"delivery-estimation.not-yet-collected",params:{}}:{key:a?"unavailable":"delivery-estimation.provider-does-not-give-estimate",params:{}},i.keySuffix&&(o=Object.assign(Object.assign({},o),{key:`${o.key}.${i.keySuffix}`}));const u=i.params||{};return b(o.key,e,Object.assign(Object.assign(Object.assign({},o.params),u),{span:t=>n("span",Object.assign({className:u.estimationClassNames},{children:t}))}))};export{O as D,g as H,h as M,j as S,k as a,l as c,P as f,f as h,d as i,b as t};
//# sourceMappingURL=deliveryEstimationFormatter-66e6704d.js.map
