<script setup lang="ts">
const props = withDefaults(
  defineProps<{
    labelFor: string
    size?: 'default' | 'narrow' | 'wide'
    height?: 'default' | 'compact'
    position?: 'default' | 'dynamic'
    stacked?: boolean
  }>(),
  {
    size: 'default',
    height: 'default',
    position: 'default',
    stacked: false,
  },
)

const sizeMap = {
  default: 'w-28 2xl:w-36',
  narrow: 'w-24 2xl:w-28',
  wide: 'w-44 2xl:w-48',
} as const

const heightMap = {
  default: 'pt-2 2xl:pt-2.5',
  compact: 'leading-[14pt]',
} as const

const positionWrapMap = {
  default: 'pe-2 text-start',
  dynamic: 'md:text-end',
} as const

const positionChildMap = {
  default: '',
  dynamic: 'block pe-2.5',
} as const

const wrapperClass = computed(() => [
  'block shrink-0',
  props.stacked ? 'w-full mb-1 text-start' : sizeMap[props.size],
  props.stacked ? '' : heightMap[props.height],
  props.stacked ? '' : positionWrapMap[props.position],
])

const labelClass = computed(() => [props.stacked ? 'block mb-1 text-sm font-medium' : positionChildMap[props.position]])
</script>

<template>
  <div :class="wrapperClass">
    <label :class="labelClass" :for="labelFor">
      <slot />
    </label>
  </div>
</template>
