oont-contents/plugins/wpify-woo/build/icdic-blocks.js
2025-04-06 08:34:48 +02:00

1 line
No EOL
6.2 KiB
JavaScript

!function(){"use strict";var e={745:function(e,t,n){var i=n(850);t.s=i.createRoot,i.hydrateRoot},850:function(e){e.exports=window.ReactDOM}},t={};function n(i){var r=t[i];if(void 0!==r)return r.exports;var c=t[i]={exports:{}};return e[i](c,c.exports,n),c.exports}!function(){function e(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,i=Array(t);n<t;n++)i[n]=e[n];return i}function t(t,n){return function(e){if(Array.isArray(e))return e}(t)||function(e,t){var n=null==e?null:"undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(null!=n){var i,r,c,o,l=[],a=!0,u=!1;try{if(c=(n=n.call(e)).next,0===t){if(Object(n)!==n)return;a=!1}else for(;!(a=(i=c.call(n)).done)&&(l.push(i.value),l.length!==t);a=!0);}catch(e){u=!0,r=e}finally{try{if(!a&&null!=n.return&&(o=n.return(),Object(o)!==o))return}finally{if(u)throw r}}return l}}(t,n)||function(t,n){if(t){if("string"==typeof t)return e(t,n);var i={}.toString.call(t).slice(8,-1);return"Object"===i&&t.constructor&&(i=t.constructor.name),"Map"===i||"Set"===i?Array.from(t):"Arguments"===i||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(i)?e(t,n):void 0}}(t,n)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var i=window.React,r=window.wp.data,c=n(745),o=n(850),l=window.wc.wcBlocksData,a=l.CART_STORE_KEY,u=l.CHECKOUT_STORE_KEY,d=(l.COLLECTIONS_STORE_KEY,l.VALIDATION_STORE_KEY),s=function(){var e=window.wc.blocksCheckout.extensionCartUpdate,n=t((0,i.useState)(!1),2),c=n[0],l=n[1],s=t((0,i.useState)(),2),f=s[0],y=s[1],p=t((0,i.useState)(),2),w=p[0],m=p[1],v=t((0,i.useState)(),2),g=v[0],_=v[1],b=t((0,i.useState)(),2),E=b[0],h=b[1],S=((0,r.useSelect)((function(e){return e(a).getCartData()}),[]),(0,r.useSelect)((function(e){return e(a).getCustomerData()}),[])),A=(0,r.useSelect)((function(e){return e(u).getAdditionalFields()}),[]),C=(0,r.useDispatch)(u).setAdditionalFields,T=(0,r.useDispatch)(d),k=(T.showValidationError,T.setValidationErrors,T.showAllValidationErrors,(0,r.useDispatch)(a)),D=k.setBillingAddress,O=k.setShippingAddress,q=(0,r.useSelect)((function(e){return e(d).getValidationError("contact-wpify-dic")}),[]);console.log(q);var I=document.querySelector(".wc-block-components-address-form__wpify-company"),K=document.querySelector(".wc-block-components-address-form__wpify-ic"),L=document.querySelector(".wc-block-components-address-form__wpify-dic"),R=document.querySelector(".wc-block-components-address-form__wpify-dic-dph"),x=document.querySelector(".wc-block-components-address-form__wpify-ic"),U=document.querySelector("#wpify-ares"),j=document.querySelector("#contact-wpify-company"),V=document.querySelector("#contact-wpify-ic"),F=document.querySelector("#contact-wpify-dic"),W=document.querySelector("#contact-wpify-dic-dph");function Y(e){return(e=(e=e.replace(""," ")).replace(/[^a-zA-Z0-9]/g,"").toUpperCase()).match(/^[A-Z]{2}/)?e:S.billingAddress.country+e}function Z(e){return(e=e.replace(""," ")).replace(/\D/g,"")}function N(e,t){return new Promise((function(n,i){fetch(e,t).then((function(e){e.ok?e.json().then(n):e.json().then((function(e){return i(e.message)}))})).catch(i)}))}function P(t){_(null),h(!0),window.wpifyWooIcDic.restUrl&&N(window.wpifyWooIcDic.restUrl+"/icdic-vies?in="+t).then((function(n){var i=n.validation,r=void 0===i?{}:i;"SK"===S.billingAddress.country?A["wpify/dic-dph"]=t:A["wpify/dic"]=t,C(A),e({namespace:"wpify_ic_dic",data:{validation:r,country:S.billingAddress.country}});var c=new CustomEvent("wpify_woo_ic_dic_vies_valid",{detail:{validation:r}});window.dispatchEvent(c)})).catch((function(e){_(e)})).finally((function(){h(!1)}))}(0,i.useEffect)((function(){I&&(R&&(R.style.display="none"),null!=A&&A["wpify/ic_dic_toggle"]?(I.style.display="block",K.style.display="block",L.style.display="block",S.billingAddress.company&&(A["wpify/company"]=S.billingAddress.company)):(I.style.display="none",K.style.display="none",L.style.display="none",A["wpify/company"]="",A["wpify/ic"]="",A["wpify/dic"]="",A["wpify/dic-dph"]="",C(A)),null!=A&&A["wpify/ic_dic_toggle"]&&"SK"===S.billingAddress.country&&(R.style.display="block"),U&&null!=A&&A["wpify/ic_dic_toggle"]&&"CZ"===S.billingAddress.country?U.style.display="block":U&&(U.style.display="none"))}),[A,j,V,F,W,I,K,L,R,S]),(0,i.useEffect)((function(){if(x){var e=document.createElement("div");e.id="wpify-ares",x.appendChild(e),l(!0)}}),[x]),(0,i.useEffect)((function(){if(V&&"CZ"===S.billingAddress.country){var e,t=function(t){clearTimeout(e),e=setTimeout((function(){var e=Z(t.target.value);t.target.value=e,A["wpify/ic"]=e,C(A),B()}),2e3)};return V.addEventListener("input",t),function(){clearTimeout(e),V.removeEventListener("input",t)}}}),[V]),(0,i.useEffect)((function(){if(F||W){var e,t="SK"===S.billingAddress.country?W:F,n=function(t){clearTimeout(e),e=setTimeout((function(){P(Y(t.target.value))}),2e3)};return null==t||t.addEventListener("input",n),function(){clearTimeout(e),null==t||t.removeEventListener("input",n)}}}),[F,W,S.billingAddress.country]);var B=function(){y(null),m(!0);var e=Z(A["wpify/ic"]);N(window.wpifyWooIcDic.restUrl+"/icdic?in="+e).then((function(e){var t=e.details,n=void 0===t?{}:t;A["wpify/company"]=n.billing_company,A["wpify/ic"]=n.billing_ic,A["wpify/dic"]=n.billing_dic,C(A),n.billing_dic&&P(Y(n.billing_dic));var i={company:n.billing_company,address_1:n.billing_address_1,city:n.billing_city,postcode:n.billing_postcode};D(i),O(i);var r=new CustomEvent("wpify_woo_ic_dic_ares_autofilled",{detail:{details:n}});window.dispatchEvent(r)})).catch((function(e){y(e)})).finally((function(){m(!1)}))};return c?(0,i.createElement)("div",null,(0,o.createPortal)((0,i.createElement)(i.Fragment,null,(0,i.createElement)("div",null,(0,i.createElement)("input",{type:"button",className:"button wp-element-button",onClick:function(){return B()},value:window.wpifyWooIcDic.searchAresText}),w&&(0,i.createElement)("div",null,"Loading"),f&&(0,i.createElement)("div",null,f))),U),(0,o.createPortal)((0,i.createElement)(i.Fragment,null,(0,i.createElement)("div",null,E&&(0,i.createElement)("div",null,"Loading"),g&&(0,i.createElement)("div",null,g))),"SK"===S.billingAddress.country?R:L)):null};document.querySelectorAll('[data-app="wpify-ic-dic"]').forEach((function(e){(0,c.s)(e).render((0,i.createElement)(s,null))}))}()}();