{{ header }}
{% if journal3.get('pageTitlePosition') == 'top' %}
  <h1 class="title page-title {{ journal3.get('title_color_scheme') }}"><span class="page-title-text">{{ post_name }}</span></h1>
{% endif %}
<div class="breadcrumbs {{ journal3.get('breadcrumbs_color_scheme') }}">
  <ul class="breadcrumb">
    {% for breadcrumb in breadcrumbs %}
      <li><a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a></li>
    {% endfor %}
  </ul>
</div>
{{ journal3_top }}
<div class="container blog-post">
  <div class="row">{{ column_left }}
    <div id="content">
      {% if journal3.get('pageTitlePosition') == 'default' %}
        <h1 class="title page-title {{ journal3.get('title_color_scheme') }}">{{ post_name }}</h1>
      {% endif %}
      {{ content_top }}
      <div class="post-details">
        <div class="post-image">
          {% if journal3.get('datePosition') == 'image' %}
            <span class="p-date p-date-image">{{ journal3.blog_date(post_date) }}</span>
          {% endif %}
          <img src="{{ post_image }}" {% if post_image2x %} srcset="{{ post_image }} 1x, {{ post_image2x }} 2x" {% endif %} width="{{ image_width }}" height="{{ image_height }}" alt="{{ post_name | escape }}" title="{{ post_name | escape }}"/>
        </div>
        <div class="post-stats-wrapper">
          <div class="post-stats">
            {% if post_author %}
              <span class="p-posted">{{ journal3.get('blogPostedByText') }}</span>
              <span class="p-author">{{ post_author }}</span>
            {% endif %}
            {% if journal3.get('datePosition') == 'default' %}
              <span class="p-date p-date-default">{{ journal3.blog_date(post_date) }}</span>
            {% endif %}
            <span class="p-comment">{{ comments|length }} {{ journal3.get('blogCommentsText') }}</span>
            <span class="p-view">{{ post_views }} {{ journal3.get('blogViewsText') }}</span>
            {% if post_categories %}
              <span class="p-category">
          {% for category in post_categories %}
            <a href="{{ category.href }}">{{ category.name }}</a>
            {% if not loop.last %}
            <span>, </span>
          {% endif %}
          {% endfor %}
          </span>
            {% endif %}
          </div>
        </div>
        <div class="post-content">
          {{ post_content }}
        </div>
        {% if post_gallery %}
          <div class="post-gallery">
            {{ post_gallery }}
          </div>
        {% endif %}
        {% if post_tags %}
          <div class="tags">
            <span class="tags-title">{{ text_tags }}</span>
            {% for tag in post_tags %}
              <a href="{{ tag.href }}">{{ tag.name }}</a><b>,</b>
            {% endfor %}
          </div>
        {% endif %}
      </div>

      {{ content_bottom }}

      {% if allow_comments %}
        <div class="post-comments">
          {% if comments_total > 0 %}
            <h3 class="title">{{ comments_total }} {{ journal3.get('blogCommentsText') }}</h3>
          {% endif %}
          {% for comment in comments %}
            <div class="post-comment" data-comment-id="{{ comment.comment_id }}" data-has-form="false">
              <img class="user-avatar" src="https://s.gravatar.com/avatar/{{ comment.avatar }}?s={{ journal3.get('postCommentImageSize') }}" width="{{ journal3.get('postCommentImageSize') }}" height="{{ journal3.get('postCommentImageSize') }}" alt="">
              <div class="comment">
                <div class="user-name">{{ comment.name }}:</div>
                <div class="user-data">
                  <div>
                    <span class="user-date p-date">{{ journal3.blog_date(comment.date) }}</span>
                    <span class="user-time p-time">{{ comment.date | date(time_format) }}</span>
                  </div>
                  {% if comment.website %}
                    <span class="user-site p-site"><a href="{{ comment.website }}" target="_blank">{{ comment.website }}</a></span>
                  {% endif %}
                </div>
                <a class="btn reply-btn">{{ journal3.get('blogReplyText') }}</a>
                <p>{{ comment.comment }}</p>
                {% for reply in comment.replies %}
                  <div class="post-reply">
                    <img class="user-avatar" src="https://s.gravatar.com/avatar/{{ comment.avatar }}?s={{ journal3.get('postCommentImageSize') }}" width="{{ journal3.get('postCommentImageSize') }}" height="{{ journal3.get('postCommentImageSize') }}" alt="">
                    <div class="comment">
                      <div class="user-name">{{ reply.name }}:</div>
                      <div class="user-data">
                        <div>
                          <span class="user-date p-date">{{ journal3.blog_date(reply.date) }}</span>
                          <span class="user-time p-time">{{ reply.date | date(time_format) }}</span>
                        </div>
                        {% if reply.website %}
                          <span class="user-site p-site"><a href="{{ reply.website }}" target="_blank">{{ reply.website }}</a></span>
                        {% endif %}
                      </div>
                      <p>{{ reply.comment }}</p>
                    </div>
                  </div>
                {% endfor %}
              </div>
            </div>
          {% endfor %}
          <div class="comment-form">
            <h3 class="title">{{ journal3.get('blogLeaveCommentText') }}</h3>
            <form method="post" enctype="multipart/form-data" class="form-horizontal">
              <fieldset>
                <div class="form-group required">
                  <label class="col-sm-2 control-label" for="input-name">{{ entry_name }}</label>
                  <div class="col-sm-10">
                    <input type="text" name="name" value="{{ default_name }}" id="input-name" class="form-control"/>
                  </div>
                </div>

                <div class="form-group required">
                  <label class="col-sm-2 control-label" for="input-email">{{ entry_email }}</label>
                  <div class="col-sm-10">
                    <input type="text" name="email" value="{{ default_email }}" id="input-email" class="form-control"/>

                  </div>
                </div>

                <div class="form-group">
                  <label class="col-sm-2 control-label" for="input-website">{{ entry_website }}</label>
                  <div class="col-sm-10">
                    <input type="text" name="website" value="{{ default_website }}" id="input-website" class="form-control"/>
                  </div>
                </div>

                <div class="form-group required">
                  <label class="col-sm-2 control-label" for="input-comment">{{ text_comment }}</label>
                  <div class="col-sm-10">
                    <textarea name="comment" rows="10" id="input-comment" class="form-control">{{ default_comment }}</textarea>
                  </div>
                </div>
              </fieldset>

              {% if captcha %}
              <div class="input-captcha">{{ captcha }}</div>
              {% endif %}

              <div class="buttons">
                <div class="pull-right">
                  <button type="button" class="btn comment-submit">{{ button_submit }}</button>
                </div>
              </div>
            </form>
          </div>
        </div>
        {% if comments_total > 0 %}
        <div class="row pagination-results">
          <div class="col-sm-6 text-left">{{ pagination }}</div>
          <div class="col-sm-6 text-right">{{ results }}</div>
        </div>
        {% endif %}
      {% endif %}

    </div>
    {{ column_right }}
  </div>
  {% if allow_comments %}
    <script type="text/javascript">
      function generateComment($form, cls, $appendTo, callback) {
        $form.find('.has-error').removeClass('has-error');

        $.post('index.php?route=journal3/blog{{ constant('JOURNAL3_ROUTE_SEPARATOR') }}comment&post_id={{ post_id }}', $form.serializeArray(), function (response) {
          if (response.status === 'success') {
            if (response.response.data) {
              var html = '';

              html += '<div class="' + cls + '" data-comment-id="' + response.response.data.comment_id + '" data-has-form="false">';
              html += ' <img class="user-avatar" src="https://s.gravatar.com/avatar/' + response.response.data.avatar + '?s={{ journal3.get('postCommentImageSize') }}" width="{{ journal3.get('postCommentImageSize') }}" height="{{ journal3.get('postCommentImageSize') }}" alt="">';
              html += ' <div class="comment">';
              html += '   <div class="user-name">' + response.response.data.name + ':</div>';
              html += '   <div class="user-data">';
              html += '     <div>';
              html += '       <span class="user-date p-date">' + response.response.data.date + '</span>';
              html += '       <span class="user-time p-time">' + response.response.data.time + '</span>';
              html += '     </div>';
              html += '     <span class="user-site p-site"><a href="' + response.response.data.website + '" target="_blank">' + response.response.data.website + '</a></span>';
              html += '   </div>';

              if (cls === 'post-comment') {
                html += ' <a class="btn reply-btn">{{ journal3.get('blogReplyText') }}</a>';
              }

              html += ' <p>' + response.response.data.comment + '</p>';
              html += '</div>';

              $appendTo.before(html);
            }

            callback && callback(response.response.message);
          }

          if (response.status === 'error') {
            $.each(response.response.errors, function (field) {
              if (field === 'captcha') {
                $form.find('.input-captcha .form-group').addClass('has-error');
              } else {
                $form.find('[name="' + field + '"]').closest('.form-group').addClass('has-error');
              }
            });
          }
        }, 'json');
      }

      $(document).delegate('.reply-btn', 'click', function () {
        var $comment = $(this).closest('.post-comment');

        if ($comment.attr('data-has-form') === 'false') {
          var $form = $('.post-comments form').clone(true, true);
          $form.find('script').remove();
          $form.find('.g-recaptcha').html('');
          $form.find('.has-error').removeClass('has-error');
          $form.append('<input type="hidden" name="parent_id" value="' + $comment.attr('data-comment-id') + '" />');
          $form.find('button').removeClass('comment-submit').addClass('reply-submit');
          $comment.find('> .comment').append('<div class="reply-form"><h3 class="title">' + '{{ journal3.get('blogLeaveReplyText') }}' + '</h3><div class="comment-form"><div><form class="form-horizontal">' + $form.html() + '</form></div></div></div>');
          $comment.attr('data-has-form', 'true');
          var gc = $comment.find('.reply-form .g-recaptcha');
          if (gc.length && window.grecaptcha) {
            window.grecaptcha.render(gc[0]);
          }
        } else {
          $comment.find('.reply-form').remove();
          $comment.attr('data-has-form', 'false');
        }
      });

      $(document).delegate('form .comment-submit', 'click', function () {
        var $form = $(this).closest('form');
        var $comment_form = $('.comment-form');

        generateComment($form, 'post-comment', $comment_form, function (message) {
          show_message({
            message: message,
          });
          $form[0].reset();
        });
      });

      $(document).delegate('form .reply-submit', 'click', function () {
        var $form = $(this).closest('form');
        var $reply_form = $(this).closest('.post-comment').find('.reply-form');

        generateComment($form, 'post-reply', $reply_form, function (message) {
          show_message({
            message: message,
          });
          $form.closest('.post-comment').attr('data-has-form', 'false');
          $reply_form.remove();
        });
      });
    </script>
  {% endif %}
</div>
{{ journal3_rich_snippets }}
{{ footer }}
