import { useMemo } from 'react';
import { useAuthStore } from '@/modules/auth/auth.store';

export function useCurrentUser() {
  const currentUser = useAuthStore((s) => s.currentUser);

  const roles = useMemo(() => currentUser?.roles ?? [], [currentUser]);

  const isAuthenticated = !!currentUser;

  const hasRole = (role: string) => roles.includes(role);

  const hasAnyRole = (...checkRoles: string[]) => checkRoles.some((r) => roles.includes(r));

  return { currentUser, isAuthenticated, roles, hasRole, hasAnyRole };
}
