<?php
/**
 * Audit Reports
 * Generate comprehensive audit reports
 * Kenyan Pension & Life Insurance Management System
 */

require_once 'layouts/main.php';
require_once 'includes/auth.php';

requireLogin();
requirePermission('view_audit_reports');

$report_type = $_GET['report_type'] ?? 'activity';
$date_from = $_GET['date_from'] ?? date('Y-m-01');
$date_to = $_GET['date_to'] ?? date('Y-m-t');
$user_id = $_GET['user_id'] ?? '';

$pageTitle = 'Audit Reports';
include 'layouts/topbar.php';
?>

<head>
    <?php includeFileWithVariables('layouts/title-meta.php', array('title' => 'Audit Reports')); ?>
    <link rel="stylesheet" href="assets/css/pension-dashboard.css">
    <?php include 'layouts/head-css.php'; ?>
</head>

<body data-sidebar="dark">
    <div id="layout-wrapper">
        <?php include 'layouts/sidebar.php'; ?>
        
        <div class="main-content">
            <div class="page-content">
                <div class="container-fluid">
                    <div class="welcome-header" style="background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%); margin-bottom: 2rem;">
                        <div class="welcome-content">
                            <div class="welcome-text">
                                <h2>Audit Reports</h2>
                                <p>Generate comprehensive audit and compliance reports</p>
                            </div>
                        </div>
                    </div>

                    <div class="row">
                        <div class="col-md-4">
                            <div class="page-card">
                                <div class="page-card-header">
                                    <h4 class="page-card-title">Generate Report</h4>
                                </div>
                                <div class="page-card-body">
                                    <form method="GET">
                                        <div class="mb-3">
                                            <label class="form-label">Report Type</label>
                                            <select name="report_type" class="form-select">
                                                <option value="activity" <?php echo $report_type === 'activity' ? 'selected' : ''; ?>>Activity Log</option>
                                                <option value="financial" <?php echo $report_type === 'financial' ? 'selected' : ''; ?>>Financial Transactions</option>
                                                <option value="user" <?php echo $report_type === 'user' ? 'selected' : ''; ?>>User Activity</option>
                                                <option value="system" <?php echo $report_type === 'system' ? 'selected' : ''; ?>>System Changes</option>
                                            </select>
                                        </div>
                                        
                                        <div class="mb-3">
                                            <label class="form-label">Date From</label>
                                            <input type="date" name="date_from" class="form-control" value="<?php echo $date_from; ?>">
                                        </div>
                                        
                                        <div class="mb-3">
                                            <label class="form-label">Date To</label>
                                            <input type="date" name="date_to" class="form-control" value="<?php echo $date_to; ?>">
                                        </div>
                                        
                                        <button type="submit" class="btn btn-primary w-100">
                                            <i class="ri-file-chart-line me-2"></i>Generate Report
                                        </button>
                                    </form>
                                </div>
                            </div>
                        </div>
                        
                        <div class="col-md-8">
                            <div class="page-card">
                                <div class="page-card-header">
                                    <h4 class="page-card-title">Report Results</h4>
                                </div>
                                <div class="page-card-body">
                                    <?php if ($_GET['action'] === 'generate'): ?>
                                        <div class="alert alert-info">
                                            <i class="ri-information-line me-2"></i>
                                            Report generation functionality will display audit data based on selected criteria.
                                        </div>
                                        <p class="text-muted">Report Type: <?php echo htmlspecialchars($report_type); ?></p>
                                        <p class="text-muted">Period: <?php echo date('d M Y', strtotime($date_from)); ?> to <?php echo date('d M Y', strtotime($date_to)); ?></p>
                                    <?php else: ?>
                                        <div class="alert alert-info">
                                            <i class="ri-information-line me-2"></i>
                                            Select report criteria and click "Generate Report" to view audit data.
                                        </div>
                                    <?php endif; ?>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <?php include 'layouts/footer.php'; ?>
        </div>
    </div>
    <?php include 'layouts/vendor-scripts.php'; ?>
</body>
</html>
