1import{g as w,r as o,j as e,c as j,P as I,l as R,m as B,n as U,s as u,X as q,C as O}from"./index-Be_2bHJP.js";import{B as m}from"./button-BlG-9S0h.js";import{P as V,a as $,b as H,C as F,f as G}from"./popover-KytfA0IP.js";import{C as _}from"./calendar-Dx13B1N8.js";import{P as W}from"./plus-IV4fWgEX.js";import{P as X,T as J}from"./trash-2-dik4pVU8.js";import"./chevron-left-BZy9fw63.js";import"./chevron-right-CG6ZPdFS.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const K=w("ChevronUp",[["path",{d:"m18 15-6-6-6 6",key:"153udz"}]]);/** 7 * @license lucide-react v0.462.0 - ISC 8 * 9 * This source code is licensed under the ISC license. 10 * See the LICENSE file in the root directory of this source tree. 11 */const Q=w("LogOut",[["path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4",key:"1uf3rs"}],["polyline",{points:"16 17 21 12 16 7",key:"1gabdz"}],["line",{x1:"21",x2:"9",y1:"12",y2:"12",key:"1uyos4"}]]);/** 12 * @license lucide-react v0.462.0 - ISC 13 * 14 * This source code is licensed under the ISC license. 15 * See the LICENSE file in the root directory of this source tree. 16 */const Y=w("Save",[["path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z",key:"1c8476"}],["path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7",key:"1ydtos"}],["path",{d:"M7 3v4a1 1 0 0 0 1 1h7",key:"t51u73"}]]),x=o.forwardRef(({className:n,type:c,...i},v)=>e.jsx("input",{type:c,className:j("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",n),ref:v,...i}));x.displayName="Input";const h=o.forwardRef(({className:n,...c},i)=>e.jsx("textarea",{className:j("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm r
16ing-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",n),ref:i,...c}));h.displayName="Textarea";var Z="Label",A=o.forwardRef((n,c)=>e.jsx(I.label,{...n,ref:c,onMouseDown:i=>{var f;i.target.closest("button, input, select, textarea")||((f=n.onMouseDown)==null||f.call(n,i),!i.defaultPrevented&&i.detail>1&&i.preventDefault())}}));A.displayName=Z;var z=A;const ee=R("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"),d=o.forwardRef(({className:n,...c},i)=>e.jsx(z,{ref:i,className:j(ee(),n),...c}));d.displayName=z.displayName;const E=["nl","fr","de","it","es","pt","ar"],te={slug:"",title:"",date:new Date().toISOString().split("T")[0],categories:[],excerpt:"",image:"",content:"",translations:{}},ce=()=>{const[n,c]=o.useState(null),[i,v]=o.useState(!0),[f,P]=o.useState([]),[s,l]=o.useState(null),[b,T]=o.useState(!1),[C,k]=o.useState(!1),{toast:g}=B();U(),o.useEffect(()=>{u.auth.getSession().then(({data:{session:a}})=>{c(a),v(!1)});const{data:{subscription:t}}=u.auth.onAuthStateChange((a,r)=>{c(r)});return()=>t.unsubscribe()},[]),o.useEffect(()=>{n&&y()},[n]);const y=async()=>{const{data:t}=await u.from("articles").select("*").order("date",{ascending:!1});P(t||[])},L=async t=>{t.preventDefault();const a=new FormData(t.currentTarget),{error:r}=await u.auth.signInWithPassword({email:a.get("email"),password:a.get("password")});r&&g({title:"Login failed",description:r.message,variant:"destructive"})},D=async()=>{if(!s)return;k(!0);const t=s.excerpt.trim()?s.excerpt:s.content.replace(/[#*_`>\[\]!\-]/g," ").replace(/\s+/g," ").trim().slice(0,200)+"...",a={slug:s.slug,title:s.title,date:s.date,categories:s.categories,excerpt:t,image:s.image,content:s.content,translations:s.translations};let r;s.id?{error:r}=await u.from("articles").update(a).eq("id",s.id):{error:r}=await u.from("articles").insert(a),k(!1),r?g({title:"Error saving",description:r.message,variant:"destructive"}):(g({title:"Article saved"}),l(null),y())},M=async t=>{if(!confirm("Are you sure you want to delete this article?"))return;const{error:a}=await u.from("articles").delete().eq("id",t);a?g({title:"Error",description:a.message,variant:"destructive"}):(g({title:"Article deleted"}),y())},N=(t,a,r)=>{s&&l({...s,translations:{...s.translations,[t]:{...s.translations[t]||{title:"",excerpt:"",content:""},[a]:r}}})};return i?e.jsx("div",{className:"min-h-screen flex items-center justify-center",children:"Loading..."}):n?s?e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsxs("div",{className:"border-b border-border px-6 py-4 flex items-center justify-between",children:[e.jsx("h1",{className:"text-xl font-bold",children:s.id?"Edit Article":"New Article"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(m,{variant:"outline",onClick:()=>l(null),children:[e.jsx(q,{size:16,className:"mr-1"})," Cancel"]}),e.jsxs(m,{onClick:D,disabled:C,children:[e.jsx(Y,{size:16,className:"mr-1"})," ",C?"Saving...":"Save"]})]})]}),e.jsxs("div",{className:"max-w-4xl mx-auto p-6 space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(d,{children:"Slug (auto-generated from title)"}),e.jsx(x,{value:s.slug,onChange:t=>l({...s,slug:t.target.value}),placeholder:"auto-generated-slug"})]}),e.jsxs("div",{children:[e.jsx(d,{children:"Date"}),e.jsxs(V,{children:[e.jsx($,{asChild:!0,children:e.jsxs(m,{variant:"outline",className:j("w-full justify-start text-left font-normal",!s.date&&"text-muted-foreground"),children:[e.jsx(_,{className:"mr-2 h-4 w-4"}),s.date?s.date:e.jsx("span",{children:"Pick a date"})]})}),e.jsx(H,{className:"w-auto p-0",align:"start",children:e.jsx(F,{mode:"single",selected:(()=>{if(!s.date)return;const t=s.date.match(/^(\d{2})-(\d{2})-(\d{4})$/);if(t)return new Date(Number(t[3]),Number(t[2])-1,Number(t[1]));const a=Date.parse(s.date);return Number.isNaN(a)?void 0:new Date(a)})(),onSelect:t=>{t&&l({...s,date:G(t,"dd-MM-yyyy")})},initialFocus:!0,className:j("p-3 pointer-events-auto")})})]})]})]}),e.jsxs("div",{children:[e.jsx(d,{children:"Title (English)"}),e.jsx(x,{value:s.title,onChange:t=>{const a=t.target.value,r=a.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"");l({...s,title:a,slug:r})}})]}),e.jsxs("div",{children:[e.jsx(d,{children:"Categories (comma-separated)"}),e.jsx(x,{value:s.categories.join(", "),onChange:t=>l({...s,categories:t.target.value.split(",").map(a=>
16a.trim()).filter(Boolean)})})]}),e.jsxs("div",{children:[e.jsx(d,{children:"Image URL"}),e.jsx(x,{value:s.image,onChange:t=>l({...s,image:t.target.value})})]}),e.jsxs("div",{children:[e.jsx(d,{children:"Excerpt (English) â auto-generated from content if left empty"}),e.jsx(h,{value:s.excerpt,onChange:t=>l({...s,excerpt:t.target.value}),rows:3})]}),e.jsxs("div",{children:[e.jsx(d,{children:"Content (English, Markdown)"}),e.jsx(h,{value:s.content,onChange:t=>l({...s,content:t.target.value}),rows:16,className:"font-mono text-sm"})]}),e.jsxs("div",{className:"border border-border rounded-lg",children:[e.jsxs("button",{type:"button",onClick:()=>T(!b),className:"w-full flex items-center justify-between px-4 py-3 text-sm font-semibold",children:["Translations (",E.length," languages)",b?e.jsx(K,{size:16}):e.jsx(O,{size:16})]}),b&&e.jsx("div",{className:"border-t border-border p-4 space-y-6",children:E.map(t=>{var a,r,S;return e.jsxs("div",{className:"space-y-3",children:[e.jsx("h3",{className:"font-semibold text-sm uppercase tracking-wider text-muted-foreground",children:t.toUpperCase()}),e.jsxs("div",{children:[e.jsx(d,{children:"Title"}),e.jsx(x,{value:((a=s.translations[t])==null?void 0:a.title)||"",onChange:p=>N(t,"title",p.target.value)})]}),e.jsxs("div",{children:[e.jsx(d,{children:"Excerpt"}),e.jsx(h,{value:((r=s.translations[t])==null?void 0:r.excerpt)||"",onChange:p=>N(t,"excerpt",p.target.value),rows:2})]}),e.jsxs("div",{children:[e.jsx(d,{children:"Content (Markdown)"}),e.jsx(h,{value:((S=s.translations[t])==null?void 0:S.content)||"",onChange:p=>N(t,"content",p.target.value),rows:8,className:"font-mono text-sm"})]})]},t)})})]})]})]}):e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsxs("div",{className:"border-b border-border px-6 py-4 flex items-center justify-between",children:[e.jsx("h1",{className:"text-xl font-bold",children:"Blog Admin"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(m,{variant:"outline",onClick:()=>l({...te}),children:[e.jsx(W,{size:16,className:"mr-1"})," New Article"]}),e.jsx(m,{variant:"ghost",size:"icon",onClick:()=>u.auth.signOut(),children:e.jsx(Q,{size:16})})]})]}),e.jsx("div",{className:"max-w-4xl mx-auto p-6",children:f.length===0?e.jsx("p",{className:"text-center text-muted-foreground py-20",children:"No articles yet. Create your first one!"}):e.jsx("div",{className:"space-y-2",children:f.map(t=>e.jsxs("div",{className:"flex items-center justify-between border border-border rounded-lg px-4 py-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"font-medium truncate",children:t.title}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[t.date," · ",t.slug]})]}),e.jsxs("div",{className:"flex gap-1 ml-4",children:[e.jsx(m,{variant:"ghost",size:"icon",onClick:()=>l(t),children:e.jsx(X,{size:14})}),e.jsx(m,{variant:"ghost",size:"icon",onClick:()=>M(t.id),children:e.jsx(J,{size:14})})]})]},t.id))})})]}):e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-background p-6",children:e.jsxs("form",{onSubmit:L,className:"w-full max-w-sm space-y-4",children:[e.jsx("h1",{className:"text-2xl font-bold text-center",children:"Blog Admin"}),e.jsx(x,{name:"email",type:"email",placeholder:"Email",required:!0}),e.jsx(x,{name:"password",type:"password",placeholder:"Password",required:!0}),e.jsx(m,{type:"submit",className:"w-full",children:"Sign In"})]})})};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.