// Certify Unified — ordering & grouping, media, exhibitions, collections.
const { useState: mS } = React;
const TODAY = "2026-10-09";
const ORDERS = [["year-asc", "Cronologico, dal più antico"], ["year-desc", "Cronologico, dal più recente"], ["added-desc", "Aggiunte di recente"], ["added-asc", "Aggiunte per prime"], ["title", "Titolo A–Z"]];
const GROUPS = [["none", "Nessun raggruppamento"], ["catdec", "Per categoria e decennio"], ["year", "Per anno"], ["decade", "Per decennio"], ["medium", "Per materiali"], ["collection", "Per collezione"]];
function sortWorks(L, o) {
  const k = { "year-asc": (a, b) => (a.seq && b.seq && a.category === b.category ? a.seq - b.seq : a.year - b.year) || a.added - b.added, "year-desc": (a, b) => b.year - a.year || a.added - b.added, "added-desc": (a, b) => b.added - a.added, "added-asc": (a, b) => a.added - b.added, title: (a, b) => a.title.localeCompare(b.title) }[o] || ((a, b) => 0);
  return L.slice().sort(k);
}
function groupWorks(L, g) {
  if (g === "none") return [["", L]];
  if (g === "catdec") { const CO = window.CU_CATS || ["Opere su tela", "Opere su carta", "Opere seriali", "Grafiche e multipli", "Opere fotografiche", "Gioielli e altri progetti"];
    const m2 = new Map(); L.forEach((a) => { const y = +a.year; const dd = Math.floor(y / 10) * 10; const k = a.category + "|" + (!y ? "Senza data" : dd < 2000 ? "Anni '" + String(dd).slice(2) : "Anni " + dd); if (!m2.has(k)) m2.set(k, []); m2.get(k).push(a); });
    const ci = (k) => { const i = CO.indexOf(k.split("|")[0]); return i < 0 ? 99 : i; };
    const yk = (v) => { const y = +v[1][0].year; return y ? Math.floor(y / 10) : 1e6; };
    return [...m2.entries()].sort((x, y) => ci(x[0]) - ci(y[0]) || (yk(x) - yk(y))); }
  const key = (a) => g === "year" ? (+a.year ? String(a.year) : "Senza data") : g === "decade" ? (+a.year ? `Anni ${String(a.year).slice(0, 3)}0` : "Senza data") : g === "medium" ? a.medium : a.collection || "Collezione non indicata";
  const m = new Map(); L.forEach((a) => { const k = key(a); if (!m.has(k)) m.set(k, []); m.get(k).push(a); });
  return [...m.entries()];
}
const exStatus = (x) => x.to < TODAY ? ["lt", "Conclusa"] : x.from > TODAY ? ["warn", "In programma"] : ["ok", "In corso"];
const currentShow = (s, a) => s.exhibitions.find((x) => a.exhibitions.includes(x.id) && x.from <= TODAY && x.to >= TODAY);
const fmtD = (d) => d ? d.split("-").reverse().join(".") : "—";

function PeekGrid({ items, cap, render, onOpen }) {
  const ref = React.useRef(null); const [st, setSt] = mS({ n: cap, h: null });
  React.useLayoutEffect(() => { const fit = () => { const g = ref.current && ref.current.firstElementChild; if (!g) return; const kids = [...g.children]; if (!kids.length) return;
    const t0 = kids[0].offsetTop; const cols = Math.max(1, kids.filter((k) => k.offsetTop === t0).length); const full = Math.max(cols, Math.floor(cap / cols) * cols);
    const n = Math.min(items.length, full + cols); if (n !== st.n && kids.length !== n) { setSt((p) => ({ ...p, n })); return; }
    const last = kids[full]; const h = last ? last.offsetTop - g.offsetTop + Math.round(last.offsetHeight * 0.45) : null; if (h !== st.h) setSt({ n, h }); };
    fit(); const ro = new ResizeObserver(fit); ref.current && ro.observe(ref.current); return () => ro.disconnect(); });
  return <div ref={ref} className="grp-peek" style={st.h ? { maxHeight: st.h } : null}>{render(items.slice(0, st.n))}<div className="grp-fade" onClick={onOpen}></div></div>;
}
function Group({ label, items, render, cap = 6 }) {
  const [all, setAll] = mS(false); if (!label) return render(items);
  return <section className="grp"><div className="grp-h"><h3>{label.split("|")[0]}{label.includes("|") && <em>{label.split("|")[1]}</em>}</h3><span>{items.length} {items.length === 1 ? "opera" : "opere"}</span>{items.length > cap && <button className="lnk" onClick={() => setAll(!all)}>{all ? "Mostra meno" : "Mostra tutte"}</button>}</div>{render(all ? items : items.slice(0, cap))}{items.length > cap && <button className="grp-more" onClick={() => setAll(!all)}><span>{all ? "Mostra meno" : `Mostra tutte le ${items.length} opere`}</span><svg viewBox="0 0 24 24" width="16" height="16" fill="none" stroke="currentColor" strokeWidth="1.8" style={{ transform: all ? "rotate(180deg)" : "none" }}><path d="M6 9l6 6 6-6" /></svg></button>}</section>;
}

// ---- media: documents, texts, images, videos ----
const MT = { doc: ["DOC", "Documento"], text: ["TXT", "Testo"], image: ["IMG", "Immagine"], video: ["VID", "Video"], audio: ["AUD", "Audio"] };
function MediaTab({ a }) {
  const { s, mut, say } = useC(); const [add, setAdd] = mS(null); const [open, setOpen] = mS(null);
  const save = () => { mut((n) => { byId(n.works, a.id).docs.push({ id: "d" + Date.now(), ...add }); log(n, { type: "catalogo", artworkId: a.id, text: `${a.title}: aggiunto ${MT[add.type][1].toLowerCase()} «${add.label}»` }); }); setAdd(null); say("Contenuto aggiunto"); };
  return <div className="card">
    <div className="c-h"><h2>Documenti e contenuti</h2><Btn k="sm dark" onClick={() => setAdd({ type: "doc", label: "", vis: "archive", body: "", url: "" })}><Ic.plus /> Aggiungi</Btn></div>
    {a.docs.map((x, i) => <div key={x.id} className="li"><span className={"file t-" + (x.type || "doc")}>{MT[x.type || "doc"][0]}</span><button className="grow" style={{ textAlign: "left" }} onClick={() => setOpen(x)}><b>{x.label}</b><div className="mut sm">{MT[x.type || "doc"][1]}{x.body ? " · " + x.body.slice(0, 60) + (x.body.length > 60 ? "…" : "") : ""}{x.url ? " · " + x.url : ""}</div></button>
      <select value={x.vis} onChange={(e) => mut((n) => { byId(n.works, a.id).docs[i].vis = e.target.value; })}><option value="public">Pubblico</option><option value="collector">Collezionista</option><option value="archive">Solo archivio</option></select>
      <button className="ib" aria-label="Rimuovi" onClick={() => mut((n) => { const w = byId(n.works, a.id); w.docs = w.docs.filter((d) => d.id !== x.id); })}><Ic.x /></button></div>)}
    {!a.docs.length && <div className="empty">Nessun contenuto. Aggiungi documenti, testi critici, immagini, video o audio.</div>}
    {add && <Modal title="Aggiungi contenuto" onClose={() => setAdd(null)} foot={<><Btn onClick={() => setAdd(null)}>Annulla</Btn><Btn k="dark" disabled={!add.label.trim()} onClick={save}>Aggiungi</Btn></>}>
      <div className="seg" style={{ marginBottom: 14 }}>{Object.keys(MT).map((k) => <button key={k} className={add.type === k ? "on" : ""} onClick={() => setAdd({ ...add, type: k })}>{MT[k][1]}</button>)}</div>
      <label className="fld"><span>Titolo</span><input value={add.label} onChange={(e) => setAdd({ ...add, label: e.target.value })} placeholder={{ doc: "Es. Lettera alla galleria, 1964", text: "Es. Scheda critica", image: "Es. Retro dell'opera", video: "Es. Intervista all'artista", audio: "Es. Registrazione d'archivio" }[add.type]} /></label>
      {add.type === "text" && <label className="fld"><span>Testo</span><textarea rows={6} value={add.body} onChange={(e) => setAdd({ ...add, body: e.target.value })} /></label>}
      {(add.type === "video" || add.type === "audio") && <label className="fld"><span>Link (YouTube, Vimeo o file)</span><input value={add.url} onChange={(e) => setAdd({ ...add, url: e.target.value })} placeholder="https://" /></label>}
      {["doc", "image"].includes(add.type) && <button className="drop" style={{ marginBottom: 12 }}><Ic.up /><b>Trascina qui il file</b><span>PDF, JPG, PNG, TIFF · caricamento simulato</span></button>}
      <label className="fld"><span>Chi può vederlo</span><select value={add.vis} onChange={(e) => setAdd({ ...add, vis: e.target.value })}><option value="archive">Solo archivio</option><option value="collector">Archivio e collezionista</option><option value="public">Pubblico, nel catalogo</option></select></label>
    </Modal>}
    {open && <Modal title={open.label} onClose={() => setOpen(null)}><MediaView d={open} /></Modal>}
  </div>;
}
function MediaView({ d }) {
  if (d.type === "text") return <p style={{ lineHeight: 1.65, fontFamily: "var(--se)", fontSize: 16, margin: 0 }}>{d.body || "—"}</p>;
  if (d.type === "video" || d.type === "audio") return <div className="vid"><span>▶</span><b>{d.label}</b><span className="mut sm">{d.url || "Nessun link"} · riproduzione simulata</span></div>;
  return <div className="vid"><span className="file">{MT[d.type || "doc"][0]}</span><b>{d.label}</b><span className="mut sm">Anteprima del file · simulata</span></div>;
}

// ---- exhibitions ----
function WorkPicker({ title, exclude, onClose, onAdd, step }) {
  const { s } = useC(); const [q, setQ] = mS(""); const [cat, setCat] = mS(""); const [dec, setDec] = mS(""); const [sel, setSel] = mS([]); const [n, setN] = mS(60);
  const cats = [...new Set(s.works.map((a) => a.category))]; const decs = [...new Set(s.works.map((a) => Math.floor(a.year / 10) * 10))].sort();
  const L = s.works.filter((a) => !exclude.includes(a.id) && (!cat || a.category === cat) && (!dec || Math.floor(a.year / 10) * 10 === +dec) && (a.title + a.catNo + a.year + a.medium).toLowerCase().includes(q.toLowerCase()));
  const tg = (id) => setSel(sel.includes(id) ? sel.filter((x) => x !== id) : [...sel, id]);
  return <Modal w={980} title={title} onClose={onClose} foot={<><span className="mut sm" style={{ marginRight: "auto" }}>{sel.length ? `${sel.length} selezionate` : "Seleziona una o più opere"}</span><Btn onClick={onClose}>{step ? "Salta, le aggiungo dopo" : "Annulla"}</Btn><Btn k="dark" disabled={!sel.length} onClick={() => onAdd(sel)}>Aggiungi opere{sel.length ? ` · ${sel.length}` : ""}</Btn></>}>
    {step && <div className="exs"><span className="done"><i>✓</i>Informazioni</span><span className="on"><i>2</i>Opere</span><em>Mostra salvata. Seleziona le opere esposte.</em></div>}
    <label className="wk-s" style={{ marginBottom: 14 }}><Ic.search /><input autoFocus value={q} onChange={(e) => setQ(e.target.value)} placeholder="Cerca per titolo, anno, numero di catalogo…" /></label>
    <div className="wk-fs" style={{ marginBottom: 16 }}><WkSel v={cat} set={setCat} label="Categoria" opts={cats} /><WkSel v={dec} set={setDec} label="Decennio" opts={decs.map((d) => [String(d), "Anni " + String(d).slice(2)])} />
      <button className="wk-clr" onClick={() => setSel([...new Set([...sel, ...L.slice(0, n).map((a) => a.id)])])}>Seleziona visibili</button>{sel.length > 0 && <button className="wk-clr" onClick={() => setSel([])}>Deseleziona</button>}<span className="wk-n" style={{ marginLeft: "auto" }}>{L.length} opere</span></div>
    <div className="wp-g">{L.slice(0, n).map((a) => { const on = sel.includes(a.id); return <button key={a.id} className={"wp-c" + (on ? " on" : "")} onClick={() => tg(a.id)}><div className="wp-i"><Art a={a} label={false} r={0} /><i>{on && <Ic.check />}</i></div><b>{a.title}</b><span>{a.yearLabel || a.year}</span></button>; })}</div>
    {!L.length && <div className="empty">Nessuna opera disponibile.</div>}
    {L.length > n && <div style={{ textAlign: "center", marginTop: 18 }}><Btn k="sm" onClick={() => setN(n + 60)}>Mostra altre</Btn></div>}
  </Modal>;
}
function Exhibitions() {
  const { s, mut, go, say } = useC(); const sel = s.route.id && byId(s.exhibitions, s.route.id); const [ed, setEd] = mS(s.route.create ? { id: "", title: "", venue: "", city: "", from: TODAY, to: TODAY } : null); const [q, setQ] = mS(""); const [pick, setPick] = mS(s.route.pick || false); React.useEffect(() => { if (s.route.pick) setPick(true); }, [s.route.id, s.route.pick]);
  const works = (x) => s.works.filter((a) => a.exhibitions.includes(x.id));
  if (sel) { const W = works(sel); const cand = q.trim() ? s.works.filter((a) => !a.exhibitions.includes(sel.id) && (a.title + a.catNo + a.year).toLowerCase().includes(q.toLowerCase())).slice(0, 8) : [];
    const link = (aid, on) => mut((n) => { const a = byId(n.works, aid); a.exhibitions = on ? [...a.exhibitions, sel.id] : a.exhibitions.filter((e) => e !== sel.id); log(n, { type: "catalogo", artworkId: aid, text: `${a.title}: ${on ? "aggiunta a" : "rimossa da"} «${sel.title}»` }); });
    const st = exStatus(sel);
    return <div className="page"><button className="lnk back" onClick={() => go({ v: "archive", p: "exhibitions" })}><Ic.back /> Mostre</button>
      <PH k={[sel.kind, [sel.venue, sel.city].filter(Boolean).join(", ")].filter(Boolean).join(" · ")} t={sel.title} sub={[`${fmtD(sel.from)} – ${fmtD(sel.to)}`, sel.curator && "a cura di " + sel.curator].filter(Boolean).join(" · ")} right={<><Pill k={st[0]}>{st[1]}</Pill><Btn onClick={() => setEd({ ...sel })}>Modifica</Btn></>} />
      {st[1] === "In corso" && <div className="hint" style={{ marginTop: 0, marginBottom: 16 }}>Mostra in corso: le opere esposte risultano «attualmente in mostra» nella loro scheda. Collezione e luogo di conservazione restano invariati.</div>}
      <div className="card"><div className="c-h"><h2>Opere in mostra · {W.length}</h2><Btn k="dark" onClick={() => setPick(true)}><Ic.plus /> Aggiungi opere</Btn></div>
        <div className="wgrid" style={{ marginTop: 14 }}>{W.map((a) => <div key={a.id} className="wc"><button className="wc-i" onClick={() => go({ v: "archive", p: "work", id: a.id })}><Art a={a} /></button><b>{a.title}</b><span className="mut sm">{a.yearLabel || a.year} · {a.collection}</span><button className="lnk sm" onClick={() => link(a.id, false)}>Rimuovi dalla mostra</button></div>)}</div>
        </div>
      {pick && <WorkPicker step={s.route.pick === "new"} title={`Aggiungi opere a «${sel.title}»`} exclude={W.map((a) => a.id)} onClose={() => { setPick(false); if (s.route.pick) go({ v: "archive", p: "exhibitions", id: sel.id }); }} onAdd={(ids) => { mut((n) => { ids.forEach((id) => { const a = byId(n.works, id); if (!a.exhibitions.includes(sel.id)) a.exhibitions.push(sel.id); }); log(n, { type: "catalogo", text: `${ids.length} opere aggiunte a «${sel.title}»` }); }); setPick(false); say(`${ids.length} ${ids.length === 1 ? "opera aggiunta" : "opere aggiunte"} alla mostra`); }} />}
      {ed && <ExForm x={ed} setX={setEd} onSave={() => { mut((n) => { Object.assign(byId(n.exhibitions, ed.id), ed); log(n, { type: "catalogo", text: `Mostra aggiornata: ${ed.title}` }); }); setEd(null); say("Mostra aggiornata su tutte le opere collegate"); }} />}
    </div>; }
  return <div className="page"><PH t="Mostre" sub="Ogni mostra si registra una volta e si collega alle opere esposte." right={<Btn k="dark" onClick={() => setEd({ id: "", title: "", venue: "", city: "", from: TODAY, to: TODAY })}><Ic.plus /> Nuova mostra</Btn>} />
    <div className="tbl"><table><thead><tr><th>Mostra</th><th>Sede</th><th>Tipologia</th><th>Date</th><th>Opere</th><th>Stato</th></tr></thead><tbody>{s.exhibitions.slice().sort((a, b) => b.from.localeCompare(a.from)).map((x) => { const st = exStatus(x); return <tr key={x.id} onClick={() => go({ v: "archive", p: "exhibitions", id: x.id })}><td><b>{x.title}</b></td><td>{[x.venue, x.city].filter(Boolean).join(", ") || "—"}</td><td className="mut">{x.kind || "—"}</td><td className="mono">{fmtD(x.from)} – {fmtD(x.to)}</td><td>{works(x).length}</td><td><Pill k={st[0]}>{st[1]}</Pill></td></tr>; })}</tbody></table></div>
    {ed && <ExForm x={ed} setX={setEd} onSave={() => { const id = "x" + Date.now(); mut((n) => { n.exhibitions.push({ ...ed, title: ed.title.trim(), id }); log(n, { type: "catalogo", text: `Nuova mostra: ${ed.title}` }); }); setEd(null); say("Mostra salvata"); go({ v: "archive", p: "exhibitions", id, pick: "new" }); }} />}
  </div>;
}
function ExForm({ x, setX, onSave }) {
  const nw = !x.id; const [ln, setLn] = uS("it");
  const Seg = ({ v, set, opts, cls }) => <div className={"exf-seg " + (cls || "")}>{opts.map(([k, l]) => <button key={k} type="button" className={v === k ? "on" : ""} onClick={() => set(k)}>{l}</button>)}</div>;
  const F = (k, l, ph) => <label className="exf-f"><span className="exf-l">{l}</span><input value={x[k] || ""} placeholder={ph || ""} onChange={(e) => setX({ ...x, [k]: e.target.value })} /></label>;
  const yOf = (v) => (v || "").slice(0, 4);
  const D = (k, l) => { const p = x[k + "P"] || "exact"; const y = yOf(x[k]); const set = (np) => setX({ ...x, [k + "P"]: np, [k]: np === "exact" ? x[k] : np === "decade" ? (y ? y.slice(0, 3) + "0-01-01" : "") : (y ? y + "-01-01" : "") });
    return <div className="exf-f"><div className="exf-lr"><span className="exf-l">{l}</span><Seg v={p} set={set} opts={[["exact", "Data"], ["year", "Anno"], ["decade", "Decennio"]]} cls="sm" /></div>
      {p === "exact" ? <input type="date" value={x[k] || ""} onChange={(e) => setX({ ...x, [k]: e.target.value })} />
        : p === "year" ? <input inputMode="numeric" maxLength={4} placeholder="Es. 1964" value={y} onChange={(e) => { const v = e.target.value.replace(/\D/g, "").slice(0, 4); setX({ ...x, [k]: v.length === 4 ? v + "-01-01" : v }); }} />
        : <select value={y ? y.slice(0, 3) + "0" : ""} onChange={(e) => setX({ ...x, [k]: e.target.value ? e.target.value + "-01-01" : "" })}><option value="">Scegli il decennio</option>{[1940, 1950, 1960, 1970, 1980, 1990, 2000, 2010, 2020].map((d) => <option key={d} value={d}>Anni {String(d).slice(2)}</option>)}</select>}
    </div>; };
  return <Modal title={nw ? "Nuova mostra" : "Modifica mostra"} onClose={() => setX(null)} foot={<><Btn onClick={() => setX(null)}>Annulla</Btn><Btn k="dark" disabled={!(x.title || "").trim()} onClick={onSave}>{nw ? "Salva e seleziona le opere" : "Salva"}</Btn></>}>
    {nw && <div className="exs"><span className="on"><i>1</i>Informazioni</span><span><i>2</i>Opere</span></div>}
    <div className="exf">
      <div className="exf-f exf-w"><div className="exf-lr"><span className="exf-l">Titolo mostra<i className="req">*</i></span><Seg v={ln} set={setLn} opts={[["it", "IT"], ["en", "EN"]]} cls="sm" /></div>
        {ln === "it" ? <input autoFocus value={x.title || ""} onChange={(e) => setX({ ...x, title: e.target.value })} placeholder="Es. Franco Angeli. Gli anni Sessanta" />
          : <input autoFocus value={x.titleEn || ""} onChange={(e) => setX({ ...x, titleEn: e.target.value })} placeholder="Titolo in inglese (facoltativo)" />}</div>
      {F("venue", "Sede / istituzione")}{F("city", "Città")}
      {F("curator", "Curatela", "Facoltativo")}
      <div className="exf-f"><span className="exf-l">Tipologia</span><Seg v={x.kind || ""} set={(k) => setX({ ...x, kind: x.kind === k ? "" : k })} opts={[["Personale", "Personale"], ["Collettiva", "Collettiva"]]} cls="lg" /></div>
      <div className="exf-sep"></div>
      {D("from", "Dal")}{D("to", "Al")}
    </div>
  </Modal>;
}


// ---- collections & locations ----
function Collections() {
  const { s, go } = useC(); const [sel, setSel] = mS(null); const [n, setN] = mS(40);
  const G = groupWorks(s.works, "collection").sort((x, y) => y[1].length - x[1].length);
  const meta = (L) => { const locs = [...new Set(L.map((a) => a.loc).filter(Boolean))]; const ys = L.map((a) => a.year).filter(Boolean); return { locs, shows: L.filter((a) => currentShow(s, a)).length, yrs: ys.length ? Math.min(...ys) + "–" + Math.max(...ys) : "—" }; };
  if (sel) { const g = G.find((x) => x[0] === sel); const L = g ? g[1] : []; const m = meta(L);
    return <div className="page"><button className="lnk back" onClick={() => { setSel(null); setN(40); }}><Ic.back /> Collezioni</button>
      <PH k={m.locs.join(" · ") || "Luogo non indicato"} t={sel} sub={`Opere dal ${m.yrs}`} right={m.shows > 0 ? <Pill k="ok">{m.shows} in mostra</Pill> : null} />
      <div className="card"><div className="c-h"><h2>Opere nella collezione · {L.length}</h2></div>
        <div className="wgrid" style={{ marginTop: 14 }}>{L.slice(0, n).map((a) => { const sh = currentShow(s, a); return <div key={a.id} className="wc"><button className="wc-i" onClick={() => go({ v: "archive", p: "work", id: a.id })}><Art a={a} /></button><b>{a.title}</b><span className="mut sm">{a.yearLabel || a.year}{a.loc ? " · " + a.loc : ""}</span>{sh && <span className="mut sm">In mostra · {sh.venue}</span>}</div>; })}</div>
        {L.length > n && <div style={{ textAlign: "center", marginTop: 20 }}><Btn k="sm" onClick={() => setN(n + 40)}>Mostra altre opere</Btn></div>}</div>
    </div>; }
  return <div className="page"><PH t="Collezioni" sub="Dove si trovano le opere oggi." />
    <div className="tbl"><table><thead><tr><th>Collezione</th><th>Luogo</th><th>Periodo</th><th>Opere</th><th>Stato</th></tr></thead><tbody>{G.map(([c, L]) => { const m = meta(L); return <tr key={c} onClick={() => setSel(c)}><td><b>{c}</b></td><td>{m.locs[0] || "—"}</td><td className="mono">{m.yrs}</td><td>{L.length.toLocaleString("it-IT")}</td><td>{m.shows > 0 ? <Pill k="ok">{m.shows} in mostra</Pill> : <span className="mut sm">In sede</span>}</td></tr>; })}</tbody></table></div>
  </div>;
}

function CollRow({ name, L, open }) {
  const { s, go } = useC(); const [o, setO] = mS(false); const [n, setN] = mS(20); const isOpen = o || open;
  const locs = [...new Set(L.map((a) => a.loc).filter(Boolean))]; const shows = L.filter((a) => currentShow(s, a)).length;
  return <div className={"acc-i" + (isOpen ? " on" : "")}>
    <button className="acc-h" onClick={() => setO(!o)}><span className="acc-c"><Ic.chev /></span><div className="grow"><b>{name}</b><span>{locs.slice(0, 2).join(" · ")}{locs.length > 2 ? " · …" : ""}</span></div>{shows > 0 && <Pill k="ok">{shows} in mostra</Pill>}<span className="acc-n">{L.length.toLocaleString("it-IT")} opere</span></button>
    {isOpen && <div className="acc-b"><div className="tbl"><table><tbody>{L.slice(0, n).map((a) => { const sh = currentShow(s, a); return <tr key={a.id} onClick={() => go({ v: "archive", p: "work", id: a.id })}><td style={{ width: 52 }}><div className="th"><Art a={a} label={false} r={6} /></div></td><td><b>{a.title}</b><div className="mut sm">{a.yearLabel || a.year}</div></td><td>{a.loc || <span className="mut">Luogo non indicato</span>}</td><td>{sh ? <Pill k="ok">In mostra · {sh.venue}</Pill> : <span className="mut sm">In sede</span>}</td></tr>; })}</tbody></table></div>
      {L.length > n && <div style={{ textAlign: "center", marginTop: 10 }}><Btn k="sm" onClick={() => setN(n + 40)}>Mostra altre {Math.min(40, L.length - n)}</Btn></div>}</div>}
  </div>;
}
Object.assign(window, { WorkPicker, CollRow, ORDERS, GROUPS, sortWorks, groupWorks, exStatus, currentShow, fmtD, Group, MediaTab, MediaView, MT, Exhibitions, Collections });
