1import{b as Y,e as Z,Q as z,g as v,j as e,k as J,ao as W,aE as X,aV as ee,aP as se,aM as te,A as ae,D as re,F as k,G as w,H as ne,J as D,am as ie,t as p}from"./index--HPZSr6_.js";import{u as oe}from"./useIsFetching-C3Fln88t.js";import ce from"./html2canvas.esm-CBrSDip1.js";import{E as le}from"./jspdf.es.min-WAM-rLWZ.js";import{D as de}from"./DateRangeFilter-DSocxZ-C.js";import{S as C}from"./StatCard-4gEb7HRj.js";import{C as h,a as g,b as f,c as y}from"./card-CsZrOj-7.js";import{u as me,Z as xe,A as ue}from"./ZoomableTrafficChart-DJNmMyjG.js";import{G as pe}from"./globe-D2znhJNn.js";import{f as H}from"./pt-BR-D9D5SaqL.js";import"./calendar-BZ9IhgeT.js";import"./subDays-CB4gPp4A.js";import"./endOfMonth-CHhJm54O.js";import"./popover-pwyEPOCM.js";import"./calendar-CvanVCF4.js";import"./file-spreadsheet-D-ZuxRaF.js";import"./file-down-Dxk88udT.js";import"./info-Cpr0pCD6.js";import"./react-brazil-heatmap.es-BIasRN1a.js";import"./generateCategoricalChart-DkVqgZ4Y.js";import"./index-DcUe6_Gn.js";import"./value-3LWPH8SZ.js";import"./LineChart-wr9J-KOT.js";import"./Line-C5yH9Wxj.js";function E(s){const r=s.getTimezoneOffset(),l=r<=0?"+":"-",j=String(Math.floor(Math.abs(r)/60)).padStart(2,"0"),d=String(Math.abs(r)%60).padStart(2,"0");return H(s,"yyyy-MM-dd'T'HH:mm:ss")+`${l}${j}:${d}`}function he(){return e.jsxs("div",{className:"space-y-8",children:[e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6",children:Array.from({length:3}).map((s,r)=>e.jsx(p,{className:"h-28 rounded-lg"},r))}),e.jsx(p,{className:"h-[380px] rounded-lg"}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsx(p,{className:"h-[350px] rounded-lg"}),e.jsx(p,{className:"h-[350px] rounded-lg"})]})]})}function ge(s){return s.includes("Chrome")?"Chrome":s.includes("Firefox")?"Firefox":s.includes("Safari")&&!s.includes("Chrome")?"Safari":s.includes("Edge")?"Edge":s.includes("Opera")||s.includes("OPR")?"Opera":s.length>30?s.substring(0,25)+"â¦":s}function Ge(){const{t:s,i18n:r}=Y(),{toast:l}=Z(),j=z(),d=v.useRef(null),m=r.language==="pt-BR"?"pt-BR":"en-US",[S,R]=v.useState(!1),F=new Date,b=new Date;b.setDate(b.getDate()-30);const[a,B]=v.useState({from:b,to:F}),A=a!=null&&a.from?E(new Date(a.from.getFullYear(),a.from.getMonth(),a.from.getDate(),0,0,0)):"",L=a!=null&&a.to?E(new Date(a.to.getFullYear(),a.to.getMonth(),a.to.getDate(),23,59,59)):"",{data:P,isLoading:U}=me(A,L),q=oe({queryKey:["beemedia-analytics"]}),n=P??{},O=n.total_hits??0,$=n.unique_visits_by_ip??0,G=n.published_contents_count??0,_=(n.events_by_hour??[]).map(t=>({date:t.key_as_string,count:t.count})),x=(n.by_user_agent??[]).map(t=>({browser:ge(t.key),count:t.count})),M=n.by_region??[],T=n.top_urls??[],V=()=>{j.invalidateQueries({queryKey:["beemedia-analytics"]})},I=async()=>{if(!(!d.current||S)){R(!0),l({title:s("pdf.exporting"),description:s("pdf.exportingDescription")});try{const t=await ce(d.current,{scale:2,useCORS:!0,logging:!1,backgroundColor:"#ffffff"}),i=t.toDataURL("image/png"),o=t.width,c=t.height,u=new le({orientation:o>c?"landscape":"portrait",unit:"px",format:[o,c]});u.addImage(i,"PNG",0,0,o,c),u.save(`beemedia-analytics-${H(new Date,"yyyy-MM-dd")}.pdf`),l({title:s("pdf.exported"),description:s("pdf.exportedDescription")})}catch{l({title:s("common.error"),description:s("beemedia.analytics.exportError"),variant:"destructive"})}finally{R(!1)}}};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold tracking-tight",children:s("beemedia.analytics.title")}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s("beemedia.analytics.subtitle")})]}),e.jsx(de,{dateRange:a,onDateRangeChange:B,onExportPDF:I,isExporting:S,onRefresh:V,isRefreshing:!!q})]}),U?e.jsx(he,{}):e.jsxs("div",{ref:d,className:"space-y-8",children:[e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-6",children:[e.jsx(C,{title:s("beemedia.analytics.totalVisits"),value:O.toLocaleStr
1ing(m),icon:J}),e.jsx(C,{title:s("beemedia.analytics.uniqueVisitors"),value:$.toLocaleString(m),icon:W}),e.jsx(C,{title:s("beemedia.analytics.publishedContents"),value:G.toLocaleString(m),icon:X})]}),e.jsxs(h,{children:[e.jsx(g,{className:"pb-2",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ee,{className:"h-5 w-5 text-muted-foreground"}),e.jsx(f,{className:"text-base",children:s("beemedia.analytics.accessByHour")})]})}),e.jsx(y,{children:_.length>0?e.jsx(xe,{data:_}):e.jsx("p",{className:"text-center text-muted-foreground py-12 text-sm",children:s("beemedia.analytics.noTrafficData")})})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[e.jsxs(h,{children:[e.jsx(g,{className:"pb-2",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(pe,{className:"h-5 w-5 text-muted-foreground"}),e.jsx(f,{className:"text-base",children:s("beemedia.analytics.browsers")})]})}),e.jsx(y,{children:x.length>0?e.jsx("div",{className:"space-y-4",children:x.map((t,i)=>{const o=x.reduce((N,K)=>N+K.count,0),c=Math.max(...x.map(N=>N.count)),u=c>0?t.count/c*100:0,Q=o>0?(t.count/o*100).toFixed(1):"0";return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"font-medium truncate mr-2",children:t.browser}),e.jsxs("span",{className:"text-muted-foreground tabular-nums whitespace-nowrap",children:[t.count.toLocaleString(m)," ",e.jsxs("span",{className:"text-xs",children:["(",Q,"%)"]})]})]}),e.jsx("div",{className:"h-2 w-full rounded-full bg-muted overflow-hidden",children:e.jsx("div",{className:"h-full rounded-full bg-primary transition-all",style:{width:`${u}%`}})})]},i)})}):e.jsx("p",{className:"text-center text-muted-foreground py-12 text-sm",children:s("beemedia.analytics.noBrowserData")})})]}),e.jsxs(h,{children:[e.jsx(g,{className:"pb-2",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(se,{className:"h-5 w-5 text-muted-foreground"}),e.jsx(f,{className:"text-base",children:s("beemedia.analytics.accessByRegion")})]})}),e.jsx(y,{children:M.length>0?e.jsx(ue,{data:M}):e.jsx("p",{className:"text-center text-muted-foreground py-12 text-sm",children:s("beemedia.analytics.noRegionData")})})]})]}),e.jsxs(h,{children:[e.jsx(g,{className:"pb-2",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(te,{className:"h-5 w-5 text-muted-foreground"}),e.jsx(f,{className:"text-base",children:s("beemedia.analytics.topContents")})]})}),e.jsx(y,{children:T.length>0?e.jsxs(ae,{children:[e.jsx(re,{children:e.jsxs(k,{children:[e.jsx(w,{className:"w-12",children:"#"}),e.jsx(w,{children:"URL"}),e.jsx(w,{className:"text-right w-32",children:s("beemedia.analytics.accesses")})]})}),e.jsx(ne,{children:T.slice(0,10).map((t,i)=>e.jsxs(k,{children:[e.jsx(D,{className:"text-muted-foreground font-medium",children:i+1}),e.jsx(D,{children:e.jsxs("a",{href:t.key,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1.5 text-sm font-medium text-primary hover:underline transition-colors max-w-[500px] truncate",title:t.key,children:[t.key,e.jsx(ie,{className:"h-3.5 w-3.5 flex-shrink-0 opacity-60"})]})}),e.jsx(D,{className:"text-right font-medium",children:t.count.toLocaleString(m)})]},i))})]}):e.jsx("p",{className:"text-center text-muted-foreground py-12 text-sm",children:s("beemedia.analytics.noUrlData")})})]})]})]})}export{Ge 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.