1import{r as i,c0 as W,c1 as p,c2 as $,s as l,j as e,m as N,L as x,I as b,bq as q,B as k,bw as c}from"./index-KSWbwNeY.js";import{A as H}from"./AdminNav-DsaLvjFx.js";import{C as S,b as _,c as C,d as E,a as P}from"./card-CwL_ed79.js";import{T as O}from"./textarea-BXv-lbww.js";import{L as u}from"./label-ndOKmXJw.js";import{S as D}from"./shuffle-BOT2k_fz.js";import{S as L}from"./save-xjMYTeam.js";import{B as U}from"./ban-Dw9y4DYY.js";import"./index-DsYLezIw.js";import"./user-cog-DvqSS7bY.js";import"./trash-2-CwcwS_bf.js";import"./book-open-DS7Nmuzn.js";import"./receipt-DgWJf9Ou.js";import"./chevron-down-D7IdZFzc.js";const ne=()=>{const[A,d]=i.useState([]),[R,T]=i.useState(!0),[h,g]=i.useState(null),[o,v]=i.useState(""),[f,j]=i.useState(!1),[r,I]=i.useState(""),y=i.useMemo(()=>W(p(o)),[o]).filter(s=>s.invalid).map(s=>s.raw),m=i.useMemo(()=>{if(!r.trim())return null;let s=r.trim();try{/^https?:\/\//i.test(s)&&(s=new URL(s).pathname)}catch{}return s.startsWith("/")||(s=`/${s}`),{path:s,excluded:$(p(o),s)}},[r,o]);i.useEffect(()=>{(async()=>{const[{data:s},{data:a}]=await Promise.all([l.from("popup_rotation_config").select("key,label,rotation_weight,is_active").order("label"),l.from("site_settings").select("value").eq("key","popup_excluded_pages").maybeSingle()]);d(s||[]);const n=a==null?void 0:a.value,t=Array.isArray(n)?n:typeof n=="string"?(()=>{try{const w=JSON.parse(n);return Array.isArray(w)?w:[]}catch{return[]}})():[];v(t.join(` 2`)),T(!1)})()},[]);const M=async s=>{g(s.key);const{error:a}=await l.from("popup_rotation_config").update({rotation_weight:s.rotation_weight,is_active:s.is_active}).eq("key",s.key);g(null),a?c({title:"Save failed",description:a.message,variant:"destructive"}):c({title:"Saved"})},B=async()=>{j(!0);const s=p(o),{error:a}=await l.from("site_settings").upsert({key:"popup_excluded_pages",value:s,updated_at:new Date().toISOString()},{onConflict:"key"});j(!1),a?c({title:"Save failed",description:a.message,variant:"destructive"}):c({title:"Excluded pages saved",description:`${s.length} rule(s) active.`})};return e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx(H,{}),e.jsxs("main",{className:"container mx-auto px-4 py-8 max-w-3xl",children:[e.jsx(N.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},transition:{duration:.35},children:e.jsxs(S,{children:[e.jsxs(_,{children:[e.jsxs(C,{className:"flex items-center gap-2 text-lg",children:[e.jsx(D,{className:"h-5 w-5"}),"Popup Rotation"]}),e.jsxs(E,{children:["When multiple popups are eligible on the same page load, one is picked using these weights. Higher weight = more often. Set weight to ",e.jsx("span",{className:"font-mono",children:"0"})," or disable to exclude. Interstitials, Notification Widgets, and LP Promotion have their own per-record weights on their edit pages."]})]}),e.jsx(P,{children:R?e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx(x,{className:"h-4 w-4 animate-spin"})," Loadingâ¦"]}):e.jsx("div",{className:"space-y-3",children:A.map(s=>e.jsxs("div",{className:"flex items-end gap-3 rounded-md border p-3",children:[e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-sm font-medium",children:s.label}),e.jsx("div",{className:"text-xs text-muted-foreground font-mono",children:s.key})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(u,{className:"text-xs",children:"Weight"}),e.jsx(b,{type:"number",min:0,className:"w-24 h-9",value:s.rotation_weight,onChange:a=>d(n=>n.map(t=>t.key===s.key?{...t,rotation_weight:parseInt(a.target.value)||0}:t))})]}),e.jsxs("div",{className:"flex items-center gap-2 pb-2",children:[e.jsx(q,{checked:s.is_active,onCheckedChange:a=>d(n=>n.map(t=>t.key===s.key?{...t,is_active:a}:t))}),e.jsx(u,{className:"text-xs",children:"Active"})]}),e.jsx(k,{size:"sm",onClick:()=>M(s),disabled:h===s.key,children:h===s.key?e.jsx(x,{className:"h-4 w-4 animate-spin"}):e.jsx(L,{className:"h-4 w-4"})})]},s.key))})})]})}),e.jsx(N.div,{initial:{opacity:0,y:8},animate:{opacity:1,y:0},transition:{duration:.35,delay:.08},className:"mt-6",children:e.jsxs(S,{children:[e.jsxs(_,{children:[e.jsxs(C,{className:"flex items-center gap-2 text-lg",children:[e.jsx(U,{className:"h-5 w-5"}),"Excluded Pages"]}),e.jsxs(E,{children:["Pages listed here never show any popup â interstitials, notification widgets, LP Promotion, event bar or the AIM Media House popup. One rule per line: a path (",e.jsx("span",{className:"font-mono",children:"/subscribe"}),", also matches sub-paths), a wildcard (",e.jsx("span",{className:"font-mono",children:"/ai-news/*"}),"), or a regex wrapped in slashes (",e.jsx("span",{className:"font-mono",children:"/^\\/lists\\/.+$/i"}),")."]})]}),e.jsxs(P,{className:"space-y-4",children:[e.jsx(O,{value:o,onChange:s=>v(s.target.value),rows:6,placeholder:`/subscribe 3/checkout 4/ai-news/*`,className:"font-mono text-xs"}),y.length>0&&e.jsxs("p",{className:"text-xs text-destructive",children:["Invalid regex ignored: ",y.join(", ")
4]}),e.jsxs("div",{className:"flex flex-wrap items-end gap-3",children:[e.jsxs("div",{className:"space-y-1 flex-1 min-w-[220px]",children:[e.jsx(u,{className:"text-xs",children:"Test a URL"}),e.jsx(b,{value:r,onChange:s=>I(s.target.value),placeholder:"/ai-news/some-article",className:"h-9"})]}),m&&e.jsx("div",{className:`h-9 flex items-center rounded-md border px-3 text-xs ${m.excluded?"border-destructive text-destructive":"text-muted-foreground"}`,children:m.excluded?"Excluded â no popups":"Allowed â popups can show"}),e.jsxs(k,{onClick:B,disabled:f,className:"gap-2",children:[f?e.jsx(x,{className:"h-4 w-4 animate-spin"}):e.jsx(L,{className:"h-4 w-4"}),"Save"]})]})]})]})})]})]})};export{ne 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.