<?php if ( !defined( 'ABSPATH' ) ) exit();
get_header( );
global $post;

$id = get_the_ID();

$list_document = get_post_meta( $id, 'ova_doc_met_list_document', true );

$image = get_theme_mod( 'doc_image_sidebar', '' );
$link_image = get_theme_mod( 'doc_link_image', '#' );

$args = array(
   'taxonomy' => 'cat_doc',
   'orderby' => 'name',
   'order'   => 'ASC'
);

$categories = get_categories($args);
?>

<div class="container">
	<div class="row">
		<div class="ova_doc_wrap ova_doc_single">
			<div class="ova-doc-sidebar">
				<div class="ova_info">

					<div class="ova-list-cat">
						<p class="title-list-cat second_font"><?php echo esc_html__( 'Document Filter', 'ova-doc' ) ?></p>
						<ul>
							<li><a href="<?php echo esc_url( get_post_type_archive_link( 'ova_doc' ) ) ?>"><?php echo esc_html__( 'All Document', 'ova-doc' ) ?></a></li>
						<?php
							if ($categories) {
								foreach ( $categories as $cate ) {
									?>
									<li>
										<a class="second_font" href="<?php echo esc_url( get_term_link( $cate->term_id ) ) ?>">
											<?php echo esc_html( $cate->cat_name ) ?>
										</a>
									</li>
									<?php									
								}
							}
						?>
						</ul>
					</div>
					<!-- end ova-list-cat -->

					<?php if( ! empty( $image ) ){ ?>
					<div class="ova-media">
						<a href="<?php echo esc_url( $link_image ) ?>">
							<img src="<?php echo esc_url( $image ) ?>" class="img-responsive" alt="<?php echo get_the_title() ?>">
						</a>
					</div>
					<?php } ?>
				</div>
			</div>
			<div class="ova_doc_content">
				
				<div class="doc-meta">
					<span class=" doc-meta-general">
						<?php the_time( get_option( 'date_format' ));?>
					</span>
					<span class=" doc-categories">
						<?php get_category_doc_by_id_doc( $id ) ?>			       
				    </span>
				</div>

				<?php if( have_posts() ) : while( have_posts() ) : the_post();
					the_content();
		 		?>
		 		<?php endwhile; endif; wp_reset_postdata(); ?>


		 		<?php

		 			if( ! empty( $list_document ) ){
		 				?>
						<ul class="ova-list-attachment">
		 				<?php
						foreach( $list_document as $document ){
							$name_file = basename( $document );
							$ext_file = pathinfo( $name_file, PATHINFO_EXTENSION );

							?>
							<li>
								<span class="icon-attachment">
									<?php echo ova_doc_get_icon_attachment_file( $ext_file ) ?>
								</span>
								<span class="ova-file-name-size">
									<span class="ova-file-name">
										<?php echo esc_html( $name_file ) ?>
									</span>
									<span class="ova-file-size">
										<span class="type">
											<?php echo esc_html( $ext_file ) ?>
										</span>
										<span class="file-size">
											(<?php echo ova_doc_get_file_size( $document ) . esc_html__( 'kb', 'ova-doc' ) ?>)
										</span>
									</span>
								</span>
								<span class="ova-download">
									<a href="<?php echo $document ?>" download>
									  <?php echo esc_html__( '[ download ]', 'ova-doc' ) ?>
									</a>
								</span>
							</li>
								
							<?php
						}

						?>
						</ul>
						<?php
					}

		 		?>
				<?php if( has_filter( 'ova_share_social' ) ){ ?>
			        <div class="share_social">
			        	<span class="ova_label second_font"><?php esc_html_e('Share Article ', 'ova-doc'); ?></span>
			        	<?php echo apply_filters('ova_share_social', get_the_permalink(), get_the_title() ); ?>
			        </div>
		        <?php } ?>

		        <?php
			        if( comments_open( get_the_ID() ) ) {
			        	comments_template(); 
			        }
		        ?>

			</div>
			<!-- end ova_doc_content -->
		</div>
		<!-- end ova_doc_single -->
	</div>
	<!-- end row -->
</div>
<!-- end container -->

<?php get_footer( );
