<?php
use yii\helpers\Html;
use yii\widgets\Pjax;
$status = ['Active' => 'Active', 'Deleted' => 'Deleted'];
$type = ['Travel' => 'Travel', 'Parking' => 'Parking', 'General' => 'General'];
$urgency = [0 => 'Not Important', 5 => 'Normal', 10 => 'Urgent'];
?>
<div class="notes">
    <div class="row ">
        <div class="col-12">
            <div class="card">
                <div class="card-header">
                    New Note
                </div>
                <div class="card-body">
                    <div class="row">
                        <div class="col-sm-12">
                            <?= HTML::textArea('note','', ['class' => 'form-control']) ?>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-sm-4">
                            <label>Status</label>
                            <?= HTML::dropdownList('status',null, $status, ['prompt' => 'Please Select', 'class' => 'form-control']) ?>
                        </div>
                        <div class="col-sm-4">
                            <label>Type</label>
                            <?= HTML::dropdownList('type', null, $type, ['prompt' => 'Please Select', 'class' => 'form-control']) ?>
                        </div>
                        <div class="col-sm-4">
                            <label>Urgency</label>
                            <?= HTML::dropdownList('urgency', null, $urgency, ['prompt' => 'Please Select', 'class' => 'form-control']) ?>
                        </div>
                    </div>
                </div>
                <div class="card-footer">
                    <div class="row">
                        <div class="col-12">
                            <span class="float-right">
                                <?= HTML::hiddenInput('actid',"$model->id", ['class' => 'form-control']) ?>
                                <?= HTML::hiddenInput('_csrf',Yii::$app->request->getCsrfToken(), ['class' => 'form-control']) ?>
                                <?= HTML::A('Create', ['/notes/new'], ['class' => 'btn btn-primary', 'data-method' => 'POST'])?>
                            </span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="row mt-5">
        <div class="col-12">
            <div class="card">
                <div class="card-header bg-success">
                    Notes
                </div>
            </div>
        </div>
	</div>
	<?php Pjax::begin(['id' => 'Notes']); ?>
    <?php if ($model->renotes) { ?>
    <?php foreach ($model->renotes as $notes) { ?>
    <div class="row mt-2 ">
        <div class="col-12">
            <div class="card">
                <div class="card-header">
					<?= $notes->type; ?>
					<span class="float-right">
						<?= Html::A('EDIT', ['/notes/update', 'id' => $notes->id], ['class' => 'btn btn-primary', 'data-method' => 'POST'])?>
						<?= Html::Button('Delete', ['class' => 'btn bg-danger text-white', 'onClick' => "deleteNote('$notes->id')"])?>
                       
					</span>
                </div>
                <div class="card-body">
                    <div class="row">
                        <div class="col-sm-12">
							<p>
								<?= $notes->note ?>
							</p>
                        </div>
                    </div>
                </div>
                <div class="card-footer">
                    <div class="row ">
                        <div class="col-sm-3">
							<span class="font-weight-bold">Created By: </span>
							<?= $notes->createdby_name ?>
						</div>
                        <div class="col-sm-3 "><span class="font-weight-bold">Created At: </span><?= $notes->created_at ?></div>
                        <div class="col-sm-3 "><span class="font-weight-bold">Updated By: </span><?= $notes->updatedby_name ?></div>
                        <div class="col-sm-3 "><span class="font-weight-bold">Updated At: </span><?= $notes->updated_at ?></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <?php } ?>
	<?php } ?>
	<?php Pjax::end(); ?>
</div>

<script>
	function deleteNote(id)
	{
        $.ajax({
                type: "POST",
                url: "/notes/deletenote",
                data: {
                    id: id
                },
            })
		.done(function(result) {
			$('#message').html(result.message);
			$('#flashmessage').delay(500).fadeIn('normal', function() {
				$(this).delay(2500).fadeOut();
			});
			$.pjax.reload({
				container: '#Notes',
				async: false
			});
		});
    }
</script>