@use(App\Models\Product)

@extends('adminlte::layouts.app')

@section('htmlheader_title')
	{{ $o->sid }}
@endsection
@section('page_title')
	{{ $o->sid }}
@endsection

@section('contentheader_title')
	Service: {{ $o->sid }} <strong>{{ $o->product->name }}</strong>
@endsection
@section('contentheader_description')
	{{ $o->name }}
@endsection

@section('main-content')
	<div class="row">
		<!-- Service Details -->
		<div class="col-12 col-md-5">
			@includeIf('theme.backend.adminlte.service.widget.'.$o->product->category_lc.'.details',['o'=>$o->type])
			@include('theme.backend.adminlte.service.widget.information')
		</div>

		<div class="col-12 col-md-7">
			<div class="card">
				<div class="card-header bg-dark d-flex p-0">
					<ul class="nav nav-pills w-100 p-2">
						@if($x=! ($o->suspend_billing || $o->external_billing))
							<li class="nav-item"><a @class(['nav-link','active'=>! (session()->has('service_update') || session()->has('charge_add'))]) href="#pending_items" data-toggle="tab">Pending Items</a></li>
						@endif

						@if($o->product->has_usage)
							<li class="nav-item"><a @class(['nav-link','active'=>! ($x || (session()->has('service_update') || session()->has('charge_add')))]) href="#traffic" data-toggle="tab">Traffic</a></li>
						@endif

						@can('wholesaler')
							<li class="nav-item ml-auto"><a class="nav-link" href="#billing" data-toggle="tab">Billing History</a></li>
							<li class="nav-item"><a class="nav-link" href="#internal" data-toggle="tab">Internal</a></li>
							<li class="nav-item"><a @class(['nav-link','active'=>session()->has('service_update')]) href="#update" data-toggle="tab">Update</a></li>
							@if($o->active || $o->is_pending_active)
								<li class="nav-item"><a @class(['nav-link','active'=>session()->has('charge_add')]) href="#charge" data-toggle="tab">Charge</a></li>
							@endif
						@endcan
					</ul>

					@can('progress',$o)
						<ul class="nav nav-pills ml-auto p-2">
							<li class="nav-item dropdown">
								<a class="nav-link dropdown-toggle" data-toggle="dropdown" href="#">ACTION <span class="caret"></span></a>

								<div class="dropdown-menu dropdown-menu-right">
									@foreach($o->actions() as $stage => $title)
										<a class="dropdown-item" tabindex="-1" href="{{ url('u/service',['id'=>$o->id,'action'=>'change','stage'=>$stage]) }}">{{ $title }}</a>
									@endforeach
									{{-- <div class="dropdown-divider"></div> --}}
								</div>
							</li>
						</ul>
					@endcan
				</div>

				<div class="card-body p-2">
					<div class="tab-content">
						@if(($x=! ($o->suspend_billing || $o->external_billing)) && $o->invoice_next)
							<div @class(['tab-pane','fade','show active'=>! (session()->has('service_update') || session()->has('charge_add'))]) id="pending_items">
								@include('theme.backend.adminlte.service.widget.invoice')
							</div>
						@endif

						@if($o->product->has_usage)
							<div @class(['tab-pane','fade','show active'=>! ($x || (session()->has('service_update') || session()->has('charge_add')))]) id="traffic">
								@if($o->type->usage(30)->count())
									@include('theme.backend.adminlte.service.widget.'.$o->product->category_lc.'.usagegraph',['o'=>$o->type])
								@endif
							</div>
						@endif

						@can('wholesaler')
							<div class="tab-pane fade" id="billing">
								@include('theme.backend.adminlte.service.widget.billinghistory',['o'=>$o])
							</div>

							<div class="tab-pane fade" id="internal">
								@if(($x=$o->changes()->where('service__change.active',TRUE)->where('complete',FALSE)->get()->pop()))
									@include('theme.backend.adminlte.service.widget.internal',['o'=>$o,'p'=>$x])
								@else
									@include('theme.backend.adminlte.service.widget.internal',['o'=>$o,'p'=>new Product()])
								@endif
							</div>

							<div @class(['tab-pane','fade','show active'=>session()->pull('service_update'),'p-2']) id="update">
								@include('theme.backend.adminlte.service.widget.update')
							</div>

							@if($o->active || $o->is_pending_active)
								<div @class(['tab-pane','fade','show active'=>session()->pull('charge_add')]) id="charge">
									@include('theme.backend.adminlte.service.widget.charge')
								</div>
							@endif
						@endcan
					</div>
				</div>
			</div>
		</div>
	</div>
@endsection