<?= $this->extend('site/layout/main') ?>
<?= $this->section('content') ?>

<?php if (!empty($slides)): ?>
<div id="heroCarousel" class="carousel slide" data-bs-ride="carousel">
    <div class="carousel-indicators">
        <?php foreach ($slides as $i => $s): ?>
            <button type="button" data-bs-target="#heroCarousel" data-bs-slide-to="<?= $i ?>" class="<?= $i === 0 ? 'active' : '' ?>"></button>
        <?php endforeach; ?>
    </div>
    <div class="carousel-inner">
        <?php foreach ($slides as $i => $s): ?>
            <div class="carousel-item <?= $i === 0 ? 'active' : '' ?>">
                <img src="<?= base_url('uploads/slides/' . $s['image']) ?>" class="d-block w-100 hero-slide" alt="">
                <?php if ($s['title'] || $s['subtitle']): ?>
                <div class="carousel-caption d-none d-md-block bg-dark bg-opacity-50 rounded p-3">
                    <h3><?= esc($s['title']) ?></h3>
                    <p><?= esc($s['subtitle']) ?></p>
                </div>
                <?php endif; ?>
            </div>
        <?php endforeach; ?>
    </div>
    <button class="carousel-control-prev" type="button" data-bs-target="#heroCarousel" data-bs-slide="prev">
        <span class="carousel-control-prev-icon"></span>
    </button>
    <button class="carousel-control-next" type="button" data-bs-target="#heroCarousel" data-bs-slide="next">
        <span class="carousel-control-next-icon"></span>
    </button>
</div>
<?php else: ?>
<div class="py-5 text-white text-center" style="background:var(--primary);">
    <div class="container py-5">
        <h1 class="display-5 fw-bold"><?= esc($company['name']) ?></h1>
        <p class="fs-5"><?= esc($company['site_tagline'] ?? '') ?></p>
    </div>
</div>
<?php endif; ?>

<section class="section">
    <div class="container">
        <div class="row align-items-center">
            <div class="col-md-6">
                <h2 class="fw-bold mb-3">نبذة عنا</h2>
                <p class="text-muted"><?= nl2br(esc($company['site_about_text'] ?? 'شركة رائدة في تقديم خدمات استضافة المواقع ونطاقات الإنترنت.')) ?></p>
                <a href="<?= base_url('site/' . $company['slug'] . '/about') ?>" class="btn btn-primary">اعرف أكتر عننا</a>
            </div>
            <div class="col-md-6">
                <h2 class="fw-bold mb-3">خدماتنا</h2>
                <p class="text-muted"><?= nl2br(esc($company['site_services_text'] ?? 'نقدم باقات استضافة، نطاقات، وشهادات أمان بأفضل الأسعار.')) ?></p>
            </div>
        </div>
    </div>
</section>

<?php if (!empty($products)): ?>
<section class="section bg-light">
    <div class="container">
        <h2 class="fw-bold text-center mb-5">منتجاتنا وخدماتنا</h2>
        <div class="row g-4">
            <?php foreach ($products as $p): ?>
                <div class="col-md-4">
                    <div class="card card-product h-100 p-4 text-center">
                        <h5><?= esc($p['name']) ?></h5>
                        <p class="text-muted small"><?= esc($p['description']) ?></p>
                        <div class="fs-4 fw-bold text-primary"><?= number_format($p['price'], 2) ?> <?= esc($p['currency']) ?></div>
                    </div>
                </div>
            <?php endforeach; ?>
        </div>
        <div class="text-center mt-4">
            <a href="<?= base_url('site/' . $company['slug'] . '/products') ?>" class="btn btn-outline-dark">عرض كل المنتجات</a>
        </div>
    </div>
</section>
<?php endif; ?>

<?php if (!empty($company['site_vision']) || !empty($company['site_mission'])): ?>
<section class="section">
    <div class="container">
        <div class="row g-4">
            <?php if (!empty($company['site_vision'])): ?>
            <div class="col-md-6">
                <div class="p-4 border rounded h-100">
                    <h4 class="text-primary">🎯 رؤيتنا</h4>
                    <p class="text-muted"><?= nl2br(esc($company['site_vision'])) ?></p>
                </div>
            </div>
            <?php endif; ?>
            <?php if (!empty($company['site_mission'])): ?>
            <div class="col-md-6">
                <div class="p-4 border rounded h-100">
                    <h4 class="text-primary">🚀 رسالتنا</h4>
                    <p class="text-muted"><?= nl2br(esc($company['site_mission'])) ?></p>
                </div>
            </div>
            <?php endif; ?>
        </div>
    </div>
</section>
<?php endif; ?>

<?php if (!empty($testimonials)): ?>
<section class="section bg-light">
    <div class="container">
        <h2 class="fw-bold text-center mb-5">آراء عملائنا</h2>
        <div class="row g-4">
            <?php foreach ($testimonials as $t): ?>
                <div class="col-md-4">
                    <div class="card h-100 p-4">
                        <div class="text-warning mb-2"><?= str_repeat('⭐', (int) $t['rating']) ?></div>
                        <p class="fst-italic">"<?= esc($t['content']) ?>"</p>
                        <div class="d-flex align-items-center gap-2 mt-3">
                            <?php if (!empty($t['photo'])): ?>
                                <img src="<?= base_url('uploads/testimonials/' . $t['photo']) ?>" style="width:40px;height:40px;border-radius:50%;object-fit:cover;">
                            <?php endif; ?>
                            <b><?= esc($t['client_name']) ?></b>
                        </div>
                    </div>
                </div>
            <?php endforeach; ?>
        </div>
    </div>
</section>
<?php endif; ?>

<?= $this->endSection() ?>
