2026-08-06 08:36:47 +02:00
|
|
|
import { Link } from "@tanstack/react-router";
|
|
|
|
|
import { ChevronRight, Lock, Radio } from "lucide-react";
|
|
|
|
|
import { cn } from "@/lib/utils";
|
|
|
|
|
import { sessioneScaduta, usePartitaDiOggi, useSessioneScout } from "@/lib/scout-live";
|
|
|
|
|
import { useGiocatoreCorrente } from "@/lib/user-store";
|
2026-08-30 17:57:59 +02:00
|
|
|
import { useIsAdmin } from "@/lib/ruoli";
|
2026-08-06 08:36:47 +02:00
|
|
|
|
|
|
|
|
/** Accesso allo scout live: attivo solo il giorno della partita e se nessun altro lo sta usando. */
|
|
|
|
|
export function ScoutEntry({ variante = "grande" }: { variante?: "grande" | "compatto" }) {
|
|
|
|
|
const { pronto, partita } = usePartitaDiOggi();
|
|
|
|
|
const io = useGiocatoreCorrente();
|
2026-08-30 17:57:59 +02:00
|
|
|
const admin = useIsAdmin();
|
2026-08-06 08:36:47 +02:00
|
|
|
const { data: sessione } = useSessioneScout(partita?.id ?? null);
|
|
|
|
|
|
|
|
|
|
// Strumento tecnico: solo i referenti/allenatori scoutizzano la partita.
|
2026-08-30 17:57:59 +02:00
|
|
|
const abilitato = admin;
|
2026-08-06 08:36:47 +02:00
|
|
|
|
|
|
|
|
const attiva = sessione && !sessioneScaduta(sessione) ? sessione : null;
|
|
|
|
|
const occupato = !!attiva && attiva.giocatore_id !== io?.id;
|
|
|
|
|
const disponibile = abilitato && pronto && !!partita && !occupato;
|
|
|
|
|
|
2026-09-01 13:38:33 +02:00
|
|
|
const titolo = !abilitato
|
|
|
|
|
? "Scout live"
|
|
|
|
|
: !partita
|
|
|
|
|
? "Scout live non attivo"
|
|
|
|
|
: occupato
|
|
|
|
|
? "Scout occupato"
|
|
|
|
|
: "Scout live";
|
|
|
|
|
const sottotitolo = !abilitato
|
|
|
|
|
? "Riservato ad allenatori e referenti"
|
|
|
|
|
: !partita
|
|
|
|
|
? "Si attiva il giorno della partita"
|
|
|
|
|
: occupato
|
|
|
|
|
? `In uso da ${attiva!.giocatore_nome}`
|
|
|
|
|
: "Segna punti, ace e muri in tempo reale";
|
2026-08-06 08:36:47 +02:00
|
|
|
|
|
|
|
|
const contenuto = (
|
|
|
|
|
<>
|
|
|
|
|
{occupato ? <Lock className="h-5 w-5 shrink-0" /> : <Radio className="h-5 w-5 shrink-0" />}
|
|
|
|
|
<span className="min-w-0 flex-1">
|
|
|
|
|
<span className="block font-display text-lg uppercase leading-none">{titolo}</span>
|
|
|
|
|
<span className="block text-[11px] opacity-80">{sottotitolo}</span>
|
|
|
|
|
</span>
|
|
|
|
|
{disponibile ? <ChevronRight className="h-5 w-5 shrink-0" /> : null}
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const classi = cn(
|
|
|
|
|
"flex items-center gap-3 rounded-3xl p-4 shadow-card",
|
|
|
|
|
variante === "compatto" && "gap-2 rounded-2xl p-3",
|
|
|
|
|
disponibile
|
|
|
|
|
? "bg-accent-grad text-accent-foreground shadow-pop"
|
|
|
|
|
: "bg-card text-muted-foreground",
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (!disponibile) {
|
|
|
|
|
return (
|
|
|
|
|
<div className={classi} aria-disabled>
|
|
|
|
|
{contenuto}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Link to="/scout" className={classi}>
|
|
|
|
|
{contenuto}
|
|
|
|
|
</Link>
|
|
|
|
|
);
|
|
|
|
|
}
|