<script setup lang="ts">
import type { SwitchRootEmits, SwitchRootProps } from "reka-ui"
import type { HTMLAttributes } from "vue"
import type { SwitchVariants } from "."
import { reactiveOmit } from "@vueuse/core"
import { SwitchRoot, SwitchThumb, useForwardPropsEmits } from "reka-ui"
import { cn } from "@/lib/utils"
import { switchThumbVariants, switchVariants } from "."

export interface SwitchProps extends SwitchRootProps {
  size?: SwitchVariants["size"]
  class?: HTMLAttributes["class"]
}

const props = defineProps<SwitchProps>()
const emits = defineEmits<SwitchRootEmits>()

const delegatedProps = reactiveOmit(props, "class", "size")

const forwarded = useForwardPropsEmits(delegatedProps, emits)
</script>

<template>
  <SwitchRoot
    v-bind="forwarded"
    :class="cn(switchVariants({ size }), props.class)"
  >
    <SwitchThumb :class="cn(switchThumbVariants({ size }))">
      <slot name="thumb" />
    </SwitchThumb>
  </SwitchRoot>
</template>
