<script setup>
const props = defineProps({
  label: String,
  items: Array,
  fields: {
    default: ['v', 'n']
  },
  modelValue: String
})

const emits = defineEmits(['update:modelValue', 'change'])

function handleClick(row) {
  emits('update:modelValue', row[props.fields[0]])
  emits('change', row)
}

</script>

<template>
  <div class="flex">
    <div class="font-bold mr-4 min-w-10">{{ label }}</div>
    <div class="flex-auto flex-wrap check">
      <label v-for="i in items" :for="i[props.fields[0]]"
        class="text-hex-949494 mx-3 px-4px py-px rounded cursor-pointer"
        :class="i[props.fields[0]] === modelValue && 'text_blue bg-hex-00A3FF bg-opacity-10'"
        @click="handleClick(i)">
        <span class="whitespace-nowrap">{{ i[props.fields[1]] }}</span>
      </label>
      <div class="border_b my-2"></div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
$color: #1259A1;
.border_b {
  border-bottom: 1px dashed #E4E6E8;
}
.text_blue{
 color: $color;
}
</style>
