<?php
declare(strict_types=1);

// PHP's built-in preview server routes every request through this file.
if (PHP_SAPI === 'cli-server') {
    $requestPath = rawurldecode((string)(parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH) ?: '/'));
    $publicRoot = realpath(__DIR__);
    $assetPath = realpath(__DIR__ . DIRECTORY_SEPARATOR . ltrim($requestPath, '/'));
    if ($publicRoot !== false && $assetPath !== false && is_file($assetPath) && str_starts_with($assetPath, $publicRoot . DIRECTORY_SEPARATOR) && preg_match('/\.(?:css|js|mjs|map|svg|png|jpe?g|webp|gif|ico|woff2?|ttf|otf)$/i', $assetPath)) {
        return false;
    }
}

require dirname(__DIR__) . '/app/bootstrap.php';
$config['request_base_path'] = $config['app_base_path'];
ob_start(static function (string $html) use (&$config): string {
    $base = rtrim((string)($config['app_base_path'] ?? ''), '/');
    if ($base === '') return $html;
    return preg_replace_callback("~\\b(href|src|action|poster|data-url)=([\"'])/(?!/)~i",
        static fn(array $m): string => $m[1] . '=' . $m[2] . $base . '/', $html) ?? $html;
});

header('X-Content-Type-Options: nosniff');
header('Referrer-Policy: strict-origin-when-cross-origin');
header('Permissions-Policy: camera=(), microphone=(), geolocation=()');
header('X-Frame-Options: DENY');
header('Content-Security-Policy: default-src \'self\'; img-src \'self\' https: data:; style-src \'self\' \'unsafe-inline\'; script-src \'self\'; font-src \'self\' data:; form-action \'self\'; frame-ancestors \'none\'; base-uri \'self\'');

function site_url(string $path = ''): string {
    global $config;
    $base = rtrim((string)($config['app_base_path'] ?? ''), '/');
    $path = '/' . ltrim($path, '/');
    if ($base !== '' && ($path === $base || str_starts_with($path, $base . '/'))) $path = substr($path, strlen($base)) ?: '/';
    return $config['app_url'] . $base . ($path === '/' ? '/' : $path);
}
function render_header(string $title, string $description, string $active = ''): void {
    global $config;
    $fullTitle = $title === 'Home' ? 'Asonsoft — Technology built for what comes next' : $title . ' | Asonsoft';
    $requestPath = parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH) ?: '/';
    $basePath = rtrim((string)($config['app_base_path'] ?? ''), '/');
    if ($basePath !== '' && ($requestPath === $basePath || str_starts_with($requestPath, $basePath . '/'))) $requestPath = substr($requestPath, strlen($basePath)) ?: '/';
    $canonical = site_url($requestPath);
    echo '<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1">';
    echo '<title>' . e($fullTitle) . '</title><meta name="description" content="' . e($description) . '">';
    echo '<meta name="theme-color" content="#ff3045"><meta property="og:type" content="website"><meta property="og:site_name" content="Asonsoft"><meta property="og:title" content="' . e($fullTitle) . '"><meta property="og:description" content="' . e($description) . '"><meta property="og:url" content="' . e($canonical) . '">';
    echo '<link rel="canonical" href="' . e($canonical) . '"><link rel="icon" href="/assets/images/asonsoft-mark.svg" type="image/svg+xml"><link rel="preload" href="/assets/css/site.css" as="style"><link rel="stylesheet" href="/assets/css/site.css">';
    echo '<script defer src="/assets/js/site.js"></script></head><body>';
    echo '<a class="skip-link" href="#main">Skip to content</a><header class="site-header"><div class="container nav-wrap">';
    echo '<a class="brand" href="/" aria-label="Asonsoft home"><img src="/assets/images/asonsoft-emblem.webp" alt="" width="58" height="58"><span>ASONSOFT</span></a>';
    echo '<button class="menu-toggle" type="button" aria-expanded="false" aria-controls="primary-nav"><span></span><span></span><span></span><b class="sr-only">Toggle navigation</b></button>';
    echo '<nav class="primary-nav" id="primary-nav" aria-label="Primary navigation">';
    $items = ['Products'=>'/products','Services'=>'/services','Developers'=>'/developers','Downloads'=>'/downloads','About'=>'/about','Insights'=>'/insights'];
    foreach ($items as $label=>$href) {
        $current = ($active === $label) ? ' aria-current="page"' : '';
        echo '<a href="' . e($href) . '"' . $current . '>' . e($label) . '</a>';
    }
    echo '<a class="nav-contact" href="/contact">Let’s talk <span aria-hidden="true">↗</span></a></nav></div></header><main id="main">';
}
function render_footer(): void {
    $publicEmail = e(site_setting('public_email','asonsoft@asonsoft.africa'));
    $tagline = e(site_setting('company_tagline','Driven by ambition to break barriers into the future.'));
    echo '</main><footer class="site-footer"><div class="container footer-main"><div class="footer-brand"><a class="brand" href="/"><img src="/assets/images/asonsoft-emblem.webp" alt="" width="52" height="52"><span>ASONSOFT</span></a><p>' . $tagline . '</p></div>';
    echo '<div><h2>Explore</h2><a href="/products">Products</a><a href="/services">Services</a><a href="/developers">Developers</a><a href="/downloads">Downloads</a><a href="/insights">Insights</a></div>';
    echo '<div><h2>Company</h2><a href="/about">About Asonsoft</a><a href="/contact">Contact</a><a href="/privacy">Privacy</a><a href="/terms">Terms</a></div>';
    echo '<div><h2>Connect</h2><a href="mailto:' . $publicEmail . '">' . $publicEmail . '</a><span class="footer-note">Building from Africa. Thinking beyond boundaries.</span></div></div>';
    echo '<div class="container footer-bottom"><span>© ' . date('Y') . ' Asonsoft. All rights reserved.</span><span>Independent software & systems engineering.</span></div></footer></body></html>';
}
function section_heading(string $eyebrow, string $title, string $copy = ''): void {
    echo '<div class="section-heading"><span class="eyebrow">' . e($eyebrow) . '</span><h2>' . e($title) . '</h2>';
    if ($copy !== '') echo '<p>' . e($copy) . '</p>';
    echo '</div>';
}
function product_card(array $p): void {
    $slug = e($p['slug'] ?? '');
    echo '<article class="product-card"><div class="card-topline"><span class="product-symbol">' . strtoupper(substr((string)($p['title'] ?? 'A'),0,1)) . '</span><span class="status-pill">' . e($p['display_status'] ?? 'In development') . '</span></div>';
    if (!empty($p['image_url'])) echo '<img class="product-card-image" src="' . e($p['image_url']) . '" alt="' . e($p['title'] ?? 'Product image') . '" loading="lazy">';
    echo '<span class="card-kicker">' . e($p['category'] ?? 'Asonsoft product') . '</span><h3><a href="/products/' . $slug . '">' . e($p['title'] ?? '') . '</a></h3><p>' . e($p['excerpt'] ?? '') . '</p><a class="text-link" href="/products/' . $slug . '">Explore product <span>↗</span></a></article>';
}

$path = parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH) ?: '/';
$appBasePath = rtrim((string)($config['app_base_path'] ?? ''), '/');
if ($appBasePath !== '' && ($path === $appBasePath || str_starts_with($path, $appBasePath . '/'))) $path = substr($path, strlen($appBasePath)) ?: '/';
$path = '/' . trim($path, '/');
if ($path === '//') $path = '/';
$segments = array_values(array_filter(explode('/', trim($path, '/'))));
$page = $segments[0] ?? 'home';
$slug = $segments[1] ?? '';

if ($path === '/robots.txt') {
    header('Content-Type: text/plain; charset=utf-8');
    echo "User-agent: *\nAllow: /\nDisallow: /admin/\nSitemap: " . site_url('sitemap.xml') . "\n";
    exit;
}
if ($path === '/sitemap.xml') {
    header('Content-Type: application/xml; charset=utf-8');
    $urls = ['','products','services','developers','downloads','about','insights','contact','privacy','terms'];
    echo '<?xml version="1.0" encoding="UTF-8"?>';
    echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
    foreach ($urls as $url) echo '<url><loc>' . e(site_url($url)) . '</loc></url>';
    foreach (['product','service','article'] as $type) foreach (content_entries($type,100) as $entry) {
        $base = $type === 'product' ? 'products' : ($type === 'service' ? 'services' : 'insights');
        echo '<url><loc>' . e(site_url($base . '/' . ($entry['slug'] ?? ''))) . '</loc></url>';
    }
    echo '</urlset>';
    exit;
}

if ($page === 'contact' && request_is_post()) {
    if (!verify_csrf()) { http_response_code(419); $contactError = 'Your session expired. Refresh the page and try again.'; }
    elseif (!empty($_POST['website'] ?? '')) { redirect_to('/contact?sent=1'); }
    else {
        $name = plain_text((string)($_POST['name'] ?? ''),160);
        $email = trim((string)($_POST['email'] ?? ''));
        $organisation = plain_text((string)($_POST['organisation'] ?? ''),190);
        $kind = plain_text((string)($_POST['enquiry_type'] ?? 'general'),80);
        $subject = plain_text((string)($_POST['subject'] ?? ''),220);
        $message = plain_text((string)($_POST['message'] ?? ''),5000);
        $last = (int)($_SESSION['_last_enquiry'] ?? 0);
        if (time() - $last < 30) $contactError = 'Please wait a moment before sending another enquiry.';
        elseif ($name === '' || !filter_var($email,FILTER_VALIDATE_EMAIL) || strlen($message) < 10) $contactError = 'Please provide your name, a valid email address and a message of at least 10 characters.';
        else {
            $pdo = db();
            if (!$pdo) $contactError = 'The enquiry service is temporarily unavailable. Please email asonsoft@asonsoft.africa instead.';
            else {
                try {
                    $stmt = $pdo->prepare('INSERT INTO enquiries (name,email,organisation,enquiry_type,subject,message,ip_hash) VALUES (?,?,?,?,?,?,?)');
                    $ip = (string)($_SERVER['REMOTE_ADDR'] ?? '');
                    $stmt->execute([$name,$email,$organisation,$kind,$subject,$message,hash('sha256',$ip . (string)($_SERVER['HTTP_USER_AGENT'] ?? ''))]);
                    $_SESSION['_last_enquiry'] = time();
                    global $config;
                    if (!empty($config['mail_to']) && function_exists('mail')) {
                        $subjectLine = preg_replace('/[\r\n]+/', ' ', $subject) ?? $subject;
                        $safeSubject = 'Website enquiry: ' . ($subjectLine !== '' ? $subjectLine : $kind);
                        $mailFrom = filter_var((string)$config['mail_from'], FILTER_VALIDATE_EMAIL) ? (string)$config['mail_from'] : 'asonsoft@asonsoft.africa';
                        $headers = 'From: ' . $mailFrom . "\r\n" . 'Reply-To: ' . $email . "\r\n" . 'Content-Type: text/plain; charset=UTF-8';
                        @mail($config['mail_to'], $safeSubject, "Name: {$name}\nEmail: {$email}\nOrganisation: {$organisation}\nType: {$kind}\n\n{$message}", $headers);
                    }
                    redirect_to('/contact?sent=1');
                } catch (Throwable $e) { ason_log('Enquiry save failed: ' . $e->getMessage()); $contactError = 'We could not save your enquiry. Please try again later.'; }
            }
        }
    }
}

if ($page === 'home') {
    render_header('Home','Asonsoft builds software, digital platforms and technology systems with ambition and engineering discipline.');
    $heroHeading = e(site_setting('hero_heading','Technology built for'));
    $heroHighlight = e(site_setting('hero_highlight','what comes next.'));
    $heroLede = e(site_setting('hero_lede','Driven by ambition to break barriers into the future. We engineer software, platforms and intelligent systems designed to move ideas into impact.'));
    echo '<section class="hero"><div class="hero-grid"></div><div class="container hero-layout"><div class="hero-copy"><span class="eyebrow"><i></i> Independent technology company</span><h1>' . $heroHeading . ' <em>' . $heroHighlight . '</em></h1><p class="hero-lede">' . $heroLede . '</p><div class="hero-actions"><a class="button button-primary" href="/products">Explore our ecosystem <span>↗</span></a><a class="button button-quiet" href="/contact">Start a conversation</a></div><div class="hero-proof"><span class="proof-line"></span><span>Ambition in vision. Precision in execution.</span></div></div><div class="hero-art" aria-label="Abstract Asonsoft technology visual"><div class="orbit orbit-one"></div><div class="orbit orbit-two"></div><div class="core-mark"><span>AS</span><small>ASONSOFT</small></div><div class="float-tag tag-one"><span class="tag-dot"></span> SOFTWARE ENGINEERING</div><div class="float-tag tag-two"><span class="tag-dot"></span> SYSTEMS & INTELLIGENCE</div><div class="art-cross cross-one">+</div><div class="art-cross cross-two">+</div></div></div><div class="hero-bottom container"><span>01 / BUILD WITH PURPOSE</span><span>GHANA · AFRICA · EVERYWHERE</span></div></section>';
    echo '<section class="intro-section section-pad"><div class="container intro-grid"><div><span class="eyebrow">Who we are</span><h2>Ambition is the starting point.<br><em>Engineering makes it real.</em></h2></div><div class="intro-copy"><p>Asonsoft is a technology company focused on designing and building useful software, digital infrastructure and connected experiences.</p><p>We believe meaningful innovation comes from understanding hard problems, building with intent and caring about the details that make technology dependable.</p><a class="text-link" href="/about">Discover Asonsoft <span>↗</span></a></div></div></section>';
    echo '<section class="products-section section-pad"><div class="container"><div class="section-row"><div>'; section_heading('The ecosystem','Ideas taking shape. Systems taking form.','A growing portfolio of products and technologies connected by one engineering vision.'); echo '</div><a class="text-link desktop-link" href="/products">View all products <span>↗</span></a></div><div class="product-grid">';
    foreach (array_slice(default_products(),0,3) as $p) product_card($p);
    echo '</div><a class="text-link mobile-link" href="/products">View all products <span>↗</span></a></div></section>';
    echo '<section class="capabilities-section section-pad"><div class="container capabilities-layout"><div><span class="eyebrow">What we work on</span><h2>From the first line of code to the <em>whole system.</em></h2><p class="muted-copy">We look beyond isolated features to the architecture, integrations and experiences that make products work together.</p></div><div class="capability-list"><div><span>01</span><h3>Software & platform engineering</h3><p>Digital products built for clarity, scale and maintainability.</p></div><div><span>02</span><h3>Enterprise & institutional systems</h3><p>Connected workflows, portals and operational experiences.</p></div><div><span>03</span><h3>AI, data & knowledge systems</h3><p>Intelligent products grounded in useful, structured information.</p></div><div><span>04</span><h3>Integrations & automation</h3><p>Services and systems designed to work together reliably.</p></div></div></div></section>';
    echo '<section class="principles-section section-pad"><div class="container"><span class="eyebrow">How we think</span><div class="principle-grid"><article><span>01</span><h3>Build with purpose</h3><p>Every product starts with a problem worth solving.</p></article><article><span>02</span><h3>Engineer for quality</h3><p>Strong foundations matter as much as visible features.</p></article><article><span>03</span><h3>Think beyond limits</h3><p>We are ambitious about what technology can make possible.</p></article></div></div></section>';
    echo '<section class="cta-band"><div class="container cta-inner"><div><span class="eyebrow">Have an idea or a challenge?</span><h2>Let’s build something<br><em>that moves things forward.</em></h2></div><a class="button button-light" href="/contact">Talk to Asonsoft <span>↗</span></a></div></section>';
    render_footer();
} elseif ($page === 'products' && $slug === '') {
    render_header('Products & Solutions','Explore Asonsoft products, platforms and technology initiatives.','Products');
    echo '<section class="page-hero"><div class="container"><span class="eyebrow">The Asonsoft ecosystem</span><h1>Products & <em>solutions.</em></h1><p>Distinct products. One engineering vision. Explore the systems we are building and the ideas behind them.</p></div></section><section class="section-pad"><div class="container product-grid product-grid-wide">';
    foreach (content_entries('product',50) as $p) product_card($p);
    echo '</div></section><section class="cta-band"><div class="container cta-inner"><div><span class="eyebrow">Product enquiries</span><h2>Looking for a solution<br><em>or a collaboration?</em></h2></div><a class="button button-light" href="/contact">Contact our team <span>↗</span></a></div></section>';
    render_footer();
} elseif ($page === 'products' && $slug !== '') {
    $entry = content_entry('product',$slug);
    if (!$entry) { http_response_code(404); render_header('Product not found','The requested product could not be found.'); echo '<section class="page-hero"><div class="container"><h1>Product <em>not found.</em></h1><a class="text-link" href="/products">Back to products ↗</a></div></section>'; render_footer(); }
    else { render_header((string)$entry['title'],(string)($entry['seo_description'] ?: $entry['excerpt']),'Products'); echo '<section class="detail-hero"><div class="container"><a class="back-link" href="/products">← All products</a><span class="eyebrow">' . e($entry['type'] ?? 'Asonsoft product') . '</span><h1>' . e($entry['title']) . '<em>.</em></h1><span class="status-pill">' . e($entry['status'] ?? 'In development') . '</span><p class="detail-lede">' . e($entry['excerpt'] ?? '') . '</p><div class="detail-body">' . nl2br(e($entry['body'] ?? '')) . '</div><a class="button button-primary" href="/contact">Enquire about this product <span>↗</span></a></div></section>'; render_footer(); }
} elseif ($page === 'services') {
    render_header('Services & Capabilities','Software engineering, enterprise platforms, AI systems and integrations.','Services');
    echo '<section class="page-hero"><div class="container"><span class="eyebrow">Capabilities</span><h1>Technology with<br><em>intent and discipline.</em></h1><p>Our capabilities span product engineering, connected systems and intelligent digital experiences.</p></div></section><section class="section-pad"><div class="container service-grid">';
    foreach (content_entries('service',50) as $i=>$s) echo '<article class="service-card"><span class="service-number">0' . ($i+1) . '</span><h2>' . e($s['title']) . '</h2><p>' . e($s['excerpt']) . '</p><div class="service-rule"></div></article>';
    echo '</div></section><section class="cta-band"><div class="container cta-inner"><div><span class="eyebrow">Work with us</span><h2>Let’s understand<br><em>what you need to build.</em></h2></div><a class="button button-light" href="/contact">Discuss a project <span>↗</span></a></div></section>'; render_footer();
} elseif ($page === 'developers') {
    render_header('Developers','Developer resources, APIs and integration information from Asonsoft.','Developers');
    echo '<section class="page-hero"><div class="container"><span class="eyebrow">For builders</span><h1>Build with the<br><em>Asonsoft ecosystem.</em></h1><p>Our developer space is where APIs, integration guides, SDKs and technical references will live as products become ready for external developers.</p><a class="button button-primary" href="https://dev.asonsoft.africa">Visit developer hub <span>↗</span></a></div></section><section class="section-pad"><div class="container developer-grid"><article><span class="eyebrow">01 / Documentation</span><h2>Clear technical references.</h2><p>Product guides, API references and integration instructions will be published alongside supported releases.</p></article><article><span class="eyebrow">02 / Integrations</span><h2>Connect systems with confidence.</h2><p>We aim for predictable interfaces, secure credentials and versioned integration contracts.</p></article><article><span class="eyebrow">03 / Community</span><h2>Build beyond the product.</h2><p>Developer programmes and contribution pathways will be announced when available.</p></article></div></section>'; render_footer();
} elseif ($page === 'about') {
    render_header('About Asonsoft','Learn about Asonsoft, its vision, mission and engineering philosophy.','About');
    echo '<section class="page-hero"><div class="container"><span class="eyebrow">About Asonsoft</span><h1>Driven by ambition<br>to <em>break barriers.</em></h1><p>We are building a technology company around a simple belief: ambitious ideas deserve thoughtful engineering and products that work in the real world.</p></div></section><section class="section-pad"><div class="container about-grid"><div><span class="eyebrow">Our vision</span><h2>Break new heights through <em>high-quality technology.</em></h2></div><div><p>Asonsoft exists to create software, services and systems that open new possibilities for people, businesses and institutions.</p><p>Our ambition is not limited to one product category. We explore the foundations of modern computing, the platforms organisations rely on, and the intelligent tools that help people learn, create and connect.</p><p>We are building from Africa with an international outlook and a commitment to engineering quality.</p></div></div></section><section class="principles-section section-pad"><div class="container"><span class="eyebrow">Our philosophy</span><div class="principle-grid"><article><span>01</span><h3>Ambition</h3><p>Look beyond current limitations and pursue meaningful progress.</p></article><article><span>02</span><h3>Quality</h3><p>Build solid foundations, protect trust and care about details.</p></article><article><span>03</span><h3>Progress</h3><p>Turn research, experimentation and ideas into useful products.</p></article></div></div></section>'; render_footer();
} elseif ($page === 'insights') {
    $article = $slug !== '' ? content_entry('article',$slug) : null;
    if ($slug !== '' && !$article) { http_response_code(404); render_header('Article not found','The requested article could not be found.','Insights'); echo '<section class="page-hero"><div class="container"><h1>Not found.</h1><a class="text-link" href="/insights">Back to insights</a></div></section>'; }
    elseif ($article) { render_header((string)$article['title'],(string)($article['seo_description'] ?: $article['excerpt']),'Insights'); echo '<section class="detail-hero"><div class="container"><a class="back-link" href="/insights">← All insights</a><span class="eyebrow">Asonsoft insights</span><h1>' . e($article['title']) . '</h1><p class="detail-lede">' . e($article['excerpt']) . '</p><div class="detail-body">' . nl2br(e($article['body'])) . '</div></div></section>'; }
    else { render_header('Insights','Company news, technical articles and ideas from Asonsoft.','Insights'); echo '<section class="page-hero"><div class="container"><span class="eyebrow">Notes from the work</span><h1>Ideas, updates &<br><em>engineering insights.</em></h1><p>Perspectives on the products we build, the systems we study and the technology shaping what comes next.</p></div></section><section class="section-pad"><div class="container article-list">';
        $articles = content_entries('article',50);
        if (!$articles) echo '<div class="empty-state"><span class="eyebrow">Coming into focus</span><h2>Our first insights are being prepared.</h2><p>Company news and technical writing will appear here as they are published.</p></div>';
        foreach ($articles as $a) echo '<article><span class="card-kicker">INSIGHT</span><h2><a href="/insights/' . e($a['slug']) . '">' . e($a['title']) . '</a></h2><p>' . e($a['excerpt']) . '</p><a class="text-link" href="/insights/' . e($a['slug']) . '">Read article ↗</a></article>';
        echo '</div></section>'; }
    render_footer();
 } elseif ($page === 'downloads') {
    render_header('Downloads','Official Asonsoft software, product releases, documents and developer resources.','Downloads');
    echo '<section class="page-hero"><div class="container"><span class="eyebrow">Asonsoft resources</span><h1>Downloads & <em>releases.</em></h1><p>Official files and resources published by Asonsoft. Verify the product, version and release notes before installing software.</p></div></section><section class="section-pad"><div class="container download-grid">';
    $downloadRows = [];
    $downloadPdo = db();
    if ($downloadPdo) {
        try { $downloadRows = $downloadPdo->query("SELECT slug,title,description,category,version,original_filename,file_size,created_at FROM downloads WHERE status='published' ORDER BY published_at DESC, created_at DESC LIMIT 100")->fetchAll(); }
        catch (Throwable $e) { ason_log('Public downloads lookup failed: ' . $e->getMessage()); }
    }
    if (!$downloadRows) echo '<div class="empty-state"><span class="eyebrow">Release library</span><h2>Downloads are being prepared.</h2><p>Official Asonsoft downloads will appear here when they are published.</p></div>';
    foreach ($downloadRows as $item) {
        $size = (int)$item['file_size'];
        $sizeLabel = $size >= 1073741824 ? number_format($size / 1073741824, 2) . ' GB' : ($size >= 1048576 ? number_format($size / 1048576, 1) . ' MB' : number_format($size / 1024, 0) . ' KB');
        $downloadUrl = site_url('download.php?slug=' . rawurlencode((string)$item['slug']));
        echo '<article class="download-card"><div class="download-card-top"><span class="download-icon">↓</span><span class="download-category">' . e($item['category'] ?: 'Asonsoft resource') . '</span></div><h2>' . e($item['title']) . '</h2><p>' . e($item['description']) . '</p><div class="download-meta"><span>' . e($item['version'] ?: 'Release') . '</span><span>' . e(strtoupper(pathinfo((string)$item['original_filename'], PATHINFO_EXTENSION))) . ' · ' . e($sizeLabel) . '</span></div><a class="button button-primary" href="' . e($downloadUrl) . '">Download file <span>↓</span></a></article>';
    }
    echo '</div></section>';
    render_footer();
} elseif ($page === 'contact') {
    render_header('Contact Asonsoft','Contact Asonsoft for business enquiries, product questions and partnerships.','');
    echo '<section class="page-hero"><div class="container"><span class="eyebrow">Contact</span><h1>Good work begins<br>with a <em>conversation.</em></h1><p>Tell us what you are working on, what you need, or how you would like to collaborate.</p></div></section><section class="section-pad"><div class="container contact-grid"><div class="contact-aside"><span class="eyebrow">Reach Asonsoft</span><h2>Let’s make the next step <em>clear.</em></h2><p>For general enquiries, partnerships and product information, send us a message or email directly.</p><a class="contact-email" href="mailto:' . e(site_setting('public_email','asonsoft@asonsoft.africa')) . '">' . e(site_setting('public_email','asonsoft@asonsoft.africa')) . ' ↗</a><div class="contact-detail"><span>BASE</span><strong>Ghana · Africa</strong></div><div class="contact-detail"><span>RESPONSE</span><strong>We aim to respond as soon as practical.</strong></div></div><div class="form-panel">';
    if (isset($_GET['sent'])) echo '<div class="alert alert-success" role="status">Thank you. Your enquiry has been received.</div>';
    if (!empty($contactError)) echo '<div class="alert alert-error" role="alert">' . e($contactError) . '</div>';
    echo '<form method="post" action="/contact" class="contact-form">' . csrf_field() . '<div class="trap-field" aria-hidden="true"><label>Leave this field empty<input type="text" name="website" tabindex="-1" autocomplete="off"></label></div><div class="form-row"><label>Your name<input name="name" required maxlength="160" autocomplete="name" placeholder="Full name"></label><label>Email address<input type="email" name="email" required maxlength="190" autocomplete="email" placeholder="you@example.com"></label></div><label>Organisation <span class="optional">Optional</span><input name="organisation" maxlength="190" autocomplete="organization" placeholder="Company or institution"></label><div class="form-row"><label>Enquiry type<select name="enquiry_type"><option value="general">General enquiry</option><option value="product">Product information</option><option value="project">Project / services</option><option value="partnership">Partnership</option><option value="developer">Developer enquiry</option></select></label><label>Subject<input name="subject" maxlength="220" placeholder="What is this about?"></label></div><label>Your message<textarea name="message" required minlength="10" maxlength="5000" rows="6" placeholder="Tell us a little about your enquiry..."></textarea></label><button class="button button-primary" type="submit">Send enquiry <span>↗</span></button><p class="form-note">Your information is used only to respond to your enquiry. See our <a href="/privacy">privacy policy</a>.</p></form></div></div></section>';
    render_footer();
} elseif ($page === 'privacy' || $page === 'terms') {
    $isPrivacy = $page === 'privacy';
    $title = $isPrivacy ? 'Privacy policy' : 'Terms of use';
    render_header($title,$isPrivacy ? 'How Asonsoft handles website enquiry information.' : 'Terms for using the Asonsoft corporate website.');
    echo '<section class="page-hero"><div class="container"><span class="eyebrow">Legal</span><h1>' . ($isPrivacy ? 'Privacy <em>policy.</em>' : 'Terms of <em>use.</em>') . '</h1><p>Last updated: November 2026</p></div></section><section class="section-pad"><div class="container legal-copy">';
    if ($isPrivacy) {
        echo '<h2>Information we collect</h2><p>When you submit the contact form, we collect the details you choose to provide, such as your name, email address, organisation and message. Basic technical information may be processed to protect the service from abuse.</p><h2>How we use information</h2><p>We use enquiry information to respond to requests, manage business communications and protect the website. We do not sell personal information.</p><h2>Retention and security</h2><p>Enquiry records are retained only as long as reasonably required for communication, business or legal purposes. We apply access controls and reasonable technical safeguards.</p><h2>Your choices</h2><p>You may request access, correction or deletion of personal information by contacting <a href="mailto:asonsoft@asonsoft.africa">asonsoft@asonsoft.africa</a>, subject to applicable legal requirements.</p><h2>Third-party services</h2><p>Links to external sites are provided for convenience. Their privacy practices are governed by their own policies.</p>';
    } else {
        echo '<h2>Website information</h2><p>This website provides general information about Asonsoft, its products, capabilities and initiatives. Product descriptions and availability may change as development progresses.</p><h2>No service guarantee</h2><p>Unless a separate written agreement states otherwise, website content is provided for general information and does not create a service-level commitment or commercial contract.</p><h2>Intellectual property</h2><p>Unless otherwise indicated, Asonsoft names, marks, text and original materials are owned by or licensed to Asonsoft. Do not copy or use them in a way that suggests endorsement or ownership.</p><h2>External links</h2><p>We are not responsible for third-party websites or services linked from this site.</p><h2>Contact</h2><p>Questions about these terms can be sent to <a href="mailto:asonsoft@asonsoft.africa">asonsoft@asonsoft.africa</a>.</p>';
    }
    echo '</div></section>'; render_footer();
} else {
    $customPage = content_entry('page',$page);
    if ($customPage) {
        render_header((string)$customPage['title'],(string)($customPage['seo_description'] ?: $customPage['excerpt']));
        echo '<section class="detail-hero"><div class="container"><span class="eyebrow">Asonsoft</span><h1>' . e($customPage['title']) . '</h1><p class="detail-lede">' . e($customPage['excerpt'] ?? '') . '</p><div class="detail-body">' . nl2br(e($customPage['body'] ?? '')) . '</div></div></section>';
        render_footer();
    } else {
        http_response_code(404);
        render_header('Page not found','The requested page could not be found.');
        echo '<section class="page-hero"><div class="container"><span class="eyebrow">404 / Not found</span><h1>This page has<br><em>moved beyond reach.</em></h1><p>The address may be incorrect, or the page may no longer exist.</p><a class="button button-primary" href="/">Return home ↗</a></div></section>';
        render_footer();
    }
}
