import { create } from 'zustand';
import type { AutoplayPayload } from '@/lib/autoplay-ipc';

interface AutoplayPayloadState {
  payload: AutoplayPayload | null;
  pendingNav: { networkId: string; streamId: string; nonce: number } | null;
  setPayload: (payload: AutoplayPayload | null) => void;
  setPendingNav: (d: { networkId: string; streamId: string } | null) => void;
}

export const useAutoplayPayloadStore = create<AutoplayPayloadState>((set) => ({
  payload: null,
  pendingNav: null,
  setPayload: (payload) => set({ payload }),
  setPendingNav: (d) =>
    set({ pendingNav: d ? { ...d, nonce: Date.now() } : null }),
}));
