(function() {
    var code = (document.getElementById('data-referral') || {}).dataset.code || '';
    var shareUrl = (document.getElementById('data-referral') || {}).dataset.shareUrl || '';

    var copyCodeBtn = document.getElementById('copyCode');
    if (copyCodeBtn) {
        copyCodeBtn.addEventListener('click', function() {
            navigator.clipboard.writeText(code).then(function() {
                copyCodeBtn.textContent = 'Copied!';
                setTimeout(function() { copyCodeBtn.textContent = 'Copy'; }, 2000);
            });
        });
    }

    var copyLinkBtn = document.getElementById('copyLink');
    if (copyLinkBtn) {
        copyLinkBtn.addEventListener('click', function() {
            navigator.clipboard.writeText(shareUrl).then(function() {
                copyLinkBtn.textContent = 'Copied!';
                setTimeout(function() { copyLinkBtn.textContent = 'Copy Link'; }, 2000);
            });
        });
    }
})();
