<?php
/**
 * Rig N Dig - Technical Change Logs Viewer
 */
$adminTitle = 'Technical Change Logs';
require_once __DIR__ . '/includes/header.php';

$logFile = dirname(__DIR__) . '/admin_change_log.md';
$content = "No change log found.";

if (file_exists($logFile)) {
    $content = file_get_contents($logFile);
}

// Simple Markdown-ish parser for the dashboard
function parseLog($text) {
    // Escaping
    $text = htmlspecialchars($text);
    
    // Headers
    $text = preg_replace('/^# (.*)$/m', '<h1 class="text-3xl font-black text-white italic tracking-tighter uppercase mb-6 mt-8 border-b border-white/5 pb-4">$1</h1>', $text);
    $text = preg_replace('/^## (.*)$/m', '<h2 class="text-xl font-black text-orange-500 uppercase tracking-widest mt-10 mb-4 flex items-center gap-3"><span class="w-8 h-px bg-orange-500/30"></span>$1</h2>', $text);
    $text = preg_replace('/^### (.*)$/m', '<h3 class="text-lg font-bold text-white mt-6 mb-2">$1</h3>', $text);
    
    // Bold
    $text = preg_replace('/\*\*(.*?)\*\*/', '<strong class="text-white">$1</strong>', $text);
    
    // List items
    $text = preg_replace('/^\* (.*)$/m', '<li class="ml-4 mb-2 text-gray-400 flex items-start gap-3"><span class="text-orange-500 mt-1">▶</span><span>$1</span></li>', $text);
    
    // Code blocks
    $text = preg_replace('/`(.*?)`/', '<code class="bg-navy-800 px-1.5 py-0.5 rounded text-orange-300 font-mono text-xs">$1</code>', $text);
    
    // Horizontal rule
    $text = str_replace('---', '<hr class="my-10 border-white/5">', $text);

    return $text;
}
?>

<div class="max-w-4xl mx-auto">
    <div class="flex items-center justify-between mb-10">
        <div>
            <h1 class="text-4xl font-black text-white italic tracking-tighter uppercase">Evolution <span class="text-orange-500">Log</span></h1>
            <p class="text-xs text-gray-500 font-bold uppercase tracking-widest mt-2">Technical Registry of the Pioneer Suite Architecture</p>
        </div>
        <div class="flex gap-3">
            <a href="/admin_change_log.md" download class="btn-outline px-4 py-2 text-[10px] font-black uppercase tracking-widest">⬇️ Raw MD</a>
            <a href="updater.php" class="btn-primary px-4 py-2 text-[10px] font-black uppercase tracking-widest">🔄 Update Engine</a>
        </div>
    </div>

    <div class="card-dark p-8 md:p-12 relative overflow-hidden border-white/5">
        <!-- Abstract Decoration -->
        <div class="absolute top-0 right-0 p-10 opacity-[0.02] pointer-events-none">
            <svg class="w-64 h-64 text-orange-600" viewBox="0 0 100 100" fill="currentColor">
                <path d="M50 0L61.8 38.2H100L69.1 61.8L80.9 100L50 76.4L19.1 100L30.9 61.8L0 38.2H38.2L50 0Z" />
            </svg>
        </div>

        <div class="prose prose-invert max-w-none relative z-10">
            <ul class="list-none p-0">
                <?= parseLog($content) ?>
            </ul>
        </div>

        <div class="mt-20 pt-8 border-t border-white/5 text-center">
            <p class="text-[10px] text-gray-600 font-bold uppercase tracking-[0.3em]">Rig N Dig Industrial Solutions • Secure Technical Intelligence</p>
        </div>
    </div>
</div>


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