<?php
use function App\Core\e;
?>
<div class="panel creator-shell"><?php require BASE_PATH . '/app/Views/partials/studio-sidebar.php'; ?>
<section class="panel-body finance-page" data-studio-bank-accounts data-csrf="<?= e($csrfToken ?? '') ?>">
    <div class="finance-head">
        <div>
            <h1>Banka Bilgilerim</h1>
            <p>Para cekme taleplerinde kullanilacak IBAN ve hesap bilgilerini yonet.</p>
        </div>
    </div>

    <?php if (!empty($loadError)): ?><div class="finance-alert"><?= e($loadError) ?></div><?php endif; ?>

    <div class="finance-grid">
        <section class="finance-card">
            <div class="finance-card-head"><h2>Banka Hesabi Ekle</h2><span>IBAN TR ile baslamali</span></div>
            <form class="finance-form" data-finance-form data-endpoint="/api/studio/bank-accounts/create">
                <input type="hidden" name="_csrf" value="<?= e($csrfToken ?? '') ?>">
                <label>Hesap sahibi<input name="account_holder" required maxlength="160"></label>
                <label>Banka adi<input name="bank_name" required maxlength="120"></label>
                <label>IBAN<input name="iban" required maxlength="34" placeholder="TR000000000000000000000000"></label>
                <label>TC/Vergi no<input name="identity_or_tax_no" maxlength="40" autocomplete="off"></label>
                <label>Sirket adi<input name="company_name" maxlength="160"></label>
                <label class="check-row"><input type="checkbox" name="is_default" value="1"> Varsayilan hesap yap</label>
                <button class="pill primary" type="submit">Kaydet</button>
            </form>
        </section>

        <section class="finance-card">
            <div class="finance-card-head"><h2>Kayitli Hesaplar</h2><span><?= count($bankAccounts ?? []) ?> hesap</span></div>
            <div class="bank-account-list">
                <?php foreach (($bankAccounts ?? []) as $account): ?>
                    <article data-bank-account>
                        <form class="finance-form compact" data-finance-form data-endpoint="/api/studio/bank-accounts/update">
                            <input type="hidden" name="_csrf" value="<?= e($csrfToken ?? '') ?>">
                            <input type="hidden" name="id" value="<?= e($account['id'] ?? '') ?>">
                            <div class="bank-card-head">
                                <strong><?= e($account['bank_name'] ?? '-') ?></strong>
                                <?php if (!empty($account['is_default'])): ?><span class="status-pill status-safe">Varsayilan</span><?php endif; ?>
                            </div>
                            <label>Hesap sahibi<input name="account_holder" value="<?= e($account['account_holder'] ?? '') ?>" required></label>
                            <label>Banka adi<input name="bank_name" value="<?= e($account['bank_name'] ?? '') ?>" required></label>
                            <label>IBAN<input name="iban" value="<?= e($account['iban'] ?? '') ?>" required></label>
                            <label>TC/Vergi no<input name="identity_or_tax_no" value="<?= e($account['identity_or_tax_no'] ?? '') ?>" autocomplete="off"></label>
                            <label>Sirket adi<input name="company_name" value="<?= e($account['company_name'] ?? '') ?>"></label>
                            <label class="check-row"><input type="checkbox" name="is_default" value="1" <?= !empty($account['is_default']) ? 'checked' : '' ?>> Varsayilan</label>
                            <div class="toolbar">
                                <button class="pill primary" type="submit">Guncelle</button>
                                <button type="button" class="pill danger" data-finance-action="/api/studio/bank-accounts/delete" data-id="<?= e($account['id'] ?? '') ?>" data-confirm="Bu banka hesabi silinsin mi?">Sil</button>
                            </div>
                            <p class="muted">Gorunen IBAN: <?= e($account['iban_masked'] ?? '') ?><?= !empty($account['identity_or_tax_no_masked']) ? ' | Kimlik: ' . e($account['identity_or_tax_no_masked']) : '' ?></p>
                        </form>
                    </article>
                <?php endforeach; ?>
                <?php if (empty($bankAccounts)): ?><div class="empty-state small"><strong>Hesap yok</strong><p>Para cekebilmek icin en az bir banka hesabi ekle.</p></div><?php endif; ?>
            </div>
        </section>
    </div>
</section></div>
