import {create} from "zustand"

export const PlayerInstance: HTMLVideoElement[] = [];
export const defaultCache:{
	firstLoadPath?: string
} = {};
type StoreInstance<T> = {
	cache: T[];
	clear: () => void;
	set: (values: T[]) => void;
	add: (value: T) => void;
	remove: (value: T) => void
}
export const useIndexArrayCache = create<StoreInstance<Id>>((set) => ({
	cache: [],
	set: (values: Id[]) => {
		set({cache: values})
	},
	clear: () => {
		set({cache: []})
	},
	add: (id: Id) => {
		set((state) => ({
			cache: [...(state.cache || []), id]
		}))
	},
	remove: (id: Id) => {
		set((state) => ({
			cache: (state.cache || []).filter((item) => item != id)
		}))
	}
}))

