const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["118ceb36.CKPjVCjx.js","f025431a.BlsbPO0-.js"])))=>i.map(i=>d[i]); import{Ft as e,Jt as t,Wt as n,Xt as r,Zt as o,jt as a,nn as c,yt as s}from"./630ba094.L_X-5TXi.js";import{f as i}from"./app.BAntcNCf.js";import{Gg as u,lk as l,rj as m,wO as d,xO as f}from"./6ec9a0fa.rdcQt2v8.js";import{r as v}from"./a45fed45.Dr0zbZ6C.js";import{t as g}from"./486c3fda.B832TPZj.js";import{t as p}from"./cb6adac5.Bl30j75Z.js";var C={FlagIcon:"sgqviy0 _1fragem5u _1fragemve _1fragemvo",sizeVariant:{base:"sgqviy1",small:"sgqviy2"}};function h({accessibilityLabel:t,countryCode:r,size:o}){const c=e(void 0);n(()=>{let e=!1;return async function(){const{ALL_FLAG_ICON_BY_COUNTRY_CODE:t}=await i(async()=>{const{ALL_FLAG_ICON_BY_COUNTRY_CODE:e}=await import("./118ceb36.CKPjVCjx.js").then(e=>e.t);return{ALL_FLAG_ICON_BY_COUNTRY_CODE:e}},__vite__mapDeps([0,1]));e||(c.value={countryCode:r,src:t[r]})}().catch(()=>{e||(c.value={countryCode:r,src:void 0})}),()=>{e=!0}},[r,c]);const u=c.value?.countryCode===r?c.value.src:void 0;return s("img",{alt:t??"",className:a(C.FlagIcon,o&&C.sizeVariant[o]),src:u??"data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20640%20480'/%3E",role:"img"})}function _(e){return e.replace(/[^+\d]/g,"")}var y="text";function b({countryCode:e,value:c,onChange:i,onFocus:m,onInput:d,disableFormatting:v=!1,hideCountries:p=!1,prefillCountryCode:C,requireCountryCode:b=!1,onInputValueChange:w,onSelectedCountryChange:j,caretPosition:x,accessoryEnd:E,autocomplete:F="tel",onBlur:I,required:A,type:B,icon:q,...P}){const T=null==c?void 0:c,{i18n:U}=f(),[z,R]=o(!1),V=t(null),Y=t(!1),D=g(e,T,C||b),{formattedNumber:G,formattedNumberValueObject:$,regionCode:M,prefix:k,loading:K}=D,S=G.replace(/\D/g,"").length<4;n(()=>{if(Y.current){Y.current=!1;const e=_(G);d?.(e),i?.(e)}},[G,i,d]);const W=a("Ls4zP",z&&"gqw6M"),Z=!p&&M&&G&&G.length>1,H=M??e;n(()=>{H!==e&&j?.(H.toUpperCase(),G)},[j,H,e,G]);const J=r(e=>{i?.(_(e))},[i]),X=!K&&(Z||b)&&!S&&s("div",{className:W,children:[s("div",{className:"wTRvB",children:s(h,{countryCode:H.toLowerCase(),accessibilityLabel:H.toUpperCase()})}),s(l,{type:"chevron-down",size:"small-200",tone:z?"accent":void 0}),s("select",{"aria-label":U.translate("contact.phone_country_code_label"),className:"KHvfK",value:H.toUpperCase(),onBlur:()=>R(!1),onFocus:()=>R(!0),name:"phone_country_select",onChange:e=>{Y.current=!0,D.selectCountry(e.target.value),V.current&&V.current.focus()},children:s(O,{})})]}),Q=t(null),ee=(E||X)&&s(u,{direction:"inline",gap:"base",alignItems:"center",children:[E,X]});return{...P,icon:"mobile"===B?"mobile":q,onChange:i&&J,required:A||b,onInputCommit:e=>{const t=function(e){return b&&!e.includes("+")?`${k}${e}`:e}(e);V?.current&&V.current.value!==t&&(V.current.value=t);const n=_(t),r=V?.current?.selectionEnd||0,o=_(t.slice(0,r));null!=Q.current&&clearTimeout(Q.current),Q.current=setTimeout(()=>{const e=V.current?.type;"tel"!==e&&e!==y||V.current?.value&&L(function(e,t){let n=0,r=e;for(const o of t){if(!r&&!N(o))break;o===r[0]&&(r=r.substring(1)),n++}return n}(o,V.current.value),V.current)}),v?(w?.(t,r),d?.(t)):n!==_(G)&&(w?.(n,r),d?.(n)),(/[a-zA-Z]/.test(t)||n!==_(G))&&D.setPhoneNumber(n)},ref:V,autocomplete:F,value:T,controlledValue:v?void 0:$,onFocus:()=>{void 0!==x&&V.current&&void 0!==T&&x-1}function L(e,t){document.activeElement===t&&(t.focus(),t.setSelectionRange(e,e))}function w(e){const t=b(e);return s(d,{...t})}function O(){const{fetchCountriesWithPhoneNumberPrefix:e}=v(),[t,r]=o([]),{observability:a,i18n:{locale:i}}=f();return n(()=>{e(i).then(e=>{r(e)}).catch(e=>{a.log("atlas_fetch_countries_error",`Unable to fetch countries with phone number prefix: ${e.name}: ${e.message}`,{errorName:e.name,errorMessage:e.message,locale:i})})},[e,i,a]),s(c,{children:t.map(({code:e,name:t,phoneNumberPrefix:n})=>s("option",{value:e,children:[t,"(+",n,")"]},e))})}export{h as i,b as n,_ as r,w as t};