/** @odoo-module
 *
 * OrderSummary integration:
 *   1. Register the LaundryOrderContextPanel as a child component.
 *   2. Lock numpad-driven mutations (qty / discount / price / remove)
 *      while the active order is in settle-due mode. The settlement
 *      amount is fixed and must not be touched from the order summary.
 */
import { patch } from "@web/core/utils/patch";
import { _t } from "@web/core/l10n/translation";
import { OrderSummary } from "@point_of_sale/app/screens/product_screen/order_summary/order_summary";
import { LaundryOrderContextPanel } from "@laundry_management/js/laundry_order_context_panel";
import { LaundrySettleBanner } from "@laundry_management/js/laundry_settle_banner";

OrderSummary.components = {
    ...(OrderSummary.components || {}),
    LaundryOrderContextPanel,
    LaundrySettleBanner,
};

patch(OrderSummary.prototype, {
    async updateSelectedOrderline(args) {
        const order = this.pos.getOrder();
        if (this.pos.isSettleDueOrder(order)) {
            this.numberBuffer.reset();
            this.pos.notification.add(
                _t("Settlement amount is fixed. Cannot modify from the cart."),
                { type: "warning" }
            );
            return;
        }
        return super.updateSelectedOrderline(args);
    },
});
