<!-- +-------------------------------------------------+
 - © 2002-2004 PMB Services / www.sigb.net pmb@sigb.net et contributeurs (voir www.sigb.net)
 - +-------------------------------------------------+
 - $Id: InputChips.vue,v 1.1 2026/07/16 gneveu Exp $
-->
<template>
    <div class="prefillingform-input-chips">
        <button type="button" v-for="opt in options" :key="opt.code" class="prefillingform-chip"
            :class="{ 'prefillingform-chip-selected': isSelected(opt.code) }" @click="toggle(opt.code)">
            {{ isSelected(opt.code) ? '✓' : '+' }} {{ messages.get('prefillingform_admin', opt.labelKey) }}
        </button>
    </div>
</template>

<script>
export default {
    props: {
        selected: {
            type: Array,
            required: true,
        },
        options: {
            type: Array,
            required: true,
        },
    },
    methods: {
        isSelected: function (code) {
            return this.selected.includes(code);
        },
        toggle: function (code) {
            let index = this.selected.indexOf(code);
            if (-1 === index) {
                this.selected.push(code);
            } else {
                this.selected.splice(index, 1);
            }
        },
    },
};
</script>
