2026-08-06 08:36:47 +02:00
|
|
|
import { useMemo } from "react";
|
|
|
|
|
import { useEventi } from "./eventi";
|
|
|
|
|
import { useRispostePresenze } from "./presenze";
|
2026-09-03 10:16:52 +02:00
|
|
|
import { useGiocatoriSquadra } from "./giocatori-squadra";
|
2026-09-06 11:41:14 +02:00
|
|
|
import {
|
|
|
|
|
presenzeUltimoMese,
|
|
|
|
|
presenzeUltimoMeseTutti,
|
|
|
|
|
type StatistichePresenza,
|
|
|
|
|
} from "./presenze-mese-core";
|
2026-08-06 08:36:47 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Percentuale di presenze dell'ultimo mese (30 giorni), utile per le convocazioni.
|
2026-09-06 11:41:14 +02:00
|
|
|
* Usa solo cache già in memoria: nessuna query aggiuntiva. Il calcolo sta in
|
|
|
|
|
* `presenze-mese-core.ts`, qui c'è solo il collegamento agli hook.
|
2026-08-06 08:36:47 +02:00
|
|
|
*/
|
2026-09-06 11:41:14 +02:00
|
|
|
export function usePresenzeUltimoMese(giocatoreId: string | undefined): StatistichePresenza {
|
2026-08-06 08:36:47 +02:00
|
|
|
const { eventi } = useEventi();
|
|
|
|
|
const { presenze } = useRispostePresenze();
|
|
|
|
|
|
2026-09-06 11:41:14 +02:00
|
|
|
return useMemo(
|
|
|
|
|
() => presenzeUltimoMese(giocatoreId, eventi, presenze),
|
|
|
|
|
[eventi, presenze, giocatoreId],
|
|
|
|
|
);
|
2026-08-06 08:36:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** Percentuale presenze ultimi 30 giorni per tutti i giocatori (mappa per id). */
|
2026-09-06 11:41:14 +02:00
|
|
|
export function usePresenzeUltimoMeseTutti(): Record<string, StatistichePresenza> {
|
2026-08-06 08:36:47 +02:00
|
|
|
const { eventi } = useEventi();
|
|
|
|
|
const { presenze } = useRispostePresenze();
|
2026-09-03 10:16:52 +02:00
|
|
|
const { righe: squadra } = useGiocatoriSquadra();
|
2026-08-06 08:36:47 +02:00
|
|
|
|
|
|
|
|
return useMemo(() => {
|
2026-09-03 10:16:52 +02:00
|
|
|
const idRosa = squadra.filter((g) => g.attivo).map((g) => g.id);
|
2026-09-06 11:41:14 +02:00
|
|
|
return presenzeUltimoMeseTutti(eventi, presenze, idRosa);
|
2026-09-03 10:16:52 +02:00
|
|
|
}, [eventi, presenze, squadra]);
|
2026-09-01 13:38:33 +02:00
|
|
|
}
|