/** @odoo-module **/

/**
 * This module intercepts clicks on external Odoo links to prevent
 * referrer leakage when users click help/documentation/upgrade links.
 */

import { browser } from "@web/core/browser/browser";

// Store original window.open
const originalOpen = browser.open;

// Override browser.open to add referrer protection
browser.open = function(url, target, features) {
    if (url && typeof url === 'string') {
        const urlLower = url.toLowerCase();
        
        // Check if it's an Odoo external link
        const odooPatterns = [
            'odoo.com',
            'odoo.sh',
            'accounts.odoo',
        ];
        
        const isOdooLink = odooPatterns.some(pattern => urlLower.includes(pattern));
        
        if (isOdooLink) {
            // For Odoo links, open with noreferrer to prevent leaking your domain
            const newWindow = originalOpen.call(this, url, target || '_blank', 'noopener,noreferrer');
            return newWindow;
        }
    }
    
    return originalOpen.call(this, url, target, features);
};

console.log('[disable_odoo_online] External link protection loaded');

