<?php global $post;
$post_id = $post->ID;
$post_type = 'series';
$links = (!empty($args['links'])) ? $args['links'] : array();
$type_id = (!empty($args['type_id'])) ? $args['type_id'] : "";
$serie_end = (!empty($post_id)) ? yc_get_post_meta($post_id, 'serie_is_end', true) : null;
if (!empty($links)) : ?>
    <ul class="inside rt">
        <?php
        $s_i = 0;
        $count_season = count($links);
        foreach ($links as $season_name => $season_info) :
            $s_i++;
            $badge = '';
            if ($s_i != $count_season) $badge = 'تکمیل شده';
            else if (!empty($serie_end)) $badge = 'پایان سریال'; ?>
            <li class="season rt rt-blur rt-8px">
                <div class="link rt rt-pointer rt-14">
                    <span class="titr rt-color rt-fff rt-30px"><?php echo (!empty($season_name)) ? $season_name : ""; ?></span>
                    <?php if (!empty($season_info["count"])) : ?><span class="count rt-ddd">تعداد قسمت: <?php echo $season_info["count"]; ?></span><?php endif; ?>
                    <?php if (!empty($badge)) : ?><span class="sec rt-color rt-fff rt-8px rt-blur"><?php echo $badge; ?></span><?php endif; ?>
                    <i class="fa fa-angle-down left rt-19"></i>
                </div>
                <div class="submenu rt-0s rt">
                    <?php if (!empty($season_info["episodes"]) && is_array($season_info["episodes"])) : ?>
                        <ul class="episodes rt">

                            <?php
                            $e_i = 0;
                            foreach ($season_info["episodes"] as $episode_name => $episode_qualities) :
                                $e_i++;
                                $episodename = (!empty($episode_name) && !is_numeric($episode_name)) ? $episode_name : "قسمت " . $e_i; ?>
                                <li class="rt episode rt-8px rt-blur">
                                    <div class="rt link2 rt-pointer">
                                        <span class="inf right"><?php echo $episodename; ?></span>
                                        <i class="fa fa-angle-down left rt-19"></i>
                                    </div>
                                    <?php if (!empty($episode_qualities) && is_array($episode_qualities)) : ?>
                                        <ul class="list submenu2 rt-0s rt">
                                            <?php foreach ($episode_qualities as $quality_name => $subtypes) :
                                                if (!empty($subtypes) && is_array($subtypes)) : ?>
                                                    <?php foreach ($subtypes as $subtype_name => $q_data) : ?>
                                                        <li class="item rt rt-bg rt-8px">
                                                            <div class="info right rt-13">
                                                                <?php if (!empty($quality_name)) : ?><span class="inf right">کیفیت : <?php echo $quality_name; ?></span><?php endif; ?>
                                                                <?php if (!empty($q_data["capacity"])) : ?><span class="inf right">حجم : <?php echo $q_data["capacity"]; ?></span><?php endif; ?>
                                                                <?php if (!empty($subtype_name)) : ?><span class="right type rt-30px"><?php echo $subtype_name; ?></span><?php endif; ?>
                                                                <?php if (!empty($q_data['price']) && is_numeric($q_data['price'])) : ?><span class="inf right">قیمت : <div class="price"><?php echo number_format((int) $q_data["price"], 0, ".", "."); ?> تومان</div></span><?php endif; ?>
                                                            </div>
                                                            <div class="links left rt-13">
                                                                <?php if (!empty($q_data['price']) || yascode_vip::limit_user_access_vip($post_type, $type_id)) : ?>
                                                                    <?php if (!empty($q_data["subtitle"])) : ?><a href="<?php echo $q_data["subtitle"]; ?>" class="right btn rt-30px rt-bg rt-rang2"><i class="fa fa-closed-captioning rt-15 right dli"></i> زیرنویس</a><?php endif; ?>
                                                                    <?php if (!empty($q_data["sound_track"])) : ?><a href="<?php echo $q_data["sound_track"]; ?>" class="right btn rt-30px rt-bg rt-rang2"><i class="fa fa-volume rt-15 right dli"></i> صوت دوبله</a><?php endif; ?>
                                                                    <?php if (!empty($q_data["quality_example"])) : ?><a href="<?php echo $q_data["quality_example"]; ?>" class="right btn rt-30px rt-bg rt-rang2"><i class="fa fa-image rt-15 right"></i> نمونه کیفیت</a><?php endif; ?>
                                                                    <?php if (!empty($q_data["link"])) : ?><a href="<?php echo $q_data["link"]; ?>" class="right btn rt-30px rt-fff dl"><i class="fa fa-arrow-down rt-15 right"></i> <?php echo (!empty($q_data['price']) && is_numeric($q_data['price'])) ? 'خرید و دانلود' : 'دانلود'; ?></a><?php endif; ?>
                                                                <?php else : ?>
                                                                    <div class="need-vip">
                                                                        <?php if (!is_user_logged_in()) : ?>
                                                                            <p class="desc">برای دانلود باید ثبت نام کنید یا وارد شوید</p>
                                                                            <div class="need-btns">
                                                                                <a href="<?php echo REGISTER_URL; ?>" target="_blank" class="btn-vip register">عضویت</a>
                                                                                <a href="<?php echo LOGIN_URL; ?>" target="_blank" class="btn-vip login">ورود به حساب</a>
                                                                            </div>
                                                                        <?php else : ?>
                                                                            <p class="desc">برای دانلود باید اشتراک تهیه نمایید</p>
                                                                            <div class="need-btns">
                                                                                <a href="<?php echo PANEL_URL . '/plans'; ?>" target="_blank" class="btn-vip register">
                                                                                    <i class="fa-light fa-sparkles"></i>
                                                                                    خرید اشتراک
                                                                                </a>
                                                                            </div>
                                                                        <?php endif; ?>
                                                                    </div>
                                                                <?php endif; ?>
                                                            </div>
                                                        </li>
                                                    <?php endforeach; ?>
                                                <?php endif; ?>
                                            <?php endforeach; ?>
                                        </ul>
                                    <?php endif; ?>
                                </li>
                            <?php endforeach; ?>

                        </ul>
                    <?php endif; ?>
                </div>
            </li>
        <?php endforeach; ?>
    </ul>
<?php endif; ?>