import{p as x,g as b,e as B,d as y,i as V,D as w,c as h,j as C,v as E,a as k,F as P,o as M,ai as U,al as $,k as q}from"./index-9b57d2d5.js";const N=x({modelValue:{type:null,default:void 0},multiple:Boolean,mandatory:[Boolean,String],max:Number,selectedClass:String,disabled:Boolean},"group"),O=x({value:null,disabled:Boolean,selectedClass:String},"group-item");function R(t,a){let d=arguments.length>2&&arguments[2]!==void 0?arguments[2]:!0;const e=b("useGroupItem");if(!e)throw new Error("[Vuetify] useGroupItem composable must be used inside a component setup function");const n=B();y(Symbol.for(`${a.description}:id`),n);const l=V(a,null);if(!l){if(!d)return l;throw new Error(`[Vuetify] Could not find useGroup injection with symbol ${a.description}`)}const m=w(t,"value"),v=h(()=>!!(l.disabled.value||t.disabled));l.register({id:n,value:m,disabled:v},e),C(()=>{l.unregister(n)});const f=h(()=>l.isSelected(n)),I=h(()=>f.value&&[l.selectedClass.value,t.selectedClass]);return E(f,g=>{e.emit("group:selected",{value:g})}),{id:n,isSelected:f,toggle:()=>l.select(n,!f.value),select:g=>l.select(n,g),selectedClass:I,value:m,disabled:v,group:l}}function W(t,a){let d=!1;const e=k([]),n=P(t,"modelValue",[],s=>s==null?[]:S(e,$(s)),s=>{const i=A(e,s);return t.multiple?i:i[0]}),l=b("useGroup");function m(s,i){const o=s,u=Symbol.for(`${a.description}:id`),c=q(u,l==null?void 0:l.vnode).indexOf(i);c>-1?e.splice(c,0,o):e.push(o)}function v(s){if(d)return;f();const i=e.findIndex(o=>o.id===s);e.splice(i,1)}function f(){const s=e.find(i=>!i.disabled);s&&t.mandatory==="force"&&!n.value.length&&(n.value=[s.id])}M(()=>{f()}),C(()=>{d=!0});function I(s,i){const o=e.find(u=>u.id===s);if(!(i&&(o!=null&&o.disabled)))if(t.multiple){const u=n.value.slice(),r=u.findIndex(G=>G===s),c=~r;if(i=i??!c,c&&t.mandatory&&u.length<=1||!c&&t.max!=null&&u.length+1>t.max)return;r<0&&i?u.push(s):r>=0&&!i&&u.splice(r,1),n.value=u}else{const u=n.value.includes(s);if(t.mandatory&&u)return;n.value=i??!u?[s]:[]}}function g(s){if(t.multiple,n.value.length){const i=n.value[0],o=e.findIndex(c=>c.id===i);let u=(o+s)%e.length,r=e[u];for(;r.disabled&&u!==o;)u=(u+s)%e.length,r=e[u];if(r.disabled)return;n.value=[e[u].id]}else{const i=e.find(o=>!o.disabled);i&&(n.value=[i.id])}}const p={register:m,unregister:v,selected:n,select:I,disabled:w(t,"disabled"),prev:()=>g(e.length-1),next:()=>g(1),isSelected:s=>n.value.includes(s),selectedClass:h(()=>t.selectedClass),items:h(()=>e),getItemIndex:s=>F(e,s)};return y(a,p),p}function F(t,a){const d=S(t,[a]);return d.length?t.findIndex(e=>e.id===d[0]):-1}function S(t,a){const d=[];return a.forEach(e=>{const n=t.find(m=>U(e,m.value)),l=t[e];(n==null?void 0:n.value)!=null?d.push(n.id):l!=null&&d.push(l.id)}),d}function A(t,a){const d=[];return a.forEach(e=>{const n=t.findIndex(l=>l.id===e);if(~n){const l=t[n];d.push(l.value!=null?l.value:n)}}),d}export{O as a,R as b,N as m,W as u};
