<?php get_header(); ?>
<div class="container">
  <div class="single-content">
    <?php
    if ( have_posts() ) :
        while ( have_posts() ) : the_post(); ?>
        <?php gt_set_post_view(); ?>
    <article class="single-title">
    <div class="box-shadow">
      <header>
        <h1><?php the_title(); ?></h1>
        <div class="single-post-meta">
          <i class="fas fa-clock"></i>
          <span><?php the_time('d F Y'); ?></span>
        </div>
        <div class="single-post-meta">
          <i class="fas fa-user"></i>
          <span><?php the_author(); ?></span>
        </div>
        <div class="single-post-meta">
          <i class="fas fa-folder-open"></i>
          <span>
          <?php
            $terms = wp_get_post_terms( $post->ID, 'video-category');
            foreach ( $terms as $term ) {
            $term_link = get_term_link( $term );
            echo '<a href="' . $term_link . '">' . $term->name . '</a>' . ' ';
            }
          ?>
          </span>
        </div>
        <div class="single-post-meta">
          <i class="fas fa-eye"></i>
          <span><?= gt_get_post_view(); ?></span>
        </div>
      </header>
      <div class="single-post-thumbnail">
      <?php $mihancode_type_video = get_post_meta(get_the_ID() , 'mihancode_type_video' , true);
      if ( $mihancode_type_video == 'link_upload_video' ) { ?>
        <figure>
          <?php
          $media = get_post_meta(get_the_ID() , 'mihancode_video' , true);
          $cover = get_the_post_thumbnail_url();
          if (!empty($media)) {
              $property = array(
                  'src'   =>  $media,
                  'width' => '1000',
                  'height'    => '600',
                  'poster' => $cover,
              );
              echo wp_video_shortcode($property);
          }
          else {
              the_post_thumbnail();
          }
          ?>
    

        <?php 
      } else { 
        $media_aparat = get_post_meta(get_the_ID() , 'mihancode_video_aparat' , true);
        echo do_shortcode("[aparat id='$media_aparat']");
      }
        ?>
        </figure>
      </div>


      <div class="post-content">
        <?php the_content(); ?>
      </div>
    </div>
    </article>
    <?php
    endwhile;
endif;
?>

<?php if ($parsa_opt['share_tv']) { ?>
<div class="box-shadow">
<div class="social-share-box">
      <span class="title">اشتراک گذاری </span>
        <a target="_blank" href="https://twitter.com/intent/tweet?text=<?php echo get_permalink(); ?>" class="twitter-share-button">
            <i class="fab fa-twitter"></i>
        </a>
        <a target="_blank" href="https://www.linkedin.com/shareArticle?mini=true&url=<?php echo get_permalink(); ?>" class="linkedin-share-button">
            <i class="fab fa-linkedin"></i>
        </a>
        <a target="_blank" href="https://pinterest.com/pin/create/button/?url=<?php echo get_permalink(); ?>" class="pinterest-share-button">
            <i class="fab fa-pinterest"></i>
        </a>
        <a target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=<?php echo get_permalink(); ?>" class="facebook-share-button">
            <i class="fab fa-facebook"></i>
        </a>
        <a target="_blank" href="https://telegram.me/share/url?url=<?php echo get_permalink(); ?>" class="telegram-share-button">
            <i class="fab fa-telegram"></i>
        </a>
</div>
</div>
<?php } ?>

<?php if ($parsa_opt['author_tv']) { ?>
<div class="box-shadow">
<div class="author-box">
    <?php
    echo get_avatar( get_the_author_meta( 'ID' ), 80 ); ?>
    <div class="post-author-name"><?php the_author(); ?></div>
    <div class="author-desc"><?php the_author_meta( 'description' ); ?></div>
</div>
</div>
<?php } ?>

<?php if ($parsa_opt['active_related_tv']) : ?>
<div class="box-shadow">
<section class="ralated-posts">
  <div class="ralated-title">
    <h3>ویدئوهای مرتبط را مشاهده کنید</h3>
  </div>
<div class="post-slider">
  <div id="relatedpost" class="owl-carousel owl-theme">
    <?php
    $trmids = wp_get_post_terms($post->ID, 'video-category');
    $trmarray = array();
    foreach ($trmids as $v) {
        $trmarray[] = $v->term_id;
    }

    $arms = array(
        'post_type' => 'video',
        'posts_per_page' => 5,
        'order' => 'DESC',
        'post_status' => 'publish',
        'post__not_in' => array($post->ID),
        'tax_query' => array(
            array(
                'taxonomy' => 'video-category',
                'terms' => $trmarray,
            ),
        )
    );
    $the_query = new WP_Query($arms);
    if ($the_query->have_posts()):
    while ($the_query->have_posts()) : $the_query->the_post(); ?>
          <div class="video-item">
          <a href="<?php the_permalink(); ?>">
        <figure>
        <div class="blog-video-image">
        <i class="fas fa-play-circle"></i>
          <?php
          if (has_post_thumbnail()) {
            the_post_thumbnail();
          }
          else {
            ?><img src="<?php echo get_template_directory_uri().'/img/pro-nothumbnail.png' ?>"> <?php
          }
          ?>
        
        </div>
        <?php
        $time = get_post_meta(get_the_ID() , 'mihancode_video_time' , true);
        if (!empty($time)) {
          ?><span><?php echo $time;?><i class="fas fa-clock"></i> </span><?php
        }
        ?>
        <a href="<?php the_permalink(); ?>">
        <h2><?php the_title(); ?></h2>
        </a>
        <div class="video-view">
          <i class="fas fa-eye"></i>
          <div class="count-view"><?= gt_get_post_view(); ?></span>
        </div>
      </figure>
      </a>
    </div>

<?php endwhile; endif; wp_reset_postdata(); ?>
    </div>
  </div>
</section>
</div>
<?php endif; ?>
  <div class="box-shadow">
  <div class="post-comments">
    <div class="comments-title">
      <h3>نظرات:</h3>
    </div>
    <?php
    if ( comments_open() || get_comments_number() ) :
    comments_template();
    endif;
    ?>
  </div>
  </div>
  </div>
  <?php
  if ($parsa_opt['position_sidebar_tv']!='none') {
        get_sidebar();
        if ($parsa_opt['position_sidebar_tv']=='right') {
            ?>
            <style>
                .single-sidebar {float: right !important;}
                .single-content {float: left !important;}
            </style>
            <?php
        }
    }
    else {
        ?>
        <style>
            .single-content {width: 100% !important;}
        </style>
        <?php } ?>
  </div>
<?php get_footer(); ?>
