{{!
    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_nested_v2_first_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"
    data-post-id="{{id}}"
    data-region="post"
    data-target="{{id}}-target"
    tabindex="0"
    aria-labelledby="post-header-{{id}}-{{uniqid}}"
    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 focus-target mb-4 {{#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="author-image-container d-inline-block text-center">
            {{^isdeleted}}
                {{#author}}
                    {{#urls.profileimage}}
                        <img
                            class="rounded-circle w-100"
                            src="{{{.}}}"
                            alt="{{#str}} pictureof, core, {{author.fullname}} {{/str}}"
                            aria-hidden="true"
                        >
                    {{/urls.profileimage}}
                {{/author}}
            {{/isdeleted}}

            {{#unread}}
                <div class="icon-size-4 text-info text-center mt-3 icon-no-margin">
                    <span
                        data-toggle="tooltip"
                        data-placement="left"
                        title="{{#str}} unreadpost, mod_forum {{/str}}"
                        tabindex="0"
                    >{{#pix}} i/flagged, core {{/pix}}</span>
                </div>
            {{/unread}}
        </div>

        <div class="forum-post-core d-flex flex-column w-100"  data-region-content="forum-post-core">
            <header id="post-header-{{id}}-{{uniqid}}">
                {{^isdeleted}}
                    <div class="d-flex flex-wrap align-items-center mb-1">
                        <div class="mr-2" tabindex="-1">
                            {{#author}}
                                <h4 class="h6 d-lg-inline-block mb-0 author-header mr-1">
                                    {{#parentauthorname}}
                                        {{#isprivatereply}}
                                            <span class="text-danger">
                                                {{#str}}
                                                    authorreplyingprivatelytoauthor, mod_forum, {
                                                        "respondant":"<a class='font-weight-bold author-name' data-region='author-name' href='{{{urls.profile}}}'>{{fullname}}</a>",
                                                        "author":"{{parentauthorname}}"
                                                    }
                                                {{/str}}
                                            </span>
                                        {{/isprivatereply}}
                                        {{^isprivatereply}}
                                            {{#str}}
                                                authorreplyingtoauthor, mod_forum, {
                                                    "respondant":"<a class='font-weight-bold author-name' data-region='author-name' href='{{{urls.profile}}}'>{{fullname}}</a>",
                                                    "author":"{{parentauthorname}}"
                                                }
                                            {{/str}}
                                        {{/isprivatereply}}
                                    {{/parentauthorname}}
                                    {{^parentauthorname}}
                                        <a class='font-weight-bold author-name' data-region='author-name' href="{{{urls.profile}}}">{{fullname}}</a>
                                    {{/parentauthorname}}
                                </h4>
                            {{/author}}
                            {{< core/time_element }}
                                {{$elementid}}created-{{id}}-{{uniqid}}{{/elementid}}
                                {{$elementclass}}text-muted{{/elementclass}}
                                {{$timestampval}}{{timecreated}}{{/timestampval}}
                                {{$userdateformatval}}{{#str}} strftimerecentfull, core_langconfig {{/str}}{{/userdateformatval}}
                            {{/core/time_element}}
                        </div>

                        <div class="d-flex align-items-center ml-auto">
                            {{#author.groups}}
                                {{#urls.image}}
                                    <div class="mr-2">
                                        {{#urls.group}}
                                            <a href="{{urls.group}}" aria-label='{{#str}} memberofgroup, group, {{name}}{{/str}}'>
                                                <img
                                                    class="rounded-circle group-image"
                                                    src="{{{urls.image}}}"
                                                    alt="{{#str}} pictureof, core, {{name}} {{/str}}"
                                                    aria-hidden="true"
                                                    title="{{#str}} pictureof, core, {{name}} {{/str}}"
                                                >
                                            </a>
                                        {{/urls.group}}
                                        {{^urls.group}}
                                            <img class="rounded-circle group-image"
                                                src="{{{urls.image}}}"
                                                alt="{{#str}} pictureof, core, {{name}} {{/str}}"
                                                title="{{#str}} pictureof, core, {{name}} {{/str}}"
                                            >
                                        {{/urls.group}}
                                    </div>
                                {{/urls.image}}
                            {{/author.groups}}

                            {{^readonly}}
                                {{#showactionmenu}}
                                    <div class="dropdown">
                                        <button
                                            class="btn btn-icon text-muted icon-no-margin icon-size-3"
                                            type="button"
                                            id="post-actions-menu-{{id}}-{{uniqid}}"
                                            data-toggle="dropdown"
                                            aria-haspopup="true"
                                            aria-expanded="false"
                                            aria-label="{{#str}} actionsforpost, mod_forum {{/str}}"
                                        >
                                            {{#pix}} i/moremenu {{/pix}}
                                        </button>
                                        <!-- inline style to fix RTL placement bug -->
                                        <div class="dropdown-menu dropdown-menu-right rounded-lg shadow border-0" aria-labelledby="post-actions-menu-{{id}}-{{uniqid}}" style="right: auto" role="menubar">
                                            {{#capabilities}}
                                                {{#view}}
                                                    <a
                                                        href="{{{urls.view}}}"
                                                        class="dropdown-item"
                                                        role="menuitem"
                                                    >
                                                        {{#str}} permalink, mod_forum {{/str}}
                                                    </a>
                                                {{/view}}
                                                {{#controlreadstatus}}
                                                    {{#unread}}
                                                        <a
                                                            href="{{{urls.markasread}}}"
                                                            class="dropdown-item"
                                                            role="menuitem"
                                                        >
                                                            {{#str}} markread, mod_forum {{/str}}
                                                        </a>
                                                    {{/unread}}
                                                    {{^unread}}
                                                        <a
                                                            href="{{{urls.markasunread}}}"
                                                            class="dropdown-item"
                                                            role="menuitem"
                                                        >
                                                            {{#str}} markunread, mod_forum {{/str}}
                                                        </a>
                                                    {{/unread}}
                                                {{/controlreadstatus}}
                                                {{#urls.viewparent}}
                                                    <a
                                                        href="{{{.}}}"
                                                        class="dropdown-item"
                                                        title="{{#str}} permanentlinktoparentpost, mod_forum {{/str}}"
                                                        role="menuitem"
                                                    >
                                                        {{#str}} parent, mod_forum {{/str}}
                                                    </a>
                                                {{/urls.viewparent}}
                                                {{#edit}}
                                                    <a
                                                        href="{{{urls.edit}}}"
                                                        class="dropdown-item"
                                                        role="menuitem"
                                                    >
                                                        {{#str}} edit, mod_forum {{/str}}
                                                    </a>
                                                {{/edit}}
                                                {{#split}}
                                                    <a
                                                        href="{{{urls.split}}}"
                                                        class="dropdown-item"
                                                        role="menuitem"
                                                    >
                                                        {{#str}} prune, mod_forum {{/str}}
                                                    </a>
                                                {{/split}}
                                                {{#delete}}
                                                    <a
                                                        href="{{{urls.delete}}}"
                                                        class="dropdown-item"
                                                        role="menuitem"
                                                    >
                                                        {{#str}} delete, mod_forum {{/str}}
                                                    </a>
                                                {{/delete}}
                                                {{#export}}
                                                    <a
                                                        href="{{{urls.export}}}"
                                                        class="dropdown-item"
                                                        role="menuitem"
                                                    >
                                                        {{#str}} addtoportfolio, core_portfolio {{/str}}
                                                    </a>
                                                {{/export}}
                                            {{/capabilities}}
                                        </div>
                                    </div>
                                {{/showactionmenu}}
                            {{/readonly}}
                            </div>
                    </div>
                {{/isdeleted}}
                {{$subject}}
                    <h2
                        class="h1 font-weight-bold post-subject mt-n2"
                        data-region-content="forum-post-core-subject"
                        data-reply-subject="{{replysubject}}"
                    >{{{subject}}}</h2>
                {{/subject}}
                {{#hasreplycount}}
                    <span class="sr-only">{{#str}} numberofreplies, mod_forum, {{replycount}} {{/str}}</span>
                {{/hasreplycount}}
            </header>

            <div class="post-message pr-md-5" id="post-content-{{id}}">
                {{{message}}}
            </div>

            {{^isdeleted}}
                {{#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}}

                {{#attachments}}
                    {{^isimage}}
                        <div class="mt-3">
                            <span class="icon-size-6">{{#pix}} {{icon}}, core {{/pix}}</span>
                            <div class="align-bottom d-inline-block">
                                <a
                                    href="{{{url}}}"
                                    aria-label="{{#str}} attachmentname, mod_forum, {{filename}} {{/str}}"
                                    class="font-weight-bold"
                                >
                                    {{#str}} attachmentnameandfilesize, mod_forum, {"name": "{{filename}}", "size": "{{filesizeformatted}}"} {{/str}}
                                </a>
                                {{#urls.export}}
                                    <a class="icon-no-margin" href="{{{.}}}" title="{{#str}} exportattachmentname, mod_forum, {{filename}} {{/str}}">
                                        {{#pix}} t/portfolioadd, core {{/pix}}
                                    </a>
                                {{/urls.export}}
                                {{#html.plagiarism}}
                                    <div>{{{.}}}</div>
                                {{/html.plagiarism}}
                            </div>
                        </div>
                    {{/isimage}}
                {{/attachments}}

                <div class="d-flex mt-3 align-items-center">
                    {{^readonly}}
                        {{#html.rating}}
                            <div>{{{.}}}</div>
                        {{/html.rating}}
                    {{/readonly}}
                    <div class="ml-auto d-flex flex-column">
                        {{#haswordcount}}
                            <span class="ml-auto badge bg-light text-dark">
                                {{#str}} numwords, core, {{wordcount}} {{/str}}
                            </span>
                        {{/haswordcount}}
                        {{#html.taglist}}
                            <div class="d-inline-block ml-auto {{#haswordcount}}mt-2{{/haswordcount}}">{{{.}}}</div>
                        {{/html.taglist}}
                    </div>
                </div>
            {{/isdeleted}}

            {{$footer}}
                {{^isdeleted}}
                    {{^readonly}}
                        <div class="d-flex mt-3">
                            {{#capabilities.reply}}
                                <button
                                    class="btn btn-primary btn-lg font-weight-bold px-4"
                                    data-href="{{{urls.reply}}}"
                                    data-post-id="{{id}}"
                                    data-action="create-inpage-reply"
                                    data-can-reply-privately="{{capabilities.canreplyprivately}}"
                                >
                                    {{#str}} reply, mod_forum {{/str}}
                                </button>
                            {{/capabilities.reply}}
                            {{^capabilities.reply}}
                                {{#discussionlocked}}
                                    <button class="btn btn-secondary btn-lg disabled" disabled>
                                        {{#str}} reply, mod_forum {{/str}}
                                    </button>
                                {{/discussionlocked}}
                            {{/capabilities.reply}}
                        </div>
                    {{/readonly}}
                {{/isdeleted}}
                {{#discussionlocked}}
                    <div><span class="badge bg-danger text-white mt-2">{{#str}} locked, mod_forum {{/str}}</span></div>
                {{/discussionlocked}}
            {{/footer}}
        </div>
    </div>

    {{$replies}}
        <div class="indent inline-reply-container" data-region="inpage-reply-container"></div>

        <div class="indent replies-container" data-region="replies-container">
            {{#hasreplies}}
                {{#replies}}
                    {{> mod_forum/forum_discussion_nested_v2_post_reply }}
                {{/replies}}
            {{/hasreplies}}
        </div>
    {{/replies}}
</article>
