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

    <!-- App Header -->
    <div class="appHeader bg-primary text-light">
        <div class="left">
            <a href="<?php echo base_url('admin/user/' . $user_data->id); ?>" class="headerButton">
                <ion-icon name="chevron-back-outline"></ion-icon>
            </a>
        </div>
        <div class="pageTitle">Create Account</div>
        <div class="right">
            <a href="#" class="headerButton" data-bs-toggle="modal" data-bs-target="#adminSidebar">
                <ion-icon name="menu-outline"></ion-icon>
            </a>
        </div>
    </div>

    <!-- App Capsule -->
    <div id="appCapsule">
        
        <?php if ($this->session->flashdata('error')): ?>
        <div class="section mt-2">
            <div class="alert alert-danger"><?php echo $this->session->flashdata('error'); ?></div>
        </div>
        <?php endif; ?>

        <!-- User Info -->
        <div class="section mt-2">
            <div class="card">
                <div class="card-body">
                    <div class="d-flex align-items-center">
                        <img src="<?php echo get_user_avatar($user_data, 'w48'); ?>" alt="avatar" class="imaged w48 rounded me-2">
                        <div>
                            <h4 class="mb-0"><?php echo htmlspecialchars($user_data->first_name . ' ' . $user_data->last_name); ?></h4>
                            <p class="text-muted mb-0"><?php echo htmlspecialchars($user_data->email); ?></p>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="section mt-2 mb-3">
            <form action="<?php echo base_url('admin/create_account/' . $user_data->id); ?>" method="POST">
                <input type="hidden" name="<?php echo $this->security->get_csrf_token_name(); ?>" value="<?php echo $this->security->get_csrf_hash(); ?>">
                
                <div class="card">
                    <div class="card-header">Account Details</div>
                    <div class="card-body">
                        <div class="form-group basic">
                            <label class="label">Account Type *</label>
                            <select name="account_type" class="form-control" required>
                                <option value="savings">Savings</option>
                                <option value="current">Current</option>
                                <option value="virtual">Virtual</option>
                            </select>
                        </div>
                        <div class="form-group basic">
                            <label class="label">Account Name *</label>
                            <input type="text" name="account_name" class="form-control" value="<?php echo htmlspecialchars($user_data->first_name . ' ' . $user_data->last_name); ?>" required>
                        </div>
                        <div class="form-group basic">
                            <label class="label">Currency</label>
                            <select name="currency" class="form-control">
                                <option value="USD">USD - US Dollar</option>
                                <option value="EUR">EUR - Euro</option>
                                <option value="GBP">GBP - British Pound</option>
                                <option value="NGN">NGN - Nigerian Naira</option>
                            </select>
                        </div>
                        <div class="form-group basic">
                            <label class="label">Account Tier *</label>
                            <select name="tier_id" class="form-control" required>
                                <?php foreach ($tiers as $tier): ?>
                                <option value="<?php echo $tier->id; ?>">
                                    Tier <?php echo $tier->tier_level; ?> - <?php echo $tier->name; ?> 
                                    (Max: <?php echo format_money($tier->max_balance, 'USD'); ?>)
                                </option>
                                <?php endforeach; ?>
                            </select>
                        </div>
                        <div class="form-group basic">
                            <label class="label">Initial Balance</label>
                            <input type="number" name="initial_balance" class="form-control" step="0.01" min="0" value="0">
                        </div>
                    </div>
                </div>

                <div class="section mt-2">
                    <button type="submit" class="btn btn-primary btn-block btn-lg">
                        Create Account
                    </button>
                </div>
            </form>
        </div>
    </div>

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

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