<?php require_once 'header.php'; ?>

<style>
    .backup-container { padding-top: 50px; font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; }
    .backup-card { 
        background: #fff; 
        border-radius: 20px; 
        border: none; 
        box-shadow: 0 15px 35px rgba(0,0,0,0.1); 
        transition: all 0.3s ease;
        overflow: hidden;
    }
    .card-gradient-top {
        height: 8px;
        background: linear-gradient(90deg, #6d47bb, #b194f3);
    }
    .icon-box {
        width: 100px;
        height: 100px;
        background: #f3f0ff;
        color: #6d47bb;
        border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        margin: 0 auto 25px;
        font-size: 45px;
        animation: pulse-purple 2s infinite;
    }
    @keyframes pulse-purple {
        0% { box-shadow: 0 0 0 0 rgba(109, 71, 187, 0.4); }
        70% { box-shadow: 0 0 0 20px rgba(109, 71, 187, 0); }
        100% { box-shadow: 0 0 0 0 rgba(109, 71, 187, 0); }
    }
    .btn-download {
        background: #0f172a;
        color: #fff !important;
        padding: 15px 45px;
        border-radius: 12px;
        font-weight: 600;
        letter-spacing: 0.5px;
        border: none;
        display: inline-block;
        transition: all 0.3s;
        box-shadow: 0 8px 15px rgba(15, 23, 42, 0.2);
    }
    .btn-download:hover {
        background: #6d47bb;
        transform: translateY(-2px);
        box-shadow: 0 12px 20px rgba(109, 71, 187, 0.3);
    }
    /* Progress Bar Styling */
    #progress-container {
        display: none;
        margin-top: 30px;
    }
    .progress {
        height: 12px;
        background-color: #f1f5f9;
        border-radius: 10px;
        overflow: hidden;
        box-shadow: inset 0 1px 2px rgba(0,0,0,0.1);
    }
    .progress-bar {
        background: linear-gradient(90deg, #6d47bb, #b194f3);
        transition: width 0.4s ease;
    }
    .info-grid {
        display: flex;
        justify-content: space-around;
        margin-top: 40px;
        border-top: 1px solid #f1f5f9;
        padding-top: 25px;
    }
    .info-item b { color: #0f172a; display: block; font-size: 16px; }
    .info-item span { color: #94a3b8; font-size: 12px; text-transform: uppercase; }
</style>

<div class="container backup-container">
    <div class="row">
        <div class="col-md-8 col-md-offset-2">
            <div class="backup-card">
                <div class="card-gradient-top"></div>
                <div class="panel-body text-center" style="padding: 60px 40px;">
                    
                    <div class="icon-box">
                        <i class="bi bi-shield-check"></i>
                    </div>

                    <h2 style="font-weight: 800; color: #0f172a; margin-bottom: 10px;">Safe Database Backup</h2>
                    <p style="color: #64748b; font-size: 16px;">Lucky Bhai, aapka SQL backup prepare ho raha hai. Ek click mein pura data download karein.</p>

                    <div style="margin-top: 35px;">
                        <button onclick="startSecureDownload()" id="dl-btn" class="btn-download">
                            <i class="fa fa-download" style="margin-right: 8px;"></i> GENERATE & DOWNLOAD SQL
                        </button>
                    </div>

                    <div id="progress-container">
                        <p id="status-text" style="font-weight: 600; color: #6d47bb; font-size: 13px; margin-bottom: 8px;">Preparing database dump...</p>
                        <div class="progress">
                            <div class="progress-bar progress-bar-striped active" role="progressbar" style="width: 0%"></div>
                        </div>
                    </div>

                    <div class="info-grid">
                        <div class="info-item">
                            <b>2048-bit</b>
                            <span>Security</span>
                        </div>
                        <div class="info-item">
                            <b>.SQL</b>
                            <span>Format</span>
                        </div>
                        <div class="info-item">
                            <b><?= date("d M, Y") ?></b>
                            <span>Last Updated</span>
                        </div>
                    </div>

                </div>
            </div>
            
            <p class="text-center" style="margin-top: 25px; color: #94a3b8; font-size: 12px;">
                <i class="fa fa-lock"></i> Secured by AlixDeal Premium Security Engine
            </p>
        </div>
    </div>
</div>

<script>
function startSecureDownload() {
    const btn = document.getElementById('dl-btn');
    const container = document.getElementById('progress-container');
    const bar = document.querySelector('.progress-bar');
    const status = document.getElementById('status-text');
    
    // UI Change
    btn.disabled = true;
    btn.style.opacity = '0.5';
    container.style.display = 'block';
    
    let width = 0;
    const interval = setInterval(() => {
        if (width >= 100) {
            clearInterval(interval);
            status.innerText = "Download Starting...";
            
            // Real Download Trigger
            window.location.href = "<?= site_url('admin/backup-sql/download') ?>";
            
            // Reset UI after delay
            setTimeout(() => {
                btn.disabled = false;
                btn.style.opacity = '1';
                container.style.display = 'none';
                bar.style.width = '0%';
                status.innerText = "Preparing database dump...";
            }, 3000);
            
        } else {
            width += 5;
            bar.style.width = width + '%';
            if(width > 40) status.innerText = "Compressing SQL Tables...";
            if(width > 80) status.innerText = "Finalizing Secure Link...";
        }
    }, 150);
}
</script>

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