1import{r as y,u as q,j as r,c as H}from"./index-ZDIuofZ7.js";import{N as Z}from"./Navbar-mxsNaU5_.js";import{P as J}from"./PageHeader-DpTcFYrE.js";import{C}from"./Card-D_YIySsz.js";import{r as Q,D as U,M as ee,br as te,bs as re,u as ae,bt as ie,o as P,bu as ne,bv as se,bw as B,bx as le,by as oe,E as ce,Z as de,L as me,q as fe,bz as ue,bA as xe,ae as L,bB as z,ac as Y,bC as ye,R as I,C as D,X as W,Y as F,T as N}from"./CartesianChart-3Ikevc9d.js";import{B as $}from"./BarChart-4fG-UnvH.js";import{B as V,C as T}from"./Bar-CDe0lyZZ.js";import"./DateFilterButton-BV4nZV58.js";function M(t,e){var a=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(s){return Object.getOwnPropertyDescriptor(t,s).enumerable})),a.push.apply(a,n)}return a}function G(t){for(var e=1;e<arguments.length;e++){var a=arguments[e]!=null?arguments[e]:{};e%2?M(Object(a),!0).forEach(function(n){ge(t,n,a[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(a)):M(Object(a)).forEach(function(n){Object.defineProperty(t,n,Object.getOwnPropertyDescriptor(a,n))})}return t}function ge(t,e,a){return(e=he(e))in t?Object.defineProperty(t,e,{value:a,enumerable:!0,configurable:!0,writable:!0}):t[e]=a,t}function he(t){var e=pe(t,"string");return typeof e=="symbol"?e:e+""}function pe(t,e){if(typeof t!="object"||!t)return t;var a=t[Symbol.toPrimitive];if(a!==void 0){var n=a.call(t,e);if(typeof n!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(t)}function R(){return R=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var a=arguments[e];for(var n in a)({}).hasOwnProperty.call(a,n)&&(t[n]=a[n])}return t},R.apply(null,arguments)}var be=(t,e)=>{var a;if(y.isValidElement(t))a=y.cloneElement(t,e);else if(typeof t=="function")a=t(e);else{if(!L(e.x1)||!L(e.y1)||!L(e.x2)||!L(e.y2))return null;a=y.createElement("line",R({},e,{className:"recharts-reference-line-line"}))}return a},ve=(t,e,a,n,s,m)=>{var{x:f,width:u}=m,l=s.y.apply(t,{position:a});if(Y(l)||e==="discard"&&!s.y.isInRange(l))return null;var d=[{x:f+u,y:l},{x:f,y:l}];return n==="left"?d.reverse():d},je=(t,e,a,n,s,m)=>{var{y:f,height:u}=m,l=s.x.apply(t,{position:a});if(Y(l)||e==="discard"&&!s.x.isInRange(l))return null;var d=[{x:l,y:f+u},{x:l,y:f}];return n==="top"?d.reverse():d},ke=(t,e,a,n)=>{var s=t.map(m=>n.apply(m,{position:a}));return e==="discard"&&s.some(m=>!n.isInRange(m))?null:s},we=(t,e,a,n,s,m)=>{var{x:f,y:u,segment:l,ifOverflow:d}=m,p=z(f),x=z(u);return x?ve(u,d,a,s,t,e):p?je(f,d,a,n,t,e):l!=null&&l.length===2?ke(l,d,a,t):null};function Se(t){var e=ee();return y.useEffect(()=>(e(te(t)),()=>{e(re(t))})),null}function _e(t){var{xAxisId:e,yAxisId:a,shape:n,className:s,ifOverflow:m}=t,f=ae(),u=ie(),l=P(k=>ne(k,e)),d=P(k=>se(k,a)),p=P(k=>B(k,"xAxis",e,f)),x=P(k=>B(k,"yAxis",a,f)),b=le();if(!u||!b||l==null||d==null||p==null||x==null)return null;var i=oe({x:p,y:x}),c=we(i,b,t.position,l.orientation,d.orientation,t);if(!c)return null;var[{x:o,y:h},{x:v,y:_}]=c,w=m==="hidden"?"url(#".concat(u,")"):void 0,S=G(G({clipPath:w},ce(t)),{},{x1:o,y1:h,x2:v,y2:_}),j=ye({x1:o,y1:h,x2:v,y2:_});return y.createElement(de,{zIndex:t.zIndex},y.createElement(me,{className:fe("recharts-reference-line",s)},be(n,S),y.createElement(ue,R({},j,{lowerWidth:j.width,upperWidth:j.width}),y.createElement(xe,{label:t.label}),t.children)))}var Pe={ifOverflow:"discard",xAxisId:0,yAxisId:0,fill:"none",stroke:"#ccc",fillOpacity:1,strokeWidth:1,position:"middle",zIndex:U.line};function E(t){var e=Q(t,Pe);return y.createElement(y.Fragment,null,y.createElement(Se,{yAxisId:e.yAxisId,xAxisId:e.xAxisId,ifOverflow:e.ifOverflow,x:e.x,y:e.y,segment:e.segment}),y.createElement(_e,e))}E.displayName="ReferenceLine";const Le=[{key:"1w",label:"1 Sem"},{key:"2w",label:"2 Sem"},{key:"3w",label:"3 Sem"},{key:"1m",label:"1 Mês"},{key:"3m",label:"3 Meses"},{key:"6m",label:"6 Meses"},{key:"1y",label:"1 Ano"},{key:"all",label:"Tudo"}],A=t=>t.toLocaleString("pt-BR",{style:"currency",currency:"BRL"}),X=t=>t>=1e3?`${(t/1e3).toFixed(1)}k`:t.toFixed(0),O=t=>{const[,e,a]=t.split("-");return`${a}/${e}`},g={rangeBar:{display:"flex",gap:"0.5rem",flexWrap:"wrap",marginBottom:"1.5rem"},rangePill:t=>({padding:"0.45rem 1rem",borderRadius:"20px",border:`1px solid ${t?"var(--secondary)":"rgba(255,255,255,0.1)"}`,background:t?"rgba(99, 102, 241, 0.2)":"rgba(255,255,255,0.03)",color:t?"var(--secondary)":"var(--text-muted)",cursor:"pointer",fontSize:"0.85rem",fontWeight:t?700:500,transition:"all 0.2s"}),kpiGrid:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(min(100%, 220px), 1fr))",gap:"1rem",marginBottom:"1.5rem"},kpiCard:{padding:"1.25rem",borderRadius:"12px",background:"rgba(255,255,255,0.03)",border:"1px solid rgba(255,255,255,0.06)",textAlign:"center"},kpiValue:{fontSize:"1.6rem",fontWeight:700,color:"var(--text-primary)",marginBottom:"0.25rem"},kpiLabel:{fontSize:"0.8rem",color:"var(--text-muted)",fontWeight:500},sectionTitle:{fontSize:"1.1rem",fontWeight:700,color:"var(--text-primary)",marginBottom:"0.75rem",display:"flex",alignItems:"center",gap:"0.5rem"},avgBadge:(t,e)=>{const n=(e>0?t/e:1)>1.3;return{display:"inline-block",padding:"2px 8px",borderRadius:"6px",fontSize:"0.8rem",fontWeight:600,background:n?"rgba(239,68,68,0.12)":"rgba(255,255,255,0.04)",color:n?"#fca5a5":"var(--text-muted)"}},chartWrap:{marginBottom:"2rem"}},K=t=>{const e=H.c(19),{active:a,payload:n,label:s,valueLabel:m,isCurrency:f}=t;if(!a||!n?.length)return null;const u=n[0]?.value??0,l=n[0]?.payload?.weekday_change_pct;let d,p;e[0]===Symbol.for("react.memo_cache_sentinel")?(d={background:"rgba(15, 23, 42, 0.95)",border:"1px solid rgba(255,255,255,0.1)",borderRadius:"8px",padding:"0.6rem 0.8rem",fontSize:"0.8rem"},p={color:"var(--text-muted)",marginBottom:"4px"},e[0]=d,e[1]=p):(d=e[0],p=e[1]);let x;
1e[2]!==s?(x=O(s),e[2]=s,e[3]=x):x=e[3];let b;e[4]!==x?(b=r.jsx("div",{style:p,children:x}),e[4]=x,e[5]=b):b=e[5];let i;e[6]===Symbol.for("react.memo_cache_sentinel")?(i={fontWeight:700,color:"var(--text-primary)"},e[6]=i):i=e[6];let c;e[7]!==f||e[8]!==u?(c=f?A(u):X(u),e[7]=f,e[8]=u,e[9]=c):c=e[9];let o;e[10]!==c||e[11]!==m?(o=r.jsxs("div",{style:i,children:[m,": ",c]}),e[10]=c,e[11]=m,e[12]=o):o=e[12];let h;e[13]!==l?(h=l!=null&&r.jsxs("div",{style:{marginTop:"4px",color:l>0?"#22c55e":l<0?"#ef4444":"#94a3b8",fontWeight:600,fontSize:"0.75rem"},children:["vs. mesma semana: ",l>0?"+":"",l.toFixed(1),"%"]}),e[13]=l,e[14]=h):h=e[14];let v;return e[15]!==b||e[16]!==o||e[17]!==h?(v=r.jsxs("div",{style:d,children:[b,o,h]}),e[15]=b,e[16]=o,e[17]=h,e[18]=v):v=e[18],v},De=()=>{const t=q(),e=localStorage.getItem("auth_token"),[a,n]=y.useState("1m"),[s,m]=y.useState(null),[f,u]=y.useState(!0),l=y.useCallback(async()=>{u(!0);try{const i=await fetch(`/api/missed-sales?range=${a}`,{headers:{Authorization:`Bearer ${e}`}});i.ok&&m(await i.json())}catch(i){console.error("Failed to fetch missed sales:",i)}finally{u(!1)}},[a,e]);y.useEffect(()=>{l()},[l]);const d=s?.revenue_chart?.reduce((i,c)=>{const o=c.weekday_diff;return o!==null&&o<0?i+o:i},0)??0,p=s?.revenue_chart?.reduce((i,c)=>{const o=c.weekday_diff;return o!==null&&o>0?i+o:i},0)??0,x=p+d,b=()=>r.jsx("div",{style:{padding:"2rem"},children:[1,2,3].map(i=>r.jsx("div",{className:"skeleton",style:{height:"60px",borderRadius:"8px",marginBottom:"0.75rem"}},i))});return r.jsxs(r.Fragment,{children:[r.jsx("div",{className:"bg-grid"}),r.jsx("div",{className:"glow-orb glow-orb-1"}),r.jsx(Z,{}),r.jsxs("div",{className:"dashboard-container",children:[r.jsx(J,{title:"Vendas Perdidas",subtitle:"Análise de visitantes que não compraram e receita potencial perdida",onBack:()=>t("/tools"),icon:"ð¸"}),r.jsx("div",{style:g.rangeBar,children:Le.map(i=>r.jsx("button",{onClick:()=>n(i.key),style:g.rangePill(a===i.key),children:i.label},i.key))}),f?r.jsx(b,{}):s&&r.jsxs(r.Fragment,{children:[r.jsxs("div",{style:g.kpiGrid,children:[r.jsxs("div",{style:{...g.kpiCard,background:"rgba(239, 68, 68, 0.08)",border:"1px solid rgba(239, 68, 68, 0.2)"},children:[r.jsx("div",{style:{...g.kpiValue,color:"#fca5a5"},children:A(Math.abs(d))}),r.jsx("div",{style:g.kpiLabel,children:"Receita Perdida"})]}),r.jsxs("div",{style:{...g.kpiCard,background:"rgba(234, 179, 8, 0.08)",border:"1px solid rgba(234, 179, 8, 0.2)"},children:[r.jsx("div",{style:{...g.kpiValue,color:"#eab308"},children:A(p)}),r.jsx("div",{style:g.kpiLabel,children:"Receita Ganha"})]}),r.jsxs("div",{style:{...g.kpiCard,background:x>=0?"rgba(34, 197, 94, 0.08)":"rgba(239, 68, 68, 0.08)",border:`1px solid ${x>=0?"rgba(34, 197, 94, 0.2)":"rgba(239, 68, 68, 0.2)"}`},children:[r.jsxs("div",{style:{...g.kpiValue,color:x>=0?"#22c55e":"#fca5a5"},children:[x>=0?"+":"-",A(Math.abs(x))]}),r.jsx("div",{style:g.kpiLabel,children:"Resultado LÃquido"})]})]}),r.jsxs(C,{children:[r.jsxs("div",{style:g.sectionTitle,children:[r.jsx("span",{children:"ð¥"})," Variação de Acessos vs. Esperado"]}),r.jsx("div",{style:{fontSize:"0.8rem",color:"var(--text-muted)",marginBottom:"1rem"},children:"Diferença entre acessos reais e a média das 3 últimas mesmas semanas. Amarelo = acima, Vermelho = abaixo."}),r.jsx("div",{style:g.chartWrap,children:r.jsx(I,{width:"100%",height:300,children:r.jsxs($,{data:s.accesses_chart.map(i=>({date:i.date,diff:i.weekday_diff??0,pct:i.weekday_change_pct})),margin:{top:20,right:10,left:0,bottom:20},children:[r.jsx(D,{strokeDasharray:"3 3",stroke:"rgba(255,255,255,0.04)"}),r.jsx(W,{dataKey:"date",tickFormatter:O,tick:{fill:"#64748b",fontSize:11},axisLine:!1,tickLine:!1,interval:"preserveStartEnd"}
1),r.jsx(F,{tickFormatter:X,tick:{fill:"#64748b",fontSize:11},axisLine:!1,tickLine:!1,width:50}),r.jsx(E,{y:0,stroke:"rgba(255,255,255,0.15)",strokeDasharray:"3 3"}),r.jsx(N,{content:r.jsx(K,{valueLabel:"Î Acessos",isCurrency:!1})}),r.jsx(V,{dataKey:"diff",radius:[4,4,0,0],label:i=>{const{x:c,y:o,width:h,height:v,index:_}=i,w=s.accesses_chart[_];if(!w||w.weekday_change_pct===null)return null;const S=w.weekday_change_pct,j=S>0,k=j?o-6:o+Math.abs(v)+4;return r.jsx("text",{x:c+h/2,y:k,textAnchor:"middle",fontSize:9,fontWeight:700,fill:j?"#eab308":"#ef4444",children:`${j?"+":""}${S.toFixed(0)}%`})},children:s.accesses_chart.map((i,c)=>r.jsx(T,{fill:(i.weekday_diff??0)>=0?"rgba(234, 179, 8, 0.7)":"rgba(239, 68, 68, 0.6)"},c))})]})})})]}),r.jsxs(C,{children:[r.jsxs("div",{style:g.sectionTitle,children:[r.jsx("span",{children:"ð"})," Variação de Receita vs. Esperado"]}),r.jsx("div",{style:{fontSize:"0.8rem",color:"var(--text-muted)",marginBottom:"1rem"},children:"Diferença em R$ entre a receita real e a média das 3 últimas mesmas semanas. Amarelo = acima, Vermelho = abaixo."}),r.jsx("div",{style:g.chartWrap,children:r.jsx(I,{width:"100%",height:300,children:r.jsxs($,{data:s.revenue_chart.map(i=>({date:i.date,diff:i.weekday_diff??0,pct:i.weekday_change_pct})),margin:{top:20,right:10,left:0,bottom:20},children:[r.jsx(D,{strokeDasharray:"3 3",stroke:"rgba(255,255,255,0.04)"}),r.jsx(W,{dataKey:"date",tickFormatter:O,tick:{fill:"#64748b",fontSize:11},axisLine:!1,tickLine:!1,interval:"preserveStartEnd"}),r.jsx(F,{tickFormatter:i=>`R$${(i/1e3).toFixed(0)}k`,tick:{fill:"#64748b",fontSize:11},axisLine:!1,tickLine:!1,width:65}),r.jsx(E,{y:0,stroke:"rgba(255,255,255,0.15)",strokeDasharray:"3 3"}),r.jsx(N,{content:r.jsx(K,{valueLabel:"Î Receita",isCurrency:!0})}),r.jsx(V,{dataKey:"diff",radius:[4,4,0,0],label:i=>{const{x:c,y:o,width:h,height:v,index:_}=i,w=s.revenue_chart[_];if(!w||w.weekday_change_pct===null)return null;const S=w.weekday_change_pct,j=S>0,k=j?o-6:o+Math.abs(v)+4;return r.jsx("text",{x:c+h/2,y:k,textAnchor:"middle",fontSize:9,fontWeight:700,fill:j?"#eab308":"#ef4444",children:`${j?"+":""}${S.toFixed(0)}%`})},children:s.revenue_chart.map((i,c)=>r.jsx(T,{fill:(i.weekday_diff??0)>=0?"rgba(234, 179, 8, 0.7)":"rgba(239, 68, 68, 0.6)"},c))})]})})})]}),r.jsx("div",{style:{marginTop:"1.5rem",textAlign:"center",fontSize:"0.8rem",color:"var(--text-muted)"},children:"ð¸ Variações comparadas com a média das 3 últimas mesmas semanas (mesmo dia da semana)"})]})]})]})};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.