'use client';

import * as React from 'react';
import * as SwitchPrimitives from '@radix-ui/react-switch';
import { cn } from '@/shared/lib/utils';

/**
 * EN: Switch component - A control that allows the user to toggle between checked and not checked
 * VI: Component Switch - Bộ điều khiển cho phép người dùng chuyển đổi giữa trạng thái checked và không checked
 */
const Switch = React.forwardRef<
  React.ElementRef<typeof SwitchPrimitives.Root>,
  React.ComponentPropsWithoutRef<typeof SwitchPrimitives.Root>
>(({ className, ...props }, ref) => (
  <SwitchPrimitives.Root
    className={cn(
      // EN: Base track styles / VI: Style track cơ bản
      'peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors',
      // EN: Focus and disabled states / VI: Trạng thái focus và disabled
      'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent-primary focus-visible:ring-offset-2 focus-visible:ring-offset-bg-primary',
      'disabled:cursor-not-allowed disabled:opacity-50',
      // EN: Color states / VI: Trạng thái màu sắc
      'data-[state=checked]:bg-brand-primary data-[state=unchecked]:bg-bg-tertiary',
      className
    )}
    {...props}
    ref={ref}
  >
    <SwitchPrimitives.Thumb
      className={cn(
        // EN: Thumb styles / VI: Style thumb
        'pointer-events-none block h-5 w-5 rounded-full bg-white shadow-lg ring-0 transition-transform',
        'data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0'
      )}
    />
  </SwitchPrimitives.Root>
));
Switch.displayName = SwitchPrimitives.Root.displayName;

export { Switch };
