PageSourceSearch

https://cpgio.com/assets/PagesDashboard-BDFfjdP7.js

js cpgio.com collected 2026-10-09 23:30:06 UTC 28,205 bytes, 1 lines download raw bytes

1import{r as s,j as e}from"./vendor-react-BQobPn2Z.js";import{d as H,b as J,L as D}from"./vendor-router-C23-jnjR.js";import{H as K}from"./Header-23knikAz.js";import{a2 as z}from"./index-CtLIdj0S.js";import"./vendor-commonjs-helpers-De8WaMV9.js";import"./vendor-react-dom-BVmTabbt.js";import"./navigation-IXkQMceL.js";import"./sun-BEHRut-d.js";import"./usePageNotesVisible-BvQIw3Tr.js";import"./target-D3GRIwEy.js";import"./shopping-cart-DHaOMzh-.js";import"./rocket-CghC31SN.js";import"./pen-tool-ZBSbgro4.js";import"./package-BKu7iZsl.js";import"./monitor-DvYsSG68.js";import"./graduation-cap-xfyfOD5r.js";import"./building-2-BqFXp6ji.js";import"./chart-column-FQ7cXIb5.js";import"./smartphone-KoqB2Y27.js";import"./settings-Ch9u1v_p.js";import"./user-Bb_Q8AC0.js";import"./admin-export-C610b6Gt.js";import"./vendor-radix-CoRXDypy.js";import"./vendor-charts-nXCWwiWB.js";import"./vendor-query-mhhVZALn.js";import"./vendor-posthog-BfjysNwK.js";async function V(l){return(await l.slice(0,204800).text()).includes("__bundler")?"bundler":"plain-html"}function W({open:l,onClose:j}){const f=H(),y=s.useRef(null),[r,c]=s.useState(null),[g,w]=s.useState(null),[v,h]=s.useState("pick"),[m,u]=s.useState(""),[a,o]=s.useState(null),[N,i]=s.useState(!1),k=s.useCallback(()=>{c(null),w(null),h("pick"),u(""),o(null),i(!1)},[]),P=s.useCallback(()=>{k(),j()},[k,j]),$=s.useCallback(async d=>{if(!/\.html$/i.test(d.name)){o("Only .html files are accepted.");return}if(d.size>10*1024*1024){o("File exceeds the 10MB upload limit.");return}o(null),c(d),w(await V(d)),h("choose")},[]),A=s.useCallback(async d=>{const C=new FormData;C.append("file",d);const p=await fetch("/api/design-uploads",{method:"POST",credentials:"include",body:C}),T=await p.json();if(!p.ok||!(T!=null&&T.success))throw new Error((T==null?void 0:T.error)||"Upload failed");return T.data},[]),R=s.useCallback(async()=>{if(r){h("working");try{u("Uploading package to S3…");const d=await A(r);u("Creating draft page…");const C=await fetch(`/api/design-uploads/${d.id}/embed`,{method:"POST",credentials:"include"}),p=await C.json();if(!C.ok||!(p!=null&&p.success))throw new Error((p==null?void 0:p.error)||"Embed failed");P(),f(`/admin/ai-page-builder?id=${p.data.pageId}`)}catch(d){o(d instanceof Error?d.message:"Embed failed"),h("error")}}},[r,A,P,f]),L=s.useCallback(async()=>{if(r){h("working");try{u("Uploading package to S3…");const d=await A(r);u("Unpacking design package…");const C=await fetch(`/api/design-uploads/${d.id}/unpack`,{method:"POST",credentials:"include"}),p=await C.json();if(!C.ok||!(p!=null&&p.success))throw new Error((p==null?void 0:p.error)||"Unpack failed");u("Translating to typed sections (AI — up to a minute)…");const T=await fetch(`/api/design-uploads/${d.id}/translate`,{method:"POST",credentials:"include"}),t=await T.json();if(!T.ok||!(t!=null&&t.success))throw new Error((t==null?void 0:t.error)||"Translate failed");P(),f(`/admin/ai-page-builder?id=${t.data.pageId}`)}catch(d){o(d instanceof Error?d.message:"Translate failed"),h("error")}}},[r,A,P,f]);return l?e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4",onClick:P,children:e.jsxs("div",{className:"w-full max-w-xl bg-background border border-border p-6",onClick:d=>d.stopPropagation(),role:"dialog","aria-modal":"true","aria-label":"Import design",children:[e.jsxs("div",{className:"flex items-start justify-between mb-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.2em] font-mono text-muted-foreground mb-1",children:"CMS · Pages"}),e.jsx("h2",{className:"text-xl font-bold",children:"Import design"})]}),e.jsx("button",{onClick:P,className:"text-muted-foreground hover:text-foreground text-xl leading-none","aria-label":"Close",children:"×"})]}),a&&e.jsx("div",{className:"p-3 mb-4 border border-destructive bg-destructive/10 text-destructive text-sm",children:a}),(v==="pick"||v==="error")&&e.jsxs("div",{"data-testid":"design-dropzone",className:`border border-dashed p-10 text-center cursor-pointer transition-colors ${N?"border-primary bg-primary/5":"border-border"}`,onClick:()=>{var d;return(d=y.current)==null?void 0:d.click()},onDragOver:d=>{d.preventDefault(),i(!0)},onDragLeave:()=>i(!1),onDrop:d=>{var p;d.preventDefault(),i(!1);const C=(p=d.dataTransfer.files)==null?void 0:p[0];C&&$(C)},children:[e.jsx("div",{className:"font-mono text-xs uppercase tracking-[0.2em] text-muted-foreground mb-2",children:"Drop .html here"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"claude.ai/design export or plain HTML · max 10MB"}),e.jsx("input",{ref:y,type:"file",accept:".html",className:"hidden",onChange:d=>{var p;const C=(p=d.target.files)==null?void 0:p[0];C&&$(C)}})]}),v==="choose"&&r&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-4 text-sm flex-wrap",children:[e.jsx("span",{className:"font-mono",children:r.name}),e.jsx("span",{"data-testid":"sniff-result",className:`text-[10px] uppercase tracking-[0.14em] font-mono font-bold px-2 py-1 ${g==="bundler"?"bg-primary/10 text-primary":"bg-muted text-muted-foreground"}`,children:g==="bundler"?"claude.ai/design package":"Plain HTML"})]}),e.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3",children:[e.jsxs("button",{onClick:R,className:"border border-border p-4 text-left hover:border-primary transition-colors",children:[e.jsx("div",{className:"font-mono text-xs uppercase tracking-[0.14em] font-bold mb-1",children:"Embed"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"Pixel-perfect. Serves the package in a sandboxed iframe. Scripts run isolated on the S3 origin."})]}),e.jsxs("button",{onClick:L,className:"border border-border p-4 text-left hover:border-primary transition-colors",children:[e.jsx("div",{className:"font-mono text-xs uppercase tracking-[0.14em] font-bold mb-1",children:"Translate"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:"Native. AI maps the design into editable typed sections for review in the builder."})]})]}),e.jsx("button",{onClick:k,className:"mt-4 text-xs font-mono uppercase tracking-[0.14em] text-muted-foreground hover:text-foreground",children:"← Pick a different file"})]}),v==="working"&&e.jsx("div",{className:"p-8 text-center",children:e.jsx("div",{className:"font-mono text-xs uppercase tracking-[0.2em] text-muted-foreground animate-pulse",children:m})})]})}):null}
1function M(l){return l?new Date(l).toLocaleString():"—"}function q({pageId:l,onRestored:j}){const[f,y]=s.useState(!1),[r,c]=s.useState(null),[g,w]=s.useState(null),[v,h]=s.useState(null),m=async()=>{y(!0),h(null);try{const a=await fetch(`/api/ai-pages/${l}/versions`,{credentials:"include"}),o=await a.json();if(!a.ok)throw new Error((o==null?void 0:o.error)||"Failed to load versions");c(o.data||[])}catch(a){h(a.message),c([])}},u=async a=>{if(window.confirm("Restore this version? The current content is snapshotted first, so nothing is lost.")){w(a),h(null);try{const o=await fetch(`/api/ai-pages/${l}/restore/${a}`,{method:"POST",credentials:"include"}),N=await o.json();if(!o.ok)throw new Error((N==null?void 0:N.error)||"Restore failed");y(!1),j()}catch(o){h(o.message)}finally{w(null)}}};return e.jsxs(e.Fragment,{children:[e.jsx("button",{onClick:m,className:"text-muted-foreground hover:text-primary",children:"History"}),f&&e.jsx("div",{className:"fixed inset-0 z-[70] bg-black/60 flex items-center justify-center p-6",onClick:()=>y(!1),children:e.jsxs("div",{className:"bg-background border border-border rounded-lg w-full max-w-2xl max-h-[80vh] overflow-y-auto p-6 text-left",onClick:a=>a.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h3",{className:"font-mono text-xs uppercase tracking-[0.2em]",children:"Version history"}),e.jsx("button",{onClick:()=>y(!1),className:"text-muted-foreground hover:text-primary",children:"✕"})]}),v&&e.jsx("div",{className:"mb-3 text-sm text-destructive",children:v}),r===null?e.jsx("div",{className:"text-muted-foreground text-sm",children:"Loading…"}):r.length===0?e.jsx("div",{className:"text-muted-foreground text-sm",children:"No versions yet — every save and publish records one."}):e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"text-left font-mono text-[10px] uppercase tracking-[0.14em] text-muted-foreground border-b border-border",children:[e.jsx("th",{className:"py-2 pr-3",children:"Saved"}),e.jsx("th",{className:"py-2 pr-3",children:"Title"}),e.jsx("th",{className:"py-2 pr-3",children:"Event"}),e.jsx("th",{className:"py-2 pr-3",children:"By"}),e.jsx("th",{className:"py-2 text-right",children:"Restore"})]})}),e.jsx("tbody",{children:r.map(a=>e.jsxs("tr",{className:"border-b border-border/50",children:[e.jsx("td",{className:"py-2 pr-3 whitespace-nowrap text-muted-foreground",children:M(a.createdAt||a.created_at)}),e.jsx("td",{className:"py-2 pr-3",children:a.title}),e.jsx("td",{className:"py-2 pr-3 text-muted-foreground",children:a.snapshotLabel||a.snapshot_label||"—"}),e.jsx("td",{className:"py-2 pr-3 text-muted-foreground",children:(a.snapshotBy||a.snapshot_by||"—").split("@")[0]}),e.jsx("td",{className:"py-2 text-right",children:e.jsx("button",{onClick:()=>u(a.id),disabled:g!==null,className:"text-primary hover:underline disabled:opacity-50",children:g===a.id?"Restoring…":"Restore"})})]},a.id))})]})]})})]})}function Q(){const[l,j]=s.useState(null),[f,y]=s.useState(null);return s.useEffect(()=>{(async()=>{try{const r=await fetch("/api/auth/audit-logs?limit=100",{credentials:"include"}),c=await r.json();if(r.status===403)throw new Error("Admin role required to view the audit log.");if(!r.ok)throw new Error((c==null?void 0:c.error)||"Failed to load audit log");j(c.data||c.logs||[])}catch(r){y(r.message),j([])}})()},[]),f?e.jsx("div",{className:"p-4 border border-destructive text-destructive text-sm rounded-lg",children:f}):l===null?e.jsx("div",{className:"text-muted-foreground font-mono text-xs uppercase tracking-[0.2em]",children:"Loading…"}):e.jsx("div",{className:"overflow-x-auto border border-border rounded-lg",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-border text-left font-mono text-xs uppercase tracking-[0.14em] text-muted-foreground",children:[e.jsx("th",{className:"px-4 py-3",children:"When"}),e.jsx("th",{className:"px-4 py-3",children:"Who"}),e.jsx("th",{className:"px-4 py-3",children:"Action"}),e.jsx("th",{className:"px-4 py-3",children:"Resource"})]})}),e.jsxs("tbody",{children:[l.map(r=>{var c,g;return e.jsxs("tr",{className:"border-b border-border/50",children:[e.jsx("td",{className:"px-4 py-2 whitespace-nowrap text-muted-foreground",children:M(r.createdAt)}),e.jsx("td",{className:"px-4 py-2",children:((g=(c=r.user)==null?void 0:c.email)==null?void 0:g.split("@")[0])||"—"}),e.jsx("td",{className:"px-4 py-2 font-mono text-xs",children:r.action}),e.jsxs("td",{className:"px-4 py-2 text-muted-foreground",children:[r.resourceType||"—",r.resourceId?` #${r.resourceId}`:""]})]},r.id)}),l.length===0&&e.jsx("tr",{children:e.jsx("td",{className:"px-4 py-6 text-muted-foreground",colSpan:4,children:"No audit entries."})})]})]})})}function Y(){const[l,j]=s.useState(null),[f,y]=s.useState(null),[r,c]=s.useState(""),[g,w]=s.useState(""),[v,h]=s.useState("301"),[m,u]=s.useState(!1),a=s.useCallback(async()=>{try{const i=await fetch("/api/seo-redirects",{credentials:"include"}),k=await i.json();if(!i.ok)throw new Error((k==null?void 0:k.error)||"Failed to load redirects");const P=k.data||[];j(P.filter($=>$.category==="redirect"))}catch(i){y(i.message),j([])}},[]);s.useEffect(()=>{a()},[a]);const o=async()=>
1{if(!(!r.trim()||!g.trim())){u(!0),y(null);try{const i=await fetch("/api/seo-redirects",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({legacyUrl:r.trim(),targetUrl:g.trim(),redirectType:v,category:"redirect",isActive:!0,createdBy:"admin-ui"})}),k=await i.json();if(!i.ok)throw new Error((k==null?void 0:k.error)||"Create failed");c(""),w(""),await a()}catch(i){y(i.message)}finally{u(!1)}}},N=async i=>{var k;try{const P=await fetch(`/api/seo-redirects/${i.id}`,{method:"PUT",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({isActive:!i.isActive})});if(!P.ok)throw new Error(((k=await P.json())==null?void 0:k.error)||"Update failed");await a()}catch(P){y(P.message)}};return e.jsxs("div",{children:[e.jsxs("div",{className:"mb-6 p-4 border border-border rounded-lg",children:[e.jsx("div",{className:"font-mono text-[10px] uppercase tracking-[0.2em] text-muted-foreground mb-3",children:"New redirect"}),e.jsxs("div",{className:"flex flex-wrap gap-2 items-center",children:[e.jsx("input",{value:r,onChange:i=>c(i.target.value),placeholder:"/old-path or full URL",className:"flex-1 min-w-[200px] px-3 py-2 bg-background border border-border rounded-lg text-sm"}),e.jsx("span",{className:"text-muted-foreground",children:"→"}),e.jsx("input",{value:g,onChange:i=>w(i.target.value),placeholder:"https://cpgio.com/new-path",className:"flex-1 min-w-[200px] px-3 py-2 bg-background border border-border rounded-lg text-sm"}),e.jsxs("select",{value:v,onChange:i=>h(i.target.value),className:"px-3 py-2 bg-background border border-border rounded-lg text-sm",children:[e.jsx("option",{value:"301",children:"301 permanent"}),e.jsx("option",{value:"302",children:"302 temporary"})]}),e.jsx("button",{onClick:o,disabled:m||!r.trim()||!g.trim(),className:"px-4 py-2 border border-primary text-primary text-sm uppercase tracking-[0.14em] font-mono hover:bg-primary hover:text-primary-foreground transition-colors disabled:opacity-50",children:m?"Adding…":"Add"})]})]}),f&&e.jsx("div",{className:"mb-4 p-3 border border-destructive text-destructive text-sm rounded-lg",children:f}),l===null?e.jsx("div",{className:"text-muted-foreground font-mono text-xs uppercase tracking-[0.2em]",children:"Loading…"}):e.jsx("div",{className:"overflow-x-auto border border-border rounded-lg",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-border text-left font-mono text-xs uppercase tracking-[0.14em] text-muted-foreground",children:[e.jsx("th",{className:"px-4 py-3",children:"From"}),e.jsx("th",{className:"px-4 py-3",children:"To"}),e.jsx("th",{className:"px-4 py-3",children:"Type"}),e.jsx("th",{className:"px-4 py-3",children:"Active"})]})}),e.jsxs("tbody",{children:[l.map(i=>e.jsxs("tr",{className:"border-b border-border/50",children:[e.jsx("td",{className:"px-4 py-2 font-mono text-xs",children:i.legacyUrl}),e.jsx("td",{className:"px-4 py-2 font-mono text-xs text-muted-foreground",children:i.targetUrl}),e.jsx("td",{className:"px-4 py-2",children:i.redirectType||"301"}),e.jsx("td",{className:"px-4 py-2",children:e.jsx("button",{onClick:()=>N(i),className:i.isActive?"text-primary hover:underline":"text-muted-foreground hover:underline",children:i.isActive?"active":"off"})})]},i.id)),l.length===0&&e.jsx("tr",{children:e.jsx("td",{className:"px-4 py-6 text-muted-foreground",colSpan:4,children:"No redirects yet."})})]})]})})]})}function G({pageId:l,scheduledAt:j,onChanged:f}){const[y,r]=s.useState(!1),[c,g]=s.useState(""),[w,v]=s.useState(!1),h=async m=>{v(!0);try{const u=await fetch(`/api/ai-pages/${l}/schedule`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({publishAt:m})}),a=await u.json();if(!u.ok)throw new Error((a==null?void 0:a.error)||"Schedule failed");r(!1),f()}catch(u){alert(u.message)}finally{v(!1)}};return j?e.jsxs("span",{className:"inline-flex items-center gap-1 whitespace-nowrap",children:[e.jsxs("span",{className:"px-1.5 py-0.5 text-[10px] uppercase font-mono bg-amber-500/10 text-amber-500 rounded",title:`Publishes ${M(j)}
1`,children:["scheduled ",new Date(j).toLocaleString(void 0,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"})]}),e.jsx("button",{onClick:()=>h(null),disabled:w,title:"Cancel scheduled publish",className:"text-muted-foreground hover:text-destructive text-xs disabled:opacity-50",children:"✕"})]}):y?e.jsxs("span",{className:"inline-flex items-center gap-1 whitespace-nowrap",children:[e.jsx("input",{type:"datetime-local",value:c,onChange:m=>g(m.target.value),className:"px-1 py-0.5 text-xs bg-background border border-border rounded"}),e.jsx("button",{onClick:()=>c&&h(new Date(c).toISOString()),disabled:w||!c,className:"text-primary hover:underline disabled:opacity-50",children:"set"}),e.jsx("button",{onClick:()=>r(!1),className:"text-muted-foreground hover:text-primary",children:"cancel"})]}):e.jsx("button",{onClick:()=>{const m=new Date(Date.now()+864e5);m.setMinutes(0,0,0);const u=a=>String(a).padStart(2,"0");g(`${m.getFullYear()}-${u(m.getMonth()+1)}-${u(m.getDate())}T${u(m.getHours())}:${u(m.getMinutes())}`),r(!0)},className:"text-primary hover:underline",children:"schedule"})}function X(){const[l,j]=s.useState(!1),[f,y]=s.useState(""),[r,c]=s.useState(""),[g,w]=s.useState(""),[v,h]=s.useState(!1),[m,u]=s.useState(null);s.useEffect(()=>{fetch("/api/site-banner").then(o=>o.json()).then(o=>{const N=(o==null?void 0:o.data)||{};j(!!N.enabled),y(N.text||""),c(N.linkLabel||""),w(N.href||"")}).catch(()=>u("Failed to load banner"))},[]);const a=async()=>{h(!0),u(null);try{const o=await fetch("/api/site-banner",{method:"PUT",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({enabled:l,text:f,linkLabel:r,href:g})}),N=await o.json();if(!o.ok)throw new Error((N==null?void 0:N.error)||"Save failed");u(l?"Saved — live within 60 seconds.":"Saved — banner is off.")}catch(o){u(o.message)}finally{h(!1)}};return e.jsxs("div",{className:"max-w-xl border border-border rounded-lg p-6 space-y-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"A slim bar shown at the bottom of every public page (visitors can dismiss it for their session). Changes go live within a minute — no deploy."}),e.jsxs("label",{className:"flex items-center gap-3 text-sm font-medium",children:[e.jsx("input",{type:"checkbox",checked:l,onChange:o=>j(o.target.checked)}),"Banner enabled"]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs uppercase tracking-[0.14em] font-mono text-muted-foreground mb-1",children:"Text (max 200)"}),e.jsx("input",{value:f,onChange:o=>y(o.target.value),maxLength:200,placeholder:"e.g. New: schedule a free Q4 readiness call",className:"w-full px-3 py-2 bg-background border border-border rounded text-sm"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs uppercase tracking-[0.14em] font-mono text-muted-foreground mb-1",children:"Link label"}),e.jsx("input",{value:r,onChange:o=>c(o.target.value),maxLength:60,placeholder:"Book now",className:"w-full px-3 py-2 bg-background border border-border rounded text-sm"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs uppercase tracking-[0.14em] font-mono text-muted-foreground mb-1",children:"Link (/path or https://…)"}),e.jsx("input",{value:g,onChange:o=>w(o.target.value),maxLength:500,placeholder:"/lets-talk",className:"w-full px-3 py-2 bg-background border border-border rounded text-sm"})]})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("button",{onClick:a,disabled:v||l&&!f.trim(),className:"px-4 py-2 border border-primary text-primary text-sm uppercase tracking-[0.14em] font-mono hover:bg-primary hover:text-primary-foreground transition-colors disabled:opacity-50",children:v?"Saving…":"Save banner"}),m&&e.jsx("span",{className:"text-sm text-muted-foreground",children:m})]})]})}function Z(l){return l?new Date(l).toLocaleDateString():"—"}function Ce(){const[l,j]=s.useState([]),[f,y]=s.useState([]),[r,c]=s.useState(!0),[g,w]=s.useState(null),[v,h]=s.useState(null),[m,u]=s.useState(""),[a,o]=s.useState(""),[N,i]=s.useState(!1),[k,P]=J(),$=k.get("tab")||"pages",A=t=>{const x=new URLSearchParams(k);t==="pages"?x.delete("tab"):x.set("tab",t),P(x,{replace:!0})},R=H(),L=s.useCallback(async()=>{c(!0),w(null);try{const[t,x]=await Promise.all([fetch("/api/ai-pages",{credentials:"include"}),fetch("/api/blogs?status=published",{credentials:"include"})]),b=await t.json();if(!t.ok)throw new Error((b==null?void 0:b.error)||"Failed to load CMS pages");j((b==null?void 0:b.data)||[]);const E=await x.json();y(x.ok?(E==null?void 0:E.blogs)||[]:[])}catch(t){w(t instanceof Error?t.message:"Failed to load")}finally{c(!1)}},[]);s.useEffect(()=>{L()},[L]);const C=s.useMemo(()=>{var _;const t=new Map;z.filter(n=>!n.path.includes(":")&&n.path!=="*"&&!n.path.startsWith("/admin")&&n.path!=="/login").forEach(n=>{t.set(n.path,{path:n.path,kind:"static",status:"code",title:n.title})}),l.forEach(n=>{const S=n.routePath||`/p/${n.slug}`,F=!!(n.routePath&&t.has(n.routePath)&&n.status==="published");t.set(S,{path:S,kind:"cms",status:n.status,updatedAt:n.updatedAt,title:n.title,cms:n,overridden:F})}),f.forEach(n=>{const S=`/blog/${n.slug}`;t.has(S)||t.set(S,{path:S,kind:"blog",status:"published",updatedAt:n.updated_at})});const x=Array.from(t.values()).sort((n,S)=>n.path.localeCompare(S.path)),b=new Map;x.forEach(n=>
1{n.cms&&b.set(n.cms.id,n)});const E=new Map,O=[];for(const n of x){const S=(_=n.cms)==null?void 0:_.parentId;S&&b.has(S)?(E.has(S)||E.set(S,[]),E.get(S).push(n)):O.push(n)}const U=[],B=new Set,I=(n,S)=>{if(!B.has(n)&&(B.add(n),n.depth=S,U.push(n),n.cms))for(const F of E.get(n.cms.id)||[])I(F,S+1)};return O.forEach(n=>I(n,0)),U},[l,f]).filter(t=>{var b,E;if(a&&((b=t.cms)==null?void 0:b.category)!==a)return!1;if(!m)return!0;const x=m.toLowerCase();return t.path.includes(m)||(t.title||"").toLowerCase().includes(x)||(((E=t.cms)==null?void 0:E.tags)||[]).some(O=>O.includes(x))}),p=async t=>{if(window.confirm(`Convert ${t} into an editable CMS draft? The live page is untouched until you publish.`)){h(t);try{const x=await fetch("/api/cms/convert",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({path:t})}),b=await x.json();if(!x.ok)throw new Error((b==null?void 0:b.error)||"Convert failed");R(`/admin/ai-page-builder?id=${b.data.pageId}`)}catch(x){alert(`Convert failed: ${x.message}`)}finally{h(null)}}},T=async t=>{if(!t.cms)return;const x=t.status==="published"?"unpublish":"publish";if(!(x==="publish"&&t.cms.routePath&&!window.confirm(`Publish will make this CMS page live at ${t.cms.routePath}, overriding any static page there. Continue?`))){h(t.path);try{const b=await fetch(`/api/ai-pages/${t.cms.id}/${x}`,{method:"POST",credentials:"include"}),E=await b.json();if(!b.ok)throw new Error((E==null?void 0:E.error)||`${x} failed`);await L()}catch(b){alert(`${x} failed: ${b.message}`)}finally{h(null)}}};return e.jsxs("div",{className:"min-h-screen bg-background text-foreground",children:[e.jsx(K,{}),e.jsxs("div",{className:"max-w-6xl mx-auto px-6 pt-[108px] pb-16",children:[e.jsxs("div",{className:"flex items-center justify-between mb-8 flex-wrap gap-4",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs uppercase tracking-[0.2em] font-mono text-muted-foreground mb-2",children:"Admin · Pages"}),e.jsx("h1",{className:"text-3xl font-bold",children:"All Pages"}),e.jsx("p",{className:"text-muted-foreground mt-1",children:"Static routes, CMS pages, and blogs in one table. Publish a CMS page with a route to override the static page; unpublish to instantly restore it."})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>i(!0),"data-testid":"import-design-btn",className:"px-4 py-2 border border-border text-sm uppercase tracking-[0.14em] font-mono hover:border-primary hover:text-primary transition-colors",children:"Import design"}),e.jsx(D,{to:"/admin/ai-page-builder",className:"px-4 py-2 border border-primary text-primary text-sm uppercase tracking-[0.14em] font-mono hover:bg-primary hover:text-primary-foreground transition-colors",children:"New page"})]})]}),e.jsx("div",{className:"flex gap-2 mb-6",children:[{key:"pages",label:"Pages"},{key:"audit",label:"Audit log"},{key:"redirects",label:"Redirects"},{key:"banner",label:"Banner"}].map(t=>e.jsx("button",{onClick:()=>A(t.key),className:`px-4 py-2 text-sm uppercase tracking-[0.14em] font-mono border transition-colors ${$===t.key?"border-primary text-primary":"border-border text-muted-foreground hover:border-primary/50"}`,children:t.label},t.key))}),$==="audit"&&e.jsx(Q,{}),$==="redirects"&&e.jsx(Y,{}),$==="banner"&&e.jsx(X,{}),$==="pages"&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex gap-3 mb-6",children:[e.jsx("input",{value:m,onChange:t=>u(t.target.value),placeholder:"Filter by path, title, or tag…",className:"flex-1 px-4 py-2 bg-background border border-border rounded-lg text-sm"}),e.jsxs("select",{value:a,onChange:t=>o(t.target.value),className:"px-3 py-2 bg-background border border-border rounded-lg text-sm","aria-label":"Filter by category",children:[e.jsx("option",{value:"",children:"All categories"}),["Channels","Solutions","Services","Case Studies","Resources","Company"].map(t=>e.jsx("option",{value:t,children:t},t))]})]}),g&&e.jsx("div",{className:"mb-6 p-4 border border-destructive text-destructive text-sm",children:g}),r?e.jsx("div",{className:"text-muted-foreground font-mono text-xs uppercase tracking-[0.2em]",children:"Loading…"}):e.jsx("div",{className:"overflow-x-auto border border-border rounded-lg",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b border-border text-left font-mono text-xs uppercase tracking-[0.14em] text-muted-foreground",children:[e.jsx("th",{className:"px-4 py-3",children:"Path"}),e.jsx("th",{className:"px-4 py-3",children:"Kind"}),e.jsx("th",{className:"px-4 py-3",children:"Status"}),e.jsx("th",{className:"px-4 py-3",children:"Updated"}),e.jsx("th",{className:"px-4 py-3 text-right",children:"Actions"})]})}),e.jsx("tbody",{children:C.map(t=>{var x;return e.jsxs("tr",{className:"border-b border-border/50 hover:bg-accent/30",children:[e.jsxs("td",{className:"px-4 py-3 font-mono text-xs",children:[t.depth?e.jsx("span",{className:"text-muted-foreground",style:{paddingLeft:(t.depth-1)*16},children:"↳ "}):null,t.path,t.overridden&&e.jsx("span",{className:"ml-2 px-1.5 py-0.5 text-[10px] uppercase bg-primary/10 text-primary rounded",children:"override live"})]}),e.jsxs("td",{className:"px-4 py-3",children:[t.kind,(x=t.cms)!=null&&x.pageKind&&t.cms.pageKind!=="ai"?` · ${t.cms.pageKind}`:""]}),e.jsx("td",{className:"px-4 py-3",children:e.jsx("span",{className:t.
1status==="published"?"text-primary":t.status==="draft"?"text-amber-500":t.status==="in_review"?"text-orange-500 font-semibold":"text-muted-foreground",children:t.status==="in_review"?"in review":t.status})}),e.jsx("td",{className:"px-4 py-3 text-muted-foreground",children:Z(t.updatedAt)}),e.jsxs("td",{className:"px-4 py-3 text-right space-x-3 whitespace-nowrap",children:[t.kind==="cms"&&t.cms&&e.jsxs(e.Fragment,{children:[e.jsx(D,{className:"text-primary hover:underline",to:`/admin/ai-page-builder?id=${t.cms.id}`,children:"Edit"}),e.jsx("a",{className:"text-muted-foreground hover:text-primary",href:`/p/${t.cms.slug}`,target:"_blank",rel:"noreferrer",children:"Preview"}),e.jsx(q,{pageId:t.cms.id,onRestored:L}),t.status==="draft"&&e.jsx(G,{pageId:t.cms.id,scheduledAt:t.cms.scheduledPublishAt,onChanged:L}),e.jsx("button",{onClick:()=>T(t),disabled:v===t.path,className:"text-primary hover:underline disabled:opacity-50",children:t.status==="published"?"Unpublish":t.status==="in_review"?"Approve & publish":"Publish"})]}),t.kind==="static"&&e.jsx("button",{onClick:()=>p(t.path),disabled:v===t.path,className:"text-primary hover:underline disabled:opacity-50",children:v===t.path?"Converting…":"Convert"}),t.kind==="blog"&&e.jsx("a",{className:"text-muted-foreground hover:text-primary",href:t.path,target:"_blank",rel:"noreferrer",children:"Open"})]})]},t.path)})})]})})]})]}),e.jsx(W,{open:N,onClose:()=>i(!1)})]})}export{Ce 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.