<template>
     <modal :id="modalId" tabindex="-1" role="dialog" :aria-labelledby="modalId+'Label'">
        <h5 slot="header" class="modal-title" :id="modalId+'Label'">
            Delete Note
        </h5>
        <div slot="body">
            Are you sure?
        </div>
        <div slot="footer">
            <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
            <button type="button" class="btn btn-danger" @click="deleteNote(note)">
                <div v-if="!noteDeleting">Confirm</div>
                <circle-spinner v-else :size="2"></circle-spinner>
            </button>
        </div>
    </modal>
</template>
<script>
import Modal from './Modal.vue'
import CircleSpinner from './CircleSpinner.vue'
export default {
    components: {
        Modal,
        CircleSpinner,
    },
    props: {
        modalId: {
            type: String,
            require: true,
        },
        note: {
            type: Object,
            required: true,
        },
    },
    data () {
        return {
            noteDeleting: false
        }
    },
    methods: {
        deleteNote: function(note) {
            this.noteDeleting = true
            axios.delete(`/api/workorders/notes/${this.note.noteid}`).then( response => {
                this.noteDeleting = false
                $(`#${this.modalId}`).modal('hide')
            }).catch( error => {
                this.noteDeleting = false
                console.log(error)
            })
        }
    }
}
</script>