import{r as i,c as t,h as e,g as s}from"./p-5308bbce.js";const n=':root{--ifx-font-family:"Source Sans 3";font-family:var(--ifx-font-family, sans-serif)}.ifx-multiselect-container{background-color:#FFFFFF;position:relative;box-sizing:border-box;font-family:var(--ifx-font-family)}.ifx-multiselect-container.small-select{height:36px}.ifx-multiselect-container.medium-select{height:40px}.ifx-multiselect-container:hover{cursor:pointer}.ifx-multiselect-container .ifx-label-wrapper{font-size:1rem;line-height:1.5rem;white-space:pre-wrap;word-wrap:break-word;overflow-wrap:anywhere;max-width:100%}.ifx-multiselect-container .ifx-error-message-wrapper{color:#CD002F;font-size:0.75rem;line-height:1rem;white-space:pre-wrap;word-wrap:break-word;overflow-wrap:anywhere;max-width:100%}.ifx-multiselect-container .ifx-multiselect-wrapper{box-sizing:border-box;position:relative;display:flex;align-items:center;border:1px solid #8D8786;border-radius:1px;width:100%;font-weight:400;font-style:normal}.ifx-multiselect-container .ifx-multiselect-wrapper.small-select{height:36px;padding:8px 12px;font-size:0.875rem;line-height:1.25rem}.ifx-multiselect-container .ifx-multiselect-wrapper.medium-select{height:40px;padding:8px 16px;font-size:1rem;line-height:1.5rem}.ifx-multiselect-container .ifx-multiselect-wrapper:focus-visible{outline:none}.ifx-multiselect-container .ifx-multiselect-wrapper:focus-visible:not(.active):not(:active){outline:none}.ifx-multiselect-container .ifx-multiselect-wrapper:focus-visible:not(.active):not(:active)::before{content:"";position:absolute;width:calc(100% + 4px);height:calc(100% + 4px);top:50%;left:50%;transform:translate(-50%, -50%);border:2px solid #0A8276;border-radius:2px}.ifx-multiselect-container .ifx-multiselect-wrapper.disabled{background:#EEEDED;color:#575352;border-color:#575352;cursor:not-allowed;-webkit-user-select:none;-ms-user-select:none;user-select:none}.ifx-multiselect-container .ifx-multiselect-wrapper.error{border-color:#CD002F}.ifx-multiselect-container .ifx-multiselect-wrapper:hover:not(.focus,:focus){border-color:#575352}.ifx-multiselect-container .ifx-multiselect-wrapper.active{border-color:#0A8276 !important}.ifx-multiselect-container .ifx-multiselect-wrapper.active .icon-wrapper-up{display:flex;align-items:center;justify-content:center;padding-left:8px}.ifx-multiselect-container .ifx-multiselect-wrapper.active .icon-wrapper-down{display:none}.ifx-multiselect-container .ifx-multiselect-wrapper .icon-wrapper-up{display:none}.ifx-multiselect-container .ifx-multiselect-wrapper .icon-wrapper-down{display:flex;align-items:center;justify-content:center;padding-left:8px}.ifx-multiselect-container .ifx-multiselect-wrapper.is-flipped .ifx-multiselect-dropdown-menu{top:auto;bottom:100%}.ifx-multiselect-container .ifx-multiselect-input{flex-grow:1;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.ifx-multiselect-container .ifx-multiselect-input.placeholder{opacity:0.5}.ifx-multiselect-container .ifx-multiselect-icon-container{margin-left:auto;align-items:center;display:flex}.ifx-multiselect-container .ifx-clear-button{margin-right:8px;display:flex}.ifx-multiselect-container .ifx-multiselect-dropdown-menu{position:absolute;top:100%;left:0;width:100%;margin-top:2px;background-color:#fff;box-shadow:0px 6px 9px 0px rgba(29, 29, 29, 0.1);max-height:300px;overflow-y:auto;z-index:var(--dynamic-z-index, 1)}.ifx-multiselect-container .ifx-multiselect-dropdown-menu .search-input{width:100%;padding:8px 16px;font-size:1rem;line-height:1.5rem;font-style:normal;font-weight:400;box-sizing:border-box;background-color:#FFFFFF;border:none;border-bottom:1px solid #8D8786}.ifx-multiselect-container .ifx-multiselect-dropdown-menu .search-input:focus{outline:none;border:1px solid #0A8276}.ifx-multiselect-container .ifx-multiselect-dropdown-menu .search-input::placeholder{color:#999}.ifx-multiselect-container .option{position:relative;padding:8px 16px;gap:8px;align-items:center;display:flex;font-style:normal;font-weight:400}.ifx-multiselect-container .option.small-select{font-size:0.875rem;line-height:1.25rem}.ifx-multiselect-container .option.medium-select{font-size:1rem;line-height:1.5rem}.ifx-multiselect-container .option:hover{background-color:#EEEDED}.ifx-multiselect-container .option:focus{background-color:#BFBBBB;outline:none}.ifx-multiselect-container .option.is-highlighted{background-color:#EEEDED}.ifx-multiselect-container .option.sub-option{padding-left:30px;}';function o(i,t){let e;return function s(...n){const o=()=>{clearTimeout(e);i(...n)};clearTimeout(e);e=setTimeout(o,t)}}const l=class{constructor(e){i(this,e);this.ifxSelect=t(this,"ifxSelect",7);this.ifxMultiselectIsOpen=t(this,"ifxMultiselectIsOpen",7);this.currentIndex=0;this.handleSearch=o((i=>{const t=i.value.toLowerCase();if(t===""){this.filteredOptions=this.loadedOptions}else{this.filteredOptions=this.loadedOptions.filter((i=>i.label.toLowerCase().includes(t)))}}),300);this.handleDocumentClick=i=>{const t=i.composedPath();if(!t.includes(this.dropdownElement)){this.dropdownOpen=false;document.removeEventListener("click",this.handleDocumentClick);this.ifxMultiselectIsOpen.emit(this.dropdownOpen)}};this.options=undefined;this.batchSize=50;this.size="medium (40px)";this.disabled=false;this.error=false;this.internalError=false;this.errorMessage="Error";this.label="";this.persistentSelectedOptions=[];this.placeholder="";this.listOfOptions=[];this.dropdownOpen=false;this.dropdownFlipped=undefined;this.maxItemCount=undefined;this.zIndex=1;this.isLoading=false;this.loadedOptions=[];this.filteredOptions=[];this.searchEnabled=true}async loadInitialOptions(){this.isLoading=true;this.internalError=this.error;this.loadedOptions=await this.fetchOptions(0,this.batchSize);this.isLoading=false}async fetchMoreOptions(){this.isLoading=true;const i=await this.fetchOptions(this.loadedOptions.length,this.batchSize);this.loadedOptions=[...this.loadedOptions,...i];this.isLoading=false}handleScroll(i){const t=i.target;const e=Math.floor((t.scrollHeight-t.clientHeight)/2);if(t.scrollTop>=e){this.fetchMoreOptions()}}async fetchOptions(i,t){let e=[];if(typeof this.options==="string"){try{e=JSON.parse(this.options)}catch(i){console.error("Failed to parse options:",i)}}else if(Array.isArray(this.options)){e=this.options}else{console.error("Unexpected value for options:",this.options)}const s=e.slice(i,i+t);if(i===0){const i=s.filter((i=>i.selected));this.persistentSelectedOptions=[...this.persistentSelectedOptions,...i]}return s}componentDidLoad(){setTimeout((()=>{this.positionDropdown()}),500)}componentWillLoad(){this.loadInitialOptions();this.filteredOptions=[...this.loadedOptions]}updateInternalError(){this.internalError=this.error}loadedOptionsChanged(){this.filteredOptions=[...this.loadedOptions]}handleOptionClick(i){this.internalError=false;if(this.isSelectionLimitReached(i)){console.error("Max item count reached");this.internalError=true;this.errorMessage="Please consider the maximum number of items to choose from";return}this.updateSelection(i);this.ifxSelect.emit(this.persistentSelectedOptions)}isSelectionLimitReached(i){let t=i.children?i.children.length:1;return this.maxItemCount&&this.persistentSelectedOptions.length+t>this.maxItemCount&&!this.persistentSelectedOptions.some((t=>t.value===i.value))}updateSelection(i){const t=this.persistentSelectedOptions.some((t=>t.value===i.value));if(i.children&&i.children.length>0){this.handleParentOptionClick(i)}else{this.handleChildOptionClick(i,t)}}handleParentOptionClick(i){const t=i.children.every((i=>this.persistentSelectedOptions.some((t=>t.value===i.value))));if(t){this.persistentSelectedOptions=[...this.persistentSelectedOptions.filter((t=>!i.children.some((i=>i.value===t.value))))]}else{const t=[...i.children.filter((i=>!this.persistentSelectedOptions.some((t=>t.value===i.value))))];this.persistentSelectedOptions=[...this.persistentSelectedOptions,...t]}}handleChildOptionClick(i,t){if(t){this.persistentSelectedOptions=[...this.persistentSelectedOptions.filter((t=>t.value!==i.value))]}else{this.persistentSelectedOptions=[...this.persistentSelectedOptions,i]}}getSizeClass(){return`${this.size}`==="s"?"small-select":"medium-select"}toggleDropdown(){this.dropdownOpen=!this.dropdownOpen;setTimeout((()=>{if(this.dropdownOpen){document.addEventListener("click",this.handleDocumentClick)}this.ifxMultiselectIsOpen.emit(this.dropdownOpen)}),0);this.zIndex=l.globalZIndex++}waitForElement(i,t,e=50){let s=0;function n(){requestAnimationFrame((()=>{const o=i();if(o.length>0||s>e){t(o)}else{s++;n()}}))}n()}handleKeyDown(i){if(this.disabled)return;const t=this.dropdownElement.querySelectorAll(".option");switch(i.code){case"Enter":if(this.dropdownOpen){this.selectItem(t)}else{this.toggleDropdown();this.waitForElement((()=>this.dropdownElement.querySelectorAll(".option")),(i=>{this.updateHighlightedOption(i)}))}break;case"ArrowDown":this.handleArrowDown(t);if(this.dropdownOpen){this.updateHighlightedOption(t)}break;case"ArrowUp":this.handleArrowUp(t);if(this.dropdownOpen){this.updateHighlightedOption(t)}break}}handleWrapperClick(i){this.positionDropdown();if(i.currentTarget===i.target){this.toggleDropdown()}}clearSelection(){this.persistentSelectedOptions=[];this.ifxSelect.emit(this.persistentSelectedOptions)}positionDropdown(){var i;const t=(i=this.el.shadowRoot.querySelector(".ifx-multiselect-wrapper"))===null||i===void 0?void 0:i.getBoundingClientRect();const e=window.innerHeight-t.bottom;const s=t.top;if(s>e&&t.height>e||t.bottom>window.innerHeight){this.dropdownFlipped=true}else{this.dropdownFlipped=false}}updateHighlightedOption(i){i.forEach((i=>i.classList.remove("is-highlighted")));if(this.currentIndex>=0&&this.currentIndex0){this.currentIndex--}else{this.currentIndex=i.length-1}}selectItem(i){const t=this.dropdownElement.querySelector(".option.selected");if(t){t.classList.remove("selected")}const e=i[this.currentIndex];e.classList.add("selected");const s=e.getAttribute("data-value");const n=typeof this.options==="string"?JSON.parse(this.options).map((i=>({value:i.value,label:i.label,children:i.children,selected:i.selected}))):this.options.map((i=>Object.assign({},i)));const o=this.findInOptions(n,s);this.handleOptionClick(o)}renderOption(i,t){var s;const n=this.isOptionIndeterminate(i);const o=i.children?n||this.isOptionSelected(i):this.persistentSelectedOptions.some((t=>t.value===i.value));const l=!o&&this.maxItemCount&&this.persistentSelectedOptions.length>=this.maxItemCount;const r=`checkbox-${i.value}-${t}`;return e("div",null,e("div",{class:`option ${o?"selected":""} \n ${this.getSizeClass()}`,"data-value":i.value,onClick:()=>!l&&this.handleOptionClick(i),tabindex:"0",role:`${((s=i.children)===null||s===void 0?void 0:s.length)>0?"treeitem":"option"}`},e("ifx-checkbox",{id:r,size:"s",value:n?false:o,indeterminate:n,disabled:l}),e("label",{htmlFor:r},i.label)),i.children&&i.children.map(((i,e)=>this.renderSubOption(i,`${t}-${e}`))))}isOptionSelected(i){if(!i.children)return false;return i.children.every((i=>this.persistentSelectedOptions.some((t=>t.value===i.value))))}isOptionIndeterminate(i){if(!i.children)return false;const t=i.children.filter((i=>this.persistentSelectedOptions.some((t=>t.value===i.value)))).length;return t>0&&tt.value===i.value));const o=!n&&this.maxItemCount&&this.persistentSelectedOptions.length>=this.maxItemCount;const l=`checkbox-${i.value}-${t}`;return e("div",{class:`option sub-option ${n?"selected":""} ${this.getSizeClass()}`,"data-value":i.value,role:`${((s=i.children)===null||s===void 0?void 0:s.length)>0?"option":"treeitem"}`,onClick:()=>!o&&this.handleOptionClick(i),tabindex:"0"},e("ifx-checkbox",{id:l,size:"s",value:n,disabled:o}),e("label",{htmlFor:l},i.label))}render(){const i=this.persistentSelectedOptions.filter((i=>{const t=this.persistentSelectedOptions.some((t=>t.children&&t.children.some((t=>t.value===i.value))&&t.selected));return!t})).map((i=>i.label)).join(", ");return e("div",{class:`ifx-multiselect-container`,ref:i=>this.dropdownElement=i},this.label?e("div",{class:"ifx-label-wrapper"},e("span",null,this.label)):null,e("div",{class:`ifx-multiselect-wrapper \n ${this.getSizeClass()} \n ${this.dropdownOpen?"active":""} \n ${this.dropdownFlipped?"is-flipped":""}\n ${this.internalError?"error":""}\n ${this.disabled?"disabled":""}`,tabindex:"0",onClick:i=>this.handleWrapperClick(i),onKeyDown:i=>this.handleKeyDown(i)},e("div",{class:`ifx-multiselect-input \n ${this.persistentSelectedOptions.length===0?"placeholder":""}\n `,onClick:this.disabled?undefined:()=>this.toggleDropdown()},this.persistentSelectedOptions.length>0?i:this.placeholder),this.dropdownOpen&&e("div",{class:"ifx-multiselect-dropdown-menu",onScroll:i=>this.handleScroll(i),style:{"--dynamic-z-index":this.zIndex.toString()}},this.searchEnabled&&e("input",{type:"text",role:"textbox",class:"search-input",onInput:i=>this.handleSearch(i.target),placeholder:"Search..."}),this.filteredOptions.map(((i,t)=>this.renderOption(i,t))),this.isLoading&&e("div",null,"Loading more options...")),e("div",{class:"ifx-multiselect-icon-container"},this.persistentSelectedOptions.length>0&&e("div",{class:"ifx-clear-button",onClick:()=>this.clearSelection()},e("ifx-icon",{icon:"cremove24"})),e("div",{class:"icon-wrapper-up",onClick:this.disabled?undefined:()=>this.toggleDropdown()},e("ifx-icon",{key:"icon-up",icon:"chevronup-16"})),e("div",{class:"icon-wrapper-down",onClick:this.disabled?undefined:()=>this.toggleDropdown()},e("ifx-icon",{key:"icon-down",icon:"chevron-down-16"})))),this.internalError?e("div",{class:"ifx-error-message-wrapper"},e("span",null,this.errorMessage)):null)}get el(){return s(this)}static get watchers(){return{error:["updateInternalError"],loadedOptions:["loadedOptionsChanged"]}}};l.globalZIndex=1;l.style=n;export{l as ifx_multiselect}; //# sourceMappingURL=p-4ef4333d.entry.js.map