import{cloneElement as e,isValidElement as t}from"react";import r from"use-intl/format-message";import{I as n,a as o,c as a,b as s}from"./formatters-CJcico0N.js";function c(...e){return e.filter(Boolean).join(".")}function i(e){return c(e.namespace,e.key)}function u(e){console.error(e)}function m(e,t,r,n){const o=c(n,r);if(!t)throw new Error(o);let a=t;return r.split(".").forEach((t=>{const r=a[t];if(null==t||null==r)throw new Error(o+` (${e})`);a=r})),a}function f(a){const s=function(e,t,r){try{if(!t)throw new Error(void 0);const n=r?m(e,t,r):t;if(!n)throw new Error(r);return n}catch(e){return new n(o.MISSING_MESSAGE,e.message)}}(a.locale,a.messages,a.namespace);return function({cache:a,formats:s,formatters:u,getMessageFallback:f=i,locale:l,messagesOrError:g,namespace:y,onError:h,timeZone:w}){const E=g instanceof n;function S(e,t,r,o){const a=new n(t,r);return h(a),o??f({error:a,key:e,namespace:y})}function d(i,d,p,M){const T=M;let R;if(E){if(!T)return h(g),f({error:g,key:i,namespace:y});R=T}else{const e=g;try{R=m(l,e,i,y)}catch(e){if(!T)return S(i,o.MISSING_MESSAGE,e.message,T);R=T}}try{const n=c(y,i);return r(n,R,d?function(r){const n={};return Object.keys(r).forEach((o=>{let a=0;const s=r[o];let c;c="function"==typeof s?r=>{const n=s(r);return t(n)?e(n,{key:o+a++}):n}:s,n[o]=c})),n}(d):d,{cache:a,formatters:u,globalFormats:s,formats:p,locale:l,timeZone:w})}catch(e){let t,r;return e instanceof n?(t=e.code,r=e.originalMessage):(t=o.FORMATTING_ERROR,r=e.message),S(i,t,r,T)}}function p(e,t,r,n){const a=d(e,t,r,n);return"string"!=typeof a?S(e,o.INVALID_MESSAGE,void 0):a}return p.rich=d,p.markup=(e,t,r,n)=>d(e,t,r,n),p.raw=e=>{if(E)return h(g),f({error:g,key:e,namespace:y});const t=g;try{return m(l,t,e,y)}catch(t){return S(e,o.MISSING_MESSAGE,t.message)}},p.has=e=>{if(E)return!1;try{return m(l,g,e,y),!0}catch{return!1}},p}({...a,messagesOrError:s})}function l(e,t){return e===t?void 0:e.slice((t+".").length)}const g=3600,y=86400,h=7*y,w=2628e3,E=7884e3,S=365*y,d={second:1,seconds:1,minute:60,minutes:60,hour:g,hours:g,day:y,days:y,week:h,weeks:h,month:w,months:w,quarter:E,quarters:E,year:S,years:S};function p(e){const{_cache:t=s(),_formatters:r=a(t),formats:c,locale:i,onError:m=u,timeZone:f}=e;function l(e){return e?.timeZone||(f?e={...e,timeZone:f}:m(new n(o.ENVIRONMENT_FALLBACK,void 0))),e}function E(e,t,r,a,s){let c;try{c=function(e,t,r){let a;if("string"==typeof t){const r=t;if(a=e?.[r],!a){const e=new n(o.MISSING_FORMAT,void 0);throw m(e),e}}else a=t;return r&&(a={...a,...r}),a}(r,e,t)}catch{return s()}try{return a(c)}catch(e){return m(new n(o.FORMATTING_ERROR,e.message)),s()}}function p(e,t,n){return E(t,n,c?.dateTime,(t=>(t=l(t),r.getDateTimeFormat(i,t).format(e))),(()=>String(e)))}function M(){return e.now?e.now:(m(new n(o.ENVIRONMENT_FALLBACK,void 0)),new Date)}return{dateTime:p,number:function(e,t,n){return E(t,n,c?.number,(t=>r.getNumberFormat(i,t).format(e)),(()=>String(e)))},relativeTime:function(e,t){try{let n,o;const a={};t instanceof Date||"number"==typeof t?n=new Date(t):t&&(n=null!=t.now?new Date(t.now):M(),o=t.unit,a.style=t.style,a.numberingSystem=t.numberingSystem),n||(n=M());const s=(new Date(e).getTime()-n.getTime())/1e3;o||(o=function(e){const t=Math.abs(e);return t<60?"second":t{const t=r.getListFormat(i,e).formatToParts(o).map((e=>"literal"===e.type?e.value:a.get(e.value)||e.value));return a.size>0?t:t.join("")}),(()=>String(e)))},dateTimeRange:function(e,t,n,o){return E(n,o,c?.dateTime,(n=>(n=l(n),r.getDateTimeFormat(i,n).formatRange(e,t))),(()=>[p(e),p(t)].join(" – ")))}}}function M({formats:e,getMessageFallback:t,messages:r,onError:n,...o}){return{...o,formats:e||void 0,messages:r||void 0,onError:n||u,getMessageFallback:t||i}}export{f as a,u as b,p as c,i as d,M as i,l as r};