<?php
ob_start();
session_start();
require_once($_SERVER['DOCUMENT_ROOT'] . "/include/Function.php");

$user_id = userDetails('id');

if (isset($_SESSION["name"])) {
    if ((time() - $_SESSION['last_login_timestamp']) > 60) {
        header("location:logout");
    } else {
        $_SESSION['last_login_timestamp'] = time();
        echo "<h1 align='center'>" . $_SESSION["name"] . "</h1>";
        echo '<h1 align="center">' . $_SESSION['last_login_timestamp'] . '</h1>';
        echo "<p align='center'><a href='logout.php'>Logout</a></p>";
    }
}

if (!$_SESSION['acct_no']) {
    header("location:../login.php");
    exit;
}

$title        = new pageTitle();
$email_message = new message();
$sendMail     = new emailMessage();
$sendSms      = new twilioController();

$user_id = userDetails('id');

// Fetch full user row
$acct_no  = $_SESSION['acct_no'];
$sqlUser  = "SELECT * FROM users WHERE acct_no = :acct_no";
$stmtUser = $conn->prepare($sqlUser);
$stmtUser->execute(['acct_no' => $acct_no]);
$row = $stmtUser->fetch(PDO::FETCH_ASSOC);

$fullName     = trim(($row['firstname'] ?? '') . ' ' . ($row['lastname'] ?? ''));
$acct_balance = $row['acct_balance'] ?? 0;
$currency     = $row['acct_currency'] ?? '$';

// Card check
$sql2    = "SELECT * FROM card WHERE user_id=:user_id";
$cardstmt = $conn->prepare($sql2);
$cardstmt->execute(['user_id' => $user_id]);
$cardCheck = $cardstmt->fetch(PDO::FETCH_ASSOC);
?>

<!doctype html>
<html lang="en">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, viewport-fit=cover" />
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="csrf_token" content="C8uPSWMnKnMSMgKJXX07rCgv3PCWPKVRelJaI36t" id="csrf_token" data-turbolinks-permanent>
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <meta name="theme-color" content="#2d8659">
    <title><?= $web_title ?> | Customer Dashboard</title>
    <meta name="description" content="Experience fast, secure, and convenient banking right from your browser with our Progressive Web App (PWA). Our online banking platform lets you manage your finances anytime, anywhere — without downloading a traditional mobile app.

With a modern, app-like experience, you can instantly check balances, transfer money, pay bills, and monitor transactions in real time. The PWA is designed to be lightweight, reliable, and works smoothly even on slow networks.

Key Features

💳 Real-time account balance &amp; transaction history

🔁 Instant transfers and bill payments

🔒 Advanced security &amp; data encryption

📱 Install directly to your phone or desktop

⚡ Fast loading and offline-ready technology

🌍 Access from any device, anywhere in the world

Our Online Banking PWA combines the power of a mobile app with the convenience of the web — giving you a seamless and secure digital banking experience at your fingertips.">
    <meta name="keywords" content="<?= $web_title ?>" />
    <link rel="icon" type="image/png" href="<?= $web_url ?>/admin/assets/images/favicon/<?= htmlspecialchars($page['favicon']) ?>" sizes="32x32">
    <link rel="apple-touch-icon" sizes="180x180" href="<?= $web_url ?>/admin/assets/images/favicon/<?= htmlspecialchars($page['favicon']) ?>">
    
        <!-- PWA Meta Tags -->
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="application-name" content="<?= $web_title ?>">
    <meta name="apple-mobile-web-app-title" content="<?= $web_title ?>">
    
    <!-- PWA Manifest -->
    <link rel="manifest" href="https://fintech.swizzfx.pro/manifest.json">
    
    <!-- Apple Touch Icons -->
    <link rel="apple-touch-icon" href="<?= $web_url ?>/admin/assets/images/favicon/<?= htmlspecialchars($page['favicon']) ?>">
    <link rel="apple-touch-icon" sizes="152x152" href="<?= $web_url ?>/admin/assets/images/favicon/<?= htmlspecialchars($page['favicon']) ?>">
    <link rel="apple-touch-icon" sizes="167x167" href="<?= $web_url ?>/admin/assets/images/favicon/<?= htmlspecialchars($page['favicon']) ?>">
        
    <!-- Tailwind CSS -->
    <script src="https://cdn.tailwindcss.com"></script>
    
    <!-- Alpine.js -->
    <script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script>
     
    
    
    <!-- Modern Icons - Lucide -->
    <script src="https://unpkg.com/lucide@latest"></script>
    
    <!-- Sophisticated Banking Fonts - Playfair Display (Luxury serif) & Inter (Clean sans) -->
    <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=Playfair+Display:wght@400;500;600;700;800;900&family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
    
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.2/css/all.min.css" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/2.1.2/sweetalert.min.js"></script>
    <script src="https://code.jquery.com/jquery-3.6.1.min.js"></script>
    
<?php
include '../user/tailwind.php';
?>

</head>


<body class="bg-[#F9F9F9] text-[#0D1B23]" x-data="{ mobileMenuOpen: false, sidebarOpen: false }">

    <!-- App Header -->
    <header class="fixed top-0 left-0 right-0 z-50 bg-white/95 backdrop-blur-sm border-b border-[#E0E5E5] lg:left-80">
        <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
            <div class="flex items-center justify-between h-14 md:h-16">
                <!-- Left: Menu Button -->
                <button @click="sidebarOpen = true" class="lg:hidden p-2 rounded-lg hover:bg-[#DFE5E5] transition-colors">
                    <i data-lucide="menu" class="w-5 h-5 text-[#4A4A4A]"></i>
                </button>
                
                <!-- Logo (centered) -->
                <div class="absolute left-1/2 -translate-x-1/2 flex items-center">
                    <img src="<?= $web_url ?>/admin/assets/images/logo/<?= htmlspecialchars($page['image']) ?>" alt="<?= $web_title ?>" class="h-7 md:h-9 w-auto object-contain">
                </div>
                
                <!-- Language Selector -->
                
                
                <!-- Right: Profile -->
                <div class="flex items-center space-x-4 lg:ml-auto">
                   
                    <!-- Profile Dropdown -->
                    <div x-data="{ profileOpen: false }" class="relative">
                        <button @click="profileOpen = !profileOpen" class="flex items-center space-x-2 lg:space-x-3 px-2 lg:px-3 py-2 rounded-lg hover:bg-[#DFE5E5] transition-colors group">
                                                            <img src="<?= $web_url ?>/assets/user/profile/<?= $row['acct_image'] ?>" 
                                     alt="eva" 
                                     class="w-8 h-8 lg:w-9 lg:h-9 rounded-full object-cover border border-[#E0E5E5]">
                                                        <div class="hidden xl:block text-left">
                                <p class="text-sm font-medium text-[#0D1B23]"><?= $fullName ?></p>
                                <p class="text-xs text-[#7A7A7A]"><?= $row['acct_type'] ?? '' ?></p>
                            </div>
                            <i data-lucide="chevron-down" class="w-3 h-3 lg:w-4 lg:h-4 text-[#7A7A7A]" :class="{ 'rotate-180': profileOpen }"></i>
                        </button>

                        <!-- Dropdown Menu -->
                        <div x-show="profileOpen"
                             @click.away="profileOpen = false"
                             x-transition:enter="transition ease-out duration-200"
                             x-transition:enter-start="opacity-0 scale-95"
                             x-transition:enter-end="opacity-100 scale-100"
                             x-transition:leave="transition ease-in duration-150"
                             x-transition:leave-start="opacity-100 scale-100"
                             x-transition:leave-end="opacity-0 scale-95"
                             class="absolute right-0 mt-2 w-64 lg:w-72 rounded-xl bg-white border border-[#E0E5E5] shadow-strong overflow-hidden z-50"
                             style="display: none;">
                            
                            <!-- User Info Header -->
                            <div class="p-3 lg:p-4 border-b border-[#E0E5E5]">
                                <div class="flex items-center space-x-2 lg:space-x-3">
                                                                            <img src="<?= $web_url ?>/assets/user/profile/<?= $row['acct_image'] ?>" 
                                             alt="eva" 
                                             class="w-10 h-10 lg:w-11 lg:h-11 rounded-full object-cover border border-[#E0E5E5]">
                                                                        <div class="flex-1 min-w-0">
                                        <p class="text-sm font-medium text-[#0D1B23] truncate"><?= $fullName ?></p>
                                        <p class="text-[10px] lg:text-xs text-[#7A7A7A] truncate"><?= $row['acct_email'] ?? '' ?></p>
                                        <span class="inline-flex items-center px-1.5 lg:px-2 py-0.5 rounded-full bg-[#DFE5E5] text-[9px] lg:text-[10px] font-medium text-[#4A4A4A] mt-1">
                                            <?= $row['acct_type'] ?? '' ?>
                                        </span>
                                    </div>
                                </div>
                            </div>

                            <!-- Menu Items -->
                            <div class="p-1.5 lg:p-2">
                                <a href="/user/account-settings.php" class="flex items-center space-x-2 lg:space-x-3 px-3 lg:px-4 py-2.5 lg:py-3 rounded-lg hover:bg-[#F9F9F9] transition-colors group">
                                    <div class="w-8 h-8 lg:w-9 lg:h-9 rounded-lg bg-[#DFE5E5] flex items-center justify-center">
                                        <i data-lucide="user-cog" class="w-3.5 h-3.5 lg:w-4 lg:h-4 text-[#4A4A4A]"></i>
                                    </div>
                                    <div class="flex-1">
                                        <p class="font-medium text-xs lg:text-sm text-[#0D1B23]">Account Settings</p>
                                        <p class="text-[10px] lg:text-xs text-[#7A7A7A]">Manage your profile</p>
                                    </div>
                                </a>

                                <a href="/user/account-settings.php" class="flex items-center space-x-2 lg:space-x-3 px-3 lg:px-4 py-2.5 lg:py-3 rounded-lg hover:bg-[#F9F9F9] transition-colors group">
                                    <div class="w-8 h-8 lg:w-9 lg:h-9 rounded-lg bg-[#DFE5E5] flex items-center justify-center">
                                        <i data-lucide="shield-check" class="w-3.5 h-3.5 lg:w-4 lg:h-4 text-[#4A4A4A]"></i>
                                    </div>
                                    <div class="flex-1">
                                        <p class="font-medium text-xs lg:text-sm text-[#0D1B23]">Security & PIN</p>
                                        <p class="text-[10px] lg:text-xs text-[#7A7A7A]">Update your PIN</p>
                                    </div>
                                </a>

                                <a href="/user/accounthistory.php" class="flex items-center space-x-2 lg:space-x-3 px-3 lg:px-4 py-2.5 lg:py-3 rounded-lg hover:bg-[#F9F9F9] transition-colors group">
                                    <div class="w-8 h-8 lg:w-9 lg:h-9 rounded-lg bg-[#DFE5E5] flex items-center justify-center">
                                        <i data-lucide="receipt" class="w-3.5 h-3.5 lg:w-4 lg:h-4 text-[#4A4A4A]"></i>
                                    </div>
                                    <div class="flex-1">
                                        <p class="font-medium text-xs lg:text-sm text-[#0D1B23]">Transaction History</p>
                                        <p class="text-[10px] lg:text-xs text-[#7A7A7A]">View all activities</p>
                                    </div>
                                </a>

                                <a href="/user/support.php" class="flex items-center space-x-2 lg:space-x-3 px-3 lg:px-4 py-2.5 lg:py-3 rounded-lg hover:bg-[#F9F9F9] transition-colors group">
                                    <div class="w-8 h-8 lg:w-9 lg:h-9 rounded-lg bg-[#DFE5E5] flex items-center justify-center">
                                        <i data-lucide="headphones" class="w-3.5 h-3.5 lg:w-4 lg:h-4 text-[#4A4A4A]"></i>
                                    </div>
                                    <div class="flex-1">
                                        <p class="font-medium text-xs lg:text-sm text-[#0D1B23]">Support Center</p>
                                        <p class="text-[10px] lg:text-xs text-[#7A7A7A]">Get help</p>
                                    </div>
                                </a>
                            </div>

                            <!-- Logout -->
                            <div class="p-1.5 lg:p-2 border-t border-[#E0E5E5]">
                                <a href="/user/logout.php" 
                                   onclick="event.preventDefault(); document.getElementById('logout-form').submit();"
                                   class="flex items-center space-x-2 lg:space-x-3 px-3 lg:px-4 py-2.5 lg:py-3 rounded-lg hover:bg-red-50 transition-colors group">
                                    <div class="w-8 h-8 lg:w-9 lg:h-9 rounded-lg bg-red-50 flex items-center justify-center">
                                        <i data-lucide="log-out" class="w-3.5 h-3.5 lg:w-4 lg:h-4 text-[#D55672]"></i>
                                    </div>
                                    <div class="flex-1">
                                        <p class="font-medium text-xs lg:text-sm text-[#D55672]">Log Out</p>
                                        <p class="text-[10px] lg:text-xs text-[#7A7A7A]">Sign out of your account</p>
                                    </div>
                                </a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </header>
