1import{_ as M}from"./cYNDVzUy.js";import{_ as N}from"./DeHp9kj6.js";import{Y as P,J as F,e as R,f as V,l as m,i as h,K as j,c as i,a as r,q as S,t as n,g as e,F as k,r as q,v as A,d as E,o,s as G,ab as I,T as O}from"./BwpL3H6q.js";function U(){const{apiFetch:y}=P(),a=F();return{list:()=>{var c;const l=(c=a.user)==null?void 0:c.id;return l?y(`/users/${l}/discounts`):Promise.resolve([])},generate:()=>{var c;const l=(c=a.user)==null?void 0:c.id;return l?y(`/users/${l}/discounts`,{},{method:"POST"}):Promise.reject(new Error("Missing authenticated user"))}}}const D={class:"flex flex-col gap-6"},J={class:"font-bold text-primary-300"},K={class:"text-md"},Y={key:0,class:"flex flex-col gap-3"},z={class:"flex flex-col"},H={class:"text-lg font-bold text-secondary-300 tracking-widest"},Q={key:0,class:"text-xs"},W={class:"text-xs"},X=["onClick"],Z={key:1,class:"text-md"},ee={class:"flex flex-col items-start gap-2"},se=["disabled"],te={key:0,class:"text-xs"},ae={key:1,class:"text-xs"},oe={key:2,class:"text-xs"},ne={key:3,class:"text-xs"},de=R({__name:"sponsorship",setup(y){const{t:a,d:w}=V(),_=F(),{list:l,generate:c}=U(),u=m([]),x=m(!0),f=m(!1),C=h(()=>{var s;const t=((s=_.user)==null?void 0:s.websites)??[],d=t.find(b=>b.default===1)??t[0];return(d==null?void 0:d.referral_per_user)??0}),v=m(!1),B=h(()=>{var t;return!!((t=_.user)!=null&&t.active||_.validLicense)}),g=h(()=>Math.max(0,C.value-u.value.length)),T=h(()=>!f.value&&B.value&&!v.value&&g.value>0);j(()=>{$()});async function $(){x.value=!0;try{const t=await l();u.value=Array.isArray(t)?t:[]}catch(t){console.error(t)}finally{x.value=!1}}async function L(){var t,d;if(T.value){f.value=!0;try{const s=await c();s!=null&&s.id&&(u.value=[s,...u.value])}catch(s){((s==null?void 0:s.statusCode)===403||((t=s==null?void 0:s.response)==null?void 0:t.status)===403)&&(v.value=!0,await $()),O.error(((d=s==null?void 0:s.data)==null?void 0:d.message)??a("errors.default"),{position:"top-right"})}finally{f.value=!1}}}return(t,d)=>{const s=M,b=N;return o(),i("div",D,[r("h3",J,n(e(a)("titles.sponsor")),1),r("p",K,n(e(a)("sponsor.intro")),1),e(x)?(o(),S(s,{key:0})):(o(),i(k,{key:1},[e(u).length>0?(o(),i("ul",Y,[(o(!0),i(k,null,q(e(u),p=>(o(),i("li",{key:p.id,class:"bg-white rounded-lg shadow p-4 flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between"},[r("div",z,[r("span",H,n(p.serial),1),p.name?(o(),i("span",Q,n(p.name),1)):G("",!0),r("span",W,n(e(a)("basics.validity"))+" : "+n(e(w)(p.valid_to)),1)]),r("button",{onClick:A(ie=>("copyToClipboard"in t?t.copyToClipboard:e(I))(`${p.serial}`,e(a)("cta.copied")),["prevent"]),class:"btn btn-action self-start sm:self-auto"}
1,n(e(a)("cta.copy")),9,X)]))),128))])):(o(),i("p",Z,n(e(a)("sponsor.empty")),1)),r("div",ee,[r("button",{class:"btn-action disabled:opacity-50 disabled:cursor-not-allowed",disabled:!e(T),onClick:A(L,["prevent"])},[e(f)?(o(),S(b,{key:0,code:"loader",cls:"fill-white",height:"1.5rem",class:"animate-spin"})):(o(),i(k,{key:1},[E(n(e(a)("sponsor.generate")),1)],64))],8,se),e(B)?e(C)<=0?(o(),i("p",ae,n(e(a)("sponsor.unavailable")),1)):e(v)||e(g)<=0?(o(),i("p",oe,n(e(a)("sponsor.limitReached")),1)):(o(),i("p",ne,n(e(a)("sponsor.remaining",{n:e(g)})),1)):(o(),i("p",te,n(e(a)("sponsor.needCard")),1))])],64))])}}});export{de as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.