import * as React from 'react'
import * as TabsPrimitive from '@radix-ui/react-tabs'
import { cn } from '@/lib/utils'

/**
 * Radix Tabs — handoff style: bottom-border accent на active tab, weight 600.
 * Use {@code <Tabs value onValueChange><TabsList>…</TabsList><TabsContent />}.
 */

export const Tabs = TabsPrimitive.Root

export const TabsList = React.forwardRef<
  React.ElementRef<typeof TabsPrimitive.List>,
  React.ComponentPropsWithoutRef<typeof TabsPrimitive.List>
>(function TabsList({ className, ...props }, ref) {
  return (
    <TabsPrimitive.List
      ref={ref}
      className={cn(
        // h-11 (44px) — DESIGN.md §13 touch target enforcement. Was h-10
        // (40px) — short on WCAG AAA 44 minimum.
        'inline-flex h-11 items-center gap-1 border-b border-line w-full',
        className,
      )}
      {...props}
    />
  )
})

export const TabsTrigger = React.forwardRef<
  React.ElementRef<typeof TabsPrimitive.Trigger>,
  React.ComponentPropsWithoutRef<typeof TabsPrimitive.Trigger>
>(function TabsTrigger({ className, ...props }, ref) {
  return (
    <TabsPrimitive.Trigger
      ref={ref}
      className={cn(
        // h-11 paired с TabsList h-11 — touch target enforcement.
        'inline-flex items-center justify-center whitespace-nowrap px-3.5 h-11 text-body text-ink-2 -mb-px',
        'border-b-2 border-transparent transition-all hover:text-ink',
        'focus-visible:outline-none focus-visible:text-accent',
        'disabled:pointer-events-none disabled:opacity-50',
        'data-[state=active]:border-accent data-[state=active]:text-ink data-[state=active]:font-semibold',
        className,
      )}
      {...props}
    />
  )
})

export const TabsContent = React.forwardRef<
  React.ElementRef<typeof TabsPrimitive.Content>,
  React.ComponentPropsWithoutRef<typeof TabsPrimitive.Content>
>(function TabsContent({ className, ...props }, ref) {
  return (
    <TabsPrimitive.Content
      ref={ref}
      className={cn(
        'mt-3 focus-visible:outline-none',
        className,
      )}
      {...props}
    />
  )
})
