import"./index.4b7607b5.js";import{_ as x,e as k,U as b,r as g,o as u,c as p,a as y,b as f,d as s,f as c,w as h,n as w,g as S,F as I,A as $,h as A,i as C,T as j,j as V,k as _,t as F}from"./index.c8fd93d6.js";import{F as L}from"./index.dbe0636e.js";import{T as B}from"./index.ab35056f.js";import{L as T}from"./Loading.6052584f.js";import{c as U,a as v,V as D}from"./object.413f31be.js";import{_ as E}from"./ck-white.4bf441fa.js";import{_ as N,a as R}from"./logo-white.e9971405.js";import"./vue-cleave.min.7c593396.js";import"./_commonjsHelpers.de833af9.js";const z={inject:{$ability:{from:k}},components:{FormGroup:L,TextInput:B,Loading:T},data(){return{checkbox:!1,form:{email:null,password:null},errors:{},state:{isLoggingIn:!1,isRedirecting:!1},systemIds:[]}},methods:{async submitForm(){console.log("submitting");try{let t={},o=null;const d=await U().shape({username:v().required("Username is required"),password:v().nullable().required("Password is required")}).validate(this.form,{abortEarly:!1});this.$store.userSettings.clear(),await b.login(this.form).then(e=>{if(console.log(e),e.status==200){this.$store.userSettings.menus=null,t=e.data.user,o=e.data.authorization.token,localStorage.setItem("activeUser",JSON.stringify(t)),localStorage.setItem("jwtToken",o),localStorage.setItem("roles",JSON.stringify(t.roles)),this.$store.userSettings.setActiveUser(t),this.$store.userSettings.setActiveCompany(t.default_company_id??11),this.$store.userSettings.setActiveDealership(t.default_dealership_id??44);let l=null;t.employee&&t.employee.department_id&&t.employee.department_id>0?l=t.employee.department_id:t.department_access&&t.department_access.length>0&&(l=t.department_access[0].id),this.$store.userSettings.setActiveDepartment(l),this.$store.userSettings.fetchCompanyAccess(),this.$store.userSettings.setRolesFromLocal(),this.fetchAbilities(t.roles.map(i=>({id:i.id,group_id:i.group_id})),o),this.$router.push("/"),this.$swal.fire({title:"Great!",text:"Login successfully.",icon:"success",timer:2e3}),this.state.isLoggingIn=!1,this.state.isRedirecting=!0}}).catch(e=>{e.response&&e.response.status==401?this.$swal.fire("Unauthorized access","error"):(console.error(e),this.$swal.fire("Ooops! something is wrong","Failed to connect to the server. Please contact system administrator","error"))}).finally(()=>{this.state.isLoggingIn=!1})}catch(t){if(t instanceof D){const o={};t.inner.forEach(a=>{o[a.path]=a.message}),this.errors=o,console.log(this.errors)}this.state.isSaving=!1}},async fetchAbilities(t,o){const{can:a,rules:d}=new $(A),e=[...new Set(t.map(i=>i.group_id))].includes(1);if(this.systemIds=[],e)a("manage","all"),this.systemIds.push(99);else{let i=[];await b.fetchCompanyPermissions({roles:t.map(n=>n.id)},o).then(n=>{n.data.data&&(i=n.data.data)}).catch(n=>{console.log(n)}).finally(()=>{if(i.length>0){const n=i==null?void 0:i.filter(r=>r.dealership_id=="0").map(r=>r.permission_id);i.forEach(r=>{r.module&&(this.systemIds.push(r.module.system_id),r.dealership_id=="0"?a(r.permission.code,r.module.code):n.includes(r.permission_id)||a(r.permission.code,r.module.code))})}})}this.$store.userSettings.setCapabilities(d),this.$ability.update(d);const l=this.systemIds.length>0?[...new Set(this.systemIds)]:[];this.$store.userSettings.setSystemAccess(l)}},mounted(){this.$store.userSettings.clear()}},P={class:"flex justify-between"},G={class:"cursor-pointer flex items-start"},q={key:0,src:E,alt:"",class:"h-[10px] w-[10px] block m-auto"},O=s("span",{class:"text-slate-500 dark:text-slate-400 text-sm leading-6"},"Keep me signed in",-1);function H(t,o,a,d,e,l){const i=g("Loading"),n=g("TextInput"),r=g("FormGroup");return u(),p(I,null,[e.state.isLoggingIn?(u(),y(i,{key:0,text:"Logging-in"})):f("",!0),e.state.isRedirecting?(u(),y(i,{key:1,text:"Redirecting to Dashboard"})):f("",!0),s("form",{onSubmit:o[3]||(o[3]=S((...m)=>l.submitForm&&l.submitForm(...m),["prevent"])),class:"space-y-4"},[c(r,{label:"Username",labelClass:"text-white"},{default:h(()=>[c(n,{type:"text",placeholder:"Type your username",name:"username",modelValue:e.form.username,"onUpdate:modelValue":o[0]||(o[0]=m=>e.form.username=m),error:e.errors.username,classInput:"h-[48px]"},null,8,["modelValue","error"])]),_:1}),c(r,{label:"Password",labelClass:"text-white"},{default:h(()=>[c(n,{type:"password",placeholder:"Type your password ",name:"password",modelValue:e.form.password,"onUpdate:modelValue":o[1]||(o[1]=m=>e.form.password=m),error:e.errors.password,hasicon:"",classInput:"h-[48px]"},null,8,["modelValue","error"])]),_:1}),s("div",P,[s("label",G,[s("input",{type:"checkbox",class:"hidden",onChange:o[2]||(o[2]=()=>e.checkbox=!e.checkbox)},null,32),s("span",{class:w(["h-4 w-4 border rounded flex-none inline-flex mr-3 relative top-1 transition-all duration-150",e.checkbox?"ring-2 ring-black-500 dark:ring-offset-slate-600 dark:ring-slate-900 dark:bg-slate-900 ring-offset-2 bg-slate-900":"bg-slate-100 dark:bg-slate-600 border-slate-100 dark:border-slate-600 "])},[e.checkbox?(u(),p("img",q)):f("",!0)],2),O])]),s("button",{type:"submit",class:w(["btn block w-full text-center","bg-pink-800 text-white"])}," Sign in ")],32)],64)}const J=x(z,[["render",H]]),W="/assets/tw.a0c0a20c.svg",K="/assets/fb.011c6dd1.svg",M="/assets/in.9a3966ff.svg",Y="/assets/gp.9fa58808.svg",Q={},X={class:"flex"},Z=C('