<?php
require_once '../src/config/db.php';
require_once '../src/includes/functions.php';
include '../src/includes/header.php';

$services = get_all_services($pdo);
?>

<!-- Page Header -->
<section class="page-header py-5 py-lg-6">
    <div class="container">
        <div class="text-center">
            <h1 class="display-4 fw-bolder text-white"><?php echo $t['nav_services']; ?></h1>
            <p class="lead text-white-50 mx-auto" style="max-width: 800px;"><?php echo $t['services_subtitle']; ?></p>
        </div>
    </div>
</section>

<section class="py-5 py-lg-6">
    <div class="container">
        <hr class="section-divider">
        <div class="row g-4">
            <?php 
            $serviceKeyMap = [
                'HDD Destruction' => ['title' => 'service_hdd_title', 'desc' => 'service_hdd_desc'],
                'SSD Destruction' => ['title' => 'service_ssd_title', 'desc' => 'service_ssd_desc'],
                'Mobile Device Destruction' => ['title' => 'service_mobile_title', 'desc' => 'service_mobile_desc'],
                'Confidential Document Destruction' => ['title' => 'service_documents_title', 'desc' => 'service_documents_desc'],
                'IT Asset Disposition (ITAD)' => ['title' => 'service_itad_title', 'desc' => 'service_itad_desc'],
                'Data Center Decommissioning' => ['title' => 'service_datacenter_title', 'desc' => 'service_datacenter_desc'],
                'Certificate of Destruction (CoD)' => ['title' => 'service_cod_title', 'desc' => 'service_cod_desc'],
            ];
            
            foreach ($services as $service): 
                $serviceKey = $serviceKeyMap[$service['name']] ?? null;
            ?>
                <div class="col-md-6 col-lg-3 d-flex">
                    <?php
                        $default_image = 'assets/img/default-service.png';
                        $image_path = !empty($service['image_url']) && file_exists(__DIR__ . '/' . $service['image_url'])
                                        ? $service['image_url']
                                        : $default_image;
                    ?>
                    <div class="service-card w-100 animated-card"><div class="service-card-image" style="background-image: url('<?php echo htmlspecialchars($image_path); ?>');"></div>
                        <div class="service-card-content">
                            <h3><?php echo htmlspecialchars($serviceKey && isset($t[$serviceKey['title']]) ? $t[$serviceKey['title']] : $service['name']); ?></h3>
                            <p><?php echo htmlspecialchars(mb_strimwidth($serviceKey && isset($t[$serviceKey['desc']]) ? $t[$serviceKey['desc']] : $service['description'], 0, 100, '...')); ?></p>
                        </div>
                    </div>
                </div>
            <?php endforeach; ?>
        </div>
    </div>
</section>

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