PageSourceSearch

https://www.socialscout.ai/_next/static/immutable/chunks/3i_vc4a-i9ml7.js

js socialscout.ai collected 2026-10-05 15:08:15 UTC 112,666 bytes, 1 lines download raw bytes

1(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,760925,839460,e=>{"use strict";var t=e.i(843476),a=e.i(271645),r=e.i(686337),s=e.i(217255),i=e.i(365178),n=e.i(979259),l=e.i(427217),o=e.i(662060),d=e.i(80843),c=e.i(163858),u=e.i(370221),m=e.i(984174),x=e.i(302292),h=e.i(779529),p=e.i(171387),f=e.i(833786),g=e.i(174080),b=e.i(846932),y=e.i(88653),v=e.i(705766),k=e.i(220316),j=e.i(39875),w=e.i(269519),N=e.i(107657),S=e.i(191929),_=e.i(232579);let C=[.25,.46,.45,.94],z="#ec4899",I="#8b5cf6",T="#6366f1",P="#10b981",E={hidden:{},show:{transition:{staggerChildren:.04,delayChildren:.05}}},O={hidden:{opacity:0,y:8,scale:.97},show:{opacity:1,y:0,scale:1,transition:{duration:.4,ease:C}}};function R({src:e,name:a,accent:r,size:s=36,icon:i}){let n=(a||"?").trim().charAt(0).toUpperCase();return(0,t.jsx)("div",{className:"relative shrink-0 rounded-xl overflow-hidden flex items-center justify-center",style:{width:s,height:s,background:e?"var(--surface-soft)":`linear-gradient(135deg, ${r}, ${r}99)`,border:"1px solid var(--border-subtle)"},children:e?(0,t.jsx)("img",{src:e,alt:a||"",className:"w-full h-full object-cover"}):i&&!a?(0,t.jsx)(i,{className:"w-4 h-4 text-white"}):(0,t.jsx)("span",{className:"text-white font-black tracking-tight",style:{fontSize:Math.round(.4*s)},children:n})})}function A({mark:e,eyebrow:a,title:r,subtitle:s,count:i,accent:n}){return(0,t.jsxs)("div",{className:"flex items-center gap-3 mb-2.5",children:[e,(0,t.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,t.jsx)("p",{className:"text-[10px] font-bold uppercase tracking-[0.14em]",style:{color:n},children:a}),(0,t.jsx)("p",{className:"text-sm font-bold text-gray-900 dark:text-zinc-100 truncate leading-tight",children:r}),s&&(0,t.jsx)("p",{className:"text-[11px] text-gray-400 dark:text-zinc-500 truncate",children:s})]}),(0,t.jsx)("span",{className:"px-2 py-0.5 rounded-full text-[10px] font-bold tabular-nums shrink-0",style:{background:`${n}14`,color:n,border:`1px solid ${n}25`},children:i})]})}function D({label:e,value:a,accent:r,icon:s}){return(0,t.jsxs)("div",{className:"flex items-center gap-2.5 px-3 py-2 rounded-xl min-w-0",style:{background:"var(--surface-soft)",border:"1px solid var(--border-subtle)"},children:[(0,t.jsx)("div",{className:"w-7 h-7 rounded-lg flex items-center justify-center shrink-0",style:{background:`${r}14`},children:(0,t.jsx)(s,{className:"w-3.5 h-3.5",style:{color:r}})}),(0,t.jsxs)("div",{className:"min-w-0",children:[(0,t.jsx)("p",{className:"text-base font-black tabular-nums leading-none text-gray-900 dark:text-zinc-100",children:a}),(0,t.jsx)("p",{className:"text-[10px] font-semibold uppercase tracking-wider text-gray-400 dark:text-zinc-500 truncate",children:e})]})]})}function F({member:e,roles:a,isMe:r,locked:s,canRemove:i,busy:n,onRemove:o}){var d;let c=[!(d=e.role)?"":d.split("_").map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" "),e.email].filter(Boolean).join(" · ");return(0,t.jsxs)(b.motion.div,{variants:O,className:"flex items-center gap-3 px-3 py-2.5",children:[(0,t.jsxs)("div",{className:"relative shrink-0",children:[(0,t.jsx)(f.default,{user:e,size:36}),a?.[0]&&(0,t.jsx)("span",{className:"absolute -bottom-0.5 -right-0.5 w-3 h-3 rounded-full ring-2 ring-white dark:ring-zinc-950",style:{background:a[0].color},title:a.map(e=>e.label).join(", ")})]}),(0,t.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,t.jsxs)("p",{className:"text-sm font-semibold text-gray-900 dark:text-zinc-100 truncate",children:[e.name||"Unknown",r&&(0,t.jsx)("span",{className:"ml-1.5 text-[10px] font-bold uppercase tracking-[0.08em] text-gray-400 dark:text-zinc-500",children:"you"})]}),a?.length?(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-1 mt-0.5",children:[a.map(e=>(0,t.jsx)("span",{className:"px-1.5 py-0.5 rounded-md text-[9px] font-bold uppercase tracking-wider",style:{background:`${e.color}14`,color:e.color,border:`1px solid ${e.color}25`},children:e.label},e.key)),e.email&&(0,t.jsxs)("span",{className:"text-[11px] text-gray-400 dark:text-zinc-500 truncate",children:["· ",e.email]})]}):(0,t.jsx)("p",{className:"text-[11px] text-gray-400 dark:text-zinc-500 truncate",children:c})]}),s?(0,t.jsx)("div",{className:"w-9 h-9 rounded-xl flex items-center justify-center text-gray-300 dark:text-zinc-600 shrink-0",style:{background:"var(--surface-soft)"},title:"In the pod — follows automatically. Change roles in Campaign Settings → Team.","aria-label":"Pod member, follows automatically",children:(0,t.jsx)(N.LockClosedIcon,{className:"w-3.5 h-3.5"})}):i?(0,t.jsx)("button",{type:"button",disabled:n,onClick:o,title:r?"Leave campaign":`Remove ${e.name}`,"aria-label":r?"Leave campaign":`Remove ${e.name}`,className:"w-9 h-9 rounded-xl flex items-center justify-center text-red-500 hover:scale-105 transition-transform disabled:opacity-50 shrink-0",style:{background:"#ef444414"},children:(0,t.jsx)(l.XMarkIcon,{className:"w-4 h-4"})}):null]})}function $({children:e}){return(0,t.jsx)("div",{className:"rounded-2xl overflow-hidden divide-y divide-black/5 dark:divide-white/5",style:{background:"var(--surface-soft)",border:"1px solid var(--border-subtle)"},children:e})}function L({campaign:e,campaignFollowers:i=[],setIsSidebarOpen:n,campaignId:d,setRefetchTrigger:c}){let{data:u}
1=(0,s.useSession)(),{can:m,loading:x}=(0,_.usePermissions)(),h=!x&&m("campaigns","edit"),p=u?.user?._id?.toString?.()||u?.user?._id,[N,M]=(0,a.useState)(!1),[B,U]=(0,a.useState)(!1),[q,W]=(0,a.useState)(""),[V,G]=(0,a.useState)([]),[H,K]=(0,a.useState)(!1),[J,X]=(0,a.useState)(null),Z=(0,a.useRef)(null);(0,a.useEffect)(()=>M(!0),[]);let Y=()=>n(!1);(0,a.useEffect)(()=>{function e(e){"Escape"===e.key&&Y()}return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[]),(0,a.useEffect)(()=>{B&&Z.current?.focus()},[B]);let Q=(0,a.useMemo)(()=>new Set((i||[]).map(e=>String(e._id))),[i]);(0,a.useEffect)(()=>{if(!B)return;let e=q.trim();if(!e)return void G([]);let t=!1;K(!0);let a=setTimeout(async()=>{try{let a=await fetch(`/api/searchAutoCompleteUsers?query=${encodeURIComponent(e)}`),r=a.ok?await a.json():[];t||G((Array.isArray(r)?r:[]).filter(e=>!Q.has(String(e._id))))}catch{t||G([])}finally{t||K(!1)}},250);return()=>{t=!0,clearTimeout(a)}},[q,B,Q]);let{pod:ee,team:et,guestGroups:ea,rolesByUser:er,agency:es}=(0,a.useMemo)(()=>{let t=(i||[]).filter(e=>e&&e._id),a=new Map(t.map(e=>[String(e._id),e])),s=new Map,n=new Map;for(let t of(0,r.normalizePodSlots)(e?.pod,r.CAMPAIGN_POD_SPEC,e))for(let e of t.users){let i=(0,r.idOf)(e);if(i&&(s.has(i)||s.set(i,[]),s.get(i).push({key:t.key,label:t.label,color:t.color}),!n.has(i))){let t=a.get(i),r="object"==typeof e?e:{};n.set(i,{...r,...t||{},_id:i,name:t?.name||r.name||""})}}let l=e?.agency&&"object"==typeof e.agency?e.agency:null,o=(0,r.idOf)(e?.agency),d=[],c=[];for(let e of t){let t=String(e._id);
1n.has(t)||(o&&(0,r.idOf)(e.agency)===o?d.push(e):c.push(e))}let u=new Map;for(let e of c){let t=e.agency?.name?{kind:"agency",...e.agency}:e.organization?.name?{kind:"org",...e.organization}:null,a=t?`${t.kind}:${(0,r.idOf)(t)}`:"none";u.has(a)||u.set(a,{key:a,entity:t,members:[]}),u.get(a).members.push(e)}let m=(e,t)=>(e.name||"").localeCompare(t.name||""),x=[...u.values()].sort((e,t)=>e.entity?t.entity?e.entity.name.localeCompare(t.entity.name):-1:1).map(e=>({...e,members:e.members.sort(m)}));return{pod:[...n.values()].sort(m),team:d.sort(m),guestGroups:x,rolesByUser:s,agency:l}},[i,e]),ei=ea.reduce((e,t)=>e+t.members.length,0),en=ee.length+et.length+ei;async function el(e){X(e._id);try{let t=await fetch("/api/addFollower",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({campaignId:d,follower:e._id})}),a=await t.json().catch(()=>({}));if(!t.ok||!a.success)throw Error(a.err||"Couldn't add teammate");v.default.success(`${e.name} added to the team`),W(""),G([]),c(e=>e+1)}catch(e){v.default.error(e.message)}finally{X(null)}}async function eo(e){X(e._id);try{let t=await fetch("/api/removeFollower",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({campaignId:d,followerId:e._id})}),a=await t.json().catch(()=>({}));if(!t.ok||!a.success)throw Error(a.err||"Couldn't remove teammate");v.default.success(`${e.name} removed`),c(e=>e+1)}catch(e){v.default.error(e.message)}finally{X(null)}}if(!N)return null;let ed=(e,{locked:a=!1}={})=>{let r=p&&String(e._id)===String(p);return(0,t.jsx)(F,{member:e,roles:er.get(String(e._id)),isMe:r,locked:a,canRemove:h||r,busy:J===e._id,onRemove:()=>eo(e)},e._id)};return(0,g.createPortal)((0,t.jsx)(y.AnimatePresence,{children:(0,t.jsxs)(b.motion.div,{initial:{opacity:0}
1,animate:{opacity:1},exit:{opacity:0},transition:{duration:.2},className:"fixed inset-0 z-[100] flex justify-end",children:[(0,t.jsx)("div",{className:"absolute inset-0 bg-black/20 backdrop-blur-sm",onClick:Y}),(0,t.jsxs)(b.motion.div,{initial:{x:"100%",scale:.98,opacity:0},animate:{x:0,scale:1,opacity:1},exit:{x:"100%",scale:.98,opacity:0},transition:{duration:.5,ease:C},className:"relative w-full max-w-none sm:max-w-[480px] flex flex-col overflow-hidden h-dvh-safe",style:{background:"var(--surface-panel)",backdropFilter:"blur(40px)",boxShadow:"-20px 0 60px var(--border-default), -4px 0 20px var(--surface-softer)"},role:"dialog","aria-modal":"true","aria-label":"Campaign team",children:[(0,t.jsx)("div",{className:"absolute top-0 left-0 right-0 h-[3px] bg-gradient-to-r from-pink-500/60 via-orange-400/60 to-violet-500/60 z-20"}),(0,t.jsx)("div",{className:"absolute top-0 left-0 bottom-0 w-[1.5px] opacity-65 pointer-events-none animate-gradient-shift z-20",style:{background:"linear-gradient(180deg, rgba(236,72,153,0.6), rgba(249,115,22,0.5), rgba(139,92,246,0.55), rgba(236,72,153,0.6))"}}),(0,t.jsx)("div",{className:"absolute -top-24 -right-24 w-72 h-72 rounded-full blur-3xl pointer-events-none animate-orb-drift-a",style:{background:"radial-gradient(circle, rgba(249,115,22,0.22), rgba(236,72,153,0.16) 55%, transparent 75%)",opacity:.85}}),(0,t.jsx)("div",{className:"absolute -bottom-32 -left-20 w-80 h-80 rounded-full blur-3xl pointer-events-none animate-orb-drift-b",style:{background:"radial-gradient(circle, rgba(139,92,246,0.18), rgba(59,130,246,0.12) 55%, transparent 75%)",opacity:.75}}),(0,t.jsxs)("div",{className:"relative z-10 flex-shrink-0 px-4 sm:px-6 pb-4",style:{paddingTop:"calc(1.25rem + env(safe-area-inset-top, 0px))",background:"var(--surface-frosted)",backdropFilter:"blur(20px)",borderBottom:"1px solid var(--border-subtle)"},children:[(0,t.jsxs)("div",{className:"flex items-center gap-3",children:[(0,t.jsx)("div",{className:"w-10 h-10 rounded-xl flex items-center justify-center flex-shrink-0",style:{background:`${z}14`,color:z},children:(0,t.jsx)(k.UsersIcon,{className:"w-5 h-5"})}),(0,t.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,t.jsx)("h2",{className:"text-lg font-black text-gray-900 dark:text-zinc-100 tracking-tight truncate",children:"Campaign Team"}),(0,t.jsxs)("p",{className:"text-xs text-gray-500 dark:text-zinc-400 truncate",children:[en," member",1!==en?"s":""," following",e?.name?` ${e.name}`:" this campaign"]})]}),(0,t.jsxs)("div",{className:"flex items-center gap-1.5 flex-shrink-0",children:[h&&(0,t.jsx)("button",{type:"button",onClick:()=>U(e=>!e),title:"Add teammate","aria-pressed":B,className:"w-9 h-9 rounded-xl flex items-center justify-center hover:scale-105 transition-transform",style:{background:B?z:`${z}14`,color:B?"#fff":z},children:(0,t.jsx)(o.UserPlusIcon,{className:"w-4 h-4"})}),(0,t.jsx)("button",{type:"button",onClick:Y,"aria-label":"Close",className:"w-9 h-9 rounded-xl flex items-center justify-center text-gray-500 dark:text-zinc-400 hover:scale-105 transition-transform",style:{background:"var(--surface-soft)"},children:(0,t.jsx)(l.XMarkIcon,{className:"w-4 h-4"})})]})]}),en>0&&(0,t.jsxs)("div",{className:"grid grid-cols-3 gap-2 mt-4",children:[(0,t.jsx)(D,{label:"Pod",value:ee.length,accent:I,icon:k.UsersIcon}),(0,t.jsx)(D,{label:"Team",value:et.length,accent:T,icon:w.BuildingOfficeIcon}),(0,t.jsx)(D,{label:"Guests",value:ei,accent:P,icon:S.GlobeAltIcon})]}),(0,t.jsx)(y.AnimatePresence,{initial:!1,children:h&&B&&(0,t.jsxs)(b.motion.div,{initial:{opacity:0,height:0,marginTop:0},animate:{opacity:1,height:"auto",marginTop:14},exit:{opacity:0,height:0,marginTop:0},transition:{duration:.35,ease:C},className:"overflow-hidden",children:[(0,t.jsxs)("div",{className:"relative group/composer",children:[(0,t.jsx)("div",{className:"absolute -inset-1 rounded-2xl opacity-0 blur-xl pointer-events-none transition-opacity duration-500 group-focus-within/composer:opacity-40 bg-gradient-to-r from-pink-500 to-orange-400"}),(0,t.jsxs)("div",{className:"relative",children:[(0,t.jsx)(j.MagnifyingGlassIcon,{className:"absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-gray-400 dark:text-zinc-500 pointer-events-none"}),(0,t.jsx)("input",{ref:Z,type:"text",value:q,onChange:e=>W(e.target.value),placeholder:"Search by name, or enter an email",className:"w-full rounded-xl pl-9 pr-9 py-2.5 text-sm text-gray-900 dark:text-zinc-100 placeholder:text-gray-400 dark:placeholder:text-zinc-500 outline-none focus:ring-2 focus:ring-pink-400/40",style:{background:"var(--surface-soft)",border:"1px solid var(--border-subtle)"}}),q&&(0,t.jsx)("button",{type:"button",onClick:()=>W(""),"aria-label":"Clear search",className:"absolute right-2 top-1/2 -translate-y-1/2 w-6 h-6 rounded-full flex items-center justify-center text-gray-400 dark:text-zinc-500 hover:text-gray-600 dark:hover:text-zinc-300",children:(0,t.jsx)(l.XMarkIcon,{className:"w-3.5 h-3.5"})})]})]}),(0,t.jsx)("p",{className:"mt-2 text-[11px] text-gray-400 dark:text-zinc-500",children:"Name search covers your agency. To add someone outside it, enter the
1ir exact email. Followers can view this campaign."}),q.trim()&&(0,t.jsx)("div",{className:"mt-2 rounded-xl overflow-hidden",style:{background:"var(--surface-soft)",border:"1px solid var(--border-subtle)"},children:H&&0===V.length?(0,t.jsx)("p",{className:"px-3 py-2.5 text-xs text-gray-400 dark:text-zinc-500",children:"Searching…"}):0===V.length?(0,t.jsxs)("p",{className:"px-3 py-2.5 text-xs text-gray-400 dark:text-zinc-500",children:["No teammates match “",q.trim(),"”."]}):(0,t.jsx)(b.motion.ul,{variants:E,initial:"hidden",animate:"show",className:"divide-y divide-black/5 dark:divide-white/5",children:V.map(e=>(0,t.jsx)(b.motion.li,{variants:O,children:(0,t.jsxs)("button",{type:"button",disabled:J===e._id,onClick:()=>el(e),className:"w-full flex items-center gap-3 px-3 py-2 text-left hover:bg-black/[0.03] dark:hover:bg-white/[0.04] transition-colors disabled:opacity-50",children:[(0,t.jsx)(f.default,{user:e,size:32}),(0,t.jsxs)("span",{className:"flex-1 min-w-0",children:[(0,t.jsx)("span",{className:"block text-sm font-semibold text-gray-900 dark:text-zinc-100 truncate",children:e.name}),e.organization?.name&&(0,t.jsx)("span",{className:"block text-[11px] text-gray-400 dark:text-zinc-500 truncate",children:e.organization.name})]}),(0,t.jsx)(o.UserPlusIcon,{className:"w-4 h-4 flex-shrink-0",style:{color:z}})]})},e._id))})})]},"add")})]}),(0,t.jsx)("div",{className:"relative z-10 flex-1 min-h-0 overflow-y-auto px-4 sm:px-6 pt-5",style:{paddingBottom:"calc(1.25rem + env(safe-area-inset-bottom, 0px))"},children:0===en?(0,t.jsxs)("div",{className:"flex flex-col items-center text-center pt-10 px-4",children:[(0,t.jsx)("div",{className:"w-16 h-16 rounded-2xl bg-gradient-to-br from-pink-100 to-orange-50 dark:from-pink-500/20 dark:to-orange-500/10 flex items-center justify-center mb-4",children:(0,t.jsx)(k.UsersIcon,{className:"w-8 h-8",style:{color:z}})}),(0,t.jsx)("h3",{className:"text-lg font-bold text-gray-800 dark:text-zinc-100",children:"No team yet"}),(0,t.jsx)("p",{className:"text-sm text-gray-500 dark:text-zinc-400 max-w-md mt-1",children:h?"Staff the pod in Campaign Settings → Team, or add teammates here so they're kept in the loop.":"Nobody is following this campaign yet."})]}):(0,t.jsxs)(b.motion.div,{variants:E,initial:"hidden",animate:"show",className:"space-y-7",children:[(0,t.jsxs)("section",{children:[(0,t.jsx)(A,{accent:I,eyebrow:"Pod",title:es?.name?`${es.name} pod`:"Campaign pod",subtitle:ee.length?"Follow automatically · roles set in Campaign Settings":"No roles filled yet · Campaign Settings → Team",count:ee.length,mark:(0,t.jsx)(R,{src:es?.image,name:es?.name,accent:I,icon:k.UsersIcon})}),ee.length>0?(0,t.jsx)($,{children:ee.map(e=>ed(e,{locked:!0}))}):(0,t.jsx)("div",{className:"rounded-2xl px-4 py-3 text-[12px] text-gray-400 dark:text-zinc-500",style:{background:"var(--surface-soft)",border:"1px dashed var(--border-default)"},children:"Roles you assign in Campaign Settings → Team show up here and follow the campaign automatically."})]}),et.length>0&&(0,t.jsxs)("section",{children:[(0,t.jsx)(A,{accent:T,eyebrow:"Team",title:es?.name||"Agency team",subtitle:[es?.country,es?.code].filter(Boolean).join(" · ")||"Followers from the owning agency",count:et.length,mark:(0,t.jsx)(R,{src:es?.image,name:es?.name,accent:T,icon:w.BuildingOfficeIcon})}),(0,t.jsx)($,{children:et.map(e=>ed(e))})]}),ea.length>0&&(0,t.jsxs)("section",{className:"space-y-4",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("span",{className:"text-[10px] font-bold uppercase tracking-[0.14em]",style:{color:P},children:"Everyone else"}),(0,t.jsx)("span",{className:"flex-1 h-px bg-gradient-to-r from-gray-200 dark:from-zinc-800 to-transparent"})]}),ea.map(e=>(0,t.jsxs)("div",{children:[(0,t.jsx)(A,{accent:P,eyebrow:e.entity?"agency"===e.entity.kind?"Agency":"Organization":"Independent",title:e.entity?.name||"No agency or organization",subtitle:e.entity?.kind==="agency"?[e.entity.country,e.entity.code].filter(Boolean).join(" · "):null,count:e.members.length,mark:(0,t.jsx)(R,{src:e.entity?.image,name:e.entity?.name,accent:P,icon:S.GlobeAltIcon})}),(0,t.jsx)($,{children:e.members.map(e=>ed(e))})]},e.key))]})]})})]})]},"follower-drawer")}),document.body)}var M=e.i(951489),B=e.i(460759),U=e.i(844735),q=e.i(247103),W=e.i(683512);function V(e){if(!e)return"";let t=e.trim(),a=t.match(/\/spreadsheets\/d\/([a-zA-Z0-9_-]+)/);return a?a[1]:/^[a-zA-Z0-9_-]{20,}$/.test(t)?t:""}let G=e=>
1Number.isFinite(e)?`$${Math.round(e).toLocaleString()}`:"—",H=e=>Number.isFinite(e)?Math.round(e).toLocaleString():"—";function K({data:e}){if(!e?.platforms)return(0,t.jsx)("p",{className:"text-xs text-gray-500 dark:text-zinc-400 py-3",children:"No parsed data on this upload."});let r={meta:"Meta",tiktok:"TikTok",snap:"Snapchat",youtube:"YouTube"};return(0,t.jsx)("div",{className:"space-y-3",children:Object.entries(e.platforms).map(([e,s])=>{let i=s.total||{},n=Object.entries(s.byInfluencer||{});return n.length||i.spend?(0,t.jsxs)("div",{className:"rounded-lg overflow-hidden",style:{background:"var(--surface-solid)",border:"1px solid var(--border-subtle)"},children:[(0,t.jsxs)("div",{className:"px-3 py-2 flex items-center justify-between",style:{background:"var(--surface-softer)",borderBottom:"1px solid var(--border-subtle)"},children:[(0,t.jsx)("span",{className:"text-[11px] font-bold uppercase tracking-wider text-gray-700 dark:text-zinc-300",children:r[e]||e}),(0,t.jsxs)("span",{className:"text-[10px] font-semibold text-gray-500 dark:text-zinc-400 tabular-nums",children:["Total: ",G(i.spend)," · ",H(i.impressions)," imp ·"," ",H(i.engagements)," eng"]})]}),(0,t.jsx)("div",{className:"overflow-x-auto",children:(0,t.jsxs)("table",{className:"w-full text-[11px] tabular-nums",children:[(0,t.jsx)("thead",{children:(0,t.jsxs)("tr",{className:"text-left text-gray-400 dark:text-zinc-500",style:{borderBottom:"1px solid var(--border-subtle)"},children:[(0,t.jsx)("th",{className:"px-3 py-1.5 font-semibold uppercase tracking-wider text-[10px]",children:"Influencer / Placement"}),(0,t.jsx)("th",{className:"px-2 py-1.5 font-semibold uppercase tracking-wider text-[10px] text-right",children:"Spend"}),(0,t.jsx)("th",{className:"px-2 py-1.5 font-semibold uppercase tracking-wider text-[10px] text-right",children:"Impr."}),(0,t.jsx)("th",{className:"px-2 py-1.5 font-semibold uppercase tracking-wider text-[10px] text-right",children:"Video Views"}),(0,t.jsx)("th",{className:"px-2 py-1.5 font-semibold uppercase tracking-wider text-[10px] text-right",children:"2s VVs"}),(0,t.jsx)("th",{className:"px-2 py-1.5 font-semibold uppercase tracking-wider text-[10px] text-right",children:"VP 100%"}),(0,t.jsx)("th",{className:"px-2 py-1.5 font-semibold uppercase tracking-wider text-[10px] text-right",children:"Eng."}),(0,t.jsx)("th",{className:"px-2 py-1.5 font-semibold uppercase tracking-wider text-[10px] text-right",children:"Clicks"})]})}),(0,t.jsx)("tbody",{children:n.map(([e,r])=>{let s=Object.entries(r.byPlacement||{});return(0,t.jsxs)(a.default.Fragment,{children:[(0,t.jsxs)("tr",{className:"text-gray-900 dark:text-zinc-100",style:{background:"var(--surface-softer)",borderTop:"1px solid var(--border-subtle)"},children:[(0,t.jsx)("td",{className:"px-3 py-1.5 font-semibold",children:e}),(0,t.jsx)("td",{className:"px-2 py-1.5 text-right font-semibold",children:G(r.total?.spend)}),(0,t.jsx)("td",{className:"px-2 py-1.5 text-right",children:H(r.total?.impressions)}),(0,t.jsx)("td",{className:"px-2 py-1.5 text-right",children:H(r.total?.videoPlays)}),(0,t.jsx)("td",{className:"px-2 py-1.5 text-right",children:H(r.total?.videoPlays3s)}),(0,t.jsx)("td",{className:"px-2 py-1.5 text-right",children:H(r.total?.videoPlays100)}),(0,t.jsx)("td",{className:"px-2 py-1.5 text-right",children:H(r.total?.engagements)}),(0,t.jsx)("td",{className:"px-2 py-1.5 text-right",children:H(r.total?.clicks)})]}),s.map(([a,r])=>(0,t.jsxs)("tr",{className:"text-gray-600 dark:text-zinc-400",children:[(0,t.jsx)("td",{className:"px-3 py-1 pl-6 truncate max-w-[280px]",children:a}),(0,t.jsx)("td",{className:"px-2 py-1 text-right",children:G(r.spend)}),(0,t.jsx)("td",{className:"px-2 py-1 text-right",children:H(r.impressions)}),(0,t.jsx)("td",{className:"px-2 py-1 text-right",children:H(r.videoPlays)}),(0,t.jsx)("td",{className:"px-2 py-1 text-right",children:H(r.videoPlays3s)}),(0,t.jsx)("td",{className:"px-2 py-1 text-right",children:H(r.videoPlays100)}),(0,t.jsx)("td",{className:"px-2 py-1 text-right",children:H(r.engagements)}),(0,t.jsx)("td",{className:"px-2 py-1 text-right",children:H(r.clicks)})]},`${e}::${a}`))]},e)})})]})})]},e):null})})}function J({campaignId:e,onClose:r}){let[s,i]=(0,a.useState)([]),[n,o]=(0,a.useState)(new Set),[d,c]=(0,a.useState)(!0),[u,m]=(0,a.useState)(!1),[h,f]=(0,a.useState)(null),[g,b]=(0,a.useState)(!1),[y,k]=(0,a.useState)(null),[j,w]=(0,a.useState)(new Set),[N,S]=(0,a.useState)({}),[_,C]=(0,a.useState)(new Set),[z,I]=(0,a.useState)(!1),[T,P]=(0,a.useState)(""),[E,O]=(0,a.useState)(""),[R,A]=(0,a.useState)([]),[D,F]=(0,a.useState)(!1),[$,L]=(0,a.useState)(""),[G,H]=(0,a.useState)(""),[X,Z]=(0,a.useState)(!1),Y=(0,a.useCallback)(async()=>{c(!0);try{let t=await fetch(`/api/campaigns/${e}/publicis-paid`);if(t.ok){let e=await t.json();i(e.uploads||[]),o(new Set((e.uploads||[]).map(e=>e._id)))}else v.default.error("Failed to load Publicis paid uploads")}catch{v.default.error("Network error")}finally{c(!1)}},[e]);(0,a.useEffect)(()=>{Y()},[Y]);let Q=async t=>{if(j.has(t))return void w(e=>{let a=new Set(e);return a.delete(t),a}
1);if(w(e=>new Set(e).add(t)),!N[t]){C(e=>new Set(e).add(t));try{let a=await fetch(`/api/campaigns/${e}/publicis-paid/${t}`);if(a.ok){let e=await a.json();S(a=>({...a,[t]:e.upload?.data||{}}))}else v.default.error("Failed to load upload details")}catch{v.default.error("Network error loading details")}finally{C(e=>{let a=new Set(e);return a.delete(t),a})}}},[ee,et]=(0,a.useState)(null);(0,a.useEffect)(()=>{let t=V(T);if(!t){A([]),et(null);return}let a=!1;return F(!0),et(null),(async()=>{try{let r=await fetch(`/api/campaigns/${e}/publicis-paid/tabs?sheetId=${encodeURIComponent(t)}`),s=await r.json().catch(()=>({}));if(a)return;r.ok&&Array.isArray(s.tabs)?(A(s.tabs),s.tabs.length&&!E&&O(s.tabs[0])):(A([]),et(s?.error||`Couldn't list tabs (${r.status})`))}catch(e){a||(A([]),et(e?.message||"Network error listing tabs"))}finally{a||F(!1)}})(),()=>{a=!0}},[T,e]);let ea=async t=>{t.preventDefault();let a=V(T);if(!a)return void v.default.error("Paste a valid Google Sheets URL or ID");Z(!0);try{let t=await fetch(`/api/campaigns/${e}/publicis-paid`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sheetId:a,tabName:E||void 0,weekStart:$||void 0,weekEnd:G||void 0})}),r=await t.json();if(!t.ok)return void v.default.error(r.error||"Upload failed");v.default.success("Publicis paid sheet uploaded"),P(""),O(""),A([]),L(""),H(""),I(!1),await Y()}catch(e){v.default.error(e.message||"Network error")}finally{Z(!1)}},er=async t=>{if(confirm("Delete this Publicis paid upload?"))try{(await fetch(`/api/campaigns/${e}/publicis-paid?uploadId=${t}`,{method:"DELETE"})).ok?(v.default.success("Deleted"),await Y()):v.default.error("Delete failed")}catch{v.default.error("Network error")}},es=async()=>{b(!0),k(null);try{let t=await fetch(`/api/campaigns/${e}/hulu-sheet`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({publicisUploadIds:Array.from(n),dryRun:!0})}),a=await t.json();if(!t.ok)return void v.default.error(a.error||"Preview failed");k(a.cellEntries||[]),v.default.success(`Previewing ${a.cellEntries?.length||0} cell ranges`)}catch(e){v.default.error(e.message||"Network error")}finally{b(!1)}},ei=async()=>{m(!0),f(null);try{let t=await fetch(`/api/campaigns/${e}/hulu-sheet`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({publicisUploadIds:Array.from(n)})}),a=await t.json();if(!t.ok)return void v.default.error(a.error||"Generation failed");f(a.url),v.default.success("Hulu sheet generated!")}catch(e){v.default.error(e.message||"Network error")}finally{m(!1)}};return(0,t.jsx)("div",{className:"fixed inset-0 z-[100] flex items-center justify-center p-4",style:{background:"var(--lightbox-scrim-soft)",backdropFilter:"blur(4px)"},onClick:e=>{e.target===e.currentTarget&&r()},children:(0,t.jsxs)("div",{className:"rounded-2xl w-full max-w-2xl max-h-[88vh] overflow-hidden flex flex-col",style:{background:"var(--surface-section)",border:"1px solid var(--border-default)",boxShadow:"0 20px 60px var(--shadow-ambient-xl), 0 4px 16px var(--shadow-ambient-md)"},children:[(0,t.jsxs)("div",{className:"px-6 py-5 flex items-center justify-between",style:{borderBottom:"1px solid var(--border-subtle)"},children:[(0,t.jsxs)("div",{children:[(0,t.jsxs)("h2",{className:"text-lg font-bold text-gray-900 dark:text-zinc-100 tracking-tight flex items-center gap-2",children:[(0,t.jsx)(x.TableCellsIcon,{className:"w-5 h-5 text-amber-500"}),"Generate Hulu Stats Sheet"]}),(0,t.jsx)("p",{className:"text-xs text-gray-400 dark:text-zinc-500 mt-0.5",children:"Populate Hulu's FY26 metrics template with this campaign's data"})]}),(0,t.jsx)("button",{onClick:r,className:"p-2 rounded-xl transition-colors hover:bg-gray-100 dark:hover:bg-zinc-900",children:(0,t.jsx)(l.XMarkIcon,{className:"w-5 h-5 text-gray-400 dark:text-zinc-500"})})]}),(0,t.jsxs)("div",{className:"flex-1 overflow-y-auto px-6 py-5 space-y-5",children:[(0,t.jsxs)("div",{children:[(0,t.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("h3",{className:"text-sm font-semibold text-gray-900 dark:text-zinc-100",children:"Publicis paid weeks to include"}),(0,t.jsx)("p",{className:"text-[11px] text-gray-400 dark:text-zinc-500 mt-0.5",children:"Each week is a sheet from Hulu's paid team. Pick which to roll up."})]}),(0,t.jsx)("button",{onClick:()=>I(e=>!e),className:"text-xs font-semibold px-3 py-1.5 rounded-full transition-colors",style:{background:z?"var(--surface-softer)":"rgba(245,158,11,0.08)",color:z?"var(--text-tertiary)":"#D97706",border:z?"1px solid var(--border-subtle)":"1px solid rgba(245,158,11,0.2)"},children:z?"Cancel":"+ Add upload"})]}),z&&(0,t.jsxs)("form",{onSubmit:ea,className:"rounded-xl p-4 mb-3 space-y-3",style:{background:"var(--surface-softer)",border:"1px solid var(--border-subtle)"},children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"block text-[11px] font-semibold text-gray-500 dark:text-zinc-400 mb-1.5 uppercase tracking-wider",children:"Google Sheet URL or ID"}),(0,t.jsx)("input",{type:"text",value:T,onChange:e=>P(e.target.value),placeholder:"https://docs.google.com/spreadsheets/d/...",className:"w-full px-3 py-2 rounded-lg text-sm text-gray-900 dark:text-zinc-100 placeholder:text-gray-400 dark:placeholder:text-zinc-600 focus:outline-none focus:ring-2 focus:ring-amber-400/30",style:{background:"var(--surface-solid)",border:"1px solid var(--border-default)"},required:!0}),(0,t.jsx)("p",{className:"text-[10px] text-gray-400 dark:text-zinc-500 mt-1",children:"The sheet must be shared with the service account."})]}),(R.length>0||D||ee)&&(0,t.jsxs)("div",{children:[(0,t.jsxs)("label",{className:"block text-[11px] font-semibold text-gray-500 dark:text-zinc-400 mb-1.5 uppercase tracking-wider",children:["Tab",D&&(0,t.jsx)("span",{className:"ml-2 text-gray-400 dark:text-zinc-500",children:"Loading..."})]}),R.length>0?(0,t.jsx)("select",{value:E,onChange:e=>O(e.target.value),className:"w-full px-3 py-2 rounded-lg text-sm text-gray-900 dark:text-zinc-100",style:{background:"var(--surface-solid)",border:"1px solid var(--border-default)"},children:R.map(e=>(0,t.jsx)("option",{value:e,children:e},e))}):(0,t.jsx)("input",{type:"text",value:E,onChange:e=>O(e.target.value),placeholder:"e.g., Paradise S2",className:"w-full px-3 py-2 rounded-lg text-sm text-gray-900 dark:text-zinc-100",style:{background:"var(--surface-solid)",border:"1px solid var(--border-default)"}}),ee?(0,t.jsxs)("p",{className:"text-[10px] text-red-500 mt-1",children:["Couldn't auto-list tabs: ",ee,". Type the tab name exactly as it appears in the workbook."]}):(0,t.jsx)("p",{className:"text-[10px] text-gray-400 dark:text-zinc-500 mt-1",children:"Pick the campaign tab inside this workbook."})]}),(0,t.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"block text-[11px] font-semibold text-gray-500 dark:text-zinc-400 mb-1.5 uppercase tracking-wider",children:"Week start (optional)"}),(0,t.jsx)("input",{type:"date",value:$,onChange:e=>L(e.target.value),className:"w-full px-3 py-2 rounded-lg text-sm text-gray-900 dark:text-zinc-100",style:{background:"var(--surface-solid)",border:"1px solid var(--border-default)"}})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("label",{className:"block text-[11px] font-semibold text-gray-500 dark:text-zinc-400 mb-1.5 uppercase tracking-wider",children:"Week end (optional)"}),(0,t.jsx)("input",{type:"date",value:G,onChange:e=>H(e.target.value),className:"w-full px-3 py-2 rounded-lg text-sm text-gray-900 dark:text-zinc-100",style:{background:"var(--surface-solid)",border:"1px solid var(--border-default)"}})]})]}),(0,t.jsx)("p",{className:"text-[10px] text-gray-400 dark:text-zinc-500",children:'Leave dates blank to auto-detect from the sheet\'s "Paid X Performance (M/D-M/D)" header.'}),(0,t.jsxs)("button",{type:"submit",disabled:X,className:"flex items-center gap-2 px-4 py-2 text-sm font-semibold text-white rounded-lg transition-all hover:shadow-lg disabled:opacity-50",style:{background:"linear-gradient(135deg, #F59E0B, #F97316)"},children:[(0,t.jsx)(M.CloudArrowUpIcon,{className:"w-4 h-4"}),X?"Uploading...":"Upload & parse"]})]}),d?(0,t.jsx)("p",{className:"text-xs text-gray-400 dark:text-zinc-500 py-4 text-center",children:"Loading..."}):0===s.length?(0,t.jsx)("div",{className:"rounded-xl p-4 text-center text-xs text-gray-500 dark:text-zinc-400",style:{background:"var(--surface-softer)",border:"1px dashed var(--border-default)"},children:"No Publicis paid uploads yet. Add one above."}):(0,t.jsx)("div",{className:"space-y-2",children:s.map(e=>
1{let a=j.has(e._id),r=_.has(e._id);return(0,t.jsxs)("div",{className:"rounded-lg overflow-hidden",style:{background:"var(--surface-solid)",border:"1px solid var(--border-subtle)"},children:[(0,t.jsxs)("div",{className:"flex items-center gap-2 px-3 py-2.5",children:[(0,t.jsx)("input",{type:"checkbox",checked:n.has(e._id),onChange:()=>{var t;return t=e._id,void o(e=>{let a=new Set(e);return a.has(t)?a.delete(t):a.add(t),a})},className:"w-4 h-4 accent-amber-500 cursor-pointer"}),(0,t.jsx)("button",{type:"button",onClick:()=>Q(e._id),className:"p-1 rounded hover:bg-gray-100 dark:hover:bg-zinc-900 text-gray-500 dark:text-zinc-400",title:a?"Collapse":"Review parsed data",children:a?(0,t.jsx)(U.ChevronDownIcon,{className:"w-3.5 h-3.5"}):(0,t.jsx)(q.ChevronRightIcon,{className:"w-3.5 h-3.5"})}),(0,t.jsxs)("div",{className:"flex-1 min-w-0 cursor-pointer",onClick:()=>Q(e._id),children:[(0,t.jsx)("div",{className:"text-sm font-semibold text-gray-900 dark:text-zinc-100",children:function(e,t){if(!e||!t)return"";let a=new Date(e),r=new Date(t);if(isNaN(a)||isNaN(r))return"";let s=e=>`${e.getMonth()+1}/${e.getDate()}/${String(e.getFullYear()).slice(2)}`;return`${s(a)} – ${s(r)}`}(e.weekStart,e.weekEnd)||"Date unknown"}),(0,t.jsx)("div",{className:"text-[11px] text-gray-500 dark:text-zinc-400 truncate",children:Object.entries(e.summary||{}).map(([e,t])=>`${e}: $${Math.round(t.spend||0).toLocaleString()}`).join("  ·  ")||"—"})]}),(0,t.jsx)("button",{type:"button",onClick:()=>er(e._id),className:"p-1.5 rounded-lg hover:bg-red-50 dark:hover:bg-red-950/30 text-gray-400 dark:text-zinc-500 hover:text-red-500",children:(0,t.jsx)(B.TrashIcon,{className:"w-3.5 h-3.5"})})]}),a&&(0,t.jsx)("div",{className:"px-3 py-3",style:{borderTop:"1px solid var(--border-subtle)",background:"var(--surface-section)"},children:r?(0,t.jsx)("p",{className:"text-xs text-gray-500 dark:text-zinc-400",children:"Loading parsed data..."}):(0,t.jsx)(K,{data:N[e._id]})})]},e._id)})})]}),y&&(0,t.jsxs)("div",{className:"rounded-xl p-4",style:{background:"var(--surface-softer)",border:"1px solid var(--border-subtle)"},children:[(0,t.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,t.jsxs)("div",{className:"text-xs font-semibold text-gray-700 dark:text-zinc-300",children:["Preview — ",y.length," cell range",1===y.length?"":"s"," would be written"]}),(0,t.jsx)("button",{type:"button",onClick:()=>k(null),className:"text-[11px] text-gray-500 dark:text-zinc-400 hover:underline",children:"Clear"})]}),(0,t.jsx)("p",{className:"text-[10px] text-gray-500 dark:text-zinc-400 mb-3",children:"Compare these ranges against the actual Hulu template to spot cell-mapping mismatches."}),(0,t.jsx)("div",{className:"max-h-[40vh] overflow-y-auto space-y-2",children:y.map((e,a)=>(0,t.jsxs)("div",{className:"rounded-md p-2 text-[11px]",style:{background:"var(--surface-solid)",border:"1px solid var(--border-subtle)"},children:[(0,t.jsx)("div",{className:"font-mono font-semibold text-gray-900 dark:text-zinc-100 mb-1",children:e.range}),(0,t.jsx)("div",{className:"overflow-x-auto",children:(0,t.jsx)("table",{className:"text-[10px] tabular-nums",children:(0,t.jsx)("tbody",{children:(e.values||[]).map((e,a)=>(0,t.jsx)("tr",{children:(e||[]).map((e,a)=>(0,t.jsx)("td",{className:"px-2 py-0.5 text-gray-700 dark:text-zinc-300 font-mono whitespace-nowrap",style:{borderRight:"1px solid var(--border-subtle)"},children:null==e||""===e?"—":String(e)},a))},a))})})})]},`${e.range}-${a}`))})]}),h&&(0,t.jsxs)("div",{className:"rounded-xl p-4",style:{background:"rgba(16,185,129,0.06)",border:"1px solid rgba(16,185,129,0.2)"},children:[(0,t.jsx)("div",{className:"text-xs font-semibold text-emerald-700 dark:text-emerald-400 mb-2",children:"✓ Hulu Stats sheet generated"}),(0,t.jsxs)("a",{href:h,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1.5 text-sm font-semibold text-emerald-700 dark:text-emerald-400 hover:underline",children:["Open in Google Sheets",(0,t.jsx)(p.ArrowTopRightOnSquareIcon,{className:"w-3.5 h-3.5"})]}),(0,t.jsx)("p",{className:"text-[11px] text-gray-500 dark:text-zinc-400 mt-2",children:"Saved to this campaign's Documents tab as a Hulu Stats record."})]})]}),(0,t.jsxs)("div",{className:"px-6 py-4 flex items-center justify-end gap-2",style:{borderTop:"1px solid var(--border-subtle)"},children:[(0,t.jsx)("button",{onClick:r,className:"px-4 py-2 text-sm font-medium text-gray-600 dark:text-zinc-400 rounded-xl transition-colors hover:bg-gray-100 dark:hover:bg-zinc-900",style:{border:"1px solid var(--border-default)"},children:"Close"}),(0,t.jsx)("button",{onClick:es,disabled:g||u,className:"flex items-center gap-1.5 px-4 py-2 text-sm font-semibold rounded-xl transition-colors disabled:opacity-50",style:{background:"var(--surface-softer)",color:"var(--text-secondary)",border:"1px solid var(--border-default)"},title:"Show the cell ranges and values without writing to a sheet",children:g?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{className:"w-3.5 h-3.5 border-2 border-gray-400/30 border-t-gray-500 rounded-full animate-spin dark:border-zinc-600/30"}),"Previewing..."]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(W.EyeIcon,{className:"w-3.5 h-3.5"}),"Preview cells"]})}),(0,t.jsx)("button",{onClick:ei,disabled:u,className:"flex items-center gap-1.5 px-5 py-2 text-sm font-semibold text-white rounded-xl transition-all hover:shadow-lg disabled:opacity-50",style:{background:"linear-gradient(135deg, #F59E0B, #F97316)",boxShadow:"0 2px 8px rgba(245,158,11,0.25)"},children:u?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{className:"w-3.5 h-3.5 border-2 border-white/30 border-t-white rounded-full animate-spin dark:border-zinc-800/30"}),"Generating..."]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(x.TableCellsIcon,{className:"w-3.5 h-3.5"}),"Generate Sheet"]})})]})]})})}var X=e.i(996874),Z=e.i(263150),Y=e.i(980618);let Q=[.25,.46,.45,.94],ee=e=>
1"number"==typeof e?e.toLocaleString():"0";function et({label:e,value:a,accent:r}){return(0,t.jsxs)("div",{className:"flex-1 min-w-[90px] rounded-xl px-3 py-2",style:{background:`${r}14`,border:`1px solid ${r}25`},children:[(0,t.jsx)("div",{className:"text-[10px] font-bold uppercase tracking-[0.12em] text-gray-400 dark:text-zinc-500",children:e}),(0,t.jsx)("div",{className:"text-lg font-black tracking-tight leading-none mt-1 tabular-nums",style:{color:r},children:a})]})}function ea({campaign:e,open:r,onClose:s,source:i="upload",sheetId:n}){let o="sheet"===i,d=(0,a.useRef)(null),[u,m]=(0,a.useState)(""),[x,p]=(0,a.useState)(""),[f,g]=(0,a.useState)(null),[v,k]=(0,a.useState)(null),[j,w]=(0,a.useState)(""),[N,S]=(0,a.useState)(null),[_,C]=(0,a.useState)([]),[z,I]=(0,a.useState)(""),T=()=>{m(""),p(""),g(null),k(null),w(""),S(null),C([]),I(""),d.current&&(d.current.value="")},P=()=>{v||(T(),s())},E=async(t,a={})=>{let{overrideCsvText:r,overrideTab:s}=a,i=void 0!==s?s:z,l=o?{sheetId:n,mode:t,...i?{tabName:i}:{}}:{csvText:r??x,mode:t},d=await fetch(`https://www.socialscout.ai/api/campaigns/${e._id}/hulu-paid-import`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(l)}),c=await d.json().catch(()=>({}));if(!d.ok)throw Error(c?.error||"Import request failed");return c},O=async e=>{let t=e.target.files?.[0];if(t){w(""),g(null),m(t.name),k("preview");try{let e=await t.text();p(e);let a=await E("preview",{overrideCsvText:e});g(a)}catch(e){w(e.message)}finally{k(null),d.current&&(d.current.value="")}}},R=async()=>{try{let t=await fetch(`https://www.socialscout.ai/api/campaigns/${e._id}/hulu-paid-import`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sheetId:n,mode:"tabs"})}),a=await t.json().catch(()=>({}));t.ok&&Array.isArray(a.tabs)&&C(a.tabs)}catch{}},A=async e=>{w(""),g(null),k("preview");try{let t=await E("preview",{overrideTab:"string"==typeof e?e:void 0});g(t)}catch(e){w(e.message)}finally{k(null)}};(0,a.useEffect)(()=>{!r||!o||f||v||j||(R(),A())},[r,o]);let D=async()=>{w(""),k("commit");try{let e=await E("commit");S({updated:e.updated}),setTimeout(()=>window.location.reload(),1200)}catch(e){w(e.message),k(null)}},F=f?.matches||[],$=f?.unmatched||[],L=f?.summary,M=o?"#f59e0b":"#6366f1",B=o?h.ArrowPathIcon:Y.FilmIcon;return(0,t.jsx)(y.AnimatePresence,{children:r&&(0,t.jsx)(b.motion.div,{className:"fixed inset-0 z-[100] flex items-center justify-center p-4 bg-black/20 backdrop-blur-sm",initial:{opacity:0}
1,animate:{opacity:1},exit:{opacity:0},transition:{duration:.25,ease:Q},onClick:P,children:(0,t.jsxs)(b.motion.div,{className:"relative w-full max-w-lg rounded-2xl overflow-hidden border border-gray-200/50 dark:border-zinc-800 flex flex-col max-h-[85dvh]",style:{background:"var(--surface-panel)",backdropFilter:"blur(40px)",boxShadow:"0 24px 64px -16px rgba(0,0,0,0.18)"},initial:{opacity:0,y:24,scale:.97},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:16,scale:.98},transition:{duration:.4,ease:Q},onClick:e=>e.stopPropagation(),children:[(0,t.jsx)("div",{className:"absolute top-0 left-0 right-0 h-[3px] z-20 bg-gradient-to-r from-pink-500/60 via-orange-400/60 to-violet-500/60"}),(0,t.jsxs)("div",{className:"flex items-center gap-3 px-5 pt-5 pb-4",children:[(0,t.jsx)("div",{className:"w-9 h-9 rounded-xl flex items-center justify-center flex-shrink-0",style:{background:`${M}14`},children:(0,t.jsx)(B,{className:"w-4 h-4",style:{color:M}})}),(0,t.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,t.jsx)("h3",{className:"text-lg font-bold text-gray-900 dark:text-zinc-100 tracking-tight leading-tight",children:o?"Sync Paid Stats":"Hulu Paid Import"}),(0,t.jsx)("p",{className:"text-[10px] font-bold uppercase tracking-[0.12em] text-gray-400 dark:text-zinc-500",children:o?"Google Sheet → client snapshots":"Publicis export → client snapshots"})]}),(0,t.jsx)("button",{onClick:P,className:"w-9 h-9 rounded-xl flex items-center justify-center flex-shrink-0 bg-[rgba(0,0,0,0.05)] dark:bg-[rgba(255,255,255,0.06)] hover:bg-[rgba(0,0,0,0.08)] dark:hover:bg-[rgba(255,255,255,0.1)] transition-colors","aria-label":"Close",children:(0,t.jsx)(l.XMarkIcon,{className:"w-4 h-4 text-gray-500 dark:text-zinc-400"})})]}),(0,t.jsx)("div",{className:"h-px bg-gradient-to-r from-transparent via-gray-200 dark:via-zinc-800 to-transparent"}),(0,t.jsxs)("div",{className:"flex-1 min-h-0 overflow-y-auto px-5 py-4",children:[o&&!N&&_.length>0&&(0,t.jsxs)("div",{className:"mb-4 flex items-center gap-2",children:[(0,t.jsx)("label",{className:"text-[11px] font-bold uppercase tracking-wider text-gray-400 dark:text-zinc-500 whitespace-nowrap",children:"Sheet tab"}),(0,t.jsxs)("select",{value:z,onChange:e=>{var t;I(t=e.target.value),A(t)},disabled:"preview"===v||"commit"===v,className:"flex-1 min-w-0 text-sm rounded-lg border border-gray-200 dark:border-zinc-800 bg-white dark:bg-zinc-900 text-gray-800 dark:text-zinc-100 px-2.5 py-1.5 focus:outline-none focus:ring-2 focus:ring-amber-400/40 disabled:opacity-50",children:[(0,t.jsx)("option",{value:"",children:"Auto-detect"}),_.map(e=>(0,t.jsx)("option",{value:e,children:e},e))]})]}),N?(0,t.jsxs)("div",{className:"py-10 text-center",children:[(0,t.jsx)("div",{className:"w-16 h-16 mx-auto rounded-2xl bg-gradient-to-br from-emerald-100 to-teal-50 dark:from-emerald-500/20 dark:to-teal-500/10 flex items-center justify-center mb-4",children:(0,t.jsx)(c.CheckCircleIcon,{className:"w-8 h-8 text-emerald-500"})}),(0,t.jsxs)("p",{className:"text-lg font-bold text-gray-800 dark:text-zinc-100",children:["Imported ",N.updated," snapshot",1===N.updated?"":"s"]}),(0,t.jsx)("p",{className:"text-sm text-gray-500 dark:text-zinc-400 mt-1",children:"Refreshing…"})]}):!f&&o?(0,t.jsxs)("div",{className:"border border-dashed border-gray-200 dark:border-zinc-800 rounded-2xl py-10 px-6 text-center bg-white/60 dark:bg-zinc-950/40",children:[(0,t.jsx)("div",{className:"w-16 h-16 mx-auto rounded-2xl bg-gradient-to-br from-amber-100 to-orange-50 dark:from-amber-500/20 dark:to-orange-500/10 flex items-center justify-center mb-4",children:(0,t.jsx)(h.ArrowPathIcon,{className:`w-8 h-8 text-amber-500 ${"preview"===v?"animate-spin":""}`})}),(0,t.jsx)("p",{className:"text-lg font-bold text-gray-800 dark:text-zinc-100",children:"preview"===v?"Fetching from Google Sheet…":"Couldn't fetch the sheet"}),(0,t.jsx)("p",{className:"text-sm text-gray-500 dark:text-zinc-400 max-w-md mx-auto mt-1 mb-5",children:"preview"===v?"Reading the raw Publicis export tab and matching rows to this campaign's posts.":"See the error below for details, fix access if needed, then try again."}),"preview"!==v&&(0,t.jsxs)("button",{onClick:A,className:"inline-flex items-center gap-1.5 px-4 py-2 rounded-full text-sm font-semibold text-white bg-gradient-to-r from-pink-500 to-orange-400 hover:scale-105 transition-transform",children:[(0,t.jsx)(h.ArrowPathIcon,{className:"w-4 h-4"}),"Retry"]})]}):f?(0,t.jsxs)("div",{children:[(0,t.jsxs)("div",{className:"flex flex-wrap gap-2 mb-4",children:[(0,t.jsx)(et,{label:"Matched",value:L?.matched??0,accent:"#10b981"}),(0,t.jsx)(et,{label:"Unmatched",value:L?.unmatched??0,accent:"#f59e0b"}),(0,t.jsx)(et,{label:"Skipped",value:(L?.skippedBlank??0)+(L?.skippedUnlinked??0),accent:"#6366f1"})]}),F.length>0&&(0,t.jsxs)("div",{className:"mb-4",children:[(0,t.jsx)("div",{className:"text-[10px] font-bold uppercase tracking-[0.12em] text-gray-400 dark:text-zinc-500 mb-2",children:"Will import"}),(0,t.jsx)("div",{className:"space-y-1.5 max-h-56 overflow-y-auto pr-1",children:F.map((e,a)=>(0,t.jsxs)("div",{className:"flex items-center gap-2.5 rounded-xl px-3 py-2",style:{background:"var(--surface-softer)",border:"1px solid var(--border-subtle)"},children:[(0,t.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,t.jsx)("div",{className:"text-[13px] font-semibold text-gray-800 dark:text-zinc-200 truncate",children:e.influencer}),(0,t.jsxs)("div",{className:"text-[11px] text-gray-400 dark:text-zinc-500",children:[e.platform," ·"," ","post_id"===e.matchedBy?"matched by post ID":`matched to ${e.creatorName||"creator"}`]})]}),(0,t.jsxs)("div",{className:"text-right flex-shrink-0 tabular-nums",children:[(0,t.jsx)("div",{className:"text-[13px] font-extrabold leading-none text-gray-900 dark:text-zinc-100",children:ee(e.videoPlays)}),(0,t.jsxs)("div",{className:"text-[10px] text-gray-400 dark:text-zinc-500 mt-0.5",children:[ee(e.impressions)," imp ·"," ",ee(e.linkCl
1icks)," clk · ",ee(e.profileVisits)," ","pv"]})]})]},`${e.matchedPostId}-${a}`))})]}),$.length>0&&(0,t.jsxs)("div",{children:[(0,t.jsx)("div",{className:"text-[10px] font-bold uppercase tracking-[0.12em] text-gray-400 dark:text-zinc-500 mb-2",children:"Not imported"}),(0,t.jsx)("div",{className:"space-y-1.5 max-h-40 overflow-y-auto pr-1",children:$.map((e,a)=>(0,t.jsxs)("div",{className:"flex items-start gap-2.5 rounded-xl px-3 py-2",style:{background:"rgba(245,158,11,0.06)",border:"1px solid rgba(245,158,11,0.15)"},children:[(0,t.jsx)(Z.ExclamationTriangleIcon,{className:"w-3.5 h-3.5 text-amber-500 flex-shrink-0 mt-0.5"}),(0,t.jsxs)("div",{className:"min-w-0",children:[(0,t.jsxs)("div",{className:"text-[13px] font-semibold text-gray-800 dark:text-zinc-200 truncate",children:[e.influencer||"(unnamed)"," ",(0,t.jsxs)("span",{className:"text-gray-400 dark:text-zinc-500 font-medium",children:["· ",e.platform]})]}),(0,t.jsx)("div",{className:"text-[11px] text-amber-600 dark:text-amber-500",children:e.reason})]})]},`${e.influencer}-${a}`))})]})]}):(0,t.jsxs)("div",{className:"border border-dashed border-gray-200 dark:border-zinc-800 rounded-2xl py-10 px-6 text-center bg-white/60 dark:bg-zinc-950/40",children:[(0,t.jsx)("div",{className:"w-16 h-16 mx-auto rounded-2xl bg-gradient-to-br from-indigo-100 to-violet-50 dark:from-indigo-500/20 dark:to-violet-500/10 flex items-center justify-center mb-4",children:(0,t.jsx)(X.ArrowUpTrayIcon,{className:"w-8 h-8 text-indigo-500"})}),(0,t.jsx)("p",{className:"text-lg font-bold text-gray-800 dark:text-zinc-100",children:"Upload the paid export"}),(0,t.jsx)("p",{className:"text-sm text-gray-500 dark:text-zinc-400 max-w-md mx-auto mt-1 mb-5",children:"Save the Publicis performance sheet as CSV. Instagram Reels and TikTok IFV rows are matched to this campaign's posts — you'll review the matches before anything is written."}),(0,t.jsxs)("button",{onClick:()=>d.current?.click(),disabled:"preview"===v,className:"inline-flex items-center gap-1.5 px-4 py-2 rounded-full text-sm font-semibold text-white bg-gradient-to-r from-pink-500 to-orange-400 hover:scale-105 transition-transform disabled:opacity-50 disabled:hover:scale-100",children:[(0,t.jsx)(X.ArrowUpTrayIcon,{className:"w-4 h-4"}),"preview"===v?"Parsing…":"Choose CSV"]}),u&&"preview"===v&&(0,t.jsx)("p",{className:"text-xs text-gray-400 dark:text-zinc-500 mt-3 truncate",children:u})]}),j&&(0,t.jsx)("div",{className:"mt-4 rounded-xl px-4 py-3",style:{background:"rgba(239,68,68,0.06)",border:"1px solid rgba(239,68,68,0.15)"},children:(0,t.jsx)("span",{className:"text-red-600 dark:text-red-400 text-sm font-semibold",children:j})})]}),!N&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{className:"h-px bg-gradient-to-r from-transparent via-gray-200 dark:via-zinc-800 to-transparent"}),(0,t.jsxs)("div",{className:"flex items-center justify-between gap-3 px-5 py-4",children:[f?(0,t.jsx)("button",{onClick:o?A:T,disabled:!!v,className:"flex items-center gap-1.5 px-3 py-2 rounded-full text-xs font-medium text-gray-500 dark:text-zinc-400 hover:bg-gray-100 dark:hover:bg-zinc-900 hover:text-gray-700 dark:hover:text-zinc-200 transition-colors disabled:opacity-50",children:o?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(h.ArrowPathIcon,{className:"w-3.5 h-3.5"}),"Refetch"]}):"Choose a different file"}):(0,t.jsx)("span",{}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("button",{onClick:P,disabled:!!v,className:"flex items-center px-3 py-2 rounded-full text-xs font-medium text-gray-500 dark:text-zinc-400 hover:bg-gray-100 dark:hover:bg-zinc-900 hover:text-gray-700 dark:hover:text-zinc-200 transition-colors disabled:opacity-50",children:"Cancel"}),f&&(0,t.jsx)("button",{onClick:D,disabled:!!v||0===F.length,className:"inline-flex items-center gap-1.5 px-4 py-2 rounded-full text-xs font-semibold text-white bg-gradient-to-r from-pink-500 to-orange-400 hover:scale-105 transition-transform disabled:opacity-50 disabled:hover:scale-100",children:"commit"===v?"Importing…":`Import ${F.length} snapshot${1===F.length?"":"s"}`})]})]})]}),(0,t.jsx)("input",{type:"file",accept:".csv,text/csv",ref:d,onChange:O,className:"hidden"})]})})})}e.s(["default",0,ea],839460);var er=e.i(163341);let es=new Set(["completed","failed","idle"]);function ei({campaignId:e}){let{job:r,loading:s,triggering:i,isStuck:n,trigger:l,retry:o}=function(e){let t,[r,s]=(0,a.useState)(null),[i,n]=(0,a.useState)(!0),[l,o]=(0,a.useState)(!1),[d,c]=(0,a.useState)(null),[u,m]=(0,a.useState)(()=>Date.now()),x=(0,a.useRef)(!1),h=(0,a.useRef)(null),p=(0,a.useRef)({currentPost:0,at:Date.now()}),f=(0,a.useRef)(null),g=(0,a.useCallback)(async()=>
1{if(e)try{let t=await fetch(`/api/campaigns/${e}/sentiment-analysis`,{cache:"no-store"});if(!t.ok)return void c(`status ${t.status}`);let a=await t.json();if(x.current)return;let r=a.job||{status:"idle"},i=p.current.currentPost,n=r?.currentPost||0;n>i&&(p.current={currentPost:n,at:Date.now()}),s(r),c(null)}catch(e){x.current||c(e?.message||"Failed to load")}finally{x.current||n(!1)}},[e]);(0,a.useEffect)(()=>(x.current=!1,g(),()=>{x.current=!0,h.current&&clearTimeout(h.current)}),[g]),(0,a.useEffect)(()=>{if((h.current&&clearTimeout(h.current),r)&&!es.has(r.status))return h.current=setTimeout(()=>{m(Date.now()),g()},2e3),()=>{h.current&&clearTimeout(h.current)}},[r,g,u]),(0,a.useEffect)(()=>{let e=r?.status;if(!e||es.has(e))return;let t=r?.startedAt?new Date(r.startedAt).getTime():Date.now();p.current.at<t&&(p.current={currentPost:r?.currentPost||0,at:t})},[r?.status,r?.startedAt,r?.currentPost]);let b=!(!(t=r?.status)||es.has(t))&&u-p.current.at>18e4;(0,a.useEffect)(()=>{let e=f.current,t=r?.status;f.current=t,e&&t&&("running"===e||"pending"===e)&&"completed"===t&&window.location.reload()},[r?.status]);let y=(0,a.useCallback)(async({force:t=!1}={})=>{if(e&&!l){o(!0),c(null);try{let a=await fetch(`/api/campaigns/${e}/sentiment-analysis`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({force:t})});if(!a.ok){let e=await a.json().catch(()=>({}));return c(e.error||`status ${a.status}`),!1}let r=Date.now();return p.current={currentPost:0,at:r},s(e=>({...e||{},status:"pending",currentPost:0,totalPosts:0,failedPosts:0,failedPostDetails:[],currentPostLink:"",error:null,errorTrace:null,startedAt:new Date(r).toISOString(),finishedAt:null})),setTimeout(g,600),!0}catch(e){return c(e?.message||"Failed to start"),!1}finally{o(!1)}}},[e,l,g]),v=(0,a.useCallback)(()=>y({force:!0}),[y]);return{job:r,loading:i,triggering:l,error:d,isStuck:b,trigger:y,retry:v,refresh:g}}(e),[d,u]=(0,a.useState)(!1),m=(0,a.useRef)(null);(0,a.useEffect)(()=>{if(d)return document.addEventListener("mousedown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t)};function e(e){m.current&&!m.current.contains(e.target)&&u(!1)}function t(e){"Escape"===e.key&&u(!1)}},[d]);let x=r?.status||"idle",p="pending"===x||"running"===x,{label:f,gradient:g,Icon:v,spin:k,title:j}=(0,a.useMemo)(()=>{if(n)return{label:"Looks stuck — click to retry",gradient:"linear-gradient(135deg, #F59E0B, #D97706)",Icon:Z.ExclamationTriangleIcon,spin:!1,title:"The job stopped reporting progress. Click to retry — this overrides the stale state and fires a fresh Lambda invocation."};if("running"===x||"pending"===x){let e=r?.totalPosts||0,t=r?.currentPost||0,a=r?.failedPosts||0,s=a>0?` \xb7 ${a} failed`:"";return{label:e>0?`${t} of ${e} analyzed`:"pending"===x?"Starting…":"Analyzing…",gradient:"linear-gradient(135deg, #6366F1, #EC4899)",Icon:h.ArrowPathIcon,spin:!0,title:a>0?`${t} of ${e} analyzed${s} — running in parallel across posts`:"Sentiment analysis running in parallel across posts"}}if("completed"===x){let e=r?.totalPosts||0,t=r?.currentPost||0,a=r?.failedPosts||0;return{label:`Analyzed ${function(e){if(!e)return"";let t=Math.floor((Date.now()-new Date(e).getTime())/6e4);if(t<1)return"just now";if(t<60)return`${t}m ago`;let a=Math.floor(t/60);if(a<24)return`${a}h ago`;let r=Math.floor(a/24);return`${r}d ago`}(r?.finishedAt||r?.lastResultAt)}`,gradient:"linear-gradient(135deg, #10B981, #059669)",Icon:c.CheckCircleIcon,spin:!1,title:a>0||e>0&&t<e?`Analyzed ${t} of ${e}${a>0?` \xb7 ${a} couldn't be processed`:""}. Click to re-run.`:"Re-run sentiment analysis"}}return"failed"===x?{label:"Analysis failed",gradient:"linear-gradient(135deg, #EF4444, #B91C1C)",Icon:Z.ExclamationTriangleIcon,spin:!1,title:r?.error?`Click to retry — ${r.error}`:"Click to retry"}:{label:"Analyze sentiment",gradient:"linear-gradient(135deg, #6366F1, #A855F7)",Icon:er.ChartBarIcon,spin:!1,title:"Run sentiment analysis on every Contracted post"}},[x,r,n]);if(s&&!r)return null;let w=r?.totalPosts||0,N=r?.currentPost||0,S=p&&!n&&w>0?Math.max(0,Math.min(1,N/w)):null,_=p&&!n&&0===w,C=i||p&&!n,z=r?.failedPosts||0,I=Array.isArray(r?.failedPostDetails)?r.failedPostDetails:[],T=z>0,P=z>I.length;return(0,t.jsxs)("div",{ref:m,className:"relative flex items-center gap-1.5",children:[(0,t.jsxs)("button",{type:"button",onClick:()=>n?o():l(),disabled:C,title:j,className:"relative flex items-center gap-1.5 px-3 py-1.5 rounded-full text-xs font-semibold text-white transition-all hover:scale-105 disabled:opacity-80 disabled:hover:scale-100 disabled:cursor-default overflow-hidden",style:{background:p&&!n?"rgba(99,102,241,0.18)":g},children:[null!==S&&(0,t.jsx)(b.motion.span,{"aria-hidden":"true",className:"absolute inset-y-0 left-0",style:{background:g,borderRadius:"inherit"},initial:!1,animate:{width:`${100*S}
1%`},transition:{duration:.45,ease:[.25,.46,.45,.94]}}),_&&(0,t.jsx)(b.motion.span,{"aria-hidden":"true",className:"absolute inset-y-0",style:{background:g,borderRadius:"inherit",width:"40%"},initial:{x:"-100%"},animate:{x:"250%"},transition:{duration:1.4,ease:"easeInOut",repeat:1/0}}),(0,t.jsx)(v,{className:`relative z-10 w-3.5 h-3.5 ${k?"animate-spin":""}`}),(0,t.jsx)("span",{className:"relative z-10",children:f})]}),T&&(0,t.jsxs)("button",{type:"button",onClick:()=>u(e=>!e),"aria-expanded":d,title:`${z} post${1===z?"":"s"} couldn't be analyzed — click for details`,className:"inline-flex items-center gap-1 px-2 py-1 rounded-full text-[11px] font-bold transition-all hover:scale-105",style:{background:"rgba(239,68,68,0.10)",color:"#B91C1C",border:"1px solid rgba(239,68,68,0.25)"},children:[(0,t.jsx)(Z.ExclamationTriangleIcon,{className:"w-3 h-3"}),z," failed"]}),(0,t.jsx)(y.AnimatePresence,{children:d&&T&&(0,t.jsx)(el,{failures:I,totalFailed:z,truncated:P,onClose:()=>u(!1)})})]})}let en={instagram:"bg-pink-50 text-pink-700 dark:bg-pink-500/15 dark:text-pink-300",tiktok:"bg-gray-100 text-gray-700 dark:bg-zinc-800 dark:text-zinc-200",youtube:"bg-red-50 text-red-700 dark:bg-red-500/15 dark:text-red-300"};function el({failures:e,totalFailed:a,truncated:r,onClose:s}){let i=[...e].sort((e,t)=>new Date(t?.failedAt||0).getTime()-new Date(e?.failedAt||0).getTime());return(0,t.jsxs)(b.motion.div,{initial:{opacity:0,y:-4,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:-4,scale:.98},transition:{duration:.18,ease:[.25,.46,.45,.94]},className:"absolute z-50 right-0 top-full mt-2 w-[360px] rounded-xl overflow-hidden",style:{background:"var(--surface-panel)",backdropFilter:"blur(20px)",border:"1px solid var(--border-default)",boxShadow:"0 18px 42px var(--shadow-ambient-xl), 0 4px 12px var(--shadow-ambient)"},children:[(0,t.jsx)("div",{className:"h-[2px] bg-gradient-to-r from-red-500/70 via-orange-400/70 to-amber-400/70"}),(0,t.jsxs)("div",{className:"px-3 py-2.5 flex items-center justify-between",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("div",{className:"text-[10px] font-bold uppercase tracking-[0.14em] text-gray-400 dark:text-zinc-500",children:"Couldn't analyze"}),(0,t.jsxs)("div",{className:"text-sm font-semibold text-gray-900 dark:text-zinc-100",children:[a," post",1===a?"":"s"," failed"]})]}),(0,t.jsx)("button",{type:"button",onClick:s,"aria-label":"Close",className:"w-7 h-7 inline-flex items-center justify-center rounded-md hover:bg-gray-100 dark:hover:bg-zinc-900",children:(0,t.jsx)(l.XMarkIcon,{className:"w-4 h-4 text-gray-400 dark:text-zinc-500"})})]}),(0,t.jsx)("div",{className:"max-h-[280px] overflow-y-auto",children:0===i.length?(0,t.jsx)("div",{className:"px-3 py-4 text-[12px] text-gray-400 dark:text-zinc-500 text-center",children:"Failure details will appear once the run reports them."}):i.map((e,a)=>{let r=String(e?.platform||"").toLowerCase(),s=en[r]||"bg-gray-100 text-gray-600 dark:bg-zinc-800 dark:text-zinc-400";return(0,t.jsxs)("div",{className:"px-3 py-2 border-t border-gray-100 dark:border-zinc-800/60",children:[(0,t.jsxs)("div",{className:"flex items-center gap-1.5 mb-1",children:[r&&(0,t.jsx)("span",{className:`text-[9px] uppercase tracking-wider font-bold px-1.5 py-0.5 rounded ${s}`,children:r}),e?.link?(0,t.jsxs)("a",{href:e.link,target:"_blank",rel:"noopener noreferrer",className:"text-[12px] font-semibold text-violet-600 dark:text-violet-400 hover:underline truncate flex-1 inline-flex items-center gap-1",title:e.link,children:[(0,t.jsx)("span",{className:"truncate",children:e.link}),(0,t.jsx)(p.ArrowTopRightOnSquareIcon,{className:"w-3 h-3 opacity-60 shrink-0"})]}):(0,t.jsx)("span",{className:"text-[12px] font-semibold text-gray-500 dark:text-zinc-400 italic",children:"(deleted post)"})]}),(0,t.jsx)("div",{className:"text-[11px] text-gray-500 dark:text-zinc-400 leading-snug",children:e?.reason||"Failure reason unavailable"})]},`${e?.postId||a}-${a}`)})}),r&&(0,t.jsxs)("div",{className:"px-3 py-2 text-[10.5px] text-gray-400 dark:text-zinc-500",style:{borderTop:"1px solid var(--border-subtle)"},children:["Showing the ",i.length," most recent · ",a-i.length," ","earlier failure",a-i.length==1?"":"s"," not shown (see CloudWatch)."]})]})}var eo=e.i(522016),ed=e.i(738692),ec=e.i(811424);let eu=(e,t)=>
1`ss.campaignBrief.bannerDismissed.${e}.${t}`;function em({campaignId:e,brief:r,onReview:s}){let[i,n]=(0,a.useState)(!0),o=r?.brief?.sourceFingerprint||null;return((0,a.useEffect)(()=>{n(function(e,t){if(!t)return!1;try{return"1"===window.localStorage.getItem(eu(e,t))}catch{return!1}}(e,o))},[e,o]),r?.hasSourceDeal&&r?.suggestions&&o&&(0,ec.hasAnyDiffering)(r.suggestions)&&function(e){if(!e?.brief?.generatedAt)return!1;if(e.stale)return!0;let t=Object.values(e.briefProvenance||{}).map(e=>e?.generatedAt?new Date(e.generatedAt).getTime():null).filter(e=>Number.isFinite(e)),a=t.length?Math.max(...t):0,r=new Date(e.brief.generatedAt).getTime();return Number.isFinite(r)&&r>a}(r)&&!i)?(0,t.jsx)("div",{className:"px-4 sm:px-8 md:px-12 mt-4",children:(0,t.jsxs)("div",{className:"flex items-center gap-3 rounded-xl px-4 py-3",style:{background:"rgba(245,158,11,0.06)",border:"1px solid rgba(245,158,11,0.18)"},children:[(0,t.jsx)("div",{className:"w-8 h-8 rounded-xl flex items-center justify-center flex-shrink-0",style:{background:"rgba(245,158,11,0.14)"},children:(0,t.jsx)(m.SparklesIcon,{className:"w-4 h-4 text-amber-600 dark:text-amber-400"})}),(0,t.jsx)("p",{className:"flex-1 min-w-0 text-[13px] font-medium text-amber-800 dark:text-amber-300",children:"New suggestions from sales for this campaign — review in Campaign Settings."}),(0,t.jsx)("button",{type:"button",onClick:s,className:"flex-shrink-0 px-3 py-1.5 rounded-full text-xs font-semibold text-amber-700 dark:text-amber-400 transition-colors hover:bg-amber-500/10",style:{border:"1px solid rgba(245,158,11,0.4)"},children:"Review"}),(0,t.jsx)("button",{type:"button",onClick:()=>{if(o)try{window.localStorage.setItem(eu(e,o),"1")}catch{}n(!0)},"aria-label":"Dismiss",className:"flex-shrink-0 w-7 h-7 rounded-full flex items-center justify-center transition-colors hover:bg-amber-500/10",children:(0,t.jsx)(l.XMarkIcon,{className:"w-3.5 h-3.5 text-amber-500 dark:text-amber-400"})})]})}):null}let ex={Live:{label:"Live",icon:d.FireIcon,color:"#10b981",bg:"rgba(16,185,129,0.08)",border:"rgba(16,185,129,0.2)",ping:!0},Wrapped:{label:"Wrapped",icon:c.CheckCircleIcon,color:"#ef4444",bg:"rgba(239,68,68,0.08)",border:"rgba(239,68,68,0.2)"},Created:{label:"Created",icon:m.SparklesIcon,color:"#f59e0b",bg:"rgba(245,158,11,0.08)",border:"rgba(245,158,11,0.2)"},"In Progress":{label:"In Progress",icon:u.ClockIcon,color:"#6366f1",bg:"rgba(99,102,241,0.08)",border:"rgba(99,102,241,0.2)"}};function eh({status:e}){let a=ex[e]||ex.Created,r=a.icon;return(0,t.jsxs)("div",{className:"inline-flex items-center gap-2 px-3 py-1.5 rounded-full text-xs font-semibold tracking-wide",style:{background:a.bg,border:`1px solid ${a.border}`,color:a.color},children:[a.ping&&(0,t.jsxs)("span",{className:"relative flex h-2 w-2",children:[(0,t.jsx)("span",{className:"absolute inline-flex h-full w-full rounded-full opacity-75 animate-ping",style:{background:a.color}}),(0,t.jsx)("span",{className:"relative inline-flex h-2 w-2 rounded-full",style:{background:a.color}})]}),!a.ping&&(0,t.jsx)(r,{className:"w-3.5 h-3.5"}),a.label]})}function ep({status:e,onStatusChange:a,onCancel:r}){return(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsxs)("select",{value:e,onChange:a,className:"appearance-none rounded-full px-4 py-1.5 pr-8 text-xs font-semibold cursor-pointer transition-all focus:outline-none focus:ring-2 focus:ring-gray-200 dark:focus:ring-zinc-800",style:{background:"var(--surface-softer)",border:"1px solid var(--border-default)",color:"var(--text-secondary)"},children:[(0,t.jsx)("option",{value:"Created",children:"Created"}),(0,t.jsx)("option",{value:"In Progress",children:"In Progress"}),(0,t.jsx)("option",{value:"Live",children:"Live"}),(0,t.jsx)("option",{value:"Wrapped",children:"Wrapped"})]}),(0,t.jsx)("button",{onClick:r,className:"p-1.5 rounded-full hover:bg-gray-100 dark:hover:bg-zinc-900 transition-colors",children:(0,t.jsx)(l.XMarkIcon,{className:"h-3.5 w-3.5 text-gray-400 dark:text-zinc-500"})})]})}function ef({followers:e,podMemberIds:r,onOpenSidebar:s}){let i=(0,a.useMemo)(()=>{let t=e||[];return r?.size?[...t].sort((e,t)=>
1!!r.has(String(t._id))-!!r.has(String(e._id))):t},[e,r]),n=i.slice(0,4),l=Math.max(0,i.length-4);return e?.length?(0,t.jsxs)("div",{className:"flex items-center gap-3 cursor-pointer group",onClick:s,children:[(0,t.jsxs)("div",{className:"flex -space-x-2.5",children:[n.map((e,a)=>(0,t.jsx)("div",{className:"rounded-full transition-transform group-hover:scale-105",style:{zIndex:10-a},children:(0,t.jsx)(f.default,{user:e,size:34})},e._id)),l>0&&(0,t.jsxs)("div",{className:"flex items-center justify-center w-9 h-9 rounded-full text-[11px] font-bold ring-2 ring-white dark:ring-zinc-950",style:{background:"var(--border-subtle)",color:"var(--text-tertiary)"},children:["+",l]})]}),(0,t.jsxs)("span",{className:"hidden sm:block text-xs text-gray-400 dark:text-zinc-500 font-medium group-hover:text-gray-600 dark:group-hover:text-zinc-400 transition-colors",children:[e.length," member",1!==e.length?"s":""]})]}):(0,t.jsxs)("button",{onClick:s,className:"flex items-center gap-2 px-4 py-2 rounded-full text-xs font-semibold transition-all hover:scale-105",style:{background:"var(--surface-softer)",border:"1px solid var(--border-subtle)",color:"var(--text-tertiary)"},children:[(0,t.jsx)(o.UserPlusIcon,{className:"w-3.5 h-3.5"}),"Add Team"]})}e.s(["STATUS_CONFIG",0,ex,"default",0,function({campaign:e,setRefetchTrigger:l,setGoalsModalOpen:o,userRole:d}){let{data:u}=(0,s.useSession)(),[m,f]=(0,a.useState)(!1),[g,b]=(0,a.useState)(!1),[y,v]=(0,a.useState)(!1),[k,j]=(0,a.useState)(!1),[w,N]=(0,a.useState)(null),S=(0,a.useMemo)(()=>new Set((0,r.podUserIds)(e?.pod,r.CAMPAIGN_POD_SPEC,e)),[e]),{can:C,loading:z}=(0,_.usePermissions)();(0,a.useEffect)(()=>{e?._id&&fetch(`/api/campaigns/${e._id}/source-deal`).then(e=>e.ok?e.json():null).then(e=>{e?.sourceDeal&&N(e.sourceDeal)}).catch(()=>{})},[e?._id]);let I=!z&&C("campaigns","edit"),{data:T}=(0,ed.default)(I?e?._id:null),P="hulu"===String(e?.organization?.name||"").toLowerCase(),E=async t=>{let a=t.target.value;try{let t=await fetch("https://www.socialscout.ai/api/updateCampaignStatus",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({campaignId:e._id,status:a})});(await t.json()).success&&(l(e=>e+1),f(!1))}catch(e){console.error("Network or server error:",e)}};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"px-4 sm:px-8 md:px-12 pt-10 pb-2",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,t.jsxs)("div",{className:"flex flex-col gap-0.5",children:[(0,t.jsx)("span",{className:"text-sm font-medium text-gray-400 dark:text-zinc-500 tracking-wide",children:e?.organization?.name}),w&&(0,t.jsxs)(eo.default,{href:`/dashboard/user/sales/deal/${w._id}`,className:"inline-flex items-center gap-1 text-[11px] text-gray-400 dark:text-zinc-500 hover:text-gray-600 dark:hover:text-zinc-300 transition-colors group w-fit",children:[(0,t.jsx)(p.ArrowTopRightOnSquareIcon,{className:"w-3 h-3 flex-shrink-0 text-gray-300 dark:text-zinc-600 group-hover:text-gray-500 dark:group-hover:text-zinc-400 transition-colors"}),(0,t.jsxs)("span",{children:["Spawned from Deal: ",(0,t.jsx)("span",{className:"font-semibold",children:w.name})]})]})]}),(0,t.jsx)(ef,{followers:e?.followers,podMemberIds:S,onOpenSidebar:()=>b(!0)})]}),(0,t.jsx)("h1",{className:"text-2xl sm:text-4xl md:text-5xl font-black tracking-tight text-gray-900 dark:text-zinc-100 mb-4 pr-14 lg:pr-0",children:e?.name}),(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-3",children:[m?(0,t.jsx)(ep,{status:e?.
1status,onStatusChange:E,onCancel:()=>f(!1)}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(eh,{status:e?.status}),!z&&C("campaigns","edit")&&(0,t.jsx)("button",{onClick:()=>f(!0),className:"p-1.5 rounded-full hover:bg-gray-100 dark:hover:bg-zinc-900 transition-colors",children:(0,t.jsx)(n.PencilIcon,{className:"w-3.5 h-3.5 text-gray-400 dark:text-zinc-500"})})]}),!z&&C("campaigns","edit")&&(0,t.jsx)("span",{className:"w-1 h-1 rounded-full bg-gray-200 dark:bg-zinc-800"}),!z&&C("campaigns","edit")&&(0,t.jsxs)("button",{onClick:()=>o(!0),className:"flex items-center gap-1.5 px-3 py-1.5 rounded-full text-xs font-medium text-gray-500 dark:text-zinc-400 transition-all hover:bg-gray-100 dark:hover:bg-zinc-900 hover:text-gray-700 dark:hover:text-zinc-300",children:[(0,t.jsx)(i.Cog6ToothIcon,{className:"w-3.5 h-3.5"}),"Settings"]}),P&&!z&&C("campaigns","edit")&&(0,t.jsxs)("div",{className:"inline-flex items-stretch rounded-full text-white transition-transform hover:scale-105",style:{background:"linear-gradient(135deg, #F59E0B, #F97316)"},children:[(0,t.jsxs)("button",{type:"button",onClick:()=>v(!0),className:"flex items-center gap-1.5 pl-3 pr-2.5 py-1.5 rounded-l-full text-xs font-semibold hover:bg-white/10 transition-colors",children:[(0,t.jsx)(x.TableCellsIcon,{className:"w-3.5 h-3.5"}),"Wrap Report"]}),(0,t.jsx)("span",{className:"w-px my-1.5 bg-white/25"}),(0,t.jsxs)("button",{type:"button",onClick:()=>j(!0),className:"flex items-center gap-1.5 pl-2.5 pr-3 py-1.5 rounded-r-full text-xs font-semibold hover:bg-white/10 transition-colors",children:[(0,t.jsx)(h.ArrowPathIcon,{className:"w-3.5 h-3.5"}),"Sync Stats"]})]}),e?._id&&!z&&C("campaigns","edit")&&(0,t.jsx)(ei,{campaignId:e._id}),e?.status==="Wrapped"&&!z&&C("campaigns","edit")&&(0,t.jsxs)(eo.default,{href:`/dashboard/user/campaign/${e._id}/wrap-deck`,className:"flex items-center gap-1.5 px-3 py-1.5 rounded-full text-xs font-semibold text-white transition-all hover:scale-105",style:{background:"linear-gradient(135deg, #f97316, #ec4899)"},children:[(0,t.jsx)(c.CheckCircleIcon,{className:"w-3.5 h-3.5"}),"Wrap Deck"]})]})]}),y&&(0,t.jsx)(J,{campaignId:e?._id,onClose:()=>v(!1)}),P&&(0,t.jsx)(ea,{campaign:e,open:k,onClose:()=>j(!1),source:"sheet",sheetId:"14m5N37AV9T7k38eBEoTT-0Q14hhvFI-i0dfJZuDFYqk"}),I&&(0,t.jsx)(em,{campaignId:e?._id,brief:T,onReview:()=>o(!0)}),(0,t.jsx)("div",{className:"mx-4 sm:mx-8 md:mx-12 mt-6",children:(0,t.jsx)("div",{className:"h-px bg-gradient-to-r from-transparent via-gray-200 to-transparent"})}),g&&(0,t.jsx)(L,{campaign:e,campaignFollowers:e?.followers,setIsSidebarOpen:b,campaignId:e?._id,setRefetchTrigger:l})]})}],760925)},883015,209428,e=>{"use strict";var t=e.i(843476),a=e.i(271645),r=e.i(846932),s=e.i(427217),i=e.i(263150),n=e.i(460759),l=e.i(491160);e.s(["default",0,function({title:e="Discard this draft?",description:o="You'll lose everything you've entered so far. This can't be undone.",summary:d,onKeepEditing:c,onDiscard:u,discardLabel:m="Discard changes"}){return(0,a.useEffect)(()=>{function e(e){"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),c?.())}return window.addEventListener("keydown",e,!0),()=>window.removeEventListener("keydown",e,!0)},[c]),(0,t.jsx)(r.motion.div,{initial:{opacity:0}
1,animate:{opacity:1},exit:{opacity:0},transition:{duration:.2},className:"fixed inset-0 z-[120] flex items-center justify-center p-4 bg-black/35 backdrop-blur-sm",onClick:c,children:(0,t.jsxs)(r.motion.div,{initial:{opacity:0,y:16,scale:.96},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:16,scale:.96},transition:{duration:.25,ease:[.25,.46,.45,.94]},className:"relative w-full max-w-md rounded-2xl overflow-hidden",style:{background:"var(--surface-panel)",backdropFilter:"blur(20px)",boxShadow:"0 20px 60px var(--shadow-ambient-xl)",border:"1px solid var(--border-default)"},onClick:e=>e.stopPropagation(),role:"alertdialog","aria-modal":"true","aria-labelledby":"discard-changes-title",children:[(0,t.jsx)("div",{className:"h-[3px] w-full bg-gradient-to-r from-amber-400 via-orange-500 to-rose-500"}),(0,t.jsx)("div",{className:"absolute -top-12 -right-12 w-44 h-44 rounded-full opacity-15 blur-3xl pointer-events-none",style:{background:"linear-gradient(135deg, #F59E0B, #F97316)"}}),(0,t.jsxs)("div",{className:"relative p-5",children:[(0,t.jsxs)("div",{className:"flex items-start justify-between mb-4",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2.5",children:[(0,t.jsx)("div",{className:"w-9 h-9 rounded-xl flex items-center justify-center",style:{background:"linear-gradient(135deg, rgba(245,158,11,0.15), rgba(249,115,22,0.15))",border:"1px solid rgba(245,158,11,0.25)"},children:(0,t.jsx)(i.ExclamationTriangleIcon,{className:"w-4 h-4 text-amber-500"})}),(0,t.jsxs)("div",{children:[(0,t.jsx)("div",{className:"text-[10px] font-bold uppercase tracking-[0.14em] text-amber-600 dark:text-amber-400",children:"Unsaved changes"}),(0,t.jsx)("h3",{id:"discard-changes-title",className:"text-base font-black text-gray-900 dark:text-zinc-100 tracking-tight",children:e})]})]}),(0,t.jsx)("button",{type:"button",onClick:c,"aria-label":"Keep editing",className:"w-7 h-7 flex items-center justify-center rounded-lg hover:bg-gray-100 dark:hover:bg-zinc-900",children:(0,t.jsx)(s.XMarkIcon,{className:"w-4 h-4 text-gray-400 dark:text-zinc-500"})})]}),d&&(0,t.jsxs)("div",{className:"rounded-xl p-3 mb-4",style:{background:"var(--surface-soft)",border:"1px solid var(--border-subtle)"},children:[(0,t.jsx)("div",{className:"text-[10px] font-bold uppercase tracking-[0.14em] mb-1",style:{color:"var(--text-tertiary)"},children:"Draft"}),(0,t.jsx)("div",{className:"text-sm font-semibold text-gray-800 dark:text-zinc-100 truncate",children:d.title||"Untitled"}),d.meta&&(0,t.jsx)("div",{className:"text-[11px] text-gray-500 dark:text-zinc-400 mt-1 line-clamp-2",children:d.meta})]}),(0,t.jsx)("p",{className:"text-[12px] text-gray-500 dark:text-zinc-400 leading-relaxed mb-5",children:o}),(0,t.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[(0,t.jsxs)("button",{type:"button",onClick:c,className:"text-xs font-bold px-3 py-2 rounded-xl flex items-center gap-1.5 transition-all duration-200 hover:shadow-md",style:{background:"linear-gradient(135deg, rgba(245,158,11,0.1), rgba(245,158,11,0.06))",color:"#D97706",border:"1px solid rgba(245,158,11,0.25)"},autoFocus:!0,children:[(0,t.jsx)(l.PencilSquareIcon,{className:"w-3 h-3"}),"Keep editing"]}),(0,t.jsxs)("button",{type:"button",onClick:u,className:"text-xs font-bold px-4 py-2 text-white rounded-xl flex items-center gap-1.5 transition-all duration-200 hover:shadow-md hover:-translate-y-0.5",style:{background:"linear-gradient(135deg, #EF4444, #DC2626)",boxShadow:"0 4px 12px rgba(239,68,68,0.25)"},children:[(0,t.jsx)(n.TrashIcon,{className:"w-3 h-3"}),m]})]})]})]})})}],883015);var o=e.i(211577);function d(e,t){var a=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),a.push.apply(a,r)}return a}e.s(["default",0,function(e){for(var t=1;t<arguments.length;t++){var a=null!=arguments[t]?arguments[t]:{};t%2?d(Object(a),!0).forEach(function(t){(0,o.default)(e,t,a[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(a)):d(Object(a)).forEac
1h(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(a,t))})}return e}],209428)},792992,e=>{"use strict";var t=e.i(843476),a=e.i(271645),r=e.i(211450);let s=["#6366F1","#F59E0B","#10B981","#3B82F6","#EC4899","#8B5CF6","#06B6D4","#F97316","#14B8A6","#EF4444","#84CC16","#A855F7","#0EA5E9","#F43F5E","#22D3EE","#E879F9","#FB923C","#34D399","#818CF8","#FBBF24"];function i(e){return e>=1e9?`${(e/1e9).toFixed(1)}B`:e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}K`:e.toLocaleString()}e.s(["default",0,function({campaign:e,metricMode:n="combined",paidSource:l="blended"}){let[o,d]=(0,a.useState)(!1),c=(0,a.useRef)(null);if((0,a.useEffect)(()=>{let e=c.current;if(!e)return;let t=new IntersectionObserver(([e])=>{e.isIntersecting&&!o&&setTimeout(()=>d(!0),100)},{threshold:.15});return t.observe(e),()=>t.disconnect()},[o]),!e?.posts?.length)return null;let u={};e.posts.forEach((e,t)=>{let a=e.creator?.name||`Post ${t+1}`,{views:s}=(0,r.calcPostMetrics)(e,n,l);u[a]=(u[a]||0)+s});let m=Object.entries(u).map(([e,t])=>({name:e,views:t})).filter(e=>e.views>0).sort((e,t)=>t.views-e.views);if(0===m.length)return null;let x=m[0].views,h=m.reduce((e,t)=>e+t.views,0);return(0,t.jsx)("div",{ref:c,className:"w-full h-full",children:(0,t.jsxs)("div",{className:"rounded-2xl overflow-hidden h-full flex flex-col",style:{background:"var(--surface-soft)",border:"1px solid var(--border-subtle)"},children:[(0,t.jsx)("div",{className:"p-5 pb-0 flex-shrink-0",children:(0,t.jsxs)("div",{className:"flex items-baseline justify-between",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("h3",{className:"text-sm font-semibold text-gray-900 dark:text-zinc-100",children:"paid"===n?"Paid Views by Creator":"organic"===n?"Organic Views by Creator":"Views by Creator"}),(0,t.jsx)("p",{className:"text-[10px] text-gray-400 dark:text-zinc-500 mt-0.5",children:"Distribution across all creators"})]}),(0,t.jsxs)("div",{className:"text-right",children:[(0,t.jsx)("div",{className:"text-lg font-black text-gray-900 dark:text-zinc-100",children:i(h)}),(0,t.jsx)("div",{className:"text-[10px] text-gray-400 dark:text-zinc-500 font-medium",children:"Total Views"})]})]})}),(0,t.jsx)("div",{className:"flex-1 overflow-y-auto p-4 pt-3 space-y-2.5",children:m.map((e,a)=>{let r=s[a%s.length],n=x>0?e.views/x*100:0,l=h>0?(e.views/h*100).toFixed(1):"0";return(0,t.jsxs)("div",{className:"group",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,t.jsx)("div",{className:"w-2 h-2 rounded-full flex-shrink-0",style:{background:r}}),(0,t.jsx)("span",{className:"text-xs font-medium text-gray-700 dark:text-zinc-300 truncate",children:e.name})]}),(0,t.jsxs)("div",{className:"flex items-center gap-2 flex-shrink-0 ml-2",children:[(0,t.jsx)("span",{className:"text-xs font-bold text-gray-900 dark:text-zinc-100",children:i(e.views)}),(0,t.jsxs)("span",{className:"text-[10px] text-gray-400 dark:text-zinc-500 w-10 text-right",children:[l,"%"]})]})]}),(0,t.jsx)("div",{className:"w-full h-1.5 rounded-full",style:{background:"var(--surface-softer)"},children:(0,t.jsx)("div",{className:"h-full rounded-full",style:{width:o?`${Math.max(n,2)}%`:"2%",background:r,transition:`width 0.8s cubic-bezier(0.16, 1, 0.3, 1) ${40*a}ms`}})})]},e.name)})})]})})}])},915027,e=>{"use strict";e.i(247167);var t=e.i(843476),a=e.i(271645),r=e.i(968518),s=e.i(59935),i=e.i(286068);e.i(411485),e.s(["default",0,function({campaign:e,setRefetchTrigger:n}){let[l,o]=(0,a.useState)([]),[d,c]=(0,a.useState)(""),[u,m]=(0,a.useState)([]),{getRootProps:x,getInputProps:h}=(0,r.useDropzone)({onDrop:e=>{let t=e[0];c(t.name),s.default.parse(t,{header:!0,complete:async e=>{let t=e.data;console.log("Parsed CSV data:",t),m(await p(t))}})}}),p=async t=>{let a=t.map(e=>e["Creator Social Scout ID"]),r=await fetch("https://www.socialscout.ai/api/fetch-creators",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({ids:a})}),s=await r.json();console.log("Fetched creators:",s);let i=t.map(t=>{let a=s.find(e=>e._id===t["Creator Social Scout ID"]),r=t["Post Platform"].toLowerCase();return"TikTok"===r?r="tiktok":"Instagram"===r?r="instagram":"YouTube"===r?r="youtube":"Facebook"===r?r="facebook":"Snapchat"===r?r="snapchat":"X"===r?r="x":"Twitch"===r?r="twitch":"Pinterest"===r?r="pinterest":"twitter"===r||"Twitter"===r?r="x":"Instagram Stories"===r?r="instagram_stories":"instagram stories"===r&&(r="instagram_stories"),{creator:a?a._id:null,campaign:e?._id??null,organization:e?.organization??null,createdBy:t["Client Social Scout ID"],platform:r,format:t["Post Format"],followers_when_posted:t["Creator Followers"],editorial_type:t["Editorial Type"],link:t.Link,pulse:t["Post Pulse"],postType:t["Post Type"],comments:t["Post Total Comments"],paid_comments:t["Post Paid Comments"]??0,views:t["Post Total Views"]??0,paid_views:t["Post Paid Views"]??0,likes:t["Post Total Likes"]??0,paid_likes:t["Post Paid Likes"]??0,shares:t["Post Total Shares"]??0,paid_shares:t["Post Paid Shares"]??0,saves:t["Post Total Saves"]??0,profile_visits:t["Post Paid Profile Visits"]??0,clicks:t["Post Total Clicks"]??0,status:t["Post Status"],format:t["Format Type"],createdAt:t["Post Go-Live Date"],creatorDetails:a?{image:a.image,name:a.name,category:a.category}:{}}});return console.log("Fetched posts with creator data:",i),i},f=async()=>{try{(await fetch("https://www.socialscout.ai/api/upload-posts",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({posts:u,campaign:e?._id??null})})).ok?(alert("Posts created successfully!"),setTimeout(()=>{n(e=>e+1)},2e3)):alert("Failed to create posts.")}catch(e){console.error("Error submitting posts:",e),alert("An error occurred while creating posts.")}};return(0,t.jsxs)("div",{className:"flex flex-col items-center p-6",children:[(0,t.jsxs)("div",{...x({className:"dropzone"}),className:"w-full max-w-lg p-6 border-2 border-dashed border-gray-400 rounded-lg text-center cursor-pointer mb-4 dark:border-zinc-600",children:[(0,t.jsx)("input",{...h()}),d?(0,t.jsx)("p",{children:d}):(0,t.jsx)("p",{children:"Drag 'n' drop a CSV file here, or click to select one"})]}),(0,t.jsx)("button",{onClick:f,className:"px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600 mb-4",children:"Submit"}),(0,t.jsx)("div",{className:"w-full  grid grid-cols-1 gap-4",children:u.map((e,a)=>(0,t.jsx)(i.default,{post:e},a))})]})}])},286068,e=>{"use strict";var t=e.i(843476),a=e.i(271645),r=e.i(657688),s=e.i(522016),i=e.i(858690),n=e.i(573948),l=e.i(482514),o=e.i(303859),d=e.i(459251);let c=a.forwardRef(function({title:e,titleId:t,...r},s){return a.createElement("svg",Object.assign({xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",strokeWidth:1.5,stroke:"currentColor","aria-hidden":"true","data-slot":"icon",ref:s,"aria-labelledby":t},r),e?a.createElement("title",{id:t},e):null,a.createElement("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"m9 14.25 6-6m4.5-3.493V21.75l-3.75-1.5-3.75 1.5-3.7
15-1.5-3.75 1.5V4.757c0-1.108.806-2.057 1.907-2.185a48.507 48.507 0 0 1 11.186 0c1.1.128 1.907 1.077 1.907 2.185ZM9.75 9h.008v.008H9.75V9Zm.375 0a.375.375 0 1 1-.75 0 .375.375 0 0 1 .75 0Zm4.125 4.5h.008v.008h-.008V13.5Zm.375 0a.375.375 0 1 1-.75 0 .375.375 0 0 1 .75 0Z"}))});var u=e.i(713691),m=e.i(467415),x=e.i(372287);e.s(["default",0,function({post:e}){e.platform.toLowerCase();let a=e.creatorDetails;return(0,t.jsx)("div",{className:"cursor-pointer block transition",children:(0,t.jsx)("div",{className:"relative",children:(0,t.jsx)("div",{className:"flex flex-col md:flex-row items-center justify-between mt-5 md:mt-3 mx-4 rounded-lg transition shadow-xl relative bg-white dark:bg-zinc-950 hover:border-2 hover:border-pink-500",children:(0,t.jsxs)("div",{className:"flex flex-col md:flex-row items-center",children:[(0,t.jsxs)("div",{className:"flex flex-col md:flex-row items-center",children:[a?.image?(0,t.jsx)("div",{className:"flex flex-col items-center justify-center",children:(0,t.jsx)("img",{src:a.image,alt:"Creator Thumbnail",className:"w-72 h-72 md:w-36 md:h-36 rounded-md mr-2 object-cover"})}):(0,t.jsx)(r.default,{src:"/images/default_image.jpg",alt:"image",width:100,height:100,sizes:"(min-width: 100px)",className:"w-10 h-10 shadow-sm"}),(0,t.jsxs)("div",{className:" w-52 space-y-2 text-center mx-2",children:[(0,t.jsx)("div",{className:"text-xl text-center mx-2 md:text-center font-bold mt-4 md:mt-0 text-gray-900 dark:text-zinc-100",children:a?.name}),(0,t.jsx)("div",{className:"text-lg text-gray-700 dark:text-zinc-300",children:"Total Subs"}),(0,t.jsx)("div",{className:"text-3xl font-bold text-gray-900 dark:text-zinc-100",children:(0,m.formatNumberReturn)(e.followers_when_posted)})]})]}),e.link&&(0,t.jsx)("div",{className:"absolute translate-y-64 translate-x-32 md:translate-y-14 md:translate-x-24",children:(0,t.jsx)(s.default,{href:e.link,children:(0,t.jsx)("img",{src:x.default[e.platform].icon,alt:`${e.platform} logo`,className:`${x.default[e.platform].bg} p-1 w-14 h-14 rounded-full object-cover hover:scale-110 shadow-md transition`})})}),(0,t.jsx)("div",{children:(0,t.jsxs)("div",{className:"grid grid-cols-3 mt-6 gap-12 mb-6 md:mt-0 md:mb-0 md:flex md:items-center md:justify-center md:ml-14 md:space-x-10",children:[e.views>0&&(0,t.jsxs)("div",{className:"flex flex-col items-center",children:[(0,t.jsx)(o.PlayCircleIcon,{className:"w-8 h-8"}),(0,t.jsx)("div",{className:"font-bold text-gray-900 dark:text-zinc-100",children:"Views"}),(0,t.jsx)("div",{className:"text-xl text-gray-900 dark:text-zinc-100",children:(0,m.formatNumberReturn)(e.views)}),(0,t.jsx)("div",{className:"text-xl text-gray-900 dark:text-zinc-100",children:(0,m.formatNumberReturn)(e.paid_views)})]}),e.likes>0&&(0,t.jsxs)("div",{className:"flex flex-col items-center",children:[(0,t.jsx)(l.HeartIcon,{className:"w-8 h-8"}),(0,t.jsx)("div",{className:"font-bold text-gray-900 dark:text-zinc-100",children:"Likes"}),(0,t.jsx)("div",{className:"text-xl text-gray-900 dark:text-zinc-100",children:(0,m.formatNumberReturn)(e.likes)}),(0,t.jsx)("div",{className:"text-xl text-gray-900 dark:text-zinc-100",children:(0,m.formatNumberReturn)(e.paid_likes)})]}),e.comments>0&&(0,t.jsxs)("div",{className:"flex flex-col items-center",children:[(0,t.jsx)(n.ChatBubbleOvalLeftIcon,{className:"w-8 h-8"}),(0,t.jsx)("div",{className:"font-bold text-gray-900 dark:text-zinc-100",children:"Comments"}),(0,t.jsx)("div",{className:"text-xl text-gray-900 dark:text-zinc-100",children:(0,m.formatNumberReturn)(e.comments)}),(0,t.jsx)("div",{className:"text-xl text-gray-900 dark:text-zinc-100",children:(0,m.formatNumberReturn)(e.paid_comments)})]}),e.shares>0&&(0,t.jsxs)("div",{className:"flex flex-col items-center",children:[(0,t.jsx)(d.ShareIcon,{className:"w-8 h-8"}),(0,t.jsx)("div",{className:"font-bold text-gray-900 dark:text-zinc-100",children:"Shares"}),(0,t.jsx)("div",{className:"text-xl text-gray-900 dark:text-zinc-100",children:(0,m.formatNumberReturn)(e.shares)}),(0,t.jsx)("div",{className:"text-xl text-gray-900 dark:text-zinc-100",children:(0,m.formatNumberReturn)(e.paid_shares)})]}),e.saves>0&&(0,t.jsxs)("div",{className:"flex flex-col items-center",children:[(0,t.jsx)(i.BookmarkIcon,{className:"w-8 h-8"}),(0,t.jsx)("div",{className:"font-bold text-gray-900 dark:text-zinc-100",children:"Saves"}),(0,t.jsx)("div",{className:"text-2xl text-gray-900 dark:text-zinc-100",children:(0,m.formatNumberReturn)(e.saves)})]}),e.profile_visits>0&&(0,t.jsxs)("div",{className:"flex flex-col items-center",children:[(0,t.jsx)(c,{className:"w-8 h-8"}),(0,t.jsx)("div",{className:"font-bold text-gray-900 dark:text-zinc-100",children:"Profile Visits"}),(0,t.jsx)("div",{className:"text-2xl text-gray-900 dark:text-zinc-100",children:`${(0,m.formatNumberReturn)(e.profile_visits)}`})]}),e.clicks>0&&(0,t.jsxs)("div",{className:"flex flex-col items-center",children:[(0,t.jsx)(u.CursorArrowRaysIcon,{className:"w-8 h-8"}),(0,t.jsx)("div",{className:"font-bold text-gray-900 dark:text-zinc-100",children:"Clicks"}),(0,t.jsx)("div",{className:"text-2xl text-gray-900 dark:text-zinc-100",children:`${(0,m.formatNumberReturn)(e.clicks)}`})]})]})})]})})})})}],286068)},411485,396039,e=>{"use strict";var t=e.i(239351);let{ObjectId:a}=t.default.Schema.Types;function r(){return new t.default.Schema({portalId:{type:String,default:null},lastSyncedAt:{type:Date,default:null},sourceModifiedAt:{type:Date,default:null},mapChecksum:{type:String,default:null},mode:{type:String,enum:["mirror","detached"],default:"mirror"},detachedFields:{type:[String],default:[]},detachedAt:{type:Date,default:null},detachedBy:{type:a,ref:"User",default:null},remoteState:{type:String,enum:["active","archived","deleted"],default:"active"}}
1,{_id:!1})}e.s(["createHubspotSyncSchema",0,r],396039);let s=new t.default.Schema({year:{type:Number,required:!0},quarter:{type:Number,required:!0,min:1,max:4},goalAmount:{type:Number,default:null},currency:{type:String,default:"USD"},note:{type:String,default:""}},{_id:!0}),i=new t.default.Schema({name:{type:String,required:!0},description:{type:String,required:!0},formula:{type:String,required:!0},format:{type:String,enum:["number","percentage","currency","decimal"],default:"number"},order:{type:Number,required:!0},enabled:{type:Boolean,default:!0}}),n=new t.default.Schema({name:{type:String,required:!0,trim:!0},description:{type:String,default:"",trim:!0},formula:{type:String,required:!0,trim:!0},type:{type:String,required:!0,enum:["er","ctr"]},enabled:{type:Boolean,default:!0},order:{type:Number,required:!0}},{_id:!0,timestamps:!1}),l=new t.default.Schema({name:{type:String,required:!0},accountManager:{type:t.default.Schema.Types.ObjectId,ref:"User"},organizationType:{type:String,required:!0},vertical:{type:String,required:!0},description:{type:String,default:"",maxlength:1e3},image:String,createdBy:{type:t.default.Schema.Types.ObjectId,ref:"User"},campaigns:{type:[t.default.Schema.Types.ObjectId],ref:"Campaign"},contacts:{type:[t.default.Schema.Types.ObjectId],default:[],ref:"Contact"},primaryContact:{type:t.default.Schema.Types.ObjectId,ref:"Contact",default:null},clientContacts:{type:[t.default.Schema.Types.ObjectId],default:[],ref:"User"},isParentCompany:{type:Boolean,default:!1},parentCompany:{type:t.default.Schema.Types.ObjectId,ref:"Organization",default:null},childCompanies:{type:[t.default.Schema.Types.ObjectId],ref:"Organization",default:[]},agency:{type:t.default.Schema.Types.ObjectId,ref:"Agency",required:!1,index:!0},claim:{claimedBy:{type:t.default.Schema.Types.ObjectId,ref:"User",default:null},claimedAt:{type:Date,default:null},domain:{type:String,default:null,index:!0}},mergedInto:{type:t.default.Schema.Types.ObjectId,ref:"Organization",default:null,index:!0},mergedAt:{type:Date,default:null},mergedBy:{type:t.default.Schema.Types.ObjectId,ref:"User",default:null},migrationSourceOrgId:{type:t.default.Schema.Types.ObjectId,ref:"Organization",default:null,index:!0},migratedToCloneIds:{type:[t.default.Schema.Types.ObjectId],default:void 0},hubspotId:{type:String,default:void 0,unique:!0,sparse:!0},hubspotSync:{type:r(),default:null},hubspotCompanyIds:{type:[String],default:void 0},clientStatus:{type:String,default:null},accountTier:{type:String,enum:["target","key_account"],default:void 0},quarterlyGoals:{type:[s],default:[]},estimatedDigitalAdSpend:{type:Number,default:null},firstDealClosedWon:{type:Date,default:null},lastDealClosedWon:{type:Date,default:null},whyTheyWouldBuy:{type:String,default:""},whyTheyWouldntBuy:{type:String,default:""},calculations:{type:[i],default:function(){return[{name:"Creators",description:"Creators",formula:"totalCreators",format:"number",order:1,enabled:!0},{name:"Posts",description:"Posts",formula:"totalPosts",format:"number",order:2,enabled:!0},{name:"Views",description:"Views",formula:"totalViews",format:"number",order:3,enabled:!0},{name:"Subscriber Reach",description:"Subscriber Reach",formula:"totalFollowers",format:"number",order:4,enabled:!0},{name:"Engagements",description:"Engagements",formula:"totalEngagements",format:"number",order:5,enabled:!0},{name:"ER%",description:"ER%",formula:"(totalEngagements / totalViews) * 100",format:"percentage",order:6,enabled:!0},{name:"Clicks",description:"Clicks",formula:"totalClicks",format:"number",order:7,enabled:!0},{name:"CTR%",description:"CTR%",formula:"(totalClicks / totalPaidViews) * 100",format:"percentage",order:8,enabled:!0}]}},scoutAnalysis:{content:{type:t.default.Schema.Types.Mixed,default:null},generatedAt:{type:Date,default:null}},aiContext:{type:String,default:""},aiContextByAgency:{type:Map,of:String,default:{}},postCalculations:{type:[n],default:[],validate:{validator:function(e){let t=e.filter(e=>"er"===e.type).length,a=e.filter(e=>"ctr"===e.type).length;return t<=1&&a<=1},message:"Only one ER calculation and one CTR calculation are allowed"}}},{timestamps:!0});l.index({parentCompany:1}),l.index({isParentCompany:1}),l.index({contacts:1}),l.index({agency:1,name:1}),l.index({agency:1,"claim.claimedBy":1}),l.index({"claim.domain":1}),l.index({"claim.claimedBy":1}),l.index({"hubspotSync.mode":1},{sparse:!0}),l.index({agency:1,accountTier:1}
1),l.index({agency:1,clientStatus:1}),l.index({hubspotCompanyIds:1},{sparse:!0});let o=["hubspotId","hubspotSync","hubspotCompanyIds","clientStatus","accountTier","quarterlyGoals","estimatedDigitalAdSpend","firstDealClosedWon","lastDealClosedWon","whyTheyWouldBuy","whyTheyWouldntBuy"];!function(){let e=t.default.models?.Organization;if(e){if(!o.some(t=>!e.schema.paths[t]&&!e.schema.singleNestedPaths?.[t]))return;delete t.default.connection?.models?.Organization,delete t.default.models.Organization}t.default.model("Organization",l)}(),e.s([],411485)},931067,e=>{"use strict";function t(){return(t=Object.assign.bind()).apply(null,arguments)}e.s(["default",()=>t])},703923,915874,e=>{"use strict";function t(e,t){if(null==e)return{};var a={};for(var r in e)if(({}).hasOwnProperty.call(e,r)){if(-1!==t.indexOf(r))continue;a[r]=e[r]}return a}e.s(["default",0,t],915874),e.s(["default",0,function(e,a){if(null==e)return{};var r,s,i=t(e,a);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);for(s=0;s<n.length;s++)r=n[s],-1===a.indexOf(r)&&({}).propertyIsEnumerable.call(e,r)&&(i[r]=e[r])}return i}],703923)},8211,e=>{"use strict";var t=e.i(949616),a=e.i(713882);e.s(["default",0,function(e){return function(e){if(Array.isArray(e))return(0,t.default)(e)}(e)||function(e){if("u">typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}(e)||(0,a.default)(e)||function(){throw TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}],8211)},59935,(e,t,a)=>{var r;let s;e.e,r=function e(){var t="u">typeof self?self:"u">typeof window?window:void 0!==t?t:{},a=!t.document&&!!t.postMessage,r=t.IS_PAPA_WORKER||!1,s={},i=0,n={};function l(e){return 65279===e.charCodeAt(0)?e.slice(1):e}function o(e){this._handle=null,this._finished=!1,this._completed=!1,this._halted=!1,this._input=null,this._baseIndex=0,this._partialLine="",this._rowCount=0,this._start=0,this._nextChunk=null,this.isFirstChunk=!0,this._completeResults={data:[],errors:[],meta:{}},(function(e){var t=y(e);t.chunkSize=parseInt(t.chunkSize),e.step||e.chunk||(t.chunkSize=null),this._handle=new x(t),(this._handle.streamer=this)._config=t}).call(this,e),this.parseChunk=function(e,a){var s=parseInt(this._config.skipFirstNLines)||0;if(this.isFirstChunk&&0<s){let t=this._config.newline;t||(i=this._config.quoteChar||'"',t=this._handle.guessLineEndings(e,i)),e=[...e.split(t).slice(s)].join(t)}this.isFirstChunk&&k(this._config.beforeFirstChunk)&&void 0!==(i=this._config.beforeFirstChunk(e))&&(e=i),this.isFirstChunk=!1,this._halted=!1;var s=this._partialLine+e,i=(this._partialLine="",this._handle.parse(s,this._baseIndex,!this._finished));if(!this._handle.paused()&&!this._handle.aborted()){if(e=i.meta.cursor,this._finished||(this._partialLine=s.substring(e
vendor: 5,581 bytes, line 1
1-this._baseIndex),this._baseIndex=e),i&&i.data&&(this._rowCount+=i.data.length),s=this._finished||this._config.preview&&this._rowCount>=this._config.preview,r)t.postMessage({results:i,workerId:n.WORKER_ID,finished:s});else if(k(this._config.chunk)&&!a){if(this._config.chunk(i,this._handle),this._handle.paused()||this._handle.aborted())return void(this._halted=!0);this._completeResults=i=void 0}return this._config.step||this._config.chunk||(this._completeResults.data=this._completeResults.data.concat(i.data),this._completeResults.errors=this._completeResults.errors.concat(i.errors),this._completeResults.meta=i.meta),this._completed||!s||!k(this._config.complete)||i&&i.meta.aborted||(this._config.complete(this._completeResults,this._input),this._completed=!0),s||i&&i.meta.paused||this._nextChunk(),i}this._halted=!0},this._sendError=function(e){k(this._config.error)?this._config.error(e):r&&this._config.error&&t.postMessage({workerId:n.WORKER_ID,error:e,finished:!1})}}function d(e){var t;(e=e||{}).chunkSize||(e.chunkSize=n.RemoteChunkSize),o.call(this,e),this._nextChunk=a?function(){this._readChunk(),this._chunkLoaded()}:function(){this._readChunk()},this.stream=function(e){this._input=e,this._nextChunk()},this._readChunk=function(){if(this._finished)this._chunkLoaded();else{if(t=new XMLHttpRequest,this._config.withCredentials&&(t.withCredentials=this._config.withCredentials),a||(t.onload=v(this._chunkLoaded,this),t.onerror=v(this._chunkError,this)),t.ontimeout=v(this._chunkTimeout,this),t.open(this._config.downloadRequestBody?"POST":"GET",this._input,!a),this._config.downloadTimeout&&!a&&(t.timeout=this._config.downloadTimeout),this._config.downloadRequestHeaders){var e,r,s=this._config.downloadRequestHeaders;for(r in s)t.setRequestHeader(r,s[r])}this._config.chunkSize&&(e=this._start+this._config.chunkSize-1,t.setRequestHeader("Range","bytes="+this._start+"-"+e));try{t.send(this._config.downloadRequestBody)}catch(e){this._chunkError(e.message)}a&&0===t.status&&this._chunkError()}},this._chunkLoaded=function(){let e;4===t.readyState&&(t.status<200||400<=t.status?this._chunkError():(this._start+=this._config.chunkSize||t.responseText.length,this._finished=!this._config.chunkSize||this._start>=(null!==(e=(e=t).getResponseHeader("Content-Range"))?parseInt(e.substring(e.lastIndexOf("/")+1)):-1),this.parseChunk(t.responseText)))},this._chunkError=function(e){e=t.statusText||e,this._sendError(Error(e))},this._chunkTimeout=function(){this._chunkError("Request timed out after "+this._config.downloadTimeout+"ms")}}function c(e){(e=e||{}).chunkSize||(e.chunkSize=n.LocalChunkSize),o.call(this,e);var t,a,r="u">typeof FileReader;this.stream=function(e){this._input=e,a=e.slice||e.webkitSlice||e.mozSlice,r?((t=new FileReader).onload=v(this._chunkLoaded,this),t.onerror=v(this._chunkError,this)):t=new FileReaderSync,this._nextChunk()},this._nextChunk=function(){this._finished||this._config.preview&&!(this._rowCount<this._config.preview)||this._readChunk()},this._readChunk=function(){var e=this._input,s=(this._config.chunkSize&&(s=Math.min(this._start+this._config.chunkSize,this._input.size),e=a.call(e,this._start,s)),t.readAsText(e,this._config.encoding));r||this._chunkLoaded({target:{result:s}})},this._chunkLoaded=function(e){this._start+=this._config.chunkSize,this._finished=!this._config.chunkSize||this._start>=this._input.size,this.parseChunk(e.target.result)},this._chunkError=function(){this._sendError(t.error)}}function u(e){var t;o.call(this,e=e||{}),this.stream=function(e){return t=e,this._nextChunk()},this._nextChunk=function(){var e,a;if(!this._finished)return t=(e=this._config.chunkSize)?(a=t.substring(0,e),t.substring(e)):(a=t,""),this._finished=!t,this.parseChunk(a)}}function m(e){o.call(this,e=e||{});var t=[],a=!0,r=!1;this.pause=function(){o.prototype.pause.apply(this,arguments),this._input.pause()},this.resume=function(){o.prototype.resume.apply(this,arguments),this._input.resume()},this.stream=function(e){this._input=e,this._input.on("data",this._streamData),this._input.on("end",this._streamEnd),this._input.on("error",this._streamError)},this._checkIsFinished=function(){r&&1===t.length&&(this._finished=!0)},this._nextChunk=function(){this._checkIsFinished(),t.length?this.parseChunk(t.shift()):a=!0},this._streamData=v(function(e){try{t.push("string"==typeof e?e:e.toString(this._config.encoding)),a&&(a=!1,this._checkIsFinished(),this.parseChunk(t.shift()))}catch(e){this._streamError(e)}},this),this._streamError=v(function(e){this._streamCleanUp(),this._sendError(e)},this),this._streamEnd=v(function(){this._streamCleanUp(),r=!0,this._streamData("")},this),this._streamCleanUp=v(function(){this._input.removeListener("data",this._streamData),this._input.removeListener("end",this._streamEnd),this._input.removeListener("error",this._streamError)},this)}function x(e){var t,a,r,s,i=/^\s*-?(\d+\.?|\.\d+|\d+\.\d+)([eE][-+]?\d+)?\s*$/,l=/^((\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z)))$/,o=this,d=0,c=0,u=!1,m=!1,x=[],f={data:[],errors:[],meta:{}};function g(t){return"greedy"===e.skipEmptyLines?""===t.join("").trim():1===t.length&&0===t[0].length}function b(){if(f&&r&&(j("Delimiter","UndetectableDelimiter","Unable to auto-detect delimiting character; defaulted to '"+n.DefaultDelimiter+"'"),r=!1),e.skipEmptyLines&&(f.data=f.data.filter(function(e){return!g(e)})),v()){if(f)if(Array.isArray(f.data[0])){for(var t,a=0;v()&&a<f.data.length;
1a++)f.data[a].forEach(s);f.data.splice(0,1)}else f.data.forEach(s);function s(e){x.push(e)}}function o(t,a){for(var r=e.header?{}:[],s=0;s<t.length;s++){var n=s,o=t[s],o=((t,a)=>(e.dynamicTypingFunction&&void 0===e.dynamicTyping[t]&&(e.dynamicTyping[t]=e.dynamicTypingFunction(t)),!0===(e.dynamicTyping[t]||e.dynamicTyping))?"true"===a||"TRUE"===a||"false"!==a&&"FALSE"!==a&&((e=>{if(i.test(e)&&-0x20000000000000<(e=parseFloat(e))&&e<0x20000000000000)return 1})(a)?parseFloat(a):l.test(a)?new Date(a):""===a?null:a):a)(n=e.header?s>=x.length?"__parsed_extra":x[s]:n,o=e.transform?e.transform(o,n):o);"__parsed_extra"===n?(r[n]=r[n]||[],r[n].push(o)):r[n]=o}return e.header&&(s>x.length?j("FieldMismatch","TooManyFields","Too many fields: expected "+x.length+" fields but parsed "+s,c+a):s<x.length&&j("FieldMismatch","TooFewFields","Too few fields: expected "+x.length+" fields but parsed "+s,c+a)),r}f&&(e.header||e.dynamicTyping||e.transform)&&(t=1,!f.data.length||Array.isArray(f.data[0])?(f.data=f.data.map(o),t=f.data.length):f.data=o(f.data,0),e.header&&f.meta&&(f.meta.fields=x),c+=t)}function v(){return e.header&&0===x.length}function j(e,t,a,r){e={type:e,code:t,message:a},void 0!==r&&(e.row=r),f.errors.push(e)}k(e.step)&&(s=e.step,e.step=function(t){f=t,v()?b():(b(),0!==f.data.length&&(d+=t.data.length,e.preview&&d>e.preview?a.abort():(f.data=f.data[0],s(f,o))))}),this.parse=function(s,i,l){var o=e.quoteChar||'"',o=(e.newline||(e.newline=this.guessLineEndings(s,o)),r=!1,e.delimiter?k(e.delimiter)&&(e.delimiter=e.delimiter(s),f.meta.delimiter=e.delimiter):((o=((t,a,r,s,i)=>{var l,o,d,c;i=i||[",","	","|",";",n.RECORD_SEP,n.UNIT_SEP];for(var u=0;u<i.length;u++){for(var m,x=i[u],h=0,f=0,b=0,y=(d=void 0,new p({comments:s,delimiter:x,newline:a,preview:10}).parse(t)),v=0;v<y.data.length;v++)r&&g(y.data[v])?b++:(f+=m=y.data[v].length,void 0===d?d=m:0<m&&(h+=Math.abs(m-d),d=m));0<y.data.length&&(f/=y.data.length-b),1.99<f&&(void 0===o||h<o||h===o&&c<f)&&(o=h,l=x,c=f)}return{successful:!!(e.delimiter=l),bestDelimiter:l}})(s,e.newline,e.skipEmptyLines,e.comments,e.delimitersToGuess)).successful?e.delimiter=o.bestDelimiter:(r=!0,e.delimiter=n.DefaultDelimiter),f.meta.delimiter=e.delimiter),y(e));return o.header=v(),e.preview&&e.header&&o.preview++,t=s,f=(a=new p(o)).parse(t,i,l),b(),u?{meta:{paused:!0}}:f||{meta:{paused:!1}}},this.paused=function(){return u},this.pause=function(){u=!0,a.abort(),t=k(e.chunk)?"":t.substring(a.getCharIndex())},this.resume=function(){o.streamer._halted?(u=!1,o.streamer.parseChunk(t,!0)):setTimeout(o.resume,3)},this.aborted=function(){return m},this.abort=function(){m=!0,a.abort(),f.meta.aborted=!0,k(e.complete)&&e.complete(f),t=""},this.guessLineEndings=function(e,t){e=e.substring(0,1048576);var t=RegExp(h(t)+"([^]*?)"+h(t),"gm"),a=(e=e.replace(t,"")).split("\r"),t=e.split("\n"),e=1<t.length&&t[0].length<a[0].length;if(1===a.length||e)return"\n";for(var r=0,s=0;s<a.length;s++)"\n"===a[s][0]&&r++;return r>=a.length/2?"\r\n":"\r"}}function h(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function p(e){var t=(e=e||{}).delimiter,a=e.newline,r=e.comments,s=e.step,i=e.preview,o=e.fastMode,d=null,c=!1,u=null==e.quoteChar?'"':e.quoteChar,m=u;if(void 0!==e.escapeChar&&(m=e.escapeChar),("string"!=typeof t||-1<n.BAD_DELIMITERS.indexOf(t))&&(t=","),r===t)throw Error("Comment character same as delimiter");!0===r?r="#":("string"!=typeof r||-1<n.BAD_DELIMITERS.indexOf(r))&&(r=!1),"\n"!==a&&"\r"!==a&&"\r\n"!==a&&(a="\n");var x=0,p=!1;this.parse=function(n,f,g){if("string"!=typeof n)throw Error("Input must be a string");var b=n.length,y=t.length,v=a.length,j=r.length,w=k(s),N=[],S=[],_=[],C=x=0;if(!n)return L();if(o||!1!==o&&-1===n.indexOf(u)){for(var z=n.split(a),I=0;I<z.length;I++){if(_=z[I],x+=_.length,I!==z.length-1)x+=a.length;else if(g)break;
vendor: 7,915 bytes, line 1
1if(!r||_.substring(0,j)!==r){if(w){if(N=[],A(_.split(t)),M(),p)return L()}else A(_.split(t));if(i&&i<=I)return N=N.slice(0,i),L(!0)}}return L()}for(var T=n.indexOf(t,x),P=n.indexOf(a,x),E=RegExp(h(m)+h(u),"g"),O=n.indexOf(u,x);;)if(n[x]===u)for(O=x,x++;;){if(-1===(O=n.indexOf(u,O+1)))return g||S.push({type:"Quotes",code:"MissingQuotes",message:"Quoted field unterminated",row:N.length,index:x}),F();if(O===b-1)return F(n.substring(x,O).replace(E,u));if(u===m&&n[O+1]===m)O++;else if(u===m||0===O||n[O-1]!==m){-1!==T&&T<O+1&&(T=n.indexOf(t,O+1));var R=D(-1===(P=-1!==P&&P<O+1?n.indexOf(a,O+1):P)?T:Math.min(T,P));if(n.substr(O+1+R,y)===t){_.push(n.substring(x,O).replace(E,u)),n[x=O+1+R+y]!==u&&(O=n.indexOf(u,x)),T=n.indexOf(t,x),P=n.indexOf(a,x);break}if(R=D(P),n.substring(O+1+R,O+1+R+v)===a){if(_.push(n.substring(x,O).replace(E,u)),$(O+1+R+v),T=n.indexOf(t,x),O=n.indexOf(u,x),w&&(M(),p))return L();if(i&&N.length>=i)return L(!0);break}S.push({type:"Quotes",code:"InvalidQuotes",message:"Trailing quote on quoted field is malformed",row:N.length,index:x}),O++}}else if(r&&0===_.length&&n.substring(x,x+j)===r){if(-1===P)return L();x=P+v,P=n.indexOf(a,x),T=n.indexOf(t,x)}else if(-1!==T&&(T<P||-1===P))_.push(n.substring(x,T)),x=T+y,T=n.indexOf(t,x);else{if(-1===P)break;if(_.push(n.substring(x,P)),$(P+v),w&&(M(),p))return L();if(i&&N.length>=i)return L(!0)}return F();function A(e){N.push(e),C=x}function D(e){return -1!==e&&(e=n.substring(O+1,e))&&""===e.trim()?e.length:0}function F(e){return g||(void 0===e&&(e=n.substring(x)),_.push(e),x=b,A(_),w&&M()),L()}function $(e){x=e,A(_),_=[],P=n.indexOf(a,x)}function L(r){if(e.header&&!f&&N.length&&!c){var s=N[0],i=Object.create(null),n=new Set(s);let t=!1;for(let a=0;a<s.length;a++){let r=l(s[a]);if(i[r=k(e.transformHeader)?e.transformHeader(r,a):r]){let e,l=i[r];for(;e=r+"_"+l,l++,n.has(e););n.add(e),s[a]=e,i[r]++,t=!0,(d=null===d?{}:d)[e]=r}else i[r]=1,s[a]=r;n.add(r)}t&&console.warn("Duplicate headers found and renamed."),c=!0}return{data:N,errors:S,meta:{delimiter:t,linebreak:a,aborted:p,truncated:!!r,cursor:C+(f||0),renamedHeaders:d}}}function M(){s(L()),N=[],S=[]}},this.abort=function(){p=!0},this.getCharIndex=function(){return x}}function f(e){var t=e.data,a=s[t.workerId],r=!1;if(t.error)a.userError(t.error,t.file);else if(t.results&&t.results.data){var i={abort:function(){r=!0,g(t.workerId,{data:[],errors:[],meta:{aborted:!0}})},pause:b,resume:b};if(k(a.userStep)){for(var n=0;n<t.results.data.length&&(a.userStep({data:t.results.data[n],errors:t.results.errors,meta:t.results.meta},i),!r);n++);delete t.results}else k(a.userChunk)&&(a.userChunk(t.results,i,t.file),delete t.results)}t.finished&&!r&&g(t.workerId,t.results)}function g(e,t){var a=s[e];k(a.userComplete)&&a.userComplete(t),a.terminate(),delete s[e]}function b(){throw Error("Not implemented.")}function y(e){if("object"!=typeof e||null===e)return e;var t,a=Array.isArray(e)?[]:{};for(t in e)a[t]=y(e[t]);return a}function v(e,t){return function(){e.apply(t,arguments)}}function k(e){return"function"==typeof e}return n.parse=function(a,r){var o,x,h,p=(r=r||{}).dynamicTyping||!1;if(k(p)&&(r.dynamicTypingFunction=p,p={}),r.dynamicTyping=p,r.transform=!!k(r.transform)&&r.transform,void 0!==r.downloadTimeout){var p=parseInt(r.downloadTimeout);if(isNaN(p))throw Error("Config downloadTimeout value ("+r.downloadTimeout+") not parsable by parseInt(val).");r.downloadTimeout=p}if(!r.worker||!n.WORKERS_SUPPORTED)return p=null,n.NODE_STREAM_INPUT,"string"==typeof a?(a=l(a),p=new(r.download?d:u)(r)):!0===a.readable&&k(a.read)&&k(a.on)?p=new m(r):(t.File&&a instanceof File||a instanceof Object)&&(p=new c(r)),p.stream(a);(p=!!n.WORKERS_SUPPORTED&&(x=t.URL||t.webkitURL||null,h=e.toString(),o=n.BLOB_URL||(n.BLOB_URL=x.createObjectURL(new Blob(["var global = (function() { if (typeof self !== 'undefined') { return self; } if (typeof window !== 'undefined') { return window; } if (typeof global !== 'undefined') { return global; } return {}; })(); global.IS_PAPA_WORKER=true; ","(",h,")();"],{type:"text/javascript"}))),(o=new t.Worker(o)).onmessage=f,o.id=i++,s[o.id]=o)).userStep=r.step,p.userChunk=r.chunk,p.userComplete=r.complete,p.userError=r.error,r.step=k(r.step),r.chunk=k(r.chunk),r.complete=k(r.complete),r.error=k(r.error),delete r.worker,p.postMessage({input:a,config:r,workerId:p.id})},n.unparse=function(e,t){var a=!1,r=!0,s=",",i="\r\n",l='"',o=l+l,d=!1,c=null,u=!1,m=((()=>{if("object"==typeof t){if("string"!=typeof t.delimiter||n.BAD_DELIMITERS.filter(function(e){return -1!==t.delimiter.indexOf(e)}).length||(s=t.delimiter),("boolean"==typeof t.quotes||"function"==typeof t.quotes||Array.isArray(t.quotes))&&(a=t.quotes),"boolean"!=typeof t.skipEmptyLines&&"string"!=typeof t.skipEmptyLines||(d=t.skipEmptyLines),"string"==typeof t.newline&&(i=t.newline),"string"==typeof t.quoteChar&&(o=(l=t.quoteChar)+l),"boolean"==typeof t.header&&(r=t.header),Array.isArray(t.columns)){if(0===t.columns.length)throw Error("Option columns is empty");c=t.columns}void 0!==t.escapeChar&&(o=t.escapeChar+l),t.escapeFormulae instanceof RegExp?u=t.escapeFormulae:"boolean"==typeof t.escapeFormulae&&t.escapeFormulae&&(u=/^[=+\-@\t\r].*$/)}})(),RegExp(h(l),"g"));if("string"==typeof e&&(e=JSON.parse(e)),Array.isArray(e)){if(!e.length||Array.isArray(e[0]))return x(null,e,d);if("object"==typeof e[0])return x(c||Object.keys(e[0]),e,d)}else if("object"==typeof e)return"string"==typeof e.data&&(e.data=JSON.parse(e.data)),Array.isArray(e.data)&&(e.fields||(e.fields=e.meta&&e.meta.fields||c),e.fields||(e.fields=Array.isArray(e.data[0])?e.fields:"object"==typeof e.data[0]?Object.keys(e.data[0]):[]),Array.isArray(e.data[0])||"object"==typeof e.data[0]||(e.data=[e.data])),x(e.fields||[],e.data||[],d);throw Error("Unable to serialize unrecognized input");function x(e,t,a){var n="",l=("string"==typeof e&&(e=JSON.parse(e)),"string"==typeof t&&(t=JSON.parse(t)),Array.isArray(e)&&0<e.length),o=!Array.isArray(t[0]);if(l&&r){for(var d=0;d<e.length;d++)0<d&&(n+=s),n+=p(e[d],d);0<t.length&&(n+=i)}for(var c=0;c<t.length;c++){var u=(l?e:t[c]).length,m=!1,x=l?0===Object.keys(t[c]).length:0===t[c].length;if(a&&!l&&(m="greedy"===a?""===t[c].join("").trim():1===t[c].length&&0===t[c][0].length),"greedy"===a&&l){for(var h=[],f=0;f<u;f++){var g=o?e[f]:f;h.push(t[c][g])}m=""===h.join("").trim()}if(!m){for(var b=0;b<u;b++){0<b&&!x&&(n+=s);var y=l&&o?e[b]:b;n+=p(t[c][y],b)}c<t.length-1&&(!a||0<u&&!x)&&(n+=i)}}return n}function p(e,t){var r,i,d;return null==e?"":e.constructor===Date?isNaN(e.getTime())?"":e.toISOString():(d=!1,u&&"string"==typeof e&&u.test(e)&&(e="'"+e,d=!0),i=(r=e.toString()).replace(m,o),(d=d||!0===a||"function"==typeof a&&a(e,t)||Array.isArray(a)&&a[t]||((e,t)=>{for(var a=0;a<t.length;a++)if(-1<e.indexOf(t[a]))return!0;return!1})(i,n.BAD_DELIMITERS)||-1<i.indexOf(s)||-1<r.indexOf(l)||" "===i.charAt(0)||" "===i.charAt(i.length-1))?l+i+l:i)}},n.RECORD_SEP="\x1e",n.UNIT_SEP="\x1f",n.BYTE_ORDER_MARK="\uFEFF",n.BAD_DELIMITERS=["\r","\n",'"',n.BYTE_ORDER_MARK],n.WORKERS_SUPPORTED=!a&&!!t.Worker,n.NODE_STREAM_INPUT=1,n.LocalChunkSize=0xa00000,n.RemoteChunkSize=5242880,n.DefaultDelimiter=",",n.Parser=p,n.ParserHandle=x,n.NetworkStreamer=d,n.FileStreamer=c,n.StringStreamer=u,n.ReadableStreamStreamer=m,r&&(t.onmessage=function(e){e=e.data,void 0===n.WORKER_ID&&e&&(n.WORKER_ID=e.workerId),"string"==typeof e.input?t.postMessage({workerId:n.WORKER_ID,results:n.parse(e.input,e.config),finished:!0}):(t.File&&e.input instanceof File||e.input instanceof Object)&&(e=n.parse(e.input,e.config))&&t.postMessage({workerId:n.WORKER_ID,results:e,finished:!0})}),(d.prototype=Object.create(o.prototype)).constructor=d,(c.prototype=Object.create(o.prototype)).constructor=c,(u.prototype=Object.create(u.prototype)).constructor=u,(m.prototype=Object.create(o.prototype)).constructor=m,n},"function"==typeof define&&define.amd?void 0!==(s=r())&&e.v(s):t.exports=r()}]);

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.