<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">define([
    'jquery',
    'Magento_Ui/js/modal/confirm',
    'mage/translate',
    'mage/url',
    'mage/cookies'
],
    (
        $,
        confirm,
        $t,
        url
    ) =&gt; {
    'use strict';

    function _redirect(url) {
        var urlParts, locationParts, forceReload;

        urlParts = url.split('#');
        locationParts = window.location.href.split('#');
        forceReload = urlParts[0] === locationParts[0];

        window.location.assign(url);

        if (forceReload) {
            window.location.reload();
        }
    };

    function checkInsights(form)
    {
        if (window.algoliaConfig
            &amp;&amp; window.algoliaConfig.ccAnalytics.enabled
            &amp;&amp; window.algoliaConfig.ccAnalytics.conversionAnalyticsMode !== 'disabled'
        ) {
            let queryId;
            if (form.find('button[type="submit"]').length
                &amp;&amp; form.find('button[type="submit"]').data('queryid')) {
                queryId = form.find('button[type="submit"]').data('queryid');
            }
            return queryId;
        }
        return '';
    }

    function addToCart(elForm) {
        const form_key = $.cookie('form_key') ? $.cookie('form_key') : false,
              form = $(elForm),
              formData = new FormData(elForm),
              products = [];

        if (form_key) formData.set('form_key', form_key);

        // Check insights / query
        let queryID = checkInsights(form);
        if (queryID.length) {
            formData.set('queryID', queryID);
        }

        products.push(elForm.product.value);

        $.ajax({
            url: form.attr('action'),
            data: formData,
            type: 'post',
            dataType: 'json',
            cache: false,
            contentType: false,
            processData: false,

            /** @inheritdoc */
            success: function(res) {
                $(document).trigger('ajax:addToCart', {
                    'sku': form.data().productSku,
                    'productIds': products,
                    'form': form,
                    'response': res
                });

                if (res.backUrl) {
                    _redirect(res.backUrl)
                }
            },

            /** @inheritdoc */
            error: function(res) {
                $(document).trigger('ajax:addToCart:error', {
                    'sku': form.data().productSku,
                    'productIds': products,
                    'form': form,
                    'response': res
                });
            },

            /** @inheritdoc */
            complete: function(res) {
                if (res.state() === 'rejected') {
                    location.reload();
                }
            }
        });
    }

    function checkAlerts(form)
    {
        let entityId = $(form).find('input[name=product]').val();

        if ([3418,3452].includes(parseInt(entityId))) {
            var requiredPhrase = "New Account";
            var userInput = prompt(`You will be required to create a new Microsoft account to redeem this code.
Please type: "${requiredPhrase}" to continue.`);
            if (!userInput || userInput.toLowerCase() !== requiredPhrase.toLowerCase()) {
                alert("Incorrect input. Product was not added to cart.");
                return false;
            }
        }
        return true;
    }

    function checkAvailability(form) {
        let e = window.event,
            entityId = $(form).find('input[name=product]').val(),
            locale = $.cookie('geoipcountrycode') ? $.cookie('geoipcountrycode') : null;

        $.ajax({
            url: url.build(`restrictions/index/product/id/${entityId}/locale/${locale}`),
            async: false,
            cache: true,
            contentType: "application/json",
            dataType: 'json',
            fail: function(){
                return false;
            },
            success: function (result) {
                if (result.message) {
                    alertUser(e, form, result.message)
                } else {
                    addToCart(form);
                }
            }
        });
    }

    function alertUser(e, form, message) {
        let actionText = $t('Buy Now');

        message = message.replace('%action%', actionText);

        e.stopPropagation();

        confirm({
            content: message,
            actions: {
                /** @inheritdoc */
                confirm: function () {
                    addToCart(form);
                },

                /** @inheritdoc */
                always: function (e) {
                    e.stopImmediatePropagation();
                }
            },
            buttons: [{
                text: $t('Cancel'),
                class: 'action-secondary action-dismiss',
                click: function (event) {
                    this.closeModal(event);
                }
            }, {
                text: actionText,
                class: 'action-primary action-accept',
                click: function (event) {
                    this.closeModal(event, true);
                }
            }]

        });
    }

    return (config, element) =&gt; {
        let $elem = $(element);

        $($elem).on('submit', function(e) {
            e.preventDefault();
            if (checkAlerts(this)) {
                checkAvailability(this);
            }
            // addToCart(this);
        });
    };
});
</pre></body></html>