"use client"

import * as React from "react"
import * as SwitchPrimitive from "@radix-ui/react-switch"

import { cn } from "@/lib/utils"

function Switch({
  className,
  ...props
}: React.ComponentProps<typeof SwitchPrimitive.Root>) {
  return (
    <SwitchPrimitive.Root
      data-slot="switch"
      className={cn(
        "peer data-[state=checked]:bg-primary data-[state=unchecked]:bg-muted-foreground focus-visible:border-primary focus-visible:ring-primary/30 dark:data-[state=unchecked]:bg-muted-foreground inline-flex h-[20px] w-[36px] shrink-0 items-center rounded-full border border-transparent shadow-sm transition-all outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",
        className
      )}
      {...props}
    >
      <SwitchPrimitive.Thumb
        data-slot="switch-thumb"
        className={cn(
          "bg-background pointer-events-none block size-[16px] rounded-full shadow-sm ring-0 transition-transform",
          "data-[state=checked]:translate-x-[16px] data-[state=unchecked]:translate-x-[2px]",
          "rtl:data-[state=checked]:-translate-x-[16px] rtl:data-[state=unchecked]:-translate-x-[2px]"
        )}
      />
    </SwitchPrimitive.Root>
  )
}

export { Switch }
