<?php

/**
 * The template for displaying archive active filters
 *
 * This template can be overridden by copying it to yourtheme/movie-engine/archive/active-filters.php.
 *
 * HOWEVER, on occasion MovieEngine will need to update template files and you
 * (the theme developer) will need to copy the new files to your theme to
 * maintain compatibility. We try to do this as little as possible, but it does
 * happen. When this occurs the version of the template file will be bumped and
 * the readme will list any important changes.
 *
 * @note Please do not delete our CSS classes when you customize, as it may break functionality.
 * @package Movie_Engine
 * @subpackage Movie_Engine/templates
 * @version 1.0.0
 * @since 1.0.0
 */

if (! defined("ABSPATH")) {
    exit; // Exit if accessed directly
}

// phpcs:ignore WordPress.Security.NonceVerification.Recommended
$movie_engine_current_sort = isset($_GET['orderby']) ? sanitize_text_field(wp_unslash($_GET['orderby'])) : 'date';
?>

<div class="me-library-top-bar">
    <div class="me-top-bar-left">
        <?php
        $movie_engine_show_search = $args['show_search'] ?? false;
        if ($movie_engine_show_search) :
            // phpcs:ignore WordPress.Security.NonceVerification.Recommended
            $movie_engine_search_val = isset($_GET['s']) ? sanitize_text_field(wp_unslash($_GET['s'])) : '';
        ?>
            <div class="me-library-search">
                <span class="fa-solid fa-magnifying-glass"></span>
                <input type="text" class="me-library-ajax-search" placeholder="<?php esc_html_e('Search...', 'cine-movie-engine'); ?>" value="<?php echo esc_attr($movie_engine_search_val); ?>">
            </div>
        <?php endif; ?>
        <div class="me-active-filters-container">
            <span class="me-results-count"></span>
            <div class="me-active-pills">
            </div>
        </div>
    </div>

    <div class="me-sort-container">
        <div class="me-sort-dropdown">
            <button class="me-sort-button">
                <span class="me-current-sort"><?php esc_html_e('Sort by', 'cine-movie-engine'); ?></span>
                <span class="fa-solid fa-chevron-down"></span>
            </button>
            <ul class="me-sort-list">
                <li data-sort="date" class="<?php echo ($movie_engine_current_sort === 'date' ? 'active' : ''); ?>"><?php esc_html_e('Latest', 'cine-movie-engine'); ?></li>
                <li data-sort="title_asc" class="<?php echo ($movie_engine_current_sort === 'title_asc' ? 'active' : ''); ?>"><?php esc_html_e('A to Z', 'cine-movie-engine'); ?></li>
                <li data-sort="title_desc" class="<?php echo ($movie_engine_current_sort === 'title_desc' ? 'active' : ''); ?>"><?php esc_html_e('Z to A', 'cine-movie-engine'); ?></li>
                <li data-sort="oldest"><?php esc_html_e('Oldest', 'cine-movie-engine'); ?></li>
                <li data-sort="upcoming"><?php esc_html_e('Upcoming', 'cine-movie-engine'); ?></li>
                <li data-sort="rating"><?php esc_html_e('Most Liked', 'cine-movie-engine'); ?></li>
                <li data-sort="views"><?php esc_html_e('Most Viewed', 'cine-movie-engine'); ?></li>
            </ul>
        </div>
    </div>
</div>