<?xml version="1.0" encoding="utf-8"?>
<odoo>

<template id="modal_ticket_registration" inherit_id="website_event.modal_ticket_registration">
    <!-- Change pricelist -->
    <xpath expr="//div[hasclass('o_wevent_price_range')]" position="after">
        <div id="o_wevent_tickets_pricelist" class="collapse show">
            <t t-call="website_sale.pricelist_list">
                <t t-set="_classes" t-valuef="d-inline p-0 ms-2 my-1"/>
            </t>
        </div>
    </xpath>
    <!-- Add style display for price if the ticket is available -->
    <xpath expr="//div[contains(@t-attf-class, 'o_wevent_registration_multi_select')]" position="attributes">
        <attribute name="t-attf-class" separator=" " add="{{'' if not ticket.sale_available and not ticket.is_expired and ticket.is_launched else ('mt-1' if ticket.price_reduce == 0 else 'mt-2')}}"/>
    </xpath>
    <!-- Add price information on tickets (multi tickets, aka in collapse) -->
    <xpath expr="//div[contains(@t-attf-class, 'o_wevent_registration_multi_select')]" position="inside">
        <t t-if="ticket.price">
            <t t-if="(ticket.price - ticket.price_reduce) &gt; 0">
                <del t-if="website.show_line_subtotals_tax_selection == 'tax_excluded'"
                     class="text-danger me-1"
                     t-field="ticket.price"
                     t-options="{'widget': 'monetary', 'from_currency': event.company_id.sudo().currency_id, 'display_currency': website.currency_id}"/>
                <del t-else=""
                     class="text-danger me-1"
                     t-field="ticket.price_incl"
                     t-options="{'widget': 'monetary', 'from_currency': event.company_id.sudo().currency_id, 'display_currency': website.currency_id}"/>
            </t>
            <span t-if="website.show_line_subtotals_tax_selection == 'tax_excluded'"
                  class="fs-6"
                  t-field="ticket.price_reduce"
                  t-options="{'widget': 'monetary', 'from_currency': event.company_id.sudo().currency_id, 'display_currency': website.currency_id}"/>
            <span t-else=""
                  t-field="ticket.price_reduce_taxinc"
                  class="fs-6"
                  t-options="{'widget': 'monetary', 'from_currency': event.company_id.sudo().currency_id, 'display_currency': website.currency_id}"/>
            <span itemprop="price" class="d-none" t-out="ticket.price"/>
            <span itemprop="priceCurrency" class="d-none" t-out="website.currency_id.name"/>
        </t>
        <span t-else="" class="badge text-bg-success p-2 px-3">Free</span>
    </xpath>
    <xpath expr="//div[hasclass('o_wevent_price_range')]" position="inside">
        <t t-if="website.show_line_subtotals_tax_selection == 'tax_excluded'" t-set="all_prices" t-value="event.event_ticket_ids.mapped('price_reduce')"/>
        <t t-else="" t-set="all_prices" t-value="event.event_ticket_ids.mapped('price_reduce_taxinc')"/>
        <t t-set="lowest_price" t-value="min(all_prices)"/>
        <t t-set="highest_price" t-value="max(all_prices)"/>
        <t t-if="highest_price > 0">
            <small class="text-muted">
                From
                <span t-out="lowest_price" t-options="{'widget': 'monetary', 'from_currency': event.company_id.sudo().currency_id, 'display_currency': website.currency_id}"/>
                <t t-if="lowest_price != highest_price">
                    to
                    <span t-out="highest_price" t-options="{'widget': 'monetary', 'from_currency': event.company_id.sudo().currency_id, 'display_currency': website.currency_id}"/>
                </t>
            </small>
        </t>
    </xpath>
    <!-- Add price information on tickets (mono ticket, aka not in collapse) -->
    <xpath expr="//div[hasclass('o_wevent_registration_single_select')]" position="before">
        <div class="flex-md-grow-1 mt-1 me-2 text-end">
            <t t-if="tickets.price">
                <t t-if="(tickets.price - tickets.price_reduce) &gt;0">
                    <del t-if="website.show_line_subtotals_tax_selection == 'tax_excluded'"
                         class="text-danger me-1"
                         t-field="tickets.price"
                         t-options="{'widget': 'monetary', 'from_currency': event.company_id.sudo().currency_id, 'display_currency': website.currency_id}"/>
                    <del t-else=""
                         class="text-danger me-1"
                         t-field="tickets.price_incl"
                         t-options="{'widget': 'monetary', 'from_currency': event.company_id.sudo().currency_id, 'display_currency': website.currency_id}"/>
                </t>
                <span t-if="website.show_line_subtotals_tax_selection == 'tax_excluded'"
                      class="badge text-bg-secondary fs-6"
                      t-field="tickets.price_reduce"
                      t-options="{'widget': 'monetary', 'from_currency': event.company_id.sudo().currency_id, 'display_currency': website.currency_id}"/>
                <span t-else=""
                      class="badge text-bg-secondary fs-6"
                      t-field="tickets.price_reduce_taxinc"
                      t-options="{'widget': 'monetary', 'from_currency': event.company_id.sudo().currency_id, 'display_currency': website.currency_id}"/>
                <span itemprop="price" class="d-none" t-out="tickets.price"/>
                <span itemprop="priceCurrency" class="d-none" t-out="website.currency_id.name"/>
            </t>
            <span t-else="" class="badge text-bg-secondary fs-6 text-uppercase">Free</span>
        </div>
    </xpath>
</template>

<template id="registration_attendee_details" inherit_id="website_event.registration_attendee_details">
    <!-- Change 'continue' button to use the website login settings -->
    <xpath expr="//div[hasclass('modal-footer')]//button[hasclass('btn-primary')]" position="replace">
        <t t-if="availability_check and limit_check">
            <t t-set="has_paying_ticket" t-value="any(ticket.get('price', 0) > 0 for ticket in tickets)"/>
            <button t-if="website.account_on_checkout == 'mandatory' and website.is_public_user() and has_paying_ticket" class="btn btn-primary" type="submit">
                <span>Sign In</span>
                <span class="fa fa-sign-in"/>
            </button>
            <button t-else="" type="submit" class="btn btn-primary">
                <span t-if="has_paying_ticket">Go to Payment</span>
                <span t-else="">Confirm Registration</span>
            </button>
        </t>
    </xpath>
</template>

</odoo>
