!function(){"use strict";var e=window.window.searchAndFilter.frontend.packages.core,t=window.window.searchAndFilter.frontend.packages.core.hooks,l=window.searchAndFilter.frontend.packages.utils,n=window.searchAndFilter.frontend.packages.hooks,o=window.searchAndFilter.frontend.packages.components;function s(){return s=Object.assign?Object.assign.bind():function(e){for(var t=1;t{},i=()=>!0,c=()=>!1,r=({value:n,baseClass:o,label:s,index:a,listboxId:i,activeOptionIndex:c,onSelect:r,updateSelected:u,isActive:p=!1,depth:d=-1,focusInput:h,countLabel:b})=>{const f=(0,t.useRef)(null),g=c===a;return(0,e.h)(e.Fragment,null,(0,e.h)("li",{tabIndex:"-1","aria-selected":g,role:"option","data-option-value":n,className:(0,l.classNames)({[o+"__listbox-option"]:!0,[o+"__listbox-option--selected"]:g,[o+"__listbox-option--active"]:p,[o+"__listbox-option--depth-"+d]:-1!==d}),id:i+"-option--"+n,ref:f,onClick:()=>{r(a)},onMouseMove:()=>{a!==c&&u(a)},onMouseUp:e=>{h()}},s,b?(0,e.h)("span",{className:o+"__listbox-option-count"},b):null))};var u=({listboxRef:n,sourceRef:u,id:p,baseClass:d,className:h,options:b,onClickOutside:f=a,activeOptionIndex:g,onSelectOption:v,onOptionChange:m,shouldRenderOption:x=i,isOptionActive:C=c,focusInput:O,contentOverride:k,showCount:_,noResultsText:w="No results",...y})=>{let I=(0,t.useRef)(null);n&&(I=n);const[N,S]=(0,t.useState)(!0),F=e=>{S(!1),m(e)};(0,t.useEffect)((()=>{if(N){if(I.current){const e=(e=>{if(I.current){const t=I.current.querySelector(`li:nth-child(${e+1})`);if(t)return t}return null})(g);e&&((e,t)=>{parseFloat(t.offsetTop)-parseFloat(e.scrollTop)<0&&(e.scrollTop=t.offsetTop);const l=parseFloat(e.scrollTop)+parseFloat(e.clientHeight);parseFloat(t.offsetTop)+parseFloat(t.clientHeight)>l&&(e.scrollTop=parseFloat(t.offsetTop)-(parseFloat(e.clientHeight)-parseFloat(t.clientHeight)))})(I.current,e)}}else S(!0)}),[g,I]);const L={[d+"__listbox"]:d};h&&(L[h]=!0);const R=(0,t.useMemo)((()=>({role:"listbox"})),[]),E=[];return k||b.forEach(((t,l)=>{x(t)&&E.push((0,e.h)(r,{key:t.value,index:l,value:t.value,label:t.label,activeOptionIndex:g,depth:t.depth,listboxId:p,onSelect:v,updateSelected:F,baseClass:d,isActive:C(t),focusInput:O,countLabel:_?t.countLabel:null}))})),(0,e.h)(o.Popup,s({name:p,id:p,elementProps:R,htmlElement:"ul",className:(0,l.classNames)(L),sourceRef:u,containerRef:I,matchWidth:!0,onClickOutside:f},y),k||E,k||0!==b.length?null:(0,e.h)("li",{className:(0,l.classNames)(d+"__listbox-option",d+"__listbox-option--disabled")},w))};function p(){return p=Object.assign?Object.assign.bind():function(e){for(var t=1;t{},h=({value:s="",icon:a,placeholder:i,showLabel:c,hasClear:r=!0,label:b,isInteractive:f=!0,options:g=[],onChange:v=d,onEnter:m=d,listboxProps:x={},InputComponent:C,clickAction:O="open",onSelectOption:k,shouldRenderOption:_,isOptionActive:w,onKeyDownCallback:y=d,onKeyUpCallback:I=d,onControlEscape:N=d,closeListboxOnScroll:S=!0,updateListboxOnScroll:F=!1,onLoseFocus:L=d,onShowListbox:R,listboxClassName:E,listboxContent:A,hideSuggestionsOnEmpty:P=!1,onClear:T=d,inputClassName:D,showCount:V=!1,inputProps:$,enableSearch:j=!0,noResultsText:M="No results",singularResultsCountText:K="%d result available",pluralResultsCountText:H="%d results available",disabled:U=!1,...B})=>{const q="search-filter-component-combobox-base",z=(0,t.useRef)(null),W=(0,t.useRef)(null),G=(0,t.useRef)(null),J=s,Q=v,X=(0,n.useInstanceId)(h),Y="search-filter-input-combobox-"+X,Z="search-filter-input-combobox-listbox-"+X,{isVisible:ee,toggle:te,position:le}=(0,o.usePopup)(Z),ne=(0,o.useFocusDispatch)(),[oe,se]=(0,t.useState)("text"),ae=(0,t.useMemo)((()=>Array.isArray(g)?g.map((e=>"string"==typeof e?{label:e,value:e}:e)):[]),[g]),[ie,ce]=(0,t.useState)(0),re=(0,t.useMemo)((()=>ae.filter((e=>(""!==e.value||""===s)&&!!e.label&&e.label.toLowerCase().includes(s.toLowerCase())))),[s,ae]);(0,t.useLayoutEffect)((()=>{pe()}),[re]);const ue=e=>!P||""!==e;(0,t.useLayoutEffect)((()=>{ue(J)||fe(!1)}),[J]);const pe=()=>{ce((e=>re.length>0?0:e))},de=()=>{ce((e=>re.length>0?re.length-1:e))},he=e=>{f&&!U&&(ve(!0),be(),ue(s)&&("open"===O?fe(!0):"toggle"===O&&fe()))},be=()=>{f&&!U&&ne({type:"SET",id:Y})},fe=e=>{if(!f||U)return;let t=e;void 0===e&&(t=!ee),te(t),t?R?R({setActiveOption:ce,setFirstOption:pe,filteredOptions:re}):pe():ce(-1)},[ge,ve]=(0,t.useState)(!1),me=(0,t.useCallback)((e=>{ve(!1),fe(!1)}),[]),xe=(0,t.useCallback)((e=>{const t=re[e];k?k(t):Q(t.label),fe(!1),be()}),[re,k]),Ce=(0,t.useCallback)((e=>{ce(e)}),[]),[Oe,ke]=(0,t.useState)(-1),_e=()=>{if(j&&z.current){const e=z.current,t=e.selectionStart;t===e.selectionEnd&&ke(t)}},we=e=>{j&&e.target?.activeElement&&e.target.activeElement.id===Y&&_e()};if((0,t.useEffect)((()=>(document.addEventListener("selectionchange",we),()=>{document.removeEventListener("selectionchange",we)})),[]),!C)return null;const ye=re.length;let Ie;return Ie=0===ye?M:(0,l.getNumericString)(K,H,ye),(0,e.h)(e.Fragment,null,(0,e.h)(C,p({id:Y,icon:a,inputRef:z,controlRef:W,label:b,showLabel:c,hasClear:r,onChange:e=>{Q(e),ue(e)&&(fe(!0),pe(),_e())},onClear:T,value:J,placeholder:i,readOnly:!f,onEnter:m,onClick:he,isInteractive:f,disabled:U,focusInput:be,onSelectOption:k,popupVisible:ee,inputClassName:D,inputProps:{maxlength:"2048",autocomplete:"off",autocorrect:"off",autocapitalize:"off",spellcheck:"false","aria-autocomplete":"list","aria-controls":Z,readOnly:!f,tabIndex:f?null:-1,onKeyDown:e=>{let t="text";const l=0===Oe,n=Oe===e.target?.value?.length;switch(e.keyCode){case 9:fe(!1),ve(!1);break;case 40:!ee&&ue(J)?fe(!0):ee&&ce((e=>ee>0?e-1:e)),t="listbox",e.preventDefault();break;case 13:if(ee&&g[ie])return void xe(ie);m(),e.preventDefault();break;case 32:break;case 36:if(!ee)break;0===ie?l&&(t="listbox"):("listbox"===oe||l)&&(t="listbox",(e=>{pe(),e.preventDefault()})(e));break;case 35:if(!ee)break;ie===re.length-1?n&&(t="listbox"):("listbox"===oe||n)&&(t="listbox",(e=>{de(),e.preventDefault()})(e));break;case 33:t="listbox",(e=>{const t=ie-5;t>=0?ce(t):pe(),e.preventDefault()})(e);break;case 34:t="listbox",(e=>{const t=ie+5;t<=re.length-1?ce(t):de(),e.preventDefault()})(e)}se(t),y(e.keyCode,l,n)},onKeyUp:e=>{switch(e.keyCode){case 27:(e=>{j&&(ee?fe(!1):N(e))})(e);break;case 46:case 8:_e()}I(e.keyCode)},onFocus:()=>{f&&!U&&ve(!0)},onBlur:e=>{f&&!U&&(e.relatedTarget&&G.current.contains(e.relatedTarget)||L(e))},...$},controlProps:{onClick:he,role:"combobox","aria-haspopup":"listbox","aria-expanded":ee,"aria-controls":Z,"aria-active-descendant":ee&&-1!==ie&&re.length>0?Z+"-option--"+re[ie].value:null,tabIndex:f?null:-1,className:(0,l.classNames)(q,{[`${q}--listbox-visible`]:ee,[`${q}--listbox-position-${le}`]:ee&&le?le:null,[`${q}--focused`]:ge,[`${q}--disabled`]:U})},showCount:V,options:g,enableSearch:!U&&j},B)),(0,e.h)("div",{"aria-live":"polite",role:"status",className:q+"__screen-reader-text"},Ie),f?(0,e.h)(u,p({className:E,listboxRef:G,baseClass:q,sourceRef:W,id:Z,options:re,activeOptionIndex:ie,onSelectOption:xe,onOptionChange:Ce,onClickOutside:me,shouldRenderOption:_,isOptionActive:w,closeOnScroll:S,updateOnScroll:F,focusInput:be,contentOverride:A,showCount:V,noResultsText:M},x)):null)};function b(){return b=Object.assign?Object.assign.bind():function(e){for(var t=1;t{const{toggle:S,isVisible:F}=(0,o.usePopup)(c),[L,R]=(0,t.useState)(!1),[E,A]=(0,t.useState)(-1);let P={className:i+"__selection"};d||(P.role="combobox",P.tabindex="0",P["aria-expanded"]="false",P["aria-controls"]=c,P["aria-haspopup"]="listbox",P=(0,l.mergeObjects)(P,a),P["aria-live"]="polite");let T={};const D=e=>{v&&S(e)};if(d)if(T={type:"text",value:C,"aria-labelledby":"yes"===u?r:null,"aria-label":"yes"===u?null:p,id:n,className:i+"__actions-input",onInput:e=>{const t=e.target.value;O(t),D(!0)},tabIndex:v?null:-1,readOnly:!v,placeholder:0===m.length?g:"",...a},h){let e=C?.length>0?C.length:1;0===m.length&&g?.length&&g.length>e&&(e=g.length),T.style={width:`calc( ${e}ch + 6px )`}}else 0===m.length&&(T.placeholder=g);const V={onClick:e=>{D(!0),d&&"function"==typeof e.currentTarget.select&&e.currentTarget.select(),R(!1)},ref:s};d?T=(0,l.mergeObjects)(T,V):P=(0,l.mergeObjects)(P,V);const $=m.length>0;let j=$?m[0].label:"";const M=0===m.length?g:"";return d||h||0!==m.length||(P.className+=` ${i}__selection-placeholder`,j=g),(0,e.h)(e.Fragment,null,h&&(0,e.h)("div",P,m.map(((t,l)=>{let n="";return L&&l===m.length-1&&(n=" "+i+"__selection-item--active"),(0,e.h)("div",{key:l,className:i+"__selection-item"+n},(0,e.h)("div",{className:i+"__selection-label"},t.label,N&&(0,e.h)("span",{className:i+"__selection-count"},t.countLabel)),(0,e.h)(o.Icon,{icon:"clear",className:i+"__selection-remove",onClick:e=>{y(t),I(),e.stopPropagation(),e.preventDefault()}}))})),d&&(0,e.h)("input",b({},T,{placeholder:M})),!d&&0===m.length&&(0,e.h)("div",{className:i+"__selection-placeholder"},M)),!h&&(0,e.h)(e.Fragment,null,""===C&&(0,e.h)("div",P,j,N&&$?(0,e.h)("span",{className:i+"__selection-count"},m[0].countLabel):null),d&&(0,e.h)("input",T)))};f.templateVars=["selectionLabel","placeholderText",["multiple",{type:"control"}],["selection",{type:"list",child:{type:"object",props:["label"]}}]];var g=f,v=({baseClass:t,show:n,onClick:s=()=>{}})=>(0,e.h)("div",{className:(0,l.classNames)({[t+"__clear-selection"]:!0,[t+"--hidden"]:!n})},(0,e.h)(o.Icon,{icon:"clear",onClick:s,isInteractive:!0,isDestructive:!0,label:"Clear selection"}));function m(){return m=Object.assign?Object.assign.bind():function(e){for(var t=1;t{const a="search-filter-component-combobox",{id:i,icon:c,inputRef:r,controlRef:u,label:p,showLabel:d,hasClear:h=!0,onChange:b,value:f,placeholder:C,labelProps:O,isInteractive:k,inputProps:_,controlProps:w,options:y,fieldValue:I,setFieldValue:N,onSelectOption:S,onClear:F,multiple:L,enableSearch:R=!0,scale:E=4,escClears:A,focusInput:P,description:T,showDescription:D,inputClassName:V,showCount:$}=s,j=`search-filter-listbox-${i}`,M=(0,n.useInstanceId)(x),K=i??"search-filter-input-combobox-"+M;(0,o.useFocusEvent)(r,K);const H="search-filter-label-"+(0,n.useInstanceId)(o.Label);let U={};R?U=w:(U.className=w.className,U.onClick=w.onClick);const B=[a+"__actions"];!1===L&&0===I.length&&B.push(a+"__actions--empty");const[q,z]=(0,t.useState)([]);(0,t.useEffect)((()=>{if(!y)return;const e=[];I.forEach((t=>{const l=y.findIndex((e=>e.value===t));-1!==l&&e.push(y[l])})),z(e)}),[y,I]);const W=q.length>0;return(0,e.h)(e.Fragment,null,(0,e.h)(o.Label,m({showLabel:d,label:p,id:H,forId:K,isInteractive:k},O)),(0,e.h)(o.Description,{description:T,showDescription:D}),(0,e.h)("div",m({},U,{"aria-labelledby":"yes"===d?H:null,"aria-label":"yes"===d?null:p,ref:u,className:(0,l.classNames)(w.className,a,V,`${a}--mode-${L?"multiple":"single"}`,`${a}--search-${R?"enabled":"disabled"}`,{[`${a}--has-icon`]:c})}),(0,e.h)("div",{className:a+"__header"},c&&(0,e.h)(o.Icon,{icon:c,className:a+"__icon"}),(0,e.h)("div",{className:(0,l.classNames)(B)},(0,e.h)(g,{baseClass:a,listboxId:j,inputId:K,labelId:H,showLabel:d,label:p,inputRef:r,inputProps:_,multiple:L,enableSearch:R,interactive:k,selection:q,fieldValue:I,searchValue:f,setFieldValue:N,setSearchValue:b,escClears:A,placeholder:C,toggleOption:S,focusInput:P,showCount:"yes"===$})),(0,e.h)(v,{baseClass:a,show:h&&W,onClick:e=>{"click"===e.type&&e.stopPropagation(),N([]),F?F():b(""),P()}}),(0,e.h)("div",{className:a+"__listbox-toggle"},(0,e.h)(o.Icon,{icon:"arrow-down"})))))};var C=window.searchAndFilter.frontend.packages.registry;(0,C.register)(["packages","components"],"ComboboxControl",(l=>{const n=l.value,o=l.onChange,[s,a]=(0,t.useState)(""),i=(0,t.useCallback)((e=>!(l.multiple&&(!l.multiple||l.hideSelectedOptions))&&n.includes(e.value)),[n]),c=(0,t.useCallback)((e=>!l.multiple||!l.hideSelectedOptions||!n.includes(e.value)),[n]);return(0,e.h)(h,m({InputComponent:x},l,{clickAction:"toggle",fieldValue:n,setFieldValue:o,value:s,onChange:a,onSelectOption:e=>{a(""),(e=>{l.enableSearch&&a("");let t=[...n];if(l.multiple){const l=n.findIndex((t=>t===e.value));-1!==l?(t.splice(l,1),o(t)):t.push(e.value)}else t=[e.value];o(t)})(e)},isOptionActive:i,shouldRenderOption:c,onLoseFocus:e=>{a("")},onControlEscape:l.escClears?()=>{s.length>0?a(""):!l.multiple&&n.length>0&&o([])}:void 0,onShowListbox:({setActiveOption:e,setFirstOption:t,filteredOptions:o})=>{if(l.multiple)return void t();if(0===n.length)return void t();const s=n[0],a=o.findIndex((e=>e.value===s));-1!==a?e(a):t()}}))})),(0,C.register)(["packages","components"],"ComboboxBase",h)}();