{% extends "base.html" %}

{% block title %}{{ section.title }} | {{ config.title }}{% endblock %}

{% block content %}
<div class="bg-white shadow overflow-hidden sm:rounded-lg">
    <div class="px-4 py-5 sm:px-6">
        <h1 class="text-3xl font-bold text-gray-900">
            {{ section.title }}
        </h1>
        {% if section.description %}
        <p class="mt-1 max-w-2xl text-sm text-gray-500">
            {{ section.description }}
        </p>
        {% endif %}
    </div>
    <div class="border-t border-gray-200">
        <div class="px-4 py-5 sm:p-6">
            <div class="prose prose-indigo lg:prose-xl text-gray-900">
                {% if section.content %}
                    {{ section.content | safe }}
                {% endif %}
            </div>
        </div>
    </div>
</div>

<div class="container mx-auto mt-8 grid gap-6 grid-cols-1 md:grid-cols-2 lg:grid-cols-3">
    {% for page in section.pages %}
        <a href="{{ page.permalink }}" class="bg-white overflow-hidden shadow rounded-lg hover:shadow-lg transition-shadow duration-300">
            {% if page.extra.image %}
                <div class="h-64 w-full overflow-hidden">
                    <img src="{{ page.extra.image }}" alt="{{ page.title }}" class="w-full h-full object-cover">
                </div>
            {% endif %}
            <div class="px-4 py-5 sm:p-6">
                <h3 class="text-lg font-medium text-gray-900 truncate">{{ page.title }}</h3>
                {% if page.description %}
                    <p class="mt-1 text-sm text-gray-500">{{ page.description }}</p>
                {% endif %}
                <div class="mt-4 flex items-center text-sm text-gray-500">
                    {% if page.date %}
                        <span>{{ page.date | date(format="%B %e, %Y") }}</span>
                    {% endif %}
                </div>
            </div>
        </a>
    {% endfor %}

    {% for subsection in section.subsections %}
        {% set subsection_data = get_section(path=subsection) %}
        <a href="{{ subsection_data.permalink }}" class="bg-white overflow-hidden shadow rounded-lg hover:shadow-lg transition-shadow duration-300">
            <div class="px-4 py-5 sm:p-6">
                <h3 class="text-lg font-medium text-gray-900 truncate">{{ subsection_data.title }}</h3>
                {% if subsection_data.description %}
                    <p class="mt-1 text-sm text-gray-500">{{ subsection_data.description }}</p>
                {% endif %}
                <div class="mt-4 flex items-center text-sm text-gray-500">
                    <span>{{ subsection_data.pages | length }} pages</span>
                </div>
            </div>
        </a>
    {% endfor %}
</div>
{% endblock %}
