(()=>{/*!
 * Copyright 2024-2025 Simply.IN Sp. z o.o.
 *
 * NOTICE OF LICENSE
 * Licensed under the EUPL-1.2 or later.
 * You may not use this work except in compliance with the Licence.
 * Copy of the Licence is available at: https://joinup.ec.europa.eu/software/page/eupl
 * It is bundled with this package in the file LICENSE.txt
 *
 * @author    Simply.IN Sp. z o.o.
 * @copyright 2024-2025 Simply.IN Sp. z o.o.
 * @license   https://joinup.ec.europa.eu/software/page/eupl
 */$(function(){SimplyIn.initEventListenersNewAccount=function(){let e=this;if(!(e.is_login||simplyin.customer_email!=""&&simplyin.customer_email==e.customer_email)&&simplyin.hide_phone_field!==!0){if(e.phoneCheckboxManager){e.phoneCheckboxManager.showCheckbox(),setTimeout(function(){$(document).off("change.simplyin","#simply-save-checkbox"),$(document).on("change.simplyin","#simply-save-checkbox",function(){var s=$(this).is(":checked"),n="";if(s){$("#simplyin-phone-checkbox .simplyin-phone-input").show();var i=$("#simplyin-phone-checkbox .phone-country-select .prefix").text(),o=$("#simplyin-phone-input").val();n=i+" "+o}else $("#simplyin-phone-checkbox .simplyin-phone-input").hide(),n="0";$.ajax({url:e.ajax,type:"POST",dataType:"json",data:{ajax:!0,action:"storeNewAccountDetails",ajax_token:simplyin.ajax_token,phone:n},success:function(a){a.success},error:function(a,c,p){}})}),$(document).off("change.simplyin","#simplyin-phone-input, #simplyin-phone-country"),$(document).on("change.simplyin","#simplyin-phone-input, #simplyin-phone-country",function(){var s=$("#simply-save-checkbox").is(":checked");if(s){var n=$("#simplyin-phone-checkbox .phone-country-select .prefix").text(),i=$("#simplyin-phone-input").val(),o=n+" "+i;$.ajax({url:e.ajax,type:"POST",dataType:"json",data:{ajax:!0,action:"storeNewAccountDetails",ajax_token:simplyin.ajax_token,phone:o},success:function(a){a.success}})}}),$(document).off("input.simplyin","#simplyin-phone-input"),$(document).on("input.simplyin","#simplyin-phone-input",function(){var s=$("#simply-save-checkbox").is(":checked");if(s){var n=$(this).val();if(n&&n.length>=9){var i=$("#simplyin-phone-checkbox .phone-country-select .prefix").text(),o=i+" "+n;$.ajax({url:e.ajax,type:"POST",dataType:"json",data:{ajax:!0,action:"storeNewAccountDetails",ajax_token:simplyin.ajax_token,phone:o},success:function(a){a.success}})}}})},500);var t=setInterval(function(){var s=$("#simplyin-phone-checkbox .phone-input input");if(s.length>0){clearInterval(t);var n=$('.address-fields input[name="phone"]');if(n.length&&n.val()!==""){var i=n.val();e.phoneCheckboxManager&&typeof e.phoneCheckboxManager.parseAndSetPhoneNumber=="function"&&e.phoneCheckboxManager.parseAndSetPhoneNumber(i)}}},100);setTimeout(function(){clearInterval(t)},5e3);return}if(typeof SimplyInPhoneCheckboxManager<"u"){e.phoneCheckboxManager=new SimplyInPhoneCheckboxManager({checkoutType:"thecheckout",emailFieldSelector:'.account-fields input[name="email"]',containerSelector:"#confirm_order",ajaxUrl:e.ajax,ajaxToken:simplyin.ajax_token,debug:!1}),e.phoneCheckboxManager.showCheckbox(),setTimeout(function(){$(document).off("change.simplyin","#simply-save-checkbox"),$(document).on("change.simplyin","#simply-save-checkbox",function(){var n=$(this).is(":checked"),i="";if(n){$("#simplyin-phone-checkbox .simplyin-phone-input").show();var o=$("#simplyin-phone-checkbox .phone-country-select .prefix").text(),a=$("#simplyin-phone-input").val();i=o+" "+a}else $("#simplyin-phone-checkbox .simplyin-phone-input").hide(),i="0";$.ajax({url:e.ajax,type:"POST",dataType:"json",data:{ajax:!0,action:"storeNewAccountDetails",ajax_token:simplyin.ajax_token,phone:i},success:function(c){c.success},error:function(c,p,l){}})}),$(document).off("change.simplyin","#simplyin-phone-input, #simplyin-phone-country"),$(document).on("change.simplyin","#simplyin-phone-input, #simplyin-phone-country",function(){var n=$("#simply-save-checkbox").is(":checked");if(n){var i=$("#simplyin-phone-checkbox .phone-country-select .prefix").text(),o=$("#simplyin-phone-input").val(),a=i+" "+o;$.ajax({url:e.ajax,type:"POST",dataType:"json",data:{ajax:!0,action:"storeNewAccountDetails",ajax_token:simplyin.ajax_token,phone:a},success:function(c){c.success}})}})},500);var t=setInterval(function(){var n=$("#simplyin-phone-checkbox .phone-input input");if(n.length>0){clearInterval(t);var i=$('.address-fields input[name="phone"]');if(i.length&&i.val()!==""){var o=i.val();e.phoneCheckboxManager&&typeof e.phoneCheckboxManager.parseAndSetPhoneNumber=="function"&&e.phoneCheckboxManager.parseAndSetPhoneNumber(o)}}},100);setTimeout(function(){clearInterval(t)},5e3)}}},SimplyIn.showChangeDataButton=function(){let e=this;if(!(!e.is_login&&!simplyin.customer.has_token||!e.customer_email)&&!($(".simplyin-show-popup").length>0)){var t=$('.account-fields input[name="email"]'),s=$("#static-customer-info-container");if(!(t.length===0&&s.length===0)){var n=t.closest(".form-group"),i=n.length>0?n:s,o=`
            <div class="simplyin-show-popup">
                <div class="simplyin-show-popup-icon">
                    <img width="30" height="30" src="${simplyin.files_url}/views/img/logo_smalln.svg"/>
                    <svg width="12" height="13" viewBox="0 0 12 13" fill="none" xmlns="http://www.w3.org/2000/svg">
                    <rect y="0.5" width="12" height="12" rx="6" fill="#33CC40"></rect>
                    <path d="M3.23096 6.54276L5.07711 8.38892L8.76942 4.38892" stroke="white" stroke-width="1.23077" stroke-linecap="round" stroke-linejoin="round"></path>
                    </svg>
                </div>
                <div class="simplyin-show-popup-edit">
                    <span>${simplyin.labels.data_completed}</span>
                    <div class="simplyin-show-popup-edit-bottom">
                    <span>${simplyin.labels.change}</span>
                    <svg width="14" height="15" viewBox="0 0 14 15" fill="none" xmlns="http://www.w3.org/2000/svg">
                        <path d="M8.41604 2.74719L8.97217 2.19107C9.89359 1.26964 11.3875 1.26964 12.3089 2.19107C13.2304 3.11249 13.2304 4.60641 12.3089 5.52783L11.7528 6.08396M8.41604 2.74719C8.41604 2.74719 8.48556 3.92897 9.5283 4.97171C10.571 6.01445 11.7528 6.08396 11.7528 6.08396M8.41604 2.74719L3.30329 7.85994C2.957 8.20624 2.78385 8.37939 2.63494 8.5703C2.45928 8.79551 2.30868 9.03919 2.18581 9.29701C2.08164 9.51558 2.00421 9.74789 1.84934 10.2125L1.3535 11.7M11.7528 6.08396L6.64006 11.1967C6.29376 11.543 6.12061 11.7162 5.9297 11.8651C5.70449 12.0407 5.46082 12.1913 5.20299 12.3142C4.98442 12.4184 4.75211 12.4958 4.28751 12.6507L2.8 13.1465M2.8 13.1465L1.8375 13.4673C1.60887 13.5435 1.35679 13.484 1.18638 13.3136C1.01596 13.1432 0.956457 12.8911 1.03267 12.6625L1.3535 11.7M2.8 13.1465L1.3535 11.7" stroke="#2D40F6" stroke-width="1.6"></path>
                    </svg>
                    </div>
                </div>
            </div>
        `;i.after(o),$(".simplyin-field-badge").hide(),$(document).off("click.simplyin",".simplyin-show-popup"),$(document).on("click.simplyin",".simplyin-show-popup",function(){e.showLastPopup()})}}},SimplyIn.initOpcTheCheckout=function(){let e=this;if(this.email_field='.account-fields input[name="email"]',$(this.email_field).length){var t=$(this.email_field),s=t.parents(".form-group");if(e.barEnabled()&&$(".simplyin-logo-container").length===0&&t.closest(".account-fields").prepend(e.barHtml()),e.badgeEnabled()&&e.injectFieldBadge(this.email_field),s.length){var n=$.trim(t.val());n&&n!==""?this.customer_email=n:this.customer_email=simplyin.customer_email,this.customer_email&&this.customer_email!==""&&(simplyin.customer_email!=""&&simplyin.customer_email==this.customer_email?e.showChangeDataButton():e.submitEmail(!1)),$(document).off("input",this.email_field),$(document).off("input.simplyin.thecheckout keyup.simplyin.thecheckout",this.email_field),$(document).on("input.simplyin.thecheckout",this.email_field,function(){let i=!1;e.is_login&&e.customer_email!=$(this).val()&&(i=!0);let o=$.trim($(this).val());e.customer_email!=o&&(e.customer_email=o,e.submitEmail(i))})}}else $("#static-customer-info-container").length&&(this.customer_email=simplyin.customer_email,e.barEnabled()&&$(".simplyin-logo-container").length===0&&$("#static-customer-info-container").before(e.barHtml()),this.customer_email&&this.customer_email!==""&&simplyin.customer.has_token&&e.showChangeDataButton());$(document).off("change.simplyin",'.address-fields input[name="phone"]'),$(document).on("change.simplyin",'.address-fields input[name="phone"]',function(){var i=$("#simplyin-phone-checkbox .phone-input input");if(i.length&&i.val()==""){let o=$(this).val();if(o.indexOf("+")===0&&!e.phoneCheckboxManager)return;e.phoneCheckboxManager&&typeof e.phoneCheckboxManager.parseAndSetPhoneNumber=="function"?(e.phoneCheckboxManager.parseAndSetPhoneNumber(o),setTimeout(function(){var a=$("#simply-save-checkbox");if(a.is(":checked")){var c=$("#simplyin-phone-checkbox .phone-country-select .prefix").text(),p=$("#simplyin-phone-input").val(),l=c+" "+p;p&&p!==""&&$.ajax({url:e.ajax,type:"POST",dataType:"json",data:{ajax:!0,action:"storeNewAccountDetails",ajax_token:simplyin.ajax_token,phone:l},success:function(h){h.success}})}},300)):o.indexOf("+")!==0&&i.val(o).trigger("change")}})},SimplyIn.submitEmail=function(e){this.last_popup="";let t=this;if(this.is_login==!1||e){this.is_login=!1;var s=this.customer_email;if(!this.isValidEmailAddress(s)&&this.force_login===!1)return;let n=new URLSearchParams;n.append("action","submitEmail"),n.append("ajax","1"),n.append("ajax_token",simplyin.ajax_token),n.append("email",s),n.append("logout",e),n.append("force_login",this.force_login?"1":"0"),fetch(t.ajax,{method:"POST",body:n}).then(function(i){return i.json()}).then(function(i){i.success&&i.show_popup&&(t.phoneCheckboxManager&&t.phoneCheckboxManager.hideCheckbox(),t.userUsedPushNotifications=i.userUsedPushNotifications,t.last_popup=i.html,t.showPopupByContent(i.html),t.focusOnCode(),t.showIcon(),i.userUsedPushNotifications?t.checkPushNotification():t.codeStartCounting()),i.error=="NOT_FOUND"&&(t.hideIcon(),t.retireOneClickOffer(),s===t.customer_email&&(simplyin.hide_phone_field=!1,t.initEventListenersNewAccount()))})}},SimplyIn.initCheckout=function(){this.initOpcTheCheckout(),simplyin.customer.need_login&&simplyin.controller=="order"&&(simplyin.customer.need_login=!1,this.force_login=!0,this.submitEmail(!1))},simplyin.checkout=="thecheckout"&&SimplyIn.init()});})();
