import{j as t}from"./jsx-runtime-BMrMXMSG.js";import{B as b}from"./button-B6K71EBC.js";import{A as w,H as v}from"./Heading-XaJD9TaV.js";import{u as S,F as N,a as m}from"./index-BvM5axzC.js";import{S as L}from"./SocialAuth-khL-ycbD.js";import{a as A,u as k}from"./use-toast-8lerf42F.js";import{s as z}from"./authSlice-wB7ecGB_.js";import{d as C}from"./index-XrU1i-Uc.js";import{k as p}from"./components-Cr-DqYPJ.js";import{C as F,T as g}from"./triangle-alert-DbGJ6_AS.js";import"./utils-Br2EXFOw.js";const H=A.injectEndpoints({endpoints:a=>({login:a.mutation({query:o=>({url:"/auth/login/",method:"POST",body:{...o}}),transformResponse(o){return o.data},async onQueryStarted(o,{dispatch:n,queryFulfilled:s}){try{const{data:i}=await s;n(z(i))}catch(i){console.log(i)}}})})}),{useLoginMutation:T}=H,f={title:"Ready to pick up where you left off?",subtitle:"Log in to unleash your creativity, access your designs, orders, and keep personalizing your products"},h={title:"Login",subtitle:"Hey there! Welcome back 👋"},Y=()=>{const a=C(),o=S(),{handleSubmit:n}=o,{toast:s}=k(),[i,{isLoading:x}]=T(),y=j=>{i(j).unwrap().then(e=>{console.log(e),s({title:"Success",description:"You have successfully logged in",variant:"success",icon:t.jsx(F,{color:"green",size:35,className:"bg-green-100 p-1 rounded"})}),window.history.state&&window.history.state.idx>0?a(-1):a("/")}).catch(e=>{var r,l,c,d,u;(r=e==null?void 0:e.data)!=null&&r.data?s({title:"An error occurred",description:(c=(l=e==null?void 0:e.data)==null?void 0:l.data)!=null&&c.non_field_errors[0]?(u=(d=e==null?void 0:e.data)==null?void 0:d.data)==null?void 0:u.non_field_errors[0]:"Something went wrong, please try again",variant:"destructive",icon:t.jsx(g,{color:"red",size:35,className:"bg-red-100 p-1 rounded"})}):s({title:"An error occurred",description:"Something went wrong, please try again",variant:"destructive",icon:t.jsx(g,{color:"red",size:35,className:"bg-red-100 p-1 rounded"})})})};return t.jsx(w,{title:f.title,subtitle:f.subtitle,children:t.jsx(N,{...o,children:t.jsxs("form",{className:"flex flex-col gap-5 w-full",onSubmit:n(y),children:[t.jsx(v,{title:h.title,subtitle:h.subtitle}),t.jsx(m,{type:"email",fieldName:"email",required:!0}),t.jsx(m,{type:"password",fieldName:"password",required:!0}),t.jsx(p,{to:"/forgot-password",className:"font-semibold self-end hover:text-primary",children:"Forgot your password?"}),t.jsx(b,{size:"lg",text:"Log in",isLoading:x}),t.jsx(L,{displayText:"or login with"}),t.jsxs("p",{className:"flex gap-2 justify-center font-semibold mb-10",children:["Don't have an account?"," ",t.jsx(p,{to:"/user/signup",className:"text-primary",children:"Create account"})]})]})})})};export{Y as default};
