<?php
require_once __DIR__ . '/servicii-data.php';

$slug = isset($_GET['serviciu']) ? $_GET['serviciu'] : '';

if (!isset($servicii[$slug])) {
    // Invalid slug — redirect to services index, preserving language
    header('Location: ' . langurl(['pagina' => 'servicii']));
    exit;
}

$s = $servicii[$slug];

// Prev / next navigation between services
$keys = $ordine_servicii;
$idx = array_search($slug, $keys);
$prev = $idx > 0 ? $keys[$idx - 1] : null;
$next = ($idx !== false && $idx < count($keys) - 1) ? $keys[$idx + 1] : null;
?>

<!-- Page Header -->
<section class="page-header">
    <div class="container">
        <div class="breadcrumb">
            <a href="<?php echo langurl_root(); ?>"><?php echo $L['breadcrumb_home']; ?></a>
            <span>/</span>
            <a href="<?php echo langurl(['pagina' => 'servicii']); ?>"><?php echo $L['breadcrumb_services']; ?></a>
            <span>/</span>
            <span class="breadcrumb-current"><?php echo $s['titlu']; ?></span>
        </div>
        <p class="section-label"><?php echo $L['service_label_single']; ?></p>
        <h1><?php echo $s['titlu']; ?></h1>
        <?php if (!empty($s['subtitlu'])): ?>
            <p class="page-header-desc"><?php echo $s['subtitlu']; ?></p>
        <?php endif; ?>
    </div>
</section>

<!-- Intro -->
<?php if (!empty($s['intro'])): ?>
<section class="section service-intro-section">
    <div class="container container-narrow">
        <p class="lead-paragraph"><?php echo $s['intro']; ?></p>
    </div>
</section>
<?php endif; ?>

<!-- Secțiuni -->
<section class="section section-dark service-sections">
    <div class="container container-narrow">
        <?php foreach ($s['sectiuni'] as $idxSec => $sectiune): ?>
            <div class="service-section">
                <div class="service-section-header">
                    <span class="service-section-number"><?php echo str_pad($idxSec + 1, 2, '0', STR_PAD_LEFT); ?></span>
                    <h2><?php echo $sectiune['titlu']; ?></h2>
                </div>

                <?php if (!empty($sectiune['intro'])): ?>
                    <p class="service-section-intro"><?php echo $sectiune['intro']; ?></p>
                <?php endif; ?>

                <div class="service-items">
                    <?php foreach ($sectiune['itemi'] as $item): ?>
                        <div class="service-item-detail">
                            <h4><?php echo $item['titlu']; ?></h4>
                            <p><?php echo $item['text']; ?></p>
                        </div>
                    <?php endforeach; ?>
                </div>
            </div>
        <?php endforeach; ?>
    </div>
</section>

<!-- Navigare între servicii -->
<section class="section service-nav-section">
    <div class="container">
        <div class="service-nav">
            <?php if ($prev): ?>
                <a href="<?php echo langurl(['pagina' => 'servicii', 'serviciu' => $prev]); ?>" class="service-nav-link service-nav-prev">
                    <span class="service-nav-label"><?php echo $L['service_nav_prev']; ?></span>
                    <span class="service-nav-title"><?php echo $servicii[$prev]['titlu']; ?></span>
                </a>
            <?php else: ?>
                <div></div>
            <?php endif; ?>

            <a href="<?php echo langurl(['pagina' => 'servicii']); ?>" class="service-nav-center"><?php echo $L['service_nav_center']; ?></a>

            <?php if ($next): ?>
                <a href="<?php echo langurl(['pagina' => 'servicii', 'serviciu' => $next]); ?>" class="service-nav-link service-nav-next">
                    <span class="service-nav-label"><?php echo $L['service_nav_next']; ?></span>
                    <span class="service-nav-title"><?php echo $servicii[$next]['titlu']; ?></span>
                </a>
            <?php else: ?>
                <div></div>
            <?php endif; ?>
        </div>
    </div>
</section>

<!-- CTA -->
<section class="section cta-section">
    <div class="container cta-content">
        <h2><?php echo $L['service_cta_h2']; ?></h2>
        <p><?php echo $L['service_cta_p']; ?></p>
        <a href="<?php echo langurl(['pagina' => 'contact']); ?>" class="btn btn-primary btn-lg"><?php echo $L['service_cta_btn']; ?></a>
    </div>
</section>
