<?php
/**
* @package   SP Soccer
* @author    JoomShaper http://www.joomshaper.com
* @copyright Copyright (C) 2010 - 2017 JoomShaper. All rights reserved.
* @license   http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 or later.
*/


// no direct access
defined('_JEXEC') or die;

$team_key = 0;
$rank_teams= array();
foreach ($teams as &$team) {
  if (!empty($team->top_team_groups)) {
    foreach($team->top_team_groups as &$top_team_group){
        $rank_teams[$team_key] = $top_team_group;
        $team_key ++;
     }
  }
}

$rank_teams = ModSpClubRankingsHelper::msort($rank_teams, array('pts'));

?>

<div class="sp-club-rankings <?php echo $moduleclass_sfx . ' ' . $module->id; ?>">

  <?php if (!empty($rank_teams)) { ?>
  <div id="carousel-rank-<?php echo $module->id; ?>" class="carousel-club-rank carousel slide" data-ride="rank-carousel">

  <!-- Controls -->
  <div class="carousel-controls">
    <a class="left rank-control" data-target="#carousel-rank-<?php echo $module->id; ?>" role="button" data-slide="prev">
      <i class="sp-soccer-angle-left"></i>
    </a>
    <a class="right rank-control" data-target="#carousel-rank-<?php echo $module->id; ?>" role="button" data-slide="next">
      <i class="sp-soccer-angle-right"></i>
    </a>
  </div>

    <!-- Wrapper for slides -->
    <div class="carousel-inner" role="listbox">
      <?php
      $rank_key = 1;
      foreach(array_chunk($rank_teams, $row) as $key => $rank_teams) { ?>

          <div class="item <?php echo ($key == 0) ? 'active' : '' ?>">
            <ul>

              <?php foreach ($rank_teams as $rank_team) {
                $rank_team['team_logo'] = SpsoccerHelper::hasImg($rank_team['team_logo']);
              ?>

                <li>
                  <span>
                    <?php echo $rank_key; ?>
                    <img class="img-responsive" src="<?php echo $rank_team['team_logo']; ?>" alt="England">
                    <?php echo $rank_team['team_name']; ?>
                  </span>
                  <span class="pull-right"><?php echo $rank_team['pts']; ?></span>
                </li>

              <?php $rank_key ++; }  // end:: foreach $matches  ?>

            </ul>
          </div> <!-- /.item -->

      <?php } // end:: array_chunk  ?>

    </div> <!-- /.carousel-inner -->


  </div> <!-- /.carousel-rank -->

  <?php } else{ ?>
      <div class="module-content">
        <p>No item found in this tournament</p>
      </div>
  <?php } // end:: else ?>


</div><!--/.sp-recent-result-->
