import create from 'zustand';
import { devtools } from 'zustand/middleware';
import { immer } from 'zustand/middleware/immer';

export interface AlbumListDataState {
  itemData: any[];
}

export interface AlbumListDataSlice extends AlbumListDataState {
  actions: {
    setItemData: (data: any[]) => void;
  };
}

export const useAlbumListDataStore = create<AlbumListDataSlice>()(
  devtools(
    immer((set) => ({
      actions: {
        setItemData: (data) => {
          set((state) => {
            state.itemData = data;
          });
        },
      },
      itemData: [],
    })),
    { name: 'store_album_list_data' },
  ),
);

export const useAlbumListStoreActions = () => useAlbumListDataStore((state) => state.actions);

export const useAlbumListItemData = () =>
  useAlbumListDataStore((state) => {
    return { itemData: state.itemData, setItemData: state.actions.setItemData };
  });
