<?php
use function App\Core\e;

$packageId = (int) (($package['id'] ?? 0));
$periodType = (string) ($periodType ?? 'monthly');
$csrfToken = (string) ($csrfToken ?? \App\Core\Csrf::token());
$providerKey = (string) ($providerKey ?? 'test');
$supportsInstallment = is_object($provider ?? null) && $provider->supportsInstallment();
$supports3d = !is_object($provider ?? null) || $provider->supports3DSecure();
?>
<form class="payment-form" data-payment-form data-package-id="<?= $packageId ?>" data-period-type="<?= e($periodType) ?>">
    <input type="hidden" name="_csrf" value="<?= e($csrfToken) ?>">
    <input class="hp" type="text" name="website" tabindex="-1" autocomplete="off" aria-hidden="true">

    <label>Kart uzerindeki isim<input name="card_holder" required autocomplete="cc-name" maxlength="120"></label>
    <label>Kart numarasi
        <span class="card-input-wrap">
            <input name="card_number" required data-card-number inputmode="numeric" maxlength="23" autocomplete="cc-number">
            <span data-card-brand>Card</span>
        </span>
    </label>

    <div class="payment-form-grid">
        <label>Ay/Yil<input name="expiry" required data-card-expiry placeholder="AA/YY" inputmode="numeric" maxlength="5" autocomplete="cc-exp"></label>
        <label>CVV<input name="cvv" required data-card-cvv inputmode="numeric" maxlength="4" autocomplete="cc-csc"></label>
    </div>

    <div class="payment-card-flags">
        <span>Visa</span>
        <span>Mastercard</span>
        <span>Troy</span>
    </div>

    <div class="payment-options">
        <?php if ($supportsInstallment): ?>
            <label>Taksit
                <select name="installment_count">
                    <option value="1">Tek cekim</option>
                    <option value="2">2 taksit</option>
                    <option value="3">3 taksit</option>
                    <option value="6">6 taksit</option>
                    <option value="9">9 taksit</option>
                </select>
            </label>
        <?php endif; ?>
        <?php if ($supports3d): ?>
            <label class="payment-toggle"><input type="checkbox" name="is_3d_secure" value="1" checked> 3D Secure kullan</label>
        <?php endif; ?>
    </div>

    <p class="muted payment-security-note">Kart numarasi, CVV ve son kullanma tarihi veritabanina yazilmaz.</p>
    <?php if ($providerKey === 'test'): ?>
        <div class="payment-test-actions">
            <button type="button" class="pill" data-test-card="success">Test Odeme Basarili</button>
            <button type="button" class="pill" data-test-card="failed">Test Odeme Basarisiz</button>
        </div>
    <?php endif; ?>
    <button type="submit" class="pill primary payment-submit" data-payment-submit>Odemeyi Tamamla</button>
</form>
