<?php

/**
 * Filter sidebar for Person archive filter person sidebar
 *
 * This template can be overridden by copying it to yourtheme/movie-engine/archive/filter-person-sidebar.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;
}

$movie_engine_collapse_all = !empty($args['collapse_all']);
?>
<aside class="movie-engine-filter-sidebar">
    <div class="me-filter-sidebar-header">
        <h3>
            <?php esc_html_e('FILTERS', 'cine-movie-engine'); ?>
            <span class="me-filter-active-count me-hidden">0</span>
        </h3>
        <button type="button" class="me-clear-all-filters me-hidden"><?php esc_html_e('Clear All', 'cine-movie-engine'); ?></button>
    </div>

    <div class="me-filter-sidebar-scroll">
        <?php if (!empty($movie_engine_departments)) : ?>
            <div class="me-filter-section<?php echo $movie_engine_collapse_all ? ' is-collapsed' : ''; ?>" data-filter="movie_engine_known_for">
                <h4 class="me-filter-section-title">
                    <?php esc_html_e('Department', 'cine-movie-engine'); ?>
                    <span class="fa-solid fa-angle-right"></span>
                </h4>
                <div class="me-filter-options">
                    <?php foreach ($movie_engine_departments as $movie_engine_dept) : ?>
                        <label class="me-filter-checkbox">
                            <input type="checkbox" name="movie_engine_known_for[]" value="<?php echo esc_attr($movie_engine_dept); ?>" <?php checked(in_array($movie_engine_dept, $movie_engine_active_departments)); ?>>
                            <span class="me-checkbox-label"><?php echo esc_html($movie_engine_dept); ?></span>
                        </label>
                    <?php endforeach; ?>
                </div>
            </div>
        <?php endif; ?>

        <?php if (!empty($movie_engine_genders)) :
            $movie_engine_gender_labels = [
                '0' => esc_html__('Other', 'cine-movie-engine'),
                '1' => esc_html__('Female', 'cine-movie-engine'),
                '2' => esc_html__('Male', 'cine-movie-engine'),
                '3' => esc_html__('Non-binary', 'cine-movie-engine'),
            ];
        ?>
            <div class="me-filter-section is-collapsed" data-filter="me_gender">
                <h4 class="me-filter-section-title">
                    <?php esc_html_e('Gender', 'cine-movie-engine'); ?>
                    <span class="fa-solid fa-angle-right"></span>
                </h4>
                <div class="me-filter-options">
                    <?php foreach ($movie_engine_genders as $movie_engine_gender_val) : ?>
                        <label class="me-filter-checkbox">
                            <input type="checkbox" name="me_gender[]" value="<?php echo esc_attr($movie_engine_gender_val); ?>" <?php checked(in_array((string)$movie_engine_gender_val, $movie_engine_active_genders)); ?>>
                            <span class="me-checkbox-label"><?php echo esc_html($movie_engine_gender_labels[$movie_engine_gender_val] ?? $movie_engine_gender_val); ?></span>
                        </label>
                    <?php endforeach; ?>
                </div>
            </div>
        <?php endif; ?>

        <?php if (!empty($movie_engine_birth_years)) : ?>
            <div class="me-filter-section is-collapsed" data-filter="me_birth_year">
                <h4 class="me-filter-section-title">
                    <?php esc_html_e('Birth Year', 'cine-movie-engine'); ?>
                    <span class="fa-solid fa-angle-right"></span>
                </h4>
                <div class="me-filter-options">
                    <?php foreach ($movie_engine_birth_years as $movie_engine_year) : ?>
                        <label class="me-filter-checkbox">
                            <input type="checkbox" name="me_birth_year[]" value="<?php echo esc_attr($movie_engine_year); ?>" <?php checked(in_array((string)$movie_engine_year, $movie_engine_active_years)); ?>>
                            <span class="me-checkbox-label"><?php echo esc_html($movie_engine_year); ?></span>
                        </label>
                    <?php endforeach; ?>
                </div>
            </div>
        <?php endif; ?>
    </div>
</aside>