import type { User } from "@supabase/supabase-js"

const DEFAULT_ADMIN_EMAILS =
  "sebastian.favaron@humand.co,lucia.strozza@humand.co,gaston.rios@humand.co,marcos.palacio@humand.co,nico@humand.co,gero@humand.co"

export function isAdminUser(user: User) {
  const adminEmails = new Set(
    (process.env.DEMO_ADMIN_EMAILS ?? DEFAULT_ADMIN_EMAILS)
      .split(",")
      .map((email) => email.trim().toLowerCase())
      .filter(Boolean),
  )

  const isAdminByEmail = user.email ? adminEmails.has(user.email.toLowerCase()) : false
  const isAdminByMetadata = user.user_metadata?.role === "admin"

  return isAdminByEmail || isAdminByMetadata
}
