{{ define "title" }}{{ .Data.event.Title }}{{ end }}
{{ define "content" }}

{{ $authedContact := .Data.authedContact }}
{{ $authedRSVP := .Data.authedRSVP }}

{{ with .Data.event }}
    {{ if and $authedContact $authedRSVP.ID }}
        <div class="row mb-4">
            <div class="col-8">
                <p>
                    <strong>{{ $authedContact.Name }}</strong>, you have been invited to...
                </p>
            </div>
            <div class="col-4 text-right">
                <form name="rsvpAnswerForm" action="/e/{{ .Fragment }}" method="POST">
                <input type="hidden" name="_csrf" value="{{ $.CSRF }}">
                <input type="hidden" name="action" value="answer-rsvp">
                <div class="btn-group">
                    <button type="submit" name="submit" value="going" class="btn{{ if eq $authedRSVP.Status "going" }} btn-success{{ end }}">Going</button>
                    <button type="submit" name="submit" value="maybe" class="btn{{ if eq $authedRSVP.Status "maybe" }} btn-warning{{ end }}">Maybe</button>
                    <button type="submit" name="submit" value="not going" class="btn{{ if eq $authedRSVP.Status "not going" }} btn-danger{{ end }}">Not Going</button>
                </div>
                <p class="small">
                    [<a href="/c/logout?next={{ $.Request.URL.Path }}">not {{ $authedContact.Name }}?</a>]
                </p>
            </div>
        </div>
    {{ end }}
    <h1>{{ .Title }}</h1>

    <div class="row mb-4">
        <div class="col-12 col-md-8">
            {{ TrustedMarkdown .Description }}
        </div>
        <div class="col-12 col-md-4">
            {{ if .Location }}
                <h4>Location</h4>
                <address class="mb-4"><a href="https://maps.google.com/?q={{ NewlinesToSpace .Location }}" target="_blank">{{ .Location }}</a></address>
            {{ end }}

            <h4>Time</h4>
            <abbr title="{{ .StartTime.Format "Mon Jan 2 15:04:05 2006" }}">
                {{ .StartTime.Format "January 2 @ 3:04 PM" }}
            </abbr>
            {{ if not .EndTime.IsZero }}
                to<br>
                <abbr title="{{ .EndTime.Format "Mon Jan 2 15:04:05 2006" }}">
                    {{ if .AllDay }}
                        {{ .EndTime.Format "January 2" }}
                    {{ else }}
                        {{ .EndTime.Format "January 2 @ 3:04 PM" }}
                    {{ end }}
                </abbr>
            {{ end }}

            <h4 class="mt-4">Invited</h4>

            <div style="max-height: 500px; overflow: auto">
                <ul class="list-group">
                    {{ range .RSVP }}
                    <li class="list-group-item
                        {{ if eq .Status "invited" }}bg-light
                        {{ else if eq .Status "going"}}border-success
                        {{ else if eq .Status "not going"}}border-danger
                        {{ else if eq .Status "maybe"}}border-warning{{ end }}">
                        {{ if .Contact }}
                            <strong>{{ .Contact.Name }}</strong>
                        {{ else }}
                            <strong>{{ .Name }}</strong>
                        {{ end }}
                        <br>
                        {{ .Status }}

                        {{ if and $.LoggedIn $.CurrentUser.Admin }}
                            {{ if not .Notified }}
                                <span class="badge badge-warning">not notified</span>
                            {{ end }}
                            <ul class="list-inline small">
                                {{ if .Contact }}
                                    {{ if .Contact.Email }}
                                    <li class="list-inline-item text-muted">
                                        <a href="mailto:{{ .Contact.Email }}">{{ .Contact.Email }}</a>
                                    </li>
                                    {{ end }}
                                    {{ if .Contact.SMS }}
                                    <li class="list-inline-item text-muted">
                                        <a href="tel:{{ .Contact.SMS }}">{{ .Contact.SMS }}</a>
                                    </li>
                                    {{ end }}
                                {{ else }}
                                    {{ if .Email }}
                                    <li class="list-inline-item text-muted">
                                        <a href="mailto:{{ .Email }}">{{ .Email }}</a>
                                    </li>
                                    {{ end }}
                                    {{ if .SMS }}
                                    <li class="list-inline-item text-muted">
                                        <a href="tel:{{ .SMS }}">{{ .SMS }}</a>
                                    </li>
                                    {{ end }}
                                {{ end }}
                            </ul>
                        {{ end }}
                    </li>
                    {{ end }}
                </ul>
            </div>
        </div>
    </div>
{{ end }}

{{ if and .LoggedIn .CurrentUser.Admin }}
    <div class="alert alert-danger">
        <a href="/e/admin/edit?id={{ .Data.event.ID }}"
            class="btn btn-primary">edit event</a>
        <a href="/e/admin/invite/{{ .Data.event.ID }}"
            class="btn btn-success">invite people</a>
    </div>
{{ end }}

<h2 id="comments" class="mt-4">Comments</h2>

{{ $idStr := printf "%d" .Data.event.ID }}
{{ RenderComments .Request .Data.event.Title "event" $idStr }}

{{ end }}
