<?php

namespace Barn2\Plugin\WC_Product_Tabs_Pro\Admin;

use Walker_Category;

class Product_Category_Walker extends Walker_Category {

	public function start_el( &$output, $term, $depth = 0, $args = [], $id = 0 ) {

		$args = wp_parse_args(
			$args,
			[
				'name'    => 'wpt_product_category',
				'checked' => [],
			]
		);

		extract( $args );

		$checked_text = '';
		if ( is_array( $checked ) ) {
			$checked_text = checked( in_array( $term->term_id, $checked ), true, false );
		}

		ob_start(); ?>

	<li>
		<input type="checkbox" <?php echo esc_attr( $checked_text ); ?> id="category-<?php echo esc_attr( $term->term_id ); ?>" name="<?php echo esc_attr( $name ); ?>[]" value="<?php echo esc_attr( $term->term_id ); ?>" />
		<label for="category-<?php echo esc_attr( $term->term_id ); ?>">
			<?php echo esc_html( $term->name ); ?>
		</label>

		<?php
		// closing LI is added inside end_el

		$output .= ob_get_clean();
	}
}
