<?php

/**
 * Layout: List.
 *
 * @link    https://aiopodcasting.com
 * @since   1.0.0
 *
 * @package AiO_Podcast_Studio
 */

// Exit if accessed directly
if ( ! defined( 'WPINC' ) ) {
	die;
}

$args = array(
	'taxonomy'         => 'aiopod_tags',      
	'orderby'          => sanitize_text_field( $attributes['orderby'] ),
	'order'            => sanitize_text_field( $attributes['order'] ),
	'hide_empty'       => (int) $attributes['hide_empty'], 
	'show_count'       => (int) $attributes['show_count'], 
	'show_option_none' => '',   
	'title_li'         => '',
	'echo'             => 0
);

if ( ! empty( $attributes['include'] ) ) { // Include tag IDs
	$args['include'] = array_map( 'intval', explode( ',', $attributes['include'] ) );
}

if ( ! empty( $attributes['exclude'] ) ) { // Exclude tag IDs
	$args['exclude'] = array_map( 'intval', explode( ',', $attributes['exclude'] ) );
}

$args    = apply_filters( 'aiopod_tags_args', $args, $attributes );
$tags_li = wp_list_categories( $args ); 

// Render HTML output
if ( ! empty( $tags_li ) ) : ?>
	<div class="aiopod aiopod-tags aiopod-tags--layout-list">
		<ul class="aiopod-tags__list">
			<?php echo $tags_li; ?>
		</ul>
	</div>
<?php elseif ( 0 === (int) $attributes['hide_if_empty'] ) : ?>
	<div class="aiopod aiopod-tags aiopod-tags--layout-list">
		<div class="aiopod-tags__empty aiopod-text-muted">
			<?php esc_html_e( 'No tags found.', 'aio-podcast-studio' ); ?>
		</div>
	</div>
<?php endif;
