<template>
    <div>
        <woinfo-edit-modal modal-id="workordereditModal" :populate-with="this.data" :store-list="this.storeList"></woinfo-edit-modal>
        <p><i class="fas fa-fw fa-info-circle"></i> <span v-text="this.data.probdesc"></span></p>
        <p><i class="far fa-fw fa-lightbulb"></i> <span v-text="this.data.suggested"></span></p>
        <p><i class="fas fa-fw fa-paste"></i> <span v-text="this.data.woid"></span></p>
        <p><i class="fas fa-fw fa-building"></i> <span>{{ storeList[data.storeid] }}</span></p>
        <p><i class="fas fa-fw fa-sign-in-alt"></i> 
            <span class="dashed-underline" data-toggle="tooltip" data-placement="bottom" v-bind:title=this.getHRDate(this.data.dropdate)>
                {{ Math.floor(this.daysSinceToday(this.data.dropdate)) }} days ago
            </span>
        </p>
        <p><i class="fas fa-sign-out-alt"></i> 
            <span class="dashed-underline" data-toggle="tooltip" data-placement="bottom" v-if="!this.isZero(this.data.pickupdate)" v-bind:title=this.getHRDate(this.data.pickupdate)>
                {{ Math.floor(this.daysSinceToday(this.data.pickupdate)) }} days ago
            </span>
        </p>
        <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#workordereditModal">Edit</button>
    </div>
</template>
<script>
    import dateMixin from '../mixins/dateMixin'
    export default {
        mixins: [dateMixin],
        props: ['workOrder', 'stores'],
        data() {
            return {
                data: JSON.parse(this.workOrder),
            }
        },
        computed: {
            storeList: function () {
                let list = {}
                JSON.parse(this.stores).map(val => {
                    list[val.storeid] = val.storesname
                })
                return list
            }
        },
        mounted() {
            Echo.channel('work-order.'+this.data.woid)
                .listen('WorkOrderUpdated', (e) => {
                    this.data = e.data;
                });
        }
    }
</script>