(function() {
    'use strict';

    document.addEventListener('contextmenu', function(e) {
        if (e.target.tagName === 'IMG' || e.target.closest('.product-image') || e.target.closest('.no-context')) {
            e.preventDefault();
        }
    });

    document.addEventListener('dragstart', function(e) {
        if (e.target.tagName === 'IMG') {
            e.preventDefault();
        }
    });

    document.addEventListener('selectstart', function(e) {
        if (e.target.closest('.no-select')) {
            e.preventDefault();
        }
    });

    document.addEventListener('copy', function(e) {
        if (e.target.closest('.no-copy') || document.activeElement.closest('.no-copy')) {
            e.preventDefault();
        }
    });

    function protectImages() {
        var images = document.querySelectorAll('.product-image img, .sf-card-image img');
        for (var i = 0; i < images.length; i++) {
            var img = images[i];
            if (img.parentNode.querySelector('.img-protect-overlay')) continue;

            var overlay = document.createElement('div');
            overlay.className = 'img-protect-overlay';
            overlay.style.cssText = 'position:absolute;top:0;left:0;width:100%;height:100%;z-index:2;';
            img.parentNode.style.position = 'relative';
            img.parentNode.appendChild(overlay);
        }
    }

    document.addEventListener('DOMContentLoaded', protectImages);
    document.addEventListener('cart-updated', protectImages);

    var observer = new MutationObserver(function() {
        protectImages();
    });

    document.addEventListener('DOMContentLoaded', function() {
        var content = document.getElementById('content');
        if (content) {
            observer.observe(content, { childList: true, subtree: true });
        }
    });
})();
