<template>
    <ul class="cate-list list-unstyled d-flex flex-wrap mb-0">
        <li v-for="category in lists" :key="category.value" class="mt-2 me-2">
            <button
                type="button"
                class="btn"
                :class="{
                    'btn-outline-primary': category.value !== selectedCategory,
                    'btn-primary': category.value === selectedCategory
                }"
                @click="selectCategory(category.value)"
            >
                {{ category.label }}
            </button>
        </li>
    </ul>

</template>

<script setup>
import { defineProps, ref } from 'vue';

// lists prop 정의
const props = defineProps({
    lists: {
        type: Array,
        required: true,
    },
});

// 카테고리 선택
const selectedCategory = ref(null);
const emit = defineEmits();
const selectCategory = (cate) => {
    selectedCategory.value = selectedCategory.value === cate ? null : cate;
    emit('update:data', selectedCategory.value);
};
</script>


<style scoped>


@media (max-width: 768px) {
    .cate-list {
        overflow-x: scroll;
        flex-wrap: nowrap !important;

        li {
            flex: 0 0 auto;
        }
    }
}
</style>
