

<?php $__env->startSection('title', 'AI Yönetimi'); ?>

<?php $__env->startSection('header-title', 'AI Yönetimi'); ?>

<?php $__env->startSection('header-actions'); ?>
<a href="<?php echo e(route('admin.ai-settings.create')); ?>" class="header-action-btn primary">
    <svg fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2">
        <path stroke-linecap="round" stroke-linejoin="round" d="M12 4v16m8-8H4"/>
    </svg>
    Yeni AI Ayarı
</a>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>

<?php if($activeSetting): ?>
    <div class="alert alert-success">
        <span class="alert-icon">✅</span>
        <div>
            <strong>Aktif AI:</strong> <?php echo e($activeSetting->provider_icon); ?> <?php echo e($activeSetting->name); ?>

            (<?php echo e($activeSetting->provider_label); ?>)
        </div>
    </div>
<?php else: ?>
    <div class="alert alert-warning">
        <span class="alert-icon">⚠️</span>
        <div>
            <strong>Aktif AI ayarı yok!</strong> AI özelliklerini kullanmak için bir ayar oluşturun ve aktif edin.
        </div>
    </div>
<?php endif; ?>


<div class="stats-grid">
    <div class="stat-card">
        <div class="stat-icon" style="background: linear-gradient(135deg, #3b82f6, #8b5cf6);">⚙️</div>
        <div class="stat-info">
            <div class="stat-value"><?php echo e($settings->total()); ?></div>
            <div class="stat-label">Toplam Ayar</div>
        </div>
    </div>
    <div class="stat-card">
        <div class="stat-icon" style="background: linear-gradient(135deg, #10b981, #059669);">✅</div>
        <div class="stat-info">
            <div class="stat-value"><?php echo e($activeSetting ? 1 : 0); ?></div>
            <div class="stat-label">Aktif Ayar</div>
        </div>
    </div>
    <div class="stat-card">
        <div class="stat-icon" style="background: linear-gradient(135deg, #f59e0b, #d97706);">🤖</div>
        <div class="stat-info">
            <div class="stat-value"><?php echo e(\App\Models\AiSetting::getForProvider('ollama')->count()); ?></div>
            <div class="stat-label">Ollama Ayarları</div>
        </div>
    </div>
    <div class="stat-card">
        <div class="stat-icon" style="background: linear-gradient(135deg, #ef4444, #dc2626);">💰</div>
        <div class="stat-info">
            <div class="stat-value"><?php echo e(\App\Models\AiSetting::getForProvider('openai')->count()); ?></div>
            <div class="stat-label">OpenAI Ayarları</div>
        </div>
    </div>
</div>


<div class="card">
    <div class="card-header">
        <div>
            <div class="card-title">AI Ayarları</div>
            <div class="card-subtitle">Tüm yapılandırılmış AI sağlayıcıları</div>
        </div>
    </div>
    <div class="card-body" style="padding: 0;">
        <?php if($settings->count() > 0): ?>
            <div class="table-wrap">
                <table class="table">
                    <thead>
                        <tr>
                            <th>Provider</th>
                            <th>Ayar Adı</th>
                            <th>Model</th>
                            <th>API URL</th>
                            <th>Durum</th>
                            <th style="text-align: right;">İşlemler</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php $__currentLoopData = $settings; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $setting): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <tr>
                                <td>
                                    <span style="font-size: 18px;"><?php echo e($setting->provider_icon); ?></span>
                                    <span style="font-weight: 500; margin-left: 6px;"><?php echo e($setting->provider_label); ?></span>
                                </td>
                                <td>
                                    <div style="font-weight: 500;"><?php echo e($setting->name); ?></div>
                                    <?php if($setting->is_active): ?>
                                        <span class="badge badge-green" style="margin-top: 4px;">Aktif</span>
                                    <?php endif; ?>
                                </td>
                                <td><code style="font-size: 12px; background: #f1f5f9; padding: 2px 6px; border-radius: 4px;"><?php echo e($setting->model); ?></code></td>
                                <td>
                                    <div style="font-size: 12px; color: #64748b; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">
                                        <?php echo e($setting->api_url); ?>

                                    </div>
                                </td>
                                <td>
                                    <?php if($setting->is_active): ?>
                                        <span class="badge badge-green">Aktif</span>
                                    <?php else: ?>
                                        <span class="badge badge-gray">Pasif</span>
                                    <?php endif; ?>
                                </td>
                                <td style="text-align: right;">
                                    <div style="display: flex; gap: 6px; justify-content: flex-end;">
                                        <?php if(!$setting->is_active): ?>
                                            <button onclick="toggleActive(<?php echo e($setting->id); ?>)" class="btn btn-sm btn-success" title="Aktif Et">
                                                <svg fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2" style="width: 14px; height: 14px;">
                                                    <path stroke-linecap="round" stroke-linejoin="round" d="M5 13l4 4L19 7"/>
                                                </svg>
                                            </button>
                                        <?php endif; ?>
                                        <a href="<?php echo e(route('admin.ai-settings.edit', $setting)); ?>" class="btn btn-sm btn-secondary" title="Düzenle">
                                            <svg fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2" style="width: 14px; height: 14px;">
                                                <path stroke-linecap="round" stroke-linejoin="round" d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"/>
                                            </svg>
                                        </a>
                                        <button onclick="deleteSetting(<?php echo e($setting->id); ?>)" class="btn btn-sm btn-danger" title="Sil">
                                            <svg fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2" style="width: 14px; height: 14px;">
                                                <path stroke-linecap="round" stroke-linejoin="round" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"/>
                                            </svg>
                                        </button>
                                    </div>
                                </td>
                            </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </tbody>
                </table>
            </div>
        <?php else: ?>
            <div class="empty-state">
                <span class="empty-icon">⚙️</span>
                <div class="empty-title">Henüz AI ayarı yok</div>
                <div class="empty-desc">AI özelliklerini kullanmak için yeni bir ayar oluşturun.</div>
                <a href="<?php echo e(route('admin.ai-settings.create')); ?>" class="btn btn-primary">İlk Ayarı Oluştur</a>
            </div>
        <?php endif; ?>
    </div>
    <?php if($settings->hasPages()): ?>
        <div class="card-footer">
            <?php echo e($settings->appends(['sort' => request('sort')])->links()); ?>

        </div>
    <?php endif; ?>
</div>


<div class="card" style="margin-top: 24px;">
    <div class="card-header">
        <div class="card-title">Desteklenen AI Sağlayıcıları</div>
    </div>
    <div class="card-body">
        <div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 16px;">
            <div style="border: 1px solid #e2e8f0; border-radius: 8px; padding: 16px;">
                <div style="display: flex; align-items: center; gap: 10px; margin-bottom: 8px;">
                    <span style="font-size: 24px;">🤖</span>
                    <div style="font-weight: 600;">OpenAI</div>
                </div>
                <p style="font-size: 13px; color: #64748b; margin-bottom: 8px;">GPT-3.5, GPT-4 ve diğer OpenAI modelleri. Ücretli API anahtarı gerekir.</p>
                <span class="badge badge-red">Ücretli</span>
            </div>
            <div style="border: 1px solid #e2e8f0; border-radius: 8px; padding: 16px;">
                <div style="display: flex; align-items: center; gap: 10px; margin-bottom: 8px;">
                    <span style="font-size: 24px;">🦙</span>
                    <div style="font-weight: 600;">Ollama</div>
                </div>
                <p style="font-size: 13px; color: #64748b; margin-bottom: 8px;">Yerel LLM çalıştırma. Llama2, Mistral vb. modelleri destekler. Tamamen ücretsiz.</p>
                <span class="badge badge-green">Ücretsiz</span>
            </div>
            <div style="border: 1px solid #e2e8f0; border-radius: 8px; padding: 16px;">
                <div style="display: flex; align-items: center; gap: 10px; margin-bottom: 8px;">
                    <span style="font-size: 24px;">💻</span>
                    <div style="font-weight: 600;">LM Studio</div>
                </div>
                <p style="font-size: 13px; color: #64748b; margin-bottom: 8px;">Yerel model sunucusu. OpenAI uyumlu API. Tamamen ücretsiz.</p>
                <span class="badge badge-green">Ücretsiz</span>
            </div>
            <div style="border: 1px solid #e2e8f0; border-radius: 8px; padding: 16px;">
                <div style="display: flex; align-items: center; gap: 10px; margin-bottom: 8px;">
                    <span style="font-size: 24px;">⚙️</span>
                    <div style="font-weight: 600;">Custom</div>
                </div>
                <p style="font-size: 13px; color: #64748b; margin-bottom: 8px;">OpenAI uyumlu herhangi bir API. Kendi sunucunuzu kullanın.</p>
                <span class="badge badge-blue">Özel</span>
            </div>
        </div>
    </div>
</div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('scripts'); ?>
<script>
function toggleActive(id) {
    if (!confirm('Bu ayarı aktif etmek istediğinizden emin misiniz? Diğer aktif ayar devre dışı bırakılacak.')) return;

    fetch(`<?php echo e(route('admin.ai-settings.toggle', ':id')); ?>`.replace(':id', id), {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json',
            'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').content
        }
    })
    .then(r => r.json())
    .then(data => {
        if (data.success) {
            showToast(data.message, 'success');
            setTimeout(() => location.reload(), 1000);
        } else {
            showToast(data.message || 'İşlem başarısız', 'error');
        }
    })
    .catch(() => showToast('Bir hata oluştu', 'error'));
}

function deleteSetting(id) {
    if (!confirm('Bu ayarı silmek istediğinizden emin misiniz?')) return;

    fetch(`<?php echo e(route('admin.ai-settings.destroy', ':id')); ?>`.replace(':id', id), {
        method: 'DELETE',
        headers: {
            'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').content,
            'Accept': 'application/json'
        }
    })
    .then(r => r.json())
    .then(data => {
        if (data.success) {
            showToast(data.message || 'Ayar başarıyla silindi', 'success');
            setTimeout(() => location.reload(), 1000);
        } else {
            showToast(data.message || 'Silme başarısız', 'error');
        }
    })
    .catch(() => showToast('Bir hata oluştu', 'error'));
}
</script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('admin.layout', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\xampp\htdocs\askeribilgiler\resources\views\admin\ai\index.blade.php ENDPATH**/ ?>