import { create } from 'zustand';
import type { StoryGroup } from '../../../core/domain/types';

interface StoryState {
  storyGroups: StoryGroup[];
  viewerIndex: number | null;
  viewerStoryIndex: number;
  setStoryGroups: (groups: StoryGroup[]) => void;
  openViewer: (userIndex: number, storyIndex?: number, groups?: StoryGroup[]) => void;
  closeViewer: () => void;
}

export const useStoryStore = create<StoryState>((set, get) => ({
  storyGroups: [],
  viewerIndex: null,
  viewerStoryIndex: 0,
  setStoryGroups: (storyGroups) => set({ storyGroups }),
  openViewer: (userIndex, storyIndex = 0, groups) => set({ 
    storyGroups: groups || get().storyGroups,
    viewerIndex: userIndex, 
    viewerStoryIndex: storyIndex 
  }),
  closeViewer: () => set({ viewerIndex: null, viewerStoryIndex: 0 }),
}));
