<?php
/**
 * SMM Paket Satış Scripti - Hesabım
 * @version 1.0.0
 */

require_once __DIR__ . '/config.php';

// Giriş yapmamışsa yönlendir
if (!isLoggedIn()) {
    setFlash('error', 'Bu sayfayı görüntülemek için giriş yapmalısınız.');
    redirect(SITE_URL . '/giris.php');
    exit;
}

// CSRF Token
if (!isset($_SESSION['csrf_token'])) {
    $_SESSION['csrf_token'] = bin2hex(random_bytes(32));
}
$csrfToken = $_SESSION['csrf_token'];

// Kullanıcı bilgilerini çek
try {
    $stmt = $db->prepare("SELECT * FROM users WHERE id = ?");
    $stmt->execute([$_SESSION['user_id']]);
    $user = $stmt->fetch(PDO::FETCH_ASSOC);
    
    if (!$user) {
        session_destroy();
        redirect(SITE_URL . '/giris.php');
        exit;
    }
} catch (PDOException $e) {
    setFlash('error', 'Bir hata oluştu.');
    redirect(SITE_URL);
    exit;
}

// Sipariş istatistikleri
try {
    $stmt = $db->prepare("
        SELECT 
            COUNT(*) as total_orders,
            SUM(CASE WHEN status = 'completed' THEN 1 ELSE 0 END) as completed_orders,
            SUM(CASE WHEN status = 'pending' THEN 1 ELSE 0 END) as pending_orders,
            SUM(CASE WHEN status = 'processing' THEN 1 ELSE 0 END) as processing_orders,
            COALESCE(SUM(CASE WHEN status = 'completed' THEN amount ELSE 0 END), 0) as total_spent
        FROM orders 
        WHERE user_id = ?
    ");
    $stmt->execute([$_SESSION['user_id']]);
    $stats = $stmt->fetch(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
    $stats = [
        'total_orders' => 0,
        'completed_orders' => 0,
        'pending_orders' => 0,
        'processing_orders' => 0,
        'total_spent' => 0
    ];
}

// Son siparişler
try {
    $stmt = $db->prepare("
        SELECT o.*, p.name as package_name, c.name as category_name, c.icon as category_icon
        FROM orders o
        JOIN packages p ON o.package_id = p.id
        JOIN categories c ON p.category_id = c.id
        WHERE o.user_id = ?
        ORDER BY o.created_at DESC
        LIMIT 5
    ");
    $stmt->execute([$_SESSION['user_id']]);
    $recentOrders = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
    $recentOrders = [];
}

// POST işlemleri
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    if (!hash_equals($csrfToken, $_POST['csrf_token'] ?? '')) {
        setFlash('error', 'Güvenlik hatası. Lütfen tekrar deneyin.');
        redirect(SITE_URL . '/hesabim.php');
        exit;
    }
    
    $action = $_POST['action'] ?? '';
    
    // Profil güncelleme
    if ($action === 'update_profile') {
        $fullName = trim($_POST['full_name'] ?? '');
        $phone = trim($_POST['phone'] ?? '');
        
        $errors = [];
        
        if (empty($fullName)) {
            $errors[] = 'Ad Soyad gereklidir.';
        } elseif (mb_strlen($fullName, 'UTF-8') < 3) {
            $errors[] = 'Ad Soyad en az 3 karakter olmalıdır.';
        }
        
        if (!empty($phone)) {
            $cleanPhone = preg_replace('/[^0-9]/', '', $phone);
            if (strlen($cleanPhone) < 10 || strlen($cleanPhone) > 15) {
                $errors[] = 'Geçerli bir telefon numarası girin.';
            }
        }
        
        if (empty($errors)) {
            try {
                $stmt = $db->prepare("UPDATE users SET full_name = ?, phone = ?, updated_at = NOW() WHERE id = ?");
                $stmt->execute([$fullName, $phone ?: null, $_SESSION['user_id']]);
                
                $_SESSION['user_name'] = $fullName;
                
                setFlash('success', 'Profil bilgileriniz güncellendi.');
            } catch (PDOException $e) {
                setFlash('error', 'Güncelleme sırasında bir hata oluştu.');
            }
        } else {
            setFlash('error', implode('<br>', $errors));
        }
        
        redirect(SITE_URL . '/hesabim.php');
        exit;
    }
    
    // Şifre değiştirme
    if ($action === 'change_password') {
        $currentPassword = $_POST['current_password'] ?? '';
        $newPassword = $_POST['new_password'] ?? '';
        $confirmPassword = $_POST['confirm_password'] ?? '';
        
        $errors = [];
        
        if (empty($currentPassword)) {
            $errors[] = 'Mevcut şifre gereklidir.';
        }
        
        if (empty($newPassword)) {
            $errors[] = 'Yeni şifre gereklidir.';
        } elseif (strlen($newPassword) < 6) {
            $errors[] = 'Yeni şifre en az 6 karakter olmalıdır.';
        }
        
        if ($newPassword !== $confirmPassword) {
            $errors[] = 'Yeni şifreler eşleşmiyor.';
        }
        
        if (empty($errors)) {
            if (!password_verify($currentPassword, $user['password'])) {
                setFlash('error', 'Mevcut şifreniz hatalı.');
            } else {
                try {
                    $hashedPassword = password_hash($newPassword, PASSWORD_DEFAULT);
                    $stmt = $db->prepare("UPDATE users SET password = ?, updated_at = NOW() WHERE id = ?");
                    $stmt->execute([$hashedPassword, $_SESSION['user_id']]);
                    
                    setFlash('success', 'Şifreniz başarıyla değiştirildi.');
                } catch (PDOException $e) {
                    setFlash('error', 'Şifre değiştirme sırasında bir hata oluştu.');
                }
            }
        } else {
            setFlash('error', implode('<br>', $errors));
        }
        
        redirect(SITE_URL . '/hesabim.php');
        exit;
    }
}

// Sayfa yenilendikten sonra güncel bilgileri al
try {
    $stmt = $db->prepare("SELECT * FROM users WHERE id = ?");
    $stmt->execute([$_SESSION['user_id']]);
    $user = $stmt->fetch(PDO::FETCH_ASSOC);
} catch (PDOException $e) {}

$pageTitle = 'Hesabım';
require_once __DIR__ . '/header.php';

// Durum badge'leri
function getStatusBadge($status) {
    $badges = [
        'pending' => '<span class="status-badge pending"><i class="fas fa-clock"></i> Beklemede</span>',
        'paid' => '<span class="status-badge paid"><i class="fas fa-check"></i> Ödendi</span>',
        'processing' => '<span class="status-badge processing"><i class="fas fa-spinner"></i> İşleniyor</span>',
        'completed' => '<span class="status-badge completed"><i class="fas fa-check-circle"></i> Tamamlandı</span>',
        'cancelled' => '<span class="status-badge cancelled"><i class="fas fa-times"></i> İptal</span>',
        'refunded' => '<span class="status-badge refunded"><i class="fas fa-undo"></i> İade</span>'
    ];
    return $badges[$status] ?? '<span class="status-badge">' . $status . '</span>';
}
?>

<style>
.account-section {
    padding: 40px 0 80px;
    min-height: calc(100vh - 80px);
}

.account-header {
    background: rgba(30, 41, 59, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 24px;
    padding: 40px;
    margin-bottom: 30px;
    display: flex;
    align-items: center;
    gap: 30px;
    position: relative;
    overflow: hidden;
}

.account-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: var(--gradient);
}

.account-avatar {
    width: 100px;
    height: 100px;
    background: var(--gradient);
    border-radius: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 42px;
    font-weight: 800;
    color: #fff;
    flex-shrink: 0;
    box-shadow: 0 10px 30px rgba(var(--primary-rgb), 0.4);
}

.account-info h1 {
    font-size: 28px;
    font-weight: 800;
    margin-bottom: 8px;
    color: #fff;
}

.account-info p {
    color: rgba(255, 255, 255, 0.6);
    font-size: 15px;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 8px;
}

.account-info p i {
    color: var(--primary);
}

.account-meta {
    margin-top: 15px;
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

.account-meta span {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.5);
    display: flex;
    align-items: center;
    gap: 6px;
}

.account-meta span i {
    color: var(--primary);
    font-size: 12px;
}

/* Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: rgba(30, 41, 59, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 20px;
    padding: 25px;
    text-align: center;
    transition: all 0.3s;
}

.stat-card:hover {
    transform: translateY(-5px);
    border-color: rgba(var(--primary-rgb), 0.3);
}

.stat-icon {
    width: 55px;
    height: 55px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    margin: 0 auto 15px;
}

.stat-icon.primary {
    background: rgba(var(--primary-rgb), 0.15);
    color: var(--primary);
}

.stat-icon.success {
    background: rgba(16, 185, 129, 0.15);
    color: #10b981;
}

.stat-icon.warning {
    background: rgba(245, 158, 11, 0.15);
    color: #f59e0b;
}

.stat-icon.info {
    background: rgba(59, 130, 246, 0.15);
    color: #3b82f6;
}

.stat-value {
    font-size: 32px;
    font-weight: 800;
    color: #fff;
    margin-bottom: 5px;
}

.stat-label {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.5);
}

/* Content Grid */
.account-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
}

.account-card {
    background: rgba(30, 41, 59, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 20px;
    overflow: hidden;
}

.account-card.full-width {
    grid-column: 1 / -1;
}

.card-header {
    padding: 25px 30px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-header h3 {
    font-size: 18px;
    font-weight: 700;
    margin: 0;
    display: flex;
    align-items: center;
    gap: 12px;
    color: #fff;
}

.card-header h3 i {
    color: var(--primary);
}

.card-header a {
    font-size: 14px;
    color: var(--primary);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 6px;
}

.card-header a:hover {
    color: var(--secondary);
}

.card-body {
    padding: 30px;
}

/* Form Styles */
.form-group {
    margin-bottom: 22px;
}

.form-label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.9);
    margin-bottom: 10px;
}

.form-label i {
    margin-right: 8px;
    color: var(--primary);
}

.form-control {
    width: 100%;
    padding: 14px 18px;
    background: rgba(15, 23, 42, 0.6);
    border: 2px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    color: #fff;
    font-size: 15px;
    transition: all 0.3s ease;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    background: rgba(15, 23, 42, 0.8);
    box-shadow: 0 0 0 4px rgba(var(--primary-rgb), 0.15);
}

.form-control:disabled {
    background: rgba(15, 23, 42, 0.3);
    color: rgba(255, 255, 255, 0.5);
    cursor: not-allowed;
}

.form-control::placeholder {
    color: rgba(255, 255, 255, 0.35);
}

.input-wrapper {
    position: relative;
}

.input-wrapper .toggle-password {
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.4);
    cursor: pointer;
    padding: 5px;
    font-size: 16px;
}

.input-wrapper .toggle-password:hover {
    color: var(--primary);
}

.btn-save {
    background: var(--gradient);
    border: none;
    color: #fff;
    padding: 14px 30px;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    transition: all 0.3s;
    box-shadow: 0 8px 25px rgba(var(--primary-rgb), 0.3);
}

.btn-save:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 35px rgba(var(--primary-rgb), 0.4);
}

/* Orders Table */
.orders-table {
    width: 100%;
}

.order-item {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 20px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.order-item:last-child {
    border-bottom: none;
}

.order-icon {
    width: 50px;
    height: 50px;
    background: rgba(var(--primary-rgb), 0.15);
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    color: var(--primary);
    flex-shrink: 0;
}

.order-details {
    flex: 1;
    min-width: 0;
}

.order-details h4 {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 4px;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.order-details p {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.5);
    margin: 0;
}

.order-right {
    text-align: right;
    flex-shrink: 0;
}

.order-amount {
    font-size: 16px;
    font-weight: 700;
    color: #10b981;
    margin-bottom: 4px;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
}

.status-badge.pending {
    background: rgba(245, 158, 11, 0.15);
    color: #f59e0b;
}

.status-badge.paid {
    background: rgba(59, 130, 246, 0.15);
    color: #3b82f6;
}

.status-badge.processing {
    background: rgba(139, 92, 246, 0.15);
    color: #8b5cf6;
}

.status-badge.completed {
    background: rgba(16, 185, 129, 0.15);
    color: #10b981;
}

.status-badge.cancelled {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
}

.status-badge.refunded {
    background: rgba(107, 114, 128, 0.15);
    color: #6b7280;
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
}

.empty-state i {
    font-size: 50px;
    color: rgba(255, 255, 255, 0.1);
    margin-bottom: 15px;
}

.empty-state h4 {
    font-size: 16px;
    color: rgba(255, 255, 255, 0.6);
    margin-bottom: 8px;
}

.empty-state p {
    font-size: 14px;
    color: rgba(255, 255, 255, 0.4);
    margin-bottom: 20px;
}

.empty-state a {
    color: var(--primary);
    font-weight: 600;
}

/* Responsive */
@media (max-width: 991px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .account-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .account-header {
        flex-direction: column;
        text-align: center;
        padding: 30px 20px;
    }
    
    .account-meta {
        justify-content: center;
    }
    
    .account-info h1 {
        font-size: 24px;
    }
}

@media (max-width: 576px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .stat-card {
        padding: 20px;
    }
    
    .stat-value {
        font-size: 28px;
    }
    
    .card-body {
        padding: 20px;
    }
    
    .order-item {
        flex-wrap: wrap;
    }
    
    .order-right {
        width: 100%;
        text-align: left;
        margin-top: 10px;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
}
</style>

<section class="account-section">
    <div class="container">
        <!-- Header -->
        <div class="account-header" data-aos="fade-up">
            <div class="account-avatar">
                <?php echo strtoupper(mb_substr($user['full_name'] ?: $user['username'], 0, 1, 'UTF-8')); ?>
            </div>
            <div class="account-info">
                <h1><?php echo clean($user['full_name'] ?: $user['username']); ?></h1>
                <p><i class="fas fa-envelope"></i> <?php echo clean($user['email']); ?></p>
                <div class="account-meta">
                    <span><i class="fas fa-user"></i> @<?php echo clean($user['username']); ?></span>
                    <span><i class="fas fa-calendar"></i> Üyelik: <?php echo date('d.m.Y', strtotime($user['created_at'])); ?></span>
                    <?php if ($user['phone']): ?>
                    <span><i class="fas fa-phone"></i> <?php echo clean($user['phone']); ?></span>
                    <?php endif; ?>
                </div>
            </div>
        </div>
        
        <!-- Stats -->
        <div class="stats-grid" data-aos="fade-up" data-aos-delay="100">
            <div class="stat-card">
                <div class="stat-icon primary">
                    <i class="fas fa-shopping-cart"></i>
                </div>
                <div class="stat-value"><?php echo (int)$stats['total_orders']; ?></div>
                <div class="stat-label">Toplam Sipariş</div>
            </div>
            <div class="stat-card">
                <div class="stat-icon success">
                    <i class="fas fa-check-circle"></i>
                </div>
                <div class="stat-value"><?php echo (int)$stats['completed_orders']; ?></div>
                <div class="stat-label">Tamamlanan</div>
            </div>
            <div class="stat-card">
                <div class="stat-icon warning">
                    <i class="fas fa-clock"></i>
                </div>
                <div class="stat-value"><?php echo (int)$stats['pending_orders'] + (int)$stats['processing_orders']; ?></div>
                <div class="stat-label">Devam Eden</div>
            </div>
            <div class="stat-card">
                <div class="stat-icon info">
                    <i class="fas fa-wallet"></i>
                </div>
                <div class="stat-value"><?php echo number_format($stats['total_spent'], 0, ',', '.'); ?>₺</div>
                <div class="stat-label">Toplam Harcama</div>
            </div>
        </div>
        
        <!-- Content Grid -->
        <div class="account-grid">
            <!-- Profil Bilgileri -->
            <div class="account-card" data-aos="fade-up" data-aos-delay="200">
                <div class="card-header">
                    <h3><i class="fas fa-user-edit"></i> Profil Bilgileri</h3>
                </div>
                <div class="card-body">
                    <form method="POST" action="">
                        <input type="hidden" name="csrf_token" value="<?php echo $csrfToken; ?>">
                        <input type="hidden" name="action" value="update_profile">
                        
                        <div class="form-group">
                            <label class="form-label">
                                <i class="fas fa-user"></i> Ad Soyad
                            </label>
                            <input type="text" name="full_name" class="form-control" 
                                   value="<?php echo clean($user['full_name']); ?>" required>
                        </div>
                        
                        <div class="form-group">
                            <label class="form-label">
                                <i class="fas fa-at"></i> Kullanıcı Adı
                            </label>
                            <input type="text" class="form-control" 
                                   value="<?php echo clean($user['username']); ?>" disabled>
                        </div>
                        
                        <div class="form-group">
                            <label class="form-label">
                                <i class="fas fa-envelope"></i> E-posta
                            </label>
                            <input type="email" class="form-control" 
                                   value="<?php echo clean($user['email']); ?>" disabled>
                        </div>
                        
                        <div class="form-group">
                            <label class="form-label">
                                <i class="fas fa-phone"></i> Telefon
                            </label>
                            <input type="tel" name="phone" class="form-control" 
                                   placeholder="05XX XXX XX XX"
                                   value="<?php echo clean($user['phone']); ?>">
                        </div>
                        
                        <button type="submit" class="btn-save">
                            <i class="fas fa-save"></i> Kaydet
                        </button>
                    </form>
                </div>
            </div>
            
            <!-- Şifre Değiştir -->
            <div class="account-card" data-aos="fade-up" data-aos-delay="300">
                <div class="card-header">
                    <h3><i class="fas fa-lock"></i> Şifre Değiştir</h3>
                </div>
                <div class="card-body">
                    <form method="POST" action="" id="passwordForm">
                        <input type="hidden" name="csrf_token" value="<?php echo $csrfToken; ?>">
                        <input type="hidden" name="action" value="change_password">
                        
                        <div class="form-group">
                            <label class="form-label">
                                <i class="fas fa-key"></i> Mevcut Şifre
                            </label>
                            <div class="input-wrapper">
                                <input type="password" name="current_password" id="current_password" 
                                       class="form-control" placeholder="••••••••" required>
                                <button type="button" class="toggle-password" onclick="togglePassword('current_password', this)">
                                    <i class="fas fa-eye"></i>
                                </button>
                            </div>
                        </div>
                        
                        <div class="form-group">
                            <label class="form-label">
                                <i class="fas fa-lock"></i> Yeni Şifre
                            </label>
                            <div class="input-wrapper">
                                <input type="password" name="new_password" id="new_password" 
                                       class="form-control" placeholder="••••••••" required minlength="6">
                                <button type="button" class="toggle-password" onclick="togglePassword('new_password', this)">
                                    <i class="fas fa-eye"></i>
                                </button>
                            </div>
                        </div>
                        
                        <div class="form-group">
                            <label class="form-label">
                                <i class="fas fa-lock"></i> Yeni Şifre Tekrar
                            </label>
                            <div class="input-wrapper">
                                <input type="password" name="confirm_password" id="confirm_password" 
                                       class="form-control" placeholder="••••••••" required minlength="6">
                                <button type="button" class="toggle-password" onclick="togglePassword('confirm_password', this)">
                                    <i class="fas fa-eye"></i>
                                </button>
                            </div>
                        </div>
                        
                        <button type="submit" class="btn-save">
                            <i class="fas fa-key"></i> Şifreyi Değiştir
                        </button>
                    </form>
                </div>
            </div>
            
            <!-- Son Siparişler -->
            <div class="account-card full-width" data-aos="fade-up" data-aos-delay="400">
                <div class="card-header">
                    <h3><i class="fas fa-shopping-bag"></i> Son Siparişler</h3>
                    <a href="<?php echo SITE_URL; ?>/siparislerim.php">
                        Tümünü Gör <i class="fas fa-arrow-right"></i>
                    </a>
                </div>
                <div class="card-body">
                    <?php if (empty($recentOrders)): ?>
                    <div class="empty-state">
                        <i class="fas fa-shopping-cart"></i>
                        <h4>Henüz siparişiniz yok</h4>
                        <p>İlk siparişinizi vermek için paketlerimize göz atın.</p>
                        <a href="<?php echo SITE_URL; ?>/#packages">Paketleri İncele</a>
                    </div>
                    <?php else: ?>
                    <div class="orders-table">
                        <?php foreach ($recentOrders as $order): ?>
                        <div class="order-item">
                            <div class="order-icon">
                                <i class="<?php echo $order['category_icon']; ?>"></i>
                            </div>
                            <div class="order-details">
                                <h4><?php echo clean($order['package_name']); ?></h4>
                                <p>#<?php echo clean($order['order_number']); ?> • <?php echo date('d.m.Y H:i', strtotime($order['created_at'])); ?></p>
                            </div>
                            <div class="order-right">
                                <div class="order-amount"><?php echo number_format($order['amount'], 2, ',', '.'); ?>₺</div>
                                <?php echo getStatusBadge($order['status']); ?>
                            </div>
                        </div>
                        <?php endforeach; ?>
                    </div>
                    <?php endif; ?>
                </div>
            </div>
        </div>
    </div>
</section>

<script>
// Şifre göster/gizle
function togglePassword(inputId, button) {
    var input = document.getElementById(inputId);
    var icon = button.querySelector('i');
    
    if (input.type === 'password') {
        input.type = 'text';
        icon.classList.remove('fa-eye');
        icon.classList.add('fa-eye-slash');
    } else {
        input.type = 'password';
        icon.classList.remove('fa-eye-slash');
        icon.classList.add('fa-eye');
    }
}

// Şifre eşleşme kontrolü
document.getElementById('confirm_password').addEventListener('input', function() {
    var newPassword = document.getElementById('new_password').value;
    var confirmPassword = this.value;
    
    if (confirmPassword.length > 0 && newPassword !== confirmPassword) {
        this.style.borderColor = '#ef4444';
    } else if (confirmPassword.length > 0 && newPassword === confirmPassword) {
        this.style.borderColor = '#10b981';
    } else {
        this.style.borderColor = '';
    }
});

// Form submit kontrolü
document.getElementById('passwordForm').addEventListener('submit', function(e) {
    var newPassword = document.getElementById('new_password').value;
    var confirmPassword = document.getElementById('confirm_password').value;
    
    if (newPassword !== confirmPassword) {
        e.preventDefault();
        alert('Yeni şifreler eşleşmiyor!');
        return false;
    }
});
</script>

<?php require_once __DIR__ . '/footer.php'; ?>