{% extends "admin_base.html" %}
{% block admin_content %}
<div class="admin-toolbar">
    <h2>Settings</h2>
</div>

<form method="POST" action="/admin/settings" class="admin-settings-form">
    <h3 style="font-size: 0.875rem; font-weight: 700; margin-bottom: 0.75rem; color: var(--text-secondary);">General</h3>

    <div class="admin-field">
        <label for="site_name">Site Name</label>
        <input type="text" id="site_name" name="site_name" value="{{ settings.get('site_name', 'DevPlace') }}" maxlength="200">
    </div>

    <div class="admin-field">
        <label for="site_description">Site Description</label>
        <textarea id="site_description" name="site_description" rows="3" maxlength="500">{{ settings.get('site_description', 'The Developer Social Network') }}</textarea>
    </div>

    <div class="admin-field">
        <label for="site_tagline">Tagline</label>
        <input type="text" id="site_tagline" name="site_tagline" value="{{ settings.get('site_tagline', 'Track industry shifts. Discover bold releases. Share what you are building in an open, uncensored environment.') }}" maxlength="500">
    </div>

    <hr style="border: none; border-top: 1px solid var(--border); margin: 1.5rem 0;">

    <h3 style="font-size: 0.875rem; font-weight: 700; margin-bottom: 0.75rem; color: var(--text-secondary);">News Service</h3>

    <div class="admin-field">
        <label for="news_grade_threshold">Grade Threshold (1-10)</label>
        <input type="number" id="news_grade_threshold" name="news_grade_threshold" value="{{ settings.get('news_grade_threshold', '7') }}" min="1" max="10" style="width: 100px;">
        <small class="hint-text">Articles with grade >= threshold are auto-published. Below this they go to draft.</small>
    </div>

    <div class="admin-field">
        <label for="news_api_url">News API URL</label>
        <input type="url" id="news_api_url" name="news_api_url" value="{{ settings.get('news_api_url', 'https://news.app.molodetz.nl/api') }}" maxlength="500">
    </div>

    <div class="admin-field">
        <label for="news_ai_url">AI Grading URL</label>
        <input type="url" id="news_ai_url" name="news_ai_url" value="{{ settings.get('news_ai_url', 'https://openai.app.molodetz.nl/v1/chat/completions') }}" maxlength="500">
    </div>

    <div class="admin-field">
        <label for="news_ai_model">AI Model</label>
        <input type="text" id="news_ai_model" name="news_ai_model" value="{{ settings.get('news_ai_model', 'molodetz') }}" maxlength="200">
    </div>

    <div class="admin-field">
        <label for="news_ai_key">AI API Key</label>
        <input type="password" id="news_ai_key" name="news_ai_key" value="{{ settings.get('news_ai_key', '') }}" maxlength="500" placeholder="Leave empty to use NEWS_AI_KEY env var">
        <small class="hint-text">Falls back to OPENROUTER_API_KEY or OPENAI_API_KEY env vars if both field and NEWS_AI_KEY are empty.</small>
    </div>

    <hr style="border: none; border-top: 1px solid var(--border); margin: 1.5rem 0;">

    <h3 style="font-size: 0.875rem; font-weight: 700; margin-bottom: 0.75rem; color: var(--text-secondary);">Uploads & Attachments</h3>

    <div class="admin-field">
        <label for="max_upload_size_mb">Max Upload Size (MB)</label>
        <input type="number" id="max_upload_size_mb" name="max_upload_size_mb" value="{{ settings.get('max_upload_size_mb', '10') }}" min="1" max="500" style="width: 120px;">
        <small class="hint-text">Maximum file size per upload in megabytes.</small>
    </div>

    <div class="admin-field">
        <label for="allowed_file_types">Allowed File Types</label>
        <input type="text" id="allowed_file_types" name="allowed_file_types" value="{{ settings.get('allowed_file_types', '') }}" maxlength="1000" placeholder="e.g. .png,.jpg,.pdf,.zip (leave empty for default)">
        <small class="hint-text">Comma-separated list of allowed extensions. Leave empty to allow all supported types.</small>
    </div>

    <div class="admin-field">
        <label for="max_attachments_per_resource">Max Attachments Per Resource</label>
        <input type="number" id="max_attachments_per_resource" name="max_attachments_per_resource" value="{{ settings.get('max_attachments_per_resource', '10') }}" min="1" max="50" style="width: 120px;">
        <small class="hint-text">Maximum number of files that can be attached to a single post, comment, etc.</small>
    </div>

    <button type="submit" class="btn btn-primary"><span class="icon">&#x1F4BE;</span>Save Settings</button>
</form>
{% endblock %}
