import { useAuthStore } from '@/store/auth.store'

/**
 * Hook helper per accedere all'utente corrente e ai permessi.
 */
export function useAuth() {
  const user = useAuthStore((s) => s.user)
  const isAuthenticated = useAuthStore((s) => s.isAuthenticated)
  const isLoading = useAuthStore((s) => s.isLoading)
  const logout = useAuthStore((s) => s.logout)

  const isAdmin = user?.role === 'admin' || user?.role === 'super_admin'
  const isSuperAdmin = user?.role === 'super_admin'
  const canSend = user?.role !== 'readonly'
  const canManage = isAdmin

  return {
    user,
    isAuthenticated,
    isLoading,
    isAdmin,
    isSuperAdmin,
    canSend,
    canManage,
    logout,
  }
}
