{{!
    This file is part of Moodle - http://moodle.org/

    Moodle is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Moodle is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
}}
{{!
    @template mod_forum/forum_discussion_post

    Template to render a single post from a discussion.

    Classes required for JS:
    * none

    Data attributes required for JS:
    * none

    Example context (json):
    {
    }
}}

<article id="p{{id}}" class="forum-post-container mb-2" data-post-id="{{id}}" data-region="post" data-target="{{id}}-target" tabindex="0" aria-labelledby="post-header-{{id}}" aria-describedby="post-content-{{id}}">
  <!-- The firstpost and starter classes below aren't used for anything other than to identify the first post in behat -->
  <div class="d-flex border p-2 mb-2 forumpost focus-target {{#unread}}unread{{/unread}} {{#firstpost}}firstpost starter{{/firstpost}}" aria-label='{{#str}} postbyuser, mod_forum, {"post": "{{subject}}", "user": "{{author.fullname}}"} {{/str}}'
    data-post-id="{{id}}" data-content="forum-post">
    {{#isfirstunread}}<a id="unread" aria-hidden="true"></a>{{/isfirstunread}}

    <div class="d-flex flex-column w-100 ccn-form-post-core" data-region-content="forum-post-core">
      <header class="mb-2 row d-flex">
        {{^isdeleted}}
          {{#author}}
            <div class="mr-3" style="width: 45px;">
              {{#urls.profileimage}}
                <img class="rounded-circle w-100" src="{{{.}}}" alt="{{#str}} pictureof, core, {{author.fullname}} {{/str}}" aria-hidden="true" title="{{#str}} pictureof, core, {{author.fullname}} {{/str}}">
              {{/urls.profileimage}}
            </div>
          {{/author}}
        {{/isdeleted}}
        <div class="d-flex flex-column">
          {{#parentauthorname}}
            <span class="sr-only">{{#str}} inreplyto, mod_forum, {{.}} {{/str}}</span>
          {{/parentauthorname}}
          <h4 {{!
                        }}class="mb-0" {{!
                        }}data-region-content="forum-post-core-subject" {{!
                        }}data-reply-subject="{{replysubject}}" {{!
                        }}>{{$subject}}{{{subject}}}{{/subject}}</h4>
          {{^isdeleted}}
            <small tabindex="-1">
              {{#html.authorsubheading}}{{{.}}}{{/html.authorsubheading}}
              {{^html.authorsubheading}}
                <time>
                  {{#userdate}} {{timecreated}}, {{#str}} strftimedaydatetime, core_langconfig {{/str}} {{/userdate}}
                </time>
              {{/html.authorsubheading}}
            </small>
          {{/isdeleted}}
          {{#isprivatereply}}
            <div class="privatereplyinfo">
              {{#str}}postisprivatereply, forum{{/str}}
            </div>
          {{/isprivatereply}}
          {{#hasreplycount}}
            <span class="sr-only">{{#str}} numberofreplies, mod_forum, {{replycount}} {{/str}}</span>
          {{/hasreplycount}}
        </div>
      </header>

      <div class="d-flex body-content-container">
        {{^isdeleted}}
          {{#author}}
            {{#groups}}
              <div class="mr-2 author-groups-container" style="width: 45px; flex-shrink: 0">
                {{#urls.group}}
                  {{#urls.image}}
                    <a href="{{urls.group}}" role="button" aria-label='{{#str}} memberofgroup, group, {{name}}{{/str}}'>
                      <img class="rounded-circle w-100" src="{{{.}}}" alt="{{#str}} pictureof, core, {{name}} {{/str}}" aria-hidden="true" title="{{#str}} pictureof, core, {{name}} {{/str}}">
                    </a>
                  {{/urls.image}}
                {{/urls.group}}
                {{^urls.group}}
                  {{#urls.image}}
                    <img class="rounded-circle w-100" src="{{{.}}}" alt="{{#str}} pictureof, core, {{name}} {{/str}}" title="{{#str}} pictureof, core, {{name}} {{/str}}">
                  {{/urls.image}}
                {{/urls.group}}
              </div>
            {{/groups}}
          {{/author}}
        {{/isdeleted}}

        <div class="no-overflow w-100 content-alignment-container">
          <div id="post-content-{{id}}" class="post-content-container">
            {{{message}}}
          </div>

          {{^isdeleted}}
            {{#haswordcount}}
              <p class="font-italic mb-0"><small>{{#str}} numwords, core, {{wordcount}} {{/str}}</small></p>
            {{/haswordcount}}

            {{#attachments}}
              {{#isimage}}
                <div class="attachedimages">
                  <img src="{{{url}}}" alt="{{#str}} attachmentname, mod_forum, {{filename}} {{/str}}" style="max-width: 100%">
                  {{#urls.export}}
                    <a href="{{{.}}}" title="{{#str}} addtoportfolio, core_portfolio {{/str}}">
                      {{#pix}} t/portfolioadd, core {{/pix}}
                    </a>
                  {{/urls.export}}
                  {{#html.plagiarism}}
                    <div>{{{.}}}</div>
                  {{/html.plagiarism}}
                </div>
              {{/isimage}}
            {{/attachments}}

            {{{html.taglist}}}

            {{#attachments}}
              {{^isimage}}
                <div>
                  <a href="{{{url}}}" aria-label="{{#str}} attachmentname, mod_forum, {{filename}} {{/str}}">
                    {{#pix}} {{icon}}, core {{/pix}} {{filename}}
                  </a>
                  {{#urls.export}}
                    <a href="{{{.}}}" title="{{#str}} exportattachmentname, mod_forum, {{filename}} {{/str}}">
                      {{#pix}} t/portfolioadd, core {{/pix}}
                    </a>
                  {{/urls.export}}
                  {{#html.plagiarism}}
                    <div>{{{.}}}</div>
                  {{/html.plagiarism}}
                </div>
              {{/isimage}}
            {{/attachments}}

            <div class="ccn-forum-post-actions">
              <div class="ccn-forum-post-actions-footer">
                {{$footer}}{{/footer}}
              </div>
              <div class="d-flex flex-wrap ccn-forum-post-actions-buttons">
                {{#html.rating}}
                  <div class="mt-2">{{{.}}}</div>
                {{/html.rating}}
                {{$actions}}
                {{^readonly}}
                  <div class="post-actions d-flex align-self-end justify-content-end flex-wrap ml-auto" data-region="post-actions-container" role="menubar"
                    aria-label='{{#str}} postbyuser, mod_forum, {"post": "{{subject}}", "user": "{{author.fullname}}"} {{/str}}' aria-controls="p{{id}}">
                    {{#capabilities}}
                      {{#view}}
                        <a data-region="post-action" href="{{{urls.view}}}" class="btn btn-link" title="{{#str}} permanentlinktopost, mod_forum {{/str}}" aria-label="{{#str}} permanentlinktopost, mod_forum {{/str}}">
                          {{#str}} permalink, mod_forum {{/str}}
                        </a>
                      {{/view}}
                      {{#controlreadstatus}}
                        {{#unread}}
                          <a data-region="post-action" href="{{{urls.markasread}}}" class="btn btn-link">
                            {{#str}} markread, mod_forum {{/str}}
                          </a>
                        {{/unread}}
                        {{^unread}}
                          <a data-region="post-action" href="{{{urls.markasunread}}}" class="btn btn-link">
                            {{#str}} markunread, mod_forum {{/str}}
                          </a>
                        {{/unread}}
                      {{/controlreadstatus}}
                      {{#urls.viewparent}}
                        <a data-region="post-action" href="{{{.}}}" class="btn btn-link" title="{{#str}} permanentlinktoparentpost, mod_forum {{/str}}" aria-label="{{#str}} permanentlinktoparentpost, mod_forum {{/str}}">
                          {{#str}} parent, mod_forum {{/str}}
                        </a>
                      {{/urls.viewparent}}
                      {{#edit}}
                        <a data-region="post-action" href="{{{urls.edit}}}" class="btn btn-link">
                          {{#str}} edit, mod_forum {{/str}}
                        </a>
                      {{/edit}}
                      {{#split}}
                        <a data-region="post-action" href="{{{urls.split}}}" class="btn btn-link">
                          {{#str}} prune, mod_forum {{/str}}
                        </a>
                      {{/split}}
                      {{#delete}}
                        <a data-region="post-action" href="{{{urls.delete}}}" class="btn btn-link">
                          {{#str}} delete, mod_forum {{/str}}
                        </a>
                      {{/delete}}
                      {{#reply}}
                        {{$replyoutput}}
                        <a data-region="post-action" href="{{{urls.reply}}}" class="btn btn-link" data-post-id="{{id}}" data-action="collapsible-link" data-can-reply-privately="{{canreplyprivately}}" title="{{#str}} reply, mod_forum {{/str}}">
                          {{#str}} reply, mod_forum {{/str}}
                        </a>
                        {{/replyoutput}}
                      {{/reply}}
                      {{^reply}}
                        {{#selfenrol}}
                          {{$replyoutput}}
                          <a href="{{{urls.reply}}}" class="btn btn-link" data-post-id="{{id}}" data-can-reply-privately="{{canreplyprivately}}" title="{{#str}} reply, mod_forum {{/str}}">
                            {{#str}} reply, mod_forum {{/str}}
                          </a>
                          {{/replyoutput}}
                        {{/selfenrol}}
                      {{/reply}}
                      {{#export}}
                        <a data-region="post-action" href="{{{urls.export}}}" class="btn btn-link">
                          {{#str}} addtoportfolio, core_portfolio {{/str}}
                        </a>
                      {{/export}}
                    {{/capabilities}}
                  </div>
                {{/readonly}}
                {{/actions}}
              </div>

          {{/isdeleted}}
        </div>
      </div>
    </div>
  </div>
  </div>

  <div data-region="replies-container">
    {{$replies}}
    <div>
      {{#hasreplies}}
        {{#replies}}
          {{> mod_forum/forum_discussion_post }}
        {{/replies}}
      {{/hasreplies}}
    </div>
    {{/replies}}
  </div>
</article>
