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

            </h1>
        </section>

        <section class="content">
            <div class="row">

                <?php if(!$valid): ?>

                    <?php if($holiday > 0): ?>

                    <div class="callout callout-danger">
                        <h4>Festivos</h4>
                        <p>El sistema sólo permite reservar 2 días festivo por socio. Para cualquier duda, contacte con el administrador, gracias.</p>
                    </div>

                    <?php elseif($message != ''): ?>

                    <div class="callout callout-danger">
                        <h4>El sistema no permite realizar la reserva</h4>
                        <p><?php echo e($message); ?> Para cualquier duda, contacte con el administrador, gracias.</p>
                    </div>

                    <?php else: ?>

                    <div class="callout callout-danger">
                        <h4>No dispone de salidas sufientes</h4>
                        <p>Ya ha agotado el número de salidas asignadas. Para cualquier duda, contacte con el administrador, gracias.</p>
                    </div>

                    <p class="text-center"><a href="<?php echo e(asset('/credits/' . Auth::user()->customer_id . '/listado' )); ?>" class="btn btn-success btn-flat">Ver créditos</a></p>

                    <?php endif; ?>

                <?php else: ?>

                    <div class="col-md-12">
                        <div class="box box-success">
                            <div class="box-header">
                                <div class="user-block">
                                    <span class="username no-margin"></span>
                                    <span class="description no-margin"><?php echo e(trans('general.reservation')); ?> </span>
                                </div>
                            </div>
                            <div class="box-body">

                        <?php echo Form::open(['route' => 'storecalendar', 'method' => 'post']); ?>

                          <div class="col-md-8 col-md-offset-2">
                            <?php echo Form::hidden('user_id', $request->user_id , ['class' => 'form-control']); ?>

	                          <?php echo Form::hidden('customer_id', $customer->id, ['class' => 'form-control']); ?>

                            <?php echo Form::hidden('boat_id', $request->boat_id , ['class' => 'form-control']); ?>

                            <?php echo Form::hidden('date_start_', $date_start , ['class' => 'form-control']); ?>

                            <?php echo Form::hidden('date_start', $date_start , ['class' => 'form-control']); ?>

	                          <?php echo Form::hidden('schedule_id', $request->schedule, ['class' => 'form-control']); ?>

                            <?php if($request->status == '4'): ?>
                                <?php echo Form::hidden('status_id', 4, ['class' => 'form-control']); ?>

                            <?php else: ?>
                                <?php echo Form::hidden('status_id', 2, ['class' => 'form-control']); ?>

                            <?php endif; ?>
                            <p>Nombre: <?php echo e(Auth::user()->first_name); ?> <?php echo e(Auth::user()->last_name); ?></p>
		                        <p>Cliente: <?php echo e($customer->fiscal_reason); ?></p>
                            <p>Embarcación: <?php echo e($boat->name); ?></p>
                            <p>Fecha: <?php echo e($date_start); ?></p>
		                        <p>Horario: <?php echo e($schedule->name); ?></p>

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

                                <?php if(isset($reference_number)): ?>
                                    <?php /*$reference_number */ ?>
                                <?php else: ?> <?php echo e($reference_number = null); ?>

                                <?php endif; ?>

                                <?php echo Form::text('reference_number',$reference_number, ['class' => 'form-control','readonly']); ?>

                                <?php if($errors->has('reference_number')): ?>
                                    <span class="help-block">
                                            <strong><?php echo e($errors->first('reference_number')); ?></strong>
                                        </span>
                                <?php endif; ?>
                            </div>
                            <div class="form-group<?php echo e($errors->has('comments') ? ' has-error' : ''); ?>">
                                <?php echo Form::label('comment', trans('general.comment')); ?>

                                <?php echo Form::textarea('comments', null, ['class' => 'form-control','rows' => '3']); ?>

                                <?php if($errors->has('comments')): ?>
                                    <span class="help-block">
                                <strong><?php echo e($errors->first('comments')); ?></strong>
                            </span>
                                <?php endif; ?>
                            </div>

                            <div id="errorDiv"></div>

                            <?php echo Form::submit(trans('general.reservationsconfirm'), ['class' => 'form-control btn btn-success btn-flat', 'id' => 'submitButton']); ?>

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



                        <?php if(Session::has('sweet_alert.alert')): ?>
                            <script>
                                swal({
                                    title: "CONFIRMAR PRE-RESERVA",
                                    text: "<?php echo e($message); ?><br/><br/>Escriba <b>CANCEL</b> para cancelar esta reserva",
                                    type: "input",
                                    html: true,
                                    cancelButtonText: 'Pre-Reservar',
                                    confirmButtonText: 'Cancelar',
                                    confirmButtonColor: "#ff1a1a",
                                    showCancelButton: true,
                                    closeOnConfirm: false,
                                    closeOnCancel: true,
                                    animation: "slide-from-top",
                                    inputPlaceholder: "CANCEL",
                                    showConfirmButton: "CANCEL",
                                    //confirmButtonText: "<?php echo Session::get('sweet_alert.confirmButtonText'); ?>",
                                    // confirmButtonColor: "#AEDEF4"

                                    // more options
                                }, function(inputValue) {
                                    if (inputValue == "CANCEL") {
                                        window.location.replace('/public/reservations');
                                    } else {
                                        swal.showInputError("Es neceserario que escriba CANCEL!");
                                        return false;
                                    }
                                });

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

                <?php endif; ?>

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


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

    <?php 

        $fecha = explode('/',$date_start);
        $fecha2 = DateTime::createFromFormat('j/n/Y', $date_start);
        $weekDay = $fecha2->format('w');

     ?>

    <script type="text/javascript">
        const url_to_request_get = "https://skipper.komunica.es/checkCredit.php";
        $('#schedule_id').on('change', function(){
            $('#errorDiv').html('');
            $('#submitButton').attr('disabled');
            $.ajax({
                url: url_to_request_get,
                method: "GET",
                data: { u : <?php echo e($request->user_id); ?> , y : <?php echo e($fecha[2]); ?>, m : <?php echo e($fecha[1]); ?>, d : <?php echo e($fecha[0]); ?>, t : $('#schedule_id').val() },
                dataType: "html"
            }).done(function(data) {
                if ( data == 'false'){
                    $('#errorDiv').html('<span class="help-block"><strong>No puedes crear esta reserva porque no tienes créditos</strong></span>');
                }else{
                    $('#submitButton').removeAttr('disabled');
                }
            });

        });

    </script>

<?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(); ?>