import { LSKeys, LStorage, LStorageHandlers } from "utils/localStorageDefs";

export type UILStorageKeys = keyof Pick<LSKeys, "drawer">;

export default function useUIStorage(): LStorage<UILStorageKeys> {
  const handlers: LStorageHandlers<UILStorageKeys> = {
    setter: {
      drawer: (key, value) => {
        localStorage.setItem(key, JSON.stringify(value));
      }
    },
    getter: {
      drawer: (key) => {
        return JSON.parse(localStorage.getItem(key) ?? "false");
      }
    }
  }
  return {
    setItem: (key, value) => {
      return handlers["setter"][key](key, value);
    },
    getItem: (key) => {
      return handlers["getter"][key](key);
    }
  }
}