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

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

{{ define "content" -}}
    {{- /*gotype: dev.tandem.ws/tandem/camper/pkg/amenity.amenityIndex*/ -}}
    <a href="/admin/amenities/new">{{( pgettext "Add Amenity" "action" )}}</a>
    <h2>{{ template "title" . }}</h2>
    {{ if .Amenities -}}
        <table>
            <thead>
            <tr>
                <th scope="col">{{( pgettext "Label" "header" )}}</th>
                <th scope="col">{{( pgettext "Name" "header" )}}</th>
                <th scope="col">{{( pgettext "Features" "header" )}}</th>
                <th scope="col">{{( pgettext "Carousel" "header" )}}</th>
                <th scope="col">{{( pgettext "Active" "amenity" )}}</th>
                <th scope="col">{{( pgettext "Actions" "header" )}}</th>
            </tr>
            </thead>
            <tbody>
            {{ $confirm := (gettext "Are you sure you wish to delete this amenity?")}}
            {{ range .Amenities -}}
                <tr>
                    <td><a href="/admin/amenities/{{ .Label }}">{{ .Label }}</a></td>
                    <td>{{ .Name }}</td>
                    <td>
                        <a href="/admin/amenities/{{ .Label }}/features">{{( pgettext "Edit Features" "action" )}}</a>
                    </td>
                    <td>
                        <a href="/admin/amenities/{{ .Label }}/slides">{{( pgettext "Edit Carousel" "action" )}}</a>
                    </td>
                    <td>{{ if .Active }}{{( gettext "Yes" )}}{{ else }}{{( gettext "No" )}}{{ end }}</td>
                    <td>
                        <button data-hx-delete="/admin/amenities/{{ .Label }}"
                                data-hx-confirm="{{ $confirm }}"
                                data-hx-headers='{ {{ CSRFHeader }} }'>
                            {{( pgettext "Delete" "action" )}}
                        </button>
                    </td>
                </tr>
            {{- end }}
            </tbody>
        </table>
    {{ else -}}
        <p>{{( gettext "No amenities added yet." )}}</p>
    {{- end }}

    <script type="module">
        import {setupCampgroundMap} from "/static/camper.js?v=";

        setupCampgroundMap(document.getElementById('campground_map'));
    </script>
{{- end }}
