1import{r as n,j as s,N as E}from"./vendor-react-d7uO_bRh.js";import{u as Q,b as L,L as u,a8 as Y,a5 as J,B as o,a9 as V,I as c,aj as O,A as W,T as D,ae as K,v as X,z as Z,s as l,t as i}from"./index-TIWzsFsZ.js";import{S as ee}from"./SEO-CMc31L76.js";import{BackToAdminButton as se}from"./BackToAdminButton-SjEvmdaV.js";import{G as te}from"./GeoQuickNav-CqLCNkqh.js";import{R as re}from"./refresh-cw-DFb_Okt4.js";import{C as ae}from"./chevron-down-FeVq52bi.js";import"./arrow-left-DdVNaQzL.js";import"./scan-search-L7bl5RoV.js";import"./chart-column-DZlYiA1D.js";const b='"Cormorant Garamond", "Playfair Display", Georgia, serif';function ie(d){return d.replace(/_/g," ").replace(/\b\w/g,j=>j.toUpperCase())}function he(){const{user:d,loading:j}=Q(),[p,f]=n.useState([]),[C,h]=n.useState([]),[y,S]=n.useState(!0),[g,v]=n.useState(null),[k,R]=n.useState(!1),[N,P]=n.useState(!1),[A,I]=n.useState("");async function z(){S(!0);const[e,t]=await Promise.all([l.from("llms_txt_overrides").select("*").order("sort_order",{ascending:!0}).order("section",{ascending:!0}),l.from("llms_key_works").select("*").order("sort_order",{ascending:!0})]);e.error?i({title:"Failed to load overrides",description:e.error.message,variant:"destructive"}):f(e.data??[]),t.error?i({title:"Failed to load key works",description:t.error.message,variant:"destructive"}):h(t.data??[]),S(!1)}n.useEffect(()=>{d&&z()},[d==null?void 0:d.id]);const w=n.useMemo(()=>[...p].sort((t,r)=>(t.sort_order??0)-(r.sort_order??0)||t.section.localeCompare(r.section)).map(t=>`## ${ie(t.section)} 2 3${t.content.trim()}`).join(` 4 5`),[p]);if(j)return s.jsx(L,{children:s.jsx("div",{className:"flex items-center justify-center py-24",children:s.jsx(u,{className:"h-6 w-6 animate-spin text-muted-foreground"})})});if(!d)return s.jsx(E,{to:Y(),replace:!0});if(!J(d))return s.jsx(E,{to:"/",replace:!0});function _(e,t){f(r=>r.map(a=>a.id===e?{...a,...t}:a))}async function T(e){v(e.id);const{error:t}=await l.from("llms_txt_overrides").update({content:e.content,sort_order:e.sort_order,section:e.section,updated_at:new Date().toISOString()}).eq("id",e.id);v(null),t?i({title:"Save failed",description:t.message,variant:"destructive"}):i({title:"Saved",description:e.section})}async function F(e){if(!confirm("Delete this section?"))return;const{error:t}=await l.from("llms_txt_overrides").delete().eq("id",e);if(t){i({title:"Delete failed",description:t.message,variant:"destructive"});return}f(r=>r.filter(a=>a.id!==e)),i({title:"Deleted"})}async function q(){const e=A.trim().toLowerCase().replace(/[^a-z0-9_]+/g,"_");if(!e){i({title:"Section name required",variant:"destructive"});return}const t=(p.reduce((x,H)=>Math.max(x,H.sort_order??0),0)||0)+10,{data:r,error:a}=await l.from("llms_txt_overrides").insert({section:e,content:"",sort_order:t}).select().single();if(a){i({title:"Create failed",description:a.message,variant:"destructive"});return}f(x=>[...x,r]),I(""),i({title:"Section added",description:e})}async function M(){R(!0);try{const{error:e}=await l.functions.invoke("generate-static-semantic-files",{});if(e)throw e;i({title:"AI files regenerated",description:"llms.txt, llms-full.txt and related files updated."})}catch(e){const t=e instanceof Error?e.message:"Unknown error";i({title:"Regenerate failed",description:t,variant:"destructive"})}finally{R(!1)}}async function B(){try{await navigator.clipboard.writeText(w),i({title:"Copied to clipboard"})}catch{i({title:"Copy failed",variant:"destructive"})}}function m(e,t){h(r=>r.map(a=>a.id===e?{...a,...t}:a))}async function G(e){v(e.id);const{error:t}=await l.from("llms_key_works").update({edition_id:e.edition_id,edition_slug:e.edition_slug,title:e.title,year:e.year,one_liner:e.one_liner,sort_order:e.sort_order,is_pinned:e.is_pinned}).eq("id",e.id);v(null),t?i({title:"Save failed",description:t.message,variant:"destructive"}):i({title:"Saved",description:e.title})}async function $(e){if(!confirm("Remove this key work?"))return;const{error:t}=await l.from("llms_key_works").delete().eq("id",e);if(t){i({title:"Delete failed",description:t.message,variant:"destructive"});return}h(r=>r.filter(a=>a.id!==e))}async function U(){const e=(C.reduce((a,x)=>Math.max(a,x.sort_order??0),0)||0)+10,{data:t,error:r}
5=await l.from("llms_key_works").insert({edition_id:"",edition_slug:"",title:"New work",one_liner:"",sort_order:e,is_pinned:!1}).select().single();if(r){i({title:"Create failed",description:r.message,variant:"destructive"});return}h(a=>[...a,t])}return s.jsxs(L,{children:[s.jsx(ee,{title:"llms.txt Editor â Admin",description:"Edit AI-readable site overrides.",noIndex:!0}),s.jsx(se,{}),s.jsxs("div",{className:"container mx-auto px-4 py-8 space-y-6 max-w-4xl",children:[s.jsx(te,{}),s.jsxs("div",{className:"flex items-end justify-between gap-4 flex-wrap",children:[s.jsxs("div",{children:[s.jsx("h1",{className:"text-4xl tracking-tight",style:{fontFamily:b},children:"llms.txt Editor"}),s.jsxs("p",{className:"text-muted-foreground mt-1 text-sm",children:["Editable sections that feed ",s.jsx("code",{className:"text-xs",children:"llms.txt"})," and related AI-readable files."]})]}),s.jsxs("div",{className:"flex gap-2",children:[s.jsxs(o,{variant:"ghost",size:"sm",onClick:z,disabled:y,children:[s.jsx(re,{className:`h-4 w-4 mr-2 ${y?"animate-spin":""}`}),"Refresh"]}),s.jsxs(o,{onClick:M,disabled:k,children:[k?s.jsx(u,{className:"h-4 w-4 mr-2 animate-spin"}):s.jsx(V,{className:"h-4 w-4 mr-2"}),"Regenerate AI files"]})]})]}),y?s.jsx("div",{className:"flex justify-center py-12",children:s.jsx(u,{className:"h-6 w-6 animate-spin text-muted-foreground"})}):s.jsxs("div",{className:"space-y-4",children:[p.map(e=>{var t;return s.jsxs("section",{className:"rounded-lg border border-border bg-card p-4 space-y-3",children:[s.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[s.jsx(c,{value:e.section,onChange:r=>_(e.id,{section:r.target.value}),className:"font-mono text-sm max-w-xs",placeholder:"section_key"}),s.jsx("label",{className:"text-xs text-muted-foreground",children:"Order"}),s.jsx(c,{type:"number",value:e.sort_order??0,onChange:r=>_(e.id,{sort_order:Number(r.target.value)||0}),className:"w-20"}),s.jsxs("span",{className:"text-xs text-muted-foreground ml-auto",children:[((t=e.content)==null?void 0:t.length)??0," chars"]}),s.jsxs(o,{size:"sm",onClick:()=>T(e),disabled:g===e.id,children:[g===e.id?s.jsx(u,{className:"h-4 w-4 mr-1 animate-spin"}):s.jsx(O,{className:"h-4 w-4 mr-1"}),"Save"]}),s.jsx(o,{size:"sm",variant:"ghost",onClick:()=>F(e.id),children:s.jsx(W,{className:"h-4 w-4"})})]}),s.jsx(D,{value:e.content??"",onChange:r=>_(e.id,{content:r.target.value}),rows:Math.min(20,Math.max(6,(e.content??"").split(` 6`).length+1)),className:"font-mono text-sm"})]},e.id)}),s.jsxs("section",{className:"rounded-lg border border-dashed border-border p-4 flex items-center gap-2 flex-wrap",children:[s.jsx(c,{placeholder:"new_section_key",value:A,onChange:e=>I(e.target.value),className:"font-mono text-sm max-w-xs"}),s.jsxs(o,{size:"sm",onClick:q,children:[s.jsx(K,{className:"h-4 w-4 mr-1"}),"Add section"]})]})]}),s.jsxs("section",{className:"rounded-lg border border-border bg-card p-4 space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2 flex-wrap",children:[s.jsxs("div",{children:[s.jsx("h2",{className:"text-2xl tracking-tight",style:{fontFamily:b},children:"Key Works"}),s.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["The flagship list rendered in ",s.jsx("code",{children:"## Key Works"}),". Keep to ~15."]})]}),s.jsxs(o,{size:"sm",onClick:U,children:[s.jsx(K,{className:"h-4 w-4 mr-1"}),"Add work"]})]}),s.jsx("div",{className:"space-y-3",children:C.map(e=>s.jsxs("div",{className:"rounded border border-border/60 p-3 space-y-2",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(c,{value:e.title,onChange:t=>m(e.id,{title:t.target.value}),placeholder:"Title",className:"max-w-xs"}),s.jsx(c,{value:e.year??"",onChange:t=>m(e.id,{year:t.target.value||null}),placeholder:"Year",className:"w-24"}),s.jsx(c,{value:e.edition_slug,onChange:t=>m(e.id,{edition_slug:t.target.value}),placeholder:"edition-slug",className:"font-mono text-xs max-w-xs"}),s.jsx(c,{type:"number",value:e.sort_order,onChange:t=>m(e.id,{sort_order:Number(t.target.value)||0}),className:"w-20"}),s.jsxs("label",{className:"flex items-center gap-1 text-xs",children:[s.jsx("input",{type:"checkbox",checked:e.is_pinned,onChange:t=>m(e.id,{is_pinned:t.target.checked})}),"Pinned"]}),s.jsxs("div",{className:"ml-auto flex gap-1",children:[s.jsxs(o,{size:"sm",onClick:()=>G(e),disabled:g===e.id,children:[g===e.id?s.jsx(u,{className:"h-4 w-4 mr-1 animate-spin"}):s.jsx(O,{className:"h-4 w-4 mr-1"}),"Save"]}),s.jsx(o,{size:"sm",variant:"ghost",onClick:()=>$(e.id),children:s.jsx(W,{className:"h-4 w-4"})})]})]}),s.jsx(D,{value:e.one_liner,onChange:t=>m(e.id,{one_liner:t.target.value}),rows:2,placeholder:"One-sentence description for AI citation",className:"text-sm"}),s.jsxs("div",{className:"text-xs text-muted-foreground font-mono",children:["edition_id: ",e.edition_id||"(none â set this if you change the slug)"]})]},e.id))})]}),s.jsxs("section",{className:"rounded-lg border border-border bg-card",children:[s.jsxs("button",{onClick:()=>P(e=>!e),className:"w-full flex items-center justify-between gap-2 p-4 text-left",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[N?s.jsx(ae,{className:"h-4 w-4"}):s.jsx(X,{className:"h-4 w-4"}),s.jsx("span",{style:{fontFamily:b},className:"text-lg",children:"Preview"}),s.jsxs("span",{className:"text-xs text-muted-foreground",children:["(",w.length," chars)"]})]}),N&&s.jsxs(o,{size:"sm",variant:"ghost",onClick:e=>{e.stopPropagation(),B()},children:[s.jsx(Z,{className:"h-4 w-4 mr-1"}),"Copy"]})]}),N&&s.jsx("pre",{className:"px-4 pb-4 text-xs whitespace-pre-wrap font-mono max-h-[60vh] overflow-y-auto border-t border-border pt-3",children:w||"(empty)"})]})]})]})}export{he 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.