import{r as p,_ as U,R as z,c as A,P as _,e as P,i as $,j as e,L as q,f as j}from"./index-sga-FecS.js";import{b as B,a as l,c}from"./index.esm-7CdJvro0.js";import{a as J,c as M}from"./university-logo-full-HPG0vyLU.js";import{C as w,a as f}from"./CRow-BaMSc2yS.js";import{C as k,a as L}from"./CCardBody-e8lVonr1.js";import{C as O}from"./CForm-C4v7yst3.js";import{C as D}from"./CAlert-UiIGbbv-.js";import{C as S,a as d}from"./CInputGroupText-BmnVX3pg.js";import{c as T,a as I}from"./cil-user-Dlmw-Gem.js";import{C as R}from"./CFormInput-DmJ_XO-V.js";const C=p.forwardRef((n,s)=>{var{children:o,className:x}=n,t=U(n,["children","className"]);return z.createElement("div",Object.assign({className:A("card-group",x)},t,{ref:s}),o)});C.propTypes={children:_.node,className:_.string};C.displayName="CCardGroup";function re({onLoginSuccess:n}){const{t:s,i18n:o}=P(),x=$(),[t,E]=p.useState({username:"",password:""}),[u,g]=p.useState({type:"",text:""}),[y,N]=p.useState(!1),b=i=>{const{name:a,value:m}=i.target;E({...t,[a]:m})},v=i=>{o.changeLanguage(i)},F=async i=>{localStorage.clear(),sessionStorage.clear(),document.cookie.split(";").forEach(a=>{document.cookie=a.replace(/^ +/,"").replace(/=.*/,"=;expires=Thu, 01 Jan 1970 00:00:00 UTC;path=/")}),i.preventDefault(),g({type:"",text:""}),N(!0);try{const a=o.language==="ar"?"/ar":"/en",h=(await j.post(`${a}/api/auth-token/`,t)).data.token;localStorage.setItem("authToken",h),j.defaults.headers.common.Authorization=`Token ${h}`;const G=(await j.get(`${a}/api/users/me/`)).data;localStorage.setItem("currentUser",JSON.stringify(G)),n&&n(h),x("/"),g({type:"success",text:s("login_successful")})}catch(a){console.error("Login error:",a.response?a.response.data:a.message);const m=a.response?.data?.non_field_errors||a.response?.data?.detail||a.message;g({type:"error",text:s("login_failed",{message:m})})}finally{N(!1)}},r=o.language==="ar";return e.jsx("div",{className:"bg-body-tertiary min-vh-100 d-flex flex-row align-items-center",dir:r?"rtl":"ltr",children:e.jsx(B,{children:e.jsx(w,{className:"justify-content-center",children:e.jsx(f,{md:10,lg:8,children:e.jsxs(C,{children:[e.jsx(k,{className:"p-4",children:e.jsxs(L,{children:[e.jsxs("div",{className:"d-flex justify-content-between align-items-center mb-4",children:[e.jsx("div",{className:"d-flex align-items-center gap-2",children:e.jsx("img",{src:J,alt:s("university_name"),height:40,style:{objectFit:"contain"}})}),e.jsxs("div",{className:"d-flex align-items-center gap-2",children:[e.jsx(l,{color:r?"primary":"outline-primary",size:"sm",variant:r?"":"outline",onClick:()=>v("ar"),children:"العربية"}),e.jsx(l,{color:r?"outline-primary":"primary",size:"sm",variant:r?"outline":"",onClick:()=>v("en"),children:"English"}),e.jsx(c,{icon:M,className:"ms-1"})]})]}),e.jsxs(O,{onSubmit:F,children:[e.jsx("h2",{className:"mb-1",children:s("login_title")}),e.jsx("p",{className:"text-body-secondary mb-4",children:s("login_subtitle")}),u.text&&e.jsx(D,{color:u.type==="success"?"success":"danger",className:"mb-3",children:u.text}),e.jsxs(S,{className:"mb-3",children:[!r&&e.jsx(d,{children:e.jsx(c,{icon:T})}),e.jsx(R,{placeholder:s("login_username"),autoComplete:"username",id:"username",name:"username",value:t.username,onChange:b,required:!0}),r&&e.jsx(d,{children:e.jsx(c,{icon:T})})]}),e.jsxs(S,{className:"mb-4",children:[!r&&e.jsx(d,{children:e.jsx(c,{icon:I})}),e.jsx(R,{type:"password",placeholder:s("login_password"),autoComplete:"current-password",id:"password",name:"password",value:t.password,onChange:b,required:!0}),r&&e.jsx(d,{children:e.jsx(c,{icon:I})})]}),e.jsxs(w,{className:r?"flex-row-reverse":"",children:[e.jsx(f,{xs:6,children:e.jsx(l,{color:"primary",className:"px-4",type:"submit",disabled:y,children:s(y?"logging_in":"login")})}),e.jsx(f,{xs:6,className:r?"text-start":"text-end",children:e.jsx(l,{color:"link",className:"px-0",children:s("login_forgot_password")})})]})]})]})}),e.jsx(k,{className:"text-white bg-primary py-5 d-none d-md-block",style:{width:"100%"},children:e.jsx(L,{className:"text-center d-flex flex-column justify-content-center",children:e.jsxs("div",{className:"px-3",children:[e.jsx("h2",{className:"mb-3",children:s("login_welcome_title")}),e.jsx("p",{className:"mb-4",children:s("login_welcome_text")}),e.jsx(q,{to:"#",children:e.jsx(l,{color:"light",className:"mt-4",variant:"outline",children:s("login_need_help")})})]})})})]})})})})})}export{re as default};
