PageSourceSearch

https://www.stazionedellarte.com/assets/admin_.mostre._id-BhIWrYHS.js

js stazionedellarte.com collected 2026-10-01 11:56:22 UTC 11,540 bytes, 1 lines download raw bytes

1import{r as b,j as e,s as N,a0 as D,d as A,L as w}from"./index-C3SzbFls.js";import{u as F}from"./use-auth-Cs4JOWiu.js";import{F as x,A as C,u as S}from"./ui-B0Ja3t6M.js";const P={slug:"",title:"",subtitle:"",period:"",start_date:"",end_date:"",curator:"",venue:"",synopsis:"",description:"",cover_image:"",gallery:[],status:"past",sort_order:0,published:!1};function _(n){return n.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^a-z0-9]+/g,"-").replace(/(^-|-$)/g,"").slice(0,80)}function L({initial:n,onSaved:u,onCancel:p}){const[t,s]=b.useState(n),[o,c]=b.useState(!1),[i,a]=b.useState(!1),l=async r=>{if(!t.title.trim()){alert("Il titolo è obbligatorio");return}const d=t.slug.trim()||_(t.title);if(!d){alert("Lo slug è obbligatorio");return}const m=r??t.published;c(!0);const g={slug:d,title:t.title,subtitle:t.subtitle,period:t.period,start_date:t.start_date||null,end_date:t.end_date||null,curator:t.curator,venue:t.venue,synopsis:t.synopsis,description:t.description,cover_image:t.cover_image,gallery:t.gallery,status:t.status,sort_order:t.sort_order,published:m},y=t.id?await N.from("exhibitions").update(g).eq("id",t.id).select().maybeSingle():await N.from("exhibitions").insert(g).select().maybeSingle();if(c(!1),y.error){alert(y.error.message);return}const k=y.data??{...t,...g,id:t.id};s(k),u(k)},f=async r=>{a(!0);try{s({...t,cover_image:await S("exhibitions",r)})}catch(d){alert(d.message)}a(!1)},h=async r=>{a(!0);try{const d=await Promise.all(Array.from(r).map(m=>S("exhibitions",m)));s({...t,gallery:[...t.gallery,...d]})}catch(d){alert(d.message)}a(!1)},v=t.slug.trim()||(t.title?_(t.title):""),j=!!t.id&&!!v;return e.jsxs("form",{onSubmit:r=>{r.preventDefault(),l()},className:"space-y-6",children:[e.jsxs("section",{className:"space-y-4",children:[e.jsxs("div",{className:"grid md:grid-cols-2 gap-4",children:[e.jsx(x,{label:"Titolo",value:t.title,onChange:r=>s({...t,title:r}),required:!0}),e.jsx(x,{label:"Slug (URL)",value:t.slug,onChange:r=>s({...t,slug:r})})]}),e.jsx(x,{label:"Sottotitolo",value:t.subtitle??"",onChange:r=>s({...t,subtitle:r})}),e.jsxs("div",{className:"grid md:grid-cols-2 gap-4",children:[e.jsx(x,{label:"Periodo (es. 2024 - 2025)",value:t.period??"",onChange:r=>s({...t,period:r})}),e.jsx(x,{label:"Curatore",value:t.curator??"",onChange:r=>s({...t,curator:r})})]}),e.jsxs("div",{className:"grid md:grid-cols-2 gap-4",children:[e.jsx(x,{label:"Data inizio",type:"date",value:t.start_date??"",onChange:r=>s({...t,start_date:r})}),e.jsx(x,{label:"Data fine",type:"date",value:t.end_date??"",onChange:r=>s({...t,end_date:r})})]}),e.jsx(x,{label:"Sede",value:t.venue??"",onChange:r=>s({...t,venue:r})})]}),e.jsxs("section",{className:"space-y-4 border-t border-border pt-6",children:[e.jsx(x,{label:"Sinossi (breve)",value:t.synopsis??"",onChange:r=>s({...t,synopsis:r}),textarea:!0,rows:3}),e.jsx(x,{label:"Descrizione completa",value:t.description??"",onChange:r=>s({...t,description:r}),textarea:!0,rows:12}),e.jsxs("p",{className:"text-xs text-stone-warm",children:["Suggerimento: separa le sezioni con ",e.jsx("code",{children:"## Titolo"})," su una nuova riga."]})]}),e.jsx("section",{className:"border-t border-border pt-6",children:e.jsx(z,{value:t.cover_image,uploading:i,onPick:r=>f(r),onRemove:()=>s({...t,cover_image:null})})}),e.jsx("section",{className:"border-t border-border pt-6",children:e.jsx(E,{items:t.gallery,uploading:i,onAdd:r=>h(r),onRemove:r=>s({...t,gallery:t.gallery.filter((d,m)=>m!==r)}),onMove:(r,d)=>{const m=[...t.gallery],g=r+d;g<0||g>=m.length||([m[r],m[g]]=[m[g],m[r]],s({...t,gallery:m}))}})}),e.jsxs("section",{className:"border-t border-border pt-6 grid md:grid-cols-3 gap-4 items-end",children:[e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"eyebrow text-stone-warm",children:"Stato"}),e.jsxs("select",{value:t.status,onChange:r=>s({...t,status:r.target.value}),className:"mt-2 w-full bg-transparent border border-border px-3 py-2 text-sm",children:[e.jsx("option",{value:"current",children:"Attuale"}),e.jsx("option",{value:"past",children:"Passata"}),e.jsx("option",{value:"upcoming",children:"In arrivo"})]})]}),e.jsx(x,{label:"Ordine",type:"number",value:String(t.sort_order),onChange:r=>s({...t,sort_order:parseInt(r)||0})}),e.jsxs("div",{children:[e.jsx("span",{className:"eyebrow text-stone-warm",children:"Visibilità attuale"}),e.jsx("div",{className:"mt-2 text-sm",children:t.published?e.jsx("span",{className:"inline-block px-2 py-1 bg-ink text-paper text-xs uppercase tracking-[0.18em]",children:"Pubblicata"}):e.jsx("span",{className:"inline-block px-2 py-1 border border-border text-stone-warm text-xs uppercase tracking-[0.18em]",children:"Bozza"})})]})]}),e.jsxs("div",{className:"sticky bottom-0 bg-paper border-t border-border pt-4 pb-4 -mx-6 px-6 md:-mx-10 md:px-10 flex flex-wrap gap-3 justify-between items-center",children:[e.jsxs("div",{className:"flex gap-3",children:[p&&e.jsx("button",{type:"button",onClick:p,className:"text-xs uppercase tracking-[0.18em] px-4 py-2 border border-border hover:border-ink",children:"Annulla"}),j&&e.jsx("a",{href:`/mostre/${v}`,target:"_blank",rel:"noreferrer",className:"text-xs uppercase tracking-[0.18em] px-4 py-2 border border-ink hover:bg-ink hover:text-paper transition",children:"Anteprima ↗"})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx(C,{variant:"outline",type:"button",disabled:o||i,onClick:()=>l(!1),children:o?"Salvataggio…":"Salva bozza"}),e.jsx(C,{type:"button",disabled:o||i,onClick:()=>l(!0),children:o?"Salvataggio…":"Salva e pubblica"})]})]})]})}function z({value:n,uploading:u,onPick:p,onRemove:t}){const[s,o]=b.useState(!1),c="cover-upload";return e.jsxs("div",{children:[e.jsx("div",{className:"eyebrow text-stone-warm mb-2",children:"Immagine di copertina"}),n?e.jsxs("div",{className:"relative inline-block group",children:[e.jsx("img",{src:n,alt:"",className:"w-64 h-40 object-cover border border-border"}),e.jsxs("div",{className:"absolute inset-0 bg-ink/0 group-hover:bg-ink/40 transition flex items-center justify-center gap-2 opacity-0 group-hover:opacity-100",children:[e.jsx("label",{htmlFor:c,className:"cursor-pointer text-[11px] uppercase tracking-[0.18em] px-3 py-2 bg-paper text-ink border border-ink",children:"Sostituisci"}),e.jsx("button",{type:"button",onClick:t,className:"text-[11px] uppercase tracking-[0.18em] px-3 py-2 bg-paper text-red-700 border border-red-700",children:"Rimuovi"})]})]}):e.jsxs("label",{htmlFor:c,onDragOver:i=>{i.preventDefault(),o(!0)},onDragLeave:()=>o(!1),onDrop:i=>{i.preventDefault(),o(!1);const a=i.dataTransfer.files?.[0];a&&p(a)},className:`flex flex-col items-center justify-center cursor-pointer border-2 border-dashed ${s?"border-ink bg-paper-warm/60":"border-border hover:border-ink/60"} px-6 py-10 transition`,children:[e.jsx("div",{className:"text-sm text-ink",children:u?"Caricamento in corso…":"Trascina qui un'immagine o clicca per scegliere"}),e.jsx("div",{className:"text-xs text-stone-warm mt-1",children:"JPG, PNG, WEBP"})]}
1),e.jsx("input",{id:c,type:"file",accept:"image/*",className:"hidden",onChange:i=>i.target.files?.[0]&&p(i.target.files[0])})]})}function E({items:n,uploading:u,onAdd:p,onRemove:t,onMove:s}){const[o,c]=b.useState(!1),i="gallery-upload";return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"eyebrow text-stone-warm",children:["Galleria ",n.length>0&&e.jsxs("span",{className:"normal-case tracking-normal text-ink",children:["· ",n.length," ",n.length===1?"immagine":"immagini"]})]}),e.jsx("label",{htmlFor:i,className:"cursor-pointer text-[11px] uppercase tracking-[0.18em] px-3 py-2 border border-ink hover:bg-ink hover:text-paper transition",children:"+ Aggiungi immagini"})]}),e.jsx("input",{id:i,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:a=>a.target.files&&a.target.files.length>0&&p(a.target.files)}),e.jsx("div",{onDragOver:a=>{a.preventDefault(),c(!0)},onDragLeave:()=>c(!1),onDrop:a=>{a.preventDefault(),c(!1),a.dataTransfer.files?.length&&p(a.dataTransfer.files)},className:`border-2 border-dashed p-3 transition ${o?"border-ink bg-paper-warm/60":"border-border"}`,children:n.length===0?e.jsx("div",{className:"text-center text-sm text-stone-warm py-8",children:u?"Caricamento in corso…":'Trascina qui le immagini o usa il pulsante "Aggiungi immagini"'}):e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3",children:[n.map((a,l)=>e.jsxs("div",{className:"relative group border border-border",children:[e.jsx("img",{src:a,alt:"",className:"w-full h-28 object-cover"}),e.jsx("div",{className:"absolute top-1 left-1 text-[10px] px-1.5 py-0.5 bg-ink text-paper",children:l+1}),e.jsx("button",{type:"button",onClick:()=>t(l),title:"Rimuovi",className:"absolute top-1 right-1 w-6 h-6 flex items-center justify-center bg-paper text-red-700 border border-red-700 opacity-0 group-hover:opacity-100 transition",children:"×"}),e.jsxs("div",{className:"absolute bottom-1 right-1 flex gap-1 opacity-0 group-hover:opacity-100 transition",children:[e.jsx("button",{type:"button",onClick:()=>s(l,-1),disabled:l===0,title:"Sposta indietro",className:"w-6 h-6 flex items-center justify-center bg-paper text-ink border border-ink disabled:opacity-30",children:"‹"}),e.jsx("button",{type:"button",onClick:()=>s(l,1),disabled:l===n.length-1,title:"Sposta avanti",className:"w-6 h-6 flex items-center justify-center bg-paper text-ink border border-ink disabled:opacity-30",children:"›"})]})]},l)),u&&e.jsx("div",{className:"border border-dashed border-border h-28 flex items-center justify-center text-xs text-stone-warm",children:"Caricamento…"})]})})]})}function q(){const{id:n}=D.useParams(),u=A(),{user:p,isAdmin:t,isContentAdmin:s,loading:o}=F(),c=t||s,i=n==="nuova",[a,l]=b.useState(null),[f,h]=b.useState(!i),[v,j]=b.useState(!1);return b.useEffect(()=>{!o&&!p&&u({to:"/login",replace:!0})},[o,p,u]),b.useEffect(()=>{if(i){l({id:"",...P});return}c&&(h(!0),N.from("exhibitions").select("*").eq("id",n).maybeSingle().then(({data:r,error:d})=>{if(d||!r){j(!0),h(!1);return}l(r),h(!1)}))},[n,i,c]),o||!i&&f?e.jsx("div",{className:"min-h-screen flex items-center justify-center text-stone-warm",children:"Caricamento…"}):p?c?v?e.jsx("div",{className:"min-h-screen bg-paper pt-24 pb-12",children:e.jsxs("div",{className:"mx-auto max-w-2xl px-6 text-center",children:[e.jsx("h1",{className:"display-md",children:"Mostra non trovata"}),e.jsx(w,{to:"/admin",className:"mt-6 inline-block text-xs uppercase tracking-[0.18em] link-underline",children:"← Torna al pannello"})]})}):a?e.jsx("div",{className:"min-h-screen bg-paper pt-6 pb-24",children:e.jsxs("div",{className:"mx-auto max-w-[1100px] px-6 md:px-10",children:[e.jsx("div",{className:"flex items-center justify-between border-b border-border pb-6",children:e.jsxs("div",{children:[e.jsx(w,{to:"/admin",className:"eyebrow text-stone-warm link-underline",children:"← Pannello"}),e.jsx("h1",{className:"display-md mt-2",children:i?"Nuova mostra":"Modifica mostra"}),!i&&a.slug&&e.jsxs("p",{className:"text-xs text-stone-warm mt-2",children:["URL pubblico: ",e.jsxs("code",{children:["/mostre/",a.slug]})]})]})}),e.jsx("div",{className:"mt-8",children:e.jsx(L,{initial:a,onCancel:()=>u({to:"/admin"}),onSaved:r=>{i&&r.id?u({to:"/admin/mostre/$id",params:{id:r.id},replace:!0}):l(r)}})})]})}):null:e.jsx("div",{className:"min-h-screen flex items-center justify-center text-stone-warm px-6",children:"Accesso negato."}):null}export{q 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.