<style>
    @media (max-width:991px) {
        .divblock {
            display: block !important;
        }

        .card-2 {
            margin-top: 20px !important;
        }
    }
</style>
<div style="padding-top: 140px; padding-bottom: 80px; min-height: 100vh;">

    <div class="container">

        <div class="text-center"> <?php if ($this->session->flashdata()) {

                                        echo Helpers::showFlash($this->session->flashdata("response"));

                                    } ?></div>

        <div class="text-center" style="margin-bottom: 3rem;">

            <h1 style="font-size: 2.5rem; font-weight: 700; margin-bottom: 1rem;">

                Withdraw <span class="gradient-text">SOL</span>

            </h1>

            <p style="color: rgba(255,255,255,0.7); font-size: 1.25rem;">Withdraw your SOL and rewards anytime</p>

        </div>



        <div class="grid grid-2" style="margin-bottom: 3rem; max-width: 900px; margin-left: auto; margin-right: auto;">

            <div class="card">

                <p style="color: rgba(255,255,255,0.6); font-size: 0.875rem; margin-bottom: 0.5rem;">Available Balance</p>

                <h3 style="font-size: 2rem; font-weight: 700; margin-bottom: 0.5rem;"><?= MemberHelper::user_wallet(); ?> SOL</h3>

                <p style="color: rgba(255,255,255,0.6); font-size: 0.875rem;">Ready to withdraw</p>

            </div>

            <div class="card">

                <p style="color: rgba(255,255,255,0.6); font-size: 0.875rem; margin-bottom: 0.5rem;">Pending Withdrawals</p>

                <?php

                $pending = '0';

                $text = 'All Done';

                if (!empty($data)) {

                    if ($data[0]['status'] == 0) {

                        $pending = $data[0]['amount'];

                        $text = 'Processing';

                    }

                } ?>

                <h3 style="font-size: 2rem; font-weight: 700; margin-bottom: 0.5rem;"> <?= $pending ?> SOL</h3>

                <p style="color: rgba(255,255,255,0.6); font-size: 0.875rem;"><?= $text ?></p>

            </div>

        </div>



        <div class="divblock" style="display: grid; grid-template-columns: 1fr 1fr; gap: 2rem; max-width: 1200px; margin: 0 auto;">

            <!-- Withdraw Form -->

            <div class="card">

                <h2 style="font-size: 1.5rem; font-weight: 700; margin-bottom: 1.5rem; display: flex; align-items: center; gap: 0.75rem;">

                    <div style="width: 48px; height: 48px; border-radius: 0.75rem; background: linear-gradient(135deg, var(--solana-purple), var(--solana-blue)); display: flex; align-items: center; justify-content: center;">📤</div>

                    Withdraw Funds

                </h2>



                <form method="post">

                    <div class="input-group">

                        <label class="input-label">Amount (SOL)</label>

                        <input type="number" name="amount" class="input" placeholder="0.00" id="amount" required>

                        <div style="display: flex; justify-content: space-between; margin-top: 0.5rem;">

                            <p style="font-size: 0.875rem; color: rgba(255,255,255,0.6);">Available: <?= MemberHelper::user_wallet(); ?> SOL</p>

                            <button type="button" class="btn" style="padding: 0.25rem 0.75rem; font-size: 0.875rem; background: none; border: none; color: var(--solana-cyan); cursor: pointer;" onclick="setMaxAmount()">Max</button>

                        </div>

                    </div>



                    <div class="input-group">

                        <label class="input-label">Wallet Address</label>

                        <input type="text" class="input" placeholder="Enter your wallet address" name="wallet_address" id="address" required>

                    </div>

                    <div class="input-group">

                        <label class="input-label">Destination Tag (optional)</label>

                        <input type="text" class="input" name="tag" placeholder="Destination Tag" id="address">

                    </div>



                    <div style="padding: 1rem; background: rgba(255, 165, 0, 0.1); border: 1px solid rgba(255, 165, 0, 0.3); border-radius: 0.75rem; margin-bottom: 1.5rem;">

                        <div style="display: flex; gap: 0.75rem;">

                            <div style="color: #ffa500; font-size: 1.25rem; flex-shrink: 0;">⚠️</div>

                            <div>

                                <div style="color: #ffa500; font-weight: 600; margin-bottom: 0.25rem; font-size: 0.875rem;">Important Warning</div>

                                <div style="font-size: 0.875rem; color: rgba(255,255,255,0.8);">Double-check your wallet address. Withdrawals cannot be reversed.</div>

                            </div>

                        </div>

                    </div>



                    <input type="submit" name="not_bank" class="btn btn-primary" style="width: 100%;max-width:unset !important" id="" value="Submit Withdrawal">

                    <!-- <button type="submit" name="not_bank" class="btn btn-primary" style="width: 100%;">Submit Withdrawal</button> -->

                    <p style="text-align: center; font-size: 0.875rem; color: rgba(255,255,255,0.6); margin-top: 1rem;">Withdrawals typically process within 24 hours</p>

                </form>

            </div>



            <!-- Transaction History -->

            <div class="card-2" style="display: flex; flex-direction: column; gap: 1.5rem;">

                <div class="card" style="height: 100%;overflow-y:scroll">

                    <h3 style="font-size: 1.25rem; font-weight: 700; margin-bottom: 1.5rem;">Recent Withdrawals</h3>

                    <div style="display: flex; flex-direction: column; gap: 1rem;">

                        <?php $i = 1;

                        if (!empty($data)) {



                            foreach ($data as $row) {   ?>

                                <div class="glass" style="padding: 1rem; border-radius: 0.75rem;">

                                    <div style="display: flex; justify-content: space-between; margin-bottom: 0.75rem;">

                                        <div>

                                            <div style="font-weight: 600; margin-bottom: 0.25rem;"><?= $row['amount']; ?> SOL</div>

                                            <div style="font-size: 0.875rem; color: rgba(255,255,255,0.6);"><?= $row['wallet_address']; ?></div>

                                        </div>

                                        <?php if ($row['status'] == '0') { ?>

                                            <div style="color: #ffa500; font-weight: 600; font-size: 0.875rem;">⏳ Pending</div>

                                        <?php } ?>

                                        <?php if ($row['status'] == '1') { ?>

                                            <div style="color: #14F195; font-weight: 600; font-size: 0.875rem;">✓ Confirmed</div>

                                        <?php } ?>

                                        <?php if ($row['status'] == '2') { ?>

                                            <div style="color: #ff7f76; font-weight: 600; font-size: 0.875rem;">❌ Unconfirmed</div>

                                        <?php } ?>

                                    </div>

                                    <div style="display: flex; justify-content: space-between; font-size: 0.875rem; color: rgba(255,255,255,0.6);">

                                        <div>2025-12-08</div>

                                        <!-- <a href="#" style="color: var(--solana-cyan); text-decoration: none;">View on Solscan</a> -->

                                    </div>

                                </div>

                            <?php

                            }

                        } else { ?>

                            <div>Data not found...</div>

                        <?php } ?>

                    </div>

                </div>



                <div class="card">

                    <div style="display: flex; gap: 0.75rem;">

                        <div style="color: var(--solana-cyan); font-size: 1.25rem; flex-shrink: 0;">ℹ️</div>

                        <div>

                            <h3 style="font-size: 1.125rem; font-weight: 700; margin-bottom: 0.75rem;">Processing Time</h3>

                            <div style="font-size: 0.875rem; color: rgba(255,255,255,0.7); line-height: 1.8;">

                                <div style="display: flex; justify-content: space-between; margin-bottom: 0.5rem;">

                                    <span>Normal withdrawals: </span>

                                    <span style="color: white; font-weight: 600;"> 6-12 hours</span>

                                </div>

                                <div style="display: flex; justify-content: space-between; margin-bottom: 0.5rem;">

                                    <span>Peak times:</span>

                                    <span style="color: white; font-weight: 600;">12-24 hours</span>

                                </div>

                                <div style="display: flex; justify-content: space-between;">

                                    <span>Network fee:</span>

                                    <span style="color: white; font-weight: 600;">~0.00025 SOL</span>

                                </div>

                            </div>

                        </div>

                    </div>

                </div>

            </div>

        </div>

    </div>

</div>



<script>

    function setMaxAmount() {

        document.getElementById('amount').value = '<?= MemberHelper::user_wallet(); ?>';

    }



    // function handleWithdraw(event) {

    //     event.preventDefault();

    //     const amount = document.getElementById('amount').value;

    //     const address = document.getElementById('address').value;



    //     if (!validateSolanaAddress(address)) {

    //         showNotification('Invalid Solana address', 'error');

    //         return;

    //     }



    //     showNotification('Withdrawal submitted successfully!');

    //     document.getElementById('amount').value = '';

    //     document.getElementById('address').value = '';

    // }

</script>