// i18n + router hooks
window.useLang=function(){
  const [lang,setLang]=React.useState(()=>localStorage.getItem("dd_lang")||"fr");
  React.useEffect(()=>{localStorage.setItem("dd_lang",lang);
    document.documentElement.lang=lang;},[lang]);
  return [lang,setLang];
};
window.useT=function(lang){
  const C=lang==="fr"?T_FR_COMMON:T_EN_COMMON;
  const P=lang==="fr"?T_FR_PAGE:T_EN_PAGE;
  const F=lang==="fr"?T_FR_FORM:T_EN_FORM;
  return {...C,...P,...F};
};
window.useRoute=function(){
  const [hash,setHash]=React.useState(window.location.hash||"#/");
  React.useEffect(()=>{
    const on=()=>{setHash(window.location.hash||"#/");window.scrollTo(0,0)};
    window.addEventListener("hashchange",on);
    return ()=>window.removeEventListener("hashchange",on);
  },[]);
  return hash.replace("#","").split("#")[0]||"/";
};
window.useFetch=function(path,fallback){
  var fb=fallback||[];
  var _=React.useState(fb),data=_[0],setData=_[1];
  var __=React.useState(true),loading=__[0],setLoading=__[1];
  React.useEffect(function(){
    apiFetch(path).then(setData).catch(function(){setData(fb);}).finally(function(){setLoading(false);});
  },[path]);
  return {data:data,loading:loading};
};
window.WA_NUMBER="+230 5453 7576";
window.WA_LINK="https://wa.me/23054537576";
window.fmtMUR=(n,lang)=>{
  const s=new Intl.NumberFormat(lang==="fr"?"fr-FR":"en-US").format(n);
  return s+" MUR";
};
