<template>
  <div class="field">
    <label :for="id" class="field-label">{{ label }}</label>
    <textarea
      :id="id"
      :value="modelValue"
      class="field-textarea"
      :rows="rows"
      :placeholder="placeholder"
      @input="$emit('update:modelValue', ($event.target as HTMLTextAreaElement).value)"
    />
  </div>
</template>

<script setup lang="ts">
const props = defineProps<{
  label: string
  modelValue: string
  rows?: number
  placeholder?: string
}>()

defineEmits<{
  'update:modelValue': [value: string]
}>()

const id = computed(() => `field-${props.label.toLowerCase().replace(/\s+/g, '-')}`)
</script>

<style scoped>
.field {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.field-label {
  font-size: 0.8rem;
  font-weight: 500;
  color: hsl(var(--color-text-muted));
}

.field-textarea {
  padding: 0.5rem 0.75rem;
  border-radius: 0.5rem;
  border: 1px solid hsl(var(--color-surface-light));
  background: hsl(var(--color-bg));
  color: white;
  font-size: 0.875rem;
  resize: vertical;
  min-height: 5rem;
  transition: border-color 0.2s;
  font-family: inherit;
}

.field-textarea:focus {
  outline: none;
  border-color: hsl(var(--color-primary) / 0.5);
}
</style>
