@standardbeagle/edit-db 0.4.484 → 0.4.494

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/common/fetcher.d.ts +7 -2
  2. package/dist/components/content-panel.d.ts +5 -2
  3. package/dist/components/filters/fk-filter.d.ts +2 -0
  4. package/dist/components/filters/fk-filter.test.d.ts +1 -0
  5. package/dist/components/filters/number-filter.d.ts +1 -0
  6. package/dist/components/filters/number-filter.test.d.ts +1 -0
  7. package/dist/components/filters/use-debounced-commit.d.ts +19 -0
  8. package/dist/components/filters/use-debounced-commit.test.d.ts +1 -0
  9. package/dist/components/fk-cell-popover.d.ts +8 -1
  10. package/dist/components/fk-cell-popover.test.d.ts +1 -0
  11. package/dist/data-data-table.test.d.ts +0 -0
  12. package/dist/data-edit.d.ts +8 -0
  13. package/dist/edit-db.css +1 -1
  14. package/dist/editor.es.js +4262 -3610
  15. package/dist/editor.umd.cjs +33 -26
  16. package/dist/hooks/useCompositeTableRef.d.ts +19 -1
  17. package/dist/hooks/useCompositeTableRef.test.d.ts +1 -0
  18. package/dist/hooks/useDataTable.d.ts +13 -1
  19. package/dist/hooks/usePath.d.ts +1 -5
  20. package/dist/hooks/useTableMutation.test.d.ts +0 -0
  21. package/dist/hooks/useTableRef.d.ts +22 -1
  22. package/dist/hooks/useTableRef.test.d.ts +1 -0
  23. package/dist/hooks/useTableStats.d.ts +7 -0
  24. package/dist/hooks/useToast.d.ts +15 -0
  25. package/dist/lib/content-detect.d.ts +5 -0
  26. package/dist/lib/date-input.d.ts +21 -0
  27. package/dist/lib/date-input.test.d.ts +1 -0
  28. package/dist/lib/fk.d.ts +10 -2
  29. package/dist/lib/invalidate.d.ts +7 -0
  30. package/dist/lib/invalidate.test.d.ts +1 -0
  31. package/dist/lib/label-match.d.ts +13 -0
  32. package/dist/lib/label-match.test.d.ts +1 -0
  33. package/dist/lib/m2m.d.ts +19 -5
  34. package/dist/lib/query-builder.d.ts +24 -2
  35. package/dist/lib/row-id.d.ts +9 -0
  36. package/dist/lib/table-ref.d.ts +45 -0
  37. package/dist/lib/table-ref.test.d.ts +1 -0
  38. package/dist/types/schema.d.ts +9 -0
  39. package/package.json +1 -3
  40. package/dist/error-panel.d.ts +0 -1
@@ -1,17 +1,17 @@
1
- (function(fe,f){typeof exports=="object"&&typeof module<"u"?f(exports,require("react"),require("@tanstack/react-query"),require("lucide-react"),require("@radix-ui/react-slot"),require("radix-ui"),require("@tanstack/react-form"),require("@tanstack/react-table")):typeof define=="function"&&define.amd?define(["exports","react","@tanstack/react-query","lucide-react","@radix-ui/react-slot","radix-ui","@tanstack/react-form","@tanstack/react-table"],f):(fe=typeof globalThis<"u"?globalThis:fe||self,f(fe.editor={},fe.React,fe.ReactQuery,fe.LucideReact,fe.RadixReactSlot,fe.RadixUI,fe.ReactForm,fe.ReactTable))})(this,(function(fe,f,le,v,Ps,G,Pn,$t){"use strict";function Es(e){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const s=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(n,r,s.get?s:{enumerable:!0,get:()=>e[r]})}}return n.default=e,Object.freeze(n)}const pe=Es(f);var _t={exports:{}},it={};var En;function Ds(){if(En)return it;En=1;var e=f,n=Symbol.for("react.element"),r=Symbol.for("react.fragment"),s=Object.prototype.hasOwnProperty,o=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,i={key:!0,ref:!0,__self:!0,__source:!0};function a(l,c,m){var p,d={},h=null,y=null;m!==void 0&&(h=""+m),c.key!==void 0&&(h=""+c.key),c.ref!==void 0&&(y=c.ref);for(p in c)s.call(c,p)&&!i.hasOwnProperty(p)&&(d[p]=c[p]);if(l&&l.defaultProps)for(p in c=l.defaultProps,c)d[p]===void 0&&(d[p]=c[p]);return{$$typeof:n,type:l,key:h,ref:y,props:d,_owner:o.current}}return it.Fragment=r,it.jsx=a,it.jsxs=a,it}var lt={};var Dn;function Is(){return Dn||(Dn=1,process.env.NODE_ENV!=="production"&&(function(){var e=f,n=Symbol.for("react.element"),r=Symbol.for("react.portal"),s=Symbol.for("react.fragment"),o=Symbol.for("react.strict_mode"),i=Symbol.for("react.profiler"),a=Symbol.for("react.provider"),l=Symbol.for("react.context"),c=Symbol.for("react.forward_ref"),m=Symbol.for("react.suspense"),p=Symbol.for("react.suspense_list"),d=Symbol.for("react.memo"),h=Symbol.for("react.lazy"),y=Symbol.for("react.offscreen"),g=Symbol.iterator,b="@@iterator";function N(u){if(u===null||typeof u!="object")return null;var C=g&&u[g]||u[b];return typeof C=="function"?C:null}var T=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function j(u){{for(var C=arguments.length,_=new Array(C>1?C-1:0),J=1;J<C;J++)_[J-1]=arguments[J];$("error",u,_)}}function $(u,C,_){{var J=T.ReactDebugCurrentFrame,te=J.getStackAddendum();te!==""&&(C+="%s",_=_.concat([te]));var ne=_.map(function(Z){return String(Z)});ne.unshift("Warning: "+C),Function.prototype.apply.call(console[u],console,ne)}}var S=!1,D=!1,w=!1,L=!1,x=!1,k;k=Symbol.for("react.module.reference");function V(u){return!!(typeof u=="string"||typeof u=="function"||u===s||u===i||x||u===o||u===m||u===p||L||u===y||S||D||w||typeof u=="object"&&u!==null&&(u.$$typeof===h||u.$$typeof===d||u.$$typeof===a||u.$$typeof===l||u.$$typeof===c||u.$$typeof===k||u.getModuleId!==void 0))}function I(u,C,_){var J=u.displayName;if(J)return J;var te=C.displayName||C.name||"";return te!==""?_+"("+te+")":_}function A(u){return u.displayName||"Context"}function W(u){if(u==null)return null;if(typeof u.tag=="number"&&j("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof u=="function")return u.displayName||u.name||null;if(typeof u=="string")return u;switch(u){case s:return"Fragment";case r:return"Portal";case i:return"Profiler";case o:return"StrictMode";case m:return"Suspense";case p:return"SuspenseList"}if(typeof u=="object")switch(u.$$typeof){case l:var C=u;return A(C)+".Consumer";case a:var _=u;return A(_._context)+".Provider";case c:return I(u,u.render,"ForwardRef");case d:var J=u.displayName||null;return J!==null?J:W(u.type)||"Memo";case h:{var te=u,ne=te._payload,Z=te._init;try{return W(Z(ne))}catch{return null}}}return null}var H=Object.assign,U=0,E,Y,se,ue,M,we,ke;function ye(){}ye.__reactDisabledLog=!0;function me(){{if(U===0){E=console.log,Y=console.info,se=console.warn,ue=console.error,M=console.group,we=console.groupCollapsed,ke=console.groupEnd;var u={configurable:!0,enumerable:!0,value:ye,writable:!0};Object.defineProperties(console,{info:u,log:u,warn:u,error:u,group:u,groupCollapsed:u,groupEnd:u})}U++}}function O(){{if(U--,U===0){var u={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:H({},u,{value:E}),info:H({},u,{value:Y}),warn:H({},u,{value:se}),error:H({},u,{value:ue}),group:H({},u,{value:M}),groupCollapsed:H({},u,{value:we}),groupEnd:H({},u,{value:ke})})}U<0&&j("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var Q=T.ReactCurrentDispatcher,oe;function ge(u,C,_){{if(oe===void 0)try{throw Error()}catch(te){var J=te.stack.trim().match(/\n( *(at )?)/);oe=J&&J[1]||""}return`
2
- `+oe+u}}var re=!1,Ie;{var Me=typeof WeakMap=="function"?WeakMap:Map;Ie=new Me}function Se(u,C){if(!u||re)return"";{var _=Ie.get(u);if(_!==void 0)return _}var J;re=!0;var te=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var ne;ne=Q.current,Q.current=null,me();try{if(C){var Z=function(){throw Error()};if(Object.defineProperty(Z.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(Z,[])}catch(be){J=be}Reflect.construct(u,[],Z)}else{try{Z.call()}catch(be){J=be}u.call(Z.prototype)}}else{try{throw Error()}catch(be){J=be}u()}}catch(be){if(be&&J&&typeof be.stack=="string"){for(var X=be.stack.split(`
3
- `),xe=J.stack.split(`
4
- `),ae=X.length-1,ie=xe.length-1;ae>=1&&ie>=0&&X[ae]!==xe[ie];)ie--;for(;ae>=1&&ie>=0;ae--,ie--)if(X[ae]!==xe[ie]){if(ae!==1||ie!==1)do if(ae--,ie--,ie<0||X[ae]!==xe[ie]){var Te=`
5
- `+X[ae].replace(" at new "," at ");return u.displayName&&Te.includes("<anonymous>")&&(Te=Te.replace("<anonymous>",u.displayName)),typeof u=="function"&&Ie.set(u,Te),Te}while(ae>=1&&ie>=0);break}}}finally{re=!1,Q.current=ne,O(),Error.prepareStackTrace=te}var at=u?u.displayName||u.name:"",Ye=at?ge(at):"";return typeof u=="function"&&Ie.set(u,Ye),Ye}function Fe(u,C,_){return Se(u,!1)}function de(u){var C=u.prototype;return!!(C&&C.isReactComponent)}function Je(u,C,_){if(u==null)return"";if(typeof u=="function")return Se(u,de(u));if(typeof u=="string")return ge(u);switch(u){case m:return ge("Suspense");case p:return ge("SuspenseList")}if(typeof u=="object")switch(u.$$typeof){case c:return Fe(u.render);case d:return Je(u.type,C,_);case h:{var J=u,te=J._payload,ne=J._init;try{return Je(ne(te),C,_)}catch{}}}return""}var He=Object.prototype.hasOwnProperty,Qe={},Xt=T.ReactDebugCurrentFrame;function rt(u){if(u){var C=u._owner,_=Je(u.type,u._source,C?C.type:null);Xt.setExtraStackFrame(_)}else Xt.setExtraStackFrame(null)}function F(u,C,_,J,te){{var ne=Function.call.bind(He);for(var Z in u)if(ne(u,Z)){var X=void 0;try{if(typeof u[Z]!="function"){var xe=Error((J||"React class")+": "+_+" type `"+Z+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof u[Z]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw xe.name="Invariant Violation",xe}X=u[Z](C,Z,J,_,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(ae){X=ae}X&&!(X instanceof Error)&&(rt(te),j("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",J||"React class",_,Z,typeof X),rt(null)),X instanceof Error&&!(X.message in Qe)&&(Qe[X.message]=!0,rt(te),j("Failed %s type: %s",_,X.message),rt(null))}}}var B=Array.isArray;function ee(u){return B(u)}function Ae(u){{var C=typeof Symbol=="function"&&Symbol.toStringTag,_=C&&u[Symbol.toStringTag]||u.constructor.name||"Object";return _}}function Re(u){try{return st(u),!1}catch{return!0}}function st(u){return""+u}function Ft(u){if(Re(u))return j("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",Ae(u)),st(u)}var Ns=T.ReactCurrentOwner,hc={key:!0,ref:!0,__self:!0,__source:!0},Cs,ws;function xc(u){if(He.call(u,"ref")){var C=Object.getOwnPropertyDescriptor(u,"ref").get;if(C&&C.isReactWarning)return!1}return u.ref!==void 0}function gc(u){if(He.call(u,"key")){var C=Object.getOwnPropertyDescriptor(u,"key").get;if(C&&C.isReactWarning)return!1}return u.key!==void 0}function bc(u,C){typeof u.ref=="string"&&Ns.current}function yc(u,C){{var _=function(){Cs||(Cs=!0,j("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",C))};_.isReactWarning=!0,Object.defineProperty(u,"key",{get:_,configurable:!0})}}function vc(u,C){{var _=function(){ws||(ws=!0,j("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",C))};_.isReactWarning=!0,Object.defineProperty(u,"ref",{get:_,configurable:!0})}}var jc=function(u,C,_,J,te,ne,Z){var X={$$typeof:n,type:u,key:C,ref:_,props:Z,_owner:ne};return X._store={},Object.defineProperty(X._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(X,"_self",{configurable:!1,enumerable:!1,writable:!1,value:J}),Object.defineProperty(X,"_source",{configurable:!1,enumerable:!1,writable:!1,value:te}),Object.freeze&&(Object.freeze(X.props),Object.freeze(X)),X};function Nc(u,C,_,J,te){{var ne,Z={},X=null,xe=null;_!==void 0&&(Ft(_),X=""+_),gc(C)&&(Ft(C.key),X=""+C.key),xc(C)&&(xe=C.ref,bc(C,te));for(ne in C)He.call(C,ne)&&!hc.hasOwnProperty(ne)&&(Z[ne]=C[ne]);if(u&&u.defaultProps){var ae=u.defaultProps;for(ne in ae)Z[ne]===void 0&&(Z[ne]=ae[ne])}if(X||xe){var ie=typeof u=="function"?u.displayName||u.name||"Unknown":u;X&&yc(Z,ie),xe&&vc(Z,ie)}return jc(u,X,xe,te,J,Ns.current,Z)}}var Fn=T.ReactCurrentOwner,ks=T.ReactDebugCurrentFrame;function ot(u){if(u){var C=u._owner,_=Je(u.type,u._source,C?C.type:null);ks.setExtraStackFrame(_)}else ks.setExtraStackFrame(null)}var $n;$n=!1;function _n(u){return typeof u=="object"&&u!==null&&u.$$typeof===n}function Ts(){{if(Fn.current){var u=W(Fn.current.type);if(u)return`
1
+ (function(be,c){typeof exports=="object"&&typeof module<"u"?c(exports,require("react"),require("@tanstack/react-query"),require("lucide-react"),require("@radix-ui/react-slot"),require("radix-ui"),require("@tanstack/react-form"),require("@tanstack/react-table")):typeof define=="function"&&define.amd?define(["exports","react","@tanstack/react-query","lucide-react","@radix-ui/react-slot","radix-ui","@tanstack/react-form","@tanstack/react-table"],c):(be=typeof globalThis<"u"?globalThis:be||self,c(be.editor={},be.React,be.ReactQuery,be.LucideReact,be.RadixReactSlot,be.RadixUI,be.ReactForm,be.ReactTable))})(this,(function(be,c,me,N,Js,Q,Bt,Kt){"use strict";function Ws(e){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const r in e)if(r!=="default"){const s=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(n,r,s.get?s:{enumerable:!0,get:()=>e[r]})}}return n.default=e,Object.freeze(n)}const ve=Ws(c);var Gt={exports:{}},Ct={};var Hn;function Hs(){if(Hn)return Ct;Hn=1;var e=c,n=Symbol.for("react.element"),r=Symbol.for("react.fragment"),s=Object.prototype.hasOwnProperty,o=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,i={key:!0,ref:!0,__self:!0,__source:!0};function a(l,u,d){var p,m={},h=null,x=null;d!==void 0&&(h=""+d),u.key!==void 0&&(h=""+u.key),u.ref!==void 0&&(x=u.ref);for(p in u)s.call(u,p)&&!i.hasOwnProperty(p)&&(m[p]=u[p]);if(l&&l.defaultProps)for(p in u=l.defaultProps,u)m[p]===void 0&&(m[p]=u[p]);return{$$typeof:n,type:l,key:h,ref:x,props:m,_owner:o.current}}return Ct.Fragment=r,Ct.jsx=a,Ct.jsxs=a,Ct}var kt={};var Qn;function Qs(){return Qn||(Qn=1,process.env.NODE_ENV!=="production"&&(function(){var e=c,n=Symbol.for("react.element"),r=Symbol.for("react.portal"),s=Symbol.for("react.fragment"),o=Symbol.for("react.strict_mode"),i=Symbol.for("react.profiler"),a=Symbol.for("react.provider"),l=Symbol.for("react.context"),u=Symbol.for("react.forward_ref"),d=Symbol.for("react.suspense"),p=Symbol.for("react.suspense_list"),m=Symbol.for("react.memo"),h=Symbol.for("react.lazy"),x=Symbol.for("react.offscreen"),g=Symbol.iterator,b="@@iterator";function k(f){if(f===null||typeof f!="object")return null;var F=g&&f[g]||f[b];return typeof F=="function"?F:null}var $=e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;function w(f){{for(var F=arguments.length,A=new Array(F>1?F-1:0),Y=1;Y<F;Y++)A[Y-1]=arguments[Y];P("error",f,A)}}function P(f,F,A){{var Y=$.ReactDebugCurrentFrame,ne=Y.getStackAddendum();ne!==""&&(F+="%s",A=A.concat([ne]));var oe=A.map(function(te){return String(te)});oe.unshift("Warning: "+F),Function.prototype.apply.call(console[f],console,oe)}}var C=!1,T=!1,j=!1,E=!1,y=!1,S;S=Symbol.for("react.module.reference");function L(f){return!!(typeof f=="string"||typeof f=="function"||f===s||f===i||y||f===o||f===d||f===p||E||f===x||C||T||j||typeof f=="object"&&f!==null&&(f.$$typeof===h||f.$$typeof===m||f.$$typeof===a||f.$$typeof===l||f.$$typeof===u||f.$$typeof===S||f.getModuleId!==void 0))}function v(f,F,A){var Y=f.displayName;if(Y)return Y;var ne=F.displayName||F.name||"";return ne!==""?A+"("+ne+")":A}function M(f){return f.displayName||"Context"}function O(f){if(f==null)return null;if(typeof f.tag=="number"&&w("Received an unexpected object in getComponentNameFromType(). This is likely a bug in React. Please file an issue."),typeof f=="function")return f.displayName||f.name||null;if(typeof f=="string")return f;switch(f){case s:return"Fragment";case r:return"Portal";case i:return"Profiler";case o:return"StrictMode";case d:return"Suspense";case p:return"SuspenseList"}if(typeof f=="object")switch(f.$$typeof){case l:var F=f;return M(F)+".Consumer";case a:var A=f;return M(A._context)+".Provider";case u:return v(f,f.render,"ForwardRef");case m:var Y=f.displayName||null;return Y!==null?Y:O(f.type)||"Memo";case h:{var ne=f,oe=ne._payload,te=ne._init;try{return O(te(oe))}catch{return null}}}return null}var z=Object.assign,I=0,_,G,U,ie,B,Te,ye;function xe(){}xe.__reactDisabledLog=!0;function le(){{if(I===0){_=console.log,G=console.info,U=console.warn,ie=console.error,B=console.group,Te=console.groupCollapsed,ye=console.groupEnd;var f={configurable:!0,enumerable:!0,value:xe,writable:!0};Object.defineProperties(console,{info:f,log:f,warn:f,error:f,group:f,groupCollapsed:f,groupEnd:f})}I++}}function re(){{if(I--,I===0){var f={configurable:!0,enumerable:!0,writable:!0};Object.defineProperties(console,{log:z({},f,{value:_}),info:z({},f,{value:G}),warn:z({},f,{value:U}),error:z({},f,{value:ie}),group:z({},f,{value:B}),groupCollapsed:z({},f,{value:Te}),groupEnd:z({},f,{value:ye})})}I<0&&w("disabledDepth fell below zero. This is a bug in React. Please file an issue.")}}var ae=$.ReactCurrentDispatcher,J;function ce(f,F,A){{if(J===void 0)try{throw Error()}catch(ne){var Y=ne.stack.trim().match(/\n( *(at )?)/);J=Y&&Y[1]||""}return`
2
+ `+J+f}}var R=!1,Ne;{var Be=typeof WeakMap=="function"?WeakMap:Map;Ne=new Be}function ze(f,F){if(!f||R)return"";{var A=Ne.get(f);if(A!==void 0)return A}var Y;R=!0;var ne=Error.prepareStackTrace;Error.prepareStackTrace=void 0;var oe;oe=ae.current,ae.current=null,le();try{if(F){var te=function(){throw Error()};if(Object.defineProperty(te.prototype,"props",{set:function(){throw Error()}}),typeof Reflect=="object"&&Reflect.construct){try{Reflect.construct(te,[])}catch(_e){Y=_e}Reflect.construct(f,[],te)}else{try{te.call()}catch(_e){Y=_e}f.call(te.prototype)}}else{try{throw Error()}catch(_e){Y=_e}f()}}catch(_e){if(_e&&Y&&typeof _e.stack=="string"){for(var ee=_e.stack.split(`
3
+ `),we=Y.stack.split(`
4
+ `),fe=ee.length-1,pe=we.length-1;fe>=1&&pe>=0&&ee[fe]!==we[pe];)pe--;for(;fe>=1&&pe>=0;fe--,pe--)if(ee[fe]!==we[pe]){if(fe!==1||pe!==1)do if(fe--,pe--,pe<0||ee[fe]!==we[pe]){var Me=`
5
+ `+ee[fe].replace(" at new "," at ");return f.displayName&&Me.includes("<anonymous>")&&(Me=Me.replace("<anonymous>",f.displayName)),typeof f=="function"&&Ne.set(f,Me),Me}while(fe>=1&&pe>=0);break}}}finally{R=!1,ae.current=oe,re(),Error.prepareStackTrace=ne}var wt=f?f.displayName||f.name:"",ft=wt?ce(wt):"";return typeof f=="function"&&Ne.set(f,ft),ft}function Ke(f,F,A){return ze(f,!1)}function De(f){var F=f.prototype;return!!(F&&F.isReactComponent)}function Ge(f,F,A){if(f==null)return"";if(typeof f=="function")return ze(f,De(f));if(typeof f=="string")return ce(f);switch(f){case d:return ce("Suspense");case p:return ce("SuspenseList")}if(typeof f=="object")switch(f.$$typeof){case u:return Ke(f.render);case m:return Ge(f.type,F,A);case h:{var Y=f,ne=Y._payload,oe=Y._init;try{return Ge(oe(ne),F,A)}catch{}}}return""}var ue=Object.prototype.hasOwnProperty,X={},se=$.ReactDebugCurrentFrame;function Se(f){if(f){var F=f._owner,A=Ge(f.type,f._source,F?F.type:null);se.setExtraStackFrame(A)}else se.setExtraStackFrame(null)}function $e(f,F,A,Y,ne){{var oe=Function.call.bind(ue);for(var te in f)if(oe(f,te)){var ee=void 0;try{if(typeof f[te]!="function"){var we=Error((Y||"React class")+": "+A+" type `"+te+"` is invalid; it must be a function, usually from the `prop-types` package, but received `"+typeof f[te]+"`.This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.");throw we.name="Invariant Violation",we}ee=f[te](F,te,Y,A,null,"SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED")}catch(fe){ee=fe}ee&&!(ee instanceof Error)&&(Se(ne),w("%s: type specification of %s `%s` is invalid; the type checker function must return `null` or an `Error` but returned a %s. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).",Y||"React class",A,te,typeof ee),Se(null)),ee instanceof Error&&!(ee.message in X)&&(X[ee.message]=!0,Se(ne),w("Failed %s type: %s",A,ee.message),Se(null))}}}var rt=Array.isArray;function Je(f){return rt(f)}function ut(f){{var F=typeof Symbol=="function"&&Symbol.toStringTag,A=F&&f[Symbol.toStringTag]||f.constructor.name||"Object";return A}}function st(f){try{return D(f),!1}catch{return!0}}function D(f){return""+f}function K(f){if(st(f))return w("The provided key is an unsupported type %s. This value must be coerced to a string before before using it here.",ut(f)),D(f)}var de=$.ReactCurrentOwner,Ee={key:!0,ref:!0,__self:!0,__source:!0},mt,We;function dn(f){if(ue.call(f,"ref")){var F=Object.getOwnPropertyDescriptor(f,"ref").get;if(F&&F.isReactWarning)return!1}return f.ref!==void 0}function vc(f){if(ue.call(f,"key")){var F=Object.getOwnPropertyDescriptor(f,"key").get;if(F&&F.isReactWarning)return!1}return f.key!==void 0}function jc(f,F){typeof f.ref=="string"&&de.current}function Nc(f,F){{var A=function(){mt||(mt=!0,w("%s: `key` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",F))};A.isReactWarning=!0,Object.defineProperty(f,"key",{get:A,configurable:!0})}}function wc(f,F){{var A=function(){We||(We=!0,w("%s: `ref` is not a prop. Trying to access it will result in `undefined` being returned. If you need to access the same value within the child component, you should pass it as a different prop. (https://reactjs.org/link/special-props)",F))};A.isReactWarning=!0,Object.defineProperty(f,"ref",{get:A,configurable:!0})}}var Cc=function(f,F,A,Y,ne,oe,te){var ee={$$typeof:n,type:f,key:F,ref:A,props:te,_owner:oe};return ee._store={},Object.defineProperty(ee._store,"validated",{configurable:!1,enumerable:!1,writable:!0,value:!1}),Object.defineProperty(ee,"_self",{configurable:!1,enumerable:!1,writable:!1,value:Y}),Object.defineProperty(ee,"_source",{configurable:!1,enumerable:!1,writable:!1,value:ne}),Object.freeze&&(Object.freeze(ee.props),Object.freeze(ee)),ee};function kc(f,F,A,Y,ne){{var oe,te={},ee=null,we=null;A!==void 0&&(K(A),ee=""+A),vc(F)&&(K(F.key),ee=""+F.key),dn(F)&&(we=F.ref,jc(F,ne));for(oe in F)ue.call(F,oe)&&!Ee.hasOwnProperty(oe)&&(te[oe]=F[oe]);if(f&&f.defaultProps){var fe=f.defaultProps;for(oe in fe)te[oe]===void 0&&(te[oe]=fe[oe])}if(ee||we){var pe=typeof f=="function"?f.displayName||f.name||"Unknown":f;ee&&Nc(te,pe),we&&wc(te,pe)}return Cc(f,ee,we,ne,Y,de.current,te)}}var Kn=$.ReactCurrentOwner,Os=$.ReactDebugCurrentFrame;function Nt(f){if(f){var F=f._owner,A=Ge(f.type,f._source,F?F.type:null);Os.setExtraStackFrame(A)}else Os.setExtraStackFrame(null)}var Gn;Gn=!1;function Jn(f){return typeof f=="object"&&f!==null&&f.$$typeof===n}function As(){{if(Kn.current){var f=O(Kn.current.type);if(f)return`
6
6
 
7
- Check the render method of \``+u+"`."}return""}}function Cc(u){return""}var Ss={};function wc(u){{var C=Ts();if(!C){var _=typeof u=="string"?u:u.displayName||u.name;_&&(C=`
7
+ Check the render method of \``+f+"`."}return""}}function Tc(f){return""}var qs={};function Sc(f){{var F=As();if(!F){var A=typeof f=="string"?f:f.displayName||f.name;A&&(F=`
8
8
 
9
- Check the top-level render call using <`+_+">.")}return C}}function Fs(u,C){{if(!u._store||u._store.validated||u.key!=null)return;u._store.validated=!0;var _=wc(C);if(Ss[_])return;Ss[_]=!0;var J="";u&&u._owner&&u._owner!==Fn.current&&(J=" It was passed a child from "+W(u._owner.type)+"."),ot(u),j('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',_,J),ot(null)}}function $s(u,C){{if(typeof u!="object")return;if(ee(u))for(var _=0;_<u.length;_++){var J=u[_];_n(J)&&Fs(J,C)}else if(_n(u))u._store&&(u._store.validated=!0);else if(u){var te=N(u);if(typeof te=="function"&&te!==u.entries)for(var ne=te.call(u),Z;!(Z=ne.next()).done;)_n(Z.value)&&Fs(Z.value,C)}}}function kc(u){{var C=u.type;if(C==null||typeof C=="string")return;var _;if(typeof C=="function")_=C.propTypes;else if(typeof C=="object"&&(C.$$typeof===c||C.$$typeof===d))_=C.propTypes;else return;if(_){var J=W(C);F(_,u.props,"prop",J,u)}else if(C.PropTypes!==void 0&&!$n){$n=!0;var te=W(C);j("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",te||"Unknown")}typeof C.getDefaultProps=="function"&&!C.getDefaultProps.isReactClassApproved&&j("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function Tc(u){{for(var C=Object.keys(u.props),_=0;_<C.length;_++){var J=C[_];if(J!=="children"&&J!=="key"){ot(u),j("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",J),ot(null);break}}u.ref!==null&&(ot(u),j("Invalid attribute `ref` supplied to `React.Fragment`."),ot(null))}}var _s={};function zs(u,C,_,J,te,ne){{var Z=V(u);if(!Z){var X="";(u===void 0||typeof u=="object"&&u!==null&&Object.keys(u).length===0)&&(X+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var xe=Cc();xe?X+=xe:X+=Ts();var ae;u===null?ae="null":ee(u)?ae="array":u!==void 0&&u.$$typeof===n?(ae="<"+(W(u.type)||"Unknown")+" />",X=" Did you accidentally export a JSX literal instead of a component?"):ae=typeof u,j("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",ae,X)}var ie=Nc(u,C,_,te,ne);if(ie==null)return ie;if(Z){var Te=C.children;if(Te!==void 0)if(J)if(ee(Te)){for(var at=0;at<Te.length;at++)$s(Te[at],u);Object.freeze&&Object.freeze(Te)}else j("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else $s(Te,u)}if(He.call(C,"key")){var Ye=W(u),be=Object.keys(C).filter(function(Pc){return Pc!=="key"}),zn=be.length>0?"{key: someKey, "+be.join(": ..., ")+": ...}":"{key: someKey}";if(!_s[Ye+zn]){var zc=be.length>0?"{"+be.join(": ..., ")+": ...}":"{}";j(`A props object containing a "key" prop is being spread into JSX:
9
+ Check the top-level render call using <`+A+">.")}return F}}function Vs(f,F){{if(!f._store||f._store.validated||f.key!=null)return;f._store.validated=!0;var A=Sc(F);if(qs[A])return;qs[A]=!0;var Y="";f&&f._owner&&f._owner!==Kn.current&&(Y=" It was passed a child from "+O(f._owner.type)+"."),Nt(f),w('Each child in a list should have a unique "key" prop.%s%s See https://reactjs.org/link/warning-keys for more information.',A,Y),Nt(null)}}function Bs(f,F){{if(typeof f!="object")return;if(Je(f))for(var A=0;A<f.length;A++){var Y=f[A];Jn(Y)&&Vs(Y,F)}else if(Jn(f))f._store&&(f._store.validated=!0);else if(f){var ne=k(f);if(typeof ne=="function"&&ne!==f.entries)for(var oe=ne.call(f),te;!(te=oe.next()).done;)Jn(te.value)&&Vs(te.value,F)}}}function $c(f){{var F=f.type;if(F==null||typeof F=="string")return;var A;if(typeof F=="function")A=F.propTypes;else if(typeof F=="object"&&(F.$$typeof===u||F.$$typeof===m))A=F.propTypes;else return;if(A){var Y=O(F);$e(A,f.props,"prop",Y,f)}else if(F.PropTypes!==void 0&&!Gn){Gn=!0;var ne=O(F);w("Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?",ne||"Unknown")}typeof F.getDefaultProps=="function"&&!F.getDefaultProps.isReactClassApproved&&w("getDefaultProps is only used on classic React.createClass definitions. Use a static property named `defaultProps` instead.")}}function _c(f){{for(var F=Object.keys(f.props),A=0;A<F.length;A++){var Y=F[A];if(Y!=="children"&&Y!=="key"){Nt(f),w("Invalid prop `%s` supplied to `React.Fragment`. React.Fragment can only have `key` and `children` props.",Y),Nt(null);break}}f.ref!==null&&(Nt(f),w("Invalid attribute `ref` supplied to `React.Fragment`."),Nt(null))}}var Ks={};function Gs(f,F,A,Y,ne,oe){{var te=L(f);if(!te){var ee="";(f===void 0||typeof f=="object"&&f!==null&&Object.keys(f).length===0)&&(ee+=" You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.");var we=Tc();we?ee+=we:ee+=As();var fe;f===null?fe="null":Je(f)?fe="array":f!==void 0&&f.$$typeof===n?(fe="<"+(O(f.type)||"Unknown")+" />",ee=" Did you accidentally export a JSX literal instead of a component?"):fe=typeof f,w("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s",fe,ee)}var pe=kc(f,F,A,ne,oe);if(pe==null)return pe;if(te){var Me=F.children;if(Me!==void 0)if(Y)if(Je(Me)){for(var wt=0;wt<Me.length;wt++)Bs(Me[wt],f);Object.freeze&&Object.freeze(Me)}else w("React.jsx: Static children should always be an array. You are likely explicitly calling React.jsxs or React.jsxDEV. Use the Babel transform instead.");else Bs(Me,f)}if(ue.call(F,"key")){var ft=O(f),_e=Object.keys(F).filter(function(Mc){return Mc!=="key"}),Wn=_e.length>0?"{key: someKey, "+_e.join(": ..., ")+": ...}":"{key: someKey}";if(!Ks[ft+Wn]){var Dc=_e.length>0?"{"+_e.join(": ..., ")+": ...}":"{}";w(`A props object containing a "key" prop is being spread into JSX:
10
10
  let props = %s;
11
11
  <%s {...props} />
12
12
  React keys must be passed directly to JSX without using spread:
13
13
  let props = %s;
14
- <%s key={someKey} {...props} />`,zn,Ye,zc,Ye),_s[Ye+zn]=!0}}return u===s?Tc(ie):kc(ie),ie}}function Sc(u,C,_){return zs(u,C,_,!0)}function Fc(u,C,_){return zs(u,C,_,!1)}var $c=Fc,_c=Sc;lt.Fragment=s,lt.jsx=$c,lt.jsxs=_c})()),lt}var In;function Ms(){return In||(In=1,process.env.NODE_ENV==="production"?_t.exports=Ds():_t.exports=Is()),_t.exports}var t=Ms();function Xe(e,n,...r){if(!e){let s;if(n===void 0)s=new Error("Minified exception occurred; use the non-minified dev environment for the full error message and additional helpful warnings.");else{let o=0;s=new Error(n.replace(/%s/g,function(){return r[o++]})),s.name="Invariant Violation"}throw s.framesToPop=1,s}}const qe=e=>typeof e=="function",Ls=e=>e.length===0,Mn=e=>e.toString(),Ut=e=>typeof e=="string",Zt="/",zt="||",Ve=e=>e,Ln=e=>e===null;function On(e,n=Ve,r){Xe(qe(n)||Ln(n),"Expected payloadCreator to be a function, undefined or null");const s=Ln(n)||n===Ve?Ve:(l,...c)=>l instanceof Error?l:n(l,...c),o=qe(r),i=e.toString(),a=(...l)=>{const c=s(...l),m={type:e};return c instanceof Error&&(m.error=!0),c!==void 0&&(m.payload=c),o&&(m.meta=r(...l)),m};return a.toString=()=>i,a}const Ue=e=>{if(typeof e!="object"||e===null)return!1;let n=e;for(;Object.getPrototypeOf(n)!==null;)n=Object.getPrototypeOf(n);return Object.getPrototypeOf(e)===n},An=e=>Array.isArray(e),qn=e=>e==null,Os=e=>e[e.length-1],As=/\s/,qs=/([-.:_])/,Vs=/([a-z][A-Z]|[A-Z][a-z])/,en="/",Bs=/[\W_]+(.|$)/g,Gs=e=>e.replace(Bs,(n,r)=>r?" "+r:""),Ks=/(.)([A-Z]+)/g,Ws=e=>e.replace(Ks,(n,r,s)=>r+" "+s.toLowerCase().split("").join(" ")),Js=e=>As.test(e)?e.toLowerCase():qs.test(e)?(Gs(e)||e).toLowerCase():Vs.test(e)?Ws(e).toLowerCase():e.toLowerCase(),Hs=e=>Js(e).replace(/[\W_]+(.|$)/g,(n,r)=>r?" "+r:"").trim(),Vn=e=>Hs(e).replace(/\s(\w)/g,(n,r)=>r.toUpperCase()),Bn=e=>e.includes(en)?e.split(en).map(Vn).join(en):Vn(e),tn=(e,n)=>e.reduce((r,s)=>n(r,s),{}),Pt=e=>typeof Map<"u"&&e instanceof Map;function nn(e){if(Pt(e))return Array.from(e.keys());if(typeof Reflect<"u"&&typeof Reflect.ownKeys=="function")return Reflect.ownKeys(e);let n=Object.getOwnPropertyNames(e);return typeof Object.getOwnPropertySymbols=="function"&&(n=n.concat(Object.getOwnPropertySymbols(e))),n}function Gn(e,n){return Pt(n)?n.get(e):n[e]}const Kn=e=>function n(r,{namespace:s=Zt,prefix:o}={},i={},a=""){function l(m){if(!a)return m;const p=m.toString().split(zt),d=a.split(zt);return[].concat(...d.map(h=>p.map(y=>`${h}${s}${y}`))).join(zt)}function c(m){return a||!o||o&&new RegExp(`^${o}${s}`).test(m)?m:`${o}${s}${m}`}return nn(r).forEach(m=>{const p=c(l(m)),d=Gn(m,r);e(d)?n(d,{namespace:s,prefix:o},i,p):i[p]=d}),i},Qs=Kn(Ue);function Rs(e,{namespace:n=Zt,prefix:r}={}){function s(i,a,l){const c=Bn(l.shift());Ls(l)?a[c]=e[i]:(a[c]||(a[c]={}),s(i,a[c],l))}const o={};return Object.getOwnPropertyNames(e).forEach(i=>{const a=r?i.replace(`${r}${n}`,""):i;return s(i,o,a.split(n))}),o}function Ys(e,...n){const r=Ue(Os(n))?n.pop():{};return Xe(n.every(Ut)&&(Ut(e)||Ue(e)),"Expected optional object followed by string action types"),Ut(e)?Jn([e,...n],r):{...Xs(e,r),...Jn(n,r)}}function Xs(e,n){const r=Qs(e,n),s=Wn(r);return Rs(s,n)}function Wn(e,{prefix:n,namespace:r=Zt}={}){function s(o){if(qe(o)||qn(o))return!0;if(An(o)){const[i=Ve,a]=o;return qe(i)&&qe(a)}return!1}return tn(Object.keys(e),(o,i)=>{const a=e[i];Xe(s(a),`Expected function, undefined, null, or array with payload and meta functions for ${i}`);const l=n?`${n}${r}${i}`:i,c=An(a)?On(l,...a):On(l,a);return{...o,[i]:c}})}function Jn(e,n){const r=tn(e,(o,i)=>({...o,[i]:Ve})),s=Wn(r,n);return tn(Object.keys(s),(o,i)=>({...o,[Bn(i)]:s[i]}))}const Us=e=>e===void 0;function Zs(e,n=Ve,r){const s=Mn(e).split(zt);Xe(!Us(r),`defaultState for reducer handling ${s.join(", ")} should be defined`),Xe(qe(n)||Ue(n),"Expected reducer to be a function or object with next and throw reducers");const[o,i]=qe(n)?[n,n]:[n.next,n.throw].map(a=>qn(a)?Ve:a);return(a=r,l)=>{const{type:c}=l;return!c||!s.includes(Mn(c))?a:(l.error===!0?i:o)(a,l)}}const eo=function(){for(var e=arguments.length,n=Array(e),r=0;r<e;r++)n[r]=arguments[r];var s=typeof n[0]!="function"&&n.shift(),o=n;if(typeof s>"u")throw new TypeError("The initial state may not be undefined. If you do not want to set a value for this reducer, you can use null instead of undefined.");return function(i,a){for(var l=arguments.length,c=Array(l>2?l-2:0),m=2;m<l;m++)c[m-2]=arguments[m];var p=typeof i>"u",d=typeof a>"u";return p&&d&&s?s:o.reduce(function(h,y,g){if(typeof y>"u")throw new TypeError("An undefined reducer was passed in at index "+g);return y.apply(void 0,[h,a].concat(c))},p&&!d&&s?s:i)}};function to(e){const n=nn(e),r=n.every(s=>s==="next"||s==="throw");return n.length>0&&n.length<=2&&r}const no=Kn(e=>(Ue(e)||Pt(e))&&!to(e));function ro(e,n,r={}){Xe(Ue(e)||Pt(e),"Expected handlers to be a plain object.");const s=no(e,r),o=nn(s).map(a=>Zs(a,Gn(a,s),n)),i=eo(n,...o);return(a=n,l)=>i(a,l)}const rn={path:"/",history:[],location:0},Hn={path:"*",data:{},hash:"",query:""},Et=f.createContext(rn),sn=f.createContext(null),ct=f.createContext(Hn),{navigate:Qn,back:so,forward:oo}=Ys({NAVIGATE:e=>e,BACK:(e=1)=>e,FORWARD:(e=1)=>e}),ao=ro({NAVIGATE:(e,n)=>{let{history:r,location:s}=e;return s>0&&(r=r.slice(s)),{path:uo(e.path,n.payload),history:[n.payload,...r],location:0}},BACK:(e,n)=>{const r=e.location+n.payload,s=e.history.at(r);return s?{path:s,history:e.history,location:r}:e},FORWARD:(e,n)=>{const r=e.location-n.payload,s=e.history.at(r);return s?{path:s,history:e.history,location:r}:e}},rn);function Rn(){return f.useContext(Et).path}function Dt(){const e=f.useContext(sn);return n=>e?.(Qn(n))}function io(){const e=f.useContext(sn),n=f.useContext(Et);return{navigate:r=>e?.(Qn(r)),back:(r=1)=>e?.(so(r)),forward:(r=1)=>e?.(oo(r)),hasBack:n.location<n.history.length-1,...n}}function on(){return f.useContext(ct).data}function Yn(){const{query:e,hash:n}=f.useContext(ct);return{search:new URLSearchParams(e),hash:n}}function lo({path:e,children:n}){const r=e?{path:e,history:[],location:0}:rn,[s,o]=f.useReducer(ao,r);return t.jsx(Et.Provider,{value:s,children:t.jsx(sn.Provider,{value:o,children:t.jsx(ct.Provider,{value:Hn,children:n})})})}const dt=f.forwardRef(({to:e,children:n,...r},s)=>{const o=Dt(),i=a=>{a.defaultPrevented||a.preventDefault(),o(e)};return t.jsx("a",{...r,href:e,ref:s,onClick:i,children:n})});function an({children:e}){const n=f.useContext(ct),r=f.useContext(Et),s=Un(e,n.path),o=co(s.map(a=>a.route),r.path);if(!o)return t.jsx(t.Fragment,{});const i=s.find(a=>a.route===o.route).element;return t.jsx(ct.Provider,{value:{...o.match},children:i})}function Xn(e){let n=0;for(const r of e.split("/"))r===""||r==="*"||(n+=r.startsWith(":")?1:100);return n}function co(e,n){let r=null;for(const s of e){const o=po(s,n);o.isMatch&&(r===null||Xn(s)>Xn(r.route))&&(r={route:s,match:o})}return r}function he({path:e,element:n}){return t.jsx(t.Fragment,{})}function Un(e,n){const r=[];return f.Children.map(e,s=>{if(!f.isValidElement(s))return;if(s.type===f.Fragment){r.push.apply(r,Un(s.props.children,n));return}const o=s.props;return r.push({route:fo(n,o.path),element:o.element}),s}),r}const uo=(e,n)=>{if(n.startsWith("/"))return n;if(n.startsWith("?")){const[o]=e?.split("?")??[""];return o+n}let r=0;const s=n.split("/").filter(o=>o!=="");for(;s.length>0&&(s[0]==="."||s[0]==="..");)s.shift()==".."&&++r;return mo(e,s.join("/"),r)},mo=(e,n,r)=>{const s=e.split("/").filter(i=>i!==""),o=n.split("/").filter(i=>i!=="");return r===0?`/${s.join("/")}/${o.join("/")}`:`/${s.slice(0,-r).join("/")}/${o.join("/")}`},fo=(e,n)=>{const r=e.split("/").filter(o=>o!==""),s=n.split("/").filter(o=>o!=="");return r.length>0&&r.at(-1)==="*"&&r.pop(),r.length===0?`/${s.join("/")}`:`/${r.join("/")}/${s.join("/")}`},po=(e,n)=>{let r=e.split("/"),s=n.split("/");if(r.at(-1)===""&&(r=r.slice(0,-1)),s.at(-1)===""&&(s=s.slice(0,-1)),r.length>s.length)return{isMatch:!1,remainer:"",data:{},query:"",hash:"",path:""};if(r.length<s.length&&r.at(-1)!=="*")return{isMatch:!1,remainer:"",data:{},query:"",hash:"",path:""};let o={},i="",a="";for(let l=0;l<r.length;++l){const c=r[l],p=[...s[l].matchAll(/([?#]?)((?:(?![?#]).)*)/g)],d=p?.find(h=>h[1]==="")?.[2]??"";if(i=p?.find(h=>h[1]==="?")?.[2]??"",a=p?.find(h=>h[1]==="#")?.[2]??"",c.startsWith(":")&&d&&d!==""){o[c.substring(1)]=d;continue}if(c==="*")return{isMatch:!0,data:o,remainer:s.splice(0,l).join("/"),query:i,hash:a,path:s.slice(0,l).join("/")};if(c!==d)return{isMatch:!1,data:{},remainer:"",query:"",hash:"",path:""}}return{isMatch:!0,remainer:"",data:o,query:i,hash:a,path:n?.split("?")?.[0]??""}},ho=`
14
+ <%s key={someKey} {...props} />`,Wn,ft,Dc,ft),Ks[ft+Wn]=!0}}return f===s?_c(pe):$c(pe),pe}}function Fc(f,F,A){return Gs(f,F,A,!0)}function zc(f,F,A){return Gs(f,F,A,!1)}var Ec=zc,Pc=Fc;kt.Fragment=s,kt.jsx=Ec,kt.jsxs=Pc})()),kt}var Yn;function Ys(){return Yn||(Yn=1,process.env.NODE_ENV==="production"?Gt.exports=Hs():Gt.exports=Qs()),Gt.exports}var t=Ys();const Rn={path:"/",history:[],location:0},Xn={path:"*",data:{},hash:"",query:""},Jt=c.createContext(Rn),un=c.createContext(null),Tt=c.createContext(Xn),Un=e=>({type:"NAVIGATE",payload:e}),Rs=(e=1)=>({type:"BACK",payload:e}),Xs=(e=1)=>({type:"FORWARD",payload:e}),Us=100;function Zs(e,n){switch(n.type){case"NAVIGATE":{let{history:r,location:s}=e;return s>0&&(r=r.slice(s)),{path:ro(e.path,n.payload),history:[n.payload,...r].slice(0,Us),location:0}}case"BACK":{const r=e.location+n.payload,s=e.history.at(r);return s?{path:s,history:e.history,location:r}:e}case"FORWARD":{const r=e.location-n.payload,s=e.history.at(r);return s?{path:s,history:e.history,location:r}:e}default:return e}}function Zn(){return c.useContext(Jt).path}function Wt(){const e=c.useContext(un);return n=>e?.(Un(n))}function eo(){const e=c.useContext(un),n=c.useContext(Jt);return{navigate:r=>e?.(Un(r)),back:(r=1)=>e?.(Rs(r)),forward:(r=1)=>e?.(Xs(r)),hasBack:n.location<n.history.length-1,...n}}function mn(){return c.useContext(Tt).data}function er(){const{query:e,hash:n}=c.useContext(Tt);return{search:new URLSearchParams(e),hash:n}}function to({path:e,children:n}){const r=e?{path:e,history:[],location:0}:Rn,[s,o]=c.useReducer(Zs,r);return t.jsx(Jt.Provider,{value:s,children:t.jsx(un.Provider,{value:o,children:t.jsx(Tt.Provider,{value:Xn,children:n})})})}const St=c.forwardRef(({to:e,children:n,...r},s)=>{const o=Wt(),i=a=>{a.defaultPrevented||a.preventDefault(),o(e)};return t.jsx("a",{...r,href:e,ref:s,onClick:i,children:n})});function fn({children:e}){const n=c.useContext(Tt),r=c.useContext(Jt),s=nr(e,n.path),o=no(s.map(a=>a.route),r.path);if(!o)return t.jsx(t.Fragment,{});const i=s.find(a=>a.route===o.route).element;return t.jsx(Tt.Provider,{value:{...o.match},children:i})}function tr(e){let n=0;for(const r of e.split("/"))r===""||r==="*"||(n+=r.startsWith(":")?1:100);return n}function no(e,n){let r=null;for(const s of e){const o=ao(s,n);o.isMatch&&(r===null||tr(s)>tr(r.route))&&(r={route:s,match:o})}return r}function je({path:e,element:n}){return t.jsx(t.Fragment,{})}function nr(e,n){const r=[];return c.Children.map(e,s=>{if(!c.isValidElement(s))return;if(s.type===c.Fragment){r.push.apply(r,nr(s.props.children,n));return}const o=s.props;return r.push({route:oo(n,o.path),element:o.element}),s}),r}const ro=(e,n)=>{if(n.startsWith("/"))return n;if(n.startsWith("?")){const[o]=e?.split("?")??[""];return o+n}let r=0;const s=n.split("/").filter(o=>o!=="");for(;s.length>0&&(s[0]==="."||s[0]==="..");)s.shift()==".."&&++r;return so(e,s.join("/"),r)},so=(e,n,r)=>{const s=e.split("/").filter(i=>i!==""),o=n.split("/").filter(i=>i!=="");return r===0?`/${s.join("/")}/${o.join("/")}`:`/${s.slice(0,-r).join("/")}/${o.join("/")}`},oo=(e,n)=>{const r=e.split("/").filter(o=>o!==""),s=n.split("/").filter(o=>o!=="");return r.length>0&&r.at(-1)==="*"&&r.pop(),r.length===0?`/${s.join("/")}`:`/${r.join("/")}/${s.join("/")}`},ao=(e,n)=>{let r=e.split("/"),s=n.split("/");if(r.at(-1)===""&&(r=r.slice(0,-1)),s.at(-1)===""&&(s=s.slice(0,-1)),r.length>s.length)return{isMatch:!1,remainer:"",data:{},query:"",hash:"",path:""};if(r.length<s.length&&r.at(-1)!=="*")return{isMatch:!1,remainer:"",data:{},query:"",hash:"",path:""};let o={},i="",a="";for(let l=0;l<r.length;++l){const u=r[l],p=[...s[l].matchAll(/([?#]?)((?:(?![?#]).)*)/g)],m=p?.find(h=>h[1]==="")?.[2]??"";if(i=p?.find(h=>h[1]==="?")?.[2]??"",a=p?.find(h=>h[1]==="#")?.[2]??"",u.startsWith(":")&&m&&m!==""){o[u.substring(1)]=m;continue}if(u==="*"){const x=[...s.slice(l).join("/").matchAll(/([?#]?)((?:(?![?#]).)*)/g)];return{isMatch:!0,data:o,remainer:x.find(g=>g[1]==="")?.[2]??"",query:x.find(g=>g[1]==="?")?.[2]??"",hash:x.find(g=>g[1]==="#")?.[2]??"",path:s.slice(0,l).join("/")}}if(u!==m)return{isMatch:!1,data:{},remainer:"",query:"",hash:"",path:""}}return{isMatch:!0,remainer:"",data:o,query:i,hash:a,path:n?.split("?")?.[0]??""}},io=`
15
15
  query dbSchema {
16
16
  _dbSchema {
17
17
  dbName
@@ -74,28 +74,35 @@ query dbSchema {
74
74
  hasPayload
75
75
  }
76
76
  }
77
- }`;class xo extends Error{constructor(n,r){super(n.map(s=>s.message).join("; ")),this.errors=n,this.data=r,this.name="GraphQLRequestError"}errors;data}class Zn{constructor(n){this.uri=n}uri;async query(n,r){const s=await fetch(this.uri,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:n,variables:r})});if(!s.ok)throw new Error(`GraphQL request failed: ${s.status} ${s.statusText}`);const o=await s.json();if(o.errors?.length)throw new xo(o.errors,o.data);return o.data}}const er=f.createContext(null),go=er.Provider;function ve(){const e=f.useContext(er);if(!e)throw new Error("useFetcher must be used within a FetcherProvider");return e}function bo(e){const n=e.lastIndexOf(".");return n>=0?e.slice(n+1):e}function yo(e){return bo(e).replace(/([a-z])([A-Z])/g,"$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g,"$1 $2").split(/[_\-\s]+/).filter(Boolean)}function vo(e){return e.length===0?e:e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()}function It(e){return e&&yo(e).map(vo).join(" ")}const tr=f.createContext({loading:!0,error:null,data:[],findTable:()=>{}}),jo=({children:e})=>{const n=No();return t.jsx(tr.Provider,{value:n,children:e})};function je(){return f.useContext(tr)}function No(){const e=ve(),{isLoading:n,error:r,data:s}=le.useQuery({queryKey:["dbSchema"],queryFn:()=>e.query(ho),staleTime:1/0});return f.useMemo(()=>{if(n)return{loading:!0,error:null,data:[],findTable:()=>{}};if(r)return{loading:!1,error:{message:r.message},data:[],findTable:()=>{}};if(!s)return{loading:!1,error:null,data:[],findTable:()=>{}};const o=s._dbSchema.map(a=>({...a,name:a.graphQlName,label:It(a.dbName),metadata:nr(a.metadata),columns:a.columns.map(l=>({...l,name:l.graphQlName,label:It(l.dbName),metadata:nr(l.metadata),inputType:To(l.inputType)}))}));return{loading:!1,error:null,data:o,findTable:a=>o.find(l=>l.graphQlName===a)}},[n,r,s])}function nr(e){return e.reduce((n,r)=>({...n,[r.key]:Co(r)}),{})}function Co({key:e,value:n}){return e==="type"?wo(n):n}function wo(e){const n=e.match(/lookup\s*\(\s*(?<id>\w+)\s*,\s*(?<label>\w+)\s*\)/m);if(n?.groups?.id&&n?.groups?.label)return{type:"lookup",id:n.groups.id,label:n.groups.label}}const ko=["text","email","url","tel","date","datetime-local","number","password","search"];function To(e){if(e&&ko.includes(e))return e}function rr(e){var n,r,s="";if(typeof e=="string"||typeof e=="number")s+=e;else if(typeof e=="object")if(Array.isArray(e)){var o=e.length;for(n=0;n<o;n++)e[n]&&(r=rr(e[n]))&&(s&&(s+=" "),s+=r)}else for(r in e)e[r]&&(s&&(s+=" "),s+=r);return s}function sr(){for(var e,n,r=0,s="",o=arguments.length;r<o;r++)(e=arguments[r])&&(n=rr(e))&&(s&&(s+=" "),s+=n);return s}const or=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,ar=sr,ir=(e,n)=>r=>{var s;if(n?.variants==null)return ar(e,r?.class,r?.className);const{variants:o,defaultVariants:i}=n,a=Object.keys(o).map(m=>{const p=r?.[m],d=i?.[m];if(p===null)return null;const h=or(p)||or(d);return o[m][h]}),l=r&&Object.entries(r).reduce((m,p)=>{let[d,h]=p;return h===void 0||(m[d]=h),m},{}),c=n==null||(s=n.compoundVariants)===null||s===void 0?void 0:s.reduce((m,p)=>{let{class:d,className:h,...y}=p;return Object.entries(y).every(g=>{let[b,N]=g;return Array.isArray(N)?N.includes({...i,...l}[b]):{...i,...l}[b]===N})?[...m,d,h]:m},[]);return ar(e,a,c,r?.class,r?.className)},So=(e,n)=>{const r=new Array(e.length+n.length);for(let s=0;s<e.length;s++)r[s]=e[s];for(let s=0;s<n.length;s++)r[e.length+s]=n[s];return r},Fo=(e,n)=>({classGroupId:e,validator:n}),lr=(e=new Map,n=null,r)=>({nextPart:e,validators:n,classGroupId:r}),Mt="-",cr=[],$o="arbitrary..",_o=e=>{const n=Po(e),{conflictingClassGroups:r,conflictingClassGroupModifiers:s}=e;return{getClassGroupId:a=>{if(a.startsWith("[")&&a.endsWith("]"))return zo(a);const l=a.split(Mt),c=l[0]===""&&l.length>1?1:0;return dr(l,c,n)},getConflictingClassGroupIds:(a,l)=>{if(l){const c=s[a],m=r[a];return c?m?So(m,c):c:m||cr}return r[a]||cr}}},dr=(e,n,r)=>{if(e.length-n===0)return r.classGroupId;const o=e[n],i=r.nextPart.get(o);if(i){const m=dr(e,n+1,i);if(m)return m}const a=r.validators;if(a===null)return;const l=n===0?e.join(Mt):e.slice(n).join(Mt),c=a.length;for(let m=0;m<c;m++){const p=a[m];if(p.validator(l))return p.classGroupId}},zo=e=>e.slice(1,-1).indexOf(":")===-1?void 0:(()=>{const n=e.slice(1,-1),r=n.indexOf(":"),s=n.slice(0,r);return s?$o+s:void 0})(),Po=e=>{const{theme:n,classGroups:r}=e;return Eo(r,n)},Eo=(e,n)=>{const r=lr();for(const s in e){const o=e[s];ln(o,r,s,n)}return r},ln=(e,n,r,s)=>{const o=e.length;for(let i=0;i<o;i++){const a=e[i];Do(a,n,r,s)}},Do=(e,n,r,s)=>{if(typeof e=="string"){Io(e,n,r);return}if(typeof e=="function"){Mo(e,n,r,s);return}Lo(e,n,r,s)},Io=(e,n,r)=>{const s=e===""?n:ur(n,e);s.classGroupId=r},Mo=(e,n,r,s)=>{if(Oo(e)){ln(e(s),n,r,s);return}n.validators===null&&(n.validators=[]),n.validators.push(Fo(r,e))},Lo=(e,n,r,s)=>{const o=Object.entries(e),i=o.length;for(let a=0;a<i;a++){const[l,c]=o[a];ln(c,ur(n,l),r,s)}},ur=(e,n)=>{let r=e;const s=n.split(Mt),o=s.length;for(let i=0;i<o;i++){const a=s[i];let l=r.nextPart.get(a);l||(l=lr(),r.nextPart.set(a,l)),r=l}return r},Oo=e=>"isThemeGetter"in e&&e.isThemeGetter===!0,Ao=e=>{if(e<1)return{get:()=>{},set:()=>{}};let n=0,r=Object.create(null),s=Object.create(null);const o=(i,a)=>{r[i]=a,n++,n>e&&(n=0,s=r,r=Object.create(null))};return{get(i){let a=r[i];if(a!==void 0)return a;if((a=s[i])!==void 0)return o(i,a),a},set(i,a){i in r?r[i]=a:o(i,a)}}},cn="!",mr=":",qo=[],fr=(e,n,r,s,o)=>({modifiers:e,hasImportantModifier:n,baseClassName:r,maybePostfixModifierPosition:s,isExternal:o}),Vo=e=>{const{prefix:n,experimentalParseClassName:r}=e;let s=o=>{const i=[];let a=0,l=0,c=0,m;const p=o.length;for(let b=0;b<p;b++){const N=o[b];if(a===0&&l===0){if(N===mr){i.push(o.slice(c,b)),c=b+1;continue}if(N==="/"){m=b;continue}}N==="["?a++:N==="]"?a--:N==="("?l++:N===")"&&l--}const d=i.length===0?o:o.slice(c);let h=d,y=!1;d.endsWith(cn)?(h=d.slice(0,-1),y=!0):d.startsWith(cn)&&(h=d.slice(1),y=!0);const g=m&&m>c?m-c:void 0;return fr(i,y,h,g)};if(n){const o=n+mr,i=s;s=a=>a.startsWith(o)?i(a.slice(o.length)):fr(qo,!1,a,void 0,!0)}if(r){const o=s;s=i=>r({className:i,parseClassName:o})}return s},Bo=e=>{const n=new Map;return e.orderSensitiveModifiers.forEach((r,s)=>{n.set(r,1e6+s)}),r=>{const s=[];let o=[];for(let i=0;i<r.length;i++){const a=r[i],l=a[0]==="[",c=n.has(a);l||c?(o.length>0&&(o.sort(),s.push(...o),o=[]),s.push(a)):o.push(a)}return o.length>0&&(o.sort(),s.push(...o)),s}},Go=e=>({cache:Ao(e.cacheSize),parseClassName:Vo(e),sortModifiers:Bo(e),postfixLookupClassGroupIds:Ko(e),..._o(e)}),Ko=e=>{const n=Object.create(null),r=e.postfixLookupClassGroups;if(r)for(let s=0;s<r.length;s++)n[r[s]]=!0;return n},Wo=/\s+/,Jo=(e,n)=>{const{parseClassName:r,getClassGroupId:s,getConflictingClassGroupIds:o,sortModifiers:i,postfixLookupClassGroupIds:a}=n,l=[],c=e.trim().split(Wo);let m="";for(let p=c.length-1;p>=0;p-=1){const d=c[p],{isExternal:h,modifiers:y,hasImportantModifier:g,baseClassName:b,maybePostfixModifierPosition:N}=r(d);if(h){m=d+(m.length>0?" "+m:m);continue}let T=!!N,j;if(T){const L=b.substring(0,N);j=s(L);const x=j&&a[j]?s(b):void 0;x&&x!==j&&(j=x,T=!1)}else j=s(b);if(!j){if(!T){m=d+(m.length>0?" "+m:m);continue}if(j=s(b),!j){m=d+(m.length>0?" "+m:m);continue}T=!1}const $=y.length===0?"":y.length===1?y[0]:i(y).join(":"),S=g?$+cn:$,D=S+j;if(l.indexOf(D)>-1)continue;l.push(D);const w=o(j,T);for(let L=0;L<w.length;++L){const x=w[L];l.push(S+x)}m=d+(m.length>0?" "+m:m)}return m},Ho=(...e)=>{let n=0,r,s,o="";for(;n<e.length;)(r=e[n++])&&(s=pr(r))&&(o&&(o+=" "),o+=s);return o},pr=e=>{if(typeof e=="string")return e;let n,r="";for(let s=0;s<e.length;s++)e[s]&&(n=pr(e[s]))&&(r&&(r+=" "),r+=n);return r},Qo=(e,...n)=>{let r,s,o,i;const a=c=>{const m=n.reduce((p,d)=>d(p),e());return r=Go(m),s=r.cache.get,o=r.cache.set,i=l,l(c)},l=c=>{const m=s(c);if(m)return m;const p=Jo(c,r);return o(c,p),p};return i=a,(...c)=>i(Ho(...c))},Ro=[],ce=e=>{const n=r=>r[e]||Ro;return n.isThemeGetter=!0,n},hr=/^\[(?:(\w[\w-]*):)?(.+)\]$/i,xr=/^\((?:(\w[\w-]*):)?(.+)\)$/i,Yo=/^\d+(?:\.\d+)?\/\d+(?:\.\d+)?$/,Xo=/^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/,Uo=/\d+(%|px|r?em|[sdl]?v([hwib]|min|max)|pt|pc|in|cm|mm|cap|ch|ex|r?lh|cq(w|h|i|b|min|max))|\b(calc|min|max|clamp)\(.+\)|^0$/,Zo=/^(rgba?|hsla?|hwb|(ok)?(lab|lch)|color-mix)\(.+\)$/,ea=/^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/,ta=/^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/,Le=e=>Yo.test(e),R=e=>!!e&&!Number.isNaN(Number(e)),$e=e=>!!e&&Number.isInteger(Number(e)),dn=e=>e.endsWith("%")&&R(e.slice(0,-1)),De=e=>Xo.test(e),gr=()=>!0,na=e=>Uo.test(e)&&!Zo.test(e),un=()=>!1,ra=e=>ea.test(e),sa=e=>ta.test(e),oa=e=>!z(e)&&!P(e),aa=e=>e.startsWith("@container")&&(e[10]==="/"&&e[11]!==void 0||e[11]==="s"&&e[16]!==void 0&&e.startsWith("-size/",10)||e[11]==="n"&&e[18]!==void 0&&e.startsWith("-normal/",10)),ia=e=>Oe(e,Cr,un),z=e=>hr.test(e),Be=e=>Oe(e,wr,na),br=e=>Oe(e,ha,R),la=e=>Oe(e,Tr,gr),ca=e=>Oe(e,kr,un),yr=e=>Oe(e,jr,un),da=e=>Oe(e,Nr,sa),Lt=e=>Oe(e,Sr,ra),P=e=>xr.test(e),ut=e=>Ge(e,wr),ua=e=>Ge(e,kr),vr=e=>Ge(e,jr),ma=e=>Ge(e,Cr),fa=e=>Ge(e,Nr),Ot=e=>Ge(e,Sr,!0),pa=e=>Ge(e,Tr,!0),Oe=(e,n,r)=>{const s=hr.exec(e);return s?s[1]?n(s[1]):r(s[2]):!1},Ge=(e,n,r=!1)=>{const s=xr.exec(e);return s?s[1]?n(s[1]):r:!1},jr=e=>e==="position"||e==="percentage",Nr=e=>e==="image"||e==="url",Cr=e=>e==="length"||e==="size"||e==="bg-size",wr=e=>e==="length",ha=e=>e==="number",kr=e=>e==="family-name",Tr=e=>e==="number"||e==="weight",Sr=e=>e==="shadow",xa=Qo(()=>{const e=ce("color"),n=ce("font"),r=ce("text"),s=ce("font-weight"),o=ce("tracking"),i=ce("leading"),a=ce("breakpoint"),l=ce("container"),c=ce("spacing"),m=ce("radius"),p=ce("shadow"),d=ce("inset-shadow"),h=ce("text-shadow"),y=ce("drop-shadow"),g=ce("blur"),b=ce("perspective"),N=ce("aspect"),T=ce("ease"),j=ce("animate"),$=()=>["auto","avoid","all","avoid-page","page","left","right","column"],S=()=>["center","top","bottom","left","right","top-left","left-top","top-right","right-top","bottom-right","right-bottom","bottom-left","left-bottom"],D=()=>[...S(),P,z],w=()=>["auto","hidden","clip","visible","scroll"],L=()=>["auto","contain","none"],x=()=>[P,z,c],k=()=>[Le,"full","auto",...x()],V=()=>[$e,"none","subgrid",P,z],I=()=>["auto",{span:["full",$e,P,z]},$e,P,z],A=()=>[$e,"auto",P,z],W=()=>["auto","min","max","fr",P,z],H=()=>["start","end","center","between","around","evenly","stretch","baseline","center-safe","end-safe"],U=()=>["start","end","center","stretch","center-safe","end-safe"],E=()=>["auto",...x()],Y=()=>[Le,"auto","full","dvw","dvh","lvw","lvh","svw","svh","min","max","fit",...x()],se=()=>[Le,"screen","full","dvw","lvw","svw","min","max","fit",...x()],ue=()=>[Le,"screen","full","lh","dvh","lvh","svh","min","max","fit",...x()],M=()=>[e,P,z],we=()=>[...S(),vr,yr,{position:[P,z]}],ke=()=>["no-repeat",{repeat:["","x","y","space","round"]}],ye=()=>["auto","cover","contain",ma,ia,{size:[P,z]}],me=()=>[dn,ut,Be],O=()=>["","none","full",m,P,z],Q=()=>["",R,ut,Be],oe=()=>["solid","dashed","dotted","double"],ge=()=>["normal","multiply","screen","overlay","darken","lighten","color-dodge","color-burn","hard-light","soft-light","difference","exclusion","hue","saturation","color","luminosity"],re=()=>[R,dn,vr,yr],Ie=()=>["","none",g,P,z],Me=()=>["none",R,P,z],Se=()=>["none",R,P,z],Fe=()=>[R,P,z],de=()=>[Le,"full",...x()];return{cacheSize:500,theme:{animate:["spin","ping","pulse","bounce"],aspect:["video"],blur:[De],breakpoint:[De],color:[gr],container:[De],"drop-shadow":[De],ease:["in","out","in-out"],font:[oa],"font-weight":["thin","extralight","light","normal","medium","semibold","bold","extrabold","black"],"inset-shadow":[De],leading:["none","tight","snug","normal","relaxed","loose"],perspective:["dramatic","near","normal","midrange","distant","none"],radius:[De],shadow:[De],spacing:["px",R],text:[De],"text-shadow":[De],tracking:["tighter","tight","normal","wide","wider","widest"]},classGroups:{aspect:[{aspect:["auto","square",Le,z,P,N]}],container:["container"],"container-type":[{"@container":["","normal","size",P,z]}],"container-named":[aa],columns:[{columns:[R,z,P,l]}],"break-after":[{"break-after":$()}],"break-before":[{"break-before":$()}],"break-inside":[{"break-inside":["auto","avoid","avoid-page","avoid-column"]}],"box-decoration":[{"box-decoration":["slice","clone"]}],box:[{box:["border","content"]}],display:["block","inline-block","inline","flex","inline-flex","table","inline-table","table-caption","table-cell","table-column","table-column-group","table-footer-group","table-header-group","table-row-group","table-row","flow-root","grid","inline-grid","contents","list-item","hidden"],sr:["sr-only","not-sr-only"],float:[{float:["right","left","none","start","end"]}],clear:[{clear:["left","right","both","none","start","end"]}],isolation:["isolate","isolation-auto"],"object-fit":[{object:["contain","cover","fill","none","scale-down"]}],"object-position":[{object:D()}],overflow:[{overflow:w()}],"overflow-x":[{"overflow-x":w()}],"overflow-y":[{"overflow-y":w()}],overscroll:[{overscroll:L()}],"overscroll-x":[{"overscroll-x":L()}],"overscroll-y":[{"overscroll-y":L()}],position:["static","fixed","absolute","relative","sticky"],inset:[{inset:k()}],"inset-x":[{"inset-x":k()}],"inset-y":[{"inset-y":k()}],start:[{"inset-s":k(),start:k()}],end:[{"inset-e":k(),end:k()}],"inset-bs":[{"inset-bs":k()}],"inset-be":[{"inset-be":k()}],top:[{top:k()}],right:[{right:k()}],bottom:[{bottom:k()}],left:[{left:k()}],visibility:["visible","invisible","collapse"],z:[{z:[$e,"auto",P,z]}],basis:[{basis:[Le,"full","auto",l,...x()]}],"flex-direction":[{flex:["row","row-reverse","col","col-reverse"]}],"flex-wrap":[{flex:["nowrap","wrap","wrap-reverse"]}],flex:[{flex:[R,Le,"auto","initial","none",z]}],grow:[{grow:["",R,P,z]}],shrink:[{shrink:["",R,P,z]}],order:[{order:[$e,"first","last","none",P,z]}],"grid-cols":[{"grid-cols":V()}],"col-start-end":[{col:I()}],"col-start":[{"col-start":A()}],"col-end":[{"col-end":A()}],"grid-rows":[{"grid-rows":V()}],"row-start-end":[{row:I()}],"row-start":[{"row-start":A()}],"row-end":[{"row-end":A()}],"grid-flow":[{"grid-flow":["row","col","dense","row-dense","col-dense"]}],"auto-cols":[{"auto-cols":W()}],"auto-rows":[{"auto-rows":W()}],gap:[{gap:x()}],"gap-x":[{"gap-x":x()}],"gap-y":[{"gap-y":x()}],"justify-content":[{justify:[...H(),"normal"]}],"justify-items":[{"justify-items":[...U(),"normal"]}],"justify-self":[{"justify-self":["auto",...U()]}],"align-content":[{content:["normal",...H()]}],"align-items":[{items:[...U(),{baseline:["","last"]}]}],"align-self":[{self:["auto",...U(),{baseline:["","last"]}]}],"place-content":[{"place-content":H()}],"place-items":[{"place-items":[...U(),"baseline"]}],"place-self":[{"place-self":["auto",...U()]}],p:[{p:x()}],px:[{px:x()}],py:[{py:x()}],ps:[{ps:x()}],pe:[{pe:x()}],pbs:[{pbs:x()}],pbe:[{pbe:x()}],pt:[{pt:x()}],pr:[{pr:x()}],pb:[{pb:x()}],pl:[{pl:x()}],m:[{m:E()}],mx:[{mx:E()}],my:[{my:E()}],ms:[{ms:E()}],me:[{me:E()}],mbs:[{mbs:E()}],mbe:[{mbe:E()}],mt:[{mt:E()}],mr:[{mr:E()}],mb:[{mb:E()}],ml:[{ml:E()}],"space-x":[{"space-x":x()}],"space-x-reverse":["space-x-reverse"],"space-y":[{"space-y":x()}],"space-y-reverse":["space-y-reverse"],size:[{size:Y()}],"inline-size":[{inline:["auto",...se()]}],"min-inline-size":[{"min-inline":["auto",...se()]}],"max-inline-size":[{"max-inline":["none",...se()]}],"block-size":[{block:["auto",...ue()]}],"min-block-size":[{"min-block":["auto",...ue()]}],"max-block-size":[{"max-block":["none",...ue()]}],w:[{w:[l,"screen",...Y()]}],"min-w":[{"min-w":[l,"screen","none",...Y()]}],"max-w":[{"max-w":[l,"screen","none","prose",{screen:[a]},...Y()]}],h:[{h:["screen","lh",...Y()]}],"min-h":[{"min-h":["screen","lh","none",...Y()]}],"max-h":[{"max-h":["screen","lh",...Y()]}],"font-size":[{text:["base",r,ut,Be]}],"font-smoothing":["antialiased","subpixel-antialiased"],"font-style":["italic","not-italic"],"font-weight":[{font:[s,pa,la]}],"font-stretch":[{"font-stretch":["ultra-condensed","extra-condensed","condensed","semi-condensed","normal","semi-expanded","expanded","extra-expanded","ultra-expanded",dn,z]}],"font-family":[{font:[ua,ca,n]}],"font-features":[{"font-features":[z]}],"fvn-normal":["normal-nums"],"fvn-ordinal":["ordinal"],"fvn-slashed-zero":["slashed-zero"],"fvn-figure":["lining-nums","oldstyle-nums"],"fvn-spacing":["proportional-nums","tabular-nums"],"fvn-fraction":["diagonal-fractions","stacked-fractions"],tracking:[{tracking:[o,P,z]}],"line-clamp":[{"line-clamp":[R,"none",P,br]}],leading:[{leading:[i,...x()]}],"list-image":[{"list-image":["none",P,z]}],"list-style-position":[{list:["inside","outside"]}],"list-style-type":[{list:["disc","decimal","none",P,z]}],"text-alignment":[{text:["left","center","right","justify","start","end"]}],"placeholder-color":[{placeholder:M()}],"text-color":[{text:M()}],"text-decoration":["underline","overline","line-through","no-underline"],"text-decoration-style":[{decoration:[...oe(),"wavy"]}],"text-decoration-thickness":[{decoration:[R,"from-font","auto",P,Be]}],"text-decoration-color":[{decoration:M()}],"underline-offset":[{"underline-offset":[R,"auto",P,z]}],"text-transform":["uppercase","lowercase","capitalize","normal-case"],"text-overflow":["truncate","text-ellipsis","text-clip"],"text-wrap":[{text:["wrap","nowrap","balance","pretty"]}],indent:[{indent:x()}],"tab-size":[{tab:[$e,P,z]}],"vertical-align":[{align:["baseline","top","middle","bottom","text-top","text-bottom","sub","super",P,z]}],whitespace:[{whitespace:["normal","nowrap","pre","pre-line","pre-wrap","break-spaces"]}],break:[{break:["normal","words","all","keep"]}],wrap:[{wrap:["break-word","anywhere","normal"]}],hyphens:[{hyphens:["none","manual","auto"]}],content:[{content:["none",P,z]}],"bg-attachment":[{bg:["fixed","local","scroll"]}],"bg-clip":[{"bg-clip":["border","padding","content","text"]}],"bg-origin":[{"bg-origin":["border","padding","content"]}],"bg-position":[{bg:we()}],"bg-repeat":[{bg:ke()}],"bg-size":[{bg:ye()}],"bg-image":[{bg:["none",{linear:[{to:["t","tr","r","br","b","bl","l","tl"]},$e,P,z],radial:["",P,z],conic:[$e,P,z]},fa,da]}],"bg-color":[{bg:M()}],"gradient-from-pos":[{from:me()}],"gradient-via-pos":[{via:me()}],"gradient-to-pos":[{to:me()}],"gradient-from":[{from:M()}],"gradient-via":[{via:M()}],"gradient-to":[{to:M()}],rounded:[{rounded:O()}],"rounded-s":[{"rounded-s":O()}],"rounded-e":[{"rounded-e":O()}],"rounded-t":[{"rounded-t":O()}],"rounded-r":[{"rounded-r":O()}],"rounded-b":[{"rounded-b":O()}],"rounded-l":[{"rounded-l":O()}],"rounded-ss":[{"rounded-ss":O()}],"rounded-se":[{"rounded-se":O()}],"rounded-ee":[{"rounded-ee":O()}],"rounded-es":[{"rounded-es":O()}],"rounded-tl":[{"rounded-tl":O()}],"rounded-tr":[{"rounded-tr":O()}],"rounded-br":[{"rounded-br":O()}],"rounded-bl":[{"rounded-bl":O()}],"border-w":[{border:Q()}],"border-w-x":[{"border-x":Q()}],"border-w-y":[{"border-y":Q()}],"border-w-s":[{"border-s":Q()}],"border-w-e":[{"border-e":Q()}],"border-w-bs":[{"border-bs":Q()}],"border-w-be":[{"border-be":Q()}],"border-w-t":[{"border-t":Q()}],"border-w-r":[{"border-r":Q()}],"border-w-b":[{"border-b":Q()}],"border-w-l":[{"border-l":Q()}],"divide-x":[{"divide-x":Q()}],"divide-x-reverse":["divide-x-reverse"],"divide-y":[{"divide-y":Q()}],"divide-y-reverse":["divide-y-reverse"],"border-style":[{border:[...oe(),"hidden","none"]}],"divide-style":[{divide:[...oe(),"hidden","none"]}],"border-color":[{border:M()}],"border-color-x":[{"border-x":M()}],"border-color-y":[{"border-y":M()}],"border-color-s":[{"border-s":M()}],"border-color-e":[{"border-e":M()}],"border-color-bs":[{"border-bs":M()}],"border-color-be":[{"border-be":M()}],"border-color-t":[{"border-t":M()}],"border-color-r":[{"border-r":M()}],"border-color-b":[{"border-b":M()}],"border-color-l":[{"border-l":M()}],"divide-color":[{divide:M()}],"outline-style":[{outline:[...oe(),"none","hidden"]}],"outline-offset":[{"outline-offset":[R,P,z]}],"outline-w":[{outline:["",R,ut,Be]}],"outline-color":[{outline:M()}],shadow:[{shadow:["","none",p,Ot,Lt]}],"shadow-color":[{shadow:M()}],"inset-shadow":[{"inset-shadow":["none",d,Ot,Lt]}],"inset-shadow-color":[{"inset-shadow":M()}],"ring-w":[{ring:Q()}],"ring-w-inset":["ring-inset"],"ring-color":[{ring:M()}],"ring-offset-w":[{"ring-offset":[R,Be]}],"ring-offset-color":[{"ring-offset":M()}],"inset-ring-w":[{"inset-ring":Q()}],"inset-ring-color":[{"inset-ring":M()}],"text-shadow":[{"text-shadow":["none",h,Ot,Lt]}],"text-shadow-color":[{"text-shadow":M()}],opacity:[{opacity:[R,P,z]}],"mix-blend":[{"mix-blend":[...ge(),"plus-darker","plus-lighter"]}],"bg-blend":[{"bg-blend":ge()}],"mask-clip":[{"mask-clip":["border","padding","content","fill","stroke","view"]},"mask-no-clip"],"mask-composite":[{mask:["add","subtract","intersect","exclude"]}],"mask-image-linear-pos":[{"mask-linear":[R]}],"mask-image-linear-from-pos":[{"mask-linear-from":re()}],"mask-image-linear-to-pos":[{"mask-linear-to":re()}],"mask-image-linear-from-color":[{"mask-linear-from":M()}],"mask-image-linear-to-color":[{"mask-linear-to":M()}],"mask-image-t-from-pos":[{"mask-t-from":re()}],"mask-image-t-to-pos":[{"mask-t-to":re()}],"mask-image-t-from-color":[{"mask-t-from":M()}],"mask-image-t-to-color":[{"mask-t-to":M()}],"mask-image-r-from-pos":[{"mask-r-from":re()}],"mask-image-r-to-pos":[{"mask-r-to":re()}],"mask-image-r-from-color":[{"mask-r-from":M()}],"mask-image-r-to-color":[{"mask-r-to":M()}],"mask-image-b-from-pos":[{"mask-b-from":re()}],"mask-image-b-to-pos":[{"mask-b-to":re()}],"mask-image-b-from-color":[{"mask-b-from":M()}],"mask-image-b-to-color":[{"mask-b-to":M()}],"mask-image-l-from-pos":[{"mask-l-from":re()}],"mask-image-l-to-pos":[{"mask-l-to":re()}],"mask-image-l-from-color":[{"mask-l-from":M()}],"mask-image-l-to-color":[{"mask-l-to":M()}],"mask-image-x-from-pos":[{"mask-x-from":re()}],"mask-image-x-to-pos":[{"mask-x-to":re()}],"mask-image-x-from-color":[{"mask-x-from":M()}],"mask-image-x-to-color":[{"mask-x-to":M()}],"mask-image-y-from-pos":[{"mask-y-from":re()}],"mask-image-y-to-pos":[{"mask-y-to":re()}],"mask-image-y-from-color":[{"mask-y-from":M()}],"mask-image-y-to-color":[{"mask-y-to":M()}],"mask-image-radial":[{"mask-radial":[P,z]}],"mask-image-radial-from-pos":[{"mask-radial-from":re()}],"mask-image-radial-to-pos":[{"mask-radial-to":re()}],"mask-image-radial-from-color":[{"mask-radial-from":M()}],"mask-image-radial-to-color":[{"mask-radial-to":M()}],"mask-image-radial-shape":[{"mask-radial":["circle","ellipse"]}],"mask-image-radial-size":[{"mask-radial":[{closest:["side","corner"],farthest:["side","corner"]}]}],"mask-image-radial-pos":[{"mask-radial-at":S()}],"mask-image-conic-pos":[{"mask-conic":[R]}],"mask-image-conic-from-pos":[{"mask-conic-from":re()}],"mask-image-conic-to-pos":[{"mask-conic-to":re()}],"mask-image-conic-from-color":[{"mask-conic-from":M()}],"mask-image-conic-to-color":[{"mask-conic-to":M()}],"mask-mode":[{mask:["alpha","luminance","match"]}],"mask-origin":[{"mask-origin":["border","padding","content","fill","stroke","view"]}],"mask-position":[{mask:we()}],"mask-repeat":[{mask:ke()}],"mask-size":[{mask:ye()}],"mask-type":[{"mask-type":["alpha","luminance"]}],"mask-image":[{mask:["none",P,z]}],filter:[{filter:["","none",P,z]}],blur:[{blur:Ie()}],brightness:[{brightness:[R,P,z]}],contrast:[{contrast:[R,P,z]}],"drop-shadow":[{"drop-shadow":["","none",y,Ot,Lt]}],"drop-shadow-color":[{"drop-shadow":M()}],grayscale:[{grayscale:["",R,P,z]}],"hue-rotate":[{"hue-rotate":[R,P,z]}],invert:[{invert:["",R,P,z]}],saturate:[{saturate:[R,P,z]}],sepia:[{sepia:["",R,P,z]}],"backdrop-filter":[{"backdrop-filter":["","none",P,z]}],"backdrop-blur":[{"backdrop-blur":Ie()}],"backdrop-brightness":[{"backdrop-brightness":[R,P,z]}],"backdrop-contrast":[{"backdrop-contrast":[R,P,z]}],"backdrop-grayscale":[{"backdrop-grayscale":["",R,P,z]}],"backdrop-hue-rotate":[{"backdrop-hue-rotate":[R,P,z]}],"backdrop-invert":[{"backdrop-invert":["",R,P,z]}],"backdrop-opacity":[{"backdrop-opacity":[R,P,z]}],"backdrop-saturate":[{"backdrop-saturate":[R,P,z]}],"backdrop-sepia":[{"backdrop-sepia":["",R,P,z]}],"border-collapse":[{border:["collapse","separate"]}],"border-spacing":[{"border-spacing":x()}],"border-spacing-x":[{"border-spacing-x":x()}],"border-spacing-y":[{"border-spacing-y":x()}],"table-layout":[{table:["auto","fixed"]}],caption:[{caption:["top","bottom"]}],transition:[{transition:["","all","colors","opacity","shadow","transform","none",P,z]}],"transition-behavior":[{transition:["normal","discrete"]}],duration:[{duration:[R,"initial",P,z]}],ease:[{ease:["linear","initial",T,P,z]}],delay:[{delay:[R,P,z]}],animate:[{animate:["none",j,P,z]}],backface:[{backface:["hidden","visible"]}],perspective:[{perspective:[b,P,z]}],"perspective-origin":[{"perspective-origin":D()}],rotate:[{rotate:Me()}],"rotate-x":[{"rotate-x":Me()}],"rotate-y":[{"rotate-y":Me()}],"rotate-z":[{"rotate-z":Me()}],scale:[{scale:Se()}],"scale-x":[{"scale-x":Se()}],"scale-y":[{"scale-y":Se()}],"scale-z":[{"scale-z":Se()}],"scale-3d":["scale-3d"],skew:[{skew:Fe()}],"skew-x":[{"skew-x":Fe()}],"skew-y":[{"skew-y":Fe()}],transform:[{transform:[P,z,"","none","gpu","cpu"]}],"transform-origin":[{origin:D()}],"transform-style":[{transform:["3d","flat"]}],translate:[{translate:de()}],"translate-x":[{"translate-x":de()}],"translate-y":[{"translate-y":de()}],"translate-z":[{"translate-z":de()}],"translate-none":["translate-none"],zoom:[{zoom:[$e,P,z]}],accent:[{accent:M()}],appearance:[{appearance:["none","auto"]}],"caret-color":[{caret:M()}],"color-scheme":[{scheme:["normal","dark","light","light-dark","only-dark","only-light"]}],cursor:[{cursor:["auto","default","pointer","wait","text","move","help","not-allowed","none","context-menu","progress","cell","crosshair","vertical-text","alias","copy","no-drop","grab","grabbing","all-scroll","col-resize","row-resize","n-resize","e-resize","s-resize","w-resize","ne-resize","nw-resize","se-resize","sw-resize","ew-resize","ns-resize","nesw-resize","nwse-resize","zoom-in","zoom-out",P,z]}],"field-sizing":[{"field-sizing":["fixed","content"]}],"pointer-events":[{"pointer-events":["auto","none"]}],resize:[{resize:["none","","y","x"]}],"scroll-behavior":[{scroll:["auto","smooth"]}],"scrollbar-thumb-color":[{"scrollbar-thumb":M()}],"scrollbar-track-color":[{"scrollbar-track":M()}],"scrollbar-gutter":[{"scrollbar-gutter":["auto","stable","both"]}],"scrollbar-w":[{scrollbar:["auto","thin","none"]}],"scroll-m":[{"scroll-m":x()}],"scroll-mx":[{"scroll-mx":x()}],"scroll-my":[{"scroll-my":x()}],"scroll-ms":[{"scroll-ms":x()}],"scroll-me":[{"scroll-me":x()}],"scroll-mbs":[{"scroll-mbs":x()}],"scroll-mbe":[{"scroll-mbe":x()}],"scroll-mt":[{"scroll-mt":x()}],"scroll-mr":[{"scroll-mr":x()}],"scroll-mb":[{"scroll-mb":x()}],"scroll-ml":[{"scroll-ml":x()}],"scroll-p":[{"scroll-p":x()}],"scroll-px":[{"scroll-px":x()}],"scroll-py":[{"scroll-py":x()}],"scroll-ps":[{"scroll-ps":x()}],"scroll-pe":[{"scroll-pe":x()}],"scroll-pbs":[{"scroll-pbs":x()}],"scroll-pbe":[{"scroll-pbe":x()}],"scroll-pt":[{"scroll-pt":x()}],"scroll-pr":[{"scroll-pr":x()}],"scroll-pb":[{"scroll-pb":x()}],"scroll-pl":[{"scroll-pl":x()}],"snap-align":[{snap:["start","end","center","align-none"]}],"snap-stop":[{snap:["normal","always"]}],"snap-type":[{snap:["none","x","y","both"]}],"snap-strictness":[{snap:["mandatory","proximity"]}],touch:[{touch:["auto","none","manipulation"]}],"touch-x":[{"touch-pan":["x","left","right"]}],"touch-y":[{"touch-pan":["y","up","down"]}],"touch-pz":["touch-pinch-zoom"],select:[{select:["none","text","all","auto"]}],"will-change":[{"will-change":["auto","scroll","contents","transform",P,z]}],fill:[{fill:["none",...M()]}],"stroke-w":[{stroke:[R,ut,Be,br]}],stroke:[{stroke:["none",...M()]}],"forced-color-adjust":[{"forced-color-adjust":["auto","none"]}]},conflictingClassGroups:{"container-named":["container-type"],overflow:["overflow-x","overflow-y"],overscroll:["overscroll-x","overscroll-y"],inset:["inset-x","inset-y","inset-bs","inset-be","start","end","top","right","bottom","left"],"inset-x":["right","left"],"inset-y":["top","bottom"],flex:["basis","grow","shrink"],gap:["gap-x","gap-y"],p:["px","py","ps","pe","pbs","pbe","pt","pr","pb","pl"],px:["pr","pl"],py:["pt","pb"],m:["mx","my","ms","me","mbs","mbe","mt","mr","mb","ml"],mx:["mr","ml"],my:["mt","mb"],size:["w","h"],"font-size":["leading"],"fvn-normal":["fvn-ordinal","fvn-slashed-zero","fvn-figure","fvn-spacing","fvn-fraction"],"fvn-ordinal":["fvn-normal"],"fvn-slashed-zero":["fvn-normal"],"fvn-figure":["fvn-normal"],"fvn-spacing":["fvn-normal"],"fvn-fraction":["fvn-normal"],"line-clamp":["display","overflow"],rounded:["rounded-s","rounded-e","rounded-t","rounded-r","rounded-b","rounded-l","rounded-ss","rounded-se","rounded-ee","rounded-es","rounded-tl","rounded-tr","rounded-br","rounded-bl"],"rounded-s":["rounded-ss","rounded-es"],"rounded-e":["rounded-se","rounded-ee"],"rounded-t":["rounded-tl","rounded-tr"],"rounded-r":["rounded-tr","rounded-br"],"rounded-b":["rounded-br","rounded-bl"],"rounded-l":["rounded-tl","rounded-bl"],"border-spacing":["border-spacing-x","border-spacing-y"],"border-w":["border-w-x","border-w-y","border-w-s","border-w-e","border-w-bs","border-w-be","border-w-t","border-w-r","border-w-b","border-w-l"],"border-w-x":["border-w-r","border-w-l"],"border-w-y":["border-w-t","border-w-b"],"border-color":["border-color-x","border-color-y","border-color-s","border-color-e","border-color-bs","border-color-be","border-color-t","border-color-r","border-color-b","border-color-l"],"border-color-x":["border-color-r","border-color-l"],"border-color-y":["border-color-t","border-color-b"],translate:["translate-x","translate-y","translate-none"],"translate-none":["translate","translate-x","translate-y","translate-z"],"scroll-m":["scroll-mx","scroll-my","scroll-ms","scroll-me","scroll-mbs","scroll-mbe","scroll-mt","scroll-mr","scroll-mb","scroll-ml"],"scroll-mx":["scroll-mr","scroll-ml"],"scroll-my":["scroll-mt","scroll-mb"],"scroll-p":["scroll-px","scroll-py","scroll-ps","scroll-pe","scroll-pbs","scroll-pbe","scroll-pt","scroll-pr","scroll-pb","scroll-pl"],"scroll-px":["scroll-pr","scroll-pl"],"scroll-py":["scroll-pt","scroll-pb"],touch:["touch-x","touch-y","touch-pz"],"touch-x":["touch"],"touch-y":["touch"],"touch-pz":["touch"]},conflictingClassGroupModifiers:{"font-size":["leading"]},postfixLookupClassGroups:["container-type"],orderSensitiveModifiers:["*","**","after","backdrop","before","details-content","file","first-letter","first-line","marker","placeholder","selection"]}});function K(...e){return xa(sr(e))}const ga=ir("relative grid w-full grid-cols-[0_1fr] items-start gap-y-0.5 rounded-lg border px-4 py-3 text-sm has-[>svg]:grid-cols-[calc(var(--spacing)*4)_1fr] has-[>svg]:gap-x-3 [&>svg]:size-4 [&>svg]:translate-y-0.5 [&>svg]:text-current",{variants:{variant:{default:"bg-card text-card-foreground",destructive:"bg-card text-destructive *:data-[slot=alert-description]:text-destructive/90 [&>svg]:text-current"}},defaultVariants:{variant:"default"}});function mt({className:e,variant:n,...r}){return t.jsx("div",{"data-slot":"alert",role:"alert",className:K(ga({variant:n}),e),...r})}function Fr({className:e,...n}){return t.jsx("div",{"data-slot":"alert-title",className:K("col-start-2 line-clamp-1 min-h-4 font-medium tracking-tight",e),...n})}function ft({className:e,...n}){return t.jsx("div",{"data-slot":"alert-description",className:K("col-start-2 grid justify-items-start gap-1 text-sm text-muted-foreground [&_p]:leading-relaxed",e),...n})}const Ne=pe.forwardRef(({className:e,type:n,...r},s)=>t.jsx("input",{type:n,ref:s,"data-slot":"input",className:K("h-9 w-full min-w-0 rounded-md border border-input bg-transparent text-foreground px-3 py-0 text-sm shadow-xs transition-[color,box-shadow] outline-none selection:bg-primary selection:text-primary-foreground file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 dark:bg-input/30","focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50","aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40",e),...r}));Ne.displayName="Input";function ba(e){return e.length===0?null:`query GetTableRowCounts { ${e.map(r=>`${r}: ${r}(limit: 1) { total }`).join(" ")} }`}function ya(e=!0){const{data:n,loading:r,error:s}=je(),o=ve(),i=f.useMemo(()=>n.map(d=>d.name),[n]),a=f.useMemo(()=>ba(i),[i]),{data:l,isLoading:c,error:m}=le.useQuery({queryKey:["tableRowCounts",i],queryFn:()=>o.query(a),enabled:e&&!!a&&i.length>0,staleTime:300*1e3});return{stats:f.useMemo(()=>{const d={};for(const h of n){const g=l?.[h.name]?.total??null;d[h.name]={columnCount:h.columns.length,rowCount:g,fkCount:h.singleJoins.length,isLoading:c,error:m?m.message:null}}return d},[n,l,c,m]),isLoading:r||c,error:s}}function va(e){if(e===null)return"—";if(e===0)return"0";if(e<1e3)return e.toString();if(e<1e6){const r=e/1e3;return r%1===0?`${r.toFixed(0)}k`:`${r.toFixed(1)}k`}const n=e/1e6;return n%1===0?`${n.toFixed(0)}M`:`${n.toFixed(1)}M`}const ja={showStats:!1},$r=f.createContext(ja);function Na({config:e,children:n}){return t.jsx($r.Provider,{value:e,children:n})}function Ca(){return f.useContext($r)}const At=50;function wa(e,n){return e===null||n<=0?0:Math.max(2,Math.min(100,Math.round(e/n*100)))}function ka({percent:e,label:n}){return t.jsx("span",{className:"flex-1 min-w-[1.5em] h-[0.5em] rounded-full bg-muted/70 overflow-hidden",role:"img","aria-label":n,title:n,children:t.jsx("span",{className:"block h-full rounded-full bg-emerald-500/70 dark:bg-emerald-400/70",style:{width:`${e}%`}})})}function mn({count:e}){return e<=0?null:t.jsxs("span",{className:"shrink-0 rounded px-1 py-px text-[0.85em] tabular-nums bg-blue-100 text-blue-700 dark:bg-blue-900/60 dark:text-blue-300",children:[e," FK"]})}function Ta({stats:e,maxRowCount:n}){const r=wa(e.rowCount,n),s="flex items-center gap-1.5 text-xs leading-none min-w-0";return e.isLoading?t.jsxs("div",{className:`${s} text-muted-foreground`,children:[t.jsxs("span",{className:"tabular-nums shrink-0",children:[e.columnCount,"c"]}),t.jsx("span",{className:"flex-1 min-w-[1.5em] h-[0.5em] rounded-full bg-muted/70 overflow-hidden",children:t.jsx("span",{className:"block h-full w-1/3 rounded-full bg-muted-foreground/30 animate-pulse"})}),t.jsx(v.Loader2,{className:"size-[1em] shrink-0 animate-spin"}),t.jsx(mn,{count:e.fkCount})]}):e.error?t.jsxs("div",{className:s,children:[t.jsxs("span",{className:"tabular-nums shrink-0 text-muted-foreground",children:[e.columnCount,"c"]}),t.jsx("span",{className:"flex-1 text-destructive truncate",title:e.error,children:"err"}),t.jsx(mn,{count:e.fkCount})]}):t.jsxs("div",{className:s,children:[t.jsxs("span",{className:"tabular-nums shrink-0 text-muted-foreground/70",children:[e.columnCount,"c"]}),t.jsx(ka,{percent:r,label:`${e.rowCount?.toLocaleString()??"unknown"} rows`}),t.jsx("span",{className:"tabular-nums shrink-0 text-right text-muted-foreground",children:va(e.rowCount)}),t.jsx(mn,{count:e.fkCount})]})}function Sa({table:e,stats:n,maxRowCount:r,showStats:s,active:o}){return t.jsx(dt,{to:`/${e.name}`,"aria-current":o?"page":void 0,className:`plain-link block no-underline py-1.5 px-2 text-sm font-medium border-l-2 ${o?"bg-accent text-accent-foreground border-primary":"text-foreground border-transparent hover:bg-muted/50 hover:text-primary"}`,children:t.jsxs("div",{className:"flex flex-col gap-0.5 min-w-0",children:[t.jsx("span",{className:"truncate",title:e.label,children:e.label}),s&&t.jsx(Ta,{stats:n,maxRowCount:r})]})})}function fn(e){const n=e.dbName.lastIndexOf(".");return n>0?e.dbName.slice(0,n):null}function _r({schema:e,count:n,collapsed:r,context:s,onToggle:o}){const i=r?v.ChevronRight:v.ChevronDown,a=t.jsxs(t.Fragment,{children:[t.jsx(i,{className:"size-3.5 shrink-0 text-muted-foreground"}),t.jsx("span",{className:"truncate font-semibold",title:e,children:e}),t.jsx("span",{className:"ml-auto shrink-0 tabular-nums text-[0.85em] text-muted-foreground",children:n})]}),l="flex items-center gap-1.5 w-full px-2 py-1 text-xs uppercase tracking-wide text-muted-foreground bg-muted/40 border-y border-border sticky top-0 z-10";return s?t.jsx("div",{className:l,"aria-hidden":"true",children:a}):t.jsx("button",{type:"button",onClick:o,"aria-expanded":!r,className:`${l} hover:bg-muted/70 text-left`,children:a})}function Fa(){const{showStats:e}=Ca(),{loading:n,error:r,data:s}=je(),{stats:o,isLoading:i}=ya(e),[a,l]=f.useState(""),[c,m]=f.useState(new Set),[p,d]=f.useState(0),h=Rn(),y=decodeURIComponent(h.split("/")[1]??""),g=f.useMemo(()=>{const I=Object.values(o).map(A=>A.rowCount).filter(A=>A!==null);return I.length>0?Math.max(...I):0},[o]),b=a.trim().length>0,N=f.useMemo(()=>{const I=a.trim().toLowerCase();return I?s.filter(A=>{const W=fn(A);return A.label.toLowerCase().includes(I)||A.dbName.toLowerCase().includes(I)||(W?.toLowerCase().includes(I)??!1)}):s},[s,a]),{schemas:T,grouped:j,multiSchema:$}=f.useMemo(()=>{const I=new Map;for(const W of N){const H=fn(W),U=I.get(H)??[];U.push(W),I.set(H,U)}const A=[...I.keys()].filter(W=>W!==null).sort((W,H)=>W.localeCompare(H));return{schemas:A,grouped:I,multiSchema:A.length>1}},[N]),S=f.useMemo(()=>{const I=[];if($){const A=[...T,...j.has(null)?[null]:[]];for(const W of A){const H=j.get(W===void 0?null:W)??[],U=!b&&c.has(W);if(I.push({kind:"group",schema:W??"(no schema)",count:H.length,collapsed:U}),!U)for(const E of H)I.push({kind:"table",schema:W,table:E})}}else for(const A of N)I.push({kind:"table",schema:fn(A),table:A});return I},[$,T,j,N,c,b]);f.useEffect(()=>{d(0)},[a]);const D=Math.max(1,Math.ceil(S.length/At)),w=Math.min(p,D-1),L=w*At,x=S.slice(L,L+At),k=$&&x[0]?.kind==="table"&&x[0].schema?x[0].schema:null,V=I=>m(A=>{const W=new Set(A);return W.has(I)?W.delete(I):W.add(I),W});return n?t.jsxs("div",{className:"flex items-center justify-center gap-2 p-4",children:[t.jsx(v.Loader2,{className:"size-4 animate-spin text-muted-foreground"}),t.jsx("span",{className:"text-sm text-muted-foreground",children:"Loading..."})]}):r?t.jsx(mt,{variant:"destructive",className:"m-2",children:t.jsxs(ft,{children:["Error: ",r.message]})}):s.length===0?t.jsxs("div",{className:"p-4 text-center text-sm text-muted-foreground",children:[t.jsx("p",{className:"font-medium",children:"No tables found"}),t.jsx("p",{className:"mt-1",children:"The database may be empty or the connection may have failed."})]}):t.jsxs("div",{className:"@container min-w-0 flex flex-col h-full",children:[t.jsxs("div",{className:"sticky top-0 z-20 bg-background p-2 border-b border-border",children:[t.jsxs("div",{className:"relative",children:[t.jsx(v.Search,{className:"absolute left-2 top-1/2 -translate-y-1/2 size-4 text-muted-foreground pointer-events-none"}),t.jsx(Ne,{type:"search",value:a,onChange:I=>l(I.target.value),placeholder:"Search tables...","aria-label":"Search tables",className:"pl-8 pr-8 h-8 text-sm"}),b&&t.jsx("button",{type:"button",onClick:()=>l(""),"aria-label":"Clear search",className:"absolute right-1.5 top-1/2 -translate-y-1/2 p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-muted",children:t.jsx(v.X,{className:"size-4"})})]}),b&&t.jsxs("p",{className:"mt-1 px-0.5 text-xs text-muted-foreground",children:[N.length," match",N.length!==1?"es":""]})]}),t.jsx("div",{className:"flex-1 overflow-y-auto min-h-0",children:S.length===0?t.jsxs("p",{className:"p-4 text-center text-sm text-muted-foreground",children:["No tables match “",a,"”."]}):t.jsxs(t.Fragment,{children:[k&&t.jsx(_r,{schema:k,count:j.get(k)?.length??0,collapsed:!1,context:!0}),x.map(I=>I.kind==="group"?t.jsx(_r,{schema:I.schema,count:I.count,collapsed:I.collapsed,onToggle:()=>V(I.schema)},`g:${I.schema}`):t.jsx(Sa,{table:I.table,stats:o[I.table.name]??{columnCount:I.table.columns.length,rowCount:null,fkCount:I.table.singleJoins.length,isLoading:i,error:null},maxRowCount:g,showStats:e,active:I.table.name===y},`t:${I.table.name}`))]})}),D>1&&t.jsxs("div",{className:"sticky bottom-0 z-20 bg-background border-t border-border flex items-center justify-between gap-2 px-2 py-1.5",children:[t.jsx("button",{type:"button",onClick:()=>d(I=>Math.max(0,I-1)),disabled:w===0,"aria-label":"Previous page",className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-muted disabled:opacity-40 disabled:pointer-events-none",children:t.jsx(v.ChevronLeft,{className:"size-4"})}),t.jsxs("span",{className:"text-xs text-muted-foreground tabular-nums",children:[L+1,"–",Math.min(L+At,S.length)," of ",S.length]}),t.jsx("button",{type:"button",onClick:()=>d(I=>Math.min(D-1,I+1)),disabled:w>=D-1,"aria-label":"Next page",className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-muted disabled:opacity-40 disabled:pointer-events-none",children:t.jsx(v.ChevronRight,{className:"size-4"})})]})]})}const $a=ir("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background text-foreground hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"text-foreground hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10","icon-sm":"h-8 w-8 rounded-md"}},defaultVariants:{variant:"default",size:"default"}}),q=pe.forwardRef(({className:e,variant:n,size:r,asChild:s=!1,...o},i)=>{const a=s?Ps.Slot:"button";return t.jsx(a,{className:K($a({variant:n,size:r,className:e})),ref:i,...o})});q.displayName="Button";function zr({...e}){return t.jsx(G.DropdownMenu.Root,{"data-slot":"dropdown-menu",...e})}function Pr({...e}){return t.jsx(G.DropdownMenu.Trigger,{"data-slot":"dropdown-menu-trigger",...e})}function Er({className:e,sideOffset:n=4,...r}){return t.jsx(G.DropdownMenu.Portal,{children:t.jsx(G.DropdownMenu.Content,{"data-slot":"dropdown-menu-content",sideOffset:n,className:K("z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",e),...r})})}function pt({className:e,inset:n,variant:r="default",...s}){return t.jsx(G.DropdownMenu.Item,{"data-slot":"dropdown-menu-item","data-inset":n,"data-variant":r,className:K("relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground data-[variant=destructive]:*:[svg]:text-destructive!",e),...s})}function _a({className:e,children:n,checked:r,...s}){return t.jsxs(G.DropdownMenu.CheckboxItem,{"data-slot":"dropdown-menu-checkbox-item",className:K("relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",e),checked:r,...s,children:[t.jsx("span",{className:"pointer-events-none absolute left-2 flex size-3.5 items-center justify-center",children:t.jsx(G.DropdownMenu.ItemIndicator,{children:t.jsx(v.CheckIcon,{className:"size-4"})})}),n]})}function Ke({className:e,...n}){return t.jsx(G.DropdownMenu.Separator,{"data-slot":"dropdown-menu-separator",className:K("-mx-1 my-1 h-px bg-border",e),...n})}function ht({...e}){return t.jsx(G.DropdownMenu.Sub,{"data-slot":"dropdown-menu-sub",...e})}function xt({className:e,inset:n,children:r,...s}){return t.jsxs(G.DropdownMenu.SubTrigger,{"data-slot":"dropdown-menu-sub-trigger","data-inset":n,className:K("flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[inset]:pl-8 data-[state=open]:bg-accent data-[state=open]:text-accent-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground",e),...s,children:[r,t.jsx(v.ChevronRightIcon,{className:"ml-auto size-4"})]})}function gt({className:e,...n}){return t.jsx(G.DropdownMenu.SubContent,{"data-slot":"dropdown-menu-sub-content",className:K("z-50 min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",e),...n})}const bt=pe.forwardRef(({...e},n)=>t.jsx(G.HoverCard.Root,{"data-slot":"hover-card",...e}));bt.displayName="HoverCard";const yt=pe.forwardRef(({...e},n)=>t.jsx(G.HoverCard.Trigger,{"data-slot":"hover-card-trigger",...e}));yt.displayName="HoverCardTrigger";const vt=pe.forwardRef(({className:e,align:n="center",sideOffset:r=4,...s},o)=>t.jsx(G.HoverCard.Portal,{children:t.jsx(G.HoverCard.Content,{ref:o,"data-slot":"hover-card-content",align:n,sideOffset:r,className:K("z-50 w-64 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...s})}));vt.displayName="HoverCardContent";function _e({...e}){return t.jsx(G.Select.Root,{"data-slot":"select",...e})}function ze({...e}){return t.jsx(G.Select.Value,{"data-slot":"select-value",...e})}function Pe({className:e,size:n="default",children:r,...s}){return t.jsxs(G.Select.Trigger,{"data-slot":"select-trigger","data-size":n,className:K("flex w-fit items-center justify-between gap-2 rounded-md border border-input bg-transparent text-foreground px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[placeholder]:text-muted-foreground data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 dark:bg-input/30 dark:hover:bg-input/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground",e),...s,children:[r,t.jsx(G.Select.Icon,{asChild:!0,children:t.jsx(v.ChevronDownIcon,{className:"size-4 opacity-50"})})]})}function Ee({className:e,children:n,position:r="item-aligned",align:s="center",...o}){return t.jsx(G.Select.Portal,{children:t.jsxs(G.Select.Content,{"data-slot":"select-content",className:K("relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",r==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:r,align:s,...o,children:[t.jsx(za,{}),t.jsx(G.Select.Viewport,{className:K("p-1",r==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1"),children:n}),t.jsx(Pa,{})]})})}function Ce({className:e,children:n,...r}){return t.jsxs(G.Select.Item,{"data-slot":"select-item",className:K("relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",e),...r,children:[t.jsx("span",{"data-slot":"select-item-indicator",className:"absolute right-2 flex size-3.5 items-center justify-center",children:t.jsx(G.Select.ItemIndicator,{children:t.jsx(v.CheckIcon,{className:"size-4"})})}),t.jsx(G.Select.ItemText,{children:n})]})}function za({className:e,...n}){return t.jsx(G.Select.ScrollUpButton,{"data-slot":"select-scroll-up-button",className:K("flex cursor-default items-center justify-center py-1",e),...n,children:t.jsx(v.ChevronUpIcon,{className:"size-4"})})}function Pa({className:e,...n}){return t.jsx(G.Select.ScrollDownButton,{"data-slot":"select-scroll-down-button",className:K("flex cursor-default items-center justify-center py-1",e),...n,children:t.jsx(v.ChevronDownIcon,{className:"size-4"})})}const Dr={_contains:"Contains",_starts_with:"Starts with",_ends_with:"Ends with",_eq:"Equals",_neq:"Not equals",_null:"Is null"},Ea=300;function Da({column:e}){const r=(e.columnDef.meta?.filterOperators??[]).filter(g=>g in Dr),s=e.getFilterValue(),[o,i]=f.useState(s?.operator??"_contains"),[a,l]=f.useState(s?.operator==="_null"?"":String(s?.value??"")),c=f.useRef(),m=o==="_null";f.useEffect(()=>()=>{c.current&&clearTimeout(c.current)},[]);const p=(g,b)=>{if(c.current&&clearTimeout(c.current),g==="_null"){e.setFilterValue({operator:"_null",value:!0});return}if(!b){e.setFilterValue(void 0);return}c.current=setTimeout(()=>{e.setFilterValue({operator:g,value:b})},Ea)},d=g=>{i(g),g==="_null"?(l(""),e.setFilterValue({operator:"_null",value:!0})):a?p(g,a):e.setFilterValue(void 0)},h=g=>{l(g),p(o,g)},y=()=>{c.current&&clearTimeout(c.current),i("_contains"),l(""),e.setFilterValue(void 0)};return r.length===0?null:t.jsxs("div",{className:"flex flex-col gap-2 p-2 min-w-[220px]",children:[t.jsxs(_e,{value:o,onValueChange:d,children:[t.jsx(Pe,{size:"sm",className:"w-full text-xs",children:t.jsx(ze,{})}),t.jsx(Ee,{children:r.map(g=>t.jsx(Ce,{value:g,children:Dr[g]},g))})]}),!m&&t.jsx(Ne,{placeholder:"Filter value...",value:a,onChange:g=>h(g.target.value),className:"h-8 text-xs",autoFocus:!0}),s!==void 0&&t.jsxs(q,{variant:"ghost",size:"sm",className:"h-7 text-xs justify-start",onClick:y,children:[t.jsx(v.X,{className:"size-3"}),"Clear filter"]})]})}const Ir={_eq:"Equals",_neq:"Not equals",_gt:"Greater than",_gte:"Greater or equal",_lt:"Less than",_lte:"Less or equal",_between:"Between",_null:"Is null"},Mr=300;function Ia(e){return(e.columnDef.meta?.paramType??"").replace("!","")==="Int"}function pn(e,n){if(e===""||e==="-")return null;const r=n?parseInt(e,10):parseFloat(e);return Number.isNaN(r)?null:r}function Ma({column:e}){const r=(e.columnDef.meta?.filterOperators??[]).filter(x=>x in Ir),s=Ia(e),o=e.getFilterValue(),i=o?.operator??"_eq",[a,l]=f.useState(i),[c,m]=f.useState(()=>!o||o.operator==="_null"||o.operator==="_between"?"":String(o.value??"")),[p,d]=f.useState(()=>o?.operator==="_between"&&Array.isArray(o.value)?String(o.value[0]??""):""),[h,y]=f.useState(()=>o?.operator==="_between"&&Array.isArray(o.value)?String(o.value[1]??""):""),g=f.useRef();f.useEffect(()=>()=>{g.current&&clearTimeout(g.current)},[]);const b=(x,k)=>{if(g.current&&clearTimeout(g.current),x==="_null"){e.setFilterValue({operator:"_null",value:!0});return}const V=pn(k,s);if(V===null){e.setFilterValue(void 0);return}g.current=setTimeout(()=>{e.setFilterValue({operator:x,value:V})},Mr)},N=(x,k)=>{g.current&&clearTimeout(g.current);const V=pn(x,s),I=pn(k,s);if(V===null||I===null){e.setFilterValue(void 0);return}g.current=setTimeout(()=>{e.setFilterValue({operator:"_between",value:[V,I]})},Mr)},T=x=>{l(x),x==="_null"?(m(""),d(""),y(""),e.setFilterValue({operator:"_null",value:!0})):x==="_between"?(m(""),p&&h?N(p,h):e.setFilterValue(void 0)):(d(""),y(""),c?b(x,c):e.setFilterValue(void 0))},j=x=>{m(x),b(a,x)},$=x=>{d(x),N(x,h)},S=x=>{y(x),N(p,x)},D=()=>{g.current&&clearTimeout(g.current),l("_eq"),m(""),d(""),y(""),e.setFilterValue(void 0)};if(r.length===0)return null;const w=a==="_between",L=a==="_null";return t.jsxs("div",{className:"flex flex-col gap-2 p-2 min-w-[220px]",children:[t.jsxs(_e,{value:a,onValueChange:T,children:[t.jsx(Pe,{size:"sm",className:"w-full text-xs",children:t.jsx(ze,{})}),t.jsx(Ee,{children:r.map(x=>t.jsx(Ce,{value:x,children:Ir[x]},x))})]}),!L&&!w&&t.jsx(Ne,{type:"number",placeholder:"Filter value...",value:c,onChange:x=>j(x.target.value),className:"h-8 text-xs",autoFocus:!0}),w&&t.jsxs("div",{className:"flex gap-2",children:[t.jsx(Ne,{type:"number",placeholder:"Min",value:p,onChange:x=>$(x.target.value),className:"h-8 text-xs",autoFocus:!0}),t.jsx(Ne,{type:"number",placeholder:"Max",value:h,onChange:x=>S(x.target.value),className:"h-8 text-xs"})]}),o!==void 0&&t.jsxs(q,{variant:"ghost",size:"sm",className:"h-7 text-xs justify-start",onClick:D,children:[t.jsx(v.X,{className:"size-3"}),"Clear filter"]})]})}const Lr={_eq:"On",_neq:"Not on",_gt:"After",_gte:"On or after",_lt:"Before",_lte:"On or before",_between:"Between",_null:"Is null"};function La({column:e}){const r=(e.columnDef.meta?.filterOperators??[]).filter(w=>w in Lr),s=e.getFilterValue(),o=s?.operator??"_eq",[i,a]=f.useState(o),[l,c]=f.useState(()=>!s||s.operator==="_null"||s.operator==="_between"?"":String(s.value??"")),[m,p]=f.useState(()=>s?.operator==="_between"&&Array.isArray(s.value)?String(s.value[0]??""):""),[d,h]=f.useState(()=>s?.operator==="_between"&&Array.isArray(s.value)?String(s.value[1]??""):""),y=(w,L)=>{if(w==="_null"){e.setFilterValue({operator:"_null",value:!0});return}if(!L){e.setFilterValue(void 0);return}e.setFilterValue({operator:w,value:L})},g=(w,L)=>{if(!w||!L){e.setFilterValue(void 0);return}e.setFilterValue({operator:"_between",value:[w,L]})},b=w=>{a(w),w==="_null"?(c(""),p(""),h(""),e.setFilterValue({operator:"_null",value:!0})):w==="_between"?(c(""),m&&d?g(m,d):e.setFilterValue(void 0)):(p(""),h(""),l?y(w,l):e.setFilterValue(void 0))},N=w=>{c(w),y(i,w)},T=w=>{p(w),g(w,d)},j=w=>{h(w),g(m,w)},$=()=>{a("_eq"),c(""),p(""),h(""),e.setFilterValue(void 0)};if(r.length===0)return null;const S=i==="_between",D=i==="_null";return t.jsxs("div",{className:"flex flex-col gap-2 p-2 min-w-[220px]",children:[t.jsxs(_e,{value:i,onValueChange:b,children:[t.jsx(Pe,{size:"sm",className:"w-full text-xs",children:t.jsx(ze,{})}),t.jsx(Ee,{children:r.map(w=>t.jsx(Ce,{value:w,children:Lr[w]},w))})]}),!D&&!S&&t.jsx(Ne,{type:"date",value:l,onChange:w=>N(w.target.value),className:"h-8 text-xs"}),S&&t.jsxs("div",{className:"flex gap-2",children:[t.jsx(Ne,{type:"date",value:m,onChange:w=>T(w.target.value),className:"h-8 text-xs"}),t.jsx(Ne,{type:"date",value:d,onChange:w=>j(w.target.value),className:"h-8 text-xs"})]}),s!==void 0&&t.jsxs(q,{variant:"ghost",size:"sm",className:"h-7 text-xs justify-start",onClick:$,children:[t.jsx(v.X,{className:"size-3"}),"Clear filter"]})]})}const Oa={all:"All",true:"True",false:"False",_null:"Is null"};function Aa(e){return e?e.operator==="_null"?"_null":e.operator==="_eq"&&e.value===!0?"true":e.operator==="_eq"&&e.value===!1?"false":"all":"all"}function qa({column:e}){const r=(e.columnDef.meta?.filterOperators??[]).includes("_null"),s=e.getFilterValue(),o=Aa(s),i=r?["all","true","false","_null"]:["all","true","false"],a=c=>{switch(c){case"true":e.setFilterValue({operator:"_eq",value:!0});break;case"false":e.setFilterValue({operator:"_eq",value:!1});break;case"_null":e.setFilterValue({operator:"_null",value:!0});break;default:e.setFilterValue(void 0)}},l=()=>{e.setFilterValue(void 0)};return t.jsxs("div",{className:"flex flex-col gap-2 p-2 min-w-[220px]",children:[t.jsxs(_e,{value:o,onValueChange:a,children:[t.jsx(Pe,{size:"sm",className:"w-full text-xs",children:t.jsx(ze,{})}),t.jsx(Ee,{children:i.map(c=>t.jsx(Ce,{value:c,children:Oa[c]},c))})]}),s!==void 0&&t.jsxs(q,{variant:"ghost",size:"sm",className:"h-7 text-xs justify-start",onClick:l,children:[t.jsx(v.X,{className:"size-3"}),"Clear filter"]})]})}function Va({column:e,joinTable:n,joinLabelColumn:r,joinFkColumn:s}){const o=ve(),a=je().findTable(n),l=`query Lookup${n} { ${n}(sort: [${r}_asc], limit: 100) { data { id: ${s} label: ${r} } } }`,{data:c}=le.useQuery({queryKey:["fkLookup",n,r],queryFn:()=>o.query(l),staleTime:300*1e3,enabled:!!a}),m=c?.[n]?.data??[],p=e.getFilterValue(),d=p?.operator==="_eq"&&p.value!=null?String(p.value):"all",h=g=>{if(g==="all"){e.setFilterValue(void 0);return}const b=Number(g),N=Number.isNaN(b)?g:b;e.setFilterValue({operator:"_eq",value:N})},y=()=>{e.setFilterValue(void 0)};return t.jsxs("div",{className:"flex flex-col gap-2 p-2 min-w-[220px]",children:[t.jsxs(_e,{value:d,onValueChange:h,children:[t.jsx(Pe,{size:"sm",className:"w-full text-xs",children:t.jsx(ze,{})}),t.jsxs(Ee,{children:[t.jsx(Ce,{value:"all",children:"All"}),m.map(g=>t.jsx(Ce,{value:String(g.id),children:String(g.label)},String(g.id)))]})]}),p!==void 0&&t.jsxs(q,{variant:"ghost",size:"sm",className:"h-7 text-xs justify-start",onClick:y,children:[t.jsx(v.X,{className:"size-3"}),"Clear filter"]})]})}function qt(e){return(e.columnDef.meta?.paramType??"").replace("!","")}function Ba(e){return qt(e)==="String"}function Ga(e){const n=qt(e);return n==="Int"||n==="Float"}function Ka(e){return qt(e)==="DateTime"}function Wa(e){return qt(e)==="Boolean"}function Ja(e){const n=e.columnDef.meta;return n?.joinTable?{joinTable:n.joinTable,joinLabelColumn:n.joinLabelColumn??"id",joinFkColumn:n.joinFkColumn??"id",isSelfReference:n.isSelfReference===!0}:null}function Ha(e){return e.columnDef.meta?.column}function Qa(e){const n=e.paramType.replace("!","");if(e.dbType){const r=e.dbType.toUpperCase();return e.maxLength&&(r.includes("VARCHAR")||r.includes("CHAR"))?`${r}(${e.maxLength})`:(r.includes("DECIMAL")||r.includes("NUMERIC"),r)}return n}function Ra(e){const n=e.paramType.replace("!","");return e.isPrimaryKey?t.jsx(v.Key,{className:"size-3.5"}):n==="Int"||n==="Float"?t.jsx(v.Hash,{className:"size-3.5"}):n==="DateTime"?t.jsx(v.Calendar,{className:"size-3.5"}):n==="Boolean"?t.jsx(v.ToggleLeft,{className:"size-3.5"}):t.jsx(v.Type,{className:"size-3.5"})}function Ya({column:e,fkMeta:n}){const r=Qa(e),s=e.isNullable,o=e.isPrimaryKey,i=e.isIdentity,a=e.defaultValue;return t.jsxs("div",{className:"space-y-2",children:[t.jsxs("div",{className:"flex items-center gap-2 border-b pb-2",children:[Ra(e),t.jsx("span",{className:"font-semibold text-foreground",children:e.label})]}),t.jsxs("dl",{className:"grid grid-cols-[auto_1fr] gap-x-3 gap-y-1 text-xs",children:[t.jsx("dt",{className:"text-muted-foreground",children:"Type"}),t.jsx("dd",{className:"text-foreground font-medium",children:r}),t.jsx("dt",{className:"text-muted-foreground",children:"Nullable"}),t.jsx("dd",{className:"text-foreground",children:s?"Yes":"No"}),o&&t.jsxs(t.Fragment,{children:[t.jsx("dt",{className:"text-muted-foreground",children:"Primary Key"}),t.jsxs("dd",{className:"text-foreground text-primary flex items-center gap-1",children:[t.jsx(v.Key,{className:"size-3"}),"Yes"]})]}),i&&t.jsxs(t.Fragment,{children:[t.jsx("dt",{className:"text-muted-foreground",children:"Auto Increment"}),t.jsx("dd",{className:"text-foreground",children:"Yes"})]}),n&&t.jsxs(t.Fragment,{children:[t.jsx("dt",{className:"text-muted-foreground",children:"Foreign Key"}),t.jsxs("dd",{className:"text-foreground text-primary flex items-center gap-1",children:[t.jsx(v.Link2,{className:"size-3"}),n.joinTable,n.isSelfReference&&t.jsx("span",{className:"ml-1 px-1 rounded bg-primary/10 text-[10px] font-medium",children:"self-ref"})]})]}),a!=null&&t.jsxs(t.Fragment,{children:[t.jsx("dt",{className:"text-muted-foreground",children:"Default"}),t.jsx("dd",{className:"text-foreground font-mono text-xs truncate max-w-[150px]",children:String(a)})]}),e.maxLength!==void 0&&t.jsxs(t.Fragment,{children:[t.jsx("dt",{className:"text-muted-foreground",children:"Max Length"}),t.jsx("dd",{className:"text-foreground",children:e.maxLength})]}),e.min!==void 0&&t.jsxs(t.Fragment,{children:[t.jsx("dt",{className:"text-muted-foreground",children:"Min"}),t.jsx("dd",{className:"text-foreground",children:e.min})]}),e.max!==void 0&&t.jsxs(t.Fragment,{children:[t.jsx("dt",{className:"text-muted-foreground",children:"Max"}),t.jsx("dd",{className:"text-foreground",children:e.max})]})]})]})}function Ze({column:e,table:n,title:r}){const s=n.options.meta?.onResetColumnWidths;if(!e.getCanSort())return t.jsx("span",{children:r});const o=e.getIsSorted(),i=e.getFilterValue()!==void 0,a=Ja(e),l=!a&&Ba(e),c=!a&&Ga(e),m=!a&&Ka(e),p=!a&&Wa(e),d=Ha(e),h=t.jsxs(q,{variant:"ghost",size:"sm",className:K("-ml-2 h-7 text-xs data-[state=open]:bg-accent",o&&"text-foreground"),children:[t.jsx("span",{children:r}),i&&t.jsx(v.Filter,{className:"size-3 text-primary"}),o==="desc"?t.jsx(v.ArrowDown,{className:"size-4"}):o==="asc"?t.jsx(v.ArrowUp,{className:"size-4"}):t.jsx(v.ArrowUpDown,{className:"size-4"})]});return t.jsxs(bt,{openDelay:400,closeDelay:200,children:[t.jsxs(zr,{children:[t.jsx(Pr,{asChild:!0,children:t.jsx(yt,{asChild:!0,children:h})}),t.jsxs(Er,{align:"start",children:[t.jsxs(pt,{onClick:()=>e.toggleSorting(!1),children:[t.jsx(v.ArrowUp,{className:"size-3.5 text-muted-foreground"}),"Asc"]}),t.jsxs(pt,{onClick:()=>e.toggleSorting(!0),children:[t.jsx(v.ArrowDown,{className:"size-3.5 text-muted-foreground"}),"Desc"]}),o&&t.jsxs(pt,{onClick:()=>e.clearSorting(),children:[t.jsx(v.ArrowUpDown,{className:"size-3.5 text-muted-foreground"}),"Clear"]}),l&&t.jsxs(t.Fragment,{children:[t.jsx(Ke,{}),t.jsxs(ht,{children:[t.jsxs(xt,{children:[t.jsx(v.Filter,{className:K("size-3.5",i?"text-primary":"text-muted-foreground")}),"Filter"]}),t.jsx(gt,{children:t.jsx(Da,{column:e})})]})]}),c&&t.jsxs(t.Fragment,{children:[t.jsx(Ke,{}),t.jsxs(ht,{children:[t.jsxs(xt,{children:[t.jsx(v.Filter,{className:K("size-3.5",i?"text-primary":"text-muted-foreground")}),"Filter"]}),t.jsx(gt,{children:t.jsx(Ma,{column:e})})]})]}),m&&t.jsxs(t.Fragment,{children:[t.jsx(Ke,{}),t.jsxs(ht,{children:[t.jsxs(xt,{children:[t.jsx(v.Filter,{className:K("size-3.5",i?"text-primary":"text-muted-foreground")}),"Filter"]}),t.jsx(gt,{children:t.jsx(La,{column:e})})]})]}),p&&t.jsxs(t.Fragment,{children:[t.jsx(Ke,{}),t.jsxs(ht,{children:[t.jsxs(xt,{children:[t.jsx(v.Filter,{className:K("size-3.5",i?"text-primary":"text-muted-foreground")}),"Filter"]}),t.jsx(gt,{children:t.jsx(qa,{column:e})})]})]}),a&&t.jsxs(t.Fragment,{children:[t.jsx(Ke,{}),t.jsxs(ht,{children:[t.jsxs(xt,{children:[t.jsx(v.Filter,{className:K("size-3.5",i?"text-primary":"text-muted-foreground")}),"Filter"]}),t.jsx(gt,{children:t.jsx(Va,{column:e,joinTable:a.joinTable,joinLabelColumn:a.joinLabelColumn,joinFkColumn:a.joinFkColumn})})]})]}),e.getCanHide()&&t.jsxs(t.Fragment,{children:[t.jsx(Ke,{}),t.jsxs(pt,{onClick:()=>e.toggleVisibility(!1),children:[t.jsx(v.EyeOff,{className:"size-3.5 text-muted-foreground"}),"Hide"]})]}),s&&t.jsxs(t.Fragment,{children:[t.jsx(Ke,{}),t.jsxs(pt,{onClick:s,children:[t.jsx(v.RotateCcw,{className:"size-3.5 text-muted-foreground"}),"Reset column widths"]})]})]})]}),d&&t.jsx(vt,{align:"start",className:"w-64",children:t.jsx(Ya,{column:d,fkMeta:a})})]})}function Xa(e,n){if(e==null)return null;switch(n){case"Int":{const r=typeof e=="number"?e:Number(e);return Number.isFinite(r)?Math.trunc(r):e}case"Float":{const r=typeof e=="number"?e:Number(e);return Number.isFinite(r)?r:e}case"Boolean":return typeof e=="boolean"?e:e==="true"||e===1?!0:e==="false"||e===0?!1:!!e;default:return String(e)}}function Ua(e){return e?.paramType?.replace("!","")??"String"}function et(e){return(e.sourceColumnNames?.length??0)>1}function Za(e,n,r,s="fk"){if(!e)return null;const o=n.sourceColumnNames??[],i=n.destinationColumnNames??[];if(o.length===0||o.length!==i.length)return null;const a=new Map((r?.columns??[]).map(d=>[d.name,d])),l=[],c={},m=[];for(let d=0;d<o.length;d++){const h=o[d],y=i[d];if(!(h in e))return null;const g=Ua(a.get(y)),b=`${s}_${y}`;c[b]=Xa(e[h],g),m.push(`$${b}: ${g}`),l.push(`{${y}: {_eq: $${b}}}`)}return{filterText:l.length===1?l[0]:`{and: [${l.join(", ")}]}`,variables:c,params:m}}function tt({kind:e}){return t.jsx("span",{className:"text-muted-foreground/60 italic select-none",children:e==="null"?"NULL":"empty"})}const ei="display-format",ti="display-format-preview",ni=new Set(["date","datetime","time","relative","number","percent","raw"]);function ri(e){return{param:(e.paramType??"").replace("!","").toLowerCase(),db:(e.dbType??"").toLowerCase()}}function si({param:e,db:n}){return e==="date"||n==="date"}function oi({param:e,db:n}){return e==="datetime"||e==="datetimeoffset"||n.includes("datetime")||n==="timestamp"||n==="smalldatetime"}function ai(e,n){const s=(n?e.metadata?.[n]:void 0)??e.metadata?.[ei];if(typeof s=="string"&&ni.has(s.toLowerCase()))return s.toLowerCase();const o=ri(e);return oi(o)?"datetime":si(o)?"date":null}function ii(e){if(e instanceof Date)return isNaN(e.getTime())?null:e;if(typeof e=="number"){const n=new Date(e);return isNaN(n.getTime())?null:n}if(typeof e=="string"){const n=new Date(e);return isNaN(n.getTime())?null:n}return null}const li=new Intl.DateTimeFormat(void 0,{dateStyle:"medium"}),ci=new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeStyle:"short"}),di=new Intl.DateTimeFormat(void 0,{timeStyle:"short"}),ui=new Intl.DateTimeFormat(void 0,{dateStyle:"full",timeStyle:"medium"}),Or=new Intl.RelativeTimeFormat(void 0,{numeric:"auto"}),mi=[["year",31536e3],["month",2592e3],["week",604800],["day",86400],["hour",3600],["minute",60],["second",1]];function fi(e,n=new Date){const r=Math.round((e.getTime()-n.getTime())/1e3),s=Math.abs(r);for(const[o,i]of mi)if(s>=i||o==="second")return Or.format(Math.round(r/i),o);return Or.format(0,"second")}function Vt(e,n,r){if(e==null)return t.jsx(tt,{kind:"null"});if(e==="")return t.jsx(tt,{kind:"empty"});const s=ai(n,r?.formatKey);if(s===null||s==="raw")return String(e);if(s==="date"||s==="datetime"||s==="time"||s==="relative"){const o=ii(e);if(!o)return String(e);const i=ui.format(o);if(s==="relative")return t.jsx("span",{title:i,className:"cursor-help underline decoration-dotted decoration-muted-foreground/40 underline-offset-2",children:fi(o)});const a=(s==="date"?li:s==="time"?di:ci).format(o);return t.jsx("span",{title:i,children:a})}if(s==="number"||s==="percent"){const o=typeof e=="number"?e:Number(e);if(isNaN(o))return String(e);const i=s==="percent"?new Intl.NumberFormat(void 0,{style:"percent",maximumFractionDigits:2}).format(o):new Intl.NumberFormat(void 0).format(o);return t.jsx("span",{title:String(e),children:i})}return String(e)}const pi=5,hi=400,xi=200;function gi(e){return e.filter(n=>!n.isPrimaryKey).slice(0,pi)}function bi(e,n,r,s){const o=n.map(a=>a.name).join(" ");return`query FkPreview($id: ${s==="Int"||s==="Int!"?"Int":"String"}) { ${e}(filter: { ${r}: { _eq: $id } } limit: 1) { data { ${o} } } }`}function yi(e,n,r,s){const o=n.map(i=>i.name).join(" ");return`query FkPreview(${r}) { ${e}(filter: ${s} limit: 1) { data { ${o} } } }`}function vi(e,n,r,s,o,i,a){if(r.length===0)return null;if(s&&et(s)&&o){const p=Za(o,s,n);if(!p)return null;const d=p.params.join(", ");return{query:yi(e,r,d,p.filterText),variables:p.variables,cacheKey:p.variables}}const l=n.columns.find(p=>p.name===a)?.paramType??"Int",m={id:["Int","Int!","Float","Float!"].includes(l)?Number(i):i};return{query:bi(e,r,a,l),variables:m,cacheKey:i}}function ji({tableName:e,recordId:n,filterColumn:r,join:s,sourceRow:o,children:i}){const[a,l]=f.useState(!1),c=je(),m=ve(),p=c.findTable(e),d=p?gi(p.columns):[],h=p?vi(e,p,d,s,o,n,r):null,{data:y,isLoading:g}=le.useQuery({queryKey:["fkPreview",e,h?.cacheKey],queryFn:()=>m.query(h.query,h.variables),enabled:a&&!!h,staleTime:300*1e3}),b=y?.[e]?.data?.[0];return t.jsxs(bt,{openDelay:hi,closeDelay:xi,open:a,onOpenChange:l,children:[t.jsx(yt,{asChild:!0,children:i}),t.jsx(vt,{align:"start",className:"w-72",children:t.jsxs("div",{className:"space-y-2",children:[t.jsx("p",{className:"text-sm font-semibold text-foreground",children:p?.label??e}),g&&t.jsx("p",{className:"text-xs text-muted-foreground",children:"Loading..."}),b&&t.jsx("dl",{className:"grid grid-cols-[auto_1fr] gap-x-3 gap-y-1 text-xs",children:d.map(N=>t.jsxs("div",{className:"contents",children:[t.jsx("dt",{className:"text-muted-foreground truncate",children:N.label}),t.jsx("dd",{className:"text-foreground truncate",children:Vt(b[N.name],N,{formatKey:ti})})]},N.name))}),!g&&!b&&a&&t.jsx("p",{className:"text-xs text-muted-foreground",children:"Record not found"})]})})]})}const Ni=new Set(["binary","varbinary","image","blob","tinyblob","mediumblob","longblob","bytea"]),Ci=new Set(["text","ntext","xml"]),wi=new Set(["json","jsonb"]);function jt(e){return Ni.has(e.toLowerCase().replace(/\(.*\)/,""))}function Ar(e){return wi.has(e.toLowerCase().replace(/\(.*\)/,""))}function Bt(e){const n=e.toLowerCase(),r=n.replace(/\(.*\)/,"");return!!(Ci.has(r)||n.includes("(max)"))}function hn(e,n){if(!e)return"text";if(n&&jt(n))return"binary";if(n&&Ar(n))return"json";const r=e.trimStart();if(r.startsWith("{")&&r.endsWith("}")||r.startsWith("[")&&r.endsWith("]"))try{return JSON.parse(r),"json"}catch{}return r.startsWith("<?xml")||r.startsWith("<")&&r.includes("</")&&r.endsWith(">")?"xml":/^[aOsidb]:\d+[:{;]/.test(r)?"php-serialized":e.length>200||e.includes(`
78
- `)?"longtext":"text"}const qr=80;function ki(e){return e.length<=qr?e:e.slice(0,qr)+"..."}function Ti(e){const n=Math.ceil(e.length*3/4);return n<1024?`${n} bytes`:n<1024*1024?`${(n/1024).toFixed(1)} KB`:`${(n/(1024*1024)).toFixed(1)} MB`}const Si={json:v.Braces,xml:v.Code,"php-serialized":v.Database,binary:v.Binary,longtext:v.FileText,text:v.FileText},Fi={json:"JSON",xml:"XML","php-serialized":"PHP",binary:"Binary",longtext:"Text",text:"Text"};function $i(e,n){if(n==="json")try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}return e}function _i({value:e,dbType:n,onExpand:r}){if(e==null)return t.jsx(tt,{kind:"null"});const s=typeof e=="object"?JSON.stringify(e):String(e);if(s==="")return t.jsx(tt,{kind:"empty"});const o=hn(s,n);if(o==="text")return t.jsx("span",{children:s});if(o==="binary")return t.jsxs("span",{className:"inline-flex items-center gap-1.5 text-muted-foreground",children:[t.jsx(v.Binary,{className:"size-3.5"}),t.jsx("span",{className:"text-xs font-mono",children:Ti(s)}),r&&t.jsx("button",{type:"button",className:"shrink-0 opacity-40 hover:opacity-100 transition-opacity",onClick:c=>{c.stopPropagation(),r()},"aria-label":"Expand content",children:t.jsx(v.Expand,{className:"size-3"})})]});const i=Si[o],a=ki(s);return s.length>80||o==="json"||o==="xml"||o==="php-serialized"?t.jsxs(bt,{openDelay:300,closeDelay:200,children:[t.jsx(yt,{asChild:!0,children:t.jsxs("button",{type:"button",className:"inline-flex items-center gap-1.5 text-left hover:text-primary transition-colors max-w-full",children:[t.jsx(i,{className:"size-3 text-muted-foreground shrink-0"}),t.jsx("span",{className:"font-mono text-xs truncate",children:a}),r&&t.jsx("span",{role:"button",tabIndex:0,className:"shrink-0 opacity-40 hover:opacity-100 transition-opacity",onClick:c=>{c.stopPropagation(),c.preventDefault(),r()},onKeyDown:c=>{c.key==="Enter"&&(c.stopPropagation(),r())},"aria-label":"Expand content",children:t.jsx(v.Expand,{className:"size-3"})})]})}),t.jsxs(vt,{side:"bottom",align:"start",className:"w-[420px] max-h-[320px] p-0",children:[t.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1.5 border-b border-border bg-muted/30",children:[t.jsx(i,{className:"size-3.5 text-muted-foreground"}),t.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:Fi[o]}),t.jsxs("span",{className:"text-xs text-muted-foreground ml-auto",children:[s.length," chars"]})]}),t.jsx("pre",{className:"p-3 text-xs font-mono overflow-auto max-h-[280px] whitespace-pre-wrap break-all",children:$i(s,o)})]})]}):t.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[t.jsx(i,{className:"size-3 text-muted-foreground shrink-0"}),t.jsx("span",{className:"font-mono text-xs",children:s}),r&&t.jsx("button",{type:"button",className:"shrink-0 opacity-40 hover:opacity-100 transition-opacity",onClick:c=>{c.stopPropagation(),r()},"aria-label":"Expand content",children:t.jsx(v.Expand,{className:"size-3"})})]})}const Vr="::";function zi(e){return e==null?"":encodeURIComponent(String(e))}function Br(e){if(e==="")return null;try{return decodeURIComponent(e)}catch{return e}}function Nt(e){return e.map(zi).join(Vr)}function Ct(e,n,r){const s=n.primaryKeys??[];return s.length===0?`row-${r}`:Nt(s.map(o=>e?.[o]))}function Gt(e,n){const r=n.primaryKeys??[];if(r.length===0||e==null)return null;const s={};for(const o of r){if(!(o in e))return null;s[o]=e[o]}return s}function Pi(e,n){if(e==null)return null;switch(n){case"Int":{const r=typeof e=="number"?e:Number(e);return Number.isFinite(r)?Math.trunc(r):e}case"Float":{const r=typeof e=="number"?e:Number(e);return Number.isFinite(r)?r:e}case"Boolean":return typeof e=="boolean"?e:e==="true"||e===1?!0:e==="false"||e===0?!1:!!e;default:return String(e)}}function Ei(e){return e?.paramType?.replace("!","")??"String"}function Gr(e,n){const r=Gt(e,n);if(!r)return null;const s=new Map((n.columns??[]).map(c=>[c.name,c])),o=[],i={},a=[];for(const c of n.primaryKeys??[]){const m=Ei(s.get(c)),p=`pk_${c}`;i[p]=Pi(r[c],m),a.push(`$${p}: ${m}`),o.push(`{${c}: {_eq: $${p}}}`)}return{filterText:o.length===1?o[0]:`{and: [${o.join(", ")}]}`,variables:i,params:a}}function Di(e,n){const r=n.primaryKeys??[];return r.length===0?"":Nt(r.map(s=>e[s]))}function xn(e,n){const r=n.primaryKeys??[];if(r.length===0)return null;if(r.length===1)return{[r[0]]:Br(e)};const s=e.split(Vr);if(s.length!==r.length)return null;const o={};for(let i=0;i<r.length;i++)o[r[i]]=Br(s[i]);return o}function Ii(e,n,r){if(!e)return;const s=e.filter(o=>o.destinationTable===n);if(s.length!==0){if(s.length===1)return s[0];if(r){const o=s.find(i=>i.destinationColumnNames?.[0]===r);if(o)return o}return s[0]}}function Mi(e){return e.fieldName??e.destinationTable}const Kr={String:["_eq","_neq","_contains","_starts_with","_ends_with","_null"],Int:["_eq","_neq","_gt","_gte","_lt","_lte","_between","_null"],Float:["_eq","_neq","_gt","_gte","_lt","_lte","_between","_null"],Boolean:["_eq","_null"],DateTime:["_eq","_neq","_gt","_gte","_lt","_lte","_between","_null"]},Li=/^[_A-Za-z][_0-9A-Za-z]*$/,Oi=/^[_A-Za-z][_0-9A-Za-z]*!?$/;function Wr(e){return typeof e=="string"&&Li.test(e)}function Ai(e){return typeof e=="string"&&Oi.test(e)}function Jr(e,n){return typeof e=="string"&&Hr(n).includes(e)}function Hr(e){const n=e.replace("!","");return Kr[n]??Kr.String}function Qr(e){try{if(!e)return{variables:{},param:"",filterText:""};const[n,r,s,o]=JSON.parse(e);return!Wr(n)||!Ai(o)||!Jr(r,o)?{variables:{},param:"",filterText:""}:{variables:{filter:s},param:`, $filter: ${o}`,filterText:`{${n}: {${r}: $filter} }`}}catch{return{variables:{},param:"",filterText:""}}}function Rr(e){if(!e)return"";const n=new Date(e);return n.toString()==="Invalid Date"||n<new Date("1973-01-01")?"":n.toLocaleString()}function qi(e,n){const r=n.primaryKeys??[];return r.length===0?Nt([e?.id]):r.length===1?Nt([e?.[r[0]]]):Ct(e,n,0)}function Vi(e){switch(e.replace("!","")){case"Int":return"Int";case"Float":return"Float";case"Boolean":return"Boolean";case"DateTime":return"String";default:return"String"}}function Yr(e,n){const r={},s=[],o=[];for(let i=0;i<e.length;i++){const a=e[i],l=a.value;if(l.value===void 0||l.value===null||l.value==="")continue;const c=n.columns.find(d=>d.name===a.id);if(!c||!Wr(a.id)||!Jr(l.operator,c.paramType))continue;const m=`cf_${a.id}_${i}`,p=Vi(c.paramType);if(l.operator==="_null"){o.push(`{${a.id}: {_null: ${l.value?"true":"false"}}}`);continue}if(l.operator==="_between"){const d=l.value;if(!Array.isArray(d)||d.length!==2)continue;const h=`${m}_lo`,y=`${m}_hi`;r[h]=d[0],r[y]=d[1],s.push(`$${h}: ${p}`,`$${y}: ${p}`),o.push(`{${a.id}: {_between: [$${h}, $${y}]}}`);continue}r[m]=l.value,s.push(`$${m}: ${p}`),o.push(`{${a.id}: {${l.operator}: $${m}}}`)}return{variables:r,params:s,filterTexts:o}}function Bi(e){return e.length===0?"":JSON.stringify(e.map(n=>[n.id,n.value.operator,n.value.value]))}function Gi(e){try{return e?JSON.parse(e).map(([r,s,o])=>({id:r,value:{operator:s,value:o}})):[]}catch{return[]}}function Xr(e){return wt(e)[0]?.gqlType??"Int"}function wt(e){const n=e.primaryKeys??[];if(n.length===0)return[];const r=new Map(e.columns.map(s=>[s.name,s]));return n.map(s=>({name:s,gqlType:r.get(s)?.paramType?.replace("!","")??"String"}))}function Ki(e,n){if(e==null)return null;switch(n){case"Int":{const r=typeof e=="number"?e:Number(e);return Number.isFinite(r)?Math.trunc(r):e}case"Float":{const r=typeof e=="number"?e:Number(e);return Number.isFinite(r)?r:e}case"Boolean":return typeof e=="boolean"?e:e==="true"||e===1;default:return String(e)}}function gn(e,n){if(wt(n).length<=1)return{id:Ki(e,Xr(n))};const s=xn(e,n);return s?Gr(s,n)?.variables??{}:{}}function Wi(e,n){return n.map(r=>{const s=e.findTable(r.destinationTable),o=s?.labelColumn??"id",a=[...s?.primaryKeys?.length?s.primaryKeys:["id"]];return o&&!a.includes(o)&&a.push(o),`${r.fieldName??r.destinationTable} { data { ${a.join(" ")} } }`}).join(" ")}function Ji(e,n,r,s,o,i,a){if(!e||!n?.data)return null;const l=n.findTable(e.graphQlName);if(!l)return null;const c=Xr(l),m=wt(l),p=m[0]?.name??"id";let{param:d,filterText:h}=Qr(r);const{params:y,filterTexts:g}=Yr(s,e);y.length>0&&(d+=y.map(S=>`, ${S}`).join(""));const b=[];h&&b.push(h),b.push(...g),b.length>1?h=`{and: [${b.join(", ")}]}`:b.length===1?h=b[0]:h="";const N=new Set,T=e.columns.filter(S=>S?.joinTable===void 0).map(S=>{const D=l.singleJoins.find(x=>x.sourceColumnNames?.[0]===S.name);if(!D)return S;const L=n.findTable(D.destinationTable)?.labelColumn??"id";return{...S,joinTable:D,joinLabelColumn:L}}).map(S=>{if(S?.joinTable){N.add(S.name);const D=n.findTable(S.joinTable.destinationTable),w=D?.primaryKeys?.length?D.primaryKeys:S.joinTable.destinationColumnNames,L=S.joinLabelColumn??"id",x=L&&!w.includes(L)?` label: ${L}`:"";return w.length===1?`${S.name} ${S.joinTable.destinationTable} { id: ${w[0]}${x} }`:`${S.name} ${S.joinTable.destinationTable} { ${w.join(" ")}${x} }`}return S.name}).join(" "),j=Wi(n,l.multiJoins),$=j?`${T} ${j}`:T;if(o&&(a||i)){const S=bn(e,n,i,a);if(S){const D=`${S.childField}(limit: $limit offset: $offset sort: $sort) { total offset limit data {${$}} }`,w=wt(S.parentTable);if(w.length<=1){const V=w[0]?.name??"id";d=`, $id: ${w[0]?.gqlType??"Int"}`;const A=`{ ${V}: { _eq: $id}}`;return`query Get${e.name}($sort: [${e.graphQlName}SortEnum!], $limit: Int, $offset: Int ${d}) { ${S.parentTable.name}(filter: ${A}) { data { ${D} } } }`}d=`, ${w.map(V=>`$pk_${V.name}: ${V.gqlType}`).join(", ")}`;const k=`{and: [${w.map(V=>`{${V.name}: {_eq: $pk_${V.name}}}`).join(", ")}]}`;return`query Get${e.name}($sort: [${e.graphQlName}SortEnum!], $limit: Int, $offset: Int ${d}) { ${S.parentTable.name}(filter: ${k}) { data { ${D} } } }`}}return o&&!i&&!a&&(m.length<=1?(d=`, $id: ${c}`,h=`{ ${p}: { _eq: $id}}`):(d=`, ${m.map(D=>`$pk_${D.name}: ${D.gqlType}`).join(", ")}`,h=`{and: [${m.map(D=>`{${D.name}: {_eq: $pk_${D.name}}}`).join(", ")}]}`)),h&&(h=`filter: ${h}`),`query Get${e.name}($sort: [${e.graphQlName}SortEnum!], $limit: Int, $offset: Int ${d}) { ${e.name}(sort: $sort limit: $limit offset: $offset ${h}) { total offset limit data {${$}}}}`}const Hi={data:[],total:0,offset:0,limit:0};function Qi(e,n,r){const i=e?.[n]?.data?.[0]?.[r];return!i||!Array.isArray(i.data)?Hi:i}function bn(e,n,r,s){const o=r??n.findTable(e.graphQlName)?.singleJoins.find(l=>l.destinationTable===s)?.destinationTable;if(!o)return null;const i=n.findTable(o);if(!i)return null;const a=Ii(i.multiJoins,e.graphQlName,s);return a?{parentTable:i,childField:Mi(a)}:null}function Ur(e,n){return e?!n||(n.primaryKeys?.length??0)<=1?String(e?.id??""):Ct(e,n,0):""}function Ri(e,n){const r=Math.max(0,n-1);return e<0?0:e>r?r:e}function Yi(e,n){const r=n.fieldName??n.destinationTable;return e[r]?.data??[]}const Xi=(e,n,r,s)=>{if(!e||!n)return[];const o=e.columns.map(a=>{const l=e.singleJoins.find(d=>d.sourceColumnNames?.[0]===a.name),c=l?void 0:e.singleJoins.find(d=>(d.sourceColumnNames??[]).includes(a.name)),m=Hr(a.paramType);if(l){const d=l.destinationTable,h=n.findTable(l.destinationTable),y=h?.labelColumn??"id",g=et(l),b=l.destinationTable===e.name,N=b?`Parent ${a.label}`:a.label;return{id:a.name,accessorKey:a.name,header:({column:T,table:j})=>t.jsx(Ze,{column:T,table:j,title:N}),enableSorting:!0,meta:{sortField:a.name,paramType:a.paramType,filterOperators:m,joinTable:l.destinationTable,joinLabelColumn:y,joinFkColumn:l.destinationColumnNames[0],column:a,isSelfReference:b,isCompositeFk:g},cell:({row:T})=>{const j=T.original[d];if(!j)return t.jsx(tt,{kind:"null"});const $=Ur(j,h);return t.jsxs("span",{className:"group/fk inline-flex items-center gap-0.5",children:[t.jsx(ji,{tableName:l.destinationTable,recordId:$,filterColumn:l.destinationColumnNames[0],join:l,sourceRow:T.original,children:t.jsx(dt,{to:"/"+h?.name+"/"+$,className:"text-primary hover:text-primary/80 hover:underline",children:j?.label})}),s&&t.jsx(q,{variant:"ghost",size:"icon-sm",className:"opacity-0 group-hover/fk:opacity-100 size-5 shrink-0",onClick:S=>{S.stopPropagation(),s({tableName:l.destinationTable,filterId:$})},"aria-label":"Open in side column",title:"Open in side column",children:t.jsx(v.PanelRight,{className:"size-3"})})]})}}}if(c){const h=n.findTable(c.destinationTable)?.labelColumn??"id",y=c.destinationTable===e.name;return{id:a.name,accessorFn:g=>a.name?String(g?.[a.name]??""):"",cell:({row:g})=>Vt(g.original[a.name],a),header:({column:g,table:b})=>t.jsx(Ze,{column:g,table:b,title:a.label}),enableSorting:!0,meta:{sortField:a.name,paramType:a.paramType,dbType:a.dbType,filterOperators:m,joinTable:c.destinationTable,joinLabelColumn:h,joinFkColumn:c.destinationColumnNames[(c.sourceColumnNames??[]).indexOf(a.name)]??c.destinationColumnNames[0],column:a,isSelfReference:y,isCompositeFk:!0,isCompositeFkMember:!0}}}return a?.joinTable?{id:a.name,accessorKey:a.name,header:({column:d,table:h})=>t.jsx(Ze,{column:d,table:h,title:a.label}),enableSorting:!0,meta:{sortField:a.name,paramType:a.paramType,filterOperators:m,column:a},cell:({row:d})=>{const h=d.original[a.name];return h?t.jsx(dt,{to:"/"+a.name+"/"+Ur(h,void 0),className:"text-primary hover:text-primary/80 hover:underline",children:a.name}):null}}:a?.paramType==="DateTime"?{id:a.name,accessorFn:d=>Rr(d?.[a.name]),cell:({row:d})=>{const h=d.original[a.name];return h==null||h===""?t.jsx(tt,{kind:h===""?"empty":"null"}):Rr(h)},header:({column:d,table:h})=>t.jsx(Ze,{column:d,table:h,title:a.label}),enableSorting:!0,meta:{sortField:a.name,paramType:a.paramType,dbType:a.dbType,filterOperators:m,column:a}}:Bt(a.dbType)||jt(a.dbType)||Ar(a.dbType)||a.paramType==="JSON"?{id:a.name,accessorFn:d=>a.name?String(d?.[a.name]??""):"",header:({column:d,table:h})=>t.jsx(Ze,{column:d,table:h,title:a.label}),enableSorting:!0,meta:{sortField:a.name,paramType:a.paramType,dbType:a.dbType,filterOperators:m,column:a},cell:({row:d})=>t.jsx(_i,{value:d.original[a.name],dbType:a.dbType,onExpand:r?()=>r(d.index,a.name):void 0})}:{id:a.name,accessorFn:d=>a.name?String(d?.[a.name]??""):"",cell:({row:d})=>Vt(d.original[a.name],a),header:({column:d,table:h})=>t.jsx(Ze,{column:d,table:h,title:a.label}),enableSorting:!0,meta:{sortField:a.name,paramType:a.paramType,dbType:a.dbType,filterOperators:m,column:a}}}),i=e.multiJoins.map(a=>{const l=n.findTable(a.destinationTable),c=l?.labelColumn??"id",p=a.destinationTable===e.name?`Child ${l?.label??a.destinationTable}`:l?.label??a.destinationTable;return{id:`join_${a.fieldName??a.destinationTable}`,header:p,enableSorting:!1,enableHiding:!0,cell:({row:d})=>{const h=qi(d.original,e),y=Yi(d.original,a),g=y.length;if(g===0)return t.jsx("span",{className:"text-muted-foreground",children:"—"});const b=y.slice(0,10).map(T=>String(T[c]??"")).filter(Boolean),N=l?.label??a.destinationTable;return t.jsxs("span",{className:"group/fk inline-flex items-center gap-1",children:[t.jsxs(bt,{openDelay:300,closeDelay:100,children:[t.jsx(yt,{asChild:!0,children:t.jsxs(dt,{to:"/"+l?.name+"/from/"+e.name+"/"+h,className:"inline-flex items-center gap-1 rounded-full border border-border bg-muted/40 px-2 py-0.5 text-xs font-medium text-primary hover:bg-muted hover:border-primary/40 transition-colors",children:[t.jsx(v.List,{className:"size-3"}),g]})}),t.jsxs(vt,{align:"start",sideOffset:6,className:"w-auto max-w-xs p-3",children:[t.jsxs("div",{className:"flex items-center gap-2 border-b pb-2 mb-2",children:[t.jsx(v.List,{className:"size-3.5 text-primary"}),t.jsxs("span",{className:"text-xs font-semibold text-foreground",children:[g," ",N]})]}),t.jsxs("ul",{className:"space-y-0.5 text-xs text-foreground",children:[b.map((T,j)=>t.jsx("li",{className:"truncate",children:T},j)),g>10&&t.jsxs("li",{className:"text-muted-foreground italic",children:["… and ",g-10," more"]})]})]})]}),s&&t.jsx(q,{variant:"ghost",size:"icon-sm",className:"opacity-40 group-hover/fk:opacity-100 size-5 shrink-0 transition-opacity",onClick:T=>{T.stopPropagation(),s({tableName:a.destinationTable,filterTable:e.name,filterId:h,...et(a)?{}:{filterColumn:a.destinationColumnNames[0]}})},"aria-label":"Open in side column",title:"Open in side column",children:t.jsx(v.PanelRight,{className:"size-3"})})]})}}});return[...o,...i]};function Ui(e,n,r,s,o){if(!s&&!o)return gn(e,n);const i=bn(n,r,s,o);return i?gn(e,i.parentTable):gn(e,n)}function Zi(e,n,r,s,o,i){const{search:a}=Yn(),l=Dt(),c=a.get("filter")??"",m=a.get("cf")??"",{variables:p}=Qr(c),d=je(),h=ve(),[y,g]=f.useState([]),[b,N]=f.useState(()=>Gi(m)),[T,j]=f.useState(0),[$,S]=f.useState(50),D=f.useRef(e);e&&e!==D.current&&(D.current=e,y.length>0&&g([]),b.length>0&&N([]),T!==0&&j(0));const w=f.useMemo(()=>{if(y.length>0&&e){const O=y[0];if(e.columns.some(oe=>oe.name===O.id))return[`${O.id}_${O.desc?"desc":"asc"}`]}return e?[`${e.columns.at(0)?.name??"id"}_asc`]:[]},[y,e]),L=f.useMemo(()=>Ji(e,d,c,b,n,r,s),[e,d,c,b,n,r,s]),x=f.useMemo(()=>e?Yr(b,e).variables:{},[b,e]),k=T*$,V=f.useMemo(()=>({sort:w,limit:$,offset:k,...n&&e?Ui(n,e,d,r,s):{},...p,...x}),[w,$,k,n,e,d,r,s,p,x]),{isLoading:I,error:A,data:W}=le.useQuery({queryKey:["tableData",e?.name,L,V],queryFn:()=>h.query(L,V),enabled:!!L&&!!e&&w.length>0}),H=f.useMemo(()=>e?Xi(e,d,o,i):[],[e,d,o,i]),U=f.useMemo(()=>n&&(r||s)&&e?bn(e,d,r,s):null,[n,r,s,e,d]);let E,Y;if(U){const O=Qi(W,U.parentTable.name,U.childField);E=O.data,Y=O.total}else{const O=W?.[e?.name??""];E=O?.data??[],Y=O?.total??0}const se=Math.max(1,Math.ceil(Y/$));f.useEffect(()=>{const O=Ri(T,se);O!==T&&j(O)},[T,se]);const ue=f.useCallback(O=>{const Q=new URLSearchParams(a),oe=Bi(O);oe?Q.set("cf",oe):Q.delete("cf");const ge=Q.toString();l(ge?`?${ge}`:"?")},[a,l]),M=f.useCallback(O=>{g(O),j(0)},[]),we=f.useCallback(O=>{N(O),j(0),ue(O)},[ue]),ke=f.useCallback(O=>{j(O)},[]),ye=f.useCallback(O=>{S(O),j(0)},[]),me=e?.primaryKeys??[];return{columns:H,sorting:y,columnFilters:b,primaryKeys:me,pageIndex:T,pageSize:$,pageCount:se,rows:E,loading:I,error:A,onSortingChange:M,onColumnFiltersChange:we,onPageIndexChange:ke,onPageSizeChange:ye}}function el(e){return typeof e=="object"&&e!==null}function Zr(e,n){if(e==null)return null;if(!n)return e;const r=n.replace("!","");if(r==="Int"){const s=typeof e=="number"?e:Number(e);return Number.isFinite(s)?Math.trunc(s):e}if(r==="Float"){const s=typeof e=="number"?e:Number(e);return Number.isFinite(s)?s:e}return r==="Boolean"?typeof e=="boolean"?e:e==="true"||e===1:String(e)}function es(e){const n=ve(),r=le.useQueryClient(),s=f.useMemo(()=>{const y=new Map;for(const g of e.columns)y.set(g.name,g.paramType);return y},[e]),o=f.useMemo(()=>{const y=e.primaryKeys??[];return y.length>0?y:["id"]},[e]),i=y=>{const g={};if(el(y)){for(const N of o)g[N]=Zr(y[N],s.get(N));return g}const b=o[0];return g[b]=Zr(y,s.get(b)),g},a=f.useMemo(()=>`mutation deleteSingle($detail: Delete_${e.name}){
77
+ }`;class lo extends Error{constructor(n,r){super(n.map(s=>s.message).join("; ")),this.errors=n,this.data=r,this.name="GraphQLRequestError"}errors;data}class rr{constructor(n){this.uri=n}uri;async query(n,r,s){const o=await fetch(this.uri,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:n,variables:r}),signal:s?.signal});if(!o.ok)throw new Error(`GraphQL request failed: ${o.status} ${o.statusText}`);const i=await o.json();if(i.errors?.length)throw new lo(i.errors,i.data);return i.data}}const sr=c.createContext(null),co=sr.Provider;function Ce(){const e=c.useContext(sr);if(!e)throw new Error("useFetcher must be used within a FetcherProvider");return e}function uo(e){const n=e.lastIndexOf(".");return n>=0?e.slice(n+1):e}function mo(e){return uo(e).replace(/([a-z])([A-Z])/g,"$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g,"$1 $2").split(/[_\-\s]+/).filter(Boolean)}function fo(e){return e.length===0?e:e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()}function Ht(e){return e&&mo(e).map(fo).join(" ")}const or=c.createContext({loading:!0,error:null,data:[],findTable:()=>{}}),po=({children:e})=>{const n=ho();return t.jsx(or.Provider,{value:n,children:e})};function Pe(){return c.useContext(or)}function ho(){const e=Ce(),{isLoading:n,error:r,data:s}=me.useQuery({queryKey:["dbSchema"],queryFn:()=>e.query(io),staleTime:1/0});return c.useMemo(()=>{if(n)return{loading:!0,error:null,data:[],findTable:()=>{}};if(r)return{loading:!1,error:{message:r.message},data:[],findTable:()=>{}};if(!s)return{loading:!1,error:null,data:[],findTable:()=>{}};const o=s._dbSchema.map(a=>({...a,name:a.graphQlName,label:Ht(a.dbName),metadata:ar(a.metadata),columns:a.columns.map(l=>({...l,name:l.graphQlName,label:Ht(l.dbName),metadata:ar(l.metadata),inputType:yo(l.inputType)}))}));return{loading:!1,error:null,data:o,findTable:a=>o.find(l=>l.graphQlName===a)}},[n,r,s])}function ar(e){return e.reduce((n,r)=>({...n,[r.key]:xo(r)}),{})}function xo({key:e,value:n}){return e==="type"?go(n):n}function go(e){const n=e.match(/lookup\s*\(\s*(?<id>\w+)\s*,\s*(?<label>\w+)\s*\)/m);if(n?.groups?.id&&n?.groups?.label)return{type:"lookup",id:n.groups.id,label:n.groups.label}}const bo=["text","email","url","tel","date","datetime-local","number","password","search"];function yo(e){if(e&&bo.includes(e))return e}function ir(e){var n,r,s="";if(typeof e=="string"||typeof e=="number")s+=e;else if(typeof e=="object")if(Array.isArray(e)){var o=e.length;for(n=0;n<o;n++)e[n]&&(r=ir(e[n]))&&(s&&(s+=" "),s+=r)}else for(r in e)e[r]&&(s&&(s+=" "),s+=r);return s}function lr(){for(var e,n,r=0,s="",o=arguments.length;r<o;r++)(e=arguments[r])&&(n=ir(e))&&(s&&(s+=" "),s+=n);return s}const cr=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,dr=lr,ur=(e,n)=>r=>{var s;if(n?.variants==null)return dr(e,r?.class,r?.className);const{variants:o,defaultVariants:i}=n,a=Object.keys(o).map(d=>{const p=r?.[d],m=i?.[d];if(p===null)return null;const h=cr(p)||cr(m);return o[d][h]}),l=r&&Object.entries(r).reduce((d,p)=>{let[m,h]=p;return h===void 0||(d[m]=h),d},{}),u=n==null||(s=n.compoundVariants)===null||s===void 0?void 0:s.reduce((d,p)=>{let{class:m,className:h,...x}=p;return Object.entries(x).every(g=>{let[b,k]=g;return Array.isArray(k)?k.includes({...i,...l}[b]):{...i,...l}[b]===k})?[...d,m,h]:d},[]);return dr(e,a,u,r?.class,r?.className)},vo=(e,n)=>{const r=new Array(e.length+n.length);for(let s=0;s<e.length;s++)r[s]=e[s];for(let s=0;s<n.length;s++)r[e.length+s]=n[s];return r},jo=(e,n)=>({classGroupId:e,validator:n}),mr=(e=new Map,n=null,r)=>({nextPart:e,validators:n,classGroupId:r}),Qt="-",fr=[],No="arbitrary..",wo=e=>{const n=ko(e),{conflictingClassGroups:r,conflictingClassGroupModifiers:s}=e;return{getClassGroupId:a=>{if(a.startsWith("[")&&a.endsWith("]"))return Co(a);const l=a.split(Qt),u=l[0]===""&&l.length>1?1:0;return pr(l,u,n)},getConflictingClassGroupIds:(a,l)=>{if(l){const u=s[a],d=r[a];return u?d?vo(d,u):u:d||fr}return r[a]||fr}}},pr=(e,n,r)=>{if(e.length-n===0)return r.classGroupId;const o=e[n],i=r.nextPart.get(o);if(i){const d=pr(e,n+1,i);if(d)return d}const a=r.validators;if(a===null)return;const l=n===0?e.join(Qt):e.slice(n).join(Qt),u=a.length;for(let d=0;d<u;d++){const p=a[d];if(p.validator(l))return p.classGroupId}},Co=e=>e.slice(1,-1).indexOf(":")===-1?void 0:(()=>{const n=e.slice(1,-1),r=n.indexOf(":"),s=n.slice(0,r);return s?No+s:void 0})(),ko=e=>{const{theme:n,classGroups:r}=e;return To(r,n)},To=(e,n)=>{const r=mr();for(const s in e){const o=e[s];pn(o,r,s,n)}return r},pn=(e,n,r,s)=>{const o=e.length;for(let i=0;i<o;i++){const a=e[i];So(a,n,r,s)}},So=(e,n,r,s)=>{if(typeof e=="string"){$o(e,n,r);return}if(typeof e=="function"){_o(e,n,r,s);return}Fo(e,n,r,s)},$o=(e,n,r)=>{const s=e===""?n:hr(n,e);s.classGroupId=r},_o=(e,n,r,s)=>{if(zo(e)){pn(e(s),n,r,s);return}n.validators===null&&(n.validators=[]),n.validators.push(jo(r,e))},Fo=(e,n,r,s)=>{const o=Object.entries(e),i=o.length;for(let a=0;a<i;a++){const[l,u]=o[a];pn(u,hr(n,l),r,s)}},hr=(e,n)=>{let r=e;const s=n.split(Qt),o=s.length;for(let i=0;i<o;i++){const a=s[i];let l=r.nextPart.get(a);l||(l=mr(),r.nextPart.set(a,l)),r=l}return r},zo=e=>"isThemeGetter"in e&&e.isThemeGetter===!0,Eo=e=>{if(e<1)return{get:()=>{},set:()=>{}};let n=0,r=Object.create(null),s=Object.create(null);const o=(i,a)=>{r[i]=a,n++,n>e&&(n=0,s=r,r=Object.create(null))};return{get(i){let a=r[i];if(a!==void 0)return a;if((a=s[i])!==void 0)return o(i,a),a},set(i,a){i in r?r[i]=a:o(i,a)}}},hn="!",xr=":",Po=[],gr=(e,n,r,s,o)=>({modifiers:e,hasImportantModifier:n,baseClassName:r,maybePostfixModifierPosition:s,isExternal:o}),Do=e=>{const{prefix:n,experimentalParseClassName:r}=e;let s=o=>{const i=[];let a=0,l=0,u=0,d;const p=o.length;for(let b=0;b<p;b++){const k=o[b];if(a===0&&l===0){if(k===xr){i.push(o.slice(u,b)),u=b+1;continue}if(k==="/"){d=b;continue}}k==="["?a++:k==="]"?a--:k==="("?l++:k===")"&&l--}const m=i.length===0?o:o.slice(u);let h=m,x=!1;m.endsWith(hn)?(h=m.slice(0,-1),x=!0):m.startsWith(hn)&&(h=m.slice(1),x=!0);const g=d&&d>u?d-u:void 0;return gr(i,x,h,g)};if(n){const o=n+xr,i=s;s=a=>a.startsWith(o)?i(a.slice(o.length)):gr(Po,!1,a,void 0,!0)}if(r){const o=s;s=i=>r({className:i,parseClassName:o})}return s},Mo=e=>{const n=new Map;return e.orderSensitiveModifiers.forEach((r,s)=>{n.set(r,1e6+s)}),r=>{const s=[];let o=[];for(let i=0;i<r.length;i++){const a=r[i],l=a[0]==="[",u=n.has(a);l||u?(o.length>0&&(o.sort(),s.push(...o),o=[]),s.push(a)):o.push(a)}return o.length>0&&(o.sort(),s.push(...o)),s}},Io=e=>({cache:Eo(e.cacheSize),parseClassName:Do(e),sortModifiers:Mo(e),postfixLookupClassGroupIds:Lo(e),...wo(e)}),Lo=e=>{const n=Object.create(null),r=e.postfixLookupClassGroups;if(r)for(let s=0;s<r.length;s++)n[r[s]]=!0;return n},Oo=/\s+/,Ao=(e,n)=>{const{parseClassName:r,getClassGroupId:s,getConflictingClassGroupIds:o,sortModifiers:i,postfixLookupClassGroupIds:a}=n,l=[],u=e.trim().split(Oo);let d="";for(let p=u.length-1;p>=0;p-=1){const m=u[p],{isExternal:h,modifiers:x,hasImportantModifier:g,baseClassName:b,maybePostfixModifierPosition:k}=r(m);if(h){d=m+(d.length>0?" "+d:d);continue}let $=!!k,w;if($){const E=b.substring(0,k);w=s(E);const y=w&&a[w]?s(b):void 0;y&&y!==w&&(w=y,$=!1)}else w=s(b);if(!w){if(!$){d=m+(d.length>0?" "+d:d);continue}if(w=s(b),!w){d=m+(d.length>0?" "+d:d);continue}$=!1}const P=x.length===0?"":x.length===1?x[0]:i(x).join(":"),C=g?P+hn:P,T=C+w;if(l.indexOf(T)>-1)continue;l.push(T);const j=o(w,$);for(let E=0;E<j.length;++E){const y=j[E];l.push(C+y)}d=m+(d.length>0?" "+d:d)}return d},qo=(...e)=>{let n=0,r,s,o="";for(;n<e.length;)(r=e[n++])&&(s=br(r))&&(o&&(o+=" "),o+=s);return o},br=e=>{if(typeof e=="string")return e;let n,r="";for(let s=0;s<e.length;s++)e[s]&&(n=br(e[s]))&&(r&&(r+=" "),r+=n);return r},Vo=(e,...n)=>{let r,s,o,i;const a=u=>{const d=n.reduce((p,m)=>m(p),e());return r=Io(d),s=r.cache.get,o=r.cache.set,i=l,l(u)},l=u=>{const d=s(u);if(d)return d;const p=Ao(u,r);return o(u,p),p};return i=a,(...u)=>i(qo(...u))},Bo=[],he=e=>{const n=r=>r[e]||Bo;return n.isThemeGetter=!0,n},yr=/^\[(?:(\w[\w-]*):)?(.+)\]$/i,vr=/^\((?:(\w[\w-]*):)?(.+)\)$/i,Ko=/^\d+(?:\.\d+)?\/\d+(?:\.\d+)?$/,Go=/^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/,Jo=/\d+(%|px|r?em|[sdl]?v([hwib]|min|max)|pt|pc|in|cm|mm|cap|ch|ex|r?lh|cq(w|h|i|b|min|max))|\b(calc|min|max|clamp)\(.+\)|^0$/,Wo=/^(rgba?|hsla?|hwb|(ok)?(lab|lch)|color-mix)\(.+\)$/,Ho=/^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/,Qo=/^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/,Ye=e=>Ko.test(e),Z=e=>!!e&&!Number.isNaN(Number(e)),Ve=e=>!!e&&Number.isInteger(Number(e)),xn=e=>e.endsWith("%")&&Z(e.slice(0,-1)),He=e=>Go.test(e),jr=()=>!0,Yo=e=>Jo.test(e)&&!Wo.test(e),gn=()=>!1,Ro=e=>Ho.test(e),Xo=e=>Qo.test(e),Uo=e=>!q(e)&&!V(e),Zo=e=>e.startsWith("@container")&&(e[10]==="/"&&e[11]!==void 0||e[11]==="s"&&e[16]!==void 0&&e.startsWith("-size/",10)||e[11]==="n"&&e[18]!==void 0&&e.startsWith("-normal/",10)),ea=e=>Re(e,Sr,gn),q=e=>yr.test(e),ot=e=>Re(e,$r,Yo),Nr=e=>Re(e,la,Z),ta=e=>Re(e,Fr,jr),na=e=>Re(e,_r,gn),wr=e=>Re(e,kr,gn),ra=e=>Re(e,Tr,Xo),Yt=e=>Re(e,zr,Ro),V=e=>vr.test(e),$t=e=>at(e,$r),sa=e=>at(e,_r),Cr=e=>at(e,kr),oa=e=>at(e,Sr),aa=e=>at(e,Tr),Rt=e=>at(e,zr,!0),ia=e=>at(e,Fr,!0),Re=(e,n,r)=>{const s=yr.exec(e);return s?s[1]?n(s[1]):r(s[2]):!1},at=(e,n,r=!1)=>{const s=vr.exec(e);return s?s[1]?n(s[1]):r:!1},kr=e=>e==="position"||e==="percentage",Tr=e=>e==="image"||e==="url",Sr=e=>e==="length"||e==="size"||e==="bg-size",$r=e=>e==="length",la=e=>e==="number",_r=e=>e==="family-name",Fr=e=>e==="number"||e==="weight",zr=e=>e==="shadow",ca=Vo(()=>{const e=he("color"),n=he("font"),r=he("text"),s=he("font-weight"),o=he("tracking"),i=he("leading"),a=he("breakpoint"),l=he("container"),u=he("spacing"),d=he("radius"),p=he("shadow"),m=he("inset-shadow"),h=he("text-shadow"),x=he("drop-shadow"),g=he("blur"),b=he("perspective"),k=he("aspect"),$=he("ease"),w=he("animate"),P=()=>["auto","avoid","all","avoid-page","page","left","right","column"],C=()=>["center","top","bottom","left","right","top-left","left-top","top-right","right-top","bottom-right","right-bottom","bottom-left","left-bottom"],T=()=>[...C(),V,q],j=()=>["auto","hidden","clip","visible","scroll"],E=()=>["auto","contain","none"],y=()=>[V,q,u],S=()=>[Ye,"full","auto",...y()],L=()=>[Ve,"none","subgrid",V,q],v=()=>["auto",{span:["full",Ve,V,q]},Ve,V,q],M=()=>[Ve,"auto",V,q],O=()=>["auto","min","max","fr",V,q],z=()=>["start","end","center","between","around","evenly","stretch","baseline","center-safe","end-safe"],I=()=>["start","end","center","stretch","center-safe","end-safe"],_=()=>["auto",...y()],G=()=>[Ye,"auto","full","dvw","dvh","lvw","lvh","svw","svh","min","max","fit",...y()],U=()=>[Ye,"screen","full","dvw","lvw","svw","min","max","fit",...y()],ie=()=>[Ye,"screen","full","lh","dvh","lvh","svh","min","max","fit",...y()],B=()=>[e,V,q],Te=()=>[...C(),Cr,wr,{position:[V,q]}],ye=()=>["no-repeat",{repeat:["","x","y","space","round"]}],xe=()=>["auto","cover","contain",oa,ea,{size:[V,q]}],le=()=>[xn,$t,ot],re=()=>["","none","full",d,V,q],ae=()=>["",Z,$t,ot],J=()=>["solid","dashed","dotted","double"],ce=()=>["normal","multiply","screen","overlay","darken","lighten","color-dodge","color-burn","hard-light","soft-light","difference","exclusion","hue","saturation","color","luminosity"],R=()=>[Z,xn,Cr,wr],Ne=()=>["","none",g,V,q],Be=()=>["none",Z,V,q],ze=()=>["none",Z,V,q],Ke=()=>[Z,V,q],De=()=>[Ye,"full",...y()];return{cacheSize:500,theme:{animate:["spin","ping","pulse","bounce"],aspect:["video"],blur:[He],breakpoint:[He],color:[jr],container:[He],"drop-shadow":[He],ease:["in","out","in-out"],font:[Uo],"font-weight":["thin","extralight","light","normal","medium","semibold","bold","extrabold","black"],"inset-shadow":[He],leading:["none","tight","snug","normal","relaxed","loose"],perspective:["dramatic","near","normal","midrange","distant","none"],radius:[He],shadow:[He],spacing:["px",Z],text:[He],"text-shadow":[He],tracking:["tighter","tight","normal","wide","wider","widest"]},classGroups:{aspect:[{aspect:["auto","square",Ye,q,V,k]}],container:["container"],"container-type":[{"@container":["","normal","size",V,q]}],"container-named":[Zo],columns:[{columns:[Z,q,V,l]}],"break-after":[{"break-after":P()}],"break-before":[{"break-before":P()}],"break-inside":[{"break-inside":["auto","avoid","avoid-page","avoid-column"]}],"box-decoration":[{"box-decoration":["slice","clone"]}],box:[{box:["border","content"]}],display:["block","inline-block","inline","flex","inline-flex","table","inline-table","table-caption","table-cell","table-column","table-column-group","table-footer-group","table-header-group","table-row-group","table-row","flow-root","grid","inline-grid","contents","list-item","hidden"],sr:["sr-only","not-sr-only"],float:[{float:["right","left","none","start","end"]}],clear:[{clear:["left","right","both","none","start","end"]}],isolation:["isolate","isolation-auto"],"object-fit":[{object:["contain","cover","fill","none","scale-down"]}],"object-position":[{object:T()}],overflow:[{overflow:j()}],"overflow-x":[{"overflow-x":j()}],"overflow-y":[{"overflow-y":j()}],overscroll:[{overscroll:E()}],"overscroll-x":[{"overscroll-x":E()}],"overscroll-y":[{"overscroll-y":E()}],position:["static","fixed","absolute","relative","sticky"],inset:[{inset:S()}],"inset-x":[{"inset-x":S()}],"inset-y":[{"inset-y":S()}],start:[{"inset-s":S(),start:S()}],end:[{"inset-e":S(),end:S()}],"inset-bs":[{"inset-bs":S()}],"inset-be":[{"inset-be":S()}],top:[{top:S()}],right:[{right:S()}],bottom:[{bottom:S()}],left:[{left:S()}],visibility:["visible","invisible","collapse"],z:[{z:[Ve,"auto",V,q]}],basis:[{basis:[Ye,"full","auto",l,...y()]}],"flex-direction":[{flex:["row","row-reverse","col","col-reverse"]}],"flex-wrap":[{flex:["nowrap","wrap","wrap-reverse"]}],flex:[{flex:[Z,Ye,"auto","initial","none",q]}],grow:[{grow:["",Z,V,q]}],shrink:[{shrink:["",Z,V,q]}],order:[{order:[Ve,"first","last","none",V,q]}],"grid-cols":[{"grid-cols":L()}],"col-start-end":[{col:v()}],"col-start":[{"col-start":M()}],"col-end":[{"col-end":M()}],"grid-rows":[{"grid-rows":L()}],"row-start-end":[{row:v()}],"row-start":[{"row-start":M()}],"row-end":[{"row-end":M()}],"grid-flow":[{"grid-flow":["row","col","dense","row-dense","col-dense"]}],"auto-cols":[{"auto-cols":O()}],"auto-rows":[{"auto-rows":O()}],gap:[{gap:y()}],"gap-x":[{"gap-x":y()}],"gap-y":[{"gap-y":y()}],"justify-content":[{justify:[...z(),"normal"]}],"justify-items":[{"justify-items":[...I(),"normal"]}],"justify-self":[{"justify-self":["auto",...I()]}],"align-content":[{content:["normal",...z()]}],"align-items":[{items:[...I(),{baseline:["","last"]}]}],"align-self":[{self:["auto",...I(),{baseline:["","last"]}]}],"place-content":[{"place-content":z()}],"place-items":[{"place-items":[...I(),"baseline"]}],"place-self":[{"place-self":["auto",...I()]}],p:[{p:y()}],px:[{px:y()}],py:[{py:y()}],ps:[{ps:y()}],pe:[{pe:y()}],pbs:[{pbs:y()}],pbe:[{pbe:y()}],pt:[{pt:y()}],pr:[{pr:y()}],pb:[{pb:y()}],pl:[{pl:y()}],m:[{m:_()}],mx:[{mx:_()}],my:[{my:_()}],ms:[{ms:_()}],me:[{me:_()}],mbs:[{mbs:_()}],mbe:[{mbe:_()}],mt:[{mt:_()}],mr:[{mr:_()}],mb:[{mb:_()}],ml:[{ml:_()}],"space-x":[{"space-x":y()}],"space-x-reverse":["space-x-reverse"],"space-y":[{"space-y":y()}],"space-y-reverse":["space-y-reverse"],size:[{size:G()}],"inline-size":[{inline:["auto",...U()]}],"min-inline-size":[{"min-inline":["auto",...U()]}],"max-inline-size":[{"max-inline":["none",...U()]}],"block-size":[{block:["auto",...ie()]}],"min-block-size":[{"min-block":["auto",...ie()]}],"max-block-size":[{"max-block":["none",...ie()]}],w:[{w:[l,"screen",...G()]}],"min-w":[{"min-w":[l,"screen","none",...G()]}],"max-w":[{"max-w":[l,"screen","none","prose",{screen:[a]},...G()]}],h:[{h:["screen","lh",...G()]}],"min-h":[{"min-h":["screen","lh","none",...G()]}],"max-h":[{"max-h":["screen","lh",...G()]}],"font-size":[{text:["base",r,$t,ot]}],"font-smoothing":["antialiased","subpixel-antialiased"],"font-style":["italic","not-italic"],"font-weight":[{font:[s,ia,ta]}],"font-stretch":[{"font-stretch":["ultra-condensed","extra-condensed","condensed","semi-condensed","normal","semi-expanded","expanded","extra-expanded","ultra-expanded",xn,q]}],"font-family":[{font:[sa,na,n]}],"font-features":[{"font-features":[q]}],"fvn-normal":["normal-nums"],"fvn-ordinal":["ordinal"],"fvn-slashed-zero":["slashed-zero"],"fvn-figure":["lining-nums","oldstyle-nums"],"fvn-spacing":["proportional-nums","tabular-nums"],"fvn-fraction":["diagonal-fractions","stacked-fractions"],tracking:[{tracking:[o,V,q]}],"line-clamp":[{"line-clamp":[Z,"none",V,Nr]}],leading:[{leading:[i,...y()]}],"list-image":[{"list-image":["none",V,q]}],"list-style-position":[{list:["inside","outside"]}],"list-style-type":[{list:["disc","decimal","none",V,q]}],"text-alignment":[{text:["left","center","right","justify","start","end"]}],"placeholder-color":[{placeholder:B()}],"text-color":[{text:B()}],"text-decoration":["underline","overline","line-through","no-underline"],"text-decoration-style":[{decoration:[...J(),"wavy"]}],"text-decoration-thickness":[{decoration:[Z,"from-font","auto",V,ot]}],"text-decoration-color":[{decoration:B()}],"underline-offset":[{"underline-offset":[Z,"auto",V,q]}],"text-transform":["uppercase","lowercase","capitalize","normal-case"],"text-overflow":["truncate","text-ellipsis","text-clip"],"text-wrap":[{text:["wrap","nowrap","balance","pretty"]}],indent:[{indent:y()}],"tab-size":[{tab:[Ve,V,q]}],"vertical-align":[{align:["baseline","top","middle","bottom","text-top","text-bottom","sub","super",V,q]}],whitespace:[{whitespace:["normal","nowrap","pre","pre-line","pre-wrap","break-spaces"]}],break:[{break:["normal","words","all","keep"]}],wrap:[{wrap:["break-word","anywhere","normal"]}],hyphens:[{hyphens:["none","manual","auto"]}],content:[{content:["none",V,q]}],"bg-attachment":[{bg:["fixed","local","scroll"]}],"bg-clip":[{"bg-clip":["border","padding","content","text"]}],"bg-origin":[{"bg-origin":["border","padding","content"]}],"bg-position":[{bg:Te()}],"bg-repeat":[{bg:ye()}],"bg-size":[{bg:xe()}],"bg-image":[{bg:["none",{linear:[{to:["t","tr","r","br","b","bl","l","tl"]},Ve,V,q],radial:["",V,q],conic:[Ve,V,q]},aa,ra]}],"bg-color":[{bg:B()}],"gradient-from-pos":[{from:le()}],"gradient-via-pos":[{via:le()}],"gradient-to-pos":[{to:le()}],"gradient-from":[{from:B()}],"gradient-via":[{via:B()}],"gradient-to":[{to:B()}],rounded:[{rounded:re()}],"rounded-s":[{"rounded-s":re()}],"rounded-e":[{"rounded-e":re()}],"rounded-t":[{"rounded-t":re()}],"rounded-r":[{"rounded-r":re()}],"rounded-b":[{"rounded-b":re()}],"rounded-l":[{"rounded-l":re()}],"rounded-ss":[{"rounded-ss":re()}],"rounded-se":[{"rounded-se":re()}],"rounded-ee":[{"rounded-ee":re()}],"rounded-es":[{"rounded-es":re()}],"rounded-tl":[{"rounded-tl":re()}],"rounded-tr":[{"rounded-tr":re()}],"rounded-br":[{"rounded-br":re()}],"rounded-bl":[{"rounded-bl":re()}],"border-w":[{border:ae()}],"border-w-x":[{"border-x":ae()}],"border-w-y":[{"border-y":ae()}],"border-w-s":[{"border-s":ae()}],"border-w-e":[{"border-e":ae()}],"border-w-bs":[{"border-bs":ae()}],"border-w-be":[{"border-be":ae()}],"border-w-t":[{"border-t":ae()}],"border-w-r":[{"border-r":ae()}],"border-w-b":[{"border-b":ae()}],"border-w-l":[{"border-l":ae()}],"divide-x":[{"divide-x":ae()}],"divide-x-reverse":["divide-x-reverse"],"divide-y":[{"divide-y":ae()}],"divide-y-reverse":["divide-y-reverse"],"border-style":[{border:[...J(),"hidden","none"]}],"divide-style":[{divide:[...J(),"hidden","none"]}],"border-color":[{border:B()}],"border-color-x":[{"border-x":B()}],"border-color-y":[{"border-y":B()}],"border-color-s":[{"border-s":B()}],"border-color-e":[{"border-e":B()}],"border-color-bs":[{"border-bs":B()}],"border-color-be":[{"border-be":B()}],"border-color-t":[{"border-t":B()}],"border-color-r":[{"border-r":B()}],"border-color-b":[{"border-b":B()}],"border-color-l":[{"border-l":B()}],"divide-color":[{divide:B()}],"outline-style":[{outline:[...J(),"none","hidden"]}],"outline-offset":[{"outline-offset":[Z,V,q]}],"outline-w":[{outline:["",Z,$t,ot]}],"outline-color":[{outline:B()}],shadow:[{shadow:["","none",p,Rt,Yt]}],"shadow-color":[{shadow:B()}],"inset-shadow":[{"inset-shadow":["none",m,Rt,Yt]}],"inset-shadow-color":[{"inset-shadow":B()}],"ring-w":[{ring:ae()}],"ring-w-inset":["ring-inset"],"ring-color":[{ring:B()}],"ring-offset-w":[{"ring-offset":[Z,ot]}],"ring-offset-color":[{"ring-offset":B()}],"inset-ring-w":[{"inset-ring":ae()}],"inset-ring-color":[{"inset-ring":B()}],"text-shadow":[{"text-shadow":["none",h,Rt,Yt]}],"text-shadow-color":[{"text-shadow":B()}],opacity:[{opacity:[Z,V,q]}],"mix-blend":[{"mix-blend":[...ce(),"plus-darker","plus-lighter"]}],"bg-blend":[{"bg-blend":ce()}],"mask-clip":[{"mask-clip":["border","padding","content","fill","stroke","view"]},"mask-no-clip"],"mask-composite":[{mask:["add","subtract","intersect","exclude"]}],"mask-image-linear-pos":[{"mask-linear":[Z]}],"mask-image-linear-from-pos":[{"mask-linear-from":R()}],"mask-image-linear-to-pos":[{"mask-linear-to":R()}],"mask-image-linear-from-color":[{"mask-linear-from":B()}],"mask-image-linear-to-color":[{"mask-linear-to":B()}],"mask-image-t-from-pos":[{"mask-t-from":R()}],"mask-image-t-to-pos":[{"mask-t-to":R()}],"mask-image-t-from-color":[{"mask-t-from":B()}],"mask-image-t-to-color":[{"mask-t-to":B()}],"mask-image-r-from-pos":[{"mask-r-from":R()}],"mask-image-r-to-pos":[{"mask-r-to":R()}],"mask-image-r-from-color":[{"mask-r-from":B()}],"mask-image-r-to-color":[{"mask-r-to":B()}],"mask-image-b-from-pos":[{"mask-b-from":R()}],"mask-image-b-to-pos":[{"mask-b-to":R()}],"mask-image-b-from-color":[{"mask-b-from":B()}],"mask-image-b-to-color":[{"mask-b-to":B()}],"mask-image-l-from-pos":[{"mask-l-from":R()}],"mask-image-l-to-pos":[{"mask-l-to":R()}],"mask-image-l-from-color":[{"mask-l-from":B()}],"mask-image-l-to-color":[{"mask-l-to":B()}],"mask-image-x-from-pos":[{"mask-x-from":R()}],"mask-image-x-to-pos":[{"mask-x-to":R()}],"mask-image-x-from-color":[{"mask-x-from":B()}],"mask-image-x-to-color":[{"mask-x-to":B()}],"mask-image-y-from-pos":[{"mask-y-from":R()}],"mask-image-y-to-pos":[{"mask-y-to":R()}],"mask-image-y-from-color":[{"mask-y-from":B()}],"mask-image-y-to-color":[{"mask-y-to":B()}],"mask-image-radial":[{"mask-radial":[V,q]}],"mask-image-radial-from-pos":[{"mask-radial-from":R()}],"mask-image-radial-to-pos":[{"mask-radial-to":R()}],"mask-image-radial-from-color":[{"mask-radial-from":B()}],"mask-image-radial-to-color":[{"mask-radial-to":B()}],"mask-image-radial-shape":[{"mask-radial":["circle","ellipse"]}],"mask-image-radial-size":[{"mask-radial":[{closest:["side","corner"],farthest:["side","corner"]}]}],"mask-image-radial-pos":[{"mask-radial-at":C()}],"mask-image-conic-pos":[{"mask-conic":[Z]}],"mask-image-conic-from-pos":[{"mask-conic-from":R()}],"mask-image-conic-to-pos":[{"mask-conic-to":R()}],"mask-image-conic-from-color":[{"mask-conic-from":B()}],"mask-image-conic-to-color":[{"mask-conic-to":B()}],"mask-mode":[{mask:["alpha","luminance","match"]}],"mask-origin":[{"mask-origin":["border","padding","content","fill","stroke","view"]}],"mask-position":[{mask:Te()}],"mask-repeat":[{mask:ye()}],"mask-size":[{mask:xe()}],"mask-type":[{"mask-type":["alpha","luminance"]}],"mask-image":[{mask:["none",V,q]}],filter:[{filter:["","none",V,q]}],blur:[{blur:Ne()}],brightness:[{brightness:[Z,V,q]}],contrast:[{contrast:[Z,V,q]}],"drop-shadow":[{"drop-shadow":["","none",x,Rt,Yt]}],"drop-shadow-color":[{"drop-shadow":B()}],grayscale:[{grayscale:["",Z,V,q]}],"hue-rotate":[{"hue-rotate":[Z,V,q]}],invert:[{invert:["",Z,V,q]}],saturate:[{saturate:[Z,V,q]}],sepia:[{sepia:["",Z,V,q]}],"backdrop-filter":[{"backdrop-filter":["","none",V,q]}],"backdrop-blur":[{"backdrop-blur":Ne()}],"backdrop-brightness":[{"backdrop-brightness":[Z,V,q]}],"backdrop-contrast":[{"backdrop-contrast":[Z,V,q]}],"backdrop-grayscale":[{"backdrop-grayscale":["",Z,V,q]}],"backdrop-hue-rotate":[{"backdrop-hue-rotate":[Z,V,q]}],"backdrop-invert":[{"backdrop-invert":["",Z,V,q]}],"backdrop-opacity":[{"backdrop-opacity":[Z,V,q]}],"backdrop-saturate":[{"backdrop-saturate":[Z,V,q]}],"backdrop-sepia":[{"backdrop-sepia":["",Z,V,q]}],"border-collapse":[{border:["collapse","separate"]}],"border-spacing":[{"border-spacing":y()}],"border-spacing-x":[{"border-spacing-x":y()}],"border-spacing-y":[{"border-spacing-y":y()}],"table-layout":[{table:["auto","fixed"]}],caption:[{caption:["top","bottom"]}],transition:[{transition:["","all","colors","opacity","shadow","transform","none",V,q]}],"transition-behavior":[{transition:["normal","discrete"]}],duration:[{duration:[Z,"initial",V,q]}],ease:[{ease:["linear","initial",$,V,q]}],delay:[{delay:[Z,V,q]}],animate:[{animate:["none",w,V,q]}],backface:[{backface:["hidden","visible"]}],perspective:[{perspective:[b,V,q]}],"perspective-origin":[{"perspective-origin":T()}],rotate:[{rotate:Be()}],"rotate-x":[{"rotate-x":Be()}],"rotate-y":[{"rotate-y":Be()}],"rotate-z":[{"rotate-z":Be()}],scale:[{scale:ze()}],"scale-x":[{"scale-x":ze()}],"scale-y":[{"scale-y":ze()}],"scale-z":[{"scale-z":ze()}],"scale-3d":["scale-3d"],skew:[{skew:Ke()}],"skew-x":[{"skew-x":Ke()}],"skew-y":[{"skew-y":Ke()}],transform:[{transform:[V,q,"","none","gpu","cpu"]}],"transform-origin":[{origin:T()}],"transform-style":[{transform:["3d","flat"]}],translate:[{translate:De()}],"translate-x":[{"translate-x":De()}],"translate-y":[{"translate-y":De()}],"translate-z":[{"translate-z":De()}],"translate-none":["translate-none"],zoom:[{zoom:[Ve,V,q]}],accent:[{accent:B()}],appearance:[{appearance:["none","auto"]}],"caret-color":[{caret:B()}],"color-scheme":[{scheme:["normal","dark","light","light-dark","only-dark","only-light"]}],cursor:[{cursor:["auto","default","pointer","wait","text","move","help","not-allowed","none","context-menu","progress","cell","crosshair","vertical-text","alias","copy","no-drop","grab","grabbing","all-scroll","col-resize","row-resize","n-resize","e-resize","s-resize","w-resize","ne-resize","nw-resize","se-resize","sw-resize","ew-resize","ns-resize","nesw-resize","nwse-resize","zoom-in","zoom-out",V,q]}],"field-sizing":[{"field-sizing":["fixed","content"]}],"pointer-events":[{"pointer-events":["auto","none"]}],resize:[{resize:["none","","y","x"]}],"scroll-behavior":[{scroll:["auto","smooth"]}],"scrollbar-thumb-color":[{"scrollbar-thumb":B()}],"scrollbar-track-color":[{"scrollbar-track":B()}],"scrollbar-gutter":[{"scrollbar-gutter":["auto","stable","both"]}],"scrollbar-w":[{scrollbar:["auto","thin","none"]}],"scroll-m":[{"scroll-m":y()}],"scroll-mx":[{"scroll-mx":y()}],"scroll-my":[{"scroll-my":y()}],"scroll-ms":[{"scroll-ms":y()}],"scroll-me":[{"scroll-me":y()}],"scroll-mbs":[{"scroll-mbs":y()}],"scroll-mbe":[{"scroll-mbe":y()}],"scroll-mt":[{"scroll-mt":y()}],"scroll-mr":[{"scroll-mr":y()}],"scroll-mb":[{"scroll-mb":y()}],"scroll-ml":[{"scroll-ml":y()}],"scroll-p":[{"scroll-p":y()}],"scroll-px":[{"scroll-px":y()}],"scroll-py":[{"scroll-py":y()}],"scroll-ps":[{"scroll-ps":y()}],"scroll-pe":[{"scroll-pe":y()}],"scroll-pbs":[{"scroll-pbs":y()}],"scroll-pbe":[{"scroll-pbe":y()}],"scroll-pt":[{"scroll-pt":y()}],"scroll-pr":[{"scroll-pr":y()}],"scroll-pb":[{"scroll-pb":y()}],"scroll-pl":[{"scroll-pl":y()}],"snap-align":[{snap:["start","end","center","align-none"]}],"snap-stop":[{snap:["normal","always"]}],"snap-type":[{snap:["none","x","y","both"]}],"snap-strictness":[{snap:["mandatory","proximity"]}],touch:[{touch:["auto","none","manipulation"]}],"touch-x":[{"touch-pan":["x","left","right"]}],"touch-y":[{"touch-pan":["y","up","down"]}],"touch-pz":["touch-pinch-zoom"],select:[{select:["none","text","all","auto"]}],"will-change":[{"will-change":["auto","scroll","contents","transform",V,q]}],fill:[{fill:["none",...B()]}],"stroke-w":[{stroke:[Z,$t,ot,Nr]}],stroke:[{stroke:["none",...B()]}],"forced-color-adjust":[{"forced-color-adjust":["auto","none"]}]},conflictingClassGroups:{"container-named":["container-type"],overflow:["overflow-x","overflow-y"],overscroll:["overscroll-x","overscroll-y"],inset:["inset-x","inset-y","inset-bs","inset-be","start","end","top","right","bottom","left"],"inset-x":["right","left"],"inset-y":["top","bottom"],flex:["basis","grow","shrink"],gap:["gap-x","gap-y"],p:["px","py","ps","pe","pbs","pbe","pt","pr","pb","pl"],px:["pr","pl"],py:["pt","pb"],m:["mx","my","ms","me","mbs","mbe","mt","mr","mb","ml"],mx:["mr","ml"],my:["mt","mb"],size:["w","h"],"font-size":["leading"],"fvn-normal":["fvn-ordinal","fvn-slashed-zero","fvn-figure","fvn-spacing","fvn-fraction"],"fvn-ordinal":["fvn-normal"],"fvn-slashed-zero":["fvn-normal"],"fvn-figure":["fvn-normal"],"fvn-spacing":["fvn-normal"],"fvn-fraction":["fvn-normal"],"line-clamp":["display","overflow"],rounded:["rounded-s","rounded-e","rounded-t","rounded-r","rounded-b","rounded-l","rounded-ss","rounded-se","rounded-ee","rounded-es","rounded-tl","rounded-tr","rounded-br","rounded-bl"],"rounded-s":["rounded-ss","rounded-es"],"rounded-e":["rounded-se","rounded-ee"],"rounded-t":["rounded-tl","rounded-tr"],"rounded-r":["rounded-tr","rounded-br"],"rounded-b":["rounded-br","rounded-bl"],"rounded-l":["rounded-tl","rounded-bl"],"border-spacing":["border-spacing-x","border-spacing-y"],"border-w":["border-w-x","border-w-y","border-w-s","border-w-e","border-w-bs","border-w-be","border-w-t","border-w-r","border-w-b","border-w-l"],"border-w-x":["border-w-r","border-w-l"],"border-w-y":["border-w-t","border-w-b"],"border-color":["border-color-x","border-color-y","border-color-s","border-color-e","border-color-bs","border-color-be","border-color-t","border-color-r","border-color-b","border-color-l"],"border-color-x":["border-color-r","border-color-l"],"border-color-y":["border-color-t","border-color-b"],translate:["translate-x","translate-y","translate-none"],"translate-none":["translate","translate-x","translate-y","translate-z"],"scroll-m":["scroll-mx","scroll-my","scroll-ms","scroll-me","scroll-mbs","scroll-mbe","scroll-mt","scroll-mr","scroll-mb","scroll-ml"],"scroll-mx":["scroll-mr","scroll-ml"],"scroll-my":["scroll-mt","scroll-mb"],"scroll-p":["scroll-px","scroll-py","scroll-ps","scroll-pe","scroll-pbs","scroll-pbe","scroll-pt","scroll-pr","scroll-pb","scroll-pl"],"scroll-px":["scroll-pr","scroll-pl"],"scroll-py":["scroll-pt","scroll-pb"],touch:["touch-x","touch-y","touch-pz"],"touch-x":["touch"],"touch-y":["touch"],"touch-pz":["touch"]},conflictingClassGroupModifiers:{"font-size":["leading"]},postfixLookupClassGroups:["container-type"],orderSensitiveModifiers:["*","**","after","backdrop","before","details-content","file","first-letter","first-line","marker","placeholder","selection"]}});function H(...e){return ca(lr(e))}const da=ur("relative grid w-full grid-cols-[0_1fr] items-start gap-y-0.5 rounded-lg border px-4 py-3 text-sm has-[>svg]:grid-cols-[calc(var(--spacing)*4)_1fr] has-[>svg]:gap-x-3 [&>svg]:size-4 [&>svg]:translate-y-0.5 [&>svg]:text-current",{variants:{variant:{default:"bg-card text-card-foreground",destructive:"bg-card text-destructive *:data-[slot=alert-description]:text-destructive/90 [&>svg]:text-current"}},defaultVariants:{variant:"default"}});function pt({className:e,variant:n,...r}){return t.jsx("div",{"data-slot":"alert",role:"alert",className:H(da({variant:n}),e),...r})}function Er({className:e,...n}){return t.jsx("div",{"data-slot":"alert-title",className:H("col-start-2 line-clamp-1 min-h-4 font-medium tracking-tight",e),...n})}function ht({className:e,...n}){return t.jsx("div",{"data-slot":"alert-description",className:H("col-start-2 grid justify-items-start gap-1 text-sm text-muted-foreground [&_p]:leading-relaxed",e),...n})}const ke=ve.forwardRef(({className:e,type:n,...r},s)=>t.jsx("input",{type:n,ref:s,"data-slot":"input",className:H("h-9 w-full min-w-0 rounded-md border border-input bg-transparent text-foreground px-3 py-0 text-sm shadow-xs transition-[color,box-shadow] outline-none selection:bg-primary selection:text-primary-foreground file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 dark:bg-input/30","focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50","aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40",e),...r}));ke.displayName="Input";function Xe(e,n){if(e==null)return null;switch(n){case"Int":{const r=typeof e=="number"?e:Number(e);return Number.isFinite(r)?Math.trunc(r):e}case"Float":{const r=typeof e=="number"?e:Number(e);return Number.isFinite(r)?r:e}case"Boolean":return typeof e=="boolean"?e:e==="true"||e===1?!0:e==="false"||e===0?!1:!!e;default:return String(e)}}function Xt(e){return e?.paramType?.replace("!","")??"String"}function it(e){return(e.sourceColumnNames?.length??0)>1}function ua(e,n,r,s="fk"){if(!e)return null;const o=n.sourceColumnNames??[],i=n.destinationColumnNames??[];if(o.length===0||o.length!==i.length)return null;const a=new Map((r?.columns??[]).map(m=>[m.name,m])),l=[],u={},d=[];for(let m=0;m<o.length;m++){const h=o[m],x=i[m];if(!(h in e))return null;const g=Xt(a.get(x)),b=`${s}_${x}`;u[b]=Xe(e[h],g),d.push(`$${b}: ${g}`),l.push(`{${x}: {_eq: $${b}}}`)}return{filterText:l.length===1?l[0]:`{and: [${l.join(", ")}]}`,variables:u,params:d}}const bn="::";function ma(e){return e==null?"":encodeURIComponent(String(e))}function Ut(e){if(e==="")return null;try{return decodeURIComponent(e)}catch{return e}}function xt(e){return e.map(ma).join(bn)}function Pr(e,n){const r=n<=1?[e]:e.split(bn);if(r.length!==n)throw new Error(`Route id '${e}' has ${r.length} part(s) but ${n} were expected.`);return r.map(s=>s===""?"":Ut(s)??"")}function _t(e,n,r){const s=n.primaryKeys??[];return s.length===0?`row-${r}`:xt(s.map(o=>e?.[o]))}function gt(e,n){const r=n.primaryKeys??[];if(r.length===0||e==null)return null;const s={};for(const o of r){if(!(o in e))return null;s[o]=e[o]}return s}function yn(e,n){const r=gt(e,n);if(!r)return null;const s=new Map((n.columns??[]).map(u=>[u.name,u])),o=[],i={},a=[];for(const u of n.primaryKeys??[]){const d=Xt(s.get(u)),p=`pk_${u}`;i[p]=Xe(r[u],d),a.push(`$${p}: ${d}`),o.push(`{${u}: {_eq: $${p}}}`)}return{filterText:o.length===1?o[0]:`{and: [${o.join(", ")}]}`,variables:i,params:a}}function vn(e,n){const r=n.primaryKeys??[];return r.length===0?"":xt(r.map(s=>e[s]))}function jn(e,n){const r=n.primaryKeys??[];if(r.length===0)return null;if(r.length===1)return{[r[0]]:Ut(e)};const s=e.split(bn);if(s.length!==r.length)return null;const o={};for(let i=0;i<r.length;i++)o[r[i]]=Ut(s[i]);return o}function fa(e,n,r){if(!e)return;const s=e.filter(o=>o.destinationTable===n);if(s.length!==0){if(s.length===1)return s[0];if(r)return s.find(o=>o.destinationColumnNames?.[0]===r)}}function pa(e){return e.fieldName??e.destinationTable}const ha=new Set(["binary","varbinary","image","blob","tinyblob","mediumblob","longblob","bytea"]),xa=new Set(["text","ntext","xml"]),ga=new Set(["json","jsonb"]);function bt(e){return ha.has(e.toLowerCase().replace(/\(.*\)/,""))}function Dr(e){return ga.has(e.toLowerCase().replace(/\(.*\)/,""))}function lt(e){return Dr(e.dbType)||e.paramType==="JSON"}function Ft(e){const n=e.toLowerCase(),r=n.replace(/\(.*\)/,"");return!!(xa.has(r)||n.includes("(max)"))}function Nn(e,n){if(!e)return"text";if(n&&bt(n))return"binary";if(n&&Dr(n))return"json";const r=e.trimStart();if(r.startsWith("{")&&r.endsWith("}")||r.startsWith("[")&&r.endsWith("]"))try{return JSON.parse(r),"json"}catch{}return r.startsWith("<?xml")||r.startsWith("<")&&r.includes("</")&&r.endsWith(">")?"xml":/^[aOsidb]:\d+[:{;]/.test(r)?"php-serialized":e.length>200||e.includes(`
78
+ `)?"longtext":"text"}const Mr=80;function ba(e){return e.length<=Mr?e:e.slice(0,Mr)+"..."}function ya(e){const n=Math.ceil(e.length*3/4);return n<1024?`${n} bytes`:n<1024*1024?`${(n/1024).toFixed(1)} KB`:`${(n/(1024*1024)).toFixed(1)} MB`}const wn={String:["_eq","_neq","_contains","_starts_with","_ends_with","_null"],Int:["_eq","_neq","_gt","_gte","_lt","_lte","_between","_null"],Float:["_eq","_neq","_gt","_gte","_lt","_lte","_between","_null"],BigInt:["_eq","_neq","_gt","_gte","_lt","_lte","_between","_null"],Decimal:["_eq","_neq","_gt","_gte","_lt","_lte","_between","_null"],Boolean:["_eq","_null"],DateTime:["_eq","_neq","_gt","_gte","_lt","_lte","_between","_null"]},va=/^[_A-Za-z][_0-9A-Za-z]*$/,ja=/^[_A-Za-z][_0-9A-Za-z]*!?$/,Na=new Set(Object.values(wn).flat());function Ie(e){return typeof e=="string"&&va.test(e)}function Fe(e,n){if(!Ie(e))throw new Error(`Invalid GraphQL ${n}: ${String(e)}`)}function wa(e){return typeof e=="string"&&ja.test(e)}function Ir(e,n){return typeof e=="string"&&Lr(n).includes(e)}function Lr(e){const n=e.replace("!","");return wn[n]??wn.String}function Or(e){try{if(!e)return{variables:{},param:"",filterText:""};const[n,r,s,o]=JSON.parse(e);return!Ie(n)||!wa(o)||!Ir(r,o)?{variables:{},param:"",filterText:""}:{variables:{filter:s},param:`, $filter: ${o}`,filterText:`{${n}: {${r}: $filter} }`}}catch{return{variables:{},param:"",filterText:""}}}function Ar(e){if(!e)return"";const n=new Date(e);return n.toString()==="Invalid Date"||n.getTime()===0||n.getUTCFullYear()<=1?"":n.toLocaleString()}function Ca(e,n,r=0){return _t(e,n,r)}function qr(e){switch(e.replace("!","")){case"Int":return"Int";case"Float":return"Float";case"Boolean":return"Boolean";case"BigInt":return"BigInt";case"Decimal":return"Decimal";case"DateTime":return"String";default:return"String"}}function Vr(e,n){const r={},s=[],o=[];for(let i=0;i<e.length;i++){const a=e[i],l=a.value;if(l.value===void 0||l.value===null||l.value==="")continue;const u=n.columns.find(m=>m.name===a.id);if(!u||!Ie(a.id)||!Ir(l.operator,u.paramType))continue;const d=`cf_${a.id}_${i}`,p=qr(u.paramType);if(l.operator==="_null"){o.push(`{${a.id}: {_null: ${l.value?"true":"false"}}}`);continue}if(l.operator==="_between"){const m=l.value;if(!Array.isArray(m)||m.length!==2)continue;const h=`${d}_lo`,x=`${d}_hi`;r[h]=m[0],r[x]=m[1],s.push(`$${h}: ${p}`,`$${x}: ${p}`),o.push(`{${a.id}: {_between: [$${h}, $${x}]}}`);continue}r[d]=l.value,s.push(`$${d}: ${p}`),o.push(`{${a.id}: {${l.operator}: $${d}}}`)}return{variables:r,params:s,filterTexts:o}}function Br(e){return e.length===0?"":JSON.stringify(e.map(n=>[n.id,n.value.operator,n.value.value]))}function Kr(e){try{if(!e)return[];const n=JSON.parse(e);return Array.isArray(n)?n.filter(ka).map(([r,s,o])=>({id:r,value:{operator:s,value:o}})):[]}catch{return[]}}function ka(e){if(!Array.isArray(e)||e.length!==3)return!1;const[n,r]=e;return Ie(n)&&typeof r=="string"&&Na.has(r)}function Gr(e){return Qe(e)[0]?.gqlType??"Int"}function Qe(e){const n=e.primaryKeys??[];if(n.length===0)return[];const r=new Map(e.columns.map(s=>[s.name,s]));return n.map(s=>({name:s,gqlType:r.get(s)?.paramType?.replace("!","")??"String"}))}function Cn(e,n){if(Qe(n).length<=1)return{id:Xe(Ut(e),Gr(n))};const s=jn(e,n);return s?yn(s,n)?.variables??{}:{}}function Ta(e,n,r){Fe(e.name,"single-row table name");for(const o of r)Fe(o,"single-row selection field");const s=n.params.length>0?`(${n.params.join(", ")})`:"";return`query GetSingleRow_${e.name}${s} { value: ${e.name}(filter: ${n.filterText}) { data { ${r.join(" ")} } } }`}const Sa=11;function Jr(e,n){return n.map(r=>{const s=e.findTable(r.destinationTable),o=s?.labelColumn??"id",a=[...s?.primaryKeys?.length?s.primaryKeys:["id"]];return o&&!a.includes(o)&&a.push(o),`${r.fieldName??r.destinationTable}(limit: ${Sa}) { total data { ${a.join(" ")} } }`}).join(" ")}function $a(e,n,r,s,o,i,a){if(!e||!n?.data)return null;const l=n.findTable(e.graphQlName);if(!l)return null;const u=Gr(l),d=Qe(l),p=d[0]?.name??"id";let{param:m,filterText:h}=Or(r);const{params:x,filterTexts:g}=Vr(s,e);x.length>0&&(m+=x.map(C=>`, ${C}`).join(""));const b=[];h&&b.push(h),b.push(...g),b.length>1?h=`{and: [${b.join(", ")}]}`:b.length===1?h=b[0]:h="";const k=new Set,$=e.columns.filter(C=>C?.joinTable===void 0).filter(C=>C.isPrimaryKey||!(bt(C.dbType)||Ft(C.dbType))).map(C=>{const T=l.singleJoins.find(y=>y.sourceColumnNames?.[0]===C.name);if(!T)return C;const E=n.findTable(T.destinationTable)?.labelColumn??"id";return{...C,joinTable:T,joinLabelColumn:E}}).map(C=>{if(C?.joinTable){k.add(C.name);const T=n.findTable(C.joinTable.destinationTable),j=T?.primaryKeys?.length?T.primaryKeys:C.joinTable.destinationColumnNames,E=C.joinLabelColumn??"id",y=E&&!j.includes(E)?` label: ${E}`:"";return j.length===1?`${C.name} ${C.joinTable.destinationTable} { id: ${j[0]}${y} }`:`${C.name} ${C.joinTable.destinationTable} { ${j.join(" ")}${y} }`}return C.name}).join(" "),w=Jr(n,l.multiJoins),P=w?`${$} ${w}`:$;if(o&&(a||i)){const C=kn(e,n,i,a);if(C&&Wr(C.childJoin)){const T=C.childJoin.destinationColumnNames[0];m=`, $id: ${Qe(C.parentTable)[0]?.gqlType??"Int"}`;const E=`filter: { ${T}: { _eq: $id } }`,y=Jr(n,l.multiJoins.filter(L=>!_a(L,C.childJoin))),S=y?`${$} ${y}`:$;return`query Get${e.name}($sort: [${e.graphQlName}SortEnum!], $limit: Int, $offset: Int ${m}) { ${e.name}(sort: $sort limit: $limit offset: $offset ${E}) { total offset limit data {${S}}}}`}if(C){const T=`${C.childField}(limit: $limit offset: $offset sort: $sort) { total offset limit data {${P}} }`,j=Qe(C.parentTable);if(j.length<=1){const L=j[0]?.name??"id";m=`, $id: ${j[0]?.gqlType??"Int"}`;const M=`{ ${L}: { _eq: $id}}`;return`query Get${e.name}($sort: [${e.graphQlName}SortEnum!], $limit: Int, $offset: Int ${m}) { ${C.parentTable.name}(filter: ${M}) { data { ${T} } } }`}m=`, ${j.map(L=>`$pk_${L.name}: ${L.gqlType}`).join(", ")}`;const S=`{and: [${j.map(L=>`{${L.name}: {_eq: $pk_${L.name}}}`).join(", ")}]}`;return`query Get${e.name}($sort: [${e.graphQlName}SortEnum!], $limit: Int, $offset: Int ${m}) { ${C.parentTable.name}(filter: ${S}) { data { ${T} } } }`}return null}return o&&!i&&!a&&(d.length<=1?(m=`, $id: ${u}`,h=`{ ${p}: { _eq: $id}}`):(m=`, ${d.map(T=>`$pk_${T.name}: ${T.gqlType}`).join(", ")}`,h=`{and: [${d.map(T=>`{${T.name}: {_eq: $pk_${T.name}}}`).join(", ")}]}`)),h&&(h=`filter: ${h}`),`query Get${e.name}($sort: [${e.graphQlName}SortEnum!], $limit: Int, $offset: Int ${m}) { ${e.name}(sort: $sort limit: $limit offset: $offset ${h}) { total offset limit data {${P}}}}`}function Wr(e){return!it(e)&&e.isPolymorphic!==!0&&(e.destinationColumnNames?.length??0)===1}function _a(e,n){return(e.fieldName??e.destinationTable)===(n.fieldName??n.destinationTable)&&e.destinationTable===n.destinationTable&&(e.destinationColumnNames??[]).join("\0")===(n.destinationColumnNames??[]).join("\0")&&(e.sourceColumnNames??[]).join("\0")===(n.sourceColumnNames??[]).join("\0")}const Fa={data:[],total:0,offset:0,limit:0};function za(e,n,r){const i=e?.[n]?.data?.[0]?.[r];return!i||!Array.isArray(i.data)?Fa:i}function kn(e,n,r,s){const o=r??n.findTable(e.graphQlName)?.singleJoins.find(l=>l.destinationTable===s)?.destinationTable;if(!o)return null;const i=n.findTable(o);if(!i)return null;const a=fa(i.multiJoins,e.graphQlName,s);return a?{parentTable:i,childField:pa(a),childJoin:a}:null}function Ea(e){const n=e.filter(Ie);return n.length===0?null:`query GetTableRowCounts { ${n.map(s=>`${s}: ${s}(limit: 1) { total }`).join(" ")} }`}function Pa(e=!0){const{data:n,loading:r,error:s}=Pe(),o=Ce(),i=c.useMemo(()=>n.map(m=>m.name),[n]),a=c.useMemo(()=>Ea(i),[i]),{data:l,isLoading:u,error:d}=me.useQuery({queryKey:["tableRowCounts",i],queryFn:()=>o.query(a),enabled:e&&!!a&&i.length>0,staleTime:300*1e3});return{stats:c.useMemo(()=>{const m={};for(const h of n){const g=l?.[h.name]?.total??null;m[h.name]={columnCount:h.columns.length,rowCount:g,fkCount:h.singleJoins.length,isLoading:u,error:d?d.message:null}}return m},[n,l,u,d]),isLoading:r||u,error:s}}function Da(e){if(e===null)return"—";if(e===0)return"0";if(e<1e3)return e.toString();if(e<1e6){const r=e/1e3;return r%1===0?`${r.toFixed(0)}k`:`${r.toFixed(1)}k`}const n=e/1e6;return n%1===0?`${n.toFixed(0)}M`:`${n.toFixed(1)}M`}const Ma={showStats:!1},Hr=c.createContext(Ma);function Ia({config:e,children:n}){return t.jsx(Hr.Provider,{value:e,children:n})}function La(){return c.useContext(Hr)}const Zt=50;function Oa(e,n){return e===null||n<=0?0:Math.max(2,Math.min(100,Math.round(e/n*100)))}function Aa({percent:e,label:n}){return t.jsx("span",{className:"flex-1 min-w-[1.5em] h-[0.5em] rounded-full bg-muted/70 overflow-hidden",role:"img","aria-label":n,title:n,children:t.jsx("span",{className:"block h-full rounded-full bg-emerald-500/70 dark:bg-emerald-400/70",style:{width:`${e}%`}})})}function Tn({count:e}){return e<=0?null:t.jsxs("span",{className:"shrink-0 rounded px-1 py-px text-[0.85em] tabular-nums bg-blue-100 text-blue-700 dark:bg-blue-900/60 dark:text-blue-300",children:[e," FK"]})}function qa(e){try{return decodeURIComponent(e)}catch{return e}}function Va({stats:e,maxRowCount:n}){const r=Oa(e.rowCount,n),s="flex items-center gap-1.5 text-xs leading-none min-w-0";return e.isLoading?t.jsxs("div",{className:`${s} text-muted-foreground`,children:[t.jsxs("span",{className:"tabular-nums shrink-0",children:[e.columnCount,"c"]}),t.jsx("span",{className:"flex-1 min-w-[1.5em] h-[0.5em] rounded-full bg-muted/70 overflow-hidden",children:t.jsx("span",{className:"block h-full w-1/3 rounded-full bg-muted-foreground/30 animate-pulse"})}),t.jsx(N.Loader2,{className:"size-[1em] shrink-0 animate-spin"}),t.jsx(Tn,{count:e.fkCount})]}):e.error?t.jsxs("div",{className:s,children:[t.jsxs("span",{className:"tabular-nums shrink-0 text-muted-foreground",children:[e.columnCount,"c"]}),t.jsx("span",{className:"flex-1 text-destructive truncate",title:e.error,children:"err"}),t.jsx(Tn,{count:e.fkCount})]}):t.jsxs("div",{className:s,children:[t.jsxs("span",{className:"tabular-nums shrink-0 text-muted-foreground/70",children:[e.columnCount,"c"]}),t.jsx(Aa,{percent:r,label:`${e.rowCount?.toLocaleString()??"unknown"} rows`}),t.jsx("span",{className:"tabular-nums shrink-0 text-right text-muted-foreground",children:Da(e.rowCount)}),t.jsx(Tn,{count:e.fkCount})]})}function Ba({table:e,stats:n,maxRowCount:r,showStats:s,active:o}){return t.jsx(St,{to:`/${e.name}`,"aria-current":o?"page":void 0,className:`plain-link block no-underline py-1.5 px-2 text-sm font-medium border-l-2 ${o?"bg-accent text-accent-foreground border-primary":"text-foreground border-transparent hover:bg-muted/50 hover:text-primary"}`,children:t.jsxs("div",{className:"flex flex-col gap-0.5 min-w-0",children:[t.jsx("span",{className:"truncate",title:e.label,children:e.label}),s&&t.jsx(Va,{stats:n,maxRowCount:r})]})})}function Sn(e){const n=e.dbName.lastIndexOf(".");return n>0?e.dbName.slice(0,n):null}function Qr({schema:e,count:n,collapsed:r,context:s,onToggle:o}){const i=r?N.ChevronRight:N.ChevronDown,a=t.jsxs(t.Fragment,{children:[t.jsx(i,{className:"size-3.5 shrink-0 text-muted-foreground"}),t.jsx("span",{className:"truncate font-semibold",title:e,children:e}),t.jsx("span",{className:"ml-auto shrink-0 tabular-nums text-[0.85em] text-muted-foreground",children:n})]}),l="flex items-center gap-1.5 w-full px-2 py-1 text-xs uppercase tracking-wide text-muted-foreground bg-muted/40 border-y border-border sticky top-0 z-10";return s?t.jsx("div",{className:l,"aria-hidden":"true",children:a}):t.jsx("button",{type:"button",onClick:o,"aria-expanded":!r,className:`${l} hover:bg-muted/70 text-left`,children:a})}function Ka(){const{showStats:e}=La(),{loading:n,error:r,data:s}=Pe(),{stats:o,isLoading:i}=Pa(e),[a,l]=c.useState(""),[u,d]=c.useState(new Set),[p,m]=c.useState(0),h=Zn(),x=qa(h.split("/")[1]??""),g=c.useMemo(()=>{const v=Object.values(o).map(M=>M.rowCount).filter(M=>M!==null);return v.length>0?Math.max(...v):0},[o]),b=a.trim().length>0,k=c.useMemo(()=>{const v=a.trim().toLowerCase();return v?s.filter(M=>{const O=Sn(M);return M.label.toLowerCase().includes(v)||M.dbName.toLowerCase().includes(v)||(O?.toLowerCase().includes(v)??!1)}):s},[s,a]),{schemas:$,grouped:w,multiSchema:P}=c.useMemo(()=>{const v=new Map;for(const O of k){const z=Sn(O),I=v.get(z)??[];I.push(O),v.set(z,I)}const M=[...v.keys()].filter(O=>O!==null).sort((O,z)=>O.localeCompare(z));return{schemas:M,grouped:v,multiSchema:M.length>1}},[k]),C=c.useMemo(()=>{const v=[];if(P){const M=[...$,...w.has(null)?[null]:[]];for(const O of M){const z=w.get(O===void 0?null:O)??[],I=!b&&u.has(O);if(v.push({kind:"group",schema:O??"(no schema)",count:z.length,collapsed:I}),!I)for(const _ of z)v.push({kind:"table",schema:O,table:_})}}else for(const M of k)v.push({kind:"table",schema:Sn(M),table:M});return v},[P,$,w,k,u,b]);c.useEffect(()=>{m(0)},[a]);const T=Math.max(1,Math.ceil(C.length/Zt)),j=Math.min(p,T-1),E=j*Zt,y=C.slice(E,E+Zt),S=P&&y[0]?.kind==="table"&&y[0].schema?y[0].schema:null,L=v=>d(M=>{const O=new Set(M);return O.has(v)?O.delete(v):O.add(v),O});return n?t.jsxs("div",{className:"flex items-center justify-center gap-2 p-4",children:[t.jsx(N.Loader2,{className:"size-4 animate-spin text-muted-foreground"}),t.jsx("span",{className:"text-sm text-muted-foreground",children:"Loading..."})]}):r?t.jsx(pt,{variant:"destructive",className:"m-2",children:t.jsxs(ht,{children:["Error: ",r.message]})}):s.length===0?t.jsxs("div",{className:"p-4 text-center text-sm text-muted-foreground",children:[t.jsx("p",{className:"font-medium",children:"No tables found"}),t.jsx("p",{className:"mt-1",children:"The database may be empty or the connection may have failed."})]}):t.jsxs("div",{className:"@container min-w-0 flex flex-col h-full",children:[t.jsxs("div",{className:"sticky top-0 z-20 bg-background p-2 border-b border-border",children:[t.jsxs("div",{className:"relative",children:[t.jsx(N.Search,{className:"absolute left-2 top-1/2 -translate-y-1/2 size-4 text-muted-foreground pointer-events-none"}),t.jsx(ke,{type:"search",value:a,onChange:v=>l(v.target.value),placeholder:"Search tables...","aria-label":"Search tables",className:"pl-8 pr-8 h-8 text-sm"}),b&&t.jsx("button",{type:"button",onClick:()=>l(""),"aria-label":"Clear search",className:"absolute right-1.5 top-1/2 -translate-y-1/2 p-0.5 rounded text-muted-foreground hover:text-foreground hover:bg-muted",children:t.jsx(N.X,{className:"size-4"})})]}),b&&t.jsxs("p",{className:"mt-1 px-0.5 text-xs text-muted-foreground",children:[k.length," match",k.length!==1?"es":""]})]}),t.jsx("div",{className:"flex-1 overflow-y-auto min-h-0",children:C.length===0?t.jsxs("p",{className:"p-4 text-center text-sm text-muted-foreground",children:["No tables match “",a,"”."]}):t.jsxs(t.Fragment,{children:[S&&t.jsx(Qr,{schema:S,count:w.get(S)?.length??0,collapsed:!1,context:!0}),y.map(v=>v.kind==="group"?t.jsx(Qr,{schema:v.schema,count:v.count,collapsed:v.collapsed,onToggle:()=>L(v.schema)},`g:${v.schema}`):t.jsx(Ba,{table:v.table,stats:o[v.table.name]??{columnCount:v.table.columns.length,rowCount:null,fkCount:v.table.singleJoins.length,isLoading:i,error:null},maxRowCount:g,showStats:e,active:v.table.name===x},`t:${v.table.name}`))]})}),T>1&&t.jsxs("div",{className:"sticky bottom-0 z-20 bg-background border-t border-border flex items-center justify-between gap-2 px-2 py-1.5",children:[t.jsx("button",{type:"button",onClick:()=>m(v=>Math.max(0,v-1)),disabled:j===0,"aria-label":"Previous page",className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-muted disabled:opacity-40 disabled:pointer-events-none",children:t.jsx(N.ChevronLeft,{className:"size-4"})}),t.jsxs("span",{className:"text-xs text-muted-foreground tabular-nums",children:[E+1,"–",Math.min(E+Zt,C.length)," of ",C.length]}),t.jsx("button",{type:"button",onClick:()=>m(v=>Math.min(T-1,v+1)),disabled:j>=T-1,"aria-label":"Next page",className:"p-1 rounded text-muted-foreground hover:text-foreground hover:bg-muted disabled:opacity-40 disabled:pointer-events-none",children:t.jsx(N.ChevronRight,{className:"size-4"})})]})]})}const Ga=ur("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background text-foreground hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"text-foreground hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10","icon-sm":"h-8 w-8 rounded-md"}},defaultVariants:{variant:"default",size:"default"}}),W=ve.forwardRef(({className:e,variant:n,size:r,asChild:s=!1,...o},i)=>{const a=s?Js.Slot:"button";return t.jsx(a,{className:H(Ga({variant:n,size:r,className:e})),ref:i,...o})});W.displayName="Button";function Yr({...e}){return t.jsx(Q.DropdownMenu.Root,{"data-slot":"dropdown-menu",...e})}function Rr({...e}){return t.jsx(Q.DropdownMenu.Trigger,{"data-slot":"dropdown-menu-trigger",...e})}function Xr({className:e,sideOffset:n=4,...r}){return t.jsx(Q.DropdownMenu.Portal,{children:t.jsx(Q.DropdownMenu.Content,{"data-slot":"dropdown-menu-content",sideOffset:n,className:H("z-50 max-h-(--radix-dropdown-menu-content-available-height) min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",e),...r})})}function zt({className:e,inset:n,variant:r="default",...s}){return t.jsx(Q.DropdownMenu.Item,{"data-slot":"dropdown-menu-item","data-inset":n,"data-variant":r,className:H("relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 data-[inset]:pl-8 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground data-[variant=destructive]:*:[svg]:text-destructive!",e),...s})}function Ja({className:e,children:n,checked:r,...s}){return t.jsxs(Q.DropdownMenu.CheckboxItem,{"data-slot":"dropdown-menu-checkbox-item",className:H("relative flex cursor-default items-center gap-2 rounded-sm py-1.5 pr-2 pl-8 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",e),checked:r,...s,children:[t.jsx("span",{className:"pointer-events-none absolute left-2 flex size-3.5 items-center justify-center",children:t.jsx(Q.DropdownMenu.ItemIndicator,{children:t.jsx(N.CheckIcon,{className:"size-4"})})}),n]})}function Wa({className:e,inset:n,...r}){return t.jsx(Q.DropdownMenu.Label,{"data-slot":"dropdown-menu-label","data-inset":n,className:H("px-2 py-1.5 text-sm font-medium data-[inset]:pl-8",e),...r})}function Ue({className:e,...n}){return t.jsx(Q.DropdownMenu.Separator,{"data-slot":"dropdown-menu-separator",className:H("-mx-1 my-1 h-px bg-border",e),...n})}function Et({...e}){return t.jsx(Q.DropdownMenu.Sub,{"data-slot":"dropdown-menu-sub",...e})}function Pt({className:e,inset:n,children:r,...s}){return t.jsxs(Q.DropdownMenu.SubTrigger,{"data-slot":"dropdown-menu-sub-trigger","data-inset":n,className:H("flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[inset]:pl-8 data-[state=open]:bg-accent data-[state=open]:text-accent-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground",e),...s,children:[r,t.jsx(N.ChevronRightIcon,{className:"ml-auto size-4"})]})}function Dt({className:e,...n}){return t.jsx(Q.DropdownMenu.SubContent,{"data-slot":"dropdown-menu-sub-content",className:H("z-50 min-w-[8rem] origin-(--radix-dropdown-menu-content-transform-origin) overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",e),...n})}const Mt=ve.forwardRef(({...e},n)=>t.jsx(Q.HoverCard.Root,{"data-slot":"hover-card",...e}));Mt.displayName="HoverCard";const It=ve.forwardRef(({...e},n)=>t.jsx(Q.HoverCard.Trigger,{"data-slot":"hover-card-trigger",...e}));It.displayName="HoverCardTrigger";const Lt=ve.forwardRef(({className:e,align:n="center",sideOffset:r=4,...s},o)=>t.jsx(Q.HoverCard.Portal,{children:t.jsx(Q.HoverCard.Content,{ref:o,"data-slot":"hover-card-content",align:n,sideOffset:r,className:H("z-50 w-64 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",e),...s})}));Lt.displayName="HoverCardContent";function Le({...e}){return t.jsx(Q.Select.Root,{"data-slot":"select",...e})}function Oe({...e}){return t.jsx(Q.Select.Value,{"data-slot":"select-value",...e})}function Ae({className:e,size:n="default",children:r,...s}){return t.jsxs(Q.Select.Trigger,{"data-slot":"select-trigger","data-size":n,className:H("flex w-fit items-center justify-between gap-2 rounded-md border border-input bg-transparent text-foreground px-3 py-2 text-sm whitespace-nowrap shadow-xs transition-[color,box-shadow] outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[placeholder]:text-muted-foreground data-[size=default]:h-9 data-[size=sm]:h-8 *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-2 dark:bg-input/30 dark:hover:bg-input/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground",e),...s,children:[r,t.jsx(Q.Select.Icon,{asChild:!0,children:t.jsx(N.ChevronDownIcon,{className:"size-4 opacity-50"})})]})}function qe({className:e,children:n,position:r="item-aligned",align:s="center",...o}){return t.jsx(Q.Select.Portal,{children:t.jsxs(Q.Select.Content,{"data-slot":"select-content",className:H("relative z-50 max-h-(--radix-select-content-available-height) min-w-[8rem] origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md border bg-popover text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",r==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",e),position:r,align:s,...o,children:[t.jsx(Ha,{}),t.jsx(Q.Select.Viewport,{className:H("p-1",r==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)] scroll-my-1"),children:n}),t.jsx(Qa,{})]})})}function ge({className:e,children:n,...r}){return t.jsxs(Q.Select.Item,{"data-slot":"select-item",className:H("relative flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",e),...r,children:[t.jsx("span",{"data-slot":"select-item-indicator",className:"absolute right-2 flex size-3.5 items-center justify-center",children:t.jsx(Q.Select.ItemIndicator,{children:t.jsx(N.CheckIcon,{className:"size-4"})})}),t.jsx(Q.Select.ItemText,{children:n})]})}function Ha({className:e,...n}){return t.jsx(Q.Select.ScrollUpButton,{"data-slot":"select-scroll-up-button",className:H("flex cursor-default items-center justify-center py-1",e),...n,children:t.jsx(N.ChevronUpIcon,{className:"size-4"})})}function Qa({className:e,...n}){return t.jsx(Q.Select.ScrollDownButton,{"data-slot":"select-scroll-down-button",className:H("flex cursor-default items-center justify-center py-1",e),...n,children:t.jsx(N.ChevronDownIcon,{className:"size-4"})})}function Ur(e){const n=c.useRef(null),r=c.useRef(null),s=c.useRef(e);s.current=e;const o=c.useMemo(()=>{const i=()=>{n.current&&(clearTimeout(n.current),n.current=null)},a=()=>{i();const l=r.current;r.current=null,l?.()};return{schedule:l=>{i(),r.current=l,n.current=setTimeout(a,s.current)},cancel:()=>{i(),r.current=null},flush:a}},[]);return c.useEffect(()=>()=>o.flush(),[o]),o}const Zr={_contains:"Contains",_starts_with:"Starts with",_ends_with:"Ends with",_eq:"Equals",_neq:"Not equals",_null:"Is null"},Ya=300;function Ra({column:e}){const r=(e.columnDef.meta?.filterOperators??[]).filter(b=>b in Zr),s=e.getFilterValue(),[o,i]=c.useState(s?.operator??"_contains"),[a,l]=c.useState(s?.operator==="_null"?"":String(s?.value??"")),{schedule:u,cancel:d}=Ur(Ya),p=o==="_null",m=(b,k)=>{if(b==="_null"){d(),e.setFilterValue({operator:"_null",value:!0});return}if(!k){d(),e.setFilterValue(void 0);return}u(()=>e.setFilterValue({operator:b,value:k}))},h=b=>{i(b),b==="_null"?(l(""),m("_null","")):a?m(b,a):(d(),e.setFilterValue(void 0))},x=b=>{l(b),m(o,b)},g=()=>{d(),i("_contains"),l(""),e.setFilterValue(void 0)};return r.length===0?null:t.jsxs("div",{className:"flex flex-col gap-2 p-2 min-w-[220px]",children:[t.jsxs(Le,{value:o,onValueChange:h,children:[t.jsx(Ae,{size:"sm",className:"w-full text-xs",children:t.jsx(Oe,{})}),t.jsx(qe,{children:r.map(b=>t.jsx(ge,{value:b,children:Zr[b]},b))})]}),!p&&t.jsx(ke,{placeholder:"Filter value...",value:a,onChange:b=>x(b.target.value),className:"h-8 text-xs",autoFocus:!0}),s!==void 0&&t.jsxs(W,{variant:"ghost",size:"sm",className:"h-7 text-xs justify-start",onClick:g,children:[t.jsx(N.X,{className:"size-3"}),"Clear filter"]})]})}const es={_eq:"Equals",_neq:"Not equals",_gt:"Greater than",_gte:"Greater or equal",_lt:"Less than",_lte:"Less or equal",_between:"Between",_null:"Is null"},Xa=300;function Ua(e){return(e.columnDef.meta?.paramType??"").replace("!","")==="Int"}function $n(e,n){const r=e.trim();if(r===""||r==="-"||r==="+"||!(n?/^[+-]?\d+$/.test(r):/^[+-]?(?:(?:\d+\.?\d*)|(?:\.\d+))(?:[eE][+-]?\d+)?$/.test(r)))return null;const o=Number(r);return Number.isFinite(o)?o:null}function Za({column:e}){const r=(e.columnDef.meta?.filterOperators??[]).filter(S=>S in es),s=Ua(e),o=e.getFilterValue(),i=o?.operator??"_eq",[a,l]=c.useState(i),[u,d]=c.useState(()=>!o||o.operator==="_null"||o.operator==="_between"?"":String(o.value??"")),[p,m]=c.useState(()=>o?.operator==="_between"&&Array.isArray(o.value)?String(o.value[0]??""):""),[h,x]=c.useState(()=>o?.operator==="_between"&&Array.isArray(o.value)?String(o.value[1]??""):""),{schedule:g,cancel:b}=Ur(Xa),k=(S,L)=>{if(S==="_null"){b(),e.setFilterValue({operator:"_null",value:!0});return}const v=$n(L,s);if(v===null){b(),e.setFilterValue(void 0);return}g(()=>e.setFilterValue({operator:S,value:v}))},$=(S,L)=>{const v=$n(S,s),M=$n(L,s);if(v===null||M===null){b(),e.setFilterValue(void 0);return}g(()=>e.setFilterValue({operator:"_between",value:[v,M]}))},w=S=>{l(S),S==="_null"?(d(""),m(""),x(""),k("_null","")):S==="_between"?(d(""),p&&h?$(p,h):(b(),e.setFilterValue(void 0))):(m(""),x(""),u?k(S,u):(b(),e.setFilterValue(void 0)))},P=S=>{d(S),k(a,S)},C=S=>{m(S),$(S,h)},T=S=>{x(S),$(p,S)},j=()=>{b(),l("_eq"),d(""),m(""),x(""),e.setFilterValue(void 0)};if(r.length===0)return null;const E=a==="_between",y=a==="_null";return t.jsxs("div",{className:"flex flex-col gap-2 p-2 min-w-[220px]",children:[t.jsxs(Le,{value:a,onValueChange:w,children:[t.jsx(Ae,{size:"sm",className:"w-full text-xs",children:t.jsx(Oe,{})}),t.jsx(qe,{children:r.map(S=>t.jsx(ge,{value:S,children:es[S]},S))})]}),!y&&!E&&t.jsx(ke,{type:"number",placeholder:"Filter value...",value:u,onChange:S=>P(S.target.value),className:"h-8 text-xs",autoFocus:!0}),E&&t.jsxs("div",{className:"flex gap-2",children:[t.jsx(ke,{type:"number",placeholder:"Min",value:p,onChange:S=>C(S.target.value),className:"h-8 text-xs",autoFocus:!0}),t.jsx(ke,{type:"number",placeholder:"Max",value:h,onChange:S=>T(S.target.value),className:"h-8 text-xs"})]}),o!==void 0&&t.jsxs(W,{variant:"ghost",size:"sm",className:"h-7 text-xs justify-start",onClick:j,children:[t.jsx(N.X,{className:"size-3"}),"Clear filter"]})]})}const ts={_eq:"On",_neq:"Not on",_gt:"After",_gte:"On or after",_lt:"Before",_lte:"On or before",_between:"Between",_null:"Is null"};function ei({column:e}){const r=(e.columnDef.meta?.filterOperators??[]).filter(j=>j in ts),s=e.getFilterValue(),o=s?.operator??"_eq",[i,a]=c.useState(o),[l,u]=c.useState(()=>!s||s.operator==="_null"||s.operator==="_between"?"":String(s.value??"")),[d,p]=c.useState(()=>s?.operator==="_between"&&Array.isArray(s.value)?String(s.value[0]??""):""),[m,h]=c.useState(()=>s?.operator==="_between"&&Array.isArray(s.value)?String(s.value[1]??""):""),x=(j,E)=>{if(j==="_null"){e.setFilterValue({operator:"_null",value:!0});return}if(!E){e.setFilterValue(void 0);return}e.setFilterValue({operator:j,value:E})},g=(j,E)=>{if(!j||!E){e.setFilterValue(void 0);return}e.setFilterValue({operator:"_between",value:[j,E]})},b=j=>{a(j),j==="_null"?(u(""),p(""),h(""),e.setFilterValue({operator:"_null",value:!0})):j==="_between"?(u(""),d&&m?g(d,m):e.setFilterValue(void 0)):(p(""),h(""),l?x(j,l):e.setFilterValue(void 0))},k=j=>{u(j),x(i,j)},$=j=>{p(j),g(j,m)},w=j=>{h(j),g(d,j)},P=()=>{a("_eq"),u(""),p(""),h(""),e.setFilterValue(void 0)};if(r.length===0)return null;const C=i==="_between",T=i==="_null";return t.jsxs("div",{className:"flex flex-col gap-2 p-2 min-w-[220px]",children:[t.jsxs(Le,{value:i,onValueChange:b,children:[t.jsx(Ae,{size:"sm",className:"w-full text-xs",children:t.jsx(Oe,{})}),t.jsx(qe,{children:r.map(j=>t.jsx(ge,{value:j,children:ts[j]},j))})]}),!T&&!C&&t.jsx(ke,{type:"date",value:l,onChange:j=>k(j.target.value),className:"h-8 text-xs"}),C&&t.jsxs("div",{className:"flex gap-2",children:[t.jsx(ke,{type:"date",value:d,onChange:j=>$(j.target.value),className:"h-8 text-xs"}),t.jsx(ke,{type:"date",value:m,onChange:j=>w(j.target.value),className:"h-8 text-xs"})]}),s!==void 0&&t.jsxs(W,{variant:"ghost",size:"sm",className:"h-7 text-xs justify-start",onClick:P,children:[t.jsx(N.X,{className:"size-3"}),"Clear filter"]})]})}const ti={all:"All",true:"True",false:"False",_null:"Is null"};function ni(e){return e?e.operator==="_null"?"_null":e.operator==="_eq"&&e.value===!0?"true":e.operator==="_eq"&&e.value===!1?"false":"all":"all"}function ri({column:e}){const r=(e.columnDef.meta?.filterOperators??[]).includes("_null"),s=e.getFilterValue(),o=ni(s),i=r?["all","true","false","_null"]:["all","true","false"],a=u=>{switch(u){case"true":e.setFilterValue({operator:"_eq",value:!0});break;case"false":e.setFilterValue({operator:"_eq",value:!1});break;case"_null":e.setFilterValue({operator:"_null",value:!0});break;default:e.setFilterValue(void 0)}},l=()=>{e.setFilterValue(void 0)};return t.jsxs("div",{className:"flex flex-col gap-2 p-2 min-w-[220px]",children:[t.jsxs(Le,{value:o,onValueChange:a,children:[t.jsx(Ae,{size:"sm",className:"w-full text-xs",children:t.jsx(Oe,{})}),t.jsx(qe,{children:i.map(u=>t.jsx(ge,{value:u,children:ti[u]},u))})]}),s!==void 0&&t.jsxs(W,{variant:"ghost",size:"sm",className:"h-7 text-xs justify-start",onClick:l,children:[t.jsx(N.X,{className:"size-3"}),"Clear filter"]})]})}function si(e,n,r,s){return!Ie(e)||!Ie(n)||!Ie(r)||s&&(!s.some(o=>o.name===n)||!s.some(o=>o.name===r))?null:`query Lookup${e} { ${e}(sort: [${n}_asc], limit: 100) { data { id: ${r} label: ${n} } } }`}function oi({column:e,joinTable:n,joinLabelColumn:r,joinFkColumn:s}){const o=Ce(),a=Pe().findTable(n),l=si(n,r,s,a?.columns),u=Xt(a?.columns.find(b=>b.name===s)),{data:d}=me.useQuery({queryKey:["fkLookup",n,r,s],queryFn:()=>o.query(l),staleTime:300*1e3,enabled:!!a&&!!l}),p=d?.[n]?.data??[],m=e.getFilterValue(),h=m?.operator==="_eq"&&m.value!=null?String(m.value):"all",x=b=>{if(b==="all"){e.setFilterValue(void 0);return}e.setFilterValue({operator:"_eq",value:Xe(b,u)})},g=()=>{e.setFilterValue(void 0)};return t.jsxs("div",{className:"flex flex-col gap-2 p-2 min-w-[220px]",children:[t.jsxs(Le,{value:h,onValueChange:x,children:[t.jsx(Ae,{size:"sm",className:"w-full text-xs",children:t.jsx(Oe,{})}),t.jsxs(qe,{children:[t.jsx(ge,{value:"all",children:"All"}),p.map(b=>t.jsx(ge,{value:String(b.id),children:String(b.label)},String(b.id)))]})]}),m!==void 0&&t.jsxs(W,{variant:"ghost",size:"sm",className:"h-7 text-xs justify-start",onClick:g,children:[t.jsx(N.X,{className:"size-3"}),"Clear filter"]})]})}function en(e){return(e.columnDef.meta?.paramType??"").replace("!","")}function ai(e){return en(e)==="String"}function ii(e){const n=en(e);return n==="Int"||n==="Float"}function li(e){return en(e)==="DateTime"}function ci(e){return en(e)==="Boolean"}function di(e){const n=e.columnDef.meta;return n?.joinTable?{joinTable:n.joinTable,joinLabelColumn:n.joinLabelColumn??"id",joinFkColumn:n.joinFkColumn??"id",isSelfReference:n.isSelfReference===!0}:null}function ui(e){return e.columnDef.meta?.column}function ns(e){const n=e.paramType.replace("!","");if(e.dbType){const r=e.dbType.toUpperCase();return e.maxLength&&(r.includes("VARCHAR")||r.includes("CHAR"))?`${r}(${e.maxLength})`:(r.includes("DECIMAL")||r.includes("NUMERIC"),r)}return n}function mi(e){const n=e.paramType.replace("!","");return e.isPrimaryKey?t.jsx(N.Key,{className:"size-3.5"}):n==="Int"||n==="Float"?t.jsx(N.Hash,{className:"size-3.5"}):n==="DateTime"?t.jsx(N.Calendar,{className:"size-3.5"}):n==="Boolean"?t.jsx(N.ToggleLeft,{className:"size-3.5"}):t.jsx(N.Type,{className:"size-3.5"})}function fi({column:e,fkMeta:n}){const r=ns(e),s=e.isNullable,o=e.isPrimaryKey,i=e.isIdentity,a=e.defaultValue;return t.jsxs("div",{className:"space-y-2",children:[t.jsxs("div",{className:"flex items-center gap-2 border-b pb-2",children:[mi(e),t.jsx("span",{className:"font-semibold text-foreground",children:e.label})]}),t.jsxs("dl",{className:"grid grid-cols-[auto_1fr] gap-x-3 gap-y-1 text-xs",children:[t.jsx("dt",{className:"text-muted-foreground",children:"Type"}),t.jsx("dd",{className:"text-foreground font-medium",children:r}),t.jsx("dt",{className:"text-muted-foreground",children:"Nullable"}),t.jsx("dd",{className:"text-foreground",children:s?"Yes":"No"}),o&&t.jsxs(t.Fragment,{children:[t.jsx("dt",{className:"text-muted-foreground",children:"Primary Key"}),t.jsxs("dd",{className:"text-foreground text-primary flex items-center gap-1",children:[t.jsx(N.Key,{className:"size-3"}),"Yes"]})]}),i&&t.jsxs(t.Fragment,{children:[t.jsx("dt",{className:"text-muted-foreground",children:"Auto Increment"}),t.jsx("dd",{className:"text-foreground",children:"Yes"})]}),n&&t.jsxs(t.Fragment,{children:[t.jsx("dt",{className:"text-muted-foreground",children:"Foreign Key"}),t.jsxs("dd",{className:"text-foreground text-primary flex items-center gap-1",children:[t.jsx(N.Link2,{className:"size-3"}),n.joinTable,n.isSelfReference&&t.jsx("span",{className:"ml-1 px-1 rounded bg-primary/10 text-[10px] font-medium",children:"self-ref"})]})]}),a!=null&&t.jsxs(t.Fragment,{children:[t.jsx("dt",{className:"text-muted-foreground",children:"Default"}),t.jsx("dd",{className:"text-foreground font-mono text-xs truncate max-w-[150px]",children:String(a)})]}),e.maxLength!==void 0&&t.jsxs(t.Fragment,{children:[t.jsx("dt",{className:"text-muted-foreground",children:"Max Length"}),t.jsx("dd",{className:"text-foreground",children:e.maxLength})]}),e.min!==void 0&&t.jsxs(t.Fragment,{children:[t.jsx("dt",{className:"text-muted-foreground",children:"Min"}),t.jsx("dd",{className:"text-foreground",children:e.min})]}),e.max!==void 0&&t.jsxs(t.Fragment,{children:[t.jsx("dt",{className:"text-muted-foreground",children:"Max"}),t.jsx("dd",{className:"text-foreground",children:e.max})]})]})]})}function yt({column:e,table:n,title:r}){const s=n.options.meta?.onResetColumnWidths;if(!e.getCanSort())return t.jsx("span",{children:r});const o=e.getIsSorted(),i=e.getFilterValue()!==void 0,a=di(e),l=!a&&ai(e),u=!a&&ii(e),d=!a&&li(e),p=!a&&ci(e),m=ui(e),h=t.jsxs(W,{variant:"ghost",size:"sm",className:H("-ml-2 h-7 text-xs data-[state=open]:bg-accent",o&&"text-foreground"),children:[t.jsx("span",{children:r}),i&&t.jsx(N.Filter,{className:"size-3 text-primary"}),o==="desc"?t.jsx(N.ArrowDown,{className:"size-4"}):o==="asc"?t.jsx(N.ArrowUp,{className:"size-4"}):t.jsx(N.ArrowUpDown,{className:"size-4"})]});return t.jsxs(Mt,{openDelay:400,closeDelay:200,children:[t.jsxs(Yr,{children:[t.jsx(Rr,{asChild:!0,children:t.jsx(It,{asChild:!0,children:h})}),t.jsxs(Xr,{align:"start",children:[m&&t.jsxs(t.Fragment,{children:[t.jsxs(Wa,{className:"text-xs font-normal text-muted-foreground",children:[ns(m),m.isNullable?" · nullable":" · required",m.isPrimaryKey?" · PK":"",a?` · FK → ${a.joinTable}`:""]}),t.jsx(Ue,{})]}),t.jsxs(zt,{onClick:()=>e.toggleSorting(!1),children:[t.jsx(N.ArrowUp,{className:"size-3.5 text-muted-foreground"}),"Asc"]}),t.jsxs(zt,{onClick:()=>e.toggleSorting(!0),children:[t.jsx(N.ArrowDown,{className:"size-3.5 text-muted-foreground"}),"Desc"]}),o&&t.jsxs(zt,{onClick:()=>e.clearSorting(),children:[t.jsx(N.ArrowUpDown,{className:"size-3.5 text-muted-foreground"}),"Clear"]}),l&&t.jsxs(t.Fragment,{children:[t.jsx(Ue,{}),t.jsxs(Et,{children:[t.jsxs(Pt,{children:[t.jsx(N.Filter,{className:H("size-3.5",i?"text-primary":"text-muted-foreground")}),"Filter"]}),t.jsx(Dt,{children:t.jsx(Ra,{column:e})})]})]}),u&&t.jsxs(t.Fragment,{children:[t.jsx(Ue,{}),t.jsxs(Et,{children:[t.jsxs(Pt,{children:[t.jsx(N.Filter,{className:H("size-3.5",i?"text-primary":"text-muted-foreground")}),"Filter"]}),t.jsx(Dt,{children:t.jsx(Za,{column:e})})]})]}),d&&t.jsxs(t.Fragment,{children:[t.jsx(Ue,{}),t.jsxs(Et,{children:[t.jsxs(Pt,{children:[t.jsx(N.Filter,{className:H("size-3.5",i?"text-primary":"text-muted-foreground")}),"Filter"]}),t.jsx(Dt,{children:t.jsx(ei,{column:e})})]})]}),p&&t.jsxs(t.Fragment,{children:[t.jsx(Ue,{}),t.jsxs(Et,{children:[t.jsxs(Pt,{children:[t.jsx(N.Filter,{className:H("size-3.5",i?"text-primary":"text-muted-foreground")}),"Filter"]}),t.jsx(Dt,{children:t.jsx(ri,{column:e})})]})]}),a&&t.jsxs(t.Fragment,{children:[t.jsx(Ue,{}),t.jsxs(Et,{children:[t.jsxs(Pt,{children:[t.jsx(N.Filter,{className:H("size-3.5",i?"text-primary":"text-muted-foreground")}),"Filter"]}),t.jsx(Dt,{children:t.jsx(oi,{column:e,joinTable:a.joinTable,joinLabelColumn:a.joinLabelColumn,joinFkColumn:a.joinFkColumn})})]})]}),e.getCanHide()&&t.jsxs(t.Fragment,{children:[t.jsx(Ue,{}),t.jsxs(zt,{onClick:()=>e.toggleVisibility(!1),children:[t.jsx(N.EyeOff,{className:"size-3.5 text-muted-foreground"}),"Hide"]})]}),s&&t.jsxs(t.Fragment,{children:[t.jsx(Ue,{}),t.jsxs(zt,{onClick:s,children:[t.jsx(N.RotateCcw,{className:"size-3.5 text-muted-foreground"}),"Reset column widths"]})]})]})]}),m&&t.jsx(Lt,{align:"start",className:"w-64",children:t.jsx(fi,{column:m,fkMeta:a})})]})}function vt({kind:e}){return t.jsx("span",{className:"text-muted-foreground/60 italic select-none",children:e==="null"?"NULL":"empty"})}const pi="display-format",hi="display-format-preview",xi=new Set(["date","datetime","time","relative","number","percent","raw"]);function gi(e){return{param:(e.paramType??"").replace("!","").toLowerCase(),db:(e.dbType??"").toLowerCase()}}function bi({param:e,db:n}){return e==="date"||n==="date"}function yi({param:e,db:n}){return e==="datetime"||e==="datetimeoffset"||n.includes("datetime")||n==="timestamp"||n==="smalldatetime"}function rs(e,n){const s=(n?e.metadata?.[n]:void 0)??e.metadata?.[pi];if(typeof s=="string"&&xi.has(s.toLowerCase()))return s.toLowerCase();const o=gi(e);return yi(o)?"datetime":bi(o)?"date":null}function vi(e){if(e instanceof Date)return isNaN(e.getTime())?null:e;if(typeof e=="number"){const n=new Date(e);return isNaN(n.getTime())?null:n}if(typeof e=="string"){const n=new Date(e);return isNaN(n.getTime())?null:n}return null}const ji=new Intl.DateTimeFormat(void 0,{dateStyle:"medium"}),Ni=new Intl.DateTimeFormat(void 0,{dateStyle:"medium",timeStyle:"short"}),wi=new Intl.DateTimeFormat(void 0,{timeStyle:"short"}),Ci=new Intl.DateTimeFormat(void 0,{dateStyle:"full",timeStyle:"medium"}),ss=new Intl.RelativeTimeFormat(void 0,{numeric:"auto"}),ki=[["year",31536e3],["month",2592e3],["week",604800],["day",86400],["hour",3600],["minute",60],["second",1]];function Ti(e,n=new Date){const r=Math.round((e.getTime()-n.getTime())/1e3),s=Math.abs(r);for(const[o,i]of ki)if(s>=i||o==="second")return ss.format(Math.round(r/i),o);return ss.format(0,"second")}function tn(e,n,r){if(e==null)return t.jsx(vt,{kind:"null"});if(e==="")return t.jsx(vt,{kind:"empty"});const s=rs(n,r?.formatKey);if(s===null||s==="raw")return String(e);if(s==="date"||s==="datetime"||s==="time"||s==="relative"){const o=vi(e);if(!o)return String(e);const i=Ci.format(o);if(s==="relative")return t.jsx("span",{title:i,className:"cursor-help underline decoration-dotted decoration-muted-foreground/40 underline-offset-2",children:Ti(o)});const a=(s==="date"?ji:s==="time"?wi:Ni).format(o);return t.jsx("span",{title:i,children:a})}if(s==="number"||s==="percent"){const o=typeof e=="number"?e:Number(e);if(isNaN(o))return String(e);const i=s==="percent"?new Intl.NumberFormat(void 0,{style:"percent",maximumFractionDigits:2}).format(o):new Intl.NumberFormat(void 0).format(o);return t.jsx("span",{title:String(e),children:i})}return String(e)}const Si=5,$i=400,_i=200;function Fi(e){return e.filter(n=>!n.isPrimaryKey).slice(0,Si)}function zi(e,n,r,s){const o=n.map(i=>i.name).join(" ");return`query FkPreview($id: ${s}) { ${e}(filter: { ${r}: { _eq: $id } } limit: 1) { data { ${o} } } }`}function Ei(e,n,r,s){const o=n.map(i=>i.name).join(" ");return`query FkPreview(${r}) { ${e}(filter: ${s} limit: 1) { data { ${o} } } }`}function Pi(e,n,r,s,o,i,a){if(r.length===0)return null;if(s&&it(s)&&o){const p=ua(o,s,n);if(!p)return null;const m=p.params.join(", ");return{query:Ei(e,r,m,p.filterText),variables:p.variables,cacheKey:p.variables}}const l=n.columns.find(p=>p.name===a)?.paramType??"Int",u=qr(l),d={id:Xe(i,u)};return{query:zi(e,r,a,u),variables:d,cacheKey:`${a}:${i}`}}function Di({tableName:e,recordId:n,filterColumn:r,join:s,sourceRow:o,children:i}){const[a,l]=c.useState(!1),u=Pe(),d=Ce(),p=u.findTable(e),m=p?Fi(p.columns):[],h=p?Pi(e,p,m,s,o,n,r):null,{data:x,isLoading:g}=me.useQuery({queryKey:["fkPreview",e,h?.cacheKey],queryFn:()=>d.query(h.query,h.variables),enabled:a&&!!h,staleTime:300*1e3}),b=x?.[e]?.data?.[0];return t.jsxs(Mt,{openDelay:$i,closeDelay:_i,open:a,onOpenChange:l,children:[t.jsx(It,{asChild:!0,children:i}),t.jsx(Lt,{align:"start",className:"w-72",children:t.jsxs("div",{className:"space-y-2",children:[t.jsx("p",{className:"text-sm font-semibold text-foreground",children:p?.label??e}),g&&t.jsx("p",{className:"text-xs text-muted-foreground",children:"Loading..."}),b&&t.jsx("dl",{className:"grid grid-cols-[auto_1fr] gap-x-3 gap-y-1 text-xs",children:m.map(k=>t.jsxs("div",{className:"contents",children:[t.jsx("dt",{className:"text-muted-foreground truncate",children:k.label}),t.jsx("dd",{className:"text-foreground truncate",children:tn(b[k.name],k,{formatKey:hi})})]},k.name))}),!g&&!b&&a&&t.jsx("p",{className:"text-xs text-muted-foreground",children:"Record not found"})]})})]})}const Mi={json:N.Braces,xml:N.Code,"php-serialized":N.Database,binary:N.Binary,longtext:N.FileText,text:N.FileText},Ii={json:"JSON",xml:"XML","php-serialized":"PHP",binary:"Binary",longtext:"Text",text:"Text"};function Li(e,n){if(n==="json")try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}return e}function Oi({value:e,dbType:n,onExpand:r}){if(e==null)return t.jsx(vt,{kind:"null"});const s=typeof e=="object"?JSON.stringify(e):String(e);if(s==="")return t.jsx(vt,{kind:"empty"});const o=Nn(s,n);if(o==="text")return t.jsx("span",{children:s});if(o==="binary")return t.jsxs("span",{className:"inline-flex items-center gap-1.5 text-muted-foreground",children:[t.jsx(N.Binary,{className:"size-3.5"}),t.jsx("span",{className:"text-xs font-mono",children:ya(s)}),r&&t.jsx("button",{type:"button",className:"shrink-0 opacity-40 hover:opacity-100 transition-opacity",onClick:u=>{u.stopPropagation(),r()},"aria-label":"Expand content",children:t.jsx(N.Expand,{className:"size-3"})})]});const i=Mi[o],a=ba(s);return s.length>80||o==="json"||o==="xml"||o==="php-serialized"?t.jsxs(Mt,{openDelay:300,closeDelay:200,children:[t.jsx(It,{asChild:!0,children:t.jsxs("button",{type:"button",className:"inline-flex items-center gap-1.5 text-left hover:text-primary transition-colors max-w-full",children:[t.jsx(i,{className:"size-3 text-muted-foreground shrink-0"}),t.jsx("span",{className:"font-mono text-xs truncate",children:a}),r&&t.jsx("span",{role:"button",tabIndex:0,className:"shrink-0 opacity-40 hover:opacity-100 transition-opacity",onClick:u=>{u.stopPropagation(),u.preventDefault(),r()},onKeyDown:u=>{u.key==="Enter"&&(u.stopPropagation(),r())},"aria-label":"Expand content",children:t.jsx(N.Expand,{className:"size-3"})})]})}),t.jsxs(Lt,{side:"bottom",align:"start",className:"w-[420px] max-h-[320px] p-0",children:[t.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1.5 border-b border-border bg-muted/30",children:[t.jsx(i,{className:"size-3.5 text-muted-foreground"}),t.jsx("span",{className:"text-xs font-medium text-muted-foreground",children:Ii[o]}),t.jsxs("span",{className:"text-xs text-muted-foreground ml-auto",children:[s.length," chars"]})]}),t.jsx("pre",{className:"p-3 text-xs font-mono overflow-auto max-h-[280px] whitespace-pre-wrap break-all",children:Li(s,o)})]})]}):t.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[t.jsx(i,{className:"size-3 text-muted-foreground shrink-0"}),t.jsx("span",{className:"font-mono text-xs",children:s}),r&&t.jsx("button",{type:"button",className:"shrink-0 opacity-40 hover:opacity-100 transition-opacity",onClick:u=>{u.stopPropagation(),r()},"aria-label":"Expand content",children:t.jsx(N.Expand,{className:"size-3"})})]})}function os(e,n){return e?!n||(n.primaryKeys?.length??0)<=1?xt([e?.id]):_t(e,n,0):""}function Ai(e,n){const r=Math.max(0,n-1);return e<0?0:e>r?r:e}function as(e,n){return Br(e)===n?e:Kr(n)}function qi(e,n){const r=n.fieldName??n.destinationTable;return e[r]?.data??[]}function Vi(e,n){const r=n.fieldName??n.destinationTable,s=e[r];return s?.total??s?.data?.length??0}const Bi=(e,n,r,s)=>{if(!e||!n)return[];const o=e.columns.map(a=>{const l=e.singleJoins.find(m=>m.sourceColumnNames?.[0]===a.name),u=l?void 0:e.singleJoins.find(m=>(m.sourceColumnNames??[]).includes(a.name)),d=Lr(a.paramType);if(l){const m=l.destinationTable,h=n.findTable(l.destinationTable),x=h?.labelColumn??"id",g=it(l),b=l.destinationTable===e.name,k=b?`Parent ${a.label}`:a.label;return{id:a.name,accessorKey:a.name,header:({column:$,table:w})=>t.jsx(yt,{column:$,table:w,title:k}),enableSorting:!0,meta:{sortField:a.name,paramType:a.paramType,filterOperators:d,joinTable:l.destinationTable,joinLabelColumn:x,joinFkColumn:l.destinationColumnNames[0],column:a,isSelfReference:b,isCompositeFk:g},cell:({row:$})=>{const w=$.original[m];if(!w)return t.jsx(vt,{kind:"null"});const P=os(w,h);return t.jsxs("span",{className:"group/fk inline-flex items-center gap-0.5",children:[t.jsx(Di,{tableName:l.destinationTable,recordId:P,filterColumn:l.destinationColumnNames[0],join:l,sourceRow:$.original,children:t.jsx(St,{to:"/"+h?.name+"/"+P,className:"text-primary hover:text-primary/80 hover:underline",children:w?.label})}),s&&t.jsx(W,{variant:"ghost",size:"icon-sm",className:"opacity-0 group-hover/fk:opacity-100 size-5 shrink-0",onClick:C=>{C.stopPropagation(),s({tableName:l.destinationTable,filterId:P})},"aria-label":"Open in side column",title:"Open in side column",children:t.jsx(N.PanelRight,{className:"size-3"})})]})}}}if(u){const h=n.findTable(u.destinationTable)?.labelColumn??"id",x=u.destinationTable===e.name;return{id:a.name,accessorFn:g=>a.name?String(g?.[a.name]??""):"",cell:({row:g})=>tn(g.original[a.name],a),header:({column:g,table:b})=>t.jsx(yt,{column:g,table:b,title:a.label}),enableSorting:!0,meta:{sortField:a.name,paramType:a.paramType,dbType:a.dbType,filterOperators:d,joinTable:u.destinationTable,joinLabelColumn:h,joinFkColumn:u.destinationColumnNames[(u.sourceColumnNames??[]).indexOf(a.name)]??u.destinationColumnNames[0],column:a,isSelfReference:x,isCompositeFk:!0,isCompositeFkMember:!0}}}return a?.joinTable?{id:a.name,accessorKey:a.name,header:({column:m,table:h})=>t.jsx(yt,{column:m,table:h,title:a.label}),enableSorting:!0,meta:{sortField:a.name,paramType:a.paramType,filterOperators:d,column:a},cell:({row:m})=>{const h=m.original[a.name];return h?t.jsx(St,{to:"/"+a.name+"/"+os(h,void 0),className:"text-primary hover:text-primary/80 hover:underline",children:a.name}):null}}:a?.paramType==="DateTime"?{id:a.name,accessorFn:m=>Ar(m?.[a.name]),cell:({row:m})=>{const h=m.original[a.name];return h==null||h===""?t.jsx(vt,{kind:h===""?"empty":"null"}):Ar(h)},header:({column:m,table:h})=>t.jsx(yt,{column:m,table:h,title:a.label}),enableSorting:!0,meta:{sortField:a.name,paramType:a.paramType,dbType:a.dbType,filterOperators:d,column:a}}:Ft(a.dbType)||bt(a.dbType)||lt(a)?{id:a.name,accessorFn:m=>a.name?String(m?.[a.name]??""):"",header:({column:m,table:h})=>t.jsx(yt,{column:m,table:h,title:a.label}),enableSorting:!0,meta:{sortField:a.name,paramType:a.paramType,dbType:a.dbType,filterOperators:d,column:a},cell:({row:m})=>t.jsx(Oi,{value:m.original[a.name],dbType:a.dbType,onExpand:r?()=>r(m.index,a.name):void 0})}:{id:a.name,accessorFn:m=>a.name?String(m?.[a.name]??""):"",cell:({row:m})=>tn(m.original[a.name],a),header:({column:m,table:h})=>t.jsx(yt,{column:m,table:h,title:a.label}),enableSorting:!0,meta:{sortField:a.name,paramType:a.paramType,dbType:a.dbType,filterOperators:d,column:a}}}),i=e.multiJoins.map(a=>{const l=n.findTable(a.destinationTable),u=l?.labelColumn??"id",p=a.destinationTable===e.name?`Child ${l?.label??a.destinationTable}`:l?.label??a.destinationTable;return{id:`join_${a.fieldName??a.destinationTable}`,header:p,enableSorting:!1,enableHiding:!0,cell:({row:m})=>{const h=Ca(m.original,e,m.index),x=qi(m.original,a),g=Vi(m.original,a);if(g===0)return t.jsx("span",{className:"text-muted-foreground",children:"—"});const b=x.slice(0,10).map($=>String($[u]??"")).filter(Boolean),k=l?.label??a.destinationTable;return t.jsxs("span",{className:"group/fk inline-flex items-center gap-1",children:[t.jsxs(Mt,{openDelay:300,closeDelay:100,children:[t.jsx(It,{asChild:!0,children:t.jsxs(St,{to:"/"+l?.name+"/from/"+e.name+"/"+h,className:"inline-flex items-center gap-1 rounded-full border border-border bg-muted/40 px-2 py-0.5 text-xs font-medium text-primary hover:bg-muted hover:border-primary/40 transition-colors",children:[t.jsx(N.List,{className:"size-3"}),g]})}),t.jsxs(Lt,{align:"start",sideOffset:6,className:"w-auto max-w-xs p-3",children:[t.jsxs("div",{className:"flex items-center gap-2 border-b pb-2 mb-2",children:[t.jsx(N.List,{className:"size-3.5 text-primary"}),t.jsxs("span",{className:"text-xs font-semibold text-foreground",children:[g," ",k]})]}),t.jsxs("ul",{className:"space-y-0.5 text-xs text-foreground",children:[b.map(($,w)=>t.jsx("li",{className:"truncate",children:$},w)),g>10&&t.jsxs("li",{className:"text-muted-foreground italic",children:["… and ",g-10," more"]})]})]})]}),s&&t.jsx(W,{variant:"ghost",size:"icon-sm",className:"opacity-40 group-hover/fk:opacity-100 size-5 shrink-0 transition-opacity",onClick:$=>{$.stopPropagation(),s({tableName:a.destinationTable,filterTable:e.name,filterId:h,...it(a)?{}:{filterColumn:a.destinationColumnNames[0]}})},"aria-label":"Open in side column",title:"Open in side column",children:t.jsx(N.PanelRight,{className:"size-3"})})]})}}});return[...o,...i]};function Ki(e,n,r,s,o){if(!s&&!o)return Cn(e,n);const i=kn(n,r,s,o);return i?Cn(e,i.parentTable):Cn(e,n)}function Gi(e,n,r,s,o,i){const{search:a}=er(),l=Wt(),u=a.get("filter")??"",d=a.get("cf")??"",{variables:p}=Or(u),m=Pe(),h=Ce(),[x,g]=c.useState([]),[b,k]=c.useState(()=>Kr(d)),[$,w]=c.useState(0),[P,C]=c.useState(50),T=c.useRef(e);e&&e!==T.current&&(T.current=e,x.length>0&&g([]),$!==0&&w(0)),c.useEffect(()=>{k(J=>as(J,d))},[d]);const j=c.useMemo(()=>as(b,d),[b,d]),E=c.useMemo(()=>{if(!e)return"id";const J=Qe(e)[0]?.name;return J&&e.columns.some(R=>R.name===J)?J:e.columns.find(R=>!bt(R.dbType)&&!Ft(R.dbType)&&!lt(R))?.name??e.columns.at(0)?.name??"id"},[e]),y=c.useMemo(()=>{if(x.length>0&&e){const J=x[0];if(e.columns.some(R=>R.name===J.id))return[`${J.id}_${J.desc?"desc":"asc"}`]}return e?[`${E}_asc`]:[]},[x,e,E]),S=c.useMemo(()=>$a(e,m,u,j,n,r,s),[e,m,u,j,n,r,s]),L=c.useMemo(()=>e?Vr(j,e).variables:{},[j,e]),v=$*P,M=c.useMemo(()=>({sort:y,limit:P,offset:v,...n&&e?Ki(n,e,m,r,s):{},...p,...L}),[y,P,v,n,e,m,r,s,p,L]),{isLoading:O,error:z,data:I}=me.useQuery({queryKey:["tableData",e?.name,S,M],queryFn:({signal:J})=>h.query(S,M,{signal:J}),enabled:!!S&&!!e&&y.length>0,placeholderData:(J,ce)=>ce?.queryKey?.[1]===e?.name?J:void 0}),_=c.useMemo(()=>e?Bi(e,m,o,i):[],[e,m,o,i]),G=c.useMemo(()=>n&&(r||s)&&e?kn(e,m,r,s):null,[n,r,s,e,m]);let U,ie;if(G&&!Wr(G.childJoin)){const J=za(I,G.parentTable.name,G.childField);U=J.data,ie=J.total}else{const J=I?.[e?.name??""];U=J?.data??[],ie=J?.total??0}const B=Math.max(1,Math.ceil(ie/P));c.useEffect(()=>{const J=Ai($,B);J!==$&&w(J)},[$,B]);const Te=c.useCallback(J=>{const ce=new URLSearchParams(a),R=Br(J);R?ce.set("cf",R):ce.delete("cf");const Ne=ce.toString();l(Ne?`?${Ne}`:"?")},[a,l]),ye=c.useCallback(J=>{g(J),w(0)},[]),xe=c.useCallback(J=>{k(J),w(0),Te(J)},[Te]),le=c.useCallback(J=>{w(J)},[]),re=c.useCallback(J=>{C(J),w(0)},[]),ae=e?.primaryKeys??[];return{columns:_,sorting:x,columnFilters:b,primaryKeys:ae,pageIndex:$,pageSize:P,pageCount:B,rows:U,loading:O,error:z,onSortingChange:ye,onColumnFiltersChange:xe,onPageIndexChange:le,onPageSizeChange:re}}const Ji=new Set(["tableData","editRecord","tableRowCounts","m2mRows","fkPreview"]),Wi=new Set(["tableRef","tableRefValue","compositeTableRef","m2mTargets"]);function nn(e,n){return e.invalidateQueries({predicate:r=>{const[s,o]=r.queryKey;return typeof s!="string"?!1:Ji.has(s)?!0:Wi.has(s)?o===n:!1}})}const is=c.createContext({toast:()=>{}}),Hi=4e3;function Qi({children:e}){const[n,r]=c.useState([]),s=c.useRef(0),o=c.useRef(new Set),i=c.useCallback(u=>{r(d=>d.filter(p=>p.id!==u))},[]),a=c.useCallback((u,d="success")=>{const p=s.current++;r(h=>[...h,{id:p,message:u,variant:d}]);const m=setTimeout(()=>{i(p),o.current.delete(m)},Hi);o.current.add(m)},[i]);c.useEffect(()=>{const u=o.current;return()=>{u.forEach(clearTimeout)}},[]);const l=c.useMemo(()=>({toast:a}),[a]);return t.jsxs(is.Provider,{value:l,children:[e,t.jsx("div",{className:"fixed bottom-4 right-4 z-[100] flex flex-col gap-2 max-w-sm",role:"region","aria-label":"Notifications",children:n.map(u=>t.jsxs("div",{role:"status",className:H("flex items-start gap-2 rounded-md border px-3 py-2 text-sm shadow-md bg-popover",u.variant==="error"?"border-destructive/40 text-destructive":"border-border text-foreground"),children:[u.variant==="error"?t.jsx(N.AlertCircle,{className:"size-4 shrink-0 mt-0.5"}):t.jsx(N.CheckCircle2,{className:"size-4 shrink-0 mt-0.5 text-green-600"}),t.jsx("span",{className:"flex-1 break-words",children:u.message}),t.jsx("button",{type:"button",onClick:()=>i(u.id),"aria-label":"Dismiss notification",className:"shrink-0 opacity-60 hover:opacity-100",children:t.jsx(N.X,{className:"size-3.5"})})]},u.id))})]})}function rn(){return c.useContext(is)}function Yi(e){return typeof e=="object"&&e!==null}function ls(e,n){if(e==null)return null;if(!n)return e;const r=n.replace("!","");if(r==="Int"){const s=typeof e=="number"?e:Number(e);return Number.isFinite(s)?Math.trunc(s):e}if(r==="Float"){const s=typeof e=="number"?e:Number(e);return Number.isFinite(s)?s:e}return r==="Boolean"?typeof e=="boolean"?e:e==="true"||e===1:String(e)}function cs(e){Fe(e.name,"delete mutation table name");const n=Ce(),r=me.useQueryClient(),{toast:s}=rn(),o=c.useMemo(()=>{const g=new Map;for(const b of e.columns)g.set(b.name,b.paramType);return g},[e]),i=c.useMemo(()=>e.primaryKeys??[],[e]),a=g=>{if(i.length===0)throw new Error(`Cannot delete from '${e.name}': the table has no primary key.`);const b={};if(Yi(g)){for(const $ of i){const w=g[$];if(w==null)throw new Error(`Cannot delete row: missing value for primary-key column '${$}'.`);b[$]=ls(w,o.get($))}return b}if(i.length!==1)throw new Error(`Cannot delete from '${e.name}': composite primary key requires an object key, not a scalar.`);if(g==null)throw new Error(`Cannot delete row: missing value for primary-key column '${i[0]}'.`);const k=i[0];return b[k]=ls(g,o.get(k)),b},l=c.useMemo(()=>`mutation deleteSingle($detail: Delete_${e.name}){
79
79
  ${e.name}(delete: $detail)
80
- }`,[e]),l=f.useMemo(()=>`mutation batchDelete($actions: [batch_${e.name}!]!){
80
+ }`,[e]),u=c.useMemo(()=>`mutation batchDelete($actions: [batch_${e.name}!]!){
81
81
  ${e.name}_batch(actions: $actions)
82
- }`,[e]),c=le.useMutation({mutationFn:y=>n.query(a,{detail:y}),onSuccess:()=>r.invalidateQueries({queryKey:["tableData",e.name]})}),m=le.useMutation({mutationFn:y=>n.query(l,{actions:y}),onSuccess:()=>r.invalidateQueries({queryKey:["tableData",e.name]})}),p=y=>c.mutateAsync(i(y)),d=y=>{const g=y.map(b=>({delete:i(b)}));return m.mutateAsync(g)},h=c.error??m.error;return{deleteRow:p,deleteRows:d,isPending:c.isPending||m.isPending,error:h}}function tl(e,n,r){const s=ve(),o=f.useMemo(()=>e?.data?.find(m=>m.graphQlName===n),[e,n]),i=f.useMemo(()=>e.loading||e.error||!o?null:`query Get_${n}_Ref {
83
- values: ${n}(limit: -1) {
82
+ }`,[e]),d=me.useMutation({mutationFn:g=>n.query(l,{detail:g}),onSuccess:()=>{nn(r,e.name),s("Row deleted")}}),p=me.useMutation({mutationFn:g=>n.query(u,{actions:g}),onSuccess:(g,b)=>{nn(r,e.name);const k=b.length;s(`${k} ${k===1?"row":"rows"} deleted`)}}),m=g=>{let b;try{b=a(g)}catch(k){return Promise.reject(k)}return d.mutateAsync(b)},h=g=>{let b;try{b=g.map(k=>({delete:a(k)}))}catch(k){return Promise.reject(k)}return p.mutateAsync(b)},x=d.error??p.error;return{deleteRow:m,deleteRows:h,isPending:d.isPending||p.isPending,error:x}}const ds=["Int","Int!","Float","Float!"],Ri=["BigInt","BigInt!"],Xi=["Boolean","Boolean!"];function us(e,n,r){const s=n.replace("!","");if(typeof e=="number"){if(Number.isFinite(e)&&(s!=="Int"||Number.isInteger(e)))return e;throw new Error(`Invalid ${s} value for column '${r}'.`)}const o=String(e).trim();if(!(s==="Int"?/^[+-]?\d+$/.test(o):/^[+-]?(?:(?:\d+\.?\d*)|(?:\.\d+))(?:[eE][+-]?\d+)?$/.test(o)))throw new Error(`Invalid ${s} value for column '${r}'.`);const a=Number(o);if(!Number.isFinite(a))throw new Error(`Invalid ${s} value for column '${r}'.`);return a}function ms(e,n,r,s,o){const i={...e};for(const{column:a}of n){if(i[a.name]===null){i[a.name]=o?void 0:null;continue}if(ds.some(l=>l===a.paramType)){const l=i[a.name];i[a.name]=l==null?void 0:l===""?o?void 0:null:us(l,a.paramType,a.name)}if(Ri.some(l=>l===a.paramType)){const l=i[a.name];i[a.name]=l==null?void 0:l===""?o?void 0:null:String(l)}if(Xi.some(l=>l===a.paramType)){const l=i[a.name];a.isNullable&&l==null?i[a.name]=o?void 0:null:i[a.name]=!!l}if(lt(a)){const l=i[a.name];if(typeof l=="string"&&l.trim()!=="")try{i[a.name]=JSON.parse(l)}catch{}}}if(!o&&s)for(const a of r){const l=s[a.name];ds.some(u=>u===a.paramType)?i[a.name]=l==null?null:us(l,a.paramType,a.name):i[a.name]=l}return i}function sn(e,n,r,s){Fe(e.name,"table mutation table name");const o=Ce(),i=me.useQueryClient(),{toast:a}=rn(),l=s===void 0||s==="",u=c.useMemo(()=>`mutation updateSingle($detail: Update_${e.name}){
83
+ ${e.name}(update: $detail)
84
+ }`,[e]),d=c.useMemo(()=>`mutation insertSingle($detail: Insert_${e.name}){
85
+ ${e.name}(insert: $detail)
86
+ }`,[e]),p=me.useMutation({mutationFn:k=>o.query(u,{detail:k}),onSuccess:()=>{nn(i,e.name),a(`${e.label??e.name} saved`)}}),m=me.useMutation({mutationFn:k=>o.query(d,{detail:k}),onSuccess:()=>{nn(i,e.name),a(`${e.label??e.name} created`)}}),h=c.useMemo(()=>l||!s?null:jn(s,e),[l,s,e]),x=k=>{if(!h||r.length===0)return Promise.reject(new Error(`Cannot update ${e.label??e.name}: the record has no resolvable primary key.`));let $;try{$=ms(k,n,r,h,!1)}catch(w){return Promise.reject(w)}return p.mutateAsync($)},g=k=>{let $;try{$=ms(k,n,r,null,!0)}catch(w){return Promise.reject(w)}return m.mutateAsync($)},b=p.error??m.error;return{update:x,insert:g,isPending:p.isPending||m.isPending,error:b}}const Ui=1e3,Zi=50;function fs(e){const n=e.labelColumn||Qe(e)[0]?.name||e.columns[0]?.name;if(!n)throw new Error(`Table '${e.name}' has no usable label column for a reference dropdown.`);return n}function el(e,n,r){Fe(e.name,"reference table name"),Fe(n,"reference key column");const s=fs(e);if(Fe(s,"reference label column"),!e.columns.some(p=>p.name===n))throw new Error(`Reference table '${e.name}' has no key column '${n}'.`);const i=e.columns.find(p=>p.name===s)?.paramType?.replace("!","")==="String",a=!!r&&r.trim()!==""&&i,l=a?"$limit: Int, $search: String":"$limit: Int",u=a?`filter: {${s}: {_contains: $search}} `:"";return{query:`query Get_${e.name}_Ref(${l}) {
87
+ values: ${e.name}(${u}limit: $limit sort: [${s}_asc]) {
84
88
  data {
85
- key: ${r}
86
- label: ${o.labelColumn??"id"}
89
+ key: ${n}
90
+ label: ${s}
87
91
  }
88
92
  }
89
- }`,[r,o,e.loading,e.error,n]),{isLoading:a,error:l,data:c}=le.useQuery({queryKey:["tableRef",n,r],queryFn:()=>s.query(i),enabled:!!i});return{loading:a||e.loading,error:l||e.error,data:c?.values?.data??[]}}const nl=500;function rl(e,n,r){const s=ve(),o=f.useMemo(()=>e?.data?.find(d=>d.graphQlName===n),[e,n]),i=f.useMemo(()=>{if(!o)return"";const d=o.labelColumn??r[0],h=new Set(r);return h.add(d),Array.from(h).join(" ")},[o,r]),a=f.useMemo(()=>e.loading||e.error||!o||r.length===0?null:`query Get_${n}_CompositeRef { values: ${n}(limit: ${nl}) { data { ${i} } } }`,[o,n,i,e.loading,e.error,r.length]),{isLoading:l,error:c,data:m}=le.useQuery({queryKey:["compositeTableRef",n,r.join("|")],queryFn:()=>s.query(a),enabled:!!a}),p=f.useMemo(()=>{if(!o||!m)return[];const d=o.labelColumn??r[0],h={primaryKeys:r};return(m.values?.data??[]).map((y,g)=>{const b={};for(const T of r)b[T]=y[T];const N=Ct(y,h,g);return{route:N,values:b,label:String(y[d]??N)}})},[o,r,m]);return{loading:l||e.loading,error:c||e.error,data:p}}const ts=["Int","Int!","Float","Float!","BigInt","BigInt!"],sl=["Boolean","Boolean!"];function ns(e,n,r,s,o){const i={...e};for(const{column:a}of n){if(ts.some(l=>l===a.paramType)){const l=i[a.name];i[a.name]=l==null?void 0:l===""?null:+l}sl.some(l=>l===a.paramType)&&(i[a.name]=!!i[a.name])}if(!o&&s)for(const a of r){const l=s[a.name];ts.some(c=>c===a.paramType)?i[a.name]=l==null?null:Number(l):i[a.name]=l}return i}function yn(e,n,r,s){const o=ve(),i=le.useQueryClient(),a=s===void 0||s==="",l=f.useMemo(()=>`mutation updateSingle($detail: Update_${e.name}){
90
- ${e.name}(update: $detail)
91
- }`,[e]),c=f.useMemo(()=>`mutation insertSingle($detail: Insert_${e.name}){
92
- ${e.name}(insert: $detail)
93
- }`,[e]),m=le.useMutation({mutationFn:b=>o.query(l,{detail:b}),onSuccess:()=>i.invalidateQueries({queryKey:["tableData",e.name]})}),p=le.useMutation({mutationFn:b=>o.query(c,{detail:b}),onSuccess:()=>i.invalidateQueries({queryKey:["tableData",e.name]})}),d=f.useMemo(()=>a||!s?null:xn(s,e),[a,s,e]),h=b=>{const N=ns(b,n,r,d,!1);return m.mutateAsync(N)},y=b=>{const N=ns(b,n,r,null,!0);return p.mutateAsync(N)},g=m.error??p.error;return{update:h,insert:y,isPending:m.isPending||p.isPending,error:g}}const ol=new Set(["Int","Int!","Float","Float!","Decimal","Decimal!"]);function al(e){return ol.has(e.paramType)}function il(e){return e.startsWith("^")?e:`^(?:${e})$`}function ll(e){if(e!==e.trim()||/\s/.test(e))return!1;const n=e.lastIndexOf("@");if(n<=0||n===e.length-1)return!1;const r=e.slice(n+1);return r.includes(".")&&!r.startsWith(".")&&!r.endsWith(".")}function cl(e){try{const n=new URL(e);return n.protocol==="http:"||n.protocol==="https:"}catch{return!1}}function dl(e,n,r){const s=e.label;if(r&&(n==null||n===""))return`${s} is required`;if(!(n==null||n==="")){if(typeof n=="string"){if(e.pattern){let o;try{o=new RegExp(il(e.pattern))}catch{return`${s} has an invalid validation pattern`}if(!o.test(n))return e.patternMessage||`${s} format is invalid`}if(e.minLength&&n.length<e.minLength)return`${s} must be at least ${e.minLength} characters`;if(e.maxLength&&n.length>e.maxLength)return`${s} must be at most ${e.maxLength} characters`;if(e.inputType==="email"&&!ll(n))return"Invalid email address";if(e.inputType==="url"&&!cl(n))return"Invalid URL"}if(al(e)){const o=Number(n);if(!Number.isNaN(o)){if(e.min!==void 0&&e.min!==null&&o<e.min)return`${s} must be at least ${e.min}`;if(e.max!==void 0&&e.max!==null&&o>e.max)return`${s} must be at most ${e.max}`}}}}const kt=pe.forwardRef(({...e},n)=>t.jsx(G.Dialog.Root,{"data-slot":"dialog",...e}));kt.displayName="Dialog";const ul=pe.forwardRef(({...e},n)=>t.jsx(G.Dialog.Trigger,{"data-slot":"dialog-trigger",...e}));ul.displayName="DialogTrigger";const rs=pe.forwardRef(({...e},n)=>t.jsx(G.Dialog.Portal,{"data-slot":"dialog-portal",...e}));rs.displayName="DialogPortal";const ml=pe.forwardRef(({...e},n)=>t.jsx(G.Dialog.Close,{"data-slot":"dialog-close",...e}));ml.displayName="DialogClose";const ss=pe.forwardRef(({className:e,...n},r)=>t.jsx(G.Dialog.Overlay,{ref:r,"data-slot":"dialog-overlay",className:K("fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",e),...n}));ss.displayName="DialogOverlay";const Tt=pe.forwardRef(({className:e,children:n,showCloseButton:r=!0,...s},o)=>t.jsxs(rs,{"data-slot":"dialog-portal",children:[t.jsx(ss,{}),t.jsxs(G.Dialog.Content,{ref:o,"data-slot":"dialog-content",className:K("fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border bg-background p-6 shadow-lg duration-200 outline-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 sm:max-w-lg",e),...s,children:[n,r&&t.jsxs(G.Dialog.Close,{"data-slot":"dialog-close",className:"absolute top-4 right-4 rounded-xs opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",children:[t.jsx(v.XIcon,{}),t.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));Tt.displayName="DialogContent";const Kt=pe.forwardRef(({className:e,...n},r)=>t.jsx("div",{ref:r,"data-slot":"dialog-header",className:K("flex flex-col gap-2 text-center sm:text-left",e),...n}));Kt.displayName="DialogHeader";const os=pe.forwardRef(({className:e,showCloseButton:n=!1,children:r,...s},o)=>t.jsxs("div",{ref:o,"data-slot":"dialog-footer",className:K("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",e),...s,children:[r,n&&t.jsx(G.Dialog.Close,{asChild:!0,children:t.jsx(q,{variant:"outline",children:"Close"})})]}));os.displayName="DialogFooter";const St=pe.forwardRef(({className:e,...n},r)=>t.jsx(G.Dialog.Title,{ref:r,"data-slot":"dialog-title",className:K("text-lg leading-none font-semibold",e),...n}));St.displayName="DialogTitle";const Wt=pe.forwardRef(({className:e,...n},r)=>t.jsx(G.Dialog.Description,{ref:r,"data-slot":"dialog-description",className:K("text-sm text-muted-foreground",e),...n}));Wt.displayName="DialogDescription";function vn({className:e,...n}){return t.jsx(G.Checkbox.Root,{"data-slot":"checkbox",className:K("peer size-4 shrink-0 rounded-[4px] border border-input shadow-xs transition-shadow outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[state=checked]:border-primary data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:bg-input/30 dark:aria-invalid:ring-destructive/40 dark:data-[state=checked]:bg-primary",e),...n,children:t.jsx(G.Checkbox.Indicator,{"data-slot":"checkbox-indicator",className:"grid place-content-center text-current transition-none",children:t.jsx(v.CheckIcon,{className:"size-3.5"})})})}function nt({className:e,...n}){return t.jsx(G.Label.Root,{"data-slot":"label",className:K("flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",e),...n})}function fl({name:e,label:n,value:r,dbType:s,onChange:o,onBlur:i,required:a,invalid:l}){const c=jt(s),m=Bt(s),p=hn(r,s),[d,h]=f.useState(null),y=f.useRef(null),g=f.useCallback(()=>{const j=y.current;j&&(j.style.height="auto",j.style.height=Math.min(j.scrollHeight,400)+"px")},[]);if(f.useEffect(g,[r,g]),c)return t.jsx(pl,{name:e,label:n,value:r});if(!m&&p==="text")return null;const b=()=>{if(h(null),p==="json")try{o(JSON.stringify(JSON.parse(r),null,2))}catch{h("Invalid JSON")}else if(p==="xml")try{const j=r.replace(/>\s*</g,`>
93
+ }`,labelColumn:s,serverSearch:i}}function tl(e,n){Fe(e.name,"reference table name"),Fe(n,"reference key column");const r=fs(e);Fe(r,"reference label column");const s=e.columns.find(a=>a.name===n);if(!s)throw new Error(`Reference table '${e.name}' has no key column '${n}'.`);const o=s.paramType.replace("!","");return{query:`query Get_${e.name}_RefValue($key: ${o}) {
94
+ values: ${e.name}(filter: {${n}: {_eq: $key}} limit: 1) {
95
+ data {
96
+ key: ${n}
97
+ label: ${r}
98
+ }
99
+ }
100
+ }`,keyType:o}}function nl(e,n){return Xe(n,e)}function ps(e,n){return e?.data?.find(r=>r.graphQlName===n)}function rl(e,n,r,s="",o=!0){const i=Ce(),a=c.useMemo(()=>ps(e,n),[e,n]),l=s.trim(),u=c.useMemo(()=>e.loading||e.error||!a?null:el(a,r,l),[r,a,e.loading,e.error,l]),d=u?.serverSearch?l:"",{isLoading:p,error:m,data:h}=me.useQuery({queryKey:["tableRef",n,r,d],queryFn:({signal:x})=>i.query(u.query,d?{limit:Zi,search:d}:{limit:Ui},{signal:x}),enabled:!!u&&o});return{loading:p||e.loading,error:m||e.error,data:h?.values?.data??[],serverSearch:u?.serverSearch??!1}}function sl(e,n,r,s){const o=Ce(),i=c.useMemo(()=>ps(e,n),[e,n]),a=!e.loading&&!e.error&&!!i&&s!=null&&s!=="",l=c.useMemo(()=>a?tl(i,r):null,[a,i,r]),{isLoading:u,error:d,data:p}=me.useQuery({queryKey:["tableRefValue",n,r,String(s??"")],queryFn:({signal:m})=>o.query(l.query,{key:nl(l.keyType,s)},{signal:m}),enabled:!!l});return{loading:u,error:d||e.error,value:p?.values?.data?.at(0)??null}}const ol=500,al=50;function il(e,n,r,s={}){const o=Ce(),{search:i="",enabled:a=!0,currentValues:l=null}=s,u=i.trim(),d=c.useMemo(()=>e?.data?.find(L=>L.graphQlName===n),[e,n]),p=c.useMemo(()=>d?.labelColumn||r[0],[d,r]),m=c.useMemo(()=>d?.columns.find(v=>v.name===p)?.paramType?.replace("!","")==="String",[d,p]),h=c.useMemo(()=>{if(!d||r.length===0||!Ie(n)||!Ie(p))return!1;const L=new Set(d.columns.map(v=>v.name));return L.has(p)?r.every(v=>Ie(v)&&L.has(v)):!1},[d,n,r,p]),x=c.useMemo(()=>{if(!d||!h)return"";const L=new Set(r);return L.add(p),Array.from(L).join(" ")},[d,h,r,p]),g=!!u&&m,b=c.useMemo(()=>{if(e.loading||e.error||!d||r.length===0||!h)return null;const L=g?"($limit: Int, $search: String)":"($limit: Int)",v=g?`filter: {${p}: {_contains: $search}} `:"";return`query Get_${n}_CompositeRef${L} { values: ${n}(${v}limit: $limit sort: [${p}_asc]) { data { ${x} } } }`},[d,n,x,p,g,e.loading,e.error,r.length,h]),k=m?u:"",{isLoading:$,error:w,data:P}=me.useQuery({queryKey:["compositeTableRef",n,r.join("|"),k],queryFn:()=>o.query(b,k?{limit:al,search:k}:{limit:ol}),enabled:!!b&&a}),C=c.useMemo(()=>{if(!d||!P)return[];const L={primaryKeys:r};return(P.values?.data??[]).map((v,M)=>{const O={};for(const I of r)O[I]=v[I];const z=_t(v,L,M);return{route:z,values:O,label:String(v[p]??z)}})},[d,r,p,P]),T=c.useMemo(()=>{if(!l)return"";const L=[];for(const v of r){const M=l[v];if(M==null||M==="")return"";L.push(M)}return xt(L)},[l,r]),j=T===""||C.some(L=>L.route===T),E=c.useMemo(()=>{if(!d||!h||j||T===""||!l)return null;const L=new Map(d.columns.map(_=>[_.name,_])),v=[],M=[],O={};for(let _=0;_<r.length;_++){const G=r[_],U=Xt(L.get(G)),ie=`k${_}`;M.push(`$${ie}: ${U}`),v.push(`{${G}: {_eq: $${ie}}}`),O[ie]=Xe(l[G],U)}const z=v.length===1?v[0]:`{and: [${v.join(", ")}]}`;return{query:`query Get_${n}_CompositeRefValue(${M.join(", ")}) { values: ${n}(filter: ${z} limit: 1) { data { ${x} } } }`,variables:O}},[d,n,x,r,j,T,l,h]),{data:y}=me.useQuery({queryKey:["compositeTableRefValue",n,T],queryFn:()=>o.query(E.query,E.variables),enabled:!!E}),S=c.useMemo(()=>{const L=y?.values?.data?.[0];if(!L)return C;const v={};for(const O of r)v[O]=L[O];const M=xt(r.map(O=>L[O]));return C.some(O=>O.route===M)?C:[{route:M,values:v,label:String(L[p]??M)},...C]},[C,y,r,p]);return{loading:$||e.loading,error:w||e.error,data:S,serverSearch:m}}const ll=new Set(["Int","Int!","Float","Float!","Decimal","Decimal!"]);function cl(e){return ll.has(e.paramType)}function dl(e){return e.startsWith("^")?e:`^(?:${e})$`}function ul(e){if(e!==e.trim()||/\s/.test(e))return!1;const n=e.lastIndexOf("@");if(n<=0||n===e.length-1)return!1;const r=e.slice(n+1);return r.includes(".")&&!r.startsWith(".")&&!r.endsWith(".")}function ml(e){try{const n=new URL(e);return n.protocol==="http:"||n.protocol==="https:"}catch{return!1}}function fl(e,n,r){const s=e.label;if(r&&(n==null||n===""))return`${s} is required`;if(!(n==null||n==="")){if(typeof n=="string"){if(e.pattern){let o;try{o=new RegExp(dl(e.pattern))}catch{return`${s} has an invalid validation pattern`}if(!o.test(n))return e.patternMessage||`${s} format is invalid`}if(e.minLength&&n.length<e.minLength)return`${s} must be at least ${e.minLength} characters`;if(e.maxLength&&n.length>e.maxLength)return`${s} must be at most ${e.maxLength} characters`;if(e.inputType==="email"&&!ul(n))return"Invalid email address";if(e.inputType==="url"&&!ml(n))return"Invalid URL"}if(cl(e)){const o=Number(n);if(!Number.isNaN(o)){if(e.min!==void 0&&e.min!==null&&o<e.min)return`${s} must be at least ${e.min}`;if(e.max!==void 0&&e.max!==null&&o>e.max)return`${s} must be at most ${e.max}`}}}}const pl=new Set(["DateTime","DateTime!"]);function _n(e){return pl.has(e.paramType)}function Fn(e){return rs(e)==="datetime"}function hs(e,n){if(!e)return"";const r=e.match(/^(\d{4}-\d{2}-\d{2})(?:[T ](\d{2}:\d{2}(?::\d{2})?))?/);if(!r||r[1]==="0001-01-01")return"";if(!n||!r[2])return r[1];const s=r[2].length===5?`${r[2]}:00`:r[2];return`${r[1]}T${s}`}function hl(e,n,r){const s={...e};for(const o of r){if(!_n(o))continue;const i=n[o.name];typeof i!="string"||i===""||hs(i,Fn(o))===s[o.name]&&(s[o.name]=i)}return s}function xs(e,n,r){const s=e;return String(s.label??s[n]??"").toLowerCase().includes(r.toLowerCase())}const Ze=ve.forwardRef(({...e},n)=>t.jsx(Q.Dialog.Root,{"data-slot":"dialog",...e}));Ze.displayName="Dialog";const xl=ve.forwardRef(({...e},n)=>t.jsx(Q.Dialog.Trigger,{"data-slot":"dialog-trigger",...e}));xl.displayName="DialogTrigger";const gs=ve.forwardRef(({...e},n)=>t.jsx(Q.Dialog.Portal,{"data-slot":"dialog-portal",...e}));gs.displayName="DialogPortal";const gl=ve.forwardRef(({...e},n)=>t.jsx(Q.Dialog.Close,{"data-slot":"dialog-close",...e}));gl.displayName="DialogClose";const bs=ve.forwardRef(({className:e,...n},r)=>t.jsx(Q.Dialog.Overlay,{ref:r,"data-slot":"dialog-overlay",className:H("fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",e),...n}));bs.displayName="DialogOverlay";const et=ve.forwardRef(({className:e,children:n,showCloseButton:r=!0,...s},o)=>t.jsxs(gs,{"data-slot":"dialog-portal",children:[t.jsx(bs,{}),t.jsxs(Q.Dialog.Content,{ref:o,"data-slot":"dialog-content",className:H("fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border bg-background p-6 shadow-lg duration-200 outline-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 sm:max-w-lg",e),...s,children:[n,r&&t.jsxs(Q.Dialog.Close,{"data-slot":"dialog-close",className:"absolute top-4 right-4 rounded-xs opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",children:[t.jsx(N.XIcon,{}),t.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));et.displayName="DialogContent";const Ot=ve.forwardRef(({className:e,...n},r)=>t.jsx("div",{ref:r,"data-slot":"dialog-header",className:H("flex flex-col gap-2 text-center sm:text-left",e),...n}));Ot.displayName="DialogHeader";const ys=ve.forwardRef(({className:e,showCloseButton:n=!1,children:r,...s},o)=>t.jsxs("div",{ref:o,"data-slot":"dialog-footer",className:H("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",e),...s,children:[r,n&&t.jsx(Q.Dialog.Close,{asChild:!0,children:t.jsx(W,{variant:"outline",children:"Close"})})]}));ys.displayName="DialogFooter";const tt=ve.forwardRef(({className:e,...n},r)=>t.jsx(Q.Dialog.Title,{ref:r,"data-slot":"dialog-title",className:H("text-lg leading-none font-semibold",e),...n}));tt.displayName="DialogTitle";const jt=ve.forwardRef(({className:e,...n},r)=>t.jsx(Q.Dialog.Description,{ref:r,"data-slot":"dialog-description",className:H("text-sm text-muted-foreground",e),...n}));jt.displayName="DialogDescription";function zn({className:e,...n}){return t.jsx(Q.Checkbox.Root,{"data-slot":"checkbox",className:H("peer size-4 shrink-0 rounded-[4px] border border-input shadow-xs transition-shadow outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[state=checked]:border-primary data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:bg-input/30 dark:aria-invalid:ring-destructive/40 dark:data-[state=checked]:bg-primary",e),...n,children:t.jsx(Q.Checkbox.Indicator,{"data-slot":"checkbox-indicator",className:"grid place-content-center text-current transition-none",children:t.jsx(N.CheckIcon,{className:"size-3.5"})})})}function ct({className:e,...n}){return t.jsx(Q.Label.Root,{"data-slot":"label",className:H("flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50",e),...n})}function En({open:e,onOpenChange:n,title:r,description:s,confirmLabel:o="Confirm",cancelLabel:i="Cancel",variant:a="default",isPending:l=!1,onConfirm:u}){return t.jsx(Ze,{open:e,onOpenChange:n,children:t.jsxs(et,{showCloseButton:!1,children:[t.jsxs(Ot,{children:[t.jsx(tt,{children:r}),t.jsx(jt,{asChild:!0,children:t.jsx("div",{children:s})})]}),t.jsxs(ys,{children:[t.jsx(W,{variant:"outline",onClick:()=>n(!1),disabled:l,children:i}),t.jsx(W,{variant:a==="destructive"?"destructive":"default",onClick:u,disabled:l,children:l?`${o}…`:o})]})]})})}function bl({name:e,label:n,value:r,dbType:s,onChange:o,onBlur:i,required:a,invalid:l}){const u=bt(s),d=Ft(s),p=Nn(r,s),[m,h]=c.useState(null),x=c.useRef(null),g=c.useCallback(()=>{const w=x.current;w&&(w.style.height="auto",w.style.height=Math.min(w.scrollHeight,400)+"px")},[]);if(c.useEffect(g,[r,g]),u)return t.jsx(yl,{name:e,label:n,value:r});if(!d&&p==="text")return null;const b=()=>{if(h(null),p==="json")try{o(JSON.stringify(JSON.parse(r),null,2))}catch{h("Invalid JSON")}else if(p==="xml")try{const w=r.replace(/>\s*</g,`>
94
101
  <`).replace(/(<[^/][^>]*[^/]>)\n/g,`$1
95
- `).trim();o(j)}catch{h("Could not format XML")}},N=()=>{if(h(null),p==="json")try{o(JSON.stringify(JSON.parse(r)))}catch{h("Invalid JSON")}else p==="xml"&&o(r.replace(/\n\s*/g,"").trim())},T=p==="json"||p==="xml";return t.jsxs("div",{className:"grid gap-1",children:[T&&t.jsxs("div",{className:"flex items-center gap-1 justify-end",children:[t.jsxs(q,{type:"button",variant:"ghost",size:"sm",className:"h-6 text-xs px-2",onClick:b,children:[t.jsx(v.WrapText,{className:"size-3"}),"Format"]}),t.jsx(q,{type:"button",variant:"ghost",size:"sm",className:"h-6 text-xs px-2",onClick:N,children:"Minify"})]}),t.jsx("textarea",{ref:y,id:e,value:r,onChange:j=>{o(j.target.value),h(null)},onBlur:i,required:a,"aria-invalid":l,className:K("flex w-full rounded-md border border-input bg-background px-3 py-2","text-xs font-mono leading-relaxed","ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2","disabled:cursor-not-allowed disabled:opacity-50","resize-none min-h-[80px] max-h-[400px]",l&&"border-destructive")}),d&&t.jsx("p",{className:"text-xs text-destructive",children:d})]})}function pl({name:e,label:n,value:r}){const s=r?Math.ceil(r.length*3/4):0,o=s<1024?`${s} bytes`:s<1024*1024?`${(s/1024).toFixed(1)} KB`:`${(s/(1024*1024)).toFixed(1)} MB`,i=r?r.slice(0,256)+(r.length>256?"...":""):"(empty)";return t.jsxs("div",{className:"grid gap-2",children:[t.jsxs(nt,{htmlFor:e,className:"flex items-center gap-1.5",children:[t.jsx(v.Binary,{className:"size-3.5 text-muted-foreground"}),n,t.jsxs("span",{className:"text-xs text-muted-foreground font-normal ml-1",children:["(binary, ",o,")"]})]}),t.jsx("div",{className:"rounded-md border border-input bg-muted/30 p-3 max-h-[160px] overflow-auto",children:t.jsx("pre",{className:"text-xs font-mono text-muted-foreground break-all whitespace-pre-wrap",children:i})}),t.jsx("p",{className:"text-xs text-muted-foreground",children:"Binary fields are read-only in this editor."})]})}const jn=["Boolean","Boolean!"],as=["DateTime","DateTime!"],hl=["Int","Int!","Float","Float!"],Nn={filterText:"",variables:{},params:[]};function xl(e,n){return f.useMemo(()=>{const r=e?.data?.find(l=>l.graphQlName==n),o=r.columns.filter(l=>!l.isReadOnly&&!l.isIdentity).map(l=>{const c=r.singleJoins.find(p=>p.sourceColumnNames[0]===l.graphQlName);if(c)return{column:l,join:c,fkRole:et(c)?"anchor-composite":"anchor-single"};const m=r.singleJoins.find(p=>(p.sourceColumnNames??[]).includes(l.graphQlName));return m?{column:l,join:m,fkRole:"member-composite"}:{column:l,fkRole:"none"}}),i=new Map(r.columns.map(l=>[l.name,l])),a=(r.primaryKeys??[]).map(l=>i.get(l)).filter(l=>!!l);return[r,o,a]},[e,n])}function gl({table:e,schema:n,editid:r,onClose:s}){const o=ve(),i=r===void 0||r==="",[a,l,c]=xl(n,e),m=a.labelColumn,p=a.label,d=yn(a,l,c,r),h=f.useMemo(()=>{if(i)return Nn;const x=xn(r,a);return x?Gr(x,a)??Nn:Nn},[i,r,a]),y=f.useMemo(()=>{const x=h.params.length>0?h.params.join(", "):"";return`query GetSingleEdit_${a.name}(${x}){
96
- value: ${a.name}(filter: ${h.filterText||"{}"}) {
97
- data { ${l.map(({column:k})=>k.name).join(" ")} }
102
+ `).trim();o(w)}catch{h("Could not format XML")}},k=()=>{if(h(null),p==="json")try{o(JSON.stringify(JSON.parse(r)))}catch{h("Invalid JSON")}else p==="xml"&&o(r.replace(/\n\s*/g,"").trim())},$=p==="json"||p==="xml";return t.jsxs("div",{className:"grid gap-1",children:[$&&t.jsxs("div",{className:"flex items-center gap-1 justify-end",children:[t.jsxs(W,{type:"button",variant:"ghost",size:"sm",className:"h-6 text-xs px-2",onClick:b,children:[t.jsx(N.WrapText,{className:"size-3"}),"Format"]}),t.jsx(W,{type:"button",variant:"ghost",size:"sm",className:"h-6 text-xs px-2",onClick:k,children:"Minify"})]}),t.jsx("textarea",{ref:x,id:e,value:r,onChange:w=>{o(w.target.value),h(null)},onBlur:i,required:a,"aria-invalid":l,className:H("flex w-full rounded-md border border-input bg-background px-3 py-2","text-xs font-mono leading-relaxed","ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2","disabled:cursor-not-allowed disabled:opacity-50","resize-none min-h-[80px] max-h-[400px]",l&&"border-destructive")}),m&&t.jsx("p",{className:"text-xs text-destructive",children:m})]})}function yl({name:e,label:n,value:r}){const s=r?Math.ceil(r.length*3/4):0,o=s<1024?`${s} bytes`:s<1024*1024?`${(s/1024).toFixed(1)} KB`:`${(s/(1024*1024)).toFixed(1)} MB`,i=r?r.slice(0,256)+(r.length>256?"...":""):"(empty)";return t.jsxs("div",{className:"grid gap-2",children:[t.jsxs(ct,{htmlFor:e,className:"flex items-center gap-1.5",children:[t.jsx(N.Binary,{className:"size-3.5 text-muted-foreground"}),n,t.jsxs("span",{className:"text-xs text-muted-foreground font-normal ml-1",children:["(binary, ",o,")"]})]}),t.jsx("div",{className:"rounded-md border border-input bg-muted/30 p-3 max-h-[160px] overflow-auto",children:t.jsx("pre",{className:"text-xs font-mono text-muted-foreground break-all whitespace-pre-wrap",children:i})}),t.jsx("p",{className:"text-xs text-muted-foreground",children:"Binary fields are read-only in this editor."})]})}const Pn=["Boolean","Boolean!"],vl=["Int","Int!","Float","Float!"],nt="__none__";function vs(e,n){return e==null||e===""?n?nt:"":String(e)}function At(e,n){const r=({value:s})=>fl(e,s,n);return{onSubmit:r,onBlur:r}}function qt(e,n){const r=e.state.meta.errors.length>0;return{hasError:r,ariaProps:{"aria-invalid":r,"aria-describedby":r?n:void 0}}}function js(e){return bt(e.dbType)||Ft(e.dbType)||lt(e)}const Ns={filterText:"",variables:{},params:[]};function jl(e,n){return c.useMemo(()=>{const r=e?.data?.find(l=>l.graphQlName===n),o=r.columns.filter(l=>!l.isReadOnly&&!l.isIdentity).map(l=>{const u=r.singleJoins.find(p=>p.sourceColumnNames[0]===l.graphQlName);if(u)return{column:l,join:u,fkRole:it(u)?"anchor-composite":"anchor-single"};const d=r.singleJoins.find(p=>(p.sourceColumnNames??[]).includes(l.graphQlName));return d?{column:l,join:d,fkRole:"member-composite"}:{column:l,fkRole:"none"}}),i=new Map(r.columns.map(l=>[l.name,l])),a=(r.primaryKeys??[]).map(l=>i.get(l)).filter(l=>!!l);return[r,o,a]},[e,n])}function Nl({table:e,schema:n,editid:r,onClose:s}){const o=Ce(),i=r===void 0||r==="",[a,l,u]=jl(n,e),d=a.labelColumn,p=a.label,m=sn(a,l,u,r),h=c.useMemo(()=>i?null:jn(r,a),[i,r,a]),x=c.useMemo(()=>i||!h?Ns:yn(h,a)??Ns,[i,h,a]),g=!i&&x.filterText==="",b=c.useMemo(()=>{const z=x.params.length>0?x.params.join(", "):"";return`query GetSingleEdit_${a.name}(${z}){
103
+ value: ${a.name}(filter: ${x.filterText||"{}"}) {
104
+ data { ${l.map(({column:I})=>I.name).join(" ")} }
98
105
  }
99
- }`},[a,l,h]),{isLoading:g,error:b,data:N}=le.useQuery({queryKey:["editRecord",a.name,r],queryFn:()=>o.query(y,h.variables),enabled:!!a&&!i&&h.filterText!==""}),T=f.useMemo(()=>N?.value?.data?.at(0)??{},[N]),j=f.useMemo(()=>{const x={};for(const{column:k}of l)if(as.some(V=>V===k.paramType)){const V=T[k.name]?.split("T")?.[0];x[k.name]=V==="0001-01-01"?"":V??""}else jn.some(V=>V===k.paramType)?x[k.name]=!!T[k.name]:x[k.name]=T[k.name]??"";return x},[T,l]),$=Pn.useForm({defaultValues:j,onSubmit:async({value:x})=>{await(i?d.insert:d.update)({...x}),s()}});if(g&&!i)return null;if(b)return t.jsxs("div",{children:["Error: ",b.message]});const S=T?.[m]??r,D=l.filter(({column:x})=>jn.some(k=>k===x.paramType)),w=l.filter(({column:x})=>jt(x.dbType)||Bt(x.dbType)),L=l.filter(({column:x})=>!jn.some(k=>k===x.paramType)&&!jt(x.dbType)&&!Bt(x.dbType));return t.jsx(kt,{open:!0,onOpenChange:x=>{x||s()},children:t.jsxs(Tt,{showCloseButton:!1,className:"sm:max-w-2xl max-h-[90vh] flex flex-col gap-0 p-0 overflow-hidden",children:[t.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-b border-border bg-muted/30 shrink-0",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsx(St,{className:"text-sm font-semibold truncate",children:i?`New ${p}`:`${p} : ${S}`}),t.jsxs(Wt,{className:"sr-only",children:[i?"Create":"Edit"," ",p," record"]})]}),t.jsx(q,{variant:"ghost",size:"icon-sm",onClick:s,"aria-label":"Close",className:"shrink-0 -mr-1",children:t.jsx(v.X,{className:"size-4"})})]}),d.error&&t.jsxs("div",{className:"flex items-center gap-2 px-5 py-2 bg-destructive/10 border-b border-destructive/20 text-destructive text-sm shrink-0",children:[t.jsx(v.AlertCircle,{className:"size-3.5 shrink-0"}),t.jsx("span",{className:"truncate",children:d.error.message})]}),t.jsxs("form",{onSubmit:x=>{x.preventDefault(),x.stopPropagation(),$.handleSubmit()},className:"flex flex-col flex-1 min-h-0",children:[t.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-4",children:[L.length>0&&t.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-x-4 gap-y-3",children:L.map(({column:x,join:k,fkRole:V})=>t.jsx(vl,{column:x,join:k,fkRole:V,form:$,schema:n},x.name))}),D.length>0&&t.jsx("div",{className:L.length>0?"mt-4 pt-4 border-t border-border":"",children:t.jsx("div",{className:"flex flex-wrap gap-x-6 gap-y-2",children:D.map(({column:x})=>t.jsx(Nl,{column:x,form:$},x.name))})}),w.length>0&&t.jsx("div",{className:L.length>0||D.length>0?"mt-4 pt-4 border-t border-border":"",children:t.jsx("div",{className:"grid gap-3",children:w.map(({column:x})=>t.jsx(Cl,{column:x,form:$},x.name))})})]}),t.jsxs("div",{className:"flex items-center justify-end gap-2 px-5 py-3 border-t border-border bg-muted/30 shrink-0",children:[t.jsx(q,{variant:"outline",size:"sm",onClick:s,children:"Cancel"}),t.jsxs(q,{type:"submit",size:"sm",disabled:d.isPending,children:[d.isPending?t.jsx(v.LoaderCircle,{className:"size-3.5 animate-spin"}):t.jsx(v.Save,{className:"size-3.5"}),i?"Create":"Save"]})]})]})]})})}function Jt(){const{table:e,editid:n}=on(),r=Dt();return e?t.jsx(is,{table:e,editid:n??"",onClose:()=>r("../..")}):t.jsx("div",{children:"Table missing"})}function is({table:e,editid:n,onClose:r}){const s=je();return e?s.loading?t.jsx("div",{children:"Loading..."}):s.error?t.jsxs("div",{children:["Error: ",s.error.message]}):t.jsx(gl,{table:e,schema:s,editid:n,onClose:r}):t.jsx("div",{children:"Table missing"})}function bl({current:e,max:n}){const r=n-e,s=r<=10&&r>0,o=r<=0;return t.jsx("div",{className:"text-xs text-right mt-0.5","aria-live":"polite",children:t.jsxs("span",{className:o?"text-destructive font-medium":s?"text-amber-500":"text-muted-foreground",children:[e,"/",n]})})}function yl({min:e,max:n,step:r}){if(e===void 0&&n===void 0)return null;let s="";return e!=null&&n!==void 0&&n!==null?s=`Range: ${e} to ${n}`:e!=null?s=`Min: ${e}`:n!=null&&(s=`Max: ${n}`),r!=null&&r!==1&&(s+=` (step: ${r})`),t.jsx("div",{className:"text-xs text-muted-foreground mt-0.5","aria-live":"polite",children:s})}function vl({column:e,join:n,fkRole:r,form:s,schema:o}){const i=e.name,a=!e.isNullable;if(r==="member-composite")return null;const l=as.some(h=>h===e.paramType),c=hl.some(h=>h===e.paramType),m=e.maxLength&&e.maxLength>0&&!l&&!c;if(e.enumValues&&e.enumValues.length>0)return t.jsx(jl,{column:e,form:s,isRequired:a});if(n&&o)return r==="anchor-composite"?t.jsx(kl,{column:e,join:n,form:s,schema:o,isRequired:a}):t.jsx(wl,{column:e,join:n,form:s,schema:o,isRequired:a});const p=e.inputType||(l?"date":c?"number":"text"),d={onSubmit:({value:h})=>dl(e,h,a)};return t.jsx(s.Field,{name:i,validators:d,children:h=>t.jsxs("div",{className:"grid gap-1",children:[t.jsxs(nt,{htmlFor:i,className:"text-xs text-muted-foreground",children:[e.label,a&&t.jsx("span",{className:"text-destructive ml-0.5",children:"*"})]}),t.jsx(Ne,{id:i,type:p,value:h.state.value??"",onChange:y=>h.handleChange(y.target.value),onBlur:h.handleBlur,required:a,maxLength:e.maxLength,minLength:e.minLength,min:e.min,max:e.max,step:e.step,pattern:e.pattern,title:e.patternMessage,"aria-invalid":h.state.meta.errors.length>0,className:"h-8 text-sm"}),m&&t.jsx(bl,{current:String(h.state.value??"").length,max:e.maxLength}),c&&(e.min!==void 0||e.max!==void 0)&&t.jsx(yl,{min:e.min,max:e.max,step:e.step}),t.jsx(Ht,{errors:h.state.meta.errors})]})})}function jl({column:e,form:n,isRequired:r}){const s=e.name,o=e.enumValues||[],i=e.enumLabels&&e.enumLabels.length===o.length?e.enumLabels:o;return t.jsx(n.Field,{name:s,validators:r?{onSubmit:({value:a})=>{if(a==null||a==="")return`${e.label} is required`}}:void 0,children:a=>t.jsxs("div",{className:"grid gap-1",children:[t.jsxs(nt,{htmlFor:s,className:"text-xs text-muted-foreground",children:[e.label,r&&t.jsx("span",{className:"text-destructive ml-0.5",children:"*"})]}),t.jsxs(_e,{value:String(a.state.value??""),onValueChange:l=>a.handleChange(l),children:[t.jsx(Pe,{id:s,className:"w-full h-8 text-sm","aria-invalid":a.state.meta.errors.length>0,children:t.jsx(ze,{placeholder:`Select ${e.label}`})}),t.jsx(Ee,{children:o.map((l,c)=>t.jsx(Ce,{value:l,children:i[c]||l},l))})]}),t.jsx(Ht,{errors:a.state.meta.errors})]})})}function Nl({column:e,form:n}){const r=e.name;return t.jsx(n.Field,{name:r,children:s=>t.jsxs("label",{htmlFor:r,className:"flex items-center gap-2 cursor-pointer select-none",children:[t.jsx(vn,{id:r,checked:!!s.state.value,onCheckedChange:o=>s.handleChange(!!o),onBlur:s.handleBlur}),t.jsx("span",{className:"text-sm",children:e.label})]})})}function Cl({column:e,form:n}){const r=e.name,s=!e.isNullable;return t.jsx(n.Field,{name:r,validators:s?{onSubmit:({value:o})=>{if(o==null||o==="")return`${e.label} is required`}}:void 0,children:o=>t.jsxs("div",{className:"grid gap-1",children:[t.jsxs(nt,{htmlFor:r,className:"text-xs text-muted-foreground",children:[e.label,s&&t.jsx("span",{className:"text-destructive ml-0.5",children:"*"})]}),t.jsx(fl,{name:r,label:e.label,value:String(o.state.value??""),dbType:e.dbType,onChange:i=>o.handleChange(i),onBlur:o.handleBlur,required:s,invalid:o.state.meta.errors.length>0}),t.jsx(Ht,{errors:o.state.meta.errors})]})})}function wl({column:e,join:n,form:r,schema:s,isRequired:o}){const i=e.name,a=tl(s,n.destinationTable,n.destinationColumnNames[0]);return t.jsx(r.Field,{name:i,validators:o?{onSubmit:({value:l})=>{if(l==null||l==="")return`${e.label} is required`}}:void 0,children:l=>t.jsxs("div",{className:"grid gap-1",children:[t.jsxs(nt,{htmlFor:i,className:"text-xs text-muted-foreground",children:[e.label,o&&t.jsx("span",{className:"text-destructive ml-0.5",children:"*"})]}),t.jsxs(_e,{value:String(l.state.value??""),onValueChange:c=>l.handleChange(c),children:[t.jsx(Pe,{id:i,className:"w-full h-8 text-sm","aria-invalid":l.state.meta.errors.length>0,children:t.jsx(ze,{placeholder:`Select ${e.label}`})}),t.jsx(Ee,{children:a.data.map(c=>t.jsx(Ce,{value:String(c.key),children:c.label},c.key))})]}),t.jsx(Ht,{errors:l.state.meta.errors})]})})}function kl({column:e,join:n,form:r,schema:s,isRequired:o}){const i=n.sourceColumnNames??[],a=n.destinationColumnNames??[],l=rl(s,n.destinationTable,a),c=Pn.useStore(r.store,p=>{const d=[];for(const h of i){const y=p.values?.[h];if(y==null||y==="")return"";d.push(y)}return Nt(d)}),m=p=>{const d=l.data.find(h=>h.route===p);if(d)for(let h=0;h<i.length;h++){const y=a[h],g=i[h];r.setFieldValue(g,d.values[y])}};return t.jsxs("div",{className:"grid gap-1 sm:col-span-2",children:[t.jsxs(nt,{htmlFor:e.name,className:"text-xs text-muted-foreground",children:[e.label,o&&t.jsx("span",{className:"text-destructive ml-0.5",children:"*"}),t.jsxs("span",{className:"ml-2 px-1 rounded bg-primary/10 text-[10px] font-medium text-primary",children:["composite FK (",i.length," cols)"]})]}),t.jsxs(_e,{value:c,onValueChange:m,children:[t.jsx(Pe,{id:e.name,className:"w-full h-8 text-sm",children:t.jsx(ze,{placeholder:`Select ${e.label}`})}),t.jsx(Ee,{children:l.data.map(p=>t.jsx(Ce,{value:p.route,children:p.label},p.route))})]})]})}function Ht({errors:e}){return e.length===0?null:t.jsx(t.Fragment,{children:e.map((n,r)=>t.jsx("p",{className:"text-xs text-destructive",children:String(n)},r))})}const ls=40,cs=32;function Tl({className:e,...n}){return t.jsx("div",{"data-slot":"table-container",className:"relative w-full h-full overflow-x-auto",children:t.jsx("table",{"data-slot":"table",className:K("min-w-full caption-bottom text-sm border-separate border-spacing-0",e),...n})})}function Sl({className:e,...n}){return t.jsx("thead",{"data-slot":"table-header",className:K("[&_tr]:border-b",e),...n})}function Fl({className:e,...n}){return t.jsx("tbody",{"data-slot":"table-body",className:K("[&_tr:last-child]:border-0 [&_tr:nth-child(even)]:bg-muted/25",e),...n})}function Qt({className:e,style:n,...r}){return t.jsx("tr",{"data-slot":"table-row",className:K("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",e),style:{height:ls,...n},...r})}function $l({className:e,style:n,...r}){return t.jsx("th",{"data-slot":"table-head",className:K("px-2 text-left align-middle font-medium whitespace-nowrap text-muted-foreground text-xs border-r border-border last:border-r-0 [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",e),style:{height:cs,...n},...r})}function Cn({className:e,...n}){return t.jsx("td",{"data-slot":"table-cell",className:K("px-2 py-1 align-middle whitespace-nowrap text-[13px] overflow-hidden text-ellipsis border-r border-border last:border-r-0 [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",e),...n})}function _l({anchorEl:e,onEdit:n,onDelete:r,onMouseEnter:s,onDismiss:o}){const i=f.useRef(null);return f.useEffect(()=>{const a=i.current;return a?((()=>{const c=e.getBoundingClientRect(),m=a.offsetHeight,p=a.offsetWidth;a.style.top=`${c.top+(c.height-m)/2}px`;const d=Math.min(c.right-p-8,window.innerWidth-p-8);a.style.left=`${Math.max(8,d)}px`})(),a.showPopover(),()=>{try{a.hidePopover()}catch{}}):void 0},[e]),f.useEffect(()=>{const a=l=>{const c=i.current;c&&!c.contains(l.target)&&o()};return document.addEventListener("pointerdown",a),()=>document.removeEventListener("pointerdown",a)},[o]),t.jsxs("div",{ref:i,popover:"manual",className:"flex items-center gap-0.5 rounded-md border border-border bg-popover px-1 py-0.5 shadow-md m-0",style:{position:"fixed"},onClick:a=>a.stopPropagation(),onMouseEnter:s,onMouseLeave:o,children:[n&&t.jsx(q,{variant:"ghost",size:"icon-sm",onClick:n,"aria-label":"Edit row",title:"Edit",className:"size-6",children:t.jsx(v.Pencil,{className:"size-3.5"})}),r&&t.jsx(q,{variant:"ghost",size:"icon-sm",onClick:r,"aria-label":"Delete row",title:"Delete",className:"size-6 text-destructive hover:text-destructive",children:t.jsx(v.Trash2,{className:"size-3.5"})})]})}const ds=60,zl=450,Pl=150,wn="bifrost-col-sizes:";function us(e){try{const n=localStorage.getItem(wn+e);return n?JSON.parse(n):{}}catch{return{}}}function El(e,n){try{Object.keys(n).length===0?localStorage.removeItem(wn+e):localStorage.setItem(wn+e,JSON.stringify(n))}catch{}}const Dl=[10,20,30,50,100],kn=-1;function Il({columns:e,data:n,tableName:r,pageCount:s,pageIndex:o,pageSize:i,sorting:a,columnFilters:l,loading:c,selectable:m=!1,primaryKeys:p=[],selectedRowId:d,onRowSelect:h,onSortingChange:y,onColumnFiltersChange:g,onPageIndexChange:b,onPageSizeChange:N,onEditRow:T,onDeleteRow:j,onDeleteSelected:$,stackingEnabled:S,onToggleStacking:D}){const[w,L]=f.useState(null),x=f.useRef(null),k=f.useCallback((F,B)=>{x.current&&(clearTimeout(x.current),x.current=null),L({rowId:F,el:B})},[]),V=f.useCallback(()=>{x.current&&clearTimeout(x.current),x.current=setTimeout(()=>L(null),150)},[]),I=f.useCallback(()=>{x.current&&(clearTimeout(x.current),x.current=null)},[]),A=f.useRef(null),W=f.useRef(!1),H=f.useRef(!1),U=500,E=f.useCallback(()=>{A.current&&(clearTimeout(A.current),A.current=null)},[]),Y=f.useCallback((F,B,ee)=>{ee.pointerType==="touch"&&(W.current=!1,E(),A.current=setTimeout(()=>{W.current||(H.current=!0,k(F,B))},U))},[E,k]),se=f.useCallback(()=>{W.current=!0,E()},[E]),[ue,M]=f.useState({}),[we,ke]=f.useState({}),[ye,me]=f.useState(()=>r?us(r):{}),[O,Q]=f.useState(!0),oe=f.useRef(null);f.useEffect(()=>{r&&El(r,ye)},[r,ye]);const ge=f.useRef(r);if(r&&r!==ge.current){ge.current=r;const F=us(r);me(F)}const re=f.useCallback(F=>{const B=oe.current;if(!B)return;const ee=B.querySelectorAll(`[data-col-id="${F}"]`);let Ae=ds;ee.forEach(st=>{const Ft=st.scrollWidth+4;Ft>Ae&&(Ae=Ft)});const Re=Math.min(Ae,zl);me(st=>({...st,[F]:Re}))},[]),Ie=f.useCallback(()=>{me({})},[]),Me=f.useRef(0),Se=f.useCallback(()=>{const F=oe.current;return F?Math.max(5,Math.floor((F.clientHeight-cs)/ls)):10},[]);f.useEffect(()=>{if(!O)return;const F=oe.current;if(!F)return;const B=()=>{const Re=Se();Re!==Me.current&&(Me.current=Re,N(Re))},ee=requestAnimationFrame(B),Ae=new ResizeObserver(()=>requestAnimationFrame(B));return Ae.observe(F),()=>{cancelAnimationFrame(ee),Ae.disconnect()}},[O,Se,N]),f.useEffect(()=>{ke({})},[n,o]);const Fe=[];m&&Fe.push({id:"_select",header:({table:F})=>t.jsx(vn,{checked:F.getIsAllPageRowsSelected()||F.getIsSomePageRowsSelected()&&"indeterminate",onCheckedChange:B=>F.toggleAllPageRowsSelected(!!B),"aria-label":"Select all"}),cell:({row:F})=>t.jsx(vn,{checked:F.getIsSelected(),onCheckedChange:B=>F.toggleSelected(!!B),onClick:B=>B.stopPropagation(),"aria-label":"Select row"}),enableSorting:!1,enableHiding:!1,enableResizing:!1,size:32}),Fe.push(...e);const de=$t.useReactTable({data:n,columns:Fe,pageCount:s,getRowId:(F,B)=>Ct(F,{primaryKeys:p},B),state:{sorting:a,columnFilters:l,pagination:{pageIndex:o,pageSize:i},columnVisibility:ue,rowSelection:we,columnSizing:ye},defaultColumn:{minSize:ds,size:Pl},columnResizeMode:"onChange",enableColumnResizing:!0,onColumnSizingChange:me,meta:{onResetColumnWidths:Ie},onSortingChange:F=>{const B=typeof F=="function"?F(a):F;y(B)},onPaginationChange:F=>{const ee=typeof F=="function"?F({pageIndex:o,pageSize:i}):F;ee.pageSize!==i?(N(ee.pageSize),b(0)):b(ee.pageIndex)},onColumnFiltersChange:F=>{const B=typeof F=="function"?F(l):F;g(B)},onColumnVisibilityChange:M,onRowSelectionChange:ke,enableRowSelection:m,getCoreRowModel:$t.getCoreRowModel(),manualSorting:!0,manualFiltering:!0,manualPagination:!0}),Je=Object.keys(we).length,He=f.useCallback(()=>{if(!$)return;const F=[];for(const B of de.getSelectedRowModel().rows){const ee=Gt(B.original,{primaryKeys:p});ee&&F.push(ee)}F.length>0&&$(F)},[de,$,p]),Qe=f.useCallback(F=>{const B=de.getRow(F);return B?Gt(B.original,{primaryKeys:p}):null},[de,p]),Xt=f.useCallback(()=>{if(!w||!T)return;const F=Qe(w.rowId);F&&T(F)},[w,T,Qe]),rt=f.useCallback(()=>{if(!w||!j)return;const F=Qe(w.rowId);F&&j(F)},[w,j,Qe]);return t.jsxs("div",{className:"flex flex-col w-full min-h-0 flex-1",children:[t.jsxs("div",{className:"flex items-center justify-between py-1 px-2",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[l.length>0&&t.jsxs(q,{variant:"outline",size:"sm",onClick:()=>de.resetColumnFilters(),title:"Clear all column filters",children:[t.jsx(v.FilterX,{className:"size-3.5"}),"Clear filters"]}),Je>0&&$&&t.jsxs(t.Fragment,{children:[t.jsxs("span",{className:"text-xs text-muted-foreground",children:[Je," selected"]}),t.jsxs(q,{variant:"outline",size:"sm",onClick:He,className:"text-destructive hover:text-destructive",children:[t.jsx(v.Trash2,{className:"size-3.5"}),"Delete"]})]})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[D&&t.jsxs(q,{variant:S?"secondary":"outline",size:"sm",role:"switch","aria-checked":!!S,onClick:()=>D(!S),title:S?"Stacked drill-down active — click for flat grid":"Flat grid active — click for stacked drill-down",children:[S?t.jsx(v.PanelRight,{className:"size-3.5"}):t.jsx(v.Rows3,{className:"size-3.5"}),S?"Stacked":"Grid"]}),t.jsxs(zr,{children:[t.jsx(Pr,{asChild:!0,children:t.jsxs(q,{variant:"outline",size:"sm",children:[t.jsx(v.Columns3,{className:"size-3.5"}),"Columns",t.jsx(v.ChevronDown,{className:"size-3.5"})]})}),t.jsx(Er,{align:"end",children:de.getAllColumns().filter(F=>F.getCanHide()).map(F=>t.jsx(_a,{checked:F.getIsVisible(),onCheckedChange:B=>F.toggleVisibility(!!B),children:F.id},F.id))})]})]})]}),t.jsxs("div",{ref:oe,className:"flex-1 overflow-auto min-h-0",children:[t.jsxs(Tl,{style:{width:de.getTotalSize()},children:[t.jsx(Sl,{children:de.getHeaderGroups().map(F=>t.jsx(Qt,{children:F.headers.map(B=>t.jsxs($l,{"data-col-id":B.column.id,className:"relative",style:{width:B.getSize()},children:[B.isPlaceholder?null:$t.flexRender(B.column.columnDef.header,B.getContext()),B.column.getCanResize()&&t.jsx("div",{onMouseDown:B.getResizeHandler(),onTouchStart:B.getResizeHandler(),onDoubleClick:()=>re(B.column.id),className:`absolute top-0 right-0 w-1 h-full cursor-col-resize select-none touch-none opacity-0 hover:opacity-100 transition-opacity ${B.column.getIsResizing()?"bg-primary opacity-100":"bg-border hover:bg-muted-foreground"}`})]},B.id))},F.id))}),t.jsx(Fl,{children:c?t.jsx(Qt,{children:t.jsx(Cn,{colSpan:Fe.length,className:"h-24 text-center",children:"Loading..."})}):de.getRowModel().rows.length===0?t.jsx(Qt,{children:t.jsx(Cn,{colSpan:Fe.length,className:"h-24 text-center",children:"No results."})}):de.getRowModel().rows.map(F=>{const B=d!=null&&F.id===d;return t.jsx(Qt,{"data-state":B||F.getIsSelected()?"selected":void 0,className:h?"cursor-pointer group/row":"group/row",onClick:h?()=>{if(H.current){H.current=!1;return}window.getSelection()?.toString()||h(B?null:F.id)}:void 0,onPointerEnter:ee=>{ee.pointerType==="mouse"&&k(F.id,ee.currentTarget)},onPointerLeave:ee=>{ee.pointerType==="mouse"&&V()},onPointerDown:ee=>Y(F.id,ee.currentTarget,ee),onPointerMove:se,onPointerUp:E,onPointerCancel:E,children:F.getVisibleCells().map(ee=>t.jsx(Cn,{"data-col-id":ee.column.id,style:{width:ee.column.getSize()},children:$t.flexRender(ee.column.columnDef.cell,ee.getContext())},ee.id))},F.id)})})]}),w&&(T||j)&&t.jsx(_l,{anchorEl:w.el,onEdit:T?Xt:void 0,onDelete:j?rt:void 0,onMouseEnter:I,onDismiss:V})]}),t.jsxs("div",{className:"flex items-center justify-between px-2 py-1.5 border-t border-border mt-auto shrink-0",children:[t.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[t.jsx("span",{children:"Rows per page"}),t.jsxs(_e,{value:String(O?kn:i),onValueChange:F=>{const B=Number(F);B===kn?(Q(!0),N(Se())):(Q(!1),N(B))},children:[t.jsx(Pe,{size:"sm",className:"w-auto h-7 text-xs","aria-label":"Rows per page",children:t.jsx(ze,{children:O?"Fit":i})}),t.jsxs(Ee,{children:[t.jsx(Ce,{value:String(kn),children:"Fit"}),Dl.map(F=>t.jsx(Ce,{value:String(F),children:F},F))]})]})]}),t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsxs("span",{className:"text-xs text-muted-foreground mr-2",children:["Page ",o+1," of ",s||1]}),t.jsx(q,{variant:"outline",size:"icon-sm",onClick:()=>b(0),disabled:o===0,"aria-label":"First page",title:"First page",children:t.jsx(v.ChevronsLeft,{className:"size-4"})}),t.jsx(q,{variant:"outline",size:"icon-sm",onClick:()=>b(o-1),disabled:!de.getCanPreviousPage(),"aria-label":"Previous page",title:"Previous page",children:t.jsx(v.ChevronLeft,{className:"size-4"})}),t.jsx(q,{variant:"outline",size:"icon-sm",onClick:()=>b(o+1),disabled:!de.getCanNextPage(),"aria-label":"Next page",title:"Next page",children:t.jsx(v.ChevronRight,{className:"size-4"})}),t.jsx(q,{variant:"outline",size:"icon-sm",onClick:()=>b(s-1),disabled:o>=s-1,"aria-label":"Last page",title:"Last page",children:t.jsx(v.ChevronsRight,{className:"size-4"})})]})]})]})}function Ml({open:e,onOpenChange:n,title:r,description:s,confirmLabel:o="Confirm",cancelLabel:i="Cancel",variant:a="default",isPending:l=!1,onConfirm:c}){return t.jsx(kt,{open:e,onOpenChange:n,children:t.jsxs(Tt,{showCloseButton:!1,children:[t.jsxs(Kt,{children:[t.jsx(St,{children:r}),t.jsx(Wt,{asChild:!0,children:t.jsx("div",{children:s})})]}),t.jsxs(os,{children:[t.jsx(q,{variant:"outline",onClick:()=>n(!1),disabled:l,children:i}),t.jsx(q,{variant:a==="destructive"?"destructive":"default",onClick:c,disabled:l,children:l?"Deleting...":o})]})]})})}function Ll({...e}){return t.jsx(G.Dialog.Root,{"data-slot":"sheet",...e})}function Ol({...e}){return t.jsx(G.Dialog.Portal,{"data-slot":"sheet-portal",...e})}function Al({className:e,...n}){return t.jsx(G.Dialog.Overlay,{"data-slot":"sheet-overlay",className:K("fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",e),...n})}function ql({className:e,children:n,side:r="right",...s}){return t.jsxs(Ol,{children:[t.jsx(Al,{}),t.jsxs(G.Dialog.Content,{"data-slot":"sheet-content",className:K("fixed z-50 flex flex-col gap-4 bg-background shadow-lg transition ease-in-out duration-200 outline-none","data-[state=closed]:animate-out data-[state=open]:animate-in data-[state=closed]:duration-200 data-[state=open]:duration-200",r==="right"&&"inset-y-0 right-0 h-full w-3/4 max-w-md border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right",r==="left"&&"inset-y-0 left-0 h-full w-3/4 max-w-md border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left",r==="top"&&"inset-x-0 top-0 h-auto border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",r==="bottom"&&"inset-x-0 bottom-0 h-auto border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",e),...s,children:[n,t.jsxs(G.Dialog.Close,{"data-slot":"sheet-close",className:"absolute top-4 right-4 rounded-xs opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",children:[t.jsx(v.XIcon,{}),t.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function Vl({className:e,...n}){return t.jsx("div",{"data-slot":"sheet-header",className:K("flex flex-col gap-2 p-4 pb-0",e),...n})}function Bl({className:e,...n}){return t.jsx(G.Dialog.Title,{"data-slot":"sheet-title",className:K("text-lg leading-none font-semibold",e),...n})}function Gl({className:e,...n}){return t.jsx(G.Dialog.Description,{"data-slot":"sheet-description",className:K("text-sm text-muted-foreground",e),...n})}const Kl={json:v.Braces,xml:v.Code,"php-serialized":v.Database,binary:v.Binary,longtext:v.FileText,text:v.FileText},Wl={json:"JSON",xml:"XML","php-serialized":"PHP Serialized",binary:"Binary",longtext:"Text",text:"Text"};function Jl(e,n){if(n==="json")try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}return n==="xml"?e.replace(/>\s*</g,`>
100
- <`).trim():e}function Hl({target:e,onClose:n,onNavigate:r,onSave:s,canNavigatePrev:o,canNavigateNext:i}){const[a,l]=f.useState(!1),[c,m]=f.useState(!1),[p,d]=f.useState(""),[h,y]=f.useState(!1),g=f.useRef(null),b=e?.value??"",N=hn(b,e?.dbType),T=Kl[N],j=Jl(b,N);f.useEffect(()=>{m(!1),d(""),y(!1)},[e?.rowIndex,e?.columnName]),f.useEffect(()=>{if(!e)return;const H=U=>{c||(U.key==="ArrowUp"&&o?(U.preventDefault(),r("prev")):U.key==="ArrowDown"&&i&&(U.preventDefault(),r("next")))};return window.addEventListener("keydown",H),()=>window.removeEventListener("keydown",H)},[e,c,o,i,r]);const $=f.useCallback(()=>{navigator.clipboard.writeText(b),y(!0),setTimeout(()=>y(!1),1500)},[b]),S=f.useCallback(()=>{d(j),m(!0),requestAnimationFrame(()=>g.current?.focus())},[j]),D=f.useCallback(()=>{m(!1),d("")},[]),w=f.useCallback(()=>{s&&p!==b&&s(p),m(!1)},[s,p,b]),L=f.useCallback(()=>{if(N==="json")try{d(JSON.stringify(JSON.parse(p),null,2))}catch{}else N==="xml"&&d(p.replace(/>\s*</g,`>
101
- <`).trim())},[p,N]),x=N==="json"||N==="xml",k=!e?.isReadOnly&&N!=="binary",V=t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[t.jsx(T,{className:"size-4 text-muted-foreground shrink-0"}),t.jsx("span",{className:"truncate font-semibold text-sm",children:e?.columnLabel}),t.jsx("span",{className:"text-xs text-muted-foreground shrink-0",children:Wl[N]}),t.jsxs("span",{className:"text-xs text-muted-foreground shrink-0",children:[b.length," chars"]})]}),I=t.jsxs("div",{className:"flex items-center gap-1 px-4 pb-2",children:[t.jsxs(q,{type:"button",variant:"ghost",size:"sm",className:"h-7 text-xs px-2",onClick:$,children:[h?t.jsx(v.Check,{className:"size-3"}):t.jsx(v.Copy,{className:"size-3"}),h?"Copied":"Copy"]}),k&&!c&&t.jsxs(q,{type:"button",variant:"ghost",size:"sm",className:"h-7 text-xs px-2",onClick:S,children:[t.jsx(v.Pencil,{className:"size-3"}),"Edit"]}),c&&x&&t.jsxs(q,{type:"button",variant:"ghost",size:"sm",className:"h-7 text-xs px-2",onClick:L,children:[t.jsx(v.WrapText,{className:"size-3"}),"Format"]}),t.jsxs("div",{className:"flex items-center gap-1 ml-auto",children:[t.jsx(q,{type:"button",variant:"ghost",size:"icon-sm",onClick:()=>r("prev"),disabled:!o,"aria-label":"Previous row",title:"Previous row",children:t.jsx(v.ChevronUp,{className:"size-4"})}),t.jsx(q,{type:"button",variant:"ghost",size:"icon-sm",onClick:()=>r("next"),disabled:!i,"aria-label":"Next row",title:"Next row",children:t.jsx(v.ChevronDown,{className:"size-4"})}),t.jsx(q,{type:"button",variant:"ghost",size:"icon-sm",onClick:()=>l(H=>!H),"aria-label":a?"Exit full screen":"Full screen",title:a?"Exit full screen":"Full screen",children:a?t.jsx(v.Minimize2,{className:"size-4"}):t.jsx(v.Maximize2,{className:"size-4"})})]})]}),A=t.jsx("div",{className:"flex-1 min-h-0 overflow-auto px-4 pb-4",children:c?t.jsxs("div",{className:"flex flex-col gap-2 h-full",children:[t.jsx("textarea",{ref:g,value:p,onChange:H=>d(H.target.value),className:K("flex-1 w-full rounded-md border border-input bg-background px-3 py-2","text-xs font-mono leading-relaxed","ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2","resize-none min-h-[200px]")}),t.jsxs("div",{className:"flex items-center gap-2 justify-end",children:[t.jsx(q,{type:"button",variant:"ghost",size:"sm",onClick:D,children:"Cancel"}),t.jsx(q,{type:"button",size:"sm",onClick:w,children:"Save"})]})]}):t.jsx("pre",{className:"text-xs font-mono leading-relaxed whitespace-pre-wrap break-all",children:j})}),W=!!e;return t.jsxs(t.Fragment,{children:[t.jsx(Ll,{open:W&&!a,onOpenChange:H=>{H||n()},children:t.jsxs(ql,{side:"right",className:"w-[480px] max-w-[90vw]",children:[t.jsxs(Vl,{children:[t.jsx(Bl,{children:V}),t.jsx(Gl,{className:"sr-only",children:"Content viewer panel"})]}),I,A]})}),t.jsx(kt,{open:W&&a,onOpenChange:H=>{H||l(!1)},children:t.jsxs(Tt,{className:"max-w-[90vw] max-h-[90vh] w-full h-full flex flex-col",children:[t.jsxs(Kt,{children:[t.jsx(St,{children:V}),t.jsx(Wt,{className:"sr-only",children:"Content viewer full screen"})]}),I,A]})})]})}function Tn({table:e,id:n,tableFilter:r,filterColumn:s,selectedRowId:o,onRowSelect:i,onOpenColumn:a,stackingEnabled:l,onToggleStacking:c}){const m=es(e),[p,d]=f.useState(null),[h,y]=f.useState(null),[g,b]=f.useState(null),[N,T]=f.useState(0),j=f.useCallback(O=>{y(Di(O,e))},[e]),$=f.useCallback(O=>{d({type:"single",pk:O})},[]),S=f.useCallback(O=>{O.length!==0&&d({type:"batch",pks:O})},[]),D=f.useCallback((O,Q)=>{T(O),b(Q)},[]),{columns:w,sorting:L,columnFilters:x,pageIndex:k,pageSize:V,pageCount:I,rows:A,loading:W,error:H,onSortingChange:U,onColumnFiltersChange:E,onPageIndexChange:Y,onPageSizeChange:se}=Zi(e,n,r,s,D,a),ue=f.useCallback(async()=>{if(p)try{p.type==="single"?await m.deleteRow(p.pk):await m.deleteRows(p.pks),d(null)}catch{}},[p,m]),M=p?.type==="batch"?p.pks.length:1,we=(()=>{if(g===null||!A[N])return null;const O=A[N],Q=e.columns.find(re=>re.name===g);if(!Q)return null;const oe=O[g];return{value:typeof oe=="object"&&oe!==null?JSON.stringify(oe,null,2):String(oe??""),columnName:Q.name,columnLabel:Q.label,dbType:Q.dbType,rowIndex:N,isReadOnly:Q.isReadOnly||Q.isPrimaryKey||Q.isIdentity}})(),ke=f.useCallback(()=>{b(null)},[]),ye=f.useCallback(O=>{T(Q=>O==="prev"?Math.max(0,Q-1):Math.min(A.length-1,Q+1))},[A.length]);if(H)return t.jsxs("div",{children:["Error: ",H.message]});const me=e.isEditable!==!1;return t.jsxs(t.Fragment,{children:[t.jsx(Il,{columns:w,data:A,tableName:e.name,pageCount:I,pageIndex:k,pageSize:V,sorting:L,columnFilters:x,loading:W,primaryKeys:e.primaryKeys??[],selectable:me,selectedRowId:o,onRowSelect:i,onSortingChange:U,onColumnFiltersChange:E,onPageIndexChange:Y,onPageSizeChange:se,onEditRow:me?j:void 0,onDeleteRow:me?$:void 0,onDeleteSelected:me?S:void 0,stackingEnabled:l,onToggleStacking:c}),t.jsx(Ml,{open:p!==null,onOpenChange:O=>{O||d(null)},title:`Delete ${M} ${M===1?"row":"rows"}?`,description:t.jsxs(t.Fragment,{children:[t.jsx("p",{children:"This action cannot be undone."}),m.error&&t.jsx("p",{className:"mt-2 text-sm text-destructive",children:m.error.message})]}),confirmLabel:`Delete ${M===1?"row":`${M} rows`}`,variant:"destructive",isPending:m.isPending,onConfirm:ue}),t.jsx(Hl,{target:we,onClose:ke,onNavigate:ye,canNavigatePrev:N>0,canNavigateNext:N<A.length-1}),h!==null&&t.jsx(is,{table:e.graphQlName,editid:h,onClose:()=>y(null)})]})}const Ql=new Set(["Int","Int!","Float","Float!"]);function Rl(e){return new Set((e.manyToManyJoins??[]).map(n=>n.junctionTable))}function ms(e){const n=Rl(e),r=e.multiJoins.filter(o=>!n.has(o.destinationTable)).map(o=>({kind:"child",key:`child:${o.fieldName??o.destinationTable}`,join:o})),s=(e.manyToManyJoins??[]).map(o=>({kind:"m2m",key:`m2m:${o.junctionTable}:${o.targetTable}`,m2m:o}));return[...r,...s]}function fs(e,n){const r=new Set([...n.junctionSourceColumnNames,...n.junctionTargetColumnNames]);return e.columns.filter(s=>!s.isPrimaryKey&&!r.has(s.name))}function Yl(e,n){return n&&Ql.has(n)?Number(e):e}function Xl(e,n,r,s){const o=r.junctionSourceColumnNames[0],i=e.columns.find(b=>b.name===o),a=i?i.paramType.replace("!",""):"Int",l=e.primaryKeys??[],c=fs(e,r).map(b=>b.name),m=n.primaryKeys?.length?n.primaryKeys:r.targetColumnNames,p=n.labelColumn,d=[...m];p&&!m.includes(p)&&d.push(`label: ${p}`);const h=`${r.junctionTargetField} { ${d.join(" ")} }`,y=[...l,...c,h].join(" ");return{query:`query GetLinks_${e.name}($id: ${a}, $limit: Int, $offset: Int) { ${e.name}(filter: { ${o}: { _eq: $id } } limit: $limit offset: $offset) { total offset limit data { ${y} } } }`,variables:{id:Yl(s,a)}}}function Ul(e,n){const r=wt(e)[0]?.name??n.targetColumnNames[0],s=e.labelColumn||r,o=s!==r?`${r} label: ${s}`:r;return{query:`query PickTarget($limit: Int) { ${e.name}(limit: $limit sort: [${s}_asc]) { data { ${o} } } }`,idColumn:r}}function Zl(e,n,r){const s=e[n.junctionTargetField];if(!s)return null;const o=Ct(s,r,0),i=s.label!=null?String(s.label):o;return{id:o,label:i}}function ec(e,n,r){if(e.junctionSourceColumnNames.length!==1||e.junctionTargetColumnNames.length!==1)throw new Error("attachJunctionDetail supports single-column junction FKs only; this relationship uses a composite key which is not yet supported.");return{[e.junctionSourceColumnNames[0]]:n,[e.junctionTargetColumnNames[0]]:r}}function tc({parentTable:e,m2m:n,parentRowId:r,onOpenColumn:s}){const o=je(),i=ve(),a=le.useQueryClient(),[l,c]=f.useState(!1),m=o.findTable(n.junctionTable),p=o.findTable(n.targetTable),d=es(m??e),{query:h,variables:y}=m&&p?Xl(m,p,n,r):{query:null,variables:{}},g=["m2mRows",n.junctionTable,n.targetTable,r],{data:b,isLoading:N,error:T}=le.useQuery({queryKey:g,queryFn:()=>i.query(h,{...y,limit:200,offset:0}),enabled:!!h}),j=f.useCallback(()=>a.invalidateQueries({queryKey:g}),[a,g]),$=f.useCallback(async L=>{if(!m)return;const x=Gt(L,m);x&&(await d.deleteRow(x),await j())},[m,d,j]);if(!m||!p)return t.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"Relationship schema unavailable."});const S=b?.[m.name]?.data??[],D=fs(m,n),w=m.isEditable!==!1;return t.jsxs("div",{className:"flex flex-col min-h-0 flex-1 overflow-hidden",children:[t.jsxs("div",{className:"flex items-center gap-2 px-2 py-1 bg-muted/20 border-b border-border shrink-0",children:[t.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full border border-border bg-muted/40 px-2 py-0.5 text-xs text-muted-foreground",title:`Linked through ${m.label}`,children:[t.jsx(v.Link2,{className:"size-3"}),"via ",m.label]}),w&&t.jsxs(q,{variant:"ghost",size:"sm",className:"h-7 px-2 text-xs ml-auto",onClick:()=>c(!0),children:[t.jsx(v.Plus,{className:"size-3 mr-1"})," Add link"]})]}),t.jsxs("div",{className:"flex-1 min-h-0 overflow-auto",children:[T&&t.jsxs("div",{className:"p-3 text-sm text-destructive",children:["Error: ",T.message]}),N&&t.jsxs("div",{className:"flex items-center gap-2 p-3 text-sm text-muted-foreground",children:[t.jsx(v.Loader2,{className:"size-4 animate-spin"})," Loading…"]}),!N&&S.length===0&&t.jsxs("div",{className:"p-3 text-sm text-muted-foreground",children:["No linked ",p.label,"."]}),S.length>0&&t.jsxs("table",{className:"w-full text-sm",children:[t.jsx("thead",{children:t.jsxs("tr",{className:"border-b border-border text-left text-xs text-muted-foreground",children:[t.jsx("th",{className:"px-2 py-1 font-medium",children:p.label}),D.map(L=>t.jsx("th",{className:"px-2 py-1 font-medium",children:L.label},L.name)),w&&t.jsx("th",{className:"px-2 py-1 w-8","aria-label":"actions"})]})}),t.jsx("tbody",{children:S.map((L,x)=>{const k=Zl(L,n,p);return t.jsxs("tr",{className:"border-b border-border/50 hover:bg-muted/30",children:[t.jsx("td",{className:"px-2 py-1",children:k?t.jsxs("span",{className:"inline-flex items-center gap-1",children:[t.jsx(dt,{to:`/${p.name}/${k.id}`,className:"text-primary hover:underline",children:k.label}),s&&t.jsx(q,{variant:"ghost",size:"icon-sm",className:"size-5",onClick:()=>s({tableName:p.name,filterId:k.id}),"aria-label":`Open ${k.label} in side column`,title:"Open in side column",children:t.jsx(v.Search,{className:"size-3"})})]}):t.jsx("span",{className:"text-muted-foreground",children:"—"})}),D.map(V=>t.jsx("td",{className:"px-2 py-1",children:Vt(L[V.name],V)},V.name)),w&&t.jsx("td",{className:"px-2 py-1",children:t.jsx(q,{variant:"ghost",size:"icon-sm",className:"size-6 text-muted-foreground hover:text-destructive",onClick:()=>$(L),disabled:d.isPending,"aria-label":`Detach ${k?.label??"link"}`,title:"Detach",children:t.jsx(v.Unlink,{className:"size-3.5"})})})]},x)})})]})]}),l&&t.jsx(nc,{target:p,junction:m,m2m:n,parentRowId:r,onClose:()=>c(!1),onLinked:j})]})}function nc({target:e,junction:n,m2m:r,parentRowId:s,onClose:o,onLinked:i}){const a=ve(),l=n.columns.filter($=>r.junctionSourceColumnNames.includes($.name)||r.junctionTargetColumnNames.includes($.name)).map($=>({column:$})),c=yn(n,l,[]),[m,p]=f.useState(""),{query:d,idColumn:h}=Ul(e,r),{data:y,isLoading:g}=le.useQuery({queryKey:["m2mTargets",e.name],queryFn:()=>a.query(d,{limit:500})}),b=y?.[e.name]?.data??[],N=m.trim().toLowerCase(),T=N?b.filter($=>String($.label??$[h]??"").toLowerCase().includes(N)):b,j=f.useCallback(async $=>{await c.insert(ec(r,s,$)),await i(),o()},[c,r,s,i,o]);return t.jsx(kt,{open:!0,onOpenChange:$=>{$||o()},children:t.jsxs(Tt,{className:"max-w-md",children:[t.jsx(Kt,{children:t.jsxs(St,{children:["Add ",e.label," link"]})}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(v.Search,{className:"size-4 text-muted-foreground"}),t.jsx(Ne,{autoFocus:!0,placeholder:`Search ${e.label}…`,value:m,onChange:$=>p($.target.value)})]}),c.error&&t.jsx("p",{className:"text-sm text-destructive",children:c.error.message}),t.jsxs("div",{className:"max-h-72 overflow-auto border border-border rounded-md",children:[g&&t.jsxs("div",{className:"flex items-center gap-2 p-3 text-sm text-muted-foreground",children:[t.jsx(v.Loader2,{className:"size-4 animate-spin"})," Loading…"]}),!g&&T.length===0&&t.jsx("div",{className:"p-3 text-sm text-muted-foreground",children:"No matches."}),T.map(($,S)=>{const D=String($[h]??""),w=$.label!=null?String($.label):D;return t.jsx("button",{type:"button",className:"block w-full text-left px-3 py-1.5 text-sm hover:bg-muted/50 disabled:opacity-50",disabled:c.isPending,onClick:()=>j(D),children:w},S)})]})]})})}function ps(e){return e.kind==="child"?e.join.destinationTable:e.m2m.targetTable}function hs({parentTable:e,selectedRowId:n,onClose:r,onOpenColumn:s}){const o=je(),i=ms(e),[a,l]=f.useState(i[0]?.key??""),[c,m]=f.useState(!1),[p,d]=f.useState(null),h=i.find(b=>b.key===a)??i[0];if(f.useEffect(()=>{d(null)},[a,n]),i.length===0||!o.data)return null;const y=h.kind==="child"?o.findTable(h.join.destinationTable):void 0,g=(y?.multiJoins?.length??0)>0;return t.jsxs("div",{className:"border-t-2 border-primary/20 flex flex-col min-h-0 flex-1 overflow-hidden",children:[t.jsxs("div",{className:"flex items-center gap-1 px-2 py-1 bg-muted/30 border-b border-border shrink-0",children:[t.jsx(q,{variant:"ghost",size:"icon-sm",onClick:()=>m(!c),"aria-label":c?"Expand detail panel":"Collapse detail panel",title:c?"Expand detail panel":"Collapse detail panel",children:c?t.jsx(v.ChevronUp,{className:"size-3.5"}):t.jsx(v.ChevronDown,{className:"size-3.5"})}),t.jsx("span",{className:"text-xs text-muted-foreground mr-1",children:"Detail:"}),t.jsx("div",{className:"flex items-center gap-0.5 overflow-x-auto",children:i.map(b=>{const T=o.findTable(ps(b))?.label??ps(b),j=b.key===h.key;return t.jsxs("span",{className:"group/tab inline-flex items-center",children:[t.jsx(q,{variant:j?"secondary":"ghost",size:"sm",className:K("text-xs h-7 px-2.5",j&&"font-semibold"),onClick:()=>l(b.key),children:T}),s&&b.kind==="child"&&t.jsx(q,{variant:"ghost",size:"icon-sm",className:"opacity-0 group-hover/tab:opacity-100 size-5 shrink-0",onClick:()=>s({tableName:b.join.destinationTable,filterTable:e.name,filterId:n,...et(b.join)?{}:{filterColumn:b.join.destinationColumnNames[0]}}),"aria-label":"Open in side column",title:"Open in side column",children:t.jsx(v.PanelRight,{className:"size-3"})})]},b.key)})}),r&&t.jsx(q,{variant:"ghost",size:"icon-sm",onClick:r,className:"ml-auto shrink-0","aria-label":"Close detail panel",title:"Close detail panel",children:t.jsx(v.X,{className:"size-3.5"})})]}),!c&&t.jsx("div",{className:"flex-1 min-h-0 overflow-hidden flex flex-col",children:h.kind==="child"?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:g&&p?"flex-1 min-h-0 max-h-[50%] overflow-hidden flex flex-col":"flex-1 min-h-0 overflow-hidden flex flex-col",children:t.jsx(Tn,{table:y,id:n,tableFilter:e.name,...et(h.join)?{}:{filterColumn:h.join.destinationColumnNames[0]},selectedRowId:g?p:void 0,onRowSelect:g?d:void 0,onOpenColumn:s},`${h.key}-${n}`)}),g&&p&&t.jsx("div",{className:"flex-1 min-h-0 overflow-hidden flex flex-col",children:t.jsx(hs,{parentTable:y,selectedRowId:p,onClose:()=>d(null),onOpenColumn:s})})]}):t.jsx(tc,{parentTable:e,m2m:h.m2m,parentRowId:n,onOpenColumn:s},`${h.key}-${n}`)})]})}const rc={mainTable:null,columns:[],focusedIndex:0,focusColumn:()=>{},closeColumn:()=>{}},xs=f.createContext(rc),gs=f.createContext({register:()=>{},unregister:()=>{}});function sc({children:e}){const[n,r]=f.useState(null),[s,o]=f.useState(0),i=f.useCallback(d=>{r(d)},[]),a=f.useCallback(()=>{r(null),o(0)},[]),l=f.useCallback(d=>{if(o(d),!n)return;const h=n.columnRefs.get(d);h&&h.scrollIntoView({behavior:"smooth",block:"nearest",inline:"nearest"})},[n]),c=f.useCallback(d=>{n&&d>0&&n.onClose(d-1)},[n]),m=n?n.columns.map((d,h)=>({panel:d,element:n.columnRefs.get(h+1)??null})):[],p={mainTable:n?.mainTable??null,columns:m,focusedIndex:s,focusColumn:l,closeColumn:c};return t.jsx(gs.Provider,{value:{register:i,unregister:a},children:t.jsx(xs.Provider,{value:p,children:e})})}function oc(){return f.useContext(xs)}function ac(){return f.useContext(gs)}function bs(e,n){return e.tableName===n.tableName&&e.filterTable===n.filterTable&&e.filterId===n.filterId&&e.filterColumn===n.filterColumn}function ic(e,n){const r=e[e.length-1];if(r&&bs(r,n))return e;const s=e.findIndex(o=>bs(o,n));return s>=0?e.slice(0,s+1):[...e,n]}function lc(e,n){return n<0?[]:n>=e.length?e:e.slice(0,n)}function cc(e,n,r){const s=i=>r(i)??i,o=[{index:-1,label:s(e)}];for(let i=0;i<n.length;i++){const a=n[i],l=a.filterTable?s(a.filterTable):s(i===0?e:n[i-1].tableName),c=a.filterId?`from ${l} #${a.filterId}`:void 0;o.push({index:i,label:s(a.tableName),detail:c,frame:a})}return o}function Rt(e,n){return e.find(r=>r.name===n)}function We(){const e=on(),{table:n,id:r,filterTable:s}=e,{loading:o,error:i,data:a}=je(),[l,c]=f.useState(null),[m,p]=f.useState([]),[d,h]=f.useState(!0),[y,g]=f.useState(new Set),b=f.useRef(n);n!==b.current&&(b.current=n,m.length>0&&p([]),y.size>0&&g(new Set));const N=f.useCallback(E=>{g(Y=>{const se=new Set(Y);return se.has(E)?se.delete(E):se.add(E),se})},[]),{register:T,unregister:j}=ac(),$=f.useRef(null),S=f.useRef(new Map),D=f.useMemo(()=>a?Rt(a,n):void 0,[a,n]),w=D?ms(D).length>0:!1,L=f.useCallback(E=>{p(Y=>ic(Y,E))},[]),x=f.useCallback(E=>{h(E),E||p([])},[]),k=d?L:void 0,V=f.useCallback(E=>{p(Y=>Y.filter((se,ue)=>ue!==E))},[]),I=f.useCallback(E=>{p(Y=>lc(Y,E+1))},[]),A=f.useMemo(()=>cc(n??"",m,E=>{if(a)return Rt(a,E)?.label}),[n,m,a]);if(f.useEffect(()=>{const E=S.current;E.set(0,$.current);for(const Y of E.keys())Y>m.length&&E.delete(Y);return T({mainTable:n,columns:m,columnRefs:E,onClose:V}),()=>j()},[n,m,T,j,V]),!n)return t.jsx("div",{className:"p-5 text-center text-muted-foreground",children:"Table missing"});if(o)return t.jsxs("div",{className:"flex items-center justify-center gap-2 p-5",children:[t.jsx(v.Loader2,{className:"size-4 animate-spin text-muted-foreground"}),t.jsx("span",{className:"text-sm text-muted-foreground",children:"Loading..."})]});if(i)return t.jsx(mt,{variant:"destructive",className:"m-2",children:t.jsxs(ft,{children:["Error: ",i.message]})});if(!D)return t.jsx("div",{className:"p-5 text-center text-muted-foreground",children:"Table not found"});const W=t.jsx(Tn,{table:D,id:r,tableFilter:s,selectedRowId:w?l:void 0,onRowSelect:w?c:void 0,onOpenColumn:k,stackingEnabled:d,onToggleStacking:x});if(m.length===0)return t.jsx("div",{className:"flex flex-col flex-1 min-h-0",children:t.jsxs("div",{ref:$,className:"flex flex-col flex-1 min-h-0 min-w-0",children:[t.jsx("div",{className:w&&l?"flex-1 min-h-0 max-h-[50%] overflow-hidden flex flex-col":"flex-1 min-h-0 overflow-hidden flex flex-col",children:W}),w&&l&&t.jsx("div",{className:"flex-1 min-h-0 overflow-hidden flex flex-col",children:t.jsx(hs,{parentTable:D,selectedRowId:l,onClose:()=>c(null),onOpenColumn:k})})]})});const H=m.length-1,U=(E,Y)=>Y||y.has(E);return t.jsxs("div",{className:"flex flex-col flex-1 min-h-0",children:[t.jsx(dc,{crumbs:A,onCrumbClick:I,activeIndex:m.length-1}),t.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto flex flex-col gap-0.5 p-0.5",children:[t.jsx(ys,{title:D.label,selectedRowId:m[0]?.filterId,expanded:U(-1,!1),active:!1,onToggle:()=>N(-1),onRef:E=>{$.current=E,S.current.set(0,E)},children:W}),m.map((E,Y)=>{const se=Y===H;return t.jsx(ys,{title:Rt(a,E.tableName)?.label??E.tableName,selectedRowId:m[Y+1]?.filterId,expanded:U(Y,se),active:se,onToggle:()=>N(Y),onClose:()=>V(Y),onRef:ue=>{S.current.set(Y+1,ue)},children:t.jsx(Tn,{table:Rt(a,E.tableName),id:E.filterId,tableFilter:E.filterTable,filterColumn:E.filterColumn,onOpenColumn:L})},`${E.tableName}-${E.filterId??""}-${E.filterColumn??""}-${Y}`)})]})]})}function dc({crumbs:e,onCrumbClick:n,activeIndex:r}){return t.jsx("nav",{"aria-label":"Drill-down breadcrumb",className:"flex items-center gap-1 px-2 py-1 bg-muted/20 border-b border-border shrink-0 overflow-x-auto",children:e.map((s,o)=>{const i=s.index===r,a=o===0;return t.jsxs("span",{className:"inline-flex items-center gap-1 shrink-0",children:[!a&&t.jsx(v.ChevronRight,{className:"size-3 text-muted-foreground shrink-0"}),t.jsxs(q,{variant:i?"secondary":"ghost",size:"sm",className:K("h-6 px-2 text-xs gap-1",i&&"font-semibold"),onClick:()=>n(s.index),"aria-current":i?"page":void 0,title:s.detail?`${s.label} (${s.detail})`:s.label,children:[a&&t.jsx(v.Home,{className:"size-3"}),t.jsx("span",{className:"truncate max-w-[12rem]",children:s.label}),s.detail&&t.jsx("span",{className:"text-muted-foreground font-normal truncate max-w-[10rem]",children:s.detail})]})]},`${s.index}-${s.label}`)})})}function ys({title:e,selectedRowId:n,expanded:r,active:s,onToggle:o,onClose:i,onRef:a,children:l}){return t.jsxs("div",{ref:a,className:"shrink-0 flex flex-col border border-border rounded-sm overflow-hidden",children:[t.jsxs("div",{className:"flex items-center gap-1 px-2 py-1 bg-muted/30 border-b border-border shrink-0",children:[t.jsx("button",{type:"button",onClick:o,className:"inline-flex items-center justify-center size-5 shrink-0 text-muted-foreground hover:text-foreground","aria-expanded":r,"aria-label":r?"Collapse table":"Expand table",title:r?"Collapse":"Expand",children:r?t.jsx(v.ChevronDown,{className:"size-3.5"}):t.jsx(v.ChevronRight,{className:"size-3.5"})}),t.jsx("span",{className:"text-xs font-medium truncate",children:e}),s&&t.jsx("span",{className:"text-[10px] uppercase tracking-wide text-primary/70 shrink-0",children:"active"}),!r&&n&&t.jsxs("span",{className:"text-xs text-muted-foreground truncate",children:["#",n]}),t.jsx("div",{className:"flex-1"}),i&&t.jsx(q,{variant:"ghost",size:"icon-sm",className:"shrink-0",onClick:i,"aria-label":"Close column",title:"Close column",children:t.jsx(v.X,{className:"size-3.5"})})]}),r&&t.jsx("div",{className:"flex flex-col min-h-[18rem] max-h-[34rem]",children:l})]})}function Sn(){const e=on(),{loading:n,error:r,data:s}=je(),{mainTable:o,columns:i,focusedIndex:a,focusColumn:l,closeColumn:c}=oc(),[m,p]=f.useState(""),d=Dt(),{search:h}=Yn(),y=!!h.get("filter"),{back:g,hasBack:b}=io(),N=e?.table,T=i.length>0,j=f.useMemo(()=>s?.find(x=>x.graphQlName===N),[s,N]),$=f.useMemo(()=>j?.columns?.map(x=>({key:x.name,value:`${x.name},${x.paramType}`,label:x.label})),[j]),[S,D]=f.useState($?.at(0)?.value??"");f.useEffect(()=>{p(""),D($?.at(0)?.value??"")},[$]);const w=()=>{if(!m)return;const[x,k]=S.split(",");(k==="Int"||k==="Int!"||k==="Float"||k==="Float!")&&d(`?filter=["${x}", "_eq", ${m}, "${k}"]`),(k==="String"||k==="String!")&&d(`?filter=["${x}", "_contains", "${m}", "${k}"]`)},L=()=>{p("");const x=new URLSearchParams(h.toString());x.delete("filter");const k=x.toString();d(k?`?${k}`:"?")};return n?t.jsxs("div",{className:"flex items-center gap-2 p-2.5",children:[t.jsx(v.Loader2,{className:"size-4 animate-spin text-muted-foreground"}),t.jsx("span",{className:"text-sm text-muted-foreground",children:"Loading..."})]}):r?t.jsx(mt,{variant:"destructive",className:"m-2",children:t.jsxs(ft,{children:["Error: ",r.message]})}):t.jsxs("header",{className:"flex flex-wrap items-center gap-x-3 gap-y-1.5 px-3 py-1.5 min-h-[2.5rem]",children:[t.jsxs("div",{className:"flex items-center gap-1.5 overflow-x-auto min-w-0 flex-1",children:[t.jsx(q,{variant:"ghost",size:"icon-sm",onClick:()=>b&&g(),disabled:!b,"aria-label":"Go back",title:"Go back",className:"shrink-0",children:t.jsx(v.ChevronLeft,{className:"size-4"})}),T?t.jsxs("div",{className:"flex items-center gap-1 overflow-x-auto",children:[t.jsx("button",{type:"button",onClick:()=>l(0),className:`flex items-center gap-1 px-2 py-0.5 rounded text-xs font-medium whitespace-nowrap transition-colors ${a===0?"bg-primary text-primary-foreground":"bg-muted/50 text-muted-foreground hover:bg-muted"}`,children:j?.label??It(e?.table??"")}),i.map((x,k)=>{const I=s?.find(A=>A.graphQlName===x.panel.tableName)?.label??It(x.panel.tableName);return t.jsxs("button",{type:"button",onClick:()=>l(k+1),className:`flex items-center gap-1 px-2 py-0.5 rounded text-xs font-medium whitespace-nowrap transition-colors ${a===k+1?"bg-primary text-primary-foreground":"bg-muted/50 text-muted-foreground hover:bg-muted"}`,children:[I,t.jsx("span",{role:"button",tabIndex:0,onClick:A=>{A.stopPropagation(),c(k+1)},onKeyDown:A=>{(A.key==="Enter"||A.key===" ")&&(A.stopPropagation(),c(k+1))},className:"ml-0.5 rounded-sm hover:bg-background/50 p-px","aria-label":`Close ${I}`,children:t.jsx(v.X,{className:"size-3"})})]},`${x.panel.tableName}-${x.panel.filterId??k}`)})]}):t.jsx("h2",{className:"text-sm font-semibold whitespace-nowrap",children:j?.dbName??e?.table??"(Select)"})]}),$?t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex items-center border border-border rounded-md overflow-hidden flex-[2_2_16rem] min-w-[12rem]",children:[t.jsxs(_e,{value:S,onValueChange:D,children:[t.jsx(Pe,{size:"sm",className:"w-auto min-w-[120px] shrink-0 border-0 rounded-none border-r border-border h-8 text-xs",children:t.jsx(ze,{})}),t.jsx(Ee,{children:$.map(x=>t.jsx(Ce,{value:x.value,children:x.label},x.key))})]}),t.jsxs("div",{className:"relative flex-1 min-w-[180px]",children:[t.jsx(v.Search,{className:"absolute left-3 top-1/2 -translate-y-1/2 size-3.5 text-muted-foreground pointer-events-none"}),t.jsx(Ne,{type:"search",value:m,onChange:x=>p(x.target.value),onKeyDown:x=>x.key==="Enter"&&w(),className:"h-8 border-0 rounded-none focus-visible:ring-0 focus-visible:ring-offset-0",style:{paddingLeft:"2.25rem"},placeholder:"Search..."})]}),t.jsxs(q,{variant:"ghost",size:"sm",onClick:w,className:"shrink-0 rounded-none border-l border-border h-8 px-3 text-xs",children:[t.jsx(v.Filter,{className:"size-3.5"}),"Filter"]}),y&&t.jsx(q,{variant:"ghost",size:"sm",onClick:L,title:"Clear filter","aria-label":"Clear filter",className:"shrink-0 rounded-none border-l border-border h-8 px-2 text-xs text-muted-foreground",children:t.jsx(v.X,{className:"size-3.5"})})]}),t.jsxs("div",{className:"flex items-center gap-px border border-border rounded-md overflow-hidden shrink-0",children:[t.jsxs(q,{variant:"ghost",size:"sm",onClick:()=>d("/"),className:"text-muted-foreground text-xs h-8 px-3 rounded-none",children:[t.jsx(v.X,{className:"size-3.5"}),"Clear"]}),j?.isEditable&&t.jsxs(q,{variant:"default",size:"sm",onClick:()=>d("edit/"),className:"h-8 text-xs px-4 rounded-none",children:[t.jsx(v.Plus,{className:"size-3.5"}),"Add"]})]})]}):null]})}class Yt extends f.Component{constructor(n){super(n),this.state={hasError:!1,error:null}}static getDerivedStateFromError(n){return{hasError:!0,error:n}}componentDidCatch(n,r){const{onError:s,section:o}=this.props;console.error(`Error in ${o??"component"}:`,n,r),s?.(n,r)}handleRetry=()=>{this.setState({hasError:!1,error:null})};render(){const{hasError:n,error:r}=this.state,{children:s,fallback:o,section:i}=this.props;return n?o||t.jsx("div",{className:"flex items-center justify-center p-5 min-h-[100px]",children:t.jsxs(mt,{variant:"destructive",className:"max-w-[400px]",children:[t.jsx(v.AlertCircle,{className:"size-4"}),t.jsxs(Fr,{children:["Something went wrong",i?` in ${i}`:""]}),t.jsxs(ft,{className:"mt-2",children:[t.jsx("p",{children:r?.message??"An unexpected error occurred"}),t.jsx(q,{variant:"destructive",size:"sm",className:"mt-3",onClick:this.handleRetry,children:"Try Again"})]})]})}):s}}function uc(){const{loading:e,error:n,data:r}=je();return e?t.jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-3 text-muted-foreground",children:[t.jsx(v.Database,{className:"size-10 animate-pulse"}),t.jsx("p",{className:"text-sm",children:"Loading schema..."})]}):n?t.jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-4 max-w-md mx-auto text-center",children:[t.jsx(v.Database,{className:"size-12 text-destructive"}),t.jsxs("div",{children:[t.jsx("h2",{className:"text-lg font-semibold text-foreground",children:"Connection Error"}),t.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:n.message})]})]}):r.length===0?t.jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-4 max-w-md mx-auto text-center",children:[t.jsx(v.Database,{className:"size-12 text-muted-foreground/50"}),t.jsxs("div",{children:[t.jsx("h2",{className:"text-lg font-semibold text-foreground",children:"No Tables Found"}),t.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"This database doesn't contain any tables. It may be a new or empty database."}),t.jsx("p",{className:"mt-3 text-xs text-muted-foreground/70",children:"Create tables in your database and reconnect, or try a different connection."})]})]}):t.jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-6 max-w-lg mx-auto text-center",children:[t.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground/50",children:[t.jsx(v.Table2,{className:"size-10"}),t.jsx(v.MousePointerClick,{className:"size-6"})]}),t.jsxs("div",{children:[t.jsx("h2",{className:"text-lg font-semibold text-foreground",children:"Select a Table"}),t.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Choose a table from the sidebar to browse and edit its data."})]}),t.jsxs("div",{className:"text-xs text-muted-foreground/60 border border-border rounded-md px-4 py-3 bg-muted/30",children:[t.jsxs("p",{className:"font-medium text-muted-foreground mb-1",children:[r.length," table",r.length!==1?"s":""," available"]}),t.jsxs("p",{className:"leading-relaxed",children:[r.slice(0,8).map(s=>s.label).join(", "),r.length>8?`, and ${r.length-8} more`:""]})]})]})}function mc({children:e}){const{loading:n,error:r}=je();return n?t.jsxs("div",{className:"flex items-center justify-center flex-1 gap-3 text-muted-foreground",children:[t.jsx(v.Loader2,{className:"size-6 animate-spin"}),t.jsx("span",{className:"text-sm",children:"Connecting to database..."})]}):r?t.jsx("div",{className:"flex items-center justify-center flex-1",children:t.jsxs(mt,{variant:"destructive",className:"max-w-lg",children:[t.jsx(v.AlertCircle,{className:"size-4"}),t.jsx(Fr,{children:"Database Connection Error"}),t.jsxs(ft,{className:"mt-2",children:[t.jsx("p",{className:"text-sm",children:r.message}),t.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:"Check your connection string and ensure the database server is running."})]})]})}):t.jsx(t.Fragment,{children:e})}const vs=()=>t.jsxs("div",{className:"flex items-center justify-center gap-2 p-4",children:[t.jsx(v.Loader2,{className:"size-4 animate-spin text-muted-foreground"}),t.jsx("span",{className:"text-sm text-muted-foreground",children:"Loading..."})]});function fc(){const[e,n]=f.useState(!0);return t.jsx(mc,{children:t.jsx(sc,{children:t.jsxs("div",{className:`grid h-full flex-1 min-h-0 grid-rows-[auto_1fr] ${e?"grid-cols-[minmax(150px,min-content)_1fr]":"grid-cols-[0px_1fr]"} md:grid-cols-[minmax(150px,min-content)_1fr] transition-[grid-template-columns] duration-200`,children:[t.jsxs("div",{className:"col-span-full sticky top-0 z-50 bg-background border-b border-border flex items-center",children:[t.jsx(q,{variant:"ghost",size:"icon",className:"md:hidden ml-1 shrink-0",onClick:()=>n(!e),"aria-label":"Toggle sidebar",title:"Toggle sidebar",children:t.jsx(v.PanelLeft,{className:"size-5"})}),t.jsx("div",{className:"flex-1 min-w-0",children:t.jsx(Yt,{section:"Header",children:t.jsxs(an,{children:[t.jsx(he,{path:"/:table/*",element:t.jsx(Sn,{})}),t.jsx(he,{path:"/:table",element:t.jsx(Sn,{})}),t.jsx(he,{path:"/",element:t.jsx(Sn,{})})]})})})]}),t.jsx("nav",{"aria-label":"Tables",className:`border-r border-border overflow-hidden min-h-0 ${e?"":"hidden"} md:block`,children:t.jsx(Yt,{section:"Table List",children:t.jsx(Fa,{})})}),t.jsxs("main",{className:"flex flex-col overflow-hidden min-h-0 px-1 py-0.5",children:[t.jsx(Yt,{section:"Data Panel",children:t.jsx(f.Suspense,{fallback:t.jsx(vs,{}),children:t.jsxs(an,{children:[t.jsx(he,{path:"/:table/from/:filterTable/:id/edit/:editid",element:t.jsx(We,{})}),t.jsx(he,{path:"/:table/from/:filterTable/:id",element:t.jsx(We,{})}),t.jsx(he,{path:"/:table/:id/edit/:editid",element:t.jsx(We,{})}),t.jsx(he,{path:"/:table/:id",element:t.jsx(We,{})}),t.jsx(he,{path:"/:table/edit/:editid",element:t.jsx(We,{})}),t.jsx(he,{path:"/:table/edit",element:t.jsx(We,{})}),t.jsx(he,{path:"/:table",element:t.jsx(We,{})}),t.jsx(he,{path:"/",element:t.jsx(uc,{})})]})})}),t.jsx(Yt,{section:"Data Edit",children:t.jsx(f.Suspense,{fallback:t.jsx(vs,{}),children:t.jsxs(an,{children:[t.jsx(he,{path:"/:table/from/:filterTable/:id/edit/:editid",element:t.jsx(Jt,{})}),t.jsx(he,{path:"/:table/:id/edit/:editid",element:t.jsx(Jt,{})}),t.jsx(he,{path:"/:table/edit/:editid",element:t.jsx(Jt,{})}),t.jsx(he,{path:"/:table/edit",element:t.jsx(Jt,{})})]})})})]})]})})})}function pc({onLocate:e}){const n=Rn();return f.useEffect(()=>{e?.(n)},[n,e]),t.jsx(fc,{})}function js({uri:e,fetcher:n,uiPath:r,onLocate:s,showStats:o=!1}){const i=f.useMemo(()=>n||(e?new Zn(e):null),[e,n]),a=f.useMemo(()=>new le.QueryClient({defaultOptions:{queries:{staleTime:300*1e3,retry:1}}}),[]);return i?t.jsx(le.QueryClientProvider,{client:a,children:t.jsx(go,{value:i,children:t.jsx(Na,{config:{showStats:o},children:t.jsx(lo,{path:r||"/",children:t.jsx(jo,{children:t.jsx(pc,{onLocate:s})})})})})}):t.jsx("section",{children:"CONFIG MISSING..."})}fe.Editor=js,fe.HttpGraphQLFetcher=Zn,fe.default=js,fe.useTableMutation=yn,Object.defineProperties(fe,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));
106
+ }`},[a,l,x]),{isLoading:k,error:$,data:w}=me.useQuery({queryKey:["editRecord",a.name,r],queryFn:()=>o.query(b,x.variables),enabled:!!a&&!i&&x.filterText!==""}),P=c.useMemo(()=>w?.value?.data?.at(0)??{},[w]),C=c.useMemo(()=>{const z={};for(const{column:I,fkRole:_}of l){const G=_!=="none"||I.enumValues!==void 0&&I.enumValues.length>0;if(_n(I))z[I.name]=hs(P[I.name],Fn(I));else if(Pn.some(U=>U===I.paramType)){const U=P[I.name];z[I.name]=I.isNullable&&U==null?null:!!U}else if(lt(I)){const U=P[I.name];z[I.name]=U==null?"":JSON.stringify(U,null,2)}else if(G){const U=P[I.name];z[I.name]=U??null}else z[I.name]=P[I.name]??""}return z},[P,l]),T=Bt.useForm({defaultValues:C,onSubmit:async({value:z})=>{const I=hl(z,P,l.map(({column:G})=>G));await(i?m.insert:m.update)(I),s()}}),j=Bt.useStore(T.store,z=>z.isDirty),[E,y]=c.useState(!1),S=()=>{j?y(!0):s()};if(k&&!i)return t.jsx(Ze,{open:!0,onOpenChange:z=>{z||s()},children:t.jsxs(et,{showCloseButton:!1,className:"sm:max-w-2xl",children:[t.jsx(tt,{className:"sr-only",children:"Loading record"}),t.jsx(jt,{className:"sr-only",children:"Loading record for editing"}),t.jsxs("div",{className:"flex items-center justify-center gap-2 py-10 text-sm text-muted-foreground",children:[t.jsx(N.LoaderCircle,{className:"size-4 animate-spin"}),"Loading…"]})]})});if($)return t.jsxs("div",{children:["Error: ",$.message]});if(g)return t.jsx(Ze,{open:!0,onOpenChange:z=>{z||s()},children:t.jsxs(et,{showCloseButton:!1,className:"sm:max-w-md",children:[t.jsx(tt,{className:"text-sm font-semibold",children:"Cannot edit record"}),t.jsxs(jt,{className:"text-sm text-muted-foreground",children:["This record can't be opened for editing: its key (",r||"empty",") is missing or malformed for the ",p," table. Return to the grid and try again."]}),t.jsx("div",{className:"flex justify-end",children:t.jsx(W,{type:"button",size:"sm",onClick:s,children:"Close"})})]})});const L=P?.[d]??r,v=l.filter(({column:z})=>Pn.some(I=>I===z.paramType)),M=l.filter(({column:z})=>js(z)),O=l.filter(({column:z})=>!Pn.some(I=>I===z.paramType)&&!js(z));return t.jsxs(Ze,{open:!0,onOpenChange:z=>{z||S()},children:[t.jsxs(et,{showCloseButton:!1,className:"sm:max-w-2xl max-h-[90vh] flex flex-col gap-0 p-0 overflow-hidden",children:[t.jsxs("div",{className:"flex items-center justify-between px-5 py-3 border-b border-border bg-muted/30 shrink-0",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsx(tt,{className:"text-sm font-semibold truncate",children:i?`New ${p}`:`${p} : ${L}`}),t.jsxs(jt,{className:"sr-only",children:[i?"Create":"Edit"," ",p," record"]})]}),t.jsx(W,{type:"button",variant:"ghost",size:"icon-sm",onClick:S,"aria-label":"Close",className:"shrink-0 -mr-1",children:t.jsx(N.X,{className:"size-4"})})]}),m.error&&t.jsxs("div",{className:"flex items-center gap-2 px-5 py-2 bg-destructive/10 border-b border-destructive/20 text-destructive text-sm shrink-0",children:[t.jsx(N.AlertCircle,{className:"size-3.5 shrink-0"}),t.jsx("span",{className:"truncate",children:m.error.message})]}),t.jsxs("form",{onSubmit:z=>{z.preventDefault(),z.stopPropagation(),T.handleSubmit()},className:"flex flex-col flex-1 min-h-0",children:[t.jsxs("div",{className:"flex-1 overflow-y-auto px-5 py-4",children:[O.length>0&&t.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-x-4 gap-y-3",children:O.map(({column:z,join:I,fkRole:_})=>t.jsx(kl,{column:z,join:I,fkRole:_,form:T,schema:n},z.name))}),v.length>0&&t.jsx("div",{className:O.length>0?"mt-4 pt-4 border-t border-border":"",children:t.jsx("div",{className:"flex flex-wrap gap-x-6 gap-y-2",children:v.map(({column:z})=>t.jsx(Sl,{column:z,form:T},z.name))})}),M.length>0&&t.jsx("div",{className:O.length>0||v.length>0?"mt-4 pt-4 border-t border-border":"",children:t.jsx("div",{className:"grid gap-3",children:M.map(({column:z})=>t.jsx($l,{column:z,form:T},z.name))})})]}),t.jsxs("div",{className:"flex items-center justify-end gap-2 px-5 py-3 border-t border-border bg-muted/30 shrink-0",children:[t.jsx(W,{type:"button",variant:"outline",size:"sm",onClick:S,children:"Cancel"}),t.jsxs(W,{type:"submit",size:"sm",disabled:m.isPending,children:[m.isPending?t.jsx(N.LoaderCircle,{className:"size-3.5 animate-spin"}):t.jsx(N.Save,{className:"size-3.5"}),i?"Create":"Save"]})]})]})]}),t.jsx(En,{open:E,onOpenChange:y,title:"Discard unsaved changes?",description:t.jsx("p",{children:"You have unsaved changes. Closing now will discard them."}),confirmLabel:"Discard",cancelLabel:"Keep editing",variant:"destructive",onConfirm:()=>{y(!1),s()}})]})}function on(){const{table:e,editid:n}=mn(),r=Wt();return e?t.jsx(ws,{table:e,editid:n??"",onClose:()=>r("../..")}):t.jsx("div",{children:"Table missing"})}function ws({table:e,editid:n,onClose:r}){const s=Pe();return e?s.loading?t.jsx("div",{children:"Loading..."}):s.error?t.jsxs("div",{children:["Error: ",s.error.message]}):s.findTable(e)?t.jsx(Nl,{table:e,schema:s,editid:n,onClose:r}):t.jsxs("div",{className:"p-4 text-sm text-destructive",children:["Table not found: ",e]}):t.jsx("div",{children:"Table missing"})}function wl({current:e,max:n}){const r=n-e,s=r<=10&&r>0,o=r<=0;return t.jsx("div",{className:"text-xs text-right mt-0.5","aria-live":"polite",children:t.jsxs("span",{className:o?"text-destructive font-medium":s?"text-amber-500":"text-muted-foreground",children:[e,"/",n]})})}function Cl({min:e,max:n,step:r}){if(e===void 0&&n===void 0)return null;let s="";return e!=null&&n!==void 0&&n!==null?s=`Range: ${e} to ${n}`:e!=null?s=`Min: ${e}`:n!=null&&(s=`Max: ${n}`),r!=null&&r!==1&&(s+=` (step: ${r})`),t.jsx("div",{className:"text-xs text-muted-foreground mt-0.5","aria-live":"polite",children:s})}function kl({column:e,join:n,fkRole:r,form:s,schema:o}){const i=e.name,a=!e.isNullable;if(r==="member-composite")return null;const l=_n(e),u=vl.some(h=>h===e.paramType),d=e.maxLength&&e.maxLength>0&&!l&&!u;if(e.enumValues&&e.enumValues.length>0)return t.jsx(Tl,{column:e,form:s,isRequired:a});if(n&&o)return r==="anchor-composite"?t.jsx(Fl,{column:e,join:n,form:s,schema:o,isRequired:a}):t.jsx(_l,{column:e,join:n,form:s,schema:o,isRequired:a});const p=e.inputType||(l?Fn(e)?"datetime-local":"date":u?"number":"text"),m=`${i}-error`;return t.jsx(s.Field,{name:i,validators:At(e,a),children:h=>{const{ariaProps:x}=qt(h,m);return t.jsxs("div",{className:"grid gap-1",children:[t.jsxs(ct,{htmlFor:i,className:"text-xs text-muted-foreground",children:[e.label,a&&t.jsx("span",{className:"text-destructive ml-0.5",children:"*"})]}),t.jsx(ke,{id:i,type:p,value:h.state.value??"",onChange:g=>h.handleChange(g.target.value),onBlur:h.handleBlur,required:a,maxLength:e.maxLength,minLength:e.minLength,min:e.min,max:e.max,step:e.step,pattern:e.pattern,title:e.patternMessage,...x,className:"h-8 text-sm"}),d&&t.jsx(wl,{current:String(h.state.value??"").length,max:e.maxLength}),u&&(e.min!==void 0||e.max!==void 0)&&t.jsx(Cl,{min:e.min,max:e.max,step:e.step}),t.jsx(Vt,{errors:h.state.meta.errors,id:m})]})}})}function Tl({column:e,form:n,isRequired:r}){const s=e.name,o=e.enumValues||[],i=e.enumLabels&&e.enumLabels.length===o.length?e.enumLabels:o,a=`${s}-error`;return t.jsx(n.Field,{name:s,validators:At(e,r),children:l=>{const{ariaProps:u}=qt(l,a);return t.jsxs("div",{className:"grid gap-1",children:[t.jsxs(ct,{htmlFor:s,className:"text-xs text-muted-foreground",children:[e.label,r&&t.jsx("span",{className:"text-destructive ml-0.5",children:"*"})]}),t.jsxs(Le,{value:vs(l.state.value,!r),onValueChange:d=>l.handleChange(d===nt?null:d),children:[t.jsx(Ae,{id:s,className:"w-full h-8 text-sm",...u,children:t.jsx(Oe,{placeholder:`Select ${e.label}`})}),t.jsxs(qe,{children:[!r&&t.jsx(ge,{value:nt,className:"text-muted-foreground",children:"(none)"}),o.map((d,p)=>t.jsx(ge,{value:d,children:i[p]||d},d))]})]}),t.jsx(Vt,{errors:l.state.meta.errors,id:a})]})}})}const Dn="true",Cs="false";function Sl({column:e,form:n}){const r=e.name;return e.isNullable?t.jsx(n.Field,{name:r,children:s=>{const o=s.state.value,i=o==null?nt:o?Dn:Cs;return t.jsxs("div",{className:"grid gap-1 min-w-[10rem]",children:[t.jsx(ct,{htmlFor:r,className:"text-xs text-muted-foreground",children:e.label}),t.jsxs(Le,{value:i,onValueChange:a=>s.handleChange(a===nt?null:a===Dn),children:[t.jsx(Ae,{id:r,className:"w-full h-8 text-sm",children:t.jsx(Oe,{})}),t.jsxs(qe,{children:[t.jsx(ge,{value:nt,className:"text-muted-foreground",children:"(unset)"}),t.jsx(ge,{value:Dn,children:"Yes"}),t.jsx(ge,{value:Cs,children:"No"})]})]})]})}}):t.jsx(n.Field,{name:r,children:s=>t.jsxs("label",{htmlFor:r,className:"flex items-center gap-2 cursor-pointer select-none",children:[t.jsx(zn,{id:r,checked:!!s.state.value,onCheckedChange:o=>s.handleChange(!!o),onBlur:s.handleBlur}),t.jsx("span",{className:"text-sm",children:e.label})]})})}function $l({column:e,form:n}){const r=e.name,s=!e.isNullable,o=`${r}-error`;return t.jsx(n.Field,{name:r,validators:At(e,s),children:i=>{const{hasError:a}=qt(i,o);return t.jsxs("div",{className:"grid gap-1",children:[t.jsxs(ct,{htmlFor:r,className:"text-xs text-muted-foreground",children:[e.label,s&&t.jsx("span",{className:"text-destructive ml-0.5",children:"*"})]}),t.jsx(bl,{name:r,label:e.label,value:String(i.state.value??""),dbType:e.dbType,onChange:l=>i.handleChange(l),onBlur:i.handleBlur,required:s,invalid:a}),t.jsx(Vt,{errors:i.state.meta.errors,id:o})]})}})}function _l({column:e,join:n,form:r,schema:s,isRequired:o}){const i=e.name,a=n.destinationColumnNames[0],[l,u]=c.useState(""),[d,p]=c.useState(""),[m,h]=c.useState(!1);c.useEffect(()=>{const T=setTimeout(()=>p(l),300);return()=>clearTimeout(T)},[l]);const x=rl(s,n.destinationTable,a,d,m),g=Bt.useStore(r.store,T=>T.values?.[i]),b=g==null||g===""||x.data.some(T=>String(T.key)===String(g)),k=sl(s,n.destinationTable,a,!x.loading&&!b?g:null),$=`${i}-error`,w=d.trim(),P=x.serverSearch||!w?x.data:x.data.filter(T=>xs(T,"key",w)),C=g==null||g===""?null:x.data.find(T=>String(T.key)===String(g))??k.value??{key:String(g),label:String(g)};return t.jsx(r.Field,{name:i,validators:At(e,o),children:T=>{const{ariaProps:j}=qt(T,$);return t.jsxs("div",{className:"grid gap-1",children:[t.jsxs(ct,{htmlFor:i,className:"text-xs text-muted-foreground",children:[e.label,o&&t.jsx("span",{className:"text-destructive ml-0.5",children:"*"})]}),t.jsxs(Le,{value:vs(T.state.value,!o),onValueChange:E=>T.handleChange(E===nt?null:E),onOpenChange:E=>{h(E),E||(u(""),p(""))},children:[t.jsx(Ae,{id:i,className:"w-full h-8 text-sm",...j,children:t.jsx(Oe,{placeholder:`Select ${e.label}`})}),t.jsxs(qe,{children:[t.jsx("div",{className:"px-1 pb-1 sticky top-0 bg-popover z-10",children:t.jsx(ke,{value:l,onChange:E=>u(E.target.value),onKeyDown:E=>{(E.key.length===1||E.key==="Backspace"||E.key==="Delete")&&E.stopPropagation()},placeholder:"Search…",className:"h-7 text-xs"})}),!o&&t.jsx(ge,{value:nt,className:"text-muted-foreground",children:"(none)"}),C&&!P.some(E=>String(E.key)===String(C.key))&&t.jsx(ge,{value:String(C.key),children:C.label}),P.map(E=>t.jsx(ge,{value:String(E.key),children:E.label},E.key)),P.length===0&&t.jsx("div",{className:"px-2 py-1.5 text-xs text-muted-foreground",children:"No matches."})]})]}),x.error!=null&&t.jsxs("p",{className:"text-xs text-destructive",role:"alert",children:["Failed to load ",e.label," options: ",String(x.error?.message??x.error)]}),t.jsx(Vt,{errors:T.state.meta.errors,id:$})]})}})}function Fl({column:e,join:n,form:r,schema:s,isRequired:o}){const i=n.sourceColumnNames??[],a=n.destinationColumnNames??[],[l,u]=c.useState(""),[d,p]=c.useState(""),[m,h]=c.useState(!1);c.useEffect(()=>{const C=setTimeout(()=>p(l),300);return()=>clearTimeout(C)},[l]);const x=Bt.useStore(r.store,C=>{const T={};for(let j=0;j<i.length;j++)T[a[j]]=C.values?.[i[j]];return T}),g=il(s,n.destinationTable,a,{search:d,enabled:m,currentValues:x}),b=c.useMemo(()=>{const C=[];for(let T=0;T<i.length;T++){const j=x[a[T]];if(j==null||j==="")return"";C.push(j)}return xt(C)},[x,i,a]),k=d.trim(),$=g.serverSearch||!k?g.data:g.data.filter(C=>C.label.toLowerCase().includes(k.toLowerCase())),w=C=>{const T=g.data.find(j=>j.route===C);if(T)for(let j=0;j<i.length;j++){const E=a[j],y=i[j];r.setFieldValue(y,T.values[E])}},P=`${e.name}-error`;return t.jsx(r.Field,{name:e.name,validators:At(e,o),children:C=>{const{ariaProps:T}=qt(C,P);return t.jsxs("div",{className:"grid gap-1 sm:col-span-2",children:[t.jsxs(ct,{htmlFor:e.name,className:"text-xs text-muted-foreground",children:[e.label,o&&t.jsx("span",{className:"text-destructive ml-0.5",children:"*"}),t.jsxs("span",{className:"ml-2 px-1 rounded bg-primary/10 text-[10px] font-medium text-primary",children:["composite FK (",i.length," cols)"]})]}),t.jsxs(Le,{value:b,onValueChange:w,onOpenChange:j=>{h(j),j||(u(""),p(""))},children:[t.jsx(Ae,{id:e.name,className:"w-full h-8 text-sm",...T,children:t.jsx(Oe,{placeholder:`Select ${e.label}`})}),t.jsxs(qe,{children:[t.jsx("div",{className:"px-1 pb-1 sticky top-0 bg-popover z-10",children:t.jsx(ke,{value:l,onChange:j=>u(j.target.value),onKeyDown:j=>{(j.key.length===1||j.key==="Backspace"||j.key==="Delete")&&j.stopPropagation()},placeholder:"Search…",className:"h-7 text-xs"})}),$.map(j=>t.jsx(ge,{value:j.route,children:j.label},j.route)),$.length===0&&t.jsx("div",{className:"px-2 py-1.5 text-xs text-muted-foreground",children:"No matches."})]})]}),g.error!=null&&t.jsxs("p",{className:"text-xs text-destructive",role:"alert",children:["Failed to load ",e.label," options: ",String(g.error?.message??g.error)]}),t.jsx(Vt,{errors:C.state.meta.errors,id:P})]})}})}function Vt({errors:e,id:n}){return e.length===0?null:t.jsx("div",{id:n,role:"alert",children:e.map((r,s)=>t.jsx("p",{className:"text-xs text-destructive",children:String(r)},s))})}const ks=40,Ts=32;function zl({className:e,...n}){return t.jsx("div",{"data-slot":"table-container",className:"relative w-full h-full overflow-x-auto",children:t.jsx("table",{"data-slot":"table",className:H("min-w-full caption-bottom text-sm border-separate border-spacing-0",e),...n})})}function El({className:e,...n}){return t.jsx("thead",{"data-slot":"table-header",className:H("[&_tr]:border-b",e),...n})}function Pl({className:e,...n}){return t.jsx("tbody",{"data-slot":"table-body",className:H("[&_tr:last-child]:border-0 [&_tr:nth-child(even)]:bg-muted/25",e),...n})}function an({className:e,style:n,...r}){return t.jsx("tr",{"data-slot":"table-row",className:H("border-b transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",e),style:{height:ks,...n},...r})}function Dl({className:e,style:n,...r}){return t.jsx("th",{"data-slot":"table-head",className:H("px-2 text-left align-middle font-medium whitespace-nowrap text-muted-foreground text-xs border-r border-border last:border-r-0 [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",e),style:{height:Ts,...n},...r})}function Mn({className:e,...n}){return t.jsx("td",{"data-slot":"table-cell",className:H("px-2 py-1 align-middle whitespace-nowrap text-[13px] overflow-hidden text-ellipsis border-r border-border last:border-r-0 [&:has([role=checkbox])]:pr-0 [&>[role=checkbox]]:translate-y-[2px]",e),...n})}function Ml({anchorEl:e,onEdit:n,onDelete:r,onMouseEnter:s,onDismiss:o}){const i=c.useRef(null);return c.useEffect(()=>{const a=i.current;return a?((()=>{const u=e.getBoundingClientRect(),d=a.offsetHeight,p=a.offsetWidth;a.style.top=`${u.top+(u.height-d)/2}px`;const m=Math.min(u.right-p-8,window.innerWidth-p-8);a.style.left=`${Math.max(8,m)}px`})(),a.showPopover(),()=>{try{a.hidePopover()}catch{}}):void 0},[e]),c.useEffect(()=>{const a=l=>{const u=i.current;u&&!u.contains(l.target)&&o()};return document.addEventListener("pointerdown",a),()=>document.removeEventListener("pointerdown",a)},[o]),t.jsxs("div",{ref:i,popover:"manual",className:"flex items-center gap-0.5 rounded-md border border-border bg-popover px-1 py-0.5 shadow-md m-0",style:{position:"fixed"},onClick:a=>a.stopPropagation(),onMouseEnter:s,onMouseLeave:o,onFocusCapture:s,onBlur:a=>{a.currentTarget.contains(a.relatedTarget)||o()},children:[n&&t.jsx(W,{variant:"ghost",size:"icon-sm",onClick:n,"aria-label":"Edit row",title:"Edit",className:"size-6",children:t.jsx(N.Pencil,{className:"size-3.5"})}),r&&t.jsx(W,{variant:"ghost",size:"icon-sm",onClick:r,"aria-label":"Delete row",title:"Delete",className:"size-6 text-destructive hover:text-destructive",children:t.jsx(N.Trash2,{className:"size-3.5"})})]})}const In=60,Ss=450,Il=150,Ln="bifrost-col-sizes:";function $s(e){try{const n=localStorage.getItem(Ln+e);return n?Ll(JSON.parse(n)):{}}catch{return{}}}function Ll(e){if(typeof e!="object"||e===null||Array.isArray(e))return{};const n={};for(const[r,s]of Object.entries(e))typeof s!="number"||!Number.isFinite(s)||(n[r]=Math.min(Math.max(s,In),Ss));return n}function On(e,n){try{Object.keys(n).length===0?localStorage.removeItem(Ln+e):localStorage.setItem(Ln+e,JSON.stringify(n))}catch{}}const Ol=[10,20,30,50,100],An=-1;function Al({columns:e,data:n,tableName:r,pageCount:s,pageIndex:o,pageSize:i,sorting:a,columnFilters:l,loading:u,selectable:d=!1,primaryKeys:p=[],selectedRowId:m,onRowSelect:h,onSortingChange:x,onColumnFiltersChange:g,onPageIndexChange:b,onPageSizeChange:k,onEditRow:$,onDeleteRow:w,onDeleteSelected:P,stackingEnabled:C,onToggleStacking:T}){const[j,E]=c.useState(null),y=c.useRef(null),S=c.useCallback((D,K)=>{y.current&&(clearTimeout(y.current),y.current=null),E({rowId:D,el:K})},[]),L=c.useCallback(()=>{y.current&&clearTimeout(y.current),y.current=setTimeout(()=>E(null),150)},[]),v=c.useCallback(()=>{y.current&&(clearTimeout(y.current),y.current=null)},[]),M=c.useRef(null),O=c.useRef(!1),z=c.useRef(!1),I=500,_=c.useCallback(()=>{M.current&&(clearTimeout(M.current),M.current=null)},[]),G=c.useCallback((D,K,de)=>{de.pointerType==="touch"&&(O.current=!1,_(),M.current=setTimeout(()=>{O.current||(z.current=!0,S(D,K))},I))},[_,S]),U=c.useCallback(()=>{O.current=!0,_()},[_]),[ie,B]=c.useState({}),[Te,ye]=c.useState({}),[xe,le]=c.useState(()=>r?$s(r):{}),[re,ae]=c.useState(!0),J=c.useRef(null),ce=c.useRef(null),R=c.useRef(!0);c.useEffect(()=>{const D=ce.current;if(D&&D.tableName!==r&&(ce.current=null,On(D.tableName,D.sizing)),!r)return;if(R.current){R.current=!1;return}ce.current={tableName:r,sizing:xe};const K=setTimeout(()=>{ce.current=null,On(r,xe)},300);return()=>clearTimeout(K)},[r,xe]),c.useEffect(()=>()=>{const D=ce.current;D&&On(D.tableName,D.sizing)},[]);const Ne=c.useRef(r);if(r&&r!==Ne.current){Ne.current=r,R.current=!0;const D=$s(r);le(D)}const Be=c.useCallback(D=>{const K=J.current;if(!K)return;const de=K.querySelectorAll(`[data-col-id="${D}"]`);let Ee=In;de.forEach(We=>{const dn=We.scrollWidth+4;dn>Ee&&(Ee=dn)});const mt=Math.min(Ee,Ss);le(We=>({...We,[D]:mt}))},[]),ze=c.useCallback(()=>{le({})},[]),Ke=c.useRef(0),De=c.useCallback(()=>{const D=J.current;return D?Math.max(5,Math.floor((D.clientHeight-Ts)/ks)):10},[]);c.useEffect(()=>{if(!re)return;const D=J.current;if(!D)return;const K=()=>{const We=De();We!==Ke.current&&(Ke.current=We,k(We))},de=requestAnimationFrame(K);let Ee=null;const mt=new ResizeObserver(()=>{Ee&&clearTimeout(Ee),Ee=setTimeout(()=>requestAnimationFrame(K),200)});return mt.observe(D),()=>{cancelAnimationFrame(de),Ee&&clearTimeout(Ee),mt.disconnect()}},[re,De,k]),c.useEffect(()=>{ye({})},[n,o]);const Ge=c.useMemo(()=>{const D=[];return d&&D.push({id:"_select",header:({table:K})=>t.jsx(zn,{checked:K.getIsAllPageRowsSelected()||K.getIsSomePageRowsSelected()&&"indeterminate",onCheckedChange:de=>K.toggleAllPageRowsSelected(!!de),"aria-label":"Select all"}),cell:({row:K})=>t.jsx(zn,{checked:K.getIsSelected(),onCheckedChange:de=>K.toggleSelected(!!de),onClick:de=>de.stopPropagation(),"aria-label":"Select row"}),enableSorting:!1,enableHiding:!1,enableResizing:!1,size:32}),D.push(...e),D},[e,d]),ue=Kt.useReactTable({data:n,columns:Ge,pageCount:s,getRowId:(D,K)=>_t(D,{primaryKeys:p},K),state:{sorting:a,columnFilters:l,pagination:{pageIndex:o,pageSize:i},columnVisibility:ie,rowSelection:Te,columnSizing:xe},defaultColumn:{minSize:In,size:Il},columnResizeMode:"onChange",enableColumnResizing:!0,onColumnSizingChange:le,meta:{onResetColumnWidths:ze},onSortingChange:D=>{const K=typeof D=="function"?D(a):D;x(K)},onPaginationChange:D=>{const de=typeof D=="function"?D({pageIndex:o,pageSize:i}):D;de.pageSize!==i?(k(de.pageSize),b(0)):b(de.pageIndex)},onColumnFiltersChange:D=>{const K=typeof D=="function"?D(l):D;g(K)},onColumnVisibilityChange:B,onRowSelectionChange:ye,enableRowSelection:d,getCoreRowModel:Kt.getCoreRowModel(),manualSorting:!0,manualFiltering:!0,manualPagination:!0}),X=Object.keys(Te).length,se=ue.getVisibleLeafColumns().map(D=>D.id).join("|"),Se=c.useCallback(()=>{if(!P)return;const D=[];for(const K of ue.getSelectedRowModel().rows){const de=gt(K.original,{primaryKeys:p});de&&D.push(de)}D.length>0&&P(D)},[ue,P,p]),$e=c.useCallback(D=>{const K=ue.getRow(D);return K?gt(K.original,{primaryKeys:p}):null},[ue,p]),rt=c.useCallback(D=>{if(!$)return;const K=$e(D);K&&$(K)},[$,$e]),Je=c.useCallback(D=>{if(!w)return;const K=$e(D);K&&w(K)},[w,$e]),ut=c.useCallback(()=>{j&&rt(j.rowId)},[j,rt]),st=c.useCallback(()=>{j&&Je(j.rowId)},[j,Je]);return t.jsxs("div",{className:"flex flex-col w-full min-h-0 flex-1",children:[t.jsxs("div",{className:"flex items-center justify-between py-1 px-2",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[l.length>0&&t.jsxs(W,{variant:"outline",size:"sm",onClick:()=>ue.resetColumnFilters(),title:"Clear all column filters",children:[t.jsx(N.FilterX,{className:"size-3.5"}),"Clear filters"]}),X>0&&P&&t.jsxs(t.Fragment,{children:[t.jsxs("span",{className:"text-xs text-muted-foreground",children:[X," selected"]}),t.jsxs(W,{variant:"outline",size:"sm",onClick:Se,className:"text-destructive hover:text-destructive",children:[t.jsx(N.Trash2,{className:"size-3.5"}),"Delete"]})]})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[T&&t.jsxs(W,{variant:C?"secondary":"outline",size:"sm",role:"switch","aria-checked":!!C,onClick:()=>T(!C),title:C?"Stacked drill-down active — click for flat grid":"Flat grid active — click for stacked drill-down",children:[C?t.jsx(N.PanelRight,{className:"size-3.5"}):t.jsx(N.Rows3,{className:"size-3.5"}),C?"Stacked":"Grid"]}),t.jsxs(Yr,{children:[t.jsx(Rr,{asChild:!0,children:t.jsxs(W,{variant:"outline",size:"sm",children:[t.jsx(N.Columns3,{className:"size-3.5"}),"Columns",t.jsx(N.ChevronDown,{className:"size-3.5"})]})}),t.jsx(Xr,{align:"end",children:ue.getAllColumns().filter(D=>D.getCanHide()).map(D=>{const de=D.columnDef.meta?.column?.label??(typeof D.columnDef.header=="string"?D.columnDef.header:D.id);return t.jsx(Ja,{checked:D.getIsVisible(),onCheckedChange:Ee=>D.toggleVisibility(!!Ee),children:de},D.id)})})]})]})]}),t.jsxs("div",{ref:J,className:"flex-1 overflow-auto min-h-0",children:[t.jsxs(zl,{style:{tableLayout:"fixed",width:ue.getTotalSize()},children:[t.jsx("colgroup",{children:ue.getVisibleLeafColumns().map(D=>t.jsx("col",{style:{width:D.getSize()}},D.id))}),t.jsx(El,{children:ue.getHeaderGroups().map(D=>t.jsx(an,{children:D.headers.map(K=>t.jsxs(Dl,{"data-col-id":K.column.id,className:"relative","aria-sort":K.column.getIsSorted()==="asc"?"ascending":K.column.getIsSorted()==="desc"?"descending":K.column.getCanSort()?"none":void 0,children:[K.isPlaceholder?null:Kt.flexRender(K.column.columnDef.header,K.getContext()),K.column.getCanResize()&&t.jsx("div",{onMouseDown:K.getResizeHandler(),onTouchStart:K.getResizeHandler(),onDoubleClick:()=>Be(K.column.id),className:`absolute top-0 right-0 w-1 h-full cursor-col-resize select-none touch-none opacity-0 hover:opacity-100 transition-opacity ${K.column.getIsResizing()?"bg-primary opacity-100":"bg-border hover:bg-muted-foreground"}`})]},K.id))},D.id))}),t.jsx(Pl,{children:u?t.jsx(an,{children:t.jsx(Mn,{colSpan:Ge.length,className:"h-24 text-center",children:"Loading..."})}):ue.getRowModel().rows.length===0?t.jsx(an,{children:t.jsx(Mn,{colSpan:Ge.length,className:"h-24 text-center",children:"No results."})}):ue.getRowModel().rows.map(D=>t.jsx(Vl,{row:D,isSelected:m!=null&&D.id===m,checked:D.getIsSelected(),visibleKey:se,onRowSelect:h,onEditRow:$?rt:void 0,onDeleteRow:w?Je:void 0,suppressClick:z,hoverRow:S,scheduleDismiss:L,startPress:G,onPressMove:U,cancelPress:_},D.id))})]}),j&&($||w)&&t.jsx(Ml,{anchorEl:j.el,onEdit:$?ut:void 0,onDelete:w?st:void 0,onMouseEnter:v,onDismiss:L})]}),t.jsxs("div",{className:"flex items-center justify-between px-2 py-1.5 border-t border-border mt-auto shrink-0",children:[t.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[t.jsx("span",{children:"Rows per page"}),t.jsxs(Le,{value:String(re?An:i),onValueChange:D=>{const K=Number(D);K===An?(ae(!0),k(De())):(ae(!1),k(K))},children:[t.jsx(Ae,{size:"sm",className:"w-auto h-7 text-xs","aria-label":"Rows per page",children:t.jsx(Oe,{children:re?"Fit":i})}),t.jsxs(qe,{children:[t.jsx(ge,{value:String(An),children:"Fit"}),Ol.map(D=>t.jsx(ge,{value:String(D),children:D},D))]})]})]}),t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsxs("span",{className:"text-xs text-muted-foreground mr-2",children:["Page ",o+1," of ",s||1]}),t.jsx(W,{variant:"outline",size:"icon-sm",onClick:()=>b(0),disabled:o===0,"aria-label":"First page",title:"First page",children:t.jsx(N.ChevronsLeft,{className:"size-4"})}),t.jsx(W,{variant:"outline",size:"icon-sm",onClick:()=>b(o-1),disabled:!ue.getCanPreviousPage(),"aria-label":"Previous page",title:"Previous page",children:t.jsx(N.ChevronLeft,{className:"size-4"})}),t.jsx(W,{variant:"outline",size:"icon-sm",onClick:()=>b(o+1),disabled:!ue.getCanNextPage(),"aria-label":"Next page",title:"Next page",children:t.jsx(N.ChevronRight,{className:"size-4"})}),t.jsx(W,{variant:"outline",size:"icon-sm",onClick:()=>b(s-1),disabled:o>=s-1,"aria-label":"Last page",title:"Last page",children:t.jsx(N.ChevronsRight,{className:"size-4"})})]})]})]})}function ql({row:e,isSelected:n,checked:r,onRowSelect:s,onEditRow:o,onDeleteRow:i,suppressClick:a,hoverRow:l,scheduleDismiss:u,startPress:d,onPressMove:p,cancelPress:m}){const h=!!(s||o||i);return t.jsx(an,{"data-state":n||r?"selected":void 0,className:s?"cursor-pointer group/row focus-visible:outline-2 focus-visible:outline-primary":"group/row focus-visible:outline-2 focus-visible:outline-primary",tabIndex:h?0:void 0,onClick:s?()=>{if(a.current){a.current=!1;return}window.getSelection()?.toString()||s(n?null:e.id)}:void 0,onKeyDown:h?x=>{x.target===x.currentTarget&&((x.key==="Enter"||x.key===" ")&&s?(x.preventDefault(),s(n?null:e.id)):(x.key==="e"||x.key==="E")&&o?(x.preventDefault(),o(e.id)):(x.key==="Delete"||x.key==="Backspace")&&i&&(x.preventDefault(),i(e.id)))}:void 0,onFocus:x=>{x.target===x.currentTarget&&l(e.id,x.currentTarget)},onBlur:x=>{x.currentTarget.contains(x.relatedTarget)||u()},onPointerEnter:x=>{x.pointerType==="mouse"&&l(e.id,x.currentTarget)},onPointerLeave:x=>{x.pointerType==="mouse"&&u()},onPointerDown:x=>d(e.id,x.currentTarget,x),onPointerMove:p,onPointerUp:m,onPointerCancel:m,children:e.getVisibleCells().map(x=>t.jsx(Mn,{"data-col-id":x.column.id,children:Kt.flexRender(x.column.columnDef.cell,x.getContext())},x.id))})}const Vl=c.memo(ql);function Bl({...e}){return t.jsx(Q.Dialog.Root,{"data-slot":"sheet",...e})}function Kl({...e}){return t.jsx(Q.Dialog.Portal,{"data-slot":"sheet-portal",...e})}function Gl({className:e,...n}){return t.jsx(Q.Dialog.Overlay,{"data-slot":"sheet-overlay",className:H("fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",e),...n})}function Jl({className:e,children:n,side:r="right",...s}){return t.jsxs(Kl,{children:[t.jsx(Gl,{}),t.jsxs(Q.Dialog.Content,{"data-slot":"sheet-content",className:H("fixed z-50 flex flex-col gap-4 bg-background shadow-lg transition ease-in-out duration-200 outline-none","data-[state=closed]:animate-out data-[state=open]:animate-in data-[state=closed]:duration-200 data-[state=open]:duration-200",r==="right"&&"inset-y-0 right-0 h-full w-3/4 max-w-md border-l data-[state=closed]:slide-out-to-right data-[state=open]:slide-in-from-right",r==="left"&&"inset-y-0 left-0 h-full w-3/4 max-w-md border-r data-[state=closed]:slide-out-to-left data-[state=open]:slide-in-from-left",r==="top"&&"inset-x-0 top-0 h-auto border-b data-[state=closed]:slide-out-to-top data-[state=open]:slide-in-from-top",r==="bottom"&&"inset-x-0 bottom-0 h-auto border-t data-[state=closed]:slide-out-to-bottom data-[state=open]:slide-in-from-bottom",e),...s,children:[n,t.jsxs(Q.Dialog.Close,{"data-slot":"sheet-close",className:"absolute top-4 right-4 rounded-xs opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",children:[t.jsx(N.XIcon,{}),t.jsx("span",{className:"sr-only",children:"Close"})]})]})]})}function Wl({className:e,...n}){return t.jsx("div",{"data-slot":"sheet-header",className:H("flex flex-col gap-2 p-4 pb-0",e),...n})}function Hl({className:e,...n}){return t.jsx(Q.Dialog.Title,{"data-slot":"sheet-title",className:H("text-lg leading-none font-semibold",e),...n})}function Ql({className:e,...n}){return t.jsx(Q.Dialog.Description,{"data-slot":"sheet-description",className:H("text-sm text-muted-foreground",e),...n})}const Yl={json:N.Braces,xml:N.Code,"php-serialized":N.Database,binary:N.Binary,longtext:N.FileText,text:N.FileText},Rl={json:"JSON",xml:"XML","php-serialized":"PHP Serialized",binary:"Binary",longtext:"Text",text:"Text"};function Xl(e,n){if(n==="json")try{return JSON.stringify(JSON.parse(e),null,2)}catch{return e}return n==="xml"?e.replace(/>\s*</g,`>
107
+ <`).trim():e}function Ul({target:e,onClose:n,onNavigate:r,onSave:s,canNavigatePrev:o,canNavigateNext:i}){const[a,l]=c.useState(!1),[u,d]=c.useState(!1),[p,m]=c.useState(""),[h,x]=c.useState(!1),[g,b]=c.useState(!1),k=c.useRef(null),$=e?.value??"",w=Nn($,e?.dbType),P=Yl[w],C=Xl($,w);c.useEffect(()=>{d(!1),m(""),x(!1),b(!1)},[e?.rowKey,e?.columnName]),c.useEffect(()=>{if(!e)return;const _=G=>{u||(G.key==="ArrowUp"&&o?(G.preventDefault(),r("prev")):G.key==="ArrowDown"&&i&&(G.preventDefault(),r("next")))};return window.addEventListener("keydown",_),()=>window.removeEventListener("keydown",_)},[e,u,o,i,r]);const T=c.useCallback(()=>{navigator.clipboard.writeText($),x(!0),setTimeout(()=>x(!1),1500)},[$]),j=c.useCallback(()=>{m(C),d(!0),requestAnimationFrame(()=>k.current?.focus())},[C]),E=c.useCallback(()=>{d(!1),m("")},[]),y=c.useCallback(async()=>{if(p===C){d(!1);return}if(!(!s||g)){b(!0);try{await s(p),d(!1)}catch{}finally{b(!1)}}},[s,p,C,g]),S=c.useCallback(()=>{if(w==="json")try{m(JSON.stringify(JSON.parse(p),null,2))}catch{}else w==="xml"&&m(p.replace(/>\s*</g,`>
108
+ <`).trim())},[p,w]),L=w==="json"||w==="xml",v=!!s&&!e?.isReadOnly&&w!=="binary",M=t.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[t.jsx(P,{className:"size-4 text-muted-foreground shrink-0"}),t.jsx("span",{className:"truncate font-semibold text-sm",children:e?.columnLabel}),t.jsx("span",{className:"text-xs text-muted-foreground shrink-0",children:Rl[w]}),t.jsxs("span",{className:"text-xs text-muted-foreground shrink-0",children:[$.length," chars"]})]}),O=t.jsxs("div",{className:"flex items-center gap-1 px-4 pb-2",children:[t.jsxs(W,{type:"button",variant:"ghost",size:"sm",className:"h-7 text-xs px-2",onClick:T,children:[h?t.jsx(N.Check,{className:"size-3"}):t.jsx(N.Copy,{className:"size-3"}),h?"Copied":"Copy"]}),v&&!u&&t.jsxs(W,{type:"button",variant:"ghost",size:"sm",className:"h-7 text-xs px-2",onClick:j,children:[t.jsx(N.Pencil,{className:"size-3"}),"Edit"]}),u&&L&&t.jsxs(W,{type:"button",variant:"ghost",size:"sm",className:"h-7 text-xs px-2",onClick:S,children:[t.jsx(N.WrapText,{className:"size-3"}),"Format"]}),t.jsxs("div",{className:"flex items-center gap-1 ml-auto",children:[t.jsx(W,{type:"button",variant:"ghost",size:"icon-sm",onClick:()=>r("prev"),disabled:!o,"aria-label":"Previous row",title:"Previous row",children:t.jsx(N.ChevronUp,{className:"size-4"})}),t.jsx(W,{type:"button",variant:"ghost",size:"icon-sm",onClick:()=>r("next"),disabled:!i,"aria-label":"Next row",title:"Next row",children:t.jsx(N.ChevronDown,{className:"size-4"})}),t.jsx(W,{type:"button",variant:"ghost",size:"icon-sm",onClick:()=>l(_=>!_),"aria-label":a?"Exit full screen":"Full screen",title:a?"Exit full screen":"Full screen",children:a?t.jsx(N.Minimize2,{className:"size-4"}):t.jsx(N.Maximize2,{className:"size-4"})})]})]}),z=t.jsx("div",{className:"flex-1 min-h-0 overflow-auto px-4 pb-4",children:u?t.jsxs("div",{className:"flex flex-col gap-2 h-full",children:[t.jsx("textarea",{ref:k,value:p,onChange:_=>m(_.target.value),className:H("flex-1 w-full rounded-md border border-input bg-background px-3 py-2","text-xs font-mono leading-relaxed","ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2","resize-none min-h-[200px]")}),t.jsxs("div",{className:"flex items-center gap-2 justify-end",children:[t.jsx(W,{type:"button",variant:"ghost",size:"sm",onClick:E,disabled:g,children:"Cancel"}),t.jsx(W,{type:"button",size:"sm",onClick:y,disabled:g,children:g?"Saving…":"Save"})]})]}):t.jsx("pre",{className:"text-xs font-mono leading-relaxed whitespace-pre-wrap break-all",children:C})}),I=!!e;return t.jsxs(t.Fragment,{children:[t.jsx(Bl,{open:I&&!a,onOpenChange:_=>{_||n()},children:t.jsxs(Jl,{side:"right",className:"w-[480px] max-w-[90vw]",children:[t.jsxs(Wl,{children:[t.jsx(Hl,{children:M}),t.jsx(Ql,{className:"sr-only",children:"Content viewer panel"})]}),O,z]})}),t.jsx(Ze,{open:I&&a,onOpenChange:_=>{_||l(!1)},children:t.jsxs(et,{className:"max-w-[90vw] max-h-[90vh] w-full h-full flex flex-col",children:[t.jsxs(Ot,{children:[t.jsx(tt,{children:M}),t.jsx(jt,{className:"sr-only",children:"Content viewer full screen"})]}),O,z]})})]})}function qn({table:e,id:n,tableFilter:r,filterColumn:s,selectedRowId:o,onRowSelect:i,onOpenColumn:a,stackingEnabled:l,onToggleStacking:u}){const d=cs(e),[p,m]=c.useState(null),[h,x]=c.useState(null),[g,b]=c.useState(null),k=c.useRef([]),$=c.useCallback(X=>{x(vn(X,e))},[e]),w=c.useCallback(X=>{m({type:"single",pk:X})},[]),P=c.useCallback(X=>{X.length!==0&&m({type:"batch",pks:X})},[]),C=c.useCallback((X,se)=>{const Se=k.current[X];b({columnName:se,pk:Se?gt(Se,e):null,rowIndex:X,tableName:e.name})},[e]),{columns:T,sorting:j,columnFilters:E,pageIndex:y,pageSize:S,pageCount:L,rows:v,loading:M,error:O,onSortingChange:z,onColumnFiltersChange:I,onPageIndexChange:_,onPageSizeChange:G}=Gi(e,n,r,s,C,a),U=c.useCallback(async()=>{if(p)try{p.type==="single"?await d.deleteRow(p.pk):await d.deleteRows(p.pks),m(null)}catch{}},[p,d]),ie=p?.type==="batch"?p.pks.length:1;k.current=v;const{toast:B}=rn(),Te=Ce(),ye=e.isEditable!==!1,xe=c.useMemo(()=>g?.pk?vn(g.pk,e):null,[g,e]),le=c.useMemo(()=>!g||g.tableName!==e.name?-1:xe===null?g.rowIndex<v.length?g.rowIndex:-1:v.findIndex(X=>{const se=gt(X,e);return se!==null&&vn(se,e)===xe}),[g,xe,v,e]),re=le>=0?v[le]:void 0;c.useEffect(()=>{g!==null&&g.tableName!==e.name&&b(null)},[g,e.name]),c.useEffect(()=>{g!==null&&g.tableName===e.name&&!M&&le===-1&&(b(null),B("Row is no longer in the current view; panel closed.","error"))},[g,e.name,M,le,B]);const ae=c.useMemo(()=>{if(!g||!re)return null;const X=e.columns.find(rt=>rt.name===g.columnName);if(!X)return null;const se=re[g.columnName],Se=lt(X);return{value:se==null?"":Se||typeof se=="object"?JSON.stringify(se,null,2):String(se),columnName:X.name,columnLabel:X.label,dbType:X.dbType,rowKey:xe??`row-${g.rowIndex}`,isReadOnly:X.isReadOnly||X.isPrimaryKey||X.isIdentity}},[g,re,xe,e]),J=c.useMemo(()=>g?.pk?yn(g.pk,e):null,[g,e]),ce=c.useMemo(()=>e.columns.filter(X=>!X.isReadOnly&&!X.isIdentity),[e]),R=c.useMemo(()=>ce.filter(X=>!X.isNullable||X.name===g?.columnName),[ce,g?.columnName]),Ne=c.useMemo(()=>R.map(X=>({column:X})),[R]),Be=c.useMemo(()=>{const X=new Map(e.columns.map(se=>[se.name,se]));return(e.primaryKeys??[]).map(se=>X.get(se)).filter(se=>!!se)},[e]),ze=sn(e,Ne,Be,xe??""),Ke=ye&&J!==null&&!ze.isPending,De=c.useCallback(async X=>{if(!g||!J)return;const se=e.columns.find($e=>$e.name===g.columnName);let Se=X;if(se&&lt(se))try{Se=JSON.parse(X)}catch{}try{const $e=Ta(e,J,R.map(st=>st.name)),Je=(await Te.query($e,J.variables))?.value?.data?.[0];if(!Je)throw new Error("Row no longer exists.");const ut={};for(const st of R)ut[st.name]=Je[st.name]??null;ut[g.columnName]=Se,await ze.update(ut)}catch($e){throw B(`Save failed: ${$e.message}`,"error"),$e}},[g,J,e,R,ze,Te,B]),Ge=c.useCallback(()=>{b(null)},[]),ue=c.useCallback(X=>{if(!g||le<0)return;const se=X==="prev"?Math.max(0,le-1):Math.min(v.length-1,le+1);C(se,g.columnName)},[g,le,v.length,C]);return O?t.jsx(pt,{variant:"destructive",className:"m-2",children:t.jsxs(ht,{children:["Error: ",O.message]})}):t.jsxs(t.Fragment,{children:[t.jsx(Al,{columns:T,data:v,tableName:e.name,pageCount:L,pageIndex:y,pageSize:S,sorting:j,columnFilters:E,loading:M,primaryKeys:e.primaryKeys??[],selectable:ye,selectedRowId:o,onRowSelect:i,onSortingChange:z,onColumnFiltersChange:I,onPageIndexChange:_,onPageSizeChange:G,onEditRow:ye?$:void 0,onDeleteRow:ye?w:void 0,onDeleteSelected:ye?P:void 0,stackingEnabled:l,onToggleStacking:u}),t.jsx(En,{open:p!==null,onOpenChange:X=>{X||m(null)},title:`Delete ${ie} ${ie===1?"row":"rows"}?`,description:t.jsxs(t.Fragment,{children:[t.jsx("p",{children:"This action cannot be undone."}),d.error&&t.jsx("p",{className:"mt-2 text-sm text-destructive",children:d.error.message})]}),confirmLabel:`Delete ${ie===1?"row":`${ie} rows`}`,variant:"destructive",isPending:d.isPending,onConfirm:U}),t.jsx(Ul,{target:ae,onClose:Ge,onNavigate:ue,onSave:Ke?De:void 0,canNavigatePrev:le>0,canNavigateNext:le>=0&&le<v.length-1}),h!==null&&t.jsx(ws,{table:e.graphQlName,editid:h,onClose:()=>x(null)})]})}function Zl(e){return new Set((e.manyToManyJoins??[]).map(n=>n.junctionTable))}function _s(e){const n=Zl(e),r=e.multiJoins.filter(o=>!n.has(o.destinationTable)).map(o=>({kind:"child",key:`child:${o.fieldName??o.destinationTable}`,join:o})),s=(e.manyToManyJoins??[]).map(o=>({kind:"m2m",key:`m2m:${o.junctionTable}:${o.targetTable}`,m2m:o}));return[...r,...s]}function Fs(e,n){const r=new Set([...n.junctionSourceColumnNames,...n.junctionTargetColumnNames]);return e.columns.filter(s=>!s.isPrimaryKey&&!r.has(s.name))}function ec(e,n,r,s){const o=r.junctionSourceColumnNames;if(o.length===0)throw new Error(`Many-to-many relationship '${r.name}' has no junction source columns.`);const i=Pr(s,o.length),a=new Map(e.columns.map(P=>[P.name,P])),l=[],u=[],d={};o.forEach((P,C)=>{const T=a.get(P);if(!T)throw new Error(`Junction table '${e.name}' has no column '${P}' (junction source column of many-to-many relationship '${r.name}').`);const j=T.paramType.replace("!",""),E=`src${C}`;l.push(`$${E}: ${j}`),u.push(`{ ${P}: { _eq: $${E} } }`),d[E]=Xe(i[C],j)});const p=u.length===1?u[0]:`{ and: [${u.join(", ")}] }`,m=e.primaryKeys??[],h=Fs(e,r).map(P=>P.name),x=n.primaryKeys?.length?n.primaryKeys:r.targetColumnNames,g=n.labelColumn,b=[...x];g&&!x.includes(g)&&b.push(`label: ${g}`);const k=`${r.junctionTargetField} { ${b.join(" ")} }`,$=[...m,...h,k].join(" ");return{query:`query GetLinks_${e.name}(${l.join(", ")}, $limit: Int, $offset: Int) { ${e.name}(filter: ${p} limit: $limit offset: $offset) { total offset limit data { ${$} } } }`,variables:d}}function tc(e,n,r){Fe(e.name,"many-to-many target table name");const s=Qe(e)[0]?.name??n.targetColumnNames[0],o=e.labelColumn||s;Fe(s,"many-to-many target id column"),Fe(o,"many-to-many target label column");const i=o!==s?`${s} label: ${o}`:s,a=e.columns.find(h=>h.name===o);if(!a)throw new Error(`Target table '${e.name}' has no column '${o}' (label column for the '${n.name}' many-to-many picker).`);const l=a.paramType.replace("!","")==="String",u=!!r&&r.trim()!==""&&l,d=u?"$limit: Int, $search: String":"$limit: Int",p=u?`filter: {${o}: {_contains: $search}} `:"";return{query:`query PickTarget(${d}) { ${e.name}(${p}limit: $limit sort: [${o}_asc]) { data { ${i} } } }`,idColumn:s,serverSearch:l}}function nc(e,n,r){const s=e[n.junctionTargetField];if(!s)return null;const o=_t(s,r,0),i=s.label!=null?String(s.label):o;return{id:o,label:i}}function rc(e,n,r){if(e.junctionSourceColumnNames.length!==1||e.junctionTargetColumnNames.length!==1)throw new Error("attachJunctionDetail supports single-column junction FKs only; this relationship uses a composite key which is not yet supported.");const[s]=Pr(n,1);return{[e.junctionSourceColumnNames[0]]:s,[e.junctionTargetColumnNames[0]]:r}}const Vn=200,sc=50,oc=500;function ac({parentTable:e,m2m:n,parentRowId:r,onOpenColumn:s}){const o=Pe(),i=Ce(),a=me.useQueryClient(),{toast:l}=rn(),[u,d]=c.useState(!1),[p,m]=c.useState(null),h=o.findTable(n.junctionTable),x=o.findTable(n.targetTable),g=cs(h??e);let b={query:null,variables:{}},k=null;if(h&&x)try{b=ec(h,x,n,r)}catch(z){k=z}const{query:$,variables:w}=b,P=c.useMemo(()=>["m2mRows",n.junctionTable,n.targetTable,r],[n.junctionTable,n.targetTable,r]),{data:C,isLoading:T,error:j}=me.useQuery({queryKey:P,queryFn:()=>i.query($,{...w,limit:Vn,offset:0}),enabled:!!$}),E=c.useCallback(()=>a.invalidateQueries({queryKey:P}),[a,P]),y=c.useCallback(async z=>{if(!h)return;const I=gt(z,h);I&&(await g.deleteRow(I),await E())},[h,g,E]);if(!h||!x)return t.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"Relationship schema unavailable."});if(k)return t.jsxs("div",{className:"p-4 text-sm text-destructive",children:["Relationship misconfigured: ",k.message]});const S=C?.[h.name]?.data??[],L=Fs(h,n),v=h.isEditable!==!1,M=Qe(x)[0]?.name??n.targetColumnNames[0],O=new Set;for(const z of S){const _=z[n.junctionTargetField]?.[M];_!=null&&O.add(String(_))}return t.jsxs("div",{className:"flex flex-col min-h-0 flex-1 overflow-hidden",children:[t.jsxs("div",{className:"flex items-center gap-2 px-2 py-1 bg-muted/20 border-b border-border shrink-0",children:[t.jsxs("span",{className:"inline-flex items-center gap-1 rounded-full border border-border bg-muted/40 px-2 py-0.5 text-xs text-muted-foreground",title:`Linked through ${h.label}`,children:[t.jsx(N.Link2,{className:"size-3"}),"via ",h.label]}),v&&t.jsxs(W,{variant:"ghost",size:"sm",className:"h-7 px-2 text-xs ml-auto",onClick:()=>d(!0),children:[t.jsx(N.Plus,{className:"size-3 mr-1"})," Add link"]})]}),t.jsxs("div",{className:"flex-1 min-h-0 overflow-auto",children:[j&&t.jsxs("div",{className:"p-3 text-sm text-destructive",children:["Error: ",j.message]}),T&&t.jsxs("div",{className:"flex items-center gap-2 p-3 text-sm text-muted-foreground",children:[t.jsx(N.Loader2,{className:"size-4 animate-spin"})," Loading…"]}),!T&&S.length===0&&t.jsxs("div",{className:"p-3 text-sm text-muted-foreground",children:["No linked ",x.label,"."]}),S.length>0&&t.jsxs("table",{className:"w-full text-sm",children:[t.jsx("thead",{children:t.jsxs("tr",{className:"border-b border-border text-left text-xs text-muted-foreground",children:[t.jsx("th",{className:"px-2 py-1 font-medium",children:x.label}),L.map(z=>t.jsx("th",{className:"px-2 py-1 font-medium",children:z.label},z.name)),v&&t.jsx("th",{className:"px-2 py-1 w-8","aria-label":"actions"})]})}),t.jsx("tbody",{children:S.map((z,I)=>{const _=nc(z,n,x);return t.jsxs("tr",{className:"border-b border-border/50 hover:bg-muted/30",children:[t.jsx("td",{className:"px-2 py-1",children:_?t.jsxs("span",{className:"inline-flex items-center gap-1",children:[t.jsx(St,{to:`/${x.name}/${_.id}`,className:"text-primary hover:underline",children:_.label}),s&&t.jsx(W,{variant:"ghost",size:"icon-sm",className:"size-5",onClick:()=>s({tableName:x.name,filterId:_.id}),"aria-label":`Open ${_.label} in side column`,title:"Open in side column",children:t.jsx(N.Search,{className:"size-3"})})]}):t.jsx("span",{className:"text-muted-foreground",children:"—"})}),L.map(G=>t.jsx("td",{className:"px-2 py-1",children:tn(z[G.name],G)},G.name)),v&&t.jsx("td",{className:"px-2 py-1",children:t.jsx(W,{variant:"ghost",size:"icon-sm",className:"size-6 text-muted-foreground hover:text-destructive",onClick:()=>m(z),disabled:g.isPending,"aria-label":`Detach ${_?.label??"link"}`,title:"Detach",children:t.jsx(N.Unlink,{className:"size-3.5"})})})]},I)})})]}),S.length>=Vn&&t.jsxs("div",{className:"px-3 py-2 text-xs text-muted-foreground italic border-t border-border",children:["Showing the first ",Vn," links. Detach some or narrow the parent selection to see more."]})]}),u&&t.jsx(ic,{target:x,junction:h,m2m:n,parentRowId:r,linkedIds:O,onClose:()=>d(!1),onLinked:E}),t.jsx(En,{open:p!==null,onOpenChange:z=>{z||m(null)},title:"Detach this link?",description:t.jsxs("p",{children:["This removes the link row. The ",x.label," record itself is not deleted."]}),confirmLabel:"Detach",variant:"destructive",isPending:g.isPending,onConfirm:async()=>{try{p&&await y(p)}catch(z){l(`Detach failed: ${z.message}`,"error")}finally{m(null)}}})]})}function ic({target:e,junction:n,m2m:r,parentRowId:s,linkedIds:o,onClose:i,onLinked:a}){const l=Ce(),u=n.columns.filter(v=>r.junctionSourceColumnNames.includes(v.name)||r.junctionTargetColumnNames.includes(v.name)).map(v=>({column:v})),d=sn(n,u,[]),[p,m]=c.useState(""),[h,x]=c.useState("");c.useEffect(()=>{const v=setTimeout(()=>x(p),300);return()=>clearTimeout(v)},[p]);const g=h.trim();let b=null,k=null;try{b=tc(e,r,g)}catch(v){k=v}const{query:$,idColumn:w,serverSearch:P}=b??{query:"",idColumn:"",serverSearch:!1},C=P?sc:oc,{data:T,isLoading:j}=me.useQuery({queryKey:["m2mTargets",e.name,P?g:""],queryFn:({signal:v})=>l.query($,P&&g?{limit:C,search:g}:{limit:C},{signal:v}),enabled:b!==null}),E=T?.[e.name]?.data??[],y=P||!g?E:E.filter(v=>xs(v,w,g)),S=E.length>=C,L=c.useCallback(async v=>{if(!o.has(v)){try{await d.insert(rc(r,s,v))}catch{return}await a(),i()}},[d,r,s,o,a,i]);return k?t.jsx(Ze,{open:!0,onOpenChange:v=>{v||i()},children:t.jsxs(et,{className:"max-w-md",children:[t.jsx(Ot,{children:t.jsxs(tt,{children:["Add ",e.label," link"]})}),t.jsxs("p",{className:"text-sm text-destructive",children:["Relationship misconfigured: ",k.message]})]})}):t.jsx(Ze,{open:!0,onOpenChange:v=>{v||i()},children:t.jsxs(et,{className:"max-w-md",children:[t.jsx(Ot,{children:t.jsxs(tt,{children:["Add ",e.label," link"]})}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(N.Search,{className:"size-4 text-muted-foreground"}),t.jsx(ke,{autoFocus:!0,placeholder:`Search ${e.label}…`,value:p,onChange:v=>m(v.target.value)})]}),d.error&&t.jsx("p",{className:"text-sm text-destructive",children:d.error.message}),t.jsxs("div",{className:"max-h-72 overflow-auto border border-border rounded-md",children:[j&&t.jsxs("div",{className:"flex items-center gap-2 p-3 text-sm text-muted-foreground",children:[t.jsx(N.Loader2,{className:"size-4 animate-spin"})," Loading…"]}),!j&&y.length===0&&t.jsx("div",{className:"p-3 text-sm text-muted-foreground",children:"No matches."}),y.map((v,M)=>{const O=String(v[w]??""),z=v.label!=null?String(v.label):O,I=o.has(O);return t.jsxs("button",{type:"button",className:"flex w-full items-center justify-between gap-2 text-left px-3 py-1.5 text-sm hover:bg-muted/50 disabled:opacity-50 disabled:hover:bg-transparent",disabled:d.isPending||I,onClick:()=>L(O),children:[t.jsx("span",{className:"truncate",children:z}),I&&t.jsx("span",{className:"shrink-0 text-xs text-muted-foreground italic",children:"Already linked"})]},M)}),!j&&S&&t.jsx("div",{className:"px-3 py-1.5 text-xs text-muted-foreground italic border-t border-border",children:P?`Showing the first ${C} matches — type to narrow.`:`Showing the first ${C} rows; some may not be listed.`})]})]})})}function zs(e){return e.kind==="child"?e.join.destinationTable:e.m2m.targetTable}function Es({parentTable:e,selectedRowId:n,onClose:r,onOpenColumn:s}){const o=Pe(),i=_s(e),[a,l]=c.useState(i[0]?.key??""),[u,d]=c.useState(!1),[p,m]=c.useState(null),h=i.find(b=>b.key===a)??i[0];if(c.useEffect(()=>{m(null)},[a,n]),i.length===0||!o.data)return null;const x=h.kind==="child"?o.findTable(h.join.destinationTable):void 0,g=(x?.multiJoins?.length??0)>0;return t.jsxs("div",{className:"border-t-2 border-primary/20 flex flex-col min-h-0 flex-1 overflow-hidden",children:[t.jsxs("div",{className:"flex items-center gap-1 px-2 py-1 bg-muted/30 border-b border-border shrink-0",children:[t.jsx(W,{variant:"ghost",size:"icon-sm",onClick:()=>d(!u),"aria-label":u?"Expand detail panel":"Collapse detail panel",title:u?"Expand detail panel":"Collapse detail panel",children:u?t.jsx(N.ChevronUp,{className:"size-3.5"}):t.jsx(N.ChevronDown,{className:"size-3.5"})}),t.jsx("span",{className:"text-xs text-muted-foreground mr-1",children:"Detail:"}),t.jsx("div",{className:"flex items-center gap-0.5 overflow-x-auto",children:i.map(b=>{const $=o.findTable(zs(b))?.label??zs(b),w=b.key===h.key;return t.jsxs("span",{className:"group/tab inline-flex items-center",children:[t.jsx(W,{variant:w?"secondary":"ghost",size:"sm",className:H("text-xs h-7 px-2.5",w&&"font-semibold"),onClick:()=>l(b.key),children:$}),s&&b.kind==="child"&&t.jsx(W,{variant:"ghost",size:"icon-sm",className:"opacity-0 group-hover/tab:opacity-100 size-5 shrink-0",onClick:()=>s({tableName:b.join.destinationTable,filterTable:e.name,filterId:n,...it(b.join)?{}:{filterColumn:b.join.destinationColumnNames[0]}}),"aria-label":"Open in side column",title:"Open in side column",children:t.jsx(N.PanelRight,{className:"size-3"})})]},b.key)})}),r&&t.jsx(W,{variant:"ghost",size:"icon-sm",onClick:r,className:"ml-auto shrink-0","aria-label":"Close detail panel",title:"Close detail panel",children:t.jsx(N.X,{className:"size-3.5"})})]}),!u&&t.jsx("div",{className:"flex-1 min-h-0 overflow-hidden flex flex-col",children:h.kind==="child"&&!x?t.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"This related table is not available."}):h.kind==="child"?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:g&&p?"flex-1 min-h-0 max-h-[50%] overflow-hidden flex flex-col":"flex-1 min-h-0 overflow-hidden flex flex-col",children:t.jsx(qn,{table:x,id:n,tableFilter:e.name,...it(h.join)?{}:{filterColumn:h.join.destinationColumnNames[0]},selectedRowId:g?p:void 0,onRowSelect:g?m:void 0,onOpenColumn:s},`${h.key}-${n}`)}),g&&p&&t.jsx("div",{className:"flex-1 min-h-0 overflow-hidden flex flex-col",children:t.jsx(Es,{parentTable:x,selectedRowId:p,onClose:()=>m(null),onOpenColumn:s})})]}):t.jsx(ac,{parentTable:e,m2m:h.m2m,parentRowId:n,onOpenColumn:s},`${h.key}-${n}`)})]})}const lc={mainTable:null,columns:[],focusedIndex:0,focusColumn:()=>{},closeColumn:()=>{}},Ps=c.createContext(lc),Ds=c.createContext({register:()=>{},unregister:()=>{}});function cc({children:e}){const[n,r]=c.useState(null),[s,o]=c.useState(0),i=c.useCallback(h=>{r(h)},[]),a=c.useCallback(()=>{r(null),o(0)},[]),l=c.useCallback(h=>{if(o(h),!n)return;const x=n.columnRefs.get(h);x&&x.scrollIntoView({behavior:"smooth",block:"nearest",inline:"nearest"})},[n]),u=c.useCallback(h=>{n&&h>0&&n.onClose(h-1)},[n]),d=c.useMemo(()=>n?n.columns.map((h,x)=>({panel:h,element:n.columnRefs.get(x+1)??null})):[],[n]),p=c.useMemo(()=>({mainTable:n?.mainTable??null,columns:d,focusedIndex:s,focusColumn:l,closeColumn:u}),[n,d,s,l,u]),m=c.useMemo(()=>({register:i,unregister:a}),[i,a]);return t.jsx(Ds.Provider,{value:m,children:t.jsx(Ps.Provider,{value:p,children:e})})}function dc(){return c.useContext(Ps)}function uc(){return c.useContext(Ds)}function Ms(e,n){return e.tableName===n.tableName&&e.filterTable===n.filterTable&&e.filterId===n.filterId&&e.filterColumn===n.filterColumn}function mc(e,n){const r=e[e.length-1];if(r&&Ms(r,n))return e;const s=e.findIndex(o=>Ms(o,n));return s>=0?e.slice(0,s+1):[...e,n]}function fc(e,n){return n<0?[]:n>=e.length?e:e.slice(0,n)}function pc(e,n,r){const s=i=>r(i)??i,o=[{index:-1,label:s(e)}];for(let i=0;i<n.length;i++){const a=n[i],l=a.filterTable?s(a.filterTable):s(i===0?e:n[i-1].tableName),u=a.filterId?`from ${l} #${a.filterId}`:void 0;o.push({index:i,label:s(a.tableName),detail:u,frame:a})}return o}function ln(e,n){return e.find(r=>r.name===n)}function dt(){const e=mn(),{table:n,id:r,filterTable:s}=e,{loading:o,error:i,data:a}=Pe(),[l,u]=c.useState(null),[d,p]=c.useState([]),[m,h]=c.useState(!0),[x,g]=c.useState(new Set),b=c.useRef(n);n!==b.current&&(b.current=n,d.length>0&&p([]),x.size>0&&g(new Set));const k=c.useCallback(_=>{g(G=>{const U=new Set(G);return U.has(_)?U.delete(_):U.add(_),U})},[]),{register:$,unregister:w}=uc(),P=c.useRef(null),C=c.useRef(new Map),T=c.useMemo(()=>a?ln(a,n):void 0,[a,n]),j=T?_s(T).length>0:!1,E=c.useCallback(_=>{p(G=>mc(G,_))},[]),y=c.useCallback(_=>{h(_),_||p([])},[]),S=m?E:void 0,L=c.useCallback(_=>{p(G=>G.filter((U,ie)=>ie!==_))},[]),v=c.useCallback(_=>{p(G=>fc(G,_+1))},[]),M=c.useMemo(()=>pc(n??"",d,_=>{if(a)return ln(a,_)?.label}),[n,d,a]);if(c.useEffect(()=>{const _=C.current;_.set(0,P.current);for(const G of _.keys())G>d.length&&_.delete(G);return $({mainTable:n,columns:d,columnRefs:_,onClose:L}),()=>w()},[n,d,$,w,L]),!n)return t.jsx("div",{className:"p-5 text-center text-muted-foreground",children:"Table missing"});if(o)return t.jsxs("div",{className:"flex items-center justify-center gap-2 p-5",children:[t.jsx(N.Loader2,{className:"size-4 animate-spin text-muted-foreground"}),t.jsx("span",{className:"text-sm text-muted-foreground",children:"Loading..."})]});if(i)return t.jsx(pt,{variant:"destructive",className:"m-2",children:t.jsxs(ht,{children:["Error: ",i.message]})});if(!T)return t.jsx("div",{className:"p-5 text-center text-muted-foreground",children:"Table not found"});const O=t.jsx(qn,{table:T,id:r,tableFilter:s,selectedRowId:j?l:void 0,onRowSelect:j?u:void 0,onOpenColumn:S,stackingEnabled:m,onToggleStacking:y});if(d.length===0)return t.jsx("div",{className:"flex flex-col flex-1 min-h-0",children:t.jsxs("div",{ref:P,className:"flex flex-col flex-1 min-h-0 min-w-0",children:[t.jsx("div",{className:j&&l?"flex-1 min-h-0 max-h-[50%] overflow-hidden flex flex-col":"flex-1 min-h-0 overflow-hidden flex flex-col",children:O}),j&&l&&t.jsx("div",{className:"flex-1 min-h-0 overflow-hidden flex flex-col",children:t.jsx(Es,{parentTable:T,selectedRowId:l,onClose:()=>u(null),onOpenColumn:S})})]})});const z=d.length-1,I=(_,G)=>G||x.has(_);return t.jsxs("div",{className:"flex flex-col flex-1 min-h-0",children:[t.jsx(hc,{crumbs:M,onCrumbClick:v,activeIndex:d.length-1}),t.jsxs("div",{className:"flex-1 min-h-0 overflow-y-auto flex flex-col gap-0.5 p-0.5",children:[t.jsx(Is,{title:T.label,selectedRowId:d[0]?.filterId,expanded:I(-1,!1),active:!1,onToggle:()=>k(-1),onRef:_=>{P.current=_,C.current.set(0,_)},children:O}),d.map((_,G)=>{const U=G===z;return t.jsx(Is,{title:ln(a,_.tableName)?.label??_.tableName,selectedRowId:d[G+1]?.filterId,expanded:I(G,U),active:U,onToggle:()=>k(G),onClose:()=>L(G),onRef:ie=>{C.current.set(G+1,ie)},children:t.jsx(qn,{table:ln(a,_.tableName),id:_.filterId,tableFilter:_.filterTable,filterColumn:_.filterColumn,onOpenColumn:E})},`${_.tableName}|${_.filterTable??""}|${_.filterId??""}|${_.filterColumn??""}`)})]})]})}function hc({crumbs:e,onCrumbClick:n,activeIndex:r}){return t.jsx("nav",{"aria-label":"Drill-down breadcrumb",className:"flex items-center gap-1 px-2 py-1 bg-muted/20 border-b border-border shrink-0 overflow-x-auto",children:e.map((s,o)=>{const i=s.index===r,a=o===0;return t.jsxs("span",{className:"inline-flex items-center gap-1 shrink-0",children:[!a&&t.jsx(N.ChevronRight,{className:"size-3 text-muted-foreground shrink-0"}),t.jsxs(W,{variant:i?"secondary":"ghost",size:"sm",className:H("h-6 px-2 text-xs gap-1",i&&"font-semibold"),onClick:()=>n(s.index),"aria-current":i?"page":void 0,title:s.detail?`${s.label} (${s.detail})`:s.label,children:[a&&t.jsx(N.Home,{className:"size-3"}),t.jsx("span",{className:"truncate max-w-[12rem]",children:s.label}),s.detail&&t.jsx("span",{className:"text-muted-foreground font-normal truncate max-w-[10rem]",children:s.detail})]})]},`${s.index}-${s.label}`)})})}function Is({title:e,selectedRowId:n,expanded:r,active:s,onToggle:o,onClose:i,onRef:a,children:l}){return t.jsxs("div",{ref:a,className:"shrink-0 flex flex-col border border-border rounded-sm overflow-hidden",children:[t.jsxs("div",{className:"flex items-center gap-1 px-2 py-1 bg-muted/30 border-b border-border shrink-0",children:[t.jsx("button",{type:"button",onClick:o,className:"inline-flex items-center justify-center size-5 shrink-0 text-muted-foreground hover:text-foreground","aria-expanded":r,"aria-label":r?"Collapse table":"Expand table",title:r?"Collapse":"Expand",children:r?t.jsx(N.ChevronDown,{className:"size-3.5"}):t.jsx(N.ChevronRight,{className:"size-3.5"})}),t.jsx("span",{className:"text-xs font-medium truncate",children:e}),s&&t.jsx("span",{className:"text-[10px] uppercase tracking-wide text-primary/70 shrink-0",children:"active"}),!r&&n&&t.jsxs("span",{className:"text-xs text-muted-foreground truncate",children:["#",n]}),t.jsx("div",{className:"flex-1"}),i&&t.jsx(W,{variant:"ghost",size:"icon-sm",className:"shrink-0",onClick:i,"aria-label":"Close column",title:"Close column",children:t.jsx(N.X,{className:"size-3.5"})})]}),r&&t.jsx("div",{className:"flex flex-col min-h-[18rem] max-h-[34rem]",children:l})]})}function Bn(){const e=mn(),{loading:n,error:r,data:s}=Pe(),{mainTable:o,columns:i,focusedIndex:a,focusColumn:l,closeColumn:u}=dc(),[d,p]=c.useState(""),m=Wt(),{search:h}=er(),x=!!h.get("filter"),{back:g,hasBack:b}=eo(),k=e?.table,$=i.length>0,w=c.useMemo(()=>s?.find(y=>y.graphQlName===k),[s,k]),P=c.useMemo(()=>w?.columns?.filter(y=>{const S=y.paramType.replace("!","");return S==="String"||S==="Int"||S==="Float"}).map(y=>({key:y.name,value:`${y.name},${y.paramType}`,label:y.label})),[w]),[C,T]=c.useState(P?.at(0)?.value??"");c.useEffect(()=>{p(""),T(P?.at(0)?.value??"")},[P]);const j=()=>{if(!d)return;const[y,S]=C.split(",");if(!S)return;const L=S.replace("!","");if(L==="Int"||L==="Float"){const v=Number(d);if(!Number.isFinite(v))return;m(`?filter=["${y}", "_eq", ${v}, "${S}"]`)}else L==="String"&&m(`?filter=["${y}", "_contains", ${JSON.stringify(d)}, "${S}"]`)},E=()=>{p("");const y=new URLSearchParams(h.toString());y.delete("filter");const S=y.toString();m(S?`?${S}`:"?")};return n?t.jsxs("div",{className:"flex items-center gap-2 p-2.5",children:[t.jsx(N.Loader2,{className:"size-4 animate-spin text-muted-foreground"}),t.jsx("span",{className:"text-sm text-muted-foreground",children:"Loading..."})]}):r?t.jsx(pt,{variant:"destructive",className:"m-2",children:t.jsxs(ht,{children:["Error: ",r.message]})}):t.jsxs("header",{className:"flex flex-wrap items-center gap-x-3 gap-y-1.5 px-3 py-1.5 min-h-[2.5rem]",children:[t.jsxs("div",{className:"flex items-center gap-1.5 overflow-x-auto min-w-0 flex-1",children:[t.jsx(W,{variant:"ghost",size:"icon-sm",onClick:()=>b&&g(),disabled:!b,"aria-label":"Go back",title:"Go back",className:"shrink-0",children:t.jsx(N.ChevronLeft,{className:"size-4"})}),$?t.jsxs("div",{className:"flex items-center gap-1 overflow-x-auto",children:[t.jsx("button",{type:"button",onClick:()=>l(0),className:`flex items-center gap-1 px-2 py-0.5 rounded text-xs font-medium whitespace-nowrap transition-colors ${a===0?"bg-primary text-primary-foreground":"bg-muted/50 text-muted-foreground hover:bg-muted"}`,children:w?.label??Ht(e?.table??"")}),i.map((y,S)=>{const v=s?.find(M=>M.graphQlName===y.panel.tableName)?.label??Ht(y.panel.tableName);return t.jsxs("span",{className:`inline-flex items-center gap-1 pl-2 pr-1 py-0.5 rounded text-xs font-medium whitespace-nowrap transition-colors ${a===S+1?"bg-primary text-primary-foreground":"bg-muted/50 text-muted-foreground hover:bg-muted"}`,children:[t.jsx("button",{type:"button",onClick:()=>l(S+1),className:"whitespace-nowrap",children:v}),t.jsx("button",{type:"button",onClick:M=>{M.stopPropagation(),u(S+1)},className:"rounded-sm hover:bg-background/50 p-px","aria-label":`Close ${v}`,children:t.jsx(N.X,{className:"size-3"})})]},`${y.panel.tableName}-${y.panel.filterId??S}`)})]}):t.jsx("h2",{className:"text-sm font-semibold whitespace-nowrap",children:w?.label??e?.table??"(Select)"})]}),P&&P.length>0&&t.jsxs("div",{className:"flex items-center border border-border rounded-md overflow-hidden flex-[2_2_16rem] min-w-[12rem]",children:[t.jsxs(Le,{value:C,onValueChange:T,children:[t.jsx(Ae,{size:"sm",className:"w-auto min-w-[120px] shrink-0 border-0 rounded-none border-r border-border h-8 text-xs",children:t.jsx(Oe,{})}),t.jsx(qe,{children:P.map(y=>t.jsx(ge,{value:y.value,children:y.label},y.key))})]}),t.jsxs("div",{className:"relative flex-1 min-w-[180px]",children:[t.jsx(N.Search,{className:"absolute left-3 top-1/2 -translate-y-1/2 size-3.5 text-muted-foreground pointer-events-none"}),t.jsx(ke,{type:"search",value:d,onChange:y=>p(y.target.value),onKeyDown:y=>y.key==="Enter"&&j(),className:"h-8 border-0 rounded-none focus-visible:ring-0 focus-visible:ring-offset-0",style:{paddingLeft:"2.25rem"},placeholder:"Search..."})]}),t.jsxs(W,{variant:"ghost",size:"sm",onClick:j,className:"shrink-0 rounded-none border-l border-border h-8 px-3 text-xs",children:[t.jsx(N.Filter,{className:"size-3.5"}),"Filter"]}),x&&t.jsx(W,{variant:"ghost",size:"sm",onClick:E,title:"Clear filter","aria-label":"Clear filter",className:"shrink-0 rounded-none border-l border-border h-8 px-2 text-xs text-muted-foreground",children:t.jsx(N.X,{className:"size-3.5"})})]}),w&&t.jsxs("div",{className:"flex items-center gap-px border border-border rounded-md overflow-hidden shrink-0",children:[t.jsxs(W,{variant:"ghost",size:"sm",onClick:()=>m("/"),title:"Back to table list",className:"text-muted-foreground text-xs h-8 px-3 rounded-none",children:[t.jsx(N.Home,{className:"size-3.5"}),"Home"]}),w?.isEditable&&t.jsxs(W,{variant:"default",size:"sm",onClick:()=>m("edit/"),className:"h-8 text-xs px-4 rounded-none",children:[t.jsx(N.Plus,{className:"size-3.5"}),"Add"]})]})]})}class cn extends c.Component{constructor(n){super(n),this.state={hasError:!1,error:null}}static getDerivedStateFromError(n){return{hasError:!0,error:n}}componentDidCatch(n,r){const{onError:s,section:o}=this.props;console.error(`Error in ${o??"component"}:`,n,r),s?.(n,r)}handleRetry=()=>{this.setState({hasError:!1,error:null})};render(){const{hasError:n,error:r}=this.state,{children:s,fallback:o,section:i}=this.props;return n?o||t.jsx("div",{className:"flex items-center justify-center p-5 min-h-[100px]",children:t.jsxs(pt,{variant:"destructive",className:"max-w-[400px]",children:[t.jsx(N.AlertCircle,{className:"size-4"}),t.jsxs(Er,{children:["Something went wrong",i?` in ${i}`:""]}),t.jsxs(ht,{className:"mt-2",children:[t.jsx("p",{children:r?.message??"An unexpected error occurred"}),t.jsx(W,{variant:"destructive",size:"sm",className:"mt-3",onClick:this.handleRetry,children:"Try Again"})]})]})}):s}}function xc(){const{loading:e,error:n,data:r}=Pe();return e?t.jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-3 text-muted-foreground",children:[t.jsx(N.Database,{className:"size-10 animate-pulse"}),t.jsx("p",{className:"text-sm",children:"Loading schema..."})]}):n?t.jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-4 max-w-md mx-auto text-center",children:[t.jsx(N.Database,{className:"size-12 text-destructive"}),t.jsxs("div",{children:[t.jsx("h2",{className:"text-lg font-semibold text-foreground",children:"Connection Error"}),t.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:n.message})]})]}):r.length===0?t.jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-4 max-w-md mx-auto text-center",children:[t.jsx(N.Database,{className:"size-12 text-muted-foreground/50"}),t.jsxs("div",{children:[t.jsx("h2",{className:"text-lg font-semibold text-foreground",children:"No Tables Found"}),t.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"This database doesn't contain any tables. It may be a new or empty database."}),t.jsx("p",{className:"mt-3 text-xs text-muted-foreground/70",children:"Create tables in your database and reconnect, or try a different connection."})]})]}):t.jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-6 max-w-lg mx-auto text-center",children:[t.jsxs("div",{className:"flex items-center gap-3 text-muted-foreground/50",children:[t.jsx(N.Table2,{className:"size-10"}),t.jsx(N.MousePointerClick,{className:"size-6"})]}),t.jsxs("div",{children:[t.jsx("h2",{className:"text-lg font-semibold text-foreground",children:"Select a Table"}),t.jsx("p",{className:"mt-1 text-sm text-muted-foreground",children:"Choose a table from the sidebar to browse and edit its data."})]}),t.jsxs("div",{className:"text-xs text-muted-foreground/60 border border-border rounded-md px-4 py-3 bg-muted/30",children:[t.jsxs("p",{className:"font-medium text-muted-foreground mb-1",children:[r.length," table",r.length!==1?"s":""," available"]}),t.jsxs("p",{className:"leading-relaxed",children:[r.slice(0,8).map(s=>s.label).join(", "),r.length>8?`, and ${r.length-8} more`:""]})]})]})}function gc({children:e}){const{loading:n,error:r}=Pe();return n?t.jsxs("div",{className:"flex items-center justify-center flex-1 gap-3 text-muted-foreground",children:[t.jsx(N.Loader2,{className:"size-6 animate-spin"}),t.jsx("span",{className:"text-sm",children:"Connecting to database..."})]}):r?t.jsx("div",{className:"flex items-center justify-center flex-1",children:t.jsxs(pt,{variant:"destructive",className:"max-w-lg",children:[t.jsx(N.AlertCircle,{className:"size-4"}),t.jsx(Er,{children:"Database Connection Error"}),t.jsxs(ht,{className:"mt-2",children:[t.jsx("p",{className:"text-sm",children:r.message}),t.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:"Check your connection string and ensure the database server is running."})]})]})}):t.jsx(t.Fragment,{children:e})}function bc(){const[e,n]=c.useState(!0);return t.jsx(gc,{children:t.jsx(cc,{children:t.jsxs("div",{className:`grid h-full flex-1 min-h-0 grid-rows-[auto_1fr] ${e?"grid-cols-[minmax(150px,min-content)_1fr]":"grid-cols-[0px_1fr]"} md:grid-cols-[minmax(150px,min-content)_1fr] transition-[grid-template-columns] duration-200`,children:[t.jsxs("div",{className:"col-span-full sticky top-0 z-50 bg-background border-b border-border flex items-center",children:[t.jsx(W,{variant:"ghost",size:"icon",className:"md:hidden ml-1 shrink-0",onClick:()=>n(!e),"aria-label":"Toggle sidebar",title:"Toggle sidebar",children:t.jsx(N.PanelLeft,{className:"size-5"})}),t.jsx("div",{className:"flex-1 min-w-0",children:t.jsx(cn,{section:"Header",children:t.jsxs(fn,{children:[t.jsx(je,{path:"/:table/*",element:t.jsx(Bn,{})}),t.jsx(je,{path:"/:table",element:t.jsx(Bn,{})}),t.jsx(je,{path:"/",element:t.jsx(Bn,{})})]})})})]}),t.jsx("nav",{"aria-label":"Tables",className:`border-r border-border overflow-hidden min-h-0 ${e?"":"hidden"} md:block`,children:t.jsx(cn,{section:"Table List",children:t.jsx(Ka,{})})}),t.jsxs("main",{className:"flex flex-col overflow-hidden min-h-0 px-1 py-0.5",children:[t.jsx(cn,{section:"Data Panel",children:t.jsxs(fn,{children:[t.jsx(je,{path:"/:table/from/:filterTable/:id/edit/:editid",element:t.jsx(dt,{})}),t.jsx(je,{path:"/:table/from/:filterTable/:id",element:t.jsx(dt,{})}),t.jsx(je,{path:"/:table/:id/edit/:editid",element:t.jsx(dt,{})}),t.jsx(je,{path:"/:table/:id",element:t.jsx(dt,{})}),t.jsx(je,{path:"/:table/edit/:editid",element:t.jsx(dt,{})}),t.jsx(je,{path:"/:table/edit",element:t.jsx(dt,{})}),t.jsx(je,{path:"/:table",element:t.jsx(dt,{})}),t.jsx(je,{path:"/",element:t.jsx(xc,{})})]})}),t.jsx(cn,{section:"Data Edit",children:t.jsxs(fn,{children:[t.jsx(je,{path:"/:table/from/:filterTable/:id/edit/:editid",element:t.jsx(on,{})}),t.jsx(je,{path:"/:table/:id/edit/:editid",element:t.jsx(on,{})}),t.jsx(je,{path:"/:table/edit/:editid",element:t.jsx(on,{})}),t.jsx(je,{path:"/:table/edit",element:t.jsx(on,{})})]})})]})]})})})}function yc({onLocate:e}){const n=Zn();return c.useEffect(()=>{e?.(n)},[n,e]),t.jsx(bc,{})}function Ls({uri:e,fetcher:n,uiPath:r,onLocate:s,showStats:o=!1}){const i=c.useMemo(()=>n||(e?new rr(e):null),[e,n]),a=c.useMemo(()=>new me.QueryClient({defaultOptions:{queries:{staleTime:300*1e3,retry:1}}}),[]);return i?t.jsx(me.QueryClientProvider,{client:a,children:t.jsx(co,{value:i,children:t.jsx(Ia,{config:{showStats:o},children:t.jsx(Qi,{children:t.jsx(to,{path:r||"/",children:t.jsx(po,{children:t.jsx(yc,{onLocate:s})})})})})})}):t.jsx("section",{children:"CONFIG MISSING..."})}be.Editor=Ls,be.HttpGraphQLFetcher=rr,be.default=Ls,be.useTableMutation=sn,Object.defineProperties(be,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}));