1import{e as ae,r as _,m as V,j as e,aW as oe,ai as v,b6 as le,G as ie,s as b}from"./index-Cbf19BJ2.js";import{A as ne,T as ce}from"./AdminLayout-BO09t3h9.js";import{C as g,a as y,b as f,c as k}from"./card-DgudV2Qs.js";import{S as de,a as xe,b as ue,c as me,d as q}from"./select-B8fJMIbm.js";import{U as pe}from"./users-Xzu6q5UA.js";import{R as he}from"./refresh-cw-jn-MXuPZ.js";import{R as K,d as je,T as z,c as G,a as O,X as W,Y as A,A as C,C as Q,b as E,B as Z,L as J}from"./ComposedChart-C6FWem8s.js";import{P as be,a as ge}from"./PieChart-B-IjQOb-.js";import{A as ke}from"./arrow-up-DdhgbpKp.js";import{A as ve}from"./arrow-down-Cr82GRtd.js";import{M as ye}from"./minus-jko-fS2V.js";import"./wallet-DiTxM8js.js";import"./list-D4zz6wAQ.js";import"./plus-BhsMqakM.js";import"./zap-bic735yl.js";import"./shopping-cart-J9DiLkwU.js";import"./package-C0aFhqOE.js";import"./circle-dot-BggEKS0Q.js";import"./truck-CiBM9Qd9.js";import"./mic-B7DTX7IA.js";import"./eye-Bp1ggn78.js";import"./upload-C7UHHK-4.js";import"./code-cui-3nIF.js";import"./file-code-Dc3Knbwk.js";import"./shield-CfgkgLd3.js";import"./credit-card-u85TQkWj.js";import"./globe-CgQQH_HA.js";import"./search-BLo06ZQ6.js";import"./ticket-G16NpKMh.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const fe=ae("UserMinus",[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["line",{x1:"22",x2:"16",y1:"11",y2:"11",key:"1shjgl"}]]);function N(c){return new Intl.NumberFormat("cs-CZ",{style:"currency",currency:"CZK",maximumFractionDigits:0}).format(c)}function u(c){return new Intl.NumberFormat("cs-CZ").format(c)}function Ne(c){return`${c.toFixed(1)}%`}function Je(){const[c,j]=_.useState("90"),{data:s,isLoading:p}=V({queryKey:["stats-membership-daily",c],queryFn:async()=>{const t=new Date;t.setDate(t.getDate()-parseInt(c));const{data:r,error:d}=await b.from("oz1_kalendar").select("datum, aktivni, neaktivni, novy, opak, poprve, expirace, klub_pocet, klub_trzba, klub_uip, klub_view, celkem_uip, celkem_view, web_uip, web_view, donio").gte("datum",t.toISOString().split("T")[0]).order("datum",{ascending:!0});if(d)throw d;return r||[]}}),{data:m,isLoading:D}=V({queryKey:["stats-membership-monthly"],queryFn:async()=>{const{data:t,error:r}=await b.from("oz1_kalendar_mesice").select("*").order("mesic",{ascending:!0});if(r)throw r;return t||[]}}),{data:P}=V({queryKey:["stats-membership-compare-daily"],queryFn:async()=>{const t=new Date,r=new Date(t.getFullYear(),t.getMonth()-1,1),{data:d,error:x}=await b.from("oz1_kalendar").select("datum, novy, opak, poprve, expirace, klub_pocet, klub_trzba, klub_uip, aktivni").gte("datum",r.toISOString().split("T")[0]).order("datum",{ascending:!0});if(x)throw x;return d||[]}}),{data:l,isLoading:S}=V({queryKey:["stats-membership-current"],queryFn:async()=>{const{count:t}=await b.from("oz1_users").select("*",{count:"exact",head:!0}).eq("is_active",!0).neq("tarif",30).gt("membership_expires_at",new Date().toISOString()),{count:r}=await b.from("oz1_users").select("*",{count:"exact",head:!0}).eq("is_active",!0).eq("tarif",30),{count:d}=await b.from("oz1_users").select("*",{count:"exact",head:!0}).eq("is_active",!0).eq("neopak",1),{count:x}=await b.from("oz1_users").select("*",{count:"exact",head:!0}),{count:R}=await b.from("oz1_users").select("*",{count:"exact",head:!0}).eq("is_active",!0).lt("membership_expires_at",new Date().toISOString()).not("membership_expires_at","is",null),{count:$}=await b.from("oz1_users").select("*",{count:"exact",head:!0}).eq("vip",1);return{paidActive:t||0,freeTarif:r||0,neopakCount:d||0,totalUsers:x||0,expired:R||0,vipCount:$||0}}}),a=_.useMemo(()=>s!=null&&s.length?s[s.length-1]:null,[s]),w=_.useMemo(()=>s!=null&&s.length?s.map(t=>({datum:t.datum,novy:t.novy||0,opak:t.opak||0,poprve:t.poprve||0,expirace:-(t.expirace||0),netGrowth:(t.novy||0)-(t.expirace||0),aktivni:t.aktivni||0})):[],[s]),B=_.useMemo(()=>{if(!(s!=null&&s.length))return 0;const t=s.reduce((d,x)=>d+(x.novy||0),0),r=s.reduce((d,x)=>d+(x.opak||0),0);return t>0?r/t*100:0},[s]),H=_.useMemo(()=>m?m.map(t=>({month:t.mesic,revenue:t.trzba_klub||0,members:t.pocet_klub||0})):[],[m]),L=_.useMemo(()=>l?[{name:"Placenà aktivnÃ",value:l.paidActive,color:"#f59e0b"},{name:"Volný tarif",value:l.freeTarif,color:"#3b82f6"},{name:"ExpirovanÃ",value:l.expired,color:"#ef4444"},{name:"VIP",value:l.vipCount,color:"#8b5cf6"}].filter(t=>t.value>0):[],[l]),o=_.useMemo(()=>{const t=new Date,r=`${t.getFullYear()}
6-${String(t.getMonth()+1).padStart(2,"0")}`,d=new Date(t.getFullYear(),t.getMonth()-1,1),x=`${d.getFullYear()}-${String(d.getMonth()+1).padStart(2,"0")}`,R=t.getDate(),$=(Y,F)=>{const U=(P||[]).filter(i=>{var n;return(n=i.datum)==null?void 0:n.startsWith(Y)}),h=F?U.filter(i=>parseInt(i.datum.split("-")[2],10)<=F):U;return{novy:h.reduce((i,n)=>i+(n.novy||0),0),opak:h.reduce((i,n)=>i+(n.opak||0),0),poprve:h.reduce((i,n)=>i+(n.poprve||0),0),expirace:h.reduce((i,n)=>i+(n.expirace||0),0),klub_trzba:h.reduce((i,n)=>i+Number(n.klub_trzba||0),0),klub_pocet:h.reduce((i,n)=>i+(n.klub_pocet||0),0),klub_uip:h.reduce((i,n)=>i+(n.klub_uip||0),0)}},te=$(r),se=$(x,R),re=$(x),X=Y=>{const F=(P||[]).filter(U=>{var h;return(h=U.datum)==null?void 0:h.startsWith(Y)});return F.length&&F[F.length-1].aktivni||0};return{curKey:r,prevKey:x,dayOfMonth:R,cur:te,prevToDate:se,prevFull:re,curActive:X(r),prevActive:X(x)}},[P]),ee=p||D||S;return e.jsx(ne,{title:"Statistiky â ÄlenstvÃ",children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(oe,{className:"w-5 h-5 text-gray-500"}),e.jsxs(de,{value:c,onValueChange:j,children:[e.jsx(xe,{className:"w-48",children:e.jsx(ue,{})}),e.jsxs(me,{children:[e.jsx(q,{value:"30",children:"PoslednÃch 30 dnÃ"}),e.jsx(q,{value:"90",children:"PoslednÃch 90 dnÃ"}),e.jsx(q,{value:"180",children:"PoslednÃch 180 dnÃ"}),e.jsx(q,{value:"365",children:"PoslednÃch 365 dnÃ"}),e.jsx(q,{value:"730",children:"2 roky"})]})]})]}),ee?e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 xl:grid-cols-6 gap-4",children:[...Array(6)].map((t,r)=>e.jsx(v,{className:"h-28"},r))}):e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-6 gap-4",children:[e.jsx(M,{title:"Aktivnà Älenové",value:u((a==null?void 0:a.aktivni)||0),subtitle:"celkem dnes",icon:e.jsx(pe,{className:"w-5 h-5"}),color:"text-yellow-600 bg-yellow-50"}),e.jsx(M,{title:"NeaktivnÃ",value:u((a==null?void 0:a.neaktivni)||0),subtitle:"neobnovili",icon:e.jsx(fe,{className:"w-5 h-5"}),color:"text-red-600 bg-red-50"}),e.jsx(M,{title:"NeopakujÃcÃ",value:u((l==null?void 0:l.neopakCount)||0),subtitle:"neopak = 1",icon:e.jsx(le,{className:"w-5 h-5"}),color:"text-orange-600 bg-orange-50"}),e.jsx(M,{title:"VIP",value:u((l==null?void 0:l.vipCount)||0),subtitle:"speciálnà status",icon:e.jsx(ie,{className:"w-5 h-5"}),color:"text-purple-600 bg-purple-50"}),e.jsx(M,{title:"Retence",value:Ne(B),subtitle:"opak / nový",icon:e.jsx(he,{className:"w-5 h-5"}),color:"text-green-600 bg-green-50"}),e.jsx(M,{title:"DneÅ¡nà tržby klub",value:N((a==null?void 0:a.klub_trzba)||0),subtitle:`${(a==null?void 0:a.klub_pocet)||0} objednávek`,icon:e.jsx(ce,{className:"w-5 h-5"}),color:"text-blue-600 bg-blue-50"})]}),e.jsxs(g,{children:[e.jsx(y,{children:e.jsxs(f,{className:"text-lg flex items-center gap-2",children:["Tento mÄsÃc vs. minulý mÄsÃc",e.jsxs("span",{className:"text-xs font-normal text-muted-foreground",children:["(",o.curKey," vs ",o.prevKey,")"]})]})}),e.jsxs(k,{children:[e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-3 lg:grid-cols-6 gap-3 mb-4",children:[e.jsx(T,{label:"Tržby klub",cur:o.cur.klub_trzba,prev:o.prevToDate.klub_trzba,prevFull:o.prevFull.klub_trzba,format:N}),e.jsx(T,{label:"Objednávky klub",cur:o.cur.klub_pocet,prev:o.prevToDate.klub_pocet,prevFull:o.prevFull.klub_pocet,format:u}),e.jsx(T,{label:"Aktivnà Älenové",cur:o.curActive,prev:o.prevActive,format:u,isSnapshot:!0}),e.jsx(T,{label:"NovÃ",cur:o.cur.novy,prev:o.prevToDate.novy,prevFull:o.prevFull.novy,format:u}),e.jsx(T,{label:"OpakujÃcÃ",cur:o.cur.opak,prev:o.prevToDate.opak,prevFull:o.prevFull.opak,format:u}),e.jsx(T,{label:"Expirace",cur:o.cur.expirace,prev:o.prevToDate.expirace,prevFull:o.prevFull.expirace,format:u,inverse:!0})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Srovnánà ke stejnému dni v mÄsÃci (1.â",o.dayOfMonth,".). V závorce celkový souÄet za minulý mÄsÃc."]})]})]}),a&&e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 lg:grid-cols-6 gap-3",children:[e.jsx(I,{label:"Novà dnes",value:a.novy,color:"text-green-600"}),e.jsx(I,{label:"OpakujÃcÃ",value:a.opak,color:"text-blue-600"}),e.jsx(I,{label:"Poprvé",value:a.poprve,color:"text-cyan-600"}),e.jsx(I,{label:"Expirace",value:a.expirace,color:"text-red-600"}),e.jsx(I,{label:"Klub UIP",value:a.klub_uip,color:"text-yellow-600"}),e.jsx(I,{label:"Klub views",value:a.klub_view,color:"text-gray-600"})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-6",children:[e.jsxs(g,{children:[e.jsx(y,{children:e.jsx(f,{className:"text-lg",children:"Složenà Älenů"})}),e.jsx(k,{children:S?e.jsx(v,{className:"h-64"}):e.jsx(K,{width:"100%",height:280,children:e.jsxs(be,{children:[e.jsx(ge,{data:L,cx:"50%",cy:"50%",innerRadius:60,outerRadius:100,paddingAngle:3,dataKey:"value",label:({name:t,percent:r})=>`${t} ${(r*100).toFixed(0)}%`,children:L.map((t,r)=>e.jsx(je,{fill:t.color},r))}),e.jsx(z,{formatter:t=>u(t)})]})})})]}),e.jsxs(g,{className:"lg:col-span-2",children:[e.jsx(y,{children:e.jsx(f,{className:"text-lg",children:"Vývoj aktivnÃch Älenů"})}),e.jsx(k,{children:p?e.jsx(v,{className:"h-64"}):e.jsx(K,{width:"100%",height:280,children:e.jsxs(G,{data:w,children:[e.jsx(O,{strokeDasharray:"3 3",stroke:"#e5e7eb"}),e.jsx(W,{dataKey:"datum",tick:{fontSize:10}
6,tickFormatter:t=>t==null?void 0:t.slice(5)}),e.jsx(A,{}),e.jsx(z,{labelFormatter:t=>`Den: ${t}`}),e.jsx(C,{type:"monotone",dataKey:"aktivni",name:"Aktivnà Älenové",fill:"#f59e0b30",stroke:"#f59e0b",strokeWidth:2})]})})})]})]}),e.jsxs(g,{children:[e.jsx(y,{children:e.jsx(f,{className:"text-lg",children:"Dennà růst vs. odchod"})}),e.jsx(k,{children:p?e.jsx(v,{className:"h-80"}):e.jsx(K,{width:"100%",height:350,children:e.jsxs(Q,{data:w,children:[e.jsx(O,{strokeDasharray:"3 3",stroke:"#e5e7eb"}),e.jsx(W,{dataKey:"datum",tick:{fontSize:10},tickFormatter:t=>t==null?void 0:t.slice(5)}),e.jsx(A,{}),e.jsx(z,{labelFormatter:t=>`Den: ${t}`}),e.jsx(E,{}),e.jsx(Z,{dataKey:"novy",name:"NovÃ",fill:"#10b981",stackId:"stack",radius:[2,2,0,0]}),e.jsx(Z,{dataKey:"opak",name:"OpakujÃcÃ",fill:"#3b82f6",stackId:"stack"}),e.jsx(Z,{dataKey:"expirace",name:"Expirace (â)",fill:"#ef4444",radius:[0,0,2,2]}),e.jsx(J,{type:"monotone",dataKey:"netGrowth",name:"Äistý růst",stroke:"#f59e0b",strokeWidth:2,dot:!1})]})})})]}),e.jsxs(g,{children:[e.jsx(y,{children:e.jsx(f,{className:"text-lg",children:"Nový Älen vs. OpakujÃcà vs. Poprvé"})}),e.jsx(k,{children:p?e.jsx(v,{className:"h-72"}):e.jsx(K,{width:"100%",height:300,children:e.jsxs(G,{data:w,children:[e.jsx(O,{strokeDasharray:"3 3",stroke:"#e5e7eb"}),e.jsx(W,{dataKey:"datum",tick:{fontSize:10},tickFormatter:t=>t==null?void 0:t.slice(5)}),e.jsx(A,{}),e.jsx(z,{labelFormatter:t=>`Den: ${t}`}),e.jsx(E,{}),e.jsx(C,{type:"monotone",dataKey:"novy",name:"NovÃ",fill:"#10b98140",stroke:"#10b981",strokeWidth:2,stackId:"1"}),e.jsx(C,{type:"monotone",dataKey:"opak",name:"OpakujÃcÃ",fill:"#3b82f640",stroke:"#3b82f6",strokeWidth:2,stackId:"1"}),e.jsx(C,{type:"monotone",dataKey:"poprve",name:"Poprvé",fill:"#8b5cf640",stroke:"#8b5cf6",strokeWidth:2,stackId:"1"})]})})})]}),e.jsxs(g,{children:[e.jsx(y,{children:e.jsx(f,{className:"text-lg",children:"MÄsÃÄnà tržby klubu a poÄet pÅedplatitelů"})}),e.jsx(k,{children:D?e.jsx(v,{className:"h-80"}):e.jsx(K,{width:"100%",height:350,children:e.jsxs(Q,{data:H,children:[e.jsx(O,{strokeDasharray:"3 3",stroke:"#e5e7eb"}),e.jsx(W,{dataKey:"month",tick:{fontSize:12}}),e.jsx(A,{yAxisId:"left",tickFormatter:t=>`${(t/1e3).toFixed(0)}k`}),e.jsx(A,{yAxisId:"right",orientation:"right"}),e.jsx(z,{formatter:(t,r)=>r==="Tržby"?N(t):u(t)}),e.jsx(E,{}),e.jsx(C,{yAxisId:"left",type:"monotone",dataKey:"revenue",name:"Tržby",fill:"#f59e0b30",stroke:"#f59e0b",strokeWidth:2}),e.jsx(J,{yAxisId:"right",type:"monotone",dataKey:"members",name:"PÅedplatitelé",stroke:"#3b82f6",strokeWidth:2,dot:{r:3}})]})})})]}),e.jsxs(g,{children:[e.jsx(y,{children:e.jsx(f,{className:"text-lg",children:"NávÅ¡tÄvnost klubu"})}),e.jsx(k,{children:p?e.jsx(v,{className:"h-64"}):e.jsx(K,{width:"100%",height:280,children:e.jsxs(G,{data:s||[],children:[e.jsx(O,{strokeDasharray:"3 3",stroke:"#e5e7eb"}),e.jsx(W,{dataKey:"datum",tick:{fontSize:10},tickFormatter:t=>t==null?void 0:t.slice(5)}),e.jsx(A,{}),e.jsx(z,{labelFormatter:t=>`Den: ${t}`}),e.jsx(E,{}),e.jsx(C,{type:"monotone",dataKey:"klub_uip",name:"Klub unikáty",fill:"#f59e0b40",stroke:"#f59e0b",strokeWidth:2}),e.jsx(C,{type:"monotone",dataKey:"web_uip",name:"Web unikáty",fill:"#3b82f640",stroke:"#3b82f6",strokeWidth:1})]})})})]}),e.jsxs(g,{children:[e.jsx(y,{children:e.jsx(f,{className:"text-lg",children:"MÄsÃÄnà pÅehled ÄlenstvÃ"})}),e.jsx(k,{children:D?e.jsx(v,{className:"h-64"}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-gray-200",children:[e.jsx("th",{className:"text-left py-3 px-2 font-medium text-gray-500",children:"MÄsÃc"}),e.jsx("th",{className:"text-right py-3 px-2 font-medium text-gray-500",children:"PÅedplatitelé"}),e.jsx("th",{className:"text-right py-3 px-2 font-medium text-gray-500",children:"Tržby klub"}),e.jsx("th",{className:"text-right py-3 px-2 font-medium text-gray-500",children:"ARPU"}),e.jsx("th",{className:"text-right py-3 px-2 font-medium text-gray-500",children:"Tržby poukazy"}),e.jsx("th",{className:"text-right py-3 px-2 font-medium text-gray-500",children:"Google Ads"}),e.jsx("th",{className:"text-right py-3 px-2 font-medium text-gray-500",children:"Náklady"})]})}),e.jsx("tbody",{children:[...m||[]].reverse().map((t,r)=>{const d=t.pocet_klub>0?(t.trzba_klub||0)/t.pocet_klub:0;return e.jsxs("tr",{className:"border-b border-gray-100 hover:bg-gray-50",children:[e.jsx("td",{className:"py-2 px-2 font-medium",children:t.mesic}),e.jsx("td",{className:"py-2 px-2 text-right",children:u(t.pocet_klub||0)}),e.jsx("td",{className:"py-2 px-2 text-right font-medium",children:N(t.trzba_klub||0)}),e.jsx("td",{className:"py-2 px-2 text-right",children:N(d)}),e.jsx("td",{className:"py-2 px-2 text-right",children:N(t.trzba_poukaz||0)}),e.jsx("td",{className:"py-2 px-2 text-right",children:N(t.google||0)}),e.jsx("td",{className:"py-2 px-2 text-right text-red-600",children:N(t.naklad_banka||0)})]},r)})})]})})})]})]})})}function M({title:c,value:j,subtitle:s,icon:p,color:m}){return e.jsx(g,{children:e.jsxs(k,{className:"p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-xs text-gray-500 uppercase tracking-wide",children:c}),e.jsx("div",{className:`p-1.5 rounded-lg ${m}`,children:p})]}),e.jsx("div",{className:"text-xl font-bold text-gray-900",children:j}),s&&e.jsx("span",{className:"text-xs text-gray-400",children:s})]})})}function I({label:c,value:j,color:s}){return e.jsxs("div",{className:"bg-white rounded-lg border border-gray-200 p-3 text-center",children:[e.jsx("div",{className:`text-lg font-bold ${s}`,children:u(j)}),e.jsx("div",{className:"text-xs text-gray-500",children:c})]})}function T({label:c,cur:j,prev:s,prevFull:p,format:m,inverse:D,isSnapshot:P}){const l=j-s,S=s!==0?l/Math.abs(s)*100:j!==0?100:0,a=l>0,w=l<0,L=(D?w:a)?"text-green-600":(D?a:w)?"text-red-600":"text-muted-foreground",o=a?ke:w?ve:ye;return e.jsxs("div",{className:"bg-card rounded-lg border border-border p-3",children:[e.jsx("div",{className:"text-xs text-muted-foreground uppercase tracking-wide mb-1",children:c}),e.jsx("div",{className:"text-lg font-bold",children:m(j)}),e.jsxs("div",{className:`text-xs flex items-center gap-1 mt-1 ${L}`,children:[e.jsx(o,{className:"w-3 h-3"}),e.jsxs("span",{children:[l>=0?"+":"",m(l)]}),e.jsxs("span",{className:"text-muted-foreground",children:["(",S>=0?"+":"",S.toFixed(1),"%)"]})]}),e.jsx("div",{className:"text-[10px] text-muted-foreground mt-0.5",children:P?`min. mÄsÃc: ${m(s)}`:`vs ${m(s)}${p!=null&&p!==s?` (z ${m(p)})`:""}`})]})}
6export{Je 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.