(function(m,r){typeof exports=="object"&&typeof module<"u"?r(exports,require("vue"),require("@vueuse/core"),require("query-string"),require("@inertiajs/vue3")):typeof define=="function"&&define.amd?define(["exports","vue","@vueuse/core","query-string","@inertiajs/vue3"],r):(m=typeof globalThis<"u"?globalThis:m||self,r(m.Vanguard={},m.vue,m.core,m.queryString,m.vue3))})(this,function(m,r,M,T,v){"use strict";const P=(t,p)=>{const g=t.split(".");let o=p||v.usePage().props;for(const y of g)o=o[y];return o},L=t=>t===""||t===null||t===void 0||(t==null?void 0:t.length)===0,I=(t={})=>{const{_url:p=location.href,_watch:g=!0,_auto:o=!0,_only:y=[],transforms:n={},...i}=t,l=r.reactive({}),e=()=>{let f={};for(const d in l)if(d in n)f[d]=n[d](l[d]);else{if(L(l[d]))continue;f[d]=l[d]}return f},u=(f,d)=>{const F=T.stringifyUrl({url:d,query:{...f,page:void 0}},{arrayFormat:"comma"});v.router.visit(F,{only:y,preserveScroll:!0,preserveState:!0})},_=()=>T.parse(location.search,{arrayFormat:"comma"}),s=()=>u(e(),p),h=(f,d)=>l[f]=d,j=(f,d)=>{Array.isArray(l[f])?l[f].push(d):l[f]=[d]},A=f=>l[f]=null,q=()=>Object.assign(l,_()),{pause:O,resume:E}=M.watchPausable(l,s);return r.onMounted(()=>{o&&(O(),Object.assign(l,_(),i),r.nextTick(()=>{g&&E()}))}),{params:l,urlParams:e,pause:O,resume:E,reset:q,get:_,set:h,add:j,update:s,clear:A}},R="sort",x="order",B=(t,p,g={})=>{const{watch:o=!0}=g,y=r.computed(()=>P(t,p)),n=I({_auto:!1,_watch:o}),i=r.computed(()=>Object.entries(y.value.sorts).reduce((c,[a,S])=>(c[a]={...S,action:()=>{A(S.name,S.direction)},clear:()=>{j()}},c),{})),l=r.computed(()=>Object.entries(y.value.filters).reduce((c,[a,S])=>(c[a]={...S,action:U=>{F(S.name,U,S.type)},clear:()=>{f(S.name)}},c),{})),e=c=>i.value[c],u=c=>l.value[c],_=()=>{h(),E()},s=()=>Object.values(i.value).filter(({active:c})=>c),h=()=>j(),j=()=>{n.clear(R),n.clear(x)},A=(c,a)=>{n.set(R,c),n.set(x,a)},q=(c,a)=>{a?A(c,a):j()},O=()=>Object.values(l.value).filter(({active:c})=>c),E=()=>Object.keys(l.value).forEach(c=>d(c)),f=c=>d(c),d=c=>n.clear(c),F=(c,a,S)=>{S==="select"?n.add(c,a):n.set(c,a)},V=c=>c?s().some(({active:a})=>a):s().length!==0,z=c=>c?O().some(({active:a})=>a):O().length!==0;return r.onMounted(async()=>{n.pause(),Object.values(i.value).length>0&&(n.set(R,null),n.set(x,null)),Object.values(l.value).forEach(a=>n.set(a.name,null));const c=n.get();Object.keys(c).forEach(a=>a in n.params?n.set(a,c[a]):null),await r.nextTick(),o&&n.resume()}),{params:n.params,sorts:i,filters:l,update:n.update,getFilter:u,getSort:e,reset:_,currentSorts:s,currentFilters:O,isFiltering:z,isSorting:V,applyFilter:F,applySort:A,clearFilters:E,clearFilter:f,clearSorts:h,clearSort:j,loopSort:q,clear:n.clear,set:n.set,add:n.add}};function D(){const t=r.reactive({all:!1,only:new Set,except:new Set}),p=()=>{t.all=!0,t.only.clear(),t.except.clear()},g=()=>{t.all=!1,t.only.clear(),t.except.clear()},o=(...e)=>{e.forEach(u=>t.except.delete(u)),e.forEach(u=>t.only.add(u))},y=(...e)=>{e.forEach(u=>t.only.delete(u)),e.forEach(u=>t.except.add(u))},n=e=>t.all?!t.except.has(e):t.only.has(e),i=(...e)=>{e.forEach(u=>{n(u)?y(u):o(u)})},l=r.computed(()=>t.all&&t.except.size===0);return r.reactive({allSelected:l,selection:t,selectAll:p,deselectAll:g,select:o,deselect:y,toggle:i,selected:n})}const K=t=>({inline:r.computed(()=>t.inline),bulk:r.computed(()=>t.bulk),page:r.computed(()=>t.page.map(p=>({...p,exec:(g,o)=>{if(p.endpoint!==null){if(p.endpoint.method==="delete"){v.router.delete(p.endpoint.route,{...o});return}v.router[p.endpoint.method](p.endpoint.route,{...g},{...o})}}})))}),Q=(t,p,g={})=>{const o=r.computed(()=>P(t,p)),y=o.value.recordKey,n=B("refinements",o.value,g),i=s=>typeof s!="object"?s:Reflect.has(s,"__hybridId")?Reflect.get(s,"__hybridId"):Reflect.get(s,y),l=o.value.actions.bulk.length>0,e=l?D():null,u=l?{allSelected:e==null?void 0:e.allSelected,selection:e?r.toRef(e,"selection"):null,selectAll:e==null?void 0:e.selectAll,deselectAll:e==null?void 0:e.deselectAll,select:s=>e==null?void 0:e.select(i(s)),deselect:s=>e==null?void 0:e.deselect(i(s)),selected:s=>e==null?void 0:e.selected(i(s)),toggle:s=>e==null?void 0:e.toggle(i(s))}:{},_=o.value.preference_cols!==void 0?{preferences:r.computed(()=>o.value.preference_cols!==void 0?o.value.preference_cols.map(s=>({...s,set:h=>n.add(s.name,h),clear:()=>n.clear(s.name)})):null)}:{};return r.reactive({recordKey:y,cols:r.computed(()=>o.value.cols.reduce((s,h)=>(h.hidden||s.push({...h,sort:h.has_sort?()=>n.loopSort(h.sort_field,h.next_direction):()=>{},clear:h.has_sort?()=>n.clearSort():()=>{}}),s),[])),rows:r.computed(()=>o.value.rows.map(s=>({...s,key:i(s),...l?{select:()=>e==null?void 0:e.select(i(s)),deselect:()=>e==null?void 0:e.deselect(i(s)),toggle:()=>e==null?void 0:e.toggle(i(s)),isSelected:r.computed(()=>e==null?void 0:e.selected(i(s))),selected:e==null?void 0:e.selected(i(s))}:{}}))),meta:r.computed(()=>o.value.meta),actions:K(o.value.actions),...u,..._,...n})};m.useActions=K,m.useBulkSelect=D,m.useQuery=I,m.useRefinements=B,m.useTable=Q,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})});