PageSourceSearch

https://sitealive.io/assets/Admin-CFUmowsr.js

js sitealive.io collected 2026-10-02 00:39:01 UTC 106,268 bytes, 1 lines download raw bytes

1import{r,j as e,L as Be,k as Ve}from"./vendor-react-D571QvPy.js";import{b as m,j as Ue,k as he,m as fe,F as pe,n as ge,B as Y,a as ne}from"./index-vhVGjLN5.js";import{bp as je,C as I,bq as ie,b7 as Qe,br as Ie,bs as ve,a0 as J,F as Je,G as Ye,W as be,bt as Re,E as Ne,O as Z,ap as Xe,aq as we,a9 as Ze,au as ye,bu as Le,bv as et,aT as ae,K as $e,b8 as tt,bw as st,X as at,bx as le,ar as nt,bc as it,a1 as lt,bb as X,ba as re,ai as Fe,by as rt,ae as dt,bz as ot,bA as ct,bB as xt,bC as mt,bD as ut,bE as ht,bF as ft,bG as pt,bH as bt,be as gt,aU as jt,aR as vt}from"./vendor-CYzKdXyE.js";import{g as Nt,d as wt}from"./domainValidation-CxhV-1jo.js";function Ae({initial:t,onSave:i,onCancel:o}){const[c,b]=r.useState(t||{slug:"",label:"",destination_url:"",notes:"",active:!0});return e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs font-medium text-[#888] mb-1",children:["Slug ",e.jsxs("span",{className:"text-[#bbb]",children:["sitealive.io/go/",e.jsx("b",{children:"slug"})]})]}),e.jsx("input",{value:c.slug,onChange:f=>b(x=>({...x,slug:f.target.value.toLowerCase().replace(/[^a-z0-9-]/g,"")})),placeholder:"vpn",className:"w-full border border-[#e0e0e0] rounded-xl px-3 py-2 text-sm focus:outline-none focus:border-[#999]"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-[#888] mb-1",children:"Label"}),e.jsx("input",{value:c.label,onChange:f=>b(x=>({...x,label:f.target.value})),placeholder:"NordVPN Affiliate",className:"w-full border border-[#e0e0e0] rounded-xl px-3 py-2 text-sm focus:outline-none focus:border-[#999]"})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-[#888] mb-1",children:"Destination URL"}),e.jsx("input",{type:"url",value:c.destination_url,onChange:f=>b(x=>({...x,destination_url:f.target.value})),placeholder:"https://affiliate.example.com/ref=abc123",className:"w-full border border-[#e0e0e0] rounded-xl px-3 py-2 text-sm focus:outline-none focus:border-[#999]"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-[#888] mb-1",children:"Notes (internal)"}),e.jsx("input",{value:c.notes,onChange:f=>b(x=>({...x,notes:f.target.value})),placeholder:"Commission: 40%, cookie 30d...",className:"w-full border border-[#e0e0e0] rounded-xl px-3 py-2 text-sm focus:outline-none focus:border-[#999]"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",id:"active-check",checked:c.active,onChange:f=>b(x=>({...x,active:f.target.checked})),className:"rounded"}),e.jsx("label",{htmlFor:"active-check",className:"text-sm text-[#555]",children:"Active (redirect enabled)"})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx("button",{onClick:o,className:"px-4 py-2 text-sm text-[#888] border border-[#e0e0e0] rounded-xl hover:bg-[#f5f5f5]",children:"Cancel"}),e.jsx("button",{onClick:()=>i(c),disabled:!c.slug||!c.destination_url,className:"px-4 py-2 text-sm font-medium bg-[#1a1a1a] text-white rounded-xl hover:bg-[#333] disabled:opacity-40",children:"Save"})]})]})}function yt({text:t}){const[i,o]=r.useState(!1),c=()=>{navigator.clipboard.writeText(t),o(!0),setTimeout(()=>o(!1),1500)};return e.jsx("button",{onClick:c,className:"p-1 text-[#bbb] hover:text-[#555] transition-colors",title:"Copy link",children:i?e.jsx(Je,{className:"w-4 h-4 text-green-500"}):e.jsx(Ye,{className:"w-4 h-4"})})}function _t(){const t=je(),[i,o]=r.useState(!1),[c,b]=r.useState(null),[f,x]=r.useState(null),{data:l=[]}=I({queryKey:["affiliate-links"],queryFn:()=>m.entities.AffiliateLink.list("-created_date",200)}),{data:u=[]}=I({queryKey:["affiliate-clicks"],queryFn:()=>m.entities.AffiliateLinkClick.list("-created_date",5e3)}),p=ie({mutationFn:h=>m.entities.AffiliateLink.create(h),onSuccess:()=>{t.invalidateQueries(["affiliate-links"]),o(!1)}}),g=ie({mutationFn:({id:h,data:d})=>m.entities.AffiliateLink.update(h,d),onSuccess:()=>{t.invalidateQueries(["affiliate-links"]),b(null)}}),v=ie({mutationFn:h=>m.entities.AffiliateLink.delete(h),onSuccess:()=>{t.invalidateQueries(["affiliate-links"]),x(null)}}),N={};u.forEach(h=>{N[h.affiliate_link_id]=(N[h.affiliate_link_id]||0)+1}),l.find(h=>h.id===f);const y=u.filter(h=>h.affiliate_link_id===f),T=(()=>
1{if(!y.length)return[];const h={};return y.forEach(d=>{var j;const n=(j=d.created_date)==null?void 0:j.slice(0,10);n&&(h[n]=(h[n]||0)+1)}),Object.entries(h).sort((d,n)=>d[0].localeCompare(n[0])).slice(-30)})(),D=(()=>{if(!y.length)return[];const h={};return y.forEach(d=>{const n=d.referrer||"(direct)";h[n]=(h[n]||0)+1}),Object.entries(h).sort((d,n)=>n[1]-d[1])})();return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-sm font-semibold text-[#1a1a1a]",children:"Affiliate Links"}),e.jsxs("p",{className:"text-xs text-[#aaa] mt-0.5",children:["Manage hidden redirect links at ",e.jsx("span",{className:"font-mono",children:"sitealive.io/go/slug"})]})]}),e.jsxs("button",{onClick:()=>{o(!0),b(null)},className:"flex items-center gap-2 px-3 py-1.5 text-sm font-medium bg-[#1a1a1a] text-white rounded-xl hover:bg-[#333] transition-colors",children:[e.jsx(Qe,{className:"w-4 h-4"}),"New link"]})]}),i&&e.jsxs("div",{className:"bg-white border border-[#ebebeb] rounded-2xl p-5",children:[e.jsx("h3",{className:"text-sm font-medium text-[#1a1a1a] mb-4",children:"New affiliate link"}),e.jsx(Ae,{onSave:h=>p.mutate(h),onCancel:()=>o(!1)})]}),e.jsx("div",{className:"bg-white border border-[#ebebeb] rounded-2xl overflow-hidden",children:l.length===0?e.jsx("p",{className:"text-sm text-[#aaa] px-5 py-10 text-center",children:"No affiliate links yet. Create one above."}):e.jsx("div",{className:"divide-y divide-[#f5f5f5]",children:l.map(h=>e.jsxs("div",{children:[(c==null?void 0:c.id)===h.id?e.jsx("div",{className:"px-5 py-4",children:e.jsx(Ae,{initial:h,onSave:d=>g.mutate({id:h.id,data:d}),onCancel:()=>b(null)})}):e.jsxs("div",{className:`px-5 py-3 flex items-center gap-3 cursor-pointer hover:bg-[#fafafa] transition-colors ${f===h.id?"bg-[#fafafa]":""}`,onClick:()=>x(f===h.id?null:h.id),children:[e.jsx("div",{className:`w-2 h-2 rounded-full shrink-0 ${h.active?"bg-green-400":"bg-[#ddd]"}`}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsx("span",{className:"font-medium text-sm text-[#1a1a1a]",children:h.label||h.slug}),e.jsxs("span",{className:"font-mono text-xs text-[#bbb]",children:["sitealive.io/go/",h.slug]})]}),e.jsx("div",{className:"text-xs text-[#aaa] truncate mt-0.5",children:h.destination_url})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsxs("span",{className:"flex items-center gap-1 text-xs text-[#888] bg-[#f3f4f6] rounded-lg px-2 py-1",children:[e.jsx(Ie,{className:"w-3 h-3"}),N[h.id]||0," clicks"]}),e.jsx(yt,{text:`https://sitealive.io/go/${h.slug}`}),e.jsx("button",{onClick:d=>{d.stopPropagation(),b(h),o(!1)},className:"p-1 text-[#bbb] hover:text-[#555]",title:"Edit",children:e.jsx(ve,{className:"w-4 h-4"})}),e.jsx("button",{onClick:d=>{d.stopPropagation(),confirm(`Delete /go/${h.slug}?`)&&v.mutate(h.id)},className:"p-1 text-[#bbb] hover:text-red-500",title:"Delete",children:e.jsx(J,{className:"w-4 h-4"})})]})]}),f===h.id&&!c&&e.jsxs("div",{className:"px-5 pb-5 border-t border-[#f5f5f5] bg-[#fafafa]",children:[e.jsxs("div",{className:"pt-4 grid grid-cols-3 gap-4 mb-4",children:[e.jsxs("div",{className:"bg-white border border-[#ebebeb] rounded-xl px-4 py-3 text-center",children:[e.jsx("div",{className:"text-xl font-bold text-[#1a1a1a]",children:y.length}),e.jsx("div",{className:"text-xs text-[#aaa]",children:"Total clicks"})]}),e.jsxs("div",{className:"bg-white border border-[#ebebeb] rounded-xl px-4 py-3 text-center",children:[e.jsx("div",{className:"text-xl font-bold text-[#1a1a1a]",children:y.filter(d=>new Date(d.created_date)>new Date(Date.now()-7*864e5)).length}),e.jsx("div",{className:"text-xs text-[#aaa]",children:"Last 7 days"})]}),e.jsxs("div",{className:"bg-white border border-[#ebebeb] rounded-xl px-4 py-3 text-center",children:[e.jsx("div",{className:"text-xl font-bold text-[#1a1a1a]",children:y.filter(d=>new Date(d.created_date)>new Date(Date.now()-864e5)).length}),e.jsx("div",{className:"text-xs text-[#aaa]",children:"Today"})]})]}),D.length>0&&e.jsxs("div",{className:"bg-white border border-[#ebebeb] rounded-xl p-4 mb-4",children:[e.jsx("div",{className:"text-xs font-semibold text-[#aaa] uppercase tracking-widest mb-3",children:"Source URLs"}),e.jsx("div",{className:"space-y-2",children:D.map(([d,n])=>e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-xs text-[#555] flex-1 truncate font-mono",title:d,children:d}),e.jsx("span",{className:"text-xs font-semibold text-[#1a1a1a] w-10 text-right shrink-0",children:n}),e.jsx("div",{className:"w-24 h-1.5 bg-[#f3f4f6] rounded-full overflow-hidden shrink-0",children:e.jsx("div",{className:"h-full bg-[#1a1a1a] rounded-full",style:{width:`${n/y.length*100}%`}})})]},d))})]}),T.length>0&&e.jsxs("div",{className:"bg-white border border-[#ebebeb] rounded-xl p-4",children:[e.jsx("div",{className:"text-xs font-semibold text-[#aaa] uppercase tracking-widest mb-3",children:"Clicks over time (last 30 days)"}),e.jsx("div",{className:"flex items-end gap-1 h-20",children:T.map(([d,n])=>{const j=Math.max(...T.map(([,k])=>k));return e.jsxs("div",{className:"flex-1 flex flex-col items-center gap-1 group relative",children:[e.jsx("div",{className:"w-full bg-[#1a1a1a] rounded-t-sm transition-all",style:{height:`${j>0?n/j*100:0}%`}}),e.jsxs("div",{className:"absolute bottom-full mb-1 hidden group-hover:block bg-[#1a1a1a] text-white text-[10px] rounded px-1.5 py-0.5 whitespace-nowrap",children:[d,": ",n]})]},d)})})]}),y.length===0&&e.jsx("p",{className:"text-sm text-[#aaa] text-center py-4",children:"No clicks recorded yet."})]})]}
1,h.id))})})]})}function kt(t){const i=Math.floor((Date.now()-new Date(t).getTime())/1e3);return i<60?`${i}s ago`:i<3600?`${Math.floor(i/60)}m ago`:i<86400?`${Math.floor(i/3600)}h ago`:`${Math.floor(i/86400)}d ago`}function St(t){return new Date(t).toLocaleString("en-GB",{day:"2-digit",month:"short",year:"numeric",hour:"2-digit",minute:"2-digit"})}function Ct(){const[t,i]=r.useState([]),[o,c]=r.useState({}),[b,f]=r.useState(new Set),[x,l]=r.useState({}),[u,p]=r.useState(!0),[g,v]=r.useState("date");r.useEffect(()=>{N()},[]);const N=async()=>{p(!0);try{const[d,n,j]=await Promise.all([m.entities.Comment.list("-created_date",500),m.entities.Site.list("-created_date",1e3),m.entities.BannedUser.list()]);i(d);const k={};n.forEach(R=>{k[R.id]=R}),c(k);const S=new Set(j.map(R=>R.user_email));f(S);const L={};d.forEach(R=>{const M=R.created_by||R.user_email;M&&(L[M]||(L[M]={count:0,name:R.user_name,lastComment:R.created_date}),L[M].count++,new Date(R.created_date)>new Date(L[M].lastComment)&&(L[M].lastComment=R.created_date))}),l(L)}catch(d){console.error("Failed to load comments:",d)}finally{p(!1)}},y=async d=>{if(confirm(`Ban user ${d} from posting comments?`))try{const n=await m.auth.me();await m.entities.BannedUser.create({user_email:d,reason:"Spam",banned_by:n.email}),f(j=>new Set([...j,d])),alert(`User ${d} has been banned`)}catch(n){alert("Failed to ban user: "+n.message)}},T=async d=>{if(confirm(`Unban user ${d}?`))try{const n=await m.entities.BannedUser.filter({user_email:d});n.length>0&&(await m.entities.BannedUser.delete(n[0].id),f(j=>{const k=new Set(j);return k.delete(d),k}),alert(`User ${d} has been unbanned`))}catch(n){alert("Failed to unban user: "+n.message)}},D=async d=>{if(confirm("Delete this comment permanently?"))try{await m.entities.Comment.delete(d),i(n=>n.filter(j=>j.id!==d)),N()}catch(n){alert("Failed to delete comment: "+n.message)}},h=[...t].sort((d,n)=>g==="date"?new Date(n.created_date)-new Date(d.created_date):g==="user"?(d.created_by||d.user_email||"").localeCompare(n.created_by||n.user_email||""):0);return u?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx("div",{className:"w-8 h-8 border-4 border-slate-200 border-t-slate-800 rounded-full animate-spin"})}):e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(be,{className:"w-5 h-5 text-slate-700"}),e.jsx("h2",{className:"text-xl font-semibold text-slate-900",children:"Comments Management"}),e.jsxs("span",{className:"px-2 py-0.5 bg-slate-100 text-slate-600 text-xs font-medium rounded-full",children:[t.length," total"]})]}),e.jsxs("select",{value:g,onChange:d=>v(d.target.value),className:"px-3 py-1.5 border border-slate-300 rounded-lg text-sm",children:[e.jsx("option",{value:"date",children:"Sort by date"}),e.jsx("option",{value:"user",children:"Sort by user"})]})]}),t.length===0?e.jsxs("div",{className:"text-center py-12 bg-slate-50 rounded-xl border border-slate-200",children:[e.jsx(be,{className:"w-12 h-12 text-slate-300 mx-auto mb-3"}),e.jsx("p",{className:"text-sm text-slate-500",children:"No comments yet"})]}):e.jsx("div",{className:"space-y-3",children:h.map(d=>{const n=o[d.site_id],j=d.created_by||d.user_email,k=b.has(j),S=x[j]||{count:0};return e.jsx("div",{className:`border rounded-xl p-4 ${k?"bg-red-50 border-red-200":"bg-white border-slate-200"}`,children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"w-10 h-10 rounded-full bg-gradient-to-br from-indigo-400 to-purple-400 flex items-center justify-center text-white text-sm font-semibold shrink-0",children:(d.user_name||j||"?")[0].toUpperCase()}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 mb-2",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("span",{className:"font-medium text-slate-900",children:d.user_name||(j==null?void 0:j.split("@")[0])||"Anonymous"}),k&&e.jsxs("span",{className:"px-2 py-0.5 bg-red-100 text-red-700 text-xs font-medium rounded-full flex items-center gap-1",children:[e.jsx(Re,{className:"w-3 h-3"}),"Banned"]})]}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-slate-500",children:[e.jsx("span",{children:j}),e.jsx("span",{children:"•"}),e.jsxs("span",{className:"font-medium text-indigo-600",children:[S.count," comment",S.count!==1?"s":""]}),e.jsx("span",{children:"•"}),e.jsx("span",{children:kt(d.created_date)}),e.jsx("span",{children:"•"}),e.jsx("span",{children:St(d.created_date)})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[k?e.jsx("button",{onClick:()=>T(j),className:"px-2 py-1 text-xs font-medium text-red-700 bg-red-100 hover:bg-red-200 rounded-lg transition-colors",children:"Unban"}):e.jsx("button",{onClick:()=>y(j),className:"p-1.5 text-slate-400 hover:text-red-600 hover:bg-red-50 rounded-lg transition-colors",title:"Ban user",children:e.jsx(Re,{className:"w-4 h-4"})}),e.jsx("button",{onClick:()=>D(d.id),className:"p-1.5 text-slate-400 hover:text-red-600 hover:bg-red-50 rounded-lg transition-colors",title:"Delete comment",children:e.jsx(J,{className:"w-4 h-4"})})]})]}),e.jsx("p",{className:"text-sm text-slate-700 mb-3 whitespace-pre-wrap",children:d.content}),n&&e.jsxs(Be,{to:`/${n.slug}`,className:"inline-flex items-center gap-1.5 px-3 py-1.5 bg-slate-100 hover:bg-slate-200 text-slate-700 text-xs font-medium rounded-lg transition-colors",children:[e.jsx(Ne,{className:"w-3 h-3"}),"View on ",n.display_name," page"]})]})]})},d.id)})})]})}const z={settings_key:"default",email_from_name:"SiteAlive",alert_repeat_minutes:15,dashboard_url:"https://sitealive.app/dashboard",down_email_subject:"is down",down_email_description:"Your monitored site appears to be unavailable.",recovery_email_subject:"is back online",recovery_email_description:"Your monitored site is accessible again."};function Dt(){const[t,i]=r.useState(z),[o,c]=r.useState(!1),[b,f]=r.useState(!1),{data:x=[],isLoading:l,refetch:u}=I({queryKey:["app-settings"],queryFn:()=>m.entities.AppSettings.list("-updated_date",1)});r.useEffect(()=>{i({...z,...x[0]||{}})},[x]);const p=async()=>{var v;c(!0),f(!1);const g={settings_key:"default",email_from_name:t.email_from_name.trim()||z.email_from_name,alert_repeat_minutes:Math.max(1,Number(t.alert_repeat_minutes)||z.alert_repeat_minutes),dashboard_url:t.dashboard_url.trim()||z.dashboard_url,down_email_subject:t.down_email_subject.trim()||z.down_email_subject,down_email_description:t.down_email_description.trim()||z.down_email_description,recovery_email_subject:t.recovery_email_subject.trim()||z.recovery_email_subject,recovery_email_description:t.recovery_email_description.trim()||z.recovery_email_description};(v=x[0])!=null&&v.id?await m.entities.AppSettings.update(x[0].id,g):await m.entities.AppSettings.create(g),await u(),c(!1),f(!0)};return e.jsxs("div",{className:"bg-white border border-[#ebebeb] rounded-[28px] p-6 shadow-[0_18px_50px_rgba(15,23,42,0.05)]",children:[e.jsxs("div",{className:"mb-6",children:[e.jsx("h2",{className:"text-lg font-semibold text-[#1a1a1a]",children:"Alert email settings"}),e.jsx("p",{className:"text-sm text-[#888] mt-1",children:"Control the sender name, email subject lines, descriptions, reminder timing, and dashboard link used in alert emails."})]}),e.jsx("div",{className:"mb-6 rounded-2xl border border-[#e5e7eb] bg-[#f8fafc] px-4 py-3 text-sm text-[#64748b] max-w-xl",children:"The sender email address itself is not set here — change that in Dashboard → Domains → Email domain."}),e.jsxs("div",{className:"space-y-4 max-w-xl",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-[#888] mb-1",children:"Email sender name"}),e.jsx("input",{value:t.email_from_name,onChange:g=>i(v=>({...v,email_from_name:g.target.value})),placeholder:"SiteAlive",className:"w-full border border-[#e0e0e0] rounded-xl px-3 py-2 text-sm focus:outline-none focus:border-[#999]"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-[#888] mb-1",children:"Reminder interval (minutes)"}),e.jsx("input",{type:"number",min:"1",value:t.alert_repeat_minutes,onChange:g=>i(v=>({...v,alert_repeat_minutes:g.target.value})),className:"w-full border border-[#e0e0e0] rounded-xl px-3 py-2 text-sm focus:outline-none focus:border-[#999]"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-[#888] mb-1",children:"Down email subject"}),e.jsx("input",{value:t.down_email_subject,onChange:g=>i(v=>({...v,down_email_subject:g.target.value})),placeholder:"is down",className:"w-full border border-[#e0e0e0] rounded-xl px-3 py-2 text-sm focus:outline-none focus:border-[#999]"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-[#888] mb-1",children:"Down email description"}),e.jsx("textarea",{value:t.down_email_description,onChange:g=>i(v=>({...v,down_email_description:g.target.value})),rows:3,className:"w-full border border-[#e0e0e0] rounded-xl px-3 py-2 text-sm focus:outline-none focus:border-[#999] resize-none"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-[#888] mb-1",children:"Recovery email subject"}),e.jsx("input",{value:t.recovery_email_subject,onChange:g=>i(v=>({...v,recovery_email_subject:g.target.value})),placeholder:"is back online",className:"w-full border border-[#e0e0e0] rounded-xl px-3 py-2 text-sm focus:outline-none focus:border-[#999]"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-[#888] mb-1",children:"Recovery email description"}),e.jsx("textarea",{value:t.recovery_email_description,onChange:g=>i(v=>({...v,recovery_email_description:g.target.value})),rows:3,className:"w-full border border-[#e0e0e0] rounded-xl px-3 py-2 text-sm focus:outline-none focus:border-[#999] resize-none"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-[#888] mb-1",children:"Dashboard link in emails"}),e.jsx("input",{type:"url",value:t.dashboard_url,onChange:g=>i(v=>({...v,dashboard_url:g.target.value})),placeholder:"https://sitealive.app/dashboard",className:"w-full border border-[#e0e0e0] rounded-xl px-3 py-2 text-sm focus:outline-none focus:border-[#999]"})]})]}),e.jsxs("div",{className:"flex items-center gap-3 mt-6",children:[e.jsx("button",{onClick:p,disabled:o||l,className:"px-4 py-2 text-sm font-medium bg-[#1a1a1a] text-white rounded-xl hover:bg-[#333] disabled:opacity-50",children:o?"Saving...":"Save settings"}),b&&e.jsx("span",{className:"text-sm text-green-700",children:"Saved"})]})]})}function Ut(){const[t,i]=r.useState(""),[o,c]=r.useState(!1),[b,f]=r.useState(""),{data:x=[],refetch:l,isLoading:u}=I({queryKey:["blocked-domains-admin"],queryFn:()=>m.entities.BannedUser.list("user_email",1e3)}),p=r.useMemo(()=>Nt().exactDomains,[]),g=async()=>{const N=t.trim().toLowerCase().replace(/^https?:\/\//,"").replace(/^www\./,"").replace(/[/?#].*$/,"");if(!N||!N.includes(".")){f("Enter a valid domain like example.com");return}const y=p.includes(N),T=x.some(D=>String(D.user_email||"").toLowerCase()===N);if(y||T){f("That domain is already in the blocked list");return}c(!0),f(""),await m.entities.BannedUser.create({user_email:N,reason:"Blocked domain"}),i(""),c(!1),await l()},v=async N=>{await m.entities.BannedUser.delete(N),await l()};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"rounded-[28px] border border-white/70 bg-white/95 p-6 shadow-[0_18px_50px_rgba(15,23,42,0.06)]",children:[e.jsx("h2",{className:"text-lg font-semibold text-[#111827]",children:"Blocked websites"}),e.jsx("p",{className:"mt-1 text-sm text-[#6b7280]",children:"This shows the blocked domains added in code and any extra domains you add here. Sites on this list are excluded from search discovery, including URL shortener services."}),e.jsxs("div",{className:"mt-5 flex flex-col gap-3 sm:flex-row",children:[e.jsx("input",{value:t,onChange:N=>{i(N.target.value),b&&f("")},placeholder:"example.com",className:"w-full rounded-xl border border-[#e0e0e0] px-3 py-2 text-sm focus:outline-none focus:border-[#999]"}),e.jsx("button",{onClick:g,disabled:o,className:"rounded-xl bg-[#111827] px-4 py-2 text-sm font-medium text-white hover:bg-[#1f2937] disabled:opacity-50",children:o?"Adding...":"Add blocked domain"})]}),b?e.jsx("p",{className:"mt-2 text-sm text-red-600",children:b}):null]}),e.jsxs("div",{className:"grid gap-6 xl:grid-cols-2",children:[e.jsxs("div",{className:"rounded-[28px] border border-white/70 bg-white/95 p-6 shadow-[0_18px_50px_rgba(15,23,42,0.06)]",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("h3",{className:"text-base font-semibold text-[#111827]",children:"Built-in blocked domains"}),e.jsx("span",{className:"rounded-full bg-[#f8fafc] px-2.5 py-1 text-xs font-medium text-[#64748b]",children:p.length})]}),e.jsx("div",{className:"mt-4 max-h-[520px] space-y-2 overflow-y-auto",children:p.map(N=>e.jsx("div",{className:"rounded-xl border border-[#eef2f7] bg-[#f8fafc] px-3 py-2 text-sm text-[#334155]",children:N},N))})]}),e.jsxs("div",{className:"rounded-[28px] border border-white/70 bg-white/95 p-6 shadow-[0_18px_50px_rgba(15,23,42,0.06)]",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsx("h3",{className:"text-base font-semibold text-[#111827]",children:"Custom blocked domains"}),e.jsx("span",{className:"rounded-full bg-[#f8fafc] px-2.5 py-1 text-xs font-medium text-[#64748b]",children:x.length})]}),e.jsx("div",{className:"mt-4 max-h-[520px] space-y-2 overflow-y-auto",children:u?e.jsx("p",{className:"text-sm text-[#94a3b8]",children:"Loading..."}):x.length===0?e.jsx("p",{className:"text-sm text-[#94a3b8]",children:"No extra blocked domains yet."}):x.map(N=>e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-xl border border-[#eef2f7] bg-white px-3 py-2",children:[e.jsx("span",{className:"min-w-0 truncate text-sm text-[#334155]",children:N.user_email}),e.jsx("button",{onClick:()=>v(N.id),className:"rounded-lg p-2 text-[#64748b] transition-colors hover:bg-red-50 hover:text-red-600",title:"Remove",children:e.jsx(J,{className:"h-4 w-4"})})]},N.id))})]})]})]})}function V({value:t,label:i}){return e.jsxs("div",{className:"rounded-[22px] border border-[#e8edf3] bg-white px-5 py-4 shadow-sm",children:[e.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-[0.12em] text-[#8a94a6]",children:i}),e.jsx("div",{className:"mt-2 text-3xl font-semibold tracking-tight text-[#111827]",children:t})]})}function Pe(t){if(!t)return null;const i=new Date(t);return Number.isNaN(i.getTime())?null:new Intl.DateTimeFormat("en-GB",{day:"2-digit",month:"short",year:"numeric",hour:"2-digit",minute:"2-digit"}).format(i)}function Rt({user:t,plan:i,used:o,bonus:c,baseLimit:b,remaining:f,bonusDraftValue:x,planDraftValue:l,proUntilDraftValue:u,unlimitedReportsUntilDraftValue:p,hasManualPro:g,hasUnlimitedReports:v,saving:N,onPlanChange:y,onBonusChange:T,onAddBonus:D,onProUntilChange:h,onQuickPro:d,onUnlimitedChange:n,onQuickUnlimited:j,onSave:k}){return e.jsx("div",{className:"rounded-[24px] border border-[#e6ebf2] bg-white p-4 shadow-sm md:p-5",children:e.jsxs("div",{className:"flex flex-col gap-4 lg:flex-row lg:items-start lg:justify-between",children:[e.jsxs("div",{className:"min-w-0 lg:max-w-[260px]",children:[e.jsx("div",{className:"text-lg font-semibold tracking-tight text-[#111827]",children:t.full_name||t.email}),e.jsx("div",{className:"mt-1 truncate text-sm text-[#6b7280]",children:t.email}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx("span",{className:"rounded-full bg-[#f3f4f6] px-2.5 py-1 text-xs font-medium text-[#4b5563]",children:i==="scale"?"Scale":i==="pro"?"Pro":"Free"}),t.role==="admin"&&e.jsx("span",{className:"rounded-full bg-[#eef2ff] px-2.5 py-1 text-xs font-medium text-[#4f46e5]",children:"Admin"}),g&&e.jsx("span",{className:"rounded-full bg-[#ecfeff] px-2.5 py-1 text-xs font-medium text-[#0f766e]",children:"Temporary Pro active"}),v&&e.jsx("span",{className:"rounded-full bg-[#eff6ff] px-2.5 py-1 text-xs font-medium text-[#1d4ed8]",children:"Unlimited PDFs active"})]}),e.jsxs("div",{className:"mt-4 grid grid-cols-2 gap-2",childre
1n:[e.jsxs("div",{className:"rounded-2xl bg-[#f8fafc] px-3 py-2",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wide text-[#8a94a6]",children:"Used today"}),e.jsx("div",{className:"mt-1 text-sm font-semibold text-[#111827]",children:o})]}),e.jsxs("div",{className:"rounded-2xl bg-[#f8fafc] px-3 py-2",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wide text-[#8a94a6]",children:"Base limit"}),e.jsx("div",{className:"mt-1 text-sm font-semibold text-[#111827]",children:b})]}),e.jsxs("div",{className:"rounded-2xl bg-[#f8fafc] px-3 py-2",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wide text-[#8a94a6]",children:"Extra credits"}),e.jsx("div",{className:"mt-1 text-sm font-semibold text-[#111827]",children:c})]}),e.jsxs("div",{className:"rounded-2xl bg-[#f8fafc] px-3 py-2",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wide text-[#8a94a6]",children:"Remaining"}),e.jsx("div",{className:"mt-1 text-sm font-semibold text-[#111827]",children:f})]})]})]}),e.jsxs("div",{className:"flex-1",children:[e.jsxs("div",{className:"grid gap-3 md:grid-cols-2 xl:grid-cols-4",children:[e.jsxs("div",{className:"rounded-2xl border border-[#edf1f5] bg-[#fbfcfd] p-3",children:[e.jsx("div",{className:"mb-2 text-xs font-semibold uppercase tracking-wide text-[#6b7280]",children:"Package"}),e.jsxs("select",{value:l,onChange:S=>y(S.target.value),className:"w-full rounded-xl border border-[#dde3ea] bg-white px-3 py-2.5 text-sm text-[#111827] focus:border-[#cbd5e1] focus:outline-none",children:[e.jsx("option",{value:"free",children:"Free"}),e.jsx("option",{value:"pro",children:"Pro"}),e.jsx("option",{value:"scale",children:"Scale"})]})]}),e.jsxs("div",{className:"rounded-2xl border border-[#edf1f5] bg-[#fbfcfd] p-3",children:[e.jsx("div",{className:"mb-2 text-xs font-semibold uppercase tracking-wide text-[#6b7280]",children:"Extra checks"}),e.jsx("input",{type:"number",min:"0",value:x,onChange:S=>T(S.target.value),className:"w-full rounded-xl border border-[#dde3ea] bg-white px-3 py-2.5 text-sm text-[#111827] focus:border-[#cbd5e1] focus:outline-none"}),e.jsx("button",{type:"button",onClick:D,className:"mt-2 w-full rounded-xl border border-[#dde3ea] bg-white px-3 py-2 text-sm font-medium text-[#4b5563] hover:bg-[#f8fafc]",children:"Add 6"})]}),e.jsxs("div",{className:"rounded-2xl border border-[#edf1f5] bg-[#fbfcfd] p-3",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[e.jsx("div",{className:"text-xs font-semibold uppercase tracking-wide text-[#6b7280]",children:"Temporary Pro"}),e.jsx("button",{type:"button",onClick:d,className:"text-xs font-medium text-[#4f46e5] hover:text-[#4338ca]",children:"30 days"})]}),e.jsx("input",{type:"datetime-local",value:u,onChange:S=>h(S.target.value),className:"w-full rounded-xl border border-[#dde3ea] bg-white px-3 py-2.5 text-sm text-[#111827] focus:border-[#cbd5e1] focus:outline-none"})]}),e.jsxs("div",{className:"rounded-2xl border border-[#edf1f5] bg-[#fbfcfd] p-3",children:[e.jsxs("div",{className:"mb-2 flex items-center justify-between gap-2",children:[e.jsx("div",{className:"text-xs font-semibold uppercase tracking-wide text-[#6b7280]",children:"Unlimited PDFs"}),e.jsx("button",{type:"button",onClick:j,className:"text-xs font-medium text-[#1d4ed8] hover:text-[#1e40af]",children:p?"Clear":"Next 24h"})]}),e.jsx("input",{type:"datetime-local",value:p,onChange:S=>n(S.target.value),className:"w-full rounded-xl border border-[#dde3ea] bg-white px-3 py-2.5 text-sm text-[#111827] focus:border-[#cbd5e1] focus:outline-none"}),e.jsx("div",{className:"mt-2 text-xs text-[#6b7280]",children:Pe(t==null?void 0:t.network_tools_admin_unlimited_reports_until)?`Current access until ${Pe(t==null?void 0:t.network_tools_admin_unlimited_reports_until)}`:"No unlimited PDF access set"})]})]}),e.jsx("div",{className:"mt-4 flex justify-end",children:e.jsx("button",{type:"button",onClick:k,disabled:N,className:"inline-flex min-w-[150px] items-center justify-center rounded-2xl bg-[#111827] px-4 py-3 text-sm font-semibold text-white transition-colors hover:bg-[#1f2937] disabled:opacity-50",children:N?"Saving...":"Save changes"})})]})]})})}const Lt=new Date().toLocaleDateString("en-CA");function de(t){return ge(t)}function Ee(t){return(t==null?void 0:t.network_tools_usage_date)===Lt&&Number(t==null?void 0:t.network_tools_usage_count)||0}function Q(t){if(!t)return"";const i=new Date(t);return Number.isNaN(i.getTime())?"":new Date(i.getTime()-i.getTimezoneOffset()*6e4).toISOString().slice(0,16)}function At(){const t=new Date(Date.now()+2592e6);return new Date(t.getTime()-t.getTimezoneOffset()*6e4).toISOString().slice(0,16)}function Pt(){const t=new Date(Date.now()+864e5);return new Date(t.getTime()-t.getTimezoneOffset()*6e4).toISOString().slice(0,16)}function Me(t,i=new Date){const o=t==null?void 0:t.network_tools_admin_unlimited_reports_until;if(!o)return!1;const c=new Date(o);return!Number.isNaN(c.getTime())&&c>i}function Et(){const[t,i]=r.useState({}),[o,c]=r.useState({}),[b,f]=r.useState({}),[x,l]=r.useState({}),[u,p]=r.useState(null),[g,v]=r.useState(""),{data:N=[],isLoading:y,refetch:T}=I({queryKey:["admin-users-credits"],queryFn:()=>m.entities.User.list("-created_date",500)}),D=r.useMemo(()=>N.reduce((n,j)=>{const k=de(j),S=k==="scale"?he:k==="pro"?fe:pe,L=Math.max(0,Number(j==null?void 0:j.network_tools_bonus_credits)||0),R=Ee(j);return n.used+=R,n.bonus+=L,n.usersWithBonus+=L>
10?1:0,n.usersWithManualPro+=Ue(j)?1:0,n.usersWithUnlimitedReports+=Me(j)?1:0,n.remaining+=Math.max(S+L-R,0),n},{used:0,bonus:0,remaining:0,usersWithBonus:0,usersWithManualPro:0,usersWithUnlimitedReports:0}),[N]),h=r.useMemo(()=>{const n=g.trim().toLowerCase();return n?N.filter(j=>String((j==null?void 0:j.full_name)||"").toLowerCase().includes(n)||String((j==null?void 0:j.email)||"").toLowerCase().includes(n)):N},[N,g]),d=async n=>{const j=t[n.id],k=o[n.id]??de(n),S=b[n.id]??Q(n==null?void 0:n.network_tools_admin_pro_until),L=x[n.id]??Q(n==null?void 0:n.network_tools_admin_unlimited_reports_until),R=Math.max(0,Number(j??(n==null?void 0:n.network_tools_bonus_credits)??0)||0),M=k==="scale"?"scale":k==="pro"?"pro":"free",$=S?new Date(S):null,F=L?new Date(L):null,s=M==="pro"&&$&&!Number.isNaN($.getTime())?$.toISOString():null,w=F&&!Number.isNaN(F.getTime())?F.toISOString():null,C=M==="pro"&&!!s;p(n.id),await m.entities.User.update(n.id,{network_tools_plan:M==="pro"&&C?"free":M,network_tools_subscription_status:M==="free"||C?"inactive":"active",network_tools_bonus_credits:R,network_tools_admin_pro_until:C?s:null,network_tools_admin_unlimited_reports_until:w}),i(A=>({...A,[n.id]:R})),c(A=>({...A,[n.id]:M})),f(A=>({...A,[n.id]:s?Q(s):""})),l(A=>({...A,[n.id]:w?Q(w):""})),await T(),p(null)};return e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-2 xl:grid-cols-3",children:[e.jsx(V,{value:N.length,label:"Users"}),e.jsx(V,{value:D.used,label:"Checks used today"}),e.jsx(V,{value:D.remaining,label:"Checks remaining today"}),e.jsx(V,{value:D.usersWithBonus,label:"Users with extra credits"}),e.jsx(V,{value:D.usersWithManualPro,label:"Manual Pro users"}),e.jsx(V,{value:D.usersWithUnlimitedReports,label:"Unlimited PDF users"})]}),e.jsxs("div",{className:"overflow-hidden rounded-[28px] border border-[#e8edf3] bg-white shadow-sm",children:[e.jsx("div",{className:"border-b border-[#eef2f6] px-5 py-5 md:px-6",children:e.jsxs("div",{className:"flex flex-col gap-4 lg:flex-row lg:items-center lg:justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-semibold tracking-tight text-[#111827]",children:"Credits"}),e.jsx("p",{className:"mt-1 text-sm text-[#6b7280]",children:"Search a user and update their plan, extra checks, or temporary access."})]}),e.jsx("div",{className:"w-full lg:w-[320px]",children:e.jsx("input",{type:"text",value:g,onChange:n=>v(n.target.value),placeholder:"Search by name or email",className:"w-full rounded-2xl border border-[#e3e8ef] bg-[#f8fafc] px-4 py-3 text-sm text-[#111827] placeholder:text-[#9aa4b2] focus:border-[#cbd5e1] focus:bg-white focus:outline-none"})})]})}),y?e.jsx("div",{className:"px-6 py-10 text-sm text-[#6b7280]",children:"Loading users..."}):e.jsx("div",{className:"grid gap-3 bg-[#f8fafc] p-3 md:p-4",children:h.length===0?e.jsx("div",{className:"rounded-[22px] border border-dashed border-[#d7dee8] bg-white px-5 py-8 text-sm text-[#6b7280]",children:"No users match your search."}):h.map(n=>{const j=de(n),k=Ee(n),S=Math.max(0,Number(n==null?void 0:n.network_tools_bonus_credits)||0),L=j==="scale"?he:j==="pro"?fe:pe,R=L+S,M=Math.max(R-k,0),$=t[n.id]??S,F=o[n.id]??j,s=b[n.id]??Q(n==null?void 0:n.network_tools_admin_pro_until),w=x[n.id]??Q(n==null?void 0:n.network_tools_admin_unlimited_reports_until),C=Ue(n),A=Me(n);return e.jsx(Rt,{user:n,plan:j,used:k,bonus:S,baseLimit:L,remaining:M,bonusDraftValue:$,planDraftValue:F,proUntilDraftValue:s,unlimitedReportsUntilDraftValue:w,hasManualPro:C,hasUnlimitedReports:A,saving:u===n.id,onPlanChange:E=>c(B=>({...B,[n.id]:E})),onBonusChange:E=>i(B=>({...B,[n.id]:E})),onAddBonus:()=>i(E=>({...E,[n.id]:S+6})),onProUntilChange:E=>f(B=>({...B,[n.id]:E})),onQuickPro:()=>f(E=>({...E,[n.id]:At()})),onUnlimitedChange:E=>l(B=>({...B,[n.id]:E})),onQuickUnlimited:()=>l(E=>({...E,[n.id]:w?"":Pt()})),onSave:()=>d(n)},n.id)})})]})]})}function se({label:t,value:i,sub:o}){return e.jsxs("div",{className:"rounded-2xl border border-[#ebebeb] bg-white px-4 py-4",children:[e.jsx("div",{className:"text-xs font-semibold uppercase tracking-[0.16em] text-[#8b95a7]",children:t}),e.jsx("div",{className:"mt-2 text-2xl font-bold text-[#111827] break-all",children:i}),o?e.jsx("div",{className:"mt-1 text-xs text-[#6b7280]",children:o}):null]})}function Te({title:t,rows:i,emailKey:o}){return e.jsxs("div",{className:"rounded-2xl border border-[#ebebeb] bg-white overflow-hidden",children:[e.jsx("div",{className:"border-b border-[#f2f4f7] px-4 py-3",children:e.jsx("h3",{className:"text-sm font-semibold text-[#111827]",children:t})}),i!=null&&i.length?e.jsx("div",{className:"divide-y divide-[#f2f4f7]",children:i.map(c=>e.jsxs("div",{className:"px-4 py-3 text-sm",children:[e.jsxs("div",{className:"flex flex-col gap-1 md:flex-row md:items-center md:justify-between",children:[e.jsx("div",{className:"font-medium text-[#111827] break-all",children:c[o]}),e.jsx("div",{className:"text-xs text-[#6b7280]",children:c.applied_at?ae(new Date(c.applied_at),{addSuffix:!0}):"—"})]}),e.jsxs("div",{className:"mt-1 text-xs text-[#6b7280] break-all",children:["Source: ",c.source_url||c.source_domain||"Unknown"]}),e.jsxs("div",{className:"mt-1 text-xs text-[#6b7280]",children:["Status: ",c.status||"active"]})]},c.id))}):e.jsx("div",{className:"px-4 py-8 text-sm text-[#8b95a7] text-center",children:"No records foun
1d."})]})}function Mt({data:t,resetting:i,onReset:o}){var c,b,f,x;return e.jsxs("div",{className:"space-y-4 bg-[#fafbfc] px-4 py-4",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-2 xl:grid-cols-4",children:[e.jsx(se,{label:"User",value:t.user.email,sub:t.user.full_name||"No name"}),e.jsx(se,{label:"Own code",value:t.user.affiliate_code||"—",sub:`Plan: ${t.user.effective_plan||"free"}${t.user.plan_source&&t.user.plan_source!=="free"?` · ${t.user.plan_source.replace("_"," ")}`:""}`}),e.jsx(se,{label:"Sent referrals",value:t.sent_referrals_count||0,sub:`Received: ${t.received_referrals_count||0}`}),e.jsx(se,{label:"Reward days",value:t.user.affiliate_reward_days_total||0,sub:t.user.affiliate_reward_tier?`Tier: ${t.user.affiliate_reward_tier}`:""})]}),e.jsxs("div",{className:"grid gap-4 lg:grid-cols-3",children:[e.jsxs("div",{className:"rounded-2xl border border-[#ebebeb] bg-white p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-[#111827]",children:[e.jsx(Ze,{className:"h-4 w-4"})," Applied on this user"]}),e.jsxs("div",{className:"mt-3 space-y-2 text-sm text-[#4b5563]",children:[e.jsxs("div",{children:["Used code: ",e.jsx("span",{className:"font-medium text-[#111827]",children:t.user.referred_by_code||"—"})]}),e.jsxs("div",{children:["Applied at: ",e.jsx("span",{className:"font-medium text-[#111827]",children:t.user.affiliate_referral_applied_at?new Date(t.user.affiliate_referral_applied_at).toLocaleString():"—"})]}),e.jsxs("div",{children:["Free until: ",e.jsx("span",{className:"font-medium text-[#111827]",children:t.user.affiliate_free_pro_until?new Date(t.user.affiliate_free_pro_until).toLocaleString():"—"})]}),e.jsxs("div",{children:["Effective plan: ",e.jsx("span",{className:"font-medium capitalize text-[#111827]",children:t.user.effective_plan||"free"})]})]})]}),e.jsxs("div",{className:"rounded-2xl border border-[#ebebeb] bg-white p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-[#111827]",children:[e.jsx(ye,{className:"h-4 w-4"})," Subscription"]}),e.jsxs("div",{className:"mt-3 space-y-2 text-sm text-[#4b5563]",children:[e.jsxs("div",{children:["Status: ",e.jsx("span",{className:"font-medium text-[#111827]",children:((c=t.subscription)==null?void 0:c.status)||"—"})]}),e.jsxs("div",{children:["Product: ",e.jsx("span",{className:"font-medium text-[#111827]",children:((b=t.subscription)==null?void 0:b.product_name)||"—"})]}),e.jsxs("div",{children:["Renews: ",e.jsx("span",{className:"font-medium text-[#111827]",children:(f=t.subscription)!=null&&f.current_period_end?new Date(t.subscription.current_period_end).toLocaleString():"—"})]})]})]}),e.jsxs("div",{className:"rounded-2xl border border-[#ebebeb] bg-white p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-[#111827]",children:[e.jsx(Le,{className:"h-4 w-4"})," Reset tools"]}),e.jsx("p",{className:"mt-3 text-sm text-[#6b7280]",children:"This removes the user’s affiliate-applied data and affiliate referral records so you can test again later."}),e.jsxs("button",{onClick:o,disabled:i,className:"mt-4 inline-flex items-center gap-2 rounded-2xl border border-red-200 bg-red-50 px-4 py-2.5 text-sm font-medium text-red-700 transition hover:bg-red-100 disabled:opacity-60",children:[e.jsx(Le,{className:"h-4 w-4"}),i?"Resetting…":"Reset affiliate data"]})]})]}),e.jsxs("div",{className:"rounded-2xl border border-[#ebebeb] bg-white p-5",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm font-semibold text-[#111827]",children:[e.jsx(et,{className:"h-4 w-4"})," Top external source URLs"]}),(x=t.top_sources)!=null&&x.length?e.jsx("div",{className:"mt-4 space-y-2",children:t.top_sources.map(l=>e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-xl border border-[#f1f5f9] px-3 py-2 text-sm",children:[e.jsx("div",{className:"min-w-0 flex-1 break-all text-[#4b5563]",children:l.source}),e.jsx("div",{className:"shrink-0 font-semibold text-[#111827]",children:l.count})]},l.source))}):e.jsx("div",{className:"mt-4 text-sm text-[#8b95a7]",children:"No external source URLs saved yet."})]}),e.jsxs("div",{className:"grid gap-4 xl:grid-cols-2",children:[e.jsx(Te,{title:"Referrals sent by this user",rows:t.sent_referrals||[],emailKey:"referred_user_email"}),e.jsx(Te,{title:"Referral used by this user",rows:t.received_referrals||[],emailKey:"referrer_email"})]})]})}function Tt(){const[t,i]=r.useState(""),[o,c]=r.useState([]),[b,f]=r.useState(!0),[x,l]=r.useState(!1),[u,p]=r.useState(!1),[g,v]=r.useState(""),[N,y]=r.useState(null),[T,D]=r.useState({}),h=async()=>{var k,S,L;f(!0);try{const R=await m.functions.invoke("getAffiliateAdminUserData",{});c(((k=R.data)==null?void 0:k.users)||[])}catch(R){v(((L=(S=R==null?void 0:R.response)==null?void 0:S.data)==null?void 0:L.error)||"Could not load users.")}finally{f(!1)}};r.useEffect(()=>{h()},[]);const d=async k=>{var L,R;const S=(k||t).trim().toLowerCase();if(S){l(!0),v("");try{const M=await m.functions.invoke("getAffiliateAdminUserData",{email:S});D($=>({...$,[S]:M.data})),y(S)}catch(M){v(((R=(L=M==null?void 0:M.response)==null?void 0:L.data)==null?void 0:R.error)||"Could not load this user.")}finally{l(!1)}}},n=async k=>{var L,R;const S=k||N;if(S&&window.confirm(`Remove affiliate data for ${S}?`)){p(!0),v("");try{await m.functions.invoke("resetAffiliateUserData",{email:S}),await Promise.all([d(S),h()])}catch(M){v(((R=(L=M==null?void 0:M.response)==null?void 0:L.data)==null?void 0:R.error)||"Could not reset this user.")}finally{p(!1)}}},j=o.filter(k=>{if(!t.trim())return!0;const S=t.trim().toLowerCase();return(k.email||"").toLowerCase().includes(S)||(k.full_name||"").toLowerCase().includes(S)});return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"rounded-[28px] border border-[#ebebeb] bg-white p-6 shadow-sm",children:[e.jsxs("div",{className:"flex flex-col gap-3 lg:flex-row lg:items-end lg:justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold text-[#111827]",children:"Affiliate user management"}),e.jsx("p",{className:"mt-1 text-sm text-[#6b7280]",children:"One row per user. Click a row to expand and see full affiliate details."})]}),e.jsxs("div",{className:"flex w-full max-w-xl gap-2",children:[e.jsx("input",{type:"text",value:t,onChange:k=>i(k.target.value),placeholder:"Search by email or name",className:"h-11 flex-1 rounded-2xl border border-[#d7dce4] bg-white px-4 text-sm text-[#111827] outline-none transition focus:border-[#111827]"}),e.jsxs("button",{onClick:()=>d(),disabled:x||!t.trim(),className:"inline-flex h-11 items-center gap-2 rounded-2xl bg-[#111827] px-4 text-sm font-medium text-white transition hover:bg-[#1f2937] disabled:opacity-60",children:[e.jsx(Z,{className:"h-4 w-4"}),x?"Loading…":"Open"]})]})]}),g?e.jsx("div",{className:"mt-3 text-sm text-red-600",children:g}):null]}),e.jsxs("div",{className:"rounded-[28px] border border-[#ebebeb] bg-white overflow-hidden shadow-sm",children:[e.jsxs("div",{className:"grid grid-cols-[minmax(0,2fr)_110px_110px_110px_40px] gap-3 border-b border-[#f2f4f7] px-4 py-3 text-xs font-semibold uppercase tracking-[0.16em] text-[#8b95a7]",children:[e.jsx("div",{children:"User"}),e.jsx("div",{children:"Plan"}),e.jsx("div",{children:"Referrals"}),e.jsx("div",{children:"Rewards"}),e.jsx("div",{})]}),b?e.jsx("div",{className:"px-4 py-10 text-center text-sm text-[#8b95a7]",children:"Loading users…"}):j.length?e.jsx("div",{className:"divide-y divide-[#f2f4f7]",children:j.map(k=>{const S=N===k.email,L=T[k.email];return e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>
1{if(S){y(null);return}d(k.email)},className:"grid w-full grid-cols-[minmax(0,2fr)_110px_110px_110px_40px] gap-3 px-4 py-4 text-left transition hover:bg-[#fafbfc]",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-medium text-[#111827] break-all",children:k.email}),e.jsxs("div",{className:"mt-1 text-xs text-[#6b7280] truncate",children:[k.full_name||"No name",k.affiliate_code?` · Code ${k.affiliate_code}`:""]})]}),e.jsx("div",{className:"text-sm text-[#4b5563] self-center capitalize",children:k.effective_plan||"free"}),e.jsx("div",{className:"text-sm text-[#4b5563] self-center",children:(L==null?void 0:L.sent_referrals_count)??"—"}),e.jsxs("div",{className:"text-sm text-[#4b5563] self-center",children:[k.affiliate_reward_days_total||0,"d"]}),e.jsx("div",{className:"flex items-center justify-end text-[#9aa4b2] self-center",children:S?e.jsx(Xe,{className:"h-4 w-4"}):e.jsx(we,{className:"h-4 w-4"})})]}),S&&L?e.jsx(Mt,{data:L,resetting:u,onReset:()=>n(k.email)}):null]},k.id)})}):e.jsx("div",{className:"px-4 py-10 text-center text-sm text-[#8b95a7]",children:"No users found."})]})]})}const Bt=new Date().toLocaleDateString("en-CA");function It(t){return(t==null?void 0:t.network_tools_usage_date)===Bt&&Number(t==null?void 0:t.network_tools_usage_count)||0}function $t(t){const i=ge(t);return i==="scale"?"Scale":i==="pro"?"Pro":"Free"}function Ft(t){const i=ge(t);return i==="scale"?he:i==="pro"?fe:pe}function qt(){const[t,i]=r.useState(""),[o,c]=r.useState(null),[b,f]=r.useState("single"),[x,l]=r.useState(""),[u,p]=r.useState(""),[g,v]=r.useState(null),[N,y]=r.useState(null),{data:T=[],isLoading:D,refetch:h}=I({queryKey:["admin-users-manager"],queryFn:()=>m.entities.User.list("-created_date",500)}),{data:d=[]}=I({queryKey:["admin-banned-users"],queryFn:()=>m.entities.BannedUser.list("-created_date",500)}),{data:n=[]}=I({queryKey:["admin-user-monitoring-jobs"],queryFn:()=>m.entities.MonitoringJob.list("-created_date",1e4)}),j=r.useMemo(()=>new Set(d.map(s=>s.user_email)),[d]),k=r.useMemo(()=>n.reduce((s,w)=>{const C=String(w.owner_email||"").toLowerCase();return C&&(s[C]||(s[C]=[]),s[C].push(w)),s},{}),[n]),S=r.useMemo(()=>{const s=t.trim().toLowerCase();return s?T.filter(w=>String((w==null?void 0:w.full_name)||"").toLowerCase().includes(s)||String((w==null?void 0:w.email)||"").toLowerCase().includes(s)):T},[T,t]),L=s=>{f("single"),c(s),l(""),p("")},R=()=>{f("all"),c({id:"all",email:"all-users"}),l(""),p("")},M=async()=>{if(!(!(o!=null&&o.id)||!x.trim()||!u.trim())){v(o.id);try{const s=await m.auth.me();if(b==="all"){const w=T.filter(C=>C==null?void 0:C.email);await Promise.all(w.map(C=>m.entities.UserMessage.create({user_email:C.email,subject:x.trim(),body:u.trim(),dismissed:!1,sent_by:(s==null?void 0:s.email)||"admin",sent_at:new Date().toISOString()}))),le.success(`In-app message sent to ${w.length} users.`)}else await m.entities.UserMessage.create({user_email:o.email,subject:x.trim(),body:u.trim(),dismissed:!1,sent_by:(s==null?void 0:s.email)||"admin",sent_at:new Date().toISOString()}),await m.integrations.Core.SendEmail({to:o.email,subject:x.trim(),body:`<div style="font-family:sans-serif;max-width:560px;margin:0 auto;padding:24px"><h2 style="margin:0 0 12px;color:#111827">${x.trim()}</h2><p style="margin:0;color:#4b5563;line-height:1.7;white-space:pre-wrap">${u.trim()}</p></div>`}),le.success("Message sent in app and by email.");c(null),l(""),p("")}catch(s){le.error((s==null?void 0:s.message)||"Message could not be saved in the app.")}finally{v(null)}}},$=async s=>{if(!confirm(`Ban ${s.email}?`))return;y(s.id);const w=await m.auth.me();await m.entities.BannedUser.create({user_email:s.email,reason:"Admin action",banned_by:(w==null?void 0:w.email)||"admin"}),y(null),h()},F=async s=>{confirm(`Delete ${s.email}? This cannot be undone.`)&&(y(s.id),await m.entities.User.delete(s.id),y(null),h())};return e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"overflow-hidden rounded-[28px] border border-[#e8edf3] bg-white shadow-sm",children:[e.jsx("div",{className:"border-b border-[#eef2f6] px-5 py-5 md:px-6",children:e.jsxs("div",{className:"flex flex-col gap-4 lg:flex-row lg:items-center lg:justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-semibold tracking-tight text-[#111827]",children:"Users"}),e.jsx("p",{className:"mt-1 text-sm text-[#6b7280]",children:"See plans, credits, signup IP, and contact or moderate users."})]}),e.jsxs("div",{className:"flex w-full flex-col gap-3 lg:w-auto lg:flex-row lg:items-center",children:[e.jsxs("button",{onClick:R,className:"inline-flex items-center justify-center gap-2 rounded-2xl border border-[#dbe4ff] bg-[#eef2ff] px-4 py-3 text-sm font-medium text-[#3730a3] hover:bg-[#e0e7ff]",children:[e.jsx(ye,{className:"h-4 w-4"}),"Message all in app"]}),e.jsxs("div",{className:"relative w-full lg:w-[320px]",children:[e.jsx(Z,{className:"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-[#9aa4b2]"}),e.jsx("input",{type:"text",value:t,onChange:s=>i(s.target.value),placeholder:"Search by name or email",className:"w-full rounded-2xl border border-[#e3e8ef] bg-[#f8fafc] py-3 pl-10 pr-4 text-sm text-[#111827] placeholder:text-[#9aa4b2] focus:border-[#cbd5e1] focus:bg-white focus:outline-none"})]})]})]})}),D?e.jsx("div",{className:"px-6 py-10 text-sm text-[#6b7280]",children:"Loading users..."}):e.jsx("div",{className:"grid gap-3 bg-[#f8fafc] p-3 md:p-4",children:S.map(s=>{const w=It(s),C=Ft(s),A=(s==null?void 0:s.signup_ip)||(s==null?void 0:s.last_signup_ip)||"—",E=j.has(s.email),B=k[String(s.email||"").toLowerCase()]||[];return e.jsxs("div",{className:"rounded-[24px] border border-[#e6ebf2] bg-white p-4 shadow-sm md:p-5",children:[e.jsxs("div",{className:"flex flex-col gap-4 lg:flex-row lg:items-start lg:justify-between",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-lg font-semibold tracking-tight text-[#111827]",children:s.full_name||s.email}),e.jsx("div",{className:"mt-1 text-sm text-[#6b7280]",children:s.email}),e.jsxs("div",{className:"mt-3 flex flex-wrap gap-2",children:[e.jsx("span",{className:"rounded-full bg-[#f3f4f6] px-2.5 py-1 text-xs font-medium text-[#4b5563]",children:$t(s)}),s.role==="admin"&&e.jsx("span",{className:"rounded-full bg-[#eef2ff] px-2.5 py-1 text-xs font-medium text-[#4f46e5]",children:"Admin"}),E&&e.jsx("span",{className:"rounded-full bg-red-50 px-2.5 py-1 text-xs font-medium text-red-700",children:"Banned"})]})]}),e.jsxs("div",{className:"grid gap-2 sm:grid-cols-3 lg:min-w-[420px]",children:[e.jsxs("div",{className:"rounded-2xl bg-[#f8fafc] px-3 py-2",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wide text-[#8a94a6]",children:"Credits used"}),e.jsxs("div",{className:"mt-1 text-sm font-semibold text-[#111827]",children:[w," / ",C]})]}),e.jsxs("div",{className:"rounded-2xl bg-[#f8fafc] px-3 py-2",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wide text-[#8a94a6]",children:"Signup IP"}),e.jsx("div",{className:"mt-1 text-sm font-semibold text-[#111827] break-all",children:A})]}),e.jsxs("div",{className:"rounded-2xl bg-[#f8fafc] px-3 py-2",children:[e.jsx("div",{className:"text-[11px] uppercase tracking-wide text-[#8a94a6]",children:"Joined"}),e.jsx("div",{className:"mt-1 text-sm font-semibold text-[#111827]",children:new Date(s.created_date).toLocaleDateString()})]})]})]}),e.jsxs("div",{className:"mt-4 rounded-2xl border border-[#eef2f6] bg-[#f8fafc] px-3 py-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-[11px] font-semibold uppercase tracking-wide text-[#8a94a6]",children:[e.jsx($e,{className:"h-3.5 w-3.5"}),"Monitored websites (",B.length,")"]}),B.length?e.jsx("div",{className:"mt-2 flex flex-wrap gap-2",children:B.map(q=>e.jsx("span",{className:"rounded-full border border-[#e2e8f0] bg-white px-2.5 py-1 text-xs font-medium text-[#475569]",children:q.domain},q.id))}):e.jsx("div",{className:"mt-2 text-sm text-[#94a3b8]",children:"No monitored websites."})]}),e.jsxs("div",{className:"mt-4 flex flex-wrap gap-2",children:[e.jsxs("button",{onClick:()=>L(s),className:"inline-flex items-center gap-2 rounded-xl border border-[#dbe4ff] bg-[#eef2ff] px-3 py-2 text-sm font-medium text-[#3730a3] hover:bg-[#e0e7ff]",children:[e.jsx(tt,{className:"h-4 w-4"}),"Contact"]}),!E&&e.jsxs("button",{onClick:()=>$(s),disabled:N===s.id,className:"inline-flex items-center gap-2 rounded-xl border border-amber-200 bg-amber-50 px-3 py-2 text-sm font-medium text-amber-700 hover:bg-amber-100 disabled:opacity-60",children:[e.jsx(st,{className:"h-4 w-4"}),"Ban"]}),e.jsxs("button",{onClick:()=>F(s),disabled:N===s.id,className:"inline-flex items-center gap-2 rounded-xl border border-red-200 bg-red-50 px-3 py-2 text-sm font-medium text-red-700 hover:bg-red-100 disabled:opacity-60",children:[e.jsx(J,{className:"h-4 w-4"}),"Delete"]})]})]},s.id)})})]}),o&&e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/40 p-4",children:e.jsxs("div",{className:"w-full max-w-xl rounded-[28px] bg-white p-6 shadow-2xl",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-xl font-semibold text-[#111827]",children:b==="all"?"Message all users":`Contact ${o.full_name||o.email}`}),e.jsx("p",{className:"mt-1 text-sm text-[#6b7280]",children:b==="all"?"This creates an in-app banner for every user without sending email.":"This sends an email and shows a dismissible banner above their dashboard pages."})]}),e.jsx("button",{onClick:()=>c(null),className:"rounded-xl border border-[#e5e7eb] px-3 py-2 text-sm text-[#4b5563] hover:bg-[#f8fafc]",children:"Close"})]}),e.jsxs("div",{className:"mt-5 space-y-4",children:[e.jsx("input",{value:x,onChange:s=>l(s.target.value),placeholder:"Subject",className:"w-full rounded-2xl border border-[#dde3ea] bg-white px-4 py-3 text-sm text-[#111827] focu
1s:border-[#cbd5e1] focus:outline-none"}),e.jsx("textarea",{value:u,onChange:s=>p(s.target.value),placeholder:"Write your message",rows:6,className:"w-full rounded-2xl border border-[#dde3ea] bg-white px-4 py-3 text-sm text-[#111827] focus:border-[#cbd5e1] focus:outline-none resize-none"}),e.jsx("div",{className:"flex justify-end",children:e.jsxs("button",{onClick:M,disabled:g===o.id||!x.trim()||!u.trim(),className:"inline-flex items-center gap-2 rounded-2xl bg-[#111827] px-4 py-3 text-sm font-semibold text-white hover:bg-[#1f2937] disabled:opacity-50",children:[e.jsx(at,{className:"h-4 w-4"}),g===o.id?"Sending...":b==="all"?"Send to all users":"Send message"]})})]})]})})]})}function Ot(){const[t,i]=r.useState(10),[o,c]=r.useState(!1),[b,f]=r.useState(!1),[x,l]=r.useState(""),[u,p]=r.useState(null),{data:g=[],refetch:v}=I({queryKey:["search-discovery-runs"],queryFn:()=>m.entities.SearchDiscoveryRun.list("-started_at",20)}),N=async()=>{var y,T;c(!0),f(!1),l("");try{await m.functions.invoke("runSearchLogger",{count:t}),await v(),f(!0)}catch(D){l(((T=(y=D==null?void 0:D.response)==null?void 0:y.data)==null?void 0:T.error)||(D==null?void 0:D.message)||"The task could not be started.")}finally{c(!1)}};return e.jsxs("div",{className:"bg-white border border-[#ebebeb] rounded-[28px] p-5 space-y-4 shadow-[0_18px_50px_rgba(15,23,42,0.05)]",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl bg-[#f3f4f6] flex items-center justify-center shrink-0",children:e.jsx(Z,{className:"w-5 h-5 text-[#555]"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-[#1a1a1a]",children:"Manual site discovery"}),e.jsx("p",{className:"text-xs text-[#888] mt-1",children:"Only runs when you click. Each run creates new real site pages for popular domains that have not been added before."})]})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3 sm:items-end",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-[#888] mb-1",children:"How many new sites to create"}),e.jsx("input",{type:"number",min:"1",max:"25",value:t,onChange:y=>i(Number(y.target.value||1)),className:"w-full sm:w-40 border border-[#e0e0e0] rounded-xl px-3 py-2 text-sm focus:outline-none focus:border-[#999]"})]}),e.jsxs("button",{onClick:N,disabled:o,className:"inline-flex items-center justify-center gap-2 px-4 py-2 text-sm font-medium bg-[#1a1a1a] text-white rounded-xl hover:bg-[#333] disabled:opacity-50",children:[o?e.jsx(nt,{className:"w-4 h-4 animate-spin"}):e.jsx(it,{className:"w-4 h-4"}),o?"Running…":"Run task"]})]}),b&&e.jsx("p",{className:"text-xs text-green-700 bg-green-50 border border-green-100 rounded-xl px-3 py-2",children:"The manual discovery run completed successfully."}),x&&e.jsx("p",{className:"text-xs text-red-700 bg-red-50 border border-red-100 rounded-xl px-3 py-2",children:x}),e.jsxs("div",{className:"border border-[#ebebeb] rounded-2xl overflow-hidden",children:[e.jsx("div",{className:"px-4 py-3 bg-[#fafafa] border-b border-[#ebebeb]",children:e.jsx("h4",{className:"text-xs font-semibold text-[#1a1a1a] uppercase tracking-widest",children:"Recent runs"})}),g.length===0?e.jsx("div",{className:"px-4 py-4 text-sm text-[#999]",children:"No runs yet."}):e.jsx("div",{className:"divide-y divide-[#f3f4f6]",children:g.map(y=>{const T=u===y.id;return e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>p(T?null:y.id),className:"w-full px-4 py-3 text-left flex items-center gap-3 hover:bg-[#fafafa] transition-colors",children:[T?e.jsx(we,{className:"w-4 h-4 text-[#999]"}):e.jsx(lt,{className:"w-4 h-4 text-[#999]"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"text-sm font-medium text-[#1a1a1a]",children:[y.created_count||0," new sites created"]}),e.jsx("div",{className:"text-xs text-[#999]",children:y.started_at?ae(new Date(y.started_at),{addSuffix:!0}):"—"})]}),e.jsx("div",{className:"text-xs text-[#777] shrink-0",children:y.status})]}),T&&e.jsx("div",{className:"px-4 pb-4 space-y-2",children:(y.created_slugs||[]).length>0?(y.created_slugs||[]).map(D=>e.jsxs("a",{href:`/${D}`,target:"_blank",rel:"noopener noreferrer",className:"flex items-center justify-between rounded-xl border border-[#ebebeb] px-3 py-2 text-sm text-[#333] hover:bg-[#fafafa]",children:[e.jsxs("span",{children:["/",D,"/"]}),e.jsx(Ne,{className:"w-4 h-4 text-[#999]"})]},D)):e.jsx("div",{className:"text-sm text-[#999]",children:"This run did not create any new site pages."})})]},y.id)})})]})]})}function Wt(t){const i=`${(t==null?void 0:t.content)||""} ${(t==null?void 0:t.featured_image_url)||""} ${(t==null?void 0:t.og_image)||""}`,o=(i.match(/!\[[^\]]*\]\([^\)]+\)/g)||[]).length,c=(i.match(/<img\s/gi)||[]).length,b=(i.match(/\.webp/gi)||[]).length;return Math.max(o+c,b,t!=null&&t.featured_image_url?1:0)}function zt(){const t=je(),{data:i,isLoading:o,refetch:c,isFetching:b}=I({queryKey:["seo-blog-posts-panel"],queryFn:async()=>{const[l,u]=await Promise.all([m.entities.BlogPost.list("-created_date",200),m.entities.BlogTopic.list("name",200)]);return{posts:l||[],topics:u||[]}},initialData:{posts:[],topics:[]}}),f=r.useMemo(()=>
1Object.fromEntries((i.topics||[]).map(l=>[l.id,l.name])),[i.topics]),x=async l=>{window.confirm(`Delete blog post "${l.title}"?`)&&(await m.entities.BlogPost.delete(l.id),await t.invalidateQueries({queryKey:["seo-blog-posts-panel"]}))};return e.jsxs("div",{className:"bg-white border border-[#ebebeb] rounded-[28px] p-6 mt-6 shadow-[0_18px_50px_rgba(15,23,42,0.05)]",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4 mb-5",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold text-[#1a1a1a]",children:"Blog posts"}),e.jsx("p",{className:"text-sm text-[#888] mt-1",children:"See every post created by the blog flow, review drafts before publishing, check image count, and delete posts when needed."})]}),e.jsxs("button",{onClick:()=>c(),disabled:b,className:"flex items-center gap-2 px-4 py-2 text-sm text-[#555] border border-[#e0e0e0] rounded-xl hover:bg-[#f5f5f5] transition-colors disabled:opacity-50",children:[e.jsx(X,{className:`w-4 h-4 ${b?"animate-spin":""}`}),"Refresh"]})]}),o?e.jsx("div",{className:"text-sm text-[#888]",children:"Loading blog posts..."}):i.posts.length===0?e.jsx("div",{className:"text-sm text-[#888]",children:"No blog posts yet."}):e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full min-w-[900px] text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-left text-[#888] border-b border-[#f0f0f0]",children:[e.jsx("th",{className:"py-3 pr-4 font-medium",children:"Title"}),e.jsx("th",{className:"py-3 pr-4 font-medium",children:"Topic"}),e.jsx("th",{className:"py-3 pr-4 font-medium",children:"Status"}),e.jsx("th",{className:"py-3 pr-4 font-medium",children:"Scheduled"}),e.jsx("th",{className:"py-3 pr-4 font-medium",children:"Published"}),e.jsx("th",{className:"py-3 pr-4 font-medium",children:"Images"}),e.jsx("th",{className:"py-3 pr-4 font-medium",children:"Slug"}),e.jsx("th",{className:"py-3 font-medium text-right",children:"Action"})]})}),e.jsx("tbody",{children:i.posts.map(l=>e.jsxs("tr",{className:"border-b border-[#f7f7f7] align-top",children:[e.jsxs("td",{className:"py-4 pr-4",children:[e.jsx("div",{className:"font-medium text-[#1a1a1a] max-w-[280px]",children:l.title}),e.jsxs("div",{className:"text-xs text-[#999] mt-1",children:["Created ",l.created_date?re(new Date(l.created_date),"yyyy-MM-dd HH:mm"):"-"]})]}),e.jsx("td",{className:"py-4 pr-4 text-[#555]",children:f[l.topic_id]||"-"}),e.jsx("td",{className:"py-4 pr-4",children:e.jsx("span",{className:`inline-flex rounded-full px-2.5 py-1 text-xs font-medium ${l.is_published?"bg-green-100 text-green-700":"bg-blue-100 text-blue-700"}`,children:l.is_published?"Published":"Ready for review"})}),e.jsx("td",{className:"py-4 pr-4 text-[#555]",children:l.publish_date?re(new Date(l.publish_date),"yyyy-MM-dd HH:mm"):"-"}),e.jsx("td",{className:"py-4 pr-4 text-[#555]",children:l.is_published&&l.publish_date?re(new Date(l.publish_date),"yyyy-MM-dd HH:mm"):"-"}),e.jsx("td",{className:"py-4 pr-4 text-[#555]",children:Wt(l)}),e.jsxs("td",{className:"py-4 pr-4 text-[#777]",children:["/",l.slug||"-","/"]}),e.jsx("td",{className:"py-4 text-right",children:e.jsxs("div",{className:"flex justify-end gap-2 flex-wrap",children:[l.slug&&e.jsxs("a",{href:l.is_published?`/blog/${l.slug}`:`/blog/${l.slug}?draft=1`,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 px-3 py-2 text-sm text-[#555] border border-[#e0e0e0] rounded-xl hover:bg-[#f5f5f5] transition-colors",children:[e.jsx(Fe,{className:"w-4 h-4"}),l.is_published?"Open post":"Open draft"]}),l.is_published&&l.slug&&e.jsxs("a",{href:`/blog/${l.slug}`,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 px-3 py-2 text-sm text-blue-600 border border-blue-200 rounded-xl hover:bg-blue-50 transition-colors",children:[e.jsx(Ne,{className:"w-4 h-4"}),"Public post"]}),e.jsxs("button",{onClick:()=>x(l),className:"inline-flex items-center gap-2 px-3 py-2 text-sm text-red-600 border border-red-200 rounded-xl hover:bg-red-50 transition-colors",children:[e.jsx(J,{className:"w-4 h-4"}),"Delete"]})]})})]},l.id))})]})})]})}const oe="blog_post_generator",ce="blog_image_generator",xe="blog_publisher";function Kt(){const[t,i]=r.useState([]),[o,c]=r.useState([]),[b,f]=r.useState([]),[x,l]=r.useState(!0),u=async()=>
1{l(!0);const[g,v,N]=await Promise.all([m.agents.listConversations({agent_name:oe}),m.agents.listConversations({agent_name:ce}),m.agents.listConversations({agent_name:xe})]);i(g||[]),c(v||[]),f(N||[]),l(!1)};r.useEffect(()=>{u()},[]);const p=async(g,v,N)=>{const y=await m.agents.createConversation({agent_name:g,metadata:{name:v,description:N}});y!=null&&y.id&&window.open(`/admin/agent/${y.id}/`,"_blank"),u()};return e.jsxs("div",{className:"bg-white border border-[#ebebeb] rounded-[28px] p-5 space-y-5 shadow-[0_18px_50px_rgba(15,23,42,0.05)]",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold text-[#1a1a1a]",children:"Blog agents"}),e.jsx("p",{className:"text-sm text-[#888] mt-1",children:"Create and open sessions for the writer, image, and publisher agents."})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(Y,{variant:"outline",onClick:()=>p(oe,"Blog writer session","SEO blog writing workspace"),children:"New writer session"}),e.jsx(Y,{variant:"outline",onClick:()=>p(ce,"Blog image session","Realistic blog image planning workspace"),children:"New image session"}),e.jsx(Y,{onClick:()=>p(xe,"Blog publisher session","Final publish validation workspace"),children:"New publisher session"})]})]}),e.jsx("div",{className:"grid gap-3 md:grid-cols-3",children:[{label:"Writer agent",name:oe,description:"Creates the blog article"},{label:"Image agent",name:ce,description:"Prepares realistic image prompts"},{label:"Publisher agent",name:xe,description:"Validates and publishes the post"}].map(g=>e.jsxs("div",{className:"rounded-xl border border-[#f0f0f0] bg-[#fafafa] p-4 text-sm text-[#555]",children:[e.jsx("div",{className:"font-medium text-[#1a1a1a]",children:g.label}),e.jsx("div",{className:"mt-1 break-all",children:g.name}),e.jsx("div",{className:"mt-2 text-xs text-[#888]",children:g.description})]},g.name))}),e.jsx("div",{className:"grid gap-4 md:grid-cols-3",children:[{title:"Writer sessions",items:t},{title:"Image sessions",items:o},{title:"Publisher sessions",items:b}].map(g=>e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-[#1a1a1a] mb-3",children:g.title}),x?e.jsx("div",{className:"text-sm text-[#888]",children:"Loading sessions..."}):g.items.length===0?e.jsx("div",{className:"text-sm text-[#888]",children:"No sessions yet."}):e.jsx("div",{className:"space-y-2",children:g.items.slice(0,6).map(v=>{var N,y;return e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-xl border border-[#efefef] p-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-[#1a1a1a] truncate",children:((N=v.metadata)==null?void 0:N.name)||"Untitled session"}),e.jsx("div",{className:"text-xs text-[#888] truncate",children:((y=v.metadata)==null?void 0:y.description)||v.id})]}),e.jsx(Y,{variant:"outline",onClick:()=>window.open(`/admin/agent/${v.id}/`,"_blank"),children:"Open"})]},v.id)})})]},g.title))})]})}const Gt="blog_post_generator",Ht="blog_image_generator",Vt="blog_publisher";function Qt(){const[t,i]=r.useState([]),[o,c]=r.useState(!0),b=async()=>{c(!0);const x=await m.entities.BlogPipelineRun.list("-created_date",10);i(x||[]),c(!1)};r.useEffect(()=>{b()},[]);const f=async()=>{await m.functions.invoke("runDailyBlogPipeline",{}),b()};return e.jsxs("div",{className:"bg-white border border-[#ebebeb] rounded-[28px] p-5 space-y-5 shadow-[0_18px_50px_rgba(15,23,42,0.05)]",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-lg font-semibold text-[#1a1a1a]",children:"Daily blog automation pipeline"}),e.jsx("p",{className:"text-sm text-[#888] mt-1",children:"Writer → image generator → publisher, then publish live on /blog/."})]}),e.jsx(Y,{onClick:f,children:"Queue run now"})]}),e.jsxs("div",{className:"grid gap-3 md:grid-cols-3",children:[e.jsxs("div",{className:"rounded-xl border border-[#f0f0f0] bg-[#fafafa] p-4 text-sm text-[#555]",children:[e.jsx("div",{className:"font-medium text-[#1a1a1a]",children:"1. Writer"}),e.jsx("div",{className:"mt-1",children:Gt})]}),e.jsxs("div",{className:"rounded-xl border border-[#f0f0f0] bg-[#fafafa] p-4 text-sm text-[#555]",children:[e.jsx("div",{className:"font-medium text-[#1a1a1a]",children:"2. Image agent"}),e.jsx("div",{className:"mt-1",children:Ht})]}),e.jsxs("div",{className:"rounded-xl border border-[#f0f0f0] bg-[#fafafa] p-4 text-sm text-[#555]",children:[e.jsx("div",{className:"font-medium text-[#1a1a1a]",children:"3. Publisher"}),e.jsx("div",{className:"mt-1",children:Vt})]})]}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-sm font-semibold text-[#1a1a1a] mb-3",children:"Recent pipeline runs"}),o?e.jsx("div",{className:"text-sm text-[#888]",children:"Loading runs..."}):t.length===0?e.jsx("div",{className:"text-sm text-[#888]",children:"No runs yet."}):e.jsx("div",{className:"space-y-2",children:t.map(x=>e.jsxs("div",{className:"rounded-xl border border-[#efefef] p-3 flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-sm font-medium text-[#1a1a1a] capitalize",children:x.status}),e.jsx("div",{className:"text-xs text-[#888] truncate",children:x.topic||x.draft_title||x.id})]}),e.jsx("div",{className:"text-xs text-[#999]",children:x.created_date?new Date(x.created_date).toLocaleStr
1ing():""})]},x.id))})]})]})}function Jt({adminUser:t}){const i=r.useRef({}),o=r.useRef({}),c=je(),[b,f]=r.useState({}),[x,l]=r.useState({}),[u,p]=r.useState(null),[g,v]=r.useState(null),{data:N=[]}=I({queryKey:["content-suggestions-admin"],queryFn:()=>m.entities.SuggestedContentEdit.list("-created_date",500)}),y=r.useMemo(()=>N.filter(s=>s.status==="pending"),[N]),T=r.useMemo(()=>N.filter(s=>s.status!=="pending"),[N]),D=()=>c.invalidateQueries({queryKey:["content-suggestions-admin"]}),h=s=>x[s.id]??s.suggested_content??"",d=s=>{const w=i.current[s],C=window.getSelection();if(!w||!C||C.rangeCount===0)return;const A=C.getRangeAt(0);w.contains(A.commonAncestorContainer)&&(o.current[s]=A.cloneRange())},n=s=>{const w=o.current[s],C=window.getSelection();return!w||!C?null:(C.removeAllRanges(),C.addRange(w),w)},j=s=>{const w=i.current[s];w&&l(C=>({...C,[s]:w.innerHTML}))},k=(s,w)=>{const C=i.current[s];C&&(C.focus(),n(s),document.execCommand(w,!1),d(s),j(s))},S=s=>{const w=i.current[s];if(!w)return;const C=window.prompt("Enter link URL");if(!C)return;const A=C.trim(),E=/^(\/|https?:\/\/(www\.)?sitealive\.io(?=\/|$))/i.test(A);w.focus();const B=n(s);if(!B||B.collapsed)return;const q=document.createElement("a");q.href=A,E||(q.target="_blank",q.rel="noopener noreferrer"),q.textContent=B.toString(),B.deleteContents(),B.insertNode(q);const G=document.createRange();G.setStartAfter(q),G.collapse(!0);const W=window.getSelection();W&&(W.removeAllRanges(),W.addRange(G)),o.current[s]=G.cloneRange(),j(s)},L=async s=>{const w=h(s).trim(),C=new Date().toISOString();p(s.id),await m.entities.Site.update(s.site_id,{description:w,description_locked:!0});const A=N.filter(E=>E.site_id===s.site_id&&E.status==="approved"&&E.id!==s.id);await Promise.all(A.map(E=>m.entities.SuggestedContentEdit.update(E.id,{status:"rejected",approved_by_user_id:t.id,approval_date:C,notes:E.notes||"Replaced by a newer approved suggestion."}))),await m.entities.SuggestedContentEdit.update(s.id,{suggested_content:w,status:"approved",approved_by_user_id:t.id,approval_date:C,notes:b[s.id]||""}),p(null),D()},R=async s=>{const w=h(s).trim();p(s.id),await m.entities.SuggestedContentEdit.update(s.id,{suggested_content:w,status:"rejected",approved_by_user_id:t.id,approval_date:new Date().toISOString(),notes:b[s.id]||""}),p(null),D()},M=async s=>{const w=h(s).trim();p(s.id),await m.entities.SuggestedContentEdit.update(s.id,{suggested_content:w,notes:b[s.id]||""}),s.status==="approved"&&await m.entities.Site.update(s.site_id,{description:w,description_locked:!0}),p(null),D()},$=async s=>{p(s.id),await m.entities.SuggestedContentEdit.delete(s.id),p(null),D()},F=(s,w)=>{const C=!w&&g!==s.id;return e.jsxs("div",{className:"rounded-[28px] border border-white/70 bg-white/95 p-6 shadow-[0_18px_50px_rgba(15,23,42,0.06)]",children:[e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold text-[#111827]",children:s.site_display_name}),e.jsxs("p",{className:"text-sm text-[#6b7280]",children:["/",s.site_slug,"/ · ",s.suggested_by_user_email]})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"inline-flex w-fit rounded-full border border-[#e5e7eb] bg-[#f8fafc] px-3 py-1 text-xs font-semibold capitalize text-[#475569]",children:s.status}),w?null:e.jsxs("button",{type:"button",onClick:()=>v(A=>A===s.id?null:s.id),className:"inline-flex items-center gap-2 rounded-2xl border border-[#dbe1ea] px-3 py-2 text-xs font-medium text-[#475569] hover:bg-[#f8fafc]",children:[C?"Expand":"Collapse",e.jsx(we,{className:`h-4 w-4 transition-transform ${C?"":"rotate-180"}`})]})]})]}),C?null:e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"mt-4 grid gap-4 lg:grid-cols-2",children:[e.jsxs("div",{className:"rounded-2xl border border-[#e5e7eb] bg-[#f8fafc] p-4",children:[e.jsx("div",{className:"mb-2 text-xs font-semibold uppercase tracking-[0.18em] text-[#64748b]",children:"Current live text"}),e.jsx("p",{className:"text-sm leading-7 text-[#475569]",children:s.original_content})]}),e.jsxs("div",{className:"rounded-2xl border border-[#dbeafe] bg-[#eff6ff] p-4",children:[e.jsx("div",{className:"mb-2 text-xs font-semibold uppercase tracking-[0.18em] text-[#2563eb]",children:"Suggested text"}),e.jsxs("div",{className:"overflow-hidden rounded-2xl border border-[#bfdbfe] bg-white text-[#1e3a8a]",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-b border-[#dbeafe] bg-[#f8fbff] px-3 py-2",children:[e.jsx("button",{type:"button",onMouseDown:A=>A.preventDefault(),onClick:()=>k(s.id,"bold"),className:"inline-flex h-9 w-9 items-center justify-center rounded-xl border border-[#dbeafe] bg-white text-[#1e3a8a] hover:bg-[#eff6ff]",children:e.jsx(rt,{className:"h-4 w-4"})}),e.jsx("button",{type:"button",onMouseDown:A=>A.preventDefault(),onClick:()=>S(s.id),className:"inline-flex h-9 w-9 items-center justify-center rounded-xl border border-[#dbeafe] bg-white text-[#1e3a8a] hover:bg-[#eff6ff]",children:e.jsx(dt,{className:"h-4 w-4"})})]}),e.jsx("div",{ref:A=>{A&&(i.current[s.id]=A)},contentEditable:!0,suppressContentEditableWarning:!0,onMouseUp:()=>
1d(s.id),onKeyUp:()=>d(s.id),onBlur:()=>d(s.id),onInput:()=>j(s.id),dangerouslySetInnerHTML:{__html:h(s)},className:"min-h-[320px] w-full px-4 py-3 text-sm leading-7 text-[#1e3a8a] focus:outline-none [&_a]:font-medium [&_a]:text-[#2563eb] [&_a]:underline [&_a]:decoration-[#2563eb] [&_a]:underline-offset-4"})]})]})]}),e.jsxs("div",{className:"mt-4",children:[e.jsx("label",{className:"mb-2 block text-xs font-semibold uppercase tracking-[0.18em] text-[#64748b]",children:"Admin note"}),e.jsx("textarea",{value:b[s.id]??s.notes??"",onChange:A=>f(E=>({...E,[s.id]:A.target.value})),rows:3,className:"w-full rounded-2xl border border-[#dbe1ea] px-4 py-3 text-sm text-[#111827] focus:outline-none focus:border-[#111827]"})]}),e.jsxs("div",{className:"mt-4 flex flex-wrap items-center justify-end gap-3",children:[w?null:e.jsx("button",{onClick:()=>$(s),disabled:u===s.id,className:"rounded-2xl border border-red-200 px-4 py-2.5 text-sm font-medium text-red-600 hover:bg-red-50 disabled:opacity-50",children:"Delete"}),e.jsx("button",{onClick:()=>M(s),disabled:u===s.id,className:"rounded-2xl border border-[#dbe1ea] px-4 py-2.5 text-sm font-medium text-[#475569] hover:bg-[#f8fafc] disabled:opacity-50",children:u===s.id?"Saving…":"Save changes"}),w?e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:()=>R(s),disabled:u===s.id,className:"rounded-2xl border border-red-200 px-4 py-2.5 text-sm font-medium text-red-600 hover:bg-red-50 disabled:opacity-50",children:"Reject"}),e.jsx("button",{onClick:()=>L(s),disabled:u===s.id||!h(s).trim(),className:"rounded-2xl bg-[#111827] px-4 py-2.5 text-sm font-medium text-white hover:bg-[#1f2937] disabled:opacity-50",children:u===s.id?"Saving…":"Approve and publish"})]}):null]})]})]},s.id)};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-semibold text-[#111827]",children:"Content review"}),e.jsx("p",{className:"mt-1 text-sm text-[#6b7280]",children:"Review user-submitted edits for the website overview section before they go live."})]}),e.jsx("div",{className:"space-y-4",children:y.length?y.map(s=>F(s,!0)):e.jsx("div",{className:"rounded-[28px] border border-white/70 bg-white/90 p-6 text-sm text-[#6b7280] shadow-[0_18px_50px_rgba(15,23,42,0.07)]",children:"No pending content edits right now."})}),T.length?e.jsxs("div",{className:"space-y-4",children:[e.jsx("h3",{className:"text-lg font-semibold text-[#111827]",children:"Reviewed"}),T.map(s=>F(s,!1))]}):null]})}function Yt(){const[t,i]=r.useState(!1),[o,c]=r.useState(null),[b,f]=r.useState("");r.useEffect(()=>{try{const l=sessionStorage.getItem("legacySlugRepairSummary");l&&c(JSON.parse(l))}catch{}},[]);const x=async()=>{var l,u;i(!0),f(""),c(null);try{const p=await m.functions.invoke("repairLegacySiteSlugs",{limit:50});c(p.data),sessionStorage.setItem("legacySlugRepairSummary",JSON.stringify(p.data))}catch(p){f(((u=(l=p==null?void 0:p.response)==null?void 0:l.data)==null?void 0:u.error)||(p==null?void 0:p.message)||"Could not repair old slug pages.")}finally{i(!1)}};return e.jsxs("div",{className:"rounded-[28px] border border-white/70 bg-white/95 p-6 shadow-[0_18px_50px_rgba(15,23,42,0.06)]",children:[e.jsxs("div",{className:"flex flex-col gap-4 lg:flex-row lg:items-center lg:justify-between",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"inline-flex items-center gap-2 rounded-full bg-[#eef2ff] px-3 py-1 text-xs font-semibold text-[#4338ca]",children:[e.jsx(ot,{className:"h-3.5 w-3.5"}),"Legacy slug repair"]}),e.jsx("h3",{className:"mt-4 text-xl font-semibold text-[#111827]",children:"Reconnect old slug pages to their real domains"}),e.jsx("p",{className:"mt-2 max-w-3xl text-sm leading-relaxed text-[#6b7280]",children:"This repairs old pages like /xfinity/ in smaller batches, so it is less likely to time out and the latest result stays visible even if the page refreshes."})]}),e.jsxs("button",{onClick:x,disabled:t,className:"inline-flex items-center justify-center gap-2 rounded-2xl bg-[#111827] px-5 py-3 text-sm font-medium text-white transition-colors hover:bg-[#1f2937] disabled:opacity-50",children:[e.jsx(X,{className:`h-4 w-4 ${t?"animate-spin":""}`}),t?"Repairing…":"Run repair"]})]}),b?e.jsx("div",{className:"mt-5 rounded-2xl border border-red-200 bg-red-50 px-4 py-3 text-sm text-red-700",children:b}):null,o?e.jsxs("div",{className:"mt-5 space-y-4",children:[e.jsxs("div",{className:"grid gap-3 sm:grid-cols-3",children:[e.jsxs("div",{className:"rounded-2xl border border-[#e5e7eb] bg-[#f8fafc] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[#94a3b8]",children:"Legacy pages found"}),e.jsx("div",{className:"mt-2 text-2xl font-bold text-[#111827]",children:o.legacy_count||0})]}),e.jsxs("div",{className:"rounded-2xl border border-[#dcfce7] bg-[#f0fdf4] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[#86efac]",children:"Updated"}),e.jsx("div",{className:"mt-2 text-2xl font-bold text-[#166534]",children:o.updated_count||0})]}),e.jsxs("div",{className:"rounded-2xl border border-[#e5e7eb] bg-[#f8fafc] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[#94a3b8]",children:"Processed now"}),e.jsx("div",{className:"mt-2 text-2xl font-bold text-[#111827]",children:o.processed_count||0})]}),e.jsxs("div",{className:"rounded-2xl border border-[#fef3c7] bg-[#fffbeb] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[#d97706]",children:"Remaining"}),e.jsx("div",{className:"mt-2 text-2xl font-bold text-[#92400e]",children:o.remaining_count||0})]}),e.jsxs("div",{className:"rounded-2xl border border-[#e5e7eb] bg-[#f8fafc] px-4 py-4",children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.18em] text-[#94a3b8]",children:"Total scanned"}),e.jsx("div",{className:"mt-2 text-2xl font-bold text-[#111827]",children:o.total_sites||0})]})]}),o.remaining_count>0?e.jsx("div",{className:"rounded-2xl border border-[#dbeafe] bg-[#eff6ff] px-4 py-3 text-sm text-[#1d4ed8]",children:"There are still more old slug pages to fix. Click Run repair again to process the next batch."}):null,Array.isArray(o.results)&&o.results.length>0?e.jsx("div",{className:"rounded-2xl border border-[#e5e7eb] bg-white overflow-hidden",children:e.jsx("div",{className:"max-h-[360px] overflow-auto divide-y divide-[#f3f4f6]",children:o.results.slice(0,100).map(l
1=>e.jsxs("div",{className:"px-4 py-3 text-sm",children:[e.jsx("div",{className:"font-medium text-[#111827]",children:l.domain}),e.jsx("div",{className:"mt-1 text-xs text-[#6b7280]",children:l.status==="updated"?`/${l.oldSlug}/ → /${l.newSlug}/`:`/${l.oldSlug}/ · ${l.reason||l.status}`})]},`${l.oldSlug}-${l.newSlug||l.reason||"row"}`))})}):null]}):null]})}function Xt(){const[t,i]=r.useState([]),[o,c]=r.useState(!0),[b,f]=r.useState(null),x=async()=>{const u=await m.entities.ProductListing.list("-created_date",200);i(u||[]),c(!1)};r.useEffect(()=>{x()},[]);const l=async(u,p)=>{f(u.id),await m.functions.invoke("adminUpdateProductApproval",{productId:u.id,isApproved:p}),await x(),f(null)};return o?e.jsx("div",{className:"h-40 animate-pulse rounded-[28px] bg-white/80"}):e.jsxs("div",{className:"rounded-[28px] border border-white/70 bg-white/95 shadow-[0_18px_50px_rgba(15,23,42,0.06)] overflow-hidden",children:[e.jsxs("div",{className:"border-b border-[#eef2f7] px-5 py-4 sm:px-6",children:[e.jsx("h2",{className:"text-base font-semibold text-[#111827]",children:"Product listings"}),e.jsx("p",{className:"text-sm text-[#6b7280]",children:"Approve products before they appear publicly."})]}),e.jsx("div",{className:"divide-y divide-[#f1f5f9]",children:t.length===0?e.jsx("div",{className:"px-5 py-8 text-center text-sm text-[#94a3b8] sm:px-6",children:"No product listings yet."}):t.map(u=>e.jsx("div",{className:"px-5 py-4 sm:px-6",children:e.jsxs("div",{className:"flex flex-col gap-4 lg:flex-row lg:items-center lg:justify-between",children:[e.jsxs("div",{className:"flex min-w-0 items-start gap-3",children:[e.jsx("img",{src:u.logo_url||`https://www.google.com/s2/favicons?domain=${u.site_domain}&sz=64`,alt:"",className:"h-10 w-10 shrink-0 rounded-xl border border-[#e5e7eb] bg-white object-cover",onError:p=>{p.currentTarget.style.display="none"}}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("h3",{className:"truncate text-sm font-semibold text-[#111827]",children:u.title}),e.jsx("span",{className:`rounded-full px-2 py-0.5 text-xs font-semibold ${u.is_approved?"bg-emerald-50 text-emerald-700":"bg-amber-50 text-amber-700"}`,children:u.is_approved?"Approved":"Pending"})]}),e.jsx("p",{className:"mt-1 text-xs text-[#94a3b8]",children:u.site_domain||u.website_url||"No website URL"}),u.created_by&&e.jsxs("p",{className:"mt-1 text-xs text-[#94a3b8]",children:["Submitted by ",u.created_by]})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 lg:justify-end",children:[e.jsx(Be,{to:`/product/${u.slug}`,className:"rounded-xl border border-[#e5e7eb] px-3 py-2 text-xs font-semibold text-[#475569] hover:bg-[#f8fafc]",children:"View"}),e.jsx("button",{onClick:()=>l(u,!u.is_approved),disabled:b===u.id,className:`rounded-xl px-3 py-2 text-xs font-semibold text-white disabled:opacity-60 ${u.is_approved?"bg-[#64748b]":"bg-[#111827]"}`,children:b===u.id?"Saving...":u.is_approved?"Unapprove":"Approve"})]})]})},u.id))})]})}const me=[{key:"sites",label:"Sites",icon:ct,hint:"Manage monitored sites"},{key:"users",label:"Users",icon:ye,hint:"App users and access"},{key:"credits",label:"Credits",icon:xt,hint:"Usage and balances"},{key:"comments",label:"Comments",icon:be,hint:"Community moderation"},{key:"content-review",label:"Content Review",icon:ve,hint:"Approve site overview edits"},{key:"products",label:"Products",icon:mt,hint:"Approve product listings"},{key:"slug-repair",label:"Slug Repair",icon:X,hint:"Reconnect legacy slug pages"},{key:"marketing",label:"Marketing",icon:ut,hint:"Affiliate tools"},{key:"search-logger",label:"Search Logger",icon:Z,hint:"Discovery runs"},{key:"affiliate-users",label:"Affiliate Users",icon:ht,hint:"Referral users"},{key:"seo",label:"SEO",icon:ft,hint:"Blog and search setup"},{key:"agent",label:"Agent",icon:pt,hint:"Blog automation agents"},{key:"blocked-domains",label:"Blocked Domains",icon:bt,hint:"Review and add blocked websites"},{key:"settings",label:"Settings",icon:gt,hint:"App configuration"}];function ue({icon:t,label:i,value:o,sub:c,color:b="#6366f1"}){return e.jsxs("div",{className:"bg-white border border-[#ebebeb] rounded-2xl px-5 py-4 flex items-center gap-4",children:[e.jsx("div",{className:"w-10 h-10 rounded-xl flex items-center justify-center shrink-0",style:{background:`${b}18`},children:e.jsx(t,{className:"w-5 h-5",style:{color:b}})}),e.jsxs("div",{children:[e.jsx("div",{className:"text-2xl font-bold text-[#1a1a1a] leading-none",children:o}),e.jsx("div",{className:"text-xs text-[#aaa] mt-0.5",children:i}),c&&e.jsx("div",{className:"text-xs text-[#bbb] mt-0.5",children:c})]})]})}function as(){const t=Ve(),[i,o]=r.useState("sites"),[c,b]=r.useState(null),[f,x]=r.useState(null),[l,u]=r.useState({}),[p,g]=r.useState(1),[v,N]=r.useState("recent"),[y,T]=r.useState(""),{data:D,isLoading:h}=I({queryKey:["me"],queryFn:()=>m.auth.me(),retry:!1});r.useEffect(()=>{!h&&(!D||D.role!=="admin")&&t("/")},[D,h,t]),r.useEffect(()=>{const a=document.createElement("script");return a.type="application/ld+json",a.id="ld-admin",a.text=JSON.stringify({"@context":"https://schema.org","@type":"WebPage",name:"SiteAlive Admin Dashboard",url:"https://sitealive.io/admin",description:"Admin dashboard for managing monitored sites, analytics, c
1omments, and marketing tools."}),document.head.appendChild(a),()=>{var _;return(_=document.getElementById("ld-admin"))==null?void 0:_.remove()}},[]);const{data:d=[],refetch:n}=I({queryKey:["sites"],queryFn:()=>m.entities.Site.list("-updated_date",1e4),enabled:!!D}),{data:j=[],refetch:k}=I({queryKey:["checks-recent"],queryFn:()=>m.entities.Check.list("-checked_at",1e4),enabled:!!D}),{data:S=[],refetch:L}=I({queryKey:["checks-all"],queryFn:async()=>{let _=0,U=[];for(;;){const P=await m.entities.Check.list("-checked_at",1e4,_);if(U=U.concat(P||[]),!P||P.length<1e4)break;_+=1e4}return U},enabled:!!D});j.reduce((a,_)=>{var P;const U=_.site_id||((P=_.data)==null?void 0:P.site_id);return U&&(a[U]||(a[U]=[]),a[U].push(_)),a},{});const[R,M]=r.useState(!1),$=async()=>{M(!0),await Promise.all([n(),k(),L()]),M(!1)},F=d.filter(a=>a.last_status==="UP").length,s=d.filter(a=>a.last_status==="DOWN").length,w=d.filter(a=>a.last_status==="DEGRADED").length,C=d.filter(a=>a.last_status!=="UP"&&a.last_status!=="UNKNOWN"),A=me.find(a=>a.key===i)||me[0],E=100,B=d.reduce((a,_)=>(a[_.id]={checked_at:_.last_checked_at,latency_ms:_.last_latency_ms,http_status:_.last_http_status,status:_.last_status},a),{}),q=d.reduce((a,_)=>(a[_.id]=_,a),{}),G=S.reduce((a,_)=>{var P;const U=_.site_id||((P=_.data)==null?void 0:P.site_id);return U&&(a[U]=(a[U]||0)+1),a},{}),W=S.reduce((a,_)=>{var O,te;const U=_.site_id||((O=_.data)==null?void 0:O.site_id),P=String(((te=q[U])==null?void 0:te.domain)||"").toLowerCase().trim();return P&&(a[P]=(a[P]||0)+1),a},{}),_e=[...d].sort((a,_)=>{if(v==="latest_checked")return new Date(_.last_checked_at||0)-new Date(a.last_checked_at||0);if(v==="most_checked"){const U=Number(W[String(_.domain||"").toLowerCase().trim()]||0)-Number(W[String(a.domain||"").toLowerCase().trim()]||0);return U!==0?U:new Date(_.last_checked_at||0)-new Date(a.last_checked_at||0)}if(v==="down_first"){const U=a.last_status==="DOWN"?1:0,P=_.last_status==="DOWN"?1:0;return P!==U?P-U:new Date(_.updated_date||0)-new Date(a.updated_date||0)}return new Date(_.updated_date||0)-new Date(a.updated_date||0)}),qe=_e.reduce((a,_)=>{const U=String(_.domain||"").toLowerCase().trim();if(!U)return a.push(_),a;const P=a.findIndex(He=>String(He.domain||"").toLowerCase().trim()===U);if(P===-1)return a.push(_),a;const O=a[P],te=Number(W[String(O.domain||"").toLowerCase().trim()]||0),Ge=Number(W[String(_.domain||"").toLowerCase().trim()]||0),Ce=O.last_status==="UP",De=_.last_status==="UP";return(De&&!Ce||De===Ce&&Ge>te)&&(a[P]=_),a},[]),ke=v==="most_checked"?qe.slice(0,30):_e,ee=y.trim().toLowerCase(),K=ee?ke.filter(a=>{const _=String(a.domain||"").toLowerCase(),U=String(a.display_name||"").toLowerCase(),P=String(a.slug||"").toLowerCase();return _.startsWith(ee)||U.startsWith(ee)||P.startsWith(ee)}):ke,H=Math.max(1,Math.ceil(K.length/E)),Se=K.slice((p-1)*E,p*E),Oe=async a=>{b(a.id);try{await m.functions.invoke("checkSite",{domain:a.domain,force:!0}),await Promise.all([n(),k(),L()])}finally{b(null)}},We=async a=>{if(!confirm(`Delete ${a.display_name}?`))return;const _=await m.entities.DeletedSlugRedirect.filter({slug:a.slug},void 0,1);_!=null&&_[0]?await m.entities.DeletedSlugRedirect.update(_[0].id,{redirect_to:"/",site_display_name:a.display_name}):await m.entities.DeletedSlugRedirect.create({slug:a.slug,redirect_to:"/",site_display_name:a.display_name});const U=String(a.domain||"").trim().toLowerCase().replace(/^www\./,"");if(U){const P=await m.entities.BannedUser.filter({user_email:U},void 0,1);P!=null&&P[0]||await m.entities.BannedUser.create({user_email:U,reason:"Removed from admin sites"})}await m.entities.Site.delete(a.id),await m.functions.invoke("invalidateSitemapCache",{entity_name:"Site"}),n()},ze=a=>{x(a),u({official_url:a.official_url||"",support_url:a.support_url||"",status_page_url:a.status_page_url||""})},Ke=async()=>{await m.entities.Site.update(f.id,l),x(null),n()};return r.useEffect(()=>{p>H&&g(H)},[p,H]),r.useEffect(()=>{g(1)},[y]),h?e.jsx("div",{className:"min-h-screen flex items-center justify-center",children:e.jsx("div",{className:"w-6 h-6 border-2 border-[#1a1a1a] border-t-transparent roun
1ded-full animate-spin"})}):e.jsx("div",{className:"min-h-screen bg-gradient-to-br from-[#f9f9f8] via-white to-[#f3f4f6]",children:e.jsxs("div",{className:"max-w-6xl mx-auto px-4 py-8",children:[e.jsxs("div",{className:"mb-8 overflow-hidden rounded-[28px] border border-white/70 bg-white/90 shadow-[0_24px_80px_rgba(15,23,42,0.08)]",children:[e.jsx("div",{className:"border-b border-[#eef0f3] px-5 py-5 sm:px-6",children:e.jsxs("div",{className:"flex flex-col gap-4 lg:flex-row lg:items-center lg:justify-between",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"inline-flex items-center gap-2 rounded-full border border-[#e8ecf3] bg-[#f8fafc] px-3 py-1 text-xs font-medium text-[#64748b]",children:[e.jsx("span",{className:"h-2 w-2 rounded-full bg-emerald-500"}),"Admin workspace"]}),e.jsx("h1",{className:"mt-3 text-2xl font-bold tracking-tight text-[#111827] sm:text-3xl",children:"Admin Dashboard"}),e.jsx("p",{className:"mt-1 text-sm text-[#6b7280]",children:"A clearer overview of site health, traffic, content, users, and admin tools."})]}),e.jsxs("button",{onClick:$,disabled:R,className:"inline-flex items-center justify-center gap-2 rounded-2xl border border-[#dbe1ea] bg-white px-4 py-2.5 text-sm font-medium text-[#475569] transition-colors hover:bg-[#f8fafc] disabled:opacity-50",children:[e.jsx(X,{className:`w-4 h-4 ${R?"animate-spin":""}`}),R?"Refreshing…":"Refresh data"]})]})}),e.jsx("div",{className:"px-5 py-5 sm:px-6",children:e.jsxs("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2 xl:grid-cols-4",children:[e.jsx(ue,{icon:$e,label:"Total sites",value:d.length,color:"#6366f1"}),e.jsx(ue,{icon:jt,label:"Sites up",value:F,sub:`${s} down · ${w} degraded`,color:"#16a34a"}),e.jsx(ue,{icon:Ie,label:"Checks today",value:j.filter(a=>new Date(a.checked_at)>new Date(Date.now()-864e5)).length,color:"#0ea5e9"})]})})]}),e.jsxs("div",{className:"mb-6 overflow-hidden rounded-[28px] border border-white/70 bg-white/90 shadow-[0_18px_50px_rgba(15,23,42,0.06)]",children:[e.jsx("div",{className:"border-b border-[#eef0f3] px-5 py-4 sm:px-6",children:e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"rounded-2xl bg-[#f8fafc] p-2 text-[#334155]",children:e.jsx(A.icon,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-semibold text-[#111827]",children:A.label}),e.jsx("p",{className:"text-sm text-[#6b7280]",children:A.hint})]})]})}),e.jsx("div",{className:"px-3 py-3 sm:px-4",children:e.jsx("div",{className:"flex flex-wrap gap-2",children:me.map(a=>{const _=a.icon,U=i===a.key;return e.jsxs("button",{onClick:()=>{o(a.key),a.key==="sites"&&g(1)},className:`flex min-h-[64px] min-w-[180px] flex-1 items-center gap-3 rounded-2xl px-3 py-3 text-left text-sm font-medium transition-all ${U?"bg-[#111827] text-white shadow-sm":"bg-[#f8fafc] text-[#64748b] hover:bg-[#eef2f7] hover:text-[#334155]"}`,children:[e.jsx("div",{className:`rounded-xl p-2 ${U?"bg-white/10":"bg-white"}`,children:e.jsx(_,{className:"h-4 w-4"})}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"truncate",children:a.label}),e.jsx("div",{className:`truncate text-xs ${U?"text-white/70":"text-[#94a3b8]"}`,children:a.hint})]})]},a.key)})})})]}),i==="sites"&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-2 xl:grid-cols-4",children:[e.jsxs("div",{className:"rounded-[24px] border border-[#dbeafe] bg-gradient-to-br from-[#eff6ff] to-white p-5",children:[e.jsx("div",{className:"text-xs font-medium uppercase tracking-[0.18em] text-[#2563eb]",children:"Total sites"}),e.jsx("div",{className:"mt-3 text-3xl font-bold text-[#0f172a]",children:d.length}),e.jsx("p",{className:"mt-2 text-sm text-[#64748b]",children:"All monitored site pages in the system."})]}),e.jsxs("div",{className:"rounded-[24px] border border-emerald-100 bg-gradient-to-br from-emerald-50 to-white p-5",children:[e.jsx("div",{className:"text-xs font-medium uppercase tracking-[0.18em] text-emerald-700",children:"Up"}),e.jsx("div",{className:"mt-3 text-3xl font-bold text-emerald-900",children:F}),e.jsx("p",{className:"mt-2 text-sm text-emerald-800/80",children:"Sites currently responding normally."})]}),e.jsxs("div",{className:"rounded-[24px] border border-red-100 bg-gradient-to-br from-red-50 to-white p-5",children:[e.jsx("div",{className:"text-xs font-medium uppercase tracking-[0.18em] text-red-700",children:"Down"}),e.jsx("div",{className:"mt-3 text-3xl font-bold text-red-900",children:s}),e.jsx("p",{className:"mt-2 text-sm text-red-800/80",children:"Sites that appear unavailable right now."})]}),e.jsxs("div",{className:"rounded-[24px] border border-amber-100 bg-gradient-to-br from-amber-50 to-white p-5",children:[e.jsx("div",{className:"text-xs font-medium uppercase tracking-[0.18em] text-amber-700",children:"Degraded"}),e.jsx("div",{className:"mt-3 text-3xl font-bold text-amber-900",children:w}),e.jsx("p",{className:"mt-2 text-sm text-amber-800/80",children:"Sites responding with partial issues."})]})]}),e.jsxs("div",{className:"grid gap-6 xl:grid-cols-[minmax(0,1.4fr)_minmax(320px,0.9fr)]",children:[e.jsxs("div",{className:"rounded-[28px] border border-white/70 bg-white/95 shadow-[0_18px_50px_rgba(15,23,42,0.06)] overflow-hidden",children:[e.jsx("div",{className:"border-b border-[#eef2f7] px-5 py-4 sm:px-6",children:e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-semibold text-[#111827]",children:"All sites"}),e.jsx("p",{className:"text-sm text-[#6b7280]",children:"Check status, open the public page, edit links, or remove a site."})]}),e.jsxs("div",{className:"flex flex-col items-stretch gap-3 sm:flex-row sm:items-center",children:[e.jsxs("div",{className:"relative",children:[e.jsx(Z,{className:"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-[#94a3b8]"}),e.jsx("input",{type:"text",value:y,onChange:a=>T(a.target.value),placeholder:"Search domain, name, or slug",className:"w-full rounded-xl border border-[#dbe1ea] bg-white py-2 pl-9 pr-3 text-sm font-medium text-[#475569] focus:outline-none sm:w-[260px]"})]}
1),e.jsxs("select",{value:v,onChange:a=>{N(a.target.value),g(1)},className:"rounded-xl border border-[#dbe1ea] bg-white px-3 py-2 text-sm font-medium text-[#475569] focus:outline-none",children:[e.jsx("option",{value:"recent",children:"Recently updated"}),e.jsx("option",{value:"latest_checked",children:"Latest checked sites"}),e.jsx("option",{value:"most_checked",children:"Most checked sites"}),e.jsx("option",{value:"down_first",children:"Down sites first"})]}),e.jsxs("div",{className:"text-xs font-medium text-[#94a3b8]",children:[K.length," match",K.length===1?"":"es"]})]})]})}),e.jsx("div",{className:"divide-y divide-[#f1f5f9]",children:Se.length===0?e.jsx("div",{className:"px-5 py-8 text-center text-sm text-[#94a3b8] sm:px-6",children:"No sites match your search."}):Se.map(a=>{var _,U,P,O;return e.jsx("div",{className:"px-5 py-4 sm:px-6",children:e.jsxs("div",{className:"flex flex-col gap-3 lg:flex-row lg:items-center",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 items-start gap-3",children:[e.jsx("img",{src:`https://www.google.com/s2/favicons?domain=${a.domain}&sz=32`,className:"mt-0.5 h-8 w-8 rounded-lg shrink-0",alt:`${a.display_name} favicon`}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"truncate text-sm font-semibold text-[#111827]",children:a.display_name}),e.jsx("span",{className:"rounded-full bg-[#f8fafc] px-2 py-0.5 text-xs text-[#64748b]",children:a.domain})]}),e.jsxs("div",{className:"mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-[#94a3b8]",children:[v==="most_checked"?e.jsxs("span",{children:[Number(W[String(a.domain||"").toLowerCase().trim()]||0).toLocaleString()," total checks"]}):e.jsx("span",{children:(_=B[a.id])!=null&&_.checked_at?`Checked ${ae(new Date(B[a.id].checked_at),{addSuffix:!0})}`:"Never checked"}),v!=="most_checked"?e.jsxs("span",{children:[Number(G[a.id]||0).toLocaleString()," total checks"]}):null,(U=B[a.id])!=null&&U.latency_ms?e.jsxs("span",{children:[B[a.id].latency_ms,"ms latency"]}):null,(P=B[a.id])!=null&&P.http_status?e.jsxs("span",{children:["HTTP ",B[a.id].http_status]}):null]})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3 lg:justify-end",children:[e.jsx(ne,{status:((O=B[a.id])==null?void 0:O.status)||a.last_status,size:"sm"}),e.jsxs("div",{className:"flex items-center gap-1 rounded-xl border border-[#e2e8f0] bg-[#f8fafc] p-1",children:[e.jsx("button",{onClick:()=>t(`/${wt(a.domain)}/`),className:"rounded-lg p-2 text-[#64748b] transition-colors hover:bg-white hover:text-[#111827]",title:"View page",children:e.jsx(Fe,{className:"h-4 w-4"})}),e.jsx("button",{onClick:()=>Oe(a),disabled:c===a.id,className:"rounded-lg p-2 text-[#64748b] transition-colors hover:bg-white hover:text-[#111827] disabled:opacity-40",title:"Re-check now",children:e.jsx(X,{className:`h-4 w-4 ${c===a.id?"animate-spin":""}`})}),e.jsx("button",{onClick:()=>ze(a),className:"rounded-lg p-2 text-[#64748b] transition-colors hover:bg-white hover:text-[#111827]",title:"Edit links",children:e.jsx(ve,{className:"h-4 w-4"})}),e.jsx("button",{onClick:()=>We(a),className:"rounded-lg p-2 text-[#64748b] transition-colors hover:bg-red-50 hover:text-red-600",title:"Delete",children:e.jsx(J,{className:"h-4 w-4"})})]})]})]})},a.id)})}),e.jsxs("div",{className:"flex flex-col gap-3 border-t border-[#eef2f7] px-5 py-4 sm:flex-row sm:items-center sm:justify-between sm:px-6",children:[e.jsxs("div",{className:"text-xs font-medium text-[#94a3b8]",children:["Showing ",K.length===0?0:(p-1)*E+1,"–",Math.min(p*E,K.length)," of ",K.length]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{onClick:()=>g(a=>Math.max(1,a-1)),disabled:p===1,className:"rounded-xl border border-[#dbe1ea] bg-white px-3 py-2 text-sm font-medium text-[#475569] transition-colors hover:bg-[#f8fafc] disabled:opacity-40",children:"Previous"}),e.jsxs("div",{className:"rounded-xl bg-[#f8fafc] px-3 py-2 text-sm font-medium text-[#475569]",children:["Page ",p," / ",H]}),e.jsx("button",{onClick:()=>g(a=>Math.min(H,a+1)),disabled:p===H,className:"rounded-xl border border-[#dbe1ea] bg-white px-3 py-2 text-sm font-medium text-[#475569] transition-colors hover:bg-[#f8fafc] disabled:opacity-40",children:"Next"})]})]})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"rounded-[28px] border border-white/70 bg-white/95 shadow-[0_18px_50px_rgba(15,23,42,0.06)] overflow-hidden",children:[e.jsx("div",{className:"border-b border-[#eef2f7] px-5 py-4 sm:px-6",children:e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-base font-semibold text-[#111827]",children:"Sites with issues"}),e.jsx("p",{className:"text-sm text-[#6b7280]",children:"Down and degraded sites grouped for quick review."})]}),e.jsxs("span",{className:"rounded-full bg-[#f8fafc] px-2.5 py-1 text-xs font-medium text-[#64748b]",children:[C.length," affected"]})]})}),C.length===0?e.jsx("p",{className:"px-5 py-8 text-center text-sm text-[#94a3b8] sm:px-6",children:"All sites are currently healthy."}):e.jsx("div",{className:"divide-y divide-[#f1f5f9]",children:C.map(a=>e.jsx("div",{className:"px-5 py-4 sm:px-6",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx("img",{src:`https://www.google.com/s2/favicons?domain=${a.domain}&sz=32`,className:"mt-0.5 h-8 w-8 rounded-lg shrink-0",alt:`${a.display_name} favicon`}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:"truncate text-sm font-semibold text-[#111827]",children:a.display_name}),e.jsx(ne,{status:a.last_status,size:"sm"})]}),e.jsx("div",{className:"mt-1 text-xs text-[#94a3b8]",children:a.domain}),a.last_error?e.jsx("div",{className:"mt-2 text-xs text-[#b45309]",children:a.last_error}):null]})]})},a.id))})]}),e.jsxs("div",{className:"rounded-[28px] border border-white/70 bg-white/95 shadow-[0_18px_50px_rgba(15,23,42,0.06)] overflow-hidden",children:[e.jsxs("div",{className:"border-b border-[#eef2f7] px-5 py-4 sm:px-6",children:[e.jsx("h2",{className:"text-base font-semibold text-[#111827]",children:"Recent checks"}),e.jsx("p",{className:"text-sm text-[#6b7280]",children:"Latest monitoring runs across your tracked sites."})]}),e.jsx("div",{className:"divide-y divide-[#f1f5f9]",children:j.slice(0,10).map(a=>{var P;const _=a.site_id||((P=a.data)==null?void 0:P.site_id),U=d.find(O=>O.id===_);return e.jsx("div",{className:"px-5 py-4 sm:px-6",children:e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:gap-4",children:[e.jsx(ne,{status:a.status,size:"sm"}),e.jsx("span",{className:"min-w-0 flex-1 truncate text-sm text-[#334155]",children:(U==null?void 0:U.display_name)||a.site_id}),e.jsxs("div",{className:"flex flex-wrap items-center gap-3 text-xs text-[#94a3b8] sm:justify-end",children:[a.latency_ms?e.jsxs("span",{children:[a.latency_ms,"ms"]}):null,e.jsx("span",{children:a.checked_at?ae(new Date(a.checked_at),{addSuffix:!0}):"—"})]})]})},a.id)})})]})]})]})]}),f&&e.jsx("div",{className:"fixed inset-0 bg-black/40 z-50 flex items-center justify-center p-4",children:e.jsxs("div",{className:"bg-white rounded-2xl shadow-xl w-full max-w-md p-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-5",children:[e.jsxs("h3",{className:"font-semibold text-[#1a1a1a]",children:["Edit links — ",f.display_name]}),e.jsx("button",{onClick:()=>x(null),className:"text-[#bbb] hover:text-[#555]",children:e.jsx(vt,{className:"w-5 h-5"})})]}),e.jsx("div",{className:"space-y-4",children:[{key:"official_url",label:"Official website URL"},{key:"support_url",label:"Support URL"},{key:"status_page_url",label:"Official status page URL"}].map(({key:a,label:_})=>e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-medium text-[#888] mb-1",children:_}),e.jsx("input",{type:"url",value:l[a],onChange:U=>u(P=>({...P,[a]:U.target.value})),placeholder:"https://...",className:"w-full border border-[#e0e0e0] rounded-xl px-3 py-2 text-sm focus:outline-none focus:border-[#999]"})]},a))}),e.jsxs("div",{className:"flex justify-end gap-2 mt-6",children:[e.jsx("button",{onClick:()=>x(null),className:"px-4 py-2 text-sm text-[#888] hover:text-[#555] border border-[#e0e0e0] rounded-xl",children:"Cancel"}),e.jsx("button",{onClick:Ke,className:"px-4 py-2 text-sm font-medium bg-[#1a1a1a] text-white rounded-xl hover:bg-[#333]",children:"Save"})]})]})}),i==="comments"&&e.jsx(Ct,{}),i==="content-review"&&e.jsx(Jt,{adminUser:D}),i==="slug-repair"&&e.jsx(Yt,{}),i==="products"&&e.jsx(Xt,{}),i==="marketing"&&e.jsx(_t,{}),i==="search-logger"&&e.jsx(Ot,{}),i==="affiliate-users"&&e.jsx(Tt,{}),i==="seo"&&e.jsx(zt,{}),i==="agent"&&e.jsxs("div",{className:"space-y-6",children:[e.jsx(Qt,{}),e.jsx(Kt,{})]}),i==="blocked-domains"&&e.jsx(Ut,{}),i==="settings"&&e.jsx(Dt,{}),i==="users"&&e.jsx(qt,{}),i==="credits"&&e.jsx(Et,{})]})})}export{as 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.