import { addSeconds } from "date-fns";
import { create } from "zustand";

import { maxPingDelaySeconds } from "@/constants";

interface State {
	isServerConnected: boolean;
	setIsServerConnected: (isConnected: boolean) => void;
	pingTimer: Date;
	setPingTimer: (date: Date) => void;
}

export const usePingStore = create<State>((set) => ({
	isServerConnected: true,
	setIsServerConnected: (connected) => set({ isServerConnected: connected }),

	pingTimer: addSeconds(new Date(), maxPingDelaySeconds),
	setPingTimer: (date) => set({ pingTimer: date }),
}));
