<h1 class="title"><?= $post->getTitle() ?></h1>

<ul class="breadcrumber">
    <li><a href="<?= url_to('/') ?>" data-ajax><?= __('Home') ?></a></li>
    <li><a href="<?= url_to('/posts') ?>" data-ajax><?= __('Posts') ?></a></li>
    <li class="active"><?= $post->getTitle() ?></li>
</ul>

<div class="single-post">
    <?php if ($post->hasImageCover()): ?>
        <div class="image-cover">
            <img src="<?= upload_to('/news/' . $post->getImageCover()) ?>" />
        </div>
    <?php endif ?>

    <?= $post->getBody() ?>

    <div class="clear"></div>
</div>

<?php if (config('posts.allow_comments', false) && $post->isAllowedComments()): ?>
    <h2 class="title"><?= __('Comments') ?></h2>
    <?php if (!$post->hasComments()): ?>
        <div class="msg"><?= __('No comments found') ?></div>
    <?php else: ?>
        <ul class="comments">
            <?php foreach ($post->getComments() as $comment) : ?>
                <li>
                    <div class="desc">
                        <span class="name">
                            <?= $comment->getAuthor()->getName() ?>
                        </span>
                        <span class="created"><?= util('Time')->relative($comment->getCreated()) ?></span>
                        <p class="body"><?= nl2br($comment->getComment()) ?></p>
                    </div>
                </li>
            <?php endforeach ?>
        </ul>
    <?php endif ?>


    <div class="box-panel margin-top">
        <div class="box-panel-title"><?= __('Add comment') ?></div>
        <form data-ajax action="<?= url_to('/posts/comments/add/' . $post->getId()) ?>" class="form" method="post">
            <?= csrf_field() ?>

            <div class="box-panel-content">
                <div class="row">
                    <div class="field block">
                        <textarea id="comment" name="comment"></textarea>
                    </div>
                </div>
            </div>

            <div class="submit">
                <input type="submit" value="<?= __('Send comment') ?>" class="btn" />
            </div>
        </form>
    </div>
<?php endif ?>
