<?
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 = "";
    $hasChildren = is_array( $page['pages'] ) && !empty( $page['pages'] );

    if ( $page['page_type'] == 3 ) {
      $page['language']['link'] ? $url = $page['language']['link'] : $url = '#';
    } else if ( $page['page_type'] == 5 ) {
      $page['category_id'] ? $url = (new \Domain\Category\CategoryRepository( $GLOBALS['mdb'] ))->categoryUrl( (int)$page['category_id'], $GLOBALS['lang_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 ( $hasChildren and is_array( $children ) and in_array( $this -> current_page, $children ) )
      echo ' open';

    if ( $hasChildren )
      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 ( $hasChildren )
      echo "class='menu-trigger'";
    echo '>';
    echo $page['language']['title'];
    if ( $hasChildren )
    echo '<i class="fa fa-chevron-down menu-toggle" menu-id="link-' . $page['id'] . '"></i>';
    echo '</a>';
    if ( $hasChildren )
      echo \front\Views\Menu::pages( $page['pages'], $this -> level + 1, $this -> current_page );
    echo '</li>';
  }
  echo '</ul>';
}
?>
