<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>DelightX - Financial Dashboard</title>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
    <meta name="theme-color" content="#3b1e54">
     <!-- Google Fonts (Capriola, Montserrat, PT Sans, Righteous) -->
     <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=Capriola&family=Montserrat+Alternates&family=Montserrat:ital,wght@0,100..900;1,100..900&family=PT+Sans:ital,wght@0,400;0,700;1,400;1,700&family=Righteous&display=swap" rel="stylesheet">
     
    <style>
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Righteous', sans-serif; /* Updated to 'Righteous' */
    font-weight: 300; /* Reduced font weight globally */
}

:root {
    --primary-color: #3b1e54; /* Updated to #3b1e54 */
    --secondary-color: #6B2D90;
    --accent-color: #9B4ECA;
    --background-color: #F8F9FA;
    --card-background: #FFFFFF;
}

body {
    background-color: var(--background-color);
    min-height: 100vh;
    position: relative;
    overflow-x: hidden;
}

.splash-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: var(--primary-color); /* Updated to #3b1e54 */
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    animation: fadeOut 0.5s ease 2.5s forwards;
}

.splash-logo {
    font-size: 6rem;
    color: white;
    font-weight: 300; /* Reduced font weight */
    opacity: 0;
    transform: translateY(20px);
    text-shadow: 2px 2px 8px rgba(0,0,0,0.3);
    letter-spacing: 2px;
    animation: fadeInUp 0.5s ease forwards,
               parallaxFloat 2s ease-in-out infinite,
               fadeOut 0.5s ease 2s forwards;
}

.watermark {
    position: fixed;
    bottom: 20px;
    right: 20px;
    font-size: 1.2rem;
    color: var(--primary-color);
    opacity: 0.2;
    pointer-events: none;
    z-index: 100;
}

.dashboard {
    max-width: 1400px;
    margin: 0 auto;
    padding: 2rem;
    opacity: 0;
    animation: fadeIn 1s ease 3s forwards;
    perspective: 1000px;
}

.header {
    margin-top: 5%;
    text-align: center;
    margin-bottom: 3rem;
    color: var(--primary-color); /* Updated to #3b1e54 */
    transform-style: preserve-3d;
}

.header h1 {
    font-size: 2.5rem;
    margin-bottom: 1rem;
    font-weight: 300; /* Reduced font weight */
    transform: translateZ(50px);
}

.partnership-info {
    background: var(--primary-color); /* Updated to #3b1e54 */
    color: white;
    padding: 1.5rem;
    margin-bottom: 3rem;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    transform-style: preserve-3d;
}

.stats-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 2rem;
    margin-bottom: 3rem;
    perspective: 1000px;
}

.stat-card {
    background: var(--card-background);
    padding: 2rem;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    transform-style: preserve-3d;
    will-change: transform;
}

.stat-card:hover {
    transform: translateY(-5px) translateZ(20px);
    box-shadow: 0 8px 12px rgba(0,0,0,0.15);
}

.stat-card h3 {
    color: var(--secondary-color);
    margin-bottom: 1rem;
    font-size: 1.2rem;
    font-weight: 300; /* Reduced font weight */
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.stat-value {
    font-size: 2rem;
    color: var(--primary-color);
    font-weight: 500; /* Reduced font weight */
}

.date-info {
    color: #666;
    font-size: 0.9rem;
    margin-top: 0.5rem;
}

.footer {
    text-align: center;
    margin-top: 4rem;
    padding: 2rem;
    background: var(--primary-color); /* Updated to #3b1e54 */
    color: white;
}

.loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 900;
}

.loading-spinner {
    width: 50px;
    height: 50px;
    border: 5px solid #f3f3f3;
    border-top: 5px solid var(--primary-color); /* Updated to #3b1e54 */
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.info-text {
    color: #666;
    font-size: 0.9rem;
    margin-top: 0.5rem;
    font-style: italic;
}

p {
    font-weight: 100 !important; /* Reduced font weight for <p> tags */
}

@keyframes parallaxFloat {
    0% { transform: translateY(0) translateZ(0); }
    50% { transform: translateY(-20px) translateZ(50px); }
    100% { transform: translateY(0) translateZ(0); }
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes fadeOut {
    from { opacity: 1; visibility: visible; }
    to { opacity: 0; visibility: hidden; }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes fadeInUp {
    from { 
        opacity: 0;
        transform: translateY(20px);
    }
    to { 
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 768px) {
    .dashboard {
        padding: 1rem;
    }

    .header h1 {
        font-size: 2rem;
        font-weight: 300; /* Reduced font weight */
    }

    .stat-card {
        padding: 1.5rem;
    }
    
    .splash-logo {
        font-size: 4rem;
        font-weight: 300; /* Reduced font weight */
    }
}

.partnership-share {
    background: var(--primary-color); /* Updated to #3b1e54 */
    color: white;
    padding: 1.5rem;
    margin: 2rem 0;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    transform-style: preserve-3d;
}

.partnership-share h3 {
    color: white !important;
    font-size: 1.4rem;
    font-weight: 300; /* Reduced font weight */
    margin-bottom: 1rem;
}

.share-details {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 1rem;
}

.next-payment {
    font-size: 0.9rem;
    opacity: 0.9;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid rgba(255,255,255,0.2);
}

.share-amount {
    font-size: 2rem;
    font-weight: 500; /* Reduced font weight */
    color: #ffffff;
}

    </style>
</head>
<body>
    <div class="splash-screen">
        <div class="splash-logo">DelightX</div>
    </div>

    <div class="watermark">DelightX © 2025</div>

    <div class="dashboard">
        <div class="header">
            <h1>DelightX Financial Dashboard</h1>
            <p>Real-time financial insights and performance metrics</p>
        </div>

        <div class="partnership-info">
            <h2>Partnership Transparency</h2>
            <p>DelightX is proud to announce our strategic partnership with Imagvitie Company, sharing 10% of our profits in this collaborative venture. This dashboard represents our commitment to transparency and mutual growth.</p>
        </div>

        <div class="stats-container">
            <div class="stat-card">
                <h3><i class="fas fa-wallet"></i> Total Income</h3>
                <div id="totalIncome" class="stat-value">₹0</div>
                <div class="info-text">*Includes operational costs</div>
            </div>
            <div class="stat-card">
                <h3><i class="fas fa-chart-line"></i> Today's Income</h3>
                <div id="todayIncome" class="stat-value">₹0</div>
                <div id="todayDate" class="date-info"></div>
            </div>
            <div class="stat-card">
                <h3><i class="fas fa-money-bill-wave"></i> COD Payments</h3>
                <div id="codPayments" class="stat-value">₹0</div>
            </div>
            <div class="stat-card">
                <h3><i class="fas fa-credit-card"></i> Online Payments</h3>
                <div id="onlinePayments" class="stat-value">₹0</div>
            </div>
        </div>

        <div class="partnership-share">
            <h3><i class="fas fa-handshake"></i> Imagvitie Partnership Share</h3>
            <div class="share-details">
                <div>
                    <div class="share-amount" id="partnershipShare">₹0</div>
                    <div>Monthly Share (10%)</div>
                </div>
            </div>
            <div class="next-payment" id="nextPaymentDate">
                Next transfer scheduled for: Calculating...
            </div>
        </div>

        <div class="footer">
            <p>Designed and Developed by DelightX Team</p>
            <p>A collaborative project with Imagvitie Company</p>
        </div>
    </div>

    <script type="module">
     // Enhanced security system with URL validation
const dashboardSecurity = {
    allowedUrls: [
        'file:///C:/Users/ragul/Desktop/index.html',
        'https://delightx-share.netlify.app'
    ],
    
    requiredElements: [
        'splash-screen',
        'splash-logo',
        'watermark',
        'dashboard',
        'header',
        'partnership-info',
        'stats-container',
        'totalIncome',
        'todayIncome',
        'codPayments',
        'onlinePayments',
        'todayDate'
    ],
    
    checkUrlValidity() {
        const currentUrl = window.location.href;
        // Remove trailing slash if present for consistent comparison
        const normalizedUrl = currentUrl.replace(/\/$/, '');
        
        const isValidUrl = this.allowedUrls.some(url => 
            normalizedUrl.toLowerCase() === url.toLowerCase()
        );
        
        if (!isValidUrl) {
            this.triggerSecurityViolation('Unauthorized Access: Invalid URL');
            return false;
        }
        return true;
    },
    
    checkIntegrity() {
        // First check URL validity
        if (!this.checkUrlValidity()) {
            return false;
        }
        
        const missingElements = this.requiredElements.filter(id => 
            !document.getElementsByClassName(id).length && !document.getElementById(id)
        );
        
        if (missingElements.length > 0) {
            this.triggerSecurityViolation('Security Alert: Dashboard Compromised');
            return false;
        }
        return true;
    },

    triggerSecurityViolation(message) {
        document.body.innerHTML = `
            <div style="
                position: fixed;
                top: 0;
                left: 0;
                width: 100%;
                height: 100%;
                background: linear-gradient(135deg, #FF0000, #CC0000);
                color: white;
                display: flex;
                flex-direction: column;
                justify-content: center;
                align-items: center;
                font-family: 'Righteous', sans-serif;
                text-align: center;
                padding: 20px;
            ">
                <div style="font-size: 28px; margin-bottom: 15px;">
                    ${message}
                </div>
                <div style="font-size: 18px;">
                    Please contact system administrator
                </div>
            </div>
        `;
        throw new Error(message);
    },

    startMonitoring() {
        // Initial check
        if (!this.checkIntegrity()) {
            return;
        }

        // Set up continuous monitoring
        const observer = new MutationObserver(() => {
            if (!this.checkIntegrity()) {
                observer.disconnect();
            }
        });

        observer.observe(document.body, {
            childList: true,
            subtree: true,
            attributes: true
        });

        // Add URL change detection for SPA support
        window.addEventListener('popstate', () => {
            this.checkIntegrity();
        });
    }
};

// Initialize security system immediately
document.addEventListener('DOMContentLoaded', () => {
    try {
        dashboardSecurity.startMonitoring();
    } catch (error) {
        console.error('Security initialization failed:', error);
    }
});

        // Firebase configuration and data management
        import { getDatabase, ref, get } from "https://www.gstatic.com/firebasejs/9.21.0/firebase-database.js";
        import { initializeApp } from "https://www.gstatic.com/firebasejs/9.21.0/firebase-app.js";

        const firebaseConfig = {
            apiKey: "AIzaSyBjZDiWXkOclw7RmmU31822nPuj9px1hSA",
            authDomain: "quickbuy-29329.firebaseapp.com",
            databaseURL: "https://quickbuy-29329-default-rtdb.firebaseio.com",
            projectId: "quickbuy-29329",
            storageBucket: "quickbuy-29329.appspot.com",
            messagingSenderId: "956510631625",
            appId: "1:956510631625:web:678411a2530ef065b97f18"
        };

        function showLoading() {
            const loader = document.createElement('div');
            loader.className = 'loading';
            loader.innerHTML = '<div class="loading-spinner"></div>';
            document.body.appendChild(loader);
        }

        function hideLoading() {
            const loader = document.querySelector('.loading');
            if (loader) {
                loader.remove();
            }
        }

        function formatCurrency(amount) {
            return new Intl.NumberFormat('en-IN', {
                style: 'currency',
                currency: 'INR',
                maximumFractionDigits: 0
            }).format(amount);
        }

        function isSameDay(date1, date2) {
            return date1.getFullYear() === date2.getFullYear() &&
                   date1.getMonth() === date2.getMonth() &&
                   date1.getDate() === date2.getDate();
        }

        async function fetchDeliveryBoys() {
            const database = getDatabase();
            const deliveryBoysRef = ref(database, 'delivery_boys');
            const snapshot = await get(deliveryBoysRef);
            if (snapshot.exists()) {
                return Object.keys(snapshot.val()).length;
            }
            return 0;
        }

        
        // Initialize dashboard when DOM is loaded
        document.addEventListener('DOMContentLoaded', () => {
            dashboardSecurity.startMonitoring();
            setTimeout(fetchPaymentData, 3000);
            setInterval(fetchPaymentData, 300000);
        });
        function calculateNextPaymentDate() {
            const now = new Date();
            const nextPayment = new Date(now.getFullYear(), now.getMonth(), 30, 18, 0, 0);
            
            if (now > nextPayment) {
                nextPayment.setMonth(nextPayment.getMonth() + 1);
            }

            return nextPayment.toLocaleString('en-IN', {
                weekday: 'long',
                year: 'numeric',
                month: 'long',
                day: 'numeric',
                hour: '2-digit',
                minute: '2-digit'
            });
        }

        async function fetchPaymentData() {
            if (!dashboardSecurity.checkIntegrity()) return;
            
            showLoading();
            try {
                const app = initializeApp(firebaseConfig);
                const database = getDatabase(app);
                const ordersRef = ref(database, 'orders');
                const ordersSnapshot = await get(ordersRef);

                // Fetch number of delivery boys
                const deliveryBoysCount = await fetchDeliveryBoys();
                let totalAmount = 0;
                let codAmount = 0;
                let onlineAmount = 0;
                let todayAmount = 0;

                const today = new Date();
                
                document.getElementById('todayDate').textContent = 
                    today.toLocaleDateString('en-IN', { 
                        weekday: 'long',
                        year: 'numeric', 
                        month: 'long', 
                        day: 'numeric' 
                    });

                if (ordersSnapshot.exists()) {
                    const orders = ordersSnapshot.val();
                    for (const userId in orders) {
                        const userOrders = orders[userId];
                        for (const orderId in userOrders) {
                            const order = userOrders[orderId];
                            
                            if (order.isDelivered && order.totalAmount) {
                                totalAmount += order.totalAmount;

                                if (order.paymentMethod === 'COD') {
                                    codAmount += order.totalAmount;
                                } else if (order.paymentMethod === 'Online') {
                                    onlineAmount += order.totalAmount;
                                }

                                if (order.orderDate) {
                                    const orderDate = new Date(order.orderDate);
                                    if (isSameDay(orderDate, today)) {
                                        todayAmount += order.totalAmount;
                                    }
                                }
                            }
                        }
                    }
                }

                // Calculate salary expenses
                const monthlySalaryPerPerson = 3100;
                const totalSalaryExpense = deliveryBoysCount * monthlySalaryPerPerson;

                // Adjust amounts after deducting salary expenses
                const salaryExpensePerDay = totalSalaryExpense / 30;
                
                // Deduct salary expenses proportionally from all amounts
                totalAmount -= totalSalaryExpense;
                todayAmount -= salaryExpensePerDay;
                codAmount = codAmount - (salaryExpensePerDay * (codAmount / (codAmount + onlineAmount)));
                onlineAmount = onlineAmount - (salaryExpensePerDay * (onlineAmount / (codAmount + onlineAmount)));

                // Calculate partnership share (10% of total profit)
                const partnershipShare = totalAmount * 0.10;

                // Update next payment date
                document.getElementById('nextPaymentDate').textContent = 
                    `Next transfer scheduled for: ${calculateNextPaymentDate()}`;

                // Animate number updates
                const elements = {
                    totalIncome: totalAmount,
                    todayIncome: todayAmount,
                    codPayments: codAmount,
                    onlinePayments: onlineAmount,
                    partnershipShare: partnershipShare
                };

                for (const [id, value] of Object.entries(elements)) {
                    const el = document.getElementById(id);
                    if (el) {
                        el.textContent = formatCurrency(Math.max(0, value));
                        el.style.opacity = 0;
                        el.style.transform = 'translateY(20px)';
                        setTimeout(() => {
                            el.style.transition = 'all 0.5s ease';
                            el.style.opacity = 1;
                            el.style.transform = 'translateY(0)';
                        }, 100);
                    }
                }

            } catch (error) {
                console.error('Error fetching payment data:', error);
                alert('Error loading payment data. Please check console for details.');
            } finally {
                hideLoading();
            }
        }

        // Initialize dashboard when DOM is loaded
        document.addEventListener('DOMContentLoaded', () => {
            dashboardSecurity.startMonitoring();
            setTimeout(fetchPaymentData, 3000);
            setInterval(fetchPaymentData, 300000);
        });
    </script>
</body>

</html>