<?
if ( is_array( $this -> pages ) ) {
  $settings = ( new \Domain\Settings\SettingsRepository( $GLOBALS['mdb'] ) )->allSettings();

  echo '<ul class="level-' . $this -> level . ' clear" level="' . $this -> level . '">';

  foreach ( $this -> pages as $page ) {
    $url = "";
    
    if ( $page['page_type'] == 3 ) {
      $page['language']['link'] ? $url = $page['language']['link'] : $url = '#';      
    } else if ( $page['page_type'] == 5 ) {
      $page['category_id'] ? $url = \front\factory\ShopCategory::category_url( $page['category_id'] ) : $url = '#';
    } else {
      $page['language']['seo_link'] ? $url = '/' . $page['language']['seo_link'] : $url = '/s-' . $page['id'] . '-' . \Shared\Helpers\Helpers::seo( $page['language']['title'] );
    }
    unset( $children );

    if ( is_array( $page['pages'] ) ): foreach ( $page['pages'] as $page_tmp ):
        $children[] = $page_tmp['id'];
      endforeach;
    endif;

    echo '<li id="link-' . $page['id'] . '" class="';

    if ( $page['id'] == $this -> current_page )
      echo ' active';

    if ( is_array( $page['pages'] ) and in_array( $this -> current_page, $children ) )
      echo ' open';

    if ( is_array( $page['pages'] ) )
      echo ' parent';

    echo '">';
    echo '<a href="';
    if ( \Shared\Helpers\Helpers::get_session( 'current-lang' ) != ( new \Domain\Languages\LanguagesRepository( $GLOBALS['mdb'] ) )->defaultLanguage() and $url != '#' and $page['page_type'] != 3 and $page['page_type'] != 5 )
      echo '/' . \Shared\Helpers\Helpers::get_session( 'current-lang' );
    echo $url . '"';
    if ( $page['language']['noindex'] )
      echo 'rel="nofollow"';
    echo ' title="' . $page['language']['title'] . '"';
    if ( is_array( $page['pages'] ) )
      echo "class='menu-trigger'";
    echo '>';
    echo $page['language']['title'];
    echo '</a>';
    if ( is_array( $page['pages'] ) )
      echo '<i class="fa fa-chevron-down menu-toggle" menu-id="link-' . $page['id'] . '"></i>';
    echo \front\view\Menu::pages( $page['pages'], $this -> level + 1, $this -> current_page );
    echo '</li>';
  }
  echo '</ul>';
}
?>