<template>
    <div class="container-fluid">
        <div class="row my-3">
            <div class="col-lg-6">
                <div class="card h-100">
                    <div class="card-header text-right">
                        <button type="button" class="btn btn-default xs-toggle" data-toggle="collapse" data-target="#assetTab">
                            <span class="sr-only">Toggle Navigation</span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                        </button>
                        <ul class="nav nav-pills card-header-pills nav-justified xs-collapse collapse" id="assetTab" role="tablist">
                            <li class="nav-item">
                                <a class="nav-link active" id="assetinfo-tab" data-toggle="pill" href="#assetinfo" role="tab" aria-controls="assetinfo" aria-selected="true">Hardware</a>
                            </li>
                            <!-- @if($workOrder->asset->group !== null)
                            <li class="nav-item">
                                <a class="nav-link" id="group-tab" data-toggle="pill" href="#group" role="tab" aria-controls="group" aria-selected="false">Group</a>
                            </li>
                            @endif -->
                            <li class="nav-item">
                                <a class="nav-link" id="credentials-tab" data-toggle="pill" href="#credentials" role="tab" aria-controls="credentials" aria-selected="false">Credentials</a>
                            </li>
                        </ul>
                    </div>
                    <div class="card-body">
                        <div class="tab-content">
                            <div class="tab-pane active" id="assetinfo" role="tabpanel" aria-labelledby="assetinfo-tab">
                                <!-- <assetinfo asset="{{$asset}}"></assetinfo> -->
                            </div>
                            <!-- @if($workOrder->asset->group !== null)
                            <div class="tab-pane" id="group" role="tabpanel" aria-labelledby="group-tab">
                                Name: {{$workOrder->asset->group->pcgroupname}}
                            </div>
                            @endif
                            <div class="tab-pane" id="credentials" role="tabpanel" aria-labelledby="credentials-tab">
                                <credential-list :credential-list="{{$workOrder->asset->credentials->sortByDesc('creddate')->values()}}" :descriptions="{{App\CredDesc::all()}}" :pcid="{{$workOrder->asset->pcid}}"></credential-list>
                            </div> -->
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-lg-6">
                <div class="card h-100">
                    <div class="card-header text-right">
                        <button type="button" class="btn btn-default xs-toggle" data-toggle="collapse" data-target="#workorderTab">
                            <span class="sr-only">Toggle Navigation</span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                            <span class="icon-bar"></span>
                        </button>
                        <ul class="nav nav-pills card-header-pills nav-justified xs-collapse collapse" id="workorderTab" role="tablist">
                            <li class="nav-item">
                                <a class="nav-link active" id="workordersumm-tab" data-toggle="pill" href="#workordersumm" role="tab" aria-controls="workordersumm" aria-selected="true">Summary</a>
                            </li>
                            <li class="nav-item">
                                <a class="nav-link" id="attachments-tab" data-toggle="pill" href="#attachments" role="tab" aria-controls="attachments" aria-selected="false">Attachments</a>
                            </li>
                        </ul>
                    </div>
                    <div class='card-body'>
                        <div class='tab-content'>
                            <div class="tab-pane active" id="workordersumm" role="tabpanel" aria-labelledby="workordersumm-tab">
                                <work-order-info v-if="!woLoading && !storesLoading" :work-order="workOrder" :stores="stores"></work-order-info>
                                <circle-spinner v-else :color="'#663399'"></circle-spinner>
                            </div>
                            <div class="tab-pane" id="attachments" role="tabpanel" aria-labelledby="attachments-tab">
                                TODO 2
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- <div class="row my-3 no-gutters">
            <div class="col-12">
                <div class="card">
                    <div class="card-body">
                        <h5 class="card-title">Customer Notes</h5>
                        <notes :initialnotes='{{ $workOrder->notes->where('notetype', '0')->values() }}' authusername="{{Auth::user()->username}}" :note-type="0" :woid="{{$workOrder->woid}}"></notes>
                    </div>
                </div>
            </div>
        </div>
        <div class="row my-3 no-gutters">
            <div class="col-12">
                <div class="card">
                    <div class="card-body">
                        <h5 class="card-title">Private/Billing Notes</h5>
                        <notes :initialnotes='{{ $workOrder->notes->where('notetype', '1')->values() }}' authusername="{{Auth::user()->username}}" :note-type="1" :woid="{{$workOrder->woid}}"></notes>
                    </div>
                </div>
            </div>
        </div> -->
    </div>
</template>
<script>
import WorkOrderInfo from '../components/WorkOrderInfo.vue'
import CircleSpinner from '../components/CircleSpinner.vue'
export default {
    components: {
        WorkOrderInfo,
        CircleSpinner,
    },
    props: ['id'],
    data () {
        return {
            workOrder: {},
            stores: {},
            woLoading: true,
            storesLoading: true,
        }
    },
    mounted () {
        let token = localStorage.getItem('jwt')
        let user = localStorage.getItem('user')

        axios.defaults.headers.common['Content-Type'] = 'application/json'
        axios.defaults.headers.common['Authorization'] = 'Bearer ' + token

        axios.get('/api/workorders/'+this.id).then(response => {
            this.workOrder = response.data
            this.woLoading = false
        }).catch(error => {
            console.log(error)
        })

        axios.get('/api/stores/').then(response => {
            this.stores = response.data
            this.storesLoading = false
        }).catch(error => {
            console.log(error)
        })
        
        Echo.channel('work-order.'+this.id)
                .listen('WorkOrderUpdated', (e) => {
                    this.workOrder = e.data;
                });
    },
}
</script>