import type { Coordonnees, GuessResult, RoundPlace } from '$lib/types';

export interface MancheDefi {
	place: RoundPlace;
	guess: Coordonnees | null;
	result: GuessResult;
}

/** État du Défi 5 rounds — client uniquement, sans session serveur. */
function creerDefiStore() {
	let manches = $state<MancheDefi[]>([]);

	return {
		get manches() {
			return manches;
		},
		get total() {
			return manches.reduce((s, m) => s + m.result.score, 0);
		},
		get termine() {
			return manches.length >= 5;
		},
		ajouter(manche: MancheDefi) {
			manches = [...manches, manche];
		},
		reinitialiser() {
			manches = [];
		}
	};
}

export const defi = creerDefiStore();
