1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[704],{65069:function(e,t,a){var r=a(60115),o=a(94233),n=a(54435),s=a(82389),i=a(51873),l=a(86889),d=a(6659),c=a(42464);t.Z=function(){let{user:e}=(0,l.aF)(),[t,a]=(0,c.useState)(!1),u=async()=>{a(!0);try{var t;let a=null==e?void 0:null===(t=e.unsafeMetadata)||void 0===t?void 0:t.location;(0,s.Am)({title:"Redirecting to eBay...",description:"Please complete the eBay authorization process.",variant:"default"}),window.location.href=(0,i.mh)(a)}catch(e){(0,s.Am)({title:"Error",description:"Unable to connect to eBay. Please try again later.",variant:"destructive"})}finally{a(!1)}};return(0,r.jsxs)(n.Tooltip,{children:[(0,r.jsx)(n.TooltipTrigger,{asChild:!0,children:(0,r.jsx)(o.z,{size:"icon",variant:"ghost",className:"h-7 w-7 text-gray-500 hover:text-gray-700 hover:bg-gray-100 dark:text-gray-400 dark:hover:text-gray-200 dark:hover:bg-gray-700",onClick:u,disabled:t,children:t?(0,r.jsx)(d.Z,{className:"w-4 h-4 animate-spin"}):(0,r.jsx)(d.Z,{className:"w-4 h-4"})})}),(0,r.jsx)(n.TooltipContent,{children:(0,r.jsx)("p",{className:"text-xs",children:"Connect to eBay store"})})]})}},10704:function(e,t,a){a.r(t),a.d(t,{default:function(){return M}});var r=a(60115),o=a(42464),n=a(36019),s=a(24551),i=a(34922),l=a(94233),d=a(54435),c=a(65112),u=a(6659),g=a(34307),x=a(5188),h=a(63450),p=a(51554),m=a(90783),b=a(89887),f=a(69826),y=a(49195),v=a(5087),w=a(91269),k=a(82675),C=a(60036),j=a(86889),N=a(51873),S=a(36136),D=a(54053),E=a(13916),T=a(3019),F=a(65069),B=function(e){let{formatter:t,isLargeScreen:a,currentYear:o}=e,n=Array.from({length:12},(e,t)=>new Date(o,new Date().getMonth()-t,1).toLocaleString("en-US",{month:"short",year:"numeric"}));return(0,r.jsxs)("section",{className:"bg-gradient-to-br from-[#F8F9FB] via-[#F9FAFB] to-[#EEF2FF]/50 dark:bg-[#1E1E2E] max-h-[400px] p-6 rounded-lg relative",children:[(0,r.jsxs)("div",{className:"w-full flex items-center justify-between gap-4",children:[(0,r.jsxs)("div",{className:"flex items-center gap-4",children:[(0,r.jsx)(l.z,{variant:"outline",className:"px-2",disabled:!0,children:(0,r.jsx)(g.Z,{className:"w-6 h-6 opacity-50"})}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("h2",{className:"text-base font-semibold text-brand-sub",children:"Profit & Expense Chart"}),(0,r.jsx)("div",{className:"ml-2 backdrop-blur-sm bg-white/60 dark:bg-gray-800/60 px-2 py-0.5 rounded border border-dashed border-gray-400 dark:border-gray-500",children:(0,r.jsx)("span",{className:"text-[9px] font-medium text-gray-600 dark:text-gray-300 tracking-wide uppercase",children:"Mock Demo"})}),(0,r.jsxs)(d.Tooltip,{children:[(0,r.jsx)(d.TooltipTrigger,{children:(0,r.jsx)(x.Z,{className:"w-4 h-4 text-brand-secondary cursor-pointer"})}),(0,r.jsxs)(d.TooltipContent,{className:"max-w-xs text-sm bg-white text-gray-900 border border-gray-200 shadow-md rounded-md p-3 dark:bg-[#1E1E2E] dark:text-gray-200 dark:border-gray-600",children:[(0,r.jsx)("p",{className:"font-semibold mb-1",children:"Profit & Expense Chart"}),(0,r.jsx)("p",{className:"text-xs text-brand-secondary",children:"Connect your eBay store to track fees, shipping costs, refunds, and taxes with daily and monthly insights."})]})]})]})]}),(0,r.jsxs)("div",{className:"flex items-center gap-3",children:[(0,r.jsxs)(l.z,{className:"px-2 text-xs font-medium",disabled:!0,variant:"outline",children:[(0,r.jsx)(m.Z,{className:"w-4 h-4 text-brand-secondary"}),"Show Expenses"]}),(0,r.jsx)(l.z,{variant:"outline",size:"icon",disabled:!0,children:(0,r.jsx)(u.Z,{size:16})})]})]}),(0,r.jsxs)("div",{className:"relative min-h-[300px] max-h-[350px] h-[calc(100%-60px)] w-full mt-2",children:[(0,r.jsx)("div",{className:"absolute inset-0 opacity-50 pointer-events-none",children:(0,r.jsx)(i.$Q,{data:{labels:n,datasets:[{label:"Profit (Demo Preview)",data:[1845.3,1256.8,2104.5,1678.9,895.6,1542.3,1986.75,1234.2,912.85,1867.4,2249.95,1534.6],backgroundColor:"#D1D5DB",borderColor:"transparent",borderWidth:0,borderRadius:8,barThickness:a?60:30,hoverBackgroundColor:"#D1D5DB",hoverBorderColor:"transparent"}]},options:{plugins:{tooltip:{enabled:!1}
1,legend:{display:!0}},responsive:!0,maintainAspectRatio:!1,onClick:()=>{},scales:{x:{grid:{display:!1}},y:{beginAtZero:!0,ticks:{callback:e=>t.format(e)}}}}})}),(0,r.jsx)("div",{className:"absolute top-1/2 left-1/2 transform -translate-x-1/2 -translate-y-1/2 z-10",children:(0,r.jsxs)("div",{className:"backdrop-blur-md bg-white/40 dark:bg-[#1E1E2E]/40 rounded-xl border border-gray-300/30 dark:border-gray-600/30 p-6 max-w-[280px] shadow-sm relative",children:[(0,r.jsx)("div",{className:"absolute top-3 right-3",children:(0,r.jsx)(F.Z,{})}),(0,r.jsxs)("div",{className:"flex flex-col items-center text-center gap-3",children:[(0,r.jsx)(g.Z,{className:"w-8 h-8 text-gray-400 dark:text-gray-500"}),(0,r.jsxs)("div",{children:[(0,r.jsx)("h3",{className:"text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"Profit & Expense Tracking"}),(0,r.jsx)("p",{className:"text-[10px] text-gray-500 dark:text-gray-500 leading-relaxed",children:"Connect to eBay store to track fees, shipping costs, refunds, and taxes with daily and monthly insights."})]})]})]})})]})]})},I=a(75744);s.kL.register(s.ZL,s.jn,s.od,s.uw,s.f$,s.u,s.De,s.Gu),a.e(645).then(a.bind(a,20645)).then(e=>{s.kL.register(e.default)});let O=[],z=!1;s.kL.register({id:"lockIconPlugin",afterDraw:e=>{let t=e.ctx,a=e.getDatasetMeta(0);a&&a.data&&a.data.forEach((e,a)=>{var r;if((null===(r=O[a])||void 0===r?void 0:r.isFiller)&&z){let{x:a,y:r,base:o,width:n}=e,s=Math.abs(r-o);t.save();let i=Math.min(.6*Math.min(.5*n,20),14);t.fillStyle="rgba(107, 114, 128, 0.7)",t.strokeStyle="rgba(107, 114, 128, 0.9)",t.lineWidth=1.5;let l=.6*i,d=.7*i,c=(r<o?r+s/2:o+s/2)-d/2+.15*i;t.beginPath(),t.roundRect(a-l/2,c,l,d,2),t.fill(),t.stroke(),t.beginPath(),t.arc(a,c,.5*l,Math.PI,0,!1),t.stroke(),t.restore()}})}});let R=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"rgba(156, 163, 175, 0.25)",t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"rgba(243, 244, 246, 0.6)",a=document.createElement("canvas"),r=a.getContext("2d");return r?(a.width=8,a.height=8,r.fillStyle=t,r.fillRect(0,0,8,8),r.strokeStyle=e,r.lineWidth=1.5,r.beginPath(),r.moveTo(0,8),r.lineTo(8,0),r.stroke(),r.beginPath(),r.moveTo(-4,4),r.lineTo(4,-4),r.stroke(),r.beginPath(),r.moveTo(4,12),r.lineTo(12,4),r.stroke(),r.createPattern(a,"repeat")||t):t};var M=function(){var e,t,a;let{user:s}=(0,j.aF)(),{token:F,activeAccountId:M,activeAccount:P}=(0,C.V)(),Z=(0,o.useRef)(null),A=(0,o.useRef)(null),L=(0,o.useRef)(null),G=(0,o.useRef)(null),[U,H]=(0,o.useState)(!1);(0,o.useEffect)(()=>{G.current=R(),H(!0)},[]);let[W,Y]=(0,o.useState)("monthly"),[_,V]=(0,o.useState)([]),[q,$]=(0,o.useState)(null),[Q,X]=(0,o.useState)(!0),[J,K]=(0,o.useState)(3),[ee,et]=(0,o.useState)({}),[ea,er]=(0,o.useState)({}),[eo,en]=(0,o.useState)(null),[es,ei]=(0,o.useState)(!1),el=(null==s?void 0:null===(e=s.publicMetadata)||void 0===e?void 0:e.userPlan)||"Freemium",ed=(0,N.nn)(el,"Pro"),ec="EBAY_".concat((null==s?void 0:null===(t=s.unsafeMetadata)||void 0===t?void 0:t.location)||"US"),eu=(null==s?void 0:null===(a=s.unsafeMetadata)||void 0===a?void 0:a.location)||"US",eg=N.LOCATIONS.find(e=>e.value===eu)||N.LOCATIONS[0],ex=eg.currency,eh=eg.locales[0]||"en-US",[ep,em]=(0,o.useState)(new Intl.NumberFormat(eh,{style:"currency",currency:ex,minimumFractionDigits:2,maximumFractionDigits:2})),{expenses:eb}=(0,S.t)(),[ef,ey]=(0,o.useState)(!1),ev=(0,N.nn)(el,"Starter"),ew=(0,I.t)(),[ek,eC]=(0,o.useState)(!ev),[ej,eN]=(0,o.useState)(!ev),[eS,eD]=(0,o.useState)({}),[eE,eT]=(0,o.useState)(!1),[eF,eB]=(0,o.useState)(!1),[eI,eO]=(0,o.useState)(!1),ez=new Date().getFullYear(),[eR,eM]=(0,o.useState)(ez);(0,o.useEffect)(()=>{let e=localStorage.getItem("showExternalExpenses");if(null!==e&&ey("true"===e),ev){eC(!1);return}let t=localStorage.getItem("showCOGS");null!==t?eC("true"===t):eC(!0)},[ev]),(0,o.useEffect)(()=>{ev||localStorage.setItem("showCOGS",ek.toString())},[ek,ev]),(0,o.useEffect)(()=>{if(ev){eN(!1);return}let e=localStorage.getItem("showInventory");null!==e&&eN("true"===e)},[ev]),(0,o.useEffect)(()=>{ev||localStorage.setItem("showInventory",ej.toString())},[ej,ev]),(0,o.useEffect)(()=>{let e;let t=!1,a=()=>{(null==s?void 0:s.id)&&M&&!ev&&!t&&(clearTimeout(e),e=setTimeout(async()=>{t=!0;try{let e=new Date,t=new Date(e.getFullYear()-1,e.getMonth(),1),a=await eq(t,e);eD(a);let r=(0,E.Cw)("inventoryData",s.id,M);await (0,D.sx)(r,a)}finally{t=!1}},500))};return window.addEventListener("cogs-updated",a),()=>{window.removeEventListener("cogs-updated",a),clearTimeout(e)}},[null==s?void 0:s.id,M,ev]),(0,o.useEffect)(()=>{let e;let t=!1,a=()=>{(null==s?void 0:s.id)&&M&&!ev&&!t&&(clearTimeout(e),e=setTimeout(async()=>{t=!0;try{let e=new Date,t=new Date(e.getFullYear()-1,e.getMonth(),1),a=await eq(t,e);eD(a);let r=(0,E.Cw)("inventoryData",s.id,M);await (0,D.sx)(r,a)}finally{t=!1}},500))};return window.addEventListener("status-updated",a),()=>{window.removeEventListener("status-updated",a),clearTimeout(e)}},[null==s?void 0:s.id,M,ev]),(0,o.useEffect)(()=>{localStorage.setItem("showExternalExpenses",String(ef))},[ef]),(0,o.useEffect)(()=>{let e=ev?1:ed?3:12;if(ed||ev){let t=localStorage.getItem("loadedMonths");if(t){let a=parseInt(t,10),r=Math.min(a,e);K(r),r!==a&&localStorage.setItem("loadedMonths",r.toString())}else K(e),localStorage.setItem("loadedMonths",e.toString())}else K(12),localStorage.setItem("loadedMonths","12")},[ed,ev]),(0,o.useEffect)(()=>{em(new Intl.NumberFormat(eh,{style:"currency",currency:ex,minimumFractionDigits:2,maximumFractionDigits:2}))},[ex,eh]);let eP=Array.from({length:12},(e,t)=>{let a=new Date(eR,new Date().getMonth()-t,1);return{key:"".concat(a.getFullYear(),"-").concat(String(a.getMonth()+1).padStart(2,"0")),label:a.toLocaleStr
1ing(eh,{month:"short",year:"numeric"})}}),eZ=eP.reduce((e,t)=>{let{key:a}=t;return e[a]=ee[a]||{profit:0,expenses:0,cogs:0},e},{}),eA=eP.map((e,t)=>({...e,isLoaded:t<J,isFiller:t>=J})),eL=eA.map(e=>{let{label:t}=e;return t}),eG=Math.max(50,...Object.values(eZ).map(e=>Math.abs(e.profit))),eU=[.45,.72,.38,.85,.55,.68,.42,.78,.5,.65,.35,.8],eH=eA.map((e,t)=>{let{key:a,isLoaded:r,isFiller:o}=e;return r?eZ[a].profit:o?(eU[t%12]||.5)*eG:0}),eW=(0,o.useCallback)(()=>{if("monthly"!==W||!Z.current||!L.current){V([]);return}let e=Z.current,t=eH.map((e,t)=>{var a;return{value:e,index:t,isVisible:!(null===(a=eA[t])||void 0===a?void 0:a.isFiller)&&0!==e}}).filter(e=>e.isVisible),a=t.length>0?t.reduce((e,t)=>t.value>e.value?t:e).index:-1;V(eH.map((t,r)=>{var o;let n=e.getDatasetMeta(0);if(!n.data[r])return{x:0,y:0,value:0,visible:!1,isHighest:!1};let{x:s}=n.data[r],i=e.height-5,l=!(null===(o=eA[r])||void 0===o?void 0:o.isFiller)&&0!==t;return{x:s,y:i,value:t,visible:l,isHighest:r===a&&t>0}}))},[W,eH,eA]);(0,o.useEffect)(()=>{let e=setTimeout(()=>{eW()},100);return()=>clearTimeout(e)},[eW,ee,J]),(0,o.useEffect)(()=>{let e=()=>{eW()};return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[eW]);let eY=(e,t)=>{let a={};return e.forEach(e=>{var t,r,o;let n=new Date(e.transactionDate),s="".concat(n.getFullYear(),"-").concat(String(n.getMonth()+1).padStart(2,"0"));a[s]||(a[s]={profit:0,orderTotal:0,refunds:0,fees:0,taxes:0,shippingCost:0,credits:0,nonSaleCharges:0,cogs:0,currency:e.amount.currency||"USD"});let i=Number(parseFloat((null===(t=e.amount)||void 0===t?void 0:t.value)||"0").toFixed(2)),l=Number(parseFloat((null===(r=e.totalFeeAmount)||void 0===r?void 0:r.value)||"0").toFixed(2)),d=Number(parseFloat((null===(o=e.ebayCollectedTaxAmount)||void 0===o?void 0:o.value)||"0").toFixed(2));switch(e.transactionType){case"SALE":a[s].orderTotal+=i,a[s].profit+=i-l-d,a[s].fees+=l,a[s].taxes+=d;break;case"REFUND":a[s].refunds+=i,a[s].profit-=i,a[s].fees+=l,a[s].taxes+=d;break;case"SHIPPING_LABEL":"DEBIT"===e.bookingEntry?(a[s].shippingCost+=i,a[s].profit-=i):"CREDIT"===e.bookingEntry&&(a[s].credits+=i,a[s].profit+=i);break;case"NON_SALE_CHARGE":a[s].nonSaleCharges+=Math.abs(i),a[s].profit-=Math.abs(i);break;default:console.warn("Unhandled transaction type: ".concat(e.transactionType))}}),t&&Object.keys(t).forEach(e=>{a[e]||(a[e]={profit:0,orderTotal:0,refunds:0,fees:0,taxes:0,shippingCost:0,credits:0,nonSaleCharges:0,cogs:0,currency:"USD"}),a[e].cogs=t[e],a[e].profit-=t[e]}),Object.keys(a).forEach(e=>{let t=a[e];t.profit=parseFloat(t.profit.toFixed(2))}),a},e_=(e=>{let t={};return e.forEach(e=>{let a=new Date(e.date),r="".concat(a.getFullYear(),"-").concat(String(a.getMonth()+1).padStart(2,"0"));t[r]||(t[r]=0),t[r]+=Number(parseFloat(e.amount||"0").toFixed(2))}),t})(eb),eV=async(e,t,a)=>{if(!F||!(null==s?void 0:s.id)||!M)return{};try{let r=(null==a?void 0:a.location)||"US",o=(null==a?void 0:a.marketplace)||"EBAY_US",n=[],s=0,i=!0;for(;i;){let a=await fetch("/api/get-orders",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:F,location:r,marketplace_id:o,accountId:M,limit:200,offset:s})});if(!a.ok)break;let l=(await a.json()).orders||[];if(0===l.length){i=!1;break}let d=!0;if(l.forEach(a=>{let r=new Date(a.dateSold||a.creationDate);r>=e&&r<=t?(n.push(a),d=!1):r>t&&(d=!1)}),d){i=!1;break}l.length<200?i=!1:(s+=200)>=2e3&&(i=!1)}let l={},d=0,c=0;return n.forEach(e=>{let t=new Date(e.dateSold||e.creationDate),a="".concat(t.getFullYear(),"-").concat(String(t.getMonth()+1).padStart(2,"0")),r=String(t.getDate()).padStart(2,"0"),o=parseFloat(e.costOfGoodsSold||"0");o>0&&(d++,c+=o,l[a]||(l[a]={monthly:0,daily:{}}),l[a].daily[r]||(l[a].daily[r]=0),l[a].monthly+=o,l[a].daily[r]+=o)}),l}catch(e){return console.error("Error fetching COGS from orders:",e),{}}},eq=async(e,t)=>{if(!(null==s?void 0:s.id)||!M)return{};try{let a=await fetch("/api/item-cost/inventory-costs?accountId=".concat(M,"&startDate=").concat(e.toISOString(),"&endDate=").concat(t.toISOString()));if(!a.ok)return{};return(await a.json()).inventoryCosts||{}}catch(e){return console.error("Error fetching inventory costs:",e),{}}},e$=(e=>
1{let[t,a]=(0,o.useState)(!1);return(0,o.useEffect)(()=>{let t=window.matchMedia(e);a(t.matches);let r=e=>{a(e.matches)};return t.addEventListener("change",r),()=>t.removeEventListener("change",r)},[e]),t})("(min-width: 1680px)"),eQ=eA.map(e=>{let{key:t,isLoaded:a}=e;return a?-(e_[t]||0):0}),eX=eA.map(e=>{var t;let{key:a,isLoaded:r}=e;return r?-((null===(t=eZ[a])||void 0===t?void 0:t.cogs)||0):0}),eJ=eA.map(e=>{var t;let{key:a,isLoaded:r}=e;return r?-((null===(t=eS[a])||void 0===t?void 0:t.monthly)||0):0});O=eA,z=ed;let eK={labels:eL,datasets:[{label:"Profit",data:eH,backgroundColor:e=>{var t;let a=e.chart,r=null===(t=eA[e.dataIndex])||void 0===t?void 0:t.isFiller,o=a.ctx.createLinearGradient(0,0,0,a.height);return o.addColorStop(0,r?"rgba(139, 92, 246, 0.15)":"#4318FF"),o.addColorStop(1,r?"rgba(109, 40, 217, 0.1)":"#6B46C1"),o},borderColor:eA.map(e=>{let{isFiller:t}=e;return t?"rgba(139, 92, 246, 0.4)":"transparent"}),borderWidth:eA.map(e=>{let{isFiller:t}=e;return t?2:0}),borderDash:[4,4],borderRadius:8,barThickness:e$?60:30,hoverBackgroundColor:eA.map(e=>{let{isFiller:t}=e;return t?"rgba(139, 92, 246, 0.25)":"#3727C3"}),hoverBorderColor:eA.map(e=>{let{isFiller:t}=e;return t?"rgba(139, 92, 246, 0.6)":"transparent"}),stack:"combined"},...ef?[{label:"External Expenses",data:eQ,backgroundColor:"#3B82F6",borderColor:"transparent",borderWidth:0,borderRadius:8,barThickness:e$?60:30,hoverBackgroundColor:"#2563EB",hoverBorderColor:"transparent",stack:"combined"}]:[],{label:"Cost of Goods Sold (COGS)",data:ek?eX:eX.map(()=>0),backgroundColor:ek?"#EF4444":"rgba(156, 163, 175, 0.3)",borderColor:"transparent",borderWidth:0,borderRadius:8,barThickness:e$?60:30,hoverBackgroundColor:ek?"#DC2626":"rgba(156, 163, 175, 0.4)",hoverBorderColor:"transparent",stack:"combined",hidden:!ek},...ej?[{label:"Inventory Cost (Unsold)",data:eJ,backgroundColor:U&&G.current?G.current:"rgba(209, 213, 219, 0.5)",borderColor:"rgba(156, 163, 175, 0.5)",borderWidth:1,borderRadius:8,barThickness:e$?60:30,hoverBackgroundColor:"rgba(156, 163, 175, 0.3)",hoverBorderColor:"rgba(156, 163, 175, 0.7)",stack:"combined"}]:[]]},e0=(e,t,a,r)=>{let o={},[n,s]=t.split("-").map(Number),i=new Date(n,s,0).getDate();o[t]={};for(let e=1;e<=i;e++){let a=String(e).padStart(2,"0");o[t][a]={profit:0,expenses:0,externalExpenses:0,cogs:0,orderTotal:0,refunds:0,fees:0,taxes:0,shippingCost:0,credits:0,nonSaleCharges:0}}return e.forEach(e=>{let a=new Date(e.transactionDate),r="".concat(a.getFullYear(),"-").concat(String(a.getMonth()+1).padStart(2,"0")),n=String(a.getDate()).padStart(2,"0");if(r===t){var s,i,l;let a=Number(parseFloat((null===(s=e.amount)||void 0===s?void 0:s.value)||"0").toFixed(2)),r=Number(parseFloat((null===(i=e.totalFeeAmount)||void 0===i?void 0:i.value)||"0").toFixed(2)),d=Number(parseFloat((null===(l=e.ebayCollectedTaxAmount)||void 0===l?void 0:l.value)||"0").toFixed(2));switch(e.transactionType){case"SALE":o[t][n].orderTotal+=a,o[t][n].profit+=a-r-d,o[t][n].fees+=r,o[t][n].taxes+=d,o[t][n].expenses+=r+d;break;case"REFUND":o[t][n].refunds+=a,o[t][n].profit-=a,o[t][n].fees+=r,o[t][n].taxes+=d,o[t][n].expenses+=a+r+d;break;case"SHIPPING_LABEL":"DEBIT"===e.bookingEntry?(o[t][n].shippingCost+=a,o[t][n].profit-=a,o[t][n].expenses+=a):"CREDIT"===e.bookingEntry&&(o[t][n].credits+=a,o[t][n].profit+=a);break;case"NON_SALE_CHARGE":o[t][n].nonSaleCharges+=a,o[t][n].profit-=a,o[t][n].expenses+=a;break;default:console.warn("â ï¸ Unhandled transaction type: ".concat(e.transactionType))}}}),a.forEach(e=>{let a=new Date(e.date),r="".concat(a.getFullYear(),"-").concat(String(a.getMonth()+1).padStart(2,"0")),n=String(a.getDate()).padStart(2,"0");if(r===t){o[t][n]||(o[t][n]={profit:0,expenses:0,externalExpenses:0,cogs:0,orderTotal:0,refunds:0,fees:0,taxes:0,shippingCost:0,credits:0,nonSaleCharges:0});let a=Number(parseFloat(e.amount||"0").toFixed(2));o[t][n].externalExpenses+=a,o[t][n].profit-=a}}),r&&Object.keys(r).forEach(e=>{if(o[t]&&o[t][e]){let a=r[e];o[t][e].cogs=a,o[t][e].profit-=a}}),Object.keys(o[t]).forEach(e=>{let a=o[t][e];a.profit=Number(a.profit.toFixed(2)),a.expenses=Number(a.expenses.toFixed(2)),a.externalExpenses=Number(a.externalExpenses.toFixed(2)),a.cogs=Number((a.cogs||0).toFixed(2)),a.orderTotal=Number(a.orderTotal.toFixed(2)),a.refunds=Number(a.refunds.toFixed(2)),a.fees=Number(a.fees.toFixed(2)),a.taxes=Number(a.taxes.toFixed(2)),a.shippingCost=Number(a.shippingCost.toFixed(2)),a.credits=Number(a.credits.toFixed(2)),a.nonSaleCharges=Number(a.nonSaleCharges.toFixed(2))}),o},e1=async function(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:3;if(!F||!(null==s?void 0:s.id)||!M)return;let a=new Date,r=(0,E.Cw)("transactionData",s.id,M),o=(0,E.Cw)("dailyData",s.id,M),i=(0,E.Cw)("lastUpdated",s.id,M),l=(0,E.Cw)("inventoryData",s.id,M),d=await (0,D.mf)(r),c=await (0,D.mf)(o),u=await (0,D.mf)(i);if(!e&&d&&u){et(e=>({...e,...d})),er(e=>({...e,...c})),en(new Date(u)),X(!1);return}X(!0);try{var g;if(!F)return;let d=(await n.default.post("/api/fetch-transactions-paginated",{token:F,marketplaceId:ec,monthsBack:t,activeAccountId:M,forceRefresh:e||!1})).data,c=new Date,u=new Date;u.setMonth(u.getMonth()-t);let x=await eV(u,c,P),h=await eq(u,c);
1eD(h);let p={};Object.keys(x).forEach(e=>{p[e]=x[e].monthly});let m=eY(d.transactions,p);et(m);let b=eP[0].key,f=(null===(g=x[b])||void 0===g?void 0:g.daily)||{},y=e0(d.transactions,b,eb,f);er(y);let v=(0,E.Cw)("rawTransactions",s.id,M);await (0,D.sx)(r,m),await (0,D.sx)(o,y),await (0,D.sx)(v,d.transactions),await (0,D.sx)(i,a.toISOString()),await (0,D.sx)(l,h),en(a),X(!1),t<12&&e2(t,12)}catch(e){console.error("â Error fetching transaction data:",e),X(!1)}},e2=async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:3,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:12;if(!(null==s?void 0:s.id)||!M)return;let a=e;for(eO(!0);a<t;){try{if(!F)return;let t=(await n.default.post("/api/fetch-transactions-paginated",{token:F,marketplaceId:ec,monthsBack:a+e,activeAccountId:M,forceRefresh:!1})).data,r=new Date,o=new Date;o.setMonth(o.getMonth()-(a+e));let i=await eV(o,r,P),l={};Object.keys(i).forEach(e=>{l[e]=i[e].monthly});let d=(0,E.Cw)("transactionData",s.id,M),c=(0,E.Cw)("rawTransactions",s.id,M);et(e=>{let a={...e,...eY(t.transactions,l)};return(0,D.sx)(d,a),a});let u=[...await (0,D.mf)(c)||[],...t.transactions];await (0,D.sx)(c,u)}catch(e){console.error("â Error fetching more transactions:",e);break}a+=e}eO(!1)};return(0,o.useEffect)(()=>{(async()=>{if(F&&(null==s?void 0:s.id)&&M){X(!0);try{let e=(0,E.Cw)("transactionData",s.id,M),t=(0,E.Cw)("dailyData",s.id,M),a=(0,E.Cw)("lastUpdated",s.id,M),r=(0,E.Cw)("inventoryData",s.id,M),o=await (0,D.mf)(e),n=await (0,D.mf)(t),i=await (0,D.mf)(a),l=await (0,D.mf)(r),d=i?new Date(i).getTime():null,c=new Date().getTime();if(o&&i&&!((d?(c-d)/36e5:null)>=8))et(o),er(n),en(new Date(i)),l&&!ev&&Object.keys(l).length>0&&eD(l);else{console.warn("â³ Data is missing or older than 8 hours. Fetching fresh data...");let e=ev?1:ed?3:12;await e1(!0,e);let t=new Date().toISOString();await (0,D.sx)(a,t),en(new Date(t))}}catch(e){console.error("â Error checking cached data:",e)}finally{X(!1)}}})()},[F,null==s?void 0:s.id,M]),(0,r.jsx)(r.Fragment,{children:F?(0,r.jsx)(r.Fragment,{children:(0,r.jsxs)("section",{className:"bg-gradient-to-br from-[#F8F9FB] via-[#F9FAFB] to-[#EEF2FF]/50 dark:bg-[#1E1E2E] max-h-[400px] p-6 rounded-lg relative",children:[ev&&(0,r.jsx)("div",{className:"absolute bottom-3 left-1/2 -translate-x-1/2 z-20",children:(0,r.jsxs)("button",{onClick:()=>ew.onOpen(),className:"flex items-center gap-1.5 bg-white/90 dark:bg-gray-900/90 backdrop-blur-sm border border-gray-200 dark:border-gray-700 rounded-full px-3 py-1 shadow-sm hover:shadow-md transition-all text-[11px] text-gray-500 dark:text-gray-400 hover:text-indigo-600 dark:hover:text-indigo-400",children:[(0,r.jsx)(c.Z,{className:"w-3 h-3"}),"Current month only \xb7 Upgrade for 12 months"]})}),eI&&(0,r.jsx)("div",{className:"absolute bottom-2 right-4 flex items-center gap-2",children:(0,r.jsxs)(T.C,{className:"px-3 py-1 text-sm font-medium flex items-center gap-2 bg-white/50 dark:bg-gray-900/70 backdrop-blur-xl text-gray-900 dark:text-gray-100 border border-white/30 dark:border-gray-700 ring-1 ring-white/20 dark:ring-gray-700 shadow-lg rounded-lg animate-pulse hover:bg-transparent",children:[(0,r.jsx)(u.Z,{className:"w-3 h-3 animate-spin text-blue-500"}),"Fetching in background..."]})}),(0,r.jsxs)("div",{className:"w-full flex items-center justify-between gap-4",children:[(0,r.jsxs)("div",{className:"flex items-center gap-4",children:["daily"===W&&(0,r.jsxs)(d.Tooltip,{children:[(0,r.jsx)(d.TooltipTrigger,{asChild:!0,children:(0,r.jsxs)(l.z,{variant:"outline",className:"px-3 py-1.5 h-7 text-xs flex items-center gap-1.5",onClick:()=>Y("monthly"),children:[(0,r.jsx)(g.Z,{className:"w-3.5 h-3.5"}),(0,r.jsx)("span",{children:"Back to Monthly View"})]})}),(0,r.jsx)(d.TooltipContent,{className:"max-w-xs text-sm bg-white text-gray-900 border border-gray-200 shadow-md rounded-md p-2 dark:bg-[#1E1E2E] dark:text-gray-200 dark:border-gray-600",children:"Switch back to monthly view"})]}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsx)("h2",{className:"text-base font-semibold text-brand-sub",children:"monthly"===W?"Profit & Expense Chart":"Daily Breakdown - ".concat(q)}),(0,r.jsxs)(d.Tooltip,{children:[(0,r.jsx)(d.TooltipTrigger,{children:(0,r.jsx)(x.Z,{className:"w-4 h-4 text-brand-secondary cursor-pointer"})}),(0,r.jsxs)(d.TooltipContent,{className:"max-w-xs text-sm bg-white text-gray-900 border border-gray-200 shadow-md rounded-md p-3 dark:bg-[#1E1E2E] dark:text-gray-200 dark:border-gray-600",children:[(0,r.jsx)("p",{className:"font-semibold mb-1",children:"Profit & Expense Chart"}),(0,r.jsx)("p",{className:"text-xs text-brand-secondary",children:"Track your eBay profits, fees, shipping costs, taxes, and refunds with interactive monthly and daily breakdowns."})]})]})]})]}),(0,r.jsxs)("div",{className:"flex items-center gap-2",children:[(0,r.jsxs)("div",{className:"flex items-center gap-1",children:[(0,r.jsxs)(d.Tooltip,{children:[(0,r.jsx)(d.TooltipTrigger,{asChild:!0,children:(0,r.jsx)(l.z,{variant:"outline",size:"icon",className:"h-7 w-7",onClick:ed?()=>{}:()=>{eM(e=>e-1)},children:ed?(0,r.jsx)(c.Z,{size:12}):(0,r.jsx)(h.Z,{size:12})})}),ed&&(0,r.jsx)(d.TooltipContent,{className:"max-w-xs text-sm bg-white text-gray-900 border border-gray-200 shadow-md rounded-md p-2 dark:bg-[#1E1E2E] dark:text-gray-200 dark:border-gray-600",children:"Upgrade to Pro or higher to access previous years."})]}),(0,r.jsx)("span",{className:"font-semibold text-sm px-1",children:(()=>{let e=eP.map(e=>parseInt(e.key.split("-")[0])),t=Math.min(...e),a=Math.max(...e);return t===a?"".concat(t):"".concat(t," - ").concat(a)})()}),(0,r.jsxs)(d.Tooltip,{children:[(0,r.jsx)(d.TooltipTrigger,{asChild:!0,children:(0,r.jsx)(l.z,{variant:"outline",size:"icon",className:"h-7 w-7",onClick:ed?()=>{}:()=>{eM(e=>e+1)},children:ed?(0,r.jsx)(c.Z,{size:12}):(0,r.jsx)(p.Z,{size:12})})}),ed&&(0,r.jsx)(d.TooltipContent,{className:"max-w-xs text-sm bg-white text-gray-900 border border-gray-200 shadow-md rounded-md p-2 dark:bg-[#1E1E2E] dark:text-gray-200 dark:border-gray-600",children:"Upgrade to Pro or higher to access future years."})]})]}),(0,r.jsxs)("div",{className:"flex items-center bg-gray-100 dark:bg-gray-800 rounded-md p-0.5",children:[(0,r.jsxs)(d.Tooltip,{children:[(0,r.jsx)(d.TooltipTrigger,{asChild:!0,children:(0,r.jsxs)("button",{onClick:()=>ey(e=>!e),disabled:ed,className:"flex items-center gap-1 px-2 py-1 rounded text-[10px] font-medium transition-all ".concat(ed?"opacity-40 cursor-not-allowed text-gray-400":ef?"bg-white dark:bg-gray-700 text-brand shadow-sm":"text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300"),children:[ed?(0,r.jsx)(c.Z,{size:10}):(0,r.jsx)(m.Z,{size:10}),(0,r.jsx)("span",{children:"Exp"})]})}),(0,r.jsx)(d.TooltipContent,{className:"text-xs bg-gray-900 text-white border-gray-700 shadow-sm rounded px-2 py-1",children:ed?"Pro required":ef?"Hide Expenses":"Show Expenses"})]}),(0,r.jsxs)(d.Tooltip,{children:[(0,r.jsx)(d.TooltipTrigger,{asChild:!0,children:(0,r.jsxs)("button",{onClick:()=>!ev&&eC(e=>!e),disabled:ev,className:"flex items-center gap-1 px-2 py-1 rounded text-[10px] font-medium transition-all ".concat(ev?"opacity-40 cursor-not-allowed text-gray-400":ek?"bg-white dark:bg-gray-700 text-brand shadow-sm":"text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300"),children:[ev?(0,r.jsx)(c.Z,{size:10}):(0,r.jsx)(b.Z,{size:10}),(0,r.jsx)("span",{children:"COGS"})]})}),(0,r.jsx)(d.TooltipContent,{className:"text-xs bg-gray-900 text-white border-gray-700 shadow-sm rounded px-2 py-1",children:ev?"Pro required":ek?"Hide COGS":"Show COGS"})]}),(0,r.jsxs)(d.Tooltip,{children:[(0,r.jsx)(d.TooltipTrigger,{asChild:!0,children:(0,r.jsxs)("button",{onClick:()=>!ev&&eN(e=>!e),disabled:ev,className:"flex items-center gap-1 px-2 py-1 rounded text-[10px] font-medium transition-all ".concat(ev?"opacity-40 cursor-not-allowed text-gray-400":ej?"bg-gray-100 dark:bg-gray-700 text-gray-700 dark:text-gray-300 shadow-sm border border-dashed border-gray-400 dark:border-gray-500":"text-gray-500 dark:text-gray-400 hover:text-gray-700 dark:hover:text-gray-300"),children:[ev?(0,r.jsx)(c.Z,{size:10}):(0,r.jsx)(f.Z,{size:10}),(0,r.jsx)("span",{children:"Inv"})]})}),(0,r.jsx)(d.TooltipContent,{className:"text-xs bg-gray-900 text-white border-gray-700 shadow-sm rounded px-2 py-1",children:ev?"Pro required":ej?"Hide Inventory":"Show Inventory"})]})]}),(0,r.jsx)("span",{className:"text-gray-500 dark:text-gray-400 text-xs",children:eo?(()=>{if(!eo)return"N/A";let e=Math.floor((new Date().getTime()-eo.getTime())/1e3);return e<60?"".concat(e," sec ago"):e<3600?"".concat(Math.floor(e/60)," min ago"):e<86400?"".concat(Math.floor(e/3600)," hr ago"):"".concat(Math.floor(e/86400)," days ago")})():"Loading..."}),(0,r.jsxs)(d.Tooltip,{children:[(0,r.jsx)(d.TooltipTrigger,{children:(0,r.jsx)(l.z,{onClick:async()=>{ei(!0);try{let e=ev?1:ed?3:12;K(e),localStorage.removeItem("loadedMonths"),await (0,D.Xx)(),et({}),er({}),en(null);let t=ev?1:ed?3:12;await e1(!0,t)}catch(e){console.error("Error refreshing chart:",e)}finally{ei(!1)}},variant:"outline",size:"icon",disabled:es,children:es?(0,r.jsx)(u.Z,{className:"animate-spin",size:16}):(0,r.jsx)(u.Z,{size:16})})}),(0,r.jsx)(d.TooltipContent,{className:"max-w-xs text-sm bg-white text-gray-900 border border-gray-200 shadow-md rounded-md p-2 dark:bg-[#1E1E2E] dark:text-gray-200 dark:border-gray-600",children:"Refresh Chart"})]})]})]}),Q?(0,r.jsx)("div",{className:"mt-2",children:(0,r.jsx)(k.Z,{})}):(0,r.jsxs)("div",{ref:L,className:"relative min-h-[300px] max-h-[350px] h-[calc(100%-60px)] w-full mt-2 transition ".concat(eF?"cursor-grabbing":eE?"cursor-grab":"cursor-default hover:cursor-pointer"),children:[0===Object.keys(ee).length?(0,r.jsx)("div",{className:"flex flex-col items-center justify-center h-full ",children:(0,r.jsx)("p",{className:"text-gray-500 dark:text-gray-400",children:"No transaction data available."})}):"monthly"===W?(0,r.jsx)(i.$Q,{ref:Z,data:eK,options:{plugins:{tooltip:{enabled:!0,callbacks:{title:e=>{var t;return(null===(t=eP[e[0].dataIndex])||void 0===t?void 0:t.label)||""},label:e=>{var t,a,r,o;let n=e.dataIndex,s=ee[null===(t=eP[n])||void 0===t?void 0:t.key]||{},i=null===(a=eA[n])||void 0===a?void 0:a.isFiller;if(i&&ed)return["\uD83D\uDD13 Upgrade to Pro to unlock all 12 months"];if(i)return["\uD83D\uDC46 Click to load this month's data"];if(!s||0===Object.keys(s).length)return["\uD83D\uDC46 Click to load data"];let l=(null==s?void 0:s.orderTotal)||0,d=(null==s?void 0:s.profit)||0,c=((null==s?void 0:s.fees)||0)+((null==s?void 0:s.nonSaleCharges)||0),u=((null==s?void 0:s.fees)||0)+((null==s?void 0:s.taxes)||0)+((null==s?void 0:s.shippingCost)||0)+((null==s?void 0:s.nonSaleCharges)||0)+((null==s?void 0:s.cogs)||0),g=null===(r=eP[n])||void 0===r?void 0:r.key,x=ef&&e_[g]||0,h=u+x,p=l>0?d/l*100:0,m=l-((null==s?void 0:s.cogs)||0),b=l>0?m/l*100:0,f=[];f.push("\uD83D\uDCB0 Net Profit: ".concat(ep.format(d)," (").concat(p>=0?"+":"").concat(p.toFixed(1),"%)")),l>0&&(ev&&(null==s?void 0:s.cogs)>0?f.push("\uD83D\uDCE6 Revenue: ".concat(ep.format(l)," | COGS: Not available on your plan")):f.push("\uD83D\uDCE6 Revenue: ".concat(ep.format(l)," | COGS: ").concat(ep.format((null==s?void 0:s.cogs)||0))),f.pu
1sh("\uD83D\uDCCA Gross Profit: ".concat(ep.format(m)," (").concat(b.toFixed(1),"% margin)"))),c>0&&f.push("\uD83D\uDCB3 eBay Fees: ".concat(ep.format(c)," (Selling: ").concat(ep.format((null==s?void 0:s.fees)||0)," + Store: ").concat(ep.format((null==s?void 0:s.nonSaleCharges)||0),")"));let y=[];if((null==s?void 0:s.taxes)>0&&y.push("Tax: ".concat(ep.format(s.taxes))),(null==s?void 0:s.shippingCost)>0&&y.push("Ship: ".concat(ep.format(s.shippingCost))),ef&&x>0&&y.push("Ext: ".concat(ep.format(x))),y.length>0&&f.push("\uD83D\uDCC9 Other Costs: ".concat(y.join(" | "))),h>0&&f.push("\uD83D\uDCCA Total Expenses: ".concat(ep.format(h))),ej&&!ev){let e=(null===(o=eS[g])||void 0===o?void 0:o.monthly)||0;e>0&&f.push("\uD83C\uDFED Unsold Inventory: ".concat(ep.format(e)," (capital tied up in unsold items)"))}let v=[];return(null==s?void 0:s.refunds)>0&&v.push("Refund: ".concat(ep.format(s.refunds))),(null==s?void 0:s.credits)>0&&v.push("Credit: ".concat(ep.format(s.credits))),v.length>0&&f.push("\uD83D\uDD04 ".concat(v.join(" | "))),f}},backgroundColor:"rgba(0, 0, 0, 0.9)",titleColor:"#fff",bodyColor:"#fff",borderColor:"rgba(255, 255, 255, 0.2)",borderWidth:1,padding:8,displayColors:!1,titleFont:{size:12,weight:"bold"},bodyFont:{size:11},boxPadding:4,titleSpacing:4,bodySpacing:3,position:"nearest",caretPadding:10,
1caretSize:6},legend:{display:!0},zoom:{pan:{enabled:!0,mode:"x"},zoom:{wheel:{enabled:!0},pinch:{enabled:!0},mode:"x"}}},animation:{onComplete:()=>{setTimeout(()=>{eW()},50)}},responsive:!0,maintainAspectRatio:!1,onClick:async(e,t)=>{if(0===t.length)return;let a=eA[t[0].index];if(a.isFiller){if(ed){ew.onOpen();return}K(e=>{let t=Math.min(e+3,12);return localStorage.setItem("loadedMonths",t.toString()),t})}else{if(!(null==s?void 0:s.id)||!M)return;let e=a.key;$(e),Y("daily");let t=(0,E.Cw)("dailyData",s.id,M),o=(0,E.Cw)("rawTransactions",s.id,M),n=await (0,D.mf)(t);if(n&&n[e])er(n);else{X(!0);try{var r;let a=await (0,D.mf)(o)||[],[s,i]=e.split("-").map(Number),l=new Date(s,i-1,1),d=new Date(s,i,0,23,59,59),c=await eV(l,d,P),u=(null===(r=c[e])||void 0===r?void 0:r.daily)||{},g=e0(a,e,eb,u);er(e=>({...e,...g})),await (0,D.sx)(t,{...n,...g})}catch(e){console.error("â Error fetching daily data:",e)}finally{X(!1)}}}},scales:{x:{grid:{display:!0,color:"rgba(156, 163, 175, 0.1)",lineWidth:1,drawOnChartArea:!0,drawTicks:!1}},y:{beginAtZero:!0,grid:{display:!0,color:"rgba(156, 163, 175, 0.1)",lineWidth:1},ticks:{callback:e=>ep.format(e)}}}}}):q&&ea[q]&&Object.keys(ea[q]).length>0?(0,r.jsx)(i.x1,{ref:A,data:function(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],a=!(arguments.length>2)||void 0===arguments[2]||arguments[2],r=!(arguments.length>3)||void 0===arguments[3]||arguments[3];if(!ea||!ea[e]||0===Object.keys(ea[e]).length)return console.warn("â ï¸ No daily data found for ".concat(e)),{labels:[],datasets:[]};let[o,n]=e.split("-").map(Number),s=Array.from({length:new Date(o,n,0).getDate()},(e,t)=>"".concat(n,"/").concat(t+1)),i=s.map(t=>{var a,r;let o=String(t.split("/")[1]).padStart(2,"0");return Number((null!==(r=null===(a=ea[e])||void 0===a?void 0:a[o])&&void 0!==r?r:{profit:0,expenses:0,externalExpenses:0,cogs:0}).profit.toFixed(2))}),l=s.map(t=>{var a,r;let o=String(t.split("/")[1]).padStart(2,"0");return-Number((null!==(r=null===(a=ea[e])||void 0===a?void 0:a[o])&&void 0!==r?r:{profit:0,expenses:0,externalExpenses:0,cogs:0}).externalExpenses.toFixed(2))}),d=s.map(t=>{var a,r;let o=String(t.split("/")[1]).padStart(2,"0");return-Number(((null!==(r=null===(a=ea[e])||void 0===a?void 0:a[o])&&void 0!==r?r:{profit:0,expenses:0,externalExpenses:0,cogs:0}).cogs||0).toFixed(2))}),c=s.map(t=>{var a,r;let o=String(t.split("/")[1]).padStart(2,"0");return-Number(((null===(r=eS[e])||void 0===r?void 0:null===(a=r.daily)||void 0===a?void 0:a[o])||0).toFixed(2))});return{labels:s,datasets:[{label:"Net Profit",data:i,borderColor:"rgba(67, 24, 255, 0.3)",backgroundColor:"rgba(67, 24, 255, 0.2)",fill:!0,pointRadius:5,pointHoverRadius:8,pointHitRadius:10,pointBorderWidth:2,pointBorderColor:"rgba(67, 24, 255, 0.3)",pointBackgroun
1dColor:"#fff",tension:.3},...t?[{label:"Expenses",data:l,borderColor:"rgba(59, 130, 246, 0.3)",backgroundColor:"rgba(59, 130, 246, 0.2)",fill:!0,pointRadius:5,pointHoverRadius:8,pointHitRadius:10,pointBorderWidth:2,pointBorderColor:"rgba(59, 130, 246, 0.3)",pointBackgroundColor:"#fff",tension:.3}]:[],{label:"COGS",data:a?d:d.map(()=>null),borderColor:a?"rgba(239, 68, 68, 0.3)":"rgba(156, 163, 175, 0.3)",backgroundColor:a?"rgba(239, 68, 68, 0.2)":"rgba(156, 163, 175, 0.1)",fill:a,pointRadius:a?5:0,pointHoverRadius:a?8:0,pointHitRadius:a?10:0,pointBorderWidth:2,pointBorderColor:a?"rgba(239, 68, 68, 0.3)":"rgba(156, 163, 175, 0.3)",pointBackgroundColor:"#fff",tension:.3,hidden:!a},...r&&!ev?[{label:"Unsold Inventory",data:c,borderColor:"rgba(156, 163, 175, 0.5)",backgroundColor:"rgba(209, 213, 219, 0.2)",borderDash:[5,3],fill:!0,pointRadius:5,pointHoverRadius:8,pointHitRadius:10,pointBorderWidth:2,pointBorderColor:"rgba(156, 163, 175, 0.5)",pointBackgroundColor:"#fff",tension:.3}]:[]]}}(q,ef,ek,ej),options:{responsive:!0,maintainAspectRatio:!1,interaction:{mode:"index",intersect:!1},plugins:{tooltip:{enabled:!0,mode:"index",intersect:!1,callbacks:{title:e=>{var t;let a=(null===(t=e[0])||void 0===t?void 0:t.label)||"",r=null!=q?q:"",o=String(a.split("/")[1]||a).padStart(2,"0"),n="".concat(r,"-").concat(o);return"".concat(a," (").concat(n,")")},label:e=>{let t=e.dataset.label||"",a=e.parsed.y,r=ep.format(a),o=t;return t.includes("Net Profit")?o="Net Profit":t.includes("External Expenses")?o="External Expenses":t.includes("COGS")?o="COGS (sold items)":t.includes("Unsold Inventory")&&(o="Unsold Inventory"),"".concat(o,": ").concat(r)},afterBody:e=>{var t,a,r,o,n;let s=(null===(t=e[0])||void 0===t?void 0:t.label)||"",i=null!=q?q:"",l=String(s.split("/")[1]||s).padStart(2,"0"),d=null!==(r=null===(a=ea[i])||void 0===a?void 0:a[l])&&void 0!==r?r:{profit:0,expenses:0,externalExpenses:0,cogs:0,orderTotal:0,refunds:0,fees:0,taxes:0,shippingCost:0,credits:0,nonSaleCharges:0,orderNumber:null},c=[];d.orderTotal>0&&c.push("\uD83D\uDCE6 Revenue: ".concat(ep.format(d.orderTotal)));let u=[];d.fees>0&&u.push("Fees: ".concat(ep.format(d.fees))),d.taxes>0&&u.push("Tax: ".concat(ep.format(d.taxes))),d.shippingCost>0&&u.push("Ship: ".concat(ep.format(d.shippingCost))),d.nonSaleCharges>0&&u.push("Store: ".concat(ep.format(d.nonSaleCharges))),ek&&d.cogs>0&&u.push("COGS: ".concat(ep.format(d.cogs))),ef&&d.externalExpenses>0&&u.push("Ext: ".concat(ep.format(d.externalExpenses))),u.length>0&&(c.push(""),c.push("--- Expenses ---"),c.push("Deductions: ".concat(u.join(" | "))));let g=[];if(d.refunds>0&&g.push("Refund: ".concat(ep.format(d.refunds))),d.credits>0&&g.push("Credit: ".concat(ep.format(d.credits))),g.length>0&&c.push("\uD83D\uDD04 Other: ".concat(g.join(" | "))),ej&&!ev){let e=(null===(n=eS[i])||void 0===n?void 0:null===(o=n.daily)||void 0===o?void 0:o[l])||0;e>0&&c.push("\uD83C\uDFED Unsold Inventory: ".concat(ep.format(e)," (items listed, not sold)"))}let x=ep.format(d.profit),h=d.orderTotal>0?ep.format(d.orderTotal-(d.cogs||0)):ep.format(d.profit+d.expenses);return c.push(""),c.push("--- Result ---"),c.push("Gross: ".concat(h," | Net: ").concat(x)),c}},filter:e=>null!==e.parsed.y&&void 0!==e.parsed.y,backgroundColor:"rgba(0, 0, 0, 0.9)",titleColor:"#fff",bodyColor:"#fff",borderColor:"rgba(255, 255, 255, 0.2)",borderWidth:1,padding:8,displayColors:!0,titleFont:{size:12,weight:"bold"},bodyFont:{size:11},boxPadding:4,titleSpacing:4,bodySpacing:3,position:"nearest",caretPadding:10,
1caretSize:6},legend:{display:!0},zoom:{pan:{enabled:!0,mode:"x"},zoom:{wheel:{enabled:!0},pinch:{enabled:!0},mode:"x"}}},scales:{x:{grid:{display:!0,color:"rgba(156, 163, 175, 0.1)",lineWidth:1,drawOnChartArea:!0,drawTicks:!1}},y:{beginAtZero:!0,grid:{display:!0,color:"rgba(156, 163, 175, 0.1)",lineWidth:1},ticks:{callback:e=>ep.format(e)}}}}}):(0,r.jsx)("div",{className:"flex flex-col items-center justify-center h-full",children:(0,r.jsx)("p",{className:"text-gray-500 dark:text-gray-400",children:"No daily data available for this month."})}),"monthly"===W&&_.map((e,t)=>e.visible?(0,r.jsxs)(d.Tooltip,{children:[(0,r.jsx)(d.TooltipTrigger,{asChild:!0,children:(0,r.jsx)("div",{className:"absolute pointer-events-auto z-10 cursor-pointer",style:{left:e.x,top:e.y,transform:"translateX(-50%)"},children:(0,r.jsx)(T.C,{variant:"secondary",className:"bg-white/30 hover:bg-white/40 backdrop-blur-sm border px-1.5 py-0.5 ".concat(e.isHighest?"border-green-600":e.value>=0?"border-green-400":"border-red-400"),style:{fontSize:"9px"},children:(0,r.jsx)("span",{className:"text-gray-700",children:ep.format(e.value)})})})}),(0,r.jsx)(d.TooltipContent,{className:"max-w-xs text-sm bg-white text-gray-900 border border-gray-200 shadow-md rounded-md p-2 dark:bg-[#1E1E2E] dark:text-gray-200 dark:border-gray-600",children:(()=>{var e,a;let o=null===(e=eP[t])||void 0===e?void 0:e.key,n=ee[o]||{};if(!n||0===Object.keys(n).length)return"No data available";let s=(null==n?void 0:n.orderTotal)||0,i=(null==n?void 0:n.profit)||0,l=((null==n?void 0:n.fees)||0)+((null==n?void 0:n.nonSaleCharges)||0),d=((null==n?void 0:n.fees)||0)+((null==n?void 0:n.taxes)||0)+((null==n?void 0:n.shippingCost)||0)+((null==n?void 0:n.nonSaleCharges)||0)+((null==n?void 0:n.cogs)||0),c=ef&&e_[o]||0,u=d+c,g=s>0?i/s*100:0,x=s-((null==n?void 0:n.cogs)||0),h=s>0?x/s*100:0;return(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)("div",{className:"font-semibold text-base pb-2 border-b border-gray-300 dark:border-gray-600",children:null===(a=eP[t])||void 0===a?void 0:a.label}),s>0&&(0,r.jsxs)("div",{className:"space-y-1",children:[(0,r.jsx)("div",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:"Revenue"}),(0,r.jsxs)("div",{className:"pl-2 space-y-0.5 text-xs",children:[(0,r.jsxs)("div",{children:["\uD83D\uDCE6 Revenue: ",(0,r.jsx)("span",{className:"font-medium",children:ep.format(s)})]}),(null==n?void 0:n.cogs)>0&&(0,r.jsxs)("div",{children:["\uD83D\uDCE6 COGS: ",ev?(0,r.jsx)("span",{className:"font-medium text-gray-400 dark:text-gray-500",children:"Not available on your plan"}):(0,r.jsx)("span",{className:"font-medium text-red-600 dark:text-red-400",children:ep.format(n.cogs)})]}),(0,r.jsxs)("div",{children:["\uD83D\uDCCA Gross Profit: ",(0,r.jsx)("span",{className:"font-medium text-green-600 dark:text-green-400",children:ep.format(x)})," (",h.toFixed(1),"% margin)"]})]})]}),(l>0||(null==n?void 0:n.taxes)>0||(null==n?void 0:n.shippingCost)>0||ef&&c>0||ek&&(null==n?void 0:n.cogs)>0&&0===s)&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"pt-1 border-t border-gray-200 dark:border-gray-700"}),(0,r.jsxs)("div",{className:"space-y-1",children:[(0,r.jsx)("div",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:"Expenses"}),(0,r.jsxs)("div",{className:"pl-2 space-y-1 text-xs",children:[l>0&&(0,r.jsxs)("div",{children:["\uD83D\uDCB3 eBay Fees: ",(0,r.jsx)("span",{className:"font-medium",children:ep.format(l)}),((null==n?void 0:n.fees)||0)>0&&((null==n?void 0:n.nonSaleCharges)||0)>0&&(0,r.jsxs)("span",{className:"text-gray-500 dark:text-gray-400 ml-1",children:["(Selling: ",ep.format(n.fees)," + Store: ",ep.format(n.nonSaleCharges),")"]})]}),((null==n?void 0:n.taxes)>0||(null==n?void 0:n.shippingCost)>0||ef&&c>0)&&(0,r.jsxs)("div",{children:["\uD83D\uDCC9 Other Costs:"," ",(0,r.jsx)("span",{className:"font-medium",children:[(null==n?void 0:n.taxes)>0&&"Tax: ".concat(ep.format(n.taxes)),(null==n?void 0:n.shippingCost)>0&&"Ship: ".concat(ep.format(n.shippingCost)),ef&&c>0&&"Ext: ".concat(ep.format(c))].filter(Boolean).join(" | ")})]}
1),ek&&(null==n?void 0:n.cogs)>0&&0===s&&(0,r.jsxs)("div",{children:["\uD83D\uDCE6 COGS: ",ev?(0,r.jsx)("span",{className:"font-medium text-gray-400 dark:text-gray-500",children:"Not available on your plan"}):(0,r.jsx)("span",{className:"font-medium text-red-600 dark:text-red-400",children:ep.format(n.cogs)})]}),u>0&&(0,r.jsxs)("div",{className:"pt-1 font-semibold",children:["\uD83D\uDCCA Total Expenses: ",(0,r.jsx)("span",{className:"text-red-600 dark:text-red-400",children:ep.format(u)})]})]})]})]}),((null==n?void 0:n.refunds)>0||(null==n?void 0:n.credits)>0)&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"pt-1 border-t border-gray-200 dark:border-gray-700"}),(0,r.jsxs)("div",{className:"text-xs",children:["\uD83D\uDD04 ",[(null==n?void 0:n.refunds)>0&&"Refund: ".concat(ep.format(n.refunds)),(null==n?void 0:n.credits)>0&&"Credit: ".concat(ep.format(n.credits))].filter(Boolean).join(" | ")]})]}),(0,r.jsx)("div",{className:"pt-2 border-t-2 border-gray-300 dark:border-gray-600",children:(0,r.jsxs)("div",{className:"text-sm font-bold",children:["\uD83D\uDCB0 Net Profit:"," ",(0,r.jsxs)("span",{className:i>=0?"text-green-600 dark:text-green-400":"text-red-600 dark:text-red-400",children:[ep.format(i)," (",g>=0?"+":"",g.toFixed(1),"%)"]})]})}),(0,r.jsx)("div",{className:"pt-1 text-xs text-gray-500 dark:text-gray-400 italic",children:"\uD83D\uDCA1 Click bar to view daily breakdown"})]})})()})]},t):null),(0,r.jsxs)("div",{className:"absolute top-2 right-2 flex gap-1 bg-white/80 dark:bg-[#1E1E2E]/80 p-1 rounded-md shadow-sm backdrop-blur-sm",children:[(0,r.jsxs)(d.Tooltip,{children:[(0,r.jsx)(d.TooltipTrigger,{asChild:!0,children:(0,r.jsx)("div",{className:"p-1 rounded cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-800 transition active:scale-90",onClick:()=>{"monthly"===W&&Z.current?Z.current.zoom(1.2):"daily"===W&&A.current&&A.current.zoom(1.2),eT(!0)},children:(0,r.jsx)(y.Z,{className:"w-3 h-3 text-gray-500 dark:text-gray-300"})})}),(0,r.jsx)(d.TooltipContent,{className:"max-w-xs text-sm bg-white text-gray-900 border border-gray-200 shadow-md rounded-md p-2 dark:bg-[#1E1E2E] dark:text-gray-200 dark:border-gray-600",children:"Zoom In"})]}),(0,r.jsxs)(d.Tooltip,{children:[(0,r.jsx)(d.TooltipTrigger,{asChild:!0,children:(0,r.jsx)("div",{className:"p-1 rounded cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-800 transition",onClick:()=>{"monthly"===W&&Z.current?Z.current.zoom(.8):"daily"===W&&A.current&&A.current.zoom(.8),eT(!0)},children:(0,r.jsx)(v.Z,{className:"w-3 h-3 text-gray-500 dark:text-gray-300"})})}),(0,r.jsx)(d.TooltipContent,{className:"max-w-xs text-sm bg-white text-gray-900 border border-gray-200 shadow-md rounded-md p-2 dark:bg-[#1E1E2E] dark:text-gray-200 dark:border-gray-600",children:"Zoom Out"})]}),(0,r.jsxs)(d.Tooltip,{children:[(0,r.jsx)(d.TooltipTrigger,{asChild:!0,children:(0,r.jsx)("div",{className:"p-1 rounded cursor-pointer hover:bg-gray-100 dark:hover:bg-gray-800 transition ".concat(eE?"text-red-500 dark:text-red-400":"text-gray-500 dark:text-gray-300"),onClick:()=>{"monthly"===W&&Z.current?Z.current.resetZoom():"daily"===W&&A.current&&A.current.resetZoom(),eT(!1),eB(!1)},children:(0,r.jsx)(w.Z,{className:"w-3 h-3"})})}),(0,r.jsx)(d.TooltipContent,{className:"max-w-xs text-sm bg-white text-gray-900 border border-gray-200 shadow-md rounded-md p-2 dark:bg-[#1E1E2E] dark:text-gray-200 dark:border-gray-600",children:"Reset Zoom"})]})]})]})]})}):(0,r.jsx)(B,{formatter:ep,isLargeScreen:e$,currentYear:ez})})}}}]);
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.