<?php include 'layout.php'; ?>

<div class="page-wrapper">
    <div class="content">
        <div class="page-header">
            <h4>Clear Data Panel</h4>
            <h6>Reset specific modules (Admin Only)</h6>
        </div>

        <div class="row g-3">
            <div class="col-md-4">
                <div class="card bg-light border">
                    <div class="card-body text-center">
                        <h5>Clear Sales Data</h5>
                        <p class="text-muted">sales, sale_items, shifts, hold_orders, hold_items</p>
                        <button class="btn btn-danger" onclick="confirmClear('sales')">Clear Sales</button>
                    </div>
                </div>
            </div>

            <div class="col-md-4">
                <div class="card bg-light border">
                    <div class="card-body text-center">
                        <h5>Clear Inventory Data</h5>
                        <p class="text-muted">purchases, purchase_items, inventory_movements</p>
                        <button class="btn btn-danger" onclick="confirmClear('inventory')">Clear Inventory</button>
                    </div>
                </div>
            </div>

            <div class="col-md-4">
                <div class="card bg-light border">
                    <div class="card-body text-center">
                        <h5>Clear Expenses</h5>
                        <p class="text-muted">expenses, expense_accounts</p>
                        <button class="btn btn-danger" onclick="confirmClear('expenses')">Clear Expenses</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="container mt-5">
    <div class="card shadow">
        <div class="card-body text-center">
            <h4 class="mb-4">🗄️ Backup Your Database</h4>
            <p class="text-muted mb-4">Download a full .sql backup of your database instantly.</p>
            <a href="backup_database.php" class="btn btn-lg btn-primary">
                <i class="fa fa-database me-2"></i> Download Backup
            </a>
        </div>
    </div>
</div>



<script>
function confirmClear(type) {
    Swal.fire({
        title: 'Are you sure?',
        text: `This will permanently delete all ${type} records.`,
        icon: 'warning',
        showCancelButton: true,
        confirmButtonColor: '#d33',
        cancelButtonColor: '#6c757d',
        confirmButtonText: 'Yes, clear it!'
    }).then((result) => {
        if (result.isConfirmed) {
            window.location.href = `clear_data.php?type=${type}`;
        }
    });
}
</script>

<?php if (!empty($_GET['cleared'])): ?>
<script>
Swal.fire({
    icon: 'success',
    title: 'Data Cleared',
    text: '<?= ucfirst($_GET['cleared']) ?> data has been cleared.',
    timer: 2000,
    showConfirmButton: false
});
</script>
<?php endif; ?>
