<?php
/**
 * Custom walker class to output markup for UIkit v3 nav in Offcanvas component.
 */

if ( ! class_exists( 'Basho_Walker_Offcanvas_Navigation' ) ) {
	/**
	 * A custom walker for primary navigation.
	 */
    class Basho_Walker_Offcanvas_Navigation extends Walker_Nav_Menu {

        /**
         * Starts the list before the elements are added.
         *
         * Adds classes to the unordered list sub-menus.
         *
         * @param string $output Passed by reference. Used to append additional content.
         * @param int    $depth  Depth of menu item. Used for padding.
         * @param array  $args   An array of arguments. @see wp_nav_menu()
         */
        function start_lvl( &$output, $depth = 0, $args = array() ) {
            // Depth-dependent classes.
            $indent = ( $depth > 0  ? str_repeat( "\t", $depth ) : '' ); // code indent

            $display_depth = ( $depth + 1 ); // because it counts the first submenu as 0

            $classes = array(
                'uk-nav-sub sub-menu',
                ( $display_depth % 2  ? 'menu-odd' : 'menu-even' ),
                ( $display_depth >=2 ? 'sub-sub-menu' : '' ),
                'menu-depth-' . $display_depth
            );
            $class_names = implode( ' ', $classes );

            // Build HTML for output.
            $output .= "\n" . $indent . '<ul class="' . $class_names . '">' . "\n";
        }

    }

}
