1import{r as m,j as e}from"./vendor-react-B3Dn138K.js";import{u as P,p as F,X as S,d as M,M as B}from"./index-aiKRc4Xw.js";import{A as O}from"./arrow-left-BT2ADOvu.js";import{C as R}from"./chart-column-DvphZLhy.js";import{B as J}from"./building-2-CFiho0IM.js";import{P as T}from"./plus-CDC8SwmR.js";import{C as Y}from"./chevron-right-BHHx9-MS.js";import{L as z}from"./link-uaQO5oWK.js";import{F as U}from"./file-text-3HY9PPr_.js";import{M as _}from"./mic-CDHUpbgh.js";import{T as G}from"./trash-2-Aaop5sTN.js";import"./vendor-query-CUmDu-Jt.js";import"./vendor-clerk-B6W-q01Q.js";import"./vendor-motion-D-LevzbG.js";const h="/".replace(/\/$/,"")+"/api",v={episode:{label:"Episode",plural:"Episodes",Icon:_,color:"#174E76"},newsletter:{label:"Newsletter",plural:"Newsletters",Icon:B,color:"#285B53"},page:{label:"Site Page",plural:"Site Pages",Icon:U,color:"#6B5FA8"},link:{label:"Tracked Link",plural:"Tracked Links",Icon:z,color:"#D8825B"}};function ie(){const[,a]=P(),{getAuthHeaders:n}=F(),[c,w]=m.useState([]),[j,f]=m.useState(null),[y,b]=m.useState(!0),[u,r]=m.useState(""),[d,N]=m.useState(!1),[C,g]=m.useState(new Set),[o,x]=m.useState(null),s=async()=>{try{const[t,i]=await Promise.all([fetch(`${h}/admin/sponsors`,{headers:n()}),fetch(`${h}/admin/sponsors/options`,{headers:n()})]),l=await t.json(),p=await i.json();Array.isArray(l)&&(w(l),g(k=>k.size===0&&l.length>0?new Set([l[0].id]):k)),p&&!p.error&&f(p)}catch{x("Failed to load sponsors.")}finally{b(!1)}};m.useEffect(()=>{s()},[]);const E=async()=>{const t=u.trim();if(!(!t||d)){N(!0),x(null);try{const i=await fetch(`${h}/admin/sponsors`,{method:"POST",headers:{...n(),"Content-Type":"application/json"},body:JSON.stringify({name:t})}),l=await i.json();i.ok?(r(""),g(p=>new Set(p).add(l.id)),await s()):x(l.error||"Failed to create sponsor.")}finally{N(!1)}}},$=async t=>{await fetch(`${h}/admin/sponsors/${t.id}`,{method:"PUT",headers:{...n(),"Content-Type":"application/json"},body:JSON.stringify({active:!t.active})}),await s()},A=async t=>{window.confirm(`Delete "${t.name}" and all its linked touchpoints and monthly data? This cannot be undone.`)&&(await fetch(`${h}/admin/sponsors/${t.id}`,{method:"DELETE",headers:n()}),await s())},L=async(t,i,l)=>{x(null);const p=await fetch(`${h}/admin/sponsors/${t}/touchpoints`,{method:"POST",headers:{...n(),"Content-Type":"application/json"},body:JSON.stringify({type:i,refId:l})});if(!p.ok){const k=await p.json().catch(()=>({}));x(k.error||"Failed to link touchpoint.")}await s()},I=async(t,i)=>{await fetch(`${h}/admin/sponsors/${t}/touchpoints/${i}`,{method:"DELETE",headers:n()}),await s()},D=t=>g(i=>{const l=new Set(i);return l.has(t)?l.delete(t):l.add(t),l});return e.jsxs("div",{className:"min-h-screen bg-[#FAFAF8]",children:[e.jsx("header",{className:"bg-white border-b border-border sticky top-0 z-40",children:e.jsxs("div",{className:"max-w-5xl mx-auto px-6 py-4 flex items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("button",{onClick:()=>a("/admin"),className:"flex items-center gap-2 text-muted-foreground hover:text-foreground text-sm transition-colors",children:[e.jsx(O,{className:"w-4 h-4"}),"Dashboard"]}),e.jsx("div",{className:"h-5 w-px bg-border"}),e.jsx("h1",{className:"text-lg font-bold",style:{color:"#174E76",fontFamily:"'Plus Jakarta Sans', sans-serif"},children:"Sponsors"})]}),e.jsxs("button",{onClick:()=>a("/admin/sponsors/report"),className:"flex items-center gap-2 px-4 py-2 rounded-xl text-sm font-bold text-white hover:opacity-90 transition-opacity",style:{backgroundColor:"#174E76"},children:[e.jsx(R,{className:"w-4 h-4"}),"Monthly Report"]})]})}),e.jsxs("main",{className:"max-w-5xl mx-auto px-6 py-10",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-6",children:"Label each sponsor, then link the episodes, newsletters, site pages and tracked links where they appear. The monthly report auto-tallies YouTube views, newsletter stats, page traffic and link clicks â podcast player numbers (Megaphone) are entered by hand on the report page."}),o&&e.jsxs("div",{className:"mb-6 px-4 py-3 rounded-xl bg-red-50 border border-red-200 text-sm text-red-700 flex items-center justify-between gap-3",children:[e.jsx("span",{children:o}),e.jsx("button",{onClick:()=>x(null),children:e.jsx(S,{className:"w-4 h-4"})})]}),e.jsx("div",{className:"bg-white rounded-2xl border border-border p-5 mb-8",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(J,{className:"w-5 h-5 flex-shrink-0",style:{color:"#285B53"}}),e.jsx("input",{value:u,onChange:t=>r(t.target.value),onKeyDown:t=>t.key==="Enter"&&E(),placeholder:"New sponsor name (e.g. StRest)",className:"flex-1 px-4 py-2.5 rounded-xl border border-border text-sm focus:outline-none focus:ring-2 focus:ring-[#174E76]/30"}),e.jsxs("button",{onClick:E,disabled:!u.trim()||d,className:"flex items-center gap-2 px-5 py-2.5 rounded-xl text-sm font-bold text-white hover:opacity-90 transition-opacity disabled:opacity-40",style:{backgroundColor:"#285B53"},children:[e.jsx(T,{className:"w-4 h-4"}),"Add Sponsor"]})]})}),y?e.jsx("div",{className:"text-center py-20 text-muted-foreground",children:"Loading sponsorsâ¦"}):c.length===0?e.jsx("div",{className:"text-center py-20 text-muted-foreground",children:"No sponsors yet â add your first sponsor above."}):e.jsx("div",{className:"space-y-5",children:c.map(t=>e.jsx(H,{sponsor:t,options:j,open:C.has(t.id),onToggle:()=>D(t.id),onToggleActive:()=>$(t),onDelete:()=>A(t),onAdd:(i,l)=>
1L(t.id,i,l),onRemove:i=>I(t.id,i)},t.id))})]})]})}function H({sponsor:a,options:n,open:c,onToggle:w,onToggleActive:j,onDelete:f,onAdd:y,onRemove:b}){const u=m.useMemo(()=>{const r={episode:0,newsletter:0,page:0,link:0};for(const d of a.touchpoints)r[d.type]=(r[d.type]||0)+1;return r},[a.touchpoints]);return e.jsxs("div",{className:"bg-white rounded-2xl border border-border overflow-hidden",children:[e.jsxs("div",{className:"px-5 py-4 flex items-center justify-between gap-4 cursor-pointer hover:bg-muted/20",onClick:w,children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[c?e.jsx(M,{className:"w-4 h-4 text-muted-foreground flex-shrink-0"}):e.jsx(Y,{className:"w-4 h-4 text-muted-foreground flex-shrink-0"}),e.jsx("span",{className:`font-bold truncate ${a.active?"":"text-muted-foreground line-through"}`,style:a.active?{color:"#174E76"}:{},children:a.name}),e.jsx("span",{className:"hidden sm:flex items-center gap-2 text-xs text-muted-foreground flex-shrink-0",children:Object.keys(v).map(r=>u[r]?e.jsxs("span",{className:"px-2 py-0.5 rounded-full bg-muted/60",children:[u[r]," ",u[r]===1?v[r].label.toLowerCase():v[r].plural.toLowerCase()]},r):null)})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",onClick:r=>r.stopPropagation(),children:[e.jsx("button",{onClick:j,className:`px-3 py-1 rounded-full text-xs font-bold border transition-colors ${a.active?"border-emerald-200 bg-emerald-50 text-emerald-700":"border-border bg-muted/40 text-muted-foreground"}`,children:a.active?"Active":"Inactive"}),e.jsx("button",{onClick:f,className:"p-1.5 rounded-lg text-muted-foreground hover:text-red-600 hover:bg-red-50 transition-colors",title:"Delete sponsor",children:e.jsx(G,{className:"w-4 h-4"})})]})]}),c&&e.jsx("div",{className:"border-t border-border px-5 py-5 grid gap-5 md:grid-cols-2",children:Object.keys(v).map(r=>e.jsx(K,{type:r,touchpoints:a.touchpoints.filter(d=>d.type===r),options:n,onAdd:d=>y(r,d),onRemove:b},r))})]})}function K({type:a,touchpoints:n,options:c,onAdd:w,onRemove:j}){const{plural:f,Icon:y,color:b}=v[a],[u,r]=m.useState(!1),[d,N]=m.useState(""),C=new Set(n.map(o=>o.refId)),g=m.useMemo(()=>{if(!c)return[];let o=[];a==="episode"?o=c.episodes.map(s=>({refId:s.slug,label:s.title,sub:s.pubDate?new Date(s.pubDate).toLocaleDateString():void 0})):a==="newsletter"?o=c.newsletters.map(s=>({refId:s.slug,label:s.title,sub:s.publishedAt?new Date(s.publishedAt).toLocaleDateString():void 0})):a==="page"?o=c.pages.map(s=>({refId:s.path,label:s.path,sub:`${s.views} views · 120d`})):o=c.links.map(s=>({refId:s.slug,label:`/go/${s.slug}`,sub:`${s.partner}${s.label?` · ${s.label}`:""}`}));const x=d.trim().toLowerCase();return o.filter(s=>!C.has(s.refId)).filter(s=>!x||s.label.toLowerCase().includes(x)||(s.sub||"").toLowerCase().includes(x)).slice(0,30)},[c,a,d,n]);return e.jsxs("div",{className:"rounded-xl border border-border overflow-hidden",children:[e.jsxs("div",{className:"px-4 py-2.5 flex items-center justify-between gap-2 border-b border-border",style:{backgroundColor:"#fafaf8"},children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(y,{className:"w-4 h-4",style:{color:b}}),e.jsx("h4",{className:"text-sm font-bold",style:{color:"#174E76"},children:f}),n.length>0&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",n.length,")"]})]}),e.jsxs("button",{onClick:()=>{r(o=>!o),N("")},className:"flex items-center gap-1 text-xs font-bold hover:opacity-80",style:{color:b},children:[u?e.jsx(S,{className:"w-3.5 h-3.5"}):e.jsx(T,{className:"w-3.5 h-3.5"}),u?"Close":"Link"]})]}),u&&e.jsxs("div",{className:"border-b border-border p-3 bg-muted/10",children:[e.jsx("input",{autoFocus:!0,value:d,onChange:o=>N(o.target.value),placeholder:`Search ${f.toLowerCase()}â¦`,className:"w-full px-3 py-2 rounded-lg border border-border text-sm mb-2 focus:outline-none focus:ring-2 focus:ring-[#174E76]/30"}),e.jsx("div",{className:"max-h-48 overflow-y-auto space-y-1",children:g.length===0?e.jsx("p",{className:"text-xs text-muted-foreground px-1 py-2",children:"No matches."}):g.map(o=>e.jsxs("button",{onClick:()=>{w(o.refId),r(!1)},className:"w-full text-left px-3 py-2 rounded-lg hover:bg-white border border-transparent hover:border-border text-sm transition-colors",children:[e.jsx("span",{className:"block truncate font-medium",children:o.label}),o.sub&&e.jsx("span",{className:"block text-xs text-muted-foreground truncate",children:o.sub})]},o.refId))})]}),n.length===0?e.jsx("p",{className:"px-4 py-3 text-xs text-muted-foreground",children:"None linked yet."}):e.jsx("div",{className:"divide-y divide-border",children:n.map(o=>e.jsxs("div",{className:"px-4 py-2.5 flex items-center justify-between gap-3 text-sm",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("span",{className:"block truncate",children:o.label||o.refId}),a==="episode"&&e.jsx("span",{className:"block text-xs text-muted-foreground",children:o.meta?.youtubeId?`YouTube ${o.meta.youtubeId}`:"No YouTube match â views need manual entry"}),a==="link"&&e.jsxs("span",{className:"block text-xs text-muted-foreground font-mono",children:["/go/",o.refId]})]}),e.jsx("button",{onClick:()=>j(o.id),className:"p-1 rounded text-muted-foreground hover:text-red-600 hover:bg-red-50 flex-shrink-0",title:"Unlink",children:e.jsx(S,{className:"w-3.5 h-3.5"})})]},o.id))})]})}export{ie as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.