<script lang="ts" setup>
import type { RangeCalendarCellTriggerProps } from 'reka-ui';
import type { HTMLAttributes } from 'vue';
import { reactiveOmit } from '@vueuse/core';
import { RangeCalendarCellTrigger, useForwardProps } from 'reka-ui';
import { cn } from '@/lib/utils';
import { buttonVariants } from '@/components/core/button';

const props = withDefaults(
  defineProps<
    RangeCalendarCellTriggerProps & { class?: HTMLAttributes['class'] }
  >(),
  {
    as: 'button',
  },
);

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

const forwardedProps = useForwardProps(delegatedProps);
</script>

<template>
  <RangeCalendarCellTrigger
    data-slot="range-calendar-trigger"
    :class="
      cn(
        buttonVariants({ variant: 'ghost' }),
        // Base: unselected dates use secondary content color
        'size-8 p-0 font-normal data-[selected]:opacity-100 cursor-default text-secondary-content hover:text-secondary-content',
        // Today (not selected): accent soft background with accent soft foreground
        '[&[data-today]:not([data-selected])]:bg-accent [&[data-today]:not([data-selected])]:text-accent-foreground',
        // Selection Start: accent-default background with accent-default foreground
        'data-[selection-start]:bg-accent-default data-[selection-start]:text-accent-default-foreground data-[selection-start]:hover:bg-accent-default data-[selection-start]:hover:text-accent-default-foreground data-[selection-start]:focus:bg-accent-default data-[selection-start]:focus:text-accent-default-foreground',
        // Selection End: accent-default background with accent-default foreground
        'data-[selection-end]:bg-accent-default data-[selection-end]:text-accent-default-foreground data-[selection-end]:hover:bg-accent-default data-[selection-end]:hover:text-accent-default-foreground data-[selection-end]:focus:bg-accent-default data-[selection-end]:focus:text-accent-default-foreground',
        // Outside months
        'data-[outside-view]:text-muted-foreground',
        // Disabled
        'data-[disabled]:text-muted-foreground data-[disabled]:opacity-50',
        // Unavailable
        'data-[unavailable]:text-destructive-foreground data-[unavailable]:line-through',
        props.class,
      )
    "
    v-bind="forwardedProps"
  >
    <slot />
  </RangeCalendarCellTrigger>
</template>
