<script setup lang="ts">
import type { HTMLAttributes } from 'vue'
import { inject, type Ref, computed } from 'vue'
import { cn } from '@/lib/utils'

const props = defineProps<{
  class?: HTMLAttributes['class']
}>()

// Inject the collapsible state from parent Alert component
const isCollapsed = inject<Ref<boolean> | null>('alertCollapsed', null)
const isCollapsible = inject<boolean>('alertCollapsible', false)

const shouldShow = computed(() => {
  if (!isCollapsible) return true
  return isCollapsed && !isCollapsed.value
})
</script>

<template>
  <div
    v-if="shouldShow"
    data-slot="alert-description"
    :class="
      cn(
        'text-muted-foreground col-start-2 grid justify-items-start gap-1 text-sm [&_p]:leading-relaxed',
        props.class
      )
    "
  >
    <slot />
  </div>
</template>
