"use client";

import { createContext, useContext, type ReactNode } from "react";
import type { SafeAuthSession } from "@/features/auth/auth-client";
import type { CurrentUserProfile } from "@/features/profile/api-contract";

type DashboardAuthState = {
  apiConfigured: boolean;
  session: SafeAuthSession | null;
  profile: CurrentUserProfile | null;
};

const DashboardAuthContext = createContext<DashboardAuthState>({
  apiConfigured: false,
  session: null,
  profile: null,
});

export function DashboardAuthProvider({
  apiConfigured,
  session,
  profile,
  children,
}: DashboardAuthState & { children: ReactNode }) {
  return (
    <DashboardAuthContext.Provider value={{ apiConfigured, session, profile }}>
      {children}
    </DashboardAuthContext.Provider>
  );
}

export function useDashboardAuth() {
  return useContext(DashboardAuthContext);
}
