

<?php $__env->startSection('styles'); ?>
<link rel="stylesheet" href="<?php echo e(asset('css/profil.css')); ?>">
<?php $__env->stopSection(); ?>

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

<div class="profil-container">

    
    <div class="breadcrumb">
        <a href="javascript:history.back()">Dashboard</a>
        <span>›</span>
        <span>Profil Saya</span>
    </div>

    <div class="profil-grid">

        
        <div class="profil-sidebar">

            <div class="avatar-card">

                <div class="avatar-wrapper">
                    <img
                        id="avatarPreview"
                        src="<?php echo e(auth()->user()->photo
                            ? asset('storage/'.auth()->user()->photo)
                            : 'https://ui-avatars.com/api/?name='.urlencode(auth()->user()->name).'&background=2e7d32&color=fff&size=200'); ?>"
                        alt="Foto Profil"
                        class="avatar-img"
                    >
                    <label for="photoInput" class="avatar-edit-btn" title="Ganti foto">
                        📷
                    </label>
                </div>

                <h3 class="avatar-name"><?php echo e(auth()->user()->name); ?></h3>

                <span class="avatar-role role-<?php echo e(auth()->user()->role); ?>">
                    <?php if(auth()->user()->role == 'admin'): ?> ⚙ Admin
                    <?php elseif(auth()->user()->role == 'penyuluh'): ?> 📋 Penyuluh
                    <?php else: ?> 🌾 Petani
                    <?php endif; ?>
                </span>

                <div class="avatar-info">
                    <div class="ai-row">
                        <span class="ai-icon">📧</span>
                        <span class="ai-val"><?php echo e(auth()->user()->email); ?></span>
                    </div>
                    <div class="ai-row">
                        <span class="ai-icon">📅</span>
                        <span class="ai-val">Bergabung <?php echo e(auth()->user()->created_at->format('M Y')); ?></span>
                    </div>
                </div>

            </div>

        </div>

        
        <div class="profil-main">

            
            <?php if(session('success')): ?>
            <div class="alert alert-success">
                ✅ <?php echo e(session('success')); ?>

            </div>
            <?php endif; ?>

            
            <?php if($errors->any()): ?>
            <div class="alert alert-danger">
                <strong>⚠ Ada kesalahan:</strong>
                <ul>
                    <?php $__currentLoopData = $errors->all(); $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $err): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                        <li><?php echo e($err); ?></li>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                </ul>
            </div>
            <?php endif; ?>

            
            <div class="form-card">

                <div class="form-card-title">
                    <span>👤</span> Edit Informasi Akun
                </div>

                <form action="<?php echo e(url('/profil/update')); ?>" method="POST" enctype="multipart/form-data" id="profilForm">
                    <?php echo csrf_field(); ?>

                    
                    <input
                        type="file"
                        id="photoInput"
                        name="photo"
                        accept="image/*"
                        style="display:none"
                        onchange="previewPhoto(this)"
                    >

                    <div class="form-group">
                        <label for="name">Nama Lengkap</label>
                        <input
                            type="text"
                            id="name"
                            name="name"
                            value="<?php echo e(old('name', auth()->user()->name)); ?>"
                            placeholder="Masukkan nama lengkap"
                            required
                            autocomplete="name"
                            class="<?php echo e($errors->has('name') ? 'is-error' : ''); ?>"
                        >
                        <?php $__errorArgs = ['name'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                            <span class="field-error"><?php echo e($message); ?></span>
                        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                    </div>

                    <div class="form-group">
                        <label for="email">Alamat Email</label>
                        <input
                            type="email"
                            id="email"
                            name="email"
                            value="<?php echo e(old('email', auth()->user()->email)); ?>"
                            placeholder="contoh@email.com"
                            required
                            autocomplete="email"
                            class="<?php echo e($errors->has('email') ? 'is-error' : ''); ?>"
                        >
                        <?php $__errorArgs = ['email'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                            <span class="field-error"><?php echo e($message); ?></span>
                        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                    </div>

                    <div class="form-group">
                        <label for="no_hp">Nomor HP <span class="optional">(opsional)</span></label>
                        <input
                            type="text"
                            id="no_hp"
                            name="no_hp"
                            value="<?php echo e(old('no_hp', auth()->user()->no_hp ?? '')); ?>"
                            placeholder="08xxxxxxxxxx"
                            autocomplete="tel"
                        >
                    </div>

                    <div class="form-group">
                        <label for="alamat">Alamat <span class="optional">(opsional)</span></label>
                        <textarea
                            id="alamat"
                            name="alamat"
                            placeholder="Desa, Kecamatan, Kabupaten..."
                            rows="3"
                        ><?php echo e(old('alamat', auth()->user()->alamat ?? '')); ?></textarea>
                    </div>

                    <button type="submit" class="btn-submit">
                        💾 Simpan Perubahan
                    </button>

                </form>

            </div>

            
            <div class="form-card">

                <div class="form-card-title">
                    <span>🔑</span> Ganti Password
                </div>

                <form action="<?php echo e(url('/profil/password')); ?>" method="POST">
                    <?php echo csrf_field(); ?>

                    <div class="form-group">
                        <label for="current_password">Password Saat Ini</label>
                        <div class="input-password">
                            <input
                                type="password"
                                id="current_password"
                                name="current_password"
                                placeholder="Masukkan password lama"
                                autocomplete="current-password"
                                class="<?php echo e($errors->has('current_password') ? 'is-error' : ''); ?>"
                            >
                            <button type="button" class="toggle-pw" onclick="togglePw('current_password', this)">👁</button>
                        </div>
                        <?php $__errorArgs = ['current_password'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                            <span class="field-error"><?php echo e($message); ?></span>
                        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                    </div>

                    <div class="form-group">
                        <label for="new_password">Password Baru</label>
                        <div class="input-password">
                            <input
                                type="password"
                                id="new_password"
                                name="password"
                                placeholder="Minimal 8 karakter"
                                autocomplete="new-password"
                                class="<?php echo e($errors->has('password') ? 'is-error' : ''); ?>"
                            >
                            <button type="button" class="toggle-pw" onclick="togglePw('new_password', this)">👁</button>
                        </div>
                        <?php $__errorArgs = ['password'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                            <span class="field-error"><?php echo e($message); ?></span>
                        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                    </div>

                    <div class="form-group">
                        <label for="password_confirmation">Konfirmasi Password Baru</label>
                        <div class="input-password">
                            <input
                                type="password"
                                id="password_confirmation"
                                name="password_confirmation"
                                placeholder="Ulangi password baru"
                                autocomplete="new-password"
                            >
                            <button type="button" class="toggle-pw" onclick="togglePw('password_confirmation', this)">👁</button>
                        </div>
                    </div>

                    <button type="submit" class="btn-submit secondary">
                        🔒 Update Password
                    </button>

                </form>

            </div>

        </div>

    </div>

</div>

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

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

// Preview foto sebelum upload
function previewPhoto(input) {
    if (input.files && input.files[0]) {
        const reader = new FileReader();
        reader.onload = e => {
            document.getElementById('avatarPreview').src = e.target.result;
        };
        reader.readAsDataURL(input.files[0]);
    }
}

// Toggle show/hide password
function togglePw(id, btn) {
    const input = document.getElementById(id);
    if (input.type === 'password') {
        input.type = 'text';
        btn.textContent = '🙈';
    } else {
        input.type = 'password';
        btn.textContent = '👁';
    }
}

</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\Users\Maylha\pelaporanpertanian\resources\views/profil.blade.php ENDPATH**/ ?>