<?= $this->extend('install/_layout') ?>
<?php $currentStep = 7; ?>

<?= $this->section('content') ?>
<h5 class="mb-3">Step 7 — Payment Configuration <small class="text-muted">(optional)</small></h5>
<p class="text-muted">Enable whichever gateways you want live at launch. You can leave all of this blank and configure it later — the platform runs in billing-disabled trial mode until a gateway is added.</p>

<form id="paymentForm">
    <div class="accordion" id="gatewayAccordion">

        <div class="accordion-item">
            <h2 class="accordion-header"><button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#stripe">Stripe</button></h2>
            <div id="stripe" class="accordion-collapse collapse show" data-bs-parent="#gatewayAccordion">
                <div class="accordion-body row g-2">
                    <div class="col-6"><label class="form-label">Publishable Key</label><input class="form-control" name="stripe_public_key"></div>
                    <div class="col-6"><label class="form-label">Secret Key</label><input class="form-control" name="stripe_secret_key" type="password"></div>
                </div>
            </div>
        </div>

        <div class="accordion-item">
            <h2 class="accordion-header"><button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#paypal">PayPal</button></h2>
            <div id="paypal" class="accordion-collapse collapse" data-bs-parent="#gatewayAccordion">
                <div class="accordion-body row g-2">
                    <div class="col-6"><label class="form-label">Client ID</label><input class="form-control" name="paypal_client_id"></div>
                    <div class="col-6"><label class="form-label">Secret</label><input class="form-control" name="paypal_secret" type="password"></div>
                </div>
            </div>
        </div>

        <div class="accordion-item">
            <h2 class="accordion-header"><button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#jazzcash">JazzCash</button></h2>
            <div id="jazzcash" class="accordion-collapse collapse" data-bs-parent="#gatewayAccordion">
                <div class="accordion-body row g-2">
                    <div class="col-4"><label class="form-label">Merchant ID</label><input class="form-control" name="jazzcash_merchant_id"></div>
                    <div class="col-4"><label class="form-label">Password</label><input class="form-control" name="jazzcash_password" type="password"></div>
                    <div class="col-4"><label class="form-label">Integrity Salt</label><input class="form-control" name="jazzcash_integrity_salt" type="password"></div>
                </div>
            </div>
        </div>

        <div class="accordion-item">
            <h2 class="accordion-header"><button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#easypaisa">Easypaisa</button></h2>
            <div id="easypaisa" class="accordion-collapse collapse" data-bs-parent="#gatewayAccordion">
                <div class="accordion-body row g-2">
                    <div class="col-6"><label class="form-label">Store ID</label><input class="form-control" name="easypaisa_store_id"></div>
                    <div class="col-6"><label class="form-label">Hash Key</label><input class="form-control" name="easypaisa_hash_key" type="password"></div>
                </div>
            </div>
        </div>

    </div>

    <div class="form-check mt-3">
        <input class="form-check-input" type="checkbox" name="bank_transfer_enabled" value="1" id="bankTransfer" checked>
        <label class="form-check-label" for="bankTransfer">Enable manual Bank Transfer (Support-staff approved)</label>
    </div>

    <div class="d-flex justify-content-between mt-4">
        <a href="<?= base_url('install/step/6') ?>" class="btn btn-outline-secondary">← Back</a>
        <button type="submit" class="btn btn-primary">Next: Install →</button>
    </div>
</form>
<?= $this->endSection() ?>

<?= $this->section('scripts') ?>
<script>
document.getElementById('paymentForm').addEventListener('submit', async (e) => {
    e.preventDefault();
    const res = await fetch('<?= base_url('install/step/7') ?>', {
        method: 'POST',
        headers: {'Content-Type': 'application/x-www-form-urlencoded'},
        body: new URLSearchParams(new FormData(e.target))
    });
    const json = await res.json();
    if (json.success) { window.location.href = json.data.next; }
    else { alert(json.errors.map(e => e.message).join('\n')); }
});
</script>
<?= $this->endSection() ?>
