

<?php $__env->startSection('title', 'Profil Saya'); ?>

<?php $__env->startSection('content_header'); ?>
    <h1><i class="fas fa-user-circle mr-2"></i>Profil Saya</h1>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>
    <?php if(session('success')): ?>
        <div class="alert alert-success alert-dismissible">
            <button type="button" class="close" data-dismiss="alert">&times;</button>
            <i class="fas fa-check-circle mr-1"></i><?php echo e(session('success')); ?>

        </div>
    <?php endif; ?>

    <div class="row">
        
        <div class="col-md-4">
            <div class="card card-primary card-outline">
                <div class="card-body text-center pt-4">
                    <div class="mb-3 position-relative d-inline-block">
                        <?php if($user->foto_profil): ?>
                            <img src="<?php echo e(asset('storage/' . $user->foto_profil)); ?>" alt="Foto Profil" id="previewFoto"
                                class="img-circle elevation-2"
                                style="width:110px;height:110px;object-fit:cover;cursor:pointer"
                                onclick="document.getElementById('inputFoto').click()">
                        <?php else: ?>
                            <img src="https://ui-avatars.com/api/?name=<?php echo e(urlencode($user->name)); ?>&background=007bff&color=fff&size=110"
                                alt="Avatar" id="previewFoto" class="img-circle elevation-2"
                                style="width:110px;height:110px;object-fit:cover;cursor:pointer"
                                onclick="document.getElementById('inputFoto').click()">
                        <?php endif; ?>
                        <span class="position-absolute" style="bottom:0;right:0">
                            <button type="button" class="btn btn-sm btn-primary rounded-circle p-1"
                                style="width:28px;height:28px;line-height:1"
                                onclick="document.getElementById('inputFoto').click()" title="Tukar gambar">
                                <i class="fas fa-camera" style="font-size:12px"></i>
                            </button>
                        </span>
                    </div>
                    <p class="text-muted small mb-2">Klik gambar untuk tukar foto</p>
                    <h4 class="font-weight-bold mb-1"><?php echo e($user->name); ?></h4>
                    <span
                        class="badge badge-<?php echo e($user->role === 'admin' ? 'danger' : ($user->role === 'supervisor' ? 'warning' : ($user->role === 'checker' ? 'info' : 'success'))); ?> px-3 py-1 mb-2">
                        <?php echo e(strtoupper($user->role)); ?>

                    </span>
                    <p class="text-muted mt-2 mb-0"><i class="fas fa-envelope mr-1"></i><?php echo e($user->email); ?></p>
                    <?php if($user->foto_profil): ?>
                        <form action="<?php echo e(route('profile.hapus-foto')); ?>" method="POST" class="mt-2"
                            onsubmit="return confirm('Padam gambar profil?')">
                            <?php echo csrf_field(); ?> <?php echo method_field('DELETE'); ?>
                            <button class="btn btn-sm btn-outline-danger">
                                <i class="fas fa-trash mr-1"></i>Padam Foto
                            </button>
                        </form>
                    <?php endif; ?>
                </div>
                <div class="card-footer text-center text-muted small">
                    Ahli sejak <?php echo e($user->created_at->translatedFormat('d F Y')); ?>

                </div>
            </div>

            
            <?php if($user->kod_sekolah || $user->nama_sekolah || $user->daerah): ?>
                <div class="card card-outline card-info">
                    <div class="card-header">
                        <h3 class="card-title"><i class="fas fa-school mr-1"></i> Maklumat Sekolah</h3>
                    </div>
                    <div class="card-body p-0">
                        <table class="table table-sm mb-0">
                            <tr>
                                <td class="text-muted pl-3" width="45%">Kod Sekolah</td>
                                <td><strong><?php echo e($user->kod_sekolah ?? '—'); ?></strong></td>
                            </tr>
                            <tr>
                                <td class="text-muted pl-3">Nama Sekolah</td>
                                <td><strong><?php echo e($user->nama_sekolah ?? '—'); ?></strong></td>
                            </tr>
                            <tr>
                                <td class="text-muted pl-3">Jenis Sekolah</td>
                                <td><strong><?php echo e(is_array($user->jenis_sekolah) ? implode(', ', $user->jenis_sekolah) : $user->jenis_sekolah ?? '—'); ?></strong>
                                </td>
                            </tr>
                            <tr>
                                <td class="text-muted pl-3">Daerah</td>
                                <td><strong><?php echo e($user->daerah ?? '—'); ?></strong></td>
                            </tr>
                        </table>
                    </div>
                </div>
            <?php endif; ?>
        </div>

        
        <div class="col-md-8">
            <div class="card card-outline card-primary">
                <div class="card-header">
                    <h3 class="card-title"><i class="fas fa-edit mr-1"></i> Kemaskini Maklumat</h3>
                </div>
                <form action="<?php echo e(route('profile.update')); ?>" method="POST" enctype="multipart/form-data">
                    <?php echo csrf_field(); ?>
                    <?php echo method_field('PUT'); ?>
                    
                    <input type="file" id="inputFoto" name="foto_profil"
                        accept="image/jpg,image/jpeg,image/png,image/webp" class="d-none">
                    <div class="card-body">
                        <?php if($errors->any()): ?>
                            <div class="alert alert-danger alert-dismissible">
                                <button type="button" class="close" data-dismiss="alert">&times;</button>
                                <ul class="mb-0">
                                    <?php $__currentLoopData = $errors->all(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $error): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <li><?php echo e($error); ?></li>
                                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                </ul>
                            </div>
                        <?php endif; ?>

                        
                        <h6 class="text-primary font-weight-bold border-bottom pb-2 mb-3">
                            <i class="fas fa-id-card mr-1"></i> Maklumat Akaun
                        </h6>

                        <div class="form-group row">
                            <label class="col-md-4 col-form-label">Nama Penuh</label>
                            <div class="col-md-8">
                                <input type="text" name="name"
                                    class="form-control <?php $__errorArgs = ['name'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
                                    value="<?php echo e(old('name', $user->name)); ?>" required>
                                <?php $__errorArgs = ['name'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                    <div class="invalid-feedback"><?php echo e($message); ?></div>
                                <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-md-4 col-form-label">E-mel</label>
                            <div class="col-md-8">
                                <input type="text" class="form-control bg-light" value="<?php echo e($user->email); ?>" disabled>
                                <small class="text-muted">E-mel tidak boleh diubah.</small>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-md-4 col-form-label">Peranan</label>
                            <div class="col-md-8">
                                <input type="text" class="form-control bg-light" value="<?php echo e(strtoupper($user->role)); ?>"
                                    disabled>
                            </div>
                        </div>

                        
                        <?php if($user->kod_sekolah || $user->nama_sekolah || $user->daerah): ?>
                            <h6 class="text-info font-weight-bold border-bottom pb-2 mb-3 mt-4">
                                <i class="fas fa-school mr-1"></i> Maklumat Sekolah
                            </h6>
                            <div class="form-group row">
                                <label class="col-md-4 col-form-label">Kod Sekolah</label>
                                <div class="col-md-8">
                                    <input type="text" class="form-control bg-light"
                                        value="<?php echo e($user->kod_sekolah ?? '—'); ?>" disabled>
                                </div>
                            </div>
                            <div class="form-group row">
                                <label class="col-md-4 col-form-label">Nama Sekolah</label>
                                <div class="col-md-8">
                                    <input type="text" class="form-control bg-light"
                                        value="<?php echo e($user->nama_sekolah ?? '—'); ?>" disabled>
                                </div>
                            </div>
                            <div class="form-group row">
                                <label class="col-md-4 col-form-label">Jenis Sekolah</label>
                                <div class="col-md-8">
                                    <input type="text" class="form-control bg-light"
                                        value="<?php echo e(is_array($user->jenis_sekolah) ? implode(', ', $user->jenis_sekolah) : $user->jenis_sekolah ?? '—'); ?>"
                                        disabled>
                                </div>
                            </div>
                            <div class="form-group row">
                                <label class="col-md-4 col-form-label">Daerah</label>
                                <div class="col-md-8">
                                    <input type="text" class="form-control bg-light"
                                        value="<?php echo e($user->daerah ?? '—'); ?>" disabled>
                                </div>
                            </div>
                        <?php endif; ?>

                        
                        <h6 class="text-warning font-weight-bold border-bottom pb-2 mb-3 mt-4">
                            <i class="fas fa-lock mr-1"></i> Tukar Kata Laluan
                            <small class="text-muted font-weight-normal">(biarkan kosong jika tidak ingin tukar)</small>
                        </h6>

                        <div class="form-group row">
                            <label class="col-md-4 col-form-label">Kata Laluan Baru</label>
                            <div class="col-md-8">
                                <input type="password" name="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]); ?> is-invalid <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>"
                                    placeholder="Minimum 8 aksara" autocomplete="new-password">
                                <?php $__errorArgs = ['password'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                                    <div class="invalid-feedback"><?php echo e($message); ?></div>
                                <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-md-4 col-form-label">Sahkan Kata Laluan</label>
                            <div class="col-md-8">
                                <input type="password" name="password_confirmation" class="form-control"
                                    placeholder="Ulang kata laluan baru" autocomplete="new-password">
                            </div>
                        </div>
                    </div>
                    <div class="card-footer text-right">
                        <button type="submit" class="btn btn-primary">
                            <i class="fas fa-save mr-1"></i> Simpan Perubahan
                        </button>
                    </div>
                </form>
            </div>
        </div>
    </div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('js'); ?>
    <script>
        document.getElementById('inputFoto').addEventListener('change', function(e) {
            const file = e.target.files[0];
            if (!file) return;

            // Semak saiz fail (max 2MB)
            if (file.size > 2 * 1024 * 1024) {
                alert('Saiz fail melebihi 2MB. Sila pilih gambar yang lebih kecil.');
                this.value = '';
                return;
            }

            // Preview gambar sebelum upload
            const reader = new FileReader();
            reader.onload = function(ev) {
                document.getElementById('previewFoto').src = ev.target.result;
            };
            reader.readAsDataURL(file);

            // Auto-submit nota: tidak auto-submit, pengguna klik "Simpan Perubahan"
            // Tunjuk notis
            const notis = document.createElement('div');
            notis.className = 'alert alert-info alert-sm mt-1 mb-0 py-1 px-2';
            notis.style.fontSize = '0.8em';
            notis.innerHTML =
                '<i class="fas fa-info-circle mr-1"></i>Gambar dipilih. Klik <strong>Simpan Perubahan</strong> untuk upload.';
            const sedia = document.querySelector('.alert.alert-info.mt-1');
            if (!sedia) {
                document.getElementById('previewFoto').closest('.card-body').appendChild(notis);
            }
        });
    </script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('adminlte::page', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\laragon\www\myspbt\resources\views/profile/show.blade.php ENDPATH**/ ?>