PageSourceSearch

https://www.growlytics.app/assets/ProjectOverview-Pl4vvQZk.js

js growlytics.app collected 2026-10-02 01:15:04 UTC 231,966 bytes, 3 lines download raw bytes

1import{aT as Ot,r as t,j as e,aW as Ke,b7 as Ct,aV as xt,a$ as sa,aU as ka}from"./vendor-libs-DqTTukLt.js";import{ab as lt,a as tt,ap as na,p as ja,X as Re,D as ot,aa as ct,M as qe,a7 as Ye,n as la,f as Ve,i as nt,a8 as Lt,z as ia,T as gt,L as ft,bA as $t,B as ut,J as oa,a9 as Ft,d as Pe,m as da,C as Ce,bx as va,ah as Mt,G as yt,H as Rt,aD as St,bB as wa,bC as Na,aT as Ca,$ as It,bD as Sa,bE as ca,bF as _a,bG as ua,F as Pt,b as Je,ax as Nt,E as mt,bH as Wt,v as xa,bI as Aa,aJ as ht,a6 as _t,bJ as ma,u as ba,bK as Ia,b9 as La,bL as Ht,at as $a,a2 as Dt,P as zt,ai as kt,af as Ma,bM as Da,bN as Ta,aq as Tt,o as Et,bO as Ea,bP as Oa,aE as Fa,bQ as Ra,bR as Pa,ad as pa,bS as ha,al as Wa,bT as za,R as ga,bi as Ba,bU as Ua,ay as qt,aV as Ga,ac as Va,bV as Ka}from"./index-DnZkLQpb.js";import{s as Ja,a as Ha,c as fa,b as qa,d as Ya}from"./competitorService-CchVSOd8.js";import{m as M,A as be}from"./vendor-heavy-BYAivpjp.js";import{P as At}from"./PageSkeleton-CMJ0Wc2K.js";import{t as Qa}from"./timezones-C_yJAfHH.js";import{I as Bt,V as Ut,G as Gt,A as Vt,E as Xa}from"./EditCompetitorModal-6Czy1XW6.js";import{S as ya,A as Za,B as er}from"./AllKeywordsView-DVsnBw0a.js";import{g as tr,a as ar}from"./backlinkService-BdhUJ9si.js";import{g as rr}from"./blogIntegrationService-CPHz3nTr.js";import{B as sr}from"./BlogIntegrationModal-DrAYfmfb.js";import{C as jt}from"./ConfirmModal-CG1WZSBu.js";import{u as nr}from"./useDemoRestriction-Bl2M6pz5.js";import lr from"./TestDetail-Dd8zHdUU.js";import{B as ir}from"./BrandModal-DNOP3oIw.js";import"./contentPlannerService-Di18ZPK8.js";import"./settingsService-YlyOunVq.js";import"./abTestsService-CTbS_oKR.js";import"./SnippetInstallModal-DNKR5zPp.js";const or=a=>e.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",...a,children:e.jsx("path",{d:"M12 0A12 12 0 0 0 0 12a12 12 0 0 0 12 12 12 12 0 0 0 12-12A12 12 0 0 0 12 0zm5.01 4.744c.688 0 1.25.561 1.25 1.249a1.25 1.249a1.25 1.249a1.25 1.249a1.25 1.249a1.25 1.249a1.25 1.249a1.25 1.249a1.25 1.249a1.25 1.249a1.25 1.249 0 0 1-2.498.056l-2.597-.547-.8 3.747c1.824.07 3.48.632 4.674 1.488.308-.309.73-.491 1.207-.491.968 0 1.754.786 1.754 1.754 0 .716-.435 1.333-1.01 1.614a3.111 3.111 0 0 1 .042.52c0 2.694-3.13 4.87-7.004 4.87-3.874 0-7.004-2.176-7.004-4.87 0-.183.015-.366.043-.534A1.748 1.748 0 0 1 4.028 12c0-.968.786-1.754 1.754-1.754.463 0 .898.196 1.207.49 1.207-.883 2.878-1.43 4.744-1.487l.885-4.182a.342.342 0 0 1 .14-.197.35.35 0 0 1 .238-.042l2.906.617a1.214 1.214 0 0 1 1.108-.701zM9.25 12C8.561 12 8 12.562 8 13.25c0 .687.561 1.248 1.25 1.248.687 0 1.248-.561 1.248-1.249 0-.688-.561-1.249-1.249-1.249zm5.5 0c-.687 0-1.248.561-1.248 1.25 0 .687.561 1.249 1.248.688 0 1.249-.561 1.249-1.249 0-.687-.562-1.249-1.25-1.249zm-5.466 3.99a.327.327 0 0 0-.231.094.33.33 0 0 0 0 .463c.842.842 2.484.913 2.961.913.477 0 2.105-.056 2.961-.913a.361.361 0 0 0 .029-.463.33.33 0 0 0-.464 0c-.547.533-1.684.73-2.512.73-.828 0-1.979-.196-2.512-.73a.326.326 0 0 0-.232-.095z"})}),rt=({label:a,info:o,className:p})=>{const[i,l]=t.useState(!1);return e.jsxs("div",{className:`flex items-center gap-1.5 mb-2 px-1 ${p}`,children:[e.jsx("label",{className:"text-[10px] font-black text-neutral-400 block",children:a}),e.jsxs("div",{className:"relative",children:[e.jsx("button",{type:"button",onMouseEnter:()=>l(!0),onMouseLeave:()=>l(!1),onClick:()=>l(!i),className:"text-cyan-500 hover:text-cyan-600 transition-colors p-0.5 rounded-full",children:e.jsx(St,{className:"w-3.5 h-3.5"})}),e.jsx(be,{children:i&&e.jsxs(M.div,{initial:{opacity:0,y:5},animate:{opacity:1,y:0},exit:{opacity:0,y:5},className:"absolute bottom-full left-1/2 -translate-x-1/2 mb-2 w-48 p-3 bg-neutral-900 text-white text-[10px] font-medium leading-relaxed rounded-lg shadow-xl z-[150] pointer-events-none",children:[e.jsx("div",{className:"absolute top-full left-1/2 -translate-x-1/2 border-8 border-transparent border-t-neutral-900"}),o]})})]})]})},Ge=10,dr=({isOpen:a,onClose:o,onMonitorCreated:p,initialMode:i=null,initialSocialQuery:l,initialCompetitorData:m})=>{var Ie;const{t:h}=Ot(),{selectedProject:u,permissions:c,refreshPermissions:g}=lt(),{addToast:s}=tt(),{openUpgradeModal:b}=na(),[f,z]=t.useState("select"),[y,V]=t.useState(null),[S,H]=t.useState(1),[Y,C]=t.useState(!1),[v,A]=t.useState(!1),[Z,T]=t.useState(""),[K,O]=t.useState("daily"),[he,oe]=t.useState(!0),[ye,ke]=t.useState("discover_pages"),[ce,xe]=t.useState("all_changes"),[ge,we]=t.useState("Monitor pricing and product section only"),[$,J]=t.useState(""),[E,U]=t.useState(""),[ee,re]=t.useState(!0),[X,se]=t.useState({twitter:"",facebook:"",linkedin:"",blog:""}),[N,q]=t.useState(["website_changes","pricing","seo","blog","social_activity","backlinks","keywords","reviews"]),[B,te]=t.useState("Untitled Listener"),[F,R]=t.useState([]),[P,ue]=t.useState(""),[ae,Q]=t.useState([]),[je,G]=t.useState(["r/saas"]),[ve,$e]=t.useState(""),[Me,Ee]=t.useState(5),[ne,I]=t.useState(!0),[d,D]=t.useState(!0),[fe,k]=t.useState(["buying-signal","question-seeking-tool","comparison"]),[de,Ne]=t.useState(""),[De,Be]=t.useState([]),[Ue,ie]=t.useState([]),We=t.useCallback(r=>
1{if(!c)return!1;let _=-1,le=0,Le="";return r==="website"?(_=c.limits.website_monitor_limit,le=c.usage.website_monitors,Le="Website Monitor"):r==="social"?(_=c.limits.social_monitor_limit,le=c.usage.social_monitors,Le="Social Listening"):r==="competitor"&&(_=c.limits.competitor_monitor_limit,le=c.usage.competitors,Le="Competitor Monitor"),_!==-1&&le>=_?{label:Le,limit:_}:!1},[c]),_e=t.useCallback(r=>({id:r.id||r.Website||Math.random(),name:r.name||r["Competitor Name"]||"Unknown Competitor",website:r.website||r.Website||"",description:r.description||r["Short Description"]||"",tags:r.tags||(typeof r["Industry Tags"]=="string"?r["Industry Tags"].split(",").map(_=>_.trim()):r["Industry Tags"])||[],socials:r.socials||{twitter:r.Twitter,linkedin:r.LinkedIn,facebook:r.Facebook,blog:r.Blog},confidence:r.confidence||r["Confidence Score"]||0}),[]),x=t.useCallback(()=>{var _,le,Le,Fe;const r=i||"select";if(i){const Te=We(i);if(Te){b({title:`${Te.label} Limit Reached`,description:`You've reached your limit of ${Te.limit} ${Te.label.toLowerCase()}s for this project. Upgrade to add more.`,featureName:Te.label}),o();return}}if(z(r),V(i||null),H(1),T(""),O("daily"),oe(!0),ke("discover_pages"),xe("all_changes"),l?(R([l]),H(2)):R([]),m?(J(m.name),U(m.website),se({twitter:((_=m.socials)==null?void 0:_.twitter)||"",facebook:((le=m.socials)==null?void 0:le.facebook)||"",linkedin:((Le=m.socials)==null?void 0:Le.linkedin)||"",blog:((Fe=m.socials)==null?void 0:Fe.blog)||""}),H(2)):(J(""),U(""),se({twitter:"",facebook:"",linkedin:"",blog:""})),te("Untitled Listener"),re(!0),ue(""),Q([]),G(["r/saas"]),$e(""),Ee(5),Ne(""),A(!1),u!=null&&u.listeners_suggestion)try{const Te=typeof u.listeners_suggestion=="string"?JSON.parse(u.listeners_suggestion):u.listeners_suggestion;Be(Array.isArray(Te)?Te:[])}catch{Be([])}else Be([]);u!=null&&u.competitors_suggestion?ie(u.competitors_suggestion.map(_e)):ie([])},[i,u,l,m,We,b,o,_e]);t.useEffect(()=>{a&&x()},[a,x]);const W=async()=>{if(u){A(!0);try{const r=await wa(u.id);r.data.suggestions&&Be(r.data.suggestions)}catch{s("Failed to generate suggestions.","error")}finally{A(!1)}}},pe=()=>{const r=P.trim();if(r){if(F.length>=Ge){s(`Maximum ${Ge} keywords allowed per monitor.`,"error");return}F.includes(r)||(R(_=>[..._,r]),ue(""))}},me=r=>{R(_=>_.filter(le=>le!==r))},Ae=()=>{const r=ve.trim().toLowerCase();if(!r)return;const _=r.startsWith("r/")?r:`r/${r}`;je.includes(_)||(G(le=>[...le,_]),$e(""))},Se=r=>{G(_=>_.filter(le=>le!==r))},Qe=r=>{if(F.length>=Ge){s(`Limit reached. ${Ge} keywords per monitor.`,"error");return}F.includes(r)||R(_=>[..._,r])},ze=async()=>{if(u){A(!0);try{const r=await Ja({project_description:u.description||`Grow my brand for ${u.name}`,project_id:u.id});r.data.competitors&&ie(r.data.competitors.map(_e))}catch{s("Failed to generate suggestions.","error")}finally{A(!1)}}},at=r=>{var _,le,Le,Fe;J(r.name),U(r.website),se({twitter:((_=r.socials)==null?void 0:_.twitter)||"",facebook:((le=r.socials)==null?void 0:le.facebook)||"",linkedin:((Le=r.socials)==null?void 0:Le.linkedin)||"",blog:((Fe=r.socials)==null?void 0:Fe.blog)||""})},He=r=>{q(_=>_.includes(r)?_.filter(le=>le!==r):[..._,r])},Xe=()=>{if(!y||!c)return;const r=We(y);if(r){b({title:`${r.label} Limit Reached`,description:`You've reached your limit of ${r.limit} ${r.label.toLowerCase()}s for this project. Upgrade to add more.`,featureName:r.label});return}z(y),H(1)},Ze=async()=>{if(u){if(f==="social"&&F.length===0){s("At least one keyword is required.","error");return}C(!0);try{f==="website"?await Na({project_id:u.id,website_url:Z,monitor_frequency:K,discovery_mode:ye,monitor_type:ce,monitor_instructions:ce==="instructions"?ge:void 0,generate_action:he}):f==="competitor"?await Ha({project_id:u.id,name:$,website:E,type:"manual",socials:X,generate_action:ee,targets:N}):f==="social"&&await Ca({project_id:u.id,channels:ae,search_query:F,title:B,instructions:de,generate_action:ne,lead_generate:d,insight_layers:fe,engagement_threshold:Me,sub_reddits:je}),s("Monitor successfully created.","success"),await g(),p(),o()}catch{s("Failed to create monitor.","error")}finally{C(!1)}}},et=()=>{x(),o()},n={hidden:{opacity:0,x:20},visible:{opacity:1,x:0},exit:{opacity:0,x:-20}},w=t.useMemo(()=>f==="social"&&S===1?F.length>0:f==="social"&&S===2?ae.length>0:f==="website"&&S===1?!!Z.trim():f==="competitor"&&S===1?!!$.trim()&&!!E.trim():!0,[f,S,F,Z,$,E,ae]);if(!a)return null;const j=(Ie=c==null?void 0:c.access)==null?void 0:Ie.competitors,L=!!(j!=null&&j.twitter||j!=null&&j.linkedin||j!=null&&j.facebook);return e.jsxs("div",{className:"fixed inset-0 z-[100] flex justify-center items-center p-4",children:[e.jsx(M.div,{initial:{opacity:0}
1,animate:{opacity:1},exit:{opacity:0},onClick:et,className:"absolute inset-0 backdrop-blur-sm bg-black/20"}),e.jsxs(M.div,{initial:{opacity:0,scale:.95},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.95},transition:{type:"spring",stiffness:300,damping:30},className:"relative bg-white dark:bg-neutral-800 rounded-2xl shadow-lg w-full max-w-4xl flex flex-col max-h-[90vh] overflow-hidden",onClick:r=>r.stopPropagation(),children:[e.jsxs("div",{className:"p-6 pb-2 border-b border-neutral-100 dark:border-neutral-700 flex justify-between items-start flex-shrink-0",children:[e.jsx("div",{children:f==="select"?e.jsx("h2",{className:"text-2xl font-bold text-neutral-900 dark:text-neutral-100 tracking-tight",children:"Add New Monitor"}):e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{type:"button",onClick:()=>{S===1&&!i?z("select"):S>1&&H(S-1)},className:"p-1 hover:bg-neutral-100 dark:hover:bg-neutral-700 rounded-full text-neutral-900 dark:text-neutral-100 transition-colors",children:e.jsx(ja,{className:"w-5 h-5"})}),e.jsxs("div",{className:"",children:[e.jsx("h3",{className:"text-xl font-bold text-neutral-900 dark:text-neutral-100 tracking-tight",children:f==="social"?"Social Listening":f==="competitor"?"Competitor Monitor":"Website Monitor"}),e.jsxs("p",{className:"text-xs font-bold text-brand-primary mt-0.5",children:["Step ",S," of 3"]})]})]})}),e.jsx("button",{type:"button",onClick:et,className:"p-1 text-neutral-400 hover:text-neutral-800 transition-colors",children:e.jsx(Re,{className:"w-6 h-6"})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-8 custom-scrollbar",children:e.jsxs(be,{mode:"wait",children:[f==="select"&&e.jsxs(M.div,{variants:n,initial:"hidden",animate:"visible",exit:"exit",className:"grid grid-cols-1 md:grid-cols-2 gap-6 pt-4 pb-8",children:[e.jsxs("button",{type:"button",onClick:()=>V("social"),className:`group flex flex-col items-center text-center p-8 bg-white dark:bg-neutral-800 border-2 rounded-xl transition-all duration-300 ${y==="social"?"border-brand-primary bg-brand-light/10 shadow-md ring-1 ring-brand-primary":"border-neutral-200 dark:border-neutral-700 hover:border-brand-primary/50"}`,children:[e.jsx("div",{className:`w-14 h-14 rounded-xl flex items-center justify-center mb-6 transition-all ${y==="social"?"bg-brand-light scale-110":"bg-neutral-100 dark:bg-neutral-700 group-hover:bg-brand-light group-hover:scale-110"}`,children:e.jsx(ot,{className:`w-8 h-8 transition-colors ${y==="social"?"text-brand-primary":"text-neutral-50 group-hover:text-brand-primary"}`})}),e.jsx("h3",{className:`text-lg font-black tracking-tight mb-2 ${y==="social"?"text-brand-primary":""}`,children:"Social"}),e.jsx("p",{className:"text-xs text-neutral-500 leading-relaxed font-medium",children:"Monitor keywords & brand mentions across X, LI & Reddit."})]}),e.jsxs("button",{type:"button",onClick:()=>V("competitor"),className:`group flex flex-col items-center text-center p-8 bg-white dark:bg-neutral-800 border-2 rounded-xl transition-all duration-300 ${y==="competitor"?"border-brand-primary bg-brand-light/10 shadow-md ring-1 ring-brand-primary":"border-neutral-200 dark:border-neutral-700 hover:border-brand-primary/50"}`,children:[e.jsx("div",{className:`w-14 h-14 rounded-xl flex items-center justify-center mb-6 transition-all ${y==="competitor"?"bg-brand-light scale-110":"bg-neutral-100 dark:bg-neutral-700 group-hover:bg-brand-light group-hover:scale-110"}`,children:e.jsx(ct,{className:`w-8 h-8 transition-colors ${y==="competitor"?"text-brand-primary":"text-neutral-50 group-hover:text-brand-primary"}`})}),e.jsx("h3",{className:`text-lg font-black tracking-tight mb-2 ${y==="competitor"?"text-brand-primary":""}`,children:"Competitor"}),e.jsx("p",{className:"text-xs text-neutral-500 leading-relaxed font-medium",children:"Track rival strategies & digital footprints."})]})]},"select"),f==="social"&&e.jsxs(M.div,{variants:n,initial:"hidden",animate:"visible",exit:"exit",className:"space-y-10",children:[S===1&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx(rt,{label:"Monitor title",info:"The label for this campaign. Helps you identify it in your navigation."}),e.jsx("input",{value:B,onChange:r=>te(r.target.value),className:"w-full px-4 py-3 text-sm border border-neutral-300 dark:border-neutral-600 rounded-xl focus:outline-none focus:ring-2 focus:ring-brand-primary bg-white dark:bg-neutral-900 text-neutral-900 dark:text-neutral-200 shadow-sm transition-all",placeholder:"Untitled Listener"})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-end mb-4",children:[e.jsx(rt,{label:"Define keywords",info:`What should we listen for? You can add up to ${Ge} keyword phrases per monitor. This counts as ONE monitor slot in y
1our plan.`}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs("div",{className:"px-3 py-1 bg-neutral-50 dark:bg-neutral-900 border border-neutral-200 dark:border-neutral-700 rounded-lg text-[9px] font-black text-neutral-400",children:["Keywords: ",e.jsxs("span",{className:F.length>=Ge?"text-amber-500":"text-brand-primary",children:[F.length," of ",Ge," used"]})]})})]}),e.jsxs("div",{className:"relative",children:[e.jsx(qe,{className:"absolute left-4 top-1/2 -translate-y-1/2 w-5 h-5 text-neutral-300"}),e.jsx("input",{type:"text",value:P,onChange:r=>ue(r.target.value),onKeyDown:r=>r.key==="Enter"&&(r.preventDefault(),pe()),placeholder:"Add a keyword...",className:"w-full pl-12 pr-12 py-4 bg-neutral-50 dark:bg-neutral-900 border-none rounded-xl focus:ring-2 focus:ring-brand-primary transition-all text-sm font-bold shadow-none",disabled:F.length>=Ge}),e.jsx("button",{type:"button",onClick:pe,disabled:!P.trim()||F.length>=Ge,className:"absolute right-4 top-1/2 -translate-y-1/2 p-1.5 bg-neutral-200 dark:bg-neutral-700 rounded-lg text-neutral-500 hover:text-brand-primary disabled:opacity-50",children:e.jsx(Ye,{className:"w-4 h-4"})})]}),F.length>=Ge&&e.jsxs(M.div,{initial:{opacity:0,y:-5},animate:{opacity:1,y:0},className:"mt-3 flex items-center gap-2 text-[10px] font-bold text-amber-600 dark:text-amber-400 bg-amber-50 dark:bg-amber-900/20 px-3 py-1.5 rounded-lg border border-amber-200 dark:border-amber-800",children:[e.jsx(la,{className:"w-3.5 h-3.5"}),"Limit reached: Max ",Ge," keywords."]}),e.jsxs("div",{className:"flex flex-wrap gap-2 mt-4 min-h-[40px]",children:[F.map(r=>e.jsxs("span",{className:"inline-flex items-center gap-2 px-3 py-1.5 bg-brand-light/50 dark:bg-brand-primary/20 border border-brand-primary/20 rounded-lg text-xs font-bold text-brand-primary",children:[r,e.jsx("button",{type:"button",onClick:()=>me(r),className:"hover:text-brand-secondary transition-colors",children:e.jsx(Re,{className:"w-4 h-4"})})]},r)),F.length===0&&e.jsx("p",{className:"text-xs text-neutral-400 italic font-medium px-1",children:"Add keywords or brand terms to track."})]})]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsxs("span",{className:"text-[10px] font-black text-neutral-400 flex items-center gap-2",children:[e.jsx("cite",{className:"not-italic flex items-center gap-2",children:e.jsx(Ve,{className:"w-4 h-4 text-brand-primary"})})," AI suggested queries"]}),e.jsx("button",{type:"button",onClick:W,disabled:v,className:"text-[10px] font-black text-brand-primary border border-brand-primary/20 rounded-lg px-3 py-1.5 hover:bg-brand-light transition-all flex items-center gap-2 disabled:opacity-50",children:v?e.jsx(nt,{}):e.jsxs(e.Fragment,{children:[e.jsx(Lt,{className:"w-3.5 h-3.5"})," Refresh"]})})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:De.length>0?De.map(r=>{const _=F.includes(r)||F.length>=Ge;return e.jsx("button",{type:"button",onClick:()=>Qe(r),disabled:_,className:`px-4 py-2 rounded-full text-[10px] font-bold tracking-tight transition-all ${_?"bg-neutral-100 text-neutral-400 cursor-not-allowed border border-neutral-200":"bg-neutral-50 dark:bg-neutral-800 border border-neutral-200 dark:border-neutral-700 text-neutral-600 dar
1k:text-neutral-300 hover:border-brand-primary hover:text-brand-primary"}`,children:r},r)}):e.jsx("p",{className:"text-sm text-neutral-400 italic px-1",children:"Click refresh to discover keywords with AI."})})]}),e.jsx("div",{className:"space-y-3",children:[{id:"ai-actions",title:"AI Actions",desc:"Auto-generate engagement tasks and outreach suggestions for every new match.",icon:e.jsx(Ve,{className:"w-5 h-5 text-brand-primary"}),checked:ne,set:I},{id:"lead-gen",title:"Lead Generation",desc:"Identify high-intent prospects and buying signals across social conversations.",icon:e.jsx(ia,{className:"w-5 h-5 text-brand-primary"}),checked:d,set:D}].map(r=>e.jsxs("div",{className:"p-5 bg-neutral-50 dark:bg-neutral-800/50 rounded-xl border border-neutral-200 dark:border-neutral-700 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"p-3 bg-brand-light dark:bg-brand-primary/10 rounded-xl",children:r.icon}),e.jsxs("div",{children:[e.jsx("h5",{className:"font-bold text-sm",children:r.title}),e.jsx("p",{className:"text-[11px] text-neutral-500 leading-tight mt-0.5 max-w-[340px] font-medium",children:r.desc})]})]}),e.jsx("button",{type:"button",onClick:()=>r.set(!r.checked),className:`relative inline-flex items-center h-6 w-12 rounded-full transition-all ${r.checked?"bg-brand-primary":"bg-neutral-300 dark:bg-neutral-700"}`,children:e.jsx("span",{className:`inline-block w-4 h-4 transform bg-white rounded-full transition-transform ${r.checked?"translate-x-7":"translate-x-1"}`})})]},r.id))})]}),S===2&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-end mb-6",children:[e.jsx("h4",{className:"text-xl font-bold tracking-tight",children:"Select channels"}),e.jsxs("div",{className:"flex gap-4 text-[10px] font-black text-brand-primary",children:[e.jsx("button",{type:"button",onClick:()=>Q(["twitter","linkedin","reddit","facebook"].filter(r=>{var _,le;return(le=(_=c==null?void 0:c.access)==null?void 0:_.social_listening)==null?void 0:le[r]})),children:"Select all"}),e.jsx("button",{type:"button",onClick:()=>Q([]),className:"text-neutral-400",children:"Deselect"})]})]}),e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[{id:"reddit",label:"Reddit",icon:e.jsx("div",{className:"p-2 bg-orange-500 rounded-xl shadow-lg shadow-orange-500/20",children:e.jsx(or,{className:"w-7 h-7 text-white"})})},{id:"twitter",label:"X (Twitter)",icon:e.jsx("div",{className:"p-2 bg-blue-400 rounded-xl shadow-lg shadow-blue-500/20",children:e.jsx(gt,{className:"w-7 h-7 text-white"})})},{id:"linkedin",label:"LinkedIn",icon:e.jsx("div",{className:"p-2 bg-blue-700 rounded-xl shadow-lg shadow-blue-800/20",children:e.jsx(ft,{className:"w-7 h-7 text-white"})})},{id:"facebook",label:"Facebook",icon:e.jsx("div",{className:"p-2 bg-blue-600 rounded-xl shadow-lg shadow-blue-600/20",children:e.jsx($t,{className:"w-7 h-7 text-white"})})}].map(r=>{var le,Le;const _=((Le=(le=c==null?void 0:c.access)==null?void 0:le.social_listening)==null?void 0:Le[r.id])??!0;return e.jsxs("button",{type:"button",disabled:!_,onClick:()=>Q(Fe=>Fe.includes(r.id)?Fe.filter(Te=>Te!==r.id):[...Fe,r.id]),className:`relative flex flex-col items-center justify-center p-6 border-2 rounded-xl transition-all ${_?ae.includes(r.id)?"border-brand-primary bg-brand-light/20 shadow-md":"border-neutral-200 dark:border-neutral-700 hover:border-brand-primary/30":"opacity-40 grayscale cursor-not-allowed bg-neutral-50 dark:bg-neutral-800"}`,children:[!_&&e.jsx("div",{className:"absolute top-2 right-2 text-amber-500",children:e.jsx(Ve,{className:"w-4 h-4"})}),r.icon,e.jsx("span",{className:`text-[10px] font-black mt-4 ${ae.includes(r.id)?"text-brand-primary":"text-neutral-700 dark:text-neutral-400"}`,children:r.label}),!_&&e.jsx("span",{className:"absolute bottom-2 text-[8px] font-black text-amber-600 bg-amber-50 px-1.5 rounded-full border border-amber-200",children:"Locked"})]},r.id)})})]}),e.jsxs("div",{className:"space-y-6",children:[ae.includes("reddit")&&e.jsxs("div",{className:"p-6 bg-neutral-50 dark:bg-neutral-800/50 rounded-xl border border-neutral-100 dar
1k:border-neutral-700",children:[e.jsx(rt,{label:"Narrow by subreddit",info:"Reddit is huge! By specifying subreddits (like r/saas or r/startups), you help us find the most relevant conversations where your audience actually hangs out.",className:"!mb-3"}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{value:ve,onChange:r=>$e(r.target.value),onKeyDown:r=>r.key==="Enter"&&(r.preventDefault(),Ae()),className:"w-full bg-white dark:bg-neutral-900 border border-neutral-200 dark:border-neutral-700 rounded-lg px-4 py-3 text-sm font-bold focus:ring-1 focus:ring-brand-primary outline-none shadow-none",placeholder:"e.g. r/saas"}),e.jsx("button",{type:"button",onClick:Ae,className:"absolute right-2 top-1/2 -translate-y-1/2 p-1.5 text-neutral-300 hover:text-brand-primary",children:e.jsx(Ye,{className:"w-5 h-5"})})]}),e.jsx("div",{className:"flex flex-wrap gap-2 mt-4",children:je.map(r=>e.jsxs("span",{className:"inline-flex items-center gap-2 px-3 py-1.5 bg-white dark:bg-neutral-900 border border-neutral-100 dark:border-neutral-700 rounded-lg text-xs font-bold text-neutral-600 dar
1k:text-neutral-300 shadow-sm",children:[r,e.jsx("button",{type:"button",onClick:()=>Se(r),className:"hover:text-red-500 transition-colors",children:e.jsx(Re,{className:"w-3.5 h-3.5"})})]},r))})]}),e.jsxs("div",{className:"p-6 bg-neutral-50 dark:bg-neutral-800/50 rounded-xl border border-neutral-100 dark:border-neutral-700",children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsx(rt,{label:"Engagement threshold",info:"Social media is full of noise. Setting a threshold (like 5 points) ensures we only notify you about conversations that are actually getting attention.",className:"!mb-0"}),e.jsxs("span",{className:"text-[11px] font-black text-brand-primary",children:[Me,"+ engagement points"]})]}),e.jsx("input",{type:"range",min:"0",max:"500",step:"5",value:Me,onChange:r=>Ee(parseInt(r.target.value)),className:"w-full h-1.5 bg-neutral-200 dark:bg-neutral-700 rounded-lg appearance-none cursor-pointer accent-brand-primary"}),e.jsx("p",{className:"text-[10px] text-neutral-400 mt-3 font-medium",children:"Define minimum engagement level (likes/upvotes) before a match is reported."})]})]})]}),S===3&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-end mb-6",children:[e.jsx("h4",{className:"text-xl font-bold tracking-tight",children:"Insight layer & Prompt"}),e.jsxs("div",{className:"flex gap-4 text-[10px] font-black text-brand-primary",children:[e.jsx("button",{type:"button",onClick:()=>k(["question-seeking-tool","complaint","comparison","open-discussion","news/trend","buying-signal","feature-request","business-opportunity"]),children:"Select all"}),e.jsx("button",{type:"button",onClick:()=>k([]),className:"text-neutral-400",children:"Deselect"})]})]}),e.jsx("div",{className:"grid grid-cols-2 gap-2",children:[{id:"question-seeking-tool",label:"Tool Seeking",desc:"Identify users looking for alternatives.",icon:e.jsx(qe,{className:"w-4 h-4 text-blue-500"})},{id:"complaint",label:"Complaint",desc:"Find frustrated users on social.",icon:e.jsx(ut,{className:"w-4 h-4 text-red-500"})},{id:"comparison",label:"Comparison",desc:"Rival vs Rival discussions.",icon:e.jsx(oa,{className:"w-4 h-4 text-amber-500"})},{id:"open-discussion",label:"Open Discussion",desc:"General relevant threads.",icon:e.jsx(Ft,{className:"w-4 h-4 text-indigo-500"})},{id:"news/trend",label:"News/Trend",desc:"Market shifts and hot topics.",icon:e.jsx(Pe,{className:"w-3.5 h-3.5 text-emerald-500"})},{id:"buying-signal",label:"Buying Signal",desc:"High intent purchasing signals.",icon:e.jsx(da,{className:"w-3.5 h-3.5 text-purple-500"})},{id:"feature-request",label:"Feature Request",desc:"Missing rival features.",icon:e.jsx(Ye,{className:"w-3.5 h-3.5 text-pink-500"})},{id:"business-opportunity",label:"Business Opportunity",desc:"Partnership or bulk signals.",icon:e.jsx(ct,{className:"w-4 h-4 text-gray-500"})}].map(r=>e.jsxs("button",{type:"button",onClick:()=>k(_=>_.includes(r.id)?_.filter(le=>le!==r.id):[..._,r.id]),className:"flex items-start gap-2.5 p-3 border-2 rounded-xl transition-all relative text-left border-neutral-100 dark:border-neutral-700 hover:border-brand-primary/30 shadow-sm",children:[e.jsx("div",{className:"p-1.5 bg-neutral-50 dark:bg-neutral-800 rounded-lg shrink-0",children:r.icon}),e.jsxs("div",{className:"flex-1 pr-4",children:[e.jsx("h5",{className:"font-bold text-[11px] text-neutral-900 dark:text-neutral-100",children:r.label}),e.jsx("p",{className:"text-[9px] text-neutral-500 mt-0.5 leading-tight font-medium",children:r.desc})]}),fe.includes(r.id)&&e.jsx("div",{className:"absolute top-2 right-2 w-4 h-4 bg-brand-primary rounded-full flex items-center justify-center shadow-sm",children:e.jsx(Ce,{className:"w-2.5 h-2.5 text-white"})})]},r.id))})]}),e.jsxs("div",{children:[e.jsx(rt,{label:"Reply / Engagement prompt",info:"Tell the AI how you like to talk! Should it be professional, cheeky, or purely helpful? This guides the drafted replies we create for you.",className:"!mb-3"}),e.jsx("textarea",{value:de,onChange:r=>Ne(r.target.value),className:"w-full h-32 bg-neutral-50 dark:bg-neutral-900 border border-neutral-200 dark:border-neutral-700 rounded-xl px-6 py-5 text-sm font-bold focus:ring-1 focus:ring-brand-primary outline-none shadow-none",placeholder:"E.g. Focus on B2B SaaS users. Replies should be helpful and establish authority."})]})]})]},"social"),f==="competitor"&&e.jsxs(M.div,{variants:n,initial:"hidden",animate:"visible",exit:"exit",className:"space-y-10",children:[S===1&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx(rt,{label:"Competitor name",info:"Just the common name of the company you're tracking. We'll use this to label your alerts and reports."}),e.jsxs("div",{className:"relative group",children:[e.jsx(va,{className:"absolute left-4 top-1/2 -translate-y-1/2 w-5 h-5 text-neutral-300"}),e.jsx("input",{value:$,onChange:r=>J(r.target.value),className:"w-full pl-12 pr-4 py-4 bg-neutral-50 dark:bg-neutral-900 border-none rounded-2xl font-bold text-sm shadow-none",placeholder:"e.g. Acme Corp"})]})]}),e.jsxs("div",{children:[e.jsx(rt,{label:"Competitor URL",info:"The main website address of your rival. Our engine will use this as the starting point to map their entire digital presence."}),e.jsxs("div",{className:"relative group",children:[e.jsx(Mt,{className:"absolute left-4 top-1/2 -translate-y-1/2 w-5 h-5 text-neutral-300"}),e.jsx("input",{value:E,onChange:r=>U(r.target.value),className:"w-full pl-12 pr-4 py-4 bg-neutral-50 dark:bg-neutral-900 border-none rounded-2xl font-bold text-sm shadow-none",placeholder:"https://compet
1itor.com"})]})]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-center mb-4",children:[e.jsx("span",{className:"text-[10px] font-black text-neutral-400 flex items-center gap-2",children:e.jsxs("cite",{className:"not-italic flex items-center gap-2",children:[e.jsx("cite",{className:"not-italic flex items-center gap-2",children:e.jsx(Ve,{className:"w-4 h-4 text-brand-primary"})})," AI suggested competitors"]})}),e.jsx("button",{type:"button",onClick:ze,disabled:v,className:"text-[10px] font-black text-brand-primary border border-brand-primary/20 rounded-lg px-3 py-1.5 hover:bg-brand-light transition-all flex items-center gap-2 disabled:opacity-50",children:v?e.jsx(nt,{}):e.jsxs(e.Fragment,{children:[e.jsx(Lt,{className:"w-3.5 h-3.5"})," Refresh"]})})]}),e.jsx("div",{className:"flex flex-wrap gap-3",children:Ue.length>0?Ue.map(r=>e.jsxs("button",{type:"button",onClick:()=>at(r),className:`relative flex items-center gap-3 px-4 py-2 rounded-full border-2 transition-all hover:scale-[1.02] active:scale-[0.98] group overflow-hidden ${E===r.website?"border-brand-primary bg-brand-light/20 ring-1 ring-brand-primary shadow-sm":"border-neutral-200 dark:border-neutral-700 bg-white dark:bg-neutral-800 hover:border-brand-primary/50"}`,children:[e.jsx("img",{src:`https://www.google.com/s2/favicons?domain=${r.website||r.name}&sz=128`,className:"w-5 h-5 object-contain rounded-sm",alt:"",onError:_=>{_.target.src=`https://ui-avatars.com/api/?name=${encodeURIComponent(r.name||"C")}&background=random`}}),e.jsx("span",{className:`text-xs font-bold ${E===r.website?"text-brand-primary":"text-neutral-700 dark:text-neutral-200"}`,children:r.name}),e.jsx("div",{className:`absolute top-0 right-0 p-1 bg-brand-primary text-white transition-opacity ${E===r.website?"opacity-100":"opacity-0"}`,children:e.jsx(Ce,{className:"w-3 h-3"})})]},r.id)):e.jsx("p",{className:"text-xs italic text-neutral-400 px-1 font-medium",children:"Click refresh to discover rivals with AI."})})]}),e.jsxs("div",{className:"p-5 bg-neutral-50 dark:bg-neutral-800/50 rounded-xl border border-neutral-200 dark:border-neutral-700 flex items-center justify-between mt-6",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"p-3 bg-brand-light dark:bg-brand-primary/10 rounded-lg",children:e.jsx("cite",{className:"not-italic flex items-center gap-2",children:e.jsx(Ve,{className:"w-5 h-5 text-brand-primary"})})}),e.jsxs("div",{children:[e.jsx("h5",{className:"font-bold text-sm",children:"Generate AI Actions?"}),e.jsx("p",{className:"text-[11px] text-neutral-500 leading-tight mt-0.5 font-medium",children:"Auto-generate counter experiments automatically."})]})]}),e.jsx("button",{type:"button",onClick:()=>re(!ee),className:`relative inline-flex items-center h-6 w-12 rounded-full transition-all ${ee?"bg-brand-primary":"bg-neutral-300 dark:bg-neutral-600"}`,children:e.jsx("span",{className:`inline-block w-4 h-4 transform bg-white rounded-full transition-transform ${ee?"translate-x-7":"translate-x-1"}`})})]})]}),S===2&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-4",children:[e.jsx("h4",{className:"text-xl font-bold tracking-tight",children:"Competitive channels"}),e.jsx("p",{className:"text-sm text-neutral-500 font-medium",children:"Provide social links to track the competitor's digital footprint."})]}),e.jsx("div",{className:"grid grid-cols-2 gap-x-8 gap-y-6",children:[{id:"twitter",label:"Twitter (X)",icon:e.jsx(gt,{className:"w-4 h-4 text-[#1DA1F2]"}),placeholder:"https://twitter.com/acme",info:"Adding their social handles allows us to track their posts and engagement trends."},{id:"linkedin",label:"LinkedIn",icon:e.jsx(ft,{className:"w-4 h-4 text-[#0A66C2]"}),placeholder:"https://linkedin.com/company/acme",info:"Adding their social handles allows us to track their posts and engagement trends."},{id:"facebook",label:"Facebook",icon:e.jsx($t,{className:"w-4 h-4 text-[#1877F2]"}),placeholder:"https://facebook.com/acme",info:"Adding their social handles allows us to track their posts and engagement trends."},{id:"blog",label:"Blog / RSS",icon:e.jsx(yt,{className:"w-4 h-4 text-neutral-400"}),placeholder:"https://acme.com/blog",info:"Stay updated on their thought leadership and product announcements."}].map(r=>e.jsxs("div",{children:[e.jsx(rt,{label:r.label,info:r.info}),e.jsxs("div",{className:"relative group",children:[e.jsx("div",{className:"absolute left-4 top-1/2 -translate-y-1/2",children:r.icon}),e.jsx("input",{value:X[r.id],onChange:_=>se({...X,[r.id]:_.target.value}),className:"w-full pl-12 pr-4 py-3 bg-neutral-50 dark:bg-neutral-900 border border-neutral-100 dar
1k:border-neutral-700 rounded-lg text-xs font-bold focus:ring-1 focus:ring-brand-primary shadow-none",placeholder:r.placeholder})]})]},r.id))})]}),S===3&&e.jsx(e.Fragment,{children:e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-end mb-6",children:[e.jsx("h4",{className:"text-xl font-bold tracking-tight",children:"Monitoring Targets"}),e.jsxs("div",{className:"flex gap-4 text-[10px] font-black text-brand-primary",children:[e.jsx("button",{type:"button",onClick:()=>q(["website_changes","pricing","seo","blog","social_activity","backlinks","keywords","reviews"].filter(r=>{var _,le,Le,Fe,Te,bt;return r==="backlinks"?(le=(_=c==null?void 0:c.access)==null?void 0:_.competitors)==null?void 0:le.backlinks:r==="keywords"?(Fe=(Le=c==null?void 0:c.access)==null?void 0:Le.competitors)==null?void 0:Fe.keywords:r==="reviews"?(bt=(Te=c==null?void 0:c.access)==null?void 0:Te.competitors)==null?void 0:bt.reviews:r==="social_activity"?L:!0})),children:"Select all"}),e.jsx("button",{type:"button",onClick:()=>q([]),className:"text-neutral-400",children:"Deselect"})]})]}),e.jsx("div",{className:"grid grid-cols-2 gap-2.5",children:[{id:"website_changes",label:"Website Changes",desc:"Track visual and structural homepage/product updates.",icon:e.jsx(yt,{className:"w-4 h-4 text-brand-primary"})},{id:"pricing",label:"Pricing changes",desc:"Track tier updates or price adjustments.",icon:e.jsx(ut,{className:"w-4 h-4 text-orange-500"})},{id:"seo",label:"SEO Changes",desc:"Detect ranking shifts and metadata changes.",icon:e.jsx(Ve,{className:"w-4 h-4 text-brand-primary"})},{id:"keywords",label:"Keywords",desc:"Track rival keyword rankings and search visibility.",icon:e.jsx(qe,{className:"w-4 h-4 text-blue-500"})},{id:"blog",label:"Blogs",desc:"Monitor new content and thought leadership.",icon:e.jsx(ot,{className:"w-4 h-4 text-red-500"})},{id:"social_activity",label:"Social Posts",desc:"Monitor new posts on Twitter, LinkedIn, and more.",icon:e.jsx(Rt,{className:"w-4 h-4 text-pink-500"})},{id:"backlinks",label:"Backlinks",desc:"Track new incoming links and referrers.",icon:e.jsx(Mt,{className:"w-4 h-4 text-purple-500"})},{id:"reviews",label:"Reviews",desc:"Track new reviews on Trustpilot, G2, Capterra and more.",icon:e.jsx(Pe,{className:"w-4 h-4 text-indigo-500"})}].map(r=>{var Le,Fe,Te,bt,Kt,Jt;const _=r.id==="backlinks"?!!((Fe=(Le=c==null?void 0:c.access)==null?void 0:Le.competitors)!=null&&Fe.backlinks):r.id==="keywords"?!!((bt=(Te=c==null?void 0:c.access)==null?void 0:Te.competitors)!=null&&bt.keywords):r.id==="reviews"?!!((Jt=(Kt=c==null?void 0:c.access)==null?void 0:Kt.competitors)!=null&&Jt.reviews):r.id==="social_activity"?L:!0,le=N.includes(r.id);return e.jsxs("button",{type:"button",disabled:!_,onClick:()=>_&&He(r.id),className:`relative flex items-start gap-4 p-5 border transition-all rounded-xl text-left ${_?le?"bg-brand-light/20 dark:bg-brand-primary/5 border-neutral-200 dark:border-neutral-600":"border-neutral-100 dark:border-neutral-700 hover:border-brand-primary/30 shadow-none":"opacity-40 grayscale cursor-not-allowed bg-neutral-50/50"}`,children:[e.jsx("div",{className:"p-2 rounded-lg bg-neutral-50 dark:bg-neutral-900",children:Ke.cloneElement(r.icon,{className:"w-4 h-4"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h5",{className:`font-black text-[11px] ${le&&_?"text-brand-primary":"text-neutral-900 dark:text-neutral-100"}`,children:r.label}),e.jsx("p",{className:"text-[9px] text-neutral-500 mt-1 leading-tight line-clamp-2 font-medium",children:r.desc})]}),_&&le&&e.jsx("div",{className:"bg-brand-primary rounded-full p-0.5 ml-auto flex-shrink-0 shadow-sm",children:e.jsx(Ce,{className:"w-2.5 h-2.5 text-white"})}),!_&&e.jsx("div",{className:"absolute top-3 right-3 text-amber-500",children:e.jsx(Ve,{className:"w-4 h-4"})})]},r.id)})})]})})]},"competitor")]})}),e.jsxs("div",{className:"p-6 border-t border-neutral-200 dark:border-neutral-700 flex justify-between items-center bg-neutral-50 dark:bg-neutral-800/50 rounded-b-xl flex-shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>{f==="select"?et():S===1&&!i?z("select"):S>1&&H(S-1)},className:"px-6 py-3 text-[11px] font-black text-neutral-500 hover:text-neutral-900 dark:hover:text-white transition-colors",children:"Go back"}),e.jsx("button",{onClick:()=>
1{if(f==="select")Xe();else if(S<3){if(S===1){if(f==="social"&&F.length===0){s("At least one keyword is required to continue.","error");return}if(f==="website"&&!Z.trim()){s("Website URL is required.","error");return}if(f==="competitor"&&(!$.trim()||!E.trim())){s("Competitor name and website are required.","error");return}}if(f==="social"&&S===2&&ae.length===0){s("Select at least one social channel to continue.","error");return}H(S+1)}else Ze()},disabled:Y||f==="select"&&!y||S===1&&f!=="select"&&!w,className:"px-10 py-4 bg-brand-primary text-white text-[11px] font-black rounded-xl hover:bg-brand-primary/90 transition-all flex items-center disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:scale-100 shadow-none border-none",children:Y?e.jsx(nt,{}):f==="select"||S<3?"Continue":"Launch Monitor"})]})]})]})},vt=a=>{if(!a)return new Date;if(typeof a=="number")return new Date(a);if(typeof a=="string"){let o=a.trim();!o.includes("Z")&&!o.includes("+")&&!o.includes("GMT")&&!/-\d{2}:\d{2}$/.test(o)&&(o=o.replace(" ","T")+"Z");const p=new Date(o);return isNaN(p.getTime())?new Date:p}return new Date(a)},cr=({isOpen:a,onClose:o,onContinue:p,project:i})=>{const{t:l}=Ot(),[m,h]=t.useState(null),[u,c]=t.useState("UTC"),[g]=t.useState(()=>new Date),s=(i==null?void 0:i.initialized_at)||g.toISOString(),[b,f]=t.useState(()=>{const C=vt(s),v=Math.floor((Date.now()-C.getTime())/1e3);return Math.max(0,300-v)}),[z,y]=t.useState(()=>{const C=vt(s);return Date.now()-C.getTime()>=3e5}),[V,S]=t.useState(()=>{const C=vt(s),v=Date.now()-C.getTime();return[{id:1,label:"Configuring article generation settings",status:v>=2e4?"completed":"pending"},{id:2,label:"Setting brand voice and writing style",status:v>=6e4?"completed":"pending"},{id:3,label:"Starting keyword, brand mentions, competitor mentions, and activities monitoring",status:v>=12e4?"completed":"pending"},{id:4,label:"Generating first week content planner keywords",status:v>=18e4?"completed":"pending"},{id:5,label:"Generating current day article",status:v>=24e4?"completed":"pending"},{id:6,label:"Finalizing setup",status:v>=295e3?"completed":"pending"}]});t.useEffect(()=>{i!=null&&i.initialized_at&&(y(!0),f(0),S(C=>C.map(v=>({...v,status:"completed"}))))},[i==null?void 0:i.initialized_at]),t.useEffect(()=>{if(!a||!(i!=null&&i.id))return;It.post(`/projects/${i.id}/initialize`).catch(K=>console.error("Project initialization API failed:",K));const C=vt(s),v=Date.now()-C.getTime(),A=[2e4,6e4,12e4,18e4,24e4,295e3],Z=[];A.forEach((K,O)=>{const he=K-v;if(he>0){const oe=window.setTimeout(()=>{S(ye=>ye.map((ke,ce)=>ce===O?{...ke,status:"completed"}:ke))},he);Z.push(oe)}}),v>=3e5&&(y(!0),f(0));const T=setInterval(()=>{const K=Math.floor((Date.now()-C.getTime())/1e3),O=Math.max(0,300-K);f(O),O<=0&&(clearInterval(T),y(!0))},1e3);return()=>{clearInterval(T),Z.forEach(K=>clearTimeout(K))}},[a,i]);const H=async C=>{c(C);try{await It.put(`/projects/${i.id}`,{name:i.name,url:i.url,description:i.description,timezone:C})}catch(v){console.error("Failed to update project timezone:",v)}};if(t.useEffect(()=>{i!=null&&i.id&&It.get(`/projects/${i.id}/monitors`).then(C=>{const v=C.data.data||[],A=C.data.summary||{total_mentions:0},Z=v.reduce((T,K)=>{const O=K.results_by_channel||{},he=Object.values(O).reduce((ye,ke)=>ye+(Number(ke)||0),0),oe=K.results_count||K.total_matches||he||K.activities_count||K.total_activities||0;return T+Number(oe)},0)+(A.total_mentions||0);h(Z)}).catch(C=>console.error("Failed to fetch actual opportunities count:",C))},[i==null?void 0:i.id]),!a)return null;const Y=C=>{const v=Math.floor(C/60),A=C%60;return`${v}:${A<10?"0":""}${A}`};return e.jsx(be,{children:e.jsxs("div",{className:"fixed inset-0 z-[99999999] flex justify-center items-center p-4",children:[e.jsx(M.div,{initial:{opacity:0}
1,animate:{opacity:1},exit:{opacity:0},className:"absolute inset-0 bg-neutral-50 dark:bg-neutral-900"}),e.jsxs(M.div,{initial:{opacity:0,scale:.9,y:20},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.9,y:20},transition:{type:"spring",damping:25,stiffness:180},className:"relative bg-white dark:bg-neutral-900 rounded-xl border border-neutral-200 dark:border-neutral-800 p-8 shadow-md w-full max-w-5xl overflow-hidden flex flex-col md:flex-row gap-8",children:[e.jsx("div",{className:"absolute top-0 left-1/4 w-96 h-96 bg-brand-primary/5 rounded-full blur-3xl -z-10 pointer-events-none"}),e.jsxs("div",{className:"flex-1 flex flex-col justify-between",children:[z?e.jsxs("div",{children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("span",{className:"text-[10px] font-bold text-green-600 dark:text-green-400 tracking-wide bg-green-500/10 px-2.5 py-1 rounded-md",children:"Setup Completed"}),e.jsx("h3",{className:"text-2xl font-black text-neutral-900 dark:text-white tracking-tight mt-3",children:"Your workspace is ready!"}),e.jsx("p",{className:"text-sm text-neutral-500 mt-1 font-medium leading-relaxed",children:"Here is a summary of what Growlytics has successfully generated and configured for your project:"})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-start gap-3 p-3.5 bg-green-50/40 dark:bg-green-950/10 border border-green-100/50 dark:border-green-900/20 rounded-lg",children:[e.jsx("div",{className:"w-5 h-5 rounded-full bg-green-500 text-white flex items-center justify-center shrink-0 mt-0.5",children:e.jsx(Ce,{className:"w-3.5 h-3.5"})}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-neutral-800 dark:text-neutral-200",children:"Opportunities Discovered"}),e.jsx("p",{className:"text-xs text-neutral-500 mt-0.5",children:"We have found high-intent opportunities for you. You need to act on them."})]})]}),e.jsxs("div",{className:"flex items-start gap-3 p-3.5 bg-brand-primary/5 border border-brand-primary/10 rounded-lg",children:[e.jsx("div",{className:"w-5 h-5 rounded-full bg-brand-primary text-white flex items-center justify-center shrink-0 mt-0.5",children:e.jsx(Ve,{className:"w-3.5 h-3.5"})}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-neutral-800 dark:text-neutral-200",children:"First Article Ready"}),e.jsx("p",{className:"text-xs text-neutral-500 mt-0.5",children:"We have generated your first article, fully optimized and ready to be published."})]})]}),e.jsxs("div",{className:"flex items-start gap-3 p-3.5 bg-blue-50/40 dark:bg-blue-950/10 border border-blue-100/50 dark:border-blue-900/20 rounded-lg",children:[e.jsx("div",{className:"w-5 h-5 rounded-full bg-blue-500 text-white flex items-center justify-center shrink-0 mt-0.5",children:e.jsx(Ce,{className:"w-3.5 h-3.5"})}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-bold text-neutral-800 dark:text-neutral-200",children:"Active Monitoring Running"}),e.jsx("p",{className:"text-xs text-neutral-500 mt-0.5",children:"Competitor reviews, keyword listening, and brand mentions monitors are actively running."})]})]})]})]}):e.jsxs("div",{children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("span",{className:"text-[10px] font-bold text-brand-primary tracking-wide bg-brand-primary/10 px-2.5 py-1 rounded-md",children:"Project Setup"}),e.jsx("h3",{className:"text-2xl font-black text-neutral-900 dark:text-white tracking-tight mt-3",children:"Setting up your project"}),e.jsx("p",{className:"text-sm text-neutral-500 mt-1 font-medium leading-relaxed",children:"We are generating your keywords strategies, analyzing signals, and starting monitors. Please wait while we initialize your workspace."})]}),e.jsx("div",{className:"space-y-3.5",children:(()=>{const C=V.findIndex(v=>v.status==="pending");return V.map((v,A)=>{const Z=v.status==="completed",T=A===C;return e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:`w-5 h-5 rounded-full border-2 flex items-center justify-center shrink-0 mt-0.5 transition-all duration-300
2                                                        ${Z?"border-green-500 bg-green-500 text-white":T?"border-brand-primary bg-transparent text-brand-primary":"border-neutral-200 dark:border-neutral-700"}`,children:Z?e.jsx(Ce,{className:"w-3.5 h-3.5"}):T?e.jsx("div",{className:"w-3 h-3 rounded-full border-2 border-brand-primary border-t-transparent animate-spin"}):null}),e.jsx("span",{className:`text-sm font-bold transition-colors duration-300 ${Z?"text-neutral-400 dark:text-neutral-500 line-through":T?"text-neutral-900 dark:text-white font-black":"text-neutral-300 dark:text-neutral-600"}`,children:v.label})]},v.id)})})()})]}),z?e.jsxs("div",{className:"mt-8 pt-6 border-t border-neutral-100 dar
2k:border-neutral-800 space-y-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-bold text-neutral-500 mb-1.5 uppercase tracking-wider",children:"Select Project Timezone"}),e.jsx("select",{value:u,onChange:C=>H(C.target.value),className:"w-full px-3 py-2 text-sm bg-neutral-50 dark:bg-neutral-800 border border-neutral-200 dark:border-neutral-700 rounded-lg text-neutral-800 dark:text-neutral-200 focus:outline-none focus:border-brand-primary",children:Qa.map(C=>e.jsx("option",{value:C.value,children:C.label},C.value))})]}),e.jsx("button",{onClick:p,className:"w-full py-2.5 px-4 bg-brand-primary text-white text-xs font-bold rounded-lg hover:opacity-95 transition-all flex items-center justify-center gap-1.5 shadow-sm",children:"Get Started"})]}):e.jsxs("div",{className:"mt-8 pt-6 border-t border-neutral-100 dark:border-neutral-800 flex items-center justify-between",children:[e.jsx("span",{className:"text-xs font-bold tracking-wide text-neutral-400",children:"Estimated remaining"}),e.jsx("span",{className:"text-xl font-black text-brand-primary tracking-tighter",children:Y(b)})]})]}),e.jsxs("div",{className:"flex-1 flex flex-col justify-center items-center bg-gradient-to-br from-neutral-50 to-neutral-100/50 dark:from-neutral-950 dark:to-neutral-900 rounded-lg border border-neutral-100 dark:border-neutral-800 overflow-hidden min-h-[320px] relative p-8",children:[e.jsx("div",{className:"absolute inset-0 bg-[radial-gradient(#ff6f00_1px,transparent_1px)] [background-size:16px_16px] opacity-10 dark:opacity-20"}),e.jsxs("div",{className:"relative w-48 h-48 flex items-center justify-center",children:[e.jsx("div",{className:"absolute inset-0 rounded-full border border-brand-primary/20 animate-[spin_10s_linear_infinite]"}),e.jsx("div",{className:"absolute inset-4 rounded-full border border-dashed border-brand-primary/30 animate-[spin_6s_linear_infinite_reverse]"}),e.jsx("div",{className:"absolute inset-10 rounded-full border border-brand-primary/10"}),e.jsx("div",{className:"absolute inset-0 rounded-full bg-gradient-to-tr from-brand-primary/0 via-brand-primary/5 to-brand-primary/25 animate-spin",style:{animationDuration:"3.5s"}}),e.jsx("div",{className:"w-12 h-12 rounded-xl bg-brand-primary/15 border border-brand-primary/30 flex items-center justify-center shadow-lg shadow-brand-primary/25 relative z-10 animate-pulse",children:e.jsx(Ve,{className:"w-6 h-6 text-brand-primary"})}),e.jsxs("div",{className:"absolute top-2 left-4 px-2.5 py-1 bg-white dark:bg-neutral-800 border border-neutral-150 dark:border-neutral-700 rounded-lg shadow-sm text-[10px] font-black text-neutral-600 dar
2k:text-neutral-300 flex items-center gap-1.5 animate-bounce",style:{animationDelay:"0.2s"},children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-green-500 animate-ping"}),"Keywords"]}),e.jsxs("div",{className:"absolute bottom-4 right-1 px-2.5 py-1 bg-white dark:bg-neutral-800 border border-neutral-150 dark:border-neutral-700 rounded-lg shadow-sm text-[10px] font-black text-neutral-600 dark:text-neutral-300 flex items-center gap-1.5 animate-bounce",style:{animationDelay:"0.8s"},children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-blue-500 animate-ping"}),"Signals"]}),e.jsxs("div",{className:"absolute top-1/2 -right-6 -translate-y-1/2 px-2.5 py-1 bg-white dark:bg-neutral-800 border border-neutral-150 dark:border-neutral-700 rounded-lg shadow-sm text-[10px] font-black text-neutral-600 dark:text-neutral-300 flex items-center gap-1.5 animate-bounce",style:{animationDelay:"0.5s"},children:[e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-brand-primary animate-ping"}),"Articles"]})]}),e.jsxs("div",{className:"mt-8 text-center space-y-1 z-10",children:[e.jsxs("div",{className:"text-xs font-bold text-neutral-800 dark:text-neutral-200",children:["Analyzed ",e.jsx("span",{className:"text-brand-primary font-black",children:"48+ keyword paths"})]}),e.jsx("div",{className:"text-[10px] font-semibold text-neutral-400 uppercase tracking-wider",children:"Scanning search indexes..."})]})]})]})]})})},Yt="growlytics_all_campaign_presets",Qt=()=>e.jsxs("div",{className:"relative flex items-center justify-center w-7 h-7",children:[e.jsx("div",{className:"absolute inset-0 border-2 border-neutral-100 dark:border-neutral-700 rounded-full"}),e.jsx("div",{className:"absolute inset-0 border-2 border-brand-primary rounded-full border-t-transparent animate-spin"})]}),Xt=({label:a,value:o,icon:p,color:i})=>e.jsxs("div",{className:"bg-white dark:bg-neutral-800 p-5 rounded-lg border border-neutral-200 dark:border-neutral-700 shadow-sm flex items-center gap-4 h-full text-left transition-all hover:border-brand-primary/20",children:[e.jsx("div",{className:`w-12 h-12 rounded-lg flex items-center justify-center flex-shrink-0 ${i}`,children:p}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-[10px] font-black text-neutral-400 uppercase tracking-widest truncate",children:a}),e.jsx("p",{className:"text-2xl font-black text-neutral-900 dark:text-neutral-100 tracking-tighter truncate",children:o})]})]}),dt=({title:a})=>e.jsx("h3",{className:"text-[10px] font-black text-neutral-900 dark:text-neutral-100 uppercase tracking-widest mb-4",children:a}),ur=({onSelect:a,className:o=""})=>{const[p,i]=t.useState(!1),l=t.useRef(null);t.useEffect(()=>{const h=u=>{l.current&&!l.current.contains(u.target)&&i(!1)};return document.addEventListener("mousedown",h),()=>document.removeEventListener("mousedown",h)},[]);const m=[{id:"competitor",label:"Competitor",description:"Track rival strategies & digital footprints.",icon:e.jsx(ct,{className:"w-5 h-5 text-blue-500"}),bg:"bg-blue-50 dark:bg-blue-900/20"},{id:"social",label:"Social Listening",description:"Monitor keywords & brand mentions on social media.",icon:e.jsx(Pe,{className:"w-5 h-5 text-orange-500"}),bg:"bg-orange-50 dark:bg-orange-900/20"}];return e.jsxs("div",{className:`relative ${o}`,ref:l,children:[e.jsxs("button",{onClick:()=>i(!p),onMouseEnter:()=>i(!0),"data-tour":"new-monitor-button",className:"inline-flex items-center gap-2 bg-brand-primary text-white text-[10px] font-black uppercase tracking-widest rounded hover:bg-brand-primary/90 transition-all active:scale-95 px-4 py-2.5",children:[e.jsx(Ye,{className:"w-4 h-4"}),"New Monitor",e.jsx(Je,{className:`w-3.5 h-3.5 transition-transform ${p?"rotate-180":""}`})]}),e.jsx(be,{children:p&&e.jsx(M.div,{initial:{opacity:0,y:10,scale:.95},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:10,scale:.95},onMouseLeave:()=>i(!1),className:"absolute top-full right-0 mt-4 w-72 bg-white dark:bg-neutral-800 rounded-2xl shadow-xl border border-neutral-100 dark:border-neutral-800 z-[100] p-1.5 overflow-hidden",children:e.jsx("div",{className:"space-y-0.5",children:m.map(h=>e.jsxs("button",{onClick:()=>{a(h.id),i(!1)},className:"w-full flex items-start gap-4 p-4 rounded-xl hover:bg-neutral-50 dark:hover:bg-neutral-800 transition-all text-left group",children:[e.jsx("div",{className:`w-10 h-10 rounded-xl flex-shrink-0 flex items-center justify-center shadow-sm border border-neutral-100 dar
2k:border-neutral-700 ${h.bg}`,children:h.icon}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h4",{className:"text-sm font-black text-neutral-900 dark:text-neutral-100 group-hover:text-brand-primary transition-colors",children:h.label}),e.jsx("p",{className:"text-[11px] text-neutral-500 dark:text-neutral-400 font-medium leading-relaxed mt-0.5",children:h.description})]})]},h.id))})})})]})},xr=({monitors:a,selectedCompositeIds:o,onToggleCompositeId:p,onClear:i,className:l=""})=>{const[m,h]=t.useState(!1),u=t.useRef(null);t.useEffect(()=>{const g=s=>{u.current&&!u.current.contains(s.target)&&h(!1)};return document.addEventListener("mousedown",g),()=>document.removeEventListener("mousedown",g)},[]);const c=t.useMemo(()=>{if(o.length===0)return"All monitors";if(o.length===1){if(o[0]==="brand:mentions")return"Brand Mentions";const g=a.find(s=>`${s.type}:${s.id}`===o[0]);return g?g.name:"1 monitor"}return`${o.length} monitors`},[o,a]);return e.jsxs("div",{className:`relative ${l}`,ref:u,children:[e.jsxs("button",{onClick:()=>h(!m),className:`flex items-center gap-2 px-3 py-2 bg-white dark:bg-neutral-800 border border-neutral-200 dark:border-neutral-700 rounded-lg text-[10px] font-black uppercase tracking-widest text-neutral-600 dar
2k:text-neutral-300 transition-all ${m?"ring-2 ring-brand-primary border-brand-primary":""}`,children:[e.jsx(qe,{className:"w-4 h-4 text-neutral-400"}),e.jsx("span",{className:"truncate max-w-[120px]",children:c}),e.jsx(Je,{className:`w-3 h-3 text-neutral-400 transition-transform ${m?"rotate-180":""}`})]}),e.jsx(be,{children:m&&e.jsxs(M.div,{initial:{opacity:0,y:8,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:8,scale:.98},className:"absolute top-full right-0 mt-2 w-64 bg-white dark:bg-neutral-800 rounded-lg shadow-2xl border border-neutral-200 dark:border-neutral-700 z-[100] p-1 overflow-hidden",children:[e.jsxs("div",{className:"p-2 border-b border-neutral-50 dark:border-neutral-800 flex justify-between items-center mb-1",children:[e.jsx("span",{className:"text-[9px] font-black uppercase text-neutral-400",children:"Trackers"}),e.jsx("button",{onClick:i,className:"text-[9px] font-black uppercase text-neutral-600 dark:text-neutral-300 hover:underline",children:"Select All"})]}),e.jsxs("div",{className:"max-h-80 overflow-y-auto custom-scrollbar space-y-0.5",children:[e.jsxs("button",{onClick:()=>p("brand:mentions"),className:`w-full flex items-center justify-between px-3 py-2.5 rounded-md text-[10px] font-bold uppercase tracking-widest transition-colors ${o.includes("brand:mentions")?"bg-neutral-50 dark:bg-neutral-800 text-neutral-900 dark:text-neutral-100":"text-neutral-500 dark:text-neutral-400 hover:bg-neutral-50 dark:hover:bg-neutral-800/50"}`,children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(xa,{className:"w-3.5 h-3.5"}),e.jsx("span",{children:"Brand Mentions"})]}),e.jsx("div",{className:`w-3.5 h-3.5 rounded-sm border flex items-center justify-center transition-colors ${o.includes("brand:mentions")?"bg-neutral-900 dark:bg-neutral-100 border-neutral-900 dark:border-neutral-100":"border-neutral-300 dark:border-neutral-600"}`,children:o.includes("brand:mentions")&&e.jsx(Ce,{className:"w-2.5 h-2.5 text-white dark:text-neutral-900"})})]}),a.map(g=>{const s=`${g.type}:${g.id}`;return e.jsxs("button",{onClick:()=>p(s),className:`w-full flex items-center justify-between px-3 py-2.5 rounded-lg text-[10px] font-bold uppercase tracking-widest transition-colors ${o.includes(s)?"bg-neutral-50 dark:bg-neutral-800 text-neutral-900 dark:text-neutral-100":"text-neutral-500 dark:text-neutral-400 hover:bg-neutral-50 dark:hover:bg-neutral-800/50"}`,children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[g.type==="competitor"?e.jsx(ct,{className:"w-3.5 h-3.5"}):g.type==="website"?e.jsx(yt,{className:"w-3.5 h-3.5"}):e.jsx(Pe,{className:"w-3.5 h-3.5"}),e.jsx("span",{className:"truncate max-w-[150px]",children:g.name})]}),e.jsx("div",{className:`w-3.5 h-3.5 rounded-sm border flex items-center justify-center transition-colors ${o.includes(s)?"bg-neutral-900 dark:bg-neutral-100 border-neutral-900 dark:border-neutral-100":"border-neutral-300 dark:border-neutral-600"}`,children:o.includes(s)&&e.jsx(Ce,{className:"w-2.5 h-2.5 text-white dark:text-neutral-900"})})]},s)})]})]})})]})},mr=({selectedFilter:a,onFilterChange:o,customDates:p,onCustomDateChange:i})=>{var g;const[l,m]=t.useState(!1),h=t.useRef(null);t.useEffect(()=>{const s=b=>{h.current&&!h.current.contains(b.target)&&m(!1)};return document.addEventListener("mousedown",s),()=>document.removeEventListener("mousedown",s)},[]);const u=[{value:"anytime",label:"All time"},{value:"last_7_days",label:"Last 7 days"},{value:"last_30_days",label:"Last 30 days"},{value:"custom",label:"Custom range"}],c=((g=u.find(s=>s.value===a))==null?void 0:g.label)||"Date";return e.jsxs("div",{className:"relative",ref:h,children:[e.jsxs("button",{type:"button",onClick:()=>m(!l),className:`flex items-center gap-2 px-3 py-2 bg-white dark:bg-neutral-800 border border-neutral-200 dark:border-neutral-700 rounded-lg text-[10px] font-black uppercase tracking-widest text-neutral-600 dar
2k:text-neutral-300 transition-all ${l?"ring-2 ring-brand-primary border-brand-primary":""}`,children:[e.jsx(_t,{className:"w-4 h-4 text-neutral-400"}),e.jsx("span",{children:c}),e.jsx(Je,{className:`w-3.5 h-3.5 text-neutral-400 ml-1 transition-transform ${l?"rotate-180":""}`})]}),e.jsx(be,{children:l&&e.jsxs(M.div,{initial:{opacity:0,y:8,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:8,scale:.98},className:"absolute top-full right-0 mt-2 w-64 bg-white dark:bg-neutral-900 rounded-lg shadow-2xl border border-neutral-200 dark:border-neutral-700 z-50 p-2 overflow-hidden",children:[e.jsx("div",{className:"space-y-1",children:u.map(s=>e.jsx("button",{onClick:()=>{o(s.value),s.value!=="custom"&&m(!1)},className:`w-full text-left px-4 py-2 rounded-md text-[10px] font-bold transition-colors ${a===s.value?"bg-brand-light dark:bg-brand-primary/20 text-brand-primary":"text-neutral-600 dark:text-neutral-300 hover:bg-neutral-50 dark:hover:bg-neutral-800"}`,children:s.label},s.value))}),a==="custom"&&e.jsxs("div",{className:"mt-2 pt-2 border-t border-neutral-100 dark:border-neutral-700 p-3 space-y-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-[9px] font-black uppercase text-neutral-400",children:"Start date"}),e.jsx("input",{type:"date",value:p.startDate,onChange:s=>
2i({startDate:s.target.value,endDate:p.endDate}),className:"w-full px-2 py-1.5 bg-neutral-50 dark:bg-neutral-800 border border-neutral-200 dark:border-neutral-700 rounded-md text-xs font-bold focus:ring-1 focus:ring-brand-primary outline-none"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-[9px] font-black uppercase text-neutral-400",children:"End date"}),e.jsx("input",{type:"date",value:p.endDate,onChange:s=>i({startDate:p.startDate,endDate:s.target.value}),className:"w-full px-2 py-1.5 bg-neutral-50 dark:bg-neutral-800 border border-neutral-200 dark:border-neutral-700 rounded-md text-xs font-bold focus:ring-1 focus:ring-brand-primary outline-none"})]}),e.jsx("button",{onClick:()=>m(!1),className:"w-full py-2 bg-brand-primary text-white text-[10px] font-black uppercase tracking-widest rounded-md active:scale-95 transition-transform",children:"Apply range"})]})]})})]})},br=[{value:"anytime",label:"All time"},{value:"last_7_days",label:"Last 7 days"},{value:"last_30_days",label:"Last 30 days"},{value:"custom",label:"Custom"}],pr=({projectId:a,monitors:o,onSelectMonitor:p,onCreateMonitor:i,onOpenCreateModal:l,refreshKey:m=0})=>{var De,Be,Ue,ie,We,_e;const{addToast:h}=tt(),{selectedProject:u}=useProject(),[c,g]=Ct(),[s,b]=t.useState([]),[f,z]=t.useState(!0),[y,V]=t.useState(!1),[S,H]=t.useState(1),[Y,C]=t.useState(!0),[v,A]=t.useState(null),[Z,T]=t.useState(!0),[K,O]=t.useState(!0),[he,oe]=t.useState(!0),[ye,ke]=t.useState(null),[ce,xe]=t.useState(null),[ge,we]=t.useState(null),$=c.get("date")||"anytime",J=c.get("status")||"all",E=t.useMemo(()=>({startDate:c.get("start")||"",endDate:c.get("end")||""}),[c]),U=t.useMemo(()=>{var x;return((x=c.get("monitors"))==null?void 0:x.split(",").filter(Boolean))||[]},[c]),ee=t.useMemo(()=>{const x=c.get("channels");return x===null?["twitter","linkedin","reddit"]:x.split(",").filter(Boolean)},[c]),[re,X]=t.useState(!1),[se,N]=t.useState([]),[q,B]=t.useState(""),te=t.useRef(null),F=t.useRef(null),R=t.useRef(null),[P,ue]=t.useState(!1),ae=t.useRef(!1),[Q,je]=t.useState({status:J,monitors:U,date:$,start:E.startDate,end:E.endDate});t.useEffect(()=>{je({status:J,monitors:U,date:$,start:E.startDate,end:E.endDate})},[J,U,$,E]),t.useEffect(()=>{const x=localStorage.getItem(Yt);if(x)try{N(JSON.parse(x))}catch{N([])}},[]);const G=x=>{N(x),localStorage.setItem(Yt,JSON.stringify(x))},ve=()=>{if(!q.trim())return h("Please enter a name for the filter","error");const x={id:Date.now().toString(),name:q,filters:{...Q}};G([...se,x]),B(""),h("Filter preset saved!","success")},$e=(x,W)=>{x.stopPropagation(),G(se.filter(pe=>pe.id!==W))},Me=x=>{je(x.filters);const W={status:x.filters.status,monitors:x.filters.monitors.join(",")||null,date:x.filters.date,start:x.filters.date==="custom"?x.filters.start:null,end:x.filters.date==="custom"?x.filters.end:null};I(W),X(!1)},Ee=t.useCallback(async()=>{T(!0);try{const x=await Sa(a);A(x.data.data)}catch(x){console.error("Failed to fetch project stats",x)}finally{T(!1)}},[a]),ne=x=>x?`${ht.endsWith("/")?ht:`${ht}/`}storage/${x}`:null,I=t.useCallback(x=>{const W=new URLSearchParams(c);Object.entries(x).forEach(([pe,me])=>{me&&me!=="all"&&me!=="anytime"?W.set(pe,me):W.delete(pe)}),W.delete("page"),g(W,{replace:!0})},[c,g]),d=t.useCallback((x,W)=>{I({[x]:W})},[I]),D=x=>{const W=U.includes(x)?U.filter(pe=>pe!==x):[...U,x];d("monitors",W.join(",")||null)},fe=t.useCallback(async x=>{if(ae.current)return;ae.current=!0;const W=U.includes("brand:mentions"),pe=U.filter(Se=>Se!=="brand:mentions");let me=[];if(U.length>0?(me=o.filter(Se=>pe.includes(`${Se.type}:${Se.id}`)),W&&me.push({id:"mentions",type:"brand",name:"Brand Mentions"})):me=[...o.filter(Se=>["competitor","website","social_listener","keyword"].includes(Se.type)),{id:"mentions",type:"brand",name:"Brand Mentions"}],me.length===0&&o.length>0){b([]),z(!1),V(!1),ae.current=!1;return}const Ae=x===1?10:5;try{const Se=me.filter(n=>n.type==="social_listener"||n.type==="keyword"),Qe=me.filter(n=>n.type!=="social_listener"&&n.type!=="keyword"),ze={};J==="saved"?ze.saved_only=!0:J==="unseen"&&(ze.unseen=!0);const at=Qe.map(async n=>{try{if(n.type==="competitor")return((await fa({project_id:a,competitor_id:n.id,...ze,date_filter:$,per_page:Ae,page:x,start_date:$==="custom"?E.startDate:void 0,end_date:$==="custom"?E.endDate:void 0})).data.data||[]).map(j=>({...j,monitor:n}));if(n.type==="website"){let j=(await ca(n.id,$,$==="custom"?E.startDate:void 0,$==="custom"?E.endDate:void 0)).data.activities||[];return J==="saved"&&(j=j.filter(L=>L.is_saved)),j.slice((x-1)*Ae,x*Ae).map(L=>{let Oe=null;if(L.blog_posts&&L.blog_posts.length>0){const Ie=L.blog_posts[0];Oe=JSON.stringify({title:Ie.title,url:Ie.link,description:L.summary,image:L.after_screenshot?ne(L.after_screenshot):null})}else L.changes&&L.changes.length>0&&(Oe=JSON.stringify({summary:L.summary,changes:L.changes.map(Ie=>({type:Ie.type,field:Ie.selector,old:Ie.old,new:Ie.new,reasoning:Ie.reason}))}));return{id:L.id,type:L.activity_type==="blog_post"?"blog":"website",summary:L.summary,created_at:L.created_at,posted_at:L.posted_at||null,before_screenshot:L.before_screenshot,after_screenshot:L.after_screenshot,diff_summary:Oe,monitor:n}})}else if(n.type==="brand")return((await _a({project_id:a,...ze,sentiment:J==="positive"||J==="negative"||J==="neutral"?J:void 0,date_range:$==="anytime"?void 0:$,page:x,per_page:Ae,start_date:$==="custom"?E.startDate:void 0,end_date:$==="custom"?E.endDate:void 0})).data.data||[]).map(j=>{var L,Oe,Ie;return{id:j.id,type:"social",is_brand_mention:!0,summary:j.text,created_at:j.created_at,posted_at:j.posted_at||null,channel:j.channel||"social",seo_data:JSON.stringify({...j,project_id:a,listener_id:0,post_text:j.text,post_link:j.url,author_name:j.author,classification:j.classification||JSON.stringify({sentiment:j.sentiment,intent:j.intent,confidence:j.confidence,summary:j.summary}),potential_reply:j.ai_reply||j.potential_reply||null,likes:((L=j.metrics)==null?void 0:L.likes)||0,shares:((Oe=j.metrics)==null?void 0:Oe.shares)||0,comments:((Ie=j.metrics)==null?void 0:Ie.comments)||0,metrics:j.metrics}),monitor:{...n,name:"Brand Mention"}}});return[]}catch{return[]}}),He=(async()=>
2{if(Se.length===0)return[];try{const n=Se.map(j=>j.id).join(",");return((await ua(a,{listener_id:n,...ze,date_range:$==="anytime"?void 0:$,start_date:$==="custom"?E.startDate:void 0,end_date:$==="custom"?E.endDate:void 0,per_page:Ae*Se.length})).data.data||[]).map(j=>({id:j.id,type:"social",summary:j.post_text,created_at:j.created_at,posted_at:j.posted_at||null,channel:j.channel||"social",seo_data:JSON.stringify(j),monitor:Se.find(L=>L.id===j.listener_id)||Se[0]}))}catch{return[]}})(),[Xe,Ze]=await Promise.all([Promise.all(at),He]),et=[...Xe.flat(),...Ze].filter(n=>{var j;const w=(n.channel||((j=n.monitor)==null?void 0:j.channel)||"social").toLowerCase();return n.type==="social"||n.is_brand_mention?ee.includes(w):!0}).sort((n,w)=>new Date(w.created_at).getTime()-new Date(n.created_at).getTime());b(x===1?et:n=>{const w=new Set(n.map(L=>`${L.monitor.type}-${L.monitor.id}-${L.id}`)),j=et.filter(L=>!w.has(`${L.monitor.type}-${L.monitor.id}-${L.id}`));return[...n,...j]}),et.length===0&&C(!1)}catch{h("Failed to aggregate activities.","error")}finally{z(!1),V(!1),ae.current=!1}},[a,o,h,$,E,U,J,ee]),k=async x=>{if(!(!u||u.is_demo===1))try{await ma(a,{result_id:x.id,action_type:"social_engagement",notes:`Engagement opportunity from ${x.channel}`}),h("AI Action created","success")}catch{h("Failed to create action","error")}};t.useEffect(()=>{if($==="custom"&&(!E.startDate||!E.endDate))return;Ee(),H(1),C(!0),z(!0);const x=setTimeout(()=>{fe(1)},150);return()=>clearTimeout(x)},[$,E,U,J,Ee,m,a,ee]),t.useEffect(()=>{if(f||y||!Y)return;const x=F.current;if(!x)return;const W=new IntersectionObserver(([pe])=>{pe.isIntersecting&&Y&&!y&&!ae.current&&(V(!0),H(me=>{const Ae=me+1;return fe(Ae),Ae}))},{threshold:.1});return W.observe(x),()=>W.disconnect()},[f,y,Y,fe]),t.useEffect(()=>{const x=R.current;if(!x)return;const W=x.closest("main")||window,pe=new IntersectionObserver(([me])=>{me.rootBounds?ue(me.boundingClientRect.top<me.rootBounds.top):ue(!me.isIntersecting&&me.boundingClientRect.top<0)},{threshold:[0,1],root:W instanceof Element?W:null});return pe.observe(x),()=>pe.disconnect()},[f]);const de=t.useMemo(()=>U.length>0||$!=="anytime"||J!=="all",[U,$,J]),Ne=()=>e.jsxs("div",{className:"max-w-4xl space-y-12 py-2 text-left",children:[e.jsxs("div",{children:[e.jsx(dt,{title:"AGGREGATED ACTIVITY STREAM"}
2),e.jsxs("p",{className:"text-xl text-neutral-600 dark:text-neutral-300 font-medium leading-relaxed",children:["This unified view aggregates strategic movements from all your ",e.jsxs("span",{className:"font-black text-neutral-900 dark:text-neutral-100 underline decoration-brand-primary decoration-2 underline-offset-4",children:["“",o.length," active monitors”"]})," including visual drifts, social signals, and competitor pivots."]})]}),e.jsxs("div",{className:"p-8 bg-neutral-50/50 dark:bg-neutral-900/30 rounded-2xl border border-neutral-100 dark:border-neutral-800",children:[e.jsx("div",{className:"flex flex-col md:flex-row md:items-center justify-between gap-6",children:e.jsxs("div",{className:"flex items-center gap-5",children:[e.jsx(Qt,{}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-base font-black text-neutral-900 dark:text-neutral-100 tracking-tight uppercase",children:"Scanning for new signals"}),e.jsx("p",{className:"text-[11px] text-neutral-500 font-bold mt-0.5",children:"Established baseline for all active trackers"})]})]})}),e.jsx("p",{className:"text-sm text-neutral-500 dark:text-neutral-400 font-medium leading-relaxed mt-6",children:"Our intelligence engine is currently indexing new arrivals across your digital landscape. As soon as a relevant shift is detected, it will be classified by sentiment, intent, and priority before appearing in this feed."})]}),e.jsxs("div",{children:[e.jsx(dt,{title:"RELEVANCE POLICY"}
2),e.jsx("p",{className:"text-base text-neutral-600 dark:text-neutral-400 font-medium leading-relaxed",children:"To maintain focus, we prioritize high-impact movements that represent real strategic intent. Routine maintenance and minor cosmetic updates are automatically filtered out to keep your team agile."})]})]});return f&&s.length===0?e.jsx(At,{type:"dashboard"}):e.jsxs("div",{className:"w-full h-full endurance-scroll relative",children:[e.jsx("div",{ref:R,className:"h-px w-full"}),e.jsx(Bt,{imageUrl:ye,onClose:()=>ke(null)}),e.jsx(Ut,{isOpen:!!ce,onClose:()=>xe(null),activity:ce,competitor:void 0}),e.jsx(Gt,{isOpen:!!ge,onClose:()=>we(null),activity:ge,competitor:void 0}),e.jsxs("div",{className:`sticky top-0 z-20 transition-all duration-300 ${P?"bg-white/95 dark:bg-neutral-900/95 backdrop-blur border-b border-neutral-100 dark:border-neutral-800 py-3 shadow-sm":"bg-transparent py-4 md:py-6"} px-6 md:px-8 flex justify-between items-center no-print`,children:[e.jsx("h2",{className:`font-black text-neutral-900 dark:text-neutral-100 tracking-tight transition-all duration-300 ${P?"text-xl":"text-2xl"}`,children:"Activities"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(xr,{monitors:o,selectedCompositeIds:U,onToggleCompositeId:D,onClear:()=>d("monitors",null),className:"hidden lg:block"}),e.jsx(mr,{selectedFilter:$,onFilterChange:x=>d("date",x),customDates:E,onCustomDateChange:x=>{d("start",x.startDate),d("end",x.endDate)}}),e.jsxs("div",{className:"relative",ref:te,children:[e.jsxs("button",{onClick:()=>X(!re),className:`flex items-center gap-2 px-3 py-2 bg-white dark:bg-neutral-800 border border-neutral-200 dark:border-neutral-700 rounded-lg text-xs font-bold transition-all ${re?"ring-2 ring-brand-primary border-brand-primary":""}`,children:[e.jsx(Pt,{className:"w-3.5 h-3.5 text-neutral-400"}),e.jsx("span",{children:"All filters"}),e.jsx(Je,{className:`w-3 h-3 text-neutral-400 ml-1 transition-transform duration-300 ${re?"rotate-180":""}`})]}),e.jsx(be,{children:re&&e.jsxs(M.div,{initial:{opacity:0,y:12,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:12,scale:.98},className:"absolute top-full right-0 mt-3 w-80 max-h-[400px] bg-white dark:bg-neutral-900 rounded-xl shadow-xl border border-neutral-100 dark:border-neutral-700 z-100 p-1 overflow-hidden flex flex-col",children:[e.jsxs("div",{className:"flex-1 overflow-y-auto custom-scrollbar",children:[e.jsxs("div",{className:"p-4 bg-neutral-50 dark:bg-neutral-950/40 border-b border-neutral-100 dark:border-neutral-700",children:[e.jsx(dt,{title:"Saved filter presets"}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[se.map(x=>e.jsxs("button",{type:"button",onClick:()=>Me(x),className:"px-2.5 py-1.5 bg-white dark:bg-neutral-800 border border-neutral-200 dark:border-neutral-700 rounded-lg text-[10px] font-bold text-neutral-600 dar
2k:text-neutral-300 flex items-center gap-2 group",children:[x.name,e.jsx("span",{onClick:W=>$e(W,x.id),className:"opacity-0 group-hover:opacity-100 hover:text-red-500 transition-opacity",children:e.jsx(Re,{className:"w-3 h-3"})})]},x.id)),se.length===0&&e.jsx("p",{className:"text-[10px] text-neutral-400 font-bold uppercase tracking-widest",children:"No presets saved"})]})]}),e.jsxs("div",{className:"p-5 space-y-8 text-left",children:[e.jsxs("div",{children:[e.jsx(dt,{title:"Activity status"}),e.jsx("div",{className:"grid grid-cols-3 gap-2",children:[{id:"all",label:"All",icon:e.jsx(Nt,{className:"w-3 h-3"})},{id:"unseen",label:"Unseen",icon:e.jsx(mt,{className:"w-3 h-3"})},{id:"saved",label:"Saved",icon:e.jsx(Wt,{className:"w-3 h-3"})}].map(x=>e.jsxs("button",{onClick:()=>je(W=>({...W,status:x.id})),className:`flex items-center justify-center gap-1.5 py-2 px-1 rounded-lg border-2 text-[9px] font-black uppercase tracking-widest transition-all ${Q.status===x.id?"bg-neutral-900 border-neutral-900 text-white dark:bg-neutral-100 dark:text-neutral-900 dark:border-neutral-100 shadow-sm":"bg-white dark:bg-neutral-800 border border-neutral-100 dark:border-neutral-700 text-neutral-400"}`,children:[x.icon,x.label]},x.id))})]}),e.jsxs("div",{children:[e.jsx(dt,{title:"Monitors"}),e.jsx("div",{className:"max-h-40 overflow-y-auto custom-scrollbar px-1",children:e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("button",{onClick:()=>{const x="brand:mentions",W=Q.monitors.includes(x)?Q.monitors.filter(pe=>pe!==x):[...Q.monitors,x];je(pe=>({...pe,monitors:W}))},className:`flex items-center justify-between px-3 py-2 rounded-lg text-[11px] font-bold border transition-all ${Q.monitors.includes("brand:mentions")?"border-brand-primary bg-brand-light/40 text-brand-primary":"border-neutral-100 dark:border-neutral-700 text-neutral-400 hover:border-brand-primary/30"}`,children:[e.jsxs("div",{className:"flex items-center gap-2 truncate",children:[e.jsx(xa,{className:"w-3.5 h-3.5"}),e.jsx("span",{className:"truncate",children:"Brand Mentions"})]}),Q.monitors.includes("brand:mentions")&&e.jsx(Ce,{className:"w-3.5 h-3.5 shrink-0"})]}),o.map(x=>{const W=`${x.type}:${x.id}`,pe=Q.monitors.includes(W);return e.jsxs("button",{onClick:()=>{const me=pe?Q.monitors.filter(Ae=>Ae!==W):[...Q.monitors,W];je(Ae=>({...Ae,monitors:me}))},className:`flex items-center justify-between px-3 py-2 rounded-lg text-[11px] font-bold border transition-all ${pe?"border-brand-primary bg-brand-light/40 text-brand-primary":"border-neutral-100 dark:border-neutral-700 text-neutral-400 hover:border-brand-primary/30"}`,children:[e.jsx("span",{className:"truncate pr-1",children:x.name}),pe&&e.jsx(Ce,{className:"w-3.5 h-3.5 shrink-0"})]},W)})]})})]}),e.jsxs("div",{children:[e.jsx(dt,{title:"Timeframe"}),e.jsx("div",{className:"grid grid-cols-3 gap-2 mb-4",children:br.map(x=>e.jsx("button",{type:"button",onClick:()=>je(W=>({...W,date:x.value})),className:`py-1.5 px-1 rounded-lg border text-[10px] font-bold transition-all ${Q.date===x.value?"bg-neutral-900 border-neutral-900 text-white dark:bg-neutral-100 dark:text-neutral-900":"bg-white dark:bg-neutral-800 border border-neutral-100 dark:border-neutral-700 text-neutral-400"}`,children:x.label},x.value))}),Q.date==="custom"&&e.jsxs("div",{className:"grid grid-cols-2 gap-3 mt-4 p-4 bg-neutral-50 dark:bg-neutral-950/40 rounded-xl border border-neutral-100 dark:border-neutral-800",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-[9px] font-black uppercase text-neutral-400",children:"Start"}),e.jsx("input",{type:"date",value:Q.start,onChange:x=>je(W=>({...W,start:x.target.value})),className:"w-full bg-white dark:bg-neutral-900 border border-neutral-200 dark:border-neutral-700 rounded p-1.5 text-[10px] font-bold"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-[9px] font-black uppercase text-neutral-400",children:"End"}),e.jsx("input",{type:"date",value:Q.end,onChange:x=>je(W=>({...W,end:x.target.value})),className:"w-full bg-white dark:bg-neutral-900 border border-neutral-200 dark:border-neutral-700 rounded p-1.5 text-[10px] font-bold"})]})]})]}
2),e.jsx("div",{className:"pt-4 border-t border-neutral-100 dark:border-neutral-800",children:e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",placeholder:"Save filter as...",value:q,onChange:x=>B(x.target.value),className:"flex-1 px-3 py-1.5 bg-neutral-50 dark:bg-neutral-950 border border-neutral-100 dark:border-neutral-800 rounded-lg text-xs font-bold outline-none focus:ring-1 focus:ring-brand-primary"}),e.jsx("button",{onClick:ve,className:"px-3 py-1.5 bg-neutral-100 dark:bg-neutral-800 text-neutral-600 dark:text-neutral-200 text-xs font-bold rounded-lg transition-all",children:"Save"})]})})]})]}),e.jsxs("div",{className:"p-4 bg-white dark:bg-neutral-900 border-t border-neutral-100 dark:border-neutral-800 flex justify-between shrink-0",children:[e.jsx("button",{type:"button",onClick:()=>je({status:"all",monitors:[],date:"anytime",start:"",end:""}),className:"px-4 py-2 text-xs font-bold text-neutral-400 hover:text-neutral-600",children:"Reset"}),e.jsx("button",{onClick:()=>{I({status:Q.status,monitors:Q.monitors.join(",")||null,date:Q.date,start:Q.date==="custom"?Q.start:null,end:
2Q.date==="custom"?Q.end:null}),X(!1)},className:"px-8 py-2.5 bg-neutral-900 text-white dark:bg-neutral-100 dark:text-neutral-900 text-xs font-bold rounded-lg active:scale-95 transition-transform shadow-sm",children:"Apply filters"})]})]})})]}),e.jsx(ur,{onSelect:l,className:"hidden lg:inline-flex"})]})]}),e.jsxs("div",{className:"px-6 md:px-8 pb-4 grid grid-cols-1 md:grid-cols-3 gap-4",children:[e.jsx(Xt,{label:"Total active monitors",value:((De=v==null?void 0:v.campaigns)==null?void 0:De.total_campaigns)??0,icon:e.jsx(Aa,{className:"w-6 h-6 text-brand-primary"}),color:"bg-brand-light dark:bg-brand-primary/10"}),e.jsx(Xt,{label:"total activites",value:(((Be=v==null?void 0:v.activities)==null?void 0:Be.total_activities)??0).toLocaleString(),icon:e.jsx(ut,{className:"w-6 h-6 text-blue-500"}),color:"bg-blue-50 dark:bg-blue-900/10"}),e.jsxs("div",{className:"bg-white dark:bg-neutral-800 p-5 rounded-lg border border-neutral-200 dark:border-neutral-700 shadow-sm text-left h-full transition-all hover:border-brand-primary/20",children:[e.jsxs("div",{className:"flex items-center gap-3 mb-3 border-b border-neutral-50 dark:border-neutral-700/50 pb-2",children:[e.jsx(Nt,{className:"w-4 h-4 text-neutral-400"}),e.jsx("span",{className:"text-[10px] font-black text-neutral-400 uppercase tracking-widest",children:"Monitor breakdown"})]}),e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex justify-between text-[11px] font-bold",children:[e.jsx("span",{className:"text-neutral-500",children:"Social Listening"}),e.jsx("span",{className:"text-neutral-900 dark:text-neutral-100",children:((Ue=v==null?void 0:v.campaigns)==null?void 0:Ue.social_listeners)??0})]}),e.jsxs("div",{className:"flex justify-between text-[11px] font-bold",children:[e.jsx("span",{className:"text-neutral-500",children:"Competitors"}),e.jsx("span",{className:"text-neutral-900 dark:text-neutral-100",children:((ie=v==null?void 0:v.campaigns)==null?void 0:ie.competitors)??0})]}),e.jsxs("div",{className:"flex justify-between text-[11px] font-bold",children:[e.jsx("span",{className:"text-neutral-500",children:"Websites"}),e.jsx("span",{className:"text-neutral-900 dark:text-neutral-100",children:((We=v==null?void 0:v.campaigns)==null?void 0:We.websites)??0})]})]})]})]}),e.jsx("div",{className:"px-6 md:px-8 pb-10 pt-2 space-y-4",children:s.length>0?e.jsxs(e.Fragment,{children:[e.jsx(be,{children:K&&e.jsxs(M.div,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},exit:{opacity:0,scale:.98},className:"bg-white dark:bg-neutral-800 border border-neutral-200 dark:border-neutral-700 p-6 flex items-start gap-5 transition-all shadow-sm rounded-lg text-left",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"text-[10px] font-black uppercase tracking-[0.2em] text-neutral-900 dark:text-neutral-100 mb-3",children:"Tracking Activated"}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-sm text-neutral-600 dar
2k:text-neutral-400 leading-relaxed font-medium",children:"Tracking engine activated. We've taken the first snapshot of your keywords, competitor activities, and website changes to establish a baseline."}),e.jsxs("p",{className:"text-sm text-neutral-600 dark:text-neutral-400 leading-relaxed font-medium",children:["Currently, we've detected ",e.jsx("span",{className:"text-brand-primary font-black",children:(((_e=v==null?void 0:v.activities)==null?void 0:_e.total_activities)||0).toLocaleString()})," signals across your digital landscape. You can add more trackers by clicking the ",e.jsx("span",{className:"text-brand-primary font-black uppercase tracking-widest",children:"New Monitor"})," button."]})]})]}),e.jsx("button",{onClick:()=>O(!1),className:"p-1.5 bg-red-50 dark:bg-red-900/20 text-red-500 rounded hover:bg-red-100 dark:hover:bg-red-900/30 transition-colors shrink-0",children:e.jsx(Re,{className:"w-4 h-4"})})]})}),e.jsxs("div",{className:"space-y-4 pb-20",children:[s.map((x,W)=>{var me,Ae,Se,Qe,ze,at,He,Xe;if((((me=x.monitor)==null?void 0:me.type)==="social_listener"||((Ae=x.monitor)==null?void 0:Ae.type)==="keyword"||((Se=x.monitor)==null?void 0:Se.type)==="brand"||x.is_brand_mention)&&x.seo_data)try{const Ze=JSON.parse(x.seo_data);return e.jsx(ya,{result:Ze,onOpenLightbox:ke,onCreateAiAction:k,highlightKeywords:he,className:"hover:border-brand-primary transition-all duration-300 rounded-lg text-left"},`${((Qe=x.monitor)==null?void 0:Qe.type)||"brand"}-${((ze=x.monitor)==null?void 0:ze.id)||0}-${x.id}-${W}`)}catch(Ze){console.error("Failed to parse social result",Ze)}return e.jsx(Vt,{activity:x,competitor:((at=x.monitor)==null?void 0:at.type)==="competitor"?x.monitor:void 0,viewMode:"grid",disableLink:!0,onViewChange:()=>xe(x),onCreateAction:()=>we(x),className:"hover:border-brand-primary transition-all duration-300 rounded-lg text-left"},`${((He=x.monitor)==null?void 0:He.type)||"activity"}-${((Xe=x.monitor)==null?void 0:Xe.id)||0}-${x.id}-${W}`)}),e.jsx("div",{ref:F,className:"h-20 w-full flex items-center justify-center mt-4",children:y&&e.jsx(Qt,{})})]})]}):e.jsx("div",{className:"flex flex-col items-center justify-center h-full",children:de?e.jsxs("div",{className:"text-center py-20 bg-white dark:bg-neutral-800 rounded-xl border border-neutral-100 dark:border-neutral-700 border-dashed w-full max-w-2xl mx-auto shadow-sm",children:[e.jsx("div",{className:"w-14 h-14 rounded-xl bg-neutral-50 dark:bg-neutral-900 flex items-center justify-center mx-auto mb-6 border border-neutral-100 dark:border-neutral-700 shadow-sm",children:e.jsx(Pe,{className:"w-6 h-6 text-neutral-200"})}),e.jsx("h3",{className:"text-lg font-black text-neutral-900 dark:text-neutral-100 tracking-tight uppercase",children:"No matching discoveries"}),e.jsx("p",{className:"text-neutral-400 text-xs font-bold uppercase tracking-widest mt-2 px-8",children:"Try broadening your filters or resetting to view the full feed."}),e.jsx("button",{onClick:()=>{I({monitors:null,date:"anytime",status:"all",start:null,end:null,channels:null})},className:"mt-8 px-8 py-3 bg-brand-primary text-white rounded-lg text-[10px] font-black uppercase tracking-[0.2em] shadow-lg shadow-brand-primary/20 hover:scale-105 active:scale-95 transition-all",children:"Clear all filters"})]}):Ne()})})]})},hr=({className:a="w-6 h-6"})=>e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:a,children:e.jsx("path",{fillRule:"evenodd",d:"M12.963 2.286a.75.75 0 0 0-1.071-.136 9.742 9.742 0 0 0-3.539 6.176 7.547 7.547 0 0 1-1.705-1.715.75.75 0 0 0-1.152-.082A9 9 0 1 0 15.68 4.534a7.46 7.46 0 0 1-2.717-2.248ZM15.75 14.25a3.75 3.75 0 1 1-7.313-1.172c.628.465 1.35.81 2.133 1a5.99 5.99 0 0 1 1.925-3.546 3.75 3.75 0 0 1 3.255 3.718Z",clipRule:"evenodd"})}),gr=({isBlogConnected:a,isEmailSetup:o,opportunitiesCompleted:p,articlesPublished:i})=>{const{selectedProject:l,permissions:m}=lt(),[h,u]=t.useState(!1),c=Ke.useRef(null);Ke.useEffect(()=>{const y=V=>{c.current&&!c.current.contains(V.target)&&u(!1)};return document.addEventListener("mousedown",y),()=>document.removeEventListener("mousedown",y)},[]);const g=Ke.useMemo(()=>
2{if(!m)return[];const{usage:y}=m;return[{id:1,text:"Connect brand",completed:!!(l!=null&&l.url)},{id:2,text:"Setup keywords & competitors",completed:y.social_monitors>0&&y.competitors>0},{id:3,text:"Connect blog integration",completed:a},{id:4,text:"Review an opportunity",completed:p>0},{id:5,text:"Publish an article",completed:i>0},{id:6,text:"Setup email outreach for backlinks",completed:o}]},[m,l,a,o,p,i]),s=g.filter(y=>y.completed).length,b=g.length===0?0:Math.round(s/g.length*100),f=2*Math.PI*15,z=f-b/100*f;return e.jsxs("div",{className:"relative",ref:c,children:[e.jsxs("button",{onClick:()=>u(!h),className:"flex items-center gap-3 px-4 py-2 bg-white dark:bg-neutral-800 border border-neutral-200 dark:border-neutral-700 rounded-xl hover:bg-neutral-50 dark:hover:bg-neutral-700 transition-colors shadow-sm min-h-[46px]",children:[e.jsxs("div",{className:"relative w-9 h-9 flex items-center justify-center shrink-0",children:[e.jsxs("svg",{className:"transform -rotate-90 w-9 h-9",viewBox:"0 0 36 36",children:[e.jsx("circle",{cx:"18",cy:"18",r:"15",stroke:"currentColor",strokeWidth:"3",fill:"transparent",className:"text-neutral-100 dark:text-neutral-700"}),e.jsx("circle",{cx:"18",cy:"18",r:"15",stroke:"currentColor",strokeWidth:"3",fill:"transparent",strokeDasharray:f,strokeDashoffset:z,className:"text-brand-primary transition-all duration-500"})]}),e.jsxs("span",{className:"absolute text-[10px] font-black text-neutral-800 dark:text-neutral-100",children:[s,"/",g.length]})]}),e.jsxs("div",{className:"flex flex-col text-left",children:[e.jsx("span",{className:"text-[9px] font-black text-neutral-400 uppercase tracking-widest leading-none",children:"Setup completion"}),e.jsxs("span",{className:"text-xs font-black text-brand-primary mt-1 leading-none",children:[b,"% Completed"]})]})]}),e.jsx(be,{children:h&&e.jsxs(M.div,{initial:{opacity:0,y:10,scale:.95},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:10,scale:.95},className:"absolute right-0 top-full mt-2 w-80 bg-white dark:bg-neutral-900 border border-neutral-200 dark:border-neutral-800 shadow-xl rounded-2xl z-50 overflow-hidden",children:[e.jsxs("div",{className:"p-5 border-b border-neutral-100 dark:border-neutral-800",children:[e.jsx("h4",{className:"text-lg font-bold text-neutral-900 dark:text-neutral-100 tracking-tight mb-1",children:"Quickstart Guide"}),e.jsxs("p",{className:"text-[10px] font-bold text-neutral-400 uppercase tracking-widest mb-3",children:[s," OF ",g.length," COMPLETED (",b,"%)"]}),e.jsx("div",{className:"h-2 w-full bg-neutral-100 dark:bg-neutral-850 rounded-full overflow-hidden",children:e.jsx(M.div,{initial:{width:0},animate:{width:`${b}%`},className:"h-full bg-brand-primary rounded-full"})})]}),e.jsx("div",{className:"p-3 max-h-[350px] overflow-y-auto",children:e.jsx("div",{className:"space-y-1.5",children:g.map(y=>e.jsxs("div",{className:"flex items-center justify-between p-3 bg-white dark:bg-neutral-900 border border-neutral-100 dark:border-neutral-800 rounded-xl group transition-all",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:`w-7 h-7 rounded-full flex items-center justify-center text-[10px] font-bold transition-all ${y.completed?"bg-brand-light dark:bg-brand-primary/10 text-brand-primary":"bg-orange-50 dark:bg-orange-900/20 text-orange-500"}`,children:y.id}),e.jsx("span",{className:`text-xs font-medium ${y.completed?"text-neutral-400 line-through":"text-neutral-700 dark:text-neutral-200"}`,children:y.text})]}),y.completed?e.jsx("div",{className:"w-5 h-5 rounded-full bg-green-50 dark:bg-green-900/30 flex items-center justify-center text-green-500",children:e.jsx(Ce,{className:"w-3 h-3"})}):e.jsx("div",{className:"w-5 h-5 rounded-full flex items-center justify-center text-neutral-300",children:e.jsx($a,{className:"w-3 h-3"})})]},y.id))})})]})})]})},fr=()=>{var se;const{user:a}=ba(),{selectedProject:o,badgeCounts:p}=lt(),i=xt(),[l,m]=t.useState(null),[h,u]=t.useState(!1),[c,g]=t.useState(!0),[s,b]=t.useState(!1),[f,z]=t.useState(!1),[y,V]=t.useState(3.3),[S,H]=t.useState(0),[Y,C]=t.useState(!!localStorage.getItem("growlytics_blog_promo_dismissed")),[v,A]=t.useState(!1),Z=t.useCallback(()=>{o&&rr(o.id).then(N=>{const q=N.data.integrations||{},B=q.active_platform;let te=!1;if(B){const F=q[B];F&&(B==="wordpress_com"?te=!!F.access_token:B==="wordpress"?te=!!F.token&&!!F.url:B==="webhook"?te=!!F.url:B==="manual"?te=!!F.notes:B==="ghost"?te=!!F.api_key&&!!F.url:te=!!F.api_key&&!!F.site_id)}b(te),z(!0)}).catch(N=>{console.error("Failed to check blog integrations in overview",N),z(!0)})},[o]);t.useEffect(()=>{o&&(tr(o.id).then(N=>{if(N.data.success){const q=N.data.data;g(!!(q.resend_api_key_configured&&q.outbound_from_email))}}).catch(N=>{console.error("Failed to check outreach settings in overview",N)}),Z(),ar(o.id).then(N=>{N.data&&V(N.data.own_dr||3.3)}).catch(N=>
2{console.error("Failed to fetch backlink settings for DR",N)}))},[o]),t.useEffect(()=>{o&&(u(!0),Ia(o.id,"this_week").then(N=>{m(N.data)}).catch(N=>{console.error("Failed to fetch overview narrative data",N)}).finally(()=>{u(!1)}))},[o]);const T=t.useMemo(()=>(l==null?void 0:l.opportunities_stats)||{completed:0,total:0,buying_signals:0,competitor_switch:0,unanswered_reddit:0,pending:0,seo_completed:0,seo_total:0,seo_pending:0},[l]),K=t.useMemo(()=>(l==null?void 0:l.competitor_activities_stats)||{completed:0,total:0,pricing_changes:0,seo_changes:0,page_changes:0},[l]),O=t.useMemo(()=>(l==null?void 0:l.publish_stats)||{completed:0,total:0,ready_posts:0,pending_drafts:0},[l]),he=T.completed,oe=K.completed,ye=O.completed,ke=he+oe+ye,ce=t.useMemo(()=>{const N=O.planned_for_the_week??0;return T.total+K.total+N},[T,K,O]),xe=ce===0?0:Math.min(100,Math.round(ke/ce*100)),ge=t.useMemo(()=>xe===0?"Complete this week’s actions to maintain your growth streak.":xe<25?"Momentum building — start acting on your weekly checklist.":xe<50?"Nice start! Momentum is building.":xe<75?"Strong activity! You're halfway through.":xe<100?"Excellent consistency! Almost there.":"Weekly growth plan completed! Excellent work.",[xe]),we=new Date().getDay()===0?6:new Date().getDay()-1,$=7,J=["M","T","W","T","F","S","S"],E=N=>N<=we&&N>we-$,U=T.total-T.completed,ee=t.useMemo(()=>{const N=[];N.push({id:"opportunities",icon:e.jsx("div",{className:"w-10 h-10 rounded-full bg-purple-50 dark:bg-purple-900/20 text-purple-650 flex items-center justify-center",children:e.jsx(Pe,{className:"w-5 h-5"})}),title:"Attend to Opportunities",description:`You have ${T.total} high-intent buying signals detected this week.`,buttonText:"View Opportunities",onClick:()=>i("/growth-opportunities")}),s?N.push({id:"blog_planner",icon:e.jsx("div",{className:"w-10 h-10 rounded-full bg-emerald-50 dark:bg-emerald-950/20 text-emerald-600 flex items-center justify-center",children:e.jsx(ot,{className:"w-5 h-5"})}),title:"Review Today's Articles",description:"Manage your content planner, review generated drafts, and schedule them for publication.",buttonText:"Manage Planner",onClick:()=>i("/publish")}):N.push({id:"blog_setup",icon:e.jsx("div",{className:"w-10 h-10 rounded-full bg-blue-50 dark:bg-blue-900/20 text-blue-650 flex items-center justify-center",children:e.jsx(ot,{className:"w-5 h-5"})}),title:"Connect Blog Integration",description:"Link your WordPress or custom CMS to automatically publish AI articles and discover link placements.",buttonText:"Connect Blog",onClick:()=>A(!0)}),c||N.push({id:"email_setup",icon:e.jsx("div",{className:"w-10 h-10 rounded-full bg-orange-50 dark:bg-orange-900/20 text-orange-650 flex items-center justify-center",children:e.jsx(La,{className:"w-5 h-5"})}),title:"Setup Outreach Email",description:"Configure your own custom company email to improve branding and trust when prospects receive your pitches.",buttonText:"Configure Email",onClick:()=>i("/manage-project?tab=backlinks")});const q=K.total-K.completed;return K.total>0&&N.push({id:"competitors",icon:e.jsx("div",{className:"w-10 h-10 rounded-full bg-rose-50 dark:bg-rose-950/20 text-rose-650 flex items-center justify-center",children:e.jsx(ct,{className:"w-5 h-5"})}),title:"Review Competitor Moves",description:`You have ${q>0?q:0} unseen competitor activities detected this week.`,buttonText:"Analyze Activities",onClick:()=>i("/monitors/competitor/all")}),N},[U,K,s,c,i]),re=()=>{H(N=>Math.min(N+1,Math.max(0,ee.length-3)))},X=()=>{H(N=>Math.max(N-1,0))};return e.jsxs("div",{className:"w-full h-full p-6 md:p-10 bg-white dark:bg-neutral-900 overflow-y-auto",children:[e.jsxs("div",{className:"w-full mx-auto space-y-8",children:[e.jsxs("div",{className:"flex flex-col md:flex-row justify-between items-start md:items-center gap-6 mb-2",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-3.5xl font-extrabold text-neutral-900 dark:text-neutral-100 tracking-tight",children:["Welcome back, ",((se=a==null?void 0:a.name)==null?void 0:se.split(" ")[0])||"there","."]}),e.jsx("p",{className:"text-sm text-neutral-500 mt-2 font-medium",children:"Here is your weekly command center. Let's grow your brand."})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(gr,{isBlogConnected:s,isEmailSetup:c,opportunitiesCompleted:T.completed,articlesPublished:O.completed}),e.jsxs("div",{className:"flex items-center gap-3 px-4 py-2 bg-white dark:bg-neutral-800 border border-neutral-200 dark:border-neutral-700 rounded-xl shadow-none min-h-[46px]",children:[e.jsxs("div",{className:"relative w-9 h-9 flex items-center justify-center shrink-0",children:[e.jsxs("svg",{className:"transform -rotate-90 w-9 h-9",viewBox:"0 0 36 36",children:[e.jsx("circle",{cx:"18",cy:"18",r:"15",stroke:"currentColor",strokeWidth:"3",fill:"transparent",className:"text-neutral-100 dar
2k:text-neutral-700"}),e.jsx("circle",{cx:"18",cy:"18",r:"15",stroke:"currentColor",strokeWidth:"3",fill:"transparent",strokeDasharray:"94.2",strokeDashoffset:94.2-y/100*94.2,className:"text-brand-primary transition-all duration-500"})]}),e.jsx("span",{className:"absolute text-[11px] font-black text-neutral-800 dark:text-neutral-100",children:y.toFixed(0)})]}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{className:"text-[9px] font-black text-neutral-400 uppercase tracking-widest leading-none",children:"Domain Rating"}),e.jsxs("span",{className:"text-xs font-black text-brand-primary mt-1 leading-none",children:["DR ",y.toFixed(0)]})]})]})]})]}),f&&!s&&!Y&&e.jsxs(M.div,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},className:"relative bg-white dark:bg-neutral-850 border border-neutral-200 dark:border-neutral-800 rounded-2xl p-6 md:p-8 flex flex-col lg:flex-row justify-between items-start lg:items-center gap-6 shadow-none overflow-hidden",children:[e.jsx("div",{className:"absolute left-0 top-0 bottom-0 w-1 bg-gradient-to-b from-brand-primary to-indigo-600"}),e.jsxs("div",{className:"space-y-4 max-w-3xl z-10 pl-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"inline-flex items-center gap-1 px-2.5 py-0.5 rounded-md bg-brand-light dark:bg-brand-primary/10 text-brand-primary text-[10px] font-black uppercase tracking-wider",children:"Recommended Setup"}),e.jsx("span",{className:"text-[11px] text-neutral-400 font-semibold",children:"• 5-minute setup"})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-xl md:text-2xl font-black text-neutral-900 dark:text-neutral-100 tracking-tight leading-tight",children:"Maximize Organic Traffic & AI Visibility"}),e.jsx("p",{className:"text-sm text-neutral-500 dark:text-neutral-400 mt-2 font-medium leading-relaxed",children:"Link your WordPress or custom CMS blog integration to unlock autopilot publishing. When connected, Growlytics automatically generates and schedules highly targeted SEO articles based on real-time competitor moves and active user search signals."})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-3 pt-1 text-xs text-neutral-600 dar
2k:text-neutral-300 font-semibold",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-5 h-5 rounded-full bg-emerald-50 dark:bg-emerald-950/20 text-emerald-600 flex items-center justify-center shrink-0",children:e.jsx(Ce,{className:"w-3 h-3"})}),e.jsx("span",{children:"Continuous organic traffic growth"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-5 h-5 rounded-full bg-emerald-50 dark:bg-emerald-950/20 text-emerald-600 flex items-center justify-center shrink-0",children:e.jsx(Ce,{className:"w-3 h-3"})}),e.jsx("span",{children:"Optimize visibility across AI engines (Claude, Perplexity)"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-5 h-5 rounded-full bg-emerald-50 dark:bg-emerald-950/20 text-emerald-600 flex items-center justify-center shrink-0",children:e.jsx(Ce,{className:"w-3 h-3"})}),e.jsx("span",{children:"Sync drafts directly to your content planner"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-5 h-5 rounded-full bg-emerald-50 dark:bg-emerald-950/20 text-emerald-600 flex items-center justify-center shrink-0",children:e.jsx(Ce,{className:"w-3 h-3"})}),e.jsx("span",{children:"Zero copy-pasting needed"})]})]})]}),e.jsxs("div",{className:"flex lg:flex-col sm:flex-row items-center justify-end gap-3 shrink-0 w-full lg:w-auto pt-4 lg:pt-0 border-t lg:border-t-0 border-neutral-100 dark:border-neutral-800 z-10 pl-2",children:[e.jsxs("button",{onClick:()=>A(!0),className:"w-full sm:w-48 whitespace-nowrap px-6 py-3 bg-brand-primary hover:bg-brand-primary/95 text-white text-xs font-black tracking-widest uppercase rounded-xl transition-all active:scale-95 shadow-md shadow-brand-primary/10 flex items-center justify-center gap-2 group shrink-0",children:["Connect Blog",e.jsx(Ht,{className:"w-4 h-4 transition-transform group-hover:translate-x-1"})]}),e.jsx("button",{onClick:()=>{localStorage.setItem("growlytics_blog_promo_dismissed","true"),C(!0)},className:"w-full sm:w-48 whitespace-nowrap px-6 py-3 border border-neutral-200 dark:border-neutral-750 hover:bg-neutral-50 dark:hover:bg-neutral-800 text-neutral-500 dark:text-neutral-400 text-xs font-black uppercase tracking-widest rounded-xl transition-all active:scale-95",children:"Dismiss"})]})]}),e.jsxs("div",{className:"bg-white dark:bg-neutral-850 border border-neutral-200 dark:border-neutral-800 rounded-2xl p-7 shadow-none",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-6 text-[10px] font-black uppercase tracking-wider text-neutral-400 border-b border-neutral-100 dark:border-neutral-800 pb-3",children:[e.jsx(ot,{className:"w-4 h-4 text-neutral-400"}),"Growth & Performance Statistics"]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 divide-y lg:divide-y-0 lg:divide-x divide-neutral-100 dark:divide-neutral-800 gap-6 lg:gap-0",children:[e.jsxs("div",{className:"lg:pr-6 lg:pb-0 pb-6",children:[e.jsx("span",{className:"text-xs font-bold text-neutral-500 block mb-2",children:"Today's Growth Plan"}),l?e.jsx("div",{className:"flex items-center gap-6 mt-1",children:e.jsx("div",{className:"cursor-pointer hover:opacity-80 transition-opacity",onClick:()=>i("/growth-opportunities"),children:e.jsxs("div",{className:"flex items-baseline gap-1.5",children:[e.jsxs("span",{className:"text-3xl font-black text-neutral-900 dark:text-white",children:[T.completed," / ",T.total]}),e.jsx("span",{className:"text-[10px] font-bold text-neutral-450 uppercase tracking-wide",children:"Completed"})]})})}):e.jsx("div",{className:"h-9 w-24 bg-neutral-200 dark:bg-neutral-800 animate-pulse rounded-lg my-1"}),e.jsx("span",{className:"text-[11px] text-neutral-450 dark:text-neutral-500 font-semibold block mt-3",children:"Daily curated growth plan"})]}),e.jsxs("div",{className:"lg:px-6 lg:py-0 py-6 cursor-pointer hover:opacity-80 transition-opacity",onClick:()=>i("/content-planner"),children:[e.jsx("span",{className:"text-xs font-bold text-neutral-500 block mb-2",children:"Articles Published"}),e.jsxs("div",{className:"flex items-baseline gap-3",children:[l?e.jsx("div",{className:"text-4xl font-extrabold text-neutral-955 dark:text-white tracking-tight",children:ye}):e.jsx("div",{className:"h-9 w-12 bg-neutral-200 dark:bg-neutral-800 animate-pulse rounded-lg my-0.5"}),e.jsx("span",{className:"text-xs font-semibold text-neutral-450 dark:text-neutral-400",children:"this week"})]}),l?e.jsxs("span",{className:"text-[11px] text-neutral-400 font-semibold block mt-2",children:["Planned for the week: ",e.jsx("span",{className:"text-neutral-700 dark:text-neutral-200 font-bold",children:O.planned_for_the_week??0})]}):e.jsx("div",{className:"h-3.5 w-32 bg-neutral-200 dark:bg-neutral-800 animate-pulse rounded mt-2.5"})]}),e.jsxs("div",{className:"lg:px-6 lg:py-0 py-6 cursor-pointer hover:opacity-80 transition-opacity",onClick:()=>
2i("/monitors/competitor/all"),children:[e.jsx("span",{className:"text-xs font-bold text-neutral-500 block mb-2",children:"Competitor Activities"}),l?e.jsx("div",{className:"text-4xl font-extrabold text-neutral-955 dark:text-white tracking-tight mb-2",children:K.total}):e.jsx("div",{className:"h-9 w-14 bg-neutral-200 dark:bg-neutral-800 animate-pulse rounded-lg my-0.5 mb-2"}),e.jsx("span",{className:"text-[11px] text-neutral-400 font-semibold",children:"Active monitoring this week"})]}),e.jsxs("div",{className:"lg:pl-6 lg:pt-0 pt-6 cursor-pointer hover:opacity-80 transition-opacity",onClick:()=>i("/ai-visibility"),children:[e.jsx("span",{className:"text-xs font-bold text-neutral-500 block mb-2",children:"AI Visibility"}),e.jsxs("div",{className:"flex items-baseline gap-2",children:[l?e.jsxs("div",{className:"text-4xl font-extrabold text-brand-primary tracking-tight",children:[l.ai_visibility_score??0,"%"]}):e.jsx("div",{className:"h-9 w-14 bg-neutral-200 dark:bg-neutral-800 animate-pulse rounded-lg my-0.5"}),e.jsx("span",{className:"text-xs font-semibold text-neutral-450 dark:text-neutral-400",children:"this week"})]}),e.jsx("span",{className:"text-[11px] text-neutral-400 font-semibold block mt-2",children:"Share of voice across AI models"})]})]})]}),e.jsxs("div",{className:"w-full bg-[#FFFAF5] dark:bg-orange-955/5 border border-[#FDE6D5] dark:border-orange-900/30 rounded-xl px-4 py-2 flex items-center justify-between shadow-none min-h-[50px] max-h-[50px] overflow-hidden gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3 min-w-0 flex-1",children:[e.jsx("div",{className:"w-7 h-7 rounded-full bg-[#FFF0E0] dark:bg-orange-900/30 flex items-center justify-center text-[#FF7043] shrink-0",children:e.jsx(hr,{className:"w-4 h-4"})}),e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsxs("span",{className:"text-xs font-black text-neutral-900 dark:text-neutral-100 whitespace-nowrap",children:[$," days streak"]}),e.jsx("span",{className:"text-neutral-300 dark:text-neutral-800",children:"|"}),e.jsx("span",{className:"text-[11px] font-bold text-neutral-600 dar
2k:text-neutral-400 truncate",children:l?`${ge} (${ke} of ${ce} completed)`:"Loading..."})]})]}),e.jsxs("div",{className:"flex items-center gap-4 shrink-0",children:[e.jsx("div",{className:"flex items-center gap-1",children:J.map((N,q)=>{const B=E(q);return e.jsx("div",{className:"flex items-center gap-1",children:e.jsx("div",{className:`w-5 h-5 rounded-md flex items-center justify-center transition-colors ${B?"bg-[#FF7043] text-white shadow-sm":"bg-neutral-100 dark:bg-neutral-800 text-neutral-400 dark:text-neutral-600"}`,children:B?e.jsx(Ce,{className:"w-3 h-3 stroke-[3]"}):e.jsx("span",{className:"text-[8px] font-black",children:N})})},q)})}),e.jsx("span",{className:"text-neutral-300 dark:text-neutral-800",children:"|"}),e.jsx("div",{className:"flex items-center gap-2",children:l?e.jsxs("span",{className:"text-sm font-black text-[#FF7043]",children:[xe,"%"]}):e.jsx("div",{className:"h-5 w-8 bg-neutral-200 dark:bg-neutral-800 animate-pulse rounded"})})]})]}),e.jsxs("div",{className:"bg-white dark:bg-neutral-850 border border-neutral-200 dark:border-neutral-800 rounded-2xl p-7 shadow-none",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("h3",{className:"text-lg font-extrabold text-neutral-955 dark:text-white",children:"Recommended Actions"}),l?e.jsxs("span",{className:"px-2.5 py-1 bg-brand-light dark:bg-brand-primary/10 border border-brand-primary/10 text-brand-primary text-[10px] font-black tracking-wider rounded-lg uppercase",children:[ee.length," suggestions"]}):e.jsx("div",{className:"h-5 w-24 bg-neutral-200 dark:bg-neutral-800 animate-pulse rounded-lg"})]}),e.jsx("p",{className:"text-xs text-neutral-500 font-medium mt-1",children:"The highest-leverage next steps for this product."})]}),ee.length>3&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:X,disabled:S===0,className:"p-2 border border-neutral-200 dark:border-neutral-700 rounded-xl hover:bg-neutral-50 dark:hover:bg-neutral-800 disabled:opacity-40 disabled:hover:bg-transparent transition-colors",children:e.jsx("svg",{className:"w-4 h-4 transform rotate-180",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M9 5l7 7-7 7"})})}),e.jsx("button",{onClick:re,disabled:S>=ee.length-3,className:"p-2 border border-neutral-200 dark:border-neutral-700 rounded-xl hover:bg-neutral-50 dark:hover:bg-neutral-800 disabled:opacity-40 disabled:hover:bg-transparent transition-colors",children:e.jsx("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M9 5l7 7-7 7"})})})]})]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-5 overflow-hidden",children:l?ee.slice(S,S+3).map(N=>e.jsxs("div",{onClick:N.onClick,className:"p-6 bg-gradient-to-br from-neutral-50 to-neutral-100/50 dark:from-neutral-800 dark:to-neutral-800/40 border border-neutral-200/60 dark:border-neutral-700/60 rounded-2xl flex flex-col justify-between h-[190px] hover:shadow-sm hover:border-brand-primary/30 cursor-pointer transition-all",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[N.icon,e.jsx("h4",{className:"text-sm font-extrabold text-neutral-900 dark:text-neutral-100",children:N.title})]}),e.jsx("p",{className:"text-xs text-neutral-500 dark:text-neutral-400 font-medium leading-relaxed",children:N.description})]}),e.jsxs("button",{onClick:N.onClick,className:"text-xs font-bold text-brand-primary hover:text-brand-primary/95 transition-colors flex items-center gap-1.5 self-start mt-4",children:[N.buttonText," ",e.jsx(Ht,{className:"w-3.5 h-3.5"})]})]},N.id)):Array.from({length:3}).map((N,q)=>e.jsxs("div",{className:"p-6 bg-gradient-to-br from-neutral-50 to-neutral-100/50 dark:from-neutral-800 dark:to-neutral-800/40 border border-neutral-200/60 dark:border-neutral-700/60 rounded-2xl flex flex-col justify-between h-[190px] animate-pulse",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-neutral-200 dark:bg-neutral-700 shrink-0"}),e.jsx("div",{className:"h-4 w-32 bg-neutral-200 dark:bg-neutral-700 rounded"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"h-3 w-full bg-neutral-200 dark:bg-neutral-700 rounded"}),e.jsx("div",{className:"h-3 w-5/6 bg-neutral-200 dark:bg-neutral-700 rounded"})]})]}),e.jsx("div",{className:"h-3 w-20 bg-neutral-200 dark:bg-neutral-700 rounded mt-4"})]},q))})]})]}),o&&e.jsx(sr,{isOpen:v,onClose:()=>A(!1),projectId:o.id,onSaved:Z})]})},yr=()=>e.jsxs("div",{className:"relative flex items-center justify-center w-6 h-6",children:[e.jsx("div",{className:"absolute inset-0 border-2 border-neutral-200 dark:border-neutral-700 rounded-full"}),e.jsx("div",{className:"absolute inset-0 border-2 border-brand-primary rounded-full border-t-transparent animate-spin"})]}),kr=({title:a,subtitle:o})=>e.jsx("div",{className:"space-y-6",children:e.jsxs("div",{className:"bg-white dark:bg-neutral-800 rounded-[7px] border border-neutral-200 dark:border-neutral-700 p-6 relative overflow-hidden shadow-sm",children:[e.jsxs("div",{className:"flex items-center mb-6",children:[e.jsx("div",{className:"w-10 h-10 rounded-lg bg-neutral-100 dar
2k:bg-neutral-700 animate-pulse mr-3"}),e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsx("div",{className:"h-3 w-1/4 bg-neutral-100 dark:bg-neutral-700 rounded animate-pulse"}),e.jsx("div",{className:"h-2 w-1/6 bg-neutral-50 dark:bg-neutral-700/50 rounded animate-pulse"})]})]}),e.jsxs("div",{className:"flex items-start gap-5 mb-8",children:[e.jsx("div",{className:"flex-shrink-0 mt-1",children:e.jsx(yr,{})}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-black text-neutral-900 dark:text-neutral-100 uppercase tracking-tight",children:a||"Initializing Intelligence Feed"}),e.jsx("p",{className:"text-xs text-neutral-500 dark:text-neutral-400 mt-1.5 font-medium leading-relaxed max-w-md",children:o||"Our system is currently scanning for initial data. AI insights will be generated automatically as results arrive."})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"h-3.5 w-full bg-neutral-50 dark:bg-neutral-700 rounded animate-pulse"}),e.jsx("div",{className:"h-3.5 w-4/5 bg-neutral-50 dark:bg-neutral-700 rounded animate-pulse"})]})]})}),jr=({competitor:a,activities:o,isLoading:p,highlightedIds:i,selectedActivityTypes:l=[],searchQuery:m="",dateFilter:h="anytime",emptyStateOverride:u})=>{const[c,g]=t.useState(null),[s,b]=t.useState(null),f=t.useMemo(()=>{let y=o;if(l.length>0&&(y=y.filter(V=>l.includes(V.type))),m.trim()){const V=m.toLowerCase();y=y.filter(S=>{var H,Y;return((H=S.summary)==null?void 0:H.toLowerCase().includes(V))||((Y=S.type)==null?void 0:Y.toLowerCase().includes(V))})}return y},[o,l,m]),z=!p&&o.length===0;return e.jsxs("div",{className:"relative h-full",children:[e.jsx(Ut,{isOpen:!!c,onClose:()=>g(null),activity:c,competitor:a}),e.jsx(Gt,{isOpen:!!s,onClose:()=>b(null),activity:s,competitor:a}),e.jsx("div",{className:"space-y-6 h-full pb-10",children:f.length>0?e.jsx("div",{className:"flex flex-col gap-6",children:f.map(y=>e.jsx(Vt,{activity:y,competitor:a,onViewChange:()=>g(y),onCreateAction:()=>b(y),viewMode:"grid",disableLink:!0},y.id))}):!p&&(z?e.jsx("div",{className:"h-full",children:u||e.jsx(kr,{title:"Gathering Intelligence...",subtitle:"Our system is tracking and monitoring for new data. Your feed will refresh automatically as results arrive."})}):e.jsxs("div",{className:"text-center py-20 bg-white dark:bg-neutral-800 rounded-xl border border-neutral-200 dark:border-neutral-700 shadow-sm",children:[e.jsx("div",{className:"bg-neutral-50 dark:bg-neutral-900 rounded-full p-5 inline-block mb-4 shadow-sm border border-neutral-100 dark:border-neutral-700",children:e.jsx(Pe,{className:"w-10 h-10 text-neutral-300"})}),e.jsx("h4",{className:"font-black text-neutral-900 dark:text-neutral-100 text-base uppercase tracking-widest",children:"No results for current filter"}),e.jsx("p",{className:"mt-3 text-sm text-neutral-500 dark:text-neutral-400 max-w-sm mx-auto font-medium leading-relaxed",children:"We found activities, but they don't match your current active filters. Try adjusting your search or selection."})]}))})]})},vr="growlytics_competitor_presets",Zt=({title:a})=>e.jsx("h3",{className:"text-[10px] font-black text-neutral-900 dark:text-neutral-100 uppercase tracking-[0.2em] mb-4",children:a}),wr=()=>e.jsxs("div",{className:"relative flex items-center justify-center w-8 h-8",children:[e.jsx("div",{className:"absolute inset-0 border-4 border-neutral-100 dark:border-neutral-700 rounded-full"}),e.jsx("div",{className:"absolute inset-0 border-4 border-brand-primary rounded-full border-t-transparent animate-spin"})]}),Nr=({selectedFilter:a,onFilterChange:o,customDates:p,onCustomDateChange:i,className:l=""})=>{var s;const[m,h]=t.useState(!1),u=t.useRef(null);t.useEffect(()=>{const b=f=>{u.current&&!u.current.contains(f.target)&&h(!1)};return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[]);const c=[{value:"anytime",label:"All activities",description:"Full history of competitor activity."},{value:"unseen",label:"Unseen",description:"New activities you haven't read yet."},{value:"saved",label:"Saved",description:"Bookmarked and starred activities."},{value:"last_7_days",label:"Last 7 days",description:"Activities from the last 7 days."},{value:"last_30_days",label:"Last 30 days",description:"Activities from the last 30 days."},{value:"custom",label:"Custom range",description:"Select a custom calendar range."}],g=((s=c.find(b=>b.value===a))==null?void 0:s.label)||"Date";return e.jsxs("div",{className:`relative ${l}`,ref:u,children:[e.jsxs("button",{onClick:()=>h(!m),className:`flex items-center gap-2 px-3 py-2 bg-white dark:bg-neutral-800 border border-neutral-200 dark:border-neutral-700 rounded-lg text-[10px] font-black uppercase tracking-widest text-neutral-600 dar
2k:text-neutral-300 transition-all ${m?"border-neutral-400 dark:border-neutral-500":""}`,children:[e.jsx(_t,{className:"w-4 h-4 text-neutral-400"}),e.jsx("span",{className:"capitalize",children:g}),e.jsx(Je,{className:`w-3.5 h-3.5 text-neutral-400 ml-1 transition-transform ${m?"rotate-180":""}`})]}),e.jsx(be,{children:m&&e.jsxs(M.div,{initial:{opacity:0,y:8,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:8,scale:.98},className:"absolute top-full right-0 mt-2 w-64 bg-white dark:bg-neutral-800 rounded-lg shadow-2xl border border-neutral-200 dark:border-neutral-700 z-50 p-2 overflow-hidden",children:[e.jsx("div",{className:"space-y-1 text-left",children:c.map(b=>e.jsxs("button",{onClick:()=>{o(b.value),b.value!=="custom"&&h(!1)},className:`w-full text-left px-4 py-2 rounded-md transition-colors flex flex-col items-start ${a===b.value?"bg-brand-light dark:bg-brand-primary/20 text-brand-primary":"text-neutral-700 dark:text-neutral-200 hover:bg-neutral-50 dark:hover:bg-neutral-800"}`,children:[e.jsx("span",{className:"text-xs font-bold",children:b.label}),e.jsx("span",{className:`text-[10px] font-medium mt-0.5 ${a===b.value?"text-brand-primary/80":"text-neutral-400 dark:text-neutral-500"}`,children:b.description})]},b.value))}),a==="custom"&&e.jsxs("div",{className:"mt-2 pt-2 border-t border-neutral-100 dark:border-neutral-800 p-3 space-y-3 text-left",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-[9px] font-black uppercase text-neutral-400",children:"Start Date"}),e.jsx("input",{type:"date",value:p.startDate,onChange:b=>i({...p,startDate:b.target.value}),className:"w-full px-2 py-1.5 bg-neutral-50 dark:bg-neutral-800 border border-neutral-200 dark:border-neutral-700 rounded-md text-xs font-bold"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-[9px] font-black uppercase text-neutral-400",children:"End Date"}),e.jsx("input",{type:"date",value:p.endDate,onChange:b=>i({...p,endDate:b.target.value}),className:"w-full px-2 py-1.5 bg-neutral-50 dark:bg-neutral-800 border border-neutral-200 dark:border-neutral-700 rounded-md text-xs font-bold"})]}),e.jsx("button",{onClick:()=>h(!1),className:"w-full py-2 bg-neutral-900 dark:bg-neutral-100 text-white dark:text-neutral-900 text-[10px] font-black uppercase tracking-widest rounded-md",children:"Apply Range"})]})]})})]})},Cr=({options:a,selected:o,onToggle:p,onClear:i,counts:l,className:m=""})=>{const[h,u]=t.useState(!1),c=t.useRef(null);t.useEffect(()=>{const s=b=>{c.current&&!c.current.contains(b.target)&&u(!1)};return document.addEventListener("mousedown",s),()=>document.removeEventListener("mousedown",s)},[]);const g=t.useMemo(()=>{var s;return o.length===a.length?"All activity types":o.length===0?"No Types Selected":o.length===1?((s=a.find(b=>b.id===o[0]))==null?void 0:s.label)||"1 Type":`${o.length} Types Selected`},[o,a]);return e.jsxs("div",{className:`relative ${m}`,ref:c,children:[e.jsxs("button",{onClick:()=>u(!h),className:`flex items-center gap-2 px-3 py-2 bg-white dark:bg-neutral-800 border border-neutral-200 dark:border-neutral-700 rounded-lg text-[10px] font-black uppercase tracking-widest text-neutral-600 dar
2k:text-neutral-300 transition-all ${h?"border-neutral-400 dark:border-neutral-500":""}`,children:[e.jsx(Pt,{className:"w-3.5 h-3.5 text-neutral-400"}),e.jsx("span",{className:"truncate max-w-[120px]",children:g}),e.jsx(Je,{className:`w-3 h-3 text-neutral-400 transition-transform ${h?"rotate-180":""}`})]}),e.jsx(be,{children:h&&e.jsxs(M.div,{initial:{opacity:0,y:8,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:8,scale:.98},className:"absolute top-full right-0 mt-2 w-64 bg-white dark:bg-neutral-800 rounded-lg shadow-2xl border border-neutral-200 dark:border-neutral-700 z-[100] p-1 overflow-hidden",children:[e.jsxs("div",{className:"p-2.5 border-b border-neutral-50 dark:border-neutral-800 flex justify-between items-center mb-1",children:[e.jsx("span",{className:"text-[9px] font-black uppercase text-neutral-400",children:"Signal Types"}),e.jsx("button",{onClick:i,className:"text-[9px] font-black uppercase text-neutral-600 dark:text-neutral-300 hover:underline",children:"Toggle All"})]}),e.jsx("div",{className:"max-h-80 overflow-y-auto custom-scrollbar space-y-0.5",children:a.map(s=>e.jsxs("button",{onClick:()=>p(s.id),className:`w-full flex items-center justify-between px-3 py-2.5 rounded-md text-[10px] font-bold uppercase tracking-widest transition-colors ${o.includes(s.id)?"bg-brand-light dark:bg-brand-primary/20 text-brand-primary":"text-neutral-500 dark:text-neutral-400 hover:bg-neutral-50 dark:hover:bg-neutral-800/50"}`,children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("div",{className:`transition-colors ${o.includes(s.id)?"text-brand-primary":"text-neutral-400"}`,children:Ke.cloneElement(s.icon,{className:"w-3.5 h-3.5"})}),e.jsx("span",{children:s.label})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-[9px] font-black px-1.5 py-0.5 rounded-md bg-neutral-100 dark:bg-neutral-800 text-neutral-400",children:l[s.id]||0}),e.jsx("div",{className:`w-3.5 h-3.5 rounded-sm border flex items-center justify-center transition-colors ${o.includes(s.id)?"bg-brand-primary border-brand-primary":"border-neutral-300 dark:border-neutral-600"}`,children:o.includes(s.id)&&e.jsx(Ce,{className:"w-2.5 h-2.5 text-white"})})]})]},s.id))})]})})]})},Sr=({competitorId:a,onUpdate:o,refreshKey:p=0})=>{const{t:i}=Ot(),{addToast:l}=tt(),{selectedProject:m,refreshPermissions:h}=lt(),{checkRestriction:u}=nr(),c=xt(),[g,s]=Ct(),[b,f]=t.useState(null),[z,y]=t.useState([]),[V,S]=t.useState(!0),[H,Y]=t.useState(!1),[C,v]=t.useState("activities"),[A,Z]=t.useState("anytime"),[T,K]=t.useState({startDate:"",endDate:""}),[O,he]=t.useState([]),oe=g.get("status")||"all",[ye,ke]=t.useState(!0),[ce,xe]=t.useState(!1),[ge,we]=t.useState("general"),[$,J]=t.useState(!1),[E,U]=t.useState(!1),[ee,re]=t.useState(!1);t.useRef(null);const[X,se]=t.useState([]),[N,q]=t.useState(""),B=(m==null?void 0:m.is_demo)===1,te=t.useMemo(()=>[{id:"website",label:"Website",icon:e.jsx(yt,{}),color:"text-amber-600",borderColor:"border-amber-200",bgColor:"bg-amber-50",types:["website"],targetKey:"website_changes"},{id:"seo",label:"SEO",icon:e.jsx(Ve,{}),color:"text-green-600",borderColor:"border-green-200",bgColor:"bg-green-50",types:["seo"],targetKey:"seo"},{id:"pricing",label:"Pricing",icon:e.jsx(ut,{}),color:"text-orange-600",borderColor:"border-orange-200",bgColor:"bg-orange-50",types:["pricing"],targetKey:"pricing"},{id:"social",label:"Social",icon:e.jsx(Rt,{}),color:"text-pink-600",borderColor:"border-pink-200",bgColor:"bg-pink-50",types:["social"],targetKey:"social_activity"},{id:"blog",label:"Blog",icon:e.jsx(ot,{}),color:"text-rose-600",borderColor:"border-rose-200",bgColor:"bg-rose-50",types:["blog"],targetKey:"blog"},{id:"backlinks",label:"Backlinks",icon:e.jsx(Mt,{}),color:"text-purple-600",borderColor:"border-purple-200",bgColor:"bg-purple-50",types:["backlinks"],targetKey:"backlinks"},{id:"keywords",label:"Keywords",icon:e.jsx(qe,{}),color:"text-indigo-600",borderColor:"border-indigo-200",bgColor:"bg-indigo-50",types:["keywords"],targetKey:"keywords"},{id:"reviews",label:"Reviews",icon:e.jsx(Pe,{}),color:"text-sky-600",borderColor:"border-sky-200",bgColor:"bg-sky-50",types:["reviews"],targetKey:"reviews"}],[]),F=t.useMemo(()=>
2{if(!(b!=null&&b.targets))return te;let I=[];try{I=Array.isArray(b.targets)?b.targets:JSON.parse(b.targets)}catch{I=[]}return te.filter(d=>I.includes(d.targetKey))},[b,te]),[R,P]=t.useState({status:"all",types:[],date:"anytime",start:"",end:""});t.useEffect(()=>{P({status:oe,types:O,date:A,start:T.startDate,end:T.endDate})},[oe,O,A,T]),t.useEffect(()=>{const I=localStorage.getItem(vr);if(I)try{se(JSON.parse(I))}catch{se([])}},[]),t.useEffect(()=>{b&&F.length>0&&O.length===0&&he(F.map(I=>I.id))},[b,F]);const ue=t.useCallback(async()=>{S(!0);try{const I=await qa(a);f(I.data)}catch{l("Failed to load competitor detail","error")}finally{S(!1)}},[a,l]),ae=t.useCallback(async(I=!1)=>{if(!(!m||!a)&&!(A==="custom"&&(!T.startDate||!T.endDate))){I||Y(!0);try{let d=null;O.length>0&&O.length<F.length&&(d=O.flatMap(de=>{const Ne=te.find(De=>De.id===de);return Ne?Ne.types:[]}).join(","));const D={project_id:m.id,competitor_id:a,type:d||void 0,date_filter:A,status:oe!=="all"?oe:void 0,start_date:A==="custom"?T.startDate:void 0,end_date:A==="custom"?T.endDate:void 0,per_page:100},fe=await fa(D);y(fe.data.data||[])}catch{I||l("Failed to load activities.","error")}finally{I||Y(!1)}}},[m,a,A,T,oe,l,O,F,te]);t.useEffect(()=>{ue()},[ue]),t.useEffect(()=>{ae()},[ae,A,T,oe,p]);const Q=t.useMemo(()=>{const I={};return te.forEach(d=>{I[d.id]=z.filter(D=>d.types.includes(D.type)).length}),I},[z,te]),je=async()=>{if(!(!b||B)){U(!0);try{await Ya(b.id),l("Competitor deleted successfully.","success"),o&&o(),h&&h(),c("/home")}catch{l("Failed to delete competitor.","error")}finally{U(!1),J(!1)}}},G=I=>{he(d=>d.includes(I)?d.filter(D=>D!==I):[...d,I])},ve=(I,d)=>{const D=new URLSearchParams(g);d&&d!=="all"?D.set(I,d):D.delete(I),s(D,{replace:!0})},$e=I=>{I==="unseen"||I==="saved"?(Z("anytime"),ve("status",I)):(Z(I),ve("status","all"))},Me=t.useMemo(()=>O.length===0?[]:O.flatMap(I=>{var d;return((d=te.find(D=>D.id===I))==null?void 0:d.types)||[]}),[O,te]),Ee=()=>b?e.jsxs("div",{className:"space-y-12 max-w-4xl py-2 text-left",children:[e.jsxs("div",{children:[e.jsx(Zt,{title:"Targeted Monitoring Ecosystem"}
2),e.jsxs("p",{className:"text-xl text-neutral-600 dark:text-neutral-300 font-medium leading-relaxed",children:["We're tracking strategic pivots for ",e.jsxs("span",{className:"text-neutral-900 dark:text-neutral-100 font-black underline decoration-brand-primary/30 underline-offset-4",children:["“",b.name,"”"]})," across their entire digital landscape—including visual architecture, pricing structures, SEO metadata, and market visibility signals."]})]}),e.jsxs("div",{className:"p-6 bg-neutral-50 dark:bg-neutral-900/50 rounded-xl border border-neutral-100 dark:border-neutral-800 shadow-sm",children:[e.jsx("div",{className:"flex flex-col md:flex-row md:items-center justify-between gap-8",children:e.jsxs("div",{className:"flex items-center gap-5",children:[e.jsx(wr,{}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-lg font-black text-neutral-900 dark:text-neutral-100 tracking-tight uppercase",children:"Scanning rival footprint"}),e.jsx("p",{className:"text-xs text-neutral-500 font-bold uppercase tracking-widest mt-1",children:"Extracting competitive intelligence"})]})]})}
2),e.jsx("p",{className:"text-base text-neutral-600 dark:text-neutral-400 font-medium leading-relaxed mt-6",children:"Our engine is currently mapping recent changes to backlinks, keyword rankings, and social activity. New signals and AI-generated counter-actions will begin appearing here as our intelligence layer classifies them."})]}),e.jsxs("div",{children:[e.jsx(Zt,{title:"Signal Relevance Policy"}),e.jsxs("p",{className:"text-base text-neutral-600 dark:text-neutral-400 font-medium leading-relaxed",children:["To maintain high signal-to-noise ratio, we filter out insignificant updates, bot activity, and routine maintenance. Your feed focuses exclusively on ",e.jsx("span",{className:"text-neutral-900 dark:text-neutral-100 font-black uppercase tracking-tight",children:"strategic movements"})," that represent meaningful shifts in market direction."]})]})]}):null;if(V&&!b)return e.jsx(At,{type:"table"});if(!b)return null;const ne=b.status==="active";return e.jsxs("div",{className:"h-full flex flex-col",children:[H&&z.length===0&&e.jsx(Dt,{}),e.jsx(Xa,{isOpen:ce,onClose:()=>xe(!1),competitor:b,onUpdate:()=>{ue(),o&&o()},initialTab:ge}),e.jsx(jt,{isOpen:$,onClose:()=>J(!1),onConfirm:je,title:`Delete ${b.name}`,message:"Are you sure you want to delete this competitor? All associated tracking data and history will be permanently removed.",confirmText:"Delete",isLoading:E}),e.jsx("div",{className:"p-6 md:p-8 pb-6 bg-white dark:bg-neutral-900 border-b border-neutral-50 dark:border-neutral-800 flex-shrink-0",children:e.jsxs("div",{className:"flex flex-col md:flex-row justify-between items-start md:items-center gap-4",children:[e.jsxs("div",{className:"flex items-center gap-5",children:[e.jsx("div",{className:"w-16 h-16 rounded-lg bg-neutral-50 dark:bg-neutral-800 border border-neutral-200 dark:border-neutral-700 flex items-center justify-center p-3",children:e.jsx("img",{src:`https://www.google.com/s2/favicons?domain=${b.website}&sz=128`,alt:"",className:"w-full h-full object-contain"})}),e.jsxs("div",{className:"min-w-0 text-left",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("h2",{className:"text-2xl font-bold text-neutral-900 dark:text-neutral-100 tracking-tight leading-none",children:b.name}),e.jsxs("div",{className:`flex items-center gap-1.5 px-2 py-0.5 rounded-full border ${ne?"bg-green-50 dark:bg-green-900/30 border-green-200 dark:border-green-800":"bg-neutral-50 border border-neutral-200 dark:border-neutral-800 dark:border-neutral-700"}`,children:[e.jsx("span",{className:`w-1 h-1 rounded-full ${ne?"bg-green-500 animate-pulse":"bg-neutral-400"}`}),e.jsx("span",{className:`text-[9px] font-bold ${ne?"text-green-600 dark:text-green-400":"text-neutral-500 dark:text-neutral-400"}`,children:ne?"Active":"Inactive"})]})]}),e.jsx("a",{href:b.website,target:"_blank",rel:"noreferrer",className:"text-brand-primary font-bold hover:underline mt-1.5 block text-sm",children:b.website})]})]}),e.jsxs("div",{className:"flex items-center gap-2 pr-4",children:[e.jsxs("button",{onClick:()=>{u()||(we("general"),xe(!0))},className:"inline-flex items-center gap-2 px-4 py-2 bg-white dark:bg-neutral-800 border border-neutral-200 dark:border-neutral-700 rounded-lg text-[11px] font-bold text-neutral-700 dark:text-neutral-200 hover:bg-neutral-50 transition-all active:scale-95 shadow-sm",children:[e.jsx(zt,{className:"w-3.5 h-3.5"}),"Edit"]}),e.jsx("button",{onClick:()=>{u()||J(!0)},className:"p-2 bg-white dark:bg-neutral-800 border border-neutral-200 dark:border-neutral-700 rounded-lg text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20 transition-all active:scale-95 shadow-sm",children:e.jsx(kt,{className:"w-5 h-5"})}),e.jsxs("button",{onClick:()=>{u()||(we("pages"),xe(!0))},className:"inline-flex items-center gap-2 px-4 py-2 bg-brand-primary text-white text-[11px] font-bold rounded-lg hover:bg-brand-primary/90 transition-all active:scale-95 shadow-lg shadow-brand-primary/20",children:[e.jsx(Ye,{className:"w-3.5 h-3.5"}),"Add page"]})]})]})}),e.jsx("div",{className:"p-6 md:p-8 bg-white dark:bg-neutral-900 min-h-0 flex-grow endurance-scroll overflow-y-auto",children:e.jsx("div",{className:"h-full pr-4 text-left",children:e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4 border-b border-neutral-100 dar
2k:border-neutral-800/60 pb-4",children:[e.jsx("h3",{className:"text-[10px] font-black text-neutral-900 dark:text-neutral-100 uppercase tracking-[0.2em]",children:"Feed Discovery"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Cr,{options:F,selected:O,onToggle:G,onClear:()=>he(O.length===F.length?[]:F.map(I=>I.id)),counts:Q}),e.jsx(Nr,{selectedFilter:oe==="unseen"||oe==="saved"?oe:A,onFilterChange:$e,customDates:T,onCustomDateChange:K})]})]}),ye&&!H&&e.jsxs(M.div,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},exit:{opacity:0,scale:.98},className:"bg-white dark:bg-neutral-800 border border-neutral-200 dark:border-neutral-700 p-6 flex items-start gap-5 transition-all shadow-sm rounded-lg text-left animate-in fade-in duration-200",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("h3",{className:"text-[10px] font-black uppercase tracking-[0.2em] text-neutral-900 dark:text-neutral-100 mb-3",children:["We’re keeping a close eye on ",b.name]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-sm text-neutral-600 dar
2k:text-neutral-400 leading-relaxed font-medium",children:"Surveillance is online. We have established a full architectural and tactical baseline for this competitor to detect any future strategic pivots."}),e.jsxs("p",{className:"text-sm text-neutral-600 dark:text-neutral-400 leading-relaxed font-medium",children:["So far, we've identified ",e.jsx("span",{className:"text-brand-primary font-black",children:(z.length||0).toLocaleString()})," recent movements across their domain. You'll be notified instantly about pricing tweaks, SEO shifts, or any new social activity as it happens."]})]})]}),e.jsx("button",{onClick:()=>ke(!1),className:"p-1.5 bg-red-50 dark:bg-red-900/20 text-red-500 rounded hover:bg-red-100 dark:hover:bg-red-900/30 transition-colors shrink-0",children:e.jsx(Re,{className:"w-4 h-4"})})]}),e.jsx(jr,{competitor:b,activities:z,isLoading:H,selectedActivityTypes:Me,dateFilter:A,emptyStateOverride:Ee()})]})})})]})},wt=({label:a,info:o,className:p})=>{const[i,l]=t.useState(!1);return e.jsxs("div",{className:`flex items-center gap-1.5 mb-2 px-1 ${p}`,children:[e.jsx("label",{className:"block text-[10px] font-black text-neutral-400",children:a}),e.jsxs("div",{className:"relative",children:[e.jsx("button",{type:"button",onMouseEnter:()=>l(!0),onMouseLeave:()=>l(!1),onClick:()=>l(!i),className:"text-cyan-500 hover:text-cyan-600 transition-colors p-0.5 rounded-full",children:e.jsx(St,{className:"w-3.5 h-3.5"})}),e.jsx(be,{children:i&&e.jsxs(M.div,{initial:{opacity:0,y:5},animate:{opacity:1,y:0},exit:{opacity:0,y:5},className:"absolute bottom-full left-1/2 -translate-x-1/2 mb-2 w-48 p-3 bg-neutral-900 text-white text-[10px] font-medium leading-relaxed rounded-lg shadow-xl z-[150] pointer-events-none",children:[e.jsx("div",{className:"absolute top-full left-1/2 -translate-x-1/2 border-8 border-transparent border-t-neutral-900"}),o]})})]})]})},_r=({isOpen:a,onClose:o,website:p,onUpdate:i})=>{const{addToast:l}=tt(),[m,h]=t.useState(""),[u,c]=t.useState("daily"),[g,s]=t.useState("all_changes"),[b,f]=t.useState(""),[z,y]=t.useState(!0),[V,S]=t.useState(!0),[H,Y]=t.useState(!1);t.useEffect(()=>{a&&p&&(h(p.name),c(p.monitor_frequency||"daily"),y(p.status==="active"),S(p.generate_action===1||p.generate_action===!0),p.user_monitor_instructions?(s("instructions"),f(p.user_monitor_instructions)):(s("all_changes"),f("")))},[a,p]);const C=async()=>{if(p){Y(!0);try{await Da(p.id,{name:m,monitor_frequency:u,monitor_type:g,monitor_instructions:g==="instructions"?b:void 0,is_active:z,generate_action:V}),l("Website monitor updated successfully.","success"),i(),o()}catch{l("Failed to update monitor.","error")}finally{Y(!1)}}};if(!a||!p)return null;const v=[{value:"hourly",label:"Every 1hr"},{value:"daily",label:"Every day"},{value:"weekly",label:"Every week"},{value:"monthly",label:"Every month"}];return e.jsxs("div",{className:"fixed inset-0 z-[100] flex justify-center items-center p-4",children:[e.jsx(M.div,{initial:{opacity:0}
2,animate:{opacity:1},exit:{opacity:0},onClick:o,className:"absolute inset-0 backdrop-blur-sm bg-black/20"}),e.jsxs(M.div,{initial:{opacity:0,y:20,scale:.95},animate:{opacity:1,scale:1},exit:{opacity:0,y:20,scale:.95},className:"relative bg-white dark:bg-neutral-800 rounded-xl shadow-lg w-full max-w-lg flex flex-col max-h-[90vh] overflow-hidden",onClick:A=>A.stopPropagation(),children:[e.jsxs("div",{className:"flex justify-between items-center p-6 border-b border-neutral-200 dark:border-neutral-700",children:[e.jsx("h3",{className:"text-lg font-black text-neutral-900 dark:text-neutral-100",children:"Edit Monitor"}),e.jsx("button",{onClick:o,className:"text-neutral-500 hover:text-neutral-800 dark:text-neutral-400 dark:hover:text-neutral-100 transition-colors",children:e.jsx(Re,{className:"w-6 h-6"})})]}),e.jsxs("div",{className:"p-6 flex-1 overflow-y-auto space-y-6",children:[e.jsxs("div",{children:[e.jsx(wt,{label:"Website name",info:"The label for this campaign. We usually use the domain name, but you can change it to anything that helps you stay organized."}),e.jsx("input",{type:"text",value:m,onChange:A=>h(A.target.value),className:"w-full px-4 py-2.5 rounded-xl border border-neutral-200 dark:border-neutral-700 bg-neutral-50 dark:bg-neutral-900 focus:ring-2 focus:ring-brand-primary focus:bg-white outline-none text-sm font-bold"})]}),e.jsxs("div",{className:"bg-neutral-50 dark:bg-neutral-900/50 rounded-2xl border border-neutral-200 dark:border-neutral-700 overflow-hidden divide-y divide-neutral-200 dark:divide-neutral-700",children:[e.jsxs("div",{className:"p-4 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:`p-2 rounded-lg ${z?"bg-green-100 text-green-600 dark:bg-green-900/30 dark:text-green-400":"bg-neutral-100 text-neutral-400"}`,children:e.jsx(Pe,{className:"w-5 h-5"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-black text-sm text-neutral-900 dark:text-neutral-100",children:"Monitoring status"}),e.jsx("p",{className:"text-[10px] text-neutral-500 font-medium",children:"Enable or disable this monitor. When disabled, no new changes will be detected."})]})]}),e.jsx("button",{type:"button",onClick:()=>y(!z),className:`relative inline-flex items-center h-6 w-11 rounded-full transition-colors flex-shrink-0 ${z?"bg-brand-primary":"bg-neutral-300 dark:bg-neutral-600"}`,children:e.jsx("span",{className:`inline-block w-4 h-4 transform bg-white rounded-full transition-transform ${z?"translate-x-6":"translate-x-1"}`})})]}),e.jsxs("div",{className:"p-4 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"p-2 bg-brand-light dark:bg-brand-primary/20 rounded-lg text-brand-primary",children:e.jsx(St,{className:"w-5 h-5"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-black text-sm text-neutral-900 dark:text-neutral-100",children:"AI actions"}),e.jsx("p",{className:"text-[10px] text-neutral-500 font-medium",children:"Auto-generate growth experiments and suggestions whenever a change is detected."})]})]}),e.jsx("button",{type:"button",onClick:()=>S(!V),className:`relative inline-flex items-center h-6 w-11 rounded-full transition-colors flex-shrink-0 ${V?"bg-brand-primary":"bg-neutral-300 dark:bg-neutral-600"}`,children:e.jsx("span",{className:`inline-block w-4 h-4 transform bg-white rounded-full transition-transform ${V?"translate-x-6":"translate-x-1"}`})})]})]}),e.jsxs("div",{children:[e.jsx(wt,{label:"Check frequency",info:"How often should our bots check for updates? Daily is standard, but you can choose faster intervals for high-traffic landing pages."}),e.jsx("select",{value:u,onChange:A=>c(A.target.value),className:"w-full px-4 py-2.5 rounded-xl border border-neutral-200 dark:border-neutral-700 bg-neutral-50 dark:bg-neutral-900 focus:ring-2 focus:ring-brand-primary focus:bg-white outline-none text-sm font-bold",children:v.map(A=>e.jsx("option",{value:A.value,children:A.label},A.value))})]}),e.jsxs("div",{children:[e.jsx(wt,{label:"What to monitor",info:"Select the scope of our change detection. 'All Changes' is safer for QA, while 'Custom' via instructions is better for high-level strategy."}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("button",{type:"button",onClick:()=>s("all_changes"),className:`flex flex-col items-center gap-2 p-4 border-2 rounded-xl transition-all ${g==="all_changes"?"border-brand-primary bg-brand-light/10":"border-neutral-100 dar
2k:border-neutral-700"}`,children:[e.jsx(mt,{className:`w-6 h-6 ${g==="all_changes"?"text-brand-primary":"text-neutral-400"}`}),e.jsx("span",{className:`text-[10px] font-black ${g==="all_changes"?"text-brand-primary":"text-neutral-500"}`,children:"All changes"})]}),e.jsxs("button",{type:"button",onClick:()=>s("instructions"),className:`flex flex-col items-center gap-2 p-4 border-2 rounded-xl transition-all ${g==="instructions"?"border-brand-primary bg-brand-light/10":"border-neutral-100 dark:border-neutral-700"}`,children:[e.jsx(Ma,{className:`w-6 h-6 ${g==="instructions"?"text-brand-primary":"text-neutral-400"}`}),e.jsx("span",{className:`text-[10px] font-black ${g==="instructions"?"text-brand-primary":"text-neutral-50"}`,children:"Custom"})]})]})]}),g==="instructions"&&e.jsxs(M.div,{initial:{opacity:0,y:5},animate:{opacity:1,y:0},children:[e.jsx(wt,{label:"AI instructions",info:"This is where you get specific. Instead of seeing every tiny change, you can tell us to 'only alert if they change their pricing' or 'watch for new product feature mentions'."}),e.jsx("textarea",{value:b,onChange:A=>f(A.target.value),placeholder:"E.g. Focus on pricing and product section only",className:"w-full h-24 px-4 py-3 rounded-xl border border-neutral-200 dark:border-neutral-700 bg-neutral-50 dark:bg-neutral-900 focus:ring-2 focus:ring-brand-primary focus:bg-white outline-none text-sm font-medium"})]})]}),e.jsxs("div",{className:"p-6 border-t border-neutral-200 dark:border-neutral-700 bg-neutral-50 dark:bg-neutral-800/50 rounded-b-2xl flex justify-between items-center",children:[e.jsx("button",{onClick:o,className:"px-6 py-2.5 text-[10px] font-black text-neutral-500 hover:text-neutral-800 transition-colors",children:"Cancel"}),e.jsx("button",{onClick:C,disabled:H,className:"px-8 py-2.5 bg-brand-primary text-white text-[10px] font-black rounded-xl hover:bg-brand-primary/90 transition-all active:scale-95 flex items-center min-w-[120px] justify-center",children:H?e.jsx(nt,{}):"Save changes"})]})]})]})},Ar=({isOpen:a,onClose:o,websiteId:p,onPageAdded:i})=>{const{addToast:l}=tt(),[m,h]=t.useState(""),[u,c]=t.useState(!1),g=async s=>{var b,f;if(s.preventDefault(),!m.trim()){l("Please enter a valid URL","error");return}c(!0);try{await Ta(p,m),l("Page added successfully.","success"),h(""),i(),o()}catch(z){const y=((f=(b=z.response)==null?void 0:b.data)==null?void 0:f.message)||"Failed to add page.";l(y,"error")}finally{c(!1)}};return a?e.jsxs("div",{className:"fixed inset-0 z-[100] flex justify-center items-center p-4",children:[e.jsx(M.div,{initial:{opacity:0}
2,animate:{opacity:1},exit:{opacity:0},onClick:o,className:"absolute inset-0 backdrop-blur-sm bg-black/20"}),e.jsxs(M.div,{initial:{opacity:0,y:20,scale:.95},animate:{opacity:1,scale:1},exit:{opacity:0,y:20,scale:.95},className:"relative bg-white dark:bg-neutral-800 rounded-2xl shadow-lg w-full max-w-md overflow-hidden",onClick:s=>s.stopPropagation(),children:[e.jsxs("div",{className:"flex justify-between items-center p-6 border-b border-neutral-200 dark:border-neutral-700",children:[e.jsx("h3",{className:"text-lg font-black text-neutral-900 dark:text-neutral-100 uppercase tracking-tight",children:"Add Tracking Page"}),e.jsx("button",{onClick:o,className:"text-neutral-500 hover:text-neutral-800 dark:text-neutral-400 dark:hover:text-neutral-100 transition-colors",children:e.jsx(Re,{className:"w-6 h-6"})})]}),e.jsxs("form",{onSubmit:g,className:"p-6",children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("label",{className:"block text-[10px] font-black uppercase tracking-widest text-neutral-400 mb-2",children:"Target URL"}),e.jsx("input",{type:"url",value:m,onChange:s=>h(s.target.value),placeholder:"https://example.com/pricing",className:"w-full px-4 py-2.5 rounded-xl border border-neutral-300 dark:border-neutral-600 bg-neutral-50 dark:bg-neutral-900 focus:ring-2 focus:ring-brand-primary focus:bg-white dark:focus:bg-neutral-800 outline-none text-neutral-900 dark:text-neutral-100 font-bold text-sm transition-all",autoFocus:!0})]}),e.jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[e.jsx("button",{type:"button",onClick:o,className:"px-4 py-2 text-[10px] font-black uppercase tracking-widest text-neutral-500 hover:text-neutral-700 dark:hover:text-neutral-300 transition-colors",children:"Cancel"}),e.jsx("button",{type:"submit",disabled:u,className:"px-6 py-2.5 text-[10px] font-black uppercase tracking-widest bg-brand-primary text-white rounded-xl hover:bg-brand-primary/90 disabled:opacity-50 disabled:cursor-not-allowed transition-all flex items-center",children:u?e.jsx(nt,{}):e.jsxs(e.Fragment,{children:[e.jsx(Ye,{className:"w-3.5 h-3.5 mr-2"})," Add Page"]})})]})]})]})]}):null},Ir=({isOpen:a,onClose:o,page:p,captures:i,isLoading:l,onViewImage:m})=>{const h=u=>u?`${ht}storage/${u}`:null;return e.jsx(be,{children:a&&p&&e.jsxs(e.Fragment,{children:[e.jsx(M.div,{initial:{opacity:0}
2,animate:{opacity:1},exit:{opacity:0},onClick:o,className:"fixed inset-0 backdrop-blur-sm bg-black/20 z-[60]"}),e.jsxs(M.div,{initial:{x:"100%"},animate:{x:0},exit:{x:"100%"},transition:{type:"spring",stiffness:300,damping:30},className:"fixed inset-y-0 right-0 w-full max-w-md bg-white dark:bg-neutral-800 shadow-xl z-[70] flex flex-col",children:[e.jsxs("div",{className:"p-6 border-b border-neutral-200 dark:border-neutral-700 flex justify-between items-start",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-bold text-neutral-900 dark:text-neutral-100",children:"Captures"}),e.jsx("p",{className:"text-sm text-neutral-500 dark:text-neutral-400 truncate mt-1",children:p.url})]}),e.jsx("button",{onClick:o,className:"text-neutral-500 hover:text-neutral-700 dark:text-neutral-400 dark:hover:text-neutral-100",children:e.jsx(Re,{className:"w-6 h-6"})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-6 space-y-6",children:l?e.jsxs("div",{className:"space-y-4",children:[e.jsx(Tt,{className:"h-40 rounded-lg"}),e.jsx(Tt,{className:"h-40 rounded-lg"})]}):i.length>0?e.jsx("div",{className:"space-y-8",children:i.map((u,c)=>{const g=h(u.screenshot_path);return e.jsxs("div",{className:"relative pl-6",children:[c!==i.length-1&&e.jsx("div",{className:"absolute left-[7px] top-2 bottom-[-32px] w-px bg-neutral-100 dark:bg-neutral-700"}),e.jsx("div",{className:"absolute left-0 top-1.5 w-3.5 h-3.5 rounded-full border-2 border-white dark:border-neutral-800 bg-brand-primary"}),e.jsxs("div",{className:"flex items-center gap-2 text-xs font-black uppercase tracking-widest text-neutral-400 mb-3",children:[e.jsx(Et,{className:"w-3.5 h-3.5"}),new Date(u.created_at).toLocaleString()]}),e.jsx("div",{className:"group relative rounded-xl overflow-hidden border border-neutral-200 dark:border-neutral-700 shadow-sm hover:shadow-md transition-shadow",children:e.jsxs("div",{className:"aspect-video bg-neutral-100 dark:bg-neutral-900 cursor-pointer relative",onClick:()=>g&&m(g),children:[g&&e.jsx("img",{src:g,alt:"",className:"w-full h-full object-cover object-top"}),e.jsx("div",{className:"absolute inset-0 bg-black/0 group-hover:bg-black/10 transition-colors flex items-center justify-center opacity-0 group-hover:opacity-100",children:e.jsx(mt,{className:"w-8 h-8 text-white drop-shadow-md"})})]})}),u.ai_summary&&e.jsxs("div",{className:"mt-3 p-3 bg-neutral-50 dark:bg-neutral-900/50 rounded-lg text-xs text-neutral-600 dar
2k:text-neutral-400 border border-neutral-100 dark:border-neutral-700 italic",children:['"',u.ai_summary,'"']})]},u.id)})}):e.jsxs("div",{className:"flex flex-col items-center justify-center py-20 text-neutral-400",children:[e.jsx(Et,{className:"w-12 h-12 mb-4 opacity-20"}),e.jsx("p",{className:"text-sm font-bold uppercase tracking-widest",children:"No history yet"})]})})]})]})})},ea=a=>a?`${ht}storage/${a}`:null,Lr=a=>{if(!a)return"N/A";const o=new Date(a),i=Math.floor((new Date().getTime()-o.getTime())/1e3);if(i<60)return"Just now";const l=[["year",31536e3],["month",2592e3],["day",86400],["hour",3600],["minute",60]];for(let m=0;m<l.length;m++){const[h,u]=l[m],c=Math.floor(i/u);if(c>0){if(h==="year"){const s=i%u,b=Math.floor(s/86400),f=c===1?"1 year":`${c} years`;if(b>0){const z=b===1?"1 day":`${b} days`;return`${f} ${z} ago`}return`${f} ago`}return`${c} ${h}${c!==1?"s":""} ago`}}return"Just now"},ta=({title:a})=>e.jsx("h3",{className:"text-[10px] font-black text-neutral-900 dark:text-neutral-100 uppercase tracking-[0.2em] mb-4",children:a}),$r=({selected:a,onSelect:o})=>{const[p,i]=t.useState(!1),l=t.useRef(null);t.useEffect(()=>{const u=c=>{l.current&&!l.current.contains(c.target)&&i(!1)};return document.addEventListener("mousedown",u),()=>document.removeEventListener("mousedown",u)},[]);const m=[{value:"all",label:"All activities",icon:e.jsx(Nt,{className:"w-4 h-4"})},{value:"unseen",label:"Unseen",icon:e.jsx(mt,{className:"w-4 h-4 text-green-500"})},{value:"saved",label:"Saved",icon:e.jsx(Wt,{className:"w-4 h-4 text-brand-primary"})}],h=m.find(u=>u.value===a)||m[0];return e.jsxs("div",{className:"relative",ref:l,children:[e.jsxs("button",{onClick:()=>i(!p),className:`flex items-center gap-2 px-3 py-2 bg-white dark:bg-neutral-800 border border-neutral-200 dark:border-neutral-700 rounded-lg text-[10px] font-black uppercase tracking-widest text-neutral-600 dar
2k:text-neutral-300 transition-all ${p?"ring-2 ring-brand-primary border-brand-primary":""}`,children:[Ke.cloneElement(h.icon,{className:"w-4 h-4"}),e.jsx("span",{children:h.label}),e.jsx(Je,{className:`w-3.5 h-3.5 text-neutral-400 ml-1 transition-transform ${p?"rotate-180":""}`})]}),e.jsx(be,{children:p&&e.jsx(M.div,{initial:{opacity:0,y:8,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:8,scale:.98},className:"absolute top-full right-0 mt-2 w-48 bg-white dark:bg-neutral-900 rounded-lg shadow-2xl border border-neutral-200 dark:border-neutral-700 z-50 p-1 overflow-hidden",children:e.jsx("div",{className:"space-y-0.5",children:m.map(u=>e.jsxs("button",{onClick:()=>{o(u.value),i(!1)},className:`w-full flex items-center gap-2 px-3 py-2 rounded-md text-[10px] font-black uppercase tracking-widest transition-colors ${a===u.value?"bg-brand-light dark:bg-brand-primary/20 text-brand-primary":"text-neutral-600 dark:text-neutral-300 hover:bg-neutral-50 dark:hover:bg-neutral-800"}`,children:[u.icon,e.jsx("span",{children:u.label}),a===u.value&&e.jsx(Ce,{className:"w-3 h-3 ml-auto"})]},u.value))})})})]})},Mr=({selectedFilter:a,onFilterChange:o,customDates:p,onCustomDateChange:i})=>{var g;const[l,m]=t.useState(!1),h=t.useRef(null);t.useEffect(()=>{const s=b=>{h.current&&!h.current.contains(b.target)&&m(!1)};return document.addEventListener("mousedown",s),()=>document.removeEventListener("mousedown",s)},[]);const u=[{value:"anytime",label:"All time"},{value:"today",label:"Today"},{value:"last_7_days",label:"Last 7 Days"},{value:"last_30_days",label:"Last 30 Days"},{value:"custom",label:"Custom Range"}],c=((g=u.find(s=>s.value===a))==null?void 0:g.label)||"Date";return e.jsxs("div",{className:"relative",ref:h,children:[e.jsxs("button",{onClick:()=>m(!l),className:`flex items-center gap-2 px-3 py-2 bg-white dark:bg-neutral-800 border border-neutral-200 dark:border-neutral-700 rounded-lg text-[11px] font-bold text-neutral-600 dar
2k:text-neutral-300 transition-all ${l?"ring-2 ring-brand-primary border-brand-primary":""}`,children:[e.jsx(_t,{className:"w-4 h-4 text-neutral-400"}),e.jsx("span",{className:"capitalize",children:c}),e.jsx(Je,{className:`w-3.5 h-3.5 text-neutral-400 ml-1 transition-transform ${l?"rotate-180":""}`})]}),e.jsx(be,{children:l&&e.jsxs(M.div,{initial:{opacity:0,y:8,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:8,scale:.98},className:"absolute top-full right-0 mt-2 w-64 bg-white dark:bg-neutral-900 rounded-lg shadow-2xl border border-neutral-200 dark:border-neutral-700 z-50 p-2 overflow-hidden",children:[e.jsx("div",{className:"space-y-1",children:u.map(s=>e.jsx("button",{onClick:()=>{o(s.value),s.value!=="custom"&&m(!1)},className:`w-full text-left px-4 py-2 rounded-md text-[11px] font-bold transition-colors ${a===s.value?"bg-brand-light dark:bg-brand-primary/20 text-brand-primary":"text-neutral-600 dark:text-neutral-300 hover:bg-neutral-50 dark:hover:bg-neutral-800"}`,children:s.label},s.value))}),a==="custom"&&e.jsxs("div",{className:"mt-2 pt-2 border-t border-neutral-100 dark:border-neutral-800 p-3 space-y-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-[9px] font-black uppercase text-neutral-400",children:"Start Date"}),e.jsx("input",{type:"date",value:p.startDate,onChange:s=>i({...p,startDate:s.target.value}),className:"w-full px-2 py-1.5 bg-neutral-50 dark:bg-neutral-800 border border-neutral-200 dark:border-neutral-700 rounded-md text-xs font-bold focus:ring-1 focus:ring-brand-primary outline-none"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-[9px] font-black uppercase text-neutral-400",children:"End Date"}),e.jsx("input",{type:"date",value:p.endDate,onChange:s=>i({...p,endDate:s.target.value}),className:"w-full px-2 py-1.5 bg-neutral-50 dark:bg-neutral-800 border border-neutral-200 dark:border-neutral-700 rounded-md text-xs font-bold focus:ring-1 focus:ring-brand-primary outline-none"})]}),e.jsx("button",{onClick:()=>m(!1),className:"w-full py-2 bg-brand-primary text-white text-[10px] font-black uppercase tracking-widest rounded-md active:scale-95 transition-transform",children:"Apply Range"})]})]})})]})},Dr=({monitorId:a,refreshKey:o=0})=>{const{id:p}=sa(),i=a||p,l=xt(),{addToast:m}=tt(),{selectedProject:h,refreshPermissions:u}=lt(),[c,g]=Ct(),[s,b]=t.useState(!0),[f,z]=t.useState(!1),[y,V]=t.useState(null),[S,H]=t.useState([]),[Y,C]=t.useState([]),[v,A]=t.useState("changes"),Z=c.get("status")||"all",[T,K]=t.useState("anytime"),[O,he]=t.useState({startDate:"",endDate:""}),[oe,ye]=t.useState(null),[ke,ce]=t.useState(null),[xe,ge]=t.useState([]),[we,$]=t.useState(null),[J,E]=t.useState(null),[U,ee]=t.useState(!1),[re,X]=t.useState(!1),[se,N]=t.useState(!1),[q,B]=t.useState(null),[te,F]=t.useState(!1),[R,P]=t.useState(!1),[ue,ae]=t.useState(!1),[Q,je]=t.useState(!0),G=(h==null?void 0:h.is_demo)===1,ve=t.useCallback(async()=>{if(i){b(!0);try{const k=await Ea(parseInt(i));V(k.data.website),H(k.data.pages)}catch{m("Failed to load website details","error")}finally{b(!1)}}},[i,m]),$e=t.useCallback(async(k=!1)=>{if(i&&!(T==="custom"&&(!O.startDate||!O.endDate))){k||z(!0);try{const de=await ca(parseInt(i),T,T==="custom"?O.startDate:void 0,T==="custom"?O.endDate:void 0);C(de.data.activities)}catch{k||m("Failed to load activities","error")}finally{k||z(!1)}}},[i,m,T,O]);t.useEffect(()=>{ve()},[ve]),t.useEffect(()=>{$e()},[$e,i,o,T,O,Z]);const Me=t.useCallback(async k=>{ce(k),b(!0);try{const de=await Oa(k.id);ge(de.data.captures||[])}catch{m("Failed to load captures.","error"),ge([])}finally{b(!1)}},[m]),Ee=async()=>{if(q){F(!0);try{await Ra(q.id),m("Page removed successfully.","success"),N(!1),B(null),ve()}catch{m("Failed to delete page.","error")}finally{F(!1)}}},ne=async()=>{if(y){ae(!0);try{await Pa(y.id),m("Monitor deleted successfully.","success"),P(!1),u&&u(),l("/home")}catch{m("Failed to delete monitor.","error")}finally{ae(!1)}}},I=t.useMemo(()=>Z==="all"?Y:Z==="saved"?Y.filter(k=>k.is_saved):Z==="unseen"?Y.filter(k=>!k.is_seen):Y,[Y,Z]),d=t.useMemo(()=>I.map(k=>{var Be,Ue;let de=null,Ne="website";const De=(Be=k.category)==null?void 0:Be.toLowerCase();if(De==="blog"){Ne="blog";const ie=(Ue=k.blog_posts)==null?void 0:Ue[0];
2de=JSON.stringify({title:(ie==null?void 0:ie.title)||k.summary,url:(ie==null?void 0:ie.url)||k.url,description:k.summary,image:k.after_screenshot?ea(k.after_screenshot):null})}else if(De==="pricing"){Ne="pricing";const ie=(k.pricing||[]).map(_e=>{var x;return{type:"price",field:`${_e.plan} tier`,old:_e.old_price,new:_e.plan,reasoning:`New features detected: ${((x=_e.changed_features)==null?void 0:x.join(", "))||"N/A"}`}}),We=k.changes||[];de=JSON.stringify({summary:k.summary,changes:ie.length>0?ie:We.map(_e=>({type:_e.type||"pricing",field:_e.field,old:_e.old,new:_e.new,reasoning:_e.reasoning||_e.field}))})}else De==="seo"?(Ne="seo",de=JSON.stringify({summary:k.summary,changes:(k.changes||[]).map(ie=>({type:ie.type||"seo",field:ie.field,old:ie.old,new:ie.new,reasoning:ie.reasoning}))})):(Ne="website",de=JSON.stringify({summary:k.summary,changes:(k.changes||[]).map(ie=>({type:ie.type,field:ie.field,old:ie.old,new:ie.new,reasoning:ie.reasoning}))}));return{id:k.id,competitor_id:0,page_id:k.page_id,type:Ne,summary:k.summary,created_at:k.created_at,before_screenshot:k.before_screenshot,after_screenshot:k.after_screenshot,diff_summary:de,monitor:y}}),[I,y]),D=(y==null?void 0:y.status)==="active",fe=()=>y?e.jsxs("div",{className:"space-y-10 max-w-4xl py-2",children:[e.jsxs("div",{children:[e.jsx(ta,{title:"About this website"}
2),e.jsx("p",{className:"text-lg text-neutral-600 dark:text-neutral-300 font-medium leading-relaxed",children:"This website is monitored to detect meaningful content, messaging, or structural changes. Growlytics watches for tactical pivots that signal shifts in market direction."})]}),e.jsxs("div",{className:"p-7 bg-neutral-50 dark:bg-neutral-900/50 rounded-xl border border-neutral-100 dark:border-neutral-800",children:[e.jsx("div",{className:"flex flex-col md:flex-row md:items-center justify-between gap-6",children:e.jsxs("div",{className:"flex items-center gap-5",children:[e.jsxs("div",{className:"relative flex items-center justify-center w-8 h-8 flex-shrink-0",children:[e.jsx("div",{className:"absolute inset-0 border-4 border-neutral-200 dark:border-neutral-700 rounded-full"}),e.jsx("div",{className:"absolute inset-0 border-4 border-brand-primary rounded-full border-t-transparent animate-spin"})]}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-base font-black text-neutral-900 dark:text-neutral-100 tracking-tight uppercase",children:"Taking initial snapshots"}),e.jsx("p",{className:"text-xs text-neutral-500 font-bold uppercase tracking-widest mt-0.5",children:"Capturing baseline architecture"})]})]})}
2),e.jsx("p",{className:"text-sm text-neutral-600 dark:text-neutral-400 font-medium leading-relaxed mt-5",children:"We're currently taking initial snapshots of your pages to establish a baseline. You'll be notified automatically as soon as we detect any significant departures from this state."})]}),e.jsxs("div",{children:[e.jsx(ta,{title:"Change Detection Logic"}),e.jsxs("p",{className:"text-lg text-neutral-600 dark:text-neutral-300 font-medium leading-relaxed",children:["Minor cosmetic updates are ignored by our engine. We prioritize ",e.jsx("span",{className:"text-neutral-900 dark:text-neutral-100 font-black underline decoration-brand-primary/30 underline-offset-4",children:"strategy, positioning, and intent"})," changes that impact your growth landscape."]})]})]}):null;return s&&!y?e.jsx(Dt,{}):y?e.jsxs("div",{className:"bg-white dark:bg-neutral-900 min-h-full flex flex-col h-full overflow-hidden",children:[f&&Y.length===0&&e.jsx(Dt,{}),e.jsx(Bt,{imageUrl:oe,onClose:()=>ye(null)}),e.jsx(Ir,{isOpen:!!ke,onClose:()=>ce(null),page:ke,captures:xe,isLoading:s,onViewImage:ye}),e.jsx(_r,{isOpen:U,onClose:()=>ee(!1),website:y,onUpdate:ve}),e.jsx(Ar,{isOpen:re,onClose:()=>X(!1),websiteId:y.id,onPageAdded:ve}),e.jsx(Ut,{isOpen:!!we,onClose:()=>$(null),activity:we,competitor:void 0}),e.jsx(Gt,{isOpen:!!J,onClose:()=>E(null),activity:J,competitor:void 0}),e.jsx(jt,{isOpen:se,onClose:()=>N(!1),onConfirm:Ee,title:"Delete Page?",message:`Are you sure you want to remove ${q==null?void 0:q.url} from monitoring?`,confirmText:"Delete",borderClassName:"border-red-500",isLoading:te}),e.jsx(jt,{isOpen:R,onClose:()=>P(!1),onConfirm:ne,title:"Delete Website Monitor?",message:`This will delete "${y.name}" and all its associated history. This action cannot be undone.`,confirmText:"Delete",isLoading:ue}),e.jsx("div",{className:"p-6 md:p-8 pb-4 flex-shrink-0",children:e.jsxs("div",{className:"flex flex-col md:flex-row justify-between items-start md:items-center gap-4",children:[e.jsxs("div",{className:"flex items-center gap-5",children:[e.jsx("div",{className:"w-16 h-16 rounded-xl bg-neutral-50 dark:bg-neutral-800 border border-neutral-200 dark:border-neutral-700 flex items-center justify-center overflow-hidden",children:y.domain?e.jsx("img",{src:`https://www.google.com/s2/favicons?domain=${y.domain}&sz=128`,alt:"",className:"w-full h-full object-contain p-2"}):e.jsx(yt,{className:"w-8 h-8 text-brand-primary"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("h1",{className:"text-2xl font-bold text-neutral-900 dark:text-neutral-100 tracking-tight truncate",children:y.name}),e.jsxs("div",{className:`flex items-center gap-1.5 px-2 py-0.5 rounded-full border ${D?"bg-green-50 dark:bg-green-900/30 border-green-200 dark:border-green-800":"bg-neutral-50 border border-neutral-200 dark:border-neutral-800 dark:border-neutral-700"}`,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${D?"bg-green-500 animate-pulse":"bg-neutral-400"}`}),e.jsx("span",{className:`text-[9px] font-bold ${D?"text-green-600 dark:text-green-400":"text-neutral-500 dark:text-neutral-400"}`,children:D?"Active":"Inactive"})]})]}),e.jsx("a",{href:`https://${y.domain}`,target:"_blank",rel:"noreferrer",className:"text-brand-primary font-bold hover:underline text-sm mt-1 block",children:y.domain})]})]}),e.jsxs("div",{className:"flex items-center gap-2 pr-4",children:[e.jsxs("button",{onClick:()=>ee(!0),disabled:G,className:"inline-flex items-center gap-2 px-4 py-2 bg-white dark:bg-neutral-800 border border-neutral-200 dark:border-neutral-700 rounded-lg text-[11px] font-bold text-neutral-700 dark:text-neutral-200 hover:bg-neutral-50 transition-all active:scale-95 shadow-sm disabled:opacity-50 disabled:cursor-not-allowed",children:[e.jsx(zt,{className:"w-3.5 h-3.5"}),"Edit"]}),e.jsx("button",{onClick:()=>P(!0),disabled:G,className:"p-2 bg-white dark:bg-neutral-800 border border-neutral-200 dark:border-neutral-700 rounded-lg text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20 transition-all active:scale-95 shadow-sm disabled:opacity-50 disabled:cursor-not-allowed",children:e.jsx(kt,{className:"w-5 h-5"})}),e.jsxs("button",{onClick:()=>{A("pages"),X(!0)},disabled:G,className:"flex items-center gap-2 px-4 py-2 bg-brand-primary text-white text-[11px] font-bold rounded-lg hover:bg-brand-primary/90 transition-all active:scale-95 shadow-lg shadow-brand-primary/20 disabled:opacity-50 disabled:cursor-not-allowed",children:[e.jsx(Ye,{className:"w-4 h-4"}),"Add page"]})]})]})}
2),e.jsx("div",{className:"sticky top-0 z-10 bg-white/95 dark:bg-neutral-900/95 backdrop-blur border-b border-neutral-100 dark:border-neutral-800 px-6 md:px-8 shadow-sm flex-shrink-0",children:e.jsxs("div",{className:"flex flex-row items-center justify-between gap-4",children:[e.jsx("div",{className:"flex items-center gap-8 -mb-px",children:[{id:"changes",label:"Changes"},{id:"pages",label:"Pages"}].map(k=>e.jsxs("button",{onClick:()=>A(k.id),className:`relative pt-4 pb-4 text-sm font-bold transition-all ${v===k.id?"text-brand-primary":"text-neutral-400 hover:text-neutral-700 dark:hover:text-neutral-200"}`,children:[k.label,v===k.id&&e.jsx(M.div,{layoutId:"websiteTabIndicator",className:"absolute bottom-0 left-0 right-0 h-0.5 bg-brand-primary"})]},k.id))}),e.jsx("div",{className:"flex items-center gap-2 py-3 pr-4",children:v==="changes"&&e.jsxs(e.Fragment,{children:[e.jsx($r,{selected:Z,onSelect:k=>{const de=new URLSearchParams(c);de.set("status",k),g(de,{replace:!0})}}),e.jsx(Mr,{selectedFilter:T,onFilterChange:K,customDates:O,onCustomDateChange:he})]})})]})}),e.jsx("div",{className:"p-6 md:p-8 bg-white dark:bg-neutral-900 flex-grow overflow-y-auto",children:e.jsx("div",{className:"pr-4 h-full",children:e.jsx(be,{mode:"wait",children:v==="changes"?e.jsxs(M.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},className:"space-y-6 h-full",children:[e.jsx(be,{children:Q&&!f&&e.jsxs(M.div,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},exit:{opacity:0,scale:.98},className:"bg-white dark:bg-neutral-800 border border-neutral-200 dark:border-neutral-700 p-6 mb-4 flex items-start gap-5 transition-all shadow-sm rounded-lg",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("h3",{className:"text-[10px] font-black uppercase tracking-[0.2em] text-neutral-900 dark:text-neutral-100 mb-3",children:["We’re monitoring ",y.domain," for any changes"]}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-sm text-neutral-600 dar
2k:text-neutral-400 leading-relaxed font-medium",children:"Website monitoring is active. We have captured a full visual and structural baseline for all tracked pages on your domain."}),e.jsxs("p",{className:"text-sm text-neutral-600 dark:text-neutral-400 leading-relaxed font-medium",children:["Currently tracking ",e.jsx("span",{className:"text-brand-primary font-black",children:S.length})," pages with ",e.jsx("span",{className:"text-brand-primary font-black",children:(Y.length||0).toLocaleString()})," historical changes indexed. You'll be the first to know about any visual or structural drift via instant notifications."]})]})]}),e.jsx("button",{onClick:()=>je(!1),className:"p-1.5 bg-red-50 dark:bg-red-900/20 text-red-500 rounded hover:bg-red-100 dark:hover:bg-red-900/30 transition-colors shrink-0",children:e.jsx(Re,{className:"w-4 h-4"})})]})}),d.length>0?e.jsx("div",{className:"flex flex-col gap-6",children:d.map((k,de)=>e.jsx(Vt,{activity:k,competitor:void 0,viewMode:"grid",disableLink:!0,onViewChange:()=>$(k),onCreateAction:()=>E(k),className:"hover:border-brand-primary transition-all duration-300 rounded-lg"},`${k.monitor.type}-${k.monitor.id}-${k.id}-${de}`))}):!f&&fe()]},"changes"):e.jsx(M.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},exit:{opacity:0,y:-10},className:"space-y-4 h-full",children:S.length>0?e.jsx("div",{className:"grid grid-cols-1 gap-4",children:S.map(k=>{const de=ea(k.screenshot_path);return e.jsxs("div",{onClick:()=>Me(k),className:"bg-white dark:bg-neutral-800 border border-neutral-200 dark:border-neutral-700 rounded-2xl p-5 hover:border-brand-primary dark:hover:border-brand-primary transition-all group flex items-center gap-6 cursor-pointer",children:[e.jsx("div",{className:"flex-shrink-0 w-32 h-20 bg-neutral-50 dark:bg-neutral-900 rounded-xl overflow-hidden border border-neutral-200 dark:border-neutral-600 flex items-center justify-center",children:de?e.jsx("img",{src:de,alt:k.title,className:"w-full h-full object-cover object-top"}):e.jsx(Fa,{className:"w-8 h-8 text-neutral-300"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h4",{className:"font-bold text-neutral-900 dark:text-neutral-100 text-lg group-hover:text-brand-primary transition-colors truncate",children:k.title||"Untitled Page"}),e.jsx("p",{className:"text-sm text-neutral-500 dark:text-neutral-400 truncate mt-0.5",children:k.url}),e.jsxs("div",{className:"flex items-center gap-4 mt-3",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] font-bold text-neutral-400 uppercase tracking-widest",children:[e.jsx(Et,{className:"w-3.5 h-3.5"}),"Checked ",Lr(k.last_checked_at)]}),e.jsxs("div",{className:"px-2 py-0.5 bg-neutral-100 dark:bg-neutral-800 rounded text-[9px] font-bold uppercase tracking-widest text-neutral-500",children:[k.captures_count||0," Captures"]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:Ne=>{Ne.stopPropagation(),Me(k)},className:"p-2.5 bg-neutral-50 dark:bg-neutral-700/50 hover:bg-neutral-100 dark:hover:bg-neutral-700 rounded-xl text-neutral-500 dark:text-neutral-300 transition-colors",title:"View History",children:e.jsx(mt,{className:"w-5 h-5"})}),e.jsx("button",{onClick:Ne=>{Ne.stopPropagation(),B(k),N(!0)},disabled:G,className:"p-2.5 bg-red-50 dark:bg-red-900/20 hover:bg-red-100 dark:hover:bg-red-900/30 rounded-xl text-red-500 transition-colors opacity-0 group-hover:opacity-100 disabled:opacity-30 disabled:cursor-not-allowed",title:"Delete Page",children:e.jsx(kt,{className:"w-5 h-5"})})]})]},k.id)})}):!s&&e.jsxs("div",{className:"py-20 p-8 text-center bg-neutral-50 dark:bg-neutral-800 rounded-3xl border border-neutral-100 dark:border-neutral-700 border-dashed",children:[e.jsx(ot,{className:"w-12 h-12 text-neutral-200 dark:text-neutral-700 mx-auto mb-4"}),e.jsx("p",{className:"text-neutral-500 font-bold uppercase tracking-widest text-sm",children:"No pages tracked"}),!G&&e.jsx("button",{onClick:()=>X(!0),className:"mt-4 text-brand-primary font-black text-xs uppercase tracking-widest hover:underline",children:"+ Add a page to start monitoring"})]})},"pages")})})})]}):null},pt=({label:a,info:o,className:p})=>{const[i,l]=t.useState(!1);return e.jsxs("div",{className:`flex items-center gap-1.5 mb-2 px-1 ${p}`,children:[e.jsx("label",{className:"text-sm font-black text-neutral-800 dark:text-neutral-200 block",children:a}),e.jsxs("div",{className:"relative",children:[e.jsx("button",{type:"button",onMouseEnter:()=>l(!0),onMouseLeave:()=>l(!1),onClick:()=>l(!i),className:"text-cyan-500 hover:text-cyan-600 transition-colors p-0.5 rounded-full",children:e.jsx(St,{className:"w-4 h-4"})}),e.jsx(be,{children:i&&e.jsxs(M.div,{initial:{opacity:0,y:5}
2,animate:{opacity:1,y:0},exit:{opacity:0,y:5},className:"absolute bottom-full left-1/2 -translate-x-1/2 mb-2 w-56 p-3 bg-neutral-900 text-white text-xs font-medium leading-relaxed rounded-lg shadow-xl z-[150] pointer-events-none",children:[e.jsx("div",{className:"absolute top-full left-1/2 -translate-x-1/2 border-8 border-transparent border-t-neutral-900"}),o]})})]})]})},st=10,Tr=a=>e.jsx("svg",{viewBox:"0 0 24 24",fill:"currentColor",...a,children:e.jsx("path",{d:"M12 0A12 12 0 0 0 0 12a12 12 0 0 0 12 12 12 12 0 0 0 12-12A12 12 0 0 0 12 0zm5.01 4.744c.688 0 1.25.561 1.25 1.249a1.25 1.249a1.25 1.249a1.25 1.249a1.25 1.249a1.25 1.249a1.25 1.249a1.25 1.249a1.25 1.249a1.25 1.249 0 0 1-2.498.056l-2.597-.547-.8 3.747c1.824.07 3.48.632 4.674 1.488.308-.309.73-.491 1.207-.491.968 0 1.754.786 1.754 1.754 0 .716-.435 1.333-1.01 1.614a3.111 3.111 0 0 1 .042.52c0 2.694-3.13 4.87-7.004 4.87-3.874 0-7.004-2.176-7.004-4.87 0-.183.015-.366.043-.534A1.748 1.748 0 0 1 4.028 12c0-.968.786-1.754 1.754-1.754.463 0 .898.196 1.207.49 1.207-.883 2.878-1.43 4.744-1.487l.885-4.182a.342.342 0 0 1 .14-.197.35.35 0 0 1 .238-.042l2.906.617a1.214 1.214 0 0 1 1.108-.701zM9.25 12C8.561 12 8 12.562 8 13.25c0 .687.561 1.248 1.25 1.248.687 0 1.248-.561 1.248-1.249 0-.688-.561-1.249-1.249-1.249zm5.5 0c-.687 0-1.248.561-1.248 1.25 0 .687.561 1.249 1.248.688 0 1.249-.561 1.249-1.249 0-.687-.562-1.249-1.25-1.249zm-5.466 3.99a.327.327 0 0 0-.231.094.33.33 0 0 0 0 .463c.842.842 2.484.913 2.961.913.477 0 2.105-.056 2.961-.913a.361.361 0 0 0 .029-.463.33.33 0 0 0-.464 0c-.547.533-1.684.73-2.512.73-.828 0-1.979-.196-2.512-.73a.326.326 0 0 0-.232-.095z"})}),Er=({isOpen:a,onClose:o,listener:p,projectId:i,onUpdate:l})=>{var I;const{addToast:m}=tt(),{permissions:h,selectedProject:u}=lt(),c=xt(),[g,s]=t.useState(!0),[b,f]=t.useState(!1),[z,y]=t.useState(!1),[V,S]=t.useState(!1),[H,Y]=t.useState("general"),[C,v]=t.useState([]),[A,Z]=t.useState(""),[T,K]=t.useState(""),[O,he]=t.useState([]),[oe,ye]=t.useState(""),[ke,ce]=t.useState([]),[xe,ge]=t.useState([]),[we,$]=t.useState(""),[J,E]=t.useState([]),[U,ee]=t.useState(5),[re,X]=t.useState(!0),[se,N]=t.useState(!1),[q,B]=t.useState(!0),te=(u==null?void 0:u.is_demo)===1,F=d=>{if(!d)return[];if(Array.isArray(d))return d;try{const D=JSON.parse(d);return Array.isArray(D)?D:[d]}catch{return[d]}};t.useEffect(()=>{if(u!=null&&u.subreddit_suggestions)try{const d=typeof u.subreddit_suggestions=="string"?JSON.parse(u.subreddit_suggestions):u.subreddit_suggestions;E(Array.isArray(d)?d:[])}catch{E([])}},[u]);const R=t.useCallback(async()=>{var d;if(!(!p||!a)){s(!0);try{const fe=(await pa(i,p.id)).data,k=fe.listener||fe;if(!k)throw new Error("No listener data found");v(F(k.search_query)),K(k.title||""),he(k.channels||[]),ye(k.instructions||""),ce(k.insight_layers||[]),ge(k.sub_reddits||[]),ee(k.engagement_threshold||5),X(k.generate_action===1||k.generate_action===!0),N(k.lead_generate===1||k.lead_generate===!0),B(((d=k.status)==null?void 0:d.toLowerCase())==="active")}catch{m("Failed to fetch listener details.","error"),o()}finally{s(!1)}}},[p,a,i,m,o]);t.useEffect(()=>{a&&(R(),Y("general"))},[a,R]);const P=(I=h==null?void 0:h.access)==null?void 0:I.social_listening,ue=[{id:"facebook",name:"Facebook",icon:e.jsx($t,{className:"w-5 h-5 text-[#1877F2]"}),color:"bg-[#1877F2]",allowed:(P==null?void 0:P.facebook)??!0},{id:"twitter",name:"Twitter",icon:e.jsx(gt,{className:"w-5 h-5 text-[#1DA1F2]"}),color:"bg-[#1DA1F2]",allowed:P==null?void 0:P.twitter},{id:"linkedin",name:"LinkedIn",icon:e.jsx(ft,{className:"w-5 h-5 text-[#0A66C2]"}),color:"bg-[#0A66C2]",allowed:P==null?void 0:P.linkedin},{id:"reddit",name:"Reddit",icon:e.jsx(Tr,{className:"w-5 h-5 text-[#FF4500]"}),color:"bg-[#FF4500]",allowed:P==null?void 0:P.reddit}],ae=[{id:"question-seeking-tool",label:"Seeking Tool",description:"Identify users looking for alternatives.",icon:e.jsx(qe,{className:"w-4 h-4 text-blue-500"}),bg:"bg-blue-100 dark:bg-blue-900/30"},{id:"complaint",label:"Complaint",description:"Find frustrated users on social.",icon:e.jsx(ut,{className:"w-4 h-4 text-red-500"}),bg:"bg-red-100 dark:bg-red-900/30"},{id:"comparison",label:"Comparison",description:"Rival vs Rival discussions.",icon:e.jsx(oa,{className:"w-4 h-4 text-amber-500"}
2),bg:"bg-amber-100 dark:bg-amber-900/30"},{id:"open-discussion",label:"Open Discussion",description:"General relevant threads.",icon:e.jsx(Ft,{className:"w-4 h-4 text-indigo-500"}),bg:"bg-indigo-100 dark:bg-indigo-900/30"},{id:"news/trend",label:"News/Trend",description:"Market shifts and hot topics.",icon:e.jsx(Pe,{className:"w-4 h-4 text-emerald-500"}),bg:"bg-emerald-100 dark:bg-emerald-900/30"},{id:"buying-signal",label:"Buying Signal",description:"High intent purchasing signals.",icon:e.jsx(da,{className:"w-3.5 h-3.5 text-purple-500"}),bg:"bg-purple-100 dark:bg-purple-900/30"},{id:"feature-request",label:"Feature Request",description:"Missing rival features.",icon:e.jsx(Ye,{className:"w-4 h-4 text-pink-500"}),bg:"bg-pink-100 dark:bg-pink-900/30"},{id:"business-opportunity",label:"Business Opportunity",description:"Partnership or bulk signals.",icon:e.jsx(ct,{className:"w-4 h-4 text-gray-500"}),bg:"bg-gray-100 dark:bg-gray-900/30"}],Q=()=>{const d=A.trim();if(d){if(C.length>=st){m(`Maximum ${st} keywords allowed per listener.`,"error");return}C.includes(d)||(v([...C,d]),Z(""))}},je=d=>{v(C.filter(D=>D!==d))},G=()=>{const d=we.trim().toLowerCase();if(d&&!xe.includes(d)){const D=d.startsWith("r/")?d:`r/${d}`;ge(fe=>[...fe,D]),$("")}},ve=d=>{he(D=>D.includes(d)?D.filter(fe=>fe!==d):[...D,d])},$e=d=>{ce(D=>D.includes(d)?D.filter(fe=>fe!==d):[...D,d])},Me=async()=>{if(p){if(C.length===0){m("At least one keyword is required.","error");return}f(!0);try{await Wa(p.id,{status:q?"active":"inactive",lead_generate:se,channels:O,search_query:C,title:T||null,instructions:oe||null,generate_action:re,sub_reddits:xe,engagement_threshold:U,insight_layers:ke,frequency:24}),m("Listener updated successfully.","success"),l(),o()}catch{m("Failed to update listener.","error")}finally{f(!1)}}},Ee=async()=>{if(!(!p||te)){y(!0);try{await ha(p.id),m("Listener deleted successfully","success"),l(),o(),c("/opportunities")}catch{m("Failed to delete listener","error")}finally{y(!1),S(!1)}}},ne="w-full px-4 py-3 text-sm border border-neutral-300 dark:border-neutral-600 rounded-xl bg-white dark:bg-neutral-800 focus:ring-2 focus:ring-brand-primary outline-none transition-all dark:text-neutral-100";return e.jsx(be,{children:a&&p&&e.jsxs("div",{className:"fixed inset-0 z-[110] flex justify-center items-center p-4",children:[e.jsx(M.div,{initial:{opacity:0}
2,animate:{opacity:1},exit:{opacity:0},onClick:o,className:"absolute inset-0 backdrop-blur-sm bg-black/20"}),e.jsxs(M.div,{initial:{opacity:0,scale:.95,y:20},animate:{opacity:1,scale:1,y:0},exit:{opacity:0,scale:.95,y:20},className:"relative bg-white dark:bg-neutral-800 rounded-2xl shadow-xl w-full max-w-2xl flex flex-col max-h-[90vh] overflow-hidden",onClick:d=>d.stopPropagation(),children:[e.jsx(jt,{isOpen:V,onClose:()=>S(!1),onConfirm:Ee,title:"Delete Listener?",message:"Stop monitoring and delete all results? This action cannot be undone.",confirmText:"Delete",isLoading:z}),e.jsxs("div",{className:"flex justify-between items-center p-6 border-b border-neutral-200 dark:border-neutral-700",children:[e.jsx("h3",{className:"text-xl font-black text-neutral-900 dark:text-neutral-100 tracking-tight",children:"Edit Social Listener"}),e.jsx("button",{onClick:o,className:"p-1 text-neutral-400 hover:text-neutral-800 transition-colors",children:e.jsx(Re,{className:"w-7 h-7"})})]}),e.jsx("div",{className:"flex px-6 border-b border-neutral-100 dark:border-neutral-700 bg-neutral-50/30 dark:bg-neutral-900/30",children:["general","channels","insights"].map(d=>e.jsxs("button",{onClick:()=>Y(d),className:`px-6 py-4 text-sm font-black transition-all relative capitalize ${H===d?"text-brand-primary":"text-neutral-400 hover:text-neutral-600"}`,children:[d,H===d&&e.jsx(M.div,{layoutId:"tabUnderline",className:"absolute bottom-0 left-0 right-0 h-0.5 bg-brand-primary"})]},d))}),e.jsx("div",{className:"p-8 flex-1 overflow-y-auto custom-scrollbar endurance-scroll relative",children:g?e.jsxs("div",{className:"absolute inset-0 z-10 flex flex-col items-center justify-center bg-white dark:bg-neutral-800",children:[e.jsx("div",{className:"w-10 h-10 border-4 border-brand-primary rounded-full border-t-transparent animate-spin mb-4"}),e.jsx("p",{className:"text-xs font-black uppercase tracking-widest text-neutral-400",children:"Fetching latest configuration..."})]}):e.jsxs(be,{mode:"wait",children:[H==="general"&&e.jsxs(M.div,{initial:{opacity:0,x:5},animate:{opacity:1,x:0},exit:{opacity:0,x:-5},className:"space-y-8",children:[e.jsxs("div",{children:[e.jsx(pt,{label:"Monitor title",info:"The label for this campaign. Helps you identify it in your navigation."}),e.jsx("input",{value:T,onChange:d=>K(d.target.value),className:ne,placeholder:"e.g. Chatbot Market Surveillance"})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-end mb-2",children:[e.jsx(pt,{label:"Keywords",info:"What should we listen for? You can add up to 4 keyword phrases or brand terms, with a combined length of 75 characters. Our AI will scan for these exact terms across social platforms.",className:"!mb-0"}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsxs("span",{className:"text-[11px] font-black text-neutral-500 uppercase tracking-tight",children:["Keywords: ",e.jsxs("span",{className:C.length>=st?"text-amber-500":"text-brand-primary",children:[C.length," / ",st," used"]})]})})]}),e.jsxs("div",{className:"relative",children:[e.jsx(qe,{className:"absolute left-4 top-1/2 -translate-y-1/2 w-5 h-5 text-neutral-300"}),e.jsx("input",{value:A,onChange:d=>Z(d.target.value),onKeyDown:d=>d.key==="Enter"&&(d.preventDefault(),Q()),disabled:C.length>=st,className:`${ne} pl-12`,placeholder:"Add keyword..."}),e.jsx("button",{type:"button",onClick:Q,disabled:!A.trim()||C.length>=st,className:"absolute right-3 top-1/2 -translate-y-1/2 p-2 bg-neutral-100 dark:bg-neutral-700 rounded-lg text-neutral-500 hover:text-brand-primary disabled:opacity-50",children:e.jsx(Ye,{className:"w-5 h-5"})})]}),C.length>=st&&e.jsxs(M.div,{initial:{opacity:0,y:-5},animate:{opacity:1,y:0},className:"mt-3 flex items-center gap-2 text-xs font-bold text-amber-600 dark:text-amber-400 bg-amber-50 dark:bg-amber-900/20 px-3 py-2 rounded-lg border border-amber-200 dark:border-amber-800",children:[e.jsx(la,{className:"w-4 h-4"}),"Limit reached: Max ",st," keywords."]}),e.jsx("div",{className:"flex flex-wrap gap-2 mt-4",children:C.map(d=>e.jsxs("span",{className:"inline-flex items-center gap-2 px-3 py-1 bg-brand-light/50 dark:bg-brand-primary/20 border border-brand-primary/10 rounded-lg text-sm font-bold text-brand-primary",children:[d,e.jsx("button",{type:"button",onClick:()=>je(d),className:"hover:text-brand-secondary transition-colors",children:e.jsx(Re,{className:"w-4 h-4"})})]},d))})]}),e.jsxs("div",{children:[e.jsx(pt,{label:"AI prompt instructions",info:"Tell the AI how to evaluate your matches. Should it be professional, cheeky, or purely helpful? This guides the drafts we create for you."}),e.jsx("textarea",{value:oe,onChange:d=>ye(d.target.value),className:`${ne} h-28 resize-none py-4 leading-relaxed`,placeholder:"Specific rules for AI analysis..."})]}),e.jsxs("div",{className:"bg-neutral-50 dark:bg-neutral-900/50 rounded-2xl border border-neutral-200 dark:border-neutral-700 overflow-hidden divide-y divide-neutral-200 dark:divide-neutral-700",children:[e.jsxs("div",{className:"p-5 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:`p-2.5 rounded-lg ${q?"bg-green-100 text-green-600 dark:bg-green-900/30 dark:text-green-400":"bg-neutral-100 text-neutral-400"}`,children:e.jsx(Pe,{className:"w-6 h-6"})}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-bold text-sm text-neutral-900 dark:text-neutral-100",children:"Monitoring status"}),e.jsx("p",{className:"text-xs text-neutral-500 font-medium",children:"Turn off to pause monitoring."})]})]}),e.jsx("button",{type:"button",onClick:()=>B(!q),className:`relative inline-flex items-center h-6 w-11 rounded-full transition-colors flex-shrink-0 ${q?"bg-brand-primary":"bg-neutral-300 dark:bg-neutral-600"}`,children:e.jsx("span",{className:`inline-block w-4 h-4 transform bg-white rounded-full transition-transform ${q?"translate-x-6":"translate-x-1"}`})})]}),e.jsxs("div",{className:"p-5 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"p-2.5 bg-brand-light dark:bg-brand-primary/20 rounded-lg text-brand-primary",children:e.jsx(Ve,{className:"w-6 h-6"})}),e.jsxs("div",{children:[e.jsx("h4",{className:"font-bold text-sm text-neutral-900 dark:text-neutral-100",children:"AI actions"}),e.jsx("p",{className:"text-xs text-neutral-500 font-medium",children:"Auto-generate growth suggestions and engagement tasks."})]})]}),e.jsx("button",{type:"button",onClick:()=>
2X(!re),className:`relative inline-flex items-center h-6 w-11 rounded-full transition-colors flex-shrink-0 ${re?"bg-brand-primary":"bg-neutral-300 dark:bg-neutral-600"}`,children:e.jsx("span",{className:`inline-block w-4 h-4 transform bg-white rounded-full transition-transform ${re?"translate-x-6":"translate-x-1"}`})})]})]})]},"general"),H==="channels"&&e.jsxs(M.div,{initial:{opacity:0,x:5},animate:{opacity:1,x:0},exit:{opacity:0,x:-5},className:"space-y-8",children:[e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:ue.map(d=>e.jsxs("button",{onClick:()=>d.allowed&&ve(d.id),disabled:!d.allowed,className:`relative flex flex-col items-center justify-center p-8 border-2 rounded-2xl transition-all ${d.allowed?O.includes(d.id)?"border-brand-primary bg-brand-light/10 shadow-sm":"border-neutral-100 dark:border-neutral-700 hover:border-brand-primary/30":"opacity-40 grayscale cursor-not-allowed bg-neutral-50 dark:bg-neutral-800"}`,children:[d.icon,e.jsx("span",{className:`text-xs font-black mt-4 uppercase tracking-widest ${O.includes(d.id)?"text-brand-primary":"text-neutral-400"}`,children:d.name}),O.includes(d.id)&&d.allowed&&e.jsx("div",{className:"absolute top-3 right-3 bg-brand-primary rounded-full p-0.5 shadow-sm",children:e.jsx(Ce,{className:"w-4 h-4 text-white"})})]},d.id))}),O.includes("reddit")&&e.jsxs("div",{className:"space-y-4 pt-4 border-t border-neutral-100 dark:border-neutral-700",children:[e.jsx(pt,{label:"Specific subreddits",info:"Reddit is huge! By specifying subreddits (like r/saas or r/startups), you help us find the most relevant conversations where your audience actually hangs out."}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx("input",{value:we,onChange:d=>$(d.target.value),onKeyDown:d=>d.key==="Enter"&&(d.preventDefault(),G()),className:ne,placeholder:"e.g. r/saas"}),e.jsx("button",{onClick:G,className:"px-5 py-2.5 bg-neutral-100 dark:bg-neutral-700 rounded-lg text-neutral-500 hover:text-brand-primary transition-colors",children:e.jsx(Ye,{className:"w-6 h-6"})})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:xe.map(d=>e.jsxs("span",{className:"px-3 py-1.5 bg-brand-primary text-white rounded-lg text-sm font-bold flex items-center gap-2 shadow-sm",children:[d,e.jsx("button",{onClick:()=>ge(D=>D.filter(fe=>fe!==d)),className:"hover:text-red-200",children:e.jsx(Re,{className:"w-4 h-4"})})]},d))}),J.length>0&&e.jsxs("div",{className:"mt-4",children:[e.jsx("p",{className:"text-[10px] font-black uppercase tracking-widest text-neutral-400 mb-3 px-1",children:"Suggested Subreddits"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:J.map(d=>{const D=d.startsWith("r/")?d:`r/${d}`,fe=xe.includes(D);return e.jsx("button",{type:"button",onClick:()=>{ge(fe?k=>k.filter(de=>de!==D):k=>[...k,D])},className:`px-3 py-1.5 rounded-lg text-xs font-bold border transition-all ${fe?"bg-neutral-800 border-neutral-800 text-white":"bg-white dark:bg-neutral-800 border-neutral-200 dark:border-neutral-700 text-neutral-600 dar
2k:text-neutral-300 hover:border-neutral-800"}`,children:D},d)})})]})]}),e.jsxs("div",{className:"space-y-4 pt-6 border-t border-neutral-100 dark:border-neutral-700",children:[e.jsxs("div",{className:"flex justify-between items-center mb-2",children:[e.jsx(pt,{label:"Engagement threshold",info:"Social media is full of noise. Setting a threshold (like 5 pts) ensures we only notify you about conversations that are actually getting attention.",className:"!mb-0"}),e.jsxs("span",{className:"text-xs font-black text-brand-primary bg-brand-light px-3 py-1 rounded-full",children:[U,"+ pts"]})]}),e.jsx("input",{type:"range",min:"0",max:"200",step:"5",value:U,onChange:d=>ee(parseInt(d.target.value)),className:"w-full h-2 bg-neutral-100 dark:bg-neutral-800 rounded-lg appearance-none cursor-pointer accent-brand-primary"}),e.jsx("p",{className:"text-xs text-neutral-500 font-medium italic",children:"Filter results by minimum engagement level across selected channels."})]})]},"channels"),H==="insights"&&e.jsx(M.div,{initial:{opacity:0,x:5},animate:{opacity:1,x:0},exit:{opacity:0,x:-5},className:"space-y-6",children:e.jsx("div",{className:"grid grid-cols-2 gap-3",children:ae.map(d=>{const D=ke.includes(d.id);return e.jsxs("button",{onClick:()=>$e(d.id),className:"flex items-start gap-4 p-4 border rounded-2xl transition-all text-left relative bg-white dark:bg-neutral-800 border-neutral-200 dark:border-neutral-700 hover:bg-neutral-50 dark:hover:bg-neutral-700/50 group",children:[e.jsx("div",{className:`p-2 rounded-lg transition-colors ${D?"bg-neutral-100 dark:bg-neutral-700 text-neutral-900 dark:text-neutral-100":"bg-neutral-100 dark:bg-neutral-700 text-neutral-500"}`,children:Ke.cloneElement(d.icon,{className:"w-5 h-5"})}),e.jsxs("div",{className:"flex-1 pr-4",children:[e.jsx("h5",{className:"font-black text-sm tracking-tight transition-colors text-neutral-900 dark:text-neutral-100",children:d.label}),e.jsx("p",{className:"text-[11px] text-neutral-500 font-medium mt-1 leading-tight",children:d.description})]}),D&&e.jsx("div",{className:"absolute top-2.5 right-2.5 bg-neutral-200 dark:bg-neutral-700 border border-neutral-100 dark:border-neutral-600 rounded-full p-0.5 shadow-sm",children:e.jsx(Ce,{className:"w-3.5 h-3.5 text-neutral-600 dar
2k:text-neutral-300"})})]},d.id)})})},"insights")]})}),e.jsxs("div",{className:"p-6 border-t border-neutral-200 dark:border-neutral-700 bg-neutral-50 dark:bg-neutral-900/50 flex justify-between items-center",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("button",{onClick:()=>!te&&S(!0),disabled:te||z||g,className:"flex items-center gap-2 px-4 py-2 bg-white dark:bg-neutral-800 border border-red-200 dark:border-red-900/30 text-red-500 rounded-lg text-xs font-bold hover:bg-red-50 dark:hover:bg-red-900/20 transition-all active:scale-95 disabled:opacity-50",children:[z?e.jsx(nt,{}):e.jsx(kt,{className:"w-4 h-4"}),"Delete Listener"]}),e.jsx("button",{onClick:o,className:"px-6 py-3 text-sm font-black text-neutral-500 hover:text-neutral-900 transition-colors uppercase tracking-widest",children:"Cancel"})]}),e.jsx("button",{onClick:Me,disabled:b||g,className:"px-12 py-3.5 bg-brand-primary text-white text-sm font-black rounded-xl hover:bg-brand-primary/90 shadow-lg shadow-brand-primary/20 transition-all active:scale-95 flex items-center min-w-[160px] justify-center uppercase tracking-widest disabled:opacity-50",children:b?e.jsx(nt,{}):"Save changes"})]})]})]})})},aa="growlytics_listener_presets",it=({title:a})=>e.jsx("h3",{className:"text-[10px] font-black text-neutral-900 dark:text-neutral-100 uppercase tracking-widest mb-3",children:a}),ra=({label:a,icon:o,options:p,selected:i,onToggle:l,onClear:m,className:h=""})=>{const[u,c]=t.useState(!1),g=t.useRef(null);t.useEffect(()=>{const b=f=>{g.current&&!g.current.contains(f.target)&&c(!1)};return document.addEventListener("mousedown",b),()=>document.removeEventListener("mousedown",b)},[]);const s=t.useMemo(()=>i.length===0?`All ${a.toLowerCase()}s`:`${a} (${i.length})`,[i,a]);return e.jsxs("div",{className:`relative ${h}`,ref:g,children:[e.jsxs("button",{onClick:()=>c(!u),className:`flex items-center gap-2 px-3 py-2 bg-white dark:bg-neutral-800 border border-neutral-200 dark:border-neutral-700 rounded-lg text-xs font-bold text-neutral-600 dar
2k:text-neutral-300 transition-all ${u?"ring-1 ring-brand-primary border-brand-primary":""}`,children:[o&&Ke.isValidElement(o)?Ke.cloneElement(o,{className:"w-3.5 h-3.5 text-neutral-400"}):o,e.jsx("span",{className:"truncate max-w-[120px]",children:s}),e.jsx(Je,{className:`w-3 h-3 text-neutral-400 transition-transform ${u?"rotate-180":""}`})]}),e.jsx(be,{children:u&&e.jsx(M.div,{initial:{opacity:0,y:8,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:8,scale:.98},className:"absolute top-full right-0 mt-2 w-60 bg-white dark:bg-neutral-800 rounded-lg shadow-2xl border border-neutral-200 dark:border-neutral-700 z-[100] p-1 overflow-hidden",children:e.jsxs("div",{className:"space-y-0.5",children:[e.jsxs("button",{onClick:()=>{m(),c(!1)},className:`w-full text-left px-2 py-1.5 rounded-md text-[11px] font-bold transition-colors ${i.length===0?"bg-brand-light dark:bg-brand-primary/20 text-brand-primary":"text-neutral-600 dark:text-neutral-300 hover:bg-neutral-50 dark:hover:bg-neutral-800"}`,children:["All ",a.toLowerCase(),"s"]}),p.map(b=>e.jsxs("button",{onClick:()=>l(b.id),className:`w-full text-left px-2 py-1.5 rounded-md text-[11px] font-bold transition-colors flex items-center justify-between group group-active:scale-95 ${i.includes(b.id)?"text-brand-primary bg-brand-light/50 dark:bg-brand-primary/10":"text-neutral-600 dar
2k:text-neutral-300 hover:bg-neutral-50 dark:hover:bg-neutral-800"}`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[b.icon&&Ke.isValidElement(b.icon)?Ke.cloneElement(b.icon,{className:"w-3.5 h-3.5"}):b.icon,e.jsx("span",{className:"truncate max-w-[150px]",children:b.label})]}),i.includes(b.id)&&e.jsx(Ce,{className:"w-3 h-3"})]},b.id))]})})})]})},Or=({selectedFilter:a,onFilterChange:o,customDates:p,onCustomDateChange:i})=>{var g;const[l,m]=t.useState(!1),h=t.useRef(null);t.useEffect(()=>{const s=b=>{h.current&&!h.current.contains(b.target)&&m(!1)};return document.addEventListener("mousedown",s),()=>document.removeEventListener("mousedown",s)},[]);const u=[{value:"anytime",label:"All time"},{value:"today",label:"Today"},{value:"last_7_days",label:"Last 7 days"},{value:"last_30_days",label:"Last 30 days"},{value:"custom",label:"Custom range"}],c=((g=u.find(s=>s.value===a))==null?void 0:g.label)||"Date";return e.jsxs("div",{className:"relative",ref:h,children:[e.jsxs("button",{onClick:()=>m(!l),className:`flex items-center gap-2 px-3 py-2 bg-white dark:bg-neutral-800 border border-neutral-200 dark:border-neutral-700 rounded-lg text-xs font-bold text-neutral-600 dar
2k:text-neutral-300 transition-all ${l?"ring-1 ring-brand-primary border-brand-primary":""}`,children:[e.jsx(_t,{className:"w-4 h-4 text-neutral-400"}),e.jsx("span",{className:"capitalize",children:c}),e.jsx(Je,{className:`w-3.5 h-3.5 text-neutral-400 ml-1 transition-transform ${l?"rotate-180":""}`})]}),e.jsx(be,{children:l&&e.jsxs(M.div,{initial:{opacity:0,y:8,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:8,scale:.98},className:"absolute top-full right-0 mt-2 w-64 bg-white dark:bg-neutral-900 rounded-lg shadow-2xl border border-neutral-200 dark:border-neutral-700 z-50 p-2 overflow-hidden",children:[e.jsx("div",{className:"space-y-1",children:u.map(s=>e.jsx("button",{onClick:()=>{o(s.value),s.value!=="custom"&&m(!1)},className:`w-full text-left px-4 py-2 rounded-md text-[11px] font-bold transition-colors ${a===s.value?"bg-brand-light dark:bg-brand-primary/20 text-brand-primary":"text-neutral-600 dark:text-neutral-300 hover:bg-neutral-50 dark:hover:bg-neutral-800"}`,children:s.label},s.value))}),a==="custom"&&e.jsxs("div",{className:"mt-2 pt-2 border-t border-neutral-100 dark:border-neutral-700 p-3 space-y-3",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-[9px] font-black uppercase text-neutral-400",children:"Start Date"}),e.jsx("input",{type:"date",value:p.start,onChange:s=>
2i({startDate:s.target.value,endDate:p.end}),className:"w-full px-2 py-1.5 bg-neutral-50 dark:bg-neutral-800 border border-neutral-200 dark:border-neutral-700 rounded-md text-xs font-bold focus:ring-1 focus:ring-brand-primary outline-none"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("label",{className:"text-[9px] font-black uppercase text-neutral-400",children:"End Date"}),e.jsx("input",{type:"date",value:p.end,onChange:s=>i({startDate:p.start,endDate:s.target.value}),className:"w-full px-2 py-1.5 bg-neutral-50 dark:bg-neutral-800 border border-neutral-200 dark:border-neutral-700 rounded-md text-xs font-bold focus:ring-1 focus:ring-brand-primary outline-none"})]}),e.jsx("button",{onClick:()=>m(!1),className:"w-full py-2 bg-brand-primary text-white text-[10px] font-black uppercase tracking-widest rounded-md active:scale-95 transition-transform",children:"Apply Range"})]})]})})]})},Fr=({lead:a,onAction:o,onAskAi:p,isDemo:i})=>{var f,z,y;const[l,m]=t.useState(!1),h=a.lead_stage||"Awareness",u=a.confidence_level||80,c=a.intent||"Interest",g=a.location||"Not Specified",s=typeof g=="object"?g.name||g.city||JSON.stringify(g):String(g),b=V=>{switch(V.toLowerCase()){case"decision":return"bg-green-50 text-green-700 dark:bg-green-900/30 dark:text-green-400";case"consideration":return"bg-blue-50 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400";case"intent":return"bg-purple-50 text-purple-700 dark:bg-purple-900/30 dark:text-purple-400";
2default:return"bg-neutral-50 text-neutral-600 dark:text-neutral-700 dark:text-neutral-300"}};return e.jsxs(Ke.Fragment,{children:[e.jsxs("tr",{onClick:()=>m(!l),className:`group cursor-pointer transition-colors border-b border-neutral-100 dark:border-neutral-700/50 ${l?"bg-neutral-50/50 dark:bg-neutral-800/40":"hover:bg-neutral-50/30 dark:hover:bg-neutral-800/20"}`,children:[e.jsx("td",{className:"px-6 py-4 text-left",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"w-8 h-8 rounded bg-neutral-100 dark:bg-neutral-700 flex items-center justify-center text-neutral-400 font-bold text-xs uppercase overflow-hidden shrink-0",children:a.avatar_url?e.jsx("img",{src:a.avatar_url,alt:"",className:"w-full h-full object-cover"}):(a.username||"U")[0]}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-bold text-neutral-900 dark:text-neutral-100 truncate max-w-[200px]",children:a.username||"Anonymous"}),e.jsxs("div",{className:"flex items-center gap-1 mt-0.5",children:[((f=a.channel)==null?void 0:f.toLowerCase())==="twitter"&&e.jsx(gt,{className:"w-3 h-3 text-[#1DA1F2]"}),((z=a.channel)==null?void 0:z.toLowerCase())==="linkedin"&&e.jsx(ft,{className:"w-3 h-3 text-[#0A66C2]"}),((y=a.channel)==null?void 0:y.toLowerCase())==="reddit"&&e.jsx(ga,{className:"w-3 h-3 text-[#FF4500]"}),e.jsx("span",{className:"text-[9px] font-bold text-neutral-400",children:a.channel})]})]})]})}),e.jsx("td",{className:"px-6 py-4 text-left",children:e.jsx("span",{className:"px-2 py-0.5 rounded text-[9px] font-black uppercase tracking-tight bg-brand-light dark:bg-brand-primary/20 text-brand-primary whitespace-nowrap",children:c})}),e.jsx("td",{className:"px-6 py-4 text-left",children:e.jsx("span",{className:`px-2 py-0.5 rounded text-[9px] font-black uppercase tracking-tight whitespace-nowrap ${b(h)}`,children:h})}),e.jsx("td",{className:"px-6 py-4 text-left",children:e.jsxs("div",{className:"flex items-center gap-3 max-w-[140px]",children:[e.jsx("div",{className:"flex-1 bg-neutral-100 dark:bg-neutral-700 h-1 rounded-full overflow-hidden",children:e.jsx("div",{className:"h-full bg-brand-primary",style:{width:`${u}%`}})}),e.jsxs("span",{className:"text-[9px] font-bold text-neutral-500 min-w-[28px]",children:[u,"%"]})]})}),e.jsx("td",{className:"px-6 py-4 text-right",children:e.jsxs("div",{className:"flex items-center justify-end gap-3",children:[e.jsx("button",{onClick:V=>{V.stopPropagation(),!i&&p(a)},disabled:i,className:"px-4 py-1.5 bg-neutral-900 dark:bg-neutral-100 text-white dark:text-neutral-900 text-[9px] font-black uppercase tracking-widest rounded hover:opacity-90 active:scale-95 disabled:opacity-30 transition-all",children:"Talk AI"}),e.jsx("div",{className:`transition-transform duration-300 ${l?"rotate-180":""}`,children:e.jsx(Je,{className:"w-4 h-4 text-neutral-300"})})]})})]}),e.jsx(be,{children:l&&e.jsx(M.tr,{initial:{opacity:0,height:0},animate:{opacity:1,height:"auto"},exit:{opacity:0,height:0},className:"bg-neutral-50/20 dark:bg-neutral-900/30",children:e.jsx("td",{colSpan:5,className:"px-6 py-6 border-b border-neutral-100 dark:border-neutral-700/50",children:e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-10",children:[e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsxs("h5",{className:"text-[9px] font-black uppercase text-neutral-400 mb-1 flex items-center gap-1.5 tracking-widest",children:[e.jsx(Ua,{className:"w-3 h-3"})," Location"]}),e.jsx("p",{className:"text-[11px] font-bold text-neutral-700 dark:text-neutral-300",children:s||"Not specified"})]}),e.jsxs("div",{children:[e.jsxs("h5",{className:"text-[9px] font-black uppercase text-neutral-400 mb-1 flex items-center gap-1.5 tracking-widest",children:[e.jsx(Ft,{className:"w-3 h-3"})," Approach"]}),e.jsx("p",{className:"text-[11px] font-bold text-brand-primary",children:a.contact_approach||"Direct Message"})]})]}),e.jsxs("div",{className:"md:col-span-2",children:[e.jsxs("h5",{className:"text-[9px] font-black uppercase text-neutral-400 mb-1 flex items-center gap-1.5 tracking-widest",children:[e.jsx(Ve,{className:"w-3 h-3 text-amber-500"})," AI opportunity insight"]}
2),e.jsxs("p",{className:"text-xs text-neutral-600 dark:text-neutral-400 leading-relaxed font-medium",children:['"',a.notes||"This lead showed high intent for an alternative solution in a recent discussion.",'"']}),e.jsxs("div",{className:"mt-4 pt-3 border-t border-neutral-100 dark:border-neutral-700 flex gap-6",children:[a.profile_url&&e.jsxs("a",{href:a.profile_url,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1.5 text-[9px] font-black uppercase tracking-widest text-neutral-400 hover:text-brand-primary transition-colors",children:["View profile ",e.jsx(qt,{className:"w-3.5 h-3.5"})]}),a.post_url&&e.jsxs("a",{href:a.post_url,target:"_blank",rel:"noreferrer",className:"inline-flex items-center gap-1.5 text-[9px] font-black uppercase tracking-widest text-neutral-400 hover:text-brand-primary transition-colors",children:["View post ",e.jsx(qt,{className:"w-3.5 h-3.5"})]})]})]})]})})})})]})},Rr=({leads:a,onAction:o,onAskAi:p,isLoading:i,isDemo:l})=>{const[m,h]=t.useState(""),u=t.useMemo(()=>m?a.filter(g=>{var s,b,f;return((s=g.username)==null?void 0:s.toLowerCase().includes(m.toLowerCase()))||((b=g.notes)==null?void 0:b.toLowerCase().includes(m.toLowerCase()))||((f=g.intent)==null?void 0:f.toLowerCase().includes(m.toLowerCase()))}):a,[a,m]),c=()=>{const g=[["Username","Channel","Intent","Stage","Confidence","Location","Approach","Status"],...u.map(f=>[f.username||"Anonymous",f.channel,f.intent||"Interest",f.lead_stage||"Awareness",f.confidence_level||"Medium",f.location||"Unknown",f.contact_approach||"Direct",f.status])].map(f=>f.join(",")).join(`
3`),s=new Blob([g],{type:"text/csv;charset=utf-8;"}),b=document.createElement("a");b.href=URL.createObjectURL(s),b.setAttribute("download","social_leads_export.csv"),b.click()};return e.jsxs("div",{className:"bg-white dark:bg-neutral-800 rounded-2xl border border-neutral-200 dark:border-neutral-700 shadow-sm overflow-hidden flex flex-col",children:[e.jsxs("div",{className:"p-4 border-b border-neutral-100 dark:border-neutral-700 flex flex-col sm:flex-row justify-between items-center gap-4",children:[e.jsxs("div",{className:"relative w-full sm:w-80",children:[e.jsx(qe,{className:"absolute left-3.5 top-1/2 -translate-y-1/2 w-4 h-4 text-neutral-400"}),e.jsx("input",{type:"text",value:m,onChange:g=>h(g.target.value),placeholder:"Search leads...",className:"w-full pl-10 pr-4 py-2 text-xs font-bold bg-neutral-50 dark:bg-neutral-900 border border-transparent rounded-xl focus:ring-1 focus:ring-brand-primary focus:bg-white outline-none transition-all"})]}),e.jsxs("button",{onClick:c,className:"flex items-center gap-2 px-4 py-2 bg-white dark:bg-neutral-800 border border-neutral-200 dark:border-neutral-700 rounded-xl text-[9px] font-black uppercase tracking-widest text-neutral-600 dar
3k:text-neutral-200 hover:bg-neutral-50 hover:border-brand-primary transition-all active:scale-95",children:[e.jsx(Ba,{className:"w-3.5 h-3.5"}),"Export"]})]}),e.jsx("div",{className:"overflow-x-auto w-full custom-scrollbar",children:e.jsxs("table",{className:"w-full min-w-[700px] border-collapse",children:[e.jsx("thead",{className:"bg-neutral-50/50 dark:bg-neutral-800/50 border-b border-neutral-100 dark:border-neutral-700",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-6 py-4 text-left text-[8px] font-black text-neutral-400 uppercase tracking-[0.2em] w-1/4",children:"Lead"}),e.jsx("th",{className:"px-6 py-4 text-left text-[8px] font-black text-neutral-400 uppercase tracking-widest w-1/6",children:"Intent"}),e.jsx("th",{className:"px-6 py-4 text-left text-[8px] font-black text-neutral-400 uppercase tracking-widest w-1/6",children:"Lead Stage"}),e.jsx("th",{className:"px-6 py-4 text-left text-[8px] font-black text-neutral-400 uppercase tracking-widest w-1/5",children:"Confidence"}),e.jsx("th",{className:"px-6 py-3 text-right text-[8px] font-black text-neutral-400 uppercase tracking-widest w-1/5",children:"Actions"})]})}),e.jsx("tbody",{className:"divide-y divide-neutral-100 dark:divide-neutral-700",children:i?[...Array(3)].map((g,s)=>e.jsx("tr",{children:e.jsx("td",{colSpan:5,className:"px-6 py-4",children:e.jsx(Tt,{className:"h-10 w-full rounded"})})},s)):u.length>0?u.map(g=>e.jsx(Fr,{lead:g,onAction:o,onAskAi:p,isDemo:l},g.id)):e.jsx("tr",{children:e.jsx("td",{colSpan:5,className:"px-6 py-20 text-center",children:e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx(ia,{className:"w-8 h-8 text-neutral-200 mb-4"}),e.jsx("h4",{className:"text-xs font-black text-neutral-400 uppercase tracking-widest",children:"No leads discovered"})]})})})})]})})]})},Pr=()=>e.jsxs("div",{className:"relative flex items-center justify-center w-8 h-8",children:[e.jsx("div",{className:"absolute inset-0 border-4 border-neutral-100 dark:border-neutral-800 rounded-full"}),e.jsx("div",{className:"absolute inset-0 border-4 border-brand-primary rounded-full border-t-transparent animate-spin"})]}),Wr=({listenerId:a,refreshKey:o=0})=>{const{id:p}=sa(),i=a||p,{selectedProject:l,refreshPermissions:m}=lt(),{addToast:h}=tt(),u=xt(),[c,g]=Ct(),[s,b]=t.useState(null),[f,z]=t.useState(null),[y,V]=t.useState([]),[S,H]=t.useState([]),[Y,C]=t.useState(!0),[v,A]=t.useState(!0),[Z,T]=t.useState(!1),[K,O]=t.useState(null),[he,oe]=t.useState(!1),[ye,ke]=t.useState(!0),[ce,xe]=t.useState(!0),[ge,we]=t.useState(!1),$=c.get("mode")||"feed",J=(l==null?void 0:l.is_demo)===1,E=t.useMemo(()=>{var n;return((n=c.get("channels"))==null?void 0:n.split(",").filter(Boolean))||[]},[c]),U=t.useMemo(()=>{var n;return((n=c.get("layers"))==null?void 0:n.split(",").filter(Boolean))||[]},[c]),ee=t.useMemo(()=>{var n;return((n=c.get("keywords"))==null?void 0:n.split(",").filter(Boolean))||[]},[c]),re=c.get("status")||"all",X=c.get("date")||"anytime",se=t.useMemo(()=>({start:c.get("start")||"",end:c.get("end")||""}),[c]),[N,q]=t.useState(!1),[B,te]=t.useState(!1),[F,R]=t.useState(!1),[P,ue]=t.useState(null),[ae,Q]=t.useState(!1),je=t.useRef(null),G=t.useRef(null),[ve,$e]=t.useState([]),[Me,Ee]=t.useState(""),[ne,I]=t.useState({status:"all",layers:[],channels:[],keywords:[],date:"anytime",start:"",end:[]});t.useEffect(()=>{},[l==null?void 0:l.id]),t.useEffect(()=>{const n=localStorage.getItem(aa);if(n)try{$e(JSON.parse(n))}catch{$e([])}},[]);const d=n=>{$e(n),localStorage.setItem(aa,JSON.stringify(n))},D=()=>{if(!Me.trim())return h("Please enter a name for the filter","error");const n={id:Date.now().toString(),name:Me,filters:{...ne}};d([...ve,n]),Ee(""),h("Filter preset saved!","success")},fe=(n,w)=>{n.stopPropagation(),d(ve.filter(j=>j.id!==w))},k=n=>{I(n.filters);const w={status:n.filters.status,layers:n.filters.layers.join(",")||null,channels:n.filters.channels.join(",")||null,keywords:n.filters.keywords.join(",")||null,date:n.filters.date,start:n.filters.date==="custom"?n.filters.start:null,end:n.filters.date==="custom"?n.filters.end:null};Ne(w),we(!1)},de=n=>{if(!n)return[];if(Array.isArray(n))return n;try{const w=JSON.parse(n);return Array.isArray(w)?w:[n]}catch{return[n]}},Ne=t.useCallback(n=>{const w=new URLSearchParams(c);
3Object.entries(n).forEach(([j,L])=>{L&&L!=="all"&&L!=="anytime"?w.set(j,L):w.delete(j)}),w.delete("page"),g(w,{replace:!0})},[c,g]),De=(n,w)=>{Ne({[n]:w})},Be=(n,w,j)=>{const L=w.includes(j)?w.filter(Oe=>Oe!==j):[...w,j];De(n,L.join(",")||null)};t.useEffect(()=>{const n=w=>{je.current&&!je.current.contains(w.target)&&Q(!1),G.current&&!G.current.contains(w.target)&&we(!1)};return document.addEventListener("mousedown",n),()=>document.removeEventListener("mousedown",n)},[]);const Ue=t.useCallback(async()=>{if(!(!l||!i)){C(!0);try{const w=(await pa(l.id,parseInt(i))).data;let j=null,L=null;if(w.id&&w.search_query&&!w.listener){if(j=w,typeof w.total_matches=="number"){const Oe=w.channel_match_breakdown||{},Ie={};Object.keys(Oe).forEach(r=>{const _=r.replace("_total_matches","");Ie[_]=Oe[r]}),L={total:w.total_matches,by_channel:Ie}}}else w.listener&&(j=w.listener,L=w.counts);j&&(b(j),z(L))}catch{h("Failed to load listener details","error")}finally{C(!1)}}},[l,i,h]),ie=t.useCallback(async(n=!1)=>{if(!(!l||!i)){n||T(!0);try{const w={project_id:l.id,listener_id:parseInt(i),date_filter:X,status:re!=="all"?re:void 0};X==="custom"&&(w.start_date=se.start,w.end_date=se.end);const j=await za(w);H(j.data.data||[])}catch{n||h("Failed to load leads","error")}finally{n||T(!1)}}},[l,i,X,se,re,h]),We=t.useCallback(async(n=!1,w=!1)=>{if(!(!l||!i)&&!(n&&!K)){w||(n?oe(!0):A(!0));try{const j={listener_id:parseInt(i),per_page:20,cursor:n?K:void 0};re==="saved"?j.saved_only=!0:re==="unseen"&&(j.unseen=!0),E.length>0&&(j.channel=E.join(",")),U.length>0&&(j["insight_layers[]"]=U),X!=="anytime"&&(j.date_range=X,X==="custom"&&(j.start_date=se.start,j.end_date=se.end));const L=await ua(l.id,j);V(n?Oe=>[...Oe,...L.data.data]:L.data.data),O(L.data.next_cursor)}catch{w||h("Failed to load results","error")}finally{w||(A(!1),oe(!1))}}},[l,i,E,U,X,se,re,K,h]),_e=t.useCallback(()=>We(!0,!1),[We]);t.useEffect(()=>{Ue()},[Ue]),t.useEffect(()=>{$==="feed"?We(!1,!1):$==="leads"&&ie()},[E,U,ee,X,se,re,$,o,We,ie]),t.useEffect(()=>{I({status:re,layers:U,channels:E,keywords:ee,date:X,start:se.start,end:se.end})},[re,U,E,ee,X,se]);const x=()=>{const n={status:ne.status,layers:ne.layers.join(",")||null,channels:ne.channels.join(",")||null,keywords:ne.keywords.join(",")||null,date:ne.date,start:ne.date==="custom"?ne.start:null,end:ne.date==="custom"?ne.end:null};Ne(n),we(!1)},W=(n,w)=>{I(j=>{const L=j[n],Oe=L.includes(w)?L.filter(Ie=>Ie!==w):[...L,w];return{...j,[n]:Oe}})},pe=async()=>{if(!(!i||J)){R(!0);try{await ha(parseInt(i)),h("Listener deleted","success"),m&&m(),u("/home")}catch{h("Failed to delete listener","error")}finally{R(!1),te(!1)}}},me=async n=>{if(!(!l||J))try{await ma(l.id,{result_id:n.id,action_type:"social_engagement",notes:`Engagement opportunity from ${n.channel}`}),h("AI Action created","success")}catch{h("Failed to create action","error")}},Ae=n=>{window.dispatchEvent(new CustomEvent("growlytics:open-ai-chat",{detail:{title:`Lead Analysis: ${n.username}`,item_type:"leads",item_id:n.id,project_id:l==null?void 0:l.id}}))},Se=t.useMemo(()=>((s==null?void 0:s.channels)||[]).map(n=>({id:n,label:n.charAt(0).toUpperCase()+n.slice(1),icon:n.toLowerCase()==="twitter"?e.jsx(gt,{className:"w-3.5 h-3.5"}):n.toLowerCase()==="linkedin"?e.jsx(ft,{className:"w-3.5 h-3.5"}):n.toLowerCase()==="reddit"?e.jsx(ga,{className:"w-3.5 h-3.5"}):null})),[s]),Qe=t.useMemo(()=>de(s==null?void 0:s.search_query).map(w=>({id:w,label:w,icon:e.jsx(qe,{className:"w-3.5 h-3.5 text-neutral-400"})})),[s]),ze=t.useMemo(()=>ee.length===0?y:y.filter(n=>{const w=n.keywords_found||[];return ee.some(j=>w.includes(j))}),[y,ee]),at=Y||$==="feed"&&v&&y.length===0||$==="leads"&&Z&&S.length===0,He=(s==null?void 0:s.status)==="active",Xe=s!=null&&s.title&&s.title!=="Untitled Listener"?s.title:de(s==null?void 0:s.search_query).join(", ")||"Social Listener",Ze=t.useMemo(()=>E.length>0||U.length>0||ee.length>0||X!=="anytime"||re!=="all",[E,U,ee,X,re]),et=()=>s?e.jsxs("div",{className:"max-w-4xl space-y-12 py-2",children:[e.jsxs("div",{children:[e.jsx(it,{title:"WHAT THIS LISTENER IS MONITORING"}
3),e.jsxs("p",{className:"text-xl text-neutral-600 dark:text-neutral-300 font-medium leading-relaxed",children:["This listener is tracking conversations related to ",e.jsxs("span",{className:"font-black text-neutral-900 dark:text-neutral-100 underline decoration-brand-primary decoration-2 underline-offset-4",children:["“",Xe,"”"]})," across multiple platforms to identify pain points and buying intent."]})]}),e.jsxs("div",{className:"p-8 bg-neutral-50/50 dark:bg-neutral-900/30 rounded-2xl border border-neutral-100 dark:border-neutral-800",children:[e.jsx("div",{className:"flex flex-col md:flex-row md:items-center justify-between gap-6",children:e.jsxs("div",{className:"flex items-center gap-5",children:[e.jsx(Pr,{}),e.jsxs("div",{children:[e.jsx("h4",{className:"text-base font-black text-neutral-900 dark:text-neutral-100 tracking-tight uppercase",children:"Searching for conversations"}),e.jsx("p",{className:"text-[11px] text-neutral-500 font-bold mt-0.5",children:"Scanning networks for matches"})]})]})}),e.jsx("p",{className:"text-sm text-neutral-500 dark:text-neutral-400 font-medium leading-relaxed mt-6",children:"Our engine is currently scouring social platforms for posts that match your keywords. We establish sentiment and intent benchmarks for every discovery. New results will appear here as soon as they are processed."})]}),e.jsxs("div",{children:[e.jsx(it,{title:"RELEVANCE POLICY"}
3),e.jsx("p",{className:"text-base text-neutral-600 dark:text-neutral-400 font-medium leading-relaxed",children:"We prioritize high-engagement threads and explicit buying intent. Our intelligence layer automatically filters out noise and low-quality mentions to keep your feed actionable."})]})]}):null;return at?e.jsx(At,{type:"table"}):e.jsxs("div",{className:"bg-white dark:bg-neutral-900 min-h-full flex flex-col min-w-0",children:[e.jsx(Er,{isOpen:N,onClose:()=>q(!1),listener:s,projectId:(l==null?void 0:l.id)||0,onUpdate:()=>{Ue(),$==="feed"?We(!1,!1):ie()}}),e.jsx(jt,{isOpen:B,onClose:()=>te(!1),onConfirm:pe,title:"Delete Listener?",message:"Stop monitoring and delete all results? This action cannot be undone.",confirmText:"Delete",isLoading:F}),e.jsx(Bt,{imageUrl:P,onClose:()=>ue(null)}),e.jsx("div",{className:"p-6 md:p-8 pb-4 bg-white dark:bg-neutral-900",children:e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center justify-between gap-6",children:[e.jsxs("div",{className:"flex items-center gap-5 min-w-0",children:[e.jsx("div",{className:"w-16 h-16 rounded-xl bg-brand-light dark:bg-brand-primary/10 border border-brand-primary/10 flex items-center justify-center text-brand-primary shrink-0",children:e.jsx(Pe,{className:"w-8 h-8"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("h1",{className:"text-2xl font-bold text-neutral-900 dark:text-neutral-100 tracking-tight truncate",children:Xe}),e.jsxs("div",{className:`flex items-center gap-1.5 px-2 py-0.5 rounded-full border shrink-0 ${He?"bg-green-50 dark:bg-green-900/30 border-green-200 dark:border-green-800":"bg-neutral-50 border border-neutral-200 dark:border-neutral-800 dark:border-neutral-700"}`,children:[e.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${He?"bg-green-500 animate-pulse":"bg-neutral-400"}`}),e.jsx("span",{className:`text-[9px] font-bold ${He?"text-green-600 dark:text-green-400":"text-neutral-500 dark:text-neutral-400"}`,children:He?"Active":"Inactive"})]})]}),e.jsx("div",{className:"flex items-center gap-4 mt-2 text-xs font-bold text-neutral-400 uppercase tracking-widest",children:e.jsxs("span",{children:[(f==null?void 0:f.total)||0," Matches Total"]})})]})]}),e.jsxs("div",{className:"flex items-center gap-2 no-print shrink-0 mt-4 sm:mt-0",children:[e.jsx("button",{onClick:()=>ke(!ye),className:`p-2 rounded-lg border transition-all ${ye?"bg-white dark:bg-neutral-800 text-brand-primary border-brand-primary shadow-sm":"bg-white dark:bg-neutral-800 text-neutral-400 border border-neutral-200 dark:border-neutral-700"}`,title:ye?"Disable highlighting":"Enable highlighting",children:e.jsx(ut,{className:"w-5 h-5"})}),e.jsxs("button",{onClick:()=>q(!0),disabled:J,className:"inline-flex items-center gap-2 px-4 py-2 bg-white dark:bg-neutral-800 border border-neutral-200 dark:border-neutral-700 rounded-lg text-[11px] font-bold text-neutral-700 dark:text-neutral-200 hover:bg-neutral-50 transition-all active:scale-95 shadow-sm disabled:opacity-50 disabled:cursor-not-allowed",children:[e.jsx(zt,{className:"w-3.5 h-3.5"}),"Edit"]}),e.jsx("button",{onClick:()=>te(!0),disabled:J,className:"p-2 bg-white dark:bg-neutral-800 border border-neutral-200 dark:border-neutral-700 rounded-lg text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20 transition-all active:scale-95 shadow-sm disabled:opacity-50 disabled:cursor-not-allowed",children:e.jsx(kt,{className:"w-5 h-5"})})]})]})}),e.jsx("div",{className:"sticky top-0 z-40 bg-white/95 dark:bg-neutral-900/95 backdrop-blur border-b border-neutral-100 dark:border-neutral-800 px-6 md:px-8 shadow-sm flex-shrink-0",children:e.jsxs("div",{className:"flex flex-row items-center justify-between gap-4",children:[e.jsx("div",{className:"flex items-center gap-8 -mb-px",children:[{id:"feed",label:"Posts"},{id:"leads",label:"Leads"}].map(n=>e.jsxs("button",{onClick:()=>De("mode",n.id),className:`relative pt-4 pb-4 text-sm font-bold transition-all ${$===n.id?"text-brand-primary":"text-neutral-400 hover:text-neutral-700 dark:hover:text-neutral-200"}`,children:[n.label,$===n.id&&e.jsx(M.div,{layoutId:"listenerTabIndicator",className:"absolute bottom-0 left-0 right-0 h-0.5 bg-brand-primary"})]},n.id))}),e.jsx("div",{className:"flex items-center gap-2 py-3 pr-4 no-print",children:$==="feed"&&e.jsxs(e.Fragment,{children:[e.jsx(ra,{label:"Keyword",icon:e.jsx(qe,{}),options:Qe,selected:ee,onToggle:n=>Be("keywords",ee,n),onClear:()=>De("keywords",null),className:"hidden lg:block"}),e.jsx(ra,{label:"Channel",icon:e.jsx(Pe,{}),options:Se,selected:E,onToggle:n=>Be("channels",E,n),onClear:()=>De("channels",null),className:"hidden lg:block"}),e.jsx(Or,{selectedFilter:X,onFilterChange:n=>De("date",n),customDates:se,onCustomDateChange:n=>{Ne({start:n.startDate,end:n.endDate})}}),e.jsxs("div",{className:"relative",ref:G,children:[e.jsxs("button",{onClick:()=>we(!ge),className:`flex items-center gap-2 px-3 py-2 bg-white dark:bg-neutral-800 border border-neutral-200 dark:border-neutral-700 rounded-lg text-xs font-bold text-neutral-600 dar
3k:text-neutral-300 transition-all ${ge?"ring-1 ring-brand-primary border-brand-primary":""}`,children:[e.jsx(Pt,{className:"w-3.5 h-3.5 text-neutral-400"}),e.jsx("span",{children:"All filters"}),e.jsx(Je,{className:`w-3.5 h-3.5 ml-1 transition-transform ${ge?"rotate-180":""}`})]}),e.jsx(be,{children:ge&&e.jsxs(M.div,{initial:{opacity:0,y:12,scale:.98},animate:{opacity:1,y:0,scale:1},exit:{opacity:0,y:12,scale:.98},className:"absolute top-full right-0 mt-3 w-80 max-h-[500px] bg-white dark:bg-neutral-900 rounded-xl shadow-xl border border-neutral-100 dark:border-neutral-700 z-100 p-1 overflow-hidden",children:[e.jsxs("div",{className:"flex-1 overflow-y-auto custom-scrollbar",children:[e.jsxs("div",{className:"p-4 bg-neutral-50 dark:bg-neutral-950/40 border-b border-neutral-100 dark:border-neutral-800",children:[e.jsx(it,{title:"Saved filter presets"}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[ve.map(n=>e.jsxs("button",{onClick:()=>k(n),className:"px-2.5 py-1.5 bg-white dark:bg-neutral-800 border border-neutral-200 dark:border-neutral-700 rounded-lg text-[10px] font-bold text-neutral-600 dar
3k:text-neutral-300 flex items-center gap-2 group",children:[n.name,e.jsx("span",{onClick:w=>fe(w,n.id),className:"opacity-0 group-hover:opacity-100 hover:text-red-500 transition-opacity",children:e.jsx(Re,{className:"w-3 h-3"})})]},n.id)),ve.length===0&&e.jsx("p",{className:"text-[10px] text-neutral-400 font-bold uppercase tracking-widest",children:"No presets saved"})]})]}),e.jsxs("div",{className:"p-5 space-y-8",children:[e.jsxs("div",{children:[e.jsx(it,{title:"Activity Status"}),e.jsx("div",{className:"grid grid-cols-3 gap-2",children:[{id:"all",label:"All",icon:e.jsx(Nt,{className:"w-3 h-3"})},{id:"unseen",label:"Unseen",icon:e.jsx(mt,{className:"w-3 h-3"})},{id:"saved",label:"Saved",icon:e.jsx(Wt,{className:"w-3 h-3"})}].map(n=>e.jsxs("button",{onClick:()=>I(w=>({...w,status:n.id})),className:`flex items-center justify-center gap-1.5 py-2 px-1 rounded-lg border-2 text-[10px] font-bold transition-all ${ne.status===n.id?"bg-neutral-900 border-neutral-900 text-white dark:bg-neutral-100 dark:text-neutral-900 dark:border-neutral-100 shadow-sm":"bg-white dark:bg-neutral-800 border border-neutral-100 dark:border-neutral-700 text-neutral-400"}`,children:[n.icon,n.label]},n.id))})]}),e.jsxs("div",{children:[e.jsx(it,{title:"Channels"}),e.jsx("div",{className:"grid grid-cols-1 gap-1.5",children:Se.map(n=>e.jsxs("button",{onClick:()=>W("channels",n.id),className:`flex items-center gap-3 px-3 py-2 rounded-xl border-2 text-left transition-all ${ne.channels.includes(n.id)?"bg-neutral-900 border-neutral-900 text-white dark:bg-neutral-100 dark:text-neutral-900 dark:border-neutral-100 shadow-sm":"bg-white dark:bg-neutral-800 border border-neutral-100 dark:border-neutral-700 text-neutral-400"}`,children:[e.jsx("div",{className:"shrink-0",children:n.icon}),e.jsx("span",{className:"text-xs font-bold truncate",children:n.label}),ne.channels.includes(n.id)&&e.jsx(Ce,{className:"w-3 h-3 ml-auto shrink-0"})]},n.id))})]}),e.jsxs("div",{children:[e.jsx(it,{title:"Keywords"}),e.jsx("div",{className:"max-h-40 overflow-y-auto custom-scrollbar space-y-1",children:Qe.map(n=>e.jsxs("button",{onClick:()=>W("keywords",n.id),className:`w-full flex items-center justify-between px-3 py-2 rounded-lg text-xs font-bold transition-colors ${ne.keywords.includes(n.id)?"bg-neutral-100 dark:bg-neutral-800 text-neutral-900 dark:text-neutral-100":"text-neutral-500 hover:bg-neutral-50"}`,children:[e.jsx("span",{className:"truncate pr-2",children:n.label}),ne.keywords.includes(n.id)&&e.jsx(Ce,{className:"w-3 h-3 flex-shrink-0"})]},n.id))})]}),e.jsxs("div",{children:[e.jsx(it,{title:"Timeframe"}),e.jsx("div",{className:"grid grid-cols-3 gap-2 mb-4",children:["anytime","today","last_7_days","last_30_days","custom"].map(n=>e.jsx("button",{onClick:()=>I(w=>({...w,date:n})),className:`py-1.5 px-1 rounded-lg border transition-all text-[11px] font-bold ${ne.date===n?"bg-neutral-900 border-neutral-900 text-white dark:bg-neutral-100 dark:text-neutral-900":"bg-white dark:bg-neutral-800 border border-neutral-100 dark:border-neutral-700 text-neutral-400"}`,children:n==="anytime"?"All time":n==="last_7_days"?"7 days":n==="last_30_days"?"30 days":n},n))})]}),e.jsx("div",{className:"pt-4 border-t border-neutral-100 dark:border-neutral-700",children:e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",placeholder:"Save filter as...",value:Me,onChange:n=>Ee(n.target.value),className:"flex-1 px-3 py-1.5 bg-neutral-50 dark:bg-neutral-950 border border-neutral-100 dark:border-neutral-800 rounded-lg text-xs font-bold outline-none focus:ring-1 focus:ring-brand-primary"}),e.jsx("button",{onClick:D,className:"px-3 py-1.5 bg-neutral-100 dark:bg-neutral-800 text-neutral-600 dar
3k:text-neutral-200 text-xs font-bold rounded-lg transition-all",children:"Save"})]})})]})]}),e.jsxs("div",{className:"p-4 bg-white dark:bg-neutral-900 border-t border-neutral-100 dark:border-neutral-800 flex justify-between shrink-0",children:[e.jsx("button",{onClick:()=>I({status:"all",layers:[],channels:[],keywords:[],date:"anytime",start:"",end:""}),className:"px-4 py-2 text-xs font-bold text-neutral-400 hover:text-neutral-600",children:"Reset"}),e.jsx("button",{onClick:x,className:"px-8 py-2.5 bg-neutral-900 text-white dark:bg-neutral-100 dark:text-neutral-900 text-xs font-bold rounded-lg active:scale-95 transition-transform shadow-sm",children:"Apply filters"})]})]})})]})]})})]})}),e.jsx("div",{className:"p-4 md:p-6 pt-6 flex-grow bg-white dark:bg-neutral-900 min-w-0 endurance-scroll overflow-y-auto",children:e.jsx("div",{className:"h-full pr-4",children:e.jsx(be,{mode:"wait",children:$==="feed"?e.jsxs(M.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},className:"space-y-4",children:[e.jsx(be,{children:ce&&!v&&e.jsxs(M.div,{initial:{opacity:0,y:-10},animate:{opacity:1,y:0},exit:{opacity:0,scale:.98},className:"bg-white dark:bg-neutral-800 border border-neutral-200 dark:border-neutral-700 p-6 mb-4 flex items-start gap-5 transition-all shadow-sm rounded-lg",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h3",{className:"text-[10px] font-black uppercase tracking-[0.2em] text-neutral-900 dark:text-neutral-100 mb-3",children:"Campaign Surveillance Started"}),e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-sm text-neutral-600 dar
3k:text-neutral-400 leading-relaxed font-medium",children:"Surveillance is active for this listener. We've established a baseline from current social threads and are now monitoring for new arrivals."}),e.jsxs("p",{className:"text-sm text-neutral-600 dark:text-neutral-400 leading-relaxed font-medium",children:["We have detected ",e.jsx("span",{className:"text-brand-primary font-black",children:(y.length||0).toLocaleString()})," initial matches for your keywords. Any new relevant conversations will trigger an immediate alert based on your sentiment and intent filters."]})]})]}),e.jsx("button",{onClick:()=>xe(!1),className:"p-1.5 bg-red-50 dark:bg-red-900/20 text-red-500 rounded hover:bg-red-100 dark:hover:bg-red-900/30 transition-colors shrink-0",children:e.jsx(Re,{className:"w-4 h-4"})})]})}),ze.length>0?e.jsx("div",{className:"grid grid-cols-1 gap-4",children:ze.map((n,w)=>e.jsx(M.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{duration:.3,delay:Math.min(w*.05,.2)},children:e.jsx(ya,{result:n,onOpenLightbox:ue,onCreateAiAction:me,highlightKeywords:ye,className:"rounded-lg border border-neutral-200 dark:border-neutral-700 shadow-xl shadow-neutral-100/30 dark:shadow-none hover:border-brand-primary transition-all duration-300"})},n.id))}):!v&&(Ze?e.jsxs("div",{className:"text-center py-20",children:[e.jsx("div",{className:"w-14 h-14 rounded-full bg-neutral-50 dark:bg-neutral-800 flex items-center justify-center mx-auto mb-6 border border-neutral-100 dark:border-neutral-700 shadow-sm",children:e.jsx(Pe,{className:"w-6 h-6 text-neutral-300"})}),e.jsx("h3",{className:"text-sm font-bold text-neutral-900 dark:text-neutral-100",children:"No matching results"}),e.jsx("button",{onClick:()=>Ne({status:"all",channels:null,layers:null,keywords:null,date:"anytime",mode:"feed"}),className:"mt-6 text-brand-primary font-bold text-[10px] hover:underline uppercase",children:"Clear all filters"})]}):et()),K&&ze.length>0&&e.jsx("div",{className:"h-20 w-full flex items-center justify-center",children:he?e.jsx(nt,{}):e.jsx("button",{onClick:_e,className:"text-[10px] font-bold text-neutral-400 hover:text-brand-primary transition-colors uppercase tracking-widest",children:"Load more"})})]},"feed-view"):e.jsx(M.div,{initial:{opacity:0,scale:.99},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.99},transition:{duration:.3},children:e.jsx(Rr,{leads:S,onAction:()=>{},onAskAi:Ae,isLoading:Z,isDemo:J})},"leads-view")})})})]})},zr=a=>{if(!a)return"N/A";const o=new Date(a),i=Math.floor((new Date().getTime()-o.getTime())/1e3);if(i<60)return"Just now";const l=Math.floor(i/60);if(l<60)return`${l}m ago`;const m=Math.floor(l/60);return m<24?`${m}h ago`:`${Math.floor(m/24)}d ago`},is=()=>{const{selectedProject:a,isPermissionsLoading:o,permissions:p,updateProject:i}=lt(),{user:l}=ba(),{addToast:m}=tt(),{isTourActive:h,goToStep:u,stopTour:c,hasCompletedTour:g}=Ga(),{openUpgradeModal:s,openDemoModal:b}=na(),f=xt(),y=ka().pathname.split("/").filter(Boolean),V=y[0]==="home",S=V?"overview":y[1],H=V?void 0:y[2],Y=y[0]==="growth-opportunities",C=(a==null?void 0:a.is_demo)===1,[v,A]=t.useState([]),[Z,T]=t.useState({total_mentions:0,unseen_mentions:0}),[K,O]=t.useState(!0),[he,oe]=t.useState(!1),[ye,ke]=t.useState(!1),[ce,xe]=t.useState(0),ge=t.useRef(0),we=t.useRef(!0),[$,J]=t.useState(!1),[E,U]=t.useState(null),[ee,re]=t.useState(!1),X=t.useCallback(R=>{if((a==null?void 0:a.is_demo)===1&&localStorage.getItem("isGuestDemo")==="true"){b();return}if(R&&p){let P=-1,ue=0,ae="";if(R==="website"?(P=p.limits.website_monitor_limit,ue=p.usage.website_monitors,ae="Website monitor"):R==="social"?(P=p.limits.social_monitor_limit,ue=p.usage.social_monitors,ae="Social listening"):R==="competitor"&&(P=p.limits.competitor_monitor_limit,ue=p.usage.competitors,ae="Competitor monitor"),P!==-1&&ue>=P){s({title:`${ae} limit reached`,description:`You've reached your limit of ${P} ${ae.toLowerCase()}s for this project. Upgrade to add more.`,featureName:ae});return}}R==="social"?f("/add/social-listener"):R==="competitor"?f("/add/competitor"):(U(R),J(!0))},[p,f,s]);t.useEffect(()=>{const R=P=>{const ue=P,{type:ae}=ue.detail;X(ae)};return window.addEventListener("growlytics:open-create-monitor",R),()=>window.removeEventListener("growlytics:open-create-monitor",R)},[X]),t.useEffect(()=>{if(!a||C)return;const R=window.innerWidth>=1024;if(!a.welcome_shown&&!he){h&&c();const P=setTimeout(()=>
3oe(!0),0);return()=>clearTimeout(P)}else if(R&&!h&&!he&&!g){const P=setTimeout(()=>{u(1)},1e3);return()=>clearTimeout(P)}},[a,C,u,he,g,h,c]);const se=async()=>{if(a){try{await Ka(a.id),i({...a,welcome_shown:!0})}catch(R){console.error("Failed to mark welcome as shown",R)}oe(!1),window.location.reload()}},N=t.useCallback((R=!1)=>{if(!a){o||(O(!1),A([]));return}R||O(!0),Va(a.id).then(P=>{const ue=P.data.data||[],ae=P.data.summary||{total_mentions:0,unseen_mentions:0};T(ae);const Q=ue.map(G=>{const ve=G.results_by_channel||{},$e=Object.values(ve).reduce((Me,Ee)=>Me+(Number(Ee)||0),0);return{...G,id:G.id,name:G.title||(Array.isArray(G.search_query)?G.search_query[0]:G.search_query),type:G.type==="keyword"?"social_listener":G.type,last_activity:zr(G.last_check),url:G.domain||G.url||G.website,activities_count:G.activities_count||G.total_activities||0,results_count:G.results_count||G.total_matches||$e||0}}),je=Q.reduce((G,ve)=>G+(Number(ve.results_count)||Number(ve.activities_count)||0),0)+ae.total_mentions;we.current?(ge.current=je,we.current=!1):je>ge.current&&ke(!0),A(Q),!S&&!Y&&f("/home",{replace:!0})}).catch(()=>{R||m("Failed to fetch monitors.","error")}).finally(()=>{R||O(!1)})},[a,m,S,Y,f,o]);t.useEffect(()=>{we.current=!0;const R=setTimeout(()=>{N()},0);return()=>clearTimeout(R)},[N]),t.useEffect(()=>{const R=()=>{N(!1),xe(P=>P+1)};return window.addEventListener("growlytics:refresh-data",R),()=>window.removeEventListener("growlytics:refresh-data",R)},[N]);const q=()=>{ke(!1),xe(P=>P+1);const R=v.reduce((P,ue)=>P+(Number(ue.results_count)||Number(ue.activities_count)||0),0)+Z.total_mentions;ge.current=R},B=t.useMemo(()=>Y?{type:"keywords",id:"all"}:S?S==="overview"?{type:"overview",id:"main"}:H?{type:S,id:H}:null:null,[S,H,Y]),te=R=>{R.type==="competitor"?f("/monitors/competitor/all"):f(`/monitors/${R.type}/${R.id}`)};return(o||K||!a&&!o)&&v.length===0?e.jsx(At,{type:Y?"table":"dashboard"}):e.jsxs("div",{className:"bg-white dark:bg-neutral-900 min-h-full flex flex-col relative",style:{overflowAnchor:"none"},children:[C&&localStorage.getItem("isGuestDemo")==="true"&&e.jsxs("div",{className:"bg-gradient-to-r from-brand-primary to-orange-505 text-white px-6 py-3 flex items-center justify-between shadow-md z-30 sticky top-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"bg-white/20 px-2 py-0.5 rounded text-[10px] font-black tracking-wide uppercase",children:"Demo Mode"}),e.jsx("p",{className:"text-xs font-medium",children:"You are viewing a live read-only demo. Create a free account to track your own brand."})]}),e.jsx("button",{onClick:()=>f("/signup"),className:"bg-white text-brand-primary px-4 py-1.5 rounded-lg text-xs font-black hover:scale-105 active:scale-95 transition-all shadow-sm shrink-0",children:"Get Started for Free"})]}),e.jsx(cr,{isOpen:he,onClose:()=>oe(!1),onContinue:se,project:a}),!C&&e.jsx(dr,{isOpen:$,onClose:()=>{J(!1),U(null)},onMonitorCreated:N,initialMode:E}),e.jsx(be,{children:ye&&e.jsx(M.div,{initial:{opacity:0,y:-20},animate:{opacity:1,y:0},exit:{opacity:0,y:-20},className:"fixed top-20 left-1/2 -translate-x-1/2 z-[100]",children:e.jsxs("button",{onClick:q,className:"bg-brand-primary text-white px-6 py-2.5 rounded-lg shadow-2xl font-black tracking-widest text-[10px] flex items-center gap-2 hover:scale-105 active:scale-95 transition-all border border-white/20",children:[e.jsx(Lt,{className:"w-3.5 h-3.5"}),"New content refresh"]})})}),e.jsx("div",{className:"flex-1 transition-all duration-700",children:e.jsx("div",{className:"w-full flex min-h-full",children:e.jsx("div",{className:"flex-1 bg-white dark:bg-neutral-900 min-w-0 flex",style:{overflowAnchor:"none"},children:e.jsx(be,{mode:"wait",children:e.jsx(M.div,{initial:{opacity:0}
3,animate:{opacity:1},exit:{opacity:0},transition:{duration:.2},className:"min-h-full w-full flex flex-col",children:B?e.jsxs("div",{className:"flex-1",children:[B.type==="overview"&&e.jsx(fr,{}),B.type==="recent"&&e.jsx(pr,{projectId:a.id,monitors:v,refreshKey:ce,onSelectMonitor:te,onCreateMonitor:()=>X(null),onOpenCreateModal:X}),B.type==="keywords"&&e.jsx(Za,{projectId:a.id,monitors:v,refreshKey:ce}),B.type==="brand"&&e.jsx(er,{projectId:a.id,project:a,refreshKey:ce,onConnectBrand:()=>re(!0)}),B.type==="competitor"&&e.jsx(Sr,{competitorId:Number(B.id),onUpdate:N,refreshKey:ce}),B.type==="website"&&e.jsx(Dr,{monitorId:B.id.toString(),refreshKey:ce}),(B.type==="social_listener"||B.type==="keyword")&&e.jsx(Wr,{listenerId:B.id.toString(),refreshKey:ce}),B.type==="ab_test"&&e.jsx(lr,{testId:B.id.toString(),refreshKey:ce}),B.type==="page"&&e.jsxs("div",{className:"p-20 text-center flex flex-col items-center justify-center h-full",children:[e.jsx("div",{className:"w-20 h-20 rounded-full bg-red-50 dark:bg-red-900/20 flex items-center justify-center mb-6",children:e.jsx(Rt,{className:"w-10 h-10 text-red-500"})}),e.jsx("h2",{className:"text-2xl font-black mb-2 tracking-tight",children:"Page Monitor"}),e.jsx("p",{className:"text-neutral-500 mb-8",children:"Deep dive into Core Web Vitals and health performance."}),e.jsx("button",{onClick:()=>f(`/pages/${B.id}`),className:"bg-neutral-900 dark:bg-neutral-100 text-white dark:text-neutral-900 px-8 py-3 rounded font-bold text-xs hover:scale-105 transition-all shadow-none",children:"Open page health"})]})]}):e.jsxs("div",{className:"flex flex-col items-center justify-center h-full min-h-[600px] text-center p-12 bg-white dark:bg-neutral-900",children:[e.jsx("div",{className:"w-20 h-20 rounded bg-neutral-50 dark:bg-neutral-800 flex items-center justify-center mb-8 border border-neutral-100 dark:border-neutral-700",children:e.jsx(Pe,{className:"w-10 h-10 text-neutral-300"})}),e.jsx("h2",{className:"text-xl font-black text-neutral-900 dark:text-neutral-100 tracking-tight",children:"Analyze your assets"}),e.jsx("p",{className:"text-neutral-500 mt-3 max-w-xs text-sm font-medium",children:"Select a monitor from the left sidebar to view real-time changes."})]})},B?`${B.type}-${B.id}`:"empty")})})})}),e.jsx(ir,{isOpen:ee,onClose:()=>re(!1),project:a,onUpdate:R=>{i(R),re(!1)}})]})};export{is as ProjectOverview,is as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.