// GameSync.tsx — Bridge useSaveSync ↔ Zustand store
// Monter une seule fois dans App. Silencieux en mode invité (pas de token).

import { useCallback } from "react";
import { useGameStore } from "../store/useGameStore";
import { useSaveSync } from "../hooks/useSaveSync";

export function GameSync() {
  const state = useGameStore((s) => s.state);
  const loadFromServer = useGameStore((s) => s.loadFromServer);
  const playSeconds = useGameStore((s) => s.playSeconds);

  const getGameState = useCallback(() => state, [state]);

  useSaveSync({
    getGameState,
    onLoad: loadFromServer,
    playTimeSeconds: playSeconds,
  });

  return null;
}
