{{ define "title" -}}
    {{( pgettext "Tax Details" "title" )}}
{{- end }}

{{ define "breadcrumbs" -}}
    {{- /*gotype: dev.tandem.ws/tandem/numerus/pkg.TaxDetailsPage*/ -}}
    <nav data-hx-target="main" data-hx-boost="true">
        <p>
            <a href="{{ companyURI "/" }}">{{( pgettext "Home" "title" )}}</a> /
            <a>{{( pgettext "Tax Details" "title" )}}</a>
        </p>
    </nav>
{{- end }}

{{ define "content" }}
    {{- /*gotype: dev.tandem.ws/tandem/numerus/pkg.TaxDetailsPage*/ -}}
    <section class="dialog-content" id="tax-details-dialog-content" data-hx-target="this">
        <h2>{{(pgettext "Tax Details" "title")}}</h2>
        {{ with .DetailsForm }}
            <form id="details" method="POST" action="{{ companyURI "/tax-details" }}" data-hx-boost="true" data-hx-select="#tax-details-dialog-content">
                {{ csrfToken }}
                {{ template "input-field" .BusinessName }}
                {{ template "input-field" .VATIN }}
                {{ template "input-field" .TradeName }}
                {{ template "input-field" .Phone }}
                {{ template "input-field" .Email }}
                {{ template "input-field" .Web }}
                {{ template "input-field" .Address | addInputAttr `class="width-2x"` }}
                {{ template "input-field" .City }}
                {{ template "input-field" .Province }}
                {{ template "input-field" .PostalCode }}
                {{ template "select-field" .Country | addSelectAttr `class="width-fixed"` }}

                <fieldset>
                    <legend id="currency-legend">{{( pgettext "Currency" "title" )}}</legend>

                    {{ template "select-field" .Currency }}
                </fieldset>

                <fieldset>
                    <legend>{{( pgettext "Invoicing" "title" )}}</legend>

                    {{ template "input-field" .InvoiceNumberFormat }}
                    {{ template "input-field" .LegalDisclaimer }}
                </fieldset>
            </form>
        {{ end }}

        <form id="newtax" method="POST" action="{{ companyURI "/tax" }}" data-hx-boost="true" data-hx-select="#tax-details-dialog-content">
            {{ csrfToken }}
        </form>

        {{ $confirm := ( gettext "Are you sure?" )}}
        <fieldset>
            <table>
                <thead>
                <tr>
                    <th width="50%"></th>
                    <th>{{( pgettext "Tax Name" "title" )}}</th>
                    <th>{{( pgettext "Rate (%)" "title" )}}</th>
                    <th>{{( pgettext "Class" "title" )}}</th>
                    <th></th>
                </tr>
                </thead>
                <tbody data-hx-confirm="{{ $confirm }}" data-hx-target="closest tr" data-hx-swap="outerHTML swap:1s">
                {{ with .Taxes }}
                    {{- range $tax := . }}
                        <tr>
                            <td></td>
                            <td>{{ .Name }}</td>
                            <td>{{ .Rate }}</td>
                            <td>{{ .Class }}</td>
                            <td>
                                <form method="POST" action="{{ companyURI "/tax"}}/{{ .Id }}" data-hx-boost="true">
                                    {{ csrfToken }}
                                    {{ deleteMethod }}
                                    <button class="icon" aria-label="{{( gettext "Delete tax" )}}" type="submit"><i
                                                class="ri-delete-back-2-line"></i></button>
                                </form>
                            </td>
                        </tr>
                    {{- end }}
                {{ else }}
                    <tr>
                        <td colspan="4">{{( gettext "No taxes added yet." )}}</td>
                    </tr>
                {{ end }}
                </tbody>
                <tfoot>
                <tr>
                    <th scope="row">{{( pgettext "New Line" "title")}}</th>
                    <td>
                        {{ template "input-field" .NewTaxForm.Name | addInputAttr `form="newtax"` }}
                    </td>
                    <td>
                        {{ template "input-field" .NewTaxForm.Rate | addInputAttr `form="newtax"` }}
                    </td>
                    <td>
                        {{ template "select-field" .NewTaxForm.Class | addSelectAttr `form="newtax"` }}
                    </td>
                </tr>
                <tr>
                    <td colspan="2"></td>
                    <td colspan="2">
                        <button form="newtax" type="submit">{{( pgettext "Add new tax" "action" )}}</button>
                    </td>
                </tr>
                </tfoot>
            </table>
        </fieldset>

        <form id="new-payment-method" method="POST" action="{{ companyURI "/payment-method" }}" data-hx-boost="true" data-hx-select="#tax-details-dialog-content">
            {{ csrfToken }}
        </form>

        <fieldset>
            <table>
                <thead>
                <tr>
                    <th width="50%"></th>
                    <th>{{( pgettext "Payment Method" "title" )}}</th>
                    <th>{{( pgettext "Instructions" "title" )}}</th>
                    <th></th>
                </tr>
                </thead>
                <tbody data-hx-confirm="{{ $confirm }}" data-hx-target="closest tr" data-hx-swap="outerHTML swap:1s">
                {{ with .PaymentMethods }}
                    {{- range $method := . }}
                        <tr>
                            <td></td>
                            <td>{{ .Name }}</td>
                            <td>{{ .Instructions }}</td>
                            <td>
                                <form method="POST" action="{{ companyURI "/payment-method"}}/{{ .Id }}" data-hx-boost="true">
                                    {{ csrfToken }}
                                    {{ deleteMethod }}
                                    <button class="icon" aria-label="{{( gettext "Delete payment method" )}}"
                                            type="submit"><i
                                                class="ri-delete-back-2-line"></i></button>
                                </form>
                            </td>
                        </tr>
                    {{- end }}
                {{ else }}
                    <tr>
                        <td colspan="4">{{( gettext "No payment methods added yet." )}}</td>
                    </tr>
                {{ end }}
                </tbody>
                <tfoot>
                <tr>
                    <th scope="row">{{( pgettext "New Line" "title")}}</th>
                    <td>
                        {{ template "input-field" .NewPaymentMethodForm.Name | addInputAttr `form="new-payment-method"` }}
                    </td>
                    <td>
                        {{ template "input-field" .NewPaymentMethodForm.Instructions | addInputAttr `form="new-payment-method"` }}
                    </td>
                </tr>
                <tr>
                    <td colspan="2"></td>
                    <td colspan="2">
                        <button form="new-payment-method"
                                type="submit">{{( pgettext "Add new payment method" "action" )}}</button>
                    </td>
                </tr>
                </tfoot>
            </table>
        </fieldset>

        <fieldset>
            <button form="details" type="submit">{{( pgettext "Save changes" "action" )}}</button>
        </fieldset>
    </section>
{{- end }}
