<?php js::set('projectID', $projectID);?>
<?php js::set('module', $module);?>
<?php js::set('method', $method);?>
<style>
#swapper .nav-tabs {position: sticky; top: 0; background: #fff; z-index: 950; border-color: #d6dae3; padding: 0 10px}
#swapper .nav-tabs>li>span {display: inline-block; margin-left: 2px;}
#swapper .nav-tabs>li+li {margin-left: 15px}
#swapper .nav-tabs>li>a {padding: 4px 0; display: inline-block}
#swapper .nav-tabs>li.active>a, .nav-tabs>li.active>span {color: #0c64eb; background: none}
#swapper .nav-tabs>li.active>a:before {position: absolute; right: 0; bottom: -1px; left: 0; display: block; height: 2px; content: ' '; background: #2B80FF; }
.nav-tabs>li.active>a, .nav-tabs>li.active>a:focus, .nav-tabs>li.active>a:hover {border: none;}

#swapper .table-row {margin: 0;}
#swapper .tab-content {margin-top: 5px; z-index: 900;}
#swapper .tab-content ul {list-style: none; margin: 0; padding-left: 0;}
#swapper .tab-content .tab-pane>ul>li.hide-in-search {position: relative;}
#swapper .tab-content .tab-pane>ul>li>label+a {padding-left: 55px;}
#swapper .tab-content .tab-pane>ul>li label {background: rgba(131,138,157,0.5); position: absolute; top: 0; left: 5px;}
#swapper .tab-content li>a {display: block; padding: 5px 10px; overflow: hidden; line-height: 20px; text-overflow: ellipsis; white-space: nowrap; text-align: left; color: inherit;}
#swapper .tab-content li a i.icon {font-size: 15px !important;}
#swapper .tab-content li a i.icon:before {min-width: 16px !important;}
#swapper .tab-content li .label {margin-top: 2px; position: unset;}
#swapper .tab-content li>a.selected {font-weight: bold}
#swapper .tab-content li>a.selected:after {content: '\e952'; font-family: zdooicon; color: #0dd66c; display: inline-block; margin-left: 5px}
#swapper .tab-content li>a.active {color: #0c64eb; background-color: #f1f3f5;}

#dropMenu .col-left {padding-bottom: 30px;}
#dropMenu .col-right a{text-align: left;}
#dropMenu .table-col {position: relative; width: 100%; min-width: 250px; max-width: 450px; padding-top: 5px}
#dropMenu {font-size: 13px!important}
#dropMenu .col-left>.list-group,
#dropMenu>.list-group {margin: 0; padding: 0}
#dropMenu li.hide-in-search>a:focus,
#dropMenu li.hide-in-search>a:hover {color: #838a9d; cursor: default;}
#dropMenu li ul li a:focus,
#dropMenu li ul li a:hover {background: #0c64eb; color: #fff;}
#dropMenu {padding: 0}
.open #dropMenu {display: block}
</style>
<?php
$projectCounts      = array();
$projectNames       = array();
$myProjectsHtml     = '';
$normalProjectsHtml = '';
$closedProjectsHtml = '';
$tabActive          = '';
$iCharges           = 0;
$others             = 0;
$dones              = 0;

foreach($projects as $project)
{
    $projectCounts[$project->id]['myProject'] = 0;
    $projectCounts[$project->id]['others']    = 0;

    if($project->status != 'finished' and $project->status != 'closed' and $project->PM == $this->app->user->account) $projectCounts[$project->id]['myProject']++;
    if($project->status != 'finished' and $project->status != 'closed' and !($project->PM == $this->app->user->account)) $projectCounts[$project->id]['others']++;
    if($project->status == 'finished' or $project->status == 'closed') $dones++;
    $projectNames[] = $project->name;
}
$projectsPinYin = commonModel::convert2Pinyin($projectNames);

foreach($projects as $project)
{
    if($projectCounts[$project->id]['myProject']) $myProjectsHtml     .= '<ul>';
    if($projectCounts[$project->id]['others'])    $normalProjectsHtml .= '<ul>';

    $selected    = $project->id == $projectID ? 'selected' : '';
    $link        = $project->type == 'normal' ? helper::createLink('task', 'browse', "projectID=%s", '', '', $project->id) : helper::createLink('kanban', 'browse', "projectID=%s", '', '', $project->id);
    $projectName = $project->name;

    if($project->status != 'finished' and $project->status != 'closed' and $project->PM == $this->app->user->account)
    {
        $myProjectsHtml .= '<li>' . html::a(sprintf($link, $project->id), $projectName, "class='$selected' title='{$project->name}' data-key='" . zget($projectsPinYin, $project->name, '') . "'") . '</li>';

        if($selected == 'selected') $tabActive = 'myProject';

        $iCharges++;
    }
    else if($project->status != 'finished' and $project->status != 'closed' and !($project->PM == $this->app->user->account))
    {
        $normalProjectsHtml .= '<li>' . html::a(sprintf($link, $project->id), $projectName, "class='$selected' title='{$project->name}' data-key='" . zget($projectsPinYin, $project->name, '') . "'") . '</li>';

        if($selected == 'selected') $tabActive = 'other';

        $others++;
    }
    else if($project->status == 'finished' or $project->status == 'closed')
    {
        $closedProjectsHtml .= html::a(sprintf($link, $project->id), $project->name, "class='$selected' title='{$project->name}' data-key='" . zget($projectsPinYin, $project->name, '') . "'");

        if($selected == 'selected') $tabActive = 'closed';
    }

    if($projectCounts[$project->id]['myProject']) $myProjectsHtml     .= '</ul>';
    if($projectCounts[$project->id]['others'])    $normalProjectsHtml .= '</ul>';
}
?>
<div class="table-row">
  <div class="table-col col-left">
    <div class='list-group'>
      <?php $tabActive = ($iCharges and ($tabActive == 'closed' or $tabActive == 'myProject')) ? 'myProject' : 'other';?>
      <?php if($iCharges): ?>
      <ul class="nav nav-tabs">
        <li class="<?php if($tabActive == 'myProject') echo 'active';?>"><?php echo html::a('#myProject', $lang->project->myProject, "data-toggle='tab' class='not-list-item not-clear-menu'");?><span><?php echo $iCharges;?></span><li>
        <li class="<?php if($tabActive == 'other') echo 'active';?>"><?php echo html::a('#other', $lang->project->other, "data-toggle='tab' class='not-list-item not-clear-menu'")?><span><?php echo $others;?></span><li>
      </ul>
      <?php endif;?>
      <div class="tab-content">
        <div class="tab-pane <?php if($tabActive == 'myProject') echo 'active';?>" id="myProject">
          <?php echo $myProjectsHtml;?>
        </div>
        <div class="tab-pane <?php if($tabActive == 'other') echo 'active';?>" id="other">
          <?php echo $normalProjectsHtml ? $normalProjectsHtml : "<ul style='padding: 30px'><li>$lang->noData</li></ul>";?>
        </div>
      </div>
    </div>
    <div class="col-footer">
      <a class='pull-right toggle-right-col not-list-item'><?php echo $lang->project->doneProjects?><i class='icon icon-angle-right'></i></a>
    </div>
  </div>
  <div class="table-col col-right">
   <div class='list-group'><?php echo $closedProjectsHtml;?></div>
  </div>
</div>
<script>
$(function()
{
    $('.nav-tabs li span').hide();
    $('.nav-tabs li.active').find('span').show();

    $('.nav-tabs>li').click(function()
    {
        $(this).find('span').show();
        $(this).siblings('li').find('span').hide();
        if($(this).attr('class') != 'active') $('.dropdown-menu').removeClass('show-right-col');
    })
})
</script>
