{% extends 'admin/base.html' %}
{% block title %}{{ t('tools.title') }}{% endblock %}

{% block content %}
<div class="page-header">
    <h2>🔧 {{ t('tools.title') }}</h2>
    <p>{{ t('tools.subtitle') }}</p>
</div>

<div class="tools-grid">
    <!-- Sitemap -->
    <div class="tool-card">
        <h3>🗺️ {{ t('tools.sitemap_title') }}</h3>
        <p>{{ t('tools.sitemap_desc') }}</p>
        <div class="stat-row">
            <span class="stat-label">{{ t('tools.sitemap_status') }}</span>
            <span class="status-badge status-active">✅ {{ t('tools.sitemap_active') }}</span>
        </div>
        <div class="stat-row">
            <span class="stat-label">{{ t('tools.total_urls') }}</span>
            <span class="stat-value">{{ sitemap_count }}</span>
        </div>
        <div class="stat-row">
            <span class="stat-label">{{ t('tools.published_posts') }}</span>
            <span class="stat-value">{{ post_count }}</span>
        </div>
        <div class="stat-row">
            <span class="stat-label">{{ t('tools.published_pages') }}</span>
            <span class="stat-value">{{ page_count }}</span>
        </div>
        <div class="stat-row">
            <span class="stat-label">{{ t('tools.homepage') }}</span>
            <span class="stat-value">1</span>
        </div>
        <div class="url-box">
            <span class="url-display" id="sitemapUrl">/sitemap.xml</span>
            <a href="/sitemap.xml" target="_blank" class="btn btn-secondary">🔗 {{ t('tools.view') }}</a>
        </div>
        <p class="text-sm text-muted mt-3">💡 {{ t('tools.sitemap_auto') }}</p>
    </div>

    <!-- Robots.txt -->
    <div class="tool-card">
        <h3>🤖 {{ t('tools.robots_title') }}</h3>
        <p>{{ t('tools.robots_desc') }}</p>
        <form method="POST">
            <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
            <div class="form-group">
                <label for="robots_txt">{{ t('tools.robots_content') }}</label>
                <textarea id="robots_txt" name="robots_txt" rows="10">{{ robots_content }}</textarea>
                <div class="help-text">{{ t('tools.robots_help') }}</div>
            </div>
            <div class="flex gap-3 items-center">
                <button type="submit" class="btn btn-primary">💾 {{ t('tools.save') }}</button>
                <a href="/robots.txt" target="_blank" class="btn btn-secondary">🔗 {{ t('tools.view') }}</a>
                <button type="button" class="btn btn-secondary" onclick="resetRobots()">↩️ {{ t('tools.reset_default') }}</button>
            </div>
        </form>
    </div>

    <!-- RSS Feed -->
    <div class="tool-card">
        <h3>📡 {{ t('tools.rss_title') }}</h3>
        <p>{{ t('tools.rss_desc') }}</p>
        <div class="stat-row">
            <span class="stat-label">{{ t('tools.sitemap_status') }}</span>
            <span class="status-badge status-active">✅ {{ t('tools.sitemap_active') }}</span>
        </div>
        <div class="stat-row">
            <span class="stat-label">{{ t('tools.rss_posts_per_feed') }}</span>
            <span class="stat-value">20</span>
        </div>
        <div class="mt-4">
            <div class="url-box mb-2">
                <span class="url-display">/feed</span>
                <a href="/feed" target="_blank" class="btn btn-secondary">🔗 {{ t('tools.view') }}</a>
            </div>
            {% for lang in active_languages %}
            <div class="url-box mb-1">
                <span class="url-display">/feed/{{ lang.code }}</span>
                <a href="/feed/{{ lang.code }}" target="_blank" class="btn btn-secondary btn-sm">🔗 {{ lang.name }}</a>
            </div>
            {% endfor %}
        </div>
        <p class="text-sm text-muted mt-3">💡 {{ t('tools.rss_auto') }}</p>
    </div>

    <!-- llms.txt -->
    <div class="tool-card">
        <h3>🤖 {{ t('tools.llms_title') }}</h3>
        <p>{{ t('tools.llms_desc') }}</p>
        <div class="stat-row">
            <span class="stat-label">{{ t('tools.sitemap_status') }}</span>
            <span class="status-badge status-active">✅ {{ t('tools.sitemap_active') }}</span>
        </div>
        <div class="stat-row">
            <span class="stat-label">{{ t('tools.llms_posts_included') }}</span>
            <span class="stat-value">{{ llms_post_count }}</span>
        </div>
        <div class="stat-row">
            <span class="stat-label">{{ t('tools.llms_pages_included') }}</span>
            <span class="stat-value">{{ llms_page_count }}</span>
        </div>
        <div class="url-box">
            <span class="url-display">/llms.txt</span>
            <a href="/llms.txt" target="_blank" class="btn btn-secondary">🔗 {{ t('tools.view') }}</a>
        </div>
        <p class="text-sm text-muted mt-3">💡 {{ t('tools.llms_auto') }}</p>
    </div>
</div>
{% endblock %}

{% block extra_js %}
<script>
function resetRobots() {
    if (confirm('{{ t("tools.reset_confirm") }}')) {
        document.getElementById('robots_txt').value = 'User-agent: *\nAllow: /\n\nUser-agent: GPTBot\nAllow: /\n\nUser-agent: Google-Extended\nAllow: /\n\nUser-agent: ClaudeBot\nAllow: /\n\nUser-agent: Amazonbot\nAllow: /';
    }
}
</script>
{% endblock %}
