<div class="page-content header-clear-medium">
    <div class="card card-style bg-theme pb-0">
        <div class="content" id="tab-group-1">
            <div class="tab-controls tabs-small tabs-rounded" data-highlight="bg-highlight">
                <a href="#" data-active data-bs-toggle="collapse" data-bs-target="#tab-1">Bank</a>
                <a href="#" data-bs-toggle="collapse" data-bs-target="#tab-2">Card</a>
                <a href="#" data-bs-toggle="collapse" data-bs-target="#tab-3"><?php echo htmlspecialchars($data->sId); ?></a>
            </div>
            <div class="clearfix mb-3"></div>
            <div data-bs-parent="#tab-group-1" class="collapse show" id="tab-1">
                <div class="text-center">
                    <p class="text-center">
                        <span class="icon icon-l gradient-blue shadow-l rounded-sm">
                            <i class="fa fa-arrow-up font-30 color-white"></i>
                        </span>
                    </p>
                    <h4 class="text-primary">FUND WALLET</h4>
                    
                    <!-- PalmPay BANK START -->
                    <?php
                    $palmpayCharges = 1.5; // 1.5% charge
                    $palmpayChargesText = $palmpayCharges . "%";
                    ?>
                    <?php if(empty($data->sPalmpayBank)): ?>
                        <p class="mb-2 text-danger font-600 font-15">Get A PalmPay Account For Automated Transfer, Generate A Dedicated Account Number Now. Funding Attracts <?php echo htmlspecialchars($palmpayChargesText); ?> only.</p>
                        <button class="btn btn-primary font-700 rounded-xl mt-3" id="generatePalmpayBtn" onclick="generatePalmpayAccount()">Generate Account</button>
                        <div id="palmpayAccountInfo" style="display: none;">
                            <p class="mb-2 text-dark font-600 font-16"><b>Bank Name: </b>PalmPay</p>
                            <p class="mb-2 text-dark font-600 font-16"><b>Account No: </b><span id="palmpayAccountNo"></span></p>
                            <p class="mb-2 text-danger font-600 font-15"><b>Note: </b>Automated bank transfer attracts additional charges of <?php echo htmlspecialchars($palmpayChargesText); ?> only.</p>
                            <button class="btn btn-primary font-700 rounded-xl mt-3" onclick="copyToClipboard(document.getElementById('palmpayAccountNo').innerText)">Copy Account No</button>
                        </div>
                    <?php else: ?>
                        <p class="mb-2 text-dark font-600 font-16"><b>Bank Name: </b>PalmPay</p>
                        <p class="mb-2 text-dark font-600 font-16"><b>Account No: </b><?php echo htmlspecialchars($data->sPalmpayBank); ?></p>
                        <p class="mb-2 text-danger font-600 font-15"><b>Note: </b>Automated bank transfer attracts additional charges of <?php echo htmlspecialchars($palmpayChargesText); ?> only.</p>
                        <button class="btn btn-primary font-700 rounded-xl mt-3" onclick="copyToClipboard('<?php echo htmlspecialchars($data->sPalmpayBank); ?>')">Copy Account No</button>
                    <?php endif; ?>
                    <hr/>
                    <!-- PalmPay BANK END -->

                    <!-- Rest of your existing bank options... -->

                </div>
            </div>

            <!-- Rest of your existing tabs... -->

        </div>
    </div> 
</div>

<script>

function generatePalmpayAccount() {
    var btn = document.getElementById('generatePalmpayBtn');
    btn.innerHTML = '<i class="fa fa-spinner fa-spin"></i> Processing...';
    btn.disabled = true;

    var email = "<?php echo htmlspecialchars($data->sEmail); ?>";

    fetch('https://mdataplus.com.ng/mobile/generate.php', { // Use absolute URL
        method: 'POST',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        body: 'email=' + encodeURIComponent(email)
    })
    .then(response => response.text()) // Read response as text first
    .then(text => {
        try {
            return JSON.parse(text); // Try parsing JSON
        } catch (e) {
            console.error('Invalid JSON response:', text);
            throw new Error('Server returned invalid JSON');
        }
    })
    .then(data => {
        if (data.success) {
            document.getElementById('palmpayAccountNo').innerText = data.account_number;
            document.getElementById('palmpayAccountInfo').style.display = 'block';
            btn.style.display = 'none';
        } else {
            throw new Error(data.error || 'Failed to generate account');
        }
    })
    .catch(error => {
        console.error('Error:', error);
        alert('An error occurred: ' + error.message);
        btn.innerHTML = 'Generate Account';
        btn.disabled = false;
    });
}

</script>
