1import{r as u,j as e}from"./index-BgbqYyaj.js";import{supabase as n}from"./client-B3XYGzq4.js";import{t as i}from"./index-C-0RxDqw.js";import{M as g}from"./MediaUploader-CeU1q79a.js";import"./tslib.es6-eMSY344_.js";import"./index-CdnAlYtj.js";const m={id:null,name:"",slug:"",role:"",bio:"",avatar_url:"",social_handles:{instagram:"",twitter:"",tiktok:""}};function j(t){return t.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")}function k(){const[t,d]=u.useState([]),[s,l]=u.useState(null);async function c(){const{data:a}=await n.from("authors").select("id, name, slug, role, bio, avatar_url, social_handles, user_id, created_at, updated_at").order("name");d(a??[])}u.useEffect(()=>{c()},[]);async function x(){if(!s)return;const a={...s,slug:s.slug||j(s.name)},o=!a.id;o&&delete a.id;const b=o?n.from("authors").insert(a):n.from("authors").update(a).eq("id",a.id),{error:h}=await b;if(h){i.error(h.message);return}i.success("Saved"),l(null),c()}async function p(a){if(!confirm("Delete this author?"))return;const{error:o}=await n.from("authors").delete().eq("id",a);if(o){i.error(o.message);return}i.success("Deleted"),c()}return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-3",children:[e.jsx("h1",{className:"yh-headline text-4xl",children:"Authors"}),e.jsx("button",{onClick:()=>l({...m}),className:"bg-cobalt text-cobalt-foreground px-4 py-2 yh-eyebrow",children:"+ New author"})]}),e.jsxs("table",{className:"mt-6 w-full border border-border text-sm",children:[e.jsx("thead",{className:"bg-secondary text-left",children:e.jsxs("tr",{children:[e.jsx("th",{className:"p-3",children:"Name"}),e.jsx("th",{className:"p-3",children:"Role"}),e.jsx("th",{})]})}),e.jsxs("tbody",{children:[t.map(a=>e.jsxs("tr",{className:"border-t border-border",children:[e.jsx("td",{className:"p-3",children:e.jsxs("div",{className:"flex items-center gap-2",children:[a.avatar_url&&e.jsx("img",{src:a.avatar_url,alt:"",className:"w-8 h-8 rounded-full object-cover",loading:"lazy",decoding:"async"}),e.jsxs("div",{children:[e.jsx("div",{className:"font-medium",children:a.name}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:["/",a.slug]})]})]})}),e.jsx("td",{className:"p-3 text-muted-foreground",children:a.role??"â"}),e.jsxs("td",{className:"p-3 text-right whitespace-nowrap",children:[e.jsx("button",{onClick:()=>l({...m,...a,social_handles:a.social_handles??{}}),className:"yh-eyebrow text-hotpink mr-3",children:"Edit"}),e.jsx("button",{onClick:()=>p(a.id),className:"yh-eyebrow text-muted-foreground hover:text-destructive",children:"Delete"})]})]},a.id)),t.length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:3,className:"p-6 text-center text-muted-foreground",children:"No authors yet."})})]})]}),s&&e.jsx("div",{className:"fixed inset-0 bg-black/50 z-50 flex items-start justify-center overflow-y-auto p-6",onClick:()=>l(null),children:e.jsxs("div",{className:"bg-background border border-border max-w-2xl w-full p-6 my-10",onClick:a=>a.stopPropagation(),children:[e.jsx("h2",{className:"yh-headline text-2xl mb-4",children:s.id?"Edit author":"New author"}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(r,{label:"Name",children:e.jsx("input",{value:s.name,onChange:a=>l({...s,name:a.target.value}),className:"w-full border border-input p-2"})}),e.jsx(r,{label:"Slug",children:e.jsx("input",{value:s.slug,onChange:a=>l({...s,slug:a.target.value}),className:"w-full border border-input p-2"})}),e.jsx(r,{label:"Role / title",children:e.jsx("input",{value:s.role??"",onChange:a=>l({...s,role:a.target.value}),className:"w-full border border-input p-2",placeholder:"Editor-in-Chief"})}),e.jsx(r,{label:"Avatar",children:e.jsx(g,{value:s.avatar_url,onChange:a=>l({...s,avatar_url:a}),folder:"authors"})}),e.jsx(r,{label:"Bio",children:e.jsx("textarea",{value:s.bio??"",onChange:a=>l({...s,bio:a.target.value}),className:"w-full border border-input p-2",rows:4})}),e.jsxs("div",{className:"grid grid-cols-3 gap-3",children:[e.jsx(r,{label:"Instagram",children:e.jsx("input",{value:s.social_handles?.instagram??"",onChange:a=>l({...s,social_handles:{...s.social_handles,instagram:a.target.value}}),className:"w-full border border-input p-2",placeholder:"@handle"})}),e.jsx(r,{label:"Twitter / X",children:e.jsx("input",{value:s.social_handles?.twitter??"",onChange:a=>l({...s,social_handles:{...s.social_handles,twitter:a.target.value}}),className:"w-full border border-input p-2",placeholder:"@handle"})}),e.jsx(r,{label:"TikTok",children:e.jsx("input",{value:s.social_handles?.tiktok??"",onChange:a=>l({...s,social_handles:{...s.social_handles,tiktok:a.target.value}}),className:"w-full border border-input p-2",placeholder:"@handle"})})]})]}),e.jsxs("div",{className:"mt-6 flex justify-end gap-3",children:[e.jsx("button",{onClick:()=>l(null),className:"border border-foreground px-4 py-2 yh-eyebrow",children:"Cancel"}),e.jsx("button",{onClick:x,className:"bg-cobalt text-cobalt-foreground px-4 py-2 yh-eyebrow",children:"Save"})]})]})})]})}function r({label:t,children:d}){return e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"yh-eyebrow text-muted-foreground text-xs",children:t}),e.jsx("div",{className:"mt-1",children:d})]})}export{k 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.