<template>
  <span class="context-pill">
    <component :is="icon" class="context-pill__icon" />
    <span class="context-pill__label">{{ label }}</span>
    <button v-if="removable" class="context-pill__remove" @click.stop="$emit('remove')">
      <CloseOutlined />
    </button>
  </span>
</template>

<script setup lang="ts">
import { type Component } from 'vue'
import { CloseOutlined } from '@ant-design/icons-vue'

defineProps<{
  label: string
  icon?: Component
  removable?: boolean
}>()

defineEmits<{
  remove: []
}>()
</script>

<style scoped>
.context-pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px var(--space-2);
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  font-size: var(--font-xs);
  color: var(--text-secondary);
  max-width: 160px;
}

.context-pill__icon {
  font-size: 10px;
  color: var(--text-tertiary);
  flex-shrink: 0;
}

.context-pill__label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.context-pill__remove {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 14px;
  height: 14px;
  border: none;
  background: transparent;
  color: var(--text-placeholder);
  cursor: pointer;
  border-radius: var(--radius-full);
  flex-shrink: 0;
  padding: 0;
  transition: all var(--transition-fast);
}

.context-pill__remove:hover {
  color: var(--color-error);
  background: var(--color-error-light);
}
</style>
