<?php
/**
 * Rig N Dig - Nexus API Console
 * Management and documentation for the Pioneer API Suite
 */
$adminTitle = 'Nexus API Console';
require_once __DIR__ . '/includes/header.php';

// Stats for the console
$totalEndpoints = 12; // Auth(3) + Products(2) + B2B(3) + System(2) + Verification(1) + Root(1)
$apiActive = file_exists(dirname(__DIR__) . '/api/v1/index.php');
$baseUrl = (SITE_URL ? rtrim(SITE_URL, '/') : 'http://' . $_SERVER['HTTP_HOST']) . '/api/v1';

// Sample Token for demonstration
$sampleToken = "1:" . hash_hmac('sha256', "1", APP_SECRET);
?>

<div class="max-w-6xl mx-auto">
    <div class="flex items-center justify-between mb-10">
        <div>
            <h1 class="text-4xl font-black text-white italic tracking-tighter uppercase">Nexus <span class="text-orange-500">API Console</span></h1>
            <p class="text-xs text-gray-500 font-bold uppercase tracking-widest mt-2">Pioneer Suite Universal Connectivity Layer</p>
        </div>
        <div class="flex gap-3">
            <div class="glass-panel px-4 py-2 flex items-center gap-3">
                <span class="flex h-3 w-3 relative">
                    <span class="animate-ping absolute inline-flex h-full w-full rounded-full bg-green-400 opacity-75"></span>
                    <span class="relative inline-flex rounded-full h-3 w-3 bg-green-500"></span>
                </span>
                <span class="text-[10px] font-black text-white uppercase tracking-widest">System Online</span>
            </div>
            <a href="/rigndig_v2.3.0_API_READY.zip" class="btn-primary px-4 py-2 text-[10px] font-black uppercase tracking-widest">⬇️ Download SDK Package</a>
        </div>
    </div>

    <!-- Overview Grid -->
    <div class="grid grid-cols-1 md:grid-cols-3 gap-6 mb-10">
        <div class="card-dark p-6 border-navy-700">
            <div class="text-xs text-gray-500 font-bold uppercase tracking-widest mb-4">API Architecture</div>
            <div class="text-3xl font-black text-white mb-2">RESTful v1.0</div>
            <div class="text-xs text-orange-500 font-bold italic">Stable Production Version</div>
        </div>
        <div class="card-dark p-6 border-navy-700">
            <div class="text-xs text-gray-500 font-bold uppercase tracking-widest mb-4">Connected Modules</div>
            <div class="text-3xl font-black text-white mb-2"><?= $totalEndpoints ?> Enpoints</div>
            <div class="text-xs text-gray-400 font-bold">Comprehensive Platform Coverage</div>
        </div>
        <div class="card-dark p-6 border-navy-700">
            <div class="text-xs text-gray-500 font-bold uppercase tracking-widest mb-4">Authentication</div>
            <div class="text-xl font-black text-white mb-2">Bearer Token (HMAC)</div>
            <div class="text-xs text-gray-400 font-bold">Secure SHA-256 Protocol</div>
        </div>
    </div>

    <!-- Main Console -->
    <div class="grid grid-cols-1 lg:grid-cols-12 gap-8">
        <!-- Documentation -->
        <div class="lg:col-span-8">
            <div class="card-dark overflow-hidden border-navy-700">
                <div class="p-6 border-b border-navy-700 bg-navy-800/50 flex items-center justify-between">
                    <h3 class="text-sm font-black text-white uppercase tracking-widest">Live Endpoint Registry</h3>
                    <div class="text-[10px] text-gray-500 font-bold">Base URL: <code class="text-orange-400"><?= $baseUrl ?></code></div>
                </div>
                <div class="divide-y divide-navy-700">
                    <?php
                    $endpoints = [
                        ['Auth / Login', 'POST', '/login.php', 'Authenticates user and returns persistent Bearer token.'],
                        ['Auth / Register', 'POST', '/auth/register.php', 'Creates new consumer account in the platform.'],
                        ['Auth / Profile', 'GET/POST', '/auth/profile.php', 'Securely manage user personal and corporate data.'],
                        ['Products / List', 'GET', '/products/list.php', 'Searchable, paginated technical asset catalog.'],
                        ['Products / Categories', 'GET', '/products/categories.php', 'List all industrial categories with asset counts.'],
                        ['Quotes / Submit', 'POST', '/quotes/submit.php', 'Trigger an RFQ transmission with custom specifications.'],
                        ['Quotes / History', 'GET', '/quotes/list.php', 'Full lifecycle tracking of RFQs, Estimates, and POs.'],
                        ['Orders / Tracking', 'GET', '/orders/track.php', 'Real-time manufacturing/sourcing milestone monitoring.'],
                        ['Vault / Verify', 'GET', '/certificates/verify.php', 'Instant verification of digital technical certs & MTRs.'],
                        ['System / Config', 'GET', '/config.php', 'Retrieve site-wide contact info and support channels.'],
                    ];
                    foreach ($endpoints as [$title, $verb, $path, $desc]):
                    ?>
                    <div class="p-6 hover:bg-navy-800/30 transition-colors">
                        <div class="flex items-center gap-4 mb-2">
                            <span class="px-2 py-0.5 rounded text-[9px] font-black uppercase tracking-widest <?= $verb === 'POST' ? 'bg-orange-600/20 text-orange-500 border border-orange-600/30' : 'bg-blue-600/20 text-blue-400 border border-blue-600/30' ?>"><?= $verb ?></span>
                            <h4 class="text-sm font-black text-white"><?= $title ?></h4>
                            <code class="text-xs text-gray-500 ml-auto"><?= $path ?></code>
                        </div>
                        <p class="text-xs text-gray-400 leading-relaxed"><?= $desc ?></p>
                    </div>
                    <?php endforeach; ?>
                </div>
            </div>
        </div>

        <!-- Sidebar -->
        <div class="lg:col-span-4 space-y-6">
            <div class="card-dark p-6 border-orange-600/20">
                <h3 class="text-xs font-black text-white uppercase tracking-widest mb-6 flex items-center gap-2">
                    <span class="text-orange-500">🛡️</span> Auth Token Blueprint
                </h3>
                <div class="bg-navy-950 p-4 rounded-xl border border-navy-700 mb-6 font-mono text-[10px] break-all text-orange-300">
                    Bearer <?= $sampleToken ?>
                </div>
                <p class="text-[10px] text-gray-500 leading-relaxed uppercase font-bold tracking-wider">
                    The Nexus API uses HMAC-SHA256 tokens. Tokens follow the format: <span class="text-white">USER_ID:HMAC_HASH</span>. Include this in the <span class="text-white">Authorization</span> header.
                </p>
            </div>

            <div class="card-dark p-6 border-navy-700">
                <h3 class="text-xs font-black text-white uppercase tracking-widest mb-6">Security Protocol</h3>
                <ul class="space-y-4">
                    <li class="flex items-start gap-3">
                        <span class="text-green-500 mt-0.5">✓</span>
                        <div class="text-[10px] text-gray-400 font-bold uppercase tracking-wider">TLS 1.3 Encryption Mandatory</div>
                    </li>
                    <li class="flex items-start gap-3">
                        <span class="text-green-500 mt-0.5">✓</span>
                        <div class="text-[10px] text-gray-400 font-bold uppercase tracking-wider">Rate Limiting Protection</div>
                    </li>
                    <li class="flex items-start gap-3">
                        <span class="text-green-500 mt-0.5">✓</span>
                        <div class="text-[10px] text-gray-400 font-bold uppercase tracking-wider">Secure Activity Logging</div>
                    </li>
                </ul>
            </div>

            <div class="card-dark p-6 bg-gradient-to-br from-orange-600 to-orange-700 border-none">
                <h3 class="text-xs font-black text-white uppercase tracking-widest mb-2 italic">Mobile SDK Ready</h3>
                <p class="text-[10px] text-orange-50 font-black leading-relaxed opacity-90">Your API update (v2.3.0) is staged and ready for the Android/iOS application rollout.</p>
                <div class="mt-4 flex items-center justify-between">
                    <div class="text-3xl">📱</div>
                    <a href="change-logs.php" class="text-[9px] font-black text-white border-b border-white border-opacity-30 uppercase tracking-widest">Read Change Log</a>
                </div>
            </div>
        </div>
    </div>
</div>

<?php require_once __DIR__ . '/includes/footer.php'; ?>
