"use client";

import React, { createContext, useContext, useState } from "react";

type Mode = "operations" | "admin";

interface NavContextType {
  mode: Mode;
  setMode: (mode: Mode) => void;
}

// 1. Provide default values so useContext never returns null/undefined
const NavContext = createContext<NavContextType>({
  mode: "operations",
  setMode: () => {},
});

export function NavProvider({ children }: { children: React.ReactNode }) {
  const [mode, setMode] = useState<Mode>("operations");

  return (
    <NavContext.Provider value={{ mode, setMode }}>
      {children}
    </NavContext.Provider>
  );
}

export function useNav() {
  const context = useContext(NavContext);
  return context;
}