import{c as v,j as e,r as h,t as m,u as j,a as u}from"./index-DiwDH9aE.js";import{B as N}from"./Button-Cu8l7rID.js";import{C}from"./graduation-cap-B3zNhUOw.js";import{u as n}from"./cycleStore-Brm22ojq.js";import"./multiUserApiClient-CKPzIhIr.js";import{r as E}from"./registerService-CxQfNS19.js";/**
 * @license lucide-react v0.544.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const k=[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]],w=v("refresh-cw",k),A=({refresh:a,compact:t=!1})=>{const c=e.jsxs(e.Fragment,{children:[!t&&e.jsx("div",{className:"bg-gradient-to-r from-red-500 to-rose-600 px-6 sm:px-8 py-6 rounded-t-2xl",children:e.jsx("div",{className:"flex justify-center",children:e.jsx("div",{className:"w-16 h-16 bg-white/95 backdrop-blur-sm rounded-2xl flex items-center justify-center shadow-lg",children:e.jsx(C,{className:"w-8 h-8 text-red-600"})})})}),e.jsxs("div",{className:t?"py-4":"px-6 sm:px-8 py-8",children:[e.jsx("h3",{className:`font-bold text-gray-900 text-center mb-6 ${t?"text-lg":"text-2xl sm:text-3xl"}`,children:"No hay Ciclos Vigentes"}),e.jsxs("div",{className:"bg-gradient-to-br from-amber-50 to-orange-50 border-2 border-amber-200 rounded-xl p-4 sm:p-5 mb-5",children:[e.jsx("p",{className:`font-semibold text-amber-900 mb-3 ${t?"text-sm":"text-base"}`,children:"⏳ Estado del sistema:"}),e.jsxs("ul",{className:`space-y-2 text-amber-800 ${t?"text-xs":"text-sm"}`,children:[e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"text-amber-500 mt-0.5",children:"•"}),e.jsxs("span",{children:["El ciclo académico ha sido ",e.jsx("span",{className:"font-semibold",children:"desactivado"})]})]}),e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"text-amber-500 mt-0.5",children:"•"}),e.jsx("span",{children:"El acceso estará disponible cuando se active el nuevo ciclo"})]}),e.jsxs("li",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"text-amber-500 mt-0.5",children:"•"}),e.jsx("span",{children:"Mantente atento a nuestros canales oficiales"})]})]})]}),e.jsx(N,{type:"button",variant:"primary",size:t?"md":"lg",text:"Verificar nuevamente",leftIcon:e.jsx(w,{className:t?"w-4 h-4":"w-5 h-5"}),onClick:a,fullWidth:!0})]})]});return t?e.jsx("div",{className:"mt-6",children:c}):e.jsx("div",{className:"bg-white rounded-2xl shadow-xl overflow-hidden max-w-2xl mx-auto",children:c})},P=(a=!0,t=!1)=>{const c=n(s=>s.cycle),i=n(s=>s.isLoading),x=n(s=>s.error),l=n(s=>s.setCycle),o=n(s=>s.clearCycle),r=n(s=>s.setLoading),d=n(s=>s.setError),f=h.useCallback(async()=>{r(!0);try{const s=await E.checkCycle();return s.success&&s.data?(l(s.data),t&&m.success(s.message||"Ciclo cargado correctamente"),{success:!0,data:s.data}):(o(),t&&m.warning(s.message||"No hay ciclo activo disponible"),{success:!1,message:s.message||"No hay ciclo activo"})}catch(s){console.error("Error verificando ciclo:",s);const p=s.message||"Error al verificar ciclo";return d(p),o(),t&&m.error(p),{success:!1,message:p}}finally{r(!1)}},[l,o,r,d,t]);h.useEffect(()=>{a&&f()},[a,f]);const g=!!c,y=g&&c.active===!0,b=y&&c.enrollment_open===!0;return{cycle:c,loading:i,error:x,hasCycle:g,isCycleActive:y,isEnrollmentOpen:b,refresh:f}},R=()=>{const a=j(),t=u(r=>r.user),c=u(r=>r.getUserType),i=u(r=>r.logout),x=n(r=>r.isEnrollmentOpen),l=()=>{if(!t){a("/login",{replace:!0});return}const r=c();switch(r){case"admin":a("/admin",{replace:!0});break;case"teacher":a("/teacher",{replace:!0});break;case"student":o();break;default:console.error("Tipo de usuario no reconocido:",r),i(),a("/login",{replace:!0})}},o=()=>{const r=t?.meta?.is_registration_completed,d=x();if(r===!0){a("/student",{replace:!0});return}if(!d){i(),a("/login",{replace:!0,state:{message:"Las inscripciones están cerradas. Por favor, contacta con la administración.",type:"warning"}});return}a("/student/onboarding",{replace:!0})};return{redirectByRole:l}},$=(a=!1)=>{const t=u(i=>i.user),{redirectByRole:c}=R();h.useEffect(()=>{t&&(a&&m.info("Ya tienes una sesión activa"),c())},[t,c,a])};export{A as N,w as R,P as a,$ as u};
