var l={exports:{}},i={};/**
 * @license React
 * react-jsx-runtime.production.js
 *
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */var h;function S(){if(h)return i;h=1;var t=Symbol.for("react.transitional.element"),e=Symbol.for("react.fragment");function n(u,r,o){var s=null;if(o!==void 0&&(s=""+o),r.key!==void 0&&(s=""+r.key),"key"in r){o={};for(var a in r)a!=="key"&&(o[a]=r[a])}else o=r;return r=o.ref,{$$typeof:t,type:u,key:s,ref:r!==void 0?r:null,props:o}}return i.Fragment=e,i.jsx=n,i.jsxs=n,i}var p;function R(){return p||(p=1,l.exports=S()),l.exports}var w=R();const v="crew_token",E="crew_usuario";function m(){return localStorage.getItem(v)}function x(){const t=localStorage.getItem(E);if(!t)return null;try{return JSON.parse(t)}catch{return null}}function k(){localStorage.removeItem(v),localStorage.removeItem(E)}async function T(t){const e=x();if(!e)return!1;try{return(await fetch("/api/auth/login",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({identificador:e.correo,contrasena:t})})).ok}catch{return!1}}const f="/api";async function c(t,e={}){const n=m(),u={"Content-Type":"application/json",...n?{Authorization:`Bearer ${n}`}:{},...e.headers||{}},r=await fetch(`${f}${t}`,{...e,headers:u,credentials:"include"});if(r.status===401){if(!t.includes("/auth/login")&&!t.includes("/auth/refresh"))try{const o=await fetch(`${f}/auth/refresh`,{method:"POST",credentials:"include"});if(o.ok){const s=await o.json();localStorage.setItem("crew_token",s.access_token);const a={...u,Authorization:`Bearer ${s.access_token}`},d=await fetch(`${f}${t}`,{...e,headers:a,credentials:"include"});if(d.ok)return d.status===204?void 0:d.json()}}catch{}throw k(),window.location.href="/login",new Error("Sesión expirada")}if(!r.ok){const o=await r.json().catch(()=>({error:"Error desconocido"}));throw new Error(o.error||`Error ${r.status}`)}if(r.status!==204)return r.json()}const y={get:t=>c(t),post:(t,e)=>c(t,{method:"POST",body:e?JSON.stringify(e):void 0}),put:(t,e)=>c(t,{method:"PUT",body:e?JSON.stringify(e):void 0}),patch:(t,e)=>c(t,{method:"PATCH",body:e?JSON.stringify(e):void 0}),delete:t=>c(t,{method:"DELETE"})};export{y as a,m as b,k as c,w as j,x as o,T as v};
