import{a as c}from"./chunk-PQ5Q7HJL.js";import{d as u}from"./chunk-72CHOCZD.js";import{S as s,X as i,g as n,xa as o}from"./chunk-56X5LYJH.js";var l=class a{constructor(t,e){this.translate=t;this.platformId=e;this.isBrowser=u(this.platformId),this.initializeLanguage()}supportedLangs=["en","ar"];langChange$=new n("ar");isBrowser;loadingSubject=new n(!0);loading$=this.loadingSubject.asObservable();initializeLanguage(){let t="ar";if(this.isBrowser){let e=localStorage.getItem("lang");t=e&&this.supportedLangs.includes(e)?e:"ar"}this.useLanguage(t,!0)}useLanguage(t,e=!1){return new Promise(r=>{if(!e&&this.translate.currentLang===t){r(!0);return}this.loadingSubject.next(!0),this.translate.use(t).subscribe({next:()=>{this.updateDocumentAttributes(t),this.langChange$.next(t),this.loadingSubject.next(!1),r(!0)},error:g=>{console.error("Language change failed:",g),e?(this.loadingSubject.next(!1),r(!1)):this.translate.use("ar").subscribe(()=>{this.updateDocumentAttributes("ar"),this.langChange$.next("ar"),this.loadingSubject.next(!1),r(!1)})}})})}updateDocumentAttributes(t){if(this.isBrowser){localStorage.setItem("lang",t);let e=t==="ar"?"rtl":"ltr";document.documentElement.dir=e,document.documentElement.lang=t,document.documentElement.setAttribute("lang",t),document.body.classList.remove("rtl","ltr"),document.body.classList.add(e)}}toggleLanguage(){let e=(this.translate.currentLang||"ar")==="en"?"ar":"en";return this.useLanguage(e)}get currentLang(){return this.translate.currentLang||"ar"}static \u0275fac=function(e){return new(e||a)(i(c),i(o))};static \u0275prov=s({token:a,factory:a.\u0275fac,providedIn:"root"})};export{l as a};
