<?php echo $this->extend('template/admin/main') ?>

<?php echo $this->section('content') ?>
    <?php echo $this->include('common/message') ?>

    <div class="card mb-4">
        <div class="card-body">
            <div class="d-flex flex-wrap justify-content-between align-items-center gap-2 mb-4">
                <div>
                    <h5 class="mb-1"><?php echo esc($offer->offer_title ?? '') ?></h5>
                    <div class="text-muted small"><?php echo lang('Localize.code') ?>: <?php echo esc($offer->code ?? '') ?></div>
                </div>
                <div class="d-flex flex-wrap gap-2 align-items-center">
                    <?php echo \Modules\Offer\Models\OfferModel::statusBadgeHtml($is_active) ?>
                    <?php if ($edit_data) : ?>
                        <a href="<?php echo base_url(route_to('edit-offer', $offer->id)) ?>" class="btn btn-sm btn-info text-white">
                            <i class="fas fa-edit"></i> <?php echo lang('Localize.edit') ?>
                        </a>
                    <?php endif ?>
                    <a href="<?php echo base_url(route_to('index-offer')) ?>" class="btn btn-sm btn-secondary">
                        <i class="fas fa-arrow-left"></i> <?php echo lang('Localize.back') ?>
                    </a>
                </div>
            </div>

            <div class="row g-4">
                <div class="col-lg-4">
                    <?php if (! empty($offer->offer_image)) : ?>
                        <img src="<?php echo base_url('public/uploads/offers/' . $offer->offer_image) ?>" alt="<?php echo esc($offer->offer_title ?? 'Offer') ?>" class="img-fluid rounded border w-100" style="max-height: 280px; object-fit: cover;">
                    <?php else : ?>
                        <div class="border rounded d-flex align-items-center justify-content-center bg-light text-muted" style="min-height: 200px;">
                            <span>No image</span>
                        </div>
                    <?php endif ?>
                </div>

                <div class="col-lg-8">
                    <div class="row g-3">
                        <div class="col-md-6">
                            <label class="form-label text-muted mb-1"><?php echo lang('Localize.company') ?></label>
                            <div class="fw-semibold"><?php echo esc($company_names ?: '-') ?></div>
                        </div>
                        <div class="col-md-6">
                            <label class="form-label text-muted mb-1"><?php echo lang('Localize.discount') ?></label>
                            <div class="fw-semibold"><?php echo esc(\Modules\Offer\Models\OfferModel::formatDiscountDisplay($offer)) ?></div>
                        </div>
                        <div class="col-md-6">
                            <label class="form-label text-muted mb-1"><?php echo lang('Localize.minimum_passengers') ?></label>
                            <div class="fw-semibold"><?php echo esc($offer->min_passengers ?? 1) ?></div>
                        </div>
                        <div class="col-md-6">
                            <label class="form-label text-muted mb-1">Discount Type</label>
                            <div class="fw-semibold">
                                <?php echo (int) ($offer->discount_type ?? 0) === 1 ? lang('Localize.fixed_amount') . ' (' . lang('Localize.key_currency_egp') . ')' : lang('Localize.percentage') . ' (%)' ?>
                            </div>
                        </div>
                        <?php if ((int) ($offer->discount_type ?? 0) === 2) : ?>
                            <div class="col-md-4">
                                <label class="form-label text-muted mb-1">Discount Cap (<?php echo lang('Localize.key_currency_egp') ?>)</label>
                                <div class="fw-semibold"><?php echo esc($offer->discount_cap ?? '-') ?></div>
                            </div>
                            <div class="col-md-4">
                                <label class="form-label text-muted mb-1">Min Discount (<?php echo lang('Localize.key_currency_egp') ?>)</label>
                                <div class="fw-semibold"><?php echo esc($offer->min_discount ?? '-') ?></div>
                            </div>
                            <div class="col-md-4">
                                <label class="form-label text-muted mb-1">Max Discount (<?php echo lang('Localize.key_currency_egp') ?>)</label>
                                <div class="fw-semibold"><?php echo esc($offer->max_discount ?? '-') ?></div>
                            </div>
                        <?php endif ?>
                    </div>
                </div>
            </div>

            <hr class="my-4">

            <div class="row g-3">
                <div class="col-md-3">
                    <label class="form-label text-muted mb-1"><?php echo lang('Localize.start') ?> <?php echo lang('Localize.date') ?></label>
                    <div class="fw-semibold"><?php echo esc(\Modules\Offer\Models\OfferModel::formatDisplayDate($offer->start_date ?? '') ?: '-') ?></div>
                </div>
                <div class="col-md-3">
                    <label class="form-label text-muted mb-1"><?php echo lang('Localize.end') ?> <?php echo lang('Localize.date') ?></label>
                    <div class="fw-semibold"><?php echo esc(\Modules\Offer\Models\OfferModel::formatDisplayDate($offer->end_date ?? '') ?: '-') ?></div>
                </div>
                <div class="col-md-3">
                    <label class="form-label text-muted mb-1">Booking Start Date</label>
                    <div class="fw-semibold"><?php echo esc(\Modules\Offer\Models\OfferModel::formatDisplayDate($offer->booking_start_date ?? '') ?: '-') ?></div>
                </div>
                <div class="col-md-3">
                    <label class="form-label text-muted mb-1">Booking End Date</label>
                    <div class="fw-semibold"><?php echo esc(\Modules\Offer\Models\OfferModel::formatDisplayDate($offer->booking_end_date ?? '') ?: '-') ?></div>
                </div>
                <div class="col-md-3">
                    <label class="form-label text-muted mb-1">Travel Start Date</label>
                    <div class="fw-semibold"><?php echo esc(\Modules\Offer\Models\OfferModel::formatDisplayDate($offer->travel_start_date ?? '') ?: '-') ?></div>
                </div>
                <div class="col-md-3">
                    <label class="form-label text-muted mb-1">Travel End Date</label>
                    <div class="fw-semibold"><?php echo esc(\Modules\Offer\Models\OfferModel::formatDisplayDate($offer->travel_end_date ?? '') ?: '-') ?></div>
                </div>
            </div>

            <?php if (! empty($offer->offer_description)) : ?>
                <hr class="my-4">
                <label class="form-label text-muted mb-1">Offer Description</label>
                <div class="border rounded p-3 bg-light"><?php echo nl2br(esc($offer->offer_description)) ?></div>
            <?php endif ?>

            <?php if ($trip_labels !== []) : ?>
                <hr class="my-4">
                <label class="form-label text-muted mb-2"><?php echo lang('Localize.sub') ?> <?php echo lang('Localize.trip') ?></label>
                <ul class="list-group list-group-flush border rounded">
                    <?php foreach ($trip_labels as $label) : ?>
                        <li class="list-group-item py-2"><?php echo esc($label) ?></li>
                    <?php endforeach ?>
                </ul>
            <?php endif ?>

            <?php if ($seat_class_names !== [] || $trip_category_names !== []) : ?>
                <hr class="my-4">
                <div class="row g-3">
                    <?php if ($seat_class_names !== []) : ?>
                        <div class="col-md-6">
                            <label class="form-label text-muted mb-1">Seat Class</label>
                            <div class="fw-semibold"><?php echo esc(implode(', ', $seat_class_names)) ?></div>
                        </div>
                    <?php endif ?>
                    <?php if ($trip_category_names !== []) : ?>
                        <div class="col-md-6">
                            <label class="form-label text-muted mb-1">Trip Category</label>
                            <div class="fw-semibold"><?php echo esc(implode(', ', $trip_category_names)) ?></div>
                        </div>
                    <?php endif ?>
                </div>
            <?php endif ?>

            <?php if (! empty($offer->condition)) : ?>
                <hr class="my-4">
                <label class="form-label text-muted mb-1"><?php echo lang('Localize.terms_conditions') ?></label>
                <div class="border rounded p-3 bg-light"><?php echo nl2br(esc($offer->condition)) ?></div>
            <?php endif ?>
        </div>
    </div>
<?php echo $this->endSection() ?>
