<?php

use yii\helpers\{Arrayhelper, Html, Url};
use yii\bootstrap4\{Modal, Tabs};
use frontend\models\{Uploads, Jobnos};
use modules\custom\models\Accounts;
use modules\users\models\Users;
use common\events\UserDataEvent;
use common\widgets\GridView;
modules\forms\models\Dt179::sitetimes($model->id);
/**
 * @var yii\web\View $this 
 * @var frontend\models\Activities $model 
 */
?>
<?php if ($model->importantnotes) { ?>
    <div class="card my-2">
        <div class="card-header bg-danger">Important Job Notes</div>
    </div>
    <?php foreach ($model->importantnotes as $a => $notes) { ?>
        <div class="card my-2">
            <div class="card-header bg-danger"><?= $notes->type ?></div>
            <div class="card-body">
                <div class="card-text">
                    <?= $notes->note ?>
                </div>
            </div>
            <div class="card-footer">
                <div class="row">
                    <div class="col-sm-6">Status: <?= $notes->status ?></div>
                    <div class="col-sm-6">Urgency: <?= $notes->urgency ?></div>
                </div>
                <div class="row">
                    <div class="col-12 col-sm-3">Created By: <?= $notes->createdby_name ?></div>
                    <div class="col-12 col-sm-3">Created At: <?= $notes->created_at ?></div>
                    <div class="col-12 col-sm-3">Updated By: <?= $notes->updatedby_name ?></div>
                    <div class="col-12 col-sm-3">Updated at: <?= $notes->updated_at ?></div>
                </div>
            </div>
        </div>
    <?php } ?>
<?php } ?>
<div class="activities-view">
        <?php
    $tabs = [];
        $tabs[] = ['label' => 'Details','content' => $this->render('viewtabs/_details_tab', ['model' => $model, 'uploads' => $uploadsAll, 'dataProvider' => $dataProvider,  ]), 'active' => true];
        $tabs[] = ['label' => 'Route','content' => $this->render('viewtabs/_route_tab', ['model' => $model]), 'active' => false];
        $tabs[] = ['label' => 'Operative Times','content' => $this->render('viewtabs/_times_tab', ['model' => $model]), 'active' => false];
        $tabs[] = ['label' => 'Fatigue / Risk','content' => $this->render('viewtabs/_fatigue_tab', ['model' => $model]), 'active' => false];
        if(Yii::$app->user->identity->ingroup('Global Admins') == true){
            $tabs[] = ['label' => 'Attachments','content' => $this->render('viewtabs/_attachments_tab', ['model' => $model, 'files' => $uploadsAll]), 'active' => false];
            $tabs[] = ['label' => 'Notes','content' => $this->render('viewtabs/_notes_tab', ['model' => $model]), 'active' => false];
            $tabs[] = ['label' => 'Update', 'url' => Url::to(['update','id' =>$model->id]), 'active' => false, 'linkOptions' => ['class' => 'bg-secondary text-white']];
        }
    ?>

    <?= Tabs::widget([
    'navType' => 'nav nav-pills nav-justified',
    'items' => $tabs ]); ?>

    <?php
    $buttons['PDF Jobs'] =[
        'label' => 'PDF Jobs',
        'url' => ['/activities/pdf', 'id' => $model->id],
        'linkOptions' =>  ['target'=>'_blank'],
        'options' => ['class' => 'bg-success'],
    ];

    
    $event = new UserDataEvent(['buttons' => $buttons, 'model' => $model]);
    $this->trigger('afteradminButtonsCollect', $event);
    if(is_array($event->buttons)){
        $buttons = $event->buttons;
    }  
?>
    <div class="actionbar">
        <div class="row">
            <div class="col-12">
                <?= yii\bootstrap4\Nav::widget([
                    'items' => $buttons,
                    'encodeLabels' => false,
                    'options'  => ['class' => 'nav fixed-bottom  nav-pills nav-justified'],
                ]); ?>
            </div>
        </div>
    </div>
</div>
<div class="form-group">
    <?php Modal::begin(['id' => 'modal']);
        echo "<div id='modalContent'></div>";
        Modal::end();
    ?>
</div>
</div>
<script>
$.getJSON("/forms/dt179/sitetimes", {
    id: "<?= $model->id ?>"
}, function(result) {
    $('#atime').text(result);
});

function map() {
    window.open("https://www.google.co.uk/maps/dir/<?= Yii::$app->params['settings']['postcode'] ?>/" +
        "<?= $model->postcode ?> ", '', 'height=' + screen.height, 'width=' + screen.width, 'fullscreen=yes');
}
</script>
