<script setup lang="ts">
import type { ToggleGroupRootEmits, ToggleGroupRootProps } from 'reka-ui';
import { ToggleGroupRoot, useForwardPropsEmits } from 'reka-ui';
import { provide, toRefs } from 'vue';
import { cn } from '@/lib/utils';
import type { ToggleGroupVariants } from '.';
import { toggleGroupContextKey } from './context';

const props = withDefaults(
  defineProps<
    ToggleGroupRootProps & {
      variant?: ToggleGroupVariants['variant'];
      size?: ToggleGroupVariants['size'];
    }
  >(),
  {
    variant: 'default',
    size: 'default',
  },
);

const emits = defineEmits<ToggleGroupRootEmits>();

const forwarded = useForwardPropsEmits(props, emits);

const { variant, size } = toRefs(props);
provide(toggleGroupContextKey, { variant, size });
</script>

<template>
  <ToggleGroupRoot
    data-slot="toggle-group"
    v-bind="forwarded"
    :class="cn('flex items-center justify-center gap-1', $attrs.class ?? '')"
  >
    <slot />
  </ToggleGroupRoot>
</template>
