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

<div class="py-5 text-white text-center" style="background:var(--primary);">
    <div class="container py-4"><h1 class="fw-bold">اتصل بنا</h1></div>
</div>

<section class="section">
    <div class="container">
        <div class="row g-5">
            <div class="col-md-5">
                <h4 class="mb-4">بيانات التواصل</h4>
                <ul class="list-unstyled">
                    <?php if (!empty($company['phone'])): ?><li class="mb-3">📞 <?= esc($company['phone']) ?></li><?php endif; ?>
                    <?php if (!empty($company['email'])): ?><li class="mb-3">✉️ <?= esc($company['email']) ?></li><?php endif; ?>
                    <?php if (!empty($company['address'])): ?><li class="mb-3">📍 <?= esc($company['address']) ?></li><?php endif; ?>
                    <?php if (!empty($company['site_whatsapp_number'])): ?>
                        <li class="mb-3">
                            <a href="https://wa.me/<?= esc($company['site_whatsapp_number']) ?>" target="_blank" class="btn btn-success btn-sm">💬 راسلنا واتساب</a>
                        </li>
                    <?php endif; ?>
                </ul>
            </div>

            <div class="col-md-7">
                <h4 class="mb-4">أرسل طلبك مباشرة</h4>

                <?php if (session()->getFlashdata('message')): ?>
                    <div class="alert alert-success"><?= esc(session()->getFlashdata('message')) ?></div>
                <?php endif; ?>
                <?php if (session()->getFlashdata('error')): ?>
                    <div class="alert alert-danger"><?= esc(session()->getFlashdata('error')) ?></div>
                <?php endif; ?>
                <?php if (session()->getFlashdata('errors')): ?>
                    <div class="alert alert-danger">
                        <ul class="mb-0">
                        <?php foreach (session()->getFlashdata('errors') as $err): ?>
                            <li><?= esc($err) ?></li>
                        <?php endforeach; ?>
                        </ul>
                    </div>
                <?php endif; ?>

                <form method="post" action="<?= base_url('site/' . $company['slug'] . '/contact') ?>">
                    <?= csrf_field() ?>
                    <div class="row g-3">
                        <div class="col-md-6">
                            <label class="form-label">الاسم</label>
                            <input type="text" name="name" class="form-control" value="<?= old('name') ?>" required>
                        </div>
                        <div class="col-md-6">
                            <label class="form-label">البريد الإلكتروني</label>
                            <input type="email" name="email" class="form-control" value="<?= old('email') ?>" required>
                        </div>
                        <div class="col-md-6">
                            <label class="form-label">رقم الهاتف</label>
                            <input type="text" name="phone" class="form-control" value="<?= old('phone') ?>">
                        </div>
                        <div class="col-md-6">
                            <label class="form-label">الموضوع</label>
                            <input type="text" name="subject" class="form-control" value="<?= old('subject') ?>">
                        </div>
                        <div class="col-12">
                            <label class="form-label">رسالتك / طلبك</label>
                            <textarea name="message" class="form-control" rows="4" required><?= old('message') ?></textarea>
                        </div>
                        <?php if (!empty($recaptchaSiteKey)): ?>
                        <div class="col-12">
                            <div class="g-recaptcha" data-sitekey="<?= esc($recaptchaSiteKey) ?>"></div>
                        </div>
                        <?php endif; ?>
                        <div class="col-12">
                            <button class="btn btn-primary px-4">إرسال الطلب</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</section>

<?php if (!empty($recaptchaSiteKey)): ?>
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
<?php endif; ?>
<?= $this->endSection() ?>
