import{c as re}from"./createLucideIcon.D3XWtEmL.js";import{A as S,u as K,ae as xe,l as B,aj as ne,y as Oe,aa as de,d as U,r as F,n as Se,s as _,a9 as ce,D as Z,a8 as H,M as ye,E as J,k as fe,z as ve,ah as Ie}from"./index.DXvi0yH9.js";import{d as Re,e as we}from"./form.C3ove4if.js";import{o as X,t as le}from"./transition.CRNcmuQX.js";import{b as N,o as E,f as Ce,E as Ee,u as Me,A as Q,T as ee,a as te,i as Te,N as Y,O as ze,c as V}from"./keyboard.D4P2wQc7.js";import{w as Fe,t as Ae,i as G,l as Pe,n as $e}from"./open-closed.CQX5sZkx.js";import{c as A,f as ie,u as ke}from"../apps/partials/index.EnUA63nb.js";import{i as De}from"./use-tree-walker.Bsdod6n3.js";import{b as Ve}from"./index.CZtQfmHi.js";/**
 * @license lucide-vue-next v0.544.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const vt=re("check",[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]]);/**
 * @license lucide-vue-next v0.544.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const ht=re("chevrons-up-down",[["path",{d:"m7 15 5 5 5-5",key:"1hf1tw"}],["path",{d:"m7 9 5-5 5 5",key:"sgt6xg"}]]);function L(l,f,t){var a;let i=(a=t.initialDeps)!=null?a:[],e;function o(){var n,c,d,r;let p;t.key&&((n=t.debug)!=null&&n.call(t))&&(p=Date.now());const x=l();if(!(x.length!==i.length||x.some((z,P)=>i[P]!==z)))return e;i=x;let y;if(t.key&&((c=t.debug)!=null&&c.call(t))&&(y=Date.now()),e=f(...x),t.key&&((d=t.debug)!=null&&d.call(t))){const z=Math.round((Date.now()-p)*100)/100,P=Math.round((Date.now()-y)*100)/100,k=P/16,b=(O,$)=>{for(O=String(O);O.length<$;)O=" "+O;return O};console.info("%c⏱ ".concat(b(P,5)," /").concat(b(z,5)," ms"),"\n            font-size: .6rem;\n            font-weight: bold;\n            color: hsl(".concat(Math.max(0,Math.min(120-120*k,120)),"deg 100% 31%);"),t==null?void 0:t.key)}return(r=t==null?void 0:t.onChange)==null||r.call(t,e),e}return o.updateDeps=n=>{i=n},o}function oe(l,f){if(l===void 0)throw new Error("Unexpected undefined");return l}const _e=(l,f)=>Math.abs(l-f)<1.01,Be=(l,f,t)=>{let i;return function(...e){l.clearTimeout(i),i=l.setTimeout(()=>f.apply(this,e),t)}},ae=l=>{const{offsetWidth:f,offsetHeight:t}=l;return{width:f,height:t}},je=l=>l,Le=l=>{const f=Math.max(l.startIndex-l.overscan,0),t=Math.min(l.endIndex+l.overscan,l.count-1),i=[];for(let e=f;e<=t;e++)i.push(e);return i},Ne=(l,f)=>{const t=l.scrollElement;if(!t)return;const i=l.targetWindow;if(!i)return;const e=a=>{const{width:n,height:c}=a;f({width:Math.round(n),height:Math.round(c)})};if(e(ae(t)),!i.ResizeObserver)return()=>{};const o=new i.ResizeObserver(a=>{const n=()=>{const c=a[0];if(c!=null&&c.borderBoxSize){const d=c.borderBoxSize[0];if(d){e({width:d.inlineSize,height:d.blockSize});return}}e(ae(t))};l.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(n):n()});return o.observe(t,{box:"border-box"}),()=>{o.unobserve(t)}},se={passive:!0},ue=typeof window>"u"?!0:"onscrollend"in window,We=(l,f)=>{const t=l.scrollElement;if(!t)return;const i=l.targetWindow;if(!i)return;let e=0;const o=l.options.useScrollendEvent&&ue?()=>{}:Be(i,()=>{f(e,!1)},l.options.isScrollingResetDelay),a=r=>()=>{const{horizontal:p,isRtl:x}=l.options;e=p?t.scrollLeft*(x&&-1||1):t.scrollTop,o(),f(e,r)},n=a(!0),c=a(!1);c(),t.addEventListener("scroll",n,se);const d=l.options.useScrollendEvent&&ue;return d&&t.addEventListener("scrollend",c,se),()=>{t.removeEventListener("scroll",n),d&&t.removeEventListener("scrollend",c)}},Ue=(l,f,t)=>{if(f!=null&&f.borderBoxSize){const i=f.borderBoxSize[0];if(i)return Math.round(i[t.options.horizontal?"inlineSize":"blockSize"])}return l[t.options.horizontal?"offsetWidth":"offsetHeight"]},qe=(l,{adjustments:f=0,behavior:t},i)=>{var e,o;const a=l+f;(o=(e=i.scrollElement)==null?void 0:e.scrollTo)==null||o.call(e,{[i.options.horizontal?"left":"top"]:a,behavior:t})};class Ke{constructor(f){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.measurementsCache=[],this.itemSizeCache=new Map,this.pendingMeasuredCacheIndexes=[],this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this.scrollAdjustments=0,this.elementsCache=new Map,this.observer=(()=>{let t=null;const i=()=>t||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:t=new this.targetWindow.ResizeObserver(e=>{e.forEach(o=>{const a=()=>{this._measureElement(o.target,o)};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(a):a()})}));return{disconnect:()=>{var e;(e=i())==null||e.disconnect(),t=null},observe:e=>{var o;return(o=i())==null?void 0:o.observe(e,{box:"border-box"})},unobserve:e=>{var o;return(o=i())==null?void 0:o.unobserve(e)}}})(),this.range=null,this.setOptions=t=>{Object.entries(t).forEach(([i,e])=>{typeof e>"u"&&delete t[i]}),this.options={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:je,rangeExtractor:Le,onChange:()=>{},measureElement:Ue,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:"data-index",initialMeasurementsCache:[],lanes:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,...t}},this.notify=t=>{var i,e;(e=(i=this.options).onChange)==null||e.call(i,this,t)},this.maybeNotify=L(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),t=>{this.notify(t)},{key:!1,debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{this.unsubs.filter(Boolean).forEach(t=>t()),this.unsubs=[],this.observer.disconnect(),this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{var e;var t;const i=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==i){if(this.cleanup(),!i){this.maybeNotify();return}this.scrollElement=i,this.scrollElement&&"ownerDocument"in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=(e=(t=this.scrollElement)==null?void 0:t.window)!=null?e:null,this.elementsCache.forEach(o=>{this.observer.observe(o)}),this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0}),this.unsubs.push(this.options.observeElementRect(this,o=>{this.scrollRect=o,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(o,a)=>{this.scrollAdjustments=0,this.scrollDirection=a?this.getScrollOffset()<o?"forward":"backward":null,this.scrollOffset=o,this.isScrolling=a,this.maybeNotify()}))}},this.getSize=()=>{var t;return this.options.enabled?(this.scrollRect=(t=this.scrollRect)!=null?t:this.options.initialRect,this.scrollRect[this.options.horizontal?"width":"height"]):(this.scrollRect=null,0)},this.getScrollOffset=()=>{var t;return this.options.enabled?(this.scrollOffset=(t=this.scrollOffset)!=null?t:typeof this.options.initialOffset=="function"?this.options.initialOffset():this.options.initialOffset,this.scrollOffset):(this.scrollOffset=null,0)},this.getFurthestMeasurement=(t,i)=>{const e=new Map,o=new Map;for(let a=i-1;a>=0;a--){const n=t[a];if(e.has(n.lane))continue;const c=o.get(n.lane);if(c==null||n.end>c.end?o.set(n.lane,n):n.end<c.end&&e.set(n.lane,!0),e.size===this.options.lanes)break}return o.size===this.options.lanes?Array.from(o.values()).sort((a,n)=>a.end===n.end?a.index-n.index:a.end-n.end)[0]:void 0},this.getMeasurementOptions=L(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled],(t,i,e,o,a)=>(this.pendingMeasuredCacheIndexes=[],{count:t,paddingStart:i,scrollMargin:e,getItemKey:o,enabled:a}),{key:!1}),this.getMeasurements=L(()=>[this.getMeasurementOptions(),this.itemSizeCache],({count:t,paddingStart:i,scrollMargin:e,getItemKey:o,enabled:a},n)=>{if(!a)return this.measurementsCache=[],this.itemSizeCache.clear(),[];this.measurementsCache.length===0&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(r=>{this.itemSizeCache.set(r.key,r.size)}));const c=this.pendingMeasuredCacheIndexes.length>0?Math.min(...this.pendingMeasuredCacheIndexes):0;this.pendingMeasuredCacheIndexes=[];const d=this.measurementsCache.slice(0,c);for(let r=c;r<t;r++){const p=o(r),x=this.options.lanes===1?d[r-1]:this.getFurthestMeasurement(d,r),T=x?x.end+this.options.gap:i+e,y=n.get(p),z=typeof y=="number"?y:this.options.estimateSize(r),P=T+z,k=x?x.lane:r%this.options.lanes;d[r]={index:r,start:T,size:z,end:P,key:p,lane:k}}return this.measurementsCache=d,d},{key:!1,debug:()=>this.options.debug}),this.calculateRange=L(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(t,i,e,o)=>this.range=t.length>0&&i>0?He({measurements:t,outerSize:i,scrollOffset:e,lanes:o}):null,{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=L(()=>{let t=null,i=null;const e=this.calculateRange();return e&&(t=e.startIndex,i=e.endIndex),this.maybeNotify.updateDeps([this.isScrolling,t,i]),[this.options.rangeExtractor,this.options.overscan,this.options.count,t,i]},(t,i,e,o,a)=>o===null||a===null?[]:t({startIndex:o,endIndex:a,overscan:i,count:e}),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=t=>{const i=this.options.indexAttribute,e=t.getAttribute(i);return e?parseInt(e,10):(console.warn("Missing attribute name '".concat(i,"={index}' on measured element.")),-1)},this._measureElement=(t,i)=>{const e=this.indexFromElement(t),o=this.measurementsCache[e];if(!o)return;const a=o.key,n=this.elementsCache.get(a);n!==t&&(n&&this.observer.unobserve(n),this.observer.observe(t),this.elementsCache.set(a,t)),t.isConnected&&this.resizeItem(e,this.options.measureElement(t,i,this))},this.resizeItem=(t,i)=>{var n;const e=this.measurementsCache[t];if(!e)return;const o=(n=this.itemSizeCache.get(e.key))!=null?n:e.size,a=i-o;a!==0&&((this.shouldAdjustScrollPositionOnItemSizeChange!==void 0?this.shouldAdjustScrollPositionOnItemSizeChange(e,a,this):e.start<this.getScrollOffset()+this.scrollAdjustments)&&this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=a,behavior:void 0}),this.pendingMeasuredCacheIndexes.push(e.index),this.itemSizeCache=new Map(this.itemSizeCache.set(e.key,i)),this.notify(!1))},this.measureElement=t=>{if(!t){this.elementsCache.forEach((i,e)=>{i.isConnected||(this.observer.unobserve(i),this.elementsCache.delete(e))});return}this._measureElement(t,void 0)},this.getVirtualItems=L(()=>[this.getVirtualIndexes(),this.getMeasurements()],(t,i)=>{const e=[];for(let o=0,a=t.length;o<a;o++){const n=t[o],c=i[n];e.push(c)}return e},{key:!1,debug:()=>this.options.debug}),this.getVirtualItemForOffset=t=>{const i=this.getMeasurements();if(i.length!==0)return oe(i[he(0,i.length-1,e=>oe(i[e]).start,t)])},this.getOffsetForAlignment=(t,i,e=0)=>{const o=this.getSize(),a=this.getScrollOffset();i==="auto"&&(i=t>=a+o?"end":"start"),i==="center"?t+=(e-o)/2:i==="end"&&(t-=o);const n=this.getTotalSize()+this.options.scrollMargin-o;return Math.max(Math.min(n,t),0)},this.getOffsetForIndex=(t,i="auto")=>{t=Math.max(0,Math.min(t,this.options.count-1));const e=this.measurementsCache[t];if(!e)return;const o=this.getSize(),a=this.getScrollOffset();if(i==="auto")if(e.end>=a+o-this.options.scrollPaddingEnd)i="end";else if(e.start<=a+this.options.scrollPaddingStart)i="start";else return[a,i];const n=i==="end"?e.end+this.options.scrollPaddingEnd:e.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(n,i,e.size),i]},this.isDynamicMode=()=>this.elementsCache.size>0,this.scrollToOffset=(t,{align:i="start",behavior:e}={})=>{e==="smooth"&&this.isDynamicMode()&&console.warn("The `smooth` scroll behavior is not fully supported with dynamic size."),this._scrollToOffset(this.getOffsetForAlignment(t,i),{adjustments:void 0,behavior:e})},this.scrollToIndex=(t,{align:i="auto",behavior:e}={})=>{e==="smooth"&&this.isDynamicMode()&&console.warn("The `smooth` scroll behavior is not fully supported with dynamic size."),t=Math.max(0,Math.min(t,this.options.count-1));let o=0;const a=10,n=d=>{if(!this.targetWindow)return;const r=this.getOffsetForIndex(t,d);if(!r){console.warn("Failed to get offset for index:",t);return}const[p,x]=r;this._scrollToOffset(p,{adjustments:void 0,behavior:e}),this.targetWindow.requestAnimationFrame(()=>{const T=this.getScrollOffset(),y=this.getOffsetForIndex(t,x);if(!y){console.warn("Failed to get offset for index:",t);return}_e(y[0],T)||c(x)})},c=d=>{this.targetWindow&&(o++,o<a?this.targetWindow.requestAnimationFrame(()=>n(d)):console.warn("Failed to scroll to index ".concat(t," after ").concat(a," attempts.")))};n(i)},this.scrollBy=(t,{behavior:i}={})=>{i==="smooth"&&this.isDynamicMode()&&console.warn("The `smooth` scroll behavior is not fully supported with dynamic size."),this._scrollToOffset(this.getScrollOffset()+t,{adjustments:void 0,behavior:i})},this.getTotalSize=()=>{var o;var t;const i=this.getMeasurements();let e;if(i.length===0)e=this.options.paddingStart;else if(this.options.lanes===1)e=(o=(t=i[i.length-1])==null?void 0:t.end)!=null?o:0;else{const a=Array(this.options.lanes).fill(null);let n=i.length-1;for(;n>=0&&a.some(c=>c===null);){const c=i[n];a[c.lane]===null&&(a[c.lane]=c.end),n--}e=Math.max(...a.filter(c=>c!==null))}return Math.max(e-this.options.scrollMargin+this.options.paddingEnd,0)},this._scrollToOffset=(t,{adjustments:i,behavior:e})=>{this.options.scrollToFn(t,{behavior:e,adjustments:i},this)},this.measure=()=>{this.itemSizeCache=new Map,this.notify(!1)},this.setOptions(f)}}const he=(l,f,t,i)=>{for(;l<=f;){const e=(l+f)/2|0,o=t(e);if(o<i)l=e+1;else if(o>i)f=e-1;else return e}return l>0?l-1:0};function He({measurements:l,outerSize:f,scrollOffset:t,lanes:i}){const e=l.length-1,o=c=>l[c].start;if(l.length<=i)return{startIndex:0,endIndex:e};let a=he(0,e,o,t),n=a;if(i===1)for(;n<e&&l[n].end<t+f;)n++;else if(i>1){const c=Array(i).fill(0);for(;n<e&&c.some(r=>r<t+f);){const r=l[n];c[r.lane]=r.end,n++}const d=Array(i).fill(t+f);for(;a>=0&&d.some(r=>r>=t);){const r=l[a];d[r.lane]=r.start,a--}a=Math.max(0,a-a%i),n=Math.min(e,n+(i-1-n%i))}return{startIndex:a,endIndex:n}}function Je(l){const f=new Ke(K(l)),t=xe(f),i=f._didMount();return B(()=>K(l).getScrollElement(),e=>{e&&f._willUpdate()},{immediate:!0}),B(()=>K(l),e=>{f.setOptions({...e,onChange:(o,a)=>{var n;ne(t),(n=e.onChange)==null||n.call(e,o,a)}}),f._willUpdate(),ne(t)},{immediate:!0}),Oe(i),t}function Ye(l){return Je(S(()=>({observeElementRect:Ne,observeElementOffset:We,scrollToFn:qe,...K(l)})))}function Ge(){let l=X();return de(()=>l.dispose()),l}function Qe(){let l=Ge();return f=>{l.dispose(),l.nextFrame(f)}}var pe=(l=>(l[l.Left=0]="Left",l[l.Right=2]="Right",l))(pe||{}),Xe={};function Ze(l,f){return l===f}var et=(l=>(l[l.Open=0]="Open",l[l.Closed=1]="Closed",l))(et||{}),tt=(l=>(l[l.Single=0]="Single",l[l.Multi=1]="Multi",l))(tt||{}),nt=(l=>(l[l.Pointer=0]="Pointer",l[l.Focus=1]="Focus",l[l.Other=2]="Other",l))(nt||{});let me=Symbol("ComboboxContext");function q(l){let f=fe(me,null);if(f===null){let t=new Error("<".concat(l," /> is missing a parent <Combobox /> component."));throw Error.captureStackTrace&&Error.captureStackTrace(t,q),t}return f}let be=Symbol("VirtualContext"),lt=U({name:"VirtualProvider",setup(l,{slots:f}){let t=q("VirtualProvider"),i=S(()=>{let n=E(t.optionsRef);if(!n)return{start:0,end:0};let c=window.getComputedStyle(n);return{start:parseFloat(c.paddingBlockStart||c.paddingTop),end:parseFloat(c.paddingBlockEnd||c.paddingBottom)}}),e=Ye(S(()=>({scrollPaddingStart:i.value.start,scrollPaddingEnd:i.value.end,count:t.virtual.value.options.length,estimateSize(){return 40},getScrollElement(){return E(t.optionsRef)},overscan:12}))),o=S(()=>{var n;return(n=t.virtual.value)==null?void 0:n.options}),a=F(0);return B([o],()=>{a.value+=1}),ce(be,t.virtual.value?e:null),()=>[H("div",{style:{position:"relative",width:"100%",height:"".concat(e.value.getTotalSize(),"px")},ref:n=>{if(n){if(typeof process<"u"&&Xe.JEST_WORKER_ID!==void 0||t.activationTrigger.value===0)return;t.activeOptionIndex.value!==null&&t.virtual.value.options.length>t.activeOptionIndex.value&&e.value.scrollToIndex(t.activeOptionIndex.value)}}},e.value.getVirtualItems().map(n=>Ie(f.default({option:t.virtual.value.options[n.index],open:t.comboboxState.value===0})[0],{key:"".concat(a.value,"-").concat(n.index),"data-index":n.index,"aria-setsize":t.virtual.value.options.length,"aria-posinset":n.index+1,style:{position:"absolute",top:0,left:0,transform:"translateY(".concat(n.start,"px)"),overflowAnchor:"none"}})))]}}),pt=U({name:"Combobox",emits:{"update:modelValue":l=>!0},props:{as:{type:[Object,String],default:"template"},disabled:{type:[Boolean],default:!1},by:{type:[String,Function],nullable:!0,default:null},modelValue:{type:[Object,String,Number,Boolean],default:void 0},defaultValue:{type:[Object,String,Number,Boolean],default:void 0},form:{type:String,optional:!0},name:{type:String,optional:!0},nullable:{type:Boolean,default:!1},multiple:{type:[Boolean],default:!1},immediate:{type:[Boolean],default:!1},virtual:{type:Object,default:null}},inheritAttrs:!1,setup(l,{slots:f,attrs:t,emit:i}){let e=F(1),o=F(null),a=F(null),n=F(null),c=F(null),d=F({static:!1,hold:!1}),r=F([]),p=F(null),x=F(2),T=F(!1);function y(s=v=>v){let v=p.value!==null?r.value[p.value]:null,m=s(r.value.slice()),g=m.length>0&&m[0].dataRef.order.value!==null?m.sort((M,D)=>M.dataRef.order.value-D.dataRef.order.value):ze(m,M=>E(M.dataRef.domRef)),C=v?g.indexOf(v):null;return C===-1&&(C=null),{options:g,activeOptionIndex:C}}let z=S(()=>l.multiple?1:0),P=S(()=>l.nullable),[k,b]=Re(S(()=>l.modelValue),s=>i("update:modelValue",s),S(()=>l.defaultValue)),O=S(()=>k.value===void 0?N(z.value,{1:[],0:void 0}):k.value),$=null,h=null;function R(s){return N(z.value,{0(){return b==null?void 0:b(s)},1:()=>{let v=_(u.value.value).slice(),m=_(s),g=v.findIndex(C=>u.compare(m,_(C)));return g===-1?v.push(m):v.splice(g,1),b==null?void 0:b(v)}})}let w=S(()=>{});B([w],([s],[v])=>{if(u.virtual.value&&s&&v&&p.value!==null){let m=s.indexOf(v[p.value]);m!==-1?p.value=m:p.value=null}});let u={comboboxState:e,value:O,mode:z,compare(s,v){if(typeof l.by=="string"){let m=l.by;return(s==null?void 0:s[m])===(v==null?void 0:v[m])}return l.by===null?Ze(s,v):l.by(s,v)},calculateIndex(s){return u.virtual.value?l.by===null?u.virtual.value.options.indexOf(s):u.virtual.value.options.findIndex(v=>u.compare(v,s)):r.value.findIndex(v=>u.compare(v.dataRef.value,s))},defaultValue:S(()=>l.defaultValue),nullable:P,immediate:S(()=>!1),virtual:S(()=>null),inputRef:a,labelRef:o,buttonRef:n,optionsRef:c,disabled:S(()=>l.disabled),options:r,change(s){b(s)},activeOptionIndex:S(()=>{if(T.value&&p.value===null&&(u.virtual.value?u.virtual.value.options.length>0:r.value.length>0)){if(u.virtual.value){let v=u.virtual.value.options.findIndex(m=>{var g;return!((g=u.virtual.value)!=null&&g.disabled(m))});if(v!==-1)return v}let s=r.value.findIndex(v=>!v.dataRef.disabled);if(s!==-1)return s}return p.value}),activationTrigger:x,optionsPropsRef:d,closeCombobox(){T.value=!1,!l.disabled&&e.value!==1&&(e.value=1,p.value=null)},openCombobox(){if(T.value=!0,!l.disabled&&e.value!==0){if(u.value.value){let s=u.calculateIndex(u.value.value);s!==-1&&(p.value=s)}e.value=0}},setActivationTrigger(s){x.value=s},goToOption(s,v,m){T.value=!1,$!==null&&cancelAnimationFrame($),$=requestAnimationFrame(()=>{if(l.disabled||c.value&&!d.value.static&&e.value===1)return;if(u.virtual.value){p.value=s===A.Specific?v:ie({focus:s},{resolveItems:()=>u.virtual.value.options,resolveActiveIndex:()=>{var M,D;return(D=(M=u.activeOptionIndex.value)!=null?M:u.virtual.value.options.findIndex(j=>{var W;return!((W=u.virtual.value)!=null&&W.disabled(j))}))!=null?D:null},resolveDisabled:M=>u.virtual.value.disabled(M),resolveId(){throw new Error("Function not implemented.")}}),x.value=m!=null?m:2;return}let g=y();if(g.activeOptionIndex===null){let M=g.options.findIndex(D=>!D.dataRef.disabled);M!==-1&&(g.activeOptionIndex=M)}let C=s===A.Specific?v:ie({focus:s},{resolveItems:()=>g.options,resolveActiveIndex:()=>g.activeOptionIndex,resolveId:M=>M.id,resolveDisabled:M=>M.dataRef.disabled});p.value=C,x.value=m!=null?m:2,r.value=g.options})},selectOption(s){let v=r.value.find(g=>g.id===s);if(!v)return;let{dataRef:m}=v;R(m.value)},selectActiveOption(){if(u.activeOptionIndex.value!==null){if(u.virtual.value)R(u.virtual.value.options[u.activeOptionIndex.value]);else{let{dataRef:s}=r.value[u.activeOptionIndex.value];R(s.value)}u.goToOption(A.Specific,u.activeOptionIndex.value)}},registerOption(s,v){let m=Se({id:s,dataRef:v});if(u.virtual.value){r.value.push(m);return}h&&cancelAnimationFrame(h);let g=y(C=>(C.push(m),C));p.value===null&&u.isSelected(v.value.value)&&(g.activeOptionIndex=g.options.indexOf(m)),r.value=g.options,p.value=g.activeOptionIndex,x.value=2,g.options.some(C=>!E(C.dataRef.domRef))&&(h=requestAnimationFrame(()=>{let C=y();r.value=C.options,p.value=C.activeOptionIndex}))},unregisterOption(s,v){if($!==null&&cancelAnimationFrame($),v&&(T.value=!0),u.virtual.value){r.value=r.value.filter(g=>g.id!==s);return}let m=y(g=>{let C=g.findIndex(M=>M.id===s);return C!==-1&&g.splice(C,1),g});r.value=m.options,p.value=m.activeOptionIndex,x.value=2},isSelected(s){return N(z.value,{0:()=>u.compare(_(u.value.value),_(s)),1:()=>_(u.value.value).some(v=>u.compare(_(v),_(s)))})},isActive(s){return p.value===u.calculateIndex(s)}};Fe([a,n,c],()=>u.closeCombobox(),S(()=>e.value===0)),ce(me,u),Ae(S(()=>N(e.value,{0:G.Open,1:G.Closed})));let I=S(()=>{var s;return(s=E(a))==null?void 0:s.closest("form")});return Z(()=>{B([I],()=>{if(!I.value||l.defaultValue===void 0)return;function s(){u.change(l.defaultValue)}return I.value.addEventListener("reset",s),()=>{var v;(v=I.value)==null||v.removeEventListener("reset",s)}},{immediate:!0})}),()=>{var s,v,m;let{name:g,disabled:C,form:M,...D}=l,j={open:e.value===0,disabled:C,activeIndex:u.activeOptionIndex.value,activeOption:u.activeOptionIndex.value===null?null:u.virtual.value?u.virtual.value.options[(s=u.activeOptionIndex.value)!=null?s:0]:(m=(v=u.options.value[u.activeOptionIndex.value])==null?void 0:v.dataRef.value)!=null?m:null,value:O.value};return H(ye,[...g!=null&&O.value!=null?we({[g]:O.value}).map(([W,ge])=>H(Ce,Ee({features:Me.Hidden,key:W,as:"input",type:"hidden",hidden:!0,readOnly:!0,form:M,disabled:C,name:W,value:ge}))):[],Q({theirProps:{...t,...ee(D,["by","defaultValue","immediate","modelValue","multiple","nullable","onUpdate:modelValue","virtual"])},ourProps:{},slot:j,slots:f,attrs:t,name:"Combobox"})])}}}),mt=U({name:"ComboboxInput",props:{as:{type:[Object,String],default:"input"},static:{type:Boolean,default:!1},unmount:{type:Boolean,default:!0},displayValue:{type:Function},defaultValue:{type:String,default:void 0},id:{type:String,default:null}},emits:{change:l=>!0},setup(l,{emit:f,attrs:t,slots:i,expose:e}){var o;let a=(o=l.id)!=null?o:"headlessui-combobox-input-".concat(te()),n=q("ComboboxInput"),c=S(()=>Te(E(n.inputRef))),d={value:!1};e({el:n.inputRef,$el:n.inputRef});function r(){n.change(null);let h=E(n.optionsRef);h&&(h.scrollTop=0),n.goToOption(A.Nothing)}let p=S(()=>{var h;let R=n.value.value;return E(n.inputRef)?typeof l.displayValue<"u"&&R!==void 0?(h=l.displayValue(R))!=null?h:"":typeof R=="string"?R:"":""});Z(()=>{B([p,n.comboboxState,c],([h,R],[w,u])=>{if(d.value)return;let I=E(n.inputRef);I&&((u===0&&R===1||h!==w)&&(I.value=h),requestAnimationFrame(()=>{var s;if(d.value||!I||((s=c.value)==null?void 0:s.activeElement)!==I)return;let{selectionStart:v,selectionEnd:m}=I;Math.abs((m!=null?m:0)-(v!=null?v:0))===0&&v===0&&I.setSelectionRange(I.value.length,I.value.length)}))},{immediate:!0}),B([n.comboboxState],([h],[R])=>{if(h===0&&R===1){if(d.value)return;let w=E(n.inputRef);if(!w)return;let u=w.value,{selectionStart:I,selectionEnd:s,selectionDirection:v}=w;w.value="",w.value=u,v!==null?w.setSelectionRange(I,s,v):w.setSelectionRange(I,s)}})});let x=F(!1);function T(){x.value=!0}function y(){X().nextFrame(()=>{x.value=!1})}let z=Qe();function P(h){switch(d.value=!0,z(()=>{d.value=!1}),h.key){case V.Enter:if(d.value=!1,n.comboboxState.value!==0||x.value)return;if(h.preventDefault(),h.stopPropagation(),n.activeOptionIndex.value===null){n.closeCombobox();return}n.selectActiveOption(),n.mode.value===0&&n.closeCombobox();break;case V.ArrowDown:return d.value=!1,h.preventDefault(),h.stopPropagation(),N(n.comboboxState.value,{0:()=>n.goToOption(A.Next),1:()=>n.openCombobox()});case V.ArrowUp:return d.value=!1,h.preventDefault(),h.stopPropagation(),N(n.comboboxState.value,{0:()=>n.goToOption(A.Previous),1:()=>{n.openCombobox(),ve(()=>{n.value.value||n.goToOption(A.Last)})}});case V.Home:if(h.shiftKey)break;return d.value=!1,h.preventDefault(),h.stopPropagation(),n.goToOption(A.First);case V.PageUp:return d.value=!1,h.preventDefault(),h.stopPropagation(),n.goToOption(A.First);case V.End:if(h.shiftKey)break;return d.value=!1,h.preventDefault(),h.stopPropagation(),n.goToOption(A.Last);case V.PageDown:return d.value=!1,h.preventDefault(),h.stopPropagation(),n.goToOption(A.Last);case V.Escape:if(d.value=!1,n.comboboxState.value!==0)return;h.preventDefault(),n.optionsRef.value&&!n.optionsPropsRef.value.static&&h.stopPropagation(),n.nullable.value&&n.mode.value===0&&n.value.value===null&&r(),n.closeCombobox();break;case V.Tab:if(d.value=!1,n.comboboxState.value!==0)return;n.mode.value===0&&n.activationTrigger.value!==1&&n.selectActiveOption(),n.closeCombobox();break}}function k(h){f("change",h),n.nullable.value&&n.mode.value===0&&h.target.value===""&&r(),n.openCombobox()}function b(h){var R,w,u;let I=(R=h.relatedTarget)!=null?R:le.find(s=>s!==h.currentTarget);if(d.value=!1,!((w=E(n.optionsRef))!=null&&w.contains(I))&&!((u=E(n.buttonRef))!=null&&u.contains(I))&&n.comboboxState.value===0)return h.preventDefault(),n.mode.value===0&&(n.nullable.value&&n.value.value===null?r():n.activationTrigger.value!==1&&n.selectActiveOption()),n.closeCombobox()}function O(h){var R,w,u;let I=(R=h.relatedTarget)!=null?R:le.find(s=>s!==h.currentTarget);(w=E(n.buttonRef))!=null&&w.contains(I)||(u=E(n.optionsRef))!=null&&u.contains(I)||n.disabled.value||n.immediate.value&&n.comboboxState.value!==0&&(n.openCombobox(),X().nextFrame(()=>{n.setActivationTrigger(1)}))}let $=S(()=>{var h,R,w,u;return(u=(w=(R=l.defaultValue)!=null?R:n.defaultValue.value!==void 0?(h=l.displayValue)==null?void 0:h.call(l,n.defaultValue.value):null)!=null?w:n.defaultValue.value)!=null?u:""});return()=>{var h,R,w,u,I,s,v;let m={open:n.comboboxState.value===0},{displayValue:g,onChange:C,...M}=l,D={"aria-controls":(h=n.optionsRef.value)==null?void 0:h.id,"aria-expanded":n.comboboxState.value===0,"aria-activedescendant":n.activeOptionIndex.value===null?void 0:n.virtual.value?(R=n.options.value.find(j=>!n.virtual.value.disabled(j.dataRef.value)&&n.compare(j.dataRef.value,n.virtual.value.options[n.activeOptionIndex.value])))==null?void 0:R.id:(w=n.options.value[n.activeOptionIndex.value])==null?void 0:w.id,"aria-labelledby":(s=(u=E(n.labelRef))==null?void 0:u.id)!=null?s:(I=E(n.buttonRef))==null?void 0:I.id,"aria-autocomplete":"list",id:a,onCompositionstart:T,onCompositionend:y,onKeydown:P,onInput:k,onFocus:O,onBlur:b,role:"combobox",type:(v=t.type)!=null?v:"text",tabIndex:0,ref:n.inputRef,defaultValue:$.value,disabled:n.disabled.value===!0?!0:void 0};return Q({ourProps:D,theirProps:M,slot:m,attrs:t,slots:i,features:Y.RenderStrategy|Y.Static,name:"ComboboxInput"})}}}),bt=U({name:"ComboboxOptions",props:{as:{type:[Object,String],default:"ul"},static:{type:Boolean,default:!1},unmount:{type:Boolean,default:!0},hold:{type:[Boolean],default:!1}},setup(l,{attrs:f,slots:t,expose:i}){let e=q("ComboboxOptions"),o="headlessui-combobox-options-".concat(te());i({el:e.optionsRef,$el:e.optionsRef}),J(()=>{e.optionsPropsRef.value.static=l.static}),J(()=>{e.optionsPropsRef.value.hold=l.hold});let a=Pe(),n=S(()=>a!==null?(a.value&G.Open)===G.Open:e.comboboxState.value===0);De({container:S(()=>E(e.optionsRef)),enabled:S(()=>e.comboboxState.value===0),accept(d){return d.getAttribute("role")==="option"?NodeFilter.FILTER_REJECT:d.hasAttribute("role")?NodeFilter.FILTER_SKIP:NodeFilter.FILTER_ACCEPT},walk(d){d.setAttribute("role","none")}});function c(d){d.preventDefault()}return()=>{var d,r,p;let x={open:e.comboboxState.value===0},T={"aria-labelledby":(p=(d=E(e.labelRef))==null?void 0:d.id)!=null?p:(r=E(e.buttonRef))==null?void 0:r.id,id:o,ref:e.optionsRef,role:"listbox","aria-multiselectable":e.mode.value===1?!0:void 0,onMousedown:c},y=ee(l,["hold"]);return Q({ourProps:T,theirProps:y,slot:x,attrs:f,slots:e.virtual.value&&e.comboboxState.value===0?{...t,default:()=>[H(lt,{},t.default)]}:t,features:Y.RenderStrategy|Y.Static,visible:n.value,name:"ComboboxOptions"})}}}),gt=U({name:"ComboboxOption",props:{as:{type:[Object,String],default:"li"},value:{type:[Object,String,Number,Boolean]},disabled:{type:Boolean,default:!1},order:{type:[Number],default:null}},setup(l,{slots:f,attrs:t,expose:i}){let e=q("ComboboxOption"),o="headlessui-combobox-option-".concat(te()),a=F(null),n=S(()=>l.disabled);i({el:a,$el:a});let c=S(()=>{var b;return e.virtual.value?e.activeOptionIndex.value===e.calculateIndex(l.value):e.activeOptionIndex.value===null?!1:((b=e.options.value[e.activeOptionIndex.value])==null?void 0:b.id)===o}),d=S(()=>e.isSelected(l.value)),r=fe(be,null),p=S(()=>({disabled:l.disabled,value:l.value,domRef:a,order:S(()=>l.order)}));Z(()=>e.registerOption(o,p)),de(()=>e.unregisterOption(o,c.value)),J(()=>{let b=E(a);b&&(r==null||r.value.measureElement(b))}),J(()=>{e.comboboxState.value===0&&c.value&&(e.virtual.value||e.activationTrigger.value!==0&&ve(()=>{var b,O;return(O=(b=E(a))==null?void 0:b.scrollIntoView)==null?void 0:O.call(b,{block:"nearest"})}))});function x(b){b.preventDefault(),b.button===pe.Left&&(n.value||(e.selectOption(o),$e()||requestAnimationFrame(()=>{var O;return(O=E(e.inputRef))==null?void 0:O.focus({preventScroll:!0})}),e.mode.value===0&&e.closeCombobox()))}function T(){var b;if(l.disabled||(b=e.virtual.value)!=null&&b.disabled(l.value))return e.goToOption(A.Nothing);let O=e.calculateIndex(l.value);e.goToOption(A.Specific,O)}let y=ke();function z(b){y.update(b)}function P(b){var O;if(!y.wasMoved(b)||l.disabled||(O=e.virtual.value)!=null&&O.disabled(l.value)||c.value)return;let $=e.calculateIndex(l.value);e.goToOption(A.Specific,$,0)}function k(b){var O;y.wasMoved(b)&&(l.disabled||(O=e.virtual.value)!=null&&O.disabled(l.value)||c.value&&(e.optionsPropsRef.value.hold||e.goToOption(A.Nothing)))}return()=>{let{disabled:b}=l,O={active:c.value,selected:d.value,disabled:b},$={id:o,ref:a,role:"option",tabIndex:b===!0?void 0:-1,"aria-disabled":b===!0?!0:void 0,"aria-selected":d.value,disabled:void 0,onMousedown:x,onFocus:T,onPointerenter:z,onMouseenter:z,onPointermove:P,onMousemove:P,onPointerleave:k,onMouseleave:k},h=ee(l,["order","value"]);return Q({ourProps:$,theirProps:h,slot:O,attrs:t,slots:f,name:"ComboboxOption"})}}});function xt(l={}){const{getUsers:f}=Ve(),t=F(""),i=F([]),e=F(!1);let o=null,a=0;return{query:t,options:i,fetching:e,search:d=>{if(t.value=d,o&&clearTimeout(o),!d||d.trim()===""){i.value=[];return}o=setTimeout(async()=>{var p;const r=++a;e.value=!0;try{const x=await f({search:d,per_page:(p=l.perPage)!=null?p:20});if(r!==a)return;const T=x.map(y=>({label:y.name,value:y.id}));i.value=l.exclude?T.filter(y=>!l.exclude(y)):T}catch(x){r===a&&(i.value=[])}finally{r===a&&(e.value=!1)}},300)},reset:()=>{t.value="",i.value=[],a++,e.value=!1,o&&(clearTimeout(o),o=null)}}}export{ht as C,bt as a,vt as b,mt as i,pt as l,gt as r,xt as u};
