import{Fn as e,Ln as t,Pn as n,Qt as r,qn as i,rn as a,zn as o}from"./index-BaTxSAlR.js";function s(e){return typeof e==`function`}function c(e,...t){return s(e)?e(...t):e}var l,u,d,f,p,m,h,g,_,v,y,b,x,S,C,w,T=(l=new WeakMap,u=new WeakMap,d=new WeakMap,f=new WeakMap,p=new WeakMap,m=new WeakMap,h=new WeakMap,g=new WeakMap,_=new WeakMap,v=new WeakMap,y=new WeakMap,b=new WeakMap,x=new WeakMap,S=new WeakMap,C=new WeakMap,w=new WeakMap,class{constructor({pluginId:r,debug:i=!1,enabled:a=!0,reconnectEveryMs:o=300}){t(this,l,!0),t(this,u,void 0),t(this,d,void 0),t(this,f,void 0),t(this,p,void 0),t(this,m,void 0),t(this,h,void 0),t(this,g,void 0),t(this,_,0),t(this,v,5),t(this,y,!1),t(this,b,!1),t(this,x,null),t(this,S,()=>{this.debugLog(`Connected to event bus`),n(m,this,!0),n(y,this,!1),this.debugLog(`Emitting queued events`,e(p,this)),e(p,this).forEach(e=>this.emitEventToBus(e)),n(p,this,[]),this.stopConnectLoop(),e(d,this).call(this).removeEventListener(`tanstack-connect-success`,e(S,this))}),t(this,C,()=>{if(e(_,this){e(y,this)||(n(y,this,!0),e(d,this).call(this).addEventListener(`tanstack-connect-success`,e(S,this)),e(C,this).call(this))}),n(u,this,r),n(l,this,a),n(d,this,this.getGlobalTarget),n(f,this,i),this.debugLog(` Initializing event subscription for plugin`,e(u,this)),n(p,this,[]),n(m,this,!1),n(b,this,!1),n(h,this,null),n(g,this,o)}startConnectLoop(){e(h,this)!==null||e(m,this)||(this.debugLog(`Starting connect loop (every ${e(g,this)}ms)`),n(h,this,setInterval(e(C,this),e(g,this))))}stopConnectLoop(){n(y,this,!1),e(h,this)!==null&&(clearInterval(e(h,this)),n(h,this,null),n(p,this,[]),this.debugLog(`Stopped connect loop`))}debugLog(...t){e(f,this)&&console.log(`🌴 [tanstack-devtools:${e(u,this)}-plugin]`,...t)}getGlobalTarget(){if(typeof globalThis<`u`&&globalThis.__TANSTACK_EVENT_TARGET__)return this.debugLog(`Using global event target`),globalThis.__TANSTACK_EVENT_TARGET__;if(typeof window<`u`&&window.addEventListener!==void 0)return this.debugLog(`Using window as event target`),window;let e=typeof EventTarget<`u`?new EventTarget:void 0;return e===void 0||e.addEventListener===void 0?(this.debugLog(`No event mechanism available, running in non-web environment`),{addEventListener:()=>{},removeEventListener:()=>{},dispatchEvent:()=>!1}):(this.debugLog(`Using new EventTarget as fallback`),e)}getPluginId(){return e(u,this)}dispatchCustomEventShim(t,n){try{let r=new Event(t,{detail:n});e(d,this).call(this).dispatchEvent(r)}catch{this.debugLog(`Failed to dispatch shim event`)}}dispatchCustomEvent(t,n){try{e(d,this).call(this).dispatchEvent(new CustomEvent(t,{detail:n}))}catch{this.dispatchCustomEventShim(t,n)}}emitEventToBus(e){this.debugLog(`Emitting event to client bus`,e),this.dispatchCustomEvent(`tanstack-dispatch-event`,e)}createEventPayload(t,n){return{type:`${e(u,this)}:${t}`,payload:n,pluginId:e(u,this)}}emit(t,n){if(!e(l,this)){this.debugLog(`Event bus client is disabled, not emitting event`,t,n);return}if(e(x,this)&&(this.debugLog(`Emitting event to internal event target`,t,n),e(x,this).dispatchEvent(new CustomEvent(`${e(u,this)}:${t}`,{detail:this.createEventPayload(t,n)}))),e(b,this)){this.debugLog(`Previously failed to connect, not emitting to bus`);return}if(!e(m,this)){this.debugLog(`Bus not available, will be pushed as soon as connected`),e(p,this).push(this.createEventPayload(t,n)),typeof CustomEvent<`u`&&!e(y,this)&&(e(w,this).call(this),this.startConnectLoop());return}return this.emitEventToBus(this.createEventPayload(t,n))}on(t,r,i){let a=(i==null?void 0:i.withEventTarget)??!1,o=`${e(u,this)}:${t}`;if(a&&(e(x,this)||n(x,this,new EventTarget),e(x,this).addEventListener(o,e=>{r(e.detail)})),!e(l,this))return this.debugLog(`Event bus client is disabled, not registering event`,o),()=>{};let s=e=>{this.debugLog(`Received event from bus`,e.detail),r(e.detail)};return e(d,this).call(this).addEventListener(o,s),this.debugLog(`Registered event to bus`,o),()=>{var t;a&&((t=e(x,this))==null||t.removeEventListener(o,s)),e(d,this).call(this).removeEventListener(o,s)}}onAll(t){if(!e(l,this))return this.debugLog(`Event bus client is disabled, not registering event`),()=>{};let n=e=>{let n=e.detail;t(n)};return e(d,this).call(this).addEventListener(`tanstack-devtools-global`,n),()=>e(d,this).call(this).removeEventListener(`tanstack-devtools-global`,n)}onAllPluginEvents(t){if(!e(l,this))return this.debugLog(`Event bus client is disabled, not registering event`),()=>{};let n=n=>{let r=n.detail;e(u,this)&&r.pluginId!==e(u,this)||t(r)};return e(d,this).call(this).addEventListener(`tanstack-devtools-global`,n),()=>e(d,this).call(this).removeEventListener(`tanstack-devtools-global`,n)}}),E=class extends T{constructor(e){super({pluginId:`pacer`,debug:e==null?void 0:e.debug})}},D=(e,t)=>{t.key&&O.emit(e,t)},O=new E,k=new WeakMap,A=new WeakMap,j={current:[]},M=!1,N=0,P=new Set,F=new Map;function I(e){let t=Array.from(e).sort((e,t)=>e instanceof H&&e.options.deps.includes(t)?1:t instanceof H&&t.options.deps.includes(e)?-1:0);for(let e of t){if(j.current.includes(e))continue;j.current.push(e),e.recompute();let t=A.get(e);if(t)for(let e of t){let t=k.get(e);t&&I(t)}}}function L(e){let t={prevVal:e.prevState,currentVal:e.state};for(let n of e.listeners)n(t)}function R(e){let t={prevVal:e.prevState,currentVal:e.state};for(let n of e.listeners)n(t)}function z(e){if(N>0&&!F.has(e)&&F.set(e,e.prevState),P.add(e),!(N>0)&&!M)try{for(M=!0;P.size>0;){let e=Array.from(P);P.clear();for(let t of e)t.prevState=F.get(t)??t.prevState,L(t);for(let t of e){let e=k.get(t);e&&(j.current.push(t),I(e))}for(let t of e){let e=k.get(t);if(e)for(let t of e)R(t)}}}finally{M=!1,j.current=[],F.clear()}}function B(e){return typeof e==`function`}var V=class{constructor(e,t){this.listeners=new Set,this.subscribe=e=>{var t,n;this.listeners.add(e);let r=(n=(t=this.options)==null?void 0:t.onSubscribe)==null?void 0:n.call(t,e,this);return()=>{this.listeners.delete(e),r==null||r()}},this.prevState=e,this.state=e,this.options=t}setState(e){var t,n,r;this.prevState=this.state,(t=this.options)!=null&&t.updateFn?this.state=this.options.updateFn(this.prevState)(e):B(e)?this.state=e(this.prevState):this.state=e,(r=(n=this.options)==null?void 0:n.onUpdate)==null||r.call(n),z(this)}},H=class e{constructor(t){this.listeners=new Set,this._subscriptions=[],this.lastSeenDepValues=[],this.getDepVals=()=>{let e=this.options.deps.length,t=Array(e),n=Array(e);for(let r=0;r{var e,t;this.prevState=this.state;let n=this.getDepVals();this.state=this.options.fn(n),(t=(e=this.options).onUpdate)==null||t.call(e)},this.checkIfRecalculationNeededDeeply=()=>{for(let t of this.options.deps)t instanceof e&&t.checkIfRecalculationNeededDeeply();let t=!1,n=this.lastSeenDepValues,{currDepVals:r}=this.getDepVals();for(let e=0;e(this.registerOnGraph(),this.checkIfRecalculationNeededDeeply(),()=>{this.unregisterFromGraph();for(let e of this._subscriptions)e()}),this.subscribe=e=>{var t,n;this.listeners.add(e);let r=(n=(t=this.options).onSubscribe)==null?void 0:n.call(t,e,this);return()=>{this.listeners.delete(e),r==null||r()}},this.options=t,this.state=t.fn({prevDepVals:void 0,prevVal:void 0,currDepVals:this.getDepVals().currDepVals})}registerOnGraph(t=this.options.deps){for(let n of t)if(n instanceof e)n.registerOnGraph(),this.registerOnGraph(n.options.deps);else if(n instanceof V){let e=k.get(n);e||(e=new Set,k.set(n,e)),e.add(this);let t=A.get(this);t||(t=new Set,A.set(this,t)),t.add(n)}}unregisterFromGraph(t=this.options.deps){for(let n of t)if(n instanceof e)this.unregisterFromGraph(n.options.deps);else if(n instanceof V){let e=k.get(n);e&&e.delete(this);let t=A.get(this);t&&t.delete(n)}}},U,W,G,K,q,J;function Y(){return{canLeadingExecute:!0,executionCount:0,isPending:!1,lastArgs:void 0,status:`idle`,maybeExecuteCount:0}}var X={enabled:!0,leading:!1,trailing:!0,wait:0},Z=(U=new WeakMap,W=new WeakMap,G=new WeakMap,K=new WeakMap,q=new WeakMap,J=new WeakMap,class{constructor(r,i){t(this,U,void 0),t(this,W,t=>{this.store.setState(n=>{let r={...n,...t},{isPending:i}=r;return{...r,status:e(G,this).call(this)?i?`pending`:`idle`:`disabled`}}),D(`Debouncer`,this)}),t(this,G,()=>!!c(this.options.enabled,this)),t(this,K,()=>c(this.options.wait,this)),t(this,q,(...t)=>{var n,r;e(G,this).call(this)&&(this.fn(...t),e(W,this).call(this,{executionCount:this.store.state.executionCount+1,isPending:!1,lastArgs:void 0}),(n=(r=this.options).onExecute)==null||n.call(r,t,this))}),t(this,J,()=>{e(U,this)&&(clearTimeout(e(U,this)),n(U,this,void 0))}),this.fn=r,this.store=new V(Y()),this.setOptions=t=>{this.options={...this.options,...t},e(G,this).call(this)||this.cancel()},this.maybeExecute=(...t)=>{if(!e(G,this).call(this))return;e(W,this).call(this,{maybeExecuteCount:this.store.state.maybeExecuteCount+1});let r=!1;this.options.leading&&this.store.state.canLeadingExecute&&(e(W,this).call(this,{canLeadingExecute:!1}),r=!0,e(q,this).call(this,...t)),this.options.trailing&&e(W,this).call(this,{isPending:!0,lastArgs:t}),e(U,this)&&clearTimeout(e(U,this)),n(U,this,setTimeout(()=>{e(W,this).call(this,{canLeadingExecute:!0}),this.options.trailing&&!r&&e(q,this).call(this,...t)},e(K,this).call(this)))},this.flush=()=>{this.store.state.isPending&&this.store.state.lastArgs&&(e(J,this).call(this),e(q,this).call(this,...this.store.state.lastArgs))},this.cancel=()=>{e(J,this).call(this),e(W,this).call(this,{canLeadingExecute:!0,isPending:!1})},this.reset=()=>{e(W,this).call(this,Y())},this.key=i.key,this.options={...X,...i},e(W,this).call(this,this.options.initialState??{}),this.key&&O.on(`d-Debouncer`,t=>{t.payload.key===this.key&&(e(W,this).call(this,t.payload.store.state),this.setOptions(t.payload.options))})}});function Q(e,t){return new Z(e,t).maybeExecute}var $=i(o(),1);function ee({table:e,className:t,simple:n}){var i;return(0,$.jsxs)(`div`,{className:a(`flex items-center gap-2`,t),children:[!n&&(0,$.jsxs)(`div`,{className:`text-sm text-muted-foreground mr-4`,children:[`本页共`,((i=e.getRowModel().rows)==null?void 0:i.length)||0,`条,总共`,e.getRowCount(),`条`]}),(0,$.jsx)(r,{size:`sm`,variant:`outline`,onClick:Q(()=>e.previousPage(),{wait:500}),disabled:!e.getCanPreviousPage(),children:`上一页`}),(0,$.jsxs)(r,{size:`sm`,disabled:!0,variant:`ghost`,children:[e.getState().pagination.pageIndex+1,` / `,e.getPageCount()]}),(0,$.jsx)(r,{size:`sm`,variant:`outline`,onClick:Q(()=>e.nextPage(),{wait:500}),disabled:!e.getCanNextPage(),children:`下一页`})]})}export{ee as t};