<input type="hidden" name="task-id" id="task-id" value="<?= $this -> task['id'];?>">
<div class="text">
  <div class="row">
    <div class="col-lg-9">
      <div class="tab-block mb25">
        <? $i = 0;?>
        <ul class="nav tabs-left tabs-border mb25">
          <? foreach ( $this -> task['text_history'] as $history ):?>
            <li <? if ( !$i++ ):?>class="active"<? endif;?>>
              <a href="#tab_task_<?= $history['id'];?>" data-toggle="tab"><?= date( 'Y-m-d H:i', strtotime( $history['date_add'] ) );?></a>
            </li>
          <? endforeach;?>
        </ul>
        <? $i = 0;?>
        <div class="tab-content">
          <? foreach ( $this -> task['text_history'] as $history ):?>
            <div class="tab-pane <? if ( !$i++ ):?>active<? endif;?>" id="tab_task_<?= $history['id'];?>">
              <button class="btn btn-primary btn-sm btn_task_content_edit mb25" history_id="<?= $history['id'];?>"><i class="fa fa-edit"></i>edytuj</button>
              <div class="task-preview-text" id="task_preview_text_<?= $history['id'];?>">
                <?= htmlspecialchars_decode( $history['text'] );?>
              </div>
            </div>
          <? endforeach;?>
        </div>
      </div>
      <div class="panel panel-success" style="clear: both;">
        <div class="panel-heading ui-sortable-handle">
          <span class="panel-title">Nowa treść</span>
        </div>
        <div class="panel-body">
          <div class="task_new_text">
            <button class="btn btn-success btn-sm btn_task_content_new" task_id="<?= $this -> task['id'];?>"><i class="fa fa-edit"></i>dodaj nowy wpis</button>
            <button class="btn btn-danger btn-sm btn_task_content_new_save" task_id="<?= $this -> task['id'];?>"><i class="fa fa-save"></i>zapisz</button>
            <button class="btn btn-dark btn-sm btn_task_content_new_cancel" task_id="<?= $this -> task['id'];?>"><i class="fa fa-times"></i>anuluj</button>
            <div class="task-preview-text" id="task_preview_text"></div>
          </div>
        </div>
      </div>
    </div>
    <div class="col-lg-3">
      <div class="task-actions">
        <a href="#" class="action-add btn btn-success btn-sm" onclick='$( ".task-preview .action-form" ).removeClass( "hidden" ); $( ".task-preview" ).find( "input" ).focus(); return false;'>
          <i class="fa fa-plus"></i>Dodaj element do checklisty
        </a>
        <div class="action-form hidden">
          <input type="text" class="form-control" placeholder="dodaj czynność..." value="" id="action-name" task-id="<?= $this -> task['id'];?>" action-id="" task-id='<?= $this -> task['id'];?>'>
          <button type="button" class="btn btn-success btn-sm" id="btn-action-add" task-id="<?= $this -> task['id'];?>"><i class="fa fa-check"></i>zatwierdź</button>
        </div>
        <div class="panel panel-primary">
          <div class="panel-heading ui-sortable-handle">
            <span class="panel-title">Checklista</span>
          </div>
          <div class="panel-body">
            <div class="action-list">
              <? if ( is_array( $this -> task['actions'] ) ): foreach( $this -> task['actions'] as $action ):?>
              <div class="action <? if ( $action['status'] ):?>done<? endif;?>" id="action-<?= $action['id'];?>">
                <div class="priority priority-0 <? if ( !$action['status'] ):?>action-mark-as-done<? else:?>action-mark-as-undone<? endif;?>" action-id="<?=  $action['id'];?>"></div>
                <div class="name">
                  <span><?= date( 'Y-m-d H:i', strtotime( $action['date_add'] ) );?> | <?= $action['name'];?></span>
                </div>
                <div class="buttons">
                  <a href="#" class="action-edit" action-id="<?= $action['id'];?>" task-id='<?= $this -> task['id'];?>'>
                    <i class="fa fa-cog"></i>
                  </a>
                  <a href="#" class="action-delete" action-id="<?= $action['id'];?>" task-id='<?= $this -> task['id'];?>'>
                    <i class="fa fa-trash"></i>
                  </a>
                </div>
              </div>
              <? endforeach; endif;?>
            </div>
          </div>
        </div>
      </div>
      <div class="panel panel-success">
        <div class="panel-heading ui-sortable-handle">
          <span class="panel-title">Historia</span>
        </div>
        <div class="panel-body">
          <ol class="timeline-list">
            <? foreach ( $this -> task['history_works'] as $history ):?>
              <li class="timeline-item">
                <div class="timeline-icon bg-dark light">
                  <span class="fa fa-calendar-o"></span>
                </div>
                <div class="timeline-desc">
                  <?= \factory\Users::user_details( $history['user_id'] )['name'];?> <?= \factory\Users::user_details( $history['user_id'] )['surname'];?> <?= $history['text'];?>
                  <!-- <a href="#">Ipod</a> -->
                </div>
                <div class="timeline-date">
                  <?
                  $date_start = new DateTime( $history['date_start'] );
                  $date_end = new DateTime( $history['date_end'] );
                  $interval = $date_start -> diff( $date_end );
                  echo $interval -> format( '%H:%I:%S' );
                  ?>
                </div>
              </li>
            <? endforeach;?>
            </ol>
        </div>
      </div>
    </div>
  </div>