<?php
/**
 * (c) ININOUT & PYXIS. All Rights Reserved.
 * Wszelkie modyfikacje tego pliku wymagaja zgloszenia oraz zgody autorow.
 * Any modifications to this file require notification and consent of the authors.
 */
/**
 * i-BOK 5 - Wniosek o zmianę taryfy (klient)
 *
 * Wyświetla dostępne oferty taryf. Po wybraniu oferty
 * przekierowuje do formularza kontaktowego z wypełnioną treścią.
 */

require_once __DIR__ . '/../inc/tariff_offers.php';

$client_id = $_SESSION['client_id'];
$clients = vbk_read_klienci();
$client = $clients[$client_id] ?? null;

if (!$client) {
    echo '<div class="alert alert-danger">' . __('common.error') . '</div>';
    return;
}

// Sprawdź dostępność
if (!tariff_offers_enabled($client_id)) {
    echo '<div class="alert alert-warning">' . __('tariff_change.not_available') . '</div>';
    return;
}

$config = tariff_offers_load();
$offers = $config['offers'];
$current_dl = $client['dl_dzien'] ?? '';
$current_ul = $client['ul_dzien'] ?? '';
?>

<div class="fade-in">
    <h4 class="mb-4">
        <i class="bi bi-arrow-left-right me-2"></i> <?= __('tariff_change.title') ?>
    </h4>

    <?= ibok_help_section('zmiana_taryfy', __('help.show_help'), __('help.zmiana_section_content')) ?>

    <!-- Obecna taryfa -->
    <div class="card mb-4">
        <div class="card-header">
            <i class="bi bi-speedometer me-1"></i> <?= __('tariff_change.current_tariff') ?><?= ibok_tooltip(__('help.tooltip_current_tariff')) ?>
        </div>
        <div class="card-body">
            <div class="row">
                <div class="col-sm-6">
                    <div class="d-flex align-items-center mb-2">
                        <i class="bi bi-arrow-down text-success me-2 fs-5"></i>
                        <div>
                            <small class="text-muted d-block"><?= __('info.download_day') ?></small>
                            <strong><?= e($current_dl) ?></strong>
                        </div>
                    </div>
                </div>
                <div class="col-sm-6">
                    <div class="d-flex align-items-center mb-2">
                        <i class="bi bi-arrow-up text-primary me-2 fs-5"></i>
                        <div>
                            <small class="text-muted d-block"><?= __('info.upload_day') ?></small>
                            <strong><?= e($current_ul) ?></strong>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Dostępne taryfy -->
    <h5 class="mb-3"><?= __('tariff_change.available_offers') ?></h5>

    <div class="row g-3 mb-4">
        <?php foreach ($offers as $i => $offer): ?>
        <div class="col-md-6 col-lg-4">
            <div class="card h-100 offer-card">
                <div class="card-body text-center">
                    <h4 class="card-title fw-bold fs-4"><?= e($offer['name']) ?></h4>
                    <div class="mb-2">
                        <span class="text-success"><i class="bi bi-arrow-down"></i> <?= e($offer['dl']) ?></span>
                        <span class="mx-2">/</span>
                        <span class="text-primary"><i class="bi bi-arrow-up"></i> <?= e($offer['ul']) ?></span>
                    </div>
                    <?php if (!empty($offer['price'])): ?>
                        <div class="fs-5 fw-bold text-primary mb-2"><?= e($offer['price']) ?></div>
                    <?php endif; ?>
                    <?php if (!empty($offer['description'])): ?>
                        <p class="text-muted small mb-2"><?= e($offer['description']) ?></p>
                    <?php endif; ?>
                    <a href="index.php?page=kontakt&subject=tariff_change&offer=<?= $i ?>" class="btn btn-outline-primary btn-sm"
                       data-bs-toggle="tooltip" title="<?= e(__('help.tooltip_tariff_submit')) ?>">
                        <i class="bi bi-envelope me-1"></i> <?= __('tariff_change.btn_select') ?>
                    </a>
                </div>
            </div>
        </div>
        <?php endforeach; ?>
    </div>
</div>
