{{define "title"}}Admin - Feedback & User Reports{{end}}
{{define "content"}}
{{$Root := .}}
<div class="container">
    <section class="hero is-danger is-bold">
        <div class="hero-body">
            <div class="container">
                <h1 class="title">
                    Feedback &amp; User Reports
                </h1>
            </div>
        </div>
    </section>

    <div class="block p-4">
        <div class="columns">
            <div class="column">
                There {{Pluralize64 .Pager.Total "is" "are"}} <strong>{{.Pager.Total}}</strong>
                {{if .Acknowledged}}acknowledged{{else}}unread{{end}}
                {{if eq .Intent "report"}}report{{else}}feedback message{{end}}{{Pluralize64 .Pager.Total}}.
            </div>
            <div class="column is-narrow">
                <div class="tabs is-toggle">
                    <ul>
                        <li{{if eq .Intent ""}} class="is-active"{{end}}>
                            <a href="{{.Request.URL.Path}}?acknowledged={{.Acknowledged}}">All</a>
                        </li>
                        <li{{if eq .Intent "contact"}} class="is-active"{{end}}>
                            <a href="{{.Request.URL.Path}}?acknowledged={{.Acknowledged}}&intent=contact">Contact</a>
                        </li>
                        <li{{if eq .Intent "report"}} class="is-active"{{end}}>
                            <a href="{{.Request.URL.Path}}?acknowledged={{.Acknowledged}}&intent=report">Reports</a>
                        </li>
                    </ul>
                </div>
            </div>
            <div class="column is-narrow">
                <div class="tabs is-toggle">
                    <ul>
                        <li{{if not .Acknowledged}} class="is-active"{{end}}>
                            <a href="{{.Request.URL.Path}}?intent={{.Intent}}">Unread</a>
                        </li>
                        <li{{if .Acknowledged}} class="is-active"{{end}}>
                            <a href="{{.Request.URL.Path}}?acknowledged=true&intent={{.Intent}}">Acknowledged</a>
                        </li>
                    </ul>
                </div>
            </div>
        </div>

        {{if .Pager}}
        <nav class="pagination" role="navigation" aria-label="pagination">
            <a class="pagination-previous{{if not .Pager.HasPrevious}} is-disabled{{end}}" title="Previous"
                href="{{.Request.URL.Path}}?{{QueryPlus "page" .Pager.Previous}}">Previous</a>
            <a class="pagination-next{{if not .Pager.HasNext}} is-disabled{{end}}" title="Next"
                href="{{.Request.URL.Path}}?{{QueryPlus "page" .Pager.Next}}">Next page</a>
            <ul class="pagination-list">
                {{range .Pager.Iter}}
                <li>
                    <a class="pagination-link{{if .IsCurrent}} is-current{{end}}"
                        aria-label="Page {{.Page}}"
                        href="{{$Root.Request.URL.Path}}?{{QueryPlus "page" .Page}}">
                        {{.Page}}
                    </a>
                </li>
                {{end}}
            </ul>
        </nav>
        {{end}}

        <div class="columns is-multiline">
        {{range .Feedback}}
            <div class="column is-one-third">
                {{$User := $Root.UserMap.Get .UserID}}
                <form action="{{$Root.Request.URL.Path}}" method="POST">
                    {{InputCSRF}}
                    <input type="hidden" name="id" value="{{.ID}}">

                    <div class="card" style="max-width: 512px">
                        <header class="card-header {{if eq .Intent "report"}}has-background-danger{{else}}has-background-link{{end}}">
                            <p class="card-header-title has-text-light">
                                {{if eq .Intent "report"}}
                                    <span class="icon"><i class="fa fa-flag"></i></span>
                                    <span>Report: {{.Subject}}</span>
                                {{else}}
                                    <span class="icon"><i class="fa fa-message"></i></span>
                                    <span>Contact: {{.Subject}}</span>
                                {{end}}
                            </p>
                        </header>
                        <div class="card-content">

                            <table class="table is-fullwidth">
                                <tr>
                                    <td class="has-text-right is-narrow">
                                        <strong>Intent:</strong>
                                    </td>
                                    <td>{{.Intent}}</td>
                                </tr>
                                <tr>
                                    <td class="has-text-right">
                                        <strong>Subject:</strong>
                                    </td>
                                    <td>{{.Subject}}</td>
                                </tr>
                                <tr>
                                    <td class="has-text-right">
                                        <strong>Table:</strong>
                                    </td>
                                    <td>
                                        {{if eq .TableName ""}}
                                            n/a
                                            {{if ne .TableID 0}} - {{.TableID}}{{end}}
                                        {{else if eq .TableName "users"}}
                                            Users: {{.TableID}}
                                            <a href="{{$Root.Request.URL.Path}}?id={{.ID}}&visit=true"
                                                class="fa fa-external-link ml-2"
                                                target="_blank"
                                                title="Visit the reported user's profile"></a>
                                        {{else if eq .TableName "photos"}}
                                            Photos: {{.TableID}}
                                            <a href="{{$Root.Request.URL.Path}}?id={{.ID}}&visit=true"
                                                class="fa fa-external-link mx-2"
                                                target="_blank"
                                                title="Visit the reported photo"></a>
                                            <a href="{{$Root.Request.URL.Path}}?id={{.ID}}&visit=true&profile=true"
                                                class="fa fa-user"
                                                target="_blank"
                                                title="Visit the user profile who owns the reported photo"></a>
                                        {{else if eq .TableName "messages"}}
                                            Messages: {{.TableID}}
                                            <a href="{{$Root.Request.URL.Path}}?id={{.ID}}&visit=true"
                                                class="fa fa-ghost ml-2"
                                                target="_blank"
                                                title="Impersonate the reporter and view this message thread"></a>
                                        {{else}}
                                            {{.TableName}}: {{.TableID}}
                                            <a href="{{$Root.Request.URL.Path}}?id={{.ID}}&visit=true" class="fa fa-external-link ml-2" target="_blank"></a>
                                        {{end}}
                                    </td>
                                </tr>
                                <tr>
                                    <td class="has-text-right">
                                        <strong>Reply&nbsp;To:</strong>
                                    </td>
                                    <td>
                                        {{if $User}}
                                            <a href="/u/{{$User.Username}}">{{$User.Username}}</a>
                                        {{else if ne .ReplyTo ""}}
                                            <a href="mailto:{{.ReplyTo}}">{{.ReplyTo}}</a>
                                        {{else}}
                                            n/a
                                        {{end}}
                                    </td>
                                </tr>
                            </table>

                            <div class="content">
                            {{if eq .Message ""}}
                                <p><em>No message attached.</em></p>
                            {{else}}
                                {{ToMarkdown .Message}}
                            {{end}}
                            </div>

                        </div>
                        <footer class="card-footer">
                            {{if not .Acknowledged}}
                            <button type="submit" name="verdict" value="acknowledge" class="card-footer-item button is-success">
                                <span class="icon"><i class="fa fa-check"></i></span>
                                <span>Acknowledge</span>
                            </button>
                            {{end}}

                            {{if .Acknowledged}}
                            <button type="submit" name="verdict" value="unacknowledge" class="card-footer-item button is-warning">
                                <span class="icon"><i class="fa fa-xmark"></i></span>
                                <span>Mark Unread</span>
                            </button>
                            {{end}}
                        </footer>
                    </div>
                </form>
            </div>
        {{end}}
        </div>
    </div>

</div>
{{end}}