<div class="task_details" task_id="<?= $this -> task['id'];?>">
  <a href="#" class="close"><i class="fa fa-times"></i></a>
  <div class="title">
    <a href="/tasks/task_edit/task_id=<?= $this -> task['id'];?>" class="_edit">
      <i class="fa fa-pencil"></i>
    </a>
    <? if ( $this -> user['id'] == 1 ):?>
      <a href="#" class="task-delete" task_id="<?= $this -> task['id'];?>">
        <i class="fa fa-trash"></i>
      </a>
    <? endif;?>
    #<?= $this -> task['id'];?> <?= $this -> task['name'];?>
  </div>
  <div class="content">
    <div class="left">
      <div class="users box">
        <? if ( is_array( $this -> task['users'] ) ): foreach ( $this -> task['users'] as $user_tmp_id ):?>
          <? $user_tmp = \factory\Users::user_details( $user_tmp_id );?>
          <div class="user">
             <div class="avatar" style="background: <?= $user_tmp['color'];?>;" title="<?= $user_tmp['name'] . $user_tmp['surname'];?>"><?= $user_tmp['name'][0] . $user_tmp['surname'][0];?></div>
             <?= $user_tmp['name'] . $user_tmp['surname'];?>
          </div>
        <? endforeach; endif;?>
      </div>
      <? if ( $this -> task['text'] ):?>
        <div class="description">
          <a href="#" class="fullscreen"><i class="fa fa-expand"></i></a>
          <?= htmlspecialchars_decode( $this -> task['text'] );?>
        </div>
      <? endif;?>
      <div class="checklist">
        <h3>Lista kontrolna</h3>
        <div class="new_element">
          <input type="text" class="form-control" placeholder="Dodaj nowy element">
          <a href="#" class="add_element" task_id="<?= $this -> task['id'];?>"><i class="fa fa-plus"></i></a>
        </div>
        <ul>
          <? foreach ( $this -> task['actions'] as $action ):?>
            <li action_id="<?= $action['id'];?>">
              <input type="checkbox" class="g-checkbox" value="<?= $action[ 'id' ];?>" <? if ( $action['status'] ):?>checked="checked"<? endif;?>>
              <?= $action['name'];?>
              <a href="#" class="point-delete" action_id="<?= $action['id'];?>">
                <i class="fa fa-trash"></i>
              </a>
            </li>
          <? endforeach;?>
        </ul>
      </div>
      <div class="comments">
        <h3>Komentarze</h3>
        <div class="new_comment">
          <textarea class="form-control" placeholder="Dodaj nowy komentarz"></textarea>
          <a href="#" class="add_comment" task_id="<?= $this -> task['id'];?>">Dodaj nowy komentarz</a>
        </div>
        <ul>
          <? foreach ( $this -> task['comments'] as $comment ):?>
            <li>
              <a href="#" class="delete_comment" comment_id="<?= $comment['id'];?>"><i class="fa fa-trash"></i></a>
              <div class="author"><?= \factory\Users::user_details( $comment['user_id'] )['name'] . ' ' . \factory\Users::user_details( $comment['user_id'] )['surname'];?></div>
              <div class="date"><?= date( 'Y/m/d H:i', strtotime( $comment['date_add'] ) );?></div>
              <div class="text"><?= nl2br( $comment['text'] );?></div>
            </li>
          <? endforeach;?>
        </ul>
      </div>
    </div>
    <div class="right">
      <div class="status box">
        <h3>Status</h3>
        <div class="current_status">
          <select name="task_status" class="form-control" task_id="<?= $this -> task['id'];?>">
            <? foreach ( \factory\Tasks::get_statuses() as $key => $status ):?>
              <option value="<?= $key;?>" <? if ( $this -> task['status'] == $key ):?>selected="selected"<? endif;?>><?= $status;?></option>
            <? endforeach;?>
          </select>
        </div>
      </div>
      <div class="dates box">
        <h3>Termin</h3>
        <? if ( $this -> task['date_start'] ):?>
          <div class="date_start"><i class="fa fa-regular fa-calendar"></i><?= $this -> task['date_start'];?></div>
        <? endif;?>
        <? if ( $this -> task['date_end'] ):?>
          <div class="date_end <? if ( $this -> task['status'] != 2 and $this -> task['date_end'] == date( 'Y-m-d' ) ):?> warning<? endif;?> <? if ( $this -> task['status'] != 2 and $this -> task['date_end'] < date( 'Y-m-d' ) ):?> dangerx<? endif;?>"><i class="fa fa-regular fa-calendar"></i><?= $this -> task['date_end'];?></div>
        <? endif;?>
      </div>
      <div class="client box">
        <h3>Klient</h3>
        <? if ( $this -> task['client_id'] ):?>
          <?= \factory\Crm::get_client_name( $this -> task['client_id'] );?>
        <? endif;?>
      </div>
      <div class="time box">
        <h3>Przepracowany czas</h3>
        <div class="time_worked">
          <a href="#" class="time_worked_toggle">
            <?= sprintf( "%02d%s%02d%s%02d", floor( $this -> task['total_time'] / 3600 ), ':', ( $this -> task['total_time'] / 60) % 60, ':', $this -> task['total_time'] % 60 );?>
          </a>
        </div>
        <a href="#" class="task_start <? if ( $this -> task['is_open'] ):?> hidden<? endif;?>" task_id="<?= $this -> task['id'];?>">
          <i class="fa fa-play"></i> Włącz timer
        </a>
        <a href="#" class="task_end <? if ( !$this -> task['is_open'] ):?> hidden<? else:?> animate<? endif;?>" task_id="<?= $this -> task['id'];?>">
          <i class="fa fa-stop"></i> Wyłącz timer
        </a>
      </div>
    </div>
    <div class="task_work_details">
      <? foreach ( $this -> task_works as $task_work ):?>
        <div class="_line">
          <div class="_user"><?= \factory\Users::user_details( $task_work['user_id'] )['name'] . ' ' . \factory\Users::user_details( $task_work['user_id'] )['surname'];?></div>
          <input type="text" class="form-control task_work_date_start" task_work_id="<?= $task_work['id'];?>" value="<?= $task_work['date_start'];?>"><span>-</span><input type="text" class="form-control task_work_date_end" task_work_id="<?= $task_work['id'];?>" value="<?= $task_work['date_end'];?>">
          <a href="#" class="_work_delete" work_id="<?= $task_work['id'];?>" task_id="<?= $this -> task['id'];?>">
            <i class="fa fa-trash"></i>
          </a>
        </div>
      <? endforeach;?>
    </div>
  </div>
</div>