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AAYnF,KACnD,GAAIiF,EAAS,CACT,IAAIG,EAAgBjI,EAAOwB,KAAK0G,eAC5BC,EAAoBnI,EAAOwB,KAAK4G,cACpCH,EAAgBA,EAAgB,QAAUD,EAAYnF,IAAM,SAAWiF,EAAU,aAAeE,EAAYR,SAC5GW,EAAoBA,EAAoB,QAAUH,EAAYnF,IAAM,SAAWiF,EAC/E,IAAIO,EAAYL,EAAYR,SAAW,EAAIS,EAAgBE,EAC3DlI,EAAEwD,KAAK,CACHC,IAAK2E,EACLZ,OAAQ,MACR7D,QAAS,WACLqD,GAAS,EACb,EACAlB,MAAO,SAAUA,GACbE,QAAQC,IAAI,2CAA4CH,GACxDkB,GAAS,EACb,GAER,MACIA,GAAS,EAEjB,IAEAnG,EAAckB,GAAG,iBAAiB,WAC9BlB,EAAcwH,WAAWtI,EAAOwB,KAAK+G,SACzC,GACJ,C","sources":["webpack:///./cartridges/app_custom_mufe/cartridges/app_custom_mufe/cartridge/client/default/js/bambuserOneToOne.js"],"sourcesContent":["'use strict';\n\nvar config = $('.js_bambuser-otoconfig').data('config');\n\nvar orgId = config.orgId;\nvar smartVariantOverride = config.smartVariantOverride;\nvar triggers = config.triggers;\n\nconst storeApi = {};\nvar basketProductLineItems = {};\nwindow.localStorage.setItem('basketProductLineItems', JSON.stringify({}));\n\nstoreApi.getProduct = (productIdentifier, bambuserId) => {\n    var dataProduct = config.urls.productData;\n    var productId = productIdentifier ? productIdentifier.split('/').pop().split('-').pop().split('.')[0] : '';\n    dataProduct = dataProduct + '?sku=' + productId;\n    if (bambuserId) {\n        dataProduct = dataProduct + '&id=' + bambuserId;\n    }\n    $.ajax({\n        url: dataProduct,\n        type: 'get',\n        dataType: 'json',\n        success: function (data) {\n            var bambuserProduct = data.product;\n            return Promise.resolve(bambuserProduct);\n        },\n        error: function (err) {\n            console.log('error', err);\n            return Promise.resolve({});\n        }\n    });\n};\n\n//======================================== Bambuser onReady Handler ==============================================\nwindow.onBambuserOneToOneReady = function(BambuserOneToOneEmbed) {\n    // This method will be invoked when embed.js has loaded and Bambuser\n    // One-to-One API is available.\n    // Creating an instance directly will allow to detect connect links \n    // that will automatically open the Live Meeting overlay on page load.\n    let oneToOneEmbed = new BambuserOneToOneEmbed({\n        orgId: orgId, // REPLACE THIS WITH YOUR OWN ORG ID\n        //  queue: 'QUEUE_ID_HERE', //if not specified, default queue configured from the dashboard will get applied\n\n        // ACTIVATE OVERLAY WIDGET\n        // The Overlay Widget (OLW) is an easy way to guide more visitors into the Call Widget.\n        // By appearing automatically after configurable amount of seconds it guides visitors towards sales help at the right time.\n        smartVariantOverride: smartVariantOverride, // Other options are 'Video', 'Avatar' and 'Side dock'\n\n        // trigger 'smart' :activate the overlay widget\n        // trigger 'connect-link' : activate the connect link - Unrelated to OLW, yet mandatory\n        triggers: triggers,\n\n        popupTimeoutSeconds: '2', // after how many seconds OLW appears on the first time page load (default = 60)\n\n        // PROVIDE CUSTOMER DATA\n        // Below information will be presented to the Agent during a call\n        // You can either provide Build-in properties or custom properties\n        // A full list of build in properties can be found on \n        // https://bambuser.com/docs/one-to-one/present-customer-data-to-agent/\n        data: {\n            firstName: '',\n            lastName: '',\n            email: ''\n        },\n\n        // Bambuser follow  ISO 639-1 Code + \"-\" + ISO 3166-2 as standard locale format.\n        // The value should be of type string\n        locale: config.locale, // Call Widget language translation for the end user (default='en-US')\n        allowFirstPartyCookies: true, // Configures if embed script is allowed to write first party cookies for tracking purposes (default=true)\n        enableScanning: false, // Agent app will scan for barcodes and QR codes when adding product through scanning (default=false)\n        enableCartQuantitySum: true,\n        merchantBaseUrl: config.urls.home\n    });\n\n    oneToOneEmbed.areQueuesOpen().then((response) => {\n        // Disable a button if the queue is closed\n        if (response.isOpen === false) {\n            if ($('.isBrandPage').length) {\n                $(\"#makeup-video-call .btn-shade-finder\").attr('disabled', true);\n            }\n        } else {\n            if ($('.isBrandPage').length) {\n                $(\"#makeup-video-call .start-one-to-one\").attr('disabled', false);\n            }\n        }\n    });\n\n    // Connect CTA button to open Bambuser One-to-One overlay.\n    let button = $('.start-one-to-one');\n\n    button.on('click' , function() {\n        oneToOneEmbed.show();\n        if ($('.isBrandPage').length) {\n            var oneToOneHash = $(this).parents('#makeup-video-call').attr('id');\n            window.location.hash = oneToOneHash;\n        }\n        if ($(this).hasClass('closed')) {\n            window.location = config.urls.brand;\n        }\n    });\n\n    // The Call Widget triggeres 'provide-product-data' event when:\n    // 1. When an Agent enters a product identifier in the Agent Tool UI\n    // 2. When an Agent clicks on the \"Recent Product\" in the Agent Tool UI\n    // 3. When an Agent clicks on the \"Related Product\" in the Agent Tool UI\n    oneToOneEmbed.on('provide-product-data', (event) => {\n        event.products.forEach(({ref, type, id: bambuserId}) => {\n            // Mandatory to handle at least URL and SKU\n            // Use the references provided above to fetch your product object\n            // Provide product data to the widget using the methods below.\n\n            // type: \"url\" | \"product-reference\" | \"scanned-code\"\n            let sku;\n            if (type === 'url') {\n                var productId = ref && ref.split('/').pop() && ref.split('/').pop().split('-').length > 0 && ref.split('/').pop().split('-').pop().split('.').length > 0 ? ref.split('/').pop().split('-').pop().split('.')[0] : '';\n                if (!productId) {\n                    return Promise.resolve({});\n                }\n                sku = productId;\n            } else if (type === 'product-reference') {\n                sku = ref;\n            }\n\n            var dataProduct = config.urls.productData;\n            dataProduct = dataProduct + '?sku=' + sku;\n            if (bambuserId) {\n                dataProduct = dataProduct + '&id=' + bambuserId;\n            }\n\n            $.ajax({\n                url: dataProduct,\n                type: 'get',\n                dataType: 'json',\n                success: function (data) {\n                    var yourProduct = data.product;\n                    // Product mapping\n                    oneToOneEmbed.updateProduct(bambuserId, (productFactory) => {\n                        if (yourProduct.options) {\n                            return (\n                                productFactory\n                                    .currency(config.currency)\n                                    .locale(config.locale)\n                                    .product((detailFactory) =>\n                                        detailFactory\n                                            .name(yourProduct.title)\n                                            .sku(yourProduct.productId)\n                                            .description(yourProduct.description)\n                                            .url(window.location.origin + yourProduct.slug)\n                                            .attributes((attribute) => {\n                                                return yourProduct.options.map((attr) =>\n                                                    attribute(attr.optionId)\n                                                        .name(attr.name)\n                                                        .options((option) =>\n                                                            attr.values.map((optionName) =>\n                                                                option(optionName)\n                                                                    .name(optionName)\n                                                            )\n                                                        )\n                                                );\n                                            }).variations((variationFactory) =>\n                                                yourProduct.variants.map((variation) =>\n                                                    variationFactory()\n                                                        .name(variation.title)\n                                                        .url(window.location.origin + variation.slug)\n                                                        .subtitle(yourProduct.brand)\n                                                        .sku(variation.variationId)\n                                                        .inStock(variation.available)\n                                                        .imageUrls(variation.images)\n                                                        .price((priceFactory) =>\n                                                            priceFactory\n                                                                .original(variation.original_price)\n                                                                .current(variation.price)\n                                                        )\n                                                        .attributes((attribute) =>\n                                                            yourProduct.options.map((attr) =>\n                                                                attribute(\n                                                                    attr.optionId,\n                                                                    variation['option' + attr.optionId]\n                                                                )\n                                                            )\n                                                        )\n                                                )\n                                            )\n                                    )\n                            );\n                        } else {\n                            return (\n                                productFactory\n                                    .currency(config.currency)\n                                    .locale(config.locale)\n                                    .product((detailFactory) =>\n                                        detailFactory\n                                            .name(yourProduct.title)\n                                            .sku(yourProduct.productId)\n                                            .description(yourProduct.description)\n                                            .url(window.location.origin + yourProduct.slug)\n                                            .variations((variationFactory) =>\n                                                yourProduct.variants.map((variation) =>\n                                                    variationFactory()\n                                                        .name(variation.title)\n                                                        .url(window.location.origin + variation.slug)\n                                                        .subtitle(yourProduct.brand)\n                                                        .sku(variation.variationId)\n                                                        .inStock(variation.available)\n                                                        .imageUrls(variation.images)\n                                                        .price((priceFactory) =>\n                                                            priceFactory\n                                                                .original(variation.original_price)\n                                                                .current(variation.price)\n                                                        )\n                                                )\n                                            )\n                                    )\n                            );\n                        }\n                    });\n                },\n                error: function (err) {\n                    console.log('error', err);\n                }\n            });\n        });\n    });\n\n    oneToOneEmbed.on('provide-search-data', (searchRequest, searchResponse) => {\n        const { term, page } = searchRequest;\n        if (term.length < 2) {\n            return searchResponse(response => {\n                return response.products(p => []) // eslint-disable-line no-unused-vars\n                    .currency(config.currency)\n                    .locale(config.locale)\n                    .pagination(p => p\n                        .totalPages(0)\n                        .totalMatches(0)\n                        .currentPageIndex(0)\n                    )\n            })\n        }\n\n        $.ajax({\n            url: config.urls.search + term + '&page=' + page,\n            type: 'get',\n            dataType: 'json',\n            success: function (yourSearchResponse) {\n                return searchResponse(response => {\n                    return response.products(p => {\n                        const results = yourSearchResponse.products.map(prod => {\n                            return p()\n                                .name(prod.name)\n                                .imageUrl(prod.imageUrl)\n                                .sku(prod.sku)\n                                .price(price => price\n                                    .current(prod.price.current)\n                                    .original(prod.price.original || null)\n                                )\n                        });\n                        return results;\n                    })\n\n                        .currency(config.currency)\n                        .locale(config.locale)\n\n                        .pagination(p => p\n                            .totalPages(yourSearchResponse.pagination.totalPages)\n                            .totalMatches(yourSearchResponse.pagination.totalMatches)\n                            .currentPageIndex(yourSearchResponse.pagination.page)\n                        )\n                })\n            },\n            error: function (err) {\n                console.log('error', err);\n            }\n        });\n    });\n\n    oneToOneEmbed.on('should-add-item-to-cart', (addedItem, callback) => {\n        basketProductLineItems = JSON.parse(window.localStorage.getItem('basketProductLineItems'));\n        var addToCartUrl = config.urls.addToCart;\n        var form = {\n            pid: addedItem.sku,\n            quantity: addedItem.quantity || 1\n        };\n        $.ajax({\n            url: addToCartUrl,\n            method: 'POST',\n            data: form,\n            success: function (data) {\n                Object.defineProperty(basketProductLineItems, addedItem.sku, {\n                    enumerable: true,\n                    value: data.pliUUID\n                });\n                window.localStorage.setItem('basketProductLineItems', JSON.stringify(basketProductLineItems));\n                callback(true);\n            },\n            error: function (e) {\n                console.log('add to cart error:', e);\n                callback(false);\n            }\n        });\n    });\n\n    oneToOneEmbed.on('should-update-item-in-cart', (updatedItem, callback) => {\n        basketProductLineItems = JSON.parse(window.localStorage.getItem('basketProductLineItems'));\n        const pliUUID = basketProductLineItems[updatedItem.sku];\n        if (pliUUID) {\n            var updateCartUrl = config.urls.updateQuantity;\n            var removeLineItemUrl = config.urls.removeProduct;\n            updateCartUrl = updateCartUrl + '?pid=' + updatedItem.sku + '&uuid=' + pliUUID + '&quantity=' + updatedItem.quantity;\n            removeLineItemUrl = removeLineItemUrl + '?pid=' + updatedItem.sku + '&uuid=' + pliUUID;\n            var updateUrl = updatedItem.quantity > 0 ? updateCartUrl : removeLineItemUrl;\n            $.ajax({\n                url: updateUrl,\n                method: 'GET',\n                success: function () {\n                    callback(true);\n                },\n                error: function (error) {\n                    console.log('data update cart remove from cart error:', error);\n                    callback(false);\n                }\n            });\n        } else {\n            callback(true);\n        }\n    });\n\n    oneToOneEmbed.on('goto-checkout', () => {\n        oneToOneEmbed.floatAbove(config.urls.checkout);\n    });\n}"],"names":["config","$","data","orgId","smartVariantOverride","triggers","basketProductLineItems","window","localStorage","setItem","JSON","stringify","onBambuserOneToOneReady","BambuserOneToOneEmbed","oneToOneEmbed","popupTimeoutSeconds","firstName","lastName","email","locale","allowFirstPartyCookies","enableScanning","enableCartQuantitySum","merchantBaseUrl","urls","home","areQueuesOpen","then","response","isOpen","length","attr","on","show","oneToOneHash","this","parents","location","hash","hasClass","brand","event","products","forEach","_ref","sku","ref","type","bambuserId","id","productId","split","pop","Promise","resolve","dataProduct","productData","ajax","url","dataType","success","yourProduct","product","updateProduct","productFactory","options","currency","detailFactory","name","title","description","origin","slug","attributes","attribute","map","optionId","option","values","optionName","variations","variationFactory","variants","variation","subtitle","variationId","inStock","available","imageUrls","images","price","priceFactory","original","original_price","current","error","err","console","log","searchRequest","searchResponse","term","page","p","pagination","totalPages","totalMatches","currentPageIndex","search","yourSearchResponse","prod","imageUrl","addedItem","callback","parse","getItem","addToCartUrl","addToCart","form","pid","quantity","method","Object","defineProperty","enumerable","value","pliUUID","e","updatedItem","updateCartUrl","updateQuantity","removeLineItemUrl","removeProduct","updateUrl","floatAbove","checkout"],"sourceRoot":""}