PageSourceSearch

https://withkona.com/_next/static/chunks/pages/admin-d871b2027791f870.js

js withkona.com collected 2026-10-02 01:49:02 UTC 110,911 bytes, 1 lines download raw bytes

1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[964],{1517:function(e,r,t){(window.__NEXT_P=window.__NEXT_P||[]).push(["/admin",function(){return t(7712)}])},3792:function(e,r,t){"use strict";t.d(r,{Z:function(){return n}});var o=t(2676),a=t(7564);function n(e){let{children:r,title:t,subtitle:n}=e;return(0,o.jsx)(a.Z,{children:(0,o.jsxs)("main",{style:{maxWidth:720,margin:"0 auto",padding:"48px 24px"},children:[t&&(0,o.jsxs)("div",{style:{marginBottom:32},children:[(0,o.jsx)("h1",{style:{fontSize:32,fontWeight:600,margin:"0 0 8px",color:"var(--color-text-primary)",letterSpacing:-.5},children:t}),n&&(0,o.jsx)("p",{style:{fontSize:15,color:"var(--color-text-secondary)",margin:0},children:n})]}),(0,o.jsx)("div",{style:{fontSize:15,lineHeight:1.8,color:"var(--color-text-primary)"},children:r})]})})}},7712:function(e,r,t){"use strict";t.r(r),t.d(r,{default:function(){return k}});var o=t(2676),a=t(5271),n=t(5276),i=t(3792);function d(e){let{changes:r,onApply:t,mode:n="sync"}=e,i="discover"===n,[d,l]=(0,a.useState)(()=>{let e={};return r.forEach(r=>{e[r.id||r.advertiserId]=!r.rateLocked&&!r.needsReview}),e}),[s,c]=(0,a.useState)(!1),[p,x]=(0,a.useState)(!1),h=e=>e.id||e.advertiserId,g=Object.values(d).filter(Boolean).length,u=r.filter(e=>!e.rateLocked).length,y=(e,r)=>{r||l(r=>({...r,[e]:!r[e]}))},v=async()=>{let e=r.filter(e=>d[h(e)]);if(0!==e.length){c(!0);try{i?await t(e.map(e=>({advertiserId:e.advertiserId,advertiserName:e.advertiserName,category:e.category,cashbackRate:e.cashbackRate,cashbackType:e.cashbackType,cookieDuration:e.cookieDuration,existingMerchantId:e.existingMerchantId}))):await t(e.map(e=>e.id)),x(!0)}catch(e){console.error("Failed to apply:",e)}finally{c(!1)}}};return p?(0,o.jsxs)("div",{style:{padding:12,borderRadius:8,background:"var(--color-background-success)",color:"var(--color-text-success)",fontSize:13,marginTop:8},children:["✓ ",g," merchant",1!==g?"s":""," ",i?"onboarded":"updated"," successfully. Refresh the merchants tab to see changes."]}):(0,o.jsxs)("div",{style:{marginTop:10,borderRadius:8,border:"0.5px solid var(--color-border-tertiary)",overflow:"hidden",background:"var(--color-background-primary)",fontSize:12},children:[(0,o.jsxs)("div",{style:{padding:"8px 12px",borderBottom:"0.5px solid var(--color-border-tertiary)",display:"flex",alignItems:"center",justifyContent:"space-between",background:"var(--color-background-secondary)"},children:[(0,o.jsx)("span",{style:{fontWeight:600,color:"var(--color-text-primary)",fontSize:13},children:i?"New CJ Advertisers — ".concat(r.length," found"):"CJ Rate Sync — ".concat(r.length," change").concat(1!==r.length?"s":""," detected")}),(0,o.jsx)("button",{onClick:()=>{let e=g===u,t={};r.forEach(r=>{t[h(r)]=!r.rateLocked&&!e}),l(t)},style:{background:"none",border:"0.5px solid var(--color-border-tertiary)",padding:"3px 10px",borderRadius:6,fontSize:11,cursor:"pointer",color:"var(--color-text-secondary)"},children:g===u?"Deselect all":"Select all"})]}),(0,o.jsx)("div",{style:{overflowX:"auto"},children:(0,o.jsxs)("table",{style:{width:"100%",borderCollapse:"collapse"},children:[(0,o.jsx)("thead",{children:(0,o.jsxs)("tr",{style:{borderBottom:"0.5px solid var(--color-border-tertiary)",background:"var(--color-background-secondary)"},children:[(0,o.jsx)("th",{style:{padding:"6px 10px",textAlign:"center",width:36}}),(0,o.jsx)("th",{style:{padding:"6px 10px",textAlign:"left",fontWeight:500,color:"var(--color-text-secondary)"},children:"Merchant"}),i?(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("th",{style:{padding:"6px 10px",textAlign:"right",fontWeight:500,color:"var(--color-text-secondary)"},children:"CJ Rate"}),(0,o.jsx)("th",{style:{padding:"6px 10px",textAlign:"right",fontWeight:500,color:"var(--color-text-secondary)"},children:"Cashback"}),(0,o.jsx)("th",{style:{padding:"6px 10px",textAlign:"right",fontWeight:500,color:"var(--color-text-secondary)"},children:"Cookie"}),(0,o.jsx)("th",{style:{padding:"6px 10px",textAlign:"left",fontWeight:500,color:"var(--color-text-secondary)"},children:"Category"}),(0,o.jsx)("th",{style:{padding:"6px 10px",textAlign:"center",fontWeight:500,color:"var(--color-text-secondary)"},children:"Status"})]}):(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("th",{style:{padding:"6px 10px",textAlign:"right",fontWeight:500,color:"var(--color-text-secondary)"},children:"Current"}),(0,o.jsx)("th",{style:{padding:"6px 10px",textAlign:"center",fontWeight:500,color:"var(--color-text-secondary)"}}),(0,o.jsx)("th",{style:{padding:"6px 10px",textAlign:"right",fontWeight:500,color:"var(--color-text-secondary)"},children:"CJ Rate"}),(0,o.jsx)("th",{style:{padding:"6px 10px",textAlign:"center",fontWeight:500,color:"var(--color-text-secondary)"}}),(0,o.jsx)("th",{style:{padding:"6px 10px",textAlign:"right",fontWeight:500,color:"var(--color-text-secondary)"},children:"New Rate"}),(0,o.jsx)("th",{style:{padding:"6px 10px",textAlign:"right",fontWeight:500,color:"var(--color-text-secondary)"},children:"Cookie"}),(0,o.jsx)("th",{style:{padding:"6px 10px",textAlign:"center",fontWeight:500,color:"var(--color-text-secondary)"},children:"Status"})]})]})}),(0,o.jsx)("tbody",{children:r.map(e=>{let r=h(e),t=e.rateLocked,a=e.needsReview,n="fixed"===e.cashbackType;if(i)return(0,o.jsxs)("tr",{style:{borderBottom:"0.5px solid var(--color-border-tertiary)",background:d[r]?"rgba(29, 158, 117, 0.05)":"transparent"},children:[(0,o.jsx)("td",{style:{padding:"8px 10px",textAlign:"center"},children:(0,o.jsx)("input",{type:"checkbox",checked:!!d[r],onChange:()=>y(r,!1),style:{cursor:"pointer",accentColor:"#1D9E75"}})}),(0,o.jsxs)("td",{style:{padding:"8px 10px",fontWeight:500,color:"var(--color-text-primary)",whiteSpace:"nowrap"},children:[e.advertiserName,e.existingMerchantId&&(0,o.jsx)("span",{style:{fontSize:10,
1color:"var(--color-text-secondary)",marginLeft:4},children:" (update)"})]}),(0,o.jsx)("td",{style:{padding:"8px 10px",textAlign:"right",fontFamily:"var(--font-mono, monospace)",color:"var(--color-text-secondary)"},children:null!=e.networkRate?n?"$".concat(e.networkRate):"".concat(e.networkRate,"%"):"—"}),(0,o.jsx)("td",{style:{padding:"8px 10px",textAlign:"right",fontWeight:600,fontFamily:"var(--font-mono, monospace)",color:"#1D9E75"},children:null!=e.cashbackRate?n?"$".concat(e.cashbackRate):"".concat(e.cashbackRate,"%"):"3%"}),(0,o.jsxs)("td",{style:{padding:"8px 10px",textAlign:"right",fontFamily:"var(--font-mono, monospace)",color:"var(--color-text-secondary)"},children:[e.cookieDuration||30,"d"]}),(0,o.jsx)("td",{style:{padding:"8px 10px",textAlign:"left",color:"var(--color-text-secondary)"},children:e.category||"General"}),(0,o.jsx)("td",{style:{padding:"8px 10px",textAlign:"center"},children:a?(0,o.jsx)("span",{style:{fontSize:10,padding:"2px 6px",borderRadius:10,background:"#FFF3CD",color:"#856404"},children:"⚠️ Review"}):e.existingMerchantId?(0,o.jsx)("span",{style:{fontSize:10,padding:"2px 6px",borderRadius:10,background:"#E3F2FD",color:"#1565C0"},children:"↻ Link"}):(0,o.jsx)("span",{style:{fontSize:10,padding:"2px 6px",borderRadius:10,background:"var(--color-background-success)",color:"var(--color-text-success)"},children:"+ New"})})]},r);let l=e.newRate>e.oldRate,s=e.newRate<e.oldRate;return(0,o.jsxs)("tr",{style:{borderBottom:"0.5px solid var(--color-border-tertiary)",opacity:t?.5:1,background:d[r]?"rgba(29, 158, 117, 0.05)":"transparent"},children:[(0,o.jsx)("td",{style:{padding:"8px 10px",textAlign:"center"},children:(0,o.jsx)("input",{type:"checkbox",checked:!!d[r],onChange:()=>y(r,t),disabled:t,style:{cursor:t?"not-allowed":"pointer",accentColor:"#1D9E75"}})}),(0,o.jsxs)("td",{style:{padding:"8px 10px",fontWeight:500,color:"var(--color-text-primary)",whiteSpace:"nowrap"},children:[e.name,e.hasSlidingScale&&(0,o.jsx)("span",{style:{fontSize:10,color:"var(--color-text-secondary)",marginLeft:4},children:"\uD83D\uDCC8"})]}),(0,o.jsx)("td",{style:{padding:"8px 10px",textAlign:"right",fontFamily:"var(--font-mono, monospace)",color:"var(--color-text-primary)"},children:n?"$".concat(e.oldRate):"".concat(e.oldRate,"%")}),(0,o.jsx)("td",{style:{padding:"8px 10px",textAlign:"center",color:"var(--color-text-secondary)"},children:"→"}),(0,o.jsx)("td",{style:{padding:"8px 10px",textAlign:"right",fontFamily:"var(--font-mono, monospace)",color:"var(--color-text-secondary)"},children:null!=e.networkRate?n?"$".concat(e.networkRate):"".concat(e.networkRate,"%"):"—"}),(0,o.jsx)("td",{style:{padding:"8px 10px",textAlign:"center",color:"var(--color-text-secondary)"},children:"→"}),(0,o.jsxs)("td",{style:{padding:"8px 10px",textAlign:"right",fontWeight:600,fontFamily:"var(--font-mono, monospace)",color:l?"#1D9E75":s?"#E53E3E":"var(--color-text-primary)"},children:[n?"$".concat(e.newRate):"".concat(e.newRate,"%"),l&&" ↑",s&&" ↓"]}),(0,o.jsx)("td",{style:{padding:"8px 10px",textAlign:"right",fontFamily:"var(--font-mono, monospace)",color:"var(--color-text-secondary)"},children:e.oldCookie!==e.newCookie?(0,o.jsxs)("span",{children:[e.oldCookie,"d → ",(0,o.jsxs)("span",{style:{color:"var(--color-text-primary)"},children:[e.newCookie,"d"]})]}):(0,o.jsxs)("span",{children:[e.oldCookie,"d"]})}),(0,o.jsx)("td",{style:{padding:"8px 10px",textAlign:"center"},children:t?(0,o.jsx)("span",{style:{fontSize:10,padding:"2px 6px",borderRadius:10,background:"var(--color-background-secondary)",color:"var(--color-text-secondary)"},children:"\uD83D\uDD12 Locked"}):a?(0,o.jsx)("span",{style:{fontSize:10,padding:"2px 6px",borderRadius:10,background:"#FFF3CD",color:"#856404"},children:"⚠️ Review"}):(0,o.jsx)("span",{style:{fontSize:10,padding:"2px 6px",borderRadius:10,background:"var(--color-background-success)",color:"var(--color-text-success)"},children:"✓ Auto"})})]},r)})})]})}),(0,o.jsxs)("div",{style:{padding:"10px 12px",borderTop:"0.5px solid var(--color-border-tertiary)",display:"flex",alignItems:"center",justifyContent:"space-between",background:"var(--color-background-secondary)"},children:[(0,o.jsxs)("span",{style:{fontSize:11,color:"var(--color-text-secondary)"},children:[g," of ",u," selected",!i&&r.some(e=>e.rateLocked)&&" \xb7 \uD83D\uDD12 = manually overridden, won't be changed"]}),(0,o.jsx)("button",{onClick:v,disabled:s||0===g,style:{background:g>
10?"#1D9E75":"var(--color-background-secondary)",color:g>0?"#fff":"var(--color-text-secondary)",border:"none",padding:"6px 16px",borderRadius:6,fontSize:12,fontWeight:600,cursor:s||0===g?"default":"pointer",opacity:s?.6:1},children:s?"Applying...":i?"Onboard ".concat(g," merchant").concat(1!==g?"s":""):"Apply ".concat(g," change").concat(1!==g?"s":"")})]})]})}let l={role:"assistant",content:'Hey! I\'m Kona\'s admin AI. I can help you manage merchants, placements, and more. Try:\n\n• "Add REI with 5% cashback in General"\n• "Feature Target on the homepage"\n• "Check for new CJ advertisers"\n• "Sync CJ rates"\n• "Write a blog post about summer deals"'};function s(e){if(!e||0===e.length)return null;let r=e.find(e=>{var r,t,o;return"SYNC_CJ_RATES"===e.type&&(null===(r=e.result)||void 0===r?void 0:r.success)&&(null===(o=e.result)||void 0===o?void 0:null===(t=o.changes)||void 0===t?void 0:t.length)>0});return r?r.result.changes:null}function c(e){if(!e||0===e.length)return null;let r=e.find(e=>{var r,t,o;return"DISCOVER_CJ_ADVERTISERS"===e.type&&(null===(r=e.result)||void 0===r?void 0:r.success)&&(null===(o=e.result)||void 0===o?void 0:null===(t=o.discoveries)||void 0===t?void 0:t.length)>0});return r?r.result.discoveries:null}function p(e){let{isSignedIn:r,activeTab:t,onDataChange:n}=e,[i,p]=(0,a.useState)(!1),[x,h]=(0,a.useState)([l]),[g,u]=(0,a.useState)(""),[y,v]=(0,a.useState)(!1),[b,f]=(0,a.useState)(!1),[m,j]=(0,a.useState)(0),k=(0,a.useRef)(null),S=(0,a.useRef)(null);(0,a.useEffect)(()=>{k.current&&i&&k.current.scrollIntoView({behavior:"smooth"})},[x,i]),(0,a.useEffect)(()=>{i&&S.current&&setTimeout(()=>{var e;return null===(e=S.current)||void 0===e?void 0:e.focus()},100)},[i]),(0,a.useEffect)(()=>{i&&j(0)},[i]),(0,a.useEffect)(()=>{r&&!b&&fetch("/api/admin/chat-history").then(e=>e.json()).then(e=>{e.messages&&e.messages.length>0&&h([l,...e.messages.map(e=>({role:e.role,content:e.content,actions:e.actions||[],savedAt:e.created_at}))]),f(!0)}).catch(()=>f(!0))},[r,b]);let w=(0,a.useCallback)(async e=>{try{await fetch("/api/admin/chat-history",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({messages:e})})}catch(e){console.error("Failed to save chat history:",e)}},[]),_=(0,a.useCallback)(async e=>{let r=await fetch("/api/cj-integration",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"apply_sync_changes",merchant_ids:e})}),t=await r.json();if(!t.success)throw Error(t.error||"Failed to apply changes");return null==n||n(),t},[n]),C=(0,a.useCallback)(async e=>{let r=await fetch("/api/cj-integration",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"onboard_discovered",advertisers:e})}),t=await r.json();if(!t.success)throw Error(t.error||"Failed to onboard advertisers");return null==n||n(),t},[n]),z=(0,a.useCallback)(async()=>{if(!g.trim()||y)return;let e=g.trim();u(""),h(r=>[...r,{role:"user",content:e}]),v(!0);let r=x.filter(e=>"user"===e.role||"assistant"===e.role).slice(-10);try{let o=await fetch("/api/admin/ai-chat",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({message:e,conversationHistory:r,activeTab:t||"merchants"})}),a=await o.json(),d={role:"assistant",content:a.message||a.error||"Something went wrong.",actions:a.actions||[]};h(e=>[...e,d]),i||j(e=>e+1),await w([{role:"user",content:e},{role:"assistant",content:d.content,actions:d.actions}]),a.hasActions&&(null==n||n())}catch(r){let e={role:"assistant",content:"Sorry, something went wrong. Please try again."};h(r=>[...r,e])}finally{v(!1)}},[g,y,x,t,i,w,n]);return r?(0,o.jsxs)(o.Fragment,{children:[!i&&(0,o.jsxs)("button",{onClick:()=>p(!0),style:{position:"fixed",bottom:24,right:24,zIndex:9999,display:"flex",alignItems:"center",gap:8,padding:"10px 18px",borderRadius:24,border:"none",background:"linear-gradient(135deg, #2775CA, #1D9E75)",color:"#fff",fontSize:13,fontWeight:600,cursor:"pointer",boxShadow:"0 4px 20px rgba(0,0,0,0.25), 0 2px 8px rgba(39,117,202,0.3)",transition:"transform 0.15s ease, box-shadow 0.15s ease"},onMouseEnter:e=>{e.currentTarget.style.transform="translateY(-2px)",e.currentTarget.style.boxShadow="0 6px 24px rgba(0,0,0,0.3), 0 3px 12px rgba(39,117,202,0.4)"},onMouseLeave:e=>{e.currentTarget.style.transform="translateY(0)",e.currentTarget.style.boxShadow="0 4px 20px rgba(0,0,0,0.25), 0 2px 8px rgba(39,117,202,0.3)"},children:[(0,o.jsx)("span",{style:{fontSize:15},children:"✦"}),"Kona Admin AI",m>0&&(0,o.jsx)("span",{style:{background:"#ff4444",color:"#fff",fontSize:10,fontWeight:700,minWidth:18,height:18,borderRadius:9,display:"flex",alignItems:"center",justifyContent:"center",marginLeft:2},children:m})]}),i&&(0,o.jsxs)("div",{style:{position:"fixed",bottom:24,right:24,zIndex:9999,width:420,maxWidth:"calc(100vw - 48px)",height:560,maxHeight:"calc(100vh - 120px)",borderRadius:16,overflow:"hidden",display:"flex",flexDirection:"column",background:"var(--color-background-primary)",border:"0.5px solid var(--color-border-tertiary)",boxShadow:"0 12px 48px rgba(0,0,0,0.3), 0 4px 16px rgba(0,0,0,0.15)"},children:[(0,o.jsxs)("div",{style:{padding:"12px 16px",background:"linear-gradient(135deg, #2775CA, #1D9E75)",display:"flex",alignItems:"center",gap:10,flexShrink:0},children:[(0,o.jsx)("div",{style:{width:30,height:30,borderRadius:"50%",background:"rgba(255,255,255,0.2)",display:"flex",alignItems:"center",justifyContent:"center",color:"#fff",fontSize:14},children:"✦"}),(0,o.jsxs)("div",{style:{flex:1},children:[(0,o.jsx)("div",{style:{fontSize:14,fontWeight:600,color:"#fff"},children:"Kona Admin AI"}),(0,o.jsx)("div",{style:{fontSize:11,color:"rgba(255,255,255,0.7)"},children:t?"Viewing: ".concat(t):"Admin assistant"})]}),x.length>1&&(0,o.jsx)("button",{onClick:()=>{h([l])},style:{background:"rgba(255,255,255,0.15)",border:"none",padding:"4px 10px",borderRadius:8,fontSize:11,cursor:"pointer",color:"rgba(255,255,255,0.8)"},children:"Clear"}),(0,o.jsx)("button",{onClick:()=>p(!1),style:{background:"rgba(255,255,255,0.15)",border:"none",width:28,height:28,borderRadius:8,display:"flex",alignItems:"center",justifyContent:"center",cursor:"pointer",color:"#fff",fontSize:16,lineHeight:1},children:"\xd7"})]}),(0,o.jsxs)("div",{style:{flex:1,overflowY:"auto",padding:14,display:"flex",flexDirection:"column",gap:10},children:[x.map((e,r)=>(0,o.jsx)("div",{style:{display:"flex",justifyContent:"user"===e.role?"flex-end":"flex-start"},children:(0,o.jsxs)("div",{style:{maxWidth:"88%",padding:"9px 12px",borderRadius:"user"===e.role?"12px 12px 4px 12px":"12px 12px 12px 4px",background:"user"===e.role?"#111":"var(--color-background-secondary)",color:"user"===e.role?"#fff":"var(--color-text-primary)",fontSize:12.5,lineHeight:1.55,whiteSpace:"pre-wrap",wordBreak:"break-word"},children:[e.content,e.savedAt&&(0,o.jsxs)("div",{style:{fontSize:9.5,color:"user"===e.role?"rgba(255,255,255,0.35)":"var(--color-text-secondary)",marginTop:3},children:[new Date(e.savedAt).toLocaleDateString("en-US",{month:"short",day:"numeric"})," ",new Date(e.savedAt).toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit"})]}),e.actions&&e.actions.length>0&&(0,o.jsxs)("div",{style:{marginTop:6,paddingTop:6,borderTop:"1px solid ".concat("user"===e.role?"rgba(255,255,255,0.15)":"var(--color-border-tertiary)")},children:[s(e.actions)&&(0,o.jsx)(d,{changes:s(e.actions),onApply:_}),c(e.actions)&&(0,o.jsx)(d,{changes:c(e.actions),mode:"discover",onApply:C}),e.actions.filter(e=>{var r,t,o,a;return("SYNC_CJ_RATES"!==e.type||!(null===(t=e.result)||void 0===t?void 0:null===(r=t.changes)||void 0===r?void 0:r.length))&&("DISCOVER_CJ_ADVERTISERS"!==e.type||!(null===(a=e.result)||void 0===a?void 0:null===(o=a.discoveries)||void 0===o?void 0:o.length))}).map((e,r)=>{var t,a,n,i,d;return(0,o.jsxs)("div",{style:{fontSize:10.5,padding:"3px 7px",borderRadius:5,marginTop:3,background:(null===(t=e.result)||void 0===t?void 0:t.success)?"var(--color-background-success)":(null===(a=e.result)||void 0===a?void 0:a.error)?"var(--color-background-danger)":"var(--color-background-secondary)",color:(null===(n=e.result)||void 0===n?void 0:n.success)?"var(--color-text-success)":(null===(i=e.result)||void 0===i?void 0:i.error)?"var(--color-text-danger)":"var(--color-text-secondary)"},children:[(null===(d=e.result)||void 0===d?void 0:d.success)?"✓":"✗"," ",e.type.replace(/_/g," ").toLowerCase()]},r)})]})]})},r)),y&&(0,o.jsx)("div",{style:{display:"flex",justifyContent:"flex-start"},children:(0,o.jsxs)("div",{style:{padding:"9px 12px",borderRadius:"12px 12px 12px 4px",background:"var(--color-background-secondary)",fontSize:12.5,color:"var(--color-text-secondary)",display:"flex",alignItems:"center",gap:6},children:[(0,o.jsxs)("span",{style:{display:"inline-flex",gap:3},children:[(0,o.jsx)("span",{style:{width:5,height:5,borderRadius:"50%",background:"var(--color-text-secondary)",opacity:.5,animation:"pulse 1.2s ease-in-out infinite"}}),(0,o.jsx)("span",{style:{width:5,height:5,borderRadius:"50%",background:"var(--color-text-secondary)",opacity:.5,animation:"pulse 1.2s ease-in-out 0.2s infinite"}}),(0,o.jsx)("span",{style:{width:5,height:5,borderRadius:"50%",background:"var(--color-text-secondary)",opacity:.5,animation:"pulse 1.2s ease-in-out 0.4s infinite"}})]}),"Thinking..."]})}),(0,o.jsx)("div",{ref:k})]}),(0,o.jsxs)("div",{style:{borderTop:"0.5px solid var(--color-border-tertiary)",padding:"10px 12px",display:"flex",gap:8,flexShrink:0,background:"var(--color-background-primary)"},children:[(0,o.jsx)("input",{ref:S,value:g,onChange:e=>u(e.target.value),onKeyDown:e=>{"Enter"===e.key&&!e.shiftKey&&g.trim()&&!y&&(e.preventDefault(),z())},placeholder:"Ask me anything...",style:{flex:1,padding:"9px 12px",borderRadius:10,border:"0.5px solid var(--color-border-tertiary)",fontSize:13,background:"var(--color-background-secondary)",color:"var(--color-text-primary)",outline:"none"},disabled:y}),(0,o.jsx)("button",{onClick:z,disabled:y||!g.trim(),style:{padding:"9px 16px",borderRadius:10,border:"none",background:y||!g.trim()?"var(--color-background-secondary)":"linear-gradient(135deg, #2775CA, #1D9E75)",color:y||!g.trim()?"var(--color-text-secondary)":"#fff",fontSize:12.5,fontWeight:600,cursor:y?"default":"pointer"},children:"Send"})]})]}),(0,o.jsx)("style",{children:"\n        @keyframes pulse {\n          0%, 80%, 100% { opacity: 0.3; transform: scale(0.8); }\n          40% { opacity: 1; transform: scale(1); }\n        }\n      "})]}):null}let x={cj_feed:{bg:"#DBEAFE",fg:"#1D4ED8",label:"CJ feed"},cj_feed_extracted:{bg:"#EDE9FE",fg:"#6D28D9",label:"CJ extracted"},rakuten_coupon_feed:{bg:"#FEE2E2",fg:"#B91C1C",label:"Rakuten feed"},rakuten_feed_extracted:{bg:"#FCE7F3",fg:"#BE185D",label:"Rakuten extracted"},impact_offers:{bg:"#F5D0FE",fg:"#A21CAF",label:"Impact feed"},impact_offers_extracted:{bg:"#FAE8FF",fg:"#86198F",label:"Impact extracted"}
1,homepage_scraper:{bg:"#D1FAE5",fg:"#047857",label:"Homepage"},ai_discovery:{bg:"#E0F2FE",fg:"#0369A1",label:"AI discovery"},email_pipeline:{bg:"#FFEDD5",fg:"#C2410C",label:"Email"}};function h(e){let{source:r}=e,t=x[r]||{bg:"var(--color-background-tertiary)",fg:"var(--color-text-secondary)",label:r};return(0,o.jsx)("span",{style:{fontSize:11,padding:"2px 8px",borderRadius:10,background:t.bg,color:t.fg,fontWeight:600,whiteSpace:"nowrap"},children:t.label})}function g(e){return new Date(Date.now()+864e5*e).toISOString().split("T")[0]}function u(e){let{showMsg:r}=e,[t,n]=(0,a.useState)(null),[i,d]=(0,a.useState)(!0),[l,s]=(0,a.useState)(!1),[c,p]=(0,a.useState)(new Set),[x,u]=(0,a.useState)(null),[y,v]=(0,a.useState)("permanent"),[b,f]=(0,a.useState)(g(30)),[m,j]=(0,a.useState)({}),k=(0,a.useCallback)(async()=>{try{d(!0);let e=await fetch("/api/admin/coupon-queue"),t=await e.json();t.success?(n(t),j({}),p(new Set)):null==r||r(t.error||"Failed to load coupon queue","error")}catch(e){null==r||r("Failed to load coupon queue: ".concat(e.message),"error")}finally{d(!1)}},[r]);(0,a.useEffect)(()=>{k()},[k]);let S=async e=>{let r=await fetch("/api/admin/coupon-queue",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}),t=await r.json().catch(()=>({}));if(!r.ok)throw Error(t.error||"HTTP ".concat(r.status));return t},w=async e=>{if(!l){s(!0);try{let t=await S({action:"approve",ids:e}),o=t.results.filter(e=>"published"===e.result).length,a=t.results.filter(e=>"witness_recorded"===e.result).length,n=t.results.filter(e=>!["published","witness_recorded","already_handled"].includes(e.result)),i="".concat(o," published");a&&(i+=", ".concat(a," already live - witness recorded")),n.length&&(i+=", ".concat(n.length," failed")),null==r||r(i,n.length?"error":"success"),await k()}catch(e){null==r||r("Approve failed: ".concat(e.message),"error")}finally{s(!1)}}},_=async()=>{if(!l&&x){s(!0);try{let e=await S({action:"reject",ids:x.ids,mode:y,rediscover_after:"temporary"===y?new Date("".concat(b,"T00:00:00Z")).toISOString():void 0});null==r||r("".concat(e.rejected," rejected (").concat(e.mode,")"),"success"),u(null),await k()}catch(e){null==r||r("Reject failed: ".concat(e.message),"error")}finally{s(!1)}}},C=async e=>{let o=m[e];
1if(!o||l)return;let a=t.config.find(r=>r.source===e);if(!("auto_publish_threshold"in o&&Number(o.auto_publish_threshold)<Number(a.auto_publish_threshold))||window.confirm("Lower ".concat(e," auto-publish threshold ").concat(a.auto_publish_threshold," → ").concat(o.auto_publish_threshold,"?\n\nCandidates scoring at or above the new threshold will publish to the live site WITHOUT human review."))){s(!0);try{await S({action:"update_config",source:e,fields:o}),null==r||r("".concat(e," config saved"),"success"),await k()}catch(e){null==r||r("Config save failed: ".concat(e.message),"error")}finally{s(!1)}}},z=e=>{p(r=>{let t=new Set(r);return t.has(e)?t.delete(e):t.add(e),t})};if(i&&!t)return(0,o.jsx)("div",{style:{padding:32,textAlign:"center",color:"var(--color-text-secondary)",fontSize:14},children:"Loading..."});if(!t)return null;let R=e=>m[e]||{},A=(e,r,t)=>j(o=>({...o,[e]:{...o[e],[r]:t}})),W=function(e,r){let t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return{background:e,color:r,border:"none",padding:"5px 12px",borderRadius:"var(--border-radius-md)",fontSize:12,fontWeight:500,cursor:l?"default":"pointer",opacity:l?.6:1,...t}};return(0,o.jsxs)("div",{children:[(0,o.jsx)("h3",{style:{fontSize:17,fontWeight:600,margin:"0 0 8px",color:"var(--color-text-primary)"},children:"Coupon queue"}),(0,o.jsx)("p",{style:{fontSize:13,color:"var(--color-text-secondary)",margin:"0 0 16px"},children:"Discovery candidates below their source's auto-publish threshold. Approving publishes through the intake hub as human_approved; rejection is permanent or temporary with a rediscovery date."}),(0,o.jsxs)("div",{style:{display:"flex",gap:10,marginBottom:20,flexWrap:"wrap"},children:[Object.entries(t.source_stats).map(e=>{let[r,t]=e;return(0,o.jsxs)("div",{style:{padding:"10px 14px",borderRadius:"var(--border-radius-md)",background:"var(--color-background-secondary)",minWidth:150},children:[(0,o.jsx)(h,{source:r}),(0,o.jsxs)("div",{style:{fontSize:20,fontWeight:600,marginTop:6,color:t.pending>0?"#E85D04":"var(--color-text-primary)"},children:[t.pending," pending"]}),(0,o.jsxs)("div",{style:{fontSize:11,color:"var(--color-text-secondary)",marginTop:2},children:["lifetime: ",t.approved," approved \xb7 ",t.rejected," rejected",t.approved+t.rejected>0&&(0,o.jsxs)(o.Fragment,{children:[" \xb7 ",Math.round(t.approved/(t.approved+t.rejected)*100),"% approval"]})]})]},r)}),0===Object.keys(t.source_stats).length&&(0,o.jsx)("div",{style:{fontSize:13,color:"var(--color-text-secondary)"},children:"No discovery candidates yet."})]}),c.size>0&&(0,o.jsxs)("div",{style:{position:"sticky",top:0,zIndex:10,display:"flex",gap:10,alignItems:"center",padding:"10px 14px",background:"var(--color-background-primary)",border:"1px solid #2775CA50",borderRadius:"var(--border-radius-md)",marginBottom:12,boxShadow:"0 2px 10px rgba(0,0,0,0.08)"},children:[(0,o.jsxs)("span",{style:{fontSize:13,fontWeight:600,color:"var(--color-text-primary)"},children:[c.size," selected"]}),(0,o.jsx)("div",{style:{flex:1}}),(0,o.jsx)("button",{onClick:()=>w([...c]),disabled:l,style:W("#1D9E75","#fff"),children:l?"Working...":"Approve selected"}),(0,o.jsx)("button",{onClick:()=>{v("permanent"),f(g(30)),u({ids:[...c]})},disabled:l,style:W("transparent","var(--color-text-danger)",{border:"0.5px solid var(--color-border-danger)"}),children:"Reject selected"}),(0,o.jsx)("button",{onClick:()=>p(new Set),style:W("transparent","var(--color-text-secondary)"),children:"Clear"})]}),0===t.groups.length?(0,o.jsxs)("div",{style:{padding:48,textAlign:"center",border:"0.5px solid var(--color-border-tertiary)",borderRadius:"var(--border-radius-lg)",background:"var(--color-background-primary)",marginBottom:28},children:[(0,o.jsx)("div",{style:{fontSize:40,marginBottom:12},children:"\uD83D\uDC3E"}),(0,o.jsx)("div",{style:{fontSize:16,fontWeight:500,color:"var(--color-text-primary)"},children:"Queue is empty"}),(0,o.jsx)("div",{style:{fontSize:13,color:"var(--color-text-secondary)",marginTop:4},children:"Discovery candidates land here when they score below their source's auto-publish threshold."})]}):t.groups.map(e=>{var r,t,a;let n=(null===(r=e.merchant)||void 0===r?void 0:r.name)||"Unmatched merchant",i=(null===(t=e.merchant)||void 0===t?void 0:t.logo_color)||"#111",d=(null===(a=e.merchant)||void 0===a?void 0:a.logo_text)||n.substring(0,2).toUpperCase();return(0,o.jsxs)("div",{style:{borderRadius:"var(--border-radius-lg)",border:"0.5px solid var(--color-border-tertiary)",background:"var(--color-background-primary)",marginBottom:12,overflow:"hidden"},children:[(0,o.jsxs)("div",{style:{padding:"12px 14px",display:"flex",alignItems:"center",gap:10,background:"var(--color-background-secondary)",borderBottom:"0.5px solid var(--color-border-tertiary)"},children:[(0,o.jsx)("div",{style:{width:32,height:32,borderRadius:"var(--border-radius-md)",background:i,display:"flex",alignItems:"center",justifyContent:"center",color:"#fff",fontSize:11,fontWeight:600,flexShrink:0},children:d}),(0,o.jsxs)("div",{style:{fontSize:14,fontWeight:600,color:"var(--color-text-primary)",flex:1},children:[n,(0,o.jsxs)("span",{style:{fontSize:11,padding:"2px 8px",borderRadius:10,background:"var(--color-background-tertiary)",color:"var(--color-text-secondary)",fontWeight:500,marginLeft:8},children:[e.items.length," candidate",1!==e.items.length?"s":""]})]}),(0,o.jsx)("button",{onClick:()=>w(e.items.map(e=>e.id)),disabled:l,style:W("#1D9E75","#fff"),children:"Approve all"})]}),e.items.map(e=>(0,o.jsxs)("div",{style:{padding:"10px 14px",display:"flex",alignItems:"flex-start",ga
1p:10,borderBottom:"0.5px solid var(--color-border-tertiary)"},children:[(0,o.jsx)("input",{type:"checkbox",checked:c.has(e.id),onChange:()=>z(e.id),style:{cursor:"pointer",marginTop:3}}),(0,o.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,o.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,flexWrap:"wrap"},children:[(0,o.jsx)("code",{style:{fontSize:13,fontWeight:700,background:"var(--color-background-tertiary)",padding:"2px 8px",borderRadius:6,color:"var(--color-text-primary)"},children:e.code}),(0,o.jsx)(h,{source:e.source}),(0,o.jsxs)("span",{style:{fontSize:11,color:"var(--color-text-secondary)"},children:["confidence ",Math.round(Number(e.agent_confidence)||0)]}),(0,o.jsxs)("span",{style:{fontSize:11,color:"var(--color-text-secondary)"},children:["\xb7 ",function(e){if(!e)return"";let r=Math.floor((Date.now()-new Date(e).getTime())/6e4);if(r<1)return"just now";if(r<60)return"".concat(r,"m ago");let t=Math.floor(r/60);return t<24?"".concat(t,"h ago"):"".concat(Math.floor(t/24),"d ago")}(e.created_at)]})]}),(e.evidence||e.title)&&(0,o.jsxs)("div",{style:{fontSize:12,color:"var(--color-text-secondary)",marginTop:4,overflow:"hidden",textOverflow:"ellipsis"},children:["“",e.evidence||e.title,"”"]}),e.source_url&&(0,o.jsx)("a",{href:e.source_url,target:"_blank",rel:"noopener noreferrer",style:{fontSize:11,color:"#2775CA",textDecoration:"none"},children:"view source link ↗"})]}),(0,o.jsxs)("div",{style:{display:"flex",gap:6,flexShrink:0},children:[(0,o.jsx)("button",{onClick:()=>w([e.id]),disabled:l,style:W("#1D9E75","#fff"),children:"Approve"}),(0,o.jsx)("button",{onClick:()=>{v("permanent"),f(g(30)),u({ids:[e.id]})},disabled:l,style:W("transparent","var(--color-text-danger)",{border:"0.5px solid var(--color-border-danger)"}),children:"Reject"})]})]},e.id))]},e.merchant_id||"unmatched")}),(0,o.jsx)("h3",{style:{fontSize:17,fontWeight:600,margin:"28px 0 8px",color:"var(--color-text-primary)"},children:"Source thresholds"}),(0,o.jsx)("p",{style:{fontSize:13,color:"var(--color-text-secondary)",margin:"0 0 12px"},children:"The autonomy control panel. Candidates scoring ≥ auto-publish go live unreviewed; ≥ review queue here; below are discarded. 101 = nothing auto-publishes."}),(0,o.jsx)("div",{style:{overflowX:"auto",border:"0.5px solid var(--color-border-tertiary)",borderRadius:"var(--border-radius-lg)",background:"var(--color-background-primary)"},children:(0,o.jsxs)("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:13},children:[(0,o.jsx)("thead",{children:(0,o.jsx)("tr",{style:{background:"var(--color-background-secondary)",textAlign:"left"},children:["Source","Enabled","Auto-publish ≥","Review ≥","Probation","Notes",""].map(e=>(0,o.jsx)("th",{style:{padding:"10px 12px",fontWeight:600,color:"var(--color-text-secondary)",fontSize:12,whiteSpace:"nowrap"},children:e},e))})}),(0,o.jsx)("tbody",{children:t.config.map(e=>{var r,t,a,n,i,d;let s=R(e.source),c=Object.keys(s).length>0;return(0,o.jsxs)("tr",{style:{borderTop:"0.5px solid var(--color-border-tertiary)"},children:[(0,o.jsx)("td",{style:{padding:"8px 12px"},children:(0,o.jsx)(h,{source:e.source})}),(0,o.jsx)("td",{style:{padding:"8px 12px"},children:(0,o.jsx)("input",{type:"checkbox",checked:null!==(r=s.enabled)&&void 0!==r?r:e.enabled,onChange:r=>A(e.source,"enabled",r.target.checked),style:{cursor:"pointer"}})}),(0,o.jsx)("td",{style:{padding:"8px 12px"},children:(0,o.jsx)("input",{type:"number",min:0,max:101,value:null!==(t=s.auto_publish_threshold)&&void 0!==t?t:e.auto_publish_threshold,onChange:r=>A(e.source,"auto_publish_threshold",r.target.value),style:{width:64,padding:"4px 6px",fontSize:13,border:"0.5px solid var(--color-border-tertiary)",borderRadius:6,background:"var(--color-background-primary)",color:"var(--color-text-primary)"}})}),(0,o.jsx)("td",{style:{padding:"8px 12px"},children:(0,o.jsx)("input",{type:"number",min:0,max:101,value:null!==(a=s.review_threshold)&&void 0!==a?a:e.review_threshold,onChange:r=>A(e.source,"review_threshold",r.target.value),style:{width:64,padding:"4px 6px",fontSize:13,border:"0.5px solid var(--color-border-tertiary)",borderRadius:6,background:"var(--color-background-primary)",color:"var(--color-text-primary)"}})}),(0,o.jsx)("td",{style:{padding:"8px 12px"},children:(0,o.jsx)("input",{type:"checkbox",checked:null!==(n=s.on_probation)&&void 0!==n?n:e.on_probation,onChange:r=>A(e.source,"on_probation",r.target.checked),style:{cursor:"pointer"}})}),(0,o.jsx)("td",{style:{padding:"8px 12px",minWidth:220},children:(0,o.jsx)("input",{type:"text",value:null!==(d=null!==(i=s.notes)&&void 0!==i?i:e.notes)&&void 0!==d?d:"",onCh
1ange:r=>A(e.source,"notes",r.target.value),style:{width:"100%",padding:"4px 6px",fontSize:12,border:"0.5px solid var(--color-border-tertiary)",borderRadius:6,background:"var(--color-background-primary)",color:"var(--color-text-secondary)"}})}),(0,o.jsx)("td",{style:{padding:"8px 12px"},children:c&&(0,o.jsx)("button",{onClick:()=>C(e.source),disabled:l,style:W("#2775CA","#fff"),children:"Save"})})]},e.source)})})]})}),x&&(0,o.jsx)("div",{style:{position:"fixed",inset:0,background:"rgba(0,0,0,0.4)",display:"flex",alignItems:"center",justifyContent:"center",zIndex:100},onClick:()=>!l&&u(null),children:(0,o.jsxs)("div",{style:{background:"var(--color-background-primary)",borderRadius:"var(--border-radius-lg)",padding:24,width:380,maxWidth:"90vw"},onClick:e=>e.stopPropagation(),children:[(0,o.jsxs)("div",{style:{fontSize:15,fontWeight:600,marginBottom:12,color:"var(--color-text-primary)"},children:["Reject ",x.ids.length," candidate",1!==x.ids.length?"s":""]}),(0,o.jsxs)("label",{style:{display:"flex",gap:8,alignItems:"center",fontSize:13,color:"var(--color-text-primary)",marginBottom:8,cursor:"pointer"},children:[(0,o.jsx)("input",{type:"radio",checked:"permanent"===y,onChange:()=>v("permanent")}),"Permanent - never resurface this code"]}),(0,o.jsxs)("label",{style:{display:"flex",gap:8,alignItems:"center",fontSize:13,color:"var(--color-text-primary)",marginBottom:8,cursor:"pointer"},children:[(0,o.jsx)("input",{type:"radio",checked:"temporary"===y,onChange:()=>v("temporary")}),"Temporary - eligible for rediscovery after"]}),"temporary"===y&&(0,o.jsx)("input",{type:"date",value:b,onChange:e=>f(e.target.value),style:{marginLeft:26,marginBottom:8,padding:"4px 8px",fontSize:13,border:"0.5px solid var(--color-border-tertiary)",borderRadius:6,background:"var(--color-background-primary)",color:"var(--color-text-primary)"}}),(0,o.jsxs)("div",{style:{display:"flex",gap:8,justifyContent:"flex-end",marginTop:16},children:[(0,o.jsx)("button",{onClick:()=>u(null),disabled:l,style:W("transparent","var(--color-text-secondary)"),children:"Cancel"}),(0,o.jsx)("button",{onClick:_,disabled:l,style:W("var(--color-text-danger, #dc2626)","#fff"),children:l?"Working...":"Reject"})]})]})})]})}let y=["Fashion","Electronics","Travel","Beauty","General","Home","Food","Entertainment","Health","Sports","Auto","Finance"],v=["ShareASale","CJ Affiliate","Impact","Rakuten Advertising","Awin","Partnerize","Pepperjam","FlexOffers","Direct","Other"],b=[{id:"hero_carousel",label:"Homepage hero carousel",desc:"Top banner, highest visibility"},{id:"featured_grid",label:"Homepage featured grid",desc:"Featured stores section on homepage"},{id:"category_featured",label:"Category page featured",desc:"Top of category pages"},{id:"search_boost",label:"Search results boost",desc:"Appears first in search results"},{id:"sidebar",label:"Sidebar placement",desc:"Side rail on store pages"},{id:"newsletter",label:"Email newsletter",desc:"Featured in weekly email"}],f={name:"",url:"",description:"",category:"General",cashback_rate:"",affiliate_network:"",affiliate_link:"",logo_text:"",logo_color:"#111111",is_active:!0,is_featured:!1,cookie_duration_days:30,tracking_speed:"1-3 days",payout_speed:"30-60 days"};function m(e){if(!e)return"";let r=Math.floor((Date.now()-new Date(e).getTime())/6e4);if(r<1)return"just now";if(r<60)return"".concat(r,"m ago");let t=Math.floor(r/60);return t<24?"".concat(t,"h ago"):"".concat(Math.floor(t/24),"d ago")}function j(e){var r;let{item:t,isSelected:a,onToggleSelect:n,onAction:i,isLoading:d,isLast:l,showMerchant:s}=e,c=t.dedupe_status||"new",p=(null===(r=t.merchant)||void 0===r?void 0:r.name)||t.merchant_name||"Unknown merchant",x="already_exists"===c?(0,o.jsx)("span",{style:{fontSize:10,padding:"2px 7px",borderRadius:10,background:"#1D9E7515",color:"#1D9E75",fontWeight:600,whiteSpace:"nowrap"},children:"Already live"}):"superseded"===c?(0,o.jsx)("span",{style:{fontSize:10,padding:"2px 7px",borderRadius:10,background:"#E85D0415",color:"#E85D04",fontWeight:600,whiteSpace:"nowrap"},children:"Update"}):(0,o.jsx)("span",{style:{fontSize:10,padding:"2px 7px",borderRadius:10,background:"#2775CA15",color:"#2775CA",fontWeight:600,whiteSpace:"nowrap"},children:"New"});return(0,o.jsxs)("div",{style:{padding:"10px 16px",display:"flex",alignItems:"center",gap:10,borderBottom:l?"none":"0.5px solid var(--color-border-tertiary)",opacity:d?.5:1,transition:"opacity 0.15s"},children:[(0,o.jsx)("input",{type:"checkbox",checked:a,onChange:n,disabled:d,style:{cursor:d?"default":"pointer",flexShrink:0}}),(0,o.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,o.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginBottom:3,flexWrap:"wrap"},children:[s&&(0,o.jsx)("span",{style:{fontSize:12,fontWeight:600,color:"var(--color-text-primary)"},children:p}),t.code&&(0,o.jsx)("span",{style:{fontSize:12,fontFamily:"var(--font-mono)",padding:"2px 7px",borderRadius:4,background:"var(--color-background-secondary)",color:"var(--color-text-primary)",fontWeight:600,letterSpacing:.3},children:t.code}),(0,o.jsx)("span",{style:{fontSize:13,color:"var(--color-text-primary)"},children:t.title||t.description||"Untitled"}),x]}),(0,o.jsxs)("div",{style:{fontSize:11,color:"var(--color-text-secondary)",display:"flex",gap:8,flexWrap:"wrap"},children:[t.item_type&&(0,o.jsx)("span",{style:{textTransform:"capitalize"},children:String(t.item_type).replace(/_/g," ")}),t.min_purchase&&(0,o.jsxs)("span",{children:["\xb7 Min $",t.min_purchase]}),t.expires_at&&(0,o.jsxs)("span",{children:["\xb7 Expires ",new Date(t.expires_at).toLocaleDateString()]}),null!=t.tier_position&&(0,o.jsxs)("span",{children:["\xb7 Tier ",t.tier_position]})]})]}),(0,o.jsxs)("div",{style:{display:"flex",gap:4,flexShrink:0},children:["already_exists"===c?(0,o.jsx)("button",{onClick:()=>i("skip"),disabled:d,title:"Mark as handled without creating a duplicate",style:{background:"#1D9E75",color:"#fff",border:"none",padding:"5px 12px",borderRadius:"var(--border-radius-md)",fontSize:11,fontWeight:500,cursor:d?"default":"pointer"},children:"Skip"}):(0,o.jsx)("button",{onClick:()=>i("approve"),disabled:d,style:{background:"superseded"===c?"#E85D04":"#1D9E75",color:"#fff",border:"none",padding:"5px 12px",borderRadius:"var(--border-radius-md)",fontSize:11,fontWeight:500,cursor:d?"default":"pointer"},children:"superseded"===c?"Update":"Approve"}),(0,o.jsx)("button",{onClick:()=>i("reject"),disabled:d,style:{background:"none",border:"0.5px solid var(--color-border-danger)",padding:"5px 10px",borderRadius:"var(--border-radius-md)",fontSize:11,cursor:d?"default":"pointer",color:"var(--color-text-danger)"},children:"Reject"})]})]})}function k(){var e,r,t,d;let{isSignedIn:l}=(0,n.aF)(),[s,c]=(0,a.useState)([]),[x,h]=(0,a.useState)(!0),[g,k]=(0,a.useState)("overview"),[S,w]=(0,a.useState)(!1),[_,C]=(0,a.useState)(null),[z,R]=(0,a.useState)({...f}),[A,W]=(0,a.useState)(""),[D,E]=(0,a.useState)("All"),[T,F]=(0,a.useState)("All"),[I,B]=(0,a.useState)(!1),[N,P]=(0,a.useState)(null),[O,L]=(0,a.useState)(""),[M,U]=(0,a.useState)(null),[J,V]=(0,a.useState)([]),[H,q]=(0,a.useState)({merchant_id:"",placement_type:"",start_date:"",end_date:"",priority:0,notes:""}),[$,X]=(0,a.useState)(null),[K,G]=(0,a.useState)("all"),[Y,Z]=(0,a.useState)(null),[Q,ee]=(0,a.useState)(!0),[er,et]=(0,a.useState)(null),[eo,ea]=(0,a.useState)("discovered_at"),[en,ei]=(0,a.useState)("desc"),[ed,el]=(0,a.useState)([]),[es,ec]=(0,a.useState)({}),[ep,ex]=(0,a.useState)(null),[eh,eg]=(0,a.useState)(!1),[eu,ey]=(0,a.useState)(new Set),[ev,eb]=(0,a.useState)(new Set),[ef,em]=(0,a.useState)(!1),[ej,ek]=(0,a.useState)(null),[eS,ew]=(0,a.useState)(null),[e_,eC]=(0,a.useState)(!1),[ez,eR]=(0,a.useState)(null),[eA,eW]=(0,a.useState)(!1),[eD,eE]=(0,a.useState)("all"),eT=(0,a.useCallback)(async()=>{try{let e=await fetch("/api/merchants?active=false"),r=await e.json();c(r.merchants||[])}catch(e){console.error("Failed to fetch merchants:",e)}finally{h(!1)}},[]);(0,a.useEffect)(()=>{eT()},[eT]);let eF=(0,a.useCallback)(async()=>{try{let e=await fetch("/api/admin/placements"),r=await e.json();V(r.placements||[])}catch(e){console.error("Failed to fetch placements:",e)}},[]);(0,a.useEffect)(()=>{eF()},[eF]);let eI=(0,a.useCallback)(async()=>{try{ee(!0);let e=await fetch("/api/admin/dashboard"),r=await e.json();r.success&&Z(r)}catch(e){console.error("Failed to fetch dashboard:",e)}finally{ee(!1)}},[]);(0,a.useEffect)(()=>{eI()},[eI]);let eB=(0,a.useCallback)(async()=>{try{let e=await fetch("/api/categories"),r=await e.json();el(r.categories||[])}catch(e){console.error("Failed to fetch categories:",e)}},[]);(0,a.useEffect)(()=>{eB()},[eB]);let eN=(0,a.useCallback)(async()=>{try{eg(!0);let e=await fetch("/api/admin/pending-items"),r=await e.json();r.success&&ex(r)}catch(e){console.error("Failed to fetch pending items:",e)}finally{eg(!1)}},[]);(0,a.useEffect)(()=>{eN()},[eN]);let eP=(0,a.useCallback)(async()=>{try{eC(!0);let e=await fetch("/api/admin/rate-changes"),r=await e.json();r.error||ew(r)}catch(e){console.error("Failed to fetch rate changes:",e)}finally{eC(!1)}},[]);(0,a.useEffect)(()=>{eP()},[eP]);let eO=(0,a.useCallback)(async()=>{try{eW(!0);let e=await fetch("/api/admin/commissions"),r=await e.json();r.error||eR(r)}catch(e){console.error("Failed to fetch commissions:",e)}finally{eW(!1)}},[]);(0,a.useEffect)(()=>{eO()},[eO]);let eL=(0,a.useCallback)(()=>{eT(),eF(),eI(),eN(),eP(),eO()},[eT,eF,eI,eN,eP,eO]),eM=function(e){let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"success";P({text:e,type:r}),setTimeout(()=>P(null),3e3)},eU=async(e,r)=>{ek(e);try{let t=await fetch("/api/deal-action",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({item_id:e,deal_id:e,action:r})}),o=await t.json().catch(()=>({}));if(!t.ok)throw Error(o.error||"Action failed");eM("Item ".concat("approve"===r?"approved":"reject"===r?"rejected":"skipped")),eN(),eI()}catch(e){eM("Failed: ".concat(e.message),"error")}finally{ek(null)}},eJ=async(e,r)=>{if(0!==e.length&&confirm("".concat("approve"===r?"Approve":"reject"===r?"Reject":"Skip"," ").concat(e.length," item").concat(1!==e.length?"s":"","?"))){em(!0);try{let t=(await Promise.allSettled(e.map(e=>fetch("/api/deal-action",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({item_id:e,deal_id:e,action:r})}).then(e=>e.ok?e:Promise.reject(e))))).filter(e=>"fulfilled"===e.status).length,o=e.length-t;0===o?eM("".concat(t," item").concat(1!==t?"s":""," ").concat("approve"===r?"approved":"reject"===r?"rejected":"skipped")):eM("".concat(t," succeeded, ").concat(o," failed"),o>t?"error":"success"),eb(new Set),eN(),eI()}catch(e){eM("Bulk action failed: ".concat(e.message),"error")}finally{em(!1)}}},eV=e=>{ey(r=>{let t=new Set(r);return t.has(e)?t.delete(e):t.add(e),t})},eH=e=>{eb(r=>{let t=new Set(r);return t.has(e)?t.delete(e):t.add(e),t})},eq=e=>{let r=e.map(e=>e.id),t=r.every(e=>ev.has(e));eb(e=>{let o=new Set(e);
1return t?r.forEach(e=>o.delete(e)):r.forEach(e=>o.add(e)),o})},e$=async e=>{et(e.id);try{let r=e.network||"cj",t=es[e.id],o=(void 0!==t?t:e.mapped_category)||null,a={network:r,merchant_name:e.advertiser_name,category:o};"rakuten"===r?a.rakuten_mid=e.rakuten_mid:"impact"===r?(a.impact_campaign_id=e.impact_campaign_id,a.discovery_id=e.id):a.cj_advertiser_id=e.cj_advertiser_id;let n=await fetch("/api/auto-onboard",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)}),i=await n.json();i.success?(eM("".concat(e.advertiser_name," onboarded! ").concat(i.pageUrl||"")),eI(),eT()):eM(i.error||"Onboard failed","error")}catch(e){eM("Failed to onboard","error")}finally{et(null)}},eX=async e=>{try{if(!(await fetch("/api/admin/discovery-update",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:e.id,status:"skipped"})})).ok)throw Error("Skip failed");eM("".concat(e.advertiser_name," skipped")),eI()}catch(e){eM("Failed to skip","error")}},eK=e=>{eo===e?ei("asc"===en?"desc":"asc"):(ea(e),ei(["seven_day_epc","three_month_epc","network_rank","base_commission_rate","cashback_rate","cookie_duration_days","discovered_at"].includes(e)?"desc":"asc"))},eG=async()=>{if(!z.name||!z.url||!z.cashback_rate){eM("Name, URL, and cashback rate are required","error");return}B(!0);try{let e=_?"PUT":"POST",r=_?{id:_,...z}:z;if(!(await fetch("/api/admin/merchants",{method:e,headers:{"Content-Type":"application/json"},body:JSON.stringify(r)})).ok)throw Error("Save failed");eM(_?"Merchant updated":"Merchant added"),w(!1),C(null),R({...f}),eT()}catch(e){eM("Failed to save merchant","error")}finally{B(!1)}},eY=async e=>{try{await fetch("/api/admin/merchants",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:e.id,is_active:!e.is_active})}),eT()}catch(e){eM("Failed to update","error")}},eZ=async e=>{try{await fetch("/api/admin/merchants",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:e.id,is_featured:!e.is_featured})}),eT()}catch(e){eM("Failed to update","error")}},eQ=async e=>{if(confirm("Delete this merchant? This cannot be undone."))try{await fetch("/api/admin/merchants",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:e})}),eM("Merchant deleted"),eT()}catch(e){eM("Failed to delete","error")}},e0=e=>{C(e.id),R({name:e.name||"",url:e.url||"",description:e.description||"",category:e.category||"General",cashback_rate:e.cashback_rate||"",affiliate_network:e.affiliate_network||"",affiliate_link:e.affiliate_link||"",logo_text:e.logo_text||"",logo_color:e.logo_color||"#111111",is_active:!1!==e.is_active,is_featured:e.is_featured||!1,cookie_duration_days:e.cookie_duration_days||30,tracking_speed:e.tracking_speed||"1-3 days",payout_speed:e.payout_speed||"30-60 days"}),w(!0)},e1=async()=>{if(!O.trim()){eM("Paste CSV data first","error");return}U(null);try{let e=O.trim().split("\n"),r=e[0].split(",").map(e=>e.trim().toLowerCase().replace(/\s+/g,"_")),t=e.slice(1).map(e=>{let t=e.split(",").map(e=>e.trim()),o={};return r.forEach((e,r)=>{o[e]=t[r]||""}),o}),o=await fetch("/api/admin/import-merchants",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({merchants:t})}),a=await o.json();if(!o.ok)throw Error(a.error||"Import failed");U(a),eM("Imported ".concat(a.imported," merchants")),L(""),eT()}catch(e){eM(e.message||"Import failed","error")}},e2=async()=>{if(!H.merchant_id||!H.placement_type||!H.start_date||!H.end_date){eM("Merchant, placement type, and dates are required","error");return}B(!0);try{let e=$?"PUT":"POST",r=$?{id:$,...H}:H;if(!(await fetch("/api/admin/placements",{method:e,headers:{"Content-Type":"application/json"},body:JSON.stringify(r)})).ok)throw Error("Save failed");eM($?"Placement updated":"Placement scheduled"),q({merchant_id:"",placement_type:"",start_date:"",end_date:"",priority:0,notes:""}),X(null),eF()}catch(e){eM("Failed to save placement","error")}finally{B(!1)}},e5=async e=>{if(confirm("Delete this placement?"))try{await fetch("/api/admin/placements",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:e})}),eM("Placement deleted"),eF()}catch(e){eM("Failed to delete","error")}},e6=async e=>{try{await fetch("/api/admin/placements",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:e.id,is_active:!e.is_active})}),eF()}catch(e){eM("Failed to update","error")}},e4=new Date().toISOString().split("T")[0],e8=J.filter(e=>"active"===K?e.is_active&&e.end_date>=e4:"upcoming"===K?e.start_date>e4:"past"!==K||e.end_date<e4),e3=s.filter(e=>
1(!A||!!e.name.toLowerCase().includes(A.toLowerCase()))&&("All"===D||(e.affiliate_network||"None")===D)&&("All"===T||e.category===T)),e7=(null==ep?void 0:null===(e=ep.stats)||void 0===e?void 0:e.total)||0,e9={padding:"10px 12px",fontSize:11,fontWeight:600,color:"var(--color-text-secondary)",textAlign:"left",textTransform:"uppercase",letterSpacing:.3,whiteSpace:"nowrap"},re={...e9,textAlign:"right"},rr={padding:"8px 12px",color:"var(--color-text-primary)",verticalAlign:"top"},rt={...rr,textAlign:"right",fontVariantNumeric:"tabular-nums"},ro=(null==Y?void 0:Y.stats)||{totalMerchants:s.length,activeMerchants:s.filter(e=>e.is_active).length,featuredMerchants:s.filter(e=>e.is_featured).length,networks:[...new Set(s.map(e=>e.affiliate_network).filter(Boolean))].length,activeCoupons:0,newDiscoveries:0,publishedPosts:0};return l?(0,o.jsxs)(i.Z,{title:"Admin panel",subtitle:"Manage merchants, track performance, and configure your store.",children:[N&&(0,o.jsx)("div",{style:{padding:"10px 16px",borderRadius:"var(--border-radius-md)",marginBottom:16,fontSize:14,background:"error"===N.type?"var(--color-background-danger)":"var(--color-background-success)",color:"error"===N.type?"var(--color-text-danger)":"var(--color-text-success)"},children:N.text}),(0,o.jsx)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(100px, 1fr))",gap:10,marginBottom:24},children:[["Merchants",ro.activeMerchants],["Coupons",ro.activeCoupons],["Blog posts",ro.publishedPosts],["Pending",e7,e7>0?"#E85D04":null,"pending items"],["Discoveries",ro.newDiscoveries,ro.newDiscoveries>0?"#2775CA":null,"discoveries"],["Networks",ro.networks]].map(e=>{let[r,t,a,n]=e;return(0,o.jsxs)("div",{style:{padding:14,borderRadius:"var(--border-radius-md)",background:a?"".concat(a,"10"):"var(--color-background-secondary)",border:a?"1px solid ".concat(a,"30"):"none",cursor:n?"pointer":"default"},onClick:()=>{n&&k(n)},children:[(0,o.jsx)("div",{style:{fontSize:12,color:a||"var(--color-text-secondary)"},children:r}),(0,o.jsx)("div",{style:{fontSize:22,fontWeight:600,color:a||"var(--color-text-primary)",marginTop:2},children:t})]},r)})}),(0,o.jsx)("div",{style:{display:"flex",gap:2,marginBottom:20,borderBottom:"0.5px solid var(--color-border-tertiary)",overflowX:"auto"},children:["overview","merchants","add new","pending items","coupon queue","discoveries","rate changes","commissions","placements","bulk import"].map(e=>(0,o.jsxs)("button",{onClick:()=>{k(e),"add new"===e&&(w(!0),C(null),R({...f}))},style:{padding:"10px 14px",fontSize:13,fontWeight:500,cursor:"pointer",border:"none",borderBottom:g===e?"2px solid var(--color-text-primary)":"2px solid transparent",background:"transparent",color:g===e?"var(--color-text-primary)":"var(--color-text-secondary)",textTransform:"capitalize",marginBottom:-.5,whiteSpace:"nowrap",position:"relative"},children:[e,"pending items"===e&&e7>0&&(0,o.jsx)("span",{style:{position:"absolute",top:4,right:2,width:8,height:8,borderRadius:"50%",background:"#E85D04"}}),"discoveries"===e&&ro.newDiscoveries>0&&(0,o.jsx)("span",{style:{position:"absolute",top:4,right:2,width:8,height:8,borderRadius:"50%",background:"#2775CA"}})]},e))}),"overview"===g&&(0,o.jsxs)("div",{children:[(0,o.jsx)("h3",{style:{fontSize:17,fontWeight:600,margin:"0 0 16px",color:"var(--color-text-primary)"},children:"Activity feed"}),Q?(0,o.jsx)("div",{style:{padding:32,textAlign:"center",color:"var(--color-text-secondary)",fontSize:14},children:"Loading..."}):(null==Y?void 0:Y.activity)&&0!==Y.activity.length?(0,o.jsx)("div",{style:{borderRadius:"var(--border-radius-lg)",border:"0.5px solid var(--color-border-tertiary)",overflow:"hidden",background:"var(--color-background-primary)"},children:Y.activity.map((e,r)=>(0,o.jsxs)("div",{style:{padding:"12px 16px",borderBottom:r<Y.activity.length-1?"0.5px solid var(--color-border-tertiary)":"none",display:"flex",alignItems:"flex-start",gap:10},children:[(0,o.jsx)("div",{style:{width:8,height:8,borderRadius:"50%",marginTop:6,flexShrink:0,background:"rate_change"===e.type?"#E85D04":"coupon"===e.type?"#1D9E75":"merchant_added"===e.type?"#2775CA":"#888"}}),(0,o.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,o.jsx)("div",{style:{fontSize:13,fontWeight:500,color:"var(--color-text-primary)"},children:e.title}),(0,o.jsx)("div",{style:{fontSize:12,color:"var(--color-text-secondary)",marginTop:2},children:e.detail})]}),(0,o.jsx)("div",{style:{fontSize:11,color:"var(--color-text-secondary)",whiteSpace:"nowrap",flexShrink:0},children:m(e.timestamp)})]},r))}):(0,o.jsx)("div",{style:{padding:32,textAlign:"center",color:"var(--color-text-secondary)",fontSize:14},children:"No recent activity in the last 7 days."}),(e7>0||(null==Y?void 0:null===(r=Y.discoveries)||void 0===r?void 0:r.length)>0)&&(0,o.jsxs)("div",{style:{display:"flex",gap:12,marginTop:20,flexWrap:"wrap"},children:[e7>0&&(0,o.jsxs)("button",{onClick:()=>k("pending items"),style:{background:"#E85D0410",border:"1px solid #E85D0430",borderRadius:"var(--border-radius-md)",padding:"10px 16px",fontSize:13,fontWeight:500,cursor:"pointer",color:"#E85D04"},children:[e7," pending item",1!==e7?"s":""," to review"]}),(null==Y?void 0:null===(t=Y.discoveries)||void 0===t?void 0:t.length)>0&&(0,o.jsxs)("button",{onClick:()=>k("discoveries"),style:{background:"#2775CA10",border:"1px solid #2775CA30",borderRadius:"var(--border-radius-md)",padding:"10px 16px",fontSize:13,fontWeight:500,cursor:"pointer",color:"#2775CA"},children:[Y.discoveries.length," new merchant",1!==Y.discoveries.length?"s":""," discovered"]})]})]}),"pending items"===g&&(0,o.jsxs)("div",{children:[(0,o.jsx)("h3",{style:{fontSize:17,fontWeight:600,margin:"0 0 8px",color:"var(--color-text-primary)"},children:"Pending items"}),(0,o.jsx)("p",{style:{fontSize:13,color:"var(--color-text-secondary)",margin:"0 0 16px"},children:"Items extracted from ingested emails and waiting for approval. Click a group header to expand and see individual items."}),eh&&!ep?(0,o.jsx)("div",{style:{padding:32,textAlign:"center",color:"var(--color-text-secondary)",fontSize:14},children:"Loading..."}):ep&&(0!==ep.groups.length||0!==ep.orphans.length)?(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)("div",{style:{display:"flex",gap:10,marginBottom:16,flexWrap:"wrap",fontSize:12,color:"var(--color-text-secondary)",alignItems:"center"},children:[(0,o.jsxs)("span",{children:[(0,o.jsx)("strong",{style:{color:"var(--color-text-primary)",fontSize:13},children:ep.stats.total})," items"]}),(0,o.jsx)("span",{children:"\xb7"}),(0,o.jsxs)("span",{children:[(0,o.jsx)("strong",{style:{color:"var(--color-text-primary)",fontSize:13},children:ep.stats.grouped})," email group",1!==ep.stats.grouped?"s":""]}),ep.stats.orphans>0&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("span",{children:"\xb7"}),(0,o.jsxs)("span",{children:[(0,o.jsx)("strong",{children:ep.stats.orphans})," ungrouped"]})]}),ep.stats.new>0&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("span",{children:"\xb7"}),(0,o.jsxs)("span",{style:{color:"#2775CA"},children:[(0,o.jsx)("strong",{children:ep.stats.new})," new"]})]}),ep.stats.already_exists>0&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("span",{children:"\xb7"}),(0,o.jsxs)("span",{style:{color:"#1D9E75"},children:[(0,o.jsx)("strong",{children:ep.stats.already_exists})," already live"]})]}),ep.stats.superseded>0&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("span",{children:"\xb7"}),(0,o.jsxs)("span",{style:{color:"#E85D04"},children:[(0,o.jsx)("strong",{children:ep.stats.superseded})," updates"]})]})]}),ev.size>0&&(0,o.jsxs)("div",{style:{position:"sticky",top:0,zIndex:10,display:"flex",gap:10,alignItems:"center",padding:"10px 14px",background:"var(--color-background-primary)",border:"1px solid #2775CA50",borderRadius:"var(--border-radius-md)",marginBottom:12,boxShadow:"0 2px 10px rgba(0,0,0,0.08)"},children:[(0,o.jsxs)("span",{style:{fontSize:13,fontWeight:600,color:"var(--color-text-primary)"},children:[ev.size," selected"]}),(0,o.jsx)("div",{style:{flex:1}}),(0,o.jsx)("button",{onClick:()=>eJ([...ev],"approve"),disabled:ef,style:{background:"#1D9E75",color:"#fff",border:"none",padding:"6px 14px",borderRadius:"var(--border-radius-md)",fontSize:12,fontWeight:500,cursor:ef?"default":"pointer",opacity:ef?.6:1},children:ef?"Working...":"Approve all selected"}),(0,o.jsx)("button",{onClick:()=>eJ([...ev],"reject"),disabled:ef,style:{background:"transparent",color:"var(--color-text-danger)",border:"0.5px solid var(--color-border-danger)",padding:"6px 14px",borderRadius:"var(--border-radius-md)",fontSize:12,fontWeight:500,cursor:ef?"default":"pointer",opacity:ef?.6:1},children:"Reject all"}),(0,o.jsx)("button",{onClick:()=>eb(new Set),style:{background:"transparent",border:"none",padding:"6px 10px",fontSize:12,cursor:"pointer",color:"var(--color-text-secondary)"},children:"Clear"})]}),ep.groups.map(e=>{var r,t,a,n,i;let d=eu.has(e.parent_email_id),l=e.items.map(e=>e.id),s=l.filter(e=>ev.has(e)).length,c=s===l.length&&l.length>0,p=(null===(r=e.merchant)||void 0===r?void 0:r.name)||e.merchant_name||"Unknown merchant",x=(null===(t=e.merchant)||void 0===t?void 0:t.logo_color)||"#111",h=(null===(a=e.merchant)||void 0===a?void 0:a.logo_text)||p.substring(0,2).toUpperCase();return(0,o.jsxs)("div",{style:{borderRadius:"var(--border-radius-lg)",border:"0.5px solid var(--color-border-tertiary)",background:"var(--color-background-primary)",marginBottom:10,overflow:"hidden"},children:[(0,o.jsxs)("div",{onClick:()=>eV(e.parent_email_id),style:{padding:"12px 14px",display:"flex",alignItems:"center",gap:10,cursor:"pointer",background:d?"var(--color-background-secondary)":"transparent",borderBottom:d?"0.5px solid var(--color-border-tertiary)":"none"},children:[(0,o.jsx)("input",{type:"checkbox",checked:c,ref:e=>{e&&(e.indeterminate=s>0&&!c)},onChange:r=>{r.stopPropagation(),eq(e.items)},onClick:e=>e.stopPropagation(),style:{cursor:"pointer",flexShrink:0}}),(0,o.jsx)("div",{style:{width:32,height:32,borderRadius:"var(--border-radius-md)",background:x,display:"flex",alignItems:"center",justifyContent:"center",color:"#fff",fontSize:11,fontWeight:600,flexShrink:0},children:h}),(0,o.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,o.jsxs)("div",{style:{fontSize:14,fontWeight:600,color:"var(--color-text-primary)",display:"flex",alignItems:"center",gap:8},children:[p,(0,o.jsxs)("span",{style:{fontSize:11,padding:"2px 8px",borderRadius:10,background:"var(--color-background-tertiary)",color:"var(--color-text-secondary)",fontWeight:500},children:[e.items.length," item",1!==e.items.length?"s":""]})]}),(0,o.jsxs)("div",{style:{fontSize:11,color:"var(--color-text-secondary)",marginTop:2,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis"},children:[(null===(n=e.email)||void 0===n?void 0:n.subject)||"No subject"," \xb7 ",(null===(i=e.email)||void 0===i?void 0:i.received_at)?m(e.email.received_at):""]})]}),(0,o.jsx)("button",{onClick:e=>{e.stopPropagation(),eJ(l,"approve")}
1,disabled:ef,title:"Approve every item in this group",style:{background:"#1D9E75",color:"#fff",border:"none",padding:"5px 12px",borderRadius:"var(--border-radius-md)",fontSize:11,fontWeight:500,cursor:ef?"default":"pointer",opacity:ef?.6:1,whiteSpace:"nowrap"},children:"Approve all"}),(0,o.jsx)("span",{style:{fontSize:16,color:"var(--color-text-secondary)",transform:d?"rotate(90deg)":"none",transition:"transform 0.15s",display:"inline-block",width:12,textAlign:"center"},children:"›"})]}),d&&(0,o.jsx)("div",{children:e.items.map((r,t)=>(0,o.jsx)(j,{item:r,isSelected:ev.has(r.id),onToggleSelect:()=>eH(r.id),onAction:e=>eU(r.id,e),isLoading:ej===r.id,isLast:t===e.items.length-1},r.id))})]},e.parent_email_id)}),ep.orphans.length>0&&(0,o.jsxs)("div",{style:{marginTop:20},children:[(0,o.jsxs)("h4",{style:{fontSize:12,fontWeight:600,color:"var(--color-text-secondary)",textTransform:"uppercase",letterSpacing:.5,margin:"0 0 10px"},children:["Ungrouped items (",ep.orphans.length,")"]}),(0,o.jsx)("div",{style:{borderRadius:"var(--border-radius-lg)",border:"0.5px solid var(--color-border-tertiary)",background:"var(--color-background-primary)",overflow:"hidden"},children:ep.orphans.map((e,r)=>(0,o.jsx)(j,{item:e,isSelected:ev.has(e.id),onToggleSelect:()=>eH(e.id),onAction:r=>eU(e.id,r),isLoading:ej===e.id,isLast:r===ep.orphans.length-1,showMerchant:!0},e.id))})]})]}):(0,o.jsxs)("div",{style:{padding:48,textAlign:"center",border:"0.5px solid var(--color-border-tertiary)",borderRadius:"var(--border-radius-lg)",background:"var(--color-background-primary)"},children:[(0,o.jsx)("div",{style:{fontSize:40,marginBottom:12},children:"\uD83C\uDF89"}),(0,o.jsx)("div",{style:{fontSize:16,fontWeight:500,color:"var(--color-text-primary)"},children:"All caught up"}),(0,o.jsx)("div",{style:{fontSize:13,color:"var(--color-text-secondary)",marginTop:4},children:"No pending items to review."})]})]}),"discoveries"===g&&(()=>{let e=(null==Y?void 0:Y.discoveries)||[],r=["seven_day_epc","three_month_epc","network_rank","base_commission_rate","cashback_rate","cookie_duration_days"],t=["discovered_at"],a=[...e].sort((e,o)=>{let a=e[eo],n=o[eo];return(r.includes(eo)?(a=parseFloat(a)||0,n=parseFloat(n)||0):t.includes(eo)?(a=new Date(a).getTime()||0,n=new Date(n).getTime()||0):(a=(a||"").toString().toLowerCase(),n=(n||"").toString().toLowerCase()),a<n)?"asc"===en?-1:1:a>n?"asc"===en?1:-1:0}),n=e=>{let{label:r,field:t,align:a="left"}=e,n=eo===t;return(0,o.jsxs)("th",{onClick:()=>eK(t),style:{padding:"10px 12px",fontSize:11,fontWeight:600,color:n?"var(--color-text-primary)":"var(--color-text-secondary)",textAlign:a,textTransform:"uppercase",letterSpacing:.3,userSelect:"none",cursor:"pointer",whiteSpace:"nowrap",background:n?"var(--color-background-tertiary)":"transparent"},children:[r," ",(0,o.jsx)("span",{style:{fontSize:10,opacity:n?1:.3,marginLeft:2},children:(n?"asc"===en?"↑":"↓":"")||"⇅"})]})};return(0,o.jsxs)("div",{children:[(0,o.jsx)("h3",{style:{fontSize:17,fontWeight:600,margin:"0 0 8px",color:"var(--color-text-primary)"},children:"New merchant discoveries"}),(0,o.jsx)("p",{style:{fontSize:13,color:"var(--color-text-secondary)",margin:"0 0 16px"},children:"Found by the daily CJ and Rakuten discovery crons. Click any column header to sort. Low-quality CJ rows (rank ≤ 1 and no recent EPC) are dimmed. Rakuten rows show — for CJ-specific metrics (rank, EPC)."}),Q?(0,o.jsx)("div",{style:{padding:32,textAlign:"center",color:"var(--color-text-secondary)",fontSize:14},children:"Loading..."}):0===a.length?(0,o.jsx)("div",{style:{padding:32,textAlign:"center",color:"var(--color-text-secondary)",fontSize:14},children:"No new discoveries. All caught up!"}):(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)("div",{style:{padding:"10px 16px",fontSize:13,fontWeight:500,color:"var(--color-text-primary)",background:"var(--color-background-secondary)",border:"0.5px solid var(--color-border-tertiary)",borderBottom:"none",borderRadius:"var(--border-radius-lg) var(--border-radius-lg) 0 0"},children:[a.length," awaiting review"]}),(0,o.jsx)("div",{style:{overflowX:"auto",border:"0.5px solid var(--color-border-tertiary)",borderRadius:"0 0 var(--border-radius-lg) var(--border-radius-lg)",background:"var(--color-background-primary)"},children:(0,o.jsxs)("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12,minWidth:920},children:[(0,o.jsx)("thead",{children:(0,o.jsxs)("tr",{style:{borderBottom:"0.5px solid var(--color-border-tertiary)"},children:[(0,o.jsx)(n,{label:"Merchant",field:"advertiser_name",align:"left"}),(0,o.jsx)(n,{label:"Network",field:"network",align:"center"}),(0,o.jsx)(n,{label:"Category",field:"mapped_category",align:"left"}),(0,o.jsx)(n,{label:"Rank",field:"network_rank",align:"center"}),(0,o.jsx)(n,{label:"7d EPC",field:"seven_day_epc",align:"right"}),(0,o.jsx)(n,{label:"3m EPC",field:"three_month_epc",align:"right"}),(0,o.jsx)(n,{label:"Commission",field:"base_commission_rate",align:"right"}),(0,o.jsx)(n,{label:"Added",field:"discovered_at",align:"right"}),(0,o.jsx)("th",{style:{padding:"10px 12px",fontSize:11,fontWeight:600,color:"var(--color-text-secondary)",textAlign:"center",textTransform:"uppercase",letterSpacing:.3},children:"Link"}),(0,o.jsx)("th",{style:{padding:"10px 12px",fontSize:11,fontWeight:600,color:"var(--color-text-secondary)",textAlign:"right",textTransform:"uppercase",letterSpacing:.3},children:"Actions"})]})}),(0,o.jsx)("tbody",{children:a.map((e,r)=>{let t="rakuten"===e.network,n="impact"===e.network,i="cj"===e.network,d=parseInt(e.network_rank)||0,l=parseFloat(e.seven_day_epc)||0,s=parseFloat(e.three_month_epc)||0,c=i&&d<=1&&l<1,p=(0,o.jsx)("span",{style:{color:"var(--color-text-secondary)"},children:"—"});return(0,o.jsxs)("tr",{style:{borderBottom:r<a.length-1?"0.5px solid var(--color-border-tertiary)":"none",opacity:c?.5:1},children:[(0,o.jsx)("td",{style:{padding:"8px 12px"},children:(0,o.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[(0,o.jsx)("div",{style:{width:28,height:28,borderRadius:"var(--border-radius-md)",background:"#1A1A1A",dis
1play:"flex",alignItems:"center",justifyContent:"center",color:"#fff",fontSize:10,fontWeight:600,flexShrink:0},children:(e.advertiser_name||"??").substring(0,2).toUpperCase()}),(0,o.jsxs)("div",{style:{minWidth:0},children:[(0,o.jsx)("div",{style:{fontSize:12,fontWeight:500,color:"var(--color-text-primary)",whiteSpace:"nowrap"},children:e.advertiser_name}),(0,o.jsx)("div",{style:{fontSize:10,color:"var(--color-text-secondary)"},children:n?"CampaignId ".concat(e.impact_campaign_id):t?"MID ".concat(e.rakuten_mid):i?"CID ".concat(e.cj_advertiser_id):""})]})]})}),(0,o.jsx)("td",{style:{padding:"8px 12px",textAlign:"center"},children:n?(0,o.jsx)("span",{style:{fontSize:9,padding:"2px 8px",borderRadius:8,background:"#F5D0FE",color:"#A21CAF",fontWeight:600,textTransform:"uppercase",letterSpacing:.4},children:"Impact"}):t?(0,o.jsx)("span",{style:{fontSize:9,padding:"2px 8px",borderRadius:8,background:"#BF000015",color:"#BF0000",fontWeight:600,textTransform:"uppercase",letterSpacing:.4},children:"Rakuten"}):(0,o.jsx)("span",{style:{fontSize:9,padding:"2px 8px",borderRadius:8,background:"#2775CA15",color:"#2775CA",fontWeight:600,textTransform:"uppercase",letterSpacing:.4},children:"CJ"})}),(0,o.jsx)("td",{style:{padding:"8px 12px",color:"var(--color-text-secondary)"},children:(0,o.jsxs)("select",{value:(void 0!==es[e.id]?es[e.id]:e.mapped_category)||"",onChange:r=>{let t=r.target.value||null;ec(r=>({...r,[e.id]:t}))},style:{fontSize:12,padding:"3px 6px",borderRadius:6,border:"0.5px solid var(--color-border-tertiary)",background:"var(--color-background-primary)",color:"var(--color-text-primary)",cursor:"pointer",minWidth:110},children:[(0,o.jsx)("option",{value:"",children:"(none)"}),ed.map(e=>(0,o.jsx)("option",{value:e.name,children:e.name},e.id||e.name))]})}),(0,o.jsx)("td",{style:{padding:"8px 12px",textAlign:"center"},children:i?(0,o.jsxs)("span",{style:{padding:"2px 8px",borderRadius:10,fontSize:11,fontWeight:600,background:d>=4?"#1D9E7515":d>=2?"var(--color-background-secondary)":"#E85D0415",color:d>=4?"#1D9E75":d>=2?"var(--color-text-secondary)":"#E85D04"},children:[d,"/5"]}):p}),(0,o.jsx)("td",{style:{padding:"8px 12px",textAlign:"right",fontVariantNumeric:"tabular-nums",fontWeight:i&&l>=10?600:400,color:i&&l>=10?"#1D9E75":"var(--color-text-primary)"},children:i?"$".concat(l.toFixed(2)):p}),(0,o.jsx)("td",{style:{padding:"8px 12px",textAlign:"right",fontVariantNumeric:"tabular-nums",color:"var(--color-text-secondary)"},children:i?"$".concat(s.toFixed(2)):p}),(0,o.jsxs)("td",{style:{padding:"8px 12px",textAlign:"right",color:"var(--color-text-secondary)",whiteSpace:"nowrap"},children:["FIXED"===e.commission_type?"$".concat(e.base_commission_rate):"".concat(e.base_commission_rate||0,"%"),e.max_commission_rate&&Number(e.max_commission_rate)!==Number(e.base_commission_rate)&&(0,o.jsxs)("span",{style:{fontSize:10,color:"var(--color-text-secondary)",marginLeft:2},children:["- ","FIXED"===e.commission_type?"$".concat(e.max_commission_rate):"".concat(e.max_commission_rate,"%")]})]}),(0,o.jsx)("td",{style:{padding:"8px 12px",textAlign:"right",color:"var(--color-text-secondary)",whiteSpace:"nowrap"},children:m(e.discovered_at)}),(0,o.jsx)("td",{style:{padding:"8px 12px",textAlign:"center"},children:e.evergreen_link?(0,o.jsx)("span",{title:e.link_type||"has affiliate link",style:{color:"#1D9E75",fontSize:14,fontWeight:700},children:"✓"}):(0,o.jsx)("span",{style:{color:"var(--color-text-secondary)",fontSize:14},children:"-"})}),(0,o.jsxs)("td",{style:{padding:"8px 12px",textAlign:"right",whiteSpace:"nowrap"},children:[(0,o.jsx)("button",{onClick:()=>e$(e),disabled:er===e.id,style:{background:"#1D9E75",color:"#fff",border:"none",padding:"4px 10px",borderRadius:"var(--border-radius-md)",fontSize:11,fontWeight:500,cursor:"pointer",opacity:er===e.id?.6:1,marginRight:4},children:er===e.id?"...":"Onboard"}),(0,o.jsx)("button",{onClick:()=>eX(e),style:{background:"none",border:"0.5px solid var(--color-border-tertiary)",padding:"4px 10px",borderRadius:"var(--border-radius-md)",fontSize:11,cursor:"pointer",color:"var(--color-text-secondary)"},children:"Skip"})]})]},e.id)})})]})})]})]})})(),"rate changes"===g&&(()=>{let e=(null==eS?void 0:eS.rows)||[],r=(null==eS?void 0:eS.pending)||0,t=(null==eS?void 0:eS.recent_applied)||0,a=(e,r)=>null==e?"—":"fixed"===r?"$".concat(Number(e).toFixed(2)):"".concat(Number(e).toFixed(2),"%"),n={pending:{color:"#E85D04",bg:"#E85D0415",label:"Pending"}
1,applied_on_schedule:{color:"#1D9E75",bg:"#1D9E7515",label:"Applied"},applied_early:{color:"#2775CA",bg:"#2775CA15",label:"Applied early"},ignored:{color:"var(--color-text-secondary)",bg:"var(--color-background-secondary)",label:"Held (locked)"},superseded:{color:"var(--color-text-secondary)",bg:"var(--color-background-secondary)",label:"Superseded"}};return(0,o.jsxs)("div",{children:[(0,o.jsx)("h3",{style:{fontSize:17,fontWeight:600,margin:"0 0 8px",color:"var(--color-text-primary)"},children:"Rate changes"}),(0,o.jsx)("p",{style:{fontSize:13,color:"var(--color-text-secondary)",margin:"0 0 16px"},children:"Commission changes detected by the daily sync-rates cron. Network-side acceptance (CJ dashboard, etc.) is manual. Use this as a heads-up and to-do list for when to log in and accept early."}),e_&&!eS?(0,o.jsx)("div",{style:{padding:32,textAlign:"center",color:"var(--color-text-secondary)",fontSize:14},children:"Loading..."}):0===e.length?(0,o.jsxs)("div",{style:{padding:48,textAlign:"center",border:"0.5px solid var(--color-border-tertiary)",borderRadius:"var(--border-radius-lg)",background:"var(--color-background-primary)"},children:[(0,o.jsx)("div",{style:{fontSize:40,marginBottom:12},children:"\uD83D\uDCCA"}),(0,o.jsx)("div",{style:{fontSize:16,fontWeight:500,color:"var(--color-text-primary)"},children:"No rate changes yet"}),(0,o.jsx)("div",{style:{fontSize:13,color:"var(--color-text-secondary)",marginTop:4},children:"The sync-rates cron runs at 6 AM UTC. Any detected changes will show up here."})]}):(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)("div",{style:{display:"flex",gap:10,marginBottom:16,flexWrap:"wrap",fontSize:12,color:"var(--color-text-secondary)",alignItems:"center"},children:[(0,o.jsxs)("span",{children:[(0,o.jsx)("strong",{style:{color:"var(--color-text-primary)",fontSize:13},children:e.length})," total"]}),r>0&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("span",{children:"\xb7"}),(0,o.jsxs)("span",{style:{color:"#E85D04"},children:[(0,o.jsx)("strong",{children:r})," pending"]})]}),t>0&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("span",{children:"\xb7"}),(0,o.jsxs)("span",{style:{color:"#1D9E75"},children:[(0,o.jsx)("strong",{children:t})," applied"]})]})]}),(0,o.jsx)("div",{style:{overflowX:"auto",border:"0.5px solid var(--color-border-tertiary)",borderRadius:"var(--border-radius-lg)",background:"var(--color-background-primary)"},children:(0,o.jsxs)("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12,minWidth:900},children:[(0,o.jsx)("thead",{children:(0,o.jsxs)("tr",{style:{borderBottom:"0.5px solid var(--color-border-tertiary)"},children:[(0,o.jsx)("th",{style:{padding:"10px 12px",fontSize:11,fontWeight:600,color:"var(--color-text-secondary)",textAlign:"left",textTransform:"uppercase",letterSpacing:.3},children:"Merchant"}),(0,o.jsx)("th",{style:{padding:"10px 12px",fontSize:11,fontWeight:600,color:"var(--color-text-secondary)",textAlign:"left",textTransform:"uppercase",letterSpacing:.3},children:"Network"}),(0,o.jsx)("th",{style:{padding:"10px 12px",fontSize:11,fontWeight:600,color:"var(--color-text-secondary)",textAlign:"left",textTransform:"uppercase",letterSpacing:.3},children:"Mode"}),(0,o.jsx)("th",{style:{padding:"10px 12px",fontSize:11,fontWeight:600,color:"var(--color-text-secondary)",textAlign:"left",textTransform:"uppercase",letterSpacing:.3,whiteSpace:"nowrap"},children:"Commission"}),(0,o.jsx)("th",{style:{padding:"10px 12px",fontSize:11,fontWeight:600,color:"var(--color-text-secondary)",textAlign:"left",textTransform:"uppercase",letterSpacing:.3,whiteSpace:"nowrap"},children:"User payout"}),(0,o.jsx)("th",{style:{padding:"10px 12px",fontSize:11,fontWeight:600,color:"var(--color-text-secondary)",textAlign:"center",textTransform:"uppercase",letterSpacing:.3},children:"Δ"}),(0,o.jsx)("th",{style:{padding:"10px 12px",fontSize:11,fontWeight:600,color:"var(--color-text-secondary)",textAlign:"left",textTransform:"uppercase",letterSpacing:.3},children:"Status"}),(0,o.jsx)("th",{style:{padding:"10px 12px",fontSize:11,fontWeight:600,color:"var(--color-text-secondary)",textAlign:"right",textTransform:"uppercase",letterSpacing:.3},children:"Detected"})]})}),(0,o.jsx)("tbody",{children:e.map((r,t)=>{let i=r.merchants||{},d="increase"===r.direction?"#1D9E75":"decrease"===r.direction?"#E85D04":"var(--color-text-secondary)",l="increase"===r.direction?"↑":"decrease"===r.direction?"↓":"—",s=n[r.status]||{color:"var(--color-text-secondary)",bg:"var(--color-background-secondary)",label:r.status},c=i.rates_locked?"\uD83D\uDD12 Locked":"fixed"===i.payout_mode?"\uD83D\uDCCC Fixed":"⚙️ Auto";return(0,o.jsxs)("tr",{style:{borderBottom:t<e.length-1?"0.5px solid var(--color-border-tertiary)":"none"},children:[(0,o.jsxs)("td",{style:{padding:"8px 12px"},children:[(0,o.jsx)("div",{style:{fontSize:12,fontWeight:500,color:"var(--color-text-primary)"},children:i.name||"—"}
1),(0,o.jsx)("div",{style:{fontSize:10,color:"var(--color-text-secondary)"},children:i.slug})]}),(0,o.jsx)("td",{style:{padding:"8px 12px",color:"var(--color-text-secondary)"},children:(0,o.jsx)("span",{style:{fontSize:11,padding:"2px 8px",borderRadius:10,background:"var(--color-background-secondary)",color:"var(--color-text-secondary)",textTransform:"uppercase",fontWeight:600},children:i.affiliate_network||"cj"})}),(0,o.jsxs)("td",{style:{padding:"8px 12px"},children:[(0,o.jsx)("div",{style:{fontSize:11,color:i.rates_locked?"#E85D04":"var(--color-text-secondary)"},children:c}),(0,o.jsxs)("div",{style:{fontSize:10,color:"var(--color-text-secondary)"},children:["split: ",Math.round(100*(i.payout_split_ratio||.5)),"%"]})]}),(0,o.jsxs)("td",{style:{padding:"8px 12px",fontVariantNumeric:"tabular-nums",color:"var(--color-text-primary)",whiteSpace:"nowrap"},children:[(0,o.jsx)("span",{style:{color:"var(--color-text-secondary)"},children:a(r.current_commission_rate,r.commission_type)}),(0,o.jsx)("span",{style:{color:"var(--color-text-secondary)",margin:"0 4px"},children:"→"}),(0,o.jsx)("strong",{children:a(r.new_commission_rate,r.commission_type)})]}),(0,o.jsxs)("td",{style:{padding:"8px 12px",fontVariantNumeric:"tabular-nums",color:"var(--color-text-primary)",whiteSpace:"nowrap"},children:[(0,o.jsx)("span",{style:{color:"var(--color-text-secondary)"},children:a(r.current_payout_rate,r.commission_type)}),(0,o.jsx)("span",{style:{color:"var(--color-text-secondary)",margin:"0 4px"},children:"→"}),(0,o.jsx)("strong",{children:a(r.proposed_payout_rate,r.commission_type)})]}),(0,o.jsxs)("td",{style:{padding:"8px 12px",textAlign:"center",fontWeight:600,color:d,fontVariantNumeric:"tabular-nums"},children:[l," ",r.commission_delta>0?"+":"",Number(r.commission_delta).toFixed(2)]}),(0,o.jsx)("td",{style:{padding:"8px 12px"},children:(0,o.jsx)("span",{style:{fontSize:11,padding:"2px 8px",borderRadius:10,background:s.bg,color:s.color,fontWeight:600,whiteSpace:"nowrap"},children:s.label})}),(0,o.jsx)("td",{style:{padding:"8px 12px",textAlign:"right",color:"var(--color-text-secondary)",whiteSpace:"nowrap"},children:m(r.detected_at)})]},r.id)})})]})})]})]})})(),"commissions"===g&&(()=>{let e=(null==ez?void 0:ez.rows)||[],r=(null==ez?void 0:ez.stats)||{},t="all"===eD?e:e.filter(e=>e.status===eD),a={pending:{color:"#E85D04",bg:"#E85D0415",label:"Pending"},confirmed:{color:"#2775CA",bg:"#2775CA15",label:"Confirmed"},available:{color:"#1D9E75",bg:"#1D9E7515",label:"Available"},paid:{color:"var(--color-text-secondary)",bg:"var(--color-background-secondary)",label:"Paid"},rejected:{color:"var(--color-text-danger)",bg:"var(--color-background-danger)",label:"Rejected"}},n=function(e){let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"USD";return null==e?"—":new Intl.NumberFormat("en-US",{style:"currency",currency:r}).format(Number(e))},i=e=>e?new Date(e).toLocaleString("en-US",{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}):"—";return(0,o.jsxs)("div",{children:[(0,o.jsx)("h3",{style:{fontSize:17,fontWeight:600,margin:"0 0 8px",color:"var(--color-text-primary)"},children:"Commissions"}),(0,o.jsxs)("p",{style:{fontSize:13,color:"var(--color-text-secondary)",margin:"0 0 16px"},children:["Every commission reported by our affiliate networks. Reconciled daily at 4 AM UTC. Status lifecycle: ",(0,o.jsx)("strong",{children:"pending"})," (reported) → ",(0,o.jsx)("strong",{children:"confirmed"})," (locked) → ",(0,o.jsx)("strong",{children:"available"})," (we got paid, user can withdraw) → ",(0,o.jsx)("strong",{children:"paid"})," (user withdrew)."]}),(0,o.jsx)("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fit, minmax(140px, 1fr))",gap:10,marginBottom:16},children:[["Pending cashback",n(r.total_cashback_pending||0),"#E85D04"],["Confirmed cashback",n(r.total_cashback_confirmed||0),"#2775CA"],["Available cashback",n(r.total_cashback_available||0),"#1D9E75"],["Kona margin earned",n(r.total_commission_earned||0),"var(--color-text-primary)"]].map(e=>{let[r,t,a]=e;return(0,o.jsxs)("div",{style:{padding:14,borderRadius:"var(--border-radius-md)",background:"var(--color-background-secondary)"},children:[(0,o.jsx)("div",{style:{fontSize:11,color:"var(--color-text-secondary)",textTransform:"uppercase",letterSpacing:.3},children:r}),(0,o.jsx)("div",{style:{fontSize:18,fontWeight:600,color:a,marginTop:4,fontVariantNumeric:"tabular-nums"},children:t})]},r)})}),(0,o.jsx)("div",{style:{display:"flex",gap:6,marginBottom:14,flexWrap:"wrap"},children:[["all","All ".concat(r.total||0)],["pending","Pending ".concat(r.pending||0)],["confirmed","Confirmed ".concat(r.confirmed||0)],["available","Available ".concat(r.available||0)],["paid","Paid ".concat(r.paid||0)],["rejected","Rejected ".concat(r.rejected||0)]].map(e=>{let[r,t]=e;return(0,o.jsx)("button",{onClick:()=>eE(r),style:{padding:"6px 14px",borderRadius:20,fontSize:12,fontWeight:500,cursor:"pointer",border:"none",background:eD===r?"#111":"var(--color-background-secondary)",color:eD===r?"#fff":"var(--color-text-secondary)"},children:t},r)})}),eA&&!ez?(0,o.jsx)("div",{style:{padding:32,textAlign:"center",color:"var(--color-text-secondary)",fontSize:14},children:"Loading..."}):0===t.length?(0,o.jsxs)("div",{style:{padding:48,textAlign:"center",border:"0.5px solid var(--color-border-tertiary)",borderRadius:"var(--border-radius-lg)",background:"var(--color-background-primary)"},children:[(0,o.jsx)("div",{style:{fontSize:40,marginBottom:12},children:"\uD83D\uDCB0"}),(0,o.jsx)("div",{style:{fontSize:16,fontWeight:500,color:"var(--color-text-primary)"},children:0===e.length?"No commissions yet":"No ".concat(eD," commissions")}),(0,o.jsx)("div",{style:{fontSize:13,color:"var(--color-text-secondary)",marginTop:4},children:0===e.length?"The sync-commissions cron runs at 4 AM UTC. Any reported conversions will show here.":"Try a different status filter."})]}):(0,o.jsx)("div",{style:{overflowX:"auto",border:"0.5px solid var(--color-border-tertiary)",borderRadius:"var(--border-radius-lg)",background:"var(--color-background-primary)"},children:(0,o.jsxs)("table",{style:{width:"100%",borderCollapse:"collapse",fontSize:12,minWidth:1200},children:[(0,o.jsx)("thead",{children:(0,o.jsxs)("tr",{style:{borderBottom:"0.5px solid var(--color-border-tertiary)"},children:[(0,o.jsx)("th",{style:e9,children:"Merchant"}),(0,o.jsx)("th",{style:e9,children:"User"}),(0,o.jsx)("th",{style:e9,children:"Status"}),(0,o.jsx)("th",{style:re,children:"Order $"}),(0,o.jsx)("th",{style:re,children:"Commission"}),(0,o.jsx)("th",{style:re,children:"User cashback"}),(0,o.jsx)("th",{style:re,children:"Kona margin"}),(0,o.jsx)("th",{style:e9,children:"Order ID"}),(0,o.jsx)("th",{style:e9,children:"Click time"}),(0,o.jsx)("th",{style:e9,children:"Conversion"}),(0,o.jsx)("th",{style:e9,children:"Reported"})]})}),(0,o.jsx)("tbody",{children:t.map((e,r)=>{var d;let l=a[e.status]||a.pending,s=e.merchant||{},c=null===(d=e.user)||void 0===d?void 0:d.is_internal_account;return(0,o.jsxs)("tr",{style:{borderBottom:r<t.length-1?"0.5px solid var(--color-border-tertiary)":"none"},children:[(0,o.jsx)("td",{style:rr,children:(0,o.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8},children:[(0,o.jsx)("div",{style:{width:24,height:24,borderRadius:"var(--border-radius-md)",background:s.logo_color||"#111",display:"flex",alignItems:"center",justifyContent:"center",color:"#fff",fontSize:9,fontWeight:600,flexShrink:0},children:s.logo_text||(s.name||"?").substring(0,2).toUpperCase()}),(0,o.jsxs)("div",{style:{minWidth:0},children:[(0,o.jsx)("div",{style:{fontSize:12,fontWeight:500,color:"var(--color-text-primary)"},children:s.name||"—"}
1),(0,o.jsx)("div",{style:{fontSize:10,color:"var(--color-text-secondary)",textTransform:"uppercase"},children:s.affiliate_network||e.network})]})]})}),(0,o.jsx)("td",{style:rr,children:e.clerk_id?(0,o.jsxs)("div",{style:{fontSize:11,fontFamily:"var(--font-mono)",color:"var(--color-text-secondary)"},children:[e.clerk_id.substring(0,16),"...",c&&(0,o.jsx)("span",{style:{display:"inline-block",marginLeft:4,fontSize:9,padding:"1px 6px",borderRadius:10,background:"#2775CA15",color:"#2775CA",fontWeight:600},children:"TEST"})]}):(0,o.jsx)("span",{style:{fontSize:11,color:"#E85D04"},children:"unattributed"})}),(0,o.jsxs)("td",{style:rr,children:[(0,o.jsx)("span",{style:{fontSize:11,padding:"2px 8px",borderRadius:10,background:l.bg,color:l.color,fontWeight:600,whiteSpace:"nowrap"},children:l.label}),e.network_status&&(0,o.jsxs)("div",{style:{fontSize:9,color:"var(--color-text-secondary)",marginTop:2,textTransform:"uppercase"},children:["cj: ",e.network_status]})]}),(0,o.jsx)("td",{style:rt,children:n(e.order_amount,e.currency)}),(0,o.jsx)("td",{style:rt,children:n(e.commission_amount,e.currency)}),(0,o.jsx)("td",{style:{...rt,color:"#1D9E75",fontWeight:600},children:n(e.cashback_amount,e.currency)}),(0,o.jsx)("td",{style:{...rt,color:"var(--color-text-primary)",fontWeight:500},children:n(e.kona_margin,e.currency)}),(0,o.jsx)("td",{style:{...rr,fontFamily:"var(--font-mono)",fontSize:11,color:"var(--color-text-secondary)"},children:e.order_id||"—"}),(0,o.jsx)("td",{style:{...rr,color:"var(--color-text-secondary)",whiteSpace:"nowrap"},children:i(e.click_time)}),(0,o.jsx)("td",{style:{...rr,color:"var(--color-text-secondary)",whiteSpace:"nowrap"},children:i(e.conversion_date)}),(0,o.jsx)("td",{style:{...rr,color:"var(--color-text-secondary)",whiteSpace:"nowrap"},children:i(e.network_reported_at)})]},e.id)})})]})})]})})(),"merchants"===g&&(0,o.jsxs)("div",{children:[(0,o.jsxs)("div",{style:{display:"flex",gap:10,marginBottom:16,flexWrap:"wrap"},children:[(0,o.jsx)("input",{type:"text",placeholder:"Search merchants...",value:A,onChange:e=>W(e.target.value),style:{flex:"1 1 200px",padding:"8px 12px",borderRadius:"var(--border-radius-md)",border:"0.5px solid var(--color-border-tertiary)",fontSize:13,background:"var(--color-background-primary)",color:"var(--color-text-primary)",outline:"none"}}),(0,o.jsxs)("select",{value:T,onChange:e=>F(e.target.value),style:{padding:"8px 12px",borderRadius:"var(--border-radius-md)",border:"0.5px solid var(--color-border-tertiary)",fontSize:13,background:"var(--color-background-primary)",color:"var(--color-text-primary)",cursor:"pointer"},children:[(0,o.jsx)("option",{value:"All",children:"All categories"}),y.map(e=>(0,o.jsx)("option",{value:e,children:e},e))]}),(0,o.jsxs)("select",{value:D,onChange:e=>E(e.target.value),style:{padding:"8px 12px",borderRadius:"var(--border-radius-md)",border:"0.5px solid var(--color-border-tertiary)",fontSize:13,background:"var(--color-background-primary)",color:"var(--color-text-primary)",cursor:"pointer"},children:[(0,o.jsx)("option",{value:"All",children:"All networks"}),v.map(e=>(0,o.jsx)("option",{value:e,children:e},e)),(0,o.jsx)("option",{value:"None",children:"No network"})]})]}),(0,o.jsxs)("div",{style:{borderRadius:"var(--border-radius-lg)",border:"0.5px solid var(--color-border-tertiary)",overflow:"hidden",background:"var(--color-background-primary)"},children:[(0,o.jsxs)("div",{style:{padding:"10px 16px",borderBottom:"0.5px solid var(--color-border-tertiary)",display:"flex",justifyContent:"space-between",alignItems:"center"},children:[(0,o.jsxs)("span",{style:{fontSize:13,fontWeight:500,color:"var(--color-text-primary)"},children:[e3.length," merchants"]}),(0,o.jsx)("button",{onClick:()=>{k("add new"),w(!0),C(null),R({...f})},style:{background:"#111",color:"#fff",border:"none",padding:"6px 14px",borderRadius:"var(--border-radius-md)",fontSize:12,fontWeight:500,cursor:"pointer"},children:"+ Add merchant"})]}),x?(0,o.jsx)("div",{style:{padding:32,textAlign:"center",color:"var(--color-text-secondary)",fontSize:14},children:"Loading..."}):0===e3.length?(0,o.jsx)("div",{style:{padding:32,textAlign:"center",color:"var(--color-text-secondary)",fontSize:14},children:"No merchants found."}):e3.map(e=>{var r;return(0,o.jsxs)("div",{style:{padding:"10px 16px",borderBottom:"0.5px solid var(--color-border-tertiary)",display:"flex",alignItems:"center",gap:10,opacity:e.is_active?1:.5},children:[(0,o.jsx)("div",{style:{width:32,height:32,borderRadius:"var(--border-radius-md)",background:e.logo_color||"#111",display:"flex",alignItems:"center",justifyContent:"center",color:"#fff",fontSize:11,fontWeight:600,flexShrink:0}
1,children:e.logo_text||(null===(r=e.name)||void 0===r?void 0:r.substring(0,2))}),(0,o.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,o.jsxs)("div",{style:{fontSize:13,fontWeight:500,color:"var(--color-text-primary)",display:"flex",alignItems:"center",gap:6},children:[e.name,e.is_featured&&(0,o.jsx)("span",{style:{fontSize:10,padding:"1px 6px",borderRadius:10,background:"#2775CA",color:"#fff"},children:"Featured"}),!e.is_active&&(0,o.jsx)("span",{style:{fontSize:10,padding:"1px 6px",borderRadius:10,background:"var(--color-background-danger)",color:"var(--color-text-danger)"},children:"Inactive"})]}),(0,o.jsxs)("div",{style:{fontSize:11,color:"var(--color-text-secondary)"},children:[e.url," \xb7 ",e.category,e.affiliate_network?" \xb7 ".concat(e.affiliate_network):""]})]}),(0,o.jsxs)("div",{style:{fontSize:15,fontWeight:600,color:"#1D9E75",minWidth:50,textAlign:"right"},children:[Number(e.cashback_rate).toFixed(1),"%"]}),(0,o.jsxs)("div",{style:{display:"flex",gap:4},children:[(0,o.jsx)("button",{onClick:()=>eY(e),title:e.is_active?"Deactivate":"Activate",style:{background:"none",border:"0.5px solid var(--color-border-tertiary)",padding:"3px 8px",borderRadius:"var(--border-radius-md)",fontSize:11,cursor:"pointer",color:e.is_active?"var(--color-text-success)":"var(--color-text-secondary)"},children:e.is_active?"On":"Off"}),(0,o.jsx)("button",{onClick:()=>eZ(e),title:e.is_featured?"Unfeature":"Feature",style:{background:"none",border:"0.5px solid var(--color-border-tertiary)",padding:"3px 8px",borderRadius:"var(--border-radius-md)",fontSize:11,cursor:"pointer",color:e.is_featured?"#2775CA":"var(--color-text-secondary)"},children:e.is_featured?"★":"☆"}),(0,o.jsx)("button",{onClick:()=>{e0(e),k("add new")},style:{background:"none",border:"0.5px solid var(--color-border-tertiary)",padding:"3px 8px",borderRadius:"var(--border-radius-md)",fontSize:11,cursor:"pointer",color:"var(--color-text-secondary)"},children:"Edit"}),(0,o.jsx)("button",{onClick:()=>eQ(e.id),style:{background:"none",border:"0.5px solid var(--color-border-danger)",padding:"3px 8px",borderRadius:"var(--border-radius-md)",fontSize:11,cursor:"pointer",color:"var(--color-text-danger)"},children:"Del"})]})]},e.id)})]})]}),"add new"===g&&(0,o.jsxs)("div",{style:{maxWidth:560},children:[(0,o.jsx)("h3",{style:{fontSize:17,fontWeight:600,margin:"0 0 16px",color:"var(--color-text-primary)"},children:_?"Edit merchant":"Add new merchant"}),(0,o.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12},children:[(0,o.jsxs)("div",{style:{gridColumn:"1 / -1"},children:[(0,o.jsx)("label",{style:{fontSize:12,color:"var(--color-text-secondary)",display:"block",marginBottom:4},children:"Merchant name *"}),(0,o.jsx)("input",{value:z.name,onChange:e=>R({...z,name:e.target.value}),placeholder:"Nike",style:{width:"100%",padding:"10px 12px",borderRadius:"var(--border-radius-md)",border:"0.5px solid var(--color-border-tertiary)",fontSize:14,background:"var(--color-background-primary)",color:"var(--color-text-primary)",boxSizing:"border-box"}})]}),(0,o.jsxs)("div",{style:{gridColumn:"1 / -1"},children:[(0,o.jsx)("label",{style:{fontSize:12,color:"var(--color-text-secondary)",display:"block",marginBottom:4},children:"Website URL *"}),(0,o.jsx)("input",{value:z.url,onChange:e=>R({...z,url:e.target.value}),placeholder:"nike.com",style:{width:"100%",padding:"10px 12px",borderRadius:"var(--border-radius-md)",border:"0.5px solid var(--color-border-tertiary)",fontSize:14,background:"var(--color-background-primary)",color:"var(--color-text-primary)",boxSizing:"border-box"}})]}),(0,o.jsxs)("div",{style:{gridColumn:"1 / -1"},children:[(0,o.jsx)("label",{style:{fontSize:12,color:"var(--color-text-secondary)",display:"block",marginBottom:4},children:"Description"}),(0,o.jsx)("textarea",{value:z.description,onChange:e=>R({...z,description:e.target.value}),placeholder:"Athletic footwear, apparel and accessories",rows:2,style:{width:"100%",padding:"10px 12px",borderRadius:"var(--border-radius-md)",border:"0.5px solid var(--color-border-tertiary)",fontSize:14,background:"var(--color-background-primary)",color:"var(--color-text-primary)",boxSizing:"border-box",fontFamily:"inherit",resize:"vertical"}})]}),(0,o.jsxs)("div",{children:[(0,o.jsx)("label",{style:{fontSize:12,color:"var(--color-text-secondary)",display:"block",marginBottom:4},children:"Category *"}),(0,o.jsx)("select",{value:z.category,onChange:e=>R({...z,category:e.target.value}),style:{width:"100%",padding:"10px 12px",borderRadius:"var(--border-radius-md)",border:"0.5px solid var(--color-border-tertiary)",fontSize:14,background:"var(--color-background-primary)",color:"var(--color-text-primary)",cursor:"pointer"},children:y.map(e=>(0,o.jsx)("option",{value:e,children:e},e))})]}),(0,o.jsxs)("div",{children:[(0,o.jsx)("label",{style:{fontSize:12,color:"var(--color-text-secondary)",display:"block",marginBottom:4},children:"Cashback rate (%) *"}),(0,o.jsx)("input",{type:"number",step:"0.1",value:z.cashback_rate,onChange:e=>R({...z,cashback_rate:e.target.value}),placeholder:"8.0",style:{width:"100%",padding:"10px 12px",borderRadius:"var(--border-radius-md)",border:"0.5px solid var(--color-border-tertiary)",fontSize:14,background:"var(--color-background-primary)",color:"var(--color-text-primary)",boxSizing:"border-box"}})]}),(0,o.jsxs)("div",{children:[(0,o.jsx)("label",{style:{fontSize:12,color:"var(--color-text-secondary)",display:"block",marginBottom:4},children:"Affiliate network"}),(0,o.jsxs)("select",{value:z.affiliate_network,onChange:e=>R({...z,affiliate_network:e.target.value}),style:{width:"100%",padding:"10px 12px",borderRadius:"var(--border-radius-md)",border:"0.5px solid var(--color-border-tertiary)",fontSize:14,background:"var(--color-background-primary)",color:"var(--color-text-primary)",cursor:"pointer"},children:[(0,o.jsx)("option",{value:"",children:"Select network..."}),v.map(e=>(0,o.jsx)("option",{value:e,children:e},e))]})]}),(0,o.jsxs)("div",{children:[(0,o.jsx)("label",{style:{fontSize:12,color:"var(--color-text-secondary)",display:"block",marginBottom:4},children:"Cookie duration (days)"}),(0,o.jsx)("input",{type:"number",value:z.cookie_duration_days,onChange:e=>R({...z,cookie_duration_days:parseInt(e.target.value)||30}),style:{width:"100%",padding:"10px 12px",borderRadius:"var(--border-radius-md)",border:"0.5px solid var(--color-border-tertiary)",fontSize:14,background:"var(--color-background-primary)",color:"var(--color-text-primary)",boxSizing:"border-box"}})]}),(0,o.jsxs)("div",{style:{gridColumn:"1 / -1"},children:[(0,o.jsx)("label",{style:{fontSize:12,color:"var(--color-text-secondary)",display:"block",marginBottom:4},children:"Affiliate tracking link"}),(0,o.jsx)("input",{value:z.affiliate_link,onChange:e=>R({...z,affiliate_link:e.target.value}),placeholder:"https://www.shareasale.com/r.cfm?b=...",style:{width:"100%",padding:"10px 12px",borderRadius:"var(--border-radius-md)",border:"0.5px solid var(--color-border-tertiary)",fontSize:14,background:"var(--color-background-primary)",color:"var(--color-text-primary)",boxSizing:"border-box",fontFamily:"var(--font-mono)"}})]}),(0,o.jsxs)("div",{children:[(0,o.jsx)("label",{style:{fontSize:12,color:"var(--color-text-secondary)",display:"block",marginBottom:4},children:"Logo text (1-2 chars)"}),(0,o.jsx)("input",{value:z.logo_text,onChange:e=>R({...z,logo_text:e.target.value}),placeholder:"N",maxLength:3,style:{width:"100%",padding:"10px 12px",borderRadius:"var(--border-radius-md)",border:"0.5px solid var(--color-border-tertiary)",fontSize:14,background:"var(--color-background-primary)",color:"var(--color-text-primary)",boxSizing:"border-box"}})]}),(0,o.jsxs)("div",{children:[(0,o.jsx)("label",{style:{fontSize:12,color:"var(--color-text-secondary)",display:"block",marginBottom:4},children:"Logo color"}),(0,o.jsxs)("div",{style:{display:"flex",gap:8,alignItems:"center"},children:[(0,o.jsx)("input",{type:"color",value:z.logo_color,onChange:e=>R({...z,logo_color:e.target.value}),style:{width:40,height:36,border:"0.5px solid var(--color-border-tertiary)",borderRadius:"var(--border-radius-md)",cursor:"pointer",padding:2}}),(0,o.jsx)("input",{value:z.logo_color,onChange:e=>R({...z,logo_color:e.target.value}),style:{flex:1,padding:"10px 12px",borderRadius:"var(--border-radius-md)",border:"0.5px solid var(--color-border-tertiary)",fontSize:14,background:"var(--color-background-primary)",color:"var(--color-text-primary)",fontFamily:"var(--font-mono)"}})]})]}),(0,o.jsxs)("div",{children:[(0,o.jsx)("label",{style:{fontSize:12,color:"var(--color-text-secondary)",display:"block",marginBottom:4},children:"Tracking speed"}),(0,o.jsxs)("select",{value:z.tracking_speed,onChange:e=>R({...z,tracking_speed:e.target.value}),style:{width:"100%",padding:"10px 12px",borderRadius:"var(--border-radius-md)",border:"0.5px solid var(--color-border-tertiary)",fontSize:14,background:"var(--color-background-primary)",color:"var(--color-text-primary)",cursor:"pointer"},children:[(0,o.jsx)("option",{value:"Instant",children:"Instant"}),(0,o.jsx)("option",{value:"1-3 days",children:"1-3 days"}),(0,o.jsx)("option",{value:"3-7 days",children:"3-7 days"}),(0,o.jsx)("option",{value:"7-14 days",children:"7-14 days"})]})]}),(0,o.jsxs)("div",{children:[(0,o.jsx)("label",{style:{fontSize:12,color:"var(--color-text-secondary)",display:"block",marginBottom:4},children:"Payout speed"}),(0,o.jsxs)("select",{value:z.payout_speed,onChange:e=>R({...z,payout_speed:e.target.value}),style:{width:"100%",padding:"10px 12px",borderRadius:"var(--border-radius-md)",border:"0.5px solid var(--color-border-tertiary)",fontSize:14,background:"var(--color-background-primary)",color:"var(--color-text-primary)",cursor:"pointer"},children:[(0,o.jsx)("option",{value:"1-7 days",children:"1-7 days"}),(0,o.jsx)("option",{value:"7-30 days",children:"7-30 days"}),(0,o.jsx)("option",{value:"30-60 days",children:"30-60 days"}),(0,o.jsx)("option",{value:"60-90 days",children:"60-90 days"})]})]}),(0,o.jsxs)("div",{style:{display:"flex",gap:16,alignItems:"center"},children:[(0,o.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:6,fontSize:13,color:"var(--color-text-primary)",cursor:"pointer"},children:[(0,o.jsx)("input",{type:"checkbox",checked:z.is_active,onChange:e=>R({...z,is_active:e.target.checked})})," Active"]}),(0,o.jsxs)("label",{style:{display:"flex",alignItems:"center",gap:6,fontSize:13,color:"var(--color-text-primary)",cursor:"pointer"},children:[(0,o.jsx)("input",{type:"checkbox",checked:z.is_featured,onChange:e=>R({...z,is_featured:e.target.checked})})," Featured"]})]})]}),(0,o.jsxs)("div",{style:{marginTop:16,padding:14,borderRadius:"var(--border-radius-md)",background:"var(--color-background-secondary)"},children:[(0,o.jsx)("div",{style:{fontSize:12,color:"var(--color-text-secondary)",marginBottom:8},children:"Preview"}),(0,o.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:10},children:[(0,o.jsx)("div",{style:{width:36,height:36,borderRadius:"var(--border-radius-md)",background:z.logo_color||"#111",display:"flex",alignItems:"center",justifyContent:"center",color:"#fff",fontSize:13,fontWeight:600},children:z.logo_text||(null===(d=z.name)||void 0===d?void 0:d.substring(0,2))||"?"}),(0,o.jsxs)("div",{children:[(0,o.jsx)("div",{style:{fontSize:14,fontWeight:500,color:"var(--color-text-primary)"},children:z.name||"Merchant name"}),(0,o.jsxs)("div",{style:{fontSize:12,color:"var(--color-text-secondary)"},children:[z.url||"url.com"," \xb7 ",z.category]})]}),(0,o.jsxs)("div",{style:{marginLeft:"auto",fontSize:18,fontWeight:600,color:"#1D9E75"},children:[z.cashback_rate||"0","%"]})]})]}),(0,o.jsxs)("div",{style:{display:"flex",gap:10,marginTop:20},children:[(0,o.jsx)("button",{onClick:eG,disabled:I,style:{background:"#111",color:"#fff",border:"none",padding:"10px 24px",borderRadius:"var(--border-radius-md)",fontSize:14,fontWeight:500,cursor:I?"default":"pointer",opacity:I?.6:1},children:I?"Saving...":_?"Update merchant":"Add merchant"}),_&&(0,o.jsx)("button",{onClick:()=>{C(null),R({...f})},style:{background:"transparent",border:"0.5px solid var(--color-border-tertiary)",padding:"10px 24px",borderRadius:"var(--border-radius-md)",fontSize:14,fontWeight:500,cursor:"pointer",color:"var(--color-text-secondary)"},children:"Cancel edit"})]})]}),"bulk import"===g&&(0,o.jsxs)("div",{style:{maxWidth:560},children:[(0,o.jsx)("h3",{style:{fontSize:17,fontWeight:600,margin:"0 0 8px",color:"var(--color-text-primary)"},children:"Bulk import merchants"}),(0,o.jsxs)("p",{style:{fontSize:13,color:"var(--color-text-secondary)",margin:"0 0 16px"},children:["Paste CSV data with headers. Required: ",(0,o.jsx)("span",{style:{fontFamily:"var(--font-mono)",fontSize:12}
1,children:"name, url, category, cashback_rate"})]}),(0,o.jsxs)("div",{style:{padding:12,borderRadius:"var(--border-radius-md)",background:"var(--color-background-secondary)",marginBottom:12,fontSize:12,fontFamily:"var(--font-mono)",color:"var(--color-text-secondary)"},children:["name,url,category,cashback_rate,affiliate_network,description",(0,o.jsx)("br",{}),"Nike,nike.com,Fashion,8.0,ShareASale,Athletic footwear and apparel",(0,o.jsx)("br",{}),"Target,target.com,General,3.5,Impact,Everything for your home"]}),(0,o.jsx)("textarea",{value:O,onChange:e=>L(e.target.value),rows:10,placeholder:"Paste your CSV data here...",style:{width:"100%",padding:"12px",borderRadius:"var(--border-radius-md)",border:"0.5px solid var(--color-border-tertiary)",fontSize:13,fontFamily:"var(--font-mono)",background:"var(--color-background-primary)",color:"var(--color-text-primary)",boxSizing:"border-box",resize:"vertical"}}),(0,o.jsx)("button",{onClick:e1,style:{marginTop:12,background:"#111",color:"#fff",border:"none",padding:"10px 24px",borderRadius:"var(--border-radius-md)",fontSize:14,fontWeight:500,cursor:"pointer"},children:"Import merchants"}),M&&(0,o.jsxs)("div",{style:{marginTop:16,padding:14,borderRadius:"var(--border-radius-md)",background:"var(--color-background-success)"},children:[(0,o.jsx)("div",{style:{fontSize:14,fontWeight:500,color:"var(--color-text-success)"},children:"Import complete"}),(0,o.jsxs)("div",{style:{fontSize:13,color:"var(--color-text-success)",marginTop:4},children:[M.imported," imported \xb7 ",M.skipped," skipped \xb7 ",M.total_submitted," total submitted"]})]})]}),"placements"===g&&(0,o.jsxs)("div",{children:[(0,o.jsxs)("div",{style:{padding:20,borderRadius:"var(--border-radius-lg)",border:"0.5px solid var(--color-border-tertiary)",background:"var(--color-background-primary)",marginBottom:20},children:[(0,o.jsx)("h3",{style:{fontSize:15,fontWeight:600,margin:"0 0 14px",color:"var(--color-text-primary)"},children:$?"Edit placement":"Schedule new placement"}),(0,o.jsxs)("div",{style:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:12},children:[(0,o.jsxs)("div",{children:[(0,o.jsx)("label",{style:{fontSize:12,color:"var(--color-text-secondary)",display:"block",marginBottom:4},children:"Merchant *"}),(0,o.jsxs)("select",{value:H.merchant_id,onChange:e=>q({...H,merchant_id:e.target.value}),style:{width:"100%",padding:"10px 12px",borderRadius:"var(--border-radius-md)",border:"0.5px solid var(--color-border-tertiary)",fontSize:13,background:"var(--color-background-primary)",color:"var(--color-text-primary)",cursor:"pointer"},children:[(0,o.jsx)("option",{value:"",children:"Select merchant..."}),s.filter(e=>e.is_active).map(e=>(0,o.jsxs)("option",{value:e.id,children:[e.name," (",Number(e.cashback_rate).toFixed(1),"%)"]},e.id))]})]}),(0,o.jsxs)("div",{children:[(0,o.jsx)("label",{style:{fontSize:12,color:"var(--color-text-secondary)",display:"block",marginBottom:4},children:"Placement type *"}),(0,o.jsxs)("select",{value:H.placement_type,onChange:e=>q({...H,placement_type:e.target.value}),style:{width:"100%",padding:"10px 12px",borderRadius:"var(--border-radius-md)",border:"0.5px solid var(--color-border-tertiary)",fontSize:13,background:"var(--color-background-primary)",color:"var(--color-text-primary)",cursor:"pointer"},children:[(0,o.jsx)("option",{value:"",children:"Select placement..."}),b.map(e=>(0,o.jsx)("option",{value:e.id,children:e.label},e.id))]})]}),(0,o.jsxs)("div",{children:[(0,o.jsx)("label",{style:{fontSize:12,color:"var(--color-text-secondary)",display:"block",marginBottom:4},children:"Start date *"}),(0,o.jsx)("input",{type:"date",value:H.start_date,onChange:e=>q({...H,start_date:e.target.value}),style:{width:"100%",padding:"10px 12px",borderRadius:"var(--border-radius-md)",border:"0.5px solid var(--color-border-tertiary)",fontSize:13,background:"var(--color-background-primary)",color:"var(--color-text-primary)",boxSizing:"border-box"}})]}),(0,o.jsxs)("div",{children:[(0,o.jsx)("label",{style:{fontSize:12,color:"var(--color-text-secondary)",display:"block",marginBottom:4},children:"End date *"}),(0,o.jsx)("input",{type:"date",value:H.end_date,onChange:e=>q({...H,end_date:e.target.value}),style:{width:"100%",padding:"10px 12px",borderRadius:"var(--border-radius-md)",border:"0.5px solid var(--color-border-tertiary)",fontSize:13,background:"var(--color-background-primary)",color:"var(--color-text-primary)",boxSizing:"border-box"}})]}),(0,o.jsxs)("div",{children:[(0,o.jsx)("label",{style:{fontSize:12,color:"var(--color-text-secondary)",display:"block",marginBottom:4},children:"Priority"}),(0,o.jsx)("input",{type:"number",value:H.priority,onChange:e=>q({...H,priority:parseInt(e.target.value)||0}),style:{width:"100%",padding:"10px 12px",borderRadius:"var(--border-radius-md)",border:"0.5px solid var(--color-border-tertiary)",fontSize:13,background:"var(--color-background-primary)",color:"var(--color-text-primary)",boxSizing:"border-box"}})]}),(0,o.jsxs)("div",{children:[(0,o.jsx)("label",{style:{fontSize:12,color:"var(--color-text-secondary)",display:"block",marginBottom:4},children:"Notes"}),(0,o.jsx)("input",{value:H.notes,onChange:e=>q({...H,notes:e.target.value}),placeholder:"e.g. Part of Q1 deal",style:{width:"100%",padding:"10px 12px",borderRadius:"var(--border-radius-md)",border:"0.5px solid var(--color-border-tertiary)",fontSize:13,background:"var(--color-background-primary)",color:"var(--color-text-primary)",boxSizing:"border-box"}})]})]}),(0,o.jsxs)("div",{style:{display:"flex",gap:8,marginTop:14},children:[(0,o.jsx)("button",{onClick:e2,disabled:I,style:{background:"#111",color:"#fff",border:"none",padding:"8px 20px",borderRadius:"var(--border-radius-md)",fontSize:13,fontWeight:500,cursor:I?"default":"pointer",opacity:I?.6:1},children:I?"Saving...":$?"Update placement":"Schedule placement"}),$&&(0,o.jsx)("button",{onClick:()=>{X(null),q({merchant_id:"",placement_type:"",start_date:"",end_date:"",priority:0,notes:""})},style:{background:"transparent",border:"0.5px solid var(--color-border-tertiary)",padding:"8px 20px",borderRadius:"var(--border-radius-md)",fontSize:13,cursor:"pointer",color:"var(--color-text-secondary)"},children:"Cancel"})]})]}),(0,o.jsx)("div",{style:{display:"flex",gap:6,marginBottom:14},children:[["all","All"],["active","Active now"],["upcoming","Upcoming"],["past","Past"]].map(e=>{let[r,t]=e;return(0,o.jsx)("button",{onClick:()=>G(r),style:{padding:"6px 14px",borderRadius:20,fontSize:12,fontWeight:500,cursor:"pointer",border:"none",background:K===r?"#111":"var(--color-background-secondary)",color:K===r?"#fff":"var(--color-text-secondary)"},children:t},r)})}),(0,o.jsxs)("div",{style:{borderRadius:"var(--border-radius-lg)",border:"0.5px solid var(--color-border-tertiary)",overflow:"hidden",background:"var(--color-background-primary)"},children:[(0,o.jsxs)("div",{style:{padding:"10px 16px",borderBottom:"0.5px solid var(--color-border-tertiary)",fontSize:13,fontWeight:500,color:"var(--color-text-primary)"},children:[e8.length," placement",1!==e8.length?"s":""]}),0===e8.length?(0,o.jsx)("div",{style:{padding:32,textAlign:"center",color:"var(--color-text-secondary)",fontSize:14},children:"No placements found. Schedule one above."}):e8.map(e=>{var r,t;let a=e.is_active&&e.start_date<=e4&&e.end_date>=e4,n=e.start_date>e4,i=e.end_date<e4,d=(null===(r=b.find(r=>r.id===e.placement_type))||void 0===r?void 0:r.label)||e.placement_type;return(0,o.jsxs)("div",{style:{padding:"10px 16px",borderBottom:"0.5px solid var(--color-border-tertiary)",display:"flex",alignItems:"center",gap:10,opacity:i?.5:1},children:[e.merchant&&(0,o.jsx)("div",{style:{width:28,height:28,borderRadius:"var(--border-radius-md)",background:e.merchant.logo_color||"#111",display:"flex",alignItems:"center",justifyContent:"center",color:"#fff",fontSize:10,fontWeight:600,flexShrink:0},children:e.merchant.logo_text||"?"}),(0,o.jsxs)("div",{style:{flex:1,minWidth:0},children:[(0,o.jsxs)("div",{style:{fontSize:13,fontWeight:500,color:"var(--color-text-primary)",display:"flex",alignItems:"center",gap:6},children:[(null===(t=e.merchant)||void 0===t?void 0:t.name)||"Unknown",a&&(0,o.jsx)("span",{style:{fontSize:10,padding:"1px 6px",borderRadius:10,background:"var(--color-background-success)",color:"var(--color-text-success)"},children:"Live"}),n&&(0,o.jsx)("span",{style:{fontSize:10,padding:"1px 6px",borderRadius:10,background:"var(--color-background-info)",color:"var(--color-text-info)"},children:"Upcoming"}),i&&(0,o.jsx)("span",{style:{fontSize:10,padding:"1px 6px",borderRadius:10,background:"var(--color-background-secondary)",color:"var(--color-text-secondary)"},children:"Ended"})]}),(0,o.jsxs)("div",{style:{fontSize:11,color:"var(--color-text-secondary)"},children:[d," \xb7 ",e.start_date," to ",e.end_date,e.notes?" \xb7 ".concat(e.notes):""]})]}),(0,o.jsxs)("div",{style:{fontSize:12,color:"var(--color-text-secondary)",minWidth:20,textAlign:"center"},children:["P",e.priority]}),(0,o.jsxs)("div",{style:{display:"flex",gap:4},children:[(0,o.jsx)("button",{onClick:()=>e6(e),style:{background:"none",border:"0.5px solid var(--color-border-tertiary)",padding:"3px 8px",borderRadius:"var(--border-radius-md)",fontSize:11,cursor:"pointer",color:e.is_active?"var(--color-text-success)":"var(--color-text-secondary)"},children:e.is_active?"On":"Off"}),(0,o.jsx)("button",{onClick:()=>{X(e.id),q({merchant_id:e.merchant_id,placement_type:e.placement_type,start_date:e.start_date,end_date:e.end_date,priority:e.priority||0,notes:e.notes||""})},style:{background:"none",border:"0.5px solid var(--color-border-tertiary)",padding:"3px 8px",borderRadius:"var(--border-radius-md)",fontSize:11,cursor:"pointer",color:"var(--color-text-secondary)"},children:"Edit"}),(0,o.jsx)("button",{onClick:()=>e5(e.id),style:{background:"none",border:"0.5px solid var(--color-border-danger)",padding:"3px 8px",borderRadius:"var(--border-radius-md)",fontSize:11,cursor:"pointer",color:"var(--color-text-danger)"},children:"Del"})]})]},e.id)})]})]}),"coupon queue"===g&&(0,o.jsx)(u,{showMsg:eM}),(0,o.jsx)(p,{isSignedIn:l,activeTab:g,onDataChange:eL})]}):(0,o.jsx)(i.Z,{title:"Admin",children:(0,o.jsx)("p",{style:{color:"var(--color-text-secondary)"},children:"Please sign in to access the admin panel."})})}}},function(e){e.O(0,[333,564,888,774,179],function(){return e(e.s=1517)}),_N_E=e.O()}]);

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.