<!--
 SPDX-FileCopyrightText: 2023 jordi fita mas <jordi@tandem.blog>
 SPDX-License-Identifier: AGPL-3.0-only
-->
{{ define "title" -}}
    {{- /*gotype: dev.tandem.ws/tandem/camper/pkg/campsite/types.typeForm*/ -}}
    {{ if .Slug}}
        {{( pgettext "Edit Campsite Type" "title" )}}
    {{ else }}
        {{( pgettext "New Campsite Type" "title" )}}
    {{ end }}
{{- end }}

{{ define "breadcrumb" -}}
    <li><a href="./../">{{( pgettext "Campsites" "title" )}}</a></li>
    <li><a href="./">{{( pgettext "Campsite Types" "title" )}}</a></li>
{{- end }}

{{ define "content" -}}
    {{- /*gotype: dev.tandem.ws/tandem/camper/pkg/campsite/types.typeForm*/ -}}
    <form
            {{ if .Slug }}
                data-hx-put="/admin/campsites/types/{{ .Slug }}"
            {{ else }}
                action="/admin/campsites/types" method="post"
            {{ end }}
    >
        <h2>
            {{ if .Slug }}
                {{( pgettext "Edit Campsite Type" "title" )}}
            {{ else }}
                {{( pgettext "New Campsite Type" "title" )}}
            {{ end }}
        </h2>
        {{ CSRFInput }}
        <fieldset {{ template "init-lang" . }}>
            {{ if .Slug }}
                {{ with .Active -}}
                    <label>
                        <input type="checkbox" name="{{ .Name }}" {{ if .Checked}}checked{{ end }}
                                {{ template "error-attrs" . }}>
                        {{( pgettext "Active" "campsite type" )}}<br>
                    </label>
                    {{ template "error-message" . }}
                {{- end }}
            {{ else }}
                <input type="hidden" name="{{ .Active.Name }}" value="true">
            {{ end }}
            {{ with .Name -}}
                <fieldset>
                    <legend>{{( pgettext "Name" "input")}}</legend>
                    {{ template "lang-selector" . }}
                    {{ range $lang, $input := . -}}
                        <label x-cloak x-show="lang === '{{ $lang }}'"><span>{{ $lang }}</span><br>
                            <input type="text" name="{{ $input.Name }}" value="{{ $input.Val }}"
                                    {{ template "error-attrs" . }}><br>
                        </label>
                    {{- end }}
                    {{ template "error-message" . }}
                </fieldset>
            {{- end }}
            {{ with .Media -}}
                {{ template "media-picker" . }}
            {{- end }}
            {{ with .CheckIn -}}
                <fieldset>
                    <legend>{{( pgettext "Check-in" "input")}}</legend>
                    {{ template "lang-selector" . }}
                    {{ range $lang, $input := . -}}
                        <label x-cloak x-show="lang === '{{ $lang }}'"><span>{{ $lang }}</span><br>
                            <input type="text" name="{{ $input.Name }}" value="{{ $input.Val }}"
                                    {{ template "error-attrs" . }}><br>
                        </label>
                    {{- end }}
                    {{ template "error-message" . }}
                </fieldset>
            {{- end }}
            {{ with .CheckOut -}}
                <fieldset>
                    <legend>{{( pgettext "Check-out" "input")}}</legend>
                    {{ template "lang-selector" . }}
                    {{ range $lang, $input := . -}}
                        <label x-cloak x-show="lang === '{{ $lang }}'"><span>{{ $lang }}</span><br>
                            <input type="text" name="{{ $input.Name }}" value="{{ $input.Val }}"
                                    {{ template "error-attrs" . }}><br>
                        </label>
                    {{- end }}
                    {{ template "error-message" . }}
                </fieldset>
            {{- end }}
            {{ with .MinNights -}}
                <label>
                    {{( pgettext "Minimum number of nights" "input")}}<br>
                    <input type="number" name="{{ .Name }}" value="{{ .Val }}" min="1"
                           required {{ template "error-attrs" . }}><br>
                    {{ template "error-message" . }}
                </label>
            {{- end }}
            {{ with .MaxNights -}}
                <label>
                    {{( pgettext "Maximum number of nights" "input")}}<br>
                    <input type="number" name="{{ .Name }}" value="{{ .Val }}" min="1"
                           required {{ template "error-attrs" . }}><br>
                    {{ template "error-message" . }}
                </label>
            {{- end }}
            <fieldset>
                {{ with .MaxCampers -}}
                    <label>
                        {{( pgettext "Maximum number of campers" "input")}}<br>
                        <input type="number" name="{{ .Name }}" value="{{ .Val }}" min="1"
                               required {{ template "error-attrs" . }}><br>
                        {{ template "error-message" . }}
                    </label>
                {{- end }}
                {{ with .OverflowAllowed -}}
                    <label>
                        <input type="checkbox" name="{{ .Name }}" {{ if .Checked}}checked{{ end }}
                                {{ template "error-attrs" . }}>
                        {{( pgettext "Allow overflowing guests to neighbouring campsites" "input" )}}<br>
                    </label>
                    {{ template "error-message" . }}
                {{- end }}
            </fieldset>
            {{ with .AskZonePreferences -}}
                <label>
                    <input type="checkbox" name="{{ .Name }}" {{ if .Checked}}checked{{ end }}
                            {{ template "error-attrs" . }}>
                    {{( pgettext "Ask for zone preferences when booking" "input" )}}<br>
                </label>
                {{ template "error-message" . }}
            {{- end }}
            <fieldset x-data="{allowed: {{ if .DogsAllowed.Checked}}true{{ else }}false{{ end }}}">
                {{ with .DogsAllowed -}}
                    <label>
                        <input type="checkbox" name="{{ .Name }}" {{ if .Checked}}checked{{ end }}
                                x-model="allowed"
                                {{ template "error-attrs" . }}>
                        {{( pgettext "Dogs allowed" "input" )}}<br>
                    </label>
                    {{ template "error-message" . }}
                {{- end }}
                {{ with .DogsPrice -}}
                    <label x-cloak x-show="allowed">{{( pgettext "Dogs price" "input")}}<br>
                        <input type="number" name="{{ .Name }}" value="{{ .Val }}" min="0"
                               step="0.01" {{ template "error-attrs" . }}><br>
                        {{ template "error-message" . }}
                    </label>
                {{- end }}
            </fieldset>
            {{ with .Prices }}
                <fieldset>
                    <legend>{{( pgettext "Prices" "title" )}}</legend>
                    <table>
                        <thead>
                        <tr>
                            <th scope="col">{{( pgettext "Season" "header" )}}</th>
                            <th scope="col">{{( pgettext "Price per night" "header" )}}</th>
                            <th scope="col">{{( pgettext "Price per adult (> 16)" "header" )}}</th>
                            <th scope="col">{{( pgettext "Price per teenager (11–16)" "header" )}}</th>
                            <th scope="col">{{( pgettext "Price per child (2–10)" "header" )}}</th>
                        </tr>
                        </thead>
                        <tbody>
                        {{ range . -}}
                            <tr>
                                <th scope="row">{{ .SeasonName }}</th>
                                {{ with .PricePerNight -}}
                                    <td>
                                        <label>
                                            <span class="sr-only">{{( pgettext "Price per night" "input")}}<br></span>
                                            <input type="number" name="{{ .Name }}" value="{{ .Val }}" min="0"
                                                   step="0.01"
                                                   required {{ template "error-attrs" . }}><br>
                                            {{ template "error-message" . }}
                                        </label>
                                    </td>
                                {{- end }}
                                {{ with .PricePerAdult -}}
                                    <td>
                                        <label>
                                            <span class="sr-only">{{( pgettext "Price per adult (> 16)" "input")}}<br></span>
                                            <input type="number" name="{{ .Name }}" value="{{ .Val }}" min="0"
                                                   step="0.01"
                                                   required {{ template "error-attrs" . }}><br>
                                            {{ template "error-message" . }}
                                        </label>
                                    </td>
                                {{- end }}
                                {{ with .PricePerTeenager -}}
                                    <td>
                                        <label>
                                            <span class="sr-only">{{( pgettext "Price per teenager (11–16)" "input")}}<br></span>
                                            <input type="number" name="{{ .Name }}" value="{{ .Val }}" min="0"
                                                   step="0.01"
                                                   required {{ template "error-attrs" . }}><br>
                                            {{ template "error-message" . }}
                                        </label>
                                    </td>
                                {{- end }}
                                {{ with .PricePerChild -}}
                                    <td>
                                        <label>
                                            <span class="sr-only">{{( pgettext "Price per child (2–10)" "input")}}<br></span>
                                            <input type="number" name="{{ .Name }}" value="{{ .Val }}" min="0"
                                                   step="0.01"
                                                   required {{ template "error-attrs" . }}><br>
                                            {{ template "error-message" . }}
                                        </label>
                                    </td>
                                {{- end }}
                            </tr>
                        {{- end }}
                        </tbody>
                    </table>
                </fieldset>
            {{- end }}
            {{ with .Spiel -}}
                <fieldset>
                    <legend>{{( pgettext "Spiel" "input")}}</legend>
                    {{ template "lang-selector" . }}
                    {{ range $lang, $input := . -}}
                        <label x-cloak x-show="lang === '{{ $lang }}'"><span>{{ $lang }}</span><br>
                            <textarea class="html"
                                      name="{{ $input.Name }}" {{ template "error-attrs" . }}>{{ $input.Val }}</textarea><br>
                        </label>
                    {{- end }}
                    {{ template "error-message" . }}
                </fieldset>
            {{- end }}
            {{ with .Info -}}
                <fieldset>
                    <legend>{{( pgettext "Info" "input")}}<br></legend>
                    {{ template "lang-selector" . }}
                    {{ range $lang, $input := . -}}
                        <label x-cloak x-show="lang === '{{ $lang }}'"><span>{{ $lang }}</span><br>
                            <textarea class="html"
                                      name="{{ .Name }}" {{ template "error-attrs" . }}>{{ .Val }}</textarea><br>
                        </label>
                    {{- end }}
                    {{ template "error-message" . }}
                </fieldset>
            {{- end }}
            {{ with .Facilities -}}
                <fieldset>
                    <legend>{{( pgettext "Facilities" "input")}}<br></legend>
                    {{ template "lang-selector" . }}
                    {{ range $lang, $input := . -}}
                        <label x-cloak x-show="lang === '{{ $lang }}'"><span>{{ $lang }}</span><br>
                            <textarea class="html"
                                      name="{{ .Name }}" {{ template "error-attrs" . }}>{{ .Val }}</textarea><br>
                        </label>
                    {{- end }}
                    {{ template "error-message" . }}
                </fieldset>
            {{- end }}
            {{ with .Description -}}
                <fieldset>
                    <legend>{{( pgettext "Description" "input")}}<br></legend>
                    {{ template "lang-selector" . }}
                    {{ range $lang, $input := . -}}
                        <label x-cloak x-show="lang === '{{ $lang }}'"><span>{{ $lang }}</span><br>
                            <textarea class="html"
                                      name="{{ .Name }}" {{ template "error-attrs" . }}>{{ .Val }}</textarea><br>
                        </label>
                    {{- end }}
                    {{ template "error-message" . }}
                </fieldset>
            {{- end }}
            {{ with .AdditionalInfo -}}
                <fieldset>
                    <legend>{{( pgettext "Additional Information" "input" )}}<br></legend>
                    {{ template "lang-selector" . }}
                    {{ range $lang, $input := . -}}
                        <label x-cloak x-show="lang === '{{ $lang }}'"><span>{{ $lang }}</span><br>
                            <textarea class="html"
                                      name="{{ .Name }}" {{ template "error-attrs" . }}>{{ .Val }}</textarea><br>
                        </label>
                    {{- end }}
                    {{ template "error-message" . }}
                </fieldset>
            {{- end }}
        </fieldset>
        <footer>
            <button type="submit">
                {{ if .Slug }}
                    {{( pgettext "Update" "action" )}}
                {{ else }}
                    {{( pgettext "Add" "action" )}}
                {{ end }}
            </button>
        </footer>
    </form>
{{- end }}
