<div id="menu" class="navbar navbar-inverse navbar-fixed-top hidden-print" ng-controller="MenuSearchCtrl" ng-cloak>

	@if(Auth::check())
		<span ng-init="user = {{ Auth::user()->load('profile_photo')->toJSON() }}"></span>
	@else
		<span ng-init="user = null"></span>
	@endif

	<div class="container-fluid">
		<!-- Brand and toggle get grouped for better mobile display -->
	    <div class="navbar-header">
			<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
				<span class="sr-only">Toggle navigation</span>
				<span class="icon-bar"></span>
				<span class="icon-bar"></span>
				<span class="icon-bar"></span>
			</button>
			<a class="navbar-brand" href="{!! URL::to('dashboard') !!}">Seraph
				@if (env('BETA_MODE')) 
					<span style="color:yellow;"> beta site </span>
				@endif
			</a>
	    </div>

	    <!-- Collect the nav links, forms, and other content for toggling -->
		<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
			<ul class="nav navbar-nav">
				<li class="divider-vertical"></li>
				<li>
					<a href="{!! URL::to('bookings') !!}">
						<i class="fa fa-plus"></i>
						Bookings
					</a>
				</li>
				<li class="divider-vertical"></li>
				<li>
					<a href="{!! URL::to('invoices') !!}">
						<i class="fa fa-money"></i>
						Till
					</a>
				</li>
				<li class="divider-vertical"></li>
				<li>
					<a href="{!! URL::to('stock#/stock/') !!}">
						<i class="fa fa-barcode"></i>
						Stock
					</a>
				</li>
				<li class="divider-vertical"></li>
				<li>
					<a href="{!! URL::to('clients#/clients/') !!}">
						<i class="fa fa-user"></i>
						Clients
					</a>
				</li>
				<li>
					<a target="_blank" href="{{ env('WIKI_URL', '#') }}"><i class="fa fa-book"></i>
					Haniel
            		</a>
				</li>
				
				@if (Auth::check() && (Auth::user()->isMemberOf(4) || Auth::user()->isMemberOf(14)))
					<li class="divider-vertical"></li>
					<li>
						<a href="{!! URL::to('stats#/stats/') !!}">
							<i class="fa fa-bar-chart-o"></i>
							Stats
						</a>
					</li>
				@endif
				@if (Auth::check() && Auth::user()->isMemberOf(5))
					<li class="divider-vertical"></li>
					<li>
						<a href="{!! URL::route('accounts.index') !!}">
							<i class="fa fa-credit-card"></i>
							Accounts
						</a>
					</li>
				@endif
				@if (Auth::check() && Auth::user()->hasPermission('access_hr'))
					<li class="divider-vertical"></li>
					<li>
						<a href="{!! URL::to('hr/admin') !!}">
							<i class="fa fa-puzzle-piece"></i>
							HR
						</a>
					</li>
				@endif
				@if (Auth::check() && Auth::user()->isMemberOf(4))
					<li class="divider-vertical"></li>
					<li>
						<a href="{!! URL::to('admin') !!}">
							<i class="fa fa-cogs"></i>
							Admin
						</a>
					</li>
				@endif
				
			</ul>
			<form class="navbar-form navbar-search navbar-right" role="search">
				<input type="text" name="as_q" class="search-query form-control" autocomplete="off" ng-model="q" ng-change="search(q)" placeholder="Search">
			</form>
		</div>
	</div>


	@include('settings')

	<div class="search-results span12" ng-show="hasResults">
		<a class="search-close" ng-click="hideResults()" href="#" eat-click>
			<span class="fa fa-times-circle" ng-hide="searching"></span>
			<i class="fa fa-spinner fa-spin" ng-show="searching"></i>
		</a>
		<div class="search-group cols-7">
			<h4>Clients</h4>
			<small ng-show="results.clients.length == 0">No results found</small>
			<div class="search-result" ng-repeat="item in results.clients">
				<a href="/clients#/client/{[{ item.id }]}" ng-click="hideResults()" ng-class="{flagged: item.flagged }"><i class="fa fa-flag" ng-if="item.flagged"></i> {[{ item.name }]}</a>
			</div>
		</div>
		<div class="search-group cols-7">
			<h4>Customers</h4>
			<small ng-show="results.customers.length == 0">No results found</small>
			<div class="search-result" ng-repeat="item in results.customers">
				<a href="/clients#/customer/{[{ item.id }]}" ng-click="hideResults()" ng-class="{flagged: item.flagged }"><i class="fa fa-flag" ng-if="item.flagged"></i> {[{ item.first_name + ' ' + item.last_name }]}</a>
			</div>
		</div>
		<div class="search-group cols-7">
			<h4>Repairs</h4>
			<small ng-show="results.repairs.length == 0">No results found</small>
			<div class="search-result" ng-repeat="item in results.repairs">
				<a href="{!! URL::to('clients') !!}#/{[{ item.client_type }]}/{[{ item.client_id }]}"><span class="muted">{[{ item.client.name }]}</span></a>
				<p><a href="/tasks/repairs/{[{ item.id }]}" ng-click="hideResults()"><span class="text-warning" ng-bind="item.id"></span> <span ng-show="item.seraph_id" class="text-success">(Seraph ID: {[{ item.seraph_id }]})</span> <span class="text-info" ng-bind="item.title | limitTo:24"></span></a></p>
			</div>
		</div>
		<div class="search-group cols-7">
			<h4>Support</h4>
			<small ng-show="results.support.length == 0">No results found</small>
			<div class="search-result" ng-repeat="item in results.support">
				<a href="{!! URL::to('clients') !!}#/{[{ item.client_type }]}/{[{ item.client_id }]}"><span class="muted">{[{ item.client.name }]}</span></a>
				<p><a href="/tasks/support/{[{ item.id }]}" ng-click="hideResults()"><span class="text-warning" ng-bind="item.id"></span> <span class="text-info" ng-bind="item.title | limitTo:24"></span></a></p>
			</div>
		</div>
		<div class="search-group cols-7">
			<h4>Onsite</h4>
			<small ng-show="results.onsite.length == 0">No results found</small>
			<div class="search-result" ng-repeat="item in results.onsite">
				<a href="{!! URL::to('clients') !!}#/{[{ item.client_type }]}/{[{ item.client_id }]}"><span class="muted">{[{ item.client.name }]}</span></a>
				<p><a href="/tasks/onsite/{[{ item.id }]}" ng-click="hideResults()"><span class="text-warning" ng-bind="item.id"></span> <span class="text-info" ng-bind="item.title | limitTo:24"></span></a></p>
			</div>
		</div>
		<div class="search-group cols-7">
			<h4>Sales</h4>
			<small ng-show="results.onsite.length == 0">No results found</small>
			<div class="search-result" ng-repeat="item in results.sale_leads">
				<a href="{!! URL::to('clients') !!}#/{[{ item.client_type }]}/{[{ item.client_id }]}"><span class="muted">{[{ item.client.name }]}</span></a>
				<p><a href="/tasks/sale-lead/{[{ item.id }]}" ng-click="hideResults()"><span class="text-warning" ng-bind="item.id"></span> <span class="text-info" ng-bind="item.title | limitTo:24"></span></a></p>
			</div>
		</div>
		<div class="search-group cols-7">
			<h4>Invoices</h4>
			<small ng-show="results.invoices.length == 0">No results found</small>
			<div class="search-result" ng-repeat="item in results.invoices">
				<a href="{!! URL::to('clients') !!}#/{[{ item.client_type }]}/{[{ item.client_id }]}"><span class="muted" ng-bind="item.client.name"></span></a>
				<p><a href="/invoices#/{[{ item.type }]}s/view/{[{ item.id }]}" ng-click="hideResults()">Invoice <span class="text-warning">#{[{ item.invoice_number }]}</span></a></p>
			</div>
		</div>
	</div>
</div>
