<script setup lang="ts">
import type { PrimitiveProps } from 'reka-ui';
import type { HTMLAttributes } from 'vue';
import type { ButtonVariants } from '.';
import { Primitive } from 'reka-ui';
import { computed } from 'vue';
import { cn } from '@/lib/utils';
import { buttonVariants } from '.';

interface Props extends PrimitiveProps {
  variant?: ButtonVariants['variant'];
  size?: ButtonVariants['size'];
  class?: HTMLAttributes['class'];
}

const props = withDefaults(defineProps<Props>(), {
  as: 'button',
});

const buttonClass = computed(() =>
  cn(buttonVariants({ variant: props.variant, size: props.size }), props.class),
);
</script>

<template>
  <Primitive
    v-if="asChild"
    data-slot="button"
    :as="as"
    :as-child="true"
    :class="buttonClass"
  >
    <slot />
  </Primitive>
  <Primitive
    v-else
    data-slot="button"
    :as="as"
    :as-child="false"
    :class="buttonClass"
  >
    <slot />
  </Primitive>
</template>
