<template>
  <div class="fc-sgroup">
    <button
      v-if="collapsible"
      class="fc-sgroup__header fc-sgroup__header--btn"
      @click="open = !open"
    >
      <v-icon size="small">{{ open ? 'mdi-chevron-down' : 'mdi-chevron-right' }}</v-icon>
      {{ label }} ({{ items.length }})
    </button>
    <div v-else class="fc-sgroup__header">{{ label }}</div>

    <div v-show="open" class="fc-sgroup__items">
      <SuggestionItem
        v-for="(s, i) in items" :key="`${s.display_name}-${i}`"
        :suggestion="s"
        @accept="$emit('accept', $event)"
        @alias="$emit('alias', $event)"
        @remove-alias="$emit('remove-alias', $event)"
        @dismiss="$emit('dismiss', $event)"
      />
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import SuggestionItem from './SuggestionItem.vue'

const props = defineProps({
  label: { type: String, required: true },
  items: { type: Array, required: true },
  collapsible: { type: Boolean, default: false },
  defaultOpen: { type: Boolean, default: true }
})
defineEmits(['accept', 'alias', 'remove-alias', 'dismiss'])

const open = ref(props.collapsible ? props.defaultOpen : true)
</script>

<style scoped>
.fc-sgroup { margin-bottom: 10px; }
.fc-sgroup__header {
  font-family: 'Inter', sans-serif;
  font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.06em;
  color: rgb(var(--v-theme-on-surface-variant, var(--v-theme-on-surface)));
  margin-bottom: 4px;
}
.fc-sgroup__header--btn {
  display: flex; align-items: center; gap: 4px;
  background: none; border: none; cursor: pointer;
  padding: 0; width: 100%; text-align: left;
  font: inherit; text-transform: uppercase; letter-spacing: 0.06em;
}
</style>
