'use client'

import { Home, FolderOpen, FileText, MessageSquare, Trophy, Star, BookOpen } from 'lucide-react'
import { trpc } from '@/lib/trpc/client'
import { RoleNav, type NavItem, type RoleNavUser } from '@/components/layouts/role-nav'

interface ApplicantNavProps {
  user: RoleNavUser
}

export function ApplicantNav({ user }: ApplicantNavProps) {
  const { data: flags } = trpc.applicant.getNavFlags.useQuery(undefined, {
    staleTime: 60_000,
  })
  const { data: featureFlags } = trpc.settings.getFeatureFlags.useQuery(undefined, {
    staleTime: 60_000,
  })

  const useExternal = featureFlags?.learningHubExternal && featureFlags.learningHubExternalUrl

  const navigation: NavItem[] = [
    { name: 'Dashboard', href: '/applicant', icon: Home },
    { name: 'Project', href: '/applicant/team', icon: FolderOpen },
    { name: 'Competition', href: '/applicant/competition', icon: Trophy },
    { name: 'Documents', href: '/applicant/documents', icon: FileText },
    ...(flags?.hasEvaluationRounds
      ? [{ name: 'Evaluations', href: '/applicant/evaluations', icon: Star }]
      : []),
    ...(flags?.hasMentor
      ? [{ name: 'Mentoring', href: '/applicant/mentor', icon: MessageSquare }]
      : []),
    {
      name: 'Learning Hub',
      href: useExternal ? featureFlags.learningHubExternalUrl : '/applicant/resources',
      icon: BookOpen,
      external: !!useExternal,
    },
  ]

  return (
    <RoleNav
      navigation={navigation}
      roleName="Applicant"
      user={user}
      basePath="/applicant"
      helpEmail={featureFlags?.supportEmail || undefined}
    />
  )
}
