{% extends 'admin/base.html.twig' %}

{% block title %}Modüller{% endblock %}
{% block page_title %}Modül Yönetimi{% endblock %}

{% block body %}
    {# Plan info banner #}
    {% set plan = current_plan() %}
    <div class="mb-6 p-4 rounded-xl border {{ plan == 'starter' ? 'bg-green-50 border-green-200' : (plan == 'professional' ? 'bg-blue-50 border-blue-200' : 'bg-purple-50 border-purple-200') }}">
        <div class="flex items-center gap-3">
            {% if plan == 'starter' %}
                <div class="w-8 h-8 rounded-lg bg-green-100 flex items-center justify-center"><i class="fas fa-rocket text-green-500 text-sm"></i></div>
                <p class="text-sm text-green-700"><strong>Starter</strong> planınızla temel modüllere erişebilirsiniz. Daha fazla modül için paketinizi yükseltin.</p>
            {% elseif plan == 'professional' %}
                <div class="w-8 h-8 rounded-lg bg-blue-100 flex items-center justify-center"><i class="fas fa-briefcase text-blue-500 text-sm"></i></div>
                <p class="text-sm text-blue-700"><strong>Professional</strong> planınızla birçok modüle erişebilirsiniz.</p>
            {% elseif plan == 'enterprise' %}
                <div class="w-8 h-8 rounded-lg bg-purple-100 flex items-center justify-center"><i class="fas fa-gem text-purple-500 text-sm"></i></div>
                <p class="text-sm text-purple-700"><strong>Enterprise</strong> planınızla tüm modüllere erişebilirsiniz.</p>
            {% endif %}
        </div>
    </div>

    <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
        {% for module in modules %}
            {% set allowedByPlan = is_module_allowed(module.slug) or module.isCore %}
            <div class="card {{ not allowedByPlan ? 'opacity-60' : '' }}">
                <div class="card-body">
                    <div class="flex items-start justify-between">
                        <div class="flex-1">
                            <h3 class="text-lg font-semibold text-gray-900">{{ module.name }}</h3>
                            <p class="text-sm text-gray-500 mt-1">{{ module.description }}</p>
                        </div>
                        <div class="ml-4">
                            {% if not allowedByPlan %}
                                <span class="inline-flex items-center gap-1 rounded-full px-2 py-1 text-xs font-medium bg-gray-100 text-gray-500">
                                    <i class="fas fa-lock text-[10px]"></i> Kilitli
                                </span>
                            {% elseif module.isActive %}
                                <span class="badge-success">Aktif</span>
                            {% else %}
                                <span class="badge-gray">Pasif</span>
                            {% endif %}
                        </div>
                    </div>

                    <div class="mt-4 flex items-center gap-4 text-xs text-gray-400">
                        <span><i class="fas fa-code-branch mr-1"></i> v{{ module.version }}</span>
                        <span>
                            <i class="fas fa-crown mr-1"></i>
                            {{ module.requiredPlan|capitalize }}
                        </span>
                        {% if module.isCore %}
                            <span class="text-primary-500 font-medium">
                                <i class="fas fa-lock mr-1"></i> Çekirdek
                            </span>
                        {% endif %}
                    </div>

                    {% if module.dependencies|length > 0 %}
                        <div class="mt-3 text-xs text-gray-400">
                            <i class="fas fa-link mr-1"></i> Bağımlılıklar:
                            {{ module.dependencies|join(', ') }}
                        </div>
                    {% endif %}

                    {% if not module.isCore %}
                        <div class="mt-4 pt-4 border-t border-gray-100">
                            {% if not allowedByPlan %}
                                {# Plan restriction - show upgrade message #}
                                <div class="text-center py-2">
                                    <p class="text-xs text-gray-400 mb-1">
                                        <i class="fas fa-arrow-up mr-1"></i>
                                        <strong>{{ module.requiredPlan|capitalize }}</strong> ve üzeri planlarda kullanılabilir
                                    </p>
                                    <span class="text-xs text-primary-500 font-medium">Yöneticinizle iletişime geçin</span>
                                </div>
                            {% else %}
                                <form method="post" action="{{ path('admin_module_toggle', {slug: module.slug}) }}">
                                    <input type="hidden" name="_token" value="{{ csrf_token('module_toggle_' ~ module.slug) }}">
                                    {% if module.isActive %}
                                        <button type="submit" class="btn-outline btn-sm w-full justify-center">
                                            <i class="fas fa-power-off mr-1"></i> Devre Dışı Bırak
                                        </button>
                                    {% else %}
                                        <button type="submit" class="btn-primary btn-sm w-full justify-center">
                                            <i class="fas fa-check mr-1"></i> Etkinleştir
                                        </button>
                                    {% endif %}
                                </form>
                            {% endif %}
                        </div>
                    {% endif %}
                </div>
            </div>
        {% endfor %}
    </div>
{% endblock %}
