import { create } from 'zustand';

type CharacterParams = {
  genders?: number[];
  tagIds?: string[];
};

type NovelParams = {
  tagIds?: string[];
};

interface HomeStore {
  tab: 'story' | 'character';
  characterParams: CharacterParams;
  novelParams: NovelParams;
  setTab: (tab: 'story' | 'character') => void;
  setCharacterParams: (params: Partial<CharacterParams>) => void;
  setNovelParams: (params: Partial<NovelParams>) => void;
}

export const useHomeStore = create<HomeStore>((set, get) => ({
  tab: 'character',
  characterParams: {
    genders: [],
    tagIds: [],
  },
  novelParams: {
    tagIds: [],
  },
  setTab: (tab: 'story' | 'character') => set({ tab }),
  setCharacterParams: (params) => {
    const { characterParams } = get();
    set({ characterParams: { ...characterParams, ...params } });
  },
  setNovelParams: (params) => {
    const { novelParams } = get();
    set({ novelParams: { ...novelParams, ...params } });
  },
}));
