1import{C as q,j as e,aG as Z,H as ee,o as j,aH as te,aI as ne,aJ as H,aK as f,aM as Q,aL as re,ao as S,a7 as n,T as o,I as ke,N as ce,a9 as L,aa as E,ay as I,aP as Le,G as He,aN as Qe,aO as Se,Q as Ke,as as Ge,ar as Ue,ac as Be}from"./mui-CRsYZxVY.js";import{r as O,b as V}from"./vendor-Dwao9eNC.js";import{aK as me,b as de,v as xe,K as se,bT as Ee,cR as ue,b_ as Ye,e6 as je,cG as Xe,er as Je,is as Ze,dF as Me,jj as et,dt as Ae,eH as tt,bN as Ie,fG as Oe,cL as $e,aE as ge,cH as nt,fP as rt,bw as st,et as it,jk as ot,e as at,p as lt,cE as Ce,f$ as ct,T as dt,cF as Fe,a$ as xt,bg as ht,bh as mt}from"./index-TALscxEc.js";import{g as ut}from"./getDateRangeFromOption-CWdx_kxA.js";import{D as pt}from"./DateRangeFilterChips-Co-vybTG.js";import{P as Ve}from"./ProductAvatar-BTM6y7KS.js";import{u as pe}from"./query-8ViTdhdk.js";import{g as W,b as T,a as ie}from"./reportBlur-CN9wVcyq.js";import{u as gt}from"./useReportTopCustomers-C_k2nec_.js";import{u as ft}from"./useReportStockMovements-g5WvMf8u.js";import{C as yt}from"./CouponUsageTable-C9JYfU43.js";import{s as be,C as oe,L as ae,a as jt,b as bt,c as vt,V as wt}from"./VisitorsCard-CdetQjzs.js";import{d as _e}from"./ExpandLess-C1pgA_h3.js";import{P as St}from"./PaymentMethodIcon-CIdwzC1T.js";import{B as It}from"./BannerCTA-ByDyLqz7.js";import"./datePickers-BIJXYOKG.js";import"./icons-D8aatgQ4.js";import"./lab-DSem1Osk.js";import"./paymentMethodIcons-Ckq94o3a.js";import"./mercado-pago-color-B_n0DTpx.js";import"./pagaleve-icon-D0kfWVyv.js";import"./Bolt-B4yhJBgX.js";(function(){try{var t=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};t.SENTRY_RELEASE={id:"2ad85febf9735404429b0670d4acf56a0af5a0a2"}}catch{}})();try{(function(){var t=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},s=new t.Error().stack;s&&(t._sentryDebugIds=t._sentryDebugIds||{},t._sentryDebugIds[s]="956bf627-0691-4dff-883d-191798cfa124",t._sentryDebugIdIdentifier="sentry-dbid-956bf627-0691-4dff-883d-191798cfa124")})()}catch{}const Ct=async t=>{var y,h;const{startDate:s,endDate:a,sortBy:x,sortDirection:c,limit:r}=t,l=s.toISOString(),g=a.toISOString(),d=await me.get("/reports/top-products",{params:{startDate:l,endDate:g,sortBy:x,sortDirection:c,limit:r}});if(d.status&&d.status!==200)throw new Error(((y=d.data)==null?void 0:y.error)||((h=d.data)==null?void 0:h.message)||"Failed to fetch top products");return d.data},Ft=t=>
1{const s=t?{startDate:t.startDate.toISOString(),endDate:t.endDate.toISOString(),sortBy:t.sortBy,sortDirection:t.sortDirection,limit:t.limit}:void 0;return pe({queryKey:["report-top-products",s],queryFn:()=>{if(!t)return Promise.reject(new Error("Params are required for top products report."));const a={...t,startDate:new Date(t.startDate),endDate:new Date(t.endDate)};return Ct(a)},enabled:!!t})},We=new Intl.NumberFormat("pt-BR",{style:"currency",currency:"BRL",notation:"compact",minimumFractionDigits:0,maximumFractionDigits:1}),Wt=({startDate:t,endDate:s,isBlurred:a})=>{const x=de(),[c]=xe(),r=q(),[l,g]=O.useState("totalQuantitySold"),d=m=>{g(m)},y=O.useMemo(()=>{if(!(!t||!s))return{startDate:t,endDate:s,sortBy:l,sortDirection:"desc",limit:5}},[t,s,l]),{data:h,isLoading:u,isError:p,error:i}=Ft(y),b=()=>e.jsxs(n,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:2},children:[e.jsxs(n,{sx:{display:"flex",alignItems:"center"},children:[e.jsx(n,{sx:{bgcolor:j(r.palette.primary.main,.12),color:r.palette.primary.main,width:32,height:32,borderRadius:"6px",display:"flex",alignItems:"center",justifyContent:"center",mr:1.25},children:e.jsx(Ye,{fontSize:"small"})}),e.jsx(o,{variant:"subtitle1",fontWeight:"500",children:"Top produtos"})]}),e.jsx(ce,{variant:"text",size:"small",endIcon:e.jsx(je,{}),onClick:()=>x(`/reports/products?${c.toString()}`),sx:{color:r.palette.primary.main,textTransform:"none",fontSize:"0.875rem",fontWeight:600,"&:hover":{backgroundColor:j(r.palette.primary.main,.04)}},children:"Ver todos"})]});return u?e.jsxs(e.Fragment,{children:[b(),e.jsx(Z,{component:ee,elevation:0,variant:"outlined",sx:{border:"none",bgcolor:"transparent","&::-webkit-scrollbar":{width:"6px",height:"6px"},"&::-webkit-scrollbar-track":{backgroundColor:"transparent"},"&::-webkit-scrollbar-thumb":{backgroundColor:r.palette.mode==="light"?j(r.palette.grey[500],.3):j(r.palette.grey[400],.3),borderRadius:"4px","&:hover":{backgroundColor:r.palette.mode==="light"?j(r.palette.grey[500],.5):j(r.palette.grey[400],.5)}}},children:e.jsxs(te,{size:"small",children:[e.jsx(ne,{children:e.jsxs(H,{sx:{fontWeight:"700",color:"text.secondary"},children:[e.jsx(f,{sx:{py:1,width:"48px"}}),e.jsx(f,{sx:{fontWeight:"inherit",py:1},children:"Produto"}),e.jsx(f,{align:"right",sx:{fontWeight:"inherit",py:1},children:e.jsx(Q,{active:!1,direction:"desc",children:"Vendas"})}),e.jsx(f,{align:"right",sx:{fontWeight:"inherit",py:1},children:e.jsx(Q,{active:!1,direction:"desc",children:"Receita"})}),e.jsx(f,{align:"right",sx:{fontWeight:"inherit",py:1},children:e.jsx(Q,{active:!1,direction:"desc",children:"Lucro"})}),e.jsx(f,{sx:{py:1,width:"48px"}})]})}),e.jsx(re,{children:[...Array(5)].map((m,w)=>e.jsxs(H,{children:[e.jsx(f,{sx:{py:1},children:e.jsx(S,{variant:"circular",width:24,height:24})}),e.jsx(f,{component:"th",scope:"row",sx:{maxWidth:150,py:1},children:e.jsx(S,{variant:"text",sx:{fontSize:"0.875rem"}})}),e.jsx(f,{align:"right",sx:{py:1},children:e.jsx(S,{variant:"text",sx:{fontSize:"0.875rem",width:"40px",display:"inline-block"}})}),e.jsx(f,{align:"right",sx:{py:1},children:e.jsx(S,{variant:"text",sx:{fontSize:"0.875rem",width:"60px",display:"inline-block"}})}),e.jsx(f,{align:"right",sx:{py:1},children:e.jsx(S,{variant:"text",sx:{fontSize:"0.875rem",width:"50px",display:"inline-block"}})}),e.jsx(f,{align:"right",sx:{py:1},children:e.jsx(S,{variant:"circular",width:28,height:28})})]},w))})]})})]}):p?e.jsxs(e.Fragment,{children:[b(),e.jsx(se,{primaryText:"Erro ao carregar os top produtos.",secondaryText:(i==null?void 0:i.message)||"Tente novamente mais tarde."})]}):e.jsxs(e.Fragment,{children:[b(),!h||h.length===0?e.jsx(se,{primaryText:"Nenhuma venda no perÃodo",secondaryText:"Quando houver vendas, você verá os produtos mais vendidos aqui."}):e.jsx(Z,{component:ee,elevation:0,variant:"outlined",sx:{border:"none",pb:"8px",bgcolor:"transparent","&::-webkit-scrollbar":{width:"6px",height:"6px"},"&::-webkit-scrollbar-track":{backgroundColor:"transparent"},"&::-webkit-scrollbar-thumb":{backgroundColor:r.palette.mode==="light"?j(r.palette.grey[500],.3):j(r.palette.grey[400],.3),borderRadius:"4px","&:hover":{backgroundColor:r.palette.mode==="light"?j(r.palette.grey[500],.5):j(r.palette.grey[400],.5)}}},children:e.jsxs(te,{size:"small",children:[e.jsx(ne,{children:e.jsxs(H,{sx:{fontWeight:"700",color:"text.secondary"},children:[e.jsx(f,{sx:{py:1,width:"48px"}}),e.jsx(f,{sx:{fontWeight:"inherit",py:1},children:"Produto"}),e.jsx(f,{align:"right",sx:{fontWeight:"inherit",py:1},children:e.jsx(Q,{active:l==="totalQuantitySold",direction:"desc",onClick:()=>d("totalQuantitySold"),children:"Vendas"})}),e.jsx(f,{align:"right",sx:{fontWeight:"inherit",py:1},children:e.jsx(Q,{active:l==="totalRevenue",direction:"desc",onClick:()=>d("totalRevenue"),children:"Receita"})}),e.jsx(f,{align:"right",sx:{fontWeight:"inherit",py:1},children:e.jsx(Q,{active:l==="profit",direction:"desc",onClick:()=>d("profit"),children:"Lucro"})}),e.jsx(f,{sx:{py:1,width:"48px"}})]})}),e.jsx(re,{children:h.map(m=>{var w;return e.jsxs(H,{hover:!0,onClick:()=>!a&&x(`/products/${m.productId}/profitability`),sx:{cursor:a?"default":"pointer"},children:[e.jsx(f,{sx:{py:1,width:"48px"},children:a?e.jsx(n,{sx:W(a),children:e.jsx(S,{variant:"circular",width:24,height:24})}):e.jsx(Ve,{imageUrl:((w=m.imageUrls)==null?void 0:w[0])??void 0,size:24})}),e.jsx(f,{component:"th",scope:"row",sx:{maxWidth:150,py:1},children:a?e.jsxs(n,{sx:W(a),children:[e.jsx(o,{variant:"body2",noWrap:!0,fontWeight:500,children:"Produto ABC"}),m.sku&&e.jsx(o,{variant:"caption",color:"text.secondary",noWrap:!0,children:"COD: 123"})]}):e.jsxs(e.Fragment,{children:[e.jsx(o,{variant:"body2",fontWeight:500,color:"text.primary",sx:Ee(3),title:m.productName,children:m.productName}),m.sku&&e.jsxs(o,{variant:"caption",color:"text.secondary",noWrap:!0,children:["COD: ",m.sku]})]})}),e.jsx(f,{align:"right",sx:{py:1},children:a?e.jsx(o,{variant:"body2",sx:W(a),children:T.number}):e.jsxs(o,{variant:"body2",color:"text.primary",fontWeight:500,children:[m.totalQuantitySold.toLocaleStr
1ing("pt-BR")," un"]})}),e.jsx(f,{align:"right",sx:{py:1},children:a?e.jsx(o,{variant:"body2",sx:W(a),children:T.currency}):e.jsx(o,{variant:"body2",color:"text.primary",fontWeight:500,children:We.format(m.totalRevenue)})}),e.jsx(f,{align:"right",sx:{py:1},children:a?e.jsx(o,{variant:"body2",sx:W(a),children:T.currency}):e.jsx(o,{variant:"body2",fontWeight:500,children:We.format(m.profit??0)})}),e.jsx(f,{align:"right",sx:{py:1,width:"48px"},children:!a&&e.jsx(ke,{size:"small",sx:{color:"text.secondary"},children:e.jsx(ue,{fontSize:"small"})})})]},m.productId)})})]})})]})},Rt=new Intl.NumberFormat("pt-BR",{style:"currency",currency:"BRL",notation:"compact",minimumFractionDigits:0,maximumFractionDigits:1}),zt=({startDate:t,endDate:s,isBlurred:a})=>{const x=de(),[c]=xe(),r=q(),[l,g]=O.useState("totalRevenue"),d=m=>{g(m)},y=O.useMemo(()=>{if(!(!t||!s))return{startDate:t,endDate:s,sortBy:l,sortDirection:"desc",limit:5}},[t,s,l]),{data:h,isLoading:u,isError:p,error:i}=gt(y),b=()=>e.jsxs(n,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:2},children:[e.jsxs(n,{sx:{display:"flex",alignItems:"center"},children:[e.jsx(n,{sx:{bgcolor:j(r.palette.success.main,.12),color:r.palette.success.main,width:32,height:32,borderRadius:"6px",display:"flex",alignItems:"center",justifyContent:"center",mr:1.25},children:e.jsx(Xe,{})}),e.jsx(o,{variant:"subtitle1",fontWeight:"500",children:"Top clientes"})]}),e.jsx(ce,{variant:"text",size:"small",endIcon:e.jsx(je,{}),onClick:()=>x(`/reports/customers?${c.toString()}`),sx:{color:r.palette.success.main,textTransform:"none",fontSize:"0.875rem",fontWeight:600,"&:hover":{backgroundColor:j(r.palette.success.main,.04)}},children:"Ver todos"})]});return u?e.jsxs(e.Fragment,{children:[b(),e.jsx(Z,{component:ee,elevation:0,variant:"outlined",sx:{pb:"8px",border:"none",bgcolor:"transparent","&::-webkit-scrollbar":{width:"6px",height:"6px"},"&::-webkit-scrollbar-track":{backgroundColor:"transparent"},"&::-webkit-scrollbar-thumb":{backgroundColor:r.palette.mode==="light"?j(r.palette.grey[500],.3):j(r.palette.grey[400],.3),borderRadius:"4px","&:hover":{backgroundColor:r.palette.mode==="light"?j(r.palette.grey[500],.5):j(r.palette.grey[400],.5)}}},children:e.jsxs(te,{size:"small",children:[e.jsx(ne,{children:e.jsxs(H,{sx:{fontWeight:"700",color:"text.secondary"},children:[e.jsx(f,{sx:{fontWeight:"inherit",py:1},children:"Cliente"}),e.jsx(f,{align:"right",sx:{fontWeight:"inherit",py:1},children:e.jsx(Q,{active:!1,direction:"desc",children:"Pedidos"})}),e.jsx(f,{align:"right",sx:{fontWeight:"inherit",py:1},children:e.jsx(Q,{active:!1,direction:"desc",children:"Total gasto"})}),e.jsx(f,{sx:{py:1,width:"48px"}})]})}),e.jsx(re,{children:[...Array(5)].map((m,w)=>e.jsxs(H,{children:[e.jsx(f,{component:"th",scope:"row",sx:{py:1,maxWidth:150},children:e.jsx(S,{variant:"text",sx:{fontSize:"0.875rem"}})}),e.jsx(f,{align:"right",sx:{py:1},children:e.jsx(S,{variant:"text",sx:{fontSize:"0.875rem",width:"30px",display:"inline-block"}})}),e.jsx(f,{align:"right",sx:{py:1},children:e.jsx(S,{variant:"text",sx:{fontSize:"0.875rem",width:"70px",display:"inline-block"}})}),e.jsx(f,{align:"right",sx:{py:1},children:e.jsx(S,{variant:"circular",width:28,height:28})})]},w))})]})})]}):p?e.jsxs(e.Fragment,{children:[b(),e.jsx(se,{primaryText:"Erro ao carregar os top clientes.",secondaryText:(i==null?void 0:i.message)||"Tente novamente mais tarde."})]}):e.jsxs(e.Fragment,{children:[b(),!h||h.length===0?e.jsx(se,{primaryText:"Nenhuma venda no perÃodo",secondaryText:"Quando houver vendas, você verá seus principais clientes aqui."}):e.jsx(Z,{component:ee,elevation:0,variant:"outlined",sx:{pb:"8px",border:"none",bgcolor:"transparent","&::-webkit-scrollbar":{width:"6px",height:"6px"},"&::-webkit-scrollbar-track":{backgroundColor:"transparent"},"&::-webkit-scrollbar-thumb":{backgroundColor:r.palette.mode==="light"?j(r.palette.grey[500],.3):j(r.palette.grey[400],.3),borderRadius:"4px","&:hover":{backgroundColor:r.palette.mode==="light"?j(r.palette.grey[500],.5):j(r.palette.grey[400],.5)}}},children:e.jsxs(te,{size:"small",children:[e.jsx(ne,{children:e.jsxs(H,{sx:{fontWeight:"700",color:"text.secondary"},children:[e.jsx(f,{sx:{fontWeight:"inherit",py:1},children:"Cliente"}),e.jsx(f,{align:"right",sx:{fontWeight:"inherit",py:1},children:e.jsx(Q,{active:l==="totalOrders",direction:"desc",onClick:()=>d("totalOrders"),children:"Pedidos"})}),e.jsx(f,{align:"right",sx:{fontWeight:"inherit",py:1},children:e.jsx(Q,{active:l==="totalRevenue",direction:"desc",onClick:()=>d("totalRevenue"),children:"Total gasto"})}),e.jsx(f,{sx:{py:1,width:"48px"}})]})}),e.jsx(re,{children:h.map(m=>e.jsxs(H,{hover:!0,onClick:()=>!a&&m.customerId&&x(`/customers/${m.customerId}`),sx:{cursor:!a&&m.customerId?"pointer":"default"},children:[e.jsx(f,{component:"th",scope:"row",sx:{py:1,maxWidth:150,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:a?e.jsx(o,{variant:"body2",fontWeight:500,sx:W(a),children:"Cliente XYZ"}):e.jsx(o,{variant:"body2",fontWeight:500,color:"text.primary",children:m.customerName||"Cliente avulso"})}),e.jsx(f,{align:"right",sx:{py:1},children:a?e.jsx(o,{variant:"body2",sx:W(a),children:T.number}):e.jsx(o,{variant:"body2",color:"text.primary",fontWeight:500,children:m.totalOrders.toLocaleStr
1ing("pt-BR")})}),e.jsx(f,{align:"right",sx:{py:1},children:a?e.jsx(o,{variant:"body2",sx:W(a),children:T.currency}):e.jsx(o,{variant:"body2",color:"text.primary",fontWeight:500,children:Rt.format(m.totalRevenue)})}),e.jsx(f,{align:"right",sx:{py:1,width:"48px"},children:!a&&m.customerId&&e.jsx(ke,{size:"small",sx:{color:"text.secondary"},children:e.jsx(ue,{fontSize:"small"})})})]},m.customerId))})]})})]})},Tt=({startDate:t,endDate:s,isBlurred:a})=>{const x=de(),[c]=xe(),r=q(),l=O.useMemo(()=>{if(!(!t||!s))return{startDate:t,endDate:s,sortBy:"valor",sortDirection:"desc",limit:5}},[t,s]),{data:g,isLoading:d,isError:y,error:h}=ft(l),u=()=>e.jsxs(n,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between",mb:2},children:[e.jsxs(n,{sx:{display:"flex",alignItems:"center"},children:[e.jsx(n,{sx:{bgcolor:j("#FF6B35",.12),color:"#FF6B35",width:32,height:32,borderRadius:"6px",display:"flex",alignItems:"center",justifyContent:"center",mr:1.25},children:e.jsx(Je,{fontSize:"small"})}),e.jsx(o,{variant:"subtitle1",fontWeight:"500",children:"Balanço de estoque"})]}),e.jsx(ce,{variant:"text",size:"small",endIcon:e.jsx(je,{}),onClick:()=>x(`/reports/stock-balance?${c.toString()}`),sx:{color:"#FF6B35",textTransform:"none",fontSize:"0.875rem",fontWeight:600,"&:hover":{backgroundColor:j("#FF6B35",.04)}},children:"Ver todos"})]});return d?e.jsxs(e.Fragment,{children:[u(),e.jsx(Z,{component:ee,elevation:0,variant:"outlined",sx:{pb:"8px",border:"none",bgcolor:"transparent","&::-webkit-scrollbar":{width:"6px",height:"6px"},"&::-webkit-scrollbar-track":{backgroundColor:"transparent"},"&::-webkit-scrollbar-thumb":{backgroundColor:r.palette.mode==="light"?j(r.palette.grey[500],.3):j(r.palette.grey[400],.3),borderRadius:"4px","&:hover":{backgroundColor:r.palette.mode==="light"?j(r.palette.grey[500],.5):j(r.palette.grey[400],.5)}}},children:e.jsxs(te,{size:"small",children:[e.jsx(ne,{children:e.jsxs(H,{sx:{fontWeight:"700",color:"text.secondary"},children:[e.jsx(f,{sx:{fontWeight:"inherit",py:1},children:"Data"}),e.jsx(f,{sx:{fontWeight:"inherit",py:1},children:"Tipo"}),e.jsx(f,{sx:{fontWeight:"inherit",py:1},children:"Produto"}),e.jsx(f,{align:"right",sx:{fontWeight:"inherit",py:1},children:"Qtd"})]})}),e.jsx(re,{children:[...Array(5)].map((p,i)=>e.jsxs(H,{children:[e.jsx(f,{sx:{py:1},children:e.jsx(S,{variant:"text",sx:{fontSize:"0.875rem"}})}),e.jsx(f,{sx:{py:1},children:e.jsx(S,{variant:"rectangular",width:100,height:24,sx:{borderRadius:"12px"}})}),e.jsx(f,{sx:{py:1},children:e.jsxs(n,{sx:{display:"flex",alignItems:"center",gap:1},children:[e.jsx(S,{variant:"circular",width:24,height:24}),e.jsx(S,{variant:"text",width:100,sx:{fontSize:"0.875rem"}})]})}),e.jsx(f,{align:"right",sx:{py:1},children:e.jsx(S,{variant:"text",sx:{fontSize:"0.875rem",width:"30px",display:"inline-block"}})})]},i))})]})})]}):y?e.jsxs(e.Fragment,{children:[u(),e.jsx(se,{primaryText:"Erro ao carregar movimentos.",secondaryText:(h==null?void 0:h.message)||"Tente novamente mais tarde."})]}):e.jsxs(e.Fragment,{children:[u(),!g||!g.products||g.products.length===0?e.jsx(se,{primaryText:"Nenhum produto no perÃodo",secondaryText:"Quando houver movimentações de estoque, você verá um resumo aqui."}):e.jsxs(e.Fragment,{children:[g.summary&&e.jsxs(n,{sx:{display:"flex",gap:2.5,mb:2,flexWrap:"wrap"},children:[e.jsxs(o,{variant:"caption",color:"text.secondary",sx:{fontSize:"0.75rem"},children:["Entradas:"," ",e.jsxs(o,{component:"span",variant:"caption",fontWeight:600,color:"success.main",sx:{fontSize:"0.75rem"},children:["+",g.summary.total_entradas.toLocaleString("pt-BR")]})]}),e.jsxs(o,{variant:"caption",color:"text.secondary",sx:{fontSize:"0.75rem"},children:["SaÃdas:"," ",e.jsxs(o,{component:"span",variant:"caption",fontWeight:600,color:"error.main",sx:{fontSize:"0.75rem"},children:["-",g.summary.total_saidas.toLocaleString("pt-BR")]})]})]}),e.jsx(Z,{component:ee,elevation:0,variant:"outlined",sx:{pb:"8px",border:"none",bgcolor:"transparent","&::-webkit-scrollbar":{width:"6px",height:"6px"},"&::-webkit-scrollbar-track":{backgroundColor:"transparent"},"&::-webkit-scrollbar-thumb":{backgroundColor:r.palette.mode==="light"?j(r.palette.grey[500],.3):j(r.palette.grey[400],.3),borderRadius:"4px","&:hover":{backgroundColor:r.palette.mode==="light"?j(r.palette.grey[500],.5):j(r.palette.grey[400],.5)}}},children:e.jsxs(te,{size:"small",children:[e.jsx(ne,{children:e.jsxs(H,{sx:{fontWeight:"700",color:"text.secondary"},children:[e.jsx(f,{sx:{fontWeight:"inherit",py:1,width:"48px"}}),e.jsx(f,{sx:{fontWeight:"inherit",py:1},children:"Produto"}),e.jsx(f,{align:"right",sx:{fontWeight:"inherit",py:1},children:"Entradas"}),e.jsx(f,{align:"right",sx:{fontWeight:"inherit",py:1},children:"SaÃdas"})]})}),e.jsx(re,{children:g.products.map(p=>e.jsxs(H,{hover:!0,onClick:()=>!a&&x(`/reports/stock-balance?${c.toString()}`),sx:{cursor:a?"default":"pointer"},children:[e.jsx(f,{sx:{py:1,width:"48px"},children:e.jsx(Ve,{imageUrl:p.produto_image_url[0],size:24})}),e.jsx(f,{sx:{py:1,maxWidth:150},children:e.jsx(o,{variant:"body2",fontWeight:500,color:"text.primary",sx:Ee(3),title:p.produto_nome,children:p.produto_nome})}),e.jsx(f,{align:"right",sx:{py:1},children:e.jsx(o,{variant:"body2",fontWeight:600,sx:{color:r.palette.success.main},children:p.entradas>0?`+${p.entradas}`:"â"})}),e.jsx(f,{align:"right",sx:{py:1},children:e.jsx(o,{variant:"body2",fontWeight:600,sx:{color:r.palette.error.main},children:p.saidas>0?`-${p.saidas}`:"â"})})]},`${p.produto_id}_${p.produto_variacao_id}`))})]})})]})]})},Dt=({kpis:t,ordersVolumeChart:s,baseChartOptions:a,customColors:x,isLoading:c})=>{var d;const r=q(),l=V.useMemo(()=>{var y,h;return!c&&(s!=null&&s.series)?be(s.series,"Pedidos"):[{name:((h=(y=s==null?void 0:s.series)==null?void 0:y[0])==null?void 0:h.name)||"Pedidos",data:[]}]},[c,s]),g=((d=s==null?void 0:s.series[0])==null?void 0:d.color)||x.sales;return e.jsx(L,{sx:{bgcolor:"white",height:"100%"},children:e.jsxs(E,{sx:{p:0,"&:last-child":{pb:0},display:"flex",flexDirection:"column",height:"100%"},children:[e.jsxs(n,{sx:{pt:2,px:2},children:[e.jsxs(n,{sx:{display:"flex",alignItems:"center",mb:1.5},children:[e.jsx(n,{sx:{bgcolor:j(g,.12),color:g,width:32,height:32,borderRadius:"6px",display:"flex",alignItems:"center",justifyContent:"center",mr:1.25}
1,children:e.jsx(Ze,{})}),e.jsx(o,{variant:"subtitle1",fontWeight:"500",children:"Volume de pedidos"})]}),e.jsxs(n,{sx:{display:"flex",alignItems:"center",mb:1},children:[c?e.jsx(S,{variant:"text",width:80,height:32}):e.jsxs(o,{variant:"h5",fontWeight:"700",children:[((t==null?void 0:t.totalOrders)??0).toLocaleString("pt-BR")," "]}),c?e.jsx(S,{variant:"text",width:50,height:20,sx:{ml:.75,alignSelf:"flex-end"}}):e.jsx(o,{variant:"caption",color:"text.secondary",sx:{ml:.75,alignSelf:"flex-end"},children:((t==null?void 0:t.totalOrders)??0)!==1?"Pedidos":"Pedido"})]}),e.jsxs(I,{container:!0,spacing:1,sx:{mb:1.5},children:[e.jsxs(I,{item:!0,xs:6,children:[e.jsxs(n,{sx:{display:"flex",alignItems:"center"},children:[e.jsx(n,{sx:{width:8,height:8,borderRadius:"50%",bgcolor:r.palette.success.main,mr:1}}),e.jsx(o,{variant:"body2",color:"text.secondary",children:"Pagos:"})]}),c?e.jsx(S,{variant:"text",width:40,sx:{pl:"16px"}}):e.jsx(o,{variant:"body2",fontWeight:"500",color:"text.primary",sx:{pl:"16px"},children:((t==null?void 0:t.paidOrdersCount)??0).toLocaleString("pt-BR")})]}),e.jsxs(I,{item:!0,xs:6,children:[e.jsxs(n,{sx:{display:"flex",alignItems:"center"},children:[e.jsx(n,{sx:{width:8,height:8,borderRadius:"50%",bgcolor:r.palette.warning.main,mr:1}}),e.jsx(o,{variant:"body2",color:"text.secondary",children:"Pendentes:"})]}),c?e.jsx(S,{variant:"text",width:40,sx:{pl:"16px"}}):e.jsx(o,{variant:"body2",fontWeight:"500",color:"text.primary",sx:{pl:"16px"},children:((t==null?void 0:t.pendingOrdersCount)??0).toLocaleString("pt-BR")})]})]})]}),e.jsx(n,{sx:{height:150,mt:"auto"},children:e.jsx(oe,{children:l.length>0&&l[0].data.length>0?e.jsx(ae,{options:{...a,colors:[g],tooltip:{...a.tooltip,y:{formatter:y=>`${y} pedidos`}},grid:{...a.grid,padding:{top:10,right:0,bottom:10,left:0}}},series:l,type:"area",height:"100%"}):e.jsx(n,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"100%"},children:e.jsx(o,{variant:"caption",color:"text.secondary",children:"Sem dados para exibir"})})})})]})})},B=({value:t,variant:s="inherit",fontWeight:a="inherit",color:x="text.primary",isLoading:c=!1,blur:r=!1,blurText:l="R$ 123,45",blurStyle:g={}})=>{const[d,y]=O.useState(!1),h=O.useMemo(()=>new Intl.NumberFormat("pt-BR",{style:"currency",currency:"BRL",notation:"compact",minimumFractionDigits:0,maximumFractionDigits:1}),[]),u=O.useMemo(()=>new Intl.NumberFormat("pt-BR",{style:"currency",currency:"BRL",minimumFractionDigits:2,maximumFractionDigits:2}),[]),p=O.useMemo(()=>t==null||isNaN(t)?"-":Math.abs(t)>=1e3&&!d?h.format(t):u.format(t),[t,d,h,u]);if(c){let i="80px";return r&&l?i=`${l.length*(s==="h5"?10:8)}px`:s==="h5"?i="120px":s==="body2"&&(i="60px"),e.jsx(S,{variant:"text",width:i,sx:{fontSize:s}})}return r?e.jsx(o,{variant:s,fontWeight:a,color:x,sx:g,children:l}):e.jsx(o,{variant:s,fontWeight:a,color:x,onClick:()=>y(i=>!i),sx:{cursor:"pointer"},title:d?"Clique para ver valor resumido":"Clique para ver valor completo",children:p})},Pt=({kpis:t,revenueChart:s,baseChartOptions:a,customColors:x,formatCurrency:c,isLoading:r})=>{var y;const l=q(),g=V.useMemo(()=>{var h,u;return!r&&(s!=null&&s.series)?be(s.series,"Receita"):[{name:((u=(h=s==null?void 0:s.series)==null?void 0:h[0])==null?void 0:u.name)||"Receita",data:[]}]},[r,s]),d=((y=s==null?void 0:s.series[0])==null?void 0:y.color)||x.revenue;return e.jsx(L,{sx:{bgcolor:"white",height:"100%"},children:e.jsxs(E,{sx:{p:0,"&:last-child":{pb:0},display:"flex",flexDirection:"column",height:"100%"},children:[e.jsxs(n,{sx:{pt:2,px:2},children:[e.jsxs(n,{sx:{display:"flex",alignItems:"center",mb:1.5},children:[e.jsx(n,{sx:{bgcolor:j(d,.12),color:d,width:32,height:32,borderRadius:"6px",display:"flex",alignItems:"center",justifyContent:"center",mr:1.25},children:e.jsx(Me,{})}),e.jsx(o,{variant:"subtitle1",fontWeight:"500",children:"Receita"})]}),e.jsx(n,{sx:{display:"flex",alignItems:"baseline",mb:1.5},children:e.jsx(B,{value:(t==null?void 0:t.totalRevenue)??0,variant:"h5",fontWeight:"700",isLoading:r})}),e.jsxs(I,{container:!0,spacing:1,sx:{mb:1.5},children:[e.jsxs(I,{item:!0,xs:6,children:[e.jsxs(n,{sx:{display:"flex",alignItems:"center"},children:[e.jsx(n,{sx:{width:8,height:8,borderRadius:"50%",bgcolor:d,mr:1}}),e.jsx(o,{variant:"body2",color:"text.secondary",children:"Confirmada:"})]}),e.jsx(B,{value:(t==null?void 0:t.confirmedRevenue)??0,variant:"body2",fontWeight:"500",color:"text.primary",isLoading:r})]}),e.jsxs(I,{item:!0,xs:6,children:[e.jsxs(n,{sx:{display:"flex",alignItems:"center"},children:[e.jsx(n,{sx:{width:8,height:8,borderRadius:"50%",bgcolor:l.palette.warning.main,mr:1}}),e.jsx(o,{variant:"body2",color:"text.secondary",children:"Pendente:"})]}),e.jsx(B,{value:(t==null?void 0:t.pendingRevenue)??0,variant:"body2",fontWeight:"500",color:"text.primary",isLoading:r})]})]})]}),e.jsx(n,{sx:{height:150,mt:"auto"},children:e.jsx(oe,{children:g.length>0&&g[0].data.length>0?e.jsx(ae,{options:{...a,colors:[d],tooltip:{...a.tooltip,y:{formatter:h=>c(h)}},grid:{...a.grid,padding:{top:0,right:0,bottom:5,left:0}}},series:g,type:"area",height:"100%"}):e.jsx(n,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"100%"},children:e.jsx(o,{variant:"caption",color:"text.secondary",children:"Sem dados para exibir"})})})})]})})};function kt(t){return(.4+Lt(t)*9.6)*t}function Lt(t){const s=Math.sin((t+1)*15731)*789221+Math.cos(t*37441)*1376312589;return Et(s)}function Et(t){return t-Math.floor(t)}const Mt=({kpis:t,profitChart:s,baseChartOptions:a,customColors:x,formatCurrency:c,isLoading:r,isBlurred:l})=>
1{var k,C,v,A,M,K,_,G,R;const g=q(),d=!l,y=O.useMemo(()=>F=>d?F:kt(F),[d]),h=O.useMemo(()=>{var F,D;if(!r&&(s!=null&&s.series)){const N=be(s.series,"Lucro");return!d&&N.length>0&&N[0].data.length>0?[{...N[0],data:N[0].data.map(U=>({...U,y:y(U.y)}))}]:N}return[{name:((D=(F=s==null?void 0:s.series)==null?void 0:F[0])==null?void 0:D.name)||"Lucro",data:[]}]},[r,s,l,y,d]),u=((k=s==null?void 0:s.series[0])==null?void 0:k.color)||x.profit,p=(t==null?void 0:t.totalProfit)??0,i=(t==null?void 0:t.totalRevenue)??0,b=(t==null?void 0:t.confirmedProfit)??0,m=(t==null?void 0:t.pendingProfit)??0,w=i>0&&!isNaN(p)&&!isNaN(i),z=w?p/i*100:0,$=w?`${z.toFixed(0)}%`:"0%";return e.jsx(L,{sx:{bgcolor:"white",height:"100%"},children:e.jsxs(E,{sx:{p:0,"&:last-child":{pb:0},display:"flex",flexDirection:"column",height:"100%"},children:[e.jsxs(n,{sx:{pt:2,px:2},children:[e.jsxs(n,{sx:{display:"flex",alignItems:"center",mb:1.5},children:[e.jsx(n,{sx:{bgcolor:j(u,.12),color:u,width:32,height:32,borderRadius:"6px",display:"flex",alignItems:"center",justifyContent:"center",mr:1.25},children:e.jsx(et,{})}),e.jsx(o,{variant:"subtitle1",fontWeight:"500",children:"Lucro"})]}),e.jsx(n,{sx:{display:"flex",alignItems:"baseline",mb:.5},children:e.jsx(B,{value:p,variant:"h5",fontWeight:"700",isLoading:r,blur:l,blurText:T.currency,blurStyle:W(l)})}),r?e.jsx(S,{variant:"text",width:"80px",height:"20px",sx:{mb:1.5,ml:.5}}):w&&e.jsxs(o,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:1.5,ml:.5,...W(l)},children:["Margem ",l?T.percentage:$]}),e.jsxs(I,{container:!0,spacing:1,sx:{mb:1.5},children:[e.jsxs(I,{item:!0,xs:6,children:[e.jsxs(n,{sx:{display:"flex",alignItems:"center"},children:[e.jsx(n,{sx:{width:8,height:8,borderRadius:"50%",bgcolor:u,mr:1}}),e.jsx(o,{variant:"body2",color:"text.secondary",children:"Confirmado:"})]}),e.jsx(B,{value:b,variant:"body2",fontWeight:"500",color:"text.primary",isLoading:r,blur:l,blurText:T.currency,blurStyle:W(l)})]}),e.jsxs(I,{item:!0,xs:6,children:[e.jsxs(n,{sx:{display:"flex",alignItems:"center"},children:[e.jsx(n,{sx:{width:8,height:8,borderRadius:"50%",bgcolor:g.palette.warning.main,mr:1}}),e.jsx(o,{variant:"body2",color:"text.secondary",children:"Pendente:"})]}),e.jsx(B,{value:m,variant:"body2",fontWeight:"500",color:"text.primary",isLoading:r,blur:l,blurText:T.currency,blurStyle:W(l)})]})]})]}),e.jsx(n,{sx:{height:150,mt:"auto",...ie(l)},children:e.jsx(oe,{children:h.length>0&&h[0].data.length>0?e.jsx(ae,{options:{...a,colors:[u],tooltip:{...a.tooltip,enabled:!l,y:{formatter:F=>c(l?0:F)}},chart:{...a.chart,events:{dataPointSelection:l?()=>{}:(v=(C=a.chart)==null?void 0:C.events)==null?void 0:v.dataPointSelection,markerClick:l?()=>{}:(M=(A=a.chart)==null?void 0:A.events)==null?void 0:M.markerClick},toolbar:{show:l?!1:(_=(K=a.chart)==null?void 0:K.toolbar)==null?void 0:_.show},zoom:{enabled:l?!1:(R=(G=a.chart)==null?void 0:G.zoom)==null?void 0:R.enabled}},grid:{...a.grid,padding:{top:0,right:0,bottom:5,left:0}}},series:h,type:"area",height:"100%"}):e.jsx(n,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"100%"},children:e.jsx(o,{variant:"caption",color:"text.secondary",children:"Sem dados para exibir"})})})})]})})},At=({kpis:t,isLoading:s,isBlurred:a})=>{const x=q(),c=(t==null?void 0:t.averageTicketSale)??0;return e.jsx(L,{sx:{bgcolor:"white",height:"100%"},children:e.jsxs(E,{sx:{display:"flex",flexDirection:"column",height:"100%"},children:[e.jsxs(n,{sx:{display:"flex",alignItems:"center",mb:1.5},children:[e.jsx(n,{sx:{bgcolor:j(x.palette.info.main,.12),color:x.palette.info.main,width:32,height:32,borderRadius:"6px",display:"flex",alignItems:"center",justifyContent:"center",mr:1.25},children:e.jsx(Me,{})}),e.jsx(o,{variant:"subtitle1",fontWeight:"500",children:"Ticket médio"})]}),a&&!s?e.jsx(o,{variant:"h5",fontWeight:"700",sx:W(a),children:T.currency}):e.jsx(B,{value:c,variant:"h5",fontWeight:"700",isLoading:s}),e.jsx(o,{variant:"caption",color:"text.secondary",sx:{mt:.5},children:"Valor médio por pedido"})]})})};var ve={},Ot=Le;
1Object.defineProperty(ve,"__esModule",{value:!0});var qe=ve.default=void 0,$t=Ot(Ae()),Vt=e;qe=ve.default=(0,$t.default)((0,Vt.jsx)("path",{d:"M12 2C6.5 2 2 6.5 2 12s4.5 10 10 10 10-4.5 10-10S17.5 2 12 2m1 2.07c3.61.45 6.48 3.33 6.93 6.93H13zM4 12c0-4.06 3.07-7.44 7-7.93v15.87c-3.93-.5-7-3.88-7-7.94m9 7.93V13h6.93c-.45 3.61-3.32 6.48-6.93 6.93"}),"PieChartOutline");const _t=({salesDistributionData:t,customColors:s,isLoading:a,isBlurred:x})=>{const c=q(),r=["Online","Presencial"],l=[s.online,s.presencial],{chartSeriesToDisplay:g,sanitizedLabels:d,sanitizedColors:y}=V.useMemo(()=>{if(a)return{chartSeriesToDisplay:[0,0],sanitizedLabels:r,sanitizedColors:l};if(!t)return{chartSeriesToDisplay:[],sanitizedLabels:[],sanitizedColors:[]};const{onlineOrders:u,presencialOrders:p}=t,i=typeof u=="number"&&Number.isFinite(u)&&u>=0?u:0,b=typeof p=="number"&&Number.isFinite(p)&&p>=0?p:0,m=i+b;if(m===0)return{chartSeriesToDisplay:[],sanitizedLabels:[],sanitizedColors:[]};const w=[i/m*100,b/m*100],{series:z,labels:$}=jt(w,r);return{chartSeriesToDisplay:z,sanitizedLabels:$,sanitizedColors:$.map((k,C)=>l[r.indexOf($[C])]||l[0])}},[t,a]),h=a;return e.jsx(L,{sx:{bgcolor:"white",height:"100%"},children:e.jsxs(E,{sx:{display:"flex",flexDirection:"column",height:"100%",p:2,"&:last-child":{pb:2}},children:[e.jsxs(n,{sx:{display:"flex",alignItems:"center",mb:1.5},children:[e.jsx(n,{sx:{bgcolor:j(c.palette.secondary.main,.12),color:c.palette.secondary.main,width:32,height:32,borderRadius:"6px",display:"flex",alignItems:"center",justifyContent:"center",mr:1.25},children:e.jsx(qe,{fontSize:"small"})}),e.jsx(o,{variant:"subtitle1",fontWeight:"500",children:"Distribuição de vendas"})]}),e.jsxs(n,{sx:{display:"flex",alignItems:"center",mt:1,flexGrow:1},children:[e.jsx(n,{sx:{width:80,height:80,mr:2,maxWidth:80,maxHeight:80,display:"flex",alignItems:"center",justifyContent:"center",...ie(x)},children:e.jsx(oe,{children:g.length>0&&g.every(u=>Number.isFinite(u)&&u>0)?e.jsx(ae,{options:{chart:{width:80,height:80,type:"pie",sparkline:{enabled:!0},animations:{enabled:!1},selection:{enabled:!1}},colors:y,stroke:{show:!0,width:3,colors:[c.palette.background.paper]},legend:{show:!1},dataLabels:{enabled:!1},tooltip:{enabled:!1},states:{hover:{filter:{type:"none"}},active:{allowMultipleDataPointsSelection:!1,filter:{type:"none"}}},plotOptions:{pie:{expandOnClick:!1,donut:{size:"50%",labels:{show:!1}}}}},series:g,type:"pie",height:"100%",width:"100%"}):e.jsx(n,{sx:{display:"flex",justifyContent:"center",alignItems:"center",width:80,height:80},children:e.jsx(o,{variant:"caption",color:"text.secondary",sx:{fontSize:"10px"},children:"Sem dados"})})})}),e.jsx(n,{sx:{flexGrow:1},children:(h?["SkeletonText1","SkeletonText2"]:d).map((u,p)=>{var i;return e.jsxs(n,{sx:{display:"flex",alignItems:"center",mb:p<(h?1:d.length-1)?1:0},children:[e.jsx(n,{sx:{width:10,height:10,borderRadius:"50%",bgcolor:h?c.palette.divider:y[p]||c.palette.divider,mr:1}}),h?e.jsx(S,{variant:"text",width:"70%"}):e.jsxs(o,{variant:"body2",sx:{flexGrow:1},children:[u,":"]}),h?e.jsx(S,{variant:"text",width:"20%",sx:{ml:.5}}):e.jsx(o,{variant:"body2",fontWeight:"500",sx:W(x),children:x?T.percentage:`${((i=g[p])==null?void 0:i.toFixed(0))??"0"}%`})]},h?p:u)})})]})]})})},qt=({kpis:t,isLoading:s,isBlurred:a})=>{const x=(t==null?void 0:t.totalDiscounts)??0,c="#C465F8";return e.jsx(L,{sx:{bgcolor:"white",height:"100%"},children:e.jsxs(E,{sx:{display:"flex",flexDirection:"column",height:"100%"},children:[e.jsxs(n,{sx:{display:"flex",alignItems:"center",mb:1.5},children:[e.jsx(n,{sx:{bgcolor:j(c,.12),color:c,width:32,height:32,borderRadius:"6px",display:"flex",alignItems:"center",justifyContent:"center",mr:1.25},children:e.jsx(tt,{})}),e.jsx(o,{variant:"subtitle1",fontWeight:"500",children:"Descontos"})]}),a&&!s?e.jsx(o,{variant:"h5",fontWeight:"700",sx:W(a),children:T.currency}):e.jsx(B,{value:x,variant:"h5",fontWeight:"700",isLoading:s}),e.jsx(o,{variant:"caption",color:"text.secondary",sx:{mt:.5},children:"Total concedido"})]})})},Nt=async t=>{var g,d;const{startDate:s,endDate:a}=t,x=s.toISOString(),c=a.toISOString(),r=await me.get("/reports/payment-methods",{params:{startDate:x,endDate:c}});if(r.status&&r.status!==200)throw new Error(((g=r.data)==null?void 0:g.error)||((d=r.data)==null?void 0:d.message)||"Failed to fetch payment methods report");const l=r.data;if(!l||typeof l!="object")throw new Error("Invalid payment methods response data format");if(l.paymentConditions&&typeof l.paymentConditions=="object"){const y=l.paymentConditions;["a_vista","parcelado","fiado"].forEach(u=>{if(u in y){const p=y[u],i=typeof p=="number"?p:parseFloat(p);!Number.isFinite(i)||i<0?(console.warn(`Invalid payment condition value for ${u}:`,p),y[u]=0):y[u]=i}})}return l},Ne=t=>
1{const s=t?{startDate:t.startDate.toISOString(),endDate:t.endDate.toISOString()}:void 0;return pe({queryKey:["report-payment-methods",s],refetchOnMount:!0,queryFn:()=>{if(!t)return Promise.reject(new Error("Params are required for payment methods report."));const a={startDate:new Date(t.startDate),endDate:new Date(t.endDate)};return Nt(a)},enabled:!!t})},Re=t=>t.toLocaleString("pt-BR",{style:"currency",currency:"BRL"}),Ht=(t,s)=>{if(t)switch(t){case"pix":return"#32BCAD";case"dinheiro":return"#85BB65";case"cartao_credito":return"#ff9800";case"cartao_debito":return"#2196f3";case"mercadopago":return"#009ee3";case"pagaleve":return"#FF0099";default:return"#666"}if(s)switch(s){case"stone":return"#22B24C";case"cielo":return"#214986";case"getnet":return"#EC0000";case"rede":return"#FF6200";case"pagseguro":return"#68B548";case"safrapay":return"#C3AC6C";case"mercadopago":return"#50B4E9";case"pagaleve":return"#FF0099";case"mastercard":return"#EB001B";case"visa":return"#1A1F71";case"elo":return"#FFCD00";case"amex":return"#006FCF";case"nupay":return"#8A05BE";case"picpay":return"#11C76F";default:return"#666"}return"#666"},Qt=({startDate:t,endDate:s,isLoading:a,isBlurred:x})=>{var m;const c=q(),[r,l]=V.useState(!1),g=t&&s?{startDate:t,endDate:s}:void 0,{data:d,isLoading:y,isError:h,error:u}=Ne(g),p=a||y,i=V.useMemo(()=>{if(!d||p)return[];const w=d.paymentMethods.slice(0,6),z=Math.max(...w.map(k=>k.totalAmount));return(r?d.paymentMethods:d.paymentMethods.slice(0,4)).map(k=>{const C=Ht(k.paymentMethodCode,k.paymentMethodIcon),v=z>0?k.totalAmount/z*100:0;return{...k,color:C,percentage:v}})},[d,p,r]),b=d&&d.paymentMethods.length>4;return h?e.jsx(L,{sx:{bgcolor:"white",height:"100%"},children:e.jsxs(E,{sx:{p:2},children:[e.jsxs(n,{sx:{display:"flex",alignItems:"center",mb:1.5},children:[e.jsx(n,{sx:{bgcolor:j(c.palette.error.main,.12),color:c.palette.error.main,width:32,height:32,borderRadius:"6px",display:"flex",alignItems:"center",justifyContent:"center",mr:1.25},children:e.jsx(Ie,{size:20})}),e.jsx(o,{variant:"subtitle1",fontWeight:"500",children:"Métodos de pagamento"})]}),e.jsxs(o,{variant:"body2",color:"error",children:["Erro ao carregar dados: ",u==null?void 0:u.message]})]})}):e.jsx(L,{sx:{bgcolor:"white",height:"100%"},children:e.jsxs(E,{sx:{display:"flex",flexDirection:"column",height:"100%",p:2,"&:last-child":{pb:2}},children:[e.jsxs(n,{sx:{display:"flex",alignItems:"center",mb:1.5},children:[e.jsx(n,{sx:{bgcolor:j("#85BB65",.12),color:"#85BB65",width:32,height:32,borderRadius:"6px",display:"flex",alignItems:"center",justifyContent:"center",mr:1.25},children:e.jsx(Ie,{size:20})}),e.jsx(o,{variant:"subtitle1",fontWeight:"500",children:"Métodos de pagamento"})]}),e.jsxs(n,{sx:{mb:2},children:[e.jsxs(n,{sx:{display:"flex",justifyContent:"space-between",mb:1},children:[e.jsx(o,{variant:"body2",color:"text.secondary",children:"Total de transações:"}),p?e.jsx(S,{variant:"text",width:60}):e.jsx(o,{variant:"body2",fontWeight:"500",sx:W(x),children:x?T.count:((m=d==null?void 0:d.totalPayments)==null?void 0:m.toLocaleString("pt-BR"))||"0"})]}),e.jsxs(n,{sx:{display:"flex",justifyContent:"space-between"},children:[e.jsx(o,{variant:"body2",color:"text.secondary",children:"Valor total:"}),p?e.jsx(S,{variant:"text",width:80}):e.jsx(o,{variant:"body2",fontWeight:"500",sx:W(x),children:x?T.currency:Re((d==null?void 0:d.totalAmount)||0)})]})]}),e.jsxs(n,{sx:{flexGrow:1,...ie(x)},children:[p?e.jsx(n,{sx:{display:"flex",flexDirection:"column",gap:1.5},children:[...Array(5)].map((w,z)=>e.jsx(S,{variant:"rectangular",width:"100%",height:40},z))}):i.length>0?e.jsx(n,{sx:{display:"flex",flexDirection:"column",gap:1.5},children:i.map(w=>e.jsxs(n,{sx:{position:"relative",height:40,bgcolor:j(w.color,.05),borderRadius:1,overflow:"hidden",display:"flex",alignItems:"center",border:`1px solid ${j(w.color,.2)}`},children:[e.jsx(n,{sx:{position:"absolute",left:0,top:0,height:"100%",width:`${w.percentage}%`,bgcolor:j(w.color,.2),borderRadius:"4px",transition:"width 0.6s ease-in-out"}}),e.jsxs(n,{sx:{position:"relative",zIndex:1,display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%",px:1.5},children:[e.jsxs(n,{sx:{display:"flex",alignItems:"center"},children:[e.jsx(n,{sx:{mr:1.5,display:"flex",alignItems:"center",bgcolor:"white",borderRadius:"50%",width:24,minWidth:24,height:24,justifyContent:"center",flexShrink:0,boxShadow:`0 0 0 1px ${j(w.color,.2)}`},children:e.jsx(St,{codigoPadrao:w.paymentMethodCode,icone:w.paymentMethodIcon,size:16})}),e.jsx(o,{variant:"body2",fontWeight:"500",sx:{color:"text.primary",fontSize:"13px"},children:w.paymentMethodName})]}),e.jsx(o,{variant:"body2",fontWeight:"600",sx:{color:w.color,fontSize:"13px",...W(x)},children:x?T.currency:Re(w.totalAmount)})]})]},w.paymentMethodId))}):e.jsx(n,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:200},children:e.jsx(o,{variant:"body2",color:"text.secondary",children:"Nenhum dado disponÃvel"})}),!p&&b&&e.jsx(n,{sx:{mt:2,textAlign:"center"},children:e.jsx(ce,{variant:"text",size:"small",fullWidth:!0,disableRipple:!0,sx:{color:c.palette.primary.main,fontSize:"12px",textTransform:"none",minHeight:"auto",py:.5,px:1,gap:.5,...x&&{filter:"blur(2px)",pointerEvents:"none"}},onClick:()=>l(!r),children:r?e.jsxs(e.Fragment,{children:["Ver menos",e.jsx(_e,{fontSize:"small"})]}):e.jsxs(e.Fragment,{children:["Ver todos (",(d==null?void 0:d.paymentMethods.length)||0,")",e.
1jsx(Oe,{fontSize:"small"})]})})})]})]})})};var we={},Kt=Le;Object.defineProperty(we,"__esModule",{value:!0});var ye=we.default=void 0,Gt=Kt(Ae()),ze=e;ye=we.default=(0,Gt.default)([(0,ze.jsx)("path",{d:"M11.99 2C6.47 2 2 6.48 2 12s4.47 10 9.99 10C17.52 22 22 17.52 22 12S17.52 2 11.99 2M12 20c-4.42 0-8-3.58-8-8s3.58-8 8-8 8 3.58 8 8-3.58 8-8 8"},"0"),(0,ze.jsx)("path",{d:"M12.5 7H11v6l5.25 3.15.75-1.23-4.5-2.67z"},"1")],"AccessTime");const Ut=({startDate:t,endDate:s,isLoading:a,isBlurred:x})=>{const c=q(),r=t&&s?{startDate:t,endDate:s}:void 0,{data:l,isLoading:g,isError:d,error:y}=Ne(r),h=a||g,u=V.useMemo(()=>{if(!(l!=null&&l.paymentConditions)||h)return{series:[],labels:[],colors:[]};const p=bt(l.paymentConditions),{a_vista:i,parcelado:b,fiado:m}=p,w=[{label:"à Vista",value:i,color:"#2AC769"},{label:"Parcelado",value:b,color:"#658FFE"},{label:"Fiado",value:m,color:"#8865FE"}].filter(z=>z.value>0);return{series:w.map(z=>z.value),labels:w.map(z=>z.label),colors:w.map(z=>z.color)}},[l,h]);return d?e.jsx(L,{sx:{bgcolor:"white",height:"100%"},children:e.jsxs(E,{sx:{p:2},children:[e.jsxs(n,{sx:{display:"flex",alignItems:"center",mb:1.5},children:[e.jsx(n,{sx:{bgcolor:j(c.palette.error.main,.12),color:c.palette.error.main,width:32,height:32,borderRadius:"6px",display:"flex",alignItems:"center",justifyContent:"center",mr:1.25},children:e.jsx(ye,{fontSize:"small"})}),e.jsx(o,{variant:"subtitle1",fontWeight:"500",children:"Condições de pagamento"})]}),e.jsxs(o,{variant:"body2",color:"error",children:["Erro ao carregar dados: ",y==null?void 0:y.message]})]})}):e.jsx(L,{sx:{bgcolor:"white",height:"100%"},children:e.jsxs(E,{sx:{display:"flex",flexDirection:"column",height:"100%",p:2,"&:last-child":{pb:2}},children:[e.jsxs(n,{sx:{display:"flex",alignItems:"center",mb:2},children:[e.jsx(n,{sx:{bgcolor:j("#85BB65",.12),color:"#85BB65",width:32,height:32,borderRadius:"6px",display:"flex",alignItems:"center",justifyContent:"center",mr:1.25},children:e.jsx(ye,{fontSize:"small"})}),e.jsx(o,{variant:"subtitle1",fontWeight:"500",children:"Condições de pagamento"})]}),e.jsxs(n,{sx:{display:"flex",alignItems:"center",mt:1,flexGrow:1},children:[e.jsx(n,{sx:{width:80,height:80,mr:2,maxWidth:80,maxHeight:80,display:"flex",alignItems:"center",justifyContent:"center",...ie(x)},children:e.jsx(oe,{children:h?e.jsx(S,{variant:"circular",width:80,height:80}):u.series.length>0&&u.series.every(p=>Number.isFinite(p)&&p>0)?e.jsx(ae,{options:{chart:{width:80,height:80,type:"pie",sparkline:{enabled:!0},animations:{enabled:!1},selection:{enabled:!1},events:{dataPointSelection:void 0,legendClick:void 0,dataPointMouseEnter:void 0,dataPointMouseLeave:void 0,mouseMove:void 0,click:void 0}},colors:u.colors,stroke:{show:!0,width:3,colors:[c.palette.background.paper]},legend:{show:!1},dataLabels:{enabled:!1},tooltip:{enabled:!1},states:{hover:{filter:{type:"none"}},active:{allowMultipleDataPointsSelection:!1,filter:{type:"none"}}},plotOptions:{pie:{expandOnClick:!1,donut:{size:"50%",labels:{show:!1}}}}},series:u.series,type:"pie",height:"100%",width:"100%"}):e.jsx(n,{sx:{display:"flex",justifyContent:"center",alignItems:"center",width:80,height:80},children:e.jsx(o,{variant:"caption",color:"text.secondary",sx:{fontSize:"10px"},children:"Sem dados"})})})}),e.jsx(n,{sx:{flexGrow:1},children:h?e.jsxs(e.Fragment,{children:[e.jsxs(n,{sx:{display:"flex",alignItems:"center",mb:1},children:[e.jsx(n,{sx:{width:10,height:10,borderRadius:"50%",bgcolor:c.palette.divider,mr:1}}),e.jsx(S,{variant:"text",width:"70%"}),e.jsx(S,{variant:"text",width:"20%",sx:{ml:.5}})]}),e.jsxs(n,{sx:{display:"flex",alignItems:"center",mb:1},children:[e.jsx(n,{sx:{width:10,height:10,borderRadius:"50%",bgcolor:c.palette.divider,mr:1}}),e.jsx(S,{variant:"text",width:"70%"}),e.jsx(S,{variant:"text",width:"20%",sx:{ml:.5}})]})]}):u.labels.map((p,i)=>e.jsxs(n,{sx:{display:"flex",alignItems:"center",mb:i<u.labels.length-1?1:0,...x&&{filter:"blur(2px)",pointerEvents:"none"}},children:[e.jsx(n,{sx:{width:10,height:10,borderRadius:"50%",bgcolor:u.colors[i],mr:1}}),e.jsxs(o,{variant:"body2",sx:{flexGrow:1},children:[p,":"]}),e.jsx(o,{variant:"body2",fontWeight:"500",sx:W(x),children:x?T.count:u.series[i].toLocaleStr
1ing("pt-BR")})]},p))})]})]})})},Te="reports.inventoryValueCard.showSaleValue",Bt=({inventoryData:t,baseChartOptions:s,formatCurrency:a,isLoading:x,isBlurred:c})=>{var w,z,$,k,C,v,A,M,K,_,G;const r="#CD853F",[l,g]=V.useState(()=>{try{const R=localStorage.getItem(Te);return R===null?!0:R==="true"}catch{return!0}}),d=V.useCallback(()=>{g(R=>{const F=!R;try{localStorage.setItem(Te,String(F))}catch{}return F})},[]),y=V.useMemo(()=>{if(!x&&(t!=null&&t.timeSeries)){const R=vt(t.timeSeries),F={name:"Custo do estoque",data:R.map(D=>({x:D.x,y:D.y,quantity:D.quantity}))};return l?[F,{name:"Potencial de venda",data:R.map(D=>({x:D.x,y:D.saleValue,quantity:D.quantity}))}]:[F]}return[{name:"Custo do estoque",data:[]}]},[x,t,l]),h=((w=t==null?void 0:t.summary)==null?void 0:w.finalValue)??0,u=((z=t==null?void 0:t.summary)==null?void 0:z.finalSaleValue)??0,p=(($=t==null?void 0:t.summary)==null?void 0:$.finalQuantity)??0,i=u>0,b=i&&u>0?(u-h)/u:0,m=i?`${(b*100).toLocaleString("pt-BR",{minimumFractionDigits:0,maximumFractionDigits:1})}%`:"-";return e.jsx(L,{sx:{bgcolor:"white",height:"100%"},children:e.jsxs(E,{sx:{p:0,"&:last-child":{pb:0},display:"flex",flexDirection:"column",height:"100%"},children:[e.jsxs(n,{sx:{pt:2,px:2},children:[e.jsxs(n,{sx:{display:"flex",alignItems:"center",mb:1.5},children:[e.jsx(n,{sx:{bgcolor:j(r,.12),color:r,width:32,height:32,borderRadius:"6px",display:"flex",alignItems:"center",justifyContent:"center",mr:1.25},children:e.jsx($e,{sx:{fontSize:20}})}),e.jsx(o,{variant:"subtitle1",fontWeight:"500",children:"Valor total do patrimônio (estoque)"})]}),e.jsx(n,{sx:{display:"flex",alignItems:"baseline",mb:.5},children:e.jsx(B,{value:h,variant:"h5",fontWeight:"700",isLoading:x,blur:c,blurText:T.currency,blurStyle:W(c)})}),x?e.jsx(o,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:1.5,ml:.5},children:"..."}):e.jsx(o,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:1.5,ml:.5,...W(c)},children:c?"â¢â¢â¢ itens em estoque":`${p.toLocaleString("pt-BR")} ${p!==1?"itens em estoque":"item em estoque"}`}),l?e.jsxs(I,{container:!0,spacing:1,sx:{mb:1.5},children:[e.jsx(I,{item:!0,xs:6,children:e.jsxs(n,{onClick:d,role:"button",tabIndex:0,onKeyDown:R=>{(R.key==="Enter"||R.key===" ")&&(R.preventDefault(),d())},"aria-label":"Ocultar potencial de venda",sx:{cursor:"pointer",borderRadius:1,mx:-.5,px:.5,"&:hover":{bgcolor:"action.hover"}},children:[e.jsxs(n,{sx:{display:"flex",alignItems:"center",minWidth:0},children:[e.jsx(n,{"aria-hidden":!0,sx:{width:12,height:0,borderTop:"2px dashed",borderColor:r,mr:.75,flexShrink:0}}),e.jsx(o,{variant:"body2",color:"text.secondary",noWrap:!0,children:"Potencial de venda:"})]}),i?e.jsx(o,{variant:"body2",fontWeight:"500",color:"text.primary",sx:W(c),children:c?T.currency:a(u)}):e.jsx(o,{variant:"body2",color:"text.disabled",sx:{fontWeight:500},children:"Defina preços de venda"})]})}),e.jsxs(I,{item:!0,xs:6,children:[e.jsx(o,{variant:"body2",color:"text.secondary",children:"Margem potencial:"}),e.jsx(o,{variant:"body2",fontWeight:"500",color:i?"text.primary":"text.disabled",sx:W(c),children:c?T.percentage:m})]})]}):e.jsx(n,{onClick:d,role:"button",tabIndex:0,onKeyDown:R=>{(R.key==="Enter"||R.key===" ")&&(R.preventDefault(),d())}
1,"aria-label":"Mostrar potencial de venda",sx:{display:"inline-flex",alignItems:"center",cursor:"pointer",mb:1.5,borderRadius:1,mx:-.5,px:.5,"&:hover":{bgcolor:"action.hover"}},children:e.jsx(o,{variant:"body2",sx:{color:r,fontWeight:500},children:"Ver potencial de venda"})})]}),e.jsx(n,{sx:{height:150,mt:"auto",...ie(c)},children:e.jsx(oe,{children:y.length>0&&y[0].data.length>0?e.jsx(ae,{options:{...s,colors:l?[r,r]:[r],stroke:{...s.stroke,width:l?[2,2]:2,curve:"smooth",dashArray:l?[0,4]:0},fill:{type:"solid",opacity:l?[.25,0]:.25},legend:{show:!1},tooltip:{...s.tooltip,enabled:!c,shared:!0,intersect:!1,y:{formatter:(R,F)=>{var U,J,he,P,Y;const D=(Y=(P=(he=(J=(U=F==null?void 0:F.w)==null?void 0:U.config)==null?void 0:J.series)==null?void 0:he[F==null?void 0:F.seriesIndex])==null?void 0:P.data)==null?void 0:Y[F==null?void 0:F.dataPointIndex],N=(D==null?void 0:D.quantity)||0;if((F==null?void 0:F.seriesIndex)===0){const le=`${N.toLocaleString("pt-BR")} ${N!==1?"itens":"item"}`;return`${a(R)} (${le})`}return a(R)}}},chart:{...s.chart,events:{dataPointSelection:c?()=>{}:(C=(k=s.chart)==null?void 0:k.events)==null?void 0:C.dataPointSelection,markerClick:c?()=>{}:(A=(v=s.chart)==null?void 0:v.events)==null?void 0:A.markerClick},toolbar:{show:c?!1:(K=(M=s.chart)==null?void 0:M.toolbar)==null?void 0:K.show},zoom:{enabled:c?!1:(G=(_=s.chart)==null?void 0:_.zoom)==null?void 0:G.enabled}},grid:{...s.grid,padding:{top:0,right:0,bottom:5,left:0}}},series:y,type:"area",height:"100%"}):e.jsx(n,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"100%"},children:e.jsx(o,{variant:"caption",color:"text.secondary",children:"Sem dados para exibir"})})})})]})})},Yt=async t=>{const s=new URLSearchParams({startDate:t.startDate.toISOString(),endDate:t.endD
1ate.toISOString()});return(await me.get(`/reports/category-performance/v2?${s.toString()}`)).data},Xt=t=>pe({queryKey:["categoryPerformance",t],queryFn:()=>Yt(t),enabled:!!t,staleTime:5*60*1e3,retry:2}),Jt=({path:t,maxMobileSegments:s=2})=>{const a=q(),x=He(a.breakpoints.down("sm")),c=O.useMemo(()=>!t||t.length===0?["Sem categoria"]:x&&t.length>s?[t[0],"...",t[t.length-1]]:t,[t,x,s]);return!t||t.length===0?e.jsx(o,{variant:"body2",fontWeight:"500",sx:{color:"text.secondary",fontSize:"13px"},children:"Sem categoria"}):e.jsx(n,{sx:{display:"flex",alignItems:"center",gap:.5,overflow:"hidden",flex:1,minWidth:0},children:c.map((r,l)=>e.jsxs(V.Fragment,{children:[e.jsx(o,{variant:"body2",noWrap:!0,sx:{fontSize:"13px",color:l===c.length-1?"text.primary":"text.secondary",fontWeight:l===c.length-1?500:400,overflow:"hidden",textOverflow:"ellipsis",flex:l===c.length-1?"1 1 auto":"0 1 auto",minWidth:0},children:r}),l<c.length-1&&e.jsx(ue,{sx:{fontSize:14,color:"text.disabled",flexShrink:0}})]},`${r}-${l}`))})},De=t=>t.toLocaleString("pt-BR",{style:"currency",currency:"BRL"}),Zt=t=>`${t.toLocaleString("pt-BR")} ${t===1?"item":"itens"}`,Pe=["#658FFE","#8865FE","#FF6B35","#2AC769","#FFB800","#EC407A","#26C6DA","#AB47BC","#FF7043","#66BB6A"],en=({startDate:t,endDate:s,isLoading:a,isBlurred:x})=>{var k;const c=q(),[r,l]=V.useState(!1),[g,d]=V.useState("subcategory"),y=t&&s?{startDate:t,endDate:s}:void 0,{data:h,isLoading:u,isError:p,error:i}=Xt(y),b=a||u,m=V.useMemo(()=>{if(!h||b)return[];if(g==="parent"){const C=new Map;return h.categories.forEach(v=>{const A=v.categoryPath[0]||v.categoryName;C.has(A)||C.set(A,{categoryName:A,categoryPath:[A],totalAmount:0,totalQuantity:0});const M=C.get(A);M.totalAmount+=v.totalAmount,M.totalQuantity+=v.totalQuantity}),Array.from(C.values()).map(v=>({categoryId:null,categoryName:v.categoryName,categoryPath:v.categoryPath,totalAmount:v.totalAmount,totalOrders:0,totalQuantity:v.totalQuantity})).sort((v,A)=>A.totalAmount-v.totalAmount)}return h.categories},[h,b,g]),w=V.useMemo(()=>{if(!m||m.length===0)return[];const C=m.slice(0,6),v=Math.max(...C.map(M=>M.totalAmount));return(r?m:m.slice(0,4)).map(M=>{const K=m.findIndex(R=>R.categoryId===M.categoryId&&R.categoryName===M.categoryName),_=Pe[K%Pe.length],G=v>0?M.totalAmount/v*100:0;return{...M,color:_,percentage:G}})},[m,r]),z=m&&m.length>4,$=V.useMemo(()=>(h==null?void 0:h.categories.reduce((C,v)=>C+v.totalQuantity,0))??0,[h]);return p?e.jsx(L,{sx:{bgcolor:"white",height:"100%"},children:e.jsxs(E,{sx:{p:2},children:[e.jsxs(n,{sx:{display:"flex",alignItems:"center",mb:1.5},children:[e.jsx(n,{sx:{bgcolor:j(c.palette.error.main,.12),color:c.palette.error.main,width:32,height:32,borderRadius:"6px",display:"flex",alignItems:"center",justifyContent:"center",mr:1.25},children:e.jsx(ge,{size:18})}),e.jsx(o,{variant:"subtitle1",fontWeight:"500",children:"Performance por categoria"})]}),e.jsxs(o,{variant:"body2",color:"error",children:["Erro ao carregar dados: ",i==null?void 0:i.message]})]})}):e.jsx(L,{sx:{bgcolor:"white",height:"100%"},children:e.jsxs(E,{sx:{display:"flex",flexDirection:"column",height:"100%",p:2,"&:last-child":{pb:2}},children:[e.jsxs(n,{sx:{display:"flex",alignItems:"center",mb:1.5},children:[e.jsx(n,{sx:{bgcolor:j("#658FFE",.12),color:"#658FFE",width:32,height:32,borderRadius:"6px",display:"flex",alignItems:"center",justifyContent:"center",mr:1.25},children:e.jsx(ge,{fontSize:"small"})}),e.jsx(o,{variant:"subtitle1",fontWeight:"500",children:"Performance por categoria"})]}),!b&&h&&h.categories.length>0&&e.jsx(n,{sx:{mb:2},children:e.jsxs(Qe,{value:g,exclusive:!0,onChange:(C,v)=>{v!==null&&(d(v),l(!1))},size:"small",fullWidth:!0,sx:{"& .MuiToggleButton-root":{fontSize:"11px",py:.5,textTransform:"none",...x&&{filter:"blur(2px)",pointerEvents:"none"}}},children:[e.jsx(Se,{value:"parent",children:"Por categoria"}),e.jsx(Se,{value:"subcategory",children:"Por subcategoria"})]})}),e.jsxs(n,{sx:{mb:2},children:[e.jsxs(n,{sx:{display:"flex",justifyContent:"space-between",mb:1},children:[e.jsx(o,{variant:"body2",color:"text.secondary",children:"Itens vendidos:"}),b?e.jsx(S,{variant:"text",width:60}):e.jsx(o,{variant:"body2",fontWeight:"500",sx:W(x),children:x?T.count:$.toLocaleStr
1ing("pt-BR")})]}),e.jsxs(n,{sx:{display:"flex",justifyContent:"space-between",mb:1},children:[e.jsx(o,{variant:"body2",color:"text.secondary",children:"Valor total:"}),b?e.jsx(S,{variant:"text",width:80}):e.jsx(o,{variant:"body2",fontWeight:"500",sx:W(x),children:x?T.currency:De((h==null?void 0:h.totalAmount)||0)})]}),e.jsxs(n,{sx:{display:"flex",justifyContent:"space-between"},children:[e.jsx(o,{variant:"body2",color:"text.secondary",children:"Pedidos no perÃodo:"}),b?e.jsx(S,{variant:"text",width:60}):e.jsx(o,{variant:"body2",fontWeight:"500",sx:W(x),children:x?T.count:((k=h==null?void 0:h.totalOrders)==null?void 0:k.toLocaleString("pt-BR"))||"0"})]})]}),!b&&w.length>0&&e.jsx(o,{variant:"caption",color:"text.secondary",sx:{display:"block",mb:1,fontSize:"11px"},children:"O tamanho da barra mostra o valor vendido"}),e.jsxs(n,{sx:{flexGrow:1,...ie(x)},children:[b?e.jsx(n,{sx:{display:"flex",flexDirection:"column",gap:1.5},children:[...Array(5)].map((C,v)=>e.jsx(S,{variant:"rectangular",width:"100%",height:40},v))}):w.length>0?e.jsx(n,{sx:{display:"flex",flexDirection:"column",gap:1.5},children:w.map((C,v)=>e.jsxs(n,{sx:{position:"relative",minHeight:52,bgcolor:j(C.color,.05),borderRadius:1,overflow:"hidden",display:"flex",alignItems:"center",border:`1px solid ${j(C.color,.2)}`},children:[e.jsx(n,{sx:{position:"absolute",left:0,top:0,height:"100%",width:`${C.percentage}%`,bgcolor:j(C.color,.2),borderRadius:"4px",transition:"width 0.6s ease-in-out"}}),e.jsxs(n,{sx:{position:"relative",zIndex:1,display:"flex",alignItems:"center",justifyContent:"space-between",width:"100%",px:1.5,py:.75,gap:1},children:[e.jsxs(n,{sx:{display:"flex",alignItems:"center",flex:1,minWidth:0,overflow:"hidden"},children:[e.jsx(n,{sx:{mr:1,display:"flex",alignItems:"center",bgcolor:C.color,borderRadius:"4px",width:20,height:20,justifyContent:"center",flexShrink:0},children:e.jsx(ge,{size:12,color:"white"})}),e.jsxs(n,{sx:{minWidth:0,flex:1},children:[e.jsx(Jt,{path:C.categoryPath}),e.jsx(o,{variant:"caption",color:"text.secondary",sx:{display:"block",fontSize:"11px",lineHeight:1.4,...W(x)},children:x?T.number:Zt(C.totalQuantity)})]})]}),e.jsx(o,{variant:"body2",fontWeight:"600",sx:{color:C.color,fontSize:"13px",flexShrink:0,whiteSpace:"nowrap",...W(x)},children:x?T.currency:De(C.totalAmount)})]})]},`${C.categoryId||"sem-categoria"}-${C.categoryName}-${v}`))}):e.jsx(n,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:200},children:e.jsx(o,{variant:"body2",color:"text.secondary",children:"Nenhum dado disponÃvel"})}),!b&&z&&e.jsx(n,{sx:{mt:2,textAlign:"center"},children:e.jsx(ce,{variant:"text",size:"small",fullWidth:!0,disableRipple:!0,sx:{color:c.palette.primary.main,fontSize:"12px",textTransform:"none",minHeight:"auto",py:.5,px:1,gap:.5,...x&&{filter:"blur(2px)",pointerEvents:"none"}},onClick:()=>l(!r),children:r?e.jsxs(e.Fragment,{children:["Ver menos",e.jsx(_e,{fontSize:"small"})]}):e.jsxs(e.Fragment,{children:["Ver todas (",(m==null?void 0:m.length)||0,")",e.
1jsx(Oe,{fontSize:"small"})]})})})]})]})})},tn=[{label:"Fluxo de caixa",description:"Quanto entrou e saiu no dia, no mês ou no perÃodo que escolher",icon:e.jsx(rt,{size:20}),route:"/reports/fluxo-caixa"},{label:"Vendas por itens",description:"Todos os itens vendidos com categoria, cliente e valores",icon:e.jsx(st,{size:20}),route:"/reports/sales-items"},{label:"Resumo diario de vendas",description:"Pedidos agrupados por dia com subtotal, descontos, frete e total",icon:e.jsx(it,{size:20}),route:"/reports/daily-sales"},{label:"Estoque por item",description:"Custos, preco de venda e quantidade em estoque de cada item",icon:e.jsx($e,{sx:{fontSize:20}}),route:"/reports/stock-items"}],nn=()=>{const t=de(),[s]=xe(),a=q();return e.jsx(L,{sx:{bgcolor:"white"},children:e.jsxs(E,{children:[e.jsxs(n,{sx:{display:"flex",alignItems:"center",mb:1.5},children:[e.jsx(n,{sx:{bgcolor:j(a.palette.primary.main,.12),color:a.palette.primary.main,width:32,height:32,borderRadius:"6px",display:"flex",alignItems:"center",justifyContent:"center",mr:1.25,flexShrink:0},children:e.jsx(nt,{size:18})}),e.jsx(o,{variant:"subtitle1",fontWeight:"500",children:"Outros relatorios"})]}),e.jsx(Ke,{disablePadding:!0,children:tn.map(x=>e.jsxs(Ge,{onClick:()=>{const c=s.toString();t(c?`${x.route}?${c}`:x.route)},sx:{borderRadius:1,mx:-1,"&:not(:last-child)":{mb:.5}},children:[e.jsx(Ue,{sx:{minWidth:36,color:a.palette.text.secondary},children:x.icon}),e.jsx(Be,{primary:x.label,secondary:x.description,primaryTypographyProps:{variant:"body2",fontWeight:500,color:"text.primary"},secondaryTypographyProps:{variant:"caption",color:"text.secondary",sx:{mt:.25}}}),e.jsx(ue,{sx:{color:a.palette.text.disabled,fontSize:20}})]},x.route))})]})})},rn=async t=>{const s=t.startDate.toISOString(),a=t.endDate.toISOString(),c=(await me.get(`/reports/inventory-value?startDate=${s}&endDate=${a}`)).data;if(!c||typeof c!="object")throw new Error("Invalid inventory value response data format");if(c.timeSeries&&Array.isArray(c.timeSeries)&&(c.timeSeries=c.timeSeries.filter(r=>{if(!r||typeof r!="object")return console.warn("Invalid time series item:",r),!1;const{label:l,totalValue:g,totalSaleValue:d,totalQuantity:y}=r;if(typeof l!="string"||l.trim()==="")return console.warn("Invalid label in time series:",l),!1;const h=typeof g=="number"?g:parseFloat(g);if(!Number.isFinite(h)||h<0)return console.warn("Invalid totalValue in time series:",g),!1;const u=typeof d=="number"?d:parseFloat(d),p=Number.isFinite(u)&&u>=0?u:0,i=typeof y=="number"?y:parseFloat(y);return!Number.isFinite(i)||i<0?(console.warn("Invalid totalQuantity in time series:",y),!1):(r.label=l.trim(),r.totalValue=h,r.totalSaleValue=p,r.totalQuantity=i,!0)})),c.summary&&typeof c.summary=="object"){const r=c.summary;["finalValue","finalSaleValue","finalQuantity","totalMovements"].forEach(g=>{if(g in r){const d=r[g],y=typeof d=="number"?d:parseFloat(d);!Number.isFinite(y)||y<0?(console.warn(`Invalid summary value for ${g}:`,d),r[g]=0):r[g]=y}})}return c},sn=t=>pe({queryKey:["inventoryValue",t],queryFn:()=>rn(t),enabled:!!t,staleTime:5*60*1e3,retry:2}),fe=t=>t.toLocaleString("pt-BR",{style:"currency",currency:"BRL"}),X={profit:"#2AC769",revenue:"#658FFE",sales:"#8865FE",online:"#8FADFF",presencial:"#FFA677",visitors:"#2563EB"},Rn=()=>{const t=de(),s=q(),[a,x]=xe(),c=()=>a.get("dateRangeOption")||"today",r=()=>{const P=a.get("startDate"),Y=a.get("endDate");return P&&Y?{startDate:Fe(P),endDate:Fe(Y)}:{startDate:xt(ht(new Date,6)),endDate:mt(new Date)}},[l,g]=O.useState(c()),[d,y]=O.useState(r()),h=(P,Y)=>{const le={dateRangeOption:P};P==="custom"&&(le.startDate=Y.startDate.toISOString(),le.endDate=Y.endDate.toISOString()),x(le,{replace:!0})},u=P=>{g(P),h(P,d)},p=P=>{y(P),h(l,P)},i=O.useMemo(()=>ut(l,d),[l,d]),{data:b,isLoading:m,isError:w,error:z}=ot(i),{data:$,isLoading:k}=at(),C=lt($),v=!Ce($,"pro"),A=Ce($,"pro"),{data:M,isLoading:K}=sn(i),{data:_,isLoading:G}=ct(A?i:void 0),R=m||k,F=O.useMemo(()=>({chart:{type:"area",height:200,toolbar:{show:!1},zoom:{enabled:!1},background:"transparent",sparkline:{enabled:!0},animations:{enabled:!0,speed:300,dynamicAnimation:{speed:300}}},grid:{show:!1,borderColor:s.palette.divider,strokeDashArray:2,xaxis:{lines:{show:!1}},yaxis:{lines:{show:!1}},padding:{top:0,right:0,bottom:5,left:0}},dataLabels:{enabled:!1},stroke:{curve:"smooth",width:2.5},fill:{type:"gradient",gradient:{shadeIntensity:1,opacityFrom:.5,opacityTo:.1,stops:[0,90,100]}},legend:{show:!1},tooltip:{enabled:!0,theme:s.palette.mode,x:{},marker:{show:!1},fixed:{enabled:!0,position:"topRight",offsetX:0,offsetY:0}}}),[s]);if(w&&!b)return e.jsxs(n,{sx:{display:"flex",justifyContent:"center",alignItems:"center",height:"calc(100vh - 64px)",flexDirection:"column",p:3},children:[e.jsx(o,{variant:"h6",color:"error",gutterBottom:!0,children:"Erro ao carregar os dados dos relatórios."}),e.jsx(o,{color:"error",sx:{textAlign:"center"},children:(z==null?void 0:z.message)||"Não foi possÃvel buscar os dados. Tente novamente mais tarde."})]});const D=b==null?void 0:b.kpis,N=b==null?void 0:b.ordersVolumeChart,U=b==null?void 0:b.revenueChart,J=b==null?void 0:b.profitChart,he=b==null?void 0:b.salesDistribution;return e.jsxs(n,{sx:{width:"100%",display:"flex",flexDirection:"column",flexGrow:1,bgcolor:s.palette.background.default,maxWidth:"100%",overflowX:"hidden"},children:[e.jsx(dt,{title:"Painel de relatórios",navigateBack:()=>t(-1)}),e.jsx(n,{sx:{pt:3,bgcolor:s.palette.background.default,zIndex:s.zIndex.appBar-1},children:e.jsx(pt,{selectedRange:l,onRangeChange:u,customDateRange:d,onCustomDateRangeChange:p})}),e.jsxs(n,{sx:{p:{xs:2,sm:2.5,md:3}},children:[!["pro","black"].includes(C)&&!R&&b&&e.jsx(n,{sx:{mb:2.5},children:e.jsx(It,{title:"Desbloqueie relatórios completos",body:e.jsx(e.Fragment,{children:"Faça o upgrade para o plano PRO para ter acesso detalhado à s métricas de performance, incluindo lucratividade, visitas na loja, ticket médio, produtos mais vendidos, patrimônio e mais."}),buttonText:"Assinar plano PRO",buttonLink:"/profile/paywall?initialPlan=pro",trigger:"reports",paywallSource:"reports_page"})}),e.jsxs(I,{container:!0,spacing:2.5,sx:{mb:2.5},children:[e.jsx(I,{item:!0,xs:12,md:12,children:e.jsx(wt,{kpis:_==null?void 0:_.kpis,visitorsChart:_==null?void 0:_.uniqueVisitorsChart,baseChartOptions:F,customColors:X,isLoading:G,startDate:i==null?void 0:i.startDate,
1showSeeMore:!0,isBlurred:v})}),e.jsx(I,{item:!0,xs:12,md:12,children:e.jsx(Dt,{kpis:D,ordersVolumeChart:N&&{...N,series:N.series.map(P=>({...P,color:X.sales}))},baseChartOptions:F,customColors:X,isLoading:m})}),e.jsx(I,{item:!0,xs:12,md:6,children:e.jsx(Pt,{kpis:D,revenueChart:U&&{...U,series:U.series.map(P=>({...P,color:X.revenue}))},baseChartOptions:F,customColors:X,formatCurrency:fe,isLoading:m})}),e.jsx(I,{item:!0,xs:12,md:6,children:e.jsx(Mt,{kpis:D,profitChart:J&&{...J,series:J.series.map(P=>({...P,color:X.profit}))},baseChartOptions:F,customColors:X,formatCurrency:fe,isLoading:m,isBlurred:v})}),e.jsx(I,{item:!0,xs:12,md:6,children:e.jsx(Bt,{isBlurred:v,inventoryData:M,baseChartOptions:F,formatCurrency:fe,isLoading:K})}),e.jsx(I,{item:!0,xs:12,md:6,children:e.jsx(en,{startDate:i==null?void 0:i.startDate,endDate:i==null?void 0:i.endDate,isLoading:m,isBlurred:v})})]}),e.jsxs(I,{container:!0,spacing:2.5,sx:{mb:2.5},children:[e.jsx(I,{item:!0,xs:12,md:6,lg:4,children:e.jsx(At,{kpis:D,isLoading:m,isBlurred:v})}),e.jsx(I,{item:!0,xs:12,md:6,lg:4,children:e.jsx(qt,{kpis:D,isLoading:m,isBlurred:v})}),e.jsx(I,{item:!0,xs:12,md:12,lg:4,children:e.jsx(_t,{salesDistributionData:he,isLoading:m,customColors:X,isBlurred:v})})]}),e.jsxs(I,{container:!0,spacing:2.5,sx:{mb:2.5},children:[e.jsx(I,{item:!0,xs:12,lg:6,children:e.jsx(Qt,{startDate:i==null?void 0:i.startDate,endDate:i==null?void 0:i.endDate,isLoading:m,isBlurred:v})}),e.jsx(I,{item:!0,xs:12,lg:6,children:e.jsx(Ut,{startDate:i==null?void 0:i.startDate,endDate:i==null?void 0:i.endDate,isLoading:m,isBlurred:v})})]}),e.jsxs(I,{container:!0,spacing:2.5,sx:{mb:2.5},children:[e.jsx(I,{item:!0,xs:12,lg:6,children:e.jsx(L,{sx:{bgcolor:"white"},children:e.jsx(E,{children:e.jsx(Wt,{startDate:i==null?void 0:i.startDate,endDate:i==null?void 0:i.endDate,isBlurred:v})})})}),e.jsx(I,{item:!0,xs:12,lg:6,children:e.jsx(L,{sx:{bgcolor:"white"},children:e.jsx(E,{children:e.jsx(zt,{startDate:i==null?void 0:i.startDate,endDate:i==null?void 0:i.endDate,isBlurred:v})})})})]}),e.jsx(I,{container:!0,spacing:2.5,children:e.jsx(I,{item:!0,xs:12,children:e.jsx(L,{sx:{bgcolor:"white"},children:e.jsx(E,{children:e.jsx(Tt,{startDate:i==null?void 0:i.startDate,endDate:i==null?void 0:i.endDate,isBlurred:v})})})})}),e.jsx(I,{container:!0,spacing:2.5,sx:{mt:0},children:e.jsx(I,{item:!0,xs:12,children:e.jsx(L,{sx:{bgcolor:"white"},children:e.jsx(E,{children:e.jsx(yt,{startDate:i==null?void 0:i.startDate,endDate:i==null?void 0:i.endDate,isBlurred:v})})})})}),e.jsx(I,{container:!0,spacing:2.5,sx:{mt:0},children:e.jsx(I,{item:!0,xs:12,children:e.jsx(nn,{})})})]})]})};export{Rn 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.