<? global $user;?>
<? if ( $this -> closed_tasks and count( $this -> closed_tasks ) ):?>
  <div class="task-group">
    <div class="title">
      Zadania zamknięte
    </div>
    <div class="dragbleList closed-tasks">
      <ul class="tasks-list sortable-list">
        <? if ( is_array( $this -> closed_tasks ) ):?>
          <? foreach ( $this -> closed_tasks as $task ):?>
            <? $task_open = \factory\Projects::is_task_open( $task['id'], $user['id'] );?>
            <li class="sortable-item task done <? if ( $task['date_end'] and $task['date_end'] <= date( 'Y-m-d' ) and !$task['status'] ):?>delayed<? endif;?>" id="task-<?= $task['id'];?>">
              <div class="manage-menu">
                <? $random_id = rand(0,9999999999);?>
                <span class="context-menu" data-container-id="task-<?= $task['id'];?>-menu-<?= $random_id;?>"></span>
                <div class="context-menu-container" id="task-<?= $task['id'];?>-menu-<?= $random_id;?>">
                  <ul>
                    <li>
                      <a href="/projects/task_edit/id=<?= $task['id'];?>" class="task-edit">
                        Edytuj
                      </a>
                    </li>
                    <li>
                      <a href="#" class="task-remove" task-id="<?= $task['id'];?>">
                        Usuń zadanie
                      </a>
                    </li>
                    <li>
                      <a href="#" class="task-remove-all" task-id="<?= $task['id'];?>">
                        Usuń zadania i zadania powiązane
                      </a>
                    </li>
                  </ul>
                </div>
              </div>
              <div class="dates <? if ( $task['date_complete'] ):?>set<? endif;?>">
                <?= date( 'Y-m-d', strtotime( $task['date_complete'] ) );?>
              </div>
              <div class="flex flex-ac">
                <div class="time">
                  <?= sprintf( "%02d%s%02d%s%02d", floor( $task['total_time'] / 3600 ), ':', ( $task['total_time'] / 60) % 60, ':', $task['total_time'] % 60 );;?>
                </div>
                <div class="status">
                  <? if ( $user['id'] == 1 ):?>
                    <select name="task-status" class="task-status" task_id="<?= $task['id'];?>">
                      <option value="0" <? if ( $task['status'] == 0 ):?>selected="selected"<? endif;?>>nowe</option>
                      <option value="1" <? if ( $task['status'] == 1 ):?>selected="selected"<? endif;?>>do sprawdzenia</option>
                      <option value="2" <? if ( $task['status'] == 2 ):?>selected="selected"<? endif;?>>zamknięte</option>
                    </select>
                  <? endif;?>
                </div>
                <div class="name">
                  <div class="top">
                    <? if ( $open_subtasks = \factory\Projects::count_open_subtasks( $task['id'] ) ):?>
                      <a href="#" class="open_subtasks_count" onclick="return false;" task-id="<?= $task['id'];?>">
                        <?= $open_subtasks;?>
                      </a>
                    <? endif;?>
                    <? if ( $task['text'] ):?>
                      <a href="#" class="task-details" task-id="<?= $task['id'];?>">
                        <i class="fa fa-info"></i>
                      </a>
                    <? endif;?>
                    <? if ( $task['client_id'] ):?>
                      <span class="client_info" task-id="<?= $task['id'];?>"><?= \factory\Crm::get_client_name( (int)$task['client_id'] );?></span>
                    <? endif;?>
                    <? if ( $task['pay_rate'] and $this -> user['id'] == 1 ):?>
                      <span class="pay-rate">stawka: <strong><?= $task['pay_rate'];?> zł</strong></span>
                    <? endif;?>
                  </div>
                  <div class="bottom">
                    <span class="task-details" task-id="<?= $task['id'];?>">
                      <?= $task['name'];?><? if ( $task['actions'] and count( $task['actions'] ) ):?> <? $count = 0; foreach ( $task['actions'] as $action ) if ( $action['status'] == null ) $count++; if ( $count ) echo '(' . $count . ')';?><? endif;?>
                    </span>
                  </div>
                </div>
              </div>
              <div class="users">
                <? if ( is_array( $task['users'] ) ): foreach ( $task['users'] as $user_tmp_id ):?>
                  <?
                    $user_tmp = \factory\Users::user_details( $user_tmp_id );
                    echo '<div class="user" style="background: ' . $user_tmp['color'] . '">' . $user_tmp['name'][0] . $user_tmp['surname'][0] . '</div>';
                  ?>
                <? endforeach; endif;?>
              </div>
              <script type="text/javascript">
                $( function()
                {
                  $(document).ready(function(){
                    var tableContextMenu = new ContextMenu("task-<?= $task['id'];?>-menu-<?= $random_id;?>", menuItemClickListener);
                  });
                });
              </script>
            </li>
          <? endforeach;?>
        <? endif;?>
      </ul>
    </div>
  </div>
<? endif;?>