<?php

/**
 * The template for displaying series details
 *
 * This template can be overridden by copying it to yourtheme/movie-engine/single-series/details.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
}

$movie_engine_post_id = get_the_ID();
$movie_engine_meta = get_post_meta($movie_engine_post_id);
?>
<div class="movie-engine-details-grid">
    <div class="movie-engine-left-col">
        <div class="movie-engine-section-title">
            <h2><?php esc_html_e('Storyline', 'cine-movie-engine'); ?></h2>
        </div>
        <div class="movie-engine-full-synopsis">
            <?php the_content(); ?>
        </div>

        <?php
        $movie_engine_cast = get_post_meta($movie_engine_post_id, '_movie_engine_cast', true);
        if (!empty($movie_engine_cast) && is_array($movie_engine_cast)) :
        ?>
            <div class="movie-engine-cast-section">
                <div class="movie-engine-section-title">
                    <h2><?php esc_html_e('Cast', 'cine-movie-engine'); ?></h2>
                </div>
                <div class="movie-engine-cast-list">
                    <?php foreach ($movie_engine_cast as $movie_engine_actor) : ?>
                        <div class="movie-engine-cast-item">
                            <div class="movie-engine-cast-avatar">
                                <?php if (!empty($movie_engine_actor['photo'])) : ?>
                                    <img src="<?php echo esc_url($movie_engine_actor['photo']); ?>" alt="<?php echo esc_attr($movie_engine_actor['name']); ?>">
                                <?php else : ?>
                                    <span class="fa-solid fa-users"></span>
                                <?php endif; ?>
                            </div>
                            <div class="movie-engine-cast-info">
                                <span class="movie-engine-actor-name"><?php echo esc_html($movie_engine_actor['name']); ?></span>
                                <span class="movie-engine-actor-role"><?php echo esc_html($movie_engine_actor['character']); ?></span>
                            </div>
                        </div>
                    <?php endforeach; ?>
                </div>
            </div>
        <?php endif; ?>
    </div>

    <div class="movie-engine-right-col">
        <div class="movie-engine-info-box">
            <ul>
                <li><strong><?php esc_html_e('Creator', 'cine-movie-engine'); ?>:</strong> <span><?php echo \MovieEngine\Utils\Helpers::kses_post(get_the_term_list($movie_engine_post_id, 'movie_engine_creator', '', ', ')); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- kses_post sanitizes HTML 
                                                                                                    ?></span></li>
                <li><strong><?php esc_html_e('Country', 'cine-movie-engine'); ?>:</strong> <span><?php echo \MovieEngine\Utils\Helpers::kses_post(get_the_term_list($movie_engine_post_id, 'movie_engine_country', '', ', ')); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- kses_post sanitizes HTML 
                                                                                                    ?></span></li>
                <li><strong><?php esc_html_e('Language', 'cine-movie-engine'); ?>:</strong> <span><?php echo \MovieEngine\Utils\Helpers::kses_post(get_the_term_list($movie_engine_post_id, 'movie_engine_language', '', ', ')); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- kses_post sanitizes HTML 
                                                                                                    ?></span></li>
                <li><strong><?php esc_html_e('Network', 'cine-movie-engine'); ?>:</strong> <span><?php echo \MovieEngine\Utils\Helpers::kses_post(get_the_term_list($movie_engine_post_id, 'movie_engine_network', '', ', ')); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- kses_post sanitizes HTML 
                                                                                                    ?></span></li>
                <li><strong><?php esc_html_e('First Air Date', 'cine-movie-engine'); ?>:</strong> <span><?php echo esc_html($movie_engine_meta['_movie_engine_release_date'][0] ?? get_the_date()); ?></span></li>
            </ul>
        </div>
    </div>
</div>