
<?php $__env->startSection('title','Customer'); ?>
<?php $__env->startSection('content'); ?>
        
        <div class="breadcrumbs">
            <div class="breadcrumbs-inner">
                <div class="row m-0">
                    <div class="col-sm-4">
                        <div class="page-header float-left">
                            <div class="page-title">
                                <h1>Customer</h1>
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-8">
                        <div class="page-header float-right">
                            <div class="page-title">
                                <ol class="breadcrumb text-right">
                                    <li><a href="#">Master</a></li>
                                    <li><a href="#">Customer</a></li>
                                    <li class="active">Ubah Customer</li>
                                </ol>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- Content -->
        <div class="content">
            <div class="animated fadeIn">
                <div class="row">

                    <div class="col-md-12">
                        <div class="card">
                            <div class="card-header">
                                <strong class="card-title">Ubah Customer</strong>
                            </div>
                            <div class="card-body card-block">
                                <form action="<?php echo e(route('customer.update', ['customer' => $customer['id']])); ?>" method="post" enctype="multipart/form-data" class="form-horizontal">
                                    <?php echo csrf_field(); ?>
                                    <?php echo method_field('PUT'); ?>
                                    <div class="row form-group">
                                        <div class="col col-md-2"><label for="text-input" class=" form-control-label">Customer</label></div>
                                        <div class="col-12 col-md-7">
                                            <input type="text" id="text-input" name="nama_customer" placeholder="Nama Customer" class="form-control" value="<?php echo e($customer->nama_customer); ?>" required>
                                        </div>
                                    </div>

                                    <div style="margin-top: 20px" class="table-responsive">
                                        <table id="lokasi" class="table table-bordered table-striped">
                                            <thead>
                                                <tr>
                                                    <th>Action</th>
                                                    <th>No</th>
                                                    <th>Lokasi</th>
                                                    
                                                </tr>
                                            </thead>
                                            <tbody>
                                                <?php $__currentLoopData = $alamat_customer; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $cs): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                                    <tr>
                                                        <td>
                                                            <button type="button" value="Delete" onclick="deleteTipe(this)" class="btn btn-danger"><i class="fa fa-trash-o"></i></button>
                                                        </td>
                                                        <td><?php echo e($loop->iteration); ?></td>
                                                        <td>
                                                            <input type="text" name="post[lokasi][]" class="form-control" value="<?php echo e($cs->alamat); ?>">
                                                            
                                                        </td>
                                                    </tr>    
                                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                                <tr>
                                                    <td>
                                                        <a onclick="createTipe()" class="btn btn-success"><i class="fa fa-plus"></i></a>
                                                    </td>
                                                    <td colspan="2"></td>
                                                </tr>
                                            </tbody>
                                        </table>
                                    </div>

                                   <hr style="border: 1px solid black">
                                    PIC
                                   <br/><br/>

                                   <div class="row form-group">
                                        <div class="col col-md-2">
                                            <label for="name" class="form-control-label">Nama</label>
                                        </div>
                                        <div class="col-12 col-md-5">
                                            <input type="text" id="name" name="name" placeholder="Nama" class="form-control" required value="<?php echo e($user[0]['nama_lengkap']); ?>">
                                            <input type="hidden" name="user_id" value="<?php echo e($user[0]['id']); ?>">
                                            <?php $__errorArgs = ['name'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                                <small class="text-danger"><?php echo e($message); ?></small>
                                            <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                        </div>
                                    </div>

                                    <div class="row form-group">
                                        <div class="col col-md-2">
                                            <label for="no_hp" class="form-control-label">No. Handphone</label>
                                        </div>
                                        <div class="col-12 col-md-4">
                                            <input type="text" id="no_hp" name="no_hp" class="form-control" value="<?php echo e($user[0]['no_telp']); ?>">
                                            <?php $__errorArgs = ['no_hp'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                                <small class="text-danger"><?php echo e($message); ?></small>
                                            <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                        </div>
                                    </div>

                                    <div class="row form-group">
                                        <div class="col col-md-2">
                                            <label for="email" class="form-control-label">Email</label>
                                        </div>
                                        <div class="col-12 col-md-4">
                                            <input type="email" id="email" name="email" class="form-control" value="<?php echo e($user[0]['email']); ?>">
                                            <?php $__errorArgs = ['email'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                                <small class="text-danger"><?php echo e($message); ?></small>
                                            <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                        </div>
                                    </div>

                                    <div class="row form-group">
                                        <div class="col col-md-2">
                                            <label for="username" class="form-control-label">Username</label>
                                        </div>
                                        <div class="col-12 col-md-5">
                                            <input type="text" onkeyup="checkUsername(this.value)" id="username" name="username" placeholder="Username" class="form-control" required value="<?php echo e($user[0]['username']); ?>">
                                            <span id="usernameFeedback" class="help-block form-text"></span>
                                            <?php $__errorArgs = ['username'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                                <small class="text-danger"><?php echo e($message); ?></small>
                                            <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                        </div>
                                    </div>

                                    <div class="row form-group">
                                        <div class="col col-md-2">
                                            <label for="password" class="form-control-label">Password</label>
                                        </div>
                                        <div class="col-12 col-md-5">
                                            <input type="text" id="password" name="password" placeholder="Password" class="form-control">
                                            <?php $__errorArgs = ['password'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                                <small class="text-danger"><?php echo e($message); ?></small>
                                            <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                            <small class="text-info">Jika password tidak diganti boleh dikosongkan</small>
                                        </div>
                                    </div>

                                    <div class="row form-group">
                                        <div class="col col-md-2">
                                            <label for="password_confirmation" class="form-control-label">Konfirmasi Password</label>
                                        </div>
                                        <div class="col-12 col-md-5">
                                            <input type="text" id="password_confirmation" name="password_confirmation" placeholder="Konfirmasi Password" class="form-control">
                                            <?php $__errorArgs = ['password_confirmation'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                                <small class="text-danger"><?php echo e($message); ?></small>
                                            <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                                        </div>
                                    </div>

                                    <button id="btnSave" type="submit" class="btn btn-primary">
                                        Simpan
                                    </button>
                                    <a href="<?php echo e(route('customer.index')); ?>" class="btn btn-default">
                                        Batal
                                    </button>
                                </form>
                            </div>
                           
                        </div>
                    </div>


                </div>
            </div><!-- .animated -->
        </div><!-- .content -->
        <!-- /.content -->
<?php $__env->startSection('js'); ?>
<script>
function createTipe() {
    var table = document.getElementById("lokasi");
    var tbodyRowCount = table.tBodies[0].rows.length;
    var row = table.insertRow(tbodyRowCount);

    var cell1L = row.insertCell(0);
    var cell2L = row.insertCell(1);
    var cell3L = row.insertCell(2);
    //var cell4L = row.insertCell(3);


    cell1L.innerHTML = "<button type='button' value='Delete' onclick='deleteTipe(this)' class='btn btn-danger'><i class='fa fa-trash-o'></i></button>";
    cell2L.innerHTML = tbodyRowCount;
    cell3L.innerHTML = '<input type="text" name="post[lokasi][]" class="form-control">';
    


}

function deleteTipe(btn) {
    var row = btn.parentNode.parentNode;
    row.parentNode.removeChild(row);
    //merek();
}
function checkUsername(username) {
    let feedback = document.getElementById("usernameFeedback");
    let inputField = document.querySelector('input[name="username"]');

    // Ambil ID user jika sedang edit (misalnya dari input hidden)
    let userId = document.querySelector('input[name="user_id"]')?.value || "";

    if (username.length > 0) {
        fetch(`<?php echo e(url('/check-username')); ?>?username=${username}&id=${userId}`)
            .then(response => response.json())
            .then(data => {
                if (data.exists) {
                    inputField.style.borderColor = "red";
                    feedback.style.color = "red";
                    feedback.textContent = "Username sudah digunakan!";
                    btnSave.style.display = "none"; // Sembunyikan tombol Simpan
                } else {
                    inputField.style.borderColor = "green";
                    feedback.style.color = "green";
                    feedback.textContent = "Username tersedia!";
                    btnSave.style.display = "";
                }
            });
    } else {
        feedback.textContent = "";
        inputField.style.borderColor = "";
    }
}
</script>
<?php $__env->stopSection(); ?>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.master', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /home3/baktijay/public_html/ptgib.co.id/admin/resources/views/master/customer/edit.blade.php ENDPATH**/ ?>