<?php $pageTitle = 'AI Settings'; ?>
<div class="mb-4"><p class="text-secondary">Configure AI providers for question generation, summaries, and assistant features</p></div>
<div class="row g-4">
    <div class="col-lg-5">
        <div class="card-cix">
            <div class="card-cix-header"><h5 class="mb-0"><i class="fas fa-robot text-orange me-2"></i> Add/Edit Provider</h5></div>
            <form method="POST" action="<?= base_url('admin/ai-settings') ?>"><?= csrf_field() ?>
                <input type="hidden" name="edit_id" value="" id="editId">
                <div class="form-group-cix"><label class="form-label-cix">Name *</label><input type="text" name="name" class="form-control-cix" id="providerName" required placeholder="e.g., OpenAI, Groq, DeepSeek"></div>
                <div class="form-group-cix"><label class="form-label-cix">Base URL *</label><input type="text" name="base_url" class="form-control-cix" id="providerUrl" required placeholder="https://api.openai.com/v1"></div>
                <div class="form-group-cix"><label class="form-label-cix">API Key</label><input type="password" name="api_key" class="form-control-cix" id="providerKey"></div>
                <div class="form-group-cix"><label class="form-label-cix">Model</label><input type="text" name="model" class="form-control-cix" id="providerModel" placeholder="gpt-4o"></div>
                <div class="row g-2">
                    <div class="col-6"><div class="form-group-cix"><label class="form-label-cix">Temperature</label><input type="number" name="temperature" class="form-control-cix" value="0.7" step="0.1" min="0" max="2"></div></div>
                    <div class="col-6"><div class="form-group-cix"><label class="form-label-cix">Max Tokens</label><input type="number" name="max_tokens" class="form-control-cix" value="1000"></div></div>
                </div>
                <div class="form-check mb-2"><input class="form-check-input" type="checkbox" name="is_active" value="1" checked><label class="form-check-label text-secondary">Active</label></div>
                <div class="form-check mb-3"><input class="form-check-input" type="checkbox" name="is_default"><label class="form-check-label text-secondary">Default Provider</label></div>
                <button type="submit" class="btn-cix btn-cix-accent w-100"><i class="fas fa-save"></i> Save Provider</button>
            </form>
        </div>
    </div>
    <div class="col-lg-7">
        <div class="card-cix">
            <div class="card-cix-header"><h5 class="mb-0"><i class="fas fa-list text-orange me-2"></i> Configured Providers</h5></div>
            <?php if (empty($providers)): ?>
                <div class="empty-state"><i class="fas fa-robot"></i><h5>No Providers</h5><p>Add your first AI provider to enable AI features.</p></div>
            <?php else: ?>
                <?php foreach ($providers as $prov): ?>
                <div style="padding:1rem;border-bottom:1px solid var(--border);">
                    <div class="d-flex justify-content-between align-items-center">
                        <div><strong><?= e($prov['name']) ?></strong> <small class="text-secondary"><?= e($prov['model'] ?? '') ?></small>
                        <?php if ($prov['is_default']): ?><span class="badge-cix badge-active" style="font-size:0.65rem;">DEFAULT</span><?php endif; ?></div>
                        <span class="badge-cix <?= $prov['is_active'] ? 'badge-active' : 'badge-rejected' ?>"><?= $prov['is_active'] ? 'Active' : 'Inactive' ?></span>
                    </div>
                    <small class="text-secondary"><?= e($prov['base_url']) ?></small>
                </div>
                <?php endforeach; ?>
            <?php endif; ?>
        </div>
    </div>
</div>
