<template>
    <div class="form form-group">
        <div class="ms-3">
            <div class="mb-3" v-for="item, ii in items" :key="ii" :value="item">{{ item.name }} <button
                    class="btn btn-outline-primary" @click="itemselected = item; changeSelect()">Wczytaj</button>
            </div>

        </div>
        <div v-show="items.length == 0"><i>Brak zapisanych szablonów</i></div>
    </div>
</template>
<script>
export default {
    created() {
        this.getPost();
    },
    data: function () {
        return {
            items: [],
            itemselected: {},
        }
    },
    methods: {
        changeSelect() {
            this.$emit('update:modelValue', this.itemselected);
        },
        getPost() {
            if (this.$pagebuilder.axios) {
                this.$pagebuilder.axios.get('api/v1/pagebuilder/template').then(response => {
                    this.items = response.data.data;
                });
            } else {
                console.error('NO AXIOS INSTACE PROVIDED TO PAGEBUILDER');
            }
        }
    }
}
</script>