<?php

/**
 * Menu functionality and enhancements
 *
 * @package Kubelio\Core
 * @since 1.0.0
 */

namespace Kubelio\Core;

if (! defined('ABSPATH')) {
	exit;
}

/**
 * Menu Class
 */
class Menu {

	/**
	 * Constructor.
	 */
	public function __construct() {
		add_filter('walker_nav_menu_start_el', array($this, 'add_menu_arrow'), 10, 4);
	}

	/**
	 * Menu arrow
	 *
	 * Add arrow to menu items with children
	 *
	 * @param string   $item_output The menu item's starting HTML output.
	 * @param \WP_Post $item        Menu item data object.
	 * @param int      $depth       Depth of menu item. Used for padding.
	 * @param \stdClass $args       An object of wp_nav_menu() arguments.
	 * @return string html
	 */
	public function add_menu_arrow($item_output, $item, $depth, $args) {
		if (in_array('menu-item-has-children', $item->classes, true)) {
			// append icon
			$item_output .= '<span class="rt-menu-arrow"><i class="rt-icon"><svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" fill="currentColor" class="bi bi-chevron-down" viewBox="0 0 16 16">
			<path fill-rule="evenodd" d="M1.646 4.646a.5.5 0 0 1 .708 0L8 10.293l5.646-5.647a.5.5 0 0 1 .708.708l-6 6a.5.5 0 0 1-.708 0l-6-6a.5.5 0 0 1 0-.708z"/>
		  </svg></i></span>';
		}

		return $item_output;
	}
}
