let e=!1;function t(e){if(!e)return;e.classList.remove("is-open");const t=e.querySelector(".b3-wvs-legacy-select-trigger");t&&t.setAttribute("aria-expanded","false")}function s(e){if(!e)return;document.querySelectorAll(".b3-wvs-legacy-select.is-open").forEach(e=>t(e)),e.classList.add("is-open");const s=e.querySelector(".b3-wvs-legacy-select-trigger");s&&s.setAttribute("aria-expanded","true")}function n(e){const s=e.nextElementSibling;if(!s||!s.classList.contains("b3-wvs-legacy-select"))return;const l=s.querySelector(".b3-wvs-legacy-select-trigger"),c=s.querySelector(".b3-wvs-legacy-select-label"),a=s.querySelector(".b3-wvs-legacy-select-menu");if(!l||!c||!a)return;const i=Array.from(e.options).map(e=>({value:String(e.value),label:String(e.textContent||"").trim(),disabled:e.disabled})),o=i.find(t=>t.value===String(e.value))||i[0];c.textContent=(null==o?void 0:o.label)||"",a.innerHTML="",i.forEach((c,i)=>{if(c.disabled)return;const o=document.createElement("li"),r=c.value===String(e.value);o.id=`${e.id||e.name||"b3-wvs-select"}-option-${i}`,o.setAttribute("role","option"),o.setAttribute("aria-selected",r?"true":"false"),o.className="b3-wvs-legacy-select-option"+(r?" is-selected":""),o.tabIndex=-1,o.innerHTML=`\n      <span class="b3-wvs-legacy-select-label">${c.label}</span>\n      ${r?'<svg class="b3-wvs-legacy-select-check" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">\n               <path fill-rule="evenodd" d="M16.704 4.153a.75.75 0 0 1 .143 1.052l-8 10.5a.75.75 0 0 1-1.127.075l-4.5-4.5a.75.75 0 0 1 1.06-1.06l3.894 3.893 7.48-9.817a.75.75 0 0 1 1.05-.143Z" clip-rule="evenodd" />\n             </svg>':""}\n    `,o.addEventListener("mouseenter",function(){a.querySelectorAll(".b3-wvs-legacy-select-option.is-focused").forEach(e=>e.classList.remove("is-focused")),o.classList.add("is-focused")}),o.addEventListener("mousedown",function(a){a.preventDefault(),e.value=c.value,function(e,t){if(!e)return;const s="function"==typeof window.jQuery?window.jQuery:"function"==typeof t?t:null;s?s(e).trigger("change"):e.dispatchEvent(new Event("change",{bubbles:!0}))}(e,$),n(e),t(s),l.focus()}),a.appendChild(o)})}function l(l,c,a){!function(s){e||(e=!0,s(document).on("mousedown.b3wvsCustomSelect",function(e){s(".b3-wvs-legacy-select.is-open").each(function(){this.contains(e.target)||t(this)})}))}(l);l(c||document).find(a).each(function(){l(this).hasClass("select2-hidden-accessible")||function(e,l){if("1"===e.dataset.b3WvsLegacySelect)return void n(e);e.dataset.b3WvsLegacySelect="1",e.classList.add("b3-wvs-legacy-select-native");const c=document.createElement("div");c.className="b3-wvs-legacy-select";const a=document.createElement("button");a.type="button",a.className="b3-wvs-legacy-select-trigger",a.setAttribute("aria-haspopup","listbox"),a.setAttribute("aria-expanded","false"),a.innerHTML='\n    <span class="b3-wvs-legacy-select-label"></span>\n    <svg class="b3-wvs-legacy-select-chevron" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">\n      <path fill-rule="evenodd" d="M5.22 8.22a.75.75 0 0 1 1.06 0L10 11.94l3.72-3.72a.75.75 0 1 1 1.06 1.06l-4.25 4.25a.75.75 0 0 1-1.06 0L5.22 9.28a.75.75 0 0 1 0-1.06Z" clip-rule="evenodd" />\n    </svg>\n  ';const i=document.createElement("ul");i.className="b3-wvs-legacy-select-menu",i.setAttribute("role","listbox"),a.addEventListener("click",function(){c.classList.contains("is-open")?t(c):s(c)}),a.addEventListener("keydown",function(e){const n=Array.from(i.querySelectorAll(".b3-wvs-legacy-select-option")),l=n.findIndex(e=>e.classList.contains("is-focused"));if("ArrowDown"===e.key){e.preventDefault(),c.classList.contains("is-open")||s(c);const t=l>=0?Math.min(l+1,n.length-1):0;return n.forEach(e=>e.classList.remove("is-focused")),void(n[t]&&(n[t].classList.add("is-focused"),n[t].scrollIntoView({block:"nearest"})))}if("ArrowUp"===e.key){e.preventDefault(),c.classList.contains("is-open")||s(c);const t=l>=0?Math.max(l-1,0):n.length-1;return n.forEach(e=>e.classList.remove("is-focused")),void(n[t]&&(n[t].classList.add("is-focused"),n[t].scrollIntoView({block:"nearest"})))}if("Enter"===e.key||" "===e.key){if(e.preventDefault(),!c.classList.contains("is-open"))return void s(c);const t=n[l]||i.querySelector(".b3-wvs-legacy-select-option.is-selected");return void(null==t||t.dispatchEvent(new MouseEvent("mousedown",{bubbles:!0})))}"Escape"===e.key&&t(c)}),c.appendChild(a),c.appendChild(i),e.insertAdjacentElement("afterend",c),l(e).on("change.b3wvsLegacySelect",function(){n(e)}),n(e)}(this,l)})}export{l as i};
