<?php
require_once __DIR__ . '/functions.php';
$siteName = get_setting('site_name', 'Tumaini Cyber');
$siteAbout = get_setting('site_about', 'At Tumaini Cyber, we bridge the gap between people and technology. From essential government services to advanced web development, we simplify digital processes and help you stay ahead in a fast-moving digital world.');
$siteWhatsapp = get_setting('site_whatsapp', '+254759607619');
$whatsappLink = preg_replace('/[^0-9]/', '', $siteWhatsapp);
$slides = pdo()->query("SELECT * FROM hero_slides WHERE status = 'Published' OR status IS NULL ORDER BY sort_order, id")->fetchAll();
$teamMembers = pdo()->query("SELECT * FROM team_members WHERE status = 'Published' OR status IS NULL ORDER BY sort_order, id")->fetchAll();
$featuredProjects = pdo()->query('SELECT pp.*, pc.name AS category_name FROM portfolio_projects pp LEFT JOIN portfolio_categories pc ON pp.category_id = pc.id WHERE pp.status = "Published" ORDER BY pp.created_at DESC LIMIT 3')->fetchAll();
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?= clean($siteName) ?></title>
    <meta name="description" content="Smart digital solutions for modern businesses from Tumaini Cyber.">
    <link rel="stylesheet" href="<?= BASE_URL ?>assets/css/style.css">
    <?php $favicon = get_setting('site_favicon'); ?>
    <?php if (!empty($favicon)): ?>
        <link rel="icon" href="<?= BASE_URL ?><?= UPLOAD_URL ?>/<?= clean($favicon) ?>" type="image/png">
    <?php endif; ?>
</head>
<body>
<?php include __DIR__ . '/includes/header.php'; ?>
<section class="hero hero-full">
    <div class="hero-visual">
        <?php if (!empty($slides)): ?>
            <?php foreach ($slides as $index => $slide): ?>
                <div class="hero-slide<?= $index === 0 ? ' active' : '' ?>" style="background-image:url('<?= BASE_URL . UPLOAD_URL . '/' . clean($slide['path']) ?>')">
                    <div class="hero-slide-overlay position-<?= clean($slide['title_position'] ?? 'center-left') ?>">
                        <?php if (!empty($slide['title'])): ?>
                            <h2 style="color: <?= clean($slide['title_color'] ?? '#ffffff') ?>; font-size: <?= clean($slide['title_font_size'] ?? '3rem') ?>;"><?= clean($slide['title']) ?></h2>
                        <?php endif; ?>
                        <?php if (!empty($slide['caption'])): ?>
                            <p><?= clean($slide['caption']) ?></p>
                        <?php endif; ?>
                        <div class="hero-actions">
                            <?php if (!empty($slide['button_1_text'])): ?>
                                <a class="btn btn-primary hero-slide-btn" href="<?= clean($slide['button_1_url'] ?: '#') ?>"><?= clean($slide['button_1_text']) ?></a>
                            <?php endif; ?>
                            <?php if (!empty($slide['button_2_text'])): ?>
                                <a class="btn btn-secondary hero-slide-btn" href="<?= clean($slide['button_2_url'] ?: '#') ?>"><?= clean($slide['button_2_text']) ?></a>
                            <?php endif; ?>
                        </div>
                    </div>
                </div>
            <?php endforeach; ?>
            <div class="hero-controls">
                <button class="hero-prev">⟨</button>
                <button class="hero-next">⟩</button>
            </div>
        <?php else: ?>
            <div class="hero-slide active fallback-hero"></div>
        <?php endif; ?>
    </div>
</section>
<main class="page-shell">
    <section class="page-section">
        <div class="section-title">Our Core Services</div>
        <p class="section-subtitle">Practical digital services built to help you stay connected, secure, and visible online.</p>
        <div class="grid service-grid">
            <article class="card">
                <h3>Government & eCitizen Services</h3>
                <p>Assistance with official services, eCitizen payments, and government digital transactions.</p>
            </article>
            <article class="card">
                <h3>Web Design & Development</h3>
                <p>Modern websites and web applications designed for usability, speed, and conversion.</p>
            </article>
            <article class="card">
                <h3>IT Support & Cyber Services</h3>
                <p>Secure IT support, cyber protection, and ongoing system maintenance for peace of mind.</p>
            </article>
            <article class="card">
                <h3>Graphic Design & Branding</h3>
                <p>Design and branding that help your company communicate clearly and professionally.</p>
            </article>
            <article class="card">
                <h3>Printing & Documentation</h3>
                <p>Document preparation, printing, and delivery services for business and individual needs.</p>
            </article>
            <article class="card">
                <h3>Digital Marketing Solutions</h3>
                <p>Campaigns and digital strategy to grow your audience and strengthen your online presence.</p>
            </article>
        </div>
    </section>

    <section class="page-section">
        <div class="section-title">Featured portfolio</div>
        <p class="section-subtitle">Recent projects demonstrating our approach to design, engineering, and security.</p>
        <?php if (empty($featuredProjects)): ?>
            <div class="message-box">No featured portfolio items are available yet.</div>
        <?php else: ?>
            <div class="grid project-grid">
                <?php foreach ($featuredProjects as $project): ?>
                    <article class="project-card">
                        <div class="card-body">
                            <span class="card-badge"><?= clean($project['category_name'] ?: 'Project') ?></span>
                            <h3><?= clean($project['title']) ?></h3>
                            <p><?= clean(substr(strip_tags($project['description']), 0, 140)) ?>…</p>
                            <a class="btn btn-primary" href="project-details.php?id=<?= $project['id'] ?>">View project</a>
                        </div>
                    </article>
                <?php endforeach; ?>
            </div>
        <?php endif; ?>
    </section>

    <section class="page-section">
        <div class="section-title">Trusted by clients</div>
        <p class="section-subtitle">We deliver practical solutions that local businesses and organizations rely on.</p>
        <div class="grid testimonial-grid">
            <article class="testimonial-card">
                <p>“Tumaini Cyber made our eCitizen application process easy and fast. Their support is dependable and clear.”</p>
                <strong>— Esther K., Nairobi</strong>
            </article>
            <article class="testimonial-card">
                <p>“The website they built for our company looks professional and performs well across devices.”</p>
                <strong>— James M., SME Owner</strong>
            </article>
            <article class="testimonial-card">
                <p>“We appreciate their quick response on IT support and the confidentiality they maintain with our data.”</p>
                <strong>— Grace N., Corporate Client</strong>
            </article>
        </div>
    </section>

    <section class="page-section">
        <div class="section-title">Meet our team</div>
        <p class="section-subtitle">Experienced professionals who build products, protect systems, and deliver growth.</p>
        <?php if (!empty($teamMembers)): ?>
            <div class="grid team-grid">
                <?php foreach ($teamMembers as $member): ?>
                    <article class="team-card">
                        <?php if (!empty($member['photo'])): ?>
                            <div class="team-avatar" style="background-image:url('<?= BASE_URL . UPLOAD_URL . '/' . clean($member['photo']) ?>')"></div>
                        <?php else: ?>
                            <div class="team-avatar team-avatar-empty"><?= strtoupper(substr(clean($member['name']), 0, 1)) ?></div>
                        <?php endif; ?>
                        <h3><?= clean($member['name']) ?></h3>
                        <p><?= clean($member['title']) ?></p>
                    </article>
                <?php endforeach; ?>
            </div>
        <?php else: ?>
            <div class="message-box">No team members have been added yet.</div>
        <?php endif; ?>
    </section>

    <section class="section-banner">
        <div>
            <h2>Fast, reliable, and secure digital services for your business</h2>
            <p>Whether you need eCitizen support, website development, or cyber protection, Tumaini Cyber delivers trusted solutions.</p>
        </div>
        <a class="btn btn-primary" href="quote.php">Request a quote</a>
    </section>
</main>
<?php include __DIR__ . '/includes/footer.php'; ?>
<script src="<?= BASE_URL ?>assets/js/site.js"></script>
<script src="<?= BASE_URL ?>assets/js/hero.js"></script>
</body>
</html>
