<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <!-- Portal Breadcrumbs -->
    <template id="portal_my_home_menu_rental" name="Portal layout : Rental menu entries" inherit_id="portal.portal_breadcrumbs" priority="30">
        <xpath expr="//ol[hasclass('o_portal_submenu')]" position="inside">
            <li t-if="page_name == 'rental_requests' or page_name == 'rental_request_detail'" t-att-class="'breadcrumb-item active' if page_name == 'rental_requests' else 'breadcrumb-item'">
                <a t-if="page_name == 'rental_request_detail'" href="/my/rentals">My Rentals</a>
                <t t-else="">My Rentals</t>
            </li>
            <li t-if="page_name == 'rental_request_detail'" class="breadcrumb-item active">
                <span t-field="rental_request.name"/>
            </li>
        </xpath>
    </template>

    <!-- Portal Home Counter -->
    <template id="portal_my_home_rental" name="Portal My Home : Rental entries" inherit_id="portal.portal_my_home" priority="30">
        <xpath expr="//div[hasclass('o_portal_docs')]" position="inside">
            <t t-call="portal.portal_docs_entry">
                <t t-set="title">My Rentals</t>
                <t t-set="url" t-value="'/my/rentals'"/>
                <t t-set="placeholder_count" t-value="'rental_count'"/>
            </t>
        </xpath>
    </template>

    <!-- Portal List View -->
    <template id="portal_my_rental_requests" name="My Rental Requests">
        <t t-call="portal.portal_layout">
            <t t-set="breadcrumbs_searchbar" t-value="True"/>
            <t t-call="portal.portal_searchbar" t-if="requests">
                <t t-set="title">Rental Requests</t>
            </t>
            
            <div t-if="not requests" class="alert alert-warning mt-3" role="alert">
                There are currently no rental requests in your account.
            </div>
            
            <table t-if="requests" class="table table-hover bg-white mt-3">
                <thead>
                    <tr>
                        <th>Reference</th>
                        <th>Event Date</th>
                        <th>Event Type</th>
                        <th class="text-right">Total Amount</th>
                        <th class="text-center">Status</th>
                    </tr>
                </thead>
                <tbody>
                    <tr t-foreach="requests" t-as="req">
                        <td>
                            <a t-att-href="'/my/rentals/%s' % req.id" t-out="req.name"/>
                        </td>
                        <td><span t-field="req.event_date"/></td>
                        <td><span t-field="req.event_type"/></td>
                        <td class="text-right">
                            <span t-field="req.amount_total" t-options="{'widget': 'monetary', 'display_currency': res_company.currency_id}"/>
                        </td>
                        <td class="text-center"><span t-field="req.status"/></td>
                    </tr>
                </tbody>
            </table>
            <div t-if="pager" class="o_portal_pager d-flex justify-content-center mt-3">
                <t t-call="portal.pager"/>
            </div>
        </t>
    </template>

    <!-- Portal Details View -->
    <template id="portal_rental_request_detail_template" name="Rental Request Detail">
        <t t-call="portal.portal_layout">
            <div class="container py-3">
                <div class="card p-4">
                    <h3>Request <span t-field="rental_request.name"/></h3>
                    <p>Status: <span t-field="rental_request.status"/></p>
                    <div class="row">
                        <div class="col-md-6">
                            <p><strong>Start:</strong> <span t-field="rental_request.start_date"/></p>
                            <p><strong>End:</strong> <span t-field="rental_request.end_date"/></p>
                            <p><strong>Location:</strong> <span t-field="rental_request.location"/></p>
                        </div>
                        <div class="col-md-6 text-right">
                            <p><strong>Total:</strong> <span t-field="rental_request.amount_total" t-options="{'widget': 'monetary', 'display_currency': res_company.currency_id}"/></p>
                            <a t-if="rental_request.sale_order_id" t-att-href="rental_request.sale_order_id.get_portal_url()" class="btn btn-primary">Pay Quotation</a>
                        </div>
                    </div>
                    <h5 class="mt-4">Requested Products</h5>
                    <table class="table">
                        <thead>
                            <tr>
                                <th>Product</th>
                                <th>Quantity</th>
                                <th>Unit Price</th>
                                <th>Subtotal</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr t-foreach="rental_request.line_ids" t-as="line">
                                <td><span t-field="line.product_id.name"/></td>
                                <td><span t-field="line.quantity"/></td>
                                <td><span t-field="line.price_unit" t-options="{'widget': 'monetary', 'display_currency': res_company.currency_id}"/></td>
                                <td><span t-field="line.price_subtotal" t-options="{'widget': 'monetary', 'display_currency': res_company.currency_id}"/></td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
        </t>
    </template>
</odoo>
