/** @odoo-module
 *
 * OrderTabs patch — gate every tab-driven order switch and the "+" new
 * order button through pos.confirmExitSettleIfNeeded so the cashier
 * cannot silently leave a live settle-due order behind.
 *
 * Both methods stay async to align with their existing signatures.
 */
import { patch } from "@web/core/utils/patch";
import { OrderTabs } from "@point_of_sale/app/components/order_tabs/order_tabs";

patch(OrderTabs.prototype, {
    async selectFloatingOrder(order) {
        const allowed = await this.pos.confirmExitSettleIfNeeded(order);
        if (!allowed) {
            return;
        }
        return super.selectFloatingOrder(order);
    },

    async newFloatingOrder() {
        const allowed = await this.pos.confirmExitSettleIfNeeded(null);
        if (!allowed) {
            return;
        }
        return super.newFloatingOrder();
    },
});
