<script setup lang="ts">
import type {
  DropdownMenuCheckboxItemEmits,
  DropdownMenuCheckboxItemProps,
} from 'reka-ui';
import type { HTMLAttributes } from 'vue';
import { reactiveOmit } from '@vueuse/core';
import { UiCheckbox } from '@/components/UiCheckbox';
import { DropdownMenuCheckboxItem, useForwardPropsEmits } from 'reka-ui';
import { cn } from '@/lib/utils';

const props = defineProps<
  DropdownMenuCheckboxItemProps & { class?: HTMLAttributes['class'] }
>();
const emits = defineEmits<DropdownMenuCheckboxItemEmits>();

const delegatedProps = reactiveOmit(props, 'class');

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

<template>
  <DropdownMenuCheckboxItem
    data-slot="dropdown-menu-checkbox-item"
    v-bind="forwarded"
    :class="
      cn(
        'group/dropdown-menu-checkbox-item hover:bg-background-surface-muted-subtle data-[highlighted]:bg-background-surface-muted-subtle focus:text-foreground relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none data-[disabled]:pointer-events-none data-[disabled]:opacity-50',
        props.class,
      )
    "
  >
    <span
      data-slot="dropdown-menu-checkbox-indicator"
      aria-hidden="true"
      class="pointer-events-none absolute left-2 flex size-4 items-center justify-center"
    >
      <slot name="indicator-icon">
        <UiCheckbox
          name="dropdown-menu-checkbox-indicator"
          :model-value="props.modelValue"
          tabindex="-1"
          class="pointer-events-none"
        />
      </slot>
    </span>
    <slot />
  </DropdownMenuCheckboxItem>
</template>
