<?
if ( is_array( $this -> categories ) ):
  ?>
    <ul class="<? if ( $this -> level == 0 ):?>shop-categories<? endif;?> level-<?= (int)$this -> level;?>">
      <? foreach ( $this -> categories as $category ):?>
        <? if ( $category['status'] ):?>
          <li id="category-<?= $category['id'];?>" class="<? if ( $category['id'] == $this -> current_category ) echo 'active open';?>
            <?
              if ( $this -> level == 1 and is_array( $category['categories'] ) ):
                foreach ( $category['categories'] as $category_tmp ):
                  if ( $category_tmp['id'] == $this -> current_category )
                    echo 'open';
                endforeach;
              endif;
            ?>">
            <?
              $category['language']['seo_link'] ? $url = '/' . $category['language']['seo_link'] : $url = '/k-' . $category['id'] . '-' . \Shared\Helpers\Helpers::seo( $category['language']['title'] );

              if ( \Shared\Helpers\Helpers::get_session( 'current-lang' ) != ( new \Domain\Languages\LanguagesRepository( $GLOBALS['mdb'] ) )->defaultLanguage() and $url != '#' )
                $url = '/' . \Shared\Helpers\Helpers::get_session( 'current-lang' ) . $url;
            ?>
            <a href="<?= $url;?>" title="<?= $category['language']['title'];?>" <? if ( is_array( $category['categories'] ) ) echo "class='menu-trigger'";?>>
              <?= $category['language']['title'];?>
            </a>
            <? if (  is_array( $category['categories'] ) and $category['id'] == $this -> current_category and $this -> level != 0 ):?>
              <i class="fa fa-chevron-up toggle" category="<?= $category['id'];?>"></i>
            <? endif;?>
            <? if (  is_array( $category['categories'] ) and $category['id'] != $this -> current_category and $this -> level != 0 ):?>
              <i class="fa fa-chevron-down toggle" category="<?= $category['id'];?>"></i>
            <? endif;?>
            <? if ( is_array( $category['categories'] ) ) echo \front\Views\ShopCategory::categories( $category['categories'], $this -> current_category, $this -> level + 1 );?>
          </li>
        <? endif;?>
      <? endforeach;?>
    </ul>
  <?
endif;
?>
<? if ( $this -> level == 0 ):?>
<script class="footer" type="text/javascript">
  $( function()
  {
    $( 'body' ).on( click_event, '.shop-categories .toggle', function()
    {
      var category = $( this ).attr( 'category' );
      if ( $( '#category-' + category ).hasClass( 'open' ) )
      {
        $( '#category-' + category ).children( 'ul' ).css( 'height', 0 );
        $( '#category-' + category ).children( 'i.toggle' ).removeClass( 'fa-chevron-up' ).addClass( 'fa-chevron-down' );
        $( '#category-' + category ).removeClass( 'open' );
      }
      else
      {
        $( '#category-' + category ).children( 'ul' ).css( 'height', 'auto' );
        $( '#category-' + category ).children( 'i.toggle' ).removeClass( 'fa-chevron-down' ).addClass( 'fa-chevron-up' );
        $( '#category-' + category ).addClass( 'open' );
      }
    });
  });
</script>
<? endif; ?>
