<?php
global $post;
// $user_id = (is_user_logged_in()) ? get_current_user_id() : 0;
// $post_type = get_post_type($post->ID);
$genre_slug = 'genre';
$genres = wp_get_post_terms($post->ID, $genre_slug);
$imdb_rate = yc_get_post_meta($post->ID, 'imdb_rate_movie');
$imdb_link = yc_get_post_meta($post->ID, 'imdbid_movie');
$imdb_link = (!empty($imdb_link)) ? get_imdb_link($imdb_link) : '';
$movie_votes = yc_get_post_meta($post->ID, 'vote_movie');
$post_title = get_the_title($post->ID);
$update_text = yc_get_post_meta($post->ID, 'movie_update_text');
$isDubbed = yc_get_post_meta($post->ID, 'has_dubbed');
$isSubbed = yc_get_post_meta($post->ID, 'has_subtitle');
$post_duration = yc_get_post_meta($post->ID, 'runtime_movie');
$countries = wp_get_post_terms($post->ID, 'country');
$releases = wp_get_post_terms($post->ID, 'release');
$languages = wp_get_post_terms($post->ID, 'language');
$age_movie = yc_get_post_meta($post->ID, 'age_movie');
$movie_plot = yc_get_post_meta($post->ID, 'fa_plot_movie');
$movie_bg = yc_get_post_meta($post->ID, 'movie_thumb_bg');
$movie_bg = (!empty($movie_bg)) ? wp_get_attachment_image_url($movie_bg, 'full') : '';
$metacritic_rate = yc_get_post_meta($post->ID, 'metacritic_rate');
$post_permalink = get_the_permalink($post->ID);
$trailer_movie = yc_get_post_meta($post->ID, 'trailer_movie');
$directors = wp_get_post_terms($post->ID, 'director');
$disabled_play = yc_get_post_meta($post->ID, 'deactive_playonline');
$post_likes = yascode_likeposts::get_post_likes_info($post->ID);
$in_watchlist = yascode_watchlist::is_post_in_watchlist($post->ID);
if (empty($disabled_play) && $post_type == 'movies') $play_box = yc_get_post_meta($post->ID, 'movies_playlinks');
?>
<section class="rt-single rt-relative rt-overflow rt">
    <?php if (!empty($movie_bg)) : ?>
        <img src="<?php echo $movie_bg; ?>" class="rt rt-absolute bgz">
    <?php endif; ?>
    <div class="main">
        <div class="pic right rt-relative">
            <?php if (!empty($isDubbed) || !empty($isSubbed)) : ?>
                <div class="chasbs">
                    <?php if (!empty($isDubbed)) : ?>
                        <span class="dooble rt-fff rt-13 rt-absolute"><i class="fa fa-microphone rt-15 right"></i> دوبله</span>
                    <?php endif; ?>
                    <?php if (!empty($isSubbed)) : ?>
                        <span class="srt dooble rt-fff rt-13 rt-absolute"><i class="fa fa-closed-captioning rt-15 right"></i> زیرنویس</span>
                    <?php endif; ?>
                </div>
            <?php endif; ?>
            <?php if (has_post_thumbnail($post->ID)) : ?>
                <?php the_post_thumbnail('single_cover', array("class" => "rt rt-8px")); ?>
            <?php endif; ?>
        </div>
        <div class="inside left">
            <h1 class="title rt rt-fff rt-bold rt-23"><?php echo $post_title; ?></h1>
            <?php if (!empty($releases)) :
                $count_r = count($releases); ?>
                <span class="eng rt rt-ddd rt-14">سال تولید
                    <?php foreach ($releases as $key => $release) : ?>
                        <a href="<?php echo get_term_link($release->term_id, 'release') ?>" rel="tag" class="rt-ddd"><?php echo $release->name; ?></a>
                        <?php if (($key + 1) < $count_r) echo "-"; ?>
                    <?php endforeach; ?>
                </span>
            <?php endif; ?>

            <?php if (!empty($update_text)) : ?>
                <div class="alarm right rt-blur rt-8px rt-fff rt-14"><i class="fa fa-bell right rt-16"></i> <?php echo $update_text; ?></div>
            <?php endif; ?>
            <div class="emtiaz rt">
                <?php if (!empty($imdb_rate)) : ?>
                    <span class="imdb right">
                        <a href="<?php echo $imdb_link; ?>" class="imdb-link" target="_blank" rel="noopener nofollow"><i class="fa fa-imdb rt-31 rt-400"></i></a>
                        <div class="ins left rt-12 rt-ddd"><span class="rt"><span class="rt-17 rt-fff rt-bold"><?php echo $imdb_rate; ?></span>/10 </span><span class="rt rt-11"><?php echo $movie_votes; ?></span></div>
                    </span>
                <?php endif; ?>
                <?php if (!empty($metacritic_rate)) : ?>
                    <div class="metacritic right rt-13">
                        <span class="icon right rt-fff rt-10px"><?php echo $metacritic_rate; ?></span>
                        <div class="name right rt-ddd">امتیاز منتقدین</div>
                    </div>
                <?php endif; ?>
            </div>
            <ul class="info rt rt-14 rt-ddd">
                <?php if (!empty($countries)) :
                    $count_c = count($countries); ?>
                    <li class="right"><i class="fa fa-globe right rt-17"></i>محصول کشور
                        <?php foreach ($countries as $key => $country) : ?>
                            <a href="<?php echo get_term_link($country->term_id, 'country') ?>" rel="tag" class="rt-fff rt-medium"><?php echo $country->name; ?></a>
                            <?php if (($key + 1) < $count_c) echo "-"; ?>
                        <?php endforeach; ?>
                    </li>
                <?php endif; ?>
                <?php if (!empty($genres)) :
                    $count_g = count($genres); ?>
                    <li class="right"><i class="fa fa-folder right rt-17"></i>ژانر
                        <?php foreach ($genres as $key => $genre) : ?>
                            <a href="<?php echo get_term_link($genre->term_id, $genre_slug) ?>" rel="category tag" class="rt-fff rt-medium"><?php echo $genre->name; ?></a>
                            <?php if (($key + 1) < $count_g) echo ","; ?>
                        <?php endforeach; ?>
                    </li>
                <?php endif; ?>
                <li class="rt rt-12">
                    <?php if (!empty($post_duration)) : ?>
                        زمان <?php echo $post_duration; ?> <span class="dash rt-blur rt-5px"></span>
                    <?php endif; ?>

                    <?php if (!empty($age_movie)) : ?>
                        رده سنی <?php echo $age_movie; ?> <span class="dash rt-blur rt-5px"></span>
                    <?php endif; ?>

                    <?php if (!empty($languages)) :
                        $count_l = count($languages); ?>
                        زبان
                        <?php foreach ($languages as $key => $lang) : ?>
                            <a href="<?php echo get_term_link($lang->term_id, 'language') ?>" rel="tag" class="rt-fff rt-medium"><?php echo $lang->name; ?></a>
                            <?php if (($key + 1) < $count_l) echo ","; ?>
                        <?php endforeach; ?>
                    <?php endif; ?>

                </li>
            </ul>

            <?php if (!empty($movie_plot)) : ?>
                <div class="text rt rt-14 rt-ddd">
                    <p><?php echo $movie_plot; ?></p>
                </div>
            <?php endif; ?>

            <?php if (!empty($directors)) : ?>
                <?php foreach ($directors as $director) :
                    $profile = get_term_meta($director->term_id, 'profile_director', true);
                    if (!empty($profile)) $profile = wp_get_attachment_image_url($profile, 'full');
                    if (empty($profile)) $profile = THEME_TEMPLATE_URL . '/assets/front/img/actor.png'; ?>
                    <a href="<?php echo get_term_link($director->term_id, 'director') ?>" class="dir right rt-35px">
                        <img src="<?php echo $profile; ?>" class="right rt-50px">
                        <div class="name right rt-13 rt-fff rt-bold"><?php echo $director->name; ?> <span class="rt-ddd rt-400 rt-10">(کارگردان)</span></div>
                    </a>
                <?php endforeach; ?>
            <?php endif; ?>

            <div class="btns left rt-15">
                <div class="like-dislike right rt-13 rt-ddd" data-post="<?php echo $post->ID; ?>">
                    <span class="like right rt-fff rt-pointer bt" data-type="like"><i class="fa fa-thumbs-up right rt-400 rt-18"></i><span class="right"><?php echo (!empty($post_likes['likes'])) ? $post_likes['likes'] : 0; ?></span></span>
                    <span class="dislike right rt-fff rt-pointer bt" data-type="dislike"><i class="fa fa-thumbs-down right rt-400 rt-18"></i><span class="right"><?php echo (!empty($post_likes['dislikes'])) ? $post_likes['dislikes'] : 0; ?></span></span>
                </div>
                <span class="btn right rt-fff rt-blur rt-8px rt-pointer book watchlist-btn <?php echo ($in_watchlist) ? 'added' : ''; ?>" data-post="<?php echo $post->ID; ?>"><i class="fa fa-bookmark right rt-21"></i></span>
                <?php if (!empty($play_box)) : ?>
                    <a href="<?php echo get_online_play_link($post->ID); ?>" target="_blank" class="btn right rt-fff rt-color rt-bold rt-8px"><i class="fa fa-play"></i> پخش آنلاین</a>
                <?php endif; ?>
            </div>
        </div>
    </div>
</section>