import{s as e}from"./rolldown-runtime-C5c2KzVm.js";import{$P as t}from"./lucide-C4oWPzu4.js";import{p as n}from"./utils-Bs-0X7qI.js";import{r}from"./bundle-mjs-C4g7ASB5.js";var i=e(t(),1),a=(0,i.createContext)(null);function o(e,t){let n=t.split(`.`),r=e;for(let e of n){if(typeof r!=`object`||!r)return;r=r[e]}return typeof r==`string`?r:void 0}function s(e,t){return e.replace(/\{(\w+)\}/g,(e,n)=>n in t?String(t[n]):e)}function c(e,t,n,r){let i=(t&&o(t,e))??(n&&o(n,e))??e;return r?s(i,r):i}var l=n(),u=r(),d=`buildingai-ui-locale`;function f(e,t){if(typeof navigator>`u`)return t;let n=navigator.languages??[navigator.language];for(let t of n){if(e.includes(t))return t;let n=t.split(`-`)[0]??``,r=e.find(e=>e.startsWith(n));if(r)return r}return t}function p(e,t,n){if(typeof window>`u`)return t;let r=localStorage.getItem(n);return r&&e.includes(r)?r:f(e,t)}function m(e){let t=(0,l.c)(21),{messages:n,defaultLocale:r,fallbackLocale:o,storageKey:s,children:f}=e,m=s===void 0?d:s,h;t[0]===n?h=t[1]:(h=Object.keys(n),t[0]=n,t[1]=h);let g=h,_;t[2]!==g||t[3]!==r||t[4]!==m?(_=()=>p(g,r,m),t[2]=g,t[3]=r,t[4]=m,t[5]=_):_=t[5];let[v,y]=(0,i.useState)(_),b;t[6]!==g||t[7]!==m?(b=e=>{if(!g.includes(e)){console.warn(`[i18n] Locale "${e}" is not available.`);return}y(e),localStorage.setItem(m,e)},t[6]=g,t[7]=m,t[8]=b):b=t[8];let x=b,S=o??r,C;t[9]!==v||t[10]!==n||t[11]!==S?(C=(e,t)=>c(e,n[v],v===S?void 0:n[S],t),t[9]=v,t[10]=n,t[11]=S,t[12]=C):C=t[12];let w=C,T;t[13]!==g||t[14]!==v||t[15]!==x||t[16]!==w?(T={t:w,locale:v,setLocale:x,availableLocales:g},t[13]=g,t[14]=v,t[15]=x,t[16]=w,t[17]=T):T=t[17];let E=T,D;return t[18]!==f||t[19]!==E?(D=(0,u.jsx)(a,{value:E,children:f}),t[18]=f,t[19]=E,t[20]=D):D=t[20],D}function h(){let e=(0,i.useContext)(a);if(!e)throw Error(`[i18n] useI18n must be used within an <I18nProvider>.`);return e}export{m as n,h as t};