1import{f as M,r as u,t as m,q as x,j as e,a$ as z,L as j,B as r,a8 as S,aU as k,w as A,am as L,as as p,a9 as O,a1 as $,X as Q}from"./index-cscxoOf9.js";import{B as R}from"./badge-Dj3athcC.js";import{A as U}from"./arrow-left-B9FPhhoq.js";import{R as P}from"./refresh-cw-D0KbhpJJ.js";import{P as _}from"./pen-CKbaVb_W.js";import{E as q}from"./eye-off-D09UZXKp.js";import{C as J}from"./chevron-up-BeQs4DJL.js";import{S as Y}from"./save-3ybFAjJw.js";import{S as H}from"./send-DI6AmIeV.js";const V=["guide","consigli","sicurezza","citta","notizie","lifestyle"],X={guide:"Guide",consigli:"Consigli",sicurezza:"Sicurezza",citta:"Città ",notizie:"Notizie",lifestyle:"Lifestyle"},K={draft:"bg-[#C28B2C]/20 text-[#C28B2C] border-[#C28B2C]/30",published:"bg-[#3D8B5A]/20 text-[#6DBF8A] border-green-500/30",archived:"bg-[#0f1117]/10 text-white/40 border-white/10"};function W(l){return l.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^a-z0-9\s-]/g,"").trim().replace(/\s+/g,"-").replace(/-+/g,"-")}function Z(l){return l?new Date(l).toLocaleDateString("it-IT",{day:"numeric",month:"short",year:"numeric"}):"â"}const ee={title:"",slug:"",excerpt:"",content:"",coverImage:"",category:"guide",tags:"",metaTitle:"",metaDescription:"",status:"draft",isFeatured:!1};function te({initial:l,onSave:f,onCancel:c,isSaving:o}){const[s,g]=u.useState({...ee,...l}),[h,v]=u.useState(!1),[n,N]=u.useState(!1),[C,y]=u.useState(!l?.slug),i=(a,b)=>{g(w=>{const d={...w,[a]:b};return a==="title"&&C&&(d.slug=W(b),d.metaTitle||(d.metaTitle=b.slice(0,70))),d})};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-white/50 font-['Nunito'] mb-1 block",children:"Titolo *"}),e.jsx(p,{value:s.title,onChange:a=>i("title",a.target.value),placeholder:"Titolo dell'articolo",className:"bg-[#0f1117]/5 border-white/10 text-white placeholder:text-white/30 font-['Nunito'] font-semibold text-base"})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"text-xs text-white/50 font-['Nunito'] mb-1 block",children:["Slug URL *",e.jsx("span",{className:"ml-2 text-white/20",children:"(solo lettere minuscole, numeri, trattini)"})]}),e.jsx(p,{value:s.slug,onChange:a=>{y(!1),i("slug",a.target.value)},placeholder:"titolo-articolo",className:"bg-[#0f1117]/5 border-white/10 text-white placeholder:text-white/30 font-mono text-sm"})]})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"text-xs text-white/50 font-['Nunito'] mb-1 block",children:["Excerpt / Descrizione breve",e.jsx("span",{className:"ml-2 text-white/20",children:"(max 500 caratteri â usata come meta description se non specificata)"})]}),e.jsx("textarea",{value:s.excerpt,onChange:a=>i("excerpt",a.target.value),placeholder:"Breve descrizione dell'articolo...",rows:2,maxLength:500,className:"w-full px-3 py-2 rounded-md bg-[#0f1117]/5 border border-white/10 text-white placeholder:text-white/30 font-['Nunito'] text-sm resize-none focus:outline-none focus:border-[#07793e]/50"}),e.jsxs("p",{className:"text-xs text-white/20 mt-1 text-right",children:[s.excerpt.length,"/500"]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-1",children:[e.jsx("label",{className:"text-xs text-white/50 font-['Nunito']",children:"Contenuto (Markdown) *"}),e.jsx("button",{type:"button",onClick:()=>N(!n),className:"text-xs text-white/40 hover:text-white/70 font-['Nunito'] flex items-center gap-1 transition-colors",children:n?e.jsxs(e.Fragment,{children:[e.jsx(q,{className:"w-3 h-3"}),"Modifica"]}):e.jsxs(e.Fragment,{children:[e.jsx(S,{className:"w-3 h-3"}),"Anteprima"]})})]}),n?e.jsx("div",{className:"min-h-64 p-4 bg-[#0f1117]/3 border border-white/10 rounded-md text-white/70 font-['Nunito'] text-sm leading-relaxed whitespace-pre-wrap",children:s.content||e.jsx("span",{className:"text-white/20 italic",children:"Nessun contenuto"})}):e.jsx("textarea",{value:s.content,onChange:a=>i("content",a.target.value),placeholder:`# Titolo 2 3Scrivi qui il contenuto in Markdown... 4 5## Sezione 6 7Testo del paragrafo.`,rows:16,className:"w-full px-3 py-2 rounded-md bg-[#0f1117]/5 border border-white/10 text-white placeholder:text-white/20 font-mono text-sm resize-y focus:outline-none focus:border-[#07793e]/50"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-white/50 font-['Nunito'] mb-1 block",children:"URL Immagine di copertina"}),e.jsx(p,{value:s.coverImage,onChange:a=>i("coverImage",a.target.value),placeholder:"https://...",className:"bg-[#0f1117]/5 border-white/10 text-white placeholder:text-white/30 font-mono text-sm"}),s.coverImage&&e.jsx("div",{className:"mt-2 rounded-xl overflow-hidden h-32 border border-white/10",children:e.jsx("img",{src:s.coverImage,alt:"Copertina",className:"w-full h-full object-cover",loading:"lazy",decoding:"async"})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-white/50 font-['Nunito'] mb-1 block",children:"Categoria"}),e.jsx("select",{value:s.category,onChange:a=>i("category",a.target.value),className:"w-full h-10 px-3 rounded-md bg-[#0f1117]/5 border border-white/10 text-white font-['Nunito'] text-sm",children:V.map(a=>e.jsx("option",{value:a,className:"bg-[#1a1025]",children:X[a]},a))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-xs text-white/50 font-['Nunito'] mb-1 block",children:"Tag (separati da virgola)"}),e.jsx(p,{value:s.tags,onChange:a=>i("tags",a.target.value),placeholder:"escort, roma, guida",className:"bg-[#0f1117]/5 border-white/10 text-white placeholder:text-white/30 text-sm"})]}),e.jsx("div",{className:"flex flex-col justify-end",children:e.jsxs("button",{type:"button",onClick:()=>i("isFeatured",!s.isFeatured),className:"flex items-center gap-2 h-10 px-3 rounded-md bg-[#0f1117]/5 border border-white/10 text-white/60 hover:text-white hover:bg-[#0f1117]/10 transition-colors font-['Nunito'] text-sm",children:[e.jsx(A,{className:`w-4 h-4 ${s.isFeatured?"text-[#C28B2C] fill-[#C28B2C]":"text-white/30"}`}),s.isFeatured?"In evidenza":"Metti in evidenza"]})})]}),e.jsxs("div",{className:"bg-[#161A1E] border border-white/8 rounded-xl overflow-hidden",children:[e.jsxs("button",{type:"button",onClick:()=>v(!h),className:"w-full flex items-center justify-between px-4 py-3 text-sm font-['Nunito'] font-semibold text-white/60 hover:text-white/80 transition-colors",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(O,{className:"w-4 h-4"}),"Impostazioni SEO avanzate"]}),h?e.jsx(J,{className:"w-4 h-4"}):e.jsx($,{className:"w-4 h-4"})]}),h&&e.jsxs("div",{className:"px-4 pb-4 space-y-3 border-t border-white/8",children:[e.jsxs("div",{children:[e.jsxs("label",{className:"text-xs text-white/50 font-['Nunito'] mb-1 block",children:["Meta Title",e.jsx("span",{className:"ml-2 text-white/20",children:"(max 70 caratteri â default: titolo articolo)"})]}),e.jsx(p,{value:s.metaTitle,onChange:a=>i("metaTitle",a.target.value),placeholder:s.title.slice(0,70),maxLength:70,className:"bg-[#0f1117]/5 border-white/10 text-white placeholder:text-white/20 text-sm"}),e.jsxs("p",{className:"text-xs text-white/20 mt-1 text-right",children:[s.metaTitle.length,"/70"]})]}),e.jsxs("div",{children:[e.jsxs("label",{className:"text-xs text-white/50 font-['Nunito'] mb-1 block",children:["Meta Description",e.jsx("span",{className:"ml-2 text-white/20",children:"(max 160 caratteri â default: excerpt)"})]}),e.jsx("textarea",{value:s.metaDescription,onChange:a=>i("metaDescription",a.target.value),placeholder:s.excerpt.slice(0,160),rows:2,maxLength:160,className:"w-full px-3 py-2 rounded-md bg-[#0f1117]/5 border border-white/10 text-white placeholder:text-white/20 font-['Nunito'] text-sm resize-none focus:outline-none focus:border-[#07793e]/50"}),e.jsxs("p",{className:"text-xs text-white/20 mt-1 text-right",children:[s.metaDescription.length,"/160"]})]})]})]}),e.jsxs("div",{className:"flex gap-3 pt-2 flex-wrap",children:[e.jsxs(r,{onClick:()=>f(s,!1),disabled:o,className:"bg-[#0f1117]/10 hover:bg-[#0f1117]/20 text-white border border-white/20 font-['Nunito'] font-bold",children:[e.jsx(Y,{className:"w-4 h-4 mr-2"}),"Salva bozza"]}),e.jsxs(r,{onClick:()=>f(s,!0),disabled:o,className:"bg-gradient-to-r from-[#07793e] to-[#246068] hover:from-[#A84A80] hover:to-[#2F7F88] text-white font-['Nunito'] font-bold",children:[e.jsx(H,{className:"w-4 h-4 mr-2"}),"Pubblica"]}),e.jsxs(r,{variant:"ghost",onClick:c,disabled:o,className:"text-white/50 hover:text-white hover:bg-[#0f1117]/10 font-['Nunito']",children:[e.jsx(Q,{className:"w-4 h-4 mr-2"}),"Annulla"]})]})]})}function xe(){const{user:l}=M(),f=l?.role==="admin",[c,o]=u.useState("list"),[s,g]=u.useState(null),[h,v]=u.useState("all"),n=m.useUtils(),{data:N=[],isLoading:C,refetch:y}=m.blog.adminGetPosts.useQuery({status:h==="all"?void 0:h,limit:100,offset:0},{enabled:f}),{data:i}=m.blog.adminGetStats.useQuery(void 0,{enabled:f}),a=m.blog.adminCreatePost.useMutation({onSuccess:()=>{n.blog.adminGetPosts.invalidate(),n.blog.adminGetStats.invalidate(),o("list"),x.success("Articolo salvato!")},onError:t=>x.error(t.message)}),b=m.blog.adminUpdatePost.useMutation({onSuccess:()=>{n.blog.adminGetPosts.invalidate(),n.blog.adminGetStats.invalidate(),o("list"),g(null),x.success("Articolo aggiornato!")},onError:t=>x.error(t.message)}),w=m.blog.adminDeletePost.useMutation({onSuccess:()=>{n.blog.adminGetPosts.invalidate(),n.blog.adminGetStats.invalidate(),x.success("Articolo eliminato")},onError:t=>x.error(t.message)}),d=m.admin.generateMissingFaqs.useMutation({onSuccess:t=>{x.success(`FAQ generate: ${t.updated} articoli aggiornati${t.errors>0?`, ${t.errors} errori`:""}`),n.blog.adminGetPosts.invalidate()},onError:t=>x.error("Errore generazione FAQ: "+t.message)});if(!l||l.role!=="admin"&&l.role!=="superadmin")return e.jsx("div",{className:"min-h-screen bg-[#0a0a14] flex items-center justify-center pb-nav",children:e.jsxs("div",{className:"text-center",children:[e.jsx(z,{className:"w-12 h-12 text-[#07793e] mx-auto mb-4"}),e.jsx("h2",{className:"font-['Nunito'] font-bold text-xl text-white mb-2",children:"Accesso Negato"}),e.jsx("p",{className:"text-white/50 font-['Nunito']",children:"Questa sezione è riservata agli amministratori."}),e.jsx(j,{href:"/",children:e.jsx(r,{className:"mt-4 bg-[#07793e] hover:bg-[#07793e] text-white",children:"Torna alla Homepage"})})]})});const T=(t,D)=>{const G=t.tags?JSON.stringify(t.tags.split(",").map(I=>
7I.trim()).filter(Boolean)):void 0,F={title:t.title,slug:t.slug,excerpt:t.excerpt||void 0,content:t.content,coverImage:t.coverImage||void 0,category:t.category,tags:G,metaTitle:t.metaTitle||void 0,metaDescription:t.metaDescription||void 0,status:D?"published":"draft",isFeatured:t.isFeatured};c==="edit"&&s?b.mutate({id:s.id,...F}):a.mutate(F)},E=t=>{g(t),o("edit")},B=a.isPending||b.isPending;return e.jsxs("div",{className:"min-h-screen bg-[#0a0a14] pb-nav",children:[e.jsx("div",{className:"border-b border-white/5 bg-[#161A1E] backdrop-blur-sm sticky top-0 z-10",children:e.jsxs("div",{className:"container py-4 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(j,{href:"/admin",children:e.jsxs(r,{variant:"ghost",size:"sm",className:"text-white/50 hover:text-white hover:bg-[#0f1117]/10",children:[e.jsx(U,{className:"w-4 h-4 mr-1"})," Admin"]})}),e.jsx("div",{className:"w-px h-5 bg-[#0f1117]/10"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(z,{className:"w-5 h-5 text-[#07793e]"}),e.jsx("h1",{className:"font-['Nunito'] font-bold text-lg text-white",children:"Gestione Blog"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[i&&e.jsxs("div",{className:"hidden md:flex items-center gap-3 text-xs text-white/40 font-['Nunito'] mr-2",children:[e.jsxs("span",{className:"text-[#6DBF8A] font-semibold",children:[i.published," pubblicati"]}),e.jsx("span",{children:"·"}),e.jsxs("span",{className:"text-[#C28B2C]",children:[i.draft," bozze"]})]}),e.jsx(j,{href:"/blog",target:"_blank",children:e.jsxs(r,{size:"sm",variant:"ghost",className:"text-white/50 hover:text-white hover:bg-[#0f1117]/10 font-['Nunito']",children:[e.jsx(S,{className:"w-4 h-4 mr-1"}),"Vedi blog"]})}),c==="list"&&e.jsxs(r,{size:"sm",onClick:()=>{g(null),o("create")},className:"bg-gradient-to-r from-[#07793e] to-[#246068] hover:from-[#A84A80] hover:to-[#2F7F88] text-white font-['Nunito'] font-bold",children:[e.jsx(k,{className:"w-4 h-4 mr-1"}),"Nuovo articolo"]})]})]})}),e.jsxs("div",{className:"container py-8",children:[(c==="create"||c==="edit")&&e.jsxs("div",{children:[e.jsx("h2",{className:"font-['Nunito'] font-bold text-xl text-white mb-6",children:c==="create"?"Nuovo articolo":`Modifica: ${s?.title}`}),e.jsx(te,{initial:s?{title:s.title,slug:s.slug,excerpt:s.excerpt??"",content:s.content,coverImage:s.coverImage??"",category:s.category,tags:(()=>{try{return s.tags?JSON.parse(s.tags).join(", "):""}catch{return s.tags??""}})(),metaTitle:s.metaTitle??"",metaDescription:s.metaDescription??"",status:s.status,isFeatured:s.isFeatured??!1}:void 0,onSave:T,onCancel:()=>{o("list"),g(null)},isSaving:B})]}),c==="list"&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-6 flex-wrap gap-3",children:[e.jsx("h2",{className:"font-['Nunito'] font-bold text-xl text-white",children:"Articoli"}),e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[["all","published","draft","archived"].map(t=>e.jsx("button",{onClick:()=>v(t),className:`px-3 py-1.5 rounded-full text-xs font-['Nunito'] font-semibold transition-all border 8 ${h===t?"bg-[#07793e]/30 text-[#07793e] border-[#07793e]/50":"bg-[#0f1117]/5 text-white/40 border-white/10 hover:text-white/60"}`,children:t==="all"?"Tutti":t==="published"?"Pubblicati":t==="draft"?"Bozze":"Archiviati"},t)),e.jsx(r,{variant:"ghost",size:"sm",onClick:()=>y(),className:"text-white/30 hover:text-white/60 hover:bg-[#0f1117]/5",children:e.jsx(P,{className:"w-3.5 h-3.5"})}),e.jsx(r,{variant:"ghost",size:"sm",onClick:()=>d.mutate({limit:50}),disabled:d.isPending,title:"Genera FAQ per articoli senza FAQ (max 50)",className:"text-[#07793e]/70 hover:text-[#07793e] hover:bg-[#07793e]/10 text-xs gap-1.5",children:d.isPending?e.jsxs(e.Fragment,{children:[e.jsx(P,{className:"w-3.5 h-3.5 animate-spin"})," Generando FAQ..."]}):e.jsxs(e.Fragment,{children:[e.jsx(A,{className:"w-3.5 h-3.5"})," Genera FAQ mancanti"]})})]})]}),C?e.jsx("div",{className:"flex items-center justify-center py-16",children:e.jsx("div",{className:"w-8 h-8 border-2 border-[#07793e]/30 border-t-[#07793e] rounded-full animate-spin"})}):N.length===0?e.jsxs("div",{className:"text-center py-20 bg-[#0f1117] border border-white/8 rounded-2xl",children:[e.jsx(z,{className:"w-12 h-12 text-white/10 mx-auto mb-3"}),e.jsx("p",{className:"text-white/40 font-['Nunito']",children:"Nessun articolo trovato"}),e.jsxs(r,{onClick:()=>o("create"),className:"mt-4 bg-gradient-to-r from-[#07793e] to-[#246068] text-white font-['Nunito'] font-bold",children:[e.jsx(k,{className:"w-4 h-4 mr-2"}),"Crea il primo articolo"]})]}):e.jsx("div",{className:"space-y-3",children:N.map(t=>e.jsxs("div",{className:"bg-[#0f1117] border border-white/8 rounded-2xl p-4 flex gap-4 items-center",children:[t.coverImage&&e.jsx("img",{src:t.coverImage,alt:t.title,className:"w-16 h-12 rounded-xl object-cover shrink-0 hidden sm:block",loading:"lazy",decoding:"async"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 flex-wrap mb-1",children:[e.jsx("span",{className:"font-['Nunito'] font-bold text-white text-sm truncate",children:t.title}),e.jsx(R,{className:`text-[10px] px-2 py-0.5 border ${K[t.status]}`,children:t.status}),t.isFeatured&&e.jsx(A,{className:"w-3.5 h-3.5 text-[#C28B2C] fill-[#C28B2C] shrink-0"})]}),e.jsxs("div",{className:"flex items-center gap-3 text-xs text-white/30 font-['Nunito']",children:[e.jsx("span",{children:t.category}),e.jsx("span",{children:"·"}),e.jsx("span",{children:Z(t.publishedAt??t.createdAt)}),e.jsx("span",{children:"·"}),e.jsxs("span",{children:[t.viewCount??0," visualizzazioni"]}),e.jsx("span",{className:"hidden md:inline",children:"·"}),e.jsxs("span",{className:"hidden md:inline font-mono text-white/20",children:["/blog/",t.slug]})]})]}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[t.status==="published"&&e.jsx(j,{href:`/blog/${t.slug}`,target:"_blank",children:e.jsx(r,{size:"sm",variant:"ghost",className:"h-8 w-8 p-0 text-white/40 hover:text-white/70 hover:bg-[#0f1117]/5",children:e.jsx(S,{className:"w-3.5 h-3.5"})})}),e.jsxs(r,{size:"sm",onClick:()=>E(t),className:"h-8 px-3 bg-[#0f1117]/5 hover:bg-[#0f1117]/10 text-white/60 border border-white/10 font-['Nunito'] text-xs",children:[e.jsx(_,{className:"w-3.5 h-3.5 mr-1"}),"Modifica"]}),e.jsx(r,{size:"sm",onClick:()=>{confirm(`Eliminare "${t.title}"?`)&&w.mutate({id:t.id})},disabled:w.isPending,className:"h-8 px-2.5 bg-red-500/20 hover:bg-red-500/30 text-red-400 border border-red-500/20 font-['Nunito'] text-xs",children:e.jsx(L,{className:"w-3.5 h-3.5"})})]})]},t.id))})]})]})]})}export{xe 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.