<div class="page-title d-flex justify-content-between align-items-center">
    <h2><i class="bi bi-pencil"></i> Edit Campaign</h2>
    <a href="<?= base_url('admin/campaign_view/' . $campaign->id) ?>" class="btn btn-secondary">
        <i class="bi bi-arrow-left"></i> Back
    </a>
</div>

<div class="row">
    <div class="col-md-8">
        <div class="card">
            <div class="card-body">
                <?= validation_errors('<div class="alert alert-danger">', '</div>') ?>
                
                <form method="post" action="">
                    <div class="mb-3">
                        <label class="form-label"><strong>Campaign Name *</strong></label>
                        <input type="text" class="form-control" name="name" value="<?= set_value('name', $campaign->name) ?>" required>
                    </div>
                    
                    <div class="mb-3">
                        <label class="form-label"><strong>Campaign Type *</strong></label>
                        <select class="form-select" name="type" required>
                            <option value="">Select Type</option>
                            <option value="SMS" <?= $campaign->type == 'SMS' ? 'selected' : '' ?>>SMS</option>
                            <option value="WhatsApp" <?= $campaign->type == 'WhatsApp' ? 'selected' : '' ?>>WhatsApp</option>
                            <option value="WhatsApp Image" <?= $campaign->type == 'WhatsApp Image' ? 'selected' : '' ?>>WhatsApp Image</option>
                            <option value="Status Messaging" <?= $campaign->type == 'Status Messaging' ? 'selected' : '' ?>>Status Messaging</option>
                            <option value="Newsletter" <?= $campaign->type == 'Newsletter' ? 'selected' : '' ?>>Newsletter</option>
                            <option value="Custom" <?= $campaign->type == 'Custom' ? 'selected' : '' ?>>Custom</option>
                        </select>
                    </div>
                    
                    <div class="mb-3">
                        <label class="form-label"><strong>Fail Percentage (%) *</strong></label>
                        <input type="number" class="form-control" name="fail_percentage" value="<?= set_value('fail_percentage', $campaign->fail_percentage) ?>" step="0.01" min="0.01" max="100" required>
                        <small class="text-muted">Set the expected failure rate (0.01% to 100%). Extra records will be assigned to compensate.</small>
                    </div>
                    
                    <div class="alert alert-info">
                        <i class="bi bi-info-circle"></i> <strong>Note:</strong> Changing fail percentage will affect future data assignments. Existing assigned data will remain unchanged.
                    </div>
                    
                    <button type="submit" class="btn btn-primary">
                        <i class="bi bi-save"></i> Update Campaign
                    </button>
                    <a href="<?= base_url('admin/campaign_view/' . $campaign->id) ?>" class="btn btn-secondary">Cancel</a>
                </form>
            </div>
        </div>
    </div>
    
    <div class="col-md-4">
        <div class="card">
            <div class="card-body">
                <h5 class="mb-3"><i class="bi bi-info-circle"></i> Campaign Info</h5>
                <p><strong>Status:</strong> <span class="badge bg-<?= $campaign->status == 'active' ? 'success' : ($campaign->status == 'paused' ? 'warning' : ($campaign->status == 'stopped' ? 'danger' : 'secondary')) ?>"><?= ucfirst($campaign->status) ?></span></p>
                <p><strong>Created By:</strong> Admin</p>
                <p><strong>Created:</strong> <?= date('M d, Y', strtotime($campaign->created_at)) ?></p>
                <hr>
                <h6>Current Statistics:</h6>
                <p class="mb-1"><strong>Total Assigned:</strong> <?= number_format($campaign->total_assigned) ?></p>
                <p class="mb-1"><strong>Sent:</strong> <?= number_format($campaign->total_sent) ?></p>
                <p class="mb-1"><strong>Failed:</strong> <?= number_format($campaign->total_failed) ?></p>
                <p class="mb-1"><strong>Remaining:</strong> <?= number_format($campaign->total_remaining ?? max(0, ($campaign->total_assigned ?? 0) - ($campaign->total_sent ?? 0) - ($campaign->total_failed ?? 0))) ?></p>
            </div>
        </div>
    </div>
</div>
