<template>
    <div class="inline">
        <notification-component ref="notification"></notification-component>
        <div class="btn btn-sm btn-success b-rad-none requestModal"  data-type="arrival">Order Arrived</div>
        <confirm-modal-component
                title="Order Arrival"
                :message="'Are you sure this order has arrived to warehouse?'"
                type="arrival"
                v-on:confirm="completeArrival()"></confirm-modal-component>
    </div>

</template>

<script>
    import notificationConstant from '../../../../../js/notification';
    export default {
        props: {
            'data': {
                required: true
            }
        },
        data() {
            return {
                isLoading: false
            }
        },
        methods: {
            completeArrival() {

                //turn on loading animation
                this.isLoading = true;
                fetch(route('api.order.step.update', {orderId: this.data}), {
                    method: 'post',
                    headers: {
                        'content-type': 'application/json'
                    }
                }).then(() => {
                    //turn off loading animation
                    this.isLoading = false;

                    let notification = this.$refs.notification;

                    notification.title = notificationConstant.ORDER.WAREHOUSE_ARRIVAL.TITLE;
                    notification.message = notificationConstant.ORDER.WAREHOUSE_ARRIVAL.MESSAGE;


                    notification.execute();

                    Event.$emit('updateOrdersList', true);


                })
            }
        }
    }
</script>