mirror of
https://github.com/pelican-dev/panel.git
synced 2025-06-26 22:31:08 +02:00
2 lines
42 KiB
JavaScript
2 lines
42 KiB
JavaScript
var et=Math.min,H=Math.max,it=Math.round;var C=i=>({x:i,y:i}),Yt={left:"right",right:"left",bottom:"top",top:"bottom"},Gt={start:"end",end:"start"};function pt(i,t,e){return H(i,et(t,e))}function st(i,t){return typeof i=="function"?i(t):i}function V(i){return i.split("-")[0]}function nt(i){return i.split("-")[1]}function mt(i){return i==="x"?"y":"x"}function gt(i){return i==="y"?"height":"width"}function z(i){return["top","bottom"].includes(V(i))?"y":"x"}function bt(i){return mt(z(i))}function Lt(i,t,e){e===void 0&&(e=!1);let s=nt(i),n=bt(i),o=gt(n),r=n==="x"?s===(e?"end":"start")?"right":"left":s==="start"?"bottom":"top";return t.reference[o]>t.floating[o]&&(r=tt(r)),[r,tt(r)]}function Ot(i){let t=tt(i);return[at(i),t,at(t)]}function at(i){return i.replace(/start|end/g,t=>Gt[t])}function Xt(i,t,e){let s=["left","right"],n=["right","left"],o=["top","bottom"],r=["bottom","top"];switch(i){case"top":case"bottom":return e?t?n:s:t?s:n;case"left":case"right":return t?o:r;default:return[]}}function At(i,t,e,s){let n=nt(i),o=Xt(V(i),e==="start",s);return n&&(o=o.map(r=>r+"-"+n),t&&(o=o.concat(o.map(at)))),o}function tt(i){return i.replace(/left|right|bottom|top/g,t=>Yt[t])}function Qt(i){return{top:0,right:0,bottom:0,left:0,...i}}function St(i){return typeof i!="number"?Qt(i):{top:i,right:i,bottom:i,left:i}}function U(i){let{x:t,y:e,width:s,height:n}=i;return{width:s,height:n,top:e,left:t,right:t+s,bottom:e+n,x:t,y:e}}function Ct(i,t,e){let{reference:s,floating:n}=i,o=z(t),r=bt(t),l=gt(r),a=V(t),c=o==="y",h=s.x+s.width/2-n.width/2,d=s.y+s.height/2-n.height/2,u=s[l]/2-n[l]/2,f;switch(a){case"top":f={x:h,y:s.y-n.height};break;case"bottom":f={x:h,y:s.y+s.height};break;case"right":f={x:s.x+s.width,y:d};break;case"left":f={x:s.x-n.width,y:d};break;default:f={x:s.x,y:s.y}}switch(nt(t)){case"start":f[r]-=u*(e&&c?-1:1);break;case"end":f[r]+=u*(e&&c?-1:1);break}return f}var Dt=async(i,t,e)=>{let{placement:s="bottom",strategy:n="absolute",middleware:o=[],platform:r}=e,l=o.filter(Boolean),a=await(r.isRTL==null?void 0:r.isRTL(t)),c=await r.getElementRects({reference:i,floating:t,strategy:n}),{x:h,y:d}=Ct(c,s,a),u=s,f={},p=0;for(let m=0;m<l.length;m++){let{name:g,fn:w}=l[m],{x:y,y:v,data:L,reset:x}=await w({x:h,y:d,initialPlacement:s,placement:u,strategy:n,middlewareData:f,rects:c,platform:r,elements:{reference:i,floating:t}});h=y??h,d=v??d,f={...f,[g]:{...f[g],...L}},x&&p<=50&&(p++,typeof x=="object"&&(x.placement&&(u=x.placement),x.rects&&(c=x.rects===!0?await r.getElementRects({reference:i,floating:t,strategy:n}):x.rects),{x:h,y:d}=Ct(c,u,a)),m=-1)}return{x:h,y:d,placement:u,strategy:n,middlewareData:f}};async function wt(i,t){var e;t===void 0&&(t={});let{x:s,y:n,platform:o,rects:r,elements:l,strategy:a}=i,{boundary:c="clippingAncestors",rootBoundary:h="viewport",elementContext:d="floating",altBoundary:u=!1,padding:f=0}=st(t,i),p=St(f),g=l[u?d==="floating"?"reference":"floating":d],w=U(await o.getClippingRect({element:(e=await(o.isElement==null?void 0:o.isElement(g)))==null||e?g:g.contextElement||await(o.getDocumentElement==null?void 0:o.getDocumentElement(l.floating)),boundary:c,rootBoundary:h,strategy:a})),y=d==="floating"?{x:s,y:n,width:r.floating.width,height:r.floating.height}:r.reference,v=await(o.getOffsetParent==null?void 0:o.getOffsetParent(l.floating)),L=await(o.isElement==null?void 0:o.isElement(v))?await(o.getScale==null?void 0:o.getScale(v))||{x:1,y:1}:{x:1,y:1},x=U(o.convertOffsetParentRelativeRectToViewportRelativeRect?await o.convertOffsetParentRelativeRectToViewportRelativeRect({elements:l,rect:y,offsetParent:v,strategy:a}):y);return{top:(w.top-x.top+p.top)/L.y,bottom:(x.bottom-w.bottom+p.bottom)/L.y,left:(w.left-x.left+p.left)/L.x,right:(x.right-w.right+p.right)/L.x}}var Et=function(i){return i===void 0&&(i={}),{name:"flip",options:i,async fn(t){var e,s;let{placement:n,middlewareData:o,rects:r,initialPlacement:l,platform:a,elements:c}=t,{mainAxis:h=!0,crossAxis:d=!0,fallbackPlacements:u,fallbackStrategy:f="bestFit",fallbackAxisSideDirection:p="none",flipAlignment:m=!0,...g}=st(i,t);if((e=o.arrow)!=null&&e.alignmentOffset)return{};let w=V(n),y=z(l),v=V(l)===l,L=await(a.isRTL==null?void 0:a.isRTL(c.floating)),x=u||(v||!m?[tt(l)]:Ot(l)),q=p!=="none";!u&&q&&x.push(...At(l,m,p,L));let X=[l,...x],$=await wt(t,g),P=[],E=((s=o.flip)==null?void 0:s.overflows)||[];if(h&&P.push($[w]),d){let k=Lt(n,r,L);P.push($[k[0]],$[k[1]])}if(E=[...E,{placement:n,overflows:P}],!P.every(k=>k<=0)){var J,j;let k=(((J=o.flip)==null?void 0:J.index)||0)+1,Q=X[k];if(Q){var W;let N=d==="alignment"?y!==z(Q):!1,R=((W=E[0])==null?void 0:W.overflows[0])>0;if(!N||R)return{data:{index:k,overflows:E},reset:{placement:Q}}}let Z=(j=E.filter(N=>N.overflows[0]<=0).sort((N,R)=>N.overflows[1]-R.overflows[1])[0])==null?void 0:j.placement;if(!Z)switch(f){case"bestFit":{var T;let N=(T=E.filter(R=>{if(q){let F=z(R.placement);return F===y||F==="y"}return!0}).map(R=>[R.placement,R.overflows.filter(F=>F>0).reduce((F,jt)=>F+jt,0)]).sort((R,F)=>R[1]-F[1])[0])==null?void 0:T[0];N&&(Z=N);break}case"initialPlacement":Z=l;break}if(n!==Z)return{reset:{placement:Z}}}return{}}}};async function Zt(i,t){let{placement:e,platform:s,elements:n}=i,o=await(s.isRTL==null?void 0:s.isRTL(n.floating)),r=V(e),l=nt(e),a=z(e)==="y",c=["left","top"].includes(r)?-1:1,h=o&&a?-1:1,d=st(t,i),{mainAxis:u,crossAxis:f,alignmentAxis:p}=typeof d=="number"?{mainAxis:d,crossAxis:0,alignmentAxis:null}:{mainAxis:d.mainAxis||0,crossAxis:d.crossAxis||0,alignmentAxis:d.alignmentAxis};return l&&typeof p=="number"&&(f=l==="end"?p*-1:p),a?{x:f*h,y:u*c}:{x:u*c,y:f*h}}var Rt=function(i){return i===void 0&&(i=0),{name:"offset",options:i,async fn(t){var e,s;let{x:n,y:o,placement:r,middlewareData:l}=t,a=await Zt(t,i);return r===((e=l.offset)==null?void 0:e.placement)&&(s=l.arrow)!=null&&s.alignmentOffset?{}:{x:n+a.x,y:o+a.y,data:{...a,placement:r}}}}},It=function(i){return i===void 0&&(i={}),{name:"shift",options:i,async fn(t){let{x:e,y:s,placement:n}=t,{mainAxis:o=!0,crossAxis:r=!1,limiter:l={fn:g=>{let{x:w,y}=g;return{x:w,y}}},...a}=st(i,t),c={x:e,y:s},h=await wt(t,a),d=z(V(n)),u=mt(d),f=c[u],p=c[d];if(o){let g=u==="y"?"top":"left",w=u==="y"?"bottom":"right",y=f+h[g],v=f-h[w];f=pt(y,f,v)}if(r){let g=d==="y"?"top":"left",w=d==="y"?"bottom":"right",y=p+h[g],v=p-h[w];p=pt(y,p,v)}let m=l.fn({...t,[u]:f,[d]:p});return{...m,data:{x:m.x-e,y:m.y-s,enabled:{[u]:o,[d]:r}}}}}};function dt(){return typeof window<"u"}function K(i){return kt(i)?(i.nodeName||"").toLowerCase():"#document"}function O(i){var t;return(i==null||(t=i.ownerDocument)==null?void 0:t.defaultView)||window}function I(i){var t;return(t=(kt(i)?i.ownerDocument:i.document)||window.document)==null?void 0:t.documentElement}function kt(i){return dt()?i instanceof Node||i instanceof O(i).Node:!1}function A(i){return dt()?i instanceof Element||i instanceof O(i).Element:!1}function D(i){return dt()?i instanceof HTMLElement||i instanceof O(i).HTMLElement:!1}function Tt(i){return!dt()||typeof ShadowRoot>"u"?!1:i instanceof ShadowRoot||i instanceof O(i).ShadowRoot}function Y(i){let{overflow:t,overflowX:e,overflowY:s,display:n}=S(i);return/auto|scroll|overlay|hidden|clip/.test(t+s+e)&&!["inline","contents"].includes(n)}function Mt(i){return["table","td","th"].includes(K(i))}function ot(i){return[":popover-open",":modal"].some(t=>{try{return i.matches(t)}catch{return!1}})}function ht(i){let t=ft(),e=A(i)?S(i):i;return["transform","translate","scale","rotate","perspective"].some(s=>e[s]?e[s]!=="none":!1)||(e.containerType?e.containerType!=="normal":!1)||!t&&(e.backdropFilter?e.backdropFilter!=="none":!1)||!t&&(e.filter?e.filter!=="none":!1)||["transform","translate","scale","rotate","perspective","filter"].some(s=>(e.willChange||"").includes(s))||["paint","layout","strict","content"].some(s=>(e.contain||"").includes(s))}function Bt(i){let t=M(i);for(;D(t)&&!_(t);){if(ht(t))return t;if(ot(t))return null;t=M(t)}return null}function ft(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}function _(i){return["html","body","#document"].includes(K(i))}function S(i){return O(i).getComputedStyle(i)}function rt(i){return A(i)?{scrollLeft:i.scrollLeft,scrollTop:i.scrollTop}:{scrollLeft:i.scrollX,scrollTop:i.scrollY}}function M(i){if(K(i)==="html")return i;let t=i.assignedSlot||i.parentNode||Tt(i)&&i.host||I(i);return Tt(t)?t.host:t}function Pt(i){let t=M(i);return _(t)?i.ownerDocument?i.ownerDocument.body:i.body:D(t)&&Y(t)?t:Pt(t)}function ct(i,t,e){var s;t===void 0&&(t=[]),e===void 0&&(e=!0);let n=Pt(i),o=n===((s=i.ownerDocument)==null?void 0:s.body),r=O(n);if(o){let l=ut(r);return t.concat(r,r.visualViewport||[],Y(n)?n:[],l&&e?ct(l):[])}return t.concat(n,ct(n,[],e))}function ut(i){return i.parent&&Object.getPrototypeOf(i.parent)?i.frameElement:null}function Ht(i){let t=S(i),e=parseFloat(t.width)||0,s=parseFloat(t.height)||0,n=D(i),o=n?i.offsetWidth:e,r=n?i.offsetHeight:s,l=it(e)!==o||it(s)!==r;return l&&(e=o,s=r),{width:e,height:s,$:l}}function Vt(i){return A(i)?i:i.contextElement}function G(i){let t=Vt(i);if(!D(t))return C(1);let e=t.getBoundingClientRect(),{width:s,height:n,$:o}=Ht(t),r=(o?it(e.width):e.width)/s,l=(o?it(e.height):e.height)/n;return(!r||!Number.isFinite(r))&&(r=1),(!l||!Number.isFinite(l))&&(l=1),{x:r,y:l}}var te=C(0);function zt(i){let t=O(i);return!ft()||!t.visualViewport?te:{x:t.visualViewport.offsetLeft,y:t.visualViewport.offsetTop}}function ee(i,t,e){return t===void 0&&(t=!1),!e||t&&e!==O(i)?!1:t}function lt(i,t,e,s){t===void 0&&(t=!1),e===void 0&&(e=!1);let n=i.getBoundingClientRect(),o=Vt(i),r=C(1);t&&(s?A(s)&&(r=G(s)):r=G(i));let l=ee(o,e,s)?zt(o):C(0),a=(n.left+l.x)/r.x,c=(n.top+l.y)/r.y,h=n.width/r.x,d=n.height/r.y;if(o){let u=O(o),f=s&&A(s)?O(s):s,p=u,m=ut(p);for(;m&&s&&f!==p;){let g=G(m),w=m.getBoundingClientRect(),y=S(m),v=w.left+(m.clientLeft+parseFloat(y.paddingLeft))*g.x,L=w.top+(m.clientTop+parseFloat(y.paddingTop))*g.y;a*=g.x,c*=g.y,h*=g.x,d*=g.y,a+=v,c+=L,p=O(m),m=ut(p)}}return U({width:h,height:d,x:a,y:c})}function xt(i,t){let e=rt(i).scrollLeft;return t?t.left+e:lt(I(i)).left+e}function $t(i,t,e){e===void 0&&(e=!1);let s=i.getBoundingClientRect(),n=s.left+t.scrollLeft-(e?0:xt(i,s)),o=s.top+t.scrollTop;return{x:n,y:o}}function ie(i){let{elements:t,rect:e,offsetParent:s,strategy:n}=i,o=n==="fixed",r=I(s),l=t?ot(t.floating):!1;if(s===r||l&&o)return e;let a={scrollLeft:0,scrollTop:0},c=C(1),h=C(0),d=D(s);if((d||!d&&!o)&&((K(s)!=="body"||Y(r))&&(a=rt(s)),D(s))){let f=lt(s);c=G(s),h.x=f.x+s.clientLeft,h.y=f.y+s.clientTop}let u=r&&!d&&!o?$t(r,a,!0):C(0);return{width:e.width*c.x,height:e.height*c.y,x:e.x*c.x-a.scrollLeft*c.x+h.x+u.x,y:e.y*c.y-a.scrollTop*c.y+h.y+u.y}}function se(i){return Array.from(i.getClientRects())}function ne(i){let t=I(i),e=rt(i),s=i.ownerDocument.body,n=H(t.scrollWidth,t.clientWidth,s.scrollWidth,s.clientWidth),o=H(t.scrollHeight,t.clientHeight,s.scrollHeight,s.clientHeight),r=-e.scrollLeft+xt(i),l=-e.scrollTop;return S(s).direction==="rtl"&&(r+=H(t.clientWidth,s.clientWidth)-n),{width:n,height:o,x:r,y:l}}function oe(i,t){let e=O(i),s=I(i),n=e.visualViewport,o=s.clientWidth,r=s.clientHeight,l=0,a=0;if(n){o=n.width,r=n.height;let c=ft();(!c||c&&t==="fixed")&&(l=n.offsetLeft,a=n.offsetTop)}return{width:o,height:r,x:l,y:a}}function re(i,t){let e=lt(i,!0,t==="fixed"),s=e.top+i.clientTop,n=e.left+i.clientLeft,o=D(i)?G(i):C(1),r=i.clientWidth*o.x,l=i.clientHeight*o.y,a=n*o.x,c=s*o.y;return{width:r,height:l,x:a,y:c}}function Nt(i,t,e){let s;if(t==="viewport")s=oe(i,e);else if(t==="document")s=ne(I(i));else if(A(t))s=re(t,e);else{let n=zt(i);s={x:t.x-n.x,y:t.y-n.y,width:t.width,height:t.height}}return U(s)}function Wt(i,t){let e=M(i);return e===t||!A(e)||_(e)?!1:S(e).position==="fixed"||Wt(e,t)}function le(i,t){let e=t.get(i);if(e)return e;let s=ct(i,[],!1).filter(l=>A(l)&&K(l)!=="body"),n=null,o=S(i).position==="fixed",r=o?M(i):i;for(;A(r)&&!_(r);){let l=S(r),a=ht(r);!a&&l.position==="fixed"&&(n=null),(o?!a&&!n:!a&&l.position==="static"&&!!n&&["absolute","fixed"].includes(n.position)||Y(r)&&!a&&Wt(i,r))?s=s.filter(h=>h!==r):n=l,r=M(r)}return t.set(i,s),s}function ae(i){let{element:t,boundary:e,rootBoundary:s,strategy:n}=i,r=[...e==="clippingAncestors"?ot(t)?[]:le(t,this._c):[].concat(e),s],l=r[0],a=r.reduce((c,h)=>{let d=Nt(t,h,n);return c.top=H(d.top,c.top),c.right=et(d.right,c.right),c.bottom=et(d.bottom,c.bottom),c.left=H(d.left,c.left),c},Nt(t,l,n));return{width:a.right-a.left,height:a.bottom-a.top,x:a.left,y:a.top}}function ce(i){let{width:t,height:e}=Ht(i);return{width:t,height:e}}function de(i,t,e){let s=D(t),n=I(t),o=e==="fixed",r=lt(i,!0,o,t),l={scrollLeft:0,scrollTop:0},a=C(0);function c(){a.x=xt(n)}if(s||!s&&!o)if((K(t)!=="body"||Y(n))&&(l=rt(t)),s){let f=lt(t,!0,o,t);a.x=f.x+t.clientLeft,a.y=f.y+t.clientTop}else n&&c();o&&!s&&n&&c();let h=n&&!s&&!o?$t(n,l):C(0),d=r.left+l.scrollLeft-a.x-h.x,u=r.top+l.scrollTop-a.y-h.y;return{x:d,y:u,width:r.width,height:r.height}}function yt(i){return S(i).position==="static"}function Ft(i,t){if(!D(i)||S(i).position==="fixed")return null;if(t)return t(i);let e=i.offsetParent;return I(i)===e&&(e=e.ownerDocument.body),e}function Ut(i,t){let e=O(i);if(ot(i))return e;if(!D(i)){let n=M(i);for(;n&&!_(n);){if(A(n)&&!yt(n))return n;n=M(n)}return e}let s=Ft(i,t);for(;s&&Mt(s)&&yt(s);)s=Ft(s,t);return s&&_(s)&&yt(s)&&!ht(s)?e:s||Bt(i)||e}var he=async function(i){let t=this.getOffsetParent||Ut,e=this.getDimensions,s=await e(i.floating);return{reference:de(i.reference,await t(i.floating),i.strategy),floating:{x:0,y:0,width:s.width,height:s.height}}};function fe(i){return S(i).direction==="rtl"}var ue={convertOffsetParentRelativeRectToViewportRelativeRect:ie,getDocumentElement:I,getClippingRect:ae,getOffsetParent:Ut,getElementRects:he,getClientRects:se,getDimensions:ce,getScale:G,isElement:A,isRTL:fe};var Kt=Rt;var _t=It,qt=Et;var Jt=(i,t,e)=>{let s=new Map,n={platform:ue,...e},o={...n.platform,_c:s};return Dt(i,t,{...n,platform:o})};function B(i){return i==null||i===""||typeof i=="string"&&i.trim()===""}function b(i){return!B(i)}function pe({canSelectPlaceholder:i,isHtmlAllowed:t,getOptionLabelUsing:e,getOptionLabelsUsing:s,getOptionsUsing:n,getSearchResultsUsing:o,initialOptionLabel:r,initialOptionLabels:l,initialState:a,isAutofocused:c,isDisabled:h,isMultiple:d,isSearchable:u,hasDynamicOptions:f,hasDynamicSearchResults:p,livewireId:m,loadingMessage:g,maxItems:w,maxItemsMessage:y,noSearchResultsMessage:v,options:L,optionsLimit:x,placeholder:q,position:X,searchDebounce:$,searchingMessage:P,searchPrompt:E,searchableOptionFields:J,state:j,statePath:W}){return{state:j,select:null,init(){this.select=new vt({element:this.$refs.select,options:L,placeholder:q,state:this.state,canSelectPlaceholder:i,initialOptionLabel:r,initialOptionLabels:l,initialState:a,isHtmlAllowed:t,isAutofocused:c,isDisabled:h,isMultiple:d,isSearchable:u,getOptionLabelUsing:e,getOptionLabelsUsing:s,getOptionsUsing:n,getSearchResultsUsing:o,hasDynamicOptions:f,hasDynamicSearchResults:p,searchPrompt:E,searchDebounce:$,loadingMessage:g,searchingMessage:P,noSearchResultsMessage:v,maxItems:w,maxItemsMessage:y,optionsLimit:x,position:X,searchableOptionFields:J,livewireId:m,statePath:W,onStateChange:T=>{this.state=T}}),this.$watch("state",T=>{this.select&&this.select.state!==T&&(this.select.state=T,this.select.updateSelectedDisplay(),this.select.renderOptions())})},destroy(){this.select&&(this.select.destroy(),this.select=null)}}}var vt=class{constructor({element:t,options:e,placeholder:s,state:n,canSelectPlaceholder:o=!0,initialOptionLabel:r=null,initialOptionLabels:l=null,initialState:a=null,isHtmlAllowed:c=!1,isAutofocused:h=!1,isDisabled:d=!1,isMultiple:u=!1,isSearchable:f=!1,getOptionLabelUsing:p=null,getOptionLabelsUsing:m=null,getOptionsUsing:g=null,getSearchResultsUsing:w=null,hasDynamicOptions:y=!1,hasDynamicSearchResults:v=!0,searchPrompt:L="Search...",searchDebounce:x=1e3,loadingMessage:q="Loading...",searchingMessage:X="Searching...",noSearchResultsMessage:$="No results found",maxItems:P=null,maxItemsMessage:E="Maximum number of items selected",optionsLimit:J=null,position:j=null,searchableOptionFields:W=["label"],livewireId:T=null,statePath:k=null,onStateChange:Q=()=>{}}){this.element=t,this.options=e,this.originalOptions=JSON.parse(JSON.stringify(e)),this.placeholder=s,this.state=n,this.canSelectPlaceholder=o,this.initialOptionLabel=r,this.initialOptionLabels=l,this.initialState=a,this.isHtmlAllowed=c,this.isAutofocused=h,this.isDisabled=d,this.isMultiple=u,this.isSearchable=f,this.getOptionLabelUsing=p,this.getOptionLabelsUsing=m,this.getOptionsUsing=g,this.getSearchResultsUsing=w,this.hasDynamicOptions=y,this.hasDynamicSearchResults=v,this.searchPrompt=L,this.searchDebounce=x,this.loadingMessage=q,this.searchingMessage=X,this.noSearchResultsMessage=$,this.maxItems=P,this.maxItemsMessage=E,this.optionsLimit=J,this.position=j,this.searchableOptionFields=Array.isArray(W)?W:["label"],this.livewireId=T,this.statePath=k,this.onStateChange=Q,this.labelRepository={},this.isOpen=!1,this.selectedIndex=-1,this.searchQuery="",this.searchTimeout=null,this.render(),this.setUpEventListeners(),this.isAutofocused&&this.selectButton.focus()}populateLabelRepositoryFromOptions(t){if(!(!t||!Array.isArray(t)))for(let e of t)e.options&&Array.isArray(e.options)?this.populateLabelRepositoryFromOptions(e.options):e.value!==void 0&&e.label!==void 0&&(this.labelRepository[e.value]=e.label)}render(){this.populateLabelRepositoryFromOptions(this.options),this.container=document.createElement("div"),this.container.className="fi-fo-select-ctn",this.container.setAttribute("aria-haspopup","listbox"),this.selectButton=document.createElement("button"),this.selectButton.className="fi-fo-select-btn",this.selectButton.type="button",this.selectButton.setAttribute("aria-expanded","false"),this.selectedDisplay=document.createElement("div"),this.selectedDisplay.className="fi-fo-select-value-ctn",this.updateSelectedDisplay(),this.selectButton.appendChild(this.selectedDisplay),this.dropdown=document.createElement("div"),this.dropdown.className="fi-dropdown-panel fi-scrollable",this.dropdown.setAttribute("role","listbox"),this.dropdown.setAttribute("tabindex","-1"),this.dropdown.style.display="none",this.dropdownId=`fi-fo-select-dropdown-${Math.random().toString(36).substring(2,11)}`,this.dropdown.id=this.dropdownId,this.isMultiple&&this.dropdown.setAttribute("aria-multiselectable","true"),this.isSearchable&&(this.searchContainer=document.createElement("div"),this.searchContainer.className="fi-fo-select-search-ctn",this.searchInput=document.createElement("input"),this.searchInput.className="fi-input",this.searchInput.type="text",this.searchInput.placeholder=this.searchPrompt,this.searchInput.setAttribute("aria-label","Search"),this.searchContainer.appendChild(this.searchInput),this.dropdown.appendChild(this.searchContainer),this.searchInput.addEventListener("input",t=>{this.isDisabled||this.handleSearch(t)}),this.searchInput.addEventListener("keydown",t=>{if(!this.isDisabled){if(t.key==="Tab"){t.preventDefault();let e=this.getVisibleOptions();if(e.length===0)return;t.shiftKey?this.selectedIndex=e.length-1:this.selectedIndex=0,e.forEach(s=>{s.classList.remove("fi-selected")}),e[this.selectedIndex].classList.add("fi-selected"),e[this.selectedIndex].focus()}else if(t.key==="ArrowDown"){if(t.preventDefault(),t.stopPropagation(),this.getVisibleOptions().length===0)return;this.selectedIndex=-1,this.searchInput.blur(),this.focusNextOption()}else if(t.key==="ArrowUp"){t.preventDefault(),t.stopPropagation();let e=this.getVisibleOptions();if(e.length===0)return;this.selectedIndex=e.length-1,this.searchInput.blur(),e[this.selectedIndex].classList.add("fi-selected"),e[this.selectedIndex].focus(),e[this.selectedIndex].id&&this.dropdown.setAttribute("aria-activedescendant",e[this.selectedIndex].id),this.scrollOptionIntoView(e[this.selectedIndex])}}})),this.optionsList=document.createElement("ul"),this.renderOptions(),this.container.appendChild(this.selectButton),this.container.appendChild(this.dropdown),this.element.appendChild(this.container),this.applyDisabledState()}renderOptions(){this.optionsList.innerHTML="";let t=0,e=this.options,s=0,n=!1;this.options.forEach(l=>{l.options&&Array.isArray(l.options)?(s+=l.options.length,n=!0):s++}),n?this.optionsList.className="fi-fo-select-options-ctn":s>0&&(this.optionsList.className="fi-dropdown-list");let o=n?null:this.optionsList,r=0;for(let l of e){if(this.optionsLimit&&r>=this.optionsLimit)break;if(l.options&&Array.isArray(l.options)){let a=l.options;if(this.isMultiple&&Array.isArray(this.state)&&this.state.length>0&&(a=l.options.filter(c=>!this.state.includes(c.value))),a.length>0){if(this.optionsLimit){let c=this.optionsLimit-r;c<a.length&&(a=a.slice(0,c))}this.renderOptionGroup(l.label,a),r+=a.length,t+=a.length}}else{if(this.isMultiple&&Array.isArray(this.state)&&this.state.includes(l.value))continue;!o&&n&&(o=document.createElement("ul"),o.className="fi-dropdown-list",this.optionsList.appendChild(o));let a=this.createOptionElement(l.value,l);o.appendChild(a),r++,t++}}t===0?(this.searchQuery?this.showNoResultsMessage():this.isMultiple&&this.isOpen&&!this.isSearchable&&this.closeDropdown(),this.optionsList.parentNode===this.dropdown&&this.dropdown.removeChild(this.optionsList)):(this.hideLoadingState(),this.optionsList.parentNode!==this.dropdown&&this.dropdown.appendChild(this.optionsList))}renderOptionGroup(t,e){if(e.length===0)return;let s=document.createElement("li");s.className="fi-fo-select-option-group";let n=document.createElement("div");n.className="fi-dropdown-header",n.textContent=t;let o=document.createElement("ul");o.className="fi-dropdown-list",e.forEach(r=>{let l=this.createOptionElement(r.value,r);o.appendChild(l)}),s.appendChild(n),s.appendChild(o),this.optionsList.appendChild(s)}createOptionElement(t,e){let s=t,n=e,o=!1;typeof e=="object"&&e!==null&&"label"in e&&"value"in e&&(s=e.value,n=e.label,o=e.isDisabled||!1);let r=document.createElement("li");r.className="fi-dropdown-list-item fi-fo-select-option",o&&r.classList.add("fi-disabled");let l=`fi-fo-select-option-${Math.random().toString(36).substring(2,11)}`;if(r.id=l,r.setAttribute("role","option"),r.setAttribute("data-value",s),r.setAttribute("tabindex","0"),o&&r.setAttribute("aria-disabled","true"),this.isHtmlAllowed&&typeof n=="string"){let c=document.createElement("div");c.innerHTML=n;let h=c.textContent||c.innerText||n;r.setAttribute("aria-label",h)}let a=this.isMultiple?Array.isArray(this.state)&&this.state.includes(s):this.state===s;if(r.setAttribute("aria-selected",a?"true":"false"),a&&r.classList.add("fi-selected"),this.isHtmlAllowed){let c=document.createElement("span");c.innerHTML=n,r.appendChild(c)}else r.appendChild(document.createTextNode(n));return o||r.addEventListener("click",c=>{c.preventDefault(),c.stopPropagation(),this.selectOption(s),this.isMultiple&&(this.isSearchable&&this.searchInput?setTimeout(()=>{this.searchInput.focus()},0):setTimeout(()=>{r.focus()},0))}),r}async updateSelectedDisplay(){if(this.selectedDisplay.innerHTML="",this.isMultiple){if(!Array.isArray(this.state)||this.state.length===0){this.selectedDisplay.textContent=this.placeholder||"Select options";return}let e=await this.getLabelsForMultipleSelection();this.addBadgesForSelectedOptions(e),this.isOpen&&this.positionDropdown();return}if(this.state===null||this.state===""){this.selectedDisplay.textContent=this.placeholder||"Select an option";return}let t=await this.getLabelForSingleSelection();this.addSingleSelectionDisplay(t)}async getLabelsForMultipleSelection(){let t=this.getSelectedOptionLabels(),e=[];if(Array.isArray(this.state)){for(let n of this.state)if(!b(this.labelRepository[n])){if(b(t[n])){this.labelRepository[n]=t[n];continue}e.push(n)}}if(e.length>0&&b(this.initialOptionLabels)&&JSON.stringify(this.state)===JSON.stringify(this.initialState)){if(Array.isArray(this.initialOptionLabels))for(let n of this.initialOptionLabels)b(n)&&n.value!==void 0&&n.label!==void 0&&e.includes(n.value)&&(this.labelRepository[n.value]=n.label)}else if(e.length>0&&this.getOptionLabelsUsing)try{let n=await this.getOptionLabelsUsing();for(let o of n)b(o)&&o.value!==void 0&&o.label!==void 0&&(this.labelRepository[o.value]=o.label)}catch(n){console.error("Error fetching option labels:",n)}let s=[];if(Array.isArray(this.state))for(let n of this.state)b(this.labelRepository[n])?s.push(this.labelRepository[n]):b(t[n])?s.push(t[n]):s.push(n);return s}createBadgeElement(t,e){let s=document.createElement("span");s.className="fi-badge fi-size-md fi-color fi-color-primary fi-text-color-600 dark:fi-text-color-200",b(t)&&s.setAttribute("data-value",t);let n=document.createElement("span");n.className="fi-badge-label-ctn";let o=document.createElement("span");o.className="fi-badge-label",this.isHtmlAllowed?o.innerHTML=e:o.textContent=e,n.appendChild(o),s.appendChild(n);let r=this.createRemoveButton(t,e);return s.appendChild(r),s}createRemoveButton(t,e){let s=document.createElement("button");return s.type="button",s.className="fi-badge-delete-btn",s.innerHTML='<svg class="fi-icon fi-size-xs" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="currentColor" aria-hidden="true" data-slot="icon"><path d="M5.28 4.22a.75.75 0 0 0-1.06 1.06L6.94 8l-2.72 2.72a.75.75 0 1 0 1.06 1.06L8 9.06l2.72 2.72a.75.75 0 1 0 1.06-1.06L9.06 8l2.72-2.72a.75.75 0 0 0-1.06-1.06L8 6.94 5.28 4.22Z"></path></svg>',s.setAttribute("aria-label","Remove "+(this.isHtmlAllowed?e.replace(/<[^>]*>/g,""):e)),s.addEventListener("click",n=>{n.stopPropagation(),b(t)&&this.selectOption(t)}),s.addEventListener("keydown",n=>{(n.key===" "||n.key==="Enter")&&(n.preventDefault(),n.stopPropagation(),b(t)&&this.selectOption(t))}),s}addBadgesForSelectedOptions(t){let e=document.createElement("div");e.className="fi-fo-select-value-badges-ctn",t.forEach((s,n)=>{let o=Array.isArray(this.state)?this.state[n]:null,r=this.createBadgeElement(o,s);e.appendChild(r)}),this.selectedDisplay.appendChild(e)}async getLabelForSingleSelection(){let t=this.labelRepository[this.state];if(B(t)&&(t=this.getSelectedOptionLabel(this.state)),B(t)&&b(this.initialOptionLabel)&&this.state===this.initialState)t=this.initialOptionLabel,b(this.state)&&(this.labelRepository[this.state]=t);else if(B(t)&&this.getOptionLabelUsing)try{t=await this.getOptionLabelUsing(),b(t)&&b(this.state)&&(this.labelRepository[this.state]=t)}catch(e){console.error("Error fetching option label:",e),t=this.state}else B(t)&&(t=this.state);return t}addSingleSelectionDisplay(t){let e=document.createElement("span");if(e.className="fi-fo-select-value-label",this.isHtmlAllowed?e.innerHTML=t:e.textContent=t,this.selectedDisplay.appendChild(e),!this.canSelectPlaceholder)return;let s=document.createElement("button");s.type="button",s.className="fi-fo-select-value-remove-btn",s.innerHTML='<svg class="fi-icon fi-size-sm" viewBox="0 0 20 20" fill="currentColor"><path fill-rule="evenodd" d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z" clip-rule="evenodd" /></svg>',s.setAttribute("aria-label","Clear selection"),s.addEventListener("click",n=>{n.stopPropagation(),this.selectOption("")}),s.addEventListener("keydown",n=>{(n.key===" "||n.key==="Enter")&&(n.preventDefault(),n.stopPropagation(),this.selectOption(""))}),this.selectedDisplay.appendChild(s)}getSelectedOptionLabel(t){if(b(this.labelRepository[t]))return this.labelRepository[t];let e="";for(let s of this.options)if(s.options&&Array.isArray(s.options)){for(let n of s.options)if(n.value===t){e=n.label,this.labelRepository[t]=e;break}}else if(s.value===t){e=s.label,this.labelRepository[t]=e;break}return e}setUpEventListeners(){this.buttonClickListener=()=>{this.toggleDropdown()},this.documentClickListener=t=>{!this.container.contains(t.target)&&this.isOpen&&this.closeDropdown()},this.buttonKeydownListener=t=>{this.isDisabled||this.handleSelectButtonKeydown(t)},this.dropdownKeydownListener=t=>{this.isDisabled||this.isSearchable&&document.activeElement===this.searchInput&&!["Tab","Escape"].includes(t.key)||this.handleDropdownKeydown(t)},this.selectButton.addEventListener("click",this.buttonClickListener),document.addEventListener("click",this.documentClickListener),this.selectButton.addEventListener("keydown",this.buttonKeydownListener),this.dropdown.addEventListener("keydown",this.dropdownKeydownListener),!this.isMultiple&&this.livewireId&&this.statePath&&this.getOptionLabelUsing&&(this.refreshOptionLabelListener=async t=>{if(t.detail.livewireId===this.livewireId&&t.detail.statePath===this.statePath&&b(this.state))try{delete this.labelRepository[this.state];let e=await this.getOptionLabelUsing();b(e)&&(this.labelRepository[this.state]=e);let s=this.selectedDisplay.querySelector(".fi-fo-select-value-label");b(s)&&(this.isHtmlAllowed?s.innerHTML=e:s.textContent=e),this.updateOptionLabelInList(this.state,e)}catch(e){console.error("Error refreshing option label:",e)}},window.addEventListener("filament-forms::select.refreshSelectedOptionLabel",this.refreshOptionLabelListener))}updateOptionLabelInList(t,e){this.labelRepository[t]=e;let s=this.getVisibleOptions();for(let n of s)if(n.getAttribute("data-value")===String(t)){if(n.innerHTML="",this.isHtmlAllowed){let o=document.createElement("span");o.innerHTML=e,n.appendChild(o)}else n.appendChild(document.createTextNode(e));break}for(let n of this.options)if(n.options&&Array.isArray(n.options)){for(let o of n.options)if(o.value===t){o.label=e;break}}else if(n.value===t){n.label=e;break}for(let n of this.originalOptions)if(n.options&&Array.isArray(n.options)){for(let o of n.options)if(o.value===t){o.label=e;break}}else if(n.value===t){n.label=e;break}}handleSelectButtonKeydown(t){switch(t.key){case"ArrowDown":t.preventDefault(),t.stopPropagation(),this.isOpen?this.focusNextOption():this.openDropdown();break;case"ArrowUp":t.preventDefault(),t.stopPropagation(),this.isOpen?this.focusPreviousOption():this.openDropdown();break;case" ":if(t.preventDefault(),this.isOpen){if(this.selectedIndex>=0){let e=this.getVisibleOptions()[this.selectedIndex];e&&e.click()}}else this.openDropdown();break;case"Enter":break;case"Escape":this.isOpen&&(t.preventDefault(),this.closeDropdown());break;case"Tab":this.isOpen&&this.closeDropdown();break}}handleDropdownKeydown(t){switch(t.key){case"ArrowDown":t.preventDefault(),t.stopPropagation(),this.focusNextOption();break;case"ArrowUp":t.preventDefault(),t.stopPropagation(),this.focusPreviousOption();break;case" ":if(t.preventDefault(),this.selectedIndex>=0){let e=this.getVisibleOptions()[this.selectedIndex];e&&e.click()}break;case"Enter":if(t.preventDefault(),this.selectedIndex>=0){let e=this.getVisibleOptions()[this.selectedIndex];e&&e.click()}else{let e=this.element.closest("form");e&&e.submit()}break;case"Escape":t.preventDefault(),this.closeDropdown(),this.selectButton.focus();break;case"Tab":this.closeDropdown();break}}toggleDropdown(){if(!this.isDisabled){if(this.isOpen){this.closeDropdown();return}this.isMultiple&&!this.isSearchable&&!this.hasAvailableOptions()||this.openDropdown()}}hasAvailableOptions(){for(let t of this.options)if(t.options&&Array.isArray(t.options)){for(let e of t.options)if(!Array.isArray(this.state)||!this.state.includes(e.value))return!0}else if(!Array.isArray(this.state)||!this.state.includes(t.value))return!0;return!1}async openDropdown(){this.dropdown.style.display="block",this.dropdown.style.opacity="0";let t=this.selectButton.closest(".fi-modal")!==null;if(this.dropdown.style.position=t?"absolute":"fixed",this.dropdown.style.width=`${this.selectButton.offsetWidth}px`,this.selectButton.setAttribute("aria-expanded","true"),this.isOpen=!0,this.positionDropdown(),this.resizeListener||(this.resizeListener=()=>{this.dropdown.style.width=`${this.selectButton.offsetWidth}px`,this.positionDropdown()},window.addEventListener("resize",this.resizeListener)),this.scrollListener||(this.scrollListener=()=>this.positionDropdown(),window.addEventListener("scroll",this.scrollListener,!0)),this.dropdown.style.opacity="1",this.hasDynamicOptions&&this.getOptionsUsing){this.showLoadingState(!1);try{let e=await this.getOptionsUsing();this.options=e,this.originalOptions=JSON.parse(JSON.stringify(e)),this.populateLabelRepositoryFromOptions(e),this.renderOptions()}catch(e){console.error("Error fetching options:",e),this.hideLoadingState()}}if(this.hideLoadingState(),this.isSearchable&&this.searchInput)this.searchInput.value="",this.searchInput.focus(),this.searchQuery="",this.options=JSON.parse(JSON.stringify(this.originalOptions)),this.renderOptions();else{this.selectedIndex=-1;let e=this.getVisibleOptions();if(this.isMultiple){if(Array.isArray(this.state)&&this.state.length>0){for(let s=0;s<e.length;s++)if(this.state.includes(e[s].getAttribute("data-value"))){this.selectedIndex=s;break}}}else for(let s=0;s<e.length;s++)if(e[s].getAttribute("data-value")===this.state){this.selectedIndex=s;break}this.selectedIndex===-1&&e.length>0&&(this.selectedIndex=0),this.selectedIndex>=0&&(e[this.selectedIndex].classList.add("fi-selected"),e[this.selectedIndex].focus())}}positionDropdown(){let t=this.position==="top"?"top-start":"bottom-start",e=[Kt(4),_t({padding:5})];this.position!=="top"&&this.position!=="bottom"&&e.push(qt());let s=this.selectButton.closest(".fi-modal")!==null;Jt(this.selectButton,this.dropdown,{placement:t,middleware:e,strategy:s?"absolute":"fixed"}).then(({x:n,y:o})=>{Object.assign(this.dropdown.style,{left:`${n}px`,top:`${o}px`})})}closeDropdown(){this.dropdown.style.display="none",this.selectButton.setAttribute("aria-expanded","false"),this.isOpen=!1,this.resizeListener&&(window.removeEventListener("resize",this.resizeListener),this.resizeListener=null),this.scrollListener&&(window.removeEventListener("scroll",this.scrollListener,!0),this.scrollListener=null),this.getVisibleOptions().forEach(e=>{e.classList.remove("fi-selected")})}focusNextOption(){let t=this.getVisibleOptions();if(t.length!==0){if(this.selectedIndex>=0&&this.selectedIndex<t.length&&t[this.selectedIndex].classList.remove("fi-selected"),this.selectedIndex===t.length-1&&this.isSearchable&&this.searchInput){this.selectedIndex=-1,this.searchInput.focus(),this.dropdown.removeAttribute("aria-activedescendant");return}this.selectedIndex=(this.selectedIndex+1)%t.length,t[this.selectedIndex].classList.add("fi-selected"),t[this.selectedIndex].focus(),t[this.selectedIndex].id&&this.dropdown.setAttribute("aria-activedescendant",t[this.selectedIndex].id),this.scrollOptionIntoView(t[this.selectedIndex])}}focusPreviousOption(){let t=this.getVisibleOptions();if(t.length!==0){if(this.selectedIndex>=0&&this.selectedIndex<t.length&&t[this.selectedIndex].classList.remove("fi-selected"),(this.selectedIndex===0||this.selectedIndex===-1)&&this.isSearchable&&this.searchInput){this.selectedIndex=-1,this.searchInput.focus(),this.dropdown.removeAttribute("aria-activedescendant");return}this.selectedIndex=(this.selectedIndex-1+t.length)%t.length,t[this.selectedIndex].classList.add("fi-selected"),t[this.selectedIndex].focus(),t[this.selectedIndex].id&&this.dropdown.setAttribute("aria-activedescendant",t[this.selectedIndex].id),this.scrollOptionIntoView(t[this.selectedIndex])}}scrollOptionIntoView(t){if(!t)return;let e=this.dropdown.getBoundingClientRect(),s=t.getBoundingClientRect();s.bottom>e.bottom?this.dropdown.scrollTop+=s.bottom-e.bottom:s.top<e.top&&(this.dropdown.scrollTop-=e.top-s.top)}getVisibleOptions(){let t=[];this.optionsList.classList.contains("fi-dropdown-list")?t=Array.from(this.optionsList.querySelectorAll(':scope > li[role="option"]')):t=Array.from(this.optionsList.querySelectorAll(':scope > ul.fi-dropdown-list > li[role="option"]'));let e=Array.from(this.optionsList.querySelectorAll('li.fi-fo-select-option-group > ul > li[role="option"]'));return[...t,...e]}getSelectedOptionLabels(){if(!Array.isArray(this.state)||this.state.length===0)return{};let t={};for(let e of this.state){let s=!1;for(let n of this.options)if(n.options&&Array.isArray(n.options)){for(let o of n.options)if(o.value===e){t[e]=o.label,s=!0;break}if(s)break}else if(n.value===e){t[e]=n.label,s=!0;break}}return t}handleSearch(t){let e=t.target.value.trim().toLowerCase();if(this.searchQuery=e,this.searchTimeout&&clearTimeout(this.searchTimeout),e===""){this.options=JSON.parse(JSON.stringify(this.originalOptions)),this.renderOptions();return}if(!this.getSearchResultsUsing||typeof this.getSearchResultsUsing!="function"||!this.hasDynamicSearchResults){this.filterOptions(e);return}this.searchTimeout=setTimeout(async()=>{try{this.showLoadingState(!0);let s=await this.getSearchResultsUsing(e);this.options=s,this.populateLabelRepositoryFromOptions(s),this.hideLoadingState(),this.renderOptions(),this.isOpen&&this.positionDropdown(),this.options.length===0&&this.showNoResultsMessage()}catch(s){console.error("Error fetching search results:",s),this.hideLoadingState(),this.options=JSON.parse(JSON.stringify(this.originalOptions)),this.renderOptions()}},this.searchDebounce)}showLoadingState(t=!1){this.optionsList.parentNode===this.dropdown&&(this.optionsList.innerHTML=""),this.hideLoadingState();let e=document.createElement("div");e.className="fi-fo-select-message",e.textContent=t?this.searchingMessage:this.loadingMessage,this.dropdown.appendChild(e)}hideLoadingState(){let t=this.dropdown.querySelector(".fi-fo-select-message");t&&t.remove()}showNoResultsMessage(){this.optionsList.parentNode===this.dropdown&&this.optionsList.children.length>0&&(this.optionsList.innerHTML=""),this.hideLoadingState();let t=document.createElement("div");t.className="fi-fo-select-message",t.textContent=this.noSearchResultsMessage,this.dropdown.appendChild(t)}filterOptions(t){let e=this.searchableOptionFields.includes("label"),s=this.searchableOptionFields.includes("value"),n=[];for(let o of this.originalOptions)if(o.options&&Array.isArray(o.options)){let r=o.options.filter(l=>e&&l.label.toLowerCase().includes(t)||s&&String(l.value).toLowerCase().includes(t));r.length>0&&n.push({label:o.label,options:r})}else(e&&o.label.toLowerCase().includes(t)||s&&String(o.value).toLowerCase().includes(t))&&n.push(o);this.options=n,this.renderOptions(),this.options.length===0&&this.showNoResultsMessage(),this.isOpen&&this.positionDropdown()}selectOption(t){if(this.isDisabled)return;if(!this.isMultiple){this.state=t,this.updateSelectedDisplay(),this.renderOptions(),this.closeDropdown(),this.selectButton.focus(),this.onStateChange(this.state);return}let e=Array.isArray(this.state)?[...this.state]:[];if(e.includes(t)){let n=this.selectedDisplay.querySelector(`[data-value="${t}"]`);if(b(n)){let o=n.parentElement;b(o)&&o.children.length===1?(e=e.filter(r=>r!==t),this.state=e,this.updateSelectedDisplay()):(n.remove(),e=e.filter(r=>r!==t),this.state=e)}else e=e.filter(o=>o!==t),this.state=e,this.updateSelectedDisplay();this.renderOptions(),this.isOpen&&this.positionDropdown(),this.maintainFocusInMultipleMode(),this.onStateChange(this.state);return}if(this.maxItems&&e.length>=this.maxItems){this.maxItemsMessage&&alert(this.maxItemsMessage);return}e.push(t),this.state=e;let s=this.selectedDisplay.querySelector(".fi-fo-select-value-badges-ctn");B(s)?this.updateSelectedDisplay():this.addSingleBadge(t,s),this.renderOptions(),this.isOpen&&this.positionDropdown(),this.maintainFocusInMultipleMode(),this.onStateChange(this.state)}async addSingleBadge(t,e){let s=this.labelRepository[t];if(B(s)&&(s=this.getSelectedOptionLabel(t),b(s)&&(this.labelRepository[t]=s)),B(s)&&this.getOptionLabelsUsing)try{let o=await this.getOptionLabelsUsing();for(let r of o)if(b(r)&&r.value===t&&r.label!==void 0){s=r.label,this.labelRepository[t]=s;break}}catch(o){console.error("Error fetching option label:",o)}B(s)&&(s=t);let n=this.createBadgeElement(t,s);e.appendChild(n)}maintainFocusInMultipleMode(){if(this.isSearchable&&this.searchInput){this.searchInput.focus();return}let t=this.getVisibleOptions();if(t.length!==0){if(this.selectedIndex=-1,Array.isArray(this.state)&&this.state.length>0){for(let e=0;e<t.length;e++)if(this.state.includes(t[e].getAttribute("data-value"))){this.selectedIndex=e;break}}this.selectedIndex===-1&&(this.selectedIndex=0),t[this.selectedIndex].classList.add("fi-selected"),t[this.selectedIndex].focus()}}disable(){this.isDisabled||(this.isDisabled=!0,this.applyDisabledState(),this.isOpen&&this.closeDropdown())}enable(){this.isDisabled&&(this.isDisabled=!1,this.applyDisabledState())}applyDisabledState(){if(this.isDisabled){if(this.selectButton.setAttribute("disabled","disabled"),this.selectButton.setAttribute("aria-disabled","true"),this.selectButton.classList.add("fi-disabled"),this.isMultiple&&this.container.querySelectorAll(".fi-fo-select-badge-remove").forEach(e=>{e.setAttribute("disabled","disabled"),e.classList.add("fi-disabled")}),!this.isMultiple&&this.canSelectPlaceholder){let t=this.container.querySelector(".fi-fo-select-value-remove-btn");t&&(t.setAttribute("disabled","disabled"),t.classList.add("fi-disabled"))}this.isSearchable&&this.searchInput&&(this.searchInput.setAttribute("disabled","disabled"),this.searchInput.classList.add("fi-disabled"))}else{if(this.selectButton.removeAttribute("disabled"),this.selectButton.removeAttribute("aria-disabled"),this.selectButton.classList.remove("fi-disabled"),this.isMultiple&&this.container.querySelectorAll(".fi-fo-select-badge-remove").forEach(e=>{e.removeAttribute("disabled"),e.classList.remove("fi-disabled")}),!this.isMultiple&&this.canSelectPlaceholder){let t=this.container.querySelector(".fi-fo-select-value-remove-btn");t&&(t.removeAttribute("disabled"),t.classList.add("fi-disabled"))}this.isSearchable&&this.searchInput&&(this.searchInput.removeAttribute("disabled"),this.searchInput.classList.remove("fi-disabled"))}}destroy(){this.selectButton&&this.buttonClickListener&&this.selectButton.removeEventListener("click",this.buttonClickListener),this.documentClickListener&&document.removeEventListener("click",this.documentClickListener),this.selectButton&&this.buttonKeydownListener&&this.selectButton.removeEventListener("keydown",this.buttonKeydownListener),this.dropdown&&this.dropdownKeydownListener&&this.dropdown.removeEventListener("keydown",this.dropdownKeydownListener),this.resizeListener&&(window.removeEventListener("resize",this.resizeListener),this.resizeListener=null),this.scrollListener&&(window.removeEventListener("scroll",this.scrollListener,!0),this.scrollListener=null),this.refreshOptionLabelListener&&window.removeEventListener("filament-forms::select.refreshSelectedOptionLabel",this.refreshOptionLabelListener),this.isOpen&&this.closeDropdown(),this.searchTimeout&&(clearTimeout(this.searchTimeout),this.searchTimeout=null)}};export{pe as default};
|