(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[520],{2386:(e,t,a)=>{"use strict";a.r(t),a.d(t,{default:()=>i});var s=a(5155),r=a(2115),o=a(2651),l=a(6046),n=a(6868);function i(){let{setUsername:e}=(0,n.A)(),[t,a]=(0,r.useState)(""),[i,d]=(0,r.useState)(""),[c,u]=(0,r.useState)(!1),[m,g]=(0,r.useState)(!1),b=(0,l.useRouter)();(0,r.useEffect)(()=>{let e=localStorage.getItem("rememberedUsername");e&&(a(e),u(!0))},[]);let h=async()=>{if(!m){if(!t.trim()||!i.trim()){alert("Please fill in all fields");return}g(!0);try{let{token:a,token_type:s,user:r}=(await o.A.post("https://cetaksuratkp-api.humicprototyping.net/api/login",{email:t,password:i})).data.data,l="".concat(s," ").concat(a);localStorage.setItem("authToken",l),localStorage.setItem("user",JSON.stringify(r)),e(r.name),c?localStorage.setItem("rememberedUsername",t):localStorage.removeItem("rememberedUsername"),b.push("/homepage")}catch(e){var a,s,r;(null===(a=e.response)||void 0===a?void 0:a.status)===422?alert(Object.values(e.response.data.errors||{}).flat().join("\n")||e.response.data.message||"Validation failed. Please check your inputs."):alert((null===(r=e.response)||void 0===r?void 0:null===(s=r.data)||void 0===s?void 0:s.message)||"Login failed"),console.error("Login error:",e)}finally{g(!1)}}};return(0,s.jsxs)("div",{className:"flex items-center justify-center min-h-screen bg-[#a32020] relative overflow-hidden",children:[(0,s.jsx)("div",{className:"absolute inset-0 bg-cover bg-center",style:{backgroundImage:"url('/assets/login.png')"}}),(0,s.jsxs)("div",{className:"relative bg-white p-12 rounded-lg shadow-md w-[500px]",children:[(0,s.jsx)("h2",{className:"text-center text-2xl font-semibold mb-6 text-black",children:"Log In with SSO"}),(0,s.jsxs)("div",{className:"mb-4",children:[(0,s.jsx)("label",{className:"block text-sm font-medium text-black",children:"Username"}),(0,s.jsx)("input",{type:"text",className:"text-black mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500",placeholder:"Enter Username",value:t,onChange:e=>a(e.target.value)})]}),(0,s.jsxs)("div",{className:"mb-4",children:[(0,s.jsx)("label",{className:"block text-sm font-medium text-black",children:"Password"}),(0,s.jsx)("input",{type:"password",className:"text-black mt-1 block w-full px-3 py-2 border border-gray-300 rounded-md shadow-sm focus:outline-none focus:ring-indigo-500 focus:border-indigo-500",placeholder:"Password",value:i,onChange:e=>d(e.target.value)})]}),(0,s.jsxs)("div",{className:"flex items-center mb-4",children:[(0,s.jsx)("input",{type:"checkbox",className:"h-4 w-4 text-indigo-600 border-gray-300 rounded focus:ring-indigo-500",checked:c,onChange:e=>u(e.target.checked)}),(0,s.jsx)("label",{className:"ml-2 text-sm text-black",children:"Remember me"})]}),(0,s.jsx)("button",{className:"w-full px-4 py-2 text-white bg-indigo-600 hover:bg-indigo-700 rounded-md cursor-pointer disabled:opacity-60 disabled:cursor-not-allowed",onClick:h,disabled:m,children:m?"Logging in...":"Log In"})]})]})}},6149:(e,t,a)=>{Promise.resolve().then(a.bind(a,2386))},6868:(e,t,a)=>{"use strict";a.d(t,{A:()=>n,AuthProvider:()=>l});var s=a(5155),r=a(2115);let o=(0,r.createContext)(void 0);function l(e){let{children:t}=e,[a,l]=(0,r.useState)("");return(0,r.useEffect)(()=>{let e=localStorage.getItem("user");if(e){let t=JSON.parse(e);(null==t?void 0:t.name)&&l(t.name)}},[]),(0,s.jsx)(o.Provider,{value:{username:a,setUsername:l,logout:()=>{localStorage.removeItem("authToken"),localStorage.removeItem("user"),l("")}},children:t})}function n(){let e=(0,r.useContext)(o);if(!e)throw Error("useAuth must be used within an AuthProvider");return e}}},e=>{var t=t=>e(e.s=t);e.O(0,[251,651,441,587,358],()=>t(6149)),_N_E=e.O()}]);