/** @odoo-module **/

import {Component} from "point_of_sale.Registries";
import ProductScreen from "point_of_sale.ProductScreen";
const { onMounted } = owl;    

const PosRequiredCustomerProductScreen = (ProductScreen) =>
    class extends ProductScreen {

        setup() {
            super.setup();
            onMounted(async () => {
                if (
                    this.env.pos.config.require_customer === "order" &&
                    !this.env.pos.get_order().get_partner()
                ) {
                    this.onClickPartner();
                }
              });
        }

        async _onClickPay() {
            if (
                (this.env.pos.config.require_customer === "order" || 
                 this.env.pos.config.require_customer === "payment") &&
                !this.env.pos.get_order().get_partner()
            ) {
                this.onClickPartner();
            }
            else {
                return super._onClickPay(...arguments);
            }
        }

    };

Component.extend(ProductScreen, PosRequiredCustomerProductScreen);
export default ProductScreen;