{# app/templates/admin/testing-hub.html #}
{% extends "admin/base.html" %}
{% from 'shared/macros/headers.html' import page_header %}

{% block title %}Testing Hub{% endblock %}

{# ✅ CRITICAL: Link to Alpine.js component #}
{% block alpine_data %}adminTestingHub(){% endblock %}

{% block content %}
{{ page_header('Testing Hub', back_url='/admin/dashboard', back_label='Back to Dashboard') }}

<!-- Introduction Card -->
<div class="bg-gradient-to-r from-purple-600 to-indigo-600 rounded-lg shadow-lg p-6 mb-8">
    <div class="flex items-start">
        <div class="flex-shrink-0 text-gray-700 dark:text-gray-200">
            <span x-html="$icon('beaker', 'w-12 h-12')"></span>
        </div>
        <div class="ml-4">
            <h3 class="text-xl font-bold mb-2 text-gray-700 dark:text-gray-200">Testing & QA Tools</h3>
            <p class="text-gray-700 dark:text-gray-200 opacity-90">
                Comprehensive testing tools for manual QA, feature verification, and bug reproduction.
                These pages help you test specific flows without writing code.
            </p>
        </div>
    </div>
</div>

<!-- Quick Stats -->
<div class="grid gap-6 mb-8 md:grid-cols-2 xl:grid-cols-4">
    <div class="flex items-center p-4 bg-white rounded-lg shadow-xs dark:bg-gray-800">
        <div class="p-3 mr-4 text-blue-500 bg-blue-100 rounded-full dark:text-blue-100 dark:bg-blue-500">
            <span x-html="$icon('clipboard-list', 'w-5 h-5')"></span>
        </div>
        <div>
            <p class="mb-2 text-sm font-medium text-gray-600 dark:text-gray-400">Test Suites</p>
            <p class="text-lg font-semibold text-gray-700 dark:text-gray-200" x-text="stats.totalSuites"></p>
        </div>
    </div>

    <div class="flex items-center p-4 bg-white rounded-lg shadow-xs dark:bg-gray-800">
        <div class="p-3 mr-4 text-green-500 bg-green-100 rounded-full dark:text-green-100 dark:bg-green-500">
            <span x-html="$icon('check-circle', 'w-5 h-5')"></span>
        </div>
        <div>
            <p class="mb-2 text-sm font-medium text-gray-600 dark:text-gray-400">Test Cases</p>
            <p class="text-lg font-semibold text-gray-700 dark:text-gray-200" x-text="stats.totalTests + '+'"></p>
        </div>
    </div>

    <div class="flex items-center p-4 bg-white rounded-lg shadow-xs dark:bg-gray-800">
        <div class="p-3 mr-4 text-orange-500 bg-orange-100 rounded-full dark:text-orange-100 dark:bg-orange-500">
            <span x-html="$icon('lightning-bolt', 'w-5 h-5')"></span>
        </div>
        <div>
            <p class="mb-2 text-sm font-medium text-gray-600 dark:text-gray-400">Features Covered</p>
            <p class="text-lg font-semibold text-gray-700 dark:text-gray-200" x-text="stats.coverage"></p>
        </div>
    </div>

    <div class="flex items-center p-4 bg-white rounded-lg shadow-xs dark:bg-gray-800">
        <div class="p-3 mr-4 text-teal-500 bg-teal-100 rounded-full dark:text-teal-100 dark:bg-teal-500">
            <span x-html="$icon('clock', 'w-5 h-5')"></span>
        </div>
        <div>
            <p class="mb-2 text-sm font-medium text-gray-600 dark:text-gray-400">Quick Tests</p>
            <p class="text-lg font-semibold text-gray-700 dark:text-gray-200" x-text="stats.avgDuration"></p>
        </div>
    </div>
</div>

<!-- Test Suites Grid -->
<div class="grid gap-6 mb-8 md:grid-cols-2">
    <template x-for="suite in testSuites" :key="suite.id">
        <div class="bg-white dark:bg-gray-800 rounded-lg shadow-md overflow-hidden hover:shadow-xl transition-shadow duration-300">
            <div class="p-4 bg-gradient-to-r" :class="getColorClasses(suite.color).gradient">
                <div class="flex items-center justify-between">
                    <h3 class="text-xl font-semibold text-white flex items-center">
                        <span x-html="$icon(suite.icon, 'w-6 h-6 mr-2 text-white')"></span>
                        <span x-text="suite.name"></span>
                    </h3>
                    <span class="inline-flex items-center justify-center px-2 py-1 text-xs font-bold leading-none text-red-600 bg-red-100 rounded-full dark:text-red-100 dark:bg-red-600">
                        <span x-text="suite.testCount"></span> Tests
                    </span>
                </div>
            </div>

            <div class="p-6">
                <p class="text-gray-600 dark:text-gray-400 mb-4" x-text="suite.description"></p>

                <div class="space-y-2 mb-6">
                    <template x-for="feature in suite.features" :key="feature">
                        <div class="flex items-start text-sm">
                            <span x-html="$icon('check-circle', 'w-4 h-4 text-green-500 mr-2 mt-0.5 flex-shrink-0')"></span>
                            <span class="text-gray-600 dark:text-gray-400" x-text="feature"></span>
                        </div>
                    </template>
                </div>

                <div class="flex gap-2">
                    <button
                            @click="goToTest(suite.url)"
                            class="flex-1 flex items-center justify-center px-4 py-2 text-sm font-medium text-white rounded-lg transition-colors"
                            :class="getColorClasses(suite.color).button">
                        <span x-html="$icon('play', 'w-4 h-4 mr-2 text-white')"></span>
                        Run Tests
                    </button>
                    <button class="px-4 py-2 text-sm font-medium text-gray-700 dark:text-gray-300 bg-gray-100 dark:bg-gray-700 rounded-lg hover:bg-gray-200 dark:hover:bg-gray-600 transition-colors">
                        <span x-html="$icon('information-circle', 'w-5 h-5')"></span>
                    </button>
                </div>
            </div>
        </div>
    </template>
</div>

<!-- Best Practices -->
<div class="px-4 py-3 mb-8 bg-white rounded-lg shadow-md dark:bg-gray-800">
    <h2 class="mb-4 text-xl font-semibold text-gray-800 dark:text-gray-200 flex items-center">
        <span x-html="$icon('light-bulb', 'w-6 h-6 mr-2 text-yellow-500')"></span>
        Testing Best Practices
    </h2>

    <div class="grid md:grid-cols-2 gap-6">
        <div>
            <h3 class="font-semibold text-gray-700 dark:text-gray-300 mb-2">Before Testing</h3>
            <ul class="space-y-2 text-sm text-gray-600 dark:text-gray-400">
                <li class="flex items-start">
                    <span class="text-purple-600 mr-2">•</span>
                    <span>Ensure FastAPI server is running on localhost:8000</span>
                </li>
                <li class="flex items-start">
                    <span class="text-purple-600 mr-2">•</span>
                    <span>Open browser DevTools (F12) to see console logs</span>
                </li>
                <li class="flex items-start">
                    <span class="text-purple-600 mr-2">•</span>
                    <span>Check Network tab for API requests</span>
                </li>
                <li class="flex items-start">
                    <span class="text-purple-600 mr-2">•</span>
                    <span>Clear localStorage before starting fresh tests</span>
                </li>
            </ul>
        </div>

        <div>
            <h3 class="font-semibold text-gray-700 dark:text-gray-300 mb-2">During Testing</h3>
            <ul class="space-y-2 text-sm text-gray-600 dark:text-gray-400">
                <li class="flex items-start">
                    <span class="text-purple-600 mr-2">•</span>
                    <span>Follow test steps in order</span>
                </li>
                <li class="flex items-start">
                    <span class="text-purple-600 mr-2">•</span>
                    <span>Check expected results against actual behavior</span>
                </li>
                <li class="flex items-start">
                    <span class="text-purple-600 mr-2">•</span>
                    <span>Look for errors in console and network tabs</span>
                </li>
                <li class="flex items-start">
                    <span class="text-purple-600 mr-2">•</span>
                    <span>Take screenshots if you find bugs</span>
                </li>
            </ul>
        </div>
    </div>
</div>

<!-- Additional Resources -->
<div class="px-4 py-3 mb-8 bg-white rounded-lg shadow-md dark:bg-gray-800">
    <h2 class="mb-4 text-xl font-semibold text-gray-800 dark:text-gray-200 flex items-center">
        <span x-html="$icon('book-open', 'w-5 h-5 mr-2 text-blue-600')"></span>
        Additional Resources
    </h2>
    <div class="grid md:grid-cols-3 gap-4">
        <div>
            <h3 class="font-semibold text-gray-700 dark:text-gray-300 mb-2">Component Library</h3>
            <ul class="space-y-2 text-sm text-gray-600 dark:text-gray-400">
                <li class="flex items-start">
                    <a href="/admin/components">
                        <span class="text-purple-600 mr-2">•</span>
                        <span>View all available UI components</span>
                    </a>
                </li>
            </ul>
        </div>
        <div>
            <h3 class="font-semibold text-gray-700 dark:text-gray-300 mb-2">Icons Browser</h3>
            <ul class="space-y-2 text-sm text-gray-600 dark:text-gray-400">
                <li class="flex items-start">
                    <a href="/admin/icons">
                        <span class="text-purple-600 mr-2">•</span>
                        <span>Browse all available icons</span>
                    </a>
                </li>
            </ul>
        </div>
        <div>
            <h3 class="font-semibold text-gray-700 dark:text-gray-300 mb-2">API Documentation</h3>
            <ul class="space-y-2 text-sm text-gray-600 dark:text-gray-400">
                <li class="flex items-start">
                    <a href="/docs">
                        <span class="text-purple-600 mr-2">•</span>
                        <span>FastAPI endpoint reference</span>
                    </a>
                </li>
            </ul>
        </div>
    </div>
</div>

</div>
</div>
</div>
{% endblock %}

{% block extra_scripts %}
{# ✅ CRITICAL: Load JavaScript file #}
<script defer src="{{ url_for('dev_tools_static', path='admin/js/testing-hub.js') }}"></script>
{% endblock %}
