'use client';

import * as React from 'react';
import * as TabsPrimitive from '@radix-ui/react-tabs';
import { clsx } from 'clsx';

export const Tabs = TabsPrimitive.Root;

export type TabsListProps = React.ComponentPropsWithoutRef<typeof TabsPrimitive.List>;

export const TabsList = React.forwardRef<
  React.ElementRef<typeof TabsPrimitive.List>,
  TabsListProps
>(({ className, ...props }, ref) => (
  <TabsPrimitive.List
    ref={ref}
    className={clsx('inline-flex rounded-lg bg-[var(--bl-surface-muted)] p-1', className)}
    {...props}
  />
));

TabsList.displayName = 'TabsList';

export type TabsTriggerProps = React.ComponentPropsWithoutRef<typeof TabsPrimitive.Trigger>;

export const TabsTrigger = React.forwardRef<
  React.ElementRef<typeof TabsPrimitive.Trigger>,
  TabsTriggerProps
>(({ className, ...props }, ref) => (
  <TabsPrimitive.Trigger
    ref={ref}
    className={clsx(
      'inline-flex min-h-8 items-center justify-center rounded-md px-3 text-sm font-medium text-[var(--bl-text-secondary)] transition-colors',
      'hover:text-[var(--bl-text-primary)] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--bl-accent)]',
      'data-[state=active]:bg-[var(--bl-surface-card)] data-[state=active]:text-[var(--bl-text-primary)]',
      className
    )}
    {...props}
  />
));

TabsTrigger.displayName = 'TabsTrigger';

export type TabsContentProps = React.ComponentPropsWithoutRef<typeof TabsPrimitive.Content>;

export const TabsContent = React.forwardRef<
  React.ElementRef<typeof TabsPrimitive.Content>,
  TabsContentProps
>(({ className, ...props }, ref) => (
  <TabsPrimitive.Content
    ref={ref}
    className={clsx(
      'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--bl-accent)]',
      className
    )}
    {...props}
  />
));

TabsContent.displayName = 'TabsContent';
