/**
 * 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";var e={selectAll:".js-choice-table-select-all"},t=window.$,r=function(){function r(){var r=this;t(document).on("change",e.selectAll,function(e){r.handleSelectAll(e)})}return r.prototype.handleSelectAll=function(e){var r=t(e.target),n=r.is(":checked");r.closest("table").find("tbody input:checkbox").prop("checked",n)},r}();class n{constructor(e,t,r=null){if(!e)throw new Error("AjaxContentRefresher requires a valid input element.");if(!t||"string"!=typeof t&&!Array.isArray(t))throw new Error("AjaxContentRefresher requires a target selector.");if(this.input=e,this.targetSelectors=Array.isArray(t)?t:[t],this.formDataBuilder=r??this.#e,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.#t.bind(this))}onContentRefreshed(e){return this.callback=e,this}#t(e){const t=new FormData;this.formDataBuilder(t),fetch(this.form.action,{method:this.form.method,body:new URLSearchParams(t).toString(),headers:{"X-Requested-With":"XMLHttpRequest","Content-Type":"application/x-www-form-urlencoded",charset:"utf-8"}}).then(e=>{if(!e.ok&&422!==e.status)throw new Error(`HTTP error! status: ${e.status}`);return e.text()}).then(e=>(new DOMParser).parseFromString(e,"text/html")).then(e=>{this.targetSelectors.forEach(t=>{const r=e.querySelector(t),n=document.querySelector(t);if(!r||!n)throw new Error(`Could not find target element or new content for selector: ${t}`);r.querySelectorAll(".invalid-feedback-container").forEach(e=>e.remove()),n.innerHTML=r.innerHTML}),"function"==typeof this.callback&&this.callback()}).catch(e=>{console.error("Error during content refresh:",e)})}#e(e){e.append(this.input.name,this.input.value)}}$(()=>{new r;const e=document.querySelector(".js-inpost-intl-carrier-type-choice");e&&new n(e,".js-inpost-intl-countries-wrapper").init()})}();