<?php $__env->startSection('content'); ?>
    <section class="page">
        <div class="section-header">
            <div>
                <h1>Model Config</h1>
                <p class="muted" style="margin: 0;">Configure which AI model powers your chatbot's conversational responses.</p>
            </div>
        </div>

        <nav class="settings-tabs" aria-label="Settings sections">
            <a href="<?php echo e(route('settings.appearance.edit')); ?>">Appearance</a>
            <a href="<?php echo e(route('settings.channels.index')); ?>">Channels</a>
            <a href="<?php echo e(route('chat-widget.show')); ?>">Chat SDKs</a>
            <a class="active" href="<?php echo e(route('settings.ai-model.edit')); ?>">Model Config</a>
        </nav>

        <?php if(session('status')): ?>
            <div class="alert success" role="alert" style="margin-bottom: 2rem;">
                <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"></path><polyline points="22 4 12 14.01 9 11.01"></polyline></svg>
                <span><?php echo e(session('status')); ?></span>
            </div>
        <?php endif; ?>

        <div class="settings-grid" style="display: grid; gap: 2rem; max-width: 800px;">
            <div class="card">
                <form action="<?php echo e(route('settings.ai-model.update')); ?>" method="POST">
                    <?php echo csrf_field(); ?>
                    <?php echo method_field('PUT'); ?>

                    <div style="margin-bottom: 1.5rem;">
                        <label for="ai_provider" class="form-label" style="display: block; margin-bottom: 0.5rem; font-weight: 500;">AI Provider</label>
                        <select name="ai_provider" id="ai_provider" class="form-input" style="width: 100%; padding: 0.75rem; border: 1px solid var(--border); border-radius: 6px;" onchange="toggleApiUrl()">
                            <option value="none" <?php echo e(old('ai_provider', $organization->ai_provider) === 'none' ? 'selected' : ''); ?>>None (Manual Mode)</option>
                            <option value="ollama" <?php echo e(old('ai_provider', $organization->ai_provider) === 'ollama' ? 'selected' : ''); ?>>Ollama (Local/Custom)</option>
                            <option value="openai" <?php echo e(old('ai_provider', $organization->ai_provider) === 'openai' ? 'selected' : ''); ?>>OpenAI</option>
                            <option value="gemini" <?php echo e(old('ai_provider', $organization->ai_provider) === 'gemini' ? 'selected' : ''); ?>>Google Gemini</option>
                            <option value="anthropic" <?php echo e(old('ai_provider', $organization->ai_provider) === 'anthropic' ? 'selected' : ''); ?>>Anthropic</option>
                        </select>
                        <?php $__errorArgs = ['ai_provider'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                            <div style="color: var(--danger); font-size: 0.875rem; margin-top: 0.25rem;"><?php echo e($message); ?></div>
                        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                    </div>

                    <div style="margin-bottom: 1.5rem;">
                        <label for="ai_model" class="form-label" style="display: block; margin-bottom: 0.5rem; font-weight: 500;">Model Name</label>
                        <input type="text" name="ai_model" id="ai_model" value="<?php echo e(old('ai_model', $organization->ai_model)); ?>" class="form-input" style="width: 100%; padding: 0.75rem; border: 1px solid var(--border); border-radius: 6px;" required>
                        <p class="muted" style="margin-top: 0.5rem; font-size: 0.875rem;">Example: <code>llama3</code>, <code>gpt-4o</code>, <code>gemini-1.5-pro</code></p>
                        <?php $__errorArgs = ['ai_model'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                            <div style="color: var(--danger); font-size: 0.875rem; margin-top: 0.25rem;"><?php echo e($message); ?></div>
                        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                    </div>

                    <div style="margin-bottom: 1.5rem;">
                        <label for="ai_api_key" class="form-label" style="display: block; margin-bottom: 0.5rem; font-weight: 500;">API Key</label>
                        <input type="password" name="ai_api_key" id="ai_api_key" value="<?php echo e(old('ai_api_key', $organization->ai_api_key)); ?>" class="form-input" style="width: 100%; padding: 0.75rem; border: 1px solid var(--border); border-radius: 6px;">
                        <p class="muted" style="margin-top: 0.5rem; font-size: 0.875rem;">Leave blank if using a local unauthenticated Ollama instance.</p>
                        <?php $__errorArgs = ['ai_api_key'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                            <div style="color: var(--danger); font-size: 0.875rem; margin-top: 0.25rem;"><?php echo e($message); ?></div>
                        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                    </div>

                    <div style="margin-bottom: 1.5rem;" id="api_url_group">
                        <label for="ai_api_url" class="form-label" style="display: block; margin-bottom: 0.5rem; font-weight: 500;">API Base URL</label>
                        <input type="url" name="ai_api_url" id="ai_api_url" value="<?php echo e(old('ai_api_url', $organization->ai_api_url)); ?>" class="form-input" style="width: 100%; padding: 0.75rem; border: 1px solid var(--border); border-radius: 6px;">
                        <p class="muted" style="margin-top: 0.5rem; font-size: 0.875rem;">Optional. For Ollama, provide the endpoint (e.g. <code>http://localhost:11434</code>).</p>
                        <?php $__errorArgs = ['ai_api_url'];
$__bag = $errors->getBag($__errorArgs[1] ?? 'default');
if ($__bag->has($__errorArgs[0])) :
if (isset($message)) { $__messageOriginal = $message; }
$message = $__bag->first($__errorArgs[0]); ?>
                            <div style="color: var(--danger); font-size: 0.875rem; margin-top: 0.25rem;"><?php echo e($message); ?></div>
                        <?php unset($message);
if (isset($__messageOriginal)) { $message = $__messageOriginal; }
endif;
unset($__errorArgs, $__bag); ?>
                    </div>

                    <div style="padding-top: 1rem; border-top: 1px solid var(--border); display: flex; justify-content: flex-end;">
                        <button type="submit" class="button primary">Save Configuration</button>
                    </div>
                </form>
            </div>
        </div>
    </section>

    <script>
        function toggleApiUrl() {
            // Optional: add logic to show/hide API URL or pre-fill it based on provider.
        }
    </script>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', [
    'title' => 'AI Model Settings | VejalNai',
    'topbarTitle' => 'Settings',
    'topbarSubtitle' => 'Configure your AI provider for smart RAG responses',
], array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH /home/ecom123/public_html/chat.shunnointernational.com/resources/views/settings/ai-model.blade.php ENDPATH**/ ?>