{% extends "base.html" %}
{% block title %}Status - LinkedIn Posts{% endblock %}

{% block content %}
<div class="mb-8">
    <h1 class="text-3xl font-bold text-white mb-2">Status</h1>
    <p class="text-gray-400">Übersicht über deinen Setup-Status</p>
</div>

{% if error %}
<div class="bg-red-900/50 border border-red-500 text-red-200 px-4 py-3 rounded-lg mb-6">
    <strong>Error:</strong> {{ error }}
</div>
{% endif %}

{% if status %}
<div class="card-bg rounded-xl border overflow-hidden">
    <!-- Header -->
    <div class="px-6 py-4 border-b border-brand-bg-light">
        <div class="flex items-center justify-between">
            <div class="flex items-center gap-4">
                <div class="w-12 h-12 rounded-full flex items-center justify-center overflow-hidden {{ 'bg-brand-highlight' if not profile_picture else '' }}">
                    {% if profile_picture %}
                    <img src="{{ profile_picture }}" alt="{{ profile.display_name }}" class="w-full h-full object-cover" loading="lazy" referrerpolicy="no-referrer">
                    {% else %}
                    <span class="text-brand-bg-dark font-bold text-lg">{{ (profile.display_name or 'U')[0] | upper }}</span>
                    {% endif %}
                </div>
                <div>
                    <h3 class="font-semibold text-white text-lg">{{ profile.display_name or session.linkedin_name or 'Unbekannt' }}</h3>
                    <p class="text-sm text-gray-400">
                        {% if session.account_type == 'ghostwriter' %}
                        Ghostwriter
                        {% else %}
                        {{ session.company_name or 'Kein Unternehmen' }}
                        {% endif %}
                    </p>
                </div>
            </div>
            <div class="flex items-center gap-2">
                {% if status.ready_for_posts %}
                <span class="px-3 py-1.5 bg-green-600/30 text-green-300 rounded-lg text-sm font-medium flex items-center gap-2">
                    <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/></svg>
                    Bereit für Posts
                </span>
                {% else %}
                <span class="px-3 py-1.5 bg-yellow-600/30 text-yellow-300 rounded-lg text-sm font-medium flex items-center gap-2">
                    <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"/></svg>
                    Setup unvollständig
                </span>
                {% endif %}
            </div>
        </div>
    </div>

    <!-- Status Grid -->
    <div class="p-6">
        <div class="grid grid-cols-2 md:grid-cols-4 gap-4 mb-6">
            <!-- Scraped Posts -->
            <div class="bg-brand-bg/30 rounded-lg p-4">
                <div class="flex items-center gap-2 mb-2">
                    {% if status.has_scraped_posts %}
                    <svg class="w-5 h-5 text-green-500" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/></svg>
                    {% else %}
                    <svg class="w-5 h-5 text-gray-500" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/></svg>
                    {% endif %}
                    <span class="text-sm text-gray-400">Scraped Posts</span>
                </div>
                <p class="text-2xl font-bold text-white">{{ status.scraped_posts_count }}</p>
            </div>

            <!-- Profile Analysis -->
            <div class="bg-brand-bg/30 rounded-lg p-4">
                <div class="flex items-center gap-2 mb-2">
                    {% if status.has_profile_analysis %}
                    <svg class="w-5 h-5 text-green-500" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/></svg>
                    {% else %}
                    <svg class="w-5 h-5 text-gray-500" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/></svg>
                    {% endif %}
                    <span class="text-sm text-gray-400">Profil Analyse</span>
                </div>
                <p class="text-lg font-semibold text-white">{{ 'Vorhanden' if status.has_profile_analysis else 'Fehlt' }}</p>
            </div>

            <!-- Research Topics -->
            <div class="bg-brand-bg/30 rounded-lg p-4">
                <div class="flex items-center gap-2 mb-2">
                    {% if status.research_count > 0 %}
                    <svg class="w-5 h-5 text-green-500" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/></svg>
                    {% else %}
                    <svg class="w-5 h-5 text-gray-500" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/></svg>
                    {% endif %}
                    <span class="text-sm text-gray-400">Research Topics</span>
                </div>
                <p class="text-2xl font-bold text-white">{{ status.research_count }}</p>
            </div>

            <!-- Generated Posts -->
            <div class="bg-brand-bg/30 rounded-lg p-4">
                <div class="flex items-center gap-2 mb-2">
                    <svg class="w-5 h-5 text-brand-highlight" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/></svg>
                    <span class="text-sm text-gray-400">Generierte Posts</span>
                </div>
                <p class="text-2xl font-bold text-white">{{ status.posts_count }}</p>
            </div>
        </div>

        <!-- Missing Items -->
        {% if status.missing_items %}
        <div class="bg-yellow-900/20 border border-yellow-600/50 rounded-lg p-4">
            <h4 class="font-medium text-yellow-300 mb-2 flex items-center gap-2">
                <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"/></svg>
                Fehlende Elemente
            </h4>
            <ul class="space-y-1">
                {% for item in status.missing_items %}
                <li class="text-yellow-200/80 text-sm flex items-center gap-2">
                    <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"/></svg>
                    {{ item }}
                </li>
                {% endfor %}
            </ul>
        </div>
        {% endif %}

        <!-- Quick Actions -->
        <div class="flex gap-3 mt-4">
            {% if status.research_count == 0 %}
            <a href="/research" class="px-4 py-2 bg-green-600 hover:bg-green-700 rounded-lg text-sm text-white transition-colors">
                Recherche starten
            </a>
            {% endif %}
            {% if status.ready_for_posts %}
            <a href="/create" class="px-4 py-2 btn-primary rounded-lg text-sm transition-colors">
                Post erstellen
            </a>
            {% endif %}
        </div>
    </div>
</div>
{% else %}
<div class="card-bg rounded-xl border p-12 text-center">
    <svg class="w-16 h-16 text-gray-600 mx-auto mb-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"/></svg>
    <h3 class="text-xl font-semibold text-white mb-2">Status nicht verfügbar</h3>
    <p class="text-gray-400 mb-6">Es konnte kein Status geladen werden.</p>
</div>
{% endif %}
{% endblock %}
