@extends('layouts.master')

@section('header')
	@include('common.header')
@stop

@section('content')
	<div class="row">
		<div class="col-sm-8">
			<div class="widget widget-classic">
				<div class="widget-content">

					<!-- Page title -->
					<p class="lead">
						Configure Contracts
						<a href="{!! URL::route('admin.settings.contracts.create') !!}" class="btn btn-primary pull-right"><i class="fa fa-plus"></i> Add new contract</a>
					</p>

					@if (Session::has('message'))
						<div class="alert alert-success">
							<i class="fa fa-check-circle"></i> {!! Session::get('message') !!}
						</div>
					@endif

					@if (Session::has('error'))
						<div class="alert alert-danger">
							<i class="fa fa-exclamation-circle"></i> {!! Session::get('error') !!}
						</div>
					@endif

					<table class="table table-hover">
						<tbody>
							@foreach($contracts as $contract)
								<tr>
									<td style="width: 25px;">{!! $contract->id !!}.</td>
									<td>{!! $contract->name !!}</td>
									<td>{!! $contract->client->name ?? 'No client assigned' !!}</td>
									<td>{!! $contract->start_date ? $contract->start_date->format('M d, Y') : 'N/A' !!}</td>
									<td>{!! $contract->end_date ? $contract->end_date->format('M d, Y') : 'N/A' !!}</td>
									<td>{!! $contract->value ? '$' . number_format($contract->value, 2) : 'N/A' !!}</td>
									<td>
										@if($contract->effective_status === 'active')
											<span class="label label-success">Active</span>
										@elseif($contract->effective_status === 'inactive')
											<span class="label label-warning">Inactive</span>
										@elseif($contract->effective_status === 'expired')
											<span class="label label-danger">Expired</span>
										@else
											<span class="label label-default">{!! ucfirst($contract->effective_status) !!}</span>
										@endif
									</td>
									<td><a href="{!! URL::route('admin.settings.contracts.edit', $contract->id) !!}" class="pull-right">Edit</a></td>
								</tr>
							@endforeach
						</tbody>
					</table>

					<hr>
					<p><small>Total of {!! count($contracts) !!} entries</small></p>
				</div>
			</div>
		</div>
		<div class="col-sm-4">
			@include('admin::settings.contracts.partials.info')
		</div>
	</div>
@stop