1import{r as o,j as e,L as P,s as f,l as M,d as J}from"./index-C3SzbFls.js";import{u as W}from"./use-auth-Cs4JOWiu.js";import{A as y,M as q,F,u as H}from"./ui-B0Ja3t6M.js";import{p as X}from"./page-schemas-DDAoyIbg.js";const T=10;function ee(){const[c,b]=o.useState([]),[s,d]=o.useState(""),[r,p]=o.useState("all"),[i,h]=o.useState("all"),[g,a]=o.useState("all"),[u,j]=o.useState(""),[n,m]=o.useState(""),[N,v]=o.useState("manual"),[x,k]=o.useState(1),l=async()=>{const{data:t}=await f.from("exhibitions").select("*").order("sort_order").order("created_at",{ascending:!1});b(t??[])};o.useEffect(()=>{l()},[]),o.useEffect(()=>{k(1)},[s,r,i,g,u,n,N]);const C=async t=>{confirm("Eliminare questa mostra?")&&(await f.from("exhibitions").delete().eq("id",t),l())},A=async t=>{await f.from("exhibitions").update({published:!t.published}).eq("id",t.id),l()},O=o.useMemo(()=>Array.from(new Set(c.map(t=>t.venue).filter(Boolean))).sort((t,E)=>t.localeCompare(E)),[c]),z=o.useMemo(()=>{const t=s.trim().toLowerCase(),E=u?new Date(u).getTime():null,$=n?new Date(n).getTime():null,Q=c.filter(w=>{if(r!=="all"&&w.status!==r||i!=="all"&&(w.venue??"")!==i||g==="published"&&!w.published||g==="draft"&&w.published)return!1;if(E||$){const S=w.start_date?new Date(w.start_date).getTime():null,D=w.end_date?new Date(w.end_date).getTime():S;if(!S&&!D||E&&(D??S)<E||$&&(S??D)>$)return!1}return t?[w.title,w.subtitle,w.period,w.venue,w.curator,w.slug].filter(Boolean).some(S=>S.toLowerCase().includes(t)):!0}),Z=(w,S)=>{const D=w.start_date?new Date(w.start_date).getTime():0,B=S.start_date?new Date(S.start_date).getTime():0;switch(N){case"title":return w.title.localeCompare(S.title);case"start_date_desc":return B-D;case"start_date_asc":return D-B;case"created_desc":return 0;default:return w.sort_order-S.sort_order}};return[...Q].sort(Z)},[c,s,r,i,g,u,n,N]),I=Math.max(1,Math.ceil(z.length/T)),_=Math.min(x,I),U=z.slice((_-1)*T,_*T),G={all:c.length,current:c.filter(t=>t.status==="current").length,upcoming:c.filter(t=>t.status==="upcoming").length,past:c.filter(t=>t.status==="past").length},R={current:"In corso",upcoming:"In arrivo",past:"Passata"},V={current:"bg-ink text-paper",upcoming:"border border-ink text-ink",past:"border border-border text-stone-warm"},K=()=>{d(""),p("all"),h("all"),a("all"),j(""),m(""),v("manual")},Y=s||r!=="all"||i!=="all"||g!=="all"||u||n||N!=="manual";return e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsxs("h2",{className:"font-serif text-xl",children:["Mostre ",e.jsxs("span",{className:"text-stone-warm text-base",children:["· ",z.length," di ",c.length]})]}),e.jsx(P,{to:"/admin/mostre/$id",params:{id:"nuova"},className:"text-xs uppercase tracking-[0.18em] px-4 py-2 bg-ink text-paper border border-ink hover:bg-thread hover:border-thread transition-colors",children:"+ Nuova mostra"})]}),e.jsxs("div",{className:"space-y-3 mb-4 border border-border p-4 bg-paper-warm/30",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("input",{placeholder:"Cerca per titolo, periodo, sede, curatoreâ¦",value:s,onChange:t=>d(t.target.value),className:"flex-1 min-w-[220px] border border-border px-3 py-2 text-sm bg-transparent"}),["all","current","upcoming","past"].map(t=>e.jsxs("button",{type:"button",onClick:()=>p(t),className:`text-xs uppercase tracking-[0.18em] px-3 py-2 border transition-colors ${r===t?"bg-ink text-paper border-ink":"border-border text-stone-warm hover:border-ink hover:text-ink"}`,children:[t==="all"?"Tutte":R[t]," (",G[t],")"]},t))]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-xs",children:[e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"eyebrow text-stone-warm",children:"Sede"}),e.jsxs("select",{value:i,onChange:t=>h(t.target.value),className:"border border-border px-2 py-1.5 bg-transparent text-sm",children:[e.jsxs("option",{value:"all",children:["Tutte (",O.length,")"]}),O.map(t=>e.jsx("option",{value:t,children:t},t))]})]}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"eyebrow text-stone-warm",children:"Visibilità "}),e.jsxs("select",{value:g,onChange:t=>a(t.target.value),className:"border border-border px-2 py-1.5 bg-transparent text-sm",children:[e.jsx("option",{value:"all",children:"Tutte"}),e.jsx("option",{value:"published",children:"Pubblicate"}),e.jsx("option",{value:"draft",children:"Bozze"})]})]}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"eyebrow text-stone-warm",children:"Dal"}),e.jsx("input",{type:"date",value:u,onChange:t=>j(t.target.value),className:"border border-border px-2 py-1.5 bg-transparent text-sm"})]}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"eyebrow text-stone-warm",children:"Al"}),e.jsx("input",{type:"date",value:n,onChange:t=>m(t.target.value),className:"border border-border px-2 py-1.5 bg-transparent text-sm"})]}),e.jsxs("label",{className:"flex items-center gap-2 ml-auto",children:[e.jsx("span",{className:"eyebrow text-stone-warm",children:"Ordina"}),e.jsxs("select",{value:N,onChange:t=>v(t.target.value),className:"border border-border px-2 py-1.5 bg-transparent text-sm",children:[e.jsx("option",{value:"manual",children:"Ordine manuale"}),e.jsx("option",{value:"start_date_desc",children:"Data inizio (recenti)"}),e.jsx("option",{value:"start_date_asc",children:"Data inizio (vecchie)"}),e.jsx("option",{value:"title",children:"Titolo AâZ"})]})]}),Y&&e.jsx("button",{type:"button",onClick:K,className:"text-xs uppercase tracking-[0.18em] px-3 py-1.5 border border-border hover:border-ink",children:"Azzera filtri"})]})]}),e.jsxs("div",{className:"grid gap-3",children:[U.map(t=>e.jsxs("div",{className:`flex items-center gap-4 border p-4 ${t.published?"border-border":"border-border bg-paper-warm/40 opacity-70"}`,children:[t.cover_image?e.jsx("img",{src:t.cover_image,alt:"",className:"w-20 h-14 object-cover"}):e.jsx("div",{className:"w-20 h-14 border border-dashed border-border flex items-center justify-center text-[10px] text-stone-warm",children:"no cover"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`text-[10px] uppercase tracking-[0.18em] px-2 py-0.5 ${V[t.status]}`,children:R[t.status]}),!t.published&&e.jsx("span",{className:"text-[10px] uppercase tracking-[0.18em] px-2 py-0.5 border border-border text-stone-warm",children:"Bozza"}),e.jsx("div",{className:"font-serif text-lg truncate",children:t.title})]}),e.jsxs("div",{className:"text-xs text-stone-warm mt-1 truncate",children:[t.period&&e.jsxs(e.Fragment,{children:[t.period," · "]}),t.venue&&e.jsxs(e.Fragment,{children:[t.venue," · "]}),e.jsxs("code",{children:["/mostre/",t.slug]})]})]}),e.jsx("button",{type:"button",onClick:()=>A(t),className:"text-xs uppercase tracking-[0.18em] px-3 py-2 border border-border hover:border-ink",title:t.published?"Nascondi dal sito":"Pubblica sul sito",children:t.published?"Nascondi":"Pubblica"}),e.jsx(P,{to:"/admin/mostre/$id",params:{id:t.id},className:"text-xs uppercase tracking-[0.18em] px-3 py-2 border border-ink hover:bg-ink hover:text-paper transition-colors",children:"Modifica"}),e.jsx(y,{variant:"danger",onClick:()=>C(t.id),children:"Elimina"})]},t.id)),z.length===0&&e.jsx("p",{className:"text-stone-warm text-sm py-8 text-center border border-dashed border-border",children:c.length===0?"Nessuna mostra.
1Crea la prima.":"Nessun risultato per i filtri attivi."})]}),I>1&&e.jsxs("div",{className:"flex items-center justify-between mt-4 text-xs",children:[e.jsxs("div",{className:"text-stone-warm",children:[(_-1)*T+1,"â",Math.min(_*T,z.length)," di ",z.length]}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx("button",{type:"button",disabled:_===1,onClick:()=>k(_-1),className:"px-3 py-1.5 border border-border uppercase tracking-[0.18em] disabled:opacity-40 hover:border-ink",children:"â¹ Prec"}),Array.from({length:I},(t,E)=>E+1).map(t=>e.jsx("button",{type:"button",onClick:()=>k(t),className:`px-3 py-1.5 border ${t===_?"bg-ink text-paper border-ink":"border-border hover:border-ink"}`,children:t},t)),e.jsx("button",{type:"button",disabled:_===I,onClick:()=>k(_+1),className:"px-3 py-1.5 border border-border uppercase tracking-[0.18em] disabled:opacity-40 hover:border-ink",children:"Succ âº"})]})]})]})}function se(){const[c,b]=o.useState([]),s=async()=>{const{data:i}=await f.from("news").select("*").order("date",{ascending:!1}).order("created_at",{ascending:!1});b(i??[])};o.useEffect(()=>{s()},[]);const d=async i=>{confirm("Eliminare questa news?")&&(await f.from("news").delete().eq("id",i),s())},r=async i=>{await f.from("news").update({published:!i.published}).eq("id",i.id),s()},p=i=>new Intl.DateTimeFormat("it-IT",{day:"numeric",month:"short",year:"numeric"}).format(new Date(i));return e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsxs("h2",{className:"font-serif text-xl",children:["News ",e.jsxs("span",{className:"text-stone-warm text-base",children:["· ",c.length]})]}),e.jsx(P,{to:"/admin/news/$id",params:{id:"nuova"},className:"text-xs uppercase tracking-[0.18em] px-4 py-2 bg-ink text-paper border border-ink hover:bg-thread hover:border-thread transition-colors",children:"+ Nuova news"})]}),e.jsxs("div",{className:"grid gap-3",children:[c.map(i=>e.jsxs("div",{className:`flex items-center gap-4 border p-4 ${i.published?"border-border":"border-border bg-paper-warm/40 opacity-70"}`,children:[i.image?e.jsx("img",{src:i.image,alt:"",className:"w-20 h-14 object-cover"}):e.jsx("div",{className:"w-20 h-14 border border-dashed border-border flex items-center justify-center text-[10px] text-stone-warm",children:"no foto"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[!i.published&&e.jsx("span",{className:"text-[10px] uppercase tracking-[0.18em] px-2 py-0.5 border border-border text-stone-warm",children:"Bozza"}),e.jsx("div",{className:"font-serif text-lg truncate",children:i.title})]}),e.jsxs("div",{className:"text-xs text-stone-warm mt-1 truncate",children:[p(i.date)," · ",e.jsxs("code",{children:["/news/",i.slug]})]})]}),e.jsx("button",{type:"button",onClick:()=>r(i),className:"text-xs uppercase tracking-[0.18em] px-3 py-2 border border-border hover:border-ink",children:i.published?"Nascondi":"Pubblica"}),e.jsx(P,{to:"/admin/news/$id",params:{id:i.id},className:"text-xs uppercase tracking-[0.18em] px-3 py-2 border border-ink hover:bg-ink hover:text-paper transition-colors",children:"Modifica"}),e.jsx(y,{variant:"danger",onClick:()=>d(i.id),children:"Elimina"})]},i.id)),c.length===0&&e.jsx("p",{className:"text-stone-warm text-sm py-8 text-center border border-dashed border-border",children:"Nessuna news. Crea la prima."})]})]})}function te(){const[c,b]=o.useState([]);o.useEffect(()=>{f.from("page_contents").select("slug,label,updated_at").then(({data:r})=>b(r??[]))},[]);const s=r=>new Intl.DateTimeFormat("it-IT",{day:"numeric",month:"short",year:"numeric",hour:"2-digit",minute:"2-digit"}).format(new Date(r)),d=X.map(r=>{const p=c.find(i=>i.slug===r.slug);return p?{...p,label:r.label,hasFields:r.fields.length>0}:null}).filter(r=>!!r);return e.jsxs("div",{children:[e.jsx("div",{className:"flex justify-between items-center mb-6",children:e.jsxs("h2",{className:"font-serif text-xl",children:["Pagine ",e.jsxs("span",{className:"text-stone-warm text-base",children:["· ",d.length]})]})}),e.jsxs("div",{className:"grid gap-3",children:[d.map(r=>e.jsxs(P,{to:"/admin/pagine/$slug",params:{slug:r.slug},className:"flex items-center gap-4 border border-border p-4 hover:border-ink transition-colors",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"font-serif text-lg truncate",children:r.label}),!r.hasFields&&e.jsx("span",{className:"text-[10px] uppercase tracking-[0.18em] px-2 py-0.5 border border-border text-stone-warm",children:"Solo SEO"})]}),e.jsxs("div",{className:"text-xs text-stone-warm mt-1 truncate",children:[e.jsxs("code",{children:["/",r.slug==="home"?"":r.slug]})," · ultimo aggiornamento ",s(r.updated_at)]})]}),e.jsx("span",{className:"text-xs uppercase tracking-[0.18em] px-3 py-2 border border-ink",children:"Modifica â"})]},r.slug)),d.length===0&&e.jsx("p",{className:"text-stone-warm text-sm py-8 text-center border border-dashed border-border",children:"Caricamentoâ¦"})]})]})}const ae={title:"",description:"",category:"",delibera_date:"",file_url:"",file_name:"",published:!0};
1function re(){const[c,b]=o.useState([]),[s,d]=o.useState(null),[r,p]=o.useState(!1),[i,h]=o.useState(""),[g,a]=o.useState("all"),u=async()=>{const{data:l}=await f.from("delibere").select("*").order("delibera_date",{ascending:!1,nullsFirst:!1});b(l??[])};o.useEffect(()=>{u()},[]);const j=async l=>{confirm("Eliminare?")&&(await f.from("delibere").delete().eq("id",l),u())},n=async l=>{await f.from("delibere").update({published:!l.published}).eq("id",l.id),u()},m=l=>l.delibera_date?new Date(l.delibera_date).getFullYear().toString():"-",N=Array.from(new Set(c.map(m))).sort((l,C)=>C.localeCompare(l)),v=i.trim().toLowerCase(),x=c.filter(l=>g!=="all"&&m(l)!==g?!1:v?[l.title,l.description,l.category,l.file_name].filter(Boolean).some(C=>C.toLowerCase().includes(v)):!0),k=s??(r?{id:"",...ae}:null);return e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsxs("h2",{className:"font-serif text-xl",children:["Delibere & Documenti ",e.jsxs("span",{className:"text-stone-warm text-base",children:["· ",x.length," di ",c.length]})]}),e.jsx(y,{onClick:()=>p(!0),children:"+ Nuova delibera"})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 mb-4",children:[e.jsx("input",{placeholder:"Cerca per titolo, categoria, fileâ¦",value:i,onChange:l=>h(l.target.value),className:"flex-1 min-w-[220px] border border-border px-3 py-2 text-sm bg-transparent"}),e.jsxs("button",{type:"button",onClick:()=>a("all"),className:`text-xs uppercase tracking-[0.18em] px-3 py-2 border ${g==="all"?"bg-ink text-paper border-ink":"border-border text-stone-warm hover:border-ink hover:text-ink"}`,children:["Tutti (",c.length,")"]}),N.map(l=>e.jsxs("button",{type:"button",onClick:()=>a(l),className:`text-xs uppercase tracking-[0.18em] px-3 py-2 border ${g===l?"bg-ink text-paper border-ink":"border-border text-stone-warm hover:border-ink hover:text-ink"}`,children:[l," (",c.filter(C=>m(C)===l).length,")"]},l))]}),e.jsxs("div",{className:"grid gap-3",children:[x.map(l=>e.jsxs("div",{className:`flex items-center gap-4 border p-4 ${l.published?"border-border":"border-border bg-paper-warm/40 opacity-70"}`,children:[e.jsx("div",{className:"w-14 h-14 border border-border flex items-center justify-center text-[10px] uppercase tracking-[0.18em] text-stone-warm shrink-0",children:l.file_url?"PDF":"-"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[!l.published&&e.jsx("span",{className:"text-[10px] uppercase tracking-[0.18em] px-2 py-0.5 border border-border text-stone-warm",children:"Bozza"}),e.jsx("div",{className:"font-serif text-lg truncate",children:l.title})]}),e.jsxs("div",{className:"text-xs text-stone-warm mt-1 truncate",children:[l.delibera_date&&e.jsxs(e.Fragment,{children:[new Date(l.delibera_date).toLocaleDateString("it-IT")," · "]}),l.category&&e.jsxs(e.Fragment,{children:[l.category," · "]}),l.file_name||(l.file_url?"file allegato":"nessun allegato")]})]}),l.file_url&&e.jsx("a",{href:l.file_url,target:"_blank",rel:"noreferrer",className:"text-xs uppercase tracking-[0.18em] link-underline",children:"Apri"}),e.jsx("button",{type:"button",onClick:()=>n(l),className:"text-xs uppercase tracking-[0.18em] px-3 py-2 border border-border hover:border-ink",title:l.published?"Nascondi dal sito":"Pubblica sul sito",children:l.published?"Nascondi":"Pubblica"}),e.jsx(y,{variant:"outline",onClick:()=>d(l),children:"Modifica"}),e.jsx(y,{variant:"danger",onClick:()=>j(l.id),children:"Elimina"})]},l.id)),x.length===0&&e.jsx("p",{className:"text-stone-warm text-sm py-8 text-center border border-dashed border-border",children:c.length===0?"Nessuna delibera.":"Nessun risultato per i filtri attivi."})]}),e.jsx(q,{open:!!k,onClose:()=>{d(null),p(!1)},title:s?"Modifica":"Nuova delibera",children:k&&e.jsx(ie,{initial:k,onSaved:()=>{d(null),p(!1),u()}})})]})}function ie({initial:c,onSaved:b}){const[s,d]=o.useState(c),[r,p]=o.useState(!1),[i,h]=o.useState(!1),g=async n=>{n.preventDefault(),p(!0);try{let m=s.id,N=s.file_url,v=s.file_name;const x={title:s.title,description:s.description,category:s.category,delibera_date:s.delibera_date||null,file_url:N,file_name:v,published:s.published};if(!m){const C=await f.from("delibere").insert(x).select("id").single();if(C.error)throw C.error;m=C.data.id}if(a&&m){const C=`${m}/${a.name}`,A=await f.storage.from("delibere").upload(C,a,{upsert:!0,contentType:"application/pdf"});if(A.error)throw A.error;v=a.name,N=`/api/public/delibere/${m}/download`}const k={...x,file_url:N,file_name:v},l=await f.from("delibere").update(k).eq("id",m);if(l.error)throw l.error;b()}catch(m){alert(m.message||String(m))}finally{p(!1)}},[a,u]=o.useState(null),j=n=>{u(n),d({...s,file_name:n.name})};return e.jsxs("form",{onSubmit:g,className:"space-y-4",children:[e.jsx(F,{label:"Titolo",value:s.title,onChange:n=>d({...s,title:n}),required:!0}),e.jsx(F,{label:"Descrizione",value:s.description??"",onChange:n=>d({...s,description:n}),textarea:!0,rows:3}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(F,{label:"Categoria",value:s.category??"",onChange:n=>d({...s,category:n})}),e.jsx(F,{label:"Data",type:"date",value:s.delibera_date??"",onChange:n=>d({...s,delibera_date:n})})]}),e.jsxs("div",{children:[e.jsx("span",{className:"eyebrow text-stone-warm block mb-2",children:"File PDF"}),e.jsx(ne,{fileName:s.file_name,fileUrl:s.file_url,onFile:j,onClear:()=>{u(null),d({...s,file_name:""})}})]}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:s.published,onChange:n=>d({...s,published:n.target.checked})}),e.jsx("span",{className:"text-sm",children:"Pubblicata"})]}),e.jsx("div",{className:"flex gap-3 justify-end pt-4 border-t border-border",children:e.jsx(y,{type:"submit",disabled:r||i,children:r?"Salvataggioâ¦":"Salva"})})]})}function ne({fileName:c,fileUrl:b,onFile:s,onClear:d}){const r=o.useRef(null);return e.jsxs("div",{className:"border border-border p-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(y,{onClick:()=>r.current?.click(),children:b?"Cambia PDF":"Scegli PDF"}),e.jsx("span",{className:"text-sm text-stone-warm truncate",children:c||(b?"File allegato":"Nessun file selezionato")})]}),b&&e.jsxs("div",{className:"mt-2 flex items-center gap-3",children:[e.jsx("a",{href:b,target:"_blank",rel:"noreferrer",className:"text-xs link-underline",children:"Apri file attuale"}),e.jsx("button",{type:"button",onClick:d,className:"text-xs text-red-600 hover:underline",children:"Rimuovi"})]}),e.jsx("input",{ref:r,type:"file",accept:"application/pdf",className:"hidden",onChange:p=>{const i=p.target.files?.[0];i&&s(i),p.target.value=""}})]})}const le=["/","/maria-lai","/mostre","/news","/visita","/educazione","/ulassai","/contatti","/donazioni","/faq","/carta-dei-servizi","/privacy-policy","/amministrazione-trasparente","/amministrazione-trasparente/delibere"];
1function oe(){const[c,b]=o.useState([]),[s,d]=o.useState(null),[r,p]=o.useState(""),[i,h]=o.useState([]),[g,a]=o.useState([]),u=async()=>{const{data:x}=await f.from("seo_pages").select("*").order("path");b(x??[]);const k=await f.from("exhibitions").select("slug, title").order("start_date",{ascending:!1});h(k.data??[]);const l=await f.from("news").select("slug, title").eq("published",!0).order("date",{ascending:!1});a(l.data??[])};o.useEffect(()=>{u()},[]);const j=async x=>{x.startsWith("/")||(x="/"+x);const{data:k,error:l}=await f.from("seo_pages").insert({path:x}).select().single();if(l){alert(l.message);return}d(k),u()},n=new Set(c.map(x=>x.path)),m=le.filter(x=>!n.has(x)),N=i.filter(x=>!n.has(`/mostre/${x.slug}`)),v=g.filter(x=>!n.has(`/news/${x.slug}`));return e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsx("h2",{className:"font-serif text-xl",children:"SEO per pagina"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{placeholder:"/percorso",value:r,onChange:x=>p(x.target.value),className:"border border-border px-3 py-2 text-sm"}),e.jsx(y,{onClick:()=>{r&&(j(r),p(""))},children:"+ Aggiungi"})]})]}),m.length>0&&e.jsxs("div",{className:"mb-6 p-4 border border-border bg-paper-warm text-sm",children:[e.jsx("div",{className:"eyebrow text-stone-warm mb-2",children:"Pagine non ancora configurate"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:m.map(x=>e.jsxs("button",{onClick:()=>j(x),className:"text-xs px-3 py-1 border border-ink hover:bg-ink hover:text-paper transition-colors",children:["+ ",x]},x))})]}),N.length>0&&e.jsxs("div",{className:"mb-6 p-4 border border-border bg-paper-warm text-sm",children:[e.jsx("div",{className:"eyebrow text-stone-warm mb-2",children:"Mostre senza SEO personalizzata"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:N.map(x=>e.jsxs("button",{onClick:()=>j(`/mostre/${x.slug}`),title:x.title,className:"text-xs px-3 py-1 border border-ink hover:bg-ink hover:text-paper transition-colors",children:["+ /mostre/",x.slug]},x.slug))})]}),v.length>0&&e.jsxs("div",{className:"mb-6 p-4 border border-border bg-paper-warm text-sm",children:[e.jsx("div",{className:"eyebrow text-stone-warm mb-2",children:"News senza SEO personalizzata"}),e.jsx("div",{className:"flex flex-wrap gap-2",children:v.map(x=>e.jsxs("button",{onClick:()=>j(`/news/${x.slug}`),title:x.title,className:"text-xs px-3 py-1 border border-ink hover:bg-ink hover:text-paper transition-colors",children:["+ /news/",x.slug]},x.slug))})]}),e.jsx("div",{className:"grid gap-3",children:c.map(x=>e.jsxs("div",{className:"flex items-center gap-4 border border-border p-4",children:[e.jsx("code",{className:"text-sm text-stone-warm w-40 truncate",children:x.path}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"font-serif truncate",children:x.title||e.jsx("span",{className:"text-stone-warm italic",children:"senza titolo"})}),e.jsx("div",{className:"text-xs text-stone-warm truncate",children:x.description})]}),e.jsx(y,{variant:"outline",onClick:()=>d(x),children:"Modifica"})]},x.id))}),e.jsx(q,{open:!!s,onClose:()=>d(null),title:`SEO - ${s?.path}`,children:s&&e.jsx(ce,{initial:s,onSaved:()=>{d(null),u()}})})]})}function ce({initial:c,onSaved:b}){const[s,d]=o.useState(c),[r,p]=o.useState(!1),i=async h=>{h.preventDefault(),p(!0);const{error:g}=await f.from("seo_pages").update({title:s.title,description:s.description,og_image:s.og_image,keywords:s.keywords}).eq("id",s.id);if(p(!1),g){alert(g.message);return}b()};return e.jsxs("form",{onSubmit:i,className:"space-y-4",children:[e.jsx(F,{label:"Title (< 60 caratteri)",value:s.title??"",onChange:h=>d({...s,title:h})}),e.jsx(F,{label:"Meta description (< 160 caratteri)",value:s.description??"",onChange:h=>d({...s,description:h}),textarea:!0,rows:3}),e.jsx(de,{value:s.og_image,onChange:h=>d({...s,og_image:h})}),e.jsx(F,{label:"Keywords (separate da virgola)",value:s.keywords??"",onChange:h=>d({...s,keywords:h})}),e.jsx("div",{className:"flex gap-3 justify-end pt-4 border-t border-border",children:e.jsx(y,{type:"submit",disabled:r,children:r?"Salvataggioâ¦":"Salva"})})]})}function de({value:c,onChange:b}
1){const[s,d]=o.useState([]),[r,p]=o.useState(!1),[i,h]=o.useState(!1);o.useEffect(()=>{(async()=>{const{data:a}=await f.from("exhibitions").select("cover_image, gallery"),u=new Set;(a??[]).forEach(j=>{j.cover_image&&u.add(j.cover_image),(Array.isArray(j.gallery)?j.gallery:[]).forEach(m=>{typeof m=="string"&&m&&u.add(m)})}),d(Array.from(u))})()},[]);const g=async a=>{h(!0);try{const u=await H("exhibitions",a);b(u)}catch(u){alert(u.message)}finally{h(!1)}};return e.jsxs("div",{className:"space-y-2",children:[e.jsx("label",{className:"eyebrow text-stone-warm block",children:"OG image"}),c?e.jsxs("div",{className:"flex items-start gap-3 border border-border p-3",children:[e.jsx("img",{src:c,alt:"",className:"w-24 h-24 object-cover bg-paper-warm"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("div",{className:"text-xs text-stone-warm break-all",children:c}),e.jsxs("div",{className:"flex gap-2 mt-2",children:[e.jsx(y,{type:"button",variant:"outline",onClick:()=>p(!0),children:"Cambia"}),e.jsx(y,{type:"button",variant:"outline",onClick:()=>b(""),children:"Rimuovi"})]})]})]}):e.jsxs("div",{className:"flex gap-2",children:[e.jsx(y,{type:"button",variant:"outline",onClick:()=>p(!0),children:"Scegli dal sito"}),e.jsxs("label",{className:"inline-flex items-center px-4 py-2 border border-ink text-sm cursor-pointer hover:bg-ink hover:text-paper transition-colors",children:[i?"Caricamentoâ¦":"Carica nuova",e.jsx("input",{type:"file",accept:"image/*",className:"hidden",disabled:i,onChange:a=>{const u=a.target.files?.[0];u&&g(u),a.target.value=""}})]})]}),e.jsx("input",{type:"text",placeholder:"oppure incolla un URL",value:c??"",onChange:a=>b(a.target.value),className:"w-full border border-border px-3 py-2 text-sm"}),e.jsx(q,{open:r,onClose:()=>p(!1),title:"Scegli un'immagine dal sito",children:e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"flex justify-end",children:e.jsxs("label",{className:"inline-flex items-center px-4 py-2 border border-ink text-sm cursor-pointer hover:bg-ink hover:text-paper transition-colors",children:[i?"Caricamentoâ¦":"Carica nuova",e.jsx("input",{type:"file",accept:"image/*",className:"hidden",disabled:i,onChange:async a=>{const u=a.target.files?.[0];u&&(await g(u),p(!1)),a.target.value=""}})]})}),s.length===0?e.jsx("div",{className:"text-sm text-stone-warm",children:"Nessuna immagine disponibile dal sito."}):e.jsx("div",{className:"grid grid-cols-3 gap-3 max-h-[60vh] overflow-y-auto",children:s.map(a=>e.jsx("button",{type:"button",onClick:()=>{b(a),p(!1)},className:`relative aspect-square overflow-hidden border-2 transition-colors ${c===a?"border-ink":"border-transparent hover:border-stone-warm"}`,children:e.jsx("img",{src:a,alt:"",className:"w-full h-full object-cover"})},a))})]})})]})}function me(){const[c,b]=o.useState([]),[s,d]=o.useState("all"),r=async()=>{const{data:a}=await f.from("contact_messages").select("*").order("created_at",{ascending:!1});b(a??[])};o.useEffect(()=>{r()},[]);const p=async a=>{await f.from("contact_messages").update({read:!a.read}).eq("id",a.id),r()},i=async a=>{confirm("Eliminare?")&&(await f.from("contact_messages").delete().eq("id",a),r())},h=s==="unread"?c.filter(a=>!a.read):c,g=c.filter(a=>!a.read).length;return e.jsxs("div",{children:[e.jsxs("div",{className:"flex justify-between items-center mb-6",children:[e.jsxs("h2",{className:"font-serif text-xl",children:["Messaggi contatti (",c.length,g>0&&` · ${g} non letti`,")"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{onClick:()=>d("all"),className:`text-xs uppercase tracking-[0.18em] px-3 py-2 ${s==="all"?"bg-ink text-paper":"border border-border"}`,children:"Tutti"}),e.jsx("button",{onClick:()=>d("unread"),className:`text-xs uppercase tracking-[0.18em] px-3 py-2 ${s==="unread"?"bg-ink text-paper":"border border-border"}`,children:"Non letti"})]})]}),e.jsxs("div",{className:"space-y-3",children:[h.map(a=>e.jsx("div",{className:`border p-5 ${a.read?"border-border":"border-ink bg-paper-warm"}`,children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-baseline gap-3 flex-wrap",children:[e.jsx("span",{className:"font-serif text-lg",children:a.name}),e.jsx("a",{href:`mailto:${a.email}
1`,className:"text-sm link-underline text-stone-warm",children:a.email}),e.jsx("span",{className:"text-xs text-stone-warm",children:new Date(a.created_at).toLocaleString("it-IT")})]}),a.subject&&e.jsx("div",{className:"text-sm font-medium mt-1",children:a.subject}),e.jsx("p",{className:"mt-3 text-sm whitespace-pre-wrap",children:a.message})]}),e.jsxs("div",{className:"flex flex-col gap-2 shrink-0",children:[e.jsx(y,{variant:"outline",onClick:()=>p(a),children:a.read?"Segna non letto":"Segna letto"}),e.jsx(y,{variant:"danger",onClick:()=>i(a.id),children:"Elimina"})]})]})},a.id)),h.length===0&&e.jsx("p",{className:"text-stone-warm text-sm",children:"Nessun messaggio."})]})]})}const L=[{key:"contact_from_name",label:"Nome mittente notifiche",help:"Apparirà come mittente delle notifiche."}];function xe(){const[c,b]=o.useState({}),[s,d]=o.useState([]),[r,p]=o.useState(!1),[i,h]=o.useState(""),g=o.useRef(null),a=async()=>{const{data:n}=await f.from("site_settings").select("key,value"),m={};for(const v of n??[])m[v.key]=v.value??"";b(m);const N=m.contact_recipient_email??"";d(N.split(",").map(v=>v.trim()).filter(Boolean)),h(m.favicon_url??"")};o.useEffect(()=>{a()},[]);const u=async()=>{p(!0);const n=s.map(m=>m.trim()).filter(Boolean);d(n);for(const{key:m}of L)await f.from("site_settings").upsert({key:m,value:c[m]??""},{onConflict:"key"});await f.from("site_settings").upsert({key:"contact_recipient_email",value:n.join(",")},{onConflict:"key"}),await f.from("site_settings").upsert({key:"favicon_url",value:i??""},{onConflict:"key"}),p(!1),alert("Impostazioni salvate.")},j=async n=>{if(n.size>512*1024){alert("Il file è troppo grande. Usa un'immagine sotto i 512 KB.");return}const m=new FileReader;m.onload=()=>h(String(m.result??"")),m.readAsDataURL(n)};return e.jsxs("div",{className:"max-w-2xl",children:[e.jsx("h2",{className:"font-serif text-xl mb-6",children:"Impostazioni sito"}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs uppercase tracking-[0.18em] text-stone-warm mb-2",children:"Email destinatario contatti"}),e.jsx("div",{className:"space-y-2",children:s.map((n,m)=>e.jsxs("div",{className:"flex gap-2 items-center",children:[e.jsx("input",{type:"email",value:n,onChange:N=>{const v=[...s];v[m]=N.target.value,d(v)},className:"flex-1 bg-transparent border-b border-border focus:border-ink outline-none py-2 text-base transition-colors"}),e.jsx("button",{type:"button",onClick:()=>d(s.filter((N,v)=>v!==m)),className:"text-xs uppercase tracking-[0.18em] text-stone-warm hover:text-thread transition-colors",children:"Rimuovi"})]},m))}),e.jsx("button",{type:"button",onClick:()=>d([...s,""]),className:"mt-3 text-xs uppercase tracking-[0.18em] border border-ink px-3 py-2 hover:bg-ink hover:text-paper transition-colors",children:"Aggiungi indirizzo"}),e.jsx("p",{className:"text-xs text-stone-warm mt-2",children:"Indirizzi dove inviare i messaggi del form."})]}),L.map(n=>e.jsxs("div",{children:[e.jsx(F,{label:n.label,value:c[n.key]??"",onChange:m=>b({...c,[n.key]:m})}),e.jsx("p",{className:"text-xs text-stone-warm mt-1",children:n.help})]},n.key))]}),e.jsxs("div",{className:"mt-12 pt-8 border-t border-border",children:[e.jsx("h3",{className:"font-serif text-lg mb-2",children:"Favicon"}),e.jsx("p",{className:"text-xs text-stone-warm mb-4",children:"Icona mostrata nella scheda del browser. Carica un'immagine (PNG/JPG/SVG, max 512 KB) oppure scegli da quelle del sito."}),e.jsxs("div",{className:"flex items-center gap-6 mb-6",children:[e.jsx("div",{className:"w-16 h-16 border border-border bg-paper-warm flex items-center justify-center overflow-hidden",children:i?e.jsx("img",{src:i,alt:"favicon",className:"w-full h-full object-cover"}):e.jsx("span",{className:"text-[10px] text-stone-warm",children:"nessuna"})}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx("input",{ref:g,type:"file",accept:"image/png,image/jpeg,image/svg+xml,image/webp,image/x-icon",className:"hidden",onChange:n=>{const m=n.target.files?.[0];m&&j(m)}}),e.jsx("button",{type:"button",onClick:()=>g.current?.click(),className:"text-xs uppercase tracking-[0.18em] border border-ink px-4 py-2 hover:bg-ink hover:text-paper transition-colors",children:"Carica file"}),i&&e.jsx("button",{type:"button",onClick:()=>h(""),className:"text-xs uppercase tracking-[0.18em] text-stone-warm hover:text-ink",children:"Rimuovi"})]})]}),e.jsx("div",{className:"eyebrow text-stone-warm mb-3",children:"Oppure usa il logo del sito"}),e.jsx("button",{type:"button",onClick:()=>h(M.url),className:"w-16 h-16 flex items-center justify-center border-2 transition-colors "+(i===M.url?"border-ink bg-ink":"border-border bg-ink hover:border-stone-warm"),title:"Usa il logo Stazione dell'Arte",children:e.jsx("img",{src:M.url,alt:"Logo",className:"w-10 h-10"})})]}),e.jsx("div",{className:"mt-8 pt-6 border-t border-border",children:e.jsx(y,{onClick:u,disabled:r,children:r?"Salvataggioâ¦":"Salva impostazioni"})}),e.jsxs("div",{className:"mt-12 p-5 border border-border bg-paper-warm",children:[e.jsx("div",{className:"eyebrow text-stone-warm mb-2",children:"Notifiche email"}),e.jsxs("p",{className:"text-sm text-stone-warm",children:["Per ricevere automaticamente le email dei contatti sui destinatari configurati, è necessario che il sistema di invio email sia attivo. Tutti i messaggi sono comunque salvati e consultabili nella sezione ",e.jsx("em",{children:"Messaggi"}),"."]})]})]})}function ge(){const c=J(),{user:b,isAdmin:s,isDelibereAdmin:d,isContentAdmin:r,loading:p}
1=W(),[i,h]=o.useState("mostre");if(o.useEffect(()=>{!p&&!b&&c({to:"/login",replace:!0})},[b,p,c]),o.useEffect(()=>{!s&&!r&&d&&h("delibere")},[s,r,d]),p)return e.jsx("div",{className:"min-h-screen flex items-center justify-center text-stone-warm",children:"Caricamentoâ¦"});if(!b)return null;if(!s&&!d&&!r)return e.jsx("div",{className:"min-h-screen flex items-center justify-center bg-paper px-6 pt-32 pb-16",children:e.jsxs("div",{className:"max-w-md text-center",children:[e.jsx("h1",{className:"display-md",children:"Accesso negato"}),e.jsx("p",{className:"text-stone-warm mt-4",children:"Il tuo account non ha privilegi di amministratore."}),e.jsxs("p",{className:"text-stone-warm text-sm mt-2",children:["User ID: ",e.jsx("code",{className:"text-xs",children:b.id})]}),e.jsx("button",{onClick:()=>f.auth.signOut(),className:"mt-8 border border-ink px-5 py-2.5 text-xs uppercase tracking-[0.18em]",children:"Esci"})]})});const g=[{id:"mostre",label:"Mostre"},{id:"news",label:"News"},{id:"pagine",label:"Pagine"},{id:"delibere",label:"Delibere"},{id:"seo",label:"SEO"},{id:"messaggi",label:"Messaggi"},{id:"impostazioni",label:"Impostazioni"}];let a=g;s||(r?a=g.filter(n=>["mostre","news","pagine","delibere"].includes(n.id)):a=g.filter(n=>n.id==="delibere"));const j=a.map(n=>n.id).includes(i)?i:a[0]?.id??"delibere";return e.jsx("div",{className:"min-h-screen bg-paper pt-6 pb-6",children:e.jsxs("div",{className:"mx-auto max-w-[1400px] px-6 md:px-10",children:[e.jsxs("div",{className:"flex items-center justify-between border-b border-border pb-8",children:[e.jsxs("div",{children:[e.jsx("div",{className:"eyebrow text-stone-warm",children:"CMS"}),e.jsx("h1",{className:"display-md mt-2",children:"Pannello amministrazione"}),e.jsxs("p",{className:"text-stone-warm text-sm mt-2",children:["Connesso come ",b.email]})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(P,{to:"/",className:"text-xs uppercase tracking-[0.18em] link-underline",children:"Vedi sito"}),e.jsx("button",{onClick:()=>f.auth.signOut().then(()=>c({to:"/login"})),className:"text-xs uppercase tracking-[0.18em] border border-ink px-4 py-2 hover:bg-ink hover:text-paper transition-colors",children:"Esci"})]})]}),e.jsx("nav",{className:"flex flex-wrap gap-2 mt-10 border-b border-border",children:a.map(n=>e.jsx("button",{onClick:()=>h(n.id),className:"px-5 py-3 text-xs uppercase tracking-[0.18em] border-b-2 transition-colors "+(j===n.id?"border-ink text-ink":"border-transparent text-stone-warm hover:text-ink"),children:n.label},n.id))}),e.jsxs("div",{className:"mt-10",children:[j==="mostre"&&(s||r)&&e.jsx(ee,{}),j==="news"&&(s||r)&&e.jsx(se,{}),j==="pagine"&&(s||r)&&e.jsx(te,{}),j==="delibere"&&e.jsx(re,{}),j==="seo"&&s&&e.jsx(oe,{}),j==="messaggi"&&s&&e.jsx(me,{}),j==="impostazioni"&&s&&e.jsx(xe,{})]})]})})}export{ge 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.