import * as React from "react";
import * as TogglePrimitive from "@radix-ui/react-toggle";
import { cva, type VariantProps } from "class-variance-authority";

import { cn } from "../lib/utils";

const toggleVariants = cva(
  "tw-figr-inline-flex tw-figr-items-center tw-figr-text-base-black tw-figr-justify-center tw-figr-rounded-sm  tw-figr-transition-colors hover:tw-figr-bg-neutral-200 hover:tw-figr-text-base-black focus-visible:tw-figr-outline-none focus-visible:tw-figr-ring-1 focus-visible:tw-figr-ring-ring disabled:tw-figr-pointer-events-none disabled:tw-figr-opacity-50 data-[state=on]:tw-figr-bg-neutral-200 data-[state=on]:tw-figr-text-base-black",
  {
    variants: {
      variant: {
        default:
          "tw-figr-gap-s tw-figr-rounded-m tw-figr-font-secondary tw-figr-text-desktop-caption-accent hover:tw-figr-text-neutral-700  hover:tw-figr-bg-neutral-200 data-[state=on]:tw-figr-bg-neutral-200 data-[state=on]:tw-figr-text-base-black",
        outline:
          "tw-figr-gap-s tw-figr-rounded-m tw-figr-font-secondary tw-figr-text-desktop-caption-accent tw-figr-border tw-figr-border-neutral-200 tw-figr-bg-transparent hover:tw-figr-text-neutral-700  hover:tw-figr-bg-neutral-100 data-[state=on]:tw-figr-bg-neutral-100 data-[state=on]:tw-figr-text-base-black"
      },
      size: {
        default: "tw-figr-px-sm tw-figr-py-s",
        sm: "tw-figr-px-sm tw-figr-py-xs",
        lg: "tw-figr-px-ml tw-figr-py-sm"
      }
    },
    defaultVariants: {
      variant: "default",
      size: "default"
    }
  }
);

const Toggle = React.forwardRef<
  React.ElementRef<typeof TogglePrimitive.Root>,
  React.ComponentPropsWithoutRef<typeof TogglePrimitive.Root> &
    VariantProps<typeof toggleVariants>
>(({ className, variant, size, ...props }, ref) => (
  <TogglePrimitive.Root
    ref={ref}
    className={cn(toggleVariants({ variant, size, className }))}
    {...props}
  />
));

Toggle.displayName = TogglePrimitive.Root.displayName;

export { Toggle, toggleVariants };
