/**
 * Copyright since 2025 InPost S.A.
 *
 * For the full license information, please view the LICENSE file bundled with the module.
 *
 * @author InPost S.A.
 * @copyright since 2025 InPost S.A.
 * @license MIT
 */
!function(){"use strict";class t{constructor(t,e,r=null){if(!t)throw new Error("AjaxContentRefresher requires a valid input element.");if(!e||"string"!=typeof e&&!Array.isArray(e))throw new Error("AjaxContentRefresher requires a target selector.");if(this.input=t,this.targetSelectors=Array.isArray(e)?e:[e],this.formDataBuilder=r??this.#t,this.form=this.input.closest("form"),!this.form)throw new Error("The select element must be inside a form.")}init(){this.input.addEventListener("change",this.#e.bind(this))}onContentRefreshed(t){return this.callback=t,this}#e(t){const e=new FormData;this.formDataBuilder(e),fetch(this.form.action,{method:this.form.method,body:new URLSearchParams(e).toString(),headers:{"X-Requested-With":"XMLHttpRequest","Content-Type":"application/x-www-form-urlencoded",charset:"utf-8"}}).then(t=>{if(!t.ok&&422!==t.status)throw new Error(`HTTP error! status: ${t.status}`);return t.text()}).then(t=>(new DOMParser).parseFromString(t,"text/html")).then(t=>{this.targetSelectors.forEach(e=>{const r=t.querySelector(e),n=document.querySelector(e);if(!r||!n)throw new Error(`Could not find target element or new content for selector: ${e}`);r.querySelectorAll(".invalid-feedback-container").forEach(t=>t.remove()),n.innerHTML=r.innerHTML}),"function"==typeof this.callback&&this.callback()}).catch(t=>{console.error("Error during content refresh:",t)})}#t(t){t.append(this.input.name,this.input.value)}}$(()=>{const e=document.querySelector(".js-inpost-intl-closest-point-search-mode-choice");e&&new t(e,".js-inpost-intl-geocoder-options-wrapper").init()})}();