<template>
  <p class="vm-kv-row">
    <span class="vm-kv-row__label">{{ label }}</span>
    <span class="vm-kv-row__value" :title="titleText">{{ text }}</span>
  </p>
</template>

<script setup lang="ts">
import { computed } from 'vue'

defineOptions({ name: 'vm-kv-row' })

const props = defineProps<{
  label: string
  modelValue?: unknown
  title?: string
}>()

const text = computed(() => {
  const v = props.modelValue
  if (v == null || v === '') return '—'
  return String(v)
})

const titleText = computed(() => props.title ?? (text.value === '—' ? undefined : text.value))
</script>

<style lang="scss" scoped>
.vm-kv-row {
  display: flex;
  gap: 8px;
  margin: 0 0 8px;
  min-width: 0;
  font-size: 12px;
  line-height: 1.45;
}

.vm-kv-row__label {
  flex-shrink: 0;
  color: var(--muted-foreground);
}

.vm-kv-row__value {
  min-width: 0;
  overflow: hidden;
  color: var(--foreground);
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}
</style>
