<?php

$current = basename($_SERVER['PHP_SELF']);
$tipo = trim($_GET['tipo'] ?? '');

function sidebarActive(
    string $current,
    string $file,
    string $tipoActual = '',
    string $tipoEsperado = ''
): string {
    if ($current !== $file) {
        return '';
    }

    if ($tipoEsperado === '') {
        return 'active';
    }

    return $tipoActual === $tipoEsperado ? 'active' : '';
}

?>

<aside class="cm-sidebar">

    <div class="cm-sidebar-brand">

        <a href="index.php" class="cm-sidebar-logo" aria-label="Cinema México">

            <span class="cm-sidebar-logo-icon">
                <i class="fa-solid fa-film"></i>
            </span>

            <span class="cm-sidebar-logo-text">
               
            </span>

        </a>

    </div>

    <nav class="cm-sidebar-nav" aria-label="Navegación principal">

        <a
            href="index.php"
            class="cm-sidebar-link <?= sidebarActive($current, 'index.php') ?>"
        >
            <span class="cm-sidebar-link-icon">
                <i class="fa-solid fa-house"></i>
            </span>

            <span class="cm-sidebar-link-text">
                Inicio
            </span>

            <span class="cm-sidebar-link-arrow">
                <i class="fa-solid fa-chevron-right"></i>
            </span>
        </a>


        <div class="cm-sidebar-group">

            <span class="cm-sidebar-group-title">
                Próximamente
            </span>

            <a
                href="peliculas.php?tipo=Mediometraje"
                class="cm-sidebar-link <?= sidebarActive(
                    $current,
                    'peliculas.php',
                    $tipo,
                    'Mediometraje'
                ) ?>"
            >
                <span class="cm-sidebar-link-icon">
                    <i class="fa-solid fa-clock"></i>
                </span>

                <span class="cm-sidebar-link-text">
                    Mediometrajes
                </span>

                <span class="cm-sidebar-link-arrow">
                    <i class="fa-solid fa-chevron-right"></i>
                </span>
            </a>

            <a
                href="peliculas.php?tipo=Documental"
                class="cm-sidebar-link <?= sidebarActive(
                    $current,
                    'peliculas.php',
                    $tipo,
                    'Documental'
                ) ?>"
            >
                <span class="cm-sidebar-link-icon">
                    <i class="fa-solid fa-video"></i>
                </span>

                <span class="cm-sidebar-link-text">
                    Documentales
                </span>

                <span class="cm-sidebar-link-arrow">
                    <i class="fa-solid fa-chevron-right"></i>
                </span>
            </a>

        </div>


        <div class="cm-sidebar-group">

            <span class="cm-sidebar-group-title">
                Catálogo
            </span>

            <a
                href="peliculas.php?tipo=Largometraje"
                class="cm-sidebar-link <?= sidebarActive(
                    $current,
                    'peliculas.php',
                    $tipo,
                    'Largometraje'
                ) ?>"
            >
                <span class="cm-sidebar-link-icon">
                    <i class="fa-solid fa-clapperboard"></i>
                </span>

                <span class="cm-sidebar-link-text">
                    Largometrajes
                </span>

                <span class="cm-sidebar-link-arrow">
                    <i class="fa-solid fa-chevron-right"></i>
                </span>
            </a>

            <a
                href="peliculas.php?tipo=Cortometraje"
                class="cm-sidebar-link <?= sidebarActive(
                    $current,
                    'peliculas.php',
                    $tipo,
                    'Cortometraje'
                ) ?>"
            >
                <span class="cm-sidebar-link-icon">
                    <i class="fa-solid fa-ticket"></i>
                </span>

                <span class="cm-sidebar-link-text">
                    Cortometrajes
                </span>

                <span class="cm-sidebar-link-arrow">
                    <i class="fa-solid fa-chevron-right"></i>
                </span>
            </a>

            <a
                href="peliculas.php?tipo=Documental"
                class="cm-sidebar-link <?= sidebarActive(
                    $current,
                    'peliculas.php',
                    $tipo,
                    'Documental'
                ) ?>"
            >
                <span class="cm-sidebar-link-icon">
                    <i class="fa-solid fa-camera-retro"></i>
                </span>

                <span class="cm-sidebar-link-text">
                    Documentales
                </span>

                <span class="cm-sidebar-link-arrow">
                    <i class="fa-solid fa-chevron-right"></i>
                </span>
            </a>

        </div>

    </nav>

    <div class="cm-sidebar-footer">

        <span class="cm-sidebar-footer-line"></span>

        <p>
            Cine · Cultura · Memoria
        </p>

    </div>

</aside>