<?php
use function App\Core\e;

$packages = $packages ?? [];
$privacy = (string) ($privacy ?? 'public');
$selectedPackageId = (int) ($selectedPackageId ?? 0);
if ($selectedPackageId > 0 && in_array($privacy, ['subscriber', 'premium'], true)) {
    $privacy = 'package';
}
?>
<div class="privacy-selector" data-privacy-selector>
    <div class="privacy-grid">
        <?php foreach ([['public', 'Herkese acik', 'Free erisim'], ['subscriber', 'Sadece aboneler', 'Aktif abonelik gerekir'], ['package', 'Belirli paketler', 'Secili paket gerekir']] as [$value, $label, $hint]): ?>
            <label class="privacy-card <?= $privacy === $value ? 'is-selected' : '' ?>">
                <input type="radio" name="privacy" value="<?= e($value) ?>" <?= $privacy === $value ? 'checked' : '' ?>>
                <strong><?= e($label) ?></strong>
                <span><?= e($hint) ?></span>
            </label>
        <?php endforeach; ?>
    </div>
    <div class="package-select-grid <?= $privacy === 'package' ? 'is-open' : '' ?>" data-package-options>
        <?php if ($packages === []): ?>
            <p class="muted">Aktif paket yok. Paket secimi icin Studio Abonelik alaninda paket olustur.</p>
        <?php endif; ?>
        <?php foreach ($packages as $package): ?>
            <label class="package-select-card <?= $selectedPackageId === (int) $package['id'] ? 'is-selected' : '' ?>">
                <input type="radio" name="package_id" value="<?= (int) $package['id'] ?>" <?= $selectedPackageId === (int) $package['id'] ? 'checked' : '' ?>>
                <strong><?= e($package['name']) ?></strong>
                <span><?= e(number_format((float) ($package['price_monthly'] ?? 0), 2, ',', '.')) ?> <?= e($package['currency'] ?? 'TRY') ?> / ay</span>
            </label>
        <?php endforeach; ?>
    </div>
</div>
