<?php $__env->startSection('title', 'Asignar Propietario'); ?>
<?php $__env->startSection('style'); ?>
<style type="text/css" media="screen">
    .chosen-container{
        width: 100% !important;
    }

    .chosen-container-single .chosen-search input[type="text"]{
        width: 90%;
    }
</style>
<?php $__env->stopSection(); ?>
<?php $__env->startSection('content'); ?>
<div class="col-sm-12 col-md-10 col-lg-10 col-xl-10">
    <h3 class="text-center titulo">Propietario Predio</h3>
    <div class="form-group row sin-salto">
        <div class="col-sm-2 col-md-2 col-lg-1 col-xl-1 superior">
            <a class="btn-sm btn-primary cursor" href="<?php echo e(route('infoPredio', encrypt($predio->id_unico))); ?>" title="Volver"><i class="fa fa-arrow-left"></i></a>
        </div>
        <div class="col-sm-9 col-md-9 col-lg-10 col-xl-10">
            <h6 class="text-center marca-pagina"><?php echo e("Predio: ".ucwords(mb_strtolower(empty($predio->nombre)?$predio->codigo_catastral:$predio->nombre))); ?></h6>
        </div>
    </div>
    <div class="col-12 col-sm-12 col-md-12 col-lg-12 col-xl-12 superior2 tamaño-letra">
        <table class="table table-striped table-condensed table-bordered" id="table" data-toggle="dataTable" data-form="deleteForm">
            <thead>
                <tr>
                    <th width="66%">Tercero</th>
                    <th width="10%">Propietario?</th>
                    <th width="15%">%</th>
                    <th width="7%"></th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <form id="form-table" method="post" accept-charset="utf-8" action="<?php echo e(route('GuardarPropietarioPredio')); ?>" novalidate>
                        <input type="hidden" name="txtPredio" value="<?php echo e(encrypt($predio->id_unico)); ?>">
                        <?php echo e(csrf_field()); ?>

                        <td>
                            <select id="sltTercero" name="sltTercero" class="form-control select" title="Seleccion un tercero" required="" style="width: 100%">
                                <option value="">Tercero</option>
                                <?php $__currentLoopData = $terceros; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                 <option value="<?php echo e($row->id_unico); ?>"><?php echo e($row->nombres." ".$row->numero." ".$row->direccion); ?></option>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </select>
                        </td>
                        <td>
                            <div class="form-check form-check-inline">
                                <label for="optP1" id="lblOpt1" class="form-check-label label-forma text-right">
                                    <input class="form-check-input" type="radio" name="optPropietario" id="optP1" value="0" required=""> SI
                                </label>
                            </div>
                            <div class="form-check form-check-inline">
                                <label for="optP2" id="lblOpt2" class="form-check-label label-forma text-right">
                                    <input class="form-check-input" type="radio" name="optPropietario" id="optP2" value="1"> NO
                                </label>
                            </div>
                        </td>
                        <td>
                            <input class="form-control tamaño-letra" type="text" id="txtParticipacion" name="txtParticipacion" style="width: 80%" placeholder="%">
                        </td>
                        <td>
                            <button type="submit" id="submit" class="btn-sin icons cursor fa fa-save"></button>
                        </td>
                    </form>
                </tr>
                <?php $__currentLoopData = $predios; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $row): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <tr class="tamaño-letra">
                        <td><?php echo e(mb_strtoupper($row->tercero)." ".mb_strtoupper($row->doc)); ?></td>
                        <td>
                            <?php if($row->propietario == 0): ?>
                                <?php echo e("SI"); ?>

                            <?php else: ?>
                                <?php echo e("NO"); ?>

                            <?php endif; ?>
                        </td>
                        <td><?php echo e($row->porcentaje); ?></td>
                        <td>
                            <a href="" class="fa fa-pencil icons" data-toggle="modal" data-target="#modalUpdate" data-pro="<?php echo e($row->propietario); ?>" data-por="<?php echo e($row->porcentaje); ?>" data-pre="<?php echo e($predio->id_unico); ?>" data-cer="<?php echo e($row->id_tercero); ?>"></a>
                            <?php echo Form::model($predio, ['method' => 'post', 'route' => ['EliminarPropietarioPredio', encrypt($predio->id_unico), encrypt($row->id_tercero)], 'class' => 'form-tabla form-delete']); ?>

                            <?php echo Form::button(trans(''), ['class' => 'fa fa-trash icons btn-sin cursor', 'type' => 'submit']); ?>

                            <?php echo Form::hidden('tercero', encrypt($row->id_tercero)); ?>

                            <?php echo Form::hidden('predio', encrypt($predio->id_unico)); ?>

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

                        </td>
                    </tr>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </tbody>
        </table>
    </div>
</div>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('propietarioPredio.modalUpdate', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
<?php echo $__env->make('modal-confirm', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
<?php $__env->startSection('script'); ?>
<script>
    $('#table').on('click', '.form-delete', function(e){
        e.preventDefault();
        var $form=$(this);
        $('#confirm').modal({ backdrop: 'static', keyboard: false })
            .on('click', '#delete-btn', function(){
                $form.submit();
            });
    });

    $('#modalUpdate').on('show.bs.modal', function (event) {
        var btn = $(event.relatedTarget);
        var por = btn.data('por');
        var pro = btn.data('pro');
        var cer = btn.data('cer');
        var pre = btn.data('pre');
        var modal = $(this);

        modal.find('.modal-body #txtPart').val(por);
        modal.find('.modal-body #txtCer').val(cer);
        modal.find('.modal-body #txtP').val(pre);

        if(pro == 0){
            $("#optPro1").attr('checked', true);
        }else{
            $("#optPro2").attr('checked', true);
        }
    });

    $("#form-table").on('submit', function(e){
        var tercero = $("#sltTercero").val();
        var prop    = $("input[name='optPropietario']").val();
        var porce   = $("#txtParticipacion").val();

        var x = 0;

        if(tercero.length > 0){
            x+= x+1;
            $("#sltTercero_chosen").removeClass('borde-error');
        }else{
            e.preventDefault();
            $("#sltTercero_chosen").addClass('borde-error');
        }

        if($("input[name='optPropietario']").is(':checked')){
            x+= x+1;
            $("#lblOpt1").removeClass("text-danger");
            $("#lblOpt2").removeClass("text-danger");
        }else{
            e.preventDefault();
            $("#lblOpt1").addClass("text-danger");
            $("#lblOpt2").addClass("text-danger");

        }

        if(porce.length > 0){
            x+= x+1;
            $("#txtParticipacion").removeClass('is-invalid');
        }else{
            e.preventDefault();
            $("#txtParticipacion").addClass('is-invalid').removeClass('is-valid');
        }
    });
</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layout_forms', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>