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

@section('content')
	<div class="row" ng-controller="AdminEmailSettingsCtrl" ng-init="data = {{ json_encode($settings) }}" ng-cloak>
		<div class="col-sm-8">
			<div class="widget widget-classic">
				<div class="widget-content">

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

						<!-- Enabled button -->
						<span ng-if="data.enabled" style="margin-right: 5px;" ng-click="toggle('{!! URL::route('admin.settings.emails.disable') !!}')" class="btn pull-right" ng-class="{'btn-danger': show_disable_text, 'btn-success': !show_disable_text}" ng-mouseenter="show_disable_text = true" ng-mouseleave="show_disable_text = false"><i ng-class="{'fa fa-check': !show_disable_text}"></i> {[{ show_disable_text ? 'Click to disable' : 'Enabled' }]}</span>

						<!-- Disabled button -->
						<span ng-if="!data.enabled" style="margin-right: 5px;" ng-click="toggle('{!! URL::route('admin.settings.emails.enable') !!}')" class="btn pull-right" ng-class="{'btn-success': show_enable_text, 'btn-danger': !show_enable_text}" ng-mouseenter="show_enable_text = true" ng-mouseleave="show_enable_text = false"><i ng-class="{'fa fa-times': !show_enable_text}"></i> {[{ show_enable_text ? 'Click to enable' : 'Disabled' }]}</span>
					</p>

					<div class="alert alert-success" ng-if="success">
						<i class="fa fa-check-circle"></i> <span ng-bind="success"></span>
					</div>

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

					<table class="table table-hover">
						<tbody>
							@foreach($emails as $email)
								<tr>
									<td style="width: 25px;">{!! $email->id !!}.</td>
									<td>{!! $email->name !!} &lt;{!! $email->email !!}&gt;</td>
									<td>
										<div><span class="muted">IMAP Server:</span> {!! $email->server !!}</div>
										<div><span class="muted">IMAP Port:</span> {!! $email->port !!}</div>
										<div><span class="muted">Protocol:</span> {!! $email->protocol !!}</div>
									</td>
									<td>
										<div><span class="muted">Username:</span> {!! $email->username !!}</div>
										<div><span class="muted">Book as:</span> {!! $email->booking_type ? App\Modules\Admin\EmailSettings::getTypes()[$email->booking_type] : '' !!}</div>
										@if($email->smtp_host)
											<div><span class="muted">SMTP:</span> {!! $email->smtp_host !!}:{!! $email->smtp_port !!}</div>
										@endif
									</td>
									<td><a href="{!! URL::route('admin.settings.emails.edit', $email->id) !!}" class="pull-right">Edit</a></td>
								</tr>
							@endforeach
						</tbody>
					</table>

					@if (count($emails) == 0)
						<p class="text-warning"><i class="fa fa-info-circle"></i> No email addresses are defined</p>
					@else
						<hr>
						<p><small>Total of {!! count($emails) !!} entries</small></p>
					@endif
				</div>
			</div>
		</div>
		<div class="col-sm-4">
			@include('admin::settings.emails.partials.info')
		</div>
	</div>
@stop