'use client'
// tdd-guard:skip — presentational only; tab-visibility logic lives in the
// unit-tested lib/project/project-tabs-config.ts (buildProjectTabs).

import Link from 'next/link'
import { usePathname } from 'next/navigation'
import { buildProjectTabs } from '@/lib/project/project-tabs-config'

interface Props {
  projectId: string
  typeCodes: string[]
  hasOeeRecords?: boolean
}

export default function ProjectTabs({ projectId, typeCodes, hasOeeRecords = false }: Props) {
  const pathname = usePathname()
  const tabs = buildProjectTabs(projectId, typeCodes, hasOeeRecords)

  function isActive(href: string, exact: boolean) {
    return exact ? pathname === href : pathname.startsWith(href)
  }

  return (
    <div className="flex overflow-x-auto scrollbar-none">
      {tabs.map((tab) => {
        const active = isActive(tab.href, tab.exact)
        return (
          <Link
            key={tab.href}
            href={tab.href}
            className={`px-4 py-2.5 text-xs font-medium whitespace-nowrap border-b-2 transition-colors ${
              active
                ? 'border-white text-white'
                : 'border-transparent text-white/60 hover:text-white'
            }`}
          >
            {tab.label}
          </Link>
        )
      })}
    </div>
  )
}
