<h3>{[{ data.name }]}</h3>

<div class="row">
	<div class="col-sm-10">
		<div data-fade="1" ngModel="activeTab" bs-tabs>
			<div ng-repeat="tab in tabs" data-title="{[{ tab.title }]}" ng-include="tab.template"></div>
		</div>

	</div>

	<div class="col-sm-2">
		<br><br>
		<a href="{!! URL::to('/bookings') !!}/#bookings/client/{[{ data.id }]}" class="btn btn-success btn-block"><i class="fa fa-plus"></i> New Booking</a>
		<br>
		@if (Auth::user()->isMemberOf(5))
			<a href="{!! URL::to('accounts') !!}/{[{ data.id }]}/client" class="btn btn-warning btn-block"><i class="fa fa-gbp"></i> View accounts</a>
		@endif
		<button class="btn btn-warning btn-block" ng-click="findDuplicates()"><i class="fa fa-tags"></i> Find duplicates</button>
		<button class="btn btn-warning btn-block" ng-confirm-click="Are you sure you want to convert this client to a customer? NOTE: this will remove all the sites and their users!" confirmed-click="convert()"><i class="fa fa-refresh"></i> Convert to customer</button>
		            <button class="btn btn-warning btn-block" ng-click="syncXero()"><i class="fa fa-exchange"></i> Sync with Xero</button>
		<button class="btn btn-warning btn-block" ng-click="createReport()"><i class="fa fa-exchange"></i> Create Report</button>
		<button class="btn btn-warning btn-block" ng-if="!data.subscribed" ng-click="subscribe()"><i class="fa fa-exchange"></i> Subscribe</button>
		<button class="btn btn-warning btn-block" ng-if="data.subscribed" ng-click="unsubscribe()"><i class="fa fa-exchange"></i> Unsubscribe</button>
		<br>
		@can('delete-client')
			<button class="btn btn-danger btn-block" ng-confirm-click="Are you sure you want to delete this client?" confirmed-click="deleteClient()"><i class="fa fa-times"></i> Delete client</button>
		@endif
	</div>
</div>

@include('templates.modals.confirmation')
@include('clients::duplicates')
@include('clients::site-modal')
@include('clients::site-user-modal')

<script type="text/ng-template" id="clients/client-summary.html">
	<div class="bookings-content repair-tab">
		<div class="alert alert-danger" ng-if="data.monthly_allowance_left !== null && data.monthly_allowance_left <= 0">
			<i class="fa fa-exclamation-triangle"></i> The monthly contract allowance for this user has been exhausted!
		</div>
		<div class="row">
			<div class="col-sm-3">
				<div class="well text-center">
					<canvas class="chart chart-doughnut" chart-data="tasks_pie.data" chart-labels="tasks_pie.labels"></canvas>
				</div>
			</div>
			<div class="col-sm-3">
				<div class="well text-center">
						<h4>{[{ summary.stats.spent | currency:"£" }]}</h4>
						<small>Money spent</small>
				</div>
			</div>
			<div class="col-sm-3">
				<div class="well text-center">
						<h4>{[{ summary.stats.last_task.created_at | fromNow }]}</h4>
						<small>Last task</small>
				</div>
			</div>
			<div class="col-sm-3">
				<div class="well text-center">
						<h4>{[{ summary.stats.payment_due | currency:"£" }]}</h4>
						<small>Payment due</small>
				</div>
			</div>
		</div>
		<div style="margin-top: 10px;">
				<i class="fa fa-rss-square fa-lg"></i> &nbsp; <a href="#" ng-click="showSubscribers()" data-eat-click><span ng-show="data.subscribed">You and </span>{[{ (data.subscribers | exclude:'id':auth.data.id).length }]} people</a> subscribed to this Client.
				<a href="#" ng-if="!data.subscribed" ng-click="subscribe()" eat-click>Subscribe</a>
				<a href="#" ng-if="data.subscribed" ng-click="unsubscribe()" eat-click>Unsubscribe</a>
		</div>
		<form name="clientForm" class="form-horizontal">
			<div class="row">
				<div class="col-sm-5">
					@include('clients::details')
				</div>

				<div class="col-sm-5">
					@include('clients::contract')
				<div class="text-right">
						<button class="btn btn-primary" ng-click="save()"  eat-click>Save changes</button>
					</div>
				</div>
			</div>
			<div class="row">

					@include('clients::sites')
					

			</div>	
		</form>
	</div>
</script>

