1import{a as l,j as e}from"./vendor-markdown-BF0EtLsy.js";import{u as i}from"./useServerFn-C99mNZR9.js";import{c as m,r as u,a as x,T,H as v,t as n}from"./index-DwlT11K4.js";import{B as N}from"./badge-CWI6k8s9.js";import{G as _}from"./gavel-BHokVQUw.js";import{L as w}from"./loader-circle-6EeRh21H.js";import{R as $}from"./refresh-ccw-z1IG1NHV.js";import{H as E}from"./history-BWAPsnAv.js";import{U as P}from"./undo-2-CU9OJ0TN.js";import"./vendor-charts-CsXlYAGE.js";import"./vendor-supabase-BlA_S1Sg.js";const B=m({method:"GET"}).middleware([u]).handler(x("b8b3b0069a2566f98eddde3ca20188e30c23ba0070c7390654a2120df54503fd")),D=m({method:"POST"}).middleware([u]).handler(x("69a911c16c6cc7420149ce5cc7170bbbf89635e65f9269ab9b47b2020e47bcbd")),G=m({method:"POST"}).middleware([u]).handler(x("9e123baa4dc268b33004e05abac0d1a0f572c8c13c052ece471ebe5fd87d3fa5")),O={disclaimer:"Disclaimer",privacy:"Privacy Policy",terms:"Terms & Conditions"},d={disclaimer:"/disclaimer",privacy:"/privacy",terms:"/terms"};function F(c=new Date){return c.getFullYear()}const H={in_sync:"Matches site",out_of_date:"Out of date",year_stale:"Copyright year stale",unmapped:"Course-only document"};function Z(){const c=i(B),S=i(D),L=i(G),[h,p]=l.useState(!1),[r,k]=l.useState(""),[f,g]=l.useState(null),{data:t,isLoading:C,error:b,refetch:y}=T({queryKey:["admin","legal-sync"],queryFn:()=>c({})}),j=(t?.lessons??[]).filter(s=>s.status!=="in_sync"&&s.status!=="unmapped");async function R(){p(!0);try{const s=await S({});n.success(`Synced ${s.updated} of ${s.checked} legal lessons`),await y()}catch(s){n.error(s instanceof Error?s.message:"Sync failed")}finally{p(!1)}}async function A(s,o){if(confirm(`Restore legal lessons in ${r||"every course"} to version ${o}?`)){g(s);try{const a=await L({data:{versionId:s,productSlug:r||null}});n.success(`Rolled back ${a.updated} lesson(s) in ${a.productSlug}`),await y()}catch(a){n.error(a instanceof Error?a.message:"Rollback failed")}finally{g(null)}}}return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(_,{className:"h-5 w-5 text-primary","aria-hidden":!0}),e.jsx("h1",{className:"text-2xl font-bold uppercase tracking-wide",children:"Legal sync"})]}),e.jsxs(v,{onClick:R,disabled:h,children:[h?e.jsx(w,{className:"h-4 w-4 animate-spin"}):e.jsx($,{className:"h-4 w-4"})," Sync courses now"]})]}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"The website pages are the source of truth. A nightly job (05:10 UTC) copies the current Disclaimer, Privacy Policy and Terms & Conditions into the Legal Agreement section of every course, and refreshes the copyright year and âAll rights reservedâ wording on the remaining legal lessons. Publishing a change to a legal page makes the next run rewrite every course automatically â press the button above if you want it immediately."}),e.jsx("div",{className:"grid gap-3 md:grid-cols-3",children:(t?.docs??[]).map(s=>e.jsxs("a",{href:d[s],target:"_blank",rel:"noreferrer",className:"border-2 border-border bg-card/40 p-4 hover:border-primary",children:[e.jsx("div",{className:"font-bold",children:O[s]}),e.jsx("div",{className:"text-xs text-muted-foreground",children:d[s]})]},s))}),e.jsxs("div",{className:"border-2 border-border bg-card/40 p-4 text-sm",children:[e.jsxs("div",{children:["Copyright year in use: ",e.jsx("span",{className:"font-bold",children:t?.year??F()})," · content version"," ",e.jsx("span",{className:"font-mono text-xs",children:t?.version??"â"})]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["Last run: ",t?.lastRunAt?new Date(t.lastRunAt).toLocaleString():"never",t?.lastRun?.updated!==void 0&&` · ${t.lastRun.updated} lesson(s) rewritten`]})]}),C&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"Loadingâ¦"}),b&&e.jsx("p",{className:"text-sm text-destructive",children:b.message}),e.jsxs("section",{className:"space-y-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[e.jsxs("h2",{className:"flex items-center gap-2 text-sm font-bold uppercase tracking-[0.2em] text-muted-foreground",children:[e.jsx(E,{className:"h-4 w-4","aria-hidden":!0})," Version history"]}),e.jsxs("label",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:["Roll back scope",e.jsxs("select",{value:r,onChange:s=>k(s.target.value),className:"border-2 border-border bg-background px-2 py-1 text-xs text-foreground",children:[e.jsx("option",{value:"",children:"All courses"}),(t?.products??[]).map(s=>e.jsx("option",{value:s,children:s},s))]})]})]}),e.jsxs("div",{className:"space-y-2",children:[(t?.versions??[]).map((s,o)=>e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 border-2 border-border bg-card/40 p-3",children:[e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center gap-2 font-semibold",children:[e.jsx("span",{className:"font-mono text-xs",children:s.version}),o===0&&e.jsx(N,{variant:"default",children:"Current"})]}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[new Date(s.created_at).toLocaleStr
1ing()," · © ",s.year,s.note&&` · ${s.note}`]})]}),e.jsxs(v,{variant:"outline",size:"sm",disabled:f!==null,onClick:()=>A(s.id,s.version),children:[f===s.id?e.jsx(w,{className:"h-4 w-4 animate-spin"}):e.jsx(P,{className:"h-4 w-4"}),"Roll back"]})]},s.id)),t&&t.versions.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"No snapshots yet â the first snapshot is stored the next time a sync runs."})]})]}),e.jsxs("h2",{className:"text-sm font-bold uppercase tracking-[0.2em] text-muted-foreground",children:["Course legal lessons ",j.length>0&&`(${j.length} need updating)`]}),e.jsxs("div",{className:"space-y-2",children:[(t?.lessons??[]).map(s=>e.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3 border-2 border-border bg-card/40 p-3",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold",children:s.lessonTitle}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[s.productSlug," · /",s.lessonSlug,s.doc&&` · mirrors ${d[s.doc]}`]})]}),e.jsx(N,{variant:s.status==="in_sync"?"default":s.status==="unmapped"?"secondary":"destructive",children:H[s.status]})]},s.lessonId)),t&&t.lessons.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"No legal sections found on any course."})]})]})}export{Z as component};
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.