<!--
 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/payment.paymentDetails*/ -}}
    {{ printf ( pgettext "Payment %s" "title" ) .Reference }}
{{- end }}

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

{{ define "content" -}}
    {{- /*gotype: dev.tandem.ws/tandem/camper/pkg/payment.paymentDetails*/ -}}
    <h2 id="payment-heading">{{ template "title" . }}</h2>

    <div id="payment-actions">
        {{ with .AcceptPreauthRequest -}}
            {{ $confirm := (gettext "Are you sure you wish to accept this pre-authorization?")}}
            <form method="post" x-data @submit.prevent="if (confirm('{{ $confirm }}')) $el.submit()"
                    {{- if eq $.Environment "live" }} action="https://sis.redsys.es/sis/realizarPago"
                    {{- else }} action="https://sis-t.redsys.es:25443/sis/realizarPago"
                    {{- end -}}
            >
                <input type="hidden" name="Ds_MerchantParameters" value="{{ .MerchantParameters }}"/>
                <input type="hidden" name="Ds_Signature" value="{{ .Signature }}"/>
                <input type="hidden" name="Ds_SignatureVersion" value="{{ .SignatureVersion }}"/>
                <button type="submit">{{( pgettext "Accept pre-authorization" "action" )}}</button>
            </form>
        {{- end }}

        {{ with .VoidPreauthRequest -}}
            {{ $confirm := (gettext "Are you sure you wish to void this pre-authorization?")}}
            <form method="post" x-data @submit.prevent="if (confirm('{{ $confirm }}')) $el.submit()"
                    {{- if eq $.Environment "live" }} action="https://sis.redsys.es/sis/realizarPago"
                    {{- else }} action="https://sis-t.redsys.es:25443/sis/realizarPago"
                    {{- end -}}
            >
                <input type="hidden" name="Ds_MerchantParameters" value="{{ .MerchantParameters }}"/>
                <input type="hidden" name="Ds_Signature" value="{{ .Signature }}"/>
                <input type="hidden" name="Ds_SignatureVersion" value="{{ .SignatureVersion }}"/>
                <button type="submit">{{( pgettext "Void pre-authorization" "action" )}}</button>
            </form>
        {{- end }}
    </div>

    <table class="payment-{{ .Status}}">
        <caption>{{( pgettext "Payment" "title" )}}</caption>
        <tbody>
        <tr>
            <th scope="row">{{( pgettext "Reference" "header" )}}</th>
            <td>{{ .Reference }}</td>
        </tr>
        <tr>
            <th scope="row">{{( pgettext "Status" "header" )}}</th>
            <td class="payment-status">{{ .StatusLabel }}</td>
        </tr>
        <tr>
            <th scope="row">{{( pgettext "Created at" "payment header" )}}</th>
            <td>{{ .CreatedAt | formatDateTime }}</td>
        </tr>
        <tr>
            <th scope="row">{{( pgettext "Last updated at" "payment header" )}}</th>
            <td>{{ .UpdatedAt | formatDateTime }}</td>
        </tr>
        </tbody>
    </table>

    <table>
        <caption>{{( pgettext "Booking" "title" )}}</caption>
        <tbody>
        <tr>
            <th scope="row">{{( pgettext "Accommodation" "title" )}}</th>
            <td>{{ .CampsiteType }}</td>
        </tr>
        <tr>
            <th scope="row">{{( pgettext "Area preferences" "header" )}}</th>
            <td>{{ .ZonePreferences }}</td>
        </tr>
        <tr>
            <th scope="row">{{( pgettext "ACSI / ANWB card?" "input" )}}</th>
            <td>{{if .ACSICard}}{{( gettext "Yes" )}}{{ else }}{{( gettext "No" )}}{{ end }}</td>
        </tr>
        <tr>
            <th scope="row">{{( pgettext "Arrival date" "input" )}}</th>
            <td>{{ .ArrivalDate | formatDate }}</td>
        </tr>
        <tr>
            <th scope="row">{{( pgettext "Departure date" "input" )}}</th>
            <td>{{ .DepartureDate | formatDate }}</td>
        </tr>
        <tr>
            <th scope="row">{{( pgettext "Nights" "cart" )}}</th>
            <td class="numeric">{{ .NumNights }}</td>
        </tr>
        <tr>
            <th scope="row">{{( pgettext "Adults aged 17 or older" "input" )}}</th>
            <td class="numeric">{{ .NumAdults }}</td>
        </tr>
        <tr>
            <th scope="row">{{( pgettext "Teenagers from 11 to 16 years old" "input" )}}</th>
            <td class="numeric">{{ .NumTeenagers }}</td>
        </tr>
        <tr>
            <th scope="row">{{( pgettext "Children from 2 to 10 years old" "input" )}}</th>
            <td class="numeric">{{ .NumChildren }}</td>
        </tr>
        <tr>
            <th scope="row">{{( pgettext "Dogs" "input" )}}</th>
            <td class="numeric">{{ .NumDogs }}</td>
        </tr>
        <tr>
            <th scope="row">{{( pgettext "Tourist tax" "cart" )}}</th>
            <td class="numeric">{{ .SubtotalTouristTax | formatPrice }}</td>
        </tr>
        <tr>
            <th scope="row">{{( pgettext "Down payment" "cart" )}}</th>
            <td class="numeric">{{ .DownPaymentPercent }} %, {{ .DownPayment | formatPrice }}</td>
        </tr>
        </tbody>
    </table>

    {{ with .Options -}}
        <table>
            <caption>{{( pgettext "Campsite Type Options" "title" )}}</caption>
            <tbody>
            {{ range . -}}
                <tr>
                    <th scope="row">{{ .Label }}</th>
                    <td class="numeric">{{ .Units }}</td>
                </tr>
            {{- end }}
            </tbody>
        </table>
    {{- end }}

    {{ with .Customer -}}
        <table>
            <caption>{{( pgettext "Customer Details" "title" )}}</caption>
            <tbody>
            <tr>
                <th scope="row">{{( pgettext "Full name" "input" )}}</th>
                <td>{{ .FullName }}</td>
            </tr>
            <tr>
                <th scope="row">{{( pgettext "Address" "input" )}}</th>
                <td>{{ .Address }}</td>
            </tr>
            <tr>
                <th scope="row">{{( pgettext "Postcode" "input" )}}</th>
                <td>{{ .PostalCode }}</td>
            </tr>
            <tr>
                <th scope="row">{{( pgettext "City" "input" )}}</th>
                <td>{{ .City }}</td>
            </tr>
            <tr>
                <th scope="row">{{( pgettext "Country" "input" )}}</th>
                <td>{{ .Country }}</td>
            </tr>
            <tr>
                <th scope="row">{{( pgettext "Email" "input" )}}</th>
                <td><a href="mailto:{{ .Email}}">{{ .Email }}</a></td>
            </tr>
            <tr>
                <th scope="row">{{( pgettext "Phone" "input" )}}</th>
                <td><a href="tel:{{ replaceAll .Phone " " "" }}">{{ .Phone }}</a></td>
            </tr>
            <tr>
                <th scope="row">{{( pgettext "Language" "input" )}}</th>
                <td>{{ .Language }}</td>
            </tr>
            </tbody>
        </table>
    {{- end }}

{{- end }}