1import{r as x,j as e}from"./vendor-react-a835ee61.js";import{B as f,j as H,h as v}from"./index-fad5f9b7.js";import{C as d,d as o,a as h,b as u,c as y}from"./card-7581065c.js";import{T,a as D,b as i,c,d as A,e as r}from"./table-b7292837.js";import{T as U,a as z,b as S,c as E}from"./tabs-7ceaeca0.js";import{A as R,a as L,b as k}from"./alert-7790bf1a.js";import{B as O}from"./badge-ff88c681.js";import{a3 as I,R as M,D as $,A as J,z as Y}from"./vendor-icons-11b98caa.js";import"./vendor-supabase-722fbc27.js";import"./vendor-radix-core-99f1042f.js";import"./vendor-radix-primitive-4e369f64.js";import"./vendor-radix-dropdown-menu-86d2342e.js";import"./vendor-radix-menu-7fb79491.js";import"./vendor-radix-tabs-eead257f.js";const ce=()=>{const[_,N]=x.useState(!0),[b,C]=x.useState(null),[a,B]=x.useState({template:[],generic:[]}),g=async()=>{N(!0),C(null);try{const[s,l]=await Promise.all([v.from("template_collection_pages").select("*").order("created_at",{ascending:!1}),v.from("generic_collection_pages").select("*").order("created_at",{ascending:!1})]);if(s.error)throw new Error(`Template Collections: ${s.error.message}`);if(l.error)throw new Error(`Generic Collections: ${l.error.message}`);B({template:s.data||[],generic:l.data||[]})}catch(s){console.error("Error fetching audit data:",s),C(s.message)}finally{N(!1)}};x.useEffect(()=>{g()},[]);const j=(()=>{const s={},l=[],n=(t,m,G)=>{if(!t)return;const p=t.toLowerCase().trim();s[p]||(s[p]=[]),s[p].push({source:m,id:G})};return a.template.forEach(t=>n(t.slug,"Template Collection",t.id)),a.generic.forEach(t=>n(t.slug,"Generic Collection",t.id)),Object.entries(s).forEach(([t,m])=>{m.length>1&&l.push({slug:t,sources:m})}),l})(),P=()=>{const s={timestamp:new Date().toISOString(),summary:{templateCount:a.template.length,genericCount:a.generic.length},conflicts:j,data:a},l=new Blob([JSON.stringify(s,null,2)],{type:"application/json"}),n=URL.createObjectURL(l),t=document.createElement("a");t.href=n,t.download=`collection-audit-${new Date().toISOString().split("T")[0]}.json`,document.body.appendChild(t),t.click(),document.body.removeChild(t),URL.revokeObjectURL(n)},w=s=>s?new Date(s).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}):"N/A";return _?e.jsxs("div",{className:"flex h-[50vh] w-full items-center justify-center flex-col gap-4",children:[e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900"}),e.jsx("p",{className:"text-gray-500",children:"Auditing collection databases..."})]}):b?e.jsx("div",{className:"container mx-auto py-8 max-w-6xl",children:e.jsx(d,{className:"border-red-200 bg-red-50",children:e.jsxs(o,{className:"flex flex-col items-center gap-4 py-8",children:[e.jsx("div",{className:"text-red-600 font-medium text-lg",children:"Audit Failed"}),e.jsx("p",{className:"text-red-500",children:b}),e.jsx("div",{className:"flex gap-4",children:e.jsxs(f,{onClick:g,variant:"outline",className:"gap-2 bg-white hover:bg-red-50",children:[e.jsx(I,{className:"h-4 w-4"})," Retry Audit"]})})]})})}):e.jsxs("div",{className:"container mx-auto py-8 px-4 max-w-7xl space-y-8",children:[e.jsx(H,{children:e.jsx("title",{children:"Collection Audit | Admin"})}),e.jsxs("div",{className:"flex flex-col md:flex-row items-start md:items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold tracking-tight",children:"Collection Audit"}),e.jsx("p",{className:"text-muted-foreground mt-1",children:"Diagnostic tool for tracking all collection page data sources and detecting conflicts."})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(f,{variant:"outline",onClick:g,className:"gap-2",children:[e.jsx(M,{className:"h-4 w-4"})," Refresh Data"]}),e.jsxs(f,{variant:"default",onClick:P,className:"gap-2",children:[e.jsx($,{className:"h-4 w-4"})," Export JSON"]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-2 gap-4",children:[e.jsxs(d,{children:[e.jsx(h,{className:"pb-2",children:e.jsx(u,{className:"text-sm font-medium text-muted-foreground",children:"Template Collections"})}),e.jsxs(o,{children:[e.jsx("div",{className:"text-2xl font-bold",children:a.template.length}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Active Dynamic Pages"})]})]}),e.jsxs(d,{children:[e.jsx(h,{className:"pb-2",children:e.jsx(u,{className:"text-sm font-medium text-muted-foreground",children:"Generic Collections"})}),e.jsxs(o,{children:[e.jsx("div",{className:"text-2xl font-bold",children:a.generic.length}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Legacy Dynamic Pages"})]})]})]}),j.length>0?e.jsxs(R,{variant:"destructive",children:[e.jsx(J,{className:"h-4 w-4"}),e.jsx(L,{children:"Slug Conflicts Detected"}),e.jsxs(k,{children:[e.jsx("div",{className:"mt-2 text-sm",children:"The following slugs appear in multiple tables, which may cause routing issues:"}),e.jsx("ul",{className:"list-disc list-inside mt-2 space-y-1",children:j.map((s,l)=>e.jsxs("li",{children:[e.jsx("span",{className:"font-bold font-mono",children:s.slug})," found in: "," ",s.sources.map((n,t)=>e.jsxs("span",{children:[n.source," (",n.id,")",t<s.sources.length-1?", ":""]},t))]},l))})]})]}):e.jsxs(R,{className:"bg-green-50 border-green-200 text-green-800",children:[e.jsx(Y,{className:"h-4 w-4 text-green-600"}),e.jsx(L,{className:"text-green-800",children:"Healthy Database"}),e.jsx(k,{className:"text-green-700",children:"No slug conflicts detected. Legacy tables (SQ, Yuno, Yuno Kontur) have been removed."})]}),e.jsxs(U,{defaultValue:"template",className:"w-full",children:[e.jsxs(z,{className:"grid w-full grid-cols-2 bg-muted/50 p-1",children:[e.jsxs(S,{value:"template",children:["Template (",a.template.length,")"]}),e.jsxs(S,{value:"generic",children:["Generic (",a.generic.length,")"]})]}),e.jsx(E,{value:"template",className:"mt-6",children:e.jsxs(d,{children:[e.jsxs(h,{children:[e.jsx(u,{children:"Template Collection Pages"}),e.jsx(y,{children:"Modern template-based collection pages managed via Admin"})]}),e.jsx(o,{children:e.jsxs(T,{children:[e.jsx(D,{children:e.jsxs(i,{children:[e.jsx(c,{className:"w-[100px]",children:"ID"}),e.jsx(c,{children:"Title"}),e.jsx(c,{children:"Slug"}),e.jsx(c,{children:"Created At"})]})}),e.jsx(A,{children:a.template.length===0?e.jsx(i,{children:e.jsx(r,{colSpan:4,className:"text-center text-muted-foreground h-24",children:"No records foun
1d"})}):a.template.map(s=>e.jsxs(i,{children:[e.jsx(r,{className:"font-mono text-xs text-muted-foreground truncate max-w-[100px]",children:s.id}),e.jsx(r,{className:"font-medium",children:s.title}),e.jsx(r,{children:e.jsx(O,{variant:"outline",children:s.slug})}),e.jsx(r,{className:"text-muted-foreground text-sm",children:w(s.created_at)})]},s.id))})]})})]})}),e.jsx(E,{value:"generic",className:"mt-6",children:e.jsxs(d,{children:[e.jsxs(h,{children:[e.jsx(u,{children:"Generic Collection Pages"}),e.jsx(y,{children:"Older generic layout pages"})]}),e.jsx(o,{children:e.jsxs(T,{children:[e.jsx(D,{children:e.jsxs(i,{children:[e.jsx(c,{className:"w-[100px]",children:"ID"}),e.jsx(c,{children:"Title"}),e.jsx(c,{children:"Slug"}),e.jsx(c,{children:"Created At"})]})}),e.jsx(A,{children:a.generic.length===0?e.jsx(i,{children:e.jsx(r,{colSpan:4,className:"text-center text-muted-foreground h-24",children:"No records found"})}):a.generic.map(s=>e.jsxs(i,{children:[e.jsx(r,{className:"font-mono text-xs text-muted-foreground truncate max-w-[100px]",children:s.id}),e.jsx(r,{className:"font-medium",children:s.title}),e.jsx(r,{children:e.jsx(O,{variant:"outline",children:s.slug})}),e.jsx(r,{className:"text-muted-foreground text-sm",children:w(s.created_at)})]},s.id))})]})})]})})]})]})};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.