<?php
require_once __DIR__ . '/config/config.php';
session_start();

$is_super_admin = isset($_SESSION['role_id']) && $_SESSION['role_id'] == 1;

if (!$is_super_admin) {
    header('Content-Type: text/plain');
    die('Access denied. Super Admin only.');
}

$checks = [
    'BASE_URL' => BASE_URL,
    'BASE_PATH' => BASE_PATH,
    'Current Script' => __FILE__,
    'Document Root' => $_SERVER['DOCUMENT_ROOT'] ?? 'N/A',
    'Script Name' => $_SERVER['SCRIPT_NAME'] ?? 'N/A',
    'PHP_SELF' => $_SERVER['PHP_SELF'] ?? 'N/A',
];

$files = [
    'technician_panel.php' => __DIR__ . '/repairs/technician_panel.php',
    'header.php' => __DIR__ . '/includes/header.php',
    'sidebar.php' => __DIR__ . '/includes/sidebar.php',
    'footer.php' => __DIR__ . '/includes/footer.php',
    'database.php' => __DIR__ . '/config/database.php',
    'auth.php' => __DIR__ . '/config/auth.php',
    'functions.php' => __DIR__ . '/includes/functions.php',
    'pos.js' => __DIR__ . '/assets/js/pos.js',
    'main.js' => __DIR__ . '/assets/js/main.js',
    'style.css' => __DIR__ . '/assets/css/style.css',
    'pos.php' => __DIR__ . '/pos/pos.php',
    'login.php' => __DIR__ . '/auth/login.php',
    'dashboard.php' => __DIR__ . '/admin/dashboard.php',
    'logo.png' => __DIR__ . '/assets/images/logo.png',
];

?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Path Debug - DigiMobiz</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <style>body{padding:20px;font-family:monospace}</style>
</head>
<body>
    <div class="container">
        <h1 class="mb-4">🔧 DigiMobiz Path Debug</h1>

        <h3>Constants</h3>
        <table class="table table-bordered table-sm">
            <thead><tr><th>Constant</th><th>Value</th></tr></thead>
            <tbody>
                <?php foreach ($checks as $key => $val): ?>
                <tr><td><strong><?= $key ?></strong></td><td><code><?= htmlspecialchars($val) ?></code></td></tr>
                <?php endforeach; ?>
            </tbody>
        </table>

        <h3>File Existence Checks</h3>
        <table class="table table-bordered table-sm">
            <thead><tr><th>File</th><th>Path</th><th>Exists</th></tr></thead>
            <tbody>
                <?php foreach ($files as $name => $path): ?>
                <tr>
                    <td><strong><?= htmlspecialchars($name) ?></strong></td>
                    <td><code><?= htmlspecialchars($path) ?></code></td>
                    <td><?= file_exists($path) ? '<span class="text-success fw-bold">YES</span>' : '<span class="text-danger fw-bold">NO</span>' ?></td>
                </tr>
                <?php endforeach; ?>
            </tbody>
        </table>

        <h3>Test URLs</h3>
        <table class="table table-bordered table-sm">
            <thead><tr><th>URL</th><th>Full URL</th></tr></thead>
            <tbody>
                <?php
                $test_urls = [
                    'Login' => 'auth/login.php',
                    'Dashboard' => 'admin/dashboard.php',
                    'POS' => 'pos/pos.php',
                    'Technician Panel' => 'repairs/technician_panel.php',
                    'Products' => 'products/products.php',
                    'Suppliers' => 'suppliers/suppliers.php',
                    'Purchases' => 'suppliers/purchases.php',
                ];
                foreach ($test_urls as $label => $path):
                ?>
                <tr>
                    <td><strong><?= htmlspecialchars($label) ?></strong></td>
                    <td><a href="<?= BASE_URL . $path ?>" target="_blank"><code><?= htmlspecialchars(BASE_URL . $path) ?></code></a></td>
                </tr>
                <?php endforeach; ?>
            </tbody>
        </table>

        <p class="text-muted mt-3"><small>Double path test: BASE_URL + 'repairs/technician_panel.php' = <code><?= htmlspecialchars(BASE_URL . 'repairs/technician_panel.php') ?></code></small></p>
    </div>
</body>
</html>
