<?php $paged = (!empty($_GET['page']) && is_numeric($_GET['page'])) ? $_GET['page'] : 1;
$user_id = get_current_user_id();
$watchlist = yascode_watchlist::get_user_watchlist($user_id, 12, $paged); ?>
<div class="rt-entery rt rt-bookmarks">
    <div class="main">

        <?php if (!empty($watchlist['items']) && is_array($watchlist['items'])) { ?>
            <section class="archive-slider rt rt-relative rt-overflow">
                <div class="inline rt rt-relative rt-align">
                    <?php foreach ($watchlist['items'] as $post_id) :
                        $post_permalink = get_the_permalink($post_id);
                        $post_title = get_post_meta($post_id, 'title_movie', true);
                        $post_title = (!empty($post_title)) ? $post_title : get_the_title($post_id);
                        $imdb_rate = get_post_meta($post_id, 'imdb_rate_movie', true);
                        $isDubbed = get_post_meta($post_id, 'has_dubbed', true);
                        $isSubbed = get_post_meta($post_id, 'has_subtitle', true);
                        $genres = wp_get_post_terms($post_id, 'genre');
                        $imdb_rate = yc_get_post_meta($post_id, 'imdb_rate_movie', true);
                        $release = yc_get_post_meta($post_id, "release_movie"); ?>
                        <article class="mini-p rt rt-relative rt-overflow">
                            <figure class="rt rt-relative rt-overflow rt-5px">
                                <?php if (!empty($isDubbed) || !empty($isSubbed)) : ?>
                                    <div class="chasbs">
                                        <?php if (!empty($isDubbed)) : ?>
                                            <span class="dooble rt-fff rt-11 rt-absolute"><i class="fa fa-microphone rt-13 right"></i> دوبله</span>
                                        <?php endif; ?>
                                        <?php if (!empty($isSubbed)) : ?>
                                            <span class="srt dooble rt-fff rt-11 rt-absolute"><i class="fa fa-closed-captioning rt-13 right"></i> زیرنویس</span>
                                        <?php endif; ?>
                                    </div>
                                <?php endif; ?>
                                <a href="<?php echo $post_permalink; ?>" target="_blank"><img src="<?php echo get_the_post_thumbnail_url($post_id, 'post_cover') ?>" alt="<?php echo $post_title; ?>" class="rt"></a>
                                <div class="hover rt rt-absolute rt-center rt-5px">
                                    <span class="remove-watchlist rt-pointer" data-post="<?php echo $post_id; ?>" data-active="true"><i class="fa fa-trash"></i></span>
                                    <a href="<?php echo $post_permalink; ?>" target="_blank" class="full-link rt rt-absolute rt-z-index"></a>
                                    <i class="fa fa-play rt-31 rt-fff"></i>
                                    <?php if (!empty($genres)) :
                                        $count_g = count($genres); ?>
                                        <div class="cat-p rt">
                                            <?php foreach ($genres as $key => $genre) : ?>
                                                <a href="<?php echo get_term_link($genre->term_id, 'genre') ?>" rel="category tag"><?php echo $genre->name; ?></a>
                                                <?php if (($key + 1) < $count_g) echo ","; ?>
                                            <?php endforeach; ?>
                                        </div>
                                    <?php endif; ?>
                                </div>
                                <?php if (!empty($imdb_rate)) : ?>
                                    <a href="<?php echo $post_permalink; ?>" target="_blank" class="imdb left rt-absolute rt-8px rt-align">
                                        <i class="fa fa-imdb rt-400 rt rt-31"></i>
                                        <span class="rt rt-12 rt-fff"><?php echo $imdb_rate; ?></span>
                                    </a>
                                <?php endif; ?>
                            </figure>
                            <h2 class="title rt rt-14 rt-overflow">
                                <a href="<?php echo $post_permalink; ?>" target="_blank" class="rt-ddd rt"><?php echo $post_title; ?>
                                    <?php if (!empty($release)) echo $release; ?>
                                </a>
                            </h2>
                        </article>
                    <?php endforeach; ?>
                </div>

                <?php if (!empty($watchlist['total_pages']) && $watchlist['total_pages'] > 1) : ?>
                    <div class="paginate rt rt-align rt-15">
                        <?php if ($paged > 1) echo '<a href="' . add_query_arg(array('page' => $paged - 1)) . '">صفحه قبل</a>'; ?>
                        <?php for ($i = 1; $i <= $watchlist['total_pages']; $i++) : ?>
                            <?php
                            if ($i == $paged) {
                                echo '<span>' . $i . '</span>';
                            } else {
                                echo '<a href="' . add_query_arg(array('page' => $i)) . '">' . $i . '</a>';
                            } ?>
                        <?php endfor; ?>
                        <?php if ($paged < $watchlist['total_pages']) echo '<a href="' . add_query_arg(array('page' => $paged + 1)) . '">صفحه بعد</a>'; ?>
                    </div>
                <?php endif; ?>
            </section>
        <?php } else { ?>
            <div class="empty rt rt-align">
                <div class="rt"><img height="190" src="<?php echo THEME_TEMPLATE_URL . '/assets/front/img/empty.png'; ?>"></div>
                <h4 class="rt rt-777 rt-18">فهرست شما خالی است!</h4>
            </div>
        <?php } ?>
        <!--پایان آرشیو مطالب-->

    </div>
</div>