<script setup lang="ts">
import { type HTMLAttributes, computed } from 'vue'
import { SelectTrigger as SelectTriggerPrimitive } from 'reka-ui'
import { ChevronDown } from 'lucide-vue-next'
import { cn } from '@/lib/utils'
import { selectTriggerVariants, type SelectTriggerVariants } from '.'

interface SelectTriggerProps {
  disabled?: boolean
  variant?: SelectTriggerVariants['variant']
  size?: SelectTriggerVariants['size']
  class?: HTMLAttributes['class']
}

const props = withDefaults(defineProps<SelectTriggerProps>(), {
  variant: 'default',
  size: 'default',
})

const delegatedProps = computed(() => {
  const { class: _, variant: __, size: ___, ...delegated } = props
  return delegated
})
</script>

<template>
  <SelectTriggerPrimitive
    v-bind="delegatedProps"
    :class="
      cn(
        selectTriggerVariants({ variant: props.variant, size: props.size }),
        props.class
      )
    "
  >
    <slot />
    <ChevronDown class="h-4 w-4 opacity-50" />
  </SelectTriggerPrimitive>
</template>
