import{a as r,t as p}from"./index-DiwDH9aE.js";const u={getToken(){return r.getState().token},getUser(){return r.getState().user},getUserType(){return r.getState().getUserType()},getMeta(){return r.getState().meta},getPermissions(){return r.getState().getPermissions()},getRoles(){return r.getState().getRoles()},getMetaProperty(s){return r.getState().meta?.[s]||null},isAuthenticated(){return r.getState().isAuthenticated()},isTokenValid(){return r.getState().isTokenValid()},checkAuth(){return r.getState().checkAuth()},isStudent(){return r.getState().isStudent()},isTeacher(){return r.getState().isTeacher()},isAdmin(){return r.getState().isAdmin()},getAuthHeader(){return r.getState().getAuthHeader()},getHeaders(){const s=this.getAuthHeader();return s?{Authorization:s,"Content-Type":"application/json"}:{"Content-Type":"application/json"}},hasPermission(s){return this.getPermissions().includes(s)},hasAnyPermission(s){const e=this.getPermissions();return s.some(t=>e.includes(t))},hasAllPermissions(s){const e=this.getPermissions();return s.every(t=>e.includes(t))},hasRole(s){return this.getRoles().includes(s)},login(s){r.getState().login(s)},logout(){r.getState().logout()},syncAuth(s){r.getState().syncAuth(s)},updateUser(s){r.getState().updateUser(s)},updateMeta(s){r.getState().updateMeta(s)},updateMetaProperty(s,e){r.getState().updateMetaProperty(s,e)}};class c{constructor(e,t={}){this.baseURL=e,this.requiresAuth=t.requiresAuth||!1,this.defaultHeaders={Accept:"application/json"},this.isRedirecting=!1}buildHeaders(e={}){const t={...this.defaultHeaders,...e};if(this.requiresAuth){const n=u.getToken();n?t.Authorization=`Bearer ${n}`:console.warn("⚠️ Token no encontrado para petición autenticada")}return t}prepareRequestBody(e,t){if(e)return e instanceof FormData?e:(t["Content-Type"]="application/json",JSON.stringify(e))}async handleResponse(e){try{return await e.json()}catch{return console.warn("Respuesta no contiene JSON válido"),null}}handleSessionExpired(e=[]){this.isRedirecting||(this.isRedirecting=!0,u.logout(),p.error(response.message||"Tu sesión ha expirado. Por favor, inicia sesión nuevamente."))}async request(e,t={}){if(this.requiresAuth&&!u.isTokenValid())return this.handleSessionExpired(),null;const n=`${this.baseURL}${e}`,o=this.buildHeaders(t.headers),a={method:t.method||"GET",headers:o};t.body&&(a.body=this.prepareRequestBody(t.body,o));try{const i=await fetch(n,a);return i.status===401?(this.handleSessionExpired(i),null):await this.handleResponse(i)}catch(i){throw console.error("❌ Error de red:",i.message),new Error(`Error de conexión: ${i.message}`)}}async get(e,t={}){const{params:n,...o}=t;let a=e;if(n&&Object.keys(n).length>0){const i=new URLSearchParams(n).toString();a=`${e}?${i}`}return this.request(a,{method:"GET",...o})}async post(e,t={},n={}){return this.request(e,{method:"POST",body:t,...n})}async put(e,t={},n={}){return this.request(e,{method:"PUT",body:t,...n})}async patch(e,t={},n={}){return this.request(e,{method:"PATCH",body:t,...n})}async delete(e,t={}){return this.request(e,{method:"DELETE",...t})}}const l={API_RENIEC:"https://api.perudevs.com/api/v1/dni/complete",RENIEC_TOKEN:"cGVydWRldnMucHJvZHVjdGlvbi5maXRjb2RlcnMuNjhhNDhhYjI3NzAwMmUxM2U0NzI4YTAy"},g={development:{API_CEPRE:"http://cepre_laravel.test/api"},production:{API_CEPRE:"https://cepre-back.sys-code.com/api"}},d="production",h={...l,...g[d],IS_DEVELOPMENT:d==="development",API_TIMEOUT:3e4,RETRY_ATTEMPTS:3,USER_TYPES:{STUDENT:"student",TEACHER:"teacher",ADMIN:"admin"},STORAGE_KEYS:{TOKEN:"cepre_token",USER_DATA:"cepre_user",USER_TYPE:"cepre_user_type"}},m=new c(h.API_CEPRE,{requiresAuth:!1}),A=new c(h.API_CEPRE,{requiresAuth:!0});new c(h.API_RENIEC,{requiresAuth:!1});export{A as a,u as b,h as c,m as p};
