import { create } from "zustand";

const AUTH_TOKEN_KEY = "auth_token";

interface SessionState {
  token: string | null;
  setToken: (token: string) => void;
  clearToken: () => void;
}

export const useSessionStore = create<SessionState>((set) => ({
  token: localStorage.getItem(AUTH_TOKEN_KEY),

  setToken: (token: string) => {
    localStorage.setItem(AUTH_TOKEN_KEY, token);
    set({ token });
  },

  clearToken: () => {
    localStorage.removeItem(AUTH_TOKEN_KEY);
    set({ token: null });
  },
}));
