<?xml version="1.0" encoding="utf-8" ?>
<odoo>
    <template
        id="portal_my_home_menu_reservation"
        name="Portal layout : reservation menu entries"
        inherit_id="portal.portal_breadcrumbs"
        priority="20"
    >
        <xpath expr="//ol[hasclass('o_portal_submenu')]" position="inside">
            <li
                t-if="page_name == 'reservations'"
                t-attf-class="breadcrumb-item #{'active ' if not reservations else ''}"
            >
                <a t-attf-href="/my/reservations?{{ keep_query() }}">Reservations</a>
            </li>
            <li t-if="reservation" class="breadcrumb-item active">
                 <a t-attf-href="/my/reservations?{{ keep_query() }}">Reservations/</a>
                <t t-esc="reservation.name" />
            </li>
        </xpath>
    </template>
    <template
        id="portal_my_reservations"
        name="Reservations"
        inherit_id="portal.portal_my_home"
        customize_show="True"
        priority="30"
    >
        <xpath expr="//div[hasclass('o_portal_docs')]" position="inside">
            <t t-call="portal.portal_docs_entry">
                <t t-set="title">Reservations</t>
                <t t-set="url" t-value="'/my/reservations'" />
                <t t-set="placeholder_count" t-value="'reservation_count'" />
            </t>
        </xpath>
    </template>

    <template id="portal_my_reservation" name="My Reservations">
      <t t-call="portal.portal_layout">
        <t t-set="breadcrumbs_searchbar" t-value="True" />

        <t t-call="portal.portal_searchbar">
            <t t-set="title">Reservations</t>
        </t>
        <t t-if="not reservations">
            <p>There are currently no reservations for your account.</p>
        </t>
        <t t-if="reservations" t-call="portal.portal_table">
            <thead>
                <tr class="active">
                    <th>Reservation #</th>
                    <th>Checkin</th>
                    <th>Checkout</th>
                    <th class="text-right">Total</th>
                </tr>
            </thead>
            <tbody>
                <t t-set="folio_old" t-value="" />
                <t t-foreach="folios_dict" t-as="folio">
                    <t t-foreach="folio.reservation_ids" t-as="reservation">
                        <t t-if="reservation.partner_id == partner">
                            <t t-if="folio != folio_old">
                                <tr class="bg-light">
                                    <td colspan="4"><em
                                                class="font-weight-normal text-muted"
                                            ><span /> Reservations by folio: </em>
                                    <a
                                                t-att-href="folio.get_portal_url()"
                                                t-att-title="folio.name"
                                            >
                                        <t t-esc="folio.name" />
                                    </a>
                                    </td>
                                </tr>
                            </t>
                            <t t-set="folio_old" t-value="folio" />
                            <tr>
                                <td>
                                    <a
                                            t-att-href="reservation.get_portal_url()"
                                            t-att-title="reservation.name"
                                        >
                                        <t t-esc="reservation.name" />
                                    </a>
                                </td>
                                <td><span t-field="reservation.checkin" /></td>
                                <td><span t-field="reservation.checkout" /></td>
                                <td class="text-right"><span
                                            t-field="reservation.price_room_services_set"
                                        /></td>
                            </tr>
                        </t>
                    </t>
                </t>
            </tbody>
        </t>
      </t>
    </template>

    <template id="portal_my_reservation_detail" name="My Reservation">
        <t t-call="portal.portal_layout">
            <t t-call="portal.portal_record_layout">
                <t t-set="card_header">
                    <div class="row no-gutters">
                        <div class="col-12">
                            <h5 class="d-flex mb-1 mb-md-0 row">
                                <span
                                    t-field="reservation.name"
                                    class="col-9 text-truncate"
                                />
                                <div class="col-3 col-md-2 text-right">
                                    <small class="text-right">Status:</small>
                                    <span
                                        t-field="reservation.state"
                                        class=" badge badge-pill badge-info"
                                        title="Current state of this reservation"
                                    />
                                </div>
                            </h5>
                        </div>
                    </div>
                </t>
                <t t-set="card_body">
                    <div class="row mb-4">
                        <div class="col-12 col-md-6">
                            <strong>Checkin:</strong> <span
                                t-field="reservation.checkin"
                                t-options='{"widget": "date"}'
                            />
                        </div>
                        <div class="col-12 col-md-6 mb-1">
                            <strong>Checkout:</strong> <span
                                t-field="reservation.checkout"
                                t-options='{"widget": "date"}'
                            />
                        </div>
                    </div>
                     <div class="row mb-4">
                        <div class="col-12 col-md-6">
                            <strong>Arrival hour:</strong> <span
                                t-field="reservation.arrival_hour"
                            />
                        </div>
                        <div class="col-12 col-md-6 mb-1">
                            <strong>Departure hour:</strong> <span
                                t-field="reservation.departure_hour"
                            />
                        </div>
                    </div>

                    <div class="row mb-4">
                        <div class="col-12 col-md-6">
                            <strong>Room:</strong> <span
                                t-field="reservation.preferred_room_id"
                            />
                        </div>
                       <div class="col-12 col-md-6 mb-1">
                           <t t-if="reservation.board_service_room_id">
                               <strong>Board Service:</strong> <span
                                    t-field="reservation.board_service_room_id.pms_board_service_id.name"
                                />
                           </t>
                        </div>
                    </div>
                    <t t-set="service_price" t-value="0" />
                    <t t-set="board_service_price" t-value="0" />
                    <t t-foreach="reservation.service_ids" t-as="service">
                        <t t-if="service.is_board_service">
                            <t
                                t-set="board_service_price"
                                t-value="board_service_price + service.price_total"
                            />
                        </t>
                        <t t-else="">
                            <t
                                t-set="service_price"
                                t-value="service_price + service.price_total"
                            />
                        </t>
                    </t>
                    <div class="row mb-4">
                        <div class="col-12 col-md-6">
                            <strong>Room price:</strong> <span
                                t-esc="reservation.price_total + board_service_price"
                                t-options='{"widget": "monetary", "display_currency": reservation.pricelist_id.currency_id}'
                            />
                        </div>
                       <div class="col-12 col-md-6 mb-1">
                           <t t-if="service_price!=0">
                                <strong>Service total:</strong> <span
                                    t-esc="service_price"
                                    t-options='{"widget": "monetary", "display_currency": reservation.pricelist_id.currency_id}'
                                />
                           </t>
                        </div>
                    </div>
                    <t t-if="reservation.service_ids">
                        <t t-if="service_price!=0">
                        <table class="table">
                            <thead style="display:table-row-group">
                                <th name="th_services">
                                    Services
                                </th>
                                <th name="th_qty">
                                    Quantity
                                </th>
                                <th name="th_price_total">
                                    Price Total
                                </th>
                            </thead>
                            <tbody>
                                <t t-foreach="reservation.service_ids" t-as="service">
                                    <t t-if="not service.is_board_service">
                                        <tr>
                                            <td><span t-esc="service.name" /></td>
                                            <td><span
                                                        t-field="service.product_qty"
                                                    /></td>
                                            <td><span
                                                        t-field="service.price_total"
                                                        t-options='{"widget": "monetary", "display_currency": reservation.pricelist_id.currency_id}'
                                                    /></td>
                                        </tr>
                                    </t>
                                </t>
                            </tbody>
                        </table>
                        </t>
                        <div class="row mb-4 justify-content-start">
                            <div class="h3 text-info">
                               <strong>Reservation total:</strong> <span
                                    t-field="reservation.price_room_services_set"
                                />
                            </div>
                        </div>
                    </t>

                    <div class="row mb-4" t-if="reservation.partner_id.is_agency">
                        <div
                            class="col-12 col-md-6 pb-2"
                            t-if="reservation.partner_id.is_agency"
                        >
                            <strong>Assigned to</strong>
                            <div class="row">
                                <div class="col flex-grow-0 pr-3">
                                    <img
                                        t-if="reservation.partner_id.image_1024"
                                        class="rounded-circle mt-1 o_portal_contact_img"
                                        t-att-src="image_data_uri(reservation.partner_id.image_1024)"
                                        alt="Contact"
                                    />
                                    <img
                                        t-else=""
                                        class="rounded-circle mt-1 o_portal_contact_img"
                                        src="/web/static/src/img/user_menu_avatar.png"
                                        alt="Contact"
                                    />
                                </div>
                                <div class="col pl-md-0">
                                    <div
                                        t-field="reservation.partner_id"
                                        t-options='{"widget": "contact", "fields": ["name", "email", "mobile"]}'
                                    />
                                </div>
                            </div>
                        </div>
                    </div>
                </t>
            </t>

            <div class="mt32">
                <h4><strong>Message and communication history</strong></h4>
                <t t-call="portal.message_thread">
                    <t t-set="object" t-value="reservation" />
                    <t t-set="token" t-value="reservation.access_token" />
                    <t t-set="pid" t-value="pid" />
                    <t t-set="hash" t-value="hash" />
                </t>
            </div>
        </t>
    </template>
</odoo>
