{"version":3,"file":"default/js/login.js","mappings":";;;;;;;;;;AAAA;AACa;;AAEb,qBAAqB,mBAAO,CAAC,iIAAgC;AAC7D,8BAA8B,mBAAO,CAAC,uIAAmC;AACzE;AACA;AACA;;;AAGA;AACA;AACA,6BAA6B,cAAc;AAC3C;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA,4EAA4E;AAC5E,4DAA4D;;AAE5D;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,oBAAoB,kBAAkB;AACtC;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,sBAAsB;AACtB;AACA;AACA;AACA,iBAAiB;AACjB;AACA;AACA;AACA,sBAAsB;AACtB;AACA;AACA;AACA;AACA,aAAa;AACb;AACA,SAAS;AACT,KAAK;;AAEL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,sBAAsB;AACtB;AACA;AACA;AACA,iBAAiB;AACjB;AACA;AACA;AACA,sBAAsB;AACtB;AACA;;AAEA;AACA;AACA,aAAa;AACb;AACA,SAAS;AACT,KAAK;;AAEL;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,sBAAsB;AACtB;AACA;AACA;AACA;AACA;AACA;AACA,0BAA0B;AAC1B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,iBAAiB;AACjB;AACA;AACA;AACA,aAAa;AACb;AACA,SAAS;AACT,KAAK;;AAEL;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;;;;;;;;;;;AClKa;;AAEb;AACA;AACA;AACA,MAAM;AACN;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;;;;;;;;;;;ACZa;;AAEb;AACA;AACA;AACA;AACA,yCAAyC;AACzC;;AAEA;AACA;;;;;;;;;;;ACVa;;AAEb;AACA;AACA,WAAW,SAAS;AACpB,aAAa;AACb;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA,sBAAsB;AACtB;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;;;;;;;UC1CA;UACA;;UAEA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;;UAEA;UACA;;UAEA;UACA;UACA;;;;;;;;;ACtBA;AACa;;AAEb,qBAAqB,mBAAO,CAAC,gFAAQ;;AAErC;AACA,mBAAmB,mBAAO,CAAC,8FAAe;AAC1C,CAAC","sources":["webpack://sfra-startup-kit/./cartridges/app_ballantynes/cartridge/client/default/js/login/login.js","webpack://sfra-startup-kit/./cartridges/app_ballantynes/cartridge/client/default/js/util.js","webpack://sfra-startup-kit/./cartridges/app_storefront_base/cartridge/client/default/js/components/errorNotification.js","webpack://sfra-startup-kit/./cartridges/app_storefront_base/cartridge/client/default/js/components/formValidation.js","webpack://sfra-startup-kit/webpack/bootstrap","webpack://sfra-startup-kit/./cartridges/app_ballantynes/cartridge/client/default/js/login.js"],"sourcesContent":["/* eslint-disable no-undef */\n\"use strict\";\n\nvar formValidation = require(\"base/components/formValidation\");\nvar createErrorNotification = require(\"base/components/errorNotification\");\nconst dayDropdown = document.getElementById(\"dobday\");\nconst monthDropdown = document.getElementById(\"dobmonth\");\nconst yearDropdown = document.getElementById(\"dobyear\");\n\n\n// Fetch all years before the current year\nconst currentYear = new Date().getFullYear();\nfor (let year = currentYear; year >= 1900; year--) {\n    const option = document.createElement(\"option\");\n    option.value = year;\n    option.text = year;\n    if (yearDropdown) yearDropdown.appendChild(option);\n}\n\n// Populate days dropdown by default\nupdateDays();\n\nfunction updateDays() {\n    if (monthDropdown == null || yearDropdown == null || dayDropdown == null) return false;\n    const selectedMonth = monthDropdown.value || new Date().getMonth() + 1; // Default to current month if not selected\n    const selectedYear = yearDropdown.value || currentYear; // Default to current year if not selected\n\n    if (isNaN(selectedMonth) || isNaN(selectedYear)) {\n        // Handle invalid month or year values\n        console.error(\"Invalid month or year\");\n        return;\n    }\n    const daysInMonth = new Date(selectedYear, selectedMonth, 0).getDate();\n    dayDropdown.innerHTML = \"<option value=\\\"\\\">Day</option>\";\n\n    for (let i = 1; i <= daysInMonth; i++) {\n        const option = document.createElement(\"option\");\n        option.value = i < 10 ? \"0\" + i : i;\n        option.text = i;\n        dayDropdown.appendChild(option);\n    }\n}\n\nmodule.exports = {\n    login: function () {\n        $(\"form.login\").submit(function (e) {\n            var form = $(this);\n            e.preventDefault();\n            var url = form.attr(\"action\");\n            form.spinner().start();\n            $(\"form.login\").trigger(\"login:submit\", e);\n            $.ajax({\n                url: url,\n                type: \"post\",\n                dataType: \"json\",\n                data: form.serialize(),\n                success: function (data) {\n                    form.spinner().stop();\n                    if (!data.success) {\n                        formValidation(form, data);\n                        $(\"form.login\").trigger(\"login:error\", data);\n                    } else {\n                        $(\"form.login\").trigger(\"login:success\", data);\n                        location.href = data.redirectUrl;\n                    }\n                },\n                error: function (data) {\n                    if (data.responseJSON.redirectUrl) {\n                        window.location.href = data.responseJSON.redirectUrl;\n                    } else {\n                        $(\"form.login\").trigger(\"login:error\", data);\n                        form.spinner().stop();\n                    }\n                }\n            });\n            return false;\n        });\n    },\n\n    register: function () {\n        $(\"form.registration\").submit(function (e) {\n            var form = $(this);\n            e.preventDefault();\n            var url = form.attr(\"action\");\n            form.spinner().start();\n            $(\"form.registration\").trigger(\"login:register\", e);\n            $.ajax({\n                url: url,\n                type: \"post\",\n                dataType: \"json\",\n                data: form.serialize(),\n                success: function (data) {\n                    form.spinner().stop();\n                    if (!data.success) {\n                        $(\"form.registration\").trigger(\"login:register:error\", data);\n                        formValidation(form, data);\n                    } else {\n                        $(\"form.registration\").trigger(\"login:register:success\", data);\n                        location.href = data.redirectUrl;\n                    }\n                },\n                error: function (err) {\n                    if (err.responseJSON.redirectUrl) {\n                        window.location.href = err.responseJSON.redirectUrl;\n                    } else {\n                        createErrorNotification($(\".error-messaging\"), err.responseJSON.errorMessage);\n                    }\n\n                    form.spinner().stop();\n                }\n            });\n            return false;\n        });\n    },\n\n    resetPassword: function () {\n        $(\".reset-password-form\").submit(function (e) {\n            var form = $(this);\n            e.preventDefault();\n            var url = form.attr(\"action\");\n            form.spinner().start();\n            $(\".reset-password-form\").trigger(\"login:register\", e);\n            $.ajax({\n                url: url,\n                type: \"post\",\n                dataType: \"json\",\n                data: form.serialize(),\n                success: function (data) {\n                    form.spinner().stop();\n                    if (!data.success) {\n                        formValidation(form, data);\n                    } else {\n                        $(\".request-password-title\").text(data.receivedMsgHeading);\n                        $(\".request-password-body\").empty()\n                            .append(\"<p>\" + data.receivedMsgBody + \"</p>\");\n                        if (!data.mobile) {\n                            $(\"#submitEmailButton\").text(data.buttonText)\n                                .attr(\"data-dismiss\", \"modal\");\n                        } else {\n                            $(\".send-email-btn\").empty()\n                                .html(\"<a href=\\\"\"\n                                    + data.returnUrl\n                                    + \"\\\" class=\\\"btn btn-primary btn-block\\\">\"\n                                    + data.buttonText + \"</a>\"\n                                );\n                        }\n                    }\n                },\n                error: function () {\n                    form.spinner().stop();\n                }\n            });\n            return false;\n        });\n    },\n\n    clearResetForm: function () {\n        $(\"#login .modal\").on(\"hidden.bs.modal\", function () {\n            $(\"#reset-password-email\").val(\"\");\n            $(\".modal-dialog .form-control.is-invalid\").removeClass(\"is-invalid\");\n        });\n    }\n};\n","\"use strict\";\n\nmodule.exports = function (include) {\n    if (typeof include === \"function\") {\n        include();\n    } else if (typeof include === \"object\") {\n        Object.keys(include).forEach(function (key) {\n            if (typeof include[key] === \"function\") {\n                include[key]();\n            }\n        });\n    }\n};\n","'use strict';\n\nmodule.exports = function (element, message) {\n    var errorHtml = '<div class=\"alert alert-danger alert-dismissible ' +\n        'fade show\" role=\"alert\">' +\n        '<button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-label=\"Close\">' +\n        '<span aria-hidden=\"true\">&times;</span>' +\n        '</button>' + message + '</div>';\n\n    $(element).append(errorHtml);\n};\n","'use strict';\n\n/**\n * Remove all validation. Should be called every time before revalidating form\n * @param {element} form - Form to be cleared\n * @returns {void}\n */\nfunction clearFormErrors(form) {\n    $(form).find('.form-control.is-invalid').removeClass('is-invalid');\n}\n\nmodule.exports = function (formElement, payload) {\n    // clear form validation first\n    clearFormErrors(formElement);\n    $('.alert', formElement).remove();\n\n    if (typeof payload === 'object' && payload.fields) {\n        Object.keys(payload.fields).forEach(function (key) {\n            if (payload.fields[key]) {\n                var feedbackElement = $(formElement).find('[name=\"' + key + '\"]')\n                    .parent()\n                    .children('.invalid-feedback');\n\n                if (feedbackElement.length > 0) {\n                    if (Array.isArray(payload[key])) {\n                        feedbackElement.html(payload.fields[key].join('<br/>'));\n                    } else {\n                        feedbackElement.html(payload.fields[key]);\n                    }\n                    feedbackElement.siblings('.form-control').addClass('is-invalid');\n                }\n            }\n        });\n    }\n    if (payload && payload.error) {\n        var form = $(formElement).prop('tagName') === 'FORM'\n            ? $(formElement)\n            : $(formElement).parents('form');\n\n        form.prepend('<div class=\"alert alert-danger\" role=\"alert\">'\n            + payload.error.join('<br/>') + '</div>');\n    }\n};\n","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","/* eslint-disable no-undef */\n\"use strict\";\n\nvar processInclude = require(\"./util\");\n\n$(document).ready(function () {\n    processInclude(require(\"./login/login\"));\n});\n"],"names":[],"sourceRoot":""}