<?php 
$this->load->view('layouts/header');
$this->load->helper('layout');
?>

    <!-- App Header -->
    <div class="appHeader bg-primary text-light">
        <div class="left">
            <a href="#" class="headerButton" data-bs-toggle="modal" data-bs-target="#adminSidebar">
                <ion-icon name="menu-outline"></ion-icon>
            </a>
        </div>
        <div class="pageTitle">Crypto Wallets</div>
        <div class="right">
            <a href="<?php echo base_url('admin/crypto-wallet/add'); ?>" class="headerButton">
                <ion-icon name="add-outline"></ion-icon>
            </a>
            <a href="<?php echo base_url('admin/dashboard'); ?>" class="headerButton">
                <ion-icon name="home-outline"></ion-icon>
            </a>
        </div>
    </div>

    <!-- App Capsule -->
    <div id="appCapsule">
        <?php if ($this->session->flashdata('success')): ?>
        <div class="section mt-2">
            <div class="alert alert-success alert-dismissible fade show"><?php echo $this->session->flashdata('success'); ?>
                <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
            </div>
        </div>
        <?php endif; ?>
        <?php if ($this->session->flashdata('error')): ?>
        <div class="section mt-2">
            <div class="alert alert-danger alert-dismissible fade show"><?php echo $this->session->flashdata('error'); ?>
                <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
            </div>
        </div>
        <?php endif; ?>

        <div class="section mt-2 mb-3">
            <div class="section-title">Deposit wallets (<?php echo count($wallets); ?>)</div>
            <p class="text-muted small">These wallets and addresses are shown on the user Deposit / Receive page. Add wallets and then add deposit addresses for each.</p>
            
            <?php if (empty($wallets)): ?>
            <div class="card">
                <div class="card-body text-center py-4">
                    <ion-icon name="logo-bitcoin" style="font-size: 48px; color: #ccc;"></ion-icon>
                    <p class="text-muted mt-2 mb-0">No crypto wallets yet</p>
                    <a href="<?php echo base_url('admin/crypto-wallet/add'); ?>" class="btn btn-primary btn-sm mt-2">Add Wallet</a>
                </div>
            </div>
            <?php else: ?>
            <ul class="listview image-listview flush">
                <?php foreach ($wallets as $w): ?>
                <li>
                    <a href="<?php echo base_url('admin/crypto-addresses/' . $w->id); ?>" class="item">
                        <div class="icon-box bg-warning">
                            <ion-icon name="logo-bitcoin"></ion-icon>
                        </div>
                        <div class="in">
                            <div>
                                <strong><?php echo htmlspecialchars($w->name); ?></strong>
                                <p class="mb-0 small text-muted">
                                    <?php echo htmlspecialchars($w->symbol); ?>
                                    <?php if ($w->network): ?> &middot; <?php echo htmlspecialchars($w->network); ?><?php endif; ?>
                                </p>
                            </div>
                            <span class="badge badge-<?php echo $w->is_active ? 'success' : 'secondary'; ?>"><?php echo $w->is_active ? 'Active' : 'Inactive'; ?></span>
                        </div>
                        <ion-icon name="chevron-forward-outline"></ion-icon>
                    </a>
                </li>
                <li class="no-line">
                    <div class="item d-flex justify-content-between align-items-center px-3 py-2">
                        <div>
                            <a href="<?php echo base_url('admin/crypto-wallet/edit/' . $w->id); ?>" class="btn btn-sm btn-outline-primary">Edit</a>
                            <a href="<?php echo base_url('admin/crypto-wallet/delete/' . $w->id); ?>" class="btn btn-sm btn-outline-danger ms-1" onclick="return confirm('Delete this wallet and all its addresses?');">Delete</a>
                        </div>
                        <a href="<?php echo base_url('admin/crypto-addresses/' . $w->id); ?>" class="text-primary small">Manage addresses</a>
                    </div>
                </li>
                <?php endforeach; ?>
            </ul>
            <?php endif; ?>
        </div>
    </div>

    <?php $this->load->view('admin/partials/sidebar'); ?>

<?php $this->load->view('layouts/footer'); ?>
