{"version":3,"file":"Context.js","sources":["requirejs/UI/Context.js"],"sourcesContent":["define([\"require\", \"exports\", \"knockout\", \"Currency\", \"Pages/Cart\", \"UI/Modal\"], function (require, exports, ko, c, cart, m) {\n    \"use strict\";\n    Object.defineProperty(exports, \"__esModule\", { value: true });\n    exports.Context = void 0;\n    var AddToCartTypeEnum;\n    (function (AddToCartTypeEnum) {\n        AddToCartTypeEnum[\"ADD_TO_CART\"] = \"AddToCart\";\n        AddToCartTypeEnum[\"ADD_TO_QUOTE\"] = \"AddToQuote\";\n        AddToCartTypeEnum[\"REQUEST_THIS_ITEM\"] = \"RequestThisItem\";\n    })(AddToCartTypeEnum || (AddToCartTypeEnum = {}));\n    const PunchOutMeta = {\n        countersketch: {\n            atcText: \"Tray\"\n        },\n        matrixgold: {\n            atcText: \"Job\"\n        },\n        everandever: {\n            atcText: \"Cart\"\n        }\n    };\n    class Context {\n        constructor(data) {\n            this.LoadCart = (callback) => {\n                if (this.Cart() != null) {\n                    callback();\n                    return;\n                }\n                $.getJSON(\"/cart/getcart/\").done(x => {\n                    if (this.Cart() == null)\n                        this.Cart(new cart.Cart(x.jsonCart));\n                    callback();\n                });\n            };\n            this.OpenUserTermsForReviewModal = (onCancel) => {\n                if (this.OrderForReviewModal == null) {\n                    this.OrderForReviewModal = new m.Modal({\n                        ModalCssClass: \"\",\n                        Title: \"Order for Product Review/Conditional Sale\",\n                        BodyTemplates: [{\n                                Name: \"/pages/2870/?sectionOnly=true\"\n                            }],\n                        FooterButtons: [{\n                                Text: \"I Agree\",\n                                CssClasses: \"largeButton primary\",\n                                BootstrapCells: \"col-sm-offset-9 col-sm-3\",\n                                Onclick: this.SaveUserTermsForReview\n                            }]\n                    });\n                }\n                this.OrderForReviewModal.OnHide(() => {\n                    if (this.UserNeedsToAgreeToTermsForReview() && onCancel != null)\n                        onCancel();\n                });\n                this.OrderForReviewModal.Open();\n            };\n            this.SaveUserTermsForReview = () => {\n                this.UserNeedsToAgreeToTermsForReview(false);\n                $.ajax({\n                    url: \"/myaccount/accountsettings/UserHasAgreedToOrderForReviewTerms/\",\n                    type: \"POST\",\n                    dataType: \"json\"\n                });\n                if (this.OrderForReviewModal != null)\n                    this.OrderForReviewModal.Close();\n            };\n            ko.mapping.fromJS(data, {\n                Currency: {\n                    create: opts => ko.observable(new c.Currency(Object.assign(Object.assign({}, opts.data), { Locale: data.CurrentCultureName })))\n                }\n            }, this);\n            this.IsUSD = ko.pureComputed(() => this.Currency().Currency() == 'USD');\n            this.GoogleMapApiKey = \"AIzaSyDV9KSt6G6XywbGPuYs4iu4laQPYUfkm3c\";\n            this.Sequence = ko.observable(1);\n            this.RequestId = createGuid();\n            this.StullerFirstTrialData = ko.observable(null);\n            this.Cart = ko.observable(null);\n            this.CanPromoteStullerFirst = ko.computed(() => {\n                if (!data.CanPromoteStullerFirst || this.HasScheduledOrder())\n                    return false;\n                if (this.Cart() == null)\n                    return true;\n                return ko.utils.arrayFirst(this.Cart().CartItems(), c => c.IsHazardous() || c.IsHeavy() || c.IsSingleShipmentItem()) == null;\n            });\n            this.IsInStullerFirstTrial.subscribe(value => {\n                $.post(\"/cart/UpdateShippingWithStullerFirstTrialPromoToggle/\", { optIntoStullerFirst: value }, data => {\n                    this.StullerFirstTrialData(data);\n                }, \"json\");\n            });\n            this.IframeHostApiDomain = ko.computed(() => {\n                var parentDomain = null;\n                if (this.AllowIframeHostApi() && window.sessionStorage) {\n                    parentDomain = window.sessionStorage.getItem(\"IframeHostDomain\");\n                    if (!parentDomain) {\n                        var match = document.referrer.match(/^https?:\\/\\/[^\\/]+/i);\n                        if (match) {\n                            parentDomain = match[0];\n                            window.sessionStorage.setItem(\"IframeHostDomain\", parentDomain);\n                        }\n                    }\n                    if (!(parentDomain && this.AllowIframeHostApiDomainsCsvList() && (this.AllowIframeHostApiDomainsCsvList().split(',').indexOf(parentDomain) !== -1 || this.AllowIframeHostApiDomainsCsvList() == '*'))) {\n                        parentDomain = null;\n                        window.sessionStorage.removeItem(\"IframeHostDomain\");\n                    }\n                }\n                return parentDomain;\n            });\n            this.IsUsingIframeHostApi = ko.computed(() => {\n                return (this.AllowIframeHostApi() && this.IframeHostApiDomain() != null);\n            });\n            this.ShowcaseDisplaySettingsFullySetUp = ko.computed(() => {\n                return !isNullOrEmpty(this.ShowcaseTitle())\n                    && !isNullOrEmpty(this.ShowcasePhoneNumber())\n                    && !isNullOrEmpty(this.ShowcaseEmailAddress());\n            }, this);\n            this.CartCount = ko.computed(() => {\n                return this.Cart() == null ? data.CartCount : this.Cart().CartCount();\n            }, this);\n            this.IsConsultantModeTradeShowOrder = ko.computed(() => {\n                if (!this.IsInConsultantMode())\n                    return false;\n                var consultantModeCookie = readCookie(\"ConsultantMode\");\n                return consultantModeCookie != null && consultantModeCookie.indexOf(\"Show Order\") > 0;\n            });\n            this.AddToCartType = ko.computed(() => {\n                if (this.IsInJewelerShowcase() && !this.HideAddToCart() && !(this.AllowIframeHostApi() && this.IsUsingIframeHostApi())) {\n                    if (this.AddToQuote() == null) {\n                        return AddToCartTypeEnum.REQUEST_THIS_ITEM;\n                    }\n                    return AddToCartTypeEnum.ADD_TO_QUOTE;\n                }\n                return AddToCartTypeEnum.ADD_TO_CART;\n            });\n            this.ShouldShowRequestThisItem = ko.computed(() => {\n                return this.AddToCartType() === AddToCartTypeEnum.REQUEST_THIS_ITEM;\n            });\n            this.AddToCartText = (action) => {\n                var _a;\n                if (this.ShouldShowRequestThisItem()) {\n                    return \"Request this Item\";\n                }\n                action = action || \"Add to\";\n                let target = \"Cart\";\n                const theme = this.PunchOutTheme();\n                if (theme !== '' && ((_a = PunchOutMeta[theme]) === null || _a === void 0 ? void 0 : _a.atcText)) {\n                    return `${action} ${PunchOutMeta[theme].atcText}`;\n                }\n                if (this.IsInJewelerShowcase() && this.IsUsingIframeHostApi() && this.IframeHostAPIButtonText()) {\n                    return `${this.IframeHostAPIButtonText()}`;\n                }\n                return `${action} ${target}`;\n            };\n            this.IsLoggedIn = ko.pureComputed(() => this.LoginId() !== null || this.IsInJewelerShowcase());\n            this.LoginUrl = ko.pureComputed(() => this.GetLoginUrl(window.location));\n        }\n        GetLoginUrl(location) {\n            return '/login/?returnUrl=' + encodeURIComponent(location.pathname + location.search);\n        }\n    }\n    exports.Context = Context;\n    var currentContext;\n    exports.default = currentContext;\n});\n//# sourceMappingURL=Context.js.map"],"names":["define","require","exports","ko","c","cart","m","AddToCartTypeEnum","Object","defineProperty","value","Context","PunchOutMeta","countersketch","atcText","matrixgold","everandever","constructor","data","this","LoadCart","Cart","callback","$","getJSON","done","x","jsonCart","OpenUserTermsForReviewModal","OrderForReviewModal","Modal","ModalCssClass","Title","BodyTemplates","Name","FooterButtons","Text","CssClasses","BootstrapCells","Onclick","SaveUserTermsForReview","OnHide","UserNeedsToAgreeToTermsForReview","onCancel","Open","ajax","url","type","dataType","Close","mapping","fromJS","Currency","create","opts","observable","assign","Locale","CurrentCultureName","IsUSD","pureComputed","GoogleMapApiKey","Sequence","RequestId","createGuid","StullerFirstTrialData","CanPromoteStullerFirst","computed","HasScheduledOrder","utils","arrayFirst","CartItems","IsHazardous","IsHeavy","IsSingleShipmentItem","IsInStullerFirstTrial","subscribe","post","optIntoStullerFirst","IframeHostApiDomain","match","parentDomain","AllowIframeHostApi","window","sessionStorage","getItem","document","referrer","setItem","AllowIframeHostApiDomainsCsvList","split","indexOf","removeItem","IsUsingIframeHostApi","ShowcaseDisplaySettingsFullySetUp","isNullOrEmpty","ShowcaseTitle","ShowcasePhoneNumber","ShowcaseEmailAddress","CartCount","IsConsultantModeTradeShowOrder","IsInConsultantMode","consultantModeCookie","readCookie","AddToCartType","IsInJewelerShowcase","HideAddToCart","ADD_TO_CART","AddToQuote","REQUEST_THIS_ITEM","ADD_TO_QUOTE","ShouldShowRequestThisItem","AddToCartText","_a","action","let","theme","PunchOutTheme","IframeHostAPIButtonText","IsLoggedIn","LoginId","LoginUrl","GetLoginUrl","location","encodeURIComponent","pathname","search","default","currentContext"],"mappings":"AAAAA,OAAO,CAAC,UA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