<template>
    <view class="tag-select">
        <view class="tags-row">
            <view v-for="opt in options" :key="opt" class="tag" :class="{ selected: isSelected(opt) }"
                @click="onClick(opt)">
                {{ opt }}
            </view>
        </view>
    </view>
</template>

<script setup>
const props = defineProps({
    options: { type: Array, default: () => [] },
    modelValue: { type: String, default: '' }
})

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

const isSelected = (opt) => props.modelValue === opt

const onClick = (opt) => {
    if (opt === props.modelValue) return
    emit('update:modelValue', opt)
    emit('change', opt)
}
</script>

<style scoped lang="scss">
.tags-row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
}

.tag {
    margin-right: 16rpx;
    margin-bottom: 12rpx;
    padding: 8rpx 18rpx;
    font-size: 24rpx;
    line-height: 30rpx;
    height: 30rpx;
    border-radius: 8rpx;
    background-color: #DADADA;
    color: #5B5B5B;
    border: 1rpx solid #DADADA;
}

.tag.selected {
    background-color: #00AC4E;
    color: #FFFFFF;
    border-color: #00AC4E;
}
</style>
