<?php

/**
 * The template for displaying cast list in single movie
 *
 * This template can be overridden by copying it to yourtheme/movie-engine/single-movie/cast.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_cast_data = get_post_meta(get_the_ID(), '_movie_engine_cast', true);
if (!empty($movie_engine_cast_data) && is_array($movie_engine_cast_data)) : ?>
    <div class="movie-engine-cast-list">
        <?php foreach ($movie_engine_cast_data as $movie_engine_actor_data) : ?>
            <div class="movie-engine-cast-item">
                <div class="movie-engine-cast-avatar">
                    <?php if (!empty($movie_engine_actor_data['photo'])) : ?>
                        <img src="<?php echo esc_url($movie_engine_actor_data['photo']); ?>" alt="<?php echo esc_attr($movie_engine_actor_data['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_data['name']); ?></span>
                    <span class="movie-engine-actor-role"><?php echo esc_html($movie_engine_actor_data['character']); ?></span>
                </div>
            </div>
        <?php endforeach; ?>
    </div>
<?php endif; ?>