<?php
use function App\Core\{e, url};

$package = $package ?? [];
$financials = $financials ?? [];
$periodType = (string) ($periodType ?? 'monthly');
$periodMonths = (int) ($periodMonths ?? 1);
$currency = (string) (($package['currency'] ?? '') ?: 'TRY');
$money = static fn (mixed $value): string => number_format((float) $value, 2, ',', '.') . ' ' . $currency;
$providerName = is_object($provider ?? null) ? $provider->getProviderName() : 'TestPaymentProvider';
$providerKey = (string) ($providerKey ?? 'test');
$periodLabels = [
    'monthly' => '1 Ay',
    '6_month' => '6 Ay',
    '12_month' => '12 Ay',
];
?>
<section class="payment-shell">
    <div class="container payment-checkout">
        <div class="payment-hero-panel">
            <p class="eyebrow">Creator aboneligi</p>
            <h1><?= e((string) ($package['name'] ?? 'Premium Paket')) ?></h1>
            <p><?= e((string) (($package['description'] ?? '') ?: 'Premium mod ve premium muzik erisimi icin creator destek paketi.')) ?></p>

            <div class="payment-creator-strip">
                <span>Icerik uretici</span>
                <strong><?= e((string) ($package['creator_name'] ?? $package['creator_username'] ?? 'Creator')) ?></strong>
            </div>

            <div class="payment-periods" aria-label="Paket suresi">
                <?php foreach ($periodLabels as $key => $label): ?>
                    <a class="<?= $periodType === $key ? 'is-active' : '' ?>" href="<?= e(url('/checkout/' . (int) ($package['id'] ?? 0)) . '?period=' . $key) ?>"><?= e($label) ?></a>
                <?php endforeach; ?>
            </div>

            <dl class="payment-breakdown">
                <div><dt>Sure</dt><dd><?= e((string) $periodMonths) ?> ay</dd></div>
                <div><dt>Paket tutari</dt><dd><?= e($money($financials['gross_amount'] ?? 0)) ?></dd></div>
                <div><dt>KDV hesap alani</dt><dd><?= e($money($financials['tax_amount'] ?? 0)) ?></dd></div>
                <div><dt>Provider komisyonu</dt><dd><?= e($money($financials['provider_fee_amount'] ?? 0)) ?></dd></div>
            </dl>

            <p class="payment-note">Creator net tutari, platform komisyonu ve vergi alanlari MVP finans hesaplamasiyla doldurulur; kesin muhasebe Bolum 11'de detaylanacak.</p>
        </div>

        <aside class="payment-card checkout-card">
            <div class="payment-card-head">
                <div>
                    <span>Toplam</span>
                    <strong><?= e($money($financials['gross_amount'] ?? 0)) ?></strong>
                </div>
                <small><?= e($providerName) ?></small>
            </div>

            <?php if ($providerKey === 'test'): ?>
                <div class="test-card-note">
                    <strong>Test kartlari</strong>
                    <span>Basarili: 4242 4242 4242 4242</span>
                    <span>Basarisiz: 4000 0000 0000 0002</span>
                </div>
            <?php endif; ?>

            <?php require BASE_PATH . '/app/Views/partials/payment-card-form.php'; ?>
        </aside>
    </div>
</section>
