<?php

use yii\widgets\ActiveForm;
use yii\helpers\Html;

use common\modules\support\models\redmine\Issue;
use common\modules\support\models\redmine\RedmineHelper;

$parser = new \Netcarver\Textile\Parser(); 

?>

<div class="container_white support-block">
    <div class="container">
        
        <div class="right_box_top row">
            <div class="col-md-6 col-xs-6 col-sm-12">
                <h2>Просмотр задачи</h2>
            </div>
            <div class="col-md-6 col-xs-6 col-sm-12">
                <div class="logo_taskon">
                    <span>Разработанно в:  </span>
                    <a href=""><img src="/images/logo_taskon.png" height="44" width="135" alt=""></a>
                </div>
            </div>
        </div>

        <div class="row">
          
            <div class="col-md-12">
          
                <div class="panel-body panel-body-ex-1 panel-body-ex-3 notifications_box color_on_cursor" <?=($model['priority']['id']==Issue::PRIORITY_SIMPLE?'style="border:0;"':'')?>>
                    <div>

                        <div class="text-mes">
                            <p><strong><?=$model['subject']?></strong></p>
                            <p><span><?=Yii::$app->formatter->asDate($model['created_on'], 'php:d F Y, H:i');?></span></p>
                        </div>

                        <?php if(isset($model['attachments']) && !empty($model['attachments'])) : ?>
                            <div class="pull-right dropdown_file">
                                <span class="glyphicon glyphicon-paperclip"></span>
                                <?=count($model['attachments'])?>

                                <div class="dropdown_box_file">
                                    <ul>
                                        <?php foreach ($model['attachments'] as $attachment) : ?>
                                            <li><span class="glyphicon glyphicon-file"></span><a target="_blank" href="<?=$attachment['content_url']?>"><?=$attachment['filename']?></a></li>
                                        <?php endforeach; ?>
                                    </ul>
                                </div>
                            </div>
                        
                        <?php endif; ?>

                    </div>
                </div>
            
            </div>

        </div>

        <div class="row">
          
            <div class="col-md-12">
          
                <p><strong>Описание задачи</strong></p>
                <p>
                    <?=$parser->textileThis($model['description']); ?>
                </p>
        
            </div>
          
        </div>

        <br>

        <div class="row">
            <div class="col-sm-12">

                <p class="label_p"><strong>Добавить комментарий к задаче</strong></p>
                <div class="text_box_form text_box_form_bg">

                    <?php $form = ActiveForm::begin(); ?>

                        <div class="row">
                            <div class="col-sm-12">

                                <?=$form->field($issue, 'notes', ['template' => "{input}<br>{hint}{error}"])->widget(\coderlex\markitup\MarkItUp::className(), [
                                    'options' => ['class' => 'form-control', 'style' => 'overflow:auto;resize:none;width:100%;min-height:100px;'],
                                    'clientOptions' => [
                                        'markupSet' => RedmineHelper::$markupSet
                                    ],
                                ])->label(false)?>

                            </div>
                        </div>

                        <div id="file-container">
                        
                        </div>

                        <input type="file" id="file-attachment-input" style="display:none;" multiple="multiple">
                        
                        <?= Html::submitButton('Отправить', ['class' => 'btn btn-success-2 gray_button_poz']) ?>

                        <div class="gray_button attachment-button">Прикрепить файл<i class="glyphicon glyphicon-paperclip"></i></div> 

                    <?php ActiveForm::end(); ?>

                </div>
        
            </div>
        </div>
    
        <?php if(isset($model['journals'])) : ?>
            <div class="row">
                <div class="col-md-12">
                    <div class="commentary_col">
                        <strong>Комментарии (<?=count($model['journals'])?>) </strong><!-- &nbsp;<span class="label label-success" data-toggle="tooltip" data-placement="bottom" title="" data-original-title="4 задачи требуют проверки">4</span> -->
                    </div>
                    
                    <?php foreach ($model['journals'] as $i => $journal) : ?>
                        <div class="commentary_box">

                            <p><strong><?=$journal['user']['name']?></strong> <span class="color_gray"><?=Yii::$app->formatter->asDate($journal['created_on'], 'php:d F Y, H:i');?></span></p>
                            <p>
                                <?=$parser->textileThis($journal['notes']);?>
                            </p>

                            <?php if(isset($journal['details'])) : ?>
                                <?php foreach ($journal['details'] as $detail) : ?>
                                    <?php if($detail['property'] == 'attachment') : ?>
                                        <span class="glyphicon glyphicon-file"></span><?=$detail['new_value']?>&nbsp;&nbsp;
                                    <?php endif; ?>
                                <?php endforeach; ?>
                            <?php endif; ?>

                            <br>

                            <?php if($i != count($model['journals']) - 1) : ?>
                                <div class="line_3"></div>
                            <?php endif; ?>

                        </div>
                    <?php endforeach; ?>
                
                </div>
            </div>

            <br>

            <br>

        <?php endif; ?>

    </div>
</div>

<?=$this->render('@app/views/layouts/footer');?>