import{c as i,e as s,f as l,k as a,j as c,u,l as d,v as m,x as f,y as h,z as y,q as r}from"./vue-Bqg3cjzV.js";import{_ as v}from"./index-CbGDU7fj.js";const b={name:"ActivateLicense",data:()=>({company_reference:"",license_token:"",reason:null,expiresAt:null}),created(){const t=this.$route.query||{};this.reason=t.reason||null,this.expiresAt=t.expires_at||null,this.company_reference=t.company_reference||"",this.$auth.active()&&this.loadCompanyReference()},methods:{loadCompanyReference(){return this.$http.get("auth/me").then(t=>{const e=t.data?.user?.company;e?.reference&&!this.company_reference&&(this.company_reference=e.reference)})},activate(){return this.$http.post("license/activate",{company_reference:this.company_reference,license_token:this.license_token}).then(t=>{this.$notify({type:"success",message:t.data.message||"Activated."}),this.$auth.active()?this.$router.replace("/dashboard"):this.$router.replace("/")}).catch(t=>{const e=t?.response?.data?.message||t?.response?.data?.reason||"Activation failed.";this.$notify({type:"error",message:e})})},checkStatus(){if(!this.company_reference){this.$notify({type:"error",message:"Enter company reference first."});return}this.$http.get("license/status",{params:{company_reference:this.company_reference}}).then(t=>{this.reason=t.data.reason||null,this.expiresAt=t.data.expires_at||null;const e=!!t.data.licensed;this.$notify({type:e?"success":"warning",message:e?"License is valid.":"License is missing/expired."})}).catch(()=>{this.$notify({type:"error",message:"Status check failed."})})}}},k={class:"authentication-bg min-vh-100"},g={class:"container"},_={class:"d-flex flex-column min-vh-100 px-3 pt-4"},x={class:"row justify-content-center my-auto"},$={class:"col-lg-8"},A={class:"py-5"},C={class:"card overflow-hidden"},L={class:"card-body p-4 p-lg-5"},w={key:0,class:"alert alert-warning",role:"alert"},S={key:0},E={class:"mb-3"},N={class:"mb-3"},V={class:"d-flex gap-2"};function q(t,e,B,R,T,o){const p=y("RouterLink");return r(),i("div",k,[s("div",g,[s("div",_,[s("div",x,[s("div",$,[s("div",A,[s("div",C,[s("div",L,[e[12]||(e[12]=s("h4",{class:"mb-2"},"Activate License",-1)),e[13]||(e[13]=s("p",{class:"text-muted mb-4"}," This installation needs a valid offline license token to continue. ",-1)),t.reason?(r(),i("div",w,[e[6]||(e[6]=s("b",null,"Reason:",-1)),a(" "+c(t.reason)+" ",1),t.expiresAt?(r(),i("span",S,[e[4]||(e[4]=a(" | ",-1)),e[5]||(e[5]=s("b",null,"Expires at:",-1)),a(" "+c(t.expiresAt),1)])):l("",!0)])):l("",!0),s("form",{onSubmit:e[3]||(e[3]=u((...n)=>o.activate&&o.activate(...n),["prevent"]))},[s("div",E,[e[7]||(e[7]=s("label",{class:"form-label"},"Company reference",-1)),d(s("input",{class:"form-control",type:"text","onUpdate:modelValue":e[0]||(e[0]=n=>t.company_reference=n),placeholder:"e.g. CNIDH-001",required:""},null,512),[[m,t.company_reference]]),e[8]||(e[8]=s("small",{class:"text-muted"},"This is `companies.reference` in the database.",-1))]),s("div",N,[e[9]||(e[9]=s("label",{class:"form-label"},"License token",-1)),d(s("textarea",{class:"form-control",rows:"5","onUpdate:modelValue":e[1]||(e[1]=n=>t.license_token=n),placeholder:"paste license token here",required:""},null,512),[[m,t.license_token]])]),s("div",V,[e[11]||(e[11]=s("button",{class:"btn btn-primary",type:"submit"}," Activate ",-1)),f(p,{class:"btn btn-outline-secondary",to:"/"},{default:h(()=>[...e[10]||(e[10]=[a(" Back to login ",-1)])]),_:1}),s("button",{class:"btn btn-outline-info ms-auto",type:"button",onClick:e[2]||(e[2]=(...n)=>o.checkStatus&&o.checkStatus(...n))}," Check status ")])],32)])]),e[14]||(e[14]=s("div",{class:"mt-3 text-muted small"}," Admin note: server must have `LICENSE_PUBLIC_KEY` configured in `.env`. ",-1))])])])])])])}const U=v(b,[["render",q]]);export{U as default};
