1import{j as t}from"./ui-D6wygKh_.js";import{f as Y,r as T}from"./vendor-CVh2rptI.js";import{A as X}from"./AppLayout-CJiK12Hw.js";import{u as q,w as H,h as G,x as g,E as j,y as I,z as C}from"./index-BrGOkkXS.js";import{u as J,a as Q}from"./ItemsContext-DdQsScrv.js";import{c as V}from"./marketplaceFees-CR5Qm1Jv.js";import{r as W}from"./orderCostBasis-hrItvBbL.js";import{g as Z}from"./registry-W_KME9A9.js";import{P as tt}from"./ProLock-CPVm0rzl.js";import{u as et}from"./useDocumentTitle-CiLM3zTd.js";import{F as st}from"./useGatingStatus-CbwjAyWy.js";import{l as at,p as M}from"./localDay-DL2GBE3p.js";import{A as rt}from"./arrow-left-UUN6mfBI.js";import{D as ot}from"./dollar-sign-DgR78AiT.js";import{T as nt}from"./trending-up-DBwVJCoE.js";import{T as it}from"./trophy-D1jKsrc9.js";import{R as L,B as lt,X as P,Y as E,T as F,a as ct,C as dt,A as mt,b as ht}from"./AreaChart-DyezYTmi.js";import{C as xt}from"./clock-B3s4vMH3.js";import"./supabase-DeF1CnPg.js";import"./planRows-B74cio-K.js";import"./scroll-area-wtzjYzGc.js";import"./index-Bb0ZwFHZ.js";import"./trash-2-C5AKxuQ4.js";import"./circle-x-BYbxmNC3.js";import"./info-D3vfiUlb.js";import"./external-link-BAeU3ll3.js";import"./useCurrencyRate-DZQPr3EK.js";import"./useQuery-CBaR5QOq.js";import"./crown-DzChXpqq.js";import"./locale-en-B-psxaJO.js";import"./photoDisplay-EN9x6-gG.js";import"./camera-BFAJzHF-.js";import"./package-CrNhTWJN.js";import"./readEdgeError-_---NsTR.js";(function(){try{var e=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};e.SENTRY_RELEASE={id:"a7370a5c3a4216b5fbce296adf990f6d25a0345a"};var n=new e.Error().stack;
1n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="47947215-6bad-47cb-abe0-e214ea5c6268",e._sentryDebugIdIdentifier="sentry-dbid-47947215-6bad-47cb-abe0-e214ea5c6268")}catch{}})();const B=e=>Math.round(e*100)/100;function ut(e,n){const l=new Map,i=a=>(l.has(a)||l.set(a,{sold:0,netSum:0,daysSum:0,daysCount:0}),l.get(a));for(const a of e){if(!a.marketplace)continue;const o=i(a.marketplace);o.sold++,o.netSum+=Number.isFinite(a.net)?a.net:0,a.daysToSell!=null&&Number.isFinite(a.daysToSell)&&a.daysToSell>=0&&(o.daysSum+=a.daysToSell,o.daysCount++)}const c=new Map;for(const a of n)a&&(c.set(a,(c.get(a)||0)+1),i(a));const N=[];for(const[a,o]of l){const p=c.get(a)||0,x=o.sold+p;N.push({marketplace:a,sold:o.sold,netProfit:B(o.netSum),avgNet:o.sold?B(o.netSum/o.sold):0,activeListings:p,avgDaysToSell:o.daysCount?Math.round(o.daysSum/o.daysCount):null,sellThrough:x>0?Math.round(o.sold/x*100):null})}return N.sort((a,o)=>o.netProfit-a.netProfit||a.marketplace.localeCompare(o.marketplace))}function pt(e){const n=new Map;for(const l of e){const i=Date.parse(l.date);if(!Number.isFinite(i))continue;const c=at(i);c&&n.set(c,(n.get(c)||0)+l.net)}return[...n.entries()].sort(([l],[i])=>l.localeCompare(i)).map(([l,i])=>({date:l,net:Math.round(i)}))}const h=e=>`$${Math.round(e).toLocaleString()}`,ft=e=>e.replace(/\b\w/g,n=>n.toUpperCase()),_=e=>Z(e)?.name||ft(e);function gt(e){const n=(e.platform||"").toLowerCase().trim();if(n&&n!=="manual"&&n!=="mock")return n;const l=e.raw,i=String(l?.manual_platform||"").toLowerCase().trim();return i&&i!=="manual"&&i!=="mock"?i:"manual"}const O=["#1D9E75","#378ADD","#7F77DD","#D85A30","#888780"];function Wt(){et("Cross-list insights - FastFlip");const{t:e}=q(),{visibleOrders:n,isLoading:l}=J(),{items:i}=Q(),{user:c}=H(),N=Y(),[a,o]=T.useState(new Map);T.useEffect(()=>{if(!c)return;let s=!1;return(async()=>{const{data:d}=await G.from("channel_listings").select("item_id, channel, created_at").eq("user_id",c.id);if(s||!d)return;const b=new Map;for(const m of d)m.item_id&&m.channel&&m.created_at&&b.set(`${m.item_id}::${m.channel}`,m.created_at);o(b)})(),()=>{s=!0}},[c]);const{stats:p,totals:x,trend:D}=T.useMemo(()=>{const s=new Map(i.map(r=>[r.id,r])),d=n.filter(r=>(r.status||"")!=="cancelled"&&(r.platform||"").toLowerCase()!=="mock").map(r=>{const u=r.item_id?s.get(r.item_id):void 0,v=gt(r),f=r.raw,z=W(f?.item_cost_basis,u?.cost_basis),K=V({platform:v,grossTotal:r.sale_price,tax:Number(f?.totals_json?.tax)||0,buyerPaidShipping:Number(f?.totals_json?.shipping)||0,category:u?.category??null,itemCost:z,realShippingCost:r.shipping_cost??null,realPayout:f?.payout_amount??(f?.totals_json?.payout!=null?Number(f.totals_json.payout):null)}),A=(r.item_id?a.get(`${r.item_id}::${v}`):void 0)||u?.created_at,w=Date.parse(r.created_at),k=A?Date.parse(A):NaN,U=Number.isFinite(w)&&Number.isFinite(k)&&w>=k?Math.round((w-k)/864e5):null;return{marketplace:v,net:K.net,daysToSell:U,date:r.created_at}}),b=i.flatMap(r=>(r.activeChannels||[]).map(u=>u.channel)),m=ut(d.map(r=>({marketplace:r.marketplace,net:r.net,daysToSell:r.daysToSell})),b),R={sold:d.length,net:d.reduce((r,u)=>r+u.net,0),marketplaces:m.filter(r=>r.sold>0).length},$=pt(d);return{stats:m,totals:R,trend:$}},[n,i,a]),y=p.find(s=>s.sold>0)||null,S=p.filter(s=>s.sold>0).map(s=>({name:_(s.marketplace),net:s.netProfit}));return t.jsx(X,{children:t.jsx(tt,{feature:"crosslist_all",className:"w-full",children:t.jsxs("div",{className:"max-w-5xl mx-auto px-3 sm:px-4 py-4 pb-24",children:[t.jsxs("button",{onClick:()=>N("/channel-listings"),className:"inline-flex items-center gap-1 text-sm text-muted-foreground hover:text-foreground mb-2",children:[t.jsx(rt,{className:"w-4 h-4"})," ",e("crossInsights.ciBackBoard")]}),t.jsx("h1",{className:"text-xl font-semibold",children:e("crossInsights.ciTitle")}),t.jsx("p",{className:"text-sm text-muted-foreground mt-0.5",children:e("crossInsights.ciSubtitle")}),l?t.jsx("div",{className:"text-center py-20 text-muted-foreground",children:e("common.loading")}):x.sold===0?t.jsxs("div",{className:"text-center py-16 border rounded-xl bg-muted/20 mt-4",children:[t.jsx(st.crosslistInsights,{className:"w-8 h-8 text-muted-foreground mx-auto mb-3"}),t.jsx("p",{className:"font-medium",children:e("crossInsights.ciNoSales")}),t.jsx("p",{className:"text-sm text-muted-foreground mt-1 max-w-md mx-auto",children:e("crossInsights.ciNoSalesDesc")})]}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-3 mt-4",children:[t.jsx(g,{children:t.jsx(j,{className:"p-4",children:t.jsxs("div",{className:"flex items-start justify-between",children:[t.jsxs("div",{children:[t.jsx("p",{className:"text-xs text-muted-foreground",children:e("crossInsights.ciTotalNet")}),t.jsx("p",{className:"text-xl font-bold text-green-600",children:h(x.net)}),t.jsx("p",{className:"text-xs text-muted-foreground",children:e("crossInsights.ciSaleCount",{count:x.sold})})]}
1),t.jsx(ot,{className:"w-5 h-5 text-muted-foreground/50"})]})})}),t.jsx(g,{children:t.jsx(j,{className:"p-4",children:t.jsxs("div",{className:"flex items-start justify-between",children:[t.jsxs("div",{children:[t.jsx("p",{className:"text-xs text-muted-foreground",children:e("crossInsights.ciMktSoldOn")}),t.jsx("p",{className:"text-xl font-bold",children:x.marketplaces}),t.jsx("p",{className:"text-xs text-muted-foreground",children:e("crossInsights.ciOfChannels")})]}),t.jsx(nt,{className:"w-5 h-5 text-muted-foreground/50"})]})})}),t.jsx(g,{className:"col-span-2 sm:col-span-1",children:t.jsx(j,{className:"p-4",children:t.jsxs("div",{className:"flex items-start justify-between",children:[t.jsxs("div",{children:[t.jsx("p",{className:"text-xs text-muted-foreground",children:e("crossInsights.ciBestEarner")}),t.jsx("p",{className:"text-xl font-bold",children:y?_(y.marketplace):"â"}),t.jsx("p",{className:"text-xs text-muted-foreground",children:y?e("crossInsights.ciNetSuffix",{amount:h(y.netProfit)}):""})]}),t.jsx(it,{className:"w-5 h-5 text-amber-500/60"})]})})})]}),S.length>0&&t.jsxs(g,{className:"mt-4",children:[t.jsx(I,{className:"pb-2",children:t.jsx(C,{className:"text-sm font-medium",children:e("crossInsights.ciNetByMkt")})}),t.jsx(j,{children:t.jsx("div",{className:"h-48",children:t.jsx(L,{width:"100%",height:"100%",children:t.jsxs(lt,{data:S,margin:{left:8,right:8,top:8,bottom:4},children:[t.jsx(P,{dataKey:"name",tick:{fontSize:11}}),t.jsx(E,{tick:{fontSize:10},tickFormatter:s=>h(s),width:52}),t.jsx(F,{formatter:s=>[h(s),e("crossInsights.ciNet")],contentStyle:{background:"hsl(var(--card))",border:"1px solid hsl(var(--border))",borderRadius:8,fontSize:12}}),t.jsx(ct,{dataKey:"net",radius:[4,4,0,0],isAnimationActive:!1,children:S.map((s,d)=>t.jsx(dt,{fill:O[d%O.length]},d))})]})})})})]}),D.length>=2&&t.jsxs(g,{className:"mt-4",children:[t.jsx(I,{className:"pb-2",children:t.jsx(C,{className:"text-sm font-medium",children:e("crossInsights.ciNetOverTime")})}),t.jsx(j,{children:t.jsx("div",{className:"h-44",children:t.jsx(L,{width:"100%",height:"100%",children:t.jsxs(mt,{data:D,margin:{left:8,right:8,top:8,bottom:4},children:[t.jsx(P,{dataKey:"date",tick:{fontSize:10},tickFormatter:s=>M(String(s)).toLocaleDateString(void 0,{month:"short",day:"numeric"})}),t.jsx(E,{tick:{fontSize:10},tickFormatter:s=>h(s),width:52}),t.jsx(F,{formatter:s=>[h(s),e("crossInsights.ciNet")],labelFormatter:s=>M(String(s)).toLocaleDateString(),contentStyle:{background:"hsl(var(--card))",border:"1px solid hsl(var(--border))",borderRadius:8,fontSize:12}}),t.jsx(ht,{type:"monotone",dataKey:"net",stroke:"#1D9E75",fill:"#1D9E75",fillOpacity:.15,isAnimationActive:!1})]})})})})]}),t.jsxs(g,{className:"mt-4",children:[t.jsx(I,{className:"pb-2",children:t.jsx(C,{className:"text-sm font-medium",children:e("crossInsights.ciPerMktPerf")})}),t.jsx(j,{className:"px-0",children:t.jsx("div",{className:"overflow-x-auto",children:t.jsxs("table",{className:"w-full text-sm",children:[t.jsx("thead",{children:t.jsxs("tr",{className:"text-muted-foreground text-xs border-b",children:[t.jsx("th",{className:"text-left font-medium px-4 py-2",children:e("crossInsights.ciThMarketplace")}),t.jsx("th",{className:"text-right font-medium px-2 py-2",children:e("crossInsights.ciThSold")}),t.jsx("th",{className:"text-right font-medium px-2 py-2",children:e("crossInsights.ciThNetProfit")}),t.jsx("th",{className:"text-right font-medium px-2 py-2",children:e("crossInsights.ciThAvgSale")}),t.jsx("th",{className:"text-right font-medium px-2 py-2",children:e("crossInsights.ciThActive")}),t.jsx("th",{className:"text-right font-medium px-2 py-2 whitespace-nowrap",children:e("crossInsights.ciThSellThrough")}),t.jsx("th",{className:"text-right font-medium px-4 py-2 whitespace-nowrap",children:e("crossInsights.ciThAvgDays")})]})}),t.jsx("tbody",{children:p.map(s=>t.jsxs("tr",{className:"border-b last:border-0",children:[t.jsx("td",{className:"px-4 py-2 font-medium",children:_(s.marketplace)}),t.jsx("td",{className:"px-2 py-2 text-right",children:s.sold}),t.jsx("td",{className:`px-2 py-2 text-right font-medium ${s.netProfit<0?"text-destructive":s.netProfit>0?"text-green-700":""}`,children:s.netProfit<0?`-${h(Math.abs(s.netProfit))}`:h(s.netProfit)}),t.jsx("td",{className:"px-2 py-2 text-right text-muted-foreground",children:s.sold?h(s.avgNet):"â"}),t.jsx("td",{className:"px-2 py-2 text-right text-muted-foreground",children:s.activeListings}),t.jsx("td",{className:"px-2 py-2 text-right text-muted-foreground",children:s.sellThrough!=null?`${s.sellThrough}%`:"â"}),t.jsx("td",{className:"px-4 py-2 text-right text-muted-foreground",children:s.avgDaysToSell!=null?t.jsxs("span",{className:"inline-flex items-center gap-1 justify-end",children:[t.jsx(xt,{className:"w-3 h-3"}),e("crossInsights.ciDaysShort",{days:s.avgDaysToSell})]}):"â"})]},s.marketplace))})]})})})]}),t.jsx("p",{className:"text-[11px] text-muted-foreground mt-3",children:e("crossInsights.ciFootnote")})]})]})})})}export{Wt 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.