<?php global $post;
$post_id = $post->ID;
$post_type = $post->post_type;
$tab_items = array();
$dlbox = get_real_post_dllinks($post_id);
$disabled_play = yc_get_post_meta($post->ID, 'deactive_playonline');
if (empty($disabled_play) && $post_type == 'series') $play_box = get_post_meta($post_id, 'series_playlinks', true);
if (!empty($dlbox) && !empty($dlbox["links"])) {
    foreach ($dlbox["links"] as $type => $items) {
        $name = "";
        $icon = "";
        if ($type == "dub") $name = "دوبله فارسی";
        elseif ($type == "sub") $name = "زیرنویس فارسی";
        else $name = "باکس دانلود";
        if ($type == "dub") $icon = "microphone";
        elseif ($type == "sub") $icon = "closed-captioning";
        else $icon = "arrow-down";
        $tab_items[] = array(
            "id" => $type,
            "label" => $name,
            "icon" => $icon,
            "type" => (!empty($dlbox["type"])) ? $dlbox["type"] : "",
            "items" => $items,
        );
    }
}
if (!empty($play_box)) $tab_items[] = array(
    "id" => "play-online",
    "label" => "پخش آنلاین",
    "icon" => "play",
    "poitems" => $play_box
);
$trailer_movie = yc_get_post_meta($post_id, 'trailer_movie');
if (!empty($trailer_movie)) $tab_items[] = array(
    "id" => "trailer-box",
    "label" => "تماشا تریلر",
    "icon" => "play",
    "link" => $trailer_movie
);
if (!empty($tab_items)) : ?>
    <div class="rt-download rt">
        <div class="main">
            <div class="entery rt-ddd rt rt-10px">
                <div class="btns rt rt-15 rt-bold">
                    <?php foreach ($tab_items as $key => $tab) : ?>
                        <span class="rt-pointer right rt-op <?php echo ($key == 0) ? "active" : ""; ?>" data-id="<?php echo (!empty($tab["id"])) ? $tab["id"] : ""; ?>">
                            <?php if (!empty($tab["icon"])) : ?><i class="fa fa-<?php echo (!empty($tab["icon"])) ? $tab["icon"] : ""; ?> rt-18 right"></i><?php endif; ?>
                            <?php echo (!empty($tab["label"])) ? $tab["label"] : ""; ?>
                        </span>
                    <?php endforeach; ?>
                </div>
                <?php foreach ($tab_items as $key => $tab) :
                    $tab_id = (!empty($tab["id"])) ? $tab["id"] : ""; ?>
                    <div class="tab-item rt <?php echo ($tab_id == "dub") ? "green" : ""; ?> <?php echo ($key != 0) ? "none" : ""; ?>" data-tab="<?php echo (!empty($tab["id"])) ? $tab["id"] : ""; ?>">
                        <?php if (!empty($tab["items"])) :
                            $link_items = (!empty($tab["items"])) ? $tab["items"] : array();
                            $link_type = (!empty($tab["type"])) ? $tab["type"] : ""; ?>
                            <?php if ($link_type == "movies") get_template_part('templates/single/movies/dlbox-movies', null, array("links" => $link_items, "type_id" => $tab_id));
                            elseif ($link_type == "series") get_template_part('templates/single/movies/dlbox-series', null, array("links" => $link_items, "type_id" => $tab_id)); ?>
                        <?php else : ?>
                            <?php if ($tab_id == "trailer-box") { ?>
                                <video class="rt rt-blur" controls="" preload="none">
                                    <source src="<?php echo (!empty($tab["link"])) ? $tab["link"] : ""; ?>" type="video/mp4">عدم ساپورت توسط مرورگر شما، لطفا از گوگل کروم استفاده کنید.
                                </video>
                            <?php } elseif ($tab_id == "play-online") get_template_part('templates/single/movies/play-online', null, array("links" => (!empty($tab["poitems"])) ? $tab["poitems"] : array())); ?>
                        <?php endif; ?>
                    </div>
                <?php endforeach; ?>
            </div>
        </div>
    </div>
<?php endif; ?>