<!DOCTYPE html>
<html lang="tr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Profil - iAccess Terminal Yönetimi</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
    <style>
        :root {
            --primary-color: #667eea;
            --secondary-color: #764ba2;
            --success-color: #28a745;
            --warning-color: #ffc107;
            --danger-color: #dc3545;
            --info-color: #17a2b8;
            --dark-color: #343a40;
            --light-color: #f8f9fa;
        }
        
        body {
            background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
            min-height: 100vh;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }
        
        .main-container {
            padding: 2rem 0;
        }
        
        .card {
            border: none;
            border-radius: 15px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
            backdrop-filter: blur(10px);
            background: rgba(255, 255, 255, 0.95);
        }
        
        .card-header-modern {
            background: linear-gradient(135deg, var(--primary-color), #357abd);
            color: white;
            border-radius: 15px 15px 0 0 !important;
            padding: 1.5rem;
            border: none;
        }
        
        .page-title {
            margin: 0;
            font-size: 2rem;
            font-weight: 700;
            text-shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
        }
        
        .btn-modern {
            border-radius: 10px;
            padding: 0.75rem 1.5rem;
            font-weight: 600;
            transition: all 0.3s ease;
            border: none;
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
        }
        
        .btn-back {
            background: linear-gradient(135deg, #6c757d, #5a6268);
            color: white;
        }
        
        .btn-back:hover {
            background: linear-gradient(135deg, #5a6268, #495057);
            color: white;
            transform: translateY(-2px);
            box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);
        }
        
        .profile-section {
            padding: 2rem;
        }
        
        .profile-avatar {
            width: 120px;
            height: 120px;
            border-radius: 50%;
            object-fit: cover;
            border: 4px solid var(--primary-color);
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
        }
        
        .form-control-modern {
            border-radius: 10px;
            border: 2px solid #e9ecef;
            padding: 0.75rem 1rem;
            transition: all 0.3s ease;
        }
        
        .form-control-modern:focus {
            border-color: var(--primary-color);
            box-shadow: 0 0 0 0.2rem rgba(102, 126, 234, 0.25);
        }
        
        .danger-zone {
            background: linear-gradient(135deg, #ff6b6b, #ee5a52);
            color: white;
            border-radius: 15px;
            padding: 2rem;
            margin-top: 2rem;
        }
        
        .danger-zone h4 {
            color: white;
            margin-bottom: 1rem;
        }
        
        .btn-danger-modern {
            background: linear-gradient(135deg, #dc3545, #c82333);
            color: white;
            border: none;
            border-radius: 10px;
            padding: 0.75rem 1.5rem;
            font-weight: 600;
            transition: all 0.3s ease;
        }
        
        .btn-danger-modern:hover {
            background: linear-gradient(135deg, #c82333, #bd2130);
            color: white;
            transform: translateY(-2px);
            box-shadow: 0 6px 20px rgba(220, 53, 69, 0.3);
        }
        
        .alert-modern {
            border-radius: 10px;
            border: none;
            padding: 1rem 1.5rem;
        }
    </style>
</head>
<body>
    <div class="main-container">
        <div class="container">
            <div class="card">
                <div class="card-header-modern">
                    <div class="d-flex justify-content-between align-items-center">
                        <h1 class="page-title">
                            <i class="fas fa-user-circle me-3"></i>{{ translations[current_language]['profile'] }}
                        </h1>
                        <a href="{{ url_for('home') }}" class="btn btn-modern btn-back">
                            <i class="fas fa-arrow-left me-2"></i>{{ translations[current_language]['home'] }}
                        </a>
                    </div>
                </div>

                <div class="profile-section">
                    {% with messages = get_flashed_messages(with_categories=true) %}
                        {% if messages %}
                            {% for category, message in messages %}
                                <div class="alert alert-{{ 'danger' if category == 'error' else category }} alert-modern alert-dismissible fade show" role="alert">
                                    <i class="fas fa-{{ 'exclamation-triangle' if category == 'error' else 'check-circle' }} me-2"></i>
                                    {{ message }}
                                    <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
                                </div>
                            {% endfor %}
                        {% endif %}
                    {% endwith %}

                    <form method="POST" enctype="multipart/form-data">
                        <div class="row">
                            <div class="col-md-4 text-center mb-4">
                                <div class="mb-3">
                                    {% if user and user.profile_image %}
                                        <img src="{{ url_for('static', filename='uploads/' + user.profile_image) }}" 
                                             alt="Profil Resmi" class="profile-avatar" id="profilePreview">
                                    {% else %}
                                        <img src="{{ url_for('static', filename='img/default-avatar.png') }}" 
                                             alt="Profil Resmi" class="profile-avatar" id="profilePreview">
                                    {% endif %}
                                </div>
                                <div class="mb-3">
                                    <label for="profile_image" class="btn btn-outline-primary btn-modern me-2">
                                        <i class="fas fa-camera me-2"></i>{{ translations[current_language]['change_profile_image'] }}
                                    </label>
                                    <input type="file" id="profile_image" name="profile_image" 
                                           accept="image/*" style="display: none;" onchange="previewImage(this)">
                                    {% if user and user.profile_image %}
                                    <button type="button" class="btn btn-outline-danger btn-modern" onclick="removeProfileImage()">
                                        <i class="fas fa-trash me-2"></i>{{ translations[current_language]['remove_profile_image'] }}
                                    </button>
                                    {% endif %}
                                </div>
                            </div>
                            
                            <div class="col-md-8">
                                <div class="row">
                                    <div class="col-md-6 mb-3">
                                        <label for="full_name" class="form-label fw-bold">{{ translations[current_language]['full_name'] }}</label>
                                        <input type="text" class="form-control form-control-modern" 
                                               id="full_name" name="full_name" 
                                               value="{{ user.full_name }}" required>
                                    </div>
                                    <div class="col-md-6 mb-3">
                                        <label for="email" class="form-label fw-bold">{{ translations[current_language]['email'] }}</label>
                                        <input type="email" class="form-control form-control-modern" 
                                               id="email" name="email" 
                                               value="{{ user.email }}" required>
                                    </div>
                                </div>
                                
                                <div class="row">
                                    <div class="col-md-4 mb-3">
                                        <label for="company" class="form-label fw-bold">{{ translations[current_language]['company'] }}</label>
                                        <input type="text" class="form-control form-control-modern" 
                                               id="company" name="company" 
                                               value="{{ user.company or '' }}">
                                    </div>
                                    <div class="col-md-4 mb-3">
                                        <label for="phone" class="form-label fw-bold">{{ translations[current_language]['phone'] }}</label>
                                        <input type="tel" class="form-control form-control-modern" 
                                               id="phone" name="phone" 
                                               value="{{ user.phone or '' }}">
                                    </div>
                                    <div class="col-md-4 mb-3">
                                        <label for="language" class="form-label fw-bold">{{ translations[current_language]['language'] }}</label>
                                        <select class="form-control form-control-modern" id="language" name="language">
                                            <option value="tr" {{ 'selected' if current_language == 'tr' else '' }}>{{ translations[current_language]['turkish'] }}</option>
                                            <option value="en" {{ 'selected' if current_language == 'en' else '' }}>{{ translations[current_language]['english'] }}</option>
                                        </select>
                                    </div>
                                </div>

                                <div class="row">
                                    <div class="col-md-6 mb-3">
                                        <label for="timezone" class="form-label fw-bold">
                                            <i class="fas fa-clock me-1"></i>{{ translations[current_language]['timezone'] }}
                                        </label>
                                        <select class="form-control form-control-modern" id="timezone" name="timezone">
                                            <option value="Europe/Istanbul" {{ 'selected' if user.timezone == 'Europe/Istanbul' or not user.timezone else '' }}>
                                                🇹🇷 {{ translations[current_language]['turkey'] }} (GMT+3)
                                            </option>
                                            <option value="UTC" {{ 'selected' if user.timezone == 'UTC' else '' }}>
                                                🌍 UTC (GMT+0)
                                            </option>
                                            <option value="Europe/London" {{ 'selected' if user.timezone == 'Europe/London' else '' }}>
                                                🇬🇧 {{ translations[current_language]['london'] }} (GMT+0/+1)
                                            </option>
                                            <option value="Europe/Berlin" {{ 'selected' if user.timezone == 'Europe/Berlin' else '' }}>
                                                🇩🇪 {{ translations[current_language]['berlin'] }} (GMT+1/+2)
                                            </option>
                                            <option value="America/New_York" {{ 'selected' if user.timezone == 'America/New_York' else '' }}>
                                                🇺🇸 {{ translations[current_language]['new_york'] }} (GMT-5/-4)
                                            </option>
                                        </select>
                                        <small class="text-muted">{{ translations[current_language]['timezone_help'] }}</small>
                                    </div>
                                    <div class="col-md-6 mb-3">
                                        <label for="user_uuid" class="form-label fw-bold">{{ translations[current_language]['user_uuid'] }}</label>
                                        <div class="input-group">
                                            <input type="text" class="form-control form-control-modern" 
                                                   id="user_uuid" name="user_uuid" 
                                                   value="{{ user.user_uuid or translations[current_language]['uuid_not_created'] }}" 
                                                   readonly>
                                            <button type="button" class="btn btn-outline-secondary" onclick="copyUUID()">
                                                <i class="fas fa-copy"></i>
                                            </button>
                                        </div>
                                        <small class="text-muted">{{ translations[current_language]['uuid_help'] }}</small>
                                    </div>
                                </div>

                                

                                <hr class="my-4">
                                
                                <h5 class="mb-3"><i class="fas fa-lock me-2"></i>{{ translations[current_language]['change_password'] }}</h5>
                                <div class="row">
                                    <div class="col-md-4 mb-3">
                                        <label for="current_password" class="form-label fw-bold">{{ translations[current_language]['current_password'] }}</label>
                                        <input type="password" class="form-control form-control-modern" 
                                               id="current_password" name="current_password">
                                    </div>
                                    <div class="col-md-4 mb-3">
                                        <label for="new_password" class="form-label fw-bold">{{ translations[current_language]['new_password'] }}</label>
                                        <input type="password" class="form-control form-control-modern" 
                                               id="new_password" name="new_password">
                                    </div>
                                    <div class="col-md-4 mb-3">
                                        <label for="confirm_password" class="form-label fw-bold">{{ translations[current_language]['confirm_password'] }}</label>
                                        <input type="password" class="form-control form-control-modern" 
                                               id="confirm_password" name="confirm_password">
                                    </div>
                                </div>
                                
                                <div class="text-end">
                                    <button type="submit" class="btn btn-modern btn-primary">
                                        <i class="fas fa-save me-2"></i>{{ translations[current_language]['save_changes'] }}
                                    </button>
                                </div>
                            </div>
                        </div>
                    </form>
                    
                    
                    
                    <!-- Tehlikeli Bölge -->
                                            <div class="danger-zone">
                            <h4><i class="fas fa-exclamation-triangle me-2"></i>{{ translations[current_language]['danger_zone'] }}</h4>
                            <p class="mb-3">{{ translations[current_language]['danger_zone_warning'] }}</p>
                            <button type="button" class="btn btn-danger-modern" data-bs-toggle="modal" data-bs-target="#deleteAccountModal">
                                <i class="fas fa-trash me-2"></i>{{ translations[current_language]['delete_account'] }}
                            </button>
                        </div>
                </div>
            </div>
        </div>
    </div>
    
    <!-- Hesap Silme Modal -->
    <div class="modal fade" id="deleteAccountModal" tabindex="-1" aria-labelledby="deleteAccountModalLabel" aria-hidden="true">
        <div class="modal-dialog modal-dialog-centered">
            <div class="modal-content">
                                    <div class="modal-header bg-danger text-white">
                        <h5 class="modal-title" id="deleteAccountModalLabel">
                            <i class="fas fa-exclamation-triangle me-2"></i>{{ translations[current_language]['delete_account'] }}
                        </h5>
                        <button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
                    </div>
                    <div class="modal-body">
                        <p class="text-danger fw-bold">{{ translations[current_language]['delete_account_warning'] }}</p>
                        <p>{{ translations[current_language]['delete_account_effects'] }}</p>
                        <ul>
                            <li>{{ translations[current_language]['delete_account_effect_1'] }}</li>
                            <li>{{ translations[current_language]['delete_account_effect_2'] }}</li>
                            <li>{{ translations[current_language]['delete_account_effect_3'] }}</li>
                            <li>{{ translations[current_language]['delete_account_effect_4'] }}</li>
                            <li>{{ translations[current_language]['delete_account_effect_5'] }}</li>
                        </ul>
                        <p class="text-danger">{{ translations[current_language]['delete_account_confirmation'] }}</p>
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">{{ translations[current_language]['cancel'] }}</button>
                        <button type="button" class="btn btn-danger" onclick="deleteAccount()">
                            <i class="fas fa-trash me-2"></i>{{ translations[current_language]['delete_account'] }}
                        </button>
                    </div>
            </div>
        </div>
    </div>

    <!-- Bootstrap JS -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
    
    <script>
        function previewImage(input) {
            if (input.files && input.files[0]) {
                var reader = new FileReader();
                reader.onload = function(e) {
                    document.getElementById('profilePreview').src = e.target.result;
                };
                reader.readAsDataURL(input.files[0]);
            }
        }
        
        // Dil değişikliği
        document.getElementById('language').addEventListener('change', function() {
            var selectedLang = this.value;
            // Sayfayı yenile
            window.location.href = '/set-lang/' + selectedLang + '?redirect=' + encodeURIComponent(window.location.pathname);
        });
        
        // Auto-hide alerts after 5 seconds
        setTimeout(function() {
            const alerts = document.querySelectorAll('.alert');
            alerts.forEach(function(alert) {
                const bsAlert = new bootstrap.Alert(alert);
                bsAlert.close();
            });
        }, 5000);
        
        // UUID kopyalama fonksiyonu
        function copyUUID() {
            const uuidInput = document.getElementById('user_uuid');
            uuidInput.select();
            uuidInput.setSelectionRange(0, 99999); // Mobile için
            document.execCommand('copy');
            
            // Kopyalandı bildirimi
            const button = event.target.closest('button');
            const originalText = button.innerHTML;
            button.innerHTML = '<i class="fas fa-check"></i>';
            button.classList.remove('btn-outline-secondary');
            button.classList.add('btn-success');
            
            setTimeout(function() {
                button.innerHTML = originalText;
                button.classList.remove('btn-success');
                button.classList.add('btn-outline-secondary');
            }, 2000);
        }
        
        function deleteAccount() {
            if (confirm('{{ translations[current_language]["delete_account_confirmation"] }}')) {
                // Form oluştur ve POST isteği gönder
                const form = document.createElement('form');
                form.method = 'POST';
                form.action = '{{ url_for("delete_account") }}';
                document.body.appendChild(form);
                form.submit();
            }
        }
        
        function removeProfileImage() {
            if (confirm('{{ translations[current_language]["remove_profile_image_confirm"] }}')) {
                // Form oluştur ve POST isteği gönder
                const form = document.createElement('form');
                form.method = 'POST';
                form.action = '{{ url_for("remove_profile_image") }}';
                document.body.appendChild(form);
                form.submit();
            }
        }
        
        // Alert'leri otomatik gizle
        setTimeout(function() {
            const alerts = document.querySelectorAll('.alert');
            alerts.forEach(function(alert) {
                alert.style.display = 'none';
            });
        }, 5000);
    </script>
</body>
</html> 