<?php $__env->startSection('content'); ?>
<div class="master-main mainContent mobile maincontent-design2 middlebackground background-design5">
    <div class="container">
        <div class="row multi">
            <div class="hidden"></div>
            <div class="col-xs-12 col-single tabbed main-content">
                
                <div class="content-inner-container profile-content">
                    <div id="MainContent_Panel1">
    
                        <h2 class="main-content-page-title">Profil</h2>
                        
                        <div class="well profileform" style="max-width:initial">
                            <div class="form-horizontal">
                                
                                
                                <div class="form-group form-group-sm">
                                    <label class="col-sm-4 control-label">Username</label>
                                    <div class="col-sm-8 form-content">
                                        <span class="control-label" style="color: #f3c300; font-weight: bold;"><?php echo e(auth()->user()->username); ?></span>
                                    </div>
                                </div>
                                
                                <div class="form-group form-group-sm">
                                    <label class="col-sm-4 control-label">Email</label>
                                    <div class="col-sm-8 form-content">
                                        <span class="control-label"><?php echo e(auth()->user()->email ?? 'Tidak ada email'); ?></span>
                                    </div>
                                </div>
                                
                                <div class="form-group form-group-sm">
                                    <label class="col-sm-4 control-label">Telepon</label>
                                    <div class="col-sm-8 form-content">
                                        <span class="control-label"><?php echo e(auth()->user()->nohp ?? auth()->user()->no_hp ?? '-'); ?></span>
                                    </div>
                                </div>
                                
                                <hr style="border-top: 1px solid #444;" />
                                
                                <h4>Tukar Password</h4>
                                
                                
                                <div class="form-group form-group-sm">
                                    <label class="col-sm-4 control-label">Password Lama</label>
                                    <div class="col-sm-8">
                                        <input type="password" id="inputpass" class="form-control" placeholder="Masukkan Password Lama" autocomplete="off" />
                                    </div>
                                </div>
                                
                                <div class="form-group form-group-sm">
                                    <label class="col-sm-4 control-label">Password Baru</label>
                                    <div class="col-sm-8">
                                        <input type="password" id="inputnewpass" class="form-control" placeholder="Masukkan Password Baru" autocomplete="off" />
                                    </div>
                                </div>
                                
                                <div class="form-group form-group-sm">
                                    <label class="col-sm-4 control-label">Konfirmasi Password</label>
                                    <div class="col-sm-8">
                                        <input type="password" id="inputnewpass2" class="form-control" placeholder="Konfirmasi Password Baru" autocomplete="off" />
                                    </div>
                                </div>
                                
                                <div class="form-group form-group-sm">
                                    <label class="col-sm-4 control-label">Nomor Rekening</label>
                                    <div class="col-sm-8 bankAcc">
                                        <div class="form-content">
                                            <?php
                                                // Sensor nomor rekening, tampilkan contoh: BCA - *******1234
                                                $namaBank = strtoupper(auth()->user()->nama_bank ?? 'BANK');
                                                $noRek = auth()->user()->nomor_rekening ?? '0000';
                                                $sensorRek = str_repeat('*', max(0, strlen($noRek) - 4)) . substr($noRek, -4);
                                            ?>
                                            <span class="control-label"><?php echo e($namaBank); ?> - <?php echo e($sensorRek); ?></span>
                                        </div>
                                        <div class="inputBankAccNum" style="margin-top: 10px;">
                                            <input type="tel" id="bankAccNumber" class="form-control" maxlength="4" placeholder="Masukkan 4 Digit Terakhir Rekening" onkeypress="return isNumberKey(event)" autocomplete="off" />
                                        </div>
                                    </div>
                                </div>
                                
                                
                                <div class="form-group form-group-sm" style="text-align: center; margin-bottom: 0px;">
                                    <div id="errormsg" class="error-msg" style="margin-bottom: 15px; color: #dc3545; font-weight:bold;"></div>
                                    <div id="successmsg" style="margin-bottom: 15px; color: #28a745; font-weight:bold;"></div>
                                    
                                    <button type="button" id="btnSubmit" class="btn btn-theme" style="margin: 0px 15px 15px 15px;">Kirim</button>
                                    <button type="button" id="btnNoChange" class="btn btn-default" style="margin: 0px 0px 15px 0px;" onclick="window.location.href='/mobile/account/deposit'">Batal / Kembali</button>
                                </div>
                                
                                <div style="text-align: center; color: #aaa; font-size: 12px;">
                                    Demi keamanan, jangan berikan password Anda kepada siapapun.<br />
                                    Password harus diisi dengan kombinasi Angka dan Huruf minimal 6 karakter.
                                </div>

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

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

<?php $__env->startPush('script'); ?>
<script>
    // Hanya izinkan input angka untuk nomor rekening
    function isNumberKey(evt) {
        var charCode = (evt.which) ? evt.which : event.keyCode;
        if (charCode > 31 && (charCode < 48 || charCode > 57)) return false;
        return true;
    }

    $(document).ready(function() {
        // Ambil 4 digit terakhir nomor rekening asli dari server (Untuk validasi frontend)
        var validLast4 = "<?php echo e(substr(auth()->user()->nomor_rekening ?? '0000', -4)); ?>";

        $('#btnSubmit').on('click', function(e) {
            e.preventDefault();
            
            // Reset Pesan
            $('#errormsg').text('');
            $('#successmsg').text('');

            // Ambil Value
            var oldPass = $('#inputpass').val();
            var newPass = $('#inputnewpass').val();
            var confirmPass = $('#inputnewpass2').val();
            var last4Rek = $('#bankAccNumber').val();

            // 1. VALIDASI FRONTEND
            if (oldPass === '' || newPass === '' || confirmPass === '') {
                $('#errormsg').text('* Semua kolom password wajib diisi.');
                return false;
            }

            if (newPass.length < 6) {
                $('#errormsg').text('* Password baru minimal 6 karakter.');
                return false;
            }

            if (newPass !== confirmPass) {
                $('#errormsg').text('* Konfirmasi password tidak cocok.');
                return false;
            }

            if (last4Rek === '') {
                $('#errormsg').text('* 4 Digit nomor rekening wajib diisi untuk verifikasi keamanan.');
                return false;
            }

            if (last4Rek !== validLast4) {
                $('#errormsg').text('* 4 Digit nomor rekening tidak sesuai dengan data Anda.');
                return false;
            }

            // 2. PROSES AJAX KE CONTROLLER
            var $btn = $(this);
            $btn.prop('disabled', true).text('Memproses...');

            $.ajax({
                url: "<?php echo e(route('update.password')); ?>", // Memanggil route API Anda
                type: "POST",
                dataType: "JSON",
                data: {
                    oldpassword: oldPass,
                    newpassword: newPass
                },
                success: function(response) {
                    // Cek berdasarkan response Controller Anda
                    if (response.success === true) {
                        $('#successmsg').text(response.data.message);
                        
                        // Kosongkan form
                        $('#inputpass').val('');
                        $('#inputnewpass').val('');
                        $('#inputnewpass2').val('');
                        $('#bankAccNumber').val('');

                        // Jika ingin redirect otomatis ke halaman login setelah ganti password
                        // setTimeout(function(){ window.location.href = '/login'; }, 2000);
                    } else {
                        $('#errormsg').text('* ' + response.data.message);
                    }
                },
                error: function(xhr, status, error) {
                    $('#errormsg').text('* Terjadi kesalahan server. Silakan coba lagi.');
                    console.error(error);
                },
                complete: function() {
                    // Kembalikan tombol seperti semula
                    $btn.prop('disabled', false).text('Kirim');
                }
            });
        });
    });
</script>
<?php $__env->stopPush(); ?>
<?php echo $__env->make('frontend.mobile.pages.account.layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /www/wwwroot/website/sewa/dragon158/resources/views/frontend/mobile/pages/account/pages/profile.blade.php ENDPATH**/ ?>