<?php $__env->startSection('head'); ?>
	<link href="<?php echo e(asset('/plugins/iCheck/square/green.css')); ?>" rel="stylesheet">
	<link rel="stylesheet" href="<?php echo e(asset('plugins/jQuery/themes/smoothness/jquery-ui.min.css')); ?>">
	<link href="<?php echo e(asset('/plugins/select2/select2.min.css')); ?>" rel="stylesheet" />
	<link rel="stylesheet" href="<?php echo e(asset('/plugins/datepicker/datepicker3.css')); ?>">
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>

	<!-- <div id="csrf-token" name="csrf-token" style="display:none;"><?php echo e(csrf_token()); ?></div> -->

	<div class="content-wrapper">
		<section class="content-header">
			<h1>
				<?php echo e(trans('general.calendario')); ?>

			</h1>
		</section>

		<section class="content">
			<div class="row no-margin" >
				<div class="col-md-8 calendar-credits-container">

					<?php echo $__env->make('alert.errorlist', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
					<?php echo $__env->make('alert.success', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>


					<?php if(Auth::user()->role->layout != 1): ?>
						<div class="row no-margin">
							<div>

								<div class="box box-default">
									<div class="box-header with-border">
										<i class="fa fa-random"></i>
										<h3 class="box-title">Créditos</h3>
										<a href="<?php echo e(asset('/credits/' . Auth::user()->customer_id . '/listado' )); ?>" type="button" class="btn btn-info btn-flat margin pull-right">Transferencia de créditos</a>
									</div>
									<div class="box-body">
										<div id="contenedor" class="credits-months">

										</div>
									</div>
								</div>

							</div>
						</div>
					<?php endif; ?>

					<div class="box box-default">
						<?php if( $boat): ?>
							<div class="box-header with-border">
								<i class="fa fa-calendar"></i>
								<h3 class="box-title"><?php echo e($boat->name); ?></h3>
								<input class="hidden" data="<?php echo e($boat->id); ?>" id="current_boat_id" value="<?php echo e($boat->id); ?>">
							</div>
						<?php endif; ?>
						<div class="box-body">
							<?php echo $calendar->calendar(); ?>

							<?php echo $calendar->script(); ?>

						</div>zz
					</div>
				</div>

				<div class="col-md-4">

					<div class="box box-default">
						<div class="box-header with-border">
							<i class="fa fa-filter"></i>
							<h3 class="box-title">Buscador</h3>
						</div>
						<div class="box-body">
							<div class="row no-margin" >
								<?php echo Form::open(['route' => 'calendar', 'method' => 'POST']); ?>

								<div class="col-md-12">
									<div class="form-group <?php echo e($errors->has('user_id') ? ' has-error' : ''); ?>">
										<?php echo Form::label('user_id', trans('general.usuario')); ?>

										<input type="hidden" name="_token" value="<?php echo e(csrf_token()); ?>">
										<?php echo Form::select('user_id', $users, null, ['class' => 'form-control']); ?>


										<?php if($errors->has('user_id')): ?>
											<span class="help-block">
										<strong><?php echo e($errors->first('user_id')); ?></strong>
									</span>
										<?php endif; ?>
									</div>
								</div>
								<div class="col-md-12">
									<div class="form-group<?php echo e($errors->has('boat') || $errors->has('boat') ? ' has-error' : ''); ?>">
										<?php echo Form::label('boat',  trans('general.boat')); ?> <br />
										<?php echo Form::select('boat_id',[], null, ['class' => 'form-control boat']); ?>


										<?php if($errors->has('boat')): ?>
											<span class="help-block">
										<strong><?php echo e($errors->first('boat')); ?></strong>
									</span>
										<?php endif; ?>
									</div>
								</div>
								<div class="col-md-12">
									<div class="form-group mt-lg">
										<?php echo Form::submit(trans('general.buscar'), ['class' => 'form-control btn btn-info']); ?>

									</div>
								</div>
								<?php echo Form::close(); ?>

							</div>
						</div>
					</div>

					<?php if(Auth::user()->role->role_permission('view_reservation')): ?>

						<div class="box box-default">
							<div class="box-header with-border">
								<i class="fa fa-eye"></i>
								<h3 class="box-title">Leyenda</h3>
							</div>
							<div class="box-body">
								<?php if(isset($status)): ?>
									<?php foreach($status as $estado): ?>
										<?php if($estado->id == 1): ?>
											<span class="col-md-12 label label-success" style="margin-bottom:10px;padding:5px"> <?php echo e($estado->name); ?></span>
										<?php elseif($estado->id == 2): ?>
											<span class="col-md-12 label label-warning" style="margin-bottom:10px;padding:5px">  <?php echo e($estado->name); ?></span>
										<?php elseif($estado->id == 4): ?>
											<span class="col-md-12 label label-info" style="margin-bottom:10px;padding:5px">  <?php echo e($estado->name); ?></span>
										<?php endif; ?>
									<?php endforeach; ?>
								<?php endif; ?>

								<span class="col-md-12 label label-gray" style="padding:5px;margin-bottom:10px;background-color: #abafb7 !important;">  Formación, Mantenimiento, Limpieza </span>

								<span class="col-md-12 label" style="padding:5px;background-color:#EF5773 !important;">Festivo</span>
							</div>
						</div>

					<?php endif; ?>

				</div>
			</div>
		</section>
	</div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('foot'); ?>
	<script src="<?php echo e(asset('/plugins/select2/select2.min.js')); ?>"></script>
	<script src="<?php echo e(asset('plugins/jQueryUI/jquery-ui.min.js')); ?>"></script>

	<script type="text/javascript">
		$(function () {

			$("#user_id").change( function() {
				user =  $('#user_id option:selected').val();
				$('.boat').find('option').remove();
				UpdateUserBoat(user);

			});

			$(".boat").change( function() {
				user =  $('#user_id option:selected').val();
				boat =  $('.boat option:selected').val();
				document.cookie = 'current_boat_id'+'='+boat+';';
			});

			function getCookie(name) {
				var value = "; " + document.cookie;
				var parts = value.split("; " + name + "=");
				if (parts.length == 2) return parts.pop().split(";").shift();
			}


			function UpdateUserBoat(user){
				var _token = $('input[name="_token"]').val();
				const cookies_set = getCookie('current_boat_id');
				$.ajax({
					type: "POST",
					url: "<?php echo e(asset('calendarchangeuserboat')); ?>",
					data: {_token : _token,user: user},
					success: function(data) {
						boats = $.parseJSON(data);
						var current_boat_id = 1;
						if(cookies_set){
							current_boat_id = cookies_set;
						}else{
							current_boat_id = $('#current_boat_id').val();
						}
						boats.forEach(function(item, key){

							if(item!=0){
								if (item.id == current_boat_id){
									$('<option>').val(item.id).text(item.name).attr("selected", "true").appendTo('.boat');
								}else{
									$('<option>').val(item.id).text(item.name).appendTo('.boat');
								}
							}
						});
					}
				});
			}


			$(window).on('load', function() {
				user =  $('#user_id option:selected').val();
				if (user == '')
					user = $('#user_id option:nth-child(2)').val();

				$('.boat').find('option').remove();
				UpdateUserBoat(user);
				boat =  $('.boat option:selected').val();

			});

		});
	</script>

	<?php if(Auth::user()->role->layout != 1): ?>

		<script type="text/javascript">
			//	<?php echo e($url_to_request_get = (string) env('APP_URL','http://skipper.komunica.es' ). "/getcreditos.php"); ?>

	    	//<?php echo e($url_to_request_change = (string) env('APP_URL','http://skipper.komunica.es' ). "/changeCredito.php"); ?>

			const url_to_request_get = "https://skipper.komunica.es/getcreditos.php";
			const url_to_request_change = "https://skipper.komunica.es/changeCredito.php";

			//const url_to_request_get = "<?php echo e($url_to_request_get); ?>";
			//const url_to_request_change = "<?php echo e($url_to_request_change); ?>";

			setTimeout ( function(){
				//var date_from_calendar = moment($('.fc').fullCalendar('getDate')).foramt("YYYY/MM/DD");
				var calendar_view = moment($('.fc').fullCalendar('getDate'));
				var current_month = parseInt(calendar_view.format('M'),10);
				var anio = calendar_view.format('Y');
				$.ajax({
					url: url_to_request_get,
					method: "GET",
					data: { usuario : <?php echo e(Auth::user()->customer_id); ?> , anyo : anio, month: current_month, admin : <?php echo e(Auth::user()->role->layout); ?>, parcial : true, boat : <?php if(isset($boatpost)): ?>  <?php echo e($boatpost->id); ?> <?php else: ?> $('.boat option:selected').val() <?php endif; ?> },
					dataType: "html"
				}).done(function(data) {
					$('#contenedor').html(data);
				});
			}, 2000);

			$('.fc-next-button').on('click', function(){

				var fecha = moment($('.fc').fullCalendar('getDate'));
				var mes = parseInt(fecha.format('M'),10);
				var ano = fecha.format('Y');
				$.ajax({
					url: url_to_request_get,
					method: "GET",
					data: { usuario : <?php echo e(Auth::user()->customer_id); ?> , anyo : ano, month: mes, admin : <?php echo e(Auth::user()->role->layout); ?>, parcial : true, boat : <?php if(isset($boatpost)): ?>  <?php echo e($boatpost->id); ?> <?php else: ?> $('.boat option:selected').val() <?php endif; ?> },
					dataType: "html"
				}).done(function(data) {
					$('#contenedor').html(data);
				});
			});

			$('.fc-prev-button').on('click', function(){

				var fecha = moment($('.fc').fullCalendar('getDate'));
				var mes = parseInt(fecha.format('M'),10);
				var ano = fecha.format('Y');

				$.ajax({
					url: url_to_request_get,
					method: "GET",
					data: { usuario : <?php echo e(Auth::user()->customer_id); ?> , anyo : ano, mnth: mes, admin : <?php echo e(Auth::user()->role->layout); ?>, parcial : true, boat : <?php if(isset($boatpost)): ?>  <?php echo e($boatpost->id); ?> <?php else: ?> $('.boat option:selected').val() <?php endif; ?> },
					dataType: "html"
				}).done(function(data) {
					$('#contenedor').html(data);
				});
			});

			function cambiar( id ){
				var opcion =  $('#anyo option:selected').val();
				let date_from_calendar = moment($('.fc').fullCalendar('getDate'));
				let current_month = parseInt(date_from_calendar.format('M'),10);
				var anio = date_from_calendar.format('Y');
				$.ajax({
					url: url_to_request_change,
					// url: "http://skipper.komunica.es/changeCredito.php" ,
					method: "GET",
					data: { usuario : <?php echo e(Auth::user()->customer_id); ?> , id : id },
					dataType: "text"
				}).done(function(data){
					$.ajax({
						url: url_to_request_get,
						method: "GET",
						data: { usuario : <?php echo e(Auth::user()->customer_id); ?> , anyo : anio, month: current_month , admin : <?php echo e(Auth::user()->role->layout); ?>, parcial : true, boat : <?php if(isset($boatpost)): ?>  <?php echo e($boatpost->id); ?> <?php else: ?> $('.boat option:selected').val() <?php endif; ?> },
						dataType: "html"
					}).done(function(data) {
						$('#contenedor').html(data);
					});
				});
			}

			function siguienteMes (){
				var fecha = moment($('.fc').fullCalendar('getDate'));
				var mes = parseInt(fecha.format('M'),10);
				var ano = fecha.format('Y');

				$.ajax({
					url: url_to_request_get,
					method: "GET",
					data: { usuario : <?php echo e(Auth::user()->customer_id); ?> , anyo : ano, month: mes, admin : <?php echo e(Auth::user()->role->layout); ?>, parcial : true, boat : <?php if(isset($boatpost)): ?>  <?php echo e($boatpost->id); ?> <?php else: ?> $('.boat option:selected').val() <?php endif; ?> },
					dataType: "html"
				}).done(function(data) {
					$('#contenedor').html(data);
				});
			}

			function anteriorMes(){
				var fecha = moment($('.fc').fullCalendar('getDate'));
				var mes = parseInt(fecha.format('M'),10);
				var ano = fecha.format('Y');

				$.ajax({
					url: url_to_request_get,
					method: "GET",
					data: { usuario : <?php echo e(Auth::user()->customer_id); ?> , anyo : ano, month: mes, admin : <?php echo e(Auth::user()->role->layout); ?>, parcial : true, boat : <?php if(isset($boatpost)): ?>  <?php echo e($boatpost->id); ?> <?php else: ?> $('.boat option:selected').val() <?php endif; ?> },
					dataType: "html"
				}).done(function(data) {
					$('#contenedor').html(data);
				});
			}

			$('.fc-today-button').css('display','none !important');

			setTimeout(function(){  $('.fc-prev-button').on('click', anteriorMes); $('.fc-next-button').on('click', siguienteMes);   },3000);

		</script>
	<?php endif; ?>
<?php $__env->stopSection(); ?>

<?php echo $__env->make(Auth::check() && Auth::user()->role->layout == 1 ? 'layouts.admin' : 'layouts.employee', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>