<div class="portfolio_classic_container discography_classic">
	<?php
		//Get all settings
		$settings = $this->get_settings();
		
		//Get portfolio items
		$widget_id = $this->get_id();
		
		$args = array( 
			'post_type' => 'podcast',
			'posts_per_page' => $settings['posts_per_page']['size'],
			'orderby' => 'menu_order',
			'order' => 'ASC',
		);
		
		switch($settings['sort_by'])
		{
			case 'menu_order':
			default:
				$args['orderby'] = 'menu_order';
			break;
			
			case 'title':
				$args['orderby'] = 'post_title';
			break;
			
			case 'newest':
				$args['orderby'] = 'date';
				$args['order'] = 'DESC';
			break;
			
			case 'oldest':
				$args['orderby'] = 'date';
				$args['order'] = 'ASC';
			break;
		}
	
		//Check if filter category is valid
		$is_tax_query_valid = false;
		if(isset($settings['podcast_category'][0]) && !empty($settings['podcast_category'][0]))
		{
			$categories_obj = get_term_by('id', $settings['podcast_category'][0], 'podcast_category');
			
			if(!empty($categories_obj))
			{
				$is_tax_query_valid = true;
			}
		}
		else
		{
			$is_tax_query_valid = true;
		}
		
		if(isset($settings['podcast_category']) && !empty($settings['podcast_category']) && $is_tax_query_valid)
		{
			$args['tax_query'] = array( 
				array( 
					'taxonomy' => 'podcast_category', //or tag or custom taxonomy
					'field' => 'id', 
					'terms' => $settings['podcast_category']
				) 
			);
		}
		
		query_posts($args);
		
		if (have_posts())
		{
			//Get all settings
			$settings = $this->get_settings();
			
			//Get spacing class
			$spacing_class = '';
			if($settings['spacing'] != 'yes')
			{
				$spacing_class = 'has_no_space';
			}
			
			$column_class = 1;
			$thumb_image_name = 'dotlife-discography-grid';
			
			//Start displaying gallery columns
			switch($settings['columns']['size'])
			{
				case 1:
					   $column_class = 'tg_one_col';
				   break;
				   
				case 2:
					   $column_class = 'tg_two_cols';
				   break;
				   
				   case 3:
				   default:
					   $column_class = 'tg_three_cols';
				   break;
				   
				   case 4:
					   $column_class = 'tg_four_cols';
				   break;
				   
				   case 5:
					   $column_class = 'tg_five_cols';
				   break;
				   
				   case 6:
					   $column_class = 'tg_six_cols';
				   break;
			}
	?>
	<div class="portfolio_classic_content_wrapper portfolio_classic layout_<?php echo esc_attr($column_class); ?> <?php echo esc_attr($spacing_class); ?>" data-cols="<?php echo esc_attr($settings['columns']['size']); ?>">
	<?php		
			$last_class = '';
			$count = 1;
			
			while (have_posts()) : the_post();
				$last_class = '';
				if($count%$settings['columns']['size'] == 0)
				{
					$last_class = 'last';
				}
				
				$thumb_image_name = 'dotlife-gallery-list';
				if(isset($settings['image_dimension']) && !empty($settings['image_dimension']))
				{
					//If display original dimension and less initial items then display higher resolution image
					if($settings['image_dimension'] == 'medium_large' && $settings['ini_item']['size'] < 3)
					{
						$settings['image_dimension'] = 'large';
					}
					
					$thumb_image_name = $settings['image_dimension'];
				}
				
				$podcast_id = get_the_id();
				$podcast_title = get_the_title();
				$podcast_subtitle = strip_shortcodes(get_the_content());
				$image_id = get_post_thumbnail_id($podcast_id);
				$image_url = wp_get_attachment_image_src($image_id, $thumb_image_name, true);
				$image_alt = get_post_meta($image_id, '_wp_attachment_image_alt', true);
				$podcast_audio = get_post_meta($podcast_id, 'podcast_audio', true);
	?>
			<div class="portfolio_classic_grid_wrapper <?php echo esc_attr($column_class); ?> <?php echo esc_attr($last_class); ?>  portfolio-<?php echo esc_attr($count); ?> tile scale-anm">
				<article class="music-container" onclick="void(0)">
					<?php
						if(!empty($podcast_audio))
						{
					?>
						<audio id="audio_<?php echo esc_attr($podcast_id); ?>" controls>
							  <source src="<?php echo esc_url($podcast_audio); ?>" type="audio/mpeg">
							  <?php echo __( 'Your browser does not support the audio element.', 'dotlife-elementor' ); ?>
						</audio>
						
						<div id="audio_<?php echo esc_attr($podcast_id); ?>_playing" class="music-playing">
							<div class="bar bar1" style="height: 15%;"></div>
							<div class="bar bar2" style="height: 75%;"></div>
							<div class="bar bar3" style="height: 25%;"></div>
							<div class="bar bar4" style="height: 90%;"></div>
						</div>
					<?php
						}
					?>
					<div class="controls">
						<?php
							if(!empty($podcast_audio))
							{
						?>
							<input type="radio" name="controls" id="btn-play">
							<label for="btn-play" class="lbl-btn-play" data-audio="audio_<?php echo esc_attr($podcast_id); ?>"><span><i class="fas fa-play"></i></span></label>
				
							<input type="radio" name="controls" id="btn-pause">
							<label for="btn-pause" class="lbl-btn-pause" data-audio="audio_<?php echo esc_attr($podcast_id); ?>"><span><i class="fas fa-pause"></i></span></label>
						<?php
							}
						?>
					</div>
			
					<div class="cover">
						<div class="static-card">
							<img src="<?php echo esc_url($image_url[0]); ?>" alt="<?php echo esc_attr($image_alt);?>" />
						</div>
						<div class="flip-card">
							<img src="<?php echo esc_url($image_url[0]); ?>" alt="<?php echo esc_attr($image_alt);?>" />
						</div>
					</div>
				</article>
				
				<div class="portfolio_classic_content">
					<?php
						if(!empty($podcast_subtitle))
						{
					?>
					<div class="portfolio_classic_subtitle"><?php echo esc_html($podcast_subtitle); ?></div>
					<?php
						}
						
						if(!empty($podcast_title))
						{
					?>
					<h3 class="portfolio_classic_title"><?php echo esc_html($podcast_title); ?></h3>
					<?php
						}
					?>
				</div>
			</div>
	<?php
				$count++;
			endwhile;
	?>
	<?php
		if($settings['spacing'] == 'yes')
		{
	?>
	<br class="clear"/>
	<?php
		}
	?>
	</div>
	<?php
		}
	?>
	</div>