<?php

/**
 * Walker Terms MultiSelect.
 *
 * @link    https://aiopodcasting.com
 * @since   1.0.0
 *
 * @package AiO_Podcast_Studio
 */

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

/**
 * AIOPOD_Walker_Terms_MultiSelect class.
 *
 * @since 1.0.0
 */
class AIOPOD_Walker_Terms_MultiSelect extends Walker_CategoryDropdown {
	
	/**
	 * Starts the element output.
	 *
	 * @since 1.0.0
	 * @param string  $output            Used to append additional content (passed by reference).
	 * @param WP_Term $data_object       Category data object.
	 * @param int     $depth             Depth of category. Used for padding.
	 * @param array   $args              Uses 'selected', 'show_count', and 'value_field' keys, if they exist.
	 *                                   See wp_dropdown_categories().
	 * @param int     $current_object_id Optional. ID of the current category. Default 0.
	 */
	public function start_el( &$output, $data_object, $depth = 0, $args = array(), $current_object_id = 0 ) {
		// Restores the more descriptive, specific name for use within this method.
		$category = $data_object;

		/** This filter is documented in wp-includes/category-template.php */
		$cat_name = apply_filters( 'list_cats', $category->name, $category );

		if ( $args['show_count'] ) {
			$cat_name .= '&nbsp;&nbsp;(' . number_format_i18n( $category->count ) . ')';
		}

		$value = (int) $category->term_id;

		$selected = in_array( $value, $args['selected'] ) ? true : false;

		$classes = array( 'aiopod-dropdown__item' );		
		if ( $selected ) $classes[] = 'aiopod-is-selected';
		$classes[] = 'level-' . $depth;

		$output .= "\t" . sprintf( '<div class="%s" style="padding-left:%dem;">', implode( ' ', $classes ), ( $depth + 1 ) );
		$output .= sprintf( '<div class="aiopod-dropdown__item-label">%s</div>', esc_html( $cat_name ) );
		$output .= sprintf( 
			'<input type="checkbox" name="%s" value="%d" tabindex="-1"%s/>', 
			esc_attr( $args['name'] ), 
			esc_attr( $value ),
			( $selected ? ' checked="checked"' : '' )
		);
		
		$output .= "</div>\n";
	}

}
