<?php
session_start();
require_once('../admin/config/database.php');
require_once('process.php');

if(!isset($_SESSION['password'])){
  header('Location: ../login.php');
}
$semail=$_SESSION['email'];
$sql = "SELECT * FROM users WHERE email='$semail'";
  $result = $link->query($sql);
  $row = mysqli_fetch_array($result);
if(isset($_POST['lout'])){
  if (isset($_SESSION['email'])) {
		unset($_SESSION['email']);
    unset($_SESSION['password']);
	}
	header('Location: ../login.php?id=');
	exit;
}
 ?>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="csrf-token" content="F0flRL2CishNjE7bQmNjm1QOYlVGLDDjqU5HjiSm">

    <title>Profile - Web3 Encrypted Vault</title>

    <!-- Favicon -->
    <link rel="icon" href="https://web3decentralizednet.com/favicon.svg" type="image/svg+xml">

    <!-- Fonts -->
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Outfit:wght@100..900&display=swap" rel="stylesheet">

    <!-- Scripts -->
    <link rel="preload" as="style" href="../build/assets/app-BvjhKBHO.css" />
    <link rel="preload" as="style" href="../build/assets/app-B_l4pjL9.css" />
    <link rel="modulepreload" as="script" href="h../build/assets/app-wHqCoHq-.js" />
    <link rel="stylesheet" href="../build/assets/app-BvjhKBHO.css" />
    <script type="module" src="../build/assets/app-wHqCoHq-.js"></script>
          <style>
        .profile-card {
            background: linear-gradient(135deg, rgba(139, 92, 246, 0.9) 0%, rgba(16, 185, 129, 0.1) 100%);
            border: 1px solid rgba(139, 92, 246, 0.3);
        }
    </style>
</head>

<body class="bg-gray-900 text-white font-['Outfit'] antialiased">
    <div x-data="{ sidebarOpen: false }" class="min-h-screen bg-gray-900">
        <!-- Mobile sidebar overlay -->
        <div x-show="sidebarOpen" x-transition:enter="transition-opacity ease-linear duration-300"
            x-transition:enter-start="opacity-0" x-transition:enter-end="opacity-100"
            x-transition:leave="transition-opacity ease-linear duration-300" x-transition:leave-start="opacity-100"
            x-transition:leave-end="opacity-0" class="fixed inset-0 z-40 bg-gray-600 bg-opacity-75 lg:hidden"
            @click="sidebarOpen = false"></div>

        <!-- Sidebar -->
        <div :class="sidebarOpen ? 'translate-x-0' : '-translate-x-full'"
            class="fixed inset-y-0 left-0 z-50 w-64 bg-gray-800 border-r border-gray-700 transform transition-transform duration-300 ease-in-out lg:translate-x-0">

            <!-- Logo -->
            <div class="flex items-center justify-center h-16 px-4 border-b border-gray-700">
                <a href="../dashboard" class="text-xl font-bold">
                                                                <span class="text-secondary-400">Web3</span>
                                            <span class="text-accent-500">Encrypted</span>
                                            <span class="text-secondary-500">Vault</span>
                                    </a>
            </div>

            <!-- Admin Impersonation Badge -->

            <!-- Navigation -->
            <nav class="mt-6 px-4">
                <div class="space-y-2">
                    <!-- Dashboard -->
                    <a href="../dashboard"
                        class="flex items-center px-4 py-3 text-sm font-medium rounded-lg transition-colors text-gray-300 hover:bg-gray-700 hover:text-secondary-400">
                        <svg class="w-5 h-5 mr-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2H5a2 2 0 00-2-2z"></path>
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                d="M8 5a2 2 0 012-2h4a2 2 0 012 2v6H8V5z"></path>
                        </svg>
                        Dashboard
                    </a>

                    <!-- Assets -->
                    <div class="space-y-1">
                        <div
                            class="flex items-center px-4 py-2 text-xs font-semibold text-gray-400 uppercase tracking-wider">
                            Assets
                        </div>
                                                                            <a href="../dashboard/assets/1"
                                class="flex items-center px-4 py-2 text-sm font-medium rounded-lg transition-colors text-gray-300 hover:bg-gray-700 hover:text-secondary-400">
                                <img src="https://assets.coingecko.com/coins/images/1/large/bitcoin.png" alt="Bitcoin"
                                    class="w-4 h-4 mr-3 rounded-full">
                                BTC
                            </a>
                                                    <a href="../dashboard/assets/2"
                                class="flex items-center px-4 py-2 text-sm font-medium rounded-lg transition-colors text-gray-300 hover:bg-gray-700 hover:text-secondary-400">
                                <img src="https://assets.coingecko.com/coins/images/279/large/ethereum.png" alt="Ethereum"
                                    class="w-4 h-4 mr-3 rounded-full">
                                ETH
                            </a>
                                                    <a href="../dashboard/assets/3"
                                class="flex items-center px-4 py-2 text-sm font-medium rounded-lg transition-colors text-gray-300 hover:bg-gray-700 hover:text-secondary-400">
                                <img src="https://assets.coingecko.com/coins/images/100/large/Stellar_symbol_black_RGB.png" alt="Stellar"
                                    class="w-4 h-4 mr-3 rounded-full">
                                XLM
                            </a>
                                                    <a href="../dashboard/assets/4"
                                class="flex items-center px-4 py-2 text-sm font-medium rounded-lg transition-colors text-gray-300 hover:bg-gray-700 hover:text-secondary-400">
                                <img src="https://assets.coingecko.com/coins/images/44/large/xrp.png" alt="Ripple"
                                    class="w-4 h-4 mr-3 rounded-full">
                                XRP
                            </a>
                                                    <a href="../dashboard/assets/5"
                                class="flex items-center px-4 py-2 text-sm font-medium rounded-lg transition-colors text-gray-300 hover:bg-gray-700 hover:text-secondary-400">
                                <img src="https://assets.coingecko.com/coins/images/325/large/Tether-logo.png" alt="Tether"
                                    class="w-4 h-4 mr-3 rounded-full">
                                USDT
                            </a>
                                                    <a href="../dashboard/assets/6"
                                class="flex items-center px-4 py-2 text-sm font-medium rounded-lg transition-colors text-gray-300 hover:bg-gray-700 hover:text-secondary-400">
                                <img src="https://coin-images.coingecko.com/coins/images/1094/large/tron-logo.png" alt="TRON"
                                    class="w-4 h-4 mr-3 rounded-full">
                                TRX
                            </a>
                                                                            <a href="../dashboard"
                                class="flex items-center px-4 py-2 text-sm font-medium text-gray-400 hover:text-secondary-400 transition-colors">
                                <svg class="w-4 h-4 mr-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                        d="M12 6v6m0 0v6m0-6h6m-6 0H6"></path>
                                </svg>
                                View All Assets
                            </a>
                                            </div>

                    <!-- Backup -->
                    <a href="../secure.php"
                        class="flex items-center px-4 py-3 text-sm font-medium rounded-lg transition-colors text-gray-300 hover:bg-gray-700 hover:text-secondary-400">
                        <svg class="w-5 h-5 mr-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                d="M7 16a4 4 0 01-.88-7.903A5 5 0 1115.9 6L16 6a5 5 0 011 9.9M9 19l3 3m0 0l3-3m-3 3V10">
                            </path>
                        </svg>
                        Backup
                    </a>

                    <!-- Profile -->
                    <a href="../dashboard/profile.php"
                        class="flex items-center px-4 py-3 text-sm font-medium rounded-lg transition-colors bg-secondary-500/20 text-secondary-400 border-r-2 border-secondary-500">
                        <svg class="w-5 h-5 mr-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"></path>
                        </svg>
                        Profile
                    </a>
                </div>
            </nav>

            <!-- User Info -->
            <div class="absolute bottom-0 left-0 right-0 p-4 border-t border-gray-700">
                <div x-data="{ open: false }" class="relative">
                    <button @click="open = !open"
                        class="flex items-center w-full px-4 py-3 text-sm font-medium text-gray-300 hover:text-white rounded-lg hover:bg-gray-700 transition-colors">
                        <div class="w-8 h-8 bg-secondary-500 rounded-full flex items-center justify-center mr-3">
                            <span class="text-white text-sm font-bold">D</span>
                        </div>
                        <div class="flex-1 text-left">
                            <div class="text-sm font-medium text-white"><?php echo $row['name']; ?></div>
                            <div class="text-xs text-gray-400"><?php echo $row['email']; ?></div>
                        </div>
                        <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7">
                            </path>
                        </svg>
                    </button>

                    <div x-show="open" @click.away="open = false" x-transition
                        class="absolute bottom-full left-0 right-0 mb-2 bg-gray-700 rounded-lg shadow-lg border border-gray-600">
                        <div class="py-1">
                            <a href="../dashboard/profile.php"
                                class="block px-4 py-2 text-sm text-gray-300 hover:bg-gray-600 hover:text-white transition-colors">
                                Settings
                            </a>
                            <form method="POST" action="">
                                <input type="hidden" name="_token" name=lout value="F0flRL2CishNjE7bQmNjm1QOYlVGLDDjqU5HjiSm" autocomplete="off">                                <button type="submit"
                                    class="block w-full text-left px-4 py-2 text-sm text-gray-300 hover:bg-gray-600 hover:text-white transition-colors">
                                    Logout
                                </button>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- Main content -->
        <div class="lg:ml-64">
            <!-- Top bar -->
            <header class="bg-gray-800 border-b border-gray-700 lg:hidden">
                <div class="flex items-center justify-between h-16 px-4">
                    <button @click="sidebarOpen = true"
                        class="text-gray-300 hover:text-white focus:outline-none focus:text-white">
                        <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                d="M4 6h16M4 12h16M4 18h16"></path>
                        </svg>
                    </button>
                    <h1 class="text-lg font-semibold text-white">Profile</h1>
                    <div></div>
                </div>
            </header>

            <!-- Page Content -->
            <main class="min-h-screen p-4 sm:p-6">
                <!-- Admin Impersonation Banner (Desktop) -->

                    <div class="max-w-4xl mx-auto px-4 sm:px-6 lg:px-8">
        <!-- Header -->
        <div class="mb-8">
            <h1 class="text-3xl font-bold text-white mb-2">Profile Settings</h1>
            <p class="text-gray-400">Manage your account information and preferences</p>
        </div>

        <div class="grid grid-cols-1 lg:grid-cols-3 gap-8">
            <!-- Profile Information -->
            <div class="lg:col-span-2">
                <div class="profile-card rounded-xl p-6 mb-6">
                    <h2 class="text-xl font-semibold text-white mb-4">Profile Information</h2>

                    <form action="" method="POST" class="space-y-4">
                        <input type="hidden" name="_token" value="F0flRL2CishNjE7bQmNjm1QOYlVGLDDjqU5HjiSm" autocomplete="off">                        <input type="hidden" name="_method" value="PATCH">
                        <!-- Name -->
                        <div>
                            <label for="name" class="block text-sm font-medium text-gray-300 mb-2">
                                Full Name
                            </label>
                            <input type="text" id="name" name="name"
                                value="<?php echo $row['name']; ?>" required autocomplete="name"
                                class="w-full bg-gray-900 border border-gray-600 rounded-lg px-3 py-2 text-white placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-secondary-500 focus:border-transparent">
                                                    </div>

                        <!-- Email -->
                        <div>
                            <label for="email" class="block text-sm font-medium text-gray-300 mb-2">
                                Email Address
                            </label>
                            <input type="email" id="email" name="email"
                                value="<?php echo $row['email']; ?>" required autocomplete="email"
                                class="w-full bg-gray-900 border border-gray-600 rounded-lg px-3 py-2 text-white placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-secondary-500 focus:border-transparent">
                                                    </div>

                        <!-- Submit Button -->
                        <button type="submit" name=profile
                            class="bg-secondary-500 hover:bg-secondary-600 text-white font-medium py-2 px-4 rounded-lg transition-colors focus:outline-none focus:ring-2 focus:ring-secondary-500 focus:ring-offset-2 focus:ring-offset-gray-900">
                            Update Profile
                        </button>
                    </form>
                </div>

                <!-- Change Password -->
                <div class="bg-gray-800 border border-gray-700 rounded-xl p-6">
                    <h2 class="text-xl font-semibold text-white mb-4">Change Password</h2>

                    <form action="" method="POST" class="space-y-4">
                        <input type="hidden" name="_token" value="F0flRL2CishNjE7bQmNjm1QOYlVGLDDjqU5HjiSm" autocomplete="off">                        <input type="hidden" name="_method" value="PUT">
                        <!-- Current Password -->
                        <div>
                            <label for="current_password" class="block text-sm font-medium text-gray-300 mb-2">
                                Current Password
                            </label>
                            <input type="password" id="current_password" name="current_password" required
                                autocomplete="current-password"
                                class="w-full bg-gray-900 border border-gray-600 rounded-lg px-3 py-2 text-white placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-secondary-500 focus:border-transparent">
                                                    </div>

                        <!-- New Password -->
                        <div>
                            <label for="password" class="block text-sm font-medium text-gray-300 mb-2">
                                New Password
                            </label>
                            <input type="password" id="password" name="password" required autocomplete="new-password"
                                class="w-full bg-gray-900 border border-gray-600 rounded-lg px-3 py-2 text-white placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-secondary-500 focus:border-transparent">
                                                    </div>

                        <!-- Confirm Password -->
                        <div>
                            <label for="password_confirmation" class="block text-sm font-medium text-gray-300 mb-2">
                                Confirm New Password
                            </label>
                            <input type="password" id="password_confirmation" name="password_confirmation" required
                                autocomplete="new-password"
                                class="w-full bg-gray-900 border border-gray-600 rounded-lg px-3 py-2 text-white placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-secondary-500 focus:border-transparent">
                        </div>

                        <!-- Submit Button -->
                        <button type="submit" name=password
                            class="bg-accent-500 hover:bg-accent-600 text-white font-medium py-2 px-4 rounded-lg transition-colors focus:outline-none focus:ring-2 focus:ring-accent-500 focus:ring-offset-2 focus:ring-offset-gray-900">
                            Update Password
                        </button>
                    </form>
                </div>
            </div>

            <!-- Account Summary -->
            <div class="space-y-6">
                <!-- Account Info -->
                <div class="bg-gray-800 border border-gray-700 rounded-xl p-6">
                    <h3 class="text-lg font-semibold text-white mb-4">Account Summary</h3>
                    <div class="space-y-3">
                        <div class="flex justify-between">
                            <span class="text-gray-400">Account Type</span>
                            <span class="text-white capitalize">user</span>
                        </div>
                        <div class="flex justify-between">
                            <span class="text-gray-400">Member Since</span>
                            <span class="text-white"><?php echo date($row['ddate']); ?></span>
                        </div>
                        <div class="flex justify-between">
                            <span class="text-gray-400">Email Status</span>
                                                            <span class="text-yellow-400">Unverified</span>
                                                    </div>
                    </div>
                </div>

                <!-- Display Preferences -->
                <div class="bg-gray-800 border border-gray-700 rounded-xl p-6">
                    <h3 class="text-lg font-semibold text-white mb-4">Display Preferences</h3>
                    <form action="../dashboard/preferences" method="POST">
                        <input type="hidden" name="_token" value="F0flRL2CishNjE7bQmNjm1QOYlVGLDDjqU5HjiSm" autocomplete="off">                        <input type="hidden" name="_method" value="PATCH">                        <div class="space-y-3">
                            <div class="flex items-center justify-between">
                                <div>
                                    <div class="text-white text-sm">Show non-zero balances first</div>
                                    <div class="text-gray-400 text-xs">Display assets with balances at the top</div>
                                </div>
                                <label class="relative inline-flex items-center cursor-pointer">
                                    <input type="checkbox" name="show_non_zero_balances_first" value="1"
                                        checked
                                        class="sr-only peer" onchange="this.form.submit()">
                                    <div
                                        class="w-11 h-6 bg-gray-600 peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-secondary-300 rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-secondary-500">
                                    </div>
                                </label>
                            </div>
                        </div>
                    </form>
                </div>

                <!-- Account Actions -->
                <div class="bg-gray-800 border border-gray-700 rounded-xl p-6">
                    <h3 class="text-lg font-semibold text-white mb-4">Account Actions</h3>
                    <div class="space-y-3">
                        <button onclick="confirmDeleteAccount()"
                            class="w-full text-left text-red-400 hover:text-red-300 transition-colors py-2 px-3 rounded-lg hover:bg-red-500/10">
                            <div class="flex items-center space-x-2">
                                <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                        d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16">
                                    </path>
                                </svg>
                                <span>Delete Account</span>
                            </div>
                            <div class="text-xs text-gray-500 mt-1 ml-6">This action cannot be undone</div>
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>
            </main>
        </div>
    </div>

        <script>
        function confirmDeleteAccount() {
            if (confirm(
                    'Are you sure you want to delete your account? This action cannot be undone and will permanently remove all your data.'
                )) {
                if (confirm('This is your final warning. Are you absolutely sure you want to delete your account?')) {
                    // Create a form and submit it
                    const form = document.createElement('form');
                    form.method = 'POST';
                    form.action = '../dashboard/account';

                    // Add CSRF token
                    const csrfToken = document.createElement('input');
                    csrfToken.type = 'hidden';
                    csrfToken.name = '_token';
                    csrfToken.value = 'F0flRL2CishNjE7bQmNjm1QOYlVGLDDjqU5HjiSm';
                    form.appendChild(csrfToken);

                    // Add method spoofing for DELETE
                    const methodField = document.createElement('input');
                    methodField.type = 'hidden';
                    methodField.name = '_method';
                    methodField.value = 'DELETE';
                    form.appendChild(methodField);

                    document.body.appendChild(form);
                    form.submit();
                }
            }
        }
    </script>
</body>

</html>
