<!--
 SPDX-FileCopyrightText: 2023 jordi fita mas <jordi@tandem.blog>
 SPDX-License-Identifier: AGPL-3.0-only
-->
{{ define "title" -}}
    {{( pgettext "Campsites" "title" )}}
{{- end }}

{{ define "breadcrumb" -}}
{{- end }}

{{ define "content" -}}
    {{- /*gotype: dev.tandem.ws/tandem/camper/pkg/campsite.campsiteIndex*/ -}}
    {{ if isAdmin -}}
        <a href="/admin/campsites/new">{{( pgettext "Add Campsite" "action" )}}</a>
    {{- end }}

    <h2>{{( pgettext "Campsites" "title" )}}</h2>
    {{ if .Campsites -}}
        {{ template "grid.gohtml" . }}
        <form id="booking-filter">
            <fieldset>
                {{ with .From -}}
                    <fieldset>
                        <legend>{{( gettext "From Date" )}}</legend>
                        {{ template "month-input" . }}
                        {{ template "error-message" . }}
                    </fieldset>
                {{- end }}
                {{ with .To -}}
                    <fieldset>
                        <legend>{{( gettext "To Date" )}}</legend>
                        {{ template "month-input" . }}
                        {{ template "error-message" . }}
                    </fieldset>
                {{- end }}
            </fieldset>
            <footer>
                <button type="submit">{{( pgettext "Show" "action" )}}</button>
            </footer>
        </form>
    {{ else -}}
        <p>{{( gettext "No campsites added yet." )}}</p>
    {{- end }}

    <script>
        (function () {
            function follow(e) {
                e.preventDefault();
                location.assign(e.target.dataset.bookingUri);
            }

            document.querySelectorAll('[data-booking-uri]').forEach((e) => e.addEventListener('dblclick', follow));
        })();
    </script>
{{- end }}

{{ define "campsite-heading" -}}
    {{- if isAdmin -}}
        <a href="/admin/campsites/{{ .Label }}">{{ .Label }}</a>
    {{- else -}}
        {{ .Label }}
    {{- end -}}
{{- end }}
