1import{c as Oe,r as x,j as e,a0 as Ne,B as Z,ah as pt,ai as ge,aj as ae,ak as A,al as oe,q as dt,am as bt,R as Nt,an as Te,ao as Re,ap as $e,aq as Le,ar as we,as as ke,C as me,v as he,m as vt,at as gt,au as Ke,I as ze,av as Be,J as Ve,K as qe,M as Ue,N as Ge,O as fe,P as ye,u as ft,a as yt,aw as _t,s as jt,w as wt,ax as He,a7 as kt,t as St,D as Dt,b as Ct,d as At,e as Et,f as Mt,A as Ft,ay as Xe,k as It,l as Ot,az as Pt,aA as Ye,aB as Je,aC as We,aD as Qe,aE as Ze,aF as et,aG as tt,aH as st,a6 as at,H as rt}from"./index-3729243f.js";import{T as Tt,a as Rt,b as _e,c as lt,d as $t,e as F,F as ot}from"./FxRateCard-425d6b77.js";import{u as Pe}from"./useFinancialCalculations-8944b8f4.js";import{P as Ae}from"./pen-square-e961d339.js";import{T as Ee}from"./trash-2-03a8c422.js";const Me=Oe("Copy",[["rect",{width:"14",height:"14",x:"8",y:"8",rx:"2",ry:"2",key:"17jyea"}],["path",{d:"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2",key:"zix9uf"}]]),nt=Oe("FilterX",[["path",{d:"M13.013 3H2l8 9.46V19l4 2v-8.54l.9-1.055",key:"1fi1da"}],["path",{d:"m22 3-5 5",key:"12jva0"}],["path",{d:"m17 3 5 5",key:"k36vhe"}]]),Lt=Oe("MoreHorizontal",[["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"19",cy:"12",r:"1",key:"1wjl8i"}],["circle",{cx:"5",cy:"12",r:"1",key:"1pcz8c"}]]),it=({className:c,...r})=>e.jsx("nav",{role:"navigation","aria-label":"pagination",className:Ne("mx-auto flex w-full justify-center",c),...r});it.displayName="Pagination";const ct=x.forwardRef(({className:c,...r},v)=>e.jsx("ul",{ref:v,className:Ne("flex flex-row items-center gap-1",c),...r}));ct.displayName="PaginationContent";const je=x.forwardRef(({className:c,...r},v)=>e.jsx("li",{ref:v,className:Ne("",c),...r}));je.displayName="PaginationItem";const Se=({className:c,isActive:r,size:v="icon",children:p,...I})=>e.jsx(Z,{"aria-current":r?"page":void 0,variant:r?"outline":"ghost",size:v,className:Ne("border-[hsl(var(--royaltix-card-border))] hover:bg-[hsl(var(--royaltix-primary)_/_0.1)] hover:text-[hsl(var(--royaltix-primary))]",r&&"bg-[hsl(var(--royaltix-primary)_/_0.2)] text-[hsl(var(--royaltix-primary))]",c),...I,children:p});Se.displayName="PaginationLink";const xt=({className:c,...r})=>e.jsxs(Se,{"aria-label":"Go to previous page",size:"default",className:Ne("gap-1 pl-2.5",c),...r,children:[e.jsx(pt,{className:"h-4 w-4"}),e.jsx("span",{children:"Previous"})]});xt.displayName="PaginationPrevious";const mt=({className:c,...r})=>e.jsxs(Se,{"aria-label":"Go to next page",size:"default",className:Ne("gap-1 pr-2.5",c),...r,children:[e.jsx("span",{children:"Next"}),e.jsx(ge,{className:"h-4 w-4"})]});mt.displayName="PaginationNext";const ut=({className:c,...r})=>e.jsxs("span",{"aria-hidden":!0,className:Ne("flex h-9 w-9 items-center justify-center",c),...r,children:[e.jsx(Lt,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"More pages"})]});ut.displayName="PaginationEllipsis";const Fe=10,Kt=({entries:c,accounts:r,onEdit:v,onDelete:p,onDuplicate:I,eurToUsdRate:o,displayCurrency:z,sortConfig:R,setSortConfig:xe,filters:pe,pagePersistenceKey:Y,groupByDay:ee=!1})=>{const[$,re]=x.useState(1),{convertAmount:D}=Pe(z),k=z==="EUR"?"â¬":"$",N=x.useMemo(()=>r.reduce((t,n)=>(t[n.id]=n.name,t),{}),[r]),[J,ue]=x.useState({}),E=x.useMemo(()=>{if(!ee)return c.map(h=>({type:"entry",entry:h}));const t=new Map;c.forEach(h=>{const j=h.date&&ae(A(h.date))?oe(A(h.date),"yyyy-MM-dd"):"unknown-date";t.has(j)||t.set(j,[]),t.get(j).push(h)});const n=[];return t.forEach((h,j)=>{h.length===1?n.push({type:"entry",entry:h[0]}):n.push({type:"group",date:j,entries:h})}),n},[c,ee]),V=Math.ceil(E.length/Fe);x.useEffect(()=>{$>V&&re(V||1)},[V,$]),x.useEffect(()=>{re(1)},[pe]),x.useEffect(()=>{if(Y)try{const t=localStorage.getItem(Y),n=parseInt(t,10);!isNaN(n)&&n>=1&&re(n)}catch{}},[Y]),x.useEffect(()=>{if(Y)try{localStorage.setItem(Y,String($))}catch{}},[$,Y]);const L=x.useMemo(()=>E.slice(($-1)*Fe,$*Fe),[E,$]),O=(t,n)=>t<=7?Array.from({length:t},(h,j)=>j+1):n<=4?[1,2,3,4,5,"ellipsis",t]:n>=t-3?[1,"ellipsis",t-4,t-3,t-2,t-1,t]:[1,"ellipsis",n-1,n,n+1,"ellipsis",t],u=({entry:t,zebra:n=!1}
1)=>{const[h,j]=x.useState(!1),m=x.useRef({sx:0,sy:0,lx:0,ly:0,locked:null}),f=t&&t.eur_to_usd_rate_at_entry!=null&&!isNaN(Number(t.eur_to_usd_rate_at_entry))?Number(t.eur_to_usd_rate_at_entry):o,P=D(t.income,t.income_currency,z,f),g=D(t.ad_spend,t.ad_spend_currency,z,f),T=P-g,q=T<0,W=g>0?P/g:0,G=t&&t.ad_acos!=null&&!isNaN(Number(t.ad_acos))?Number(t.ad_acos):null,te=P>0&&g>0?g/P*100:null,H=G??te,K=t&&t.orders!=null&&!isNaN(Number(t.orders))?Number(t.orders):null,M=t&&t.ad_orders!=null&&!isNaN(Number(t.ad_orders))?Number(t.ad_orders):null,Q=K!=null?Math.max(0,Math.round(K)-(M!=null?Math.round(M):0)):null;let X="text-[hsl(var(--royaltix-text-muted))]",se="bg-[hsl(var(--royaltix-card-bg)_/_0.35)] border-[hsl(var(--royaltix-card-border)_/_0.7)]";H!=null&&!isNaN(H)&&(H<=25?(X="text-emerald-300",se="bg-emerald-500/10 border-emerald-500/30"):H<=40?(X="text-yellow-300",se="bg-yellow-500/10 border-yellow-500/30"):(X="text-rose-300",se="bg-rose-500/10 border-rose-500/30"));const le=t!=null&&t.date&&ae(A(t.date))?A(t.date):null,ce=le?oe(le,"dd"):"â",s=le?oe(le,"MMM"):"â",a=le?oe(le,"EEE"):"",l=N[t.account_id]||"N/A",y=x.useCallback(b=>{const w=b.touches&&b.touches[0];w&&(m.current={sx:w.clientX,sy:w.clientY,lx:w.clientX,ly:w.clientY,locked:null})},[]),d=x.useCallback(b=>{const w=b.touches&&b.touches[0];if(!w)return;const S=m.current;S.lx=w.clientX,S.ly=w.clientY;const de=S.lx-S.sx,ie=S.ly-S.sy,be=Math.abs(de),ve=Math.abs(ie);if(!S.locked){if(be<6&&ve<6)return;S.locked=be>ve?"x":"y"}},[]),i=x.useCallback(()=>{const b=m.current,w=b.lx-b.sx;b.locked==="x"&&(w<-44&&j(!0),w>44&&j(!1)),m.current.locked=null},[]);return e.jsx("div",{className:"rounded-xl border overflow-hidden shadow-sm "+(q?n?"border-rose-500/35 bg-rose-500/10":"border-rose-500/30 bg-rose-500/08":"border-[hsl(var(--royaltix-card-border)_/_0.65)] "+(n?"bg-[hsl(var(--royaltix-card-bg)_/_0.45)]":"bg-[hsl(var(--royaltix-card-bg)_/_0.58)]")),style:{touchAction:"pan-y"},onTouchStart:y,onTouchMove:d,onTouchEnd:i,onTouchCancel:i,children:e.jsxs("div",{className:"flex w-[200%] transition-transform duration-300",style:{transform:h?"translateX(-50%)":"translateX(0%)"},children:[e.jsx("div",{className:"w-1/2 p-2.5",children:e.jsxs("div",{className:"flex items-start gap-2.5",children:[e.jsxs("div",{className:"shrink-0 rounded-xl border border-[hsl(var(--royaltix-card-border)_/_0.75)] bg-[hsl(var(--royaltix-card-bg)_/_0.35)] px-2.5 py-2",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.18em] text-[hsl(var(--royaltix-text-muted))]",children:s}),e.jsx("div",{className:"text-2xl leading-none font-extrabold tabular-nums text-[hsl(var(--royaltix-text-primary))]",children:ce}),e.jsx("div",{className:"mt-1 text-[10px] text-[hsl(var(--royaltix-text-muted))]",children:a})]}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate text-[15px] font-semibold text-[hsl(var(--royaltix-text-primary))]",children:l}),e.jsx("div",{className:"mt-0.5 text-[11px] text-[hsl(var(--royaltix-text-muted))]",children:"Orders / Ad / Org"})]}),e.jsxs("button",{type:"button",onClick:()=>j(!0),className:"shrink-0 inline-flex items-center gap-1 rounded-full border border-[hsl(var(--royaltix-card-border)_/_0.7)] bg-[hsl(var(--royaltix-card-bg)_/_0.35)] px-2 py-1 text-[11px] font-semibold text-[hsl(var(--royaltix-text-primary))]",children:[e.jsx("span",{children:"More"}),e.jsx(ge,{className:"h-3.5 w-3.5 text-[hsl(var(--royaltix-text-muted))]"})]})]}),e.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-2",children:[e.jsxs("span",{className:"inline-flex items-center rounded-full border border-[hsl(var(--royaltix-card-border)_/_0.7)] bg-[hsl(var(--royaltix-card-bg)_/_0.35)] px-2 py-1 text-[11px] font-semibold text-[hsl(var(--royaltix-text-secondary))] tabular-nums",children:["Orders ",K!=null?Math.round(K):"â"]}),e.jsxs("span",{className:"inline-flex items-center rounded-full border border-orange-500/30 bg-
1orange-500/10 px-2 py-1 text-[11px] font-semibold text-orange-200 tabular-nums",children:["Ad ",M!=null?Math.round(M):"â"]}),e.jsxs("span",{className:"inline-flex items-center rounded-full border border-emerald-500/30 bg-emerald-500/10 px-2 py-1 text-[11px] font-semibold text-emerald-200 tabular-nums",children:["Org ",Q!=null?Math.round(Q):"â"]})]}),e.jsxs("div",{className:"mt-1.5 grid grid-cols-3 gap-2",children:[e.jsxs("div",{className:"rounded-xl border border-emerald-500/25 bg-emerald-500/10 p-2",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.16em] text-emerald-200/80",children:"Income"}),e.jsxs("div",{className:"mt-0.5 text-[14px] font-bold tabular-nums text-emerald-200",children:[k,P.toFixed(2)]})]}),e.jsxs("div",{className:"rounded-xl border border-rose-500/25 bg-rose-500/10 p-2",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.16em] text-rose-200/80",children:"Spend"}),e.jsxs("div",{className:"mt-0.5 text-[14px] font-bold tabular-nums text-rose-200",children:[k,g.toFixed(2)]})]}),e.jsxs("div",{className:`rounded-xl border p-2 ${T>=0?"border-emerald-500/25 bg-emerald-500/10":"border-rose-500/25 bg-rose-500/10"}`,children:[e.jsx("div",{className:`text-[10px] uppercase tracking-[0.16em] ${T>=0?"text-emerald-200/80":"text-rose-200/80"}`,children:"Profit"}),e.jsxs("div",{className:`mt-0.5 text-[14px] font-bold tabular-nums ${T>=0?"text-emerald-200":"text-rose-200"}`,children:[k,T.toFixed(2)]})]})]}),e.jsxs("div",{className:"mt-1.5 flex flex-wrap items-center gap-2",children:[e.jsxs("span",{className:"inline-flex items-center rounded-full border border-sky-500/30 bg-sky-500/10 px-2 py-1 text-[11px] font-semibold text-sky-200 tabular-nums",children:["ROAS ",W.toFixed(2),"x"]}),e.jsxs("span",{className:`inline-flex items-center rounded-full border px-2 py-1 text-[11px] font-semibold tabular-nums ${X} ${se}`,children:["ACOS ",H!=null&&!isNaN(H)?`${H.toFixed(1)}%`:"â"]})]}),e.jsxs("div",{className:"mt-1.5 flex items-center justify-end gap-1",children:[e.jsx(Z,{variant:"ghost",size:"icon",className:"h-9 w-9 text-[hsl(var(--royaltix-text-muted))] hover:text-[hsl(var(--royaltix-accent))]",onClick:()=>v(t),"aria-label":"Edit",children:e.jsx(Ae,{className:"h-4 w-4"})}),e.jsx(Z,{variant:"ghost",size:"icon",className:"h-9 w-9 text-[hsl(var(--royaltix-text-muted))] hover:text-blue-400",onClick:()=>I(t),"aria-label":"Duplicate",children:e.jsx(Me,{className:"h-4 w-4"})}),e.jsx(Z,{variant:"ghost",size:"icon",className:"h-9 w-9 text-[hsl(var(--royaltix-text-muted))] hover:text-rose-300",onClick:()=>p(t.id),"aria-label":"Delete",children:e.jsx(Ee,{className:"h-4 w-4"})})]})]})]})}),e.jsxs("div",{className:"w-1/2 p-2.5",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-[0.18em] text-[hsl(var(--royaltix-text-muted))]",children:"Details"}),e.jsx("div",{className:"truncate text-[15px] font-semibold text-[hsl(var(--royaltix-text-primary))]",children:l})]}),e.jsxs("button",{type:"button",onClick:()=>j(!1),className:"shrink-0 inline-flex items-center gap-1 rounded-full border border-[hsl(var(--royaltix-card-border)_/_0.7)] bg-[hsl(var(--royaltix-card-bg)_/_0.35)] px-2.5 py-1 text-[11px] font-semibold text-[hsl(var(--royaltix-text-primary))]",children:[e.jsx(ge,{className:"h-3.5 w-3.5 rotate-180 text-[hsl(var(--royaltix-text-muted))]"}),e.jsx("span",{children:"Back"})]})]}),e.jsxs("div",{className:"mt-2 grid grid-cols-2 gap-2",children:[e.jsxs("div",{className:"rounded-xl border border-[hsl(var(--royaltix-card-border)_/_0.65)] bg-[hsl(var(--royaltix-card-bg)_/_0.35)] p-2",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.16em] text-[hsl(var(--royaltix-text-muted))]",children:"Orders"}),e.jsx("div",{className:"mt-0.5 text-[15px] font-bold tabular-nums text-[hsl(var(--royaltix-text-primary))]",children:K!=null?Math.round(K):"â"})]}),e.jsxs("div",{className:"rounded-xl border border-[hsl(var(--royaltix-card-border)_/_0.65)] bg-[hsl(var(--royaltix-card-bg)_/_0.35)] p-2",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.16em] text-[hsl(var(--royaltix-text-muted))]",children:"Ad / Org"}),e.jsxs("div",{className:"mt-0.5 text-[15px] font-bold tabular-nums text-[hsl(var(--royaltix-text-primary))]",children:[M!=null?Math.round(M):"â"," / ",Q!=null?Math.round(Q):"â"]})]})]}),e.jsxs("div",{className:"mt-2 rounded-xl border border-[hsl(var(--royaltix-card-border)_/_0.65)] bg-[hsl(var(--royaltix-card-bg)_/_0.35)] p-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-2 text-[11px] text-[hsl(var(--royaltix-text-muted))]",children:[e.jsx("span",{children:"Entry FX"}),e.jsxs("span",{className:"tabular-nums",children:["1 EUR = ",Number(f).toFixed(4)," USD"]})]}),e.jsxs("div",{className:"mt-1 flex items-center justify-between gap-2 text-[11px] text-[hsl(var(--royaltix-text-muted))]",children:[e.jsx("span",{children:"Raw values"}),e.jsxs("span",{className:"tabular-nums",children:[t==null?void 0:t.income_currency," ",Number((t==null?void 0:t.income)||0).toFixed(2)," / ",t==null?void 0:t.ad_spend_currency," ",Number((t==null?void 0:t.ad_spend)||0).toFixed(2)]})]})]}),e.jsxs("div",{className:"mt-3 flex items-center justify-end gap-2",children:[e.jsxs(Z,{variant:"outline",size:"sm",className:"border-[hsl(var(--royaltix-card-border))] text-[hsl(var(--royaltix-text-secondary))]",onClick:()=>v(t),children:[e.jsx(Ae,{className:"mr-2 h-4 w-4"})," Edit"]}),e.jsxs(Z,{variant:"outline",size:"sm",className:"border-[hsl(var(--royaltix-card-border))] text-[hsl(var(--royaltix-text-secondary))]",onClick:()=>I(t),children:[e.jsx(Me,{className:"mr-2 h-4 w-4"})," Copy"]}),e.jsxs(Z,{variant:"outline",size:"sm",className:"border-rose-500/40 text-rose-300",onClick:()=>p(t.id),children:[e.jsx(Ee,{className:"mr-2 h-4 w-4"})," Del"]})]})]})]})})},ne=({date:t,entries:n,zebra:h=!1})=>{const j=!!J[t||""];let m=0,f=0,P=0,g=0,T=0,q=0,W=0,G=0;
1(n||[]).forEach(d=>{const i=d&&d.eur_to_usd_rate_at_entry!=null&&!isNaN(Number(d.eur_to_usd_rate_at_entry))?Number(d.eur_to_usd_rate_at_entry):o,b=D(d.income,d.income_currency,z,i),w=D(d.ad_spend,d.ad_spend_currency,z,i);m+=b,f+=w;const S=d&&d.orders!=null&&!isNaN(Number(d.orders))?Number(d.orders):null,de=d&&d.ad_orders!=null&&!isNaN(Number(d.ad_orders))?Number(d.ad_orders):null;S!=null&&(T+=Math.round(S),W+=1),de!=null&&(q+=Math.round(de),G+=1);const ie=d&&d.ad_acos!=null&&!isNaN(Number(d.ad_acos))?Number(d.ad_acos):null;ie!=null&&(P+=ie,g+=1)});const te=m-f,H=te<0,K=f>0?m/f:0,M=g>0?P/g:m>0&&f>0?f/m*100:null,Q=W>0?Math.max(0,Math.round(T)-Math.round(q)):null,X=t&&ae(A(t))?A(t):null,se=X?oe(X,"dd"):"â",le=X?oe(X,"MMM"):"â",ce=X?oe(X,"EEE"):"",s=Array.from(new Set((n||[]).map(d=>N[d.account_id]||"N/A"))),a=s.length===1?s[0]:`${s[0]} +${s.length-1}`;let l="text-[hsl(var(--royaltix-text-muted))]",y="bg-[hsl(var(--royaltix-card-bg)_/_0.35)] border-[hsl(var(--royaltix-card-border)_/_0.7)]";return M!=null&&!isNaN(M)&&(M<=25?(l="text-emerald-300",y="bg-emerald-500/10 border-emerald-500/30"):M<=40?(l="text-yellow-300",y="bg-yellow-500/10 border-yellow-500/30"):(l="text-rose-300",y="bg-rose-500/10 border-rose-500/30")),e.jsxs("div",{className:"rounded-xl border border-dashed overflow-hidden shadow-sm "+(H?h?"border-rose-500/45 bg-rose-500/16":"border-rose-500/40 bg-rose-500/12":h?"border-[hsl(var(--royaltix-accent)_/_0.75)] bg-[hsl(var(--royaltix-accent)_/_0.18)]":"border-[hsl(var(--royaltix-accent)_/_0.70)] bg-[hsl(var(--royaltix-accent)_/_0.14)]"),children:[e.jsx("button",{type:"button",onClick:()=>ue(d=>({...d,[t||""]:!d[t||""]})),className:"w-full text-left p-3",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsxs("div",{className:"shrink-0 rounded-xl border border-[hsl(var(--royaltix-card-border)_/_0.75)] bg-[hsl(var(--royaltix-card-bg)_/_0.35)] px-3 py-2",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.18em] text-[hsl(var(--royaltix-text-muted))]",children:le}),e.jsx("div",{className:"text-2xl leading-none font-extrabold tabular-nums text-[hsl(var(--royaltix-text-primary))]",children:se}),e.jsx("div",{className:"mt-1 text-[10px] text-[hsl(var(--royaltix-text-muted))]",children:ce})]}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"inline-flex items-center rounded-full border px-2 py-0.5 text-[10px] font-extrabold tracking-[0.14em] uppercase "+(H?"border-rose-500/40 bg-rose-500/18 text-rose-100":"border-[hsl(var(--royaltix-accent)_/_0.55)] bg-[hsl(var(--royaltix-accent)_/_0.18)] text-[hsl(var(--royaltix-text-primary))]"),children:"Grouped day"}),e.jsx("span",{className:"truncate text-[15px] font-extrabold text-[hsl(var(--royaltix-text-primary))]",children:a})]}),e.jsxs("div",{className:"mt-0.5 text-[11px] font-semibold text-[hsl(var(--royaltix-text-secondary))]",children:["Day totals ⢠",(n||[]).length," entries"]})]}),e.jsxs("div",{className:"shrink-0 inline-flex items-center gap-1 rounded-full border bg-[hsl(var(--royaltix-card-bg)_/_0.35)] px-2.5 py-1 text-[11px] font-extrabold "+(H?"border-rose-500/40 text-rose-100":"border-[hsl(var(--royaltix-accent)_/_0.45)] text-[hsl(var(--royaltix-text-primary))]"),children:[e.jsx("span",{children:j?"Hide":"Show"}),j?e.jsx(Te,{className:"h-3.5 w-3.5 text-[hsl(var(--royaltix-text-muted))]"}):e.jsx(ge,{className:"h-3.5 w-3.5 text-[hsl(var(--royaltix-text-muted))]"})]})]}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[e.jsxs("span",{className:"inline-flex items-center rounded-full border border-[hsl(var(--royaltix-card-border)_/_0.7)] bg-[hsl(var(--royaltix-card-bg)_/_0.35)] px-2 py-1 text-[11px] font-semibold text-[hsl(var(--royaltix-text-secondary))] tabular-nums",children:["Orders ",W>0?Math.round(T):"â"]}),e.jsxs("span",{className:"inline-flex items-center rounded-full border border-orange-500/30 bg-
1orange-500/10 px-2 py-1 text-[11px] font-semibold text-orange-200 tabular-nums",children:["Ad ",G>0?Math.round(q):"â"]}),e.jsxs("span",{className:"inline-flex items-center rounded-full border border-emerald-500/30 bg-emerald-500/10 px-2 py-1 text-[11px] font-semibold text-emerald-200 tabular-nums",children:["Org ",Q!=null?Math.round(Q):"â"]})]}),e.jsxs("div",{className:"mt-2 grid grid-cols-3 gap-2",children:[e.jsxs("div",{className:"rounded-xl border border-emerald-500/25 bg-emerald-500/10 p-2",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.16em] text-emerald-200/80",children:"Income"}),e.jsxs("div",{className:"mt-0.5 text-[14px] font-bold tabular-nums text-emerald-200",children:[k,m.toFixed(2)]})]}),e.jsxs("div",{className:"rounded-xl border border-rose-500/25 bg-rose-500/10 p-2",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.16em] text-rose-200/80",children:"Spend"}),e.jsxs("div",{className:"mt-0.5 text-[14px] font-bold tabular-nums text-rose-200",children:[k,f.toFixed(2)]})]}),e.jsxs("div",{className:`rounded-xl border p-2 ${te>=0?"border-emerald-500/25 bg-emerald-500/10":"border-rose-500/25 bg-rose-500/10"}`,children:[e.jsx("div",{className:`text-[10px] uppercase tracking-[0.16em] ${te>=0?"text-emerald-200/80":"text-rose-200/80"}`,children:"Profit"}),e.jsxs("div",{className:`mt-0.5 text-[14px] font-bold tabular-nums ${te>=0?"text-emerald-200":"text-rose-200"}`,children:[k,te.toFixed(2)]})]})]}),e.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[e.jsxs("span",{className:"inline-flex items-center rounded-full border border-sky-500/30 bg-sky-500/10 px-2 py-1 text-[11px] font-semibold text-sky-200 tabular-nums",children:["ROAS ",K.toFixed(2),"x"]}),e.jsxs("span",{className:`inline-flex items-center rounded-full border px-2 py-1 text-[11px] font-semibold tabular-nums ${l} ${y}`,children:["ACOS ",M!=null&&!isNaN(M)?`${M.toFixed(1)}%`:"â"]})]})]})]})}),j?e.jsx("div",{className:"px-3 pb-3 space-y-3",children:(n||[]).map((d,i)=>e.jsx(u,{entry:d,zebra:i%2===1},d.id))}):null]})},B=t=>{let n="ascending";R.key===t&&R.direction==="ascending"&&(n="descending"),xe({key:t,direction:n})},C=t=>R.key===t?R.direction==="ascending"?" â²":" â¼":"",U=t=>{const n=t&&t.eur_to_usd_rate_at_entry!=null&&!isNaN(Number(t.eur_to_usd_rate_at_entry))?Number(t.eur_to_usd_rate_at_entry):o,h=D(t.income,t.income_currency,z,n),j=D(t.ad_spend,t.ad_spend_currency,z,n),m=h-j,f=j>0?h/j:0,P=m>0,g=t&&t.ad_acos!=null&&!isNaN(Number(t.ad_acos))?Number(t.ad_acos):null,T=t&&t.orders!=null&&!isNaN(Number(t.orders))?Number(t.orders):null,q=t&&t.ad_orders!=null&&!isNaN(Number(t.ad_orders))?Number(t.ad_orders):null,W=T!=null?Math.max(0,Math.round(T)-(q!=null?Math.round(q):0)):null;let G="text-[hsl(var(--royaltix-text-muted))]";return g!=null&&!isNaN(g)&&(g<=25?G="text-green-400 font-semibold":g<=40?G="text-yellow-400 font-semibold":G="text-red-400 font-semibold"),e.jsxs(_e,{className:`group border-b-[hsl(var(--royaltix-border-subtle))] hover:bg-[hsl(var(--royaltix-primary)_/_0.05)] hover:shadow-sm transition-colors duration-200 ${P?"bg-green-500/5":"bg-red-500/5"}`,children:[e.jsx(F,{className:"text-[hsl(var(--royaltix-text-primary))]",children:t.date&&ae(A(t.date))?oe(A(t.date),"MMM dd, yyyy"):"Invalid Date"}),e.jsx(F,{className:"text-[hsl(var(--royaltix-text-primary))]",children:N[t.account_id]||"N/A"}),e.jsx(F,{className:"text-[hsl(var(--royaltix-text-primary))] font-medium tabular-nums",children:T!=null?Math.round(T):"â"}),e.jsx(F,{className:"text-orange-300 font-semibold tabular-nums",children:q!=null?Math.round(q):"â"}),e.jsx(F,{className:"text-emerald-300 font-semibold tabular-nums",children:W!=null?Math.round(W):"â"}),e.jsxs(F,{className:"text-green-400",children:[e.jsxs(Re,{children:[e.jsx($e,{asChild:!0,children:e.jsxs("span",{className:"inline-block transition-transform duration-200 group-hover:-translate-y-0.5",children:[k,h.toFixed(2)]})}),e.jsx(Le,{side:"top",children:e.jsxs("span",{className:"text-xs text-[hsl(var(--royaltix-text-secondary))]",children:["FX at entry: 1 EUR = ",Number(n).toFixed(4)," USD"]})})]}),e.jsxs("span",{className:"text-xs text-[hsl(var(--royaltix-text-muted))] ml-1",children:["(",t.income_currency," ",Number(t.income).toFixed(2),")"]})]}),e.jsxs(F,{className:"text-red-400",children:[e.jsxs(Re,{children:[e.jsx($e,{asChild:!0,children:e.jsxs("span",{className:"inline-block transition-transform duration-200 group-hover:-translate-y-0.5",children:[k,j.toFixed(2)]})}),e.jsx(Le,{side:"top",children:e.jsxs("span",{className:"text-xs text-[hsl(var(--royaltix-text-secondary))]",children:["FX at entry: 1 EUR = ",Number(n).toFixed(4)," USD"]})})]}),e.jsxs("span",{className:"text-xs text-[hsl(var(--royaltix-text-muted))] ml-1",children:["(",t.ad_spend_currency," ",Number(t.ad_spend).toFixed(2),")"]})]}),e.jsxs(F,{className:m>=0?"text-green-400 font-semibold":"text-red-400 font-semibold",children:[k,m.toFixed(2),m>50&&e.jsx(we,{className:"inline ml-1 h-4 w-4 text-green-500"}),m<-10&&e.jsx(ke,{className:"inline ml-1 h-4 w-4 text-red-500"})]}),e.jsxs(F,{className:"text-blue-400",children:[f.toFixed(2),"x"]}),e.jsx(F,{className:G,children:g!=null&&!isNaN(g)?e.jsxs(e.Fragment,{children:[g.toFixed(1),"%",g<=25&&e.jsx(ke,{className:"inline ml-1 h-4 w-4 text-green-400"}),g>40&&e.jsx(we,{className:"inline ml-1 h-4 w-4 text-red-500"})]}):"â"}),e.jsx(F,{children:e.jsxs("div",{className:"flex space-x-1",children:[e.jsx(Z,{variant:"ghost",size:"icon",onClick:()=>v(t),className:"hover:text-[hsl(var(--royaltix-accent))] text-[hsl(var(--royaltix-text-muted))] transition-transform duration-200 hover:scale-110",children:e.jsx(Ae,{className:"h-4 w-4"})}),e.jsx(Z,{variant:"ghost",size:"icon",onClick:()=>p(t.id),className:"hover:text-red-500 text-[hsl(var(--royaltix-text-muted))] transition-transform duration-200 hover:scale-110",children:e.jsx(Ee,{className:"h-4 w-4"})}),e.jsx(Z,{variant:"ghost",size:"icon",onClick:()=>I(t),className:"hover:text-blue-500 text-[hsl(var(--royaltix-text-muted))] transition-transform duration-200 hover:scale-110",children:e.jsx(Me,{className:"h-4 w-4"})})]})})]},t.id)},_={date:"Date",account_id:"Account",orders:"Orders",ad_orders:"Ad Orders",organic_orders:"Organic Orders",income:"Income",ad_spend:"Ad Spend",profit:"Profit",roas:"ROAS",ad_acos:"ACOS"};return e.jsxs(dt.div,{initial:{opacity:0}
1,animate:{opacity:1},transition:{duration:.5},children:[e.jsx("div",{className:"sm:hidden",children:e.jsxs("div",{className:"space-y-2",children:[L.map((t,n)=>{if(t.type==="group"){const h=t.date||`group-${n}`;return e.jsx(ne,{date:t.date,entries:t.entries,zebra:n%2===1},h)}return e.jsx(u,{entry:t.entry,zebra:n%2===1},t.entry.id)}),L.length===0&&e.jsx("div",{className:"rounded-xl border border-[hsl(var(--royaltix-card-border))] bg-[hsl(var(--royaltix-card-bg)_/_0.4)] p-6 text-center text-sm text-[hsl(var(--royaltix-text-muted))]",children:"No entries match your current filters. Try adjusting your search or date range!"})]})}),e.jsx("div",{className:"hidden sm:block",children:e.jsx("div",{className:"overflow-x-auto rounded-lg border border-[hsl(var(--royaltix-card-border))] bg-[hsl(var(--royaltix-card-bg)_/_0.5)]",children:e.jsx(bt,{children:e.jsxs(Tt,{children:[e.jsx(Rt,{children:e.jsxs(_e,{className:"border-b-[hsl(var(--royaltix-card-border))]",children:[["date","account_id","orders","ad_orders","organic_orders","income","ad_spend","profit","roas","ad_acos"].map(t=>e.jsxs(lt,{onClick:()=>B(t),className:"cursor-pointer hover:text-[hsl(var(--royaltix-primary))] text-[hsl(var(--royaltix-text-secondary))] transition-colors duration-200",children:[_[t]||t,C(t)]},t)),e.jsx(lt,{className:"text-[hsl(var(--royaltix-text-secondary))]",children:"Actions"})]})}),e.jsxs($t,{children:[L.map((t,n)=>{if(t.type==="group"){const h=t.date||`group-${n}`,j=!!J[t.date||""];let m=0,f=0,P=0,g=0,T=0,q=0,W=0,G=0;t.entries.forEach(s=>{const a=s&&s.eur_to_usd_rate_at_entry!=null&&!isNaN(Number(s.eur_to_usd_rate_at_entry))?Number(s.eur_to_usd_rate_at_entry):o,l=D(s.income,s.income_currency,z,a),y=D(s.ad_spend,s.ad_spend_currency,z,a);m+=l,f+=y;const d=s&&s.orders!=null&&!isNaN(Number(s.orders))?Number(s.orders):null,i=s&&s.ad_orders!=null&&!isNaN(Number(s.ad_orders))?Number(s.ad_orders):null;d!=null&&(T+=Math.round(d),W+=1),i!=null&&(q+=Math.round(i),G+=1);const b=s&&s.ad_acos!=null&&!isNaN(Number(s.ad_acos))?Number(s.ad_acos):null;b!=null&&(P+=b,g+=1)});const te=m-f,H=f>0?m/f:0,K=g>0?P/g:m>0&&f>0?f/m*100:null,M=W>0?Math.max(0,Math.round(T)-Math.round(q)):null;let Q="text-[hsl(var(--royaltix-text-muted))]";K!=null&&!isNaN(K)&&(K<=25?Q="text-green-400 font-semibold":K<=40?Q="text-yellow-400 font-semibold":Q="text-red-400 font-semibold");const X=t.date&&ae(A(t.date))?oe(A(t.date),"MMM dd, yyyy"):"Invalid Date",se=Array.from(new Set(t.entries.map(s=>N[s.account_id]||"N/A"))),le=se.length===1?se[0]:`${se[0]} +${se.length-1} more`,ce=te>0;return e.jsxs(Nt.Fragment,{children:[e.jsxs(_e,{className:`group border-b-[hsl(var(--royaltix-border-subtle))] cursor-pointer hover:bg-[hsl(var(--royaltix-primary)_/_0.08)] hover:shadow-sm transition-colors duration-200 ${ce?"bg-green-500/10":"bg-red-500/10"}`,onClick:()=>ue(s=>({...s,[t.date||""]:!s[t.date||""]})),children:[e.jsx(F,{className:"text-[hsl(var(--royaltix-text-primary))]",children:e.jsxs("div",{className:"flex items-center gap-2",children:[j?e.jsx(Te,{className:"h-4 w-4 text-[hsl(var(--royaltix-text-muted))]"}):e.jsx(ge,{className:"h-4 w-4 text-[hsl(var(--royaltix-text-muted))]"}),e.jsx("span",{children:X}),e.jsxs("span",{className:"text-xs text-[hsl(var(--royaltix-text-muted))]",children:[t.entries.length," entries"]})]})}),e.jsx(F,{className:"text-[hsl(var(--royaltix-text-primary))]",children:le}),e.jsx(F,{className:"text-[hsl(var(--royaltix-text-primary))] font-semibold tabular-nums",children:W>0?Math.round(T):"â"}),e.jsx(F,{className:"text-orange-300 font-semibold tabular-nums",children:G>0?Math.round(q):"â"}),e.jsx(F,{className:"text-emerald-300 font-semibold tabular-nums",children:M!=null?Math.round(M):"â"}),e.jsxs(F,{className:"text-green-400 font-semibold",children:[k,m.toFixed(2)]}),e.jsxs(F,{className:"text-red-400 font-semibold",children:[k,f.toFixed(2)]}),e.jsxs(F,{className:te>=0?"text-green-400 font-semibold":"text-red-400 font-semibold",children:[k,te.toFixed(2)]}),e.jsxs(F,{className:"text-blue-400 font-semibold",children:[H.toFixed(2),"x"]}),e.jsx(F,{className:Q,children:K!=null&&!isNaN(K)?`${K.toFixed(1)}%`:"â"}),e.jsx(F,{className:"text-right text-xs text-[hsl(var(--royaltix-text-muted))] pr-4",children:j?"Click to collapse":"Click to expand"})]}),j&&t.entries.map(s=>U(s))]},h)}return U(t.entry)}),L.length===0&&e.jsx(_e,{children:e.jsx(F,{colSpan:11,className:"text-center text-[hsl(var(--royaltix-text-muted))] py-10",children:"No entries match your current filters. Try adjusting your search or date range!"})})]})]})})})}),V>1&&e.jsx(it,{className:"mt-6",children:e.jsxs(ct,{className:"flex-wrap",children:[e.jsx(je,{children:e.jsx(xt,{href:"#",onClick:t=>{t.preventDefault(),re(n=>Math.max(1,n-1))},disabled:$===1})}),O(V,$).map((t,n)=>e.jsx(je,{children:t==="ellipsis"?e.jsx(ut,{}):e.jsx(Se,{href:"#",onClick:h=>{h.preventDefault(),re(t)},isActive:$===t,children:t})},`${t}-${n}`)),e.jsx(je,{children:e.jsx(mt,{href:"#",onClick:t=>{t.preventDefault(),re(n=>Math.min(V,n+1))},disabled:$===V})})]})})]})}
1,zt=({entries:c,displayCurrency:r,eurToUsdRate:v,lastFxUpdatedAt:p,grossWithholdingPercent:I=0,adVatPercent:o=0})=>{const{convertAmount:z}=Pe(r),xe=(()=>{if(!c||c.length===0)return{score:0,message:"Start logging to see consistency!"};const O=c.map(U=>U.date&&ae(A(U.date))?A(U.date):null).filter(Boolean).sort((U,_)=>U-_);if(O.length===0)return{score:0,message:"No valid dates in entries."};let u=0;const ne=new Set(O.map(U=>oe(U,"yyyy-MM-dd"))).size;if(u+=Math.min(50,ne*2),O.length>1){const U=Ke(O[O.length-1],O[0])+1,_=Math.max(1,Math.floor(U/7)),t=ne/Math.max(1,_);u+=Math.min(30,t*10);const n=Ke(new Date,O[O.length-1]);n<=7?u+=20:n<=14&&(u+=10)}else u+=10;const B=Math.min(100,Math.round(u));let C="Good job logging!";return B>=80?C="Excellent consistency!":B>=50?C="Good consistency, keep it up!":B>=20?C="Getting started, log more regularly!":C="Log more consistently for better insights!",{score:B,message:C}})(),pe=c.reduce((O,u)=>{const ne=u&&u.eur_to_usd_rate_at_entry!=null&&!isNaN(Number(u.eur_to_usd_rate_at_entry))?Number(u.eur_to_usd_rate_at_entry):v;return O+z(u.income,u.income_currency,r,ne)},0),Y=c.reduce((O,u)=>{const ne=u&&u.eur_to_usd_rate_at_entry!=null&&!isNaN(Number(u.eur_to_usd_rate_at_entry))?Number(u.eur_to_usd_rate_at_entry):v;return O+z(u.ad_spend,u.ad_spend_currency,r,ne)},0),ee=typeof I=="number"&&isFinite(I)&&I>0?I:0,$=ee>0?pe*ee/100:0,re=pe-$,D=typeof o=="number"&&isFinite(o)&&o>0?o:0,k=D>0?Y*D/100:0,N=Y+k,J=N>0?pe/N:0,ue=c.reduce((O,u)=>(u&&u.ad_acos!=null&&!isNaN(Number(u.ad_acos))&&(O.sum+=Number(u.ad_acos),O.count+=1),O),{sum:0,count:0}),E=ue.count>0?ue.sum/ue.count:null;let V="text-[hsl(var(--royaltix-text-muted))]";E!=null&&!isNaN(E)&&(E<=25?V="text-green-400 font-semibold":E<=40?V="text-yellow-400 font-semibold":V="text-red-400 font-semibold");const L=r==="EUR"?"â¬":"$";return!c||c.length===0?e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-4 gap-4 mb-6",children:[e.jsxs(me,{className:"bg-[hsl(var(--royaltix-card-bg)_/_0.7)] border-[hsl(var(--royaltix-card-border))] p-4",children:[e.jsx(he,{className:"text-sm font-medium text-[hsl(var(--royaltix-text-secondary))]",children:"Total Entries"}),e.jsx("p",{className:"text-2xl font-bold text-[hsl(var(--royaltix-text-primary))]",children:"0"}),e.jsx(vt,{className:"h-5 w-5 text-[hsl(var(--royaltix-text-muted))] mt-1"})]}),e.jsxs(me,{className:"bg-[hsl(var(--royaltix-card-bg)_/_0.7)] border-[hsl(var(--royaltix-card-border))] p-4",children:[e.jsx(he,{className:"text-sm font-medium text-[hsl(var(--royaltix-text-secondary))]",children:"Log Consistency"}),e.jsx("p",{className:"text-2xl font-bold text-[hsl(var(--royaltix-text-muted))]",children:"0/100"}),e.jsx("p",{className:"text-xs text-[hsl(var(--royaltix-text-muted))]",children:"No entries to analyze."})]}),e.jsxs(me,{className:"bg-[hsl(var(--royaltix-card-bg)_/_0.7)] border-[hsl(var(--royaltix-card-border))] p-4",children:[e.jsxs(he,{className:"text-sm font-medium text-[hsl(var(--royaltix-text-secondary))]",children:["Quick Summary (",r,")"]}),e.jsxs("p",{className:"text-lg font-semibold text-gray-400 flex items-center",children:[e.jsx(we,{className:"h-4 w-4 mr-1"})," Income: ",L,"0.00"]}),e.jsxs("p",{className:"text-lg font-semibold text-gray-400 flex items-center",children:[e.jsx(ke,{className:"h-4 w-4 mr-1"})," Ad Spend: ",L,"0.00"]})]}),e.jsx("div",{className:"hidden md:block",children:e.jsx(ot,{rate:Number(v),updatedAt:p,title:"EURâUSD"})})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"sm:hidden mb-3",children:e.jsxs(me,{className:"bg-[hsl(var(--royaltix-card-bg)_/_0.55)] border-[hsl(var(--royaltix-card-border))] p-3",children:[e.jsxs("div",{className:"flex gap-2 overflow-x-auto pb-1",children:[e.jsxs("div",{className:"shrink-0 min-w-[140px] rounded-xl border border-[hsl(var(--royaltix-card-border)_/_0.8)] bg-[hsl(var(--royaltix-card-bg)_/_0.35)] p-2",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.18em] text-[hsl(var(--royaltix-text-muted))]",children:"Entries"}),e.jsx("div",{className:"mt-0.5 text-[18px] font-extrabold tabular-nums text-[hsl(var(--royaltix-text-primary))]",children:c.length})]}),e.jsxs("div",{className:"shrink-0 min-w-[170px] rounded-xl border border-[hsl(var(--royaltix-card-border)_/_0.8)] bg-[hsl(var(--royaltix-card-bg)_/_0.35)] p-2",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.18em] text-[hsl(var(--royaltix-text-muted))]",children:"Consistency"}),e.jsxs("div",{className:"mt-0.5 text-[18px] font-extrabold tabular-nums text-[hsl(var(--royaltix-primary))]",children:[xe.score,"/100"]}),e.jsx("div",{className:"mt-0.5 text-[11px] text-[hsl(var(--royaltix-text-muted))] truncate",children:xe.message})]}),e.jsxs("div",{className:"shrink-0 min-w-[190px] rounded-xl border border-emerald-500/25 bg-emerald-500/10 p-2",children:[e.jsxs("div",{className:"text-[10px] uppercase tracking-[0.18em] text-emerald-200/80",children:["Income (",r,")"]}),e.jsxs("div",{className:"mt-0.5 text-[18px] font-extrabold tabular-nums text-emerald-200",children:[L,re.toFixed(2)]})]}),e.jsxs("div",{className:"shrink-0 min-w-[190px] rounded-xl border border-rose-500/25 bg-rose-500/10 p-2",children:[e.jsxs("div",{className:"text-[10px] uppercase tracking-[0.18em] text-rose-200/80",children:["Spend (",r,")"]}),e.jsxs("div",{className:"mt-0.5 text-[18px] font-extrabold tabular-nums text-rose-200",children:[L,N.toFixed(2)]})]}),e.jsxs("div",{className:"shrink-0 min-w-[150px] rounded-xl border border-sky-500/25 bg-sky-500/10 p-2",children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.18em] text-sky-200/80",children:"ROAS"}),e.jsxs("div",{className:"mt-0.5 text-[18px] font-extrabold tabular-nums text-sky-200",children:[J.toFixed(2),"x"]})]}),e.jsxs("div",{className:`shrink-0 min-w-[160px] rounded-xl border p-2 ${E!=null&&!isNaN(E)?E<=25?"border-emerald-500/25 bg-emerald-500/10":E<=40?"border-yellow-500/25 bg-yellow-500/10":"border-rose-500/25 bg-rose-500/10":"border-[hsl(var(--royaltix-card-border)_/_0.8)] bg-[hsl(var(--royaltix-card-bg)_/_0.35)]"}`,children:[e.jsx("div",{className:"text-[10px] uppercase tracking-[0.18em] text-[hsl(var(--royaltix-text-muted))]",children:"Avg ACOS"}),e.jsx("div",{className:`mt-0.5 text-[18px] font-extrabold tabular-nums ${V}`,children:E!=null&&!isNaN(E)?`${E.toFixed(1)}%`:"â"})]})]}),ee>0||D>0?e.jsxs("div",{className:"mt-2 text-[11px] text-[hsl(var(--royaltix-text-muted))]",children:[ee>0?`Withheld (${ee.toFixed(1)}%): ${L}${$.toFixed(2)}`:"",ee>0&&D>0?" · ":"",D>0?`Ad VAT (${D.toFixed(1)}%): ${L}${k.toFixed(2)}`:""]}):null]})}),e.jsxs("div",{className:"hidden sm:grid grid-cols-2 lg:grid-cols-5 ga
1p-2 sm:gap-4 mb-3 sm:mb-6",children:[e.jsxs(me,{className:"bg-[hsl(var(--royaltix-card-bg)_/_0.65)] border-[hsl(var(--royaltix-card-border))] p-3 sm:p-4",children:[e.jsx(he,{className:"text-[11px] font-semibold text-[hsl(var(--royaltix-text-secondary))]",children:"Total Entries"}),e.jsx("p",{className:"text-xl sm:text-2xl font-extrabold text-[hsl(var(--royaltix-text-primary))]",children:c.length}),e.jsx(gt,{className:"h-4 w-4 text-[hsl(var(--royaltix-accent))] mt-1"})]}),e.jsxs(me,{className:"bg-[hsl(var(--royaltix-card-bg)_/_0.65)] border-[hsl(var(--royaltix-card-border))] p-3 sm:p-4",children:[e.jsx(he,{className:"text-[11px] font-semibold text-[hsl(var(--royaltix-text-secondary))]",children:"Consistency"}),e.jsxs("p",{className:"text-xl sm:text-2xl font-extrabold text-[hsl(var(--royaltix-primary))]",children:[xe.score,"/100"]}),e.jsx("p",{className:"text-[11px] text-[hsl(var(--royaltix-text-muted))] leading-snug",children:xe.message})]}),e.jsxs(me,{className:"col-span-2 sm:col-span-1 bg-[hsl(var(--royaltix-card-bg)_/_0.65)] border-[hsl(var(--royaltix-card-border))] p-3 sm:p-4",children:[e.jsxs(he,{className:"text-[11px] font-semibold text-[hsl(var(--royaltix-text-secondary))] mb-1",children:["Summary (",r,")"]}),e.jsxs("p",{className:"text-[12px] sm:text-base font-semibold text-green-400 flex items-center",children:[e.jsx(we,{className:"h-4 w-4 mr-1"}),e.jsx("span",{className:"opacity-80",children:"Income:"}),e.jsxs("span",{className:"ml-1",children:[L,re.toFixed(2)]})]}),e.jsxs("p",{className:"mt-1 text-[12px] sm:text-base font-semibold text-red-400 flex items-center",children:[e.jsx(ke,{className:"h-4 w-4 mr-1"}),e.jsx("span",{className:"opacity-80",children:"Ad Spend:"}),e.jsxs("span",{className:"ml-1",children:[L,N.toFixed(2)]})]}),ee>0&&e.jsxs("p",{className:"mt-1 text-[11px] text-[hsl(var(--royaltix-text-muted))]",children:["Withheld (",ee.toFixed(1),"%): ",L,$.toFixed(2)]}),D>0&&e.jsxs("p",{className:"mt-0.5 text-[11px] text-[hsl(var(--royaltix-text-muted))]",children:["Ad VAT (",D.toFixed(1),"%): ",L,k.toFixed(2)]})]}),e.jsxs(me,{className:"bg-[hsl(var(--royaltix-card-bg)_/_0.65)] border-[hsl(var(--royaltix-card-border))] p-3 sm:p-4",children:[e.jsx(he,{className:"text-[11px] font-semibold text-[hsl(var(--royaltix-text-secondary))]",children:"Efficiency"}),e.jsxs("div",{className:"mt-2 space-y-1 text-xs sm:text-sm",children:[e.jsxs("div",{className:"flex items-baseline justify-between",children:[e.jsx("span",{className:"text-[hsl(var(--royaltix-text-muted))] tracking-[0.16em] uppercase",children:"ROAS"}),e.jsxs("span",{className:"text-blue-400 font-semibold text-base sm:text-lg",children:[J.toFixed(2),"x"]})]}),e.jsxs("div",{className:"flex items-baseline justify-between",children:[e.jsx("span",{className:"text-[hsl(var(--royaltix-text-muted))] tracking-[0.16em] uppercase",children:"Avg ACOS"}),e.jsx("span",{className:`${V} text-base sm:text-lg`,children:E!=null&&!isNaN(E)?`${E.toFixed(1)}%`:"â"})]})]})]}),e.jsx("div",{className:"hidden md:block",children:e.jsx(ot,{rate:Number(v),updatedAt:p,title:"EURâUSD"})})]})]})},Bt=({filters:c,setFilters:r,accounts:v})=>{const p=(o,z)=>{r(R=>({...R,[o]:z}))},I=()=>{r({searchTerm:"",accountId:"all",startDate:null,endDate:null})};return e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"sm:hidden mb-3",children:e.jsx("div",{className:"p-3 rounded-xl bg-[hsl(var(--royaltix-card-bg)_/_0.45)] border border-[hsl(var(--royaltix-card-border))]",children:e.jsxs("div",{className:"flex gap-2 overflow-x-auto pb-1",children:[e.jsxs("div",{className:"relative shrink-0 min-w-[210px]",children:[e.jsx(ze,{type:"text",placeholder:"Search...",value:c.searchTerm,onChange:o=>p("searchTerm",o.target.value),className:"h-9 pl-9 text-sm bg-[hsl(var(--royaltix-input-bg))] border-[hsl(var(--royaltix-card-border))] focus:border-[hsl(var(--royaltix-primary))]"}),e.jsx(Be,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-[hsl(var(--royaltix-text-muted))]"})]}),e.jsx("div",{className:"shrink-0 min-w-[170px]",children:e.jsxs(Ve,{value:c.accountId||"all",onValueChange:o=>p("accountId",o==="all"?"all":o),children:[e.jsx(qe,{className:"h-9 text-sm bg-[hsl(var(--royaltix-input-bg))] border-[hsl(var(--royaltix-card-border))] focus:border-[hsl(var(--royaltix-primary))]",children:e.jsx(Ue,{placeholder:"Account"})}),e.jsxs(Ge,{children:[e.jsx(fe,{value:"all",children:"All Accounts"}),v.map(o=>e.jsx(fe,{value:o.id,children:o.name},o.id))]})]})}),e.jsx("div",{className:"shrink-0 min-w-[150px]",children:e.jsx(ye,{date:c.startDate,
1setDate:o=>p("startDate",o),placeholderText:"Start",buttonClassName:"w-full h-9 text-sm bg-[hsl(var(--royaltix-input-bg))] border-[hsl(var(--royaltix-card-border))] focus:border-[hsl(var(--royaltix-primary))]"})}),e.jsx("div",{className:"shrink-0 min-w-[150px]",children:e.jsx(ye,{date:c.endDate,setDate:o=>p("endDate",o),placeholderText:"End",buttonClassName:"w-full h-9 text-sm bg-[hsl(var(--royaltix-input-bg))] border-[hsl(var(--royaltix-card-border))] focus:border-[hsl(var(--royaltix-primary))]"})}),e.jsxs(Z,{onClick:I,variant:"outline",className:"h-9 shrink-0 px-3 border-[hsl(var(--royaltix-card-border))] hover:border-[hsl(var(--royaltix-accent))] text-[hsl(var(--royaltix-text-secondary))]",children:[e.jsx(nt,{className:"mr-2 h-4 w-4"})," Reset"]})]})})}),e.jsx("div",{className:"hidden sm:block mb-3 sm:mb-4 p-3 sm:p-4 rounded-xl bg-[hsl(var(--royaltix-card-bg)_/_0.45)] border border-[hsl(var(--royaltix-card-border))]",children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-2 sm:gap-4 items-end",children:[e.jsxs("div",{className:"relative",children:[e.jsx(ze,{type:"text",placeholder:"Search entries...",value:c.searchTerm,onChange:o=>p("searchTerm",o.target.value),className:"h-9 pl-10 text-sm bg-[hsl(var(--royaltix-input-bg))] border-[hsl(var(--royaltix-card-border))] focus:border-[hsl(var(--royaltix-primary))]"}),e.jsx(Be,{className:"absolute left-3 top-1/2 transform -translate-y-1/2 h-4 w-4 text-[hsl(var(--royaltix-text-muted))]"})]}),e.jsxs(Ve,{value:c.accountId||"all",onValueChange:o=>p("accountId",o==="all"?"all":o),children:[e.jsx(qe,{className:"h-9 text-sm bg-[hsl(var(--royaltix-input-bg))] border-[hsl(var(--royaltix-card-border))] focus:border-[hsl(var(--royaltix-primary))]",children:e.jsx(Ue,{placeholder:"Filter by Account"})}),e.jsxs(Ge,{children:[e.jsx(fe,{value:"all",children:"All Accounts"}),v.map(o=>e.jsx(fe,{value:o.id,children:o.name},o.id))]})]}),e.jsx(ye,{date:c.startDate,setDate:o=>p("startDate",o),placeholderText:"Start Date",buttonClassName:"w-full h-9 text-sm bg-[hsl(var(--royaltix-input-bg))] border-[hsl(var(--royaltix-card-border))] focus:border-[hsl(var(--royaltix-primary))]"}),e.jsx(ye,{date:c.endDate,setDate:o=>p("endDate",o),placeholderText:"End Date",buttonClassName:"w-full h-9 text-sm bg-[hsl(var(--royaltix-input-bg))] border-[hsl(var(--royaltix-card-border))] focus:border-[hsl(var(--royaltix-primary))]"}),e.jsxs(Z,{onClick:I,variant:"outline",className:"h-9 col-span-full md:col-span-1 lg:col-span-4 border-[hsl(var(--royaltix-card-border))] hover:border-[hsl(var(--royaltix-accent))] text-[hsl(var(--royaltix-text-secondary))]",children:[e.jsx(nt,{className:"mr-2 h-4 w-4"})," Reset Filters"]})]})})]})},Vt=c=>c?`kdpFormNewEntry_${c}`:null,Ie="kdpFormEditEntry-",Yt=()=>{const{supabase:c,user:r}=ft(),{toast:v}=yt(),{userSettings:p,eurToUsdRate:I,displayCurrency:o,lastFxUpdatedAt:z}=_t(),{convertAmount:R}=Pe(o),[xe,pe]=x.useState([]),[Y,ee]=x.useState([]),[$,re]=x.useState(!0),[D,k]=x.useState(!1),[N,J]=x.useState(null),[ue,E]=x.useState(!1),[V,L]=x.useState(null),[O,u]=x.useState(!1),[ne,B]=x.useState(null),[C,U]=x.useState({key:"date",direction:"descending"}),[_,t]=x.useState({searchTerm:"",accountId:"all",startDate:null,endDate:null}),n=x.useMemo(()=>r!=null&&r.id?`kdpLogFilters_${r.id}`:null,[r==null?void 0:r.id]),h=x.useMemo(()=>r!=null&&r.id?`kdpLogSort_${r.id}`:null,[r==null?void 0:r.id]),j=x.useMemo(()=>r!=null&&r.id?`kdpLogPage_${r.id}`:null,[r==null?void 0:r.id]),m=x.useMemo(()=>Vt(r==null?void 0:r.id),[r==null?void 0:r.id]),f=x.useMemo(()=>Y.reduce((s,a)=>(s[a.id]=a.name,s),{}),[Y]);x.useEffect(()=>{const s=()=>
1{if(!m||D)return;const a=localStorage.getItem(m);if(a)try{const l=JSON.parse(a);B(l),J(null),u(!0),k(!0),v({title:"Resuming KDP Entry",description:"We found an unfinished KDP entry draft and have loaded it for you.",action:e.jsx(Xe,{className:"text-blue-500"})})}catch{localStorage.removeItem(m),u(!1),B(null)}else u(!1),B(null)};p&&(r!=null&&r.id)&&!D&&s()},[p,r==null?void 0:r.id,m,D,v]);const P=x.useCallback(async()=>{if(!r||!c)return;re(!0);const s=1e3;let a=[];try{const l=await c.from("kdp_entries").select("id",{count:"exact",head:!0}).eq("user_id",r.id);if(l.error)throw l.error;const y=Number(l.count)||0,d=Math.ceil(y/s);for(let i=0;i<d;i+=1){const b=i*s,w=b+s-1,{data:S,error:de}=await c.from("kdp_entries").select("*").eq("user_id",r.id).order("date",{ascending:!1}).order("created_at",{ascending:!1}).order("id",{ascending:!1}).range(b,w);if(de)throw de;const ie=S||[];a=a.concat(ie)}pe(a)}catch(l){v({title:"Error fetching KDP entries",description:(l==null?void 0:l.message)||"Failed to fetch KDP entries.",variant:"destructive"})}finally{re(!1)}},[r,c,v]),g=x.useCallback(async()=>{if(!r||!c)return;const{data:s,error:a}=await c.from("kdp_accounts").select("id, name, color").eq("user_id",r.id);a?v({title:"Error fetching accounts",description:a.message,variant:"destructive"}):ee(s||[])},[r,c,v]);x.useEffect(()=>{r&&p&&(P(),g())},[r,p,P,g]),x.useEffect(()=>{if(n)try{const s=localStorage.getItem(n);if(s){const a=JSON.parse(s);t({searchTerm:a.searchTerm||"",accountId:a.accountId||"all",startDate:a.startDate?new Date(a.startDate):null,endDate:a.endDate?new Date(a.endDate):null})}}catch(s){console.warn("Failed to load persisted KDP log filters",s)}},[n]),x.useEffect(()=>{if(n)try{const s={searchTerm:_.searchTerm||"",accountId:_.accountId||"all",startDate:_.startDate?_.startDate.toISOString():null,endDate:_.endDate?_.endDate.toISOString():null};localStorage.setItem(n,JSON.stringify(s))}catch(s){console.warn("Failed to persist KDP log filters",s)}},[_,n]),x.useEffect(()=>{if(h)try{const s=localStorage.getItem(h);if(s){const a=JSON.parse(s);a&&a.key&&a.direction&&U({key:a.key,direction:a.direction})}}catch(s){console.warn("Failed to load persisted KDP log sort",s)}},[h]),x.useEffect(()=>{if(h)try{localStorage.setItem(h,JSON.stringify(C))}catch(s){console.warn("Failed to persist KDP log sort",s)}},[C,h]),x.useEffect(()=>{const s=()=>{P(),g()};return window.addEventListener("kdpLogDataRefresh",s),window.addEventListener("kdpAccountDataRefresh",s),()=>{window.removeEventListener("kdpLogDataRefresh",s),window.removeEventListener("kdpAccountDataRefresh",s)}},[P,g]);const T=()=>{J(null),u(!1),B(null),k(!0)},q=s=>{m&&localStorage.removeItem(m),J(s),u(!1),B(null),k(!0)},W=s=>{const{id:a,created_at:l,...y}=s;y.date=s.date?A(s.date):new Date,m&&localStorage.removeItem(m),J(y),u(!1),B(null),k(!0),v({title:"Entry Duplicated",description:"Review and save the new entry.",action:e.jsx(rt,{className:"text-blue-500"})})},G=s=>{L(s),E(!0)},te=async()=>{if(!V||!r||!c)return;const{error:s}=await c.from("kdp_entries").delete().eq("id",V).eq("user_id",r.id);s?v({title:"Error deleting entry",description:s.message,variant:"destructive"}):(v({title:"Entry Deleted",description:"The KDP entry has been successfully removed.",action:e.jsx(rt,{className:"text-green-500"})}),P(),window.dispatchEvent(new CustomEvent("kdpLogDataRefresh"))),E(!1),L(null)},H=()=>{k(!1),u(!1),B(null),N!=null&&N.id?localStorage.removeItem(`${Ie}${N.id}`):m&&localStorage.removeItem(m),J(null),P(),window.dispatchEvent(new CustomEvent("kdpLogDataRefresh"))},[K,M]=x.useState(!1),Q=()=>{const s=N==null?void 0:N.id;!s&&m&&localStorage.getItem(m)?M(!0):(s&&localStorage.removeItem(`${Ie}${s}`),k(!1),u(!1),B(null),J(null))},X=()=>{m&&localStorage.removeItem(m),M(!1),J(null),k(!1),u(!1),B(null)},se=s=>{if(!s){const a=N==null?void 0:N.id;if(!a&&m&&localStorage.getItem(m)){M(!0);return}a&&localStorage.removeItem(`${Ie}${a}`),u(!1),B(null),J(null)}k(s)},le=()=>{if(!p){v({title:"Settings not loaded",description:"Cannot export CSV without user settings.",variant:"destructive"});return}const s=["Date","Account Name","Orders","Ad Orders","Organic Orders","Income (Original)","Income Currency","Ad Spend (Original)","Ad Spend Currency",`Income (${o})`,`Ad Spend (${o})`,`Profit (${o})`,"ROAS","ACOS"],a=ce.map(i=>{const b=i&&i.eur_to_usd_rate_at_entry!=null&&!isNaN(Number(i.eur_to_usd_rate_at_entry))?Number(i.eur_to_usd_rate_at_entry):I,w=R(i.income,i.income_currency,o,b),S=R(i.ad_spend,i.ad_spend_currency,o,b),de=w-S,ie=S>0?(w/S).toFixed(2):"0.00",be=i&&i.ad_acos!=null&&!isNaN(Number(i.ad_acos))?Number(i.ad_acos):null,ve=be!==null?be.toFixed(2):"",De=i&&i.orders!=null&&!isNaN(Number(i.orders))?Math.round(Number(i.orders)):"",Ce=i&&i.ad_orders!=null&&!isNaN(Number(i.ad_orders))?Math.round(Number(i.ad_orders)):"",ht=De!==""?Math.max(0,Number(De)-(Ce!==""?Number(Ce):0)):"";return[oe(A(i.date),"yyyy-MM-dd"),f[i.account_id]||"N/A",De,Ce,ht,i.income,i.income_currency,i.ad_spend,i.ad_spend_currency,w.toFixed(2),S.toFixed(2),de.toFixed(2),ie,ve].join(",")}),l="data:text/csv;charset=utf-8,"+[s.join(","),...a].join(` 2`),y=encodeURI(l),d=document.createElement("a");d.setAttribute("href",y),d.setAttribute("download","kdp_log_export.csv"),document.body.appendChild(d),d.click(),document.body.removeChild(d),v({title:"Export Started",description:"Your KDP log is being downloaded as a CSV file.",action:e.jsx(He,{className:"text-green-500"})})},ce=x.useMemo(()=>{let s=[...xe];if(_.searchTerm){const a=_.searchTerm.toLowerCase();s=s.filter(l=>l.date&&ae(A(l.date))&&oe(A(l.date),"yyyy-MM-dd").includes(a)||f[l.account_id]&&f[l.account_id].toLowerCase().includes(a)||l.income.toString().includes(a)||l.ad_spend.toString().includes(a)||l.orders!=null&&l.orders.toString().includes(a)||l.ad_orders!=null&&l.ad_orders.toString().includes(a))}return _.accountId!=="all"&&_.accountId&&(s=s.filter(a=>a.account_id===_.accountId)),_.startDate&&ae(_.startDate)&&(s=s.filter(a=>a.date&&ae(A(a.date))&&A(a.date)>=_.startDate)),_.endDate&&ae(_.endDate)&&(s=s.filter(a=>a.date&&ae(A(a.date))&&A(a.date)<=_.endDate)),C.key&&s.sort((a,l)=>{let y=a[C.key],d=l[C.key];if(C.key==="date")y=a.date&&ae(A(a.date))?A(a.date):new Date(0),d=l.date&&ae(A(l.date))?A(l.date):new Date(0);else if(C.key==="account_id")y=f[a.account_id]||"",d=f[l.account_id]||"";else if(C.key==="orders"){const i=a&&a.orders!=null&&!isNaN(Number(a.orders))?Math.round(Number(a.orders)):-1/0,b=l&&l.orders!=null&&!isNaN(Number(l.orders))?Math.round(Number(l.orders)):-1/0;y=i,d=b}else if(C.key==="ad_orders"){const i=a&&a.ad_orders!=null&&!isNaN(Number(a.ad_orders))?Math.round(Number(a.ad_orders)):-1/0,b=l&&l.ad_orders!=null&&!isNaN(Number(l.ad_orders))?Math.round(Number(l.ad_orders)):-1/0;y=i,d=b}else if(C.key==="organic_orders"){const i=a&&a.orders!=null&&!isNaN(Number(a.orders))?Math.round(Number(a.orders)):null,b=a&&a.ad_orders!=null&&!isNaN(Number(a.ad_orders))?Math.round(Number(a.ad_orders)):0,w=l&&l.orders!=null&&!isNaN(Number(l.orders))?Math.round(Number(l.orders)):null,S=l&&l.ad_orders!=null&&!isNaN(Number(l.ad_orders))?Math.round(Number(l.ad_orders)):0;y=i!=null?Math.max(0,i-b):-1/0,d=w!=null?Math.max(0,w-S):-1/0}else if(C.key==="profit"){const i=a&&a.eur_to_usd_rate_at_entry!=null&&!isNaN(Number(a.eur_to_usd_rate_at_entry))?Number(a.eur_to_usd_rate_at_entry):I,b=l&&l.eur_to_usd_rate_at_entry!=null&&!isNaN(Number(l.eur_to_usd_rate_at_entry))?Number(l.eur_to_usd_rate_at_entry):I,w=R(a.income,a.income_currency,o,i)-R(a.ad_spend,a.ad_spend_currency,o,i),S=R(l.income,l.income_currency,o,b)-R(l.ad_spend,l.ad_spend_currency,o,b);y=w,d=S}else if(C.key==="roas"){const i=a&&a.eur_to_usd_rate_at_entry!=null&&!isNaN(Number(a.eur_to_usd_rate_at_entry))?Number(a.eur_to_usd_rate_at_entry):I,b=l&&l.eur_to_usd_rate_at_entry!=null&&!isNaN(Number(l.eur_to_usd_rate_at_entry))?Number(l.eur_to_usd_rate_at_entry):I,w=R(a.income,a.income_currency,o,i),S=R(a.ad_spend,a.ad_spend_currency,o,i),de=R(l.income,l.income_currency,o,b),ie=R(l.ad_spend,l.ad_spend_currency,o,b),be=S>0?w/S:0,ve=ie>0?de/ie:0;y=be,d=ve}
2else typeof y=="string"&&typeof d=="string"&&(y=y.toLowerCase(),d=d.toLowerCase());return y<d?C.direction==="ascending"?-1:1:y>d?C.direction==="ascending"?1:-1:0}),s},[xe,C,_,f,o,I,R]);return e.jsxs(dt.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},transition:{duration:.5,delay:.1},className:"container mx-auto py-4 sm:py-8 px-2 sm:px-4",children:[e.jsxs(me,{className:"glassmorphic-card shadow-2xl",children:[e.jsxs(jt,{className:"flex flex-col sm:flex-row justify-between items-start sm:items-center gap-3 sm:gap-0",children:[e.jsxs("div",{children:[e.jsx(he,{className:"text-xl sm:text-3xl font-extrabold bg-gradient-to-r from-[hsl(var(--royaltix-primary))] via-[hsl(var(--royaltix-secondary))] to-[hsl(var(--royaltix-accent))] bg-clip-text text-transparent pb-0.5",children:"KDP Log"}),e.jsx(wt,{className:"text-xs sm:text-sm text-[hsl(var(--royaltix-text-muted))]",children:"Manage and analyze all your KDP financial entries."})]}),e.jsxs("div",{className:"flex gap-2 sm:mt-0",children:[e.jsxs(Z,{onClick:le,variant:"outline",className:"h-9 px-3 text-xs sm:h-10 sm:text-sm border-[hsl(var(--royaltix-accent))] text-[hsl(var(--royaltix-accent))] hover:bg-[hsl(var(--royaltix-accent)_/_0.1)] hover:text-[hsl(var(--royaltix-accent))]",disabled:!p||ce.length===0,children:[e.jsx(He,{className:"mr-2 h-4 w-4"}),e.jsx("span",{children:"Export"})]}),e.jsxs(Z,{onClick:T,className:"h-9 px-3 text-xs sm:h-10 sm:text-sm bg-[hsl(var(--royaltix-accent))] hover:bg-[hsl(var(--royaltix-accent)_/_0.9)] text-white",children:[e.jsx(kt,{className:"mr-2 h-4 w-4"}),e.jsx("span",{children:"Add"})]})]})]}),e.jsxs(St,{children:[e.jsxs("div",{className:"mb-4 sm:mb-6",children:[p&&e.jsx(zt,{entries:ce,displayCurrency:o,eurToUsdRate:I,lastFxUpdatedAt:z,grossWithholdingPercent:typeof p.income_withholding_percent=="number"?p.income_withholding_percent:0,adVatPercent:typeof p.ad_vat_percent=="number"?p.ad_vat_percent:0}),e.jsx(Bt,{filters:_,setFilters:t,accounts:Y})]}),p&&e.jsx(Kt,{entries:ce,accounts:Y,onEdit:q,onDelete:G,onDuplicate:W,eurToUsdRate:I,displayCurrency:o,isLoading:$,sortConfig:C,setSortConfig:U,filters:_,pagePersistenceKey:j,groupByDay:!!p.kdp_log_group_by_day}),!p&&$&&e.jsx("p",{className:"text-center text-[hsl(var(--royaltix-text-muted))]",children:"Loading settings and entries..."})]})]}),e.jsx(Dt,{open:D,onOpenChange:se,children:e.jsxs(Ct,{className:"max-w-[92vw] sm:max-w-[520px] bg-[hsl(var(--royaltix-dialog-bg))] border-[hsl(var(--royaltix-dialog-border))] p-0 rounded-xl sm:rounded-2xl",children:[e.jsxs(At,{className:"p-4 sm:p-6 pb-3 sm:pb-4 border-b border-[hsl(var(--royaltix-card-border)_/_0.5)]",children:[e.jsx(Et,{className:"text-2xl font-bold bg-gradient-to-r from-[hsl(var(--royaltix-primary))] via-[hsl(var(--royaltix-secondary))] to-[hsl(var(--royaltix-accent))] bg-clip-text text-transparent",children:N&&N.id?"Edit KDP Entry":N?"Duplicate KDP Entry":"Add New KDP Entry"}),e.jsx(Mt,{className:"text-[hsl(var(--royaltix-text-muted))]",children:N&&N.id?"Update the details of your KDP entry.":N?"Review and save this duplicated entry.":"Log your KDP income and ad spend for a specific date."}),(O||ne)&&!(N!=null&&N.id)&&e.jsxs(Ft,{variant:"default",className:"mt-3 bg-blue-500/10 border-blue-500/50 text-blue-700",children:[e.jsx(Xe,{className:"h-4 w-4 !text-blue-700"}),e.jsx(It,{children:"Draft Resumed"}),e.jsx(Ot,{children:"We've loaded your previously unsaved KDP entry."})]})]}),e.jsx("div",{className:"p-4 sm:p-6 max-h-[65vh] sm:max-h-[70vh] overflow-y-auto custom-scrollbar",children:D&&e.jsx(Pt,{onSuccess:H,onCancel:Q,entry:N,userId:r==null?void 0:r.id,forceResumeFromStorage:O,persistedDataOverride:ne,isModalOpen:D})})]})}),e.jsx(Ye,{open:ue,onOpenChange:E,children:e.jsxs(Je,{className:"bg-[hsl(var(--royaltix-dialog-bg))] border-[hsl(var(--royaltix-dialog-border))]",children:[e.jsxs(We,{children:[e.jsx(Qe,{className:"text-[hsl(var(--royaltix-text-primary))]",children:"Are you absolutely sure?"}),e.jsx(Ze,{className:"text-[hsl(var(--royaltix-text-muted))]",children:"This action cannot be undone. This will permanently delete the KDP entry."})]}),e.jsxs(et,{children:[e.jsx(tt,{onClick:()=>E(!1),className:"border-[hsl(var(--royaltix-card-border))] hover:border-[hsl(var(--royaltix-accent))] text-[hsl(var(--royaltix-text-secondary))]",children:"Cancel"}),e.jsxs(st,{onClick:te,className:"bg-red-600 hover:bg-red-700 text-white",children:[e.jsx(at,{className:"mr-2 h-4 w-4"})," Delete"]})]})]})}),e.jsx(Ye,{open:K,onOpenChange:M,children:e.jsxs(Je,{className:"bg-[hsl(var(--royaltix-dialog-bg))] border-[hsl(var(--royaltix-dialog-border))]",children:[e.jsxs(We,{children:[e.jsx(Qe,{className:"text-[hsl(var(--royaltix-text-primary))]",children:"Unsaved Changes"}),e.jsx(Ze,{className:"text-[hsl(var(--royaltix-text-muted))]",children:"You have an unsaved KDP entry draft. Closing this form will clear the draft. Are you sure you want to continue?"})]}),e.jsxs(et,{children:[e.jsx(tt,{onClick:()=>{M(!1),k(!0)},className:"border-[hsl(var(--royaltix-card-border))] hover:border-[hsl(var(--royaltix-accent))] text-[hsl(var(--royaltix-text-secondary))]",children:"Keep Editing"}),e.jsxs(st,{onClick:X,className:"bg-yellow-500 hover:bg-yellow-600 text-white",children:[e.jsx(at,{className:"mr-2 h-4 w-4"})," Clear Draft & Close"]})]})]})})]})};export{Yt 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.