@karni/ui 0.3.1 → 0.4.0

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 (127) hide show
  1. package/README.md +712 -72
  2. package/dist/index.cjs +5 -5
  3. package/dist/index.cjs.map +1 -1
  4. package/dist/index.js +8660 -4725
  5. package/dist/index.js.map +1 -1
  6. package/dist/manifest.json +18 -1
  7. package/dist/script-BVJ9BbPm.cjs +2 -0
  8. package/dist/script-BVJ9BbPm.cjs.map +1 -0
  9. package/dist/script-D1fn4Dm4.js +6 -0
  10. package/dist/script-D1fn4Dm4.js.map +1 -0
  11. package/dist/src/auth/AuthGuard.d.ts +69 -4
  12. package/dist/src/auth/LoginForm.d.ts +41 -7
  13. package/dist/src/auth/engine.d.ts +15 -13
  14. package/dist/src/auth/provider.d.ts +10 -10
  15. package/dist/src/auth/storage.d.ts +1 -1
  16. package/dist/src/auth/types.d.ts +3 -3
  17. package/dist/src/components/brand/karni-mark.d.ts +4 -4
  18. package/dist/src/components/chart/data-chart.d.ts +66 -11
  19. package/dist/src/components/empty-state/empty-state.d.ts +22 -2
  20. package/dist/src/components/file-upload/FileUpload.d.ts +67 -3
  21. package/dist/src/components/layout/layout.d.ts +104 -9
  22. package/dist/src/components/layout/route-focus.d.ts +43 -0
  23. package/dist/src/components/modal/modal.d.ts +49 -8
  24. package/dist/src/components/page/page.d.ts +36 -5
  25. package/dist/src/components/primitives/button.d.ts +1 -0
  26. package/dist/src/components/primitives/checkbox.d.ts +4 -1
  27. package/dist/src/components/primitives/dropdown-menu.d.ts +1 -1
  28. package/dist/src/components/primitives/icons.d.ts +9 -1
  29. package/dist/src/components/primitives/input.d.ts +4 -1
  30. package/dist/src/components/primitives/label.d.ts +4 -1
  31. package/dist/src/components/primitives/select.d.ts +37 -6
  32. package/dist/src/components/primitives/skeleton.d.ts +4 -1
  33. package/dist/src/components/primitives/switch.d.ts +4 -1
  34. package/dist/src/components/primitives/tabs.d.ts +2 -2
  35. package/dist/src/components/primitives/textarea.d.ts +4 -1
  36. package/dist/src/components/resource/ResourceDetail.d.ts +3 -3
  37. package/dist/src/components/resource/ResourceForm.d.ts +4 -3
  38. package/dist/src/components/resource/ResourceSelect.d.ts +3 -1
  39. package/dist/src/components/resource/ResourceTable.d.ts +9 -3
  40. package/dist/src/components/resource/audit-fields.d.ts +1 -1
  41. package/dist/src/components/resource/detail/ResourceDetail.d.ts +109 -11
  42. package/dist/src/components/resource/empty-value.d.ts +17 -0
  43. package/dist/src/components/resource/form/ResourceForm.d.ts +65 -6
  44. package/dist/src/components/resource/form/field-inputs.d.ts +15 -1
  45. package/dist/src/components/resource/form/form-states.d.ts +87 -0
  46. package/dist/src/components/resource/form/prepare.d.ts +3 -3
  47. package/dist/src/components/resource/form/server-errors.d.ts +14 -0
  48. package/dist/src/components/resource/history/ChangeHistory.d.ts +46 -4
  49. package/dist/src/components/resource/import/ResourceImport.d.ts +73 -7
  50. package/dist/src/components/resource/nouns.d.ts +12 -0
  51. package/dist/src/components/resource/query-state.d.ts +20 -0
  52. package/dist/src/components/resource/resource-names.d.ts +23 -0
  53. package/dist/src/components/resource/select/ResourceSelect.d.ts +39 -8
  54. package/dist/src/components/resource/select/select-states.d.ts +68 -0
  55. package/dist/src/components/resource/select/use-option-pages.d.ts +37 -0
  56. package/dist/src/components/resource/select/venue-backend.d.ts +144 -0
  57. package/dist/src/components/resource/table/BulkActionsBar.d.ts +62 -5
  58. package/dist/src/components/resource/table/CardList.d.ts +31 -0
  59. package/dist/src/components/resource/table/ConfirmDialog.d.ts +28 -0
  60. package/dist/src/components/resource/table/ExportButtons.d.ts +2 -2
  61. package/dist/src/components/resource/table/FilterBar.d.ts +3 -3
  62. package/dist/src/components/resource/table/PaginationControls.d.ts +15 -3
  63. package/dist/src/components/resource/table/ResourceTable.d.ts +79 -14
  64. package/dist/src/components/resource/table/RowCard.d.ts +31 -0
  65. package/dist/src/components/resource/table/TableView.d.ts +29 -0
  66. package/dist/src/components/resource/table/ViewOptions.d.ts +19 -0
  67. package/dist/src/components/resource/table/access.d.ts +12 -0
  68. package/dist/src/components/resource/table/derive-columns.d.ts +2 -2
  69. package/dist/src/components/resource/table/grid-navigation.d.ts +23 -0
  70. package/dist/src/components/resource/table/layout.d.ts +37 -0
  71. package/dist/src/components/resource/table/preferences.d.ts +12 -0
  72. package/dist/src/components/resource/table/slots.d.ts +41 -0
  73. package/dist/src/components/resource/table/states.d.ts +91 -0
  74. package/dist/src/components/resource/table/story-fixtures.d.ts +25 -0
  75. package/dist/src/components/resource/table/structural-columns.d.ts +25 -0
  76. package/dist/src/components/resource/table/table-icons.d.ts +16 -0
  77. package/dist/src/components/resource/table/table-utils.d.ts +27 -3
  78. package/dist/src/components/resource/table/url-state.d.ts +67 -0
  79. package/dist/src/components/resource/table/use-container-width.d.ts +10 -0
  80. package/dist/src/components/resource/testapp-fixtures.d.ts +78 -0
  81. package/dist/src/components/stat/stat.d.ts +36 -6
  82. package/dist/src/components/toast/toast-store.d.ts +1 -1
  83. package/dist/src/components/toast/toaster.d.ts +39 -6
  84. package/dist/src/components/toast/use-toast.d.ts +1 -1
  85. package/dist/src/hooks/keys.d.ts +4 -4
  86. package/dist/src/hooks/multipart.d.ts +9 -9
  87. package/dist/src/hooks/params.d.ts +1 -1
  88. package/dist/src/hooks/types.d.ts +3 -3
  89. package/dist/src/hooks/useChangeHistory.d.ts +3 -2
  90. package/dist/src/hooks/useResourceImport.d.ts +2 -2
  91. package/dist/src/hooks/useResourceMutations.d.ts +2 -2
  92. package/dist/src/hooks/useUnsavedChangesGuard.d.ts +31 -0
  93. package/dist/src/index.d.ts +49 -31
  94. package/dist/src/lib/roles.d.ts +4 -4
  95. package/dist/src/lib/variants.d.ts +1 -1
  96. package/dist/src/primitives/registry.d.ts +81 -0
  97. package/dist/src/schema/client.d.ts +10 -10
  98. package/dist/src/schema/parse.d.ts +2 -2
  99. package/dist/src/schema/provider.d.ts +10 -3
  100. package/dist/src/schema/types.d.ts +18 -9
  101. package/dist/src/schema/useSchema.d.ts +5 -1
  102. package/dist/src/states/ErrorState.d.ts +43 -0
  103. package/dist/src/states/PendingButton.d.ts +16 -0
  104. package/dist/src/states/describe-error.d.ts +25 -0
  105. package/dist/src/states/hooks.d.ts +10 -0
  106. package/dist/src/theme/script.d.ts +12 -0
  107. package/dist/src/theme/theme.d.ts +45 -0
  108. package/dist/styles.css +174 -13
  109. package/dist/tailwind-preset.cjs +2 -2
  110. package/dist/tailwind-preset.cjs.map +1 -1
  111. package/dist/tailwind-preset.d.ts +83 -1
  112. package/dist/tailwind-preset.js +181 -62
  113. package/dist/tailwind-preset.js.map +1 -1
  114. package/dist/tailwind-v4.css +31 -0
  115. package/dist/vite-plugin.cjs +2 -0
  116. package/dist/vite-plugin.cjs.map +1 -0
  117. package/dist/vite-plugin.d.ts +19 -0
  118. package/dist/vite-plugin.js +16 -0
  119. package/dist/vite-plugin.js.map +1 -0
  120. package/eslint-plugin/index.js +4 -0
  121. package/eslint-plugin/rules/max-page-lines.js +1 -1
  122. package/eslint-plugin/rules/no-deep-imports.js +1 -1
  123. package/eslint-plugin/rules/no-direct-http.js +1 -1
  124. package/eslint-plugin/rules/no-raw-elements.js +1 -1
  125. package/eslint-plugin/rules/no-style-literals.js +222 -0
  126. package/eslint-plugin/rules.json +10 -4
  127. package/package.json +22 -19
package/dist/index.cjs CHANGED
@@ -1,9 +1,9 @@
1
- "use strict";var hr=Object.defineProperty;var gr=(e,t,n)=>t in e?hr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var Z=(e,t,n)=>gr(e,typeof t!="symbol"?t+"":t,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const pr=require("clsx"),xr=require("tailwind-merge"),r=require("react/jsx-runtime"),re=require("react"),br=require("@radix-ui/react-select"),yr=require("@radix-ui/react-checkbox"),jr=require("@radix-ui/react-switch"),vr=require("@radix-ui/react-label"),wr=require("@radix-ui/react-tabs"),Nr=require("@radix-ui/react-dropdown-menu"),W=require("@tanstack/react-query"),B=require("zod"),Sr=require("@radix-ui/react-dialog"),kr=require("@radix-ui/react-toast"),Cr=require("@radix-ui/react-visually-hidden"),Rr=require("@hookform/resolvers/zod"),yt=require("react-hook-form"),Tr=require("@radix-ui/react-popover"),Ke=require("@tanstack/react-table");var ut=typeof document<"u"?document.currentScript:null;function pe(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const n in e)if(n!=="default"){const s=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,s.get?s:{enumerable:!0,get:()=>e[n]})}}return t.default=e,Object.freeze(t)}const d=pe(re),se=pe(br),qt=pe(yr),Jt=pe(jr),Ar=pe(vr),st=pe(wr),ge=pe(Nr),we=pe(Sr),Fe=pe(kr),Mr=pe(Cr),Ge=pe(Tr);function p(...e){return xr.twMerge(pr.clsx(e))}const Pe=new Map;function Lr(){var e,t;try{const n={url:typeof document>"u"?require("url").pathToFileURL(__filename).href:ut&&ut.tagName.toUpperCase()==="SCRIPT"&&ut.src||new URL("index.cjs",document.baseURI).href};return!(!n.hot||((e=n.env)==null?void 0:e.MODE)==="test"||typeof process<"u"&&((t=process.env)==null?void 0:t.VITEST)!==void 0)}catch{return!1}}let Dr=Lr;function Y(e,t,n){var o;if(n!=null&&n.replace){const a=((o=n.reason)==null?void 0:o.trim())??"";if(a==="")throw new Error(`[karni] registerComponentRole: replacing role "${e}" requires a non-empty reason — pass { replace: true, reason: "<why>" }.`);const u=Pe.get(e);u!==void 0&&u!==t&&console.warn(`[karni] component role "${e}" replaced: "${u}" -> "${t}" (${a})`),Pe.set(e,t);return}const s=Pe.get(e);if(s===void 0||s===t){Pe.set(e,t);return}const i=`[karni] duplicate component role "${e}": already registered by "${s}", now claimed by "${t}". Compose or extend the existing component instead, or replace it on purpose with { replace: true, reason: "<why>" }.`;if(Dr()){console.error(i),Pe.set(e,t);return}throw new Error(i)}function Er(){return Object.freeze(Object.fromEntries(Pe))}function kt(e){const t=Object.keys(e.variants);return n=>{var l;const{className:s,...i}=n??{},o=i,a={},u=[];e.base&&u.push(e.base);for(const c of t){const m=o[c]??((l=e.defaultVariants)==null?void 0:l[c]);if(m==null)continue;a[c]=m;const h=e.variants[c][m];h&&u.push(h)}for(const c of e.compoundVariants??[]){const{className:m,...h}=c,b=h;Object.keys(b).every(y=>{const N=b[y];return N!=null&&a[y]===N})&&u.push(m)}return p(...u,s)}}const jn=kt({base:"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",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 hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"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"}},defaultVariants:{variant:"default",size:"default"}}),Q=d.forwardRef(({className:e,variant:t,size:n,type:s,...i},o)=>r.jsx("button",{ref:o,type:s??"button",className:jn({variant:t,size:n,className:e}),...i}));Q.displayName="Button";const ye=d.forwardRef(({className:e,...t},n)=>r.jsx("input",{ref:n,className:p("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),...t}));ye.displayName="Input";const Xe=d.forwardRef(({className:e,...t},n)=>r.jsx("textarea",{ref:n,className:p("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",e),...t}));Xe.displayName="Textarea";function Ct(e){return{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,focusable:!1,...e}}function qe(e){return r.jsx("svg",{...Ct(e),children:r.jsx("polyline",{points:"20 6 9 17 4 12"})})}function it(e){return r.jsx("svg",{...Ct(e),children:r.jsx("polyline",{points:"6 9 12 15 18 9"})})}function vn(e){return r.jsx("svg",{...Ct(e),children:r.jsx("polyline",{points:"18 15 12 9 6 15"})})}const Oe="__karni_empty__",wn=se.Root,Fr=se.Group,Nn=se.Value,Rt=d.forwardRef(({className:e,children:t,...n},s)=>r.jsxs(se.Trigger,{ref:s,className:p("flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",e),...n,children:[t,r.jsx(se.Icon,{asChild:!0,children:r.jsx(it,{className:"h-4 w-4 shrink-0 opacity-50"})})]}));Rt.displayName="SelectTrigger";const Sn=d.forwardRef(({className:e,...t},n)=>r.jsx(se.ScrollUpButton,{ref:n,className:p("flex cursor-default items-center justify-center py-1",e),...t,children:r.jsx(vn,{className:"h-4 w-4"})}));Sn.displayName="SelectScrollUpButton";const kn=d.forwardRef(({className:e,...t},n)=>r.jsx(se.ScrollDownButton,{ref:n,className:p("flex cursor-default items-center justify-center py-1",e),...t,children:r.jsx(it,{className:"h-4 w-4"})}));kn.displayName="SelectScrollDownButton";const Tt=d.forwardRef(({className:e,children:t,position:n="popper",...s},i)=>r.jsx(se.Portal,{children:r.jsxs(se.Content,{ref:i,position:n,className:p("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border border-border bg-popover text-popover-foreground shadow-md",n==="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),...s,children:[r.jsx(Sn,{}),r.jsx(se.Viewport,{className:p("p-1",n==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:t}),r.jsx(kn,{})]})}));Tt.displayName="SelectContent";const Cn=d.forwardRef(({className:e,...t},n)=>r.jsx(se.Label,{ref:n,className:p("py-1.5 pl-8 pr-2 text-sm font-semibold",e),...t}));Cn.displayName="SelectLabel";const Ie=d.forwardRef(({className:e,children:t,...n},s)=>r.jsxs(se.Item,{ref:s,className:p("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...n,children:[r.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:r.jsx(se.ItemIndicator,{children:r.jsx(qe,{className:"h-4 w-4"})})}),r.jsx(se.ItemText,{children:t})]}));Ie.displayName="SelectItem";const Rn=d.forwardRef(({className:e,...t},n)=>r.jsx(se.Separator,{ref:n,className:p("-mx-1 my-1 h-px bg-muted",e),...t}));Rn.displayName="SelectSeparator";const Be=d.forwardRef((e,t)=>{const{value:n,onValueChange:s,options:i,placeholder:o,clearable:a=!1,clearLabel:u="—",disabled:l,name:c,id:m,className:h,contentClassName:b,children:T,"aria-label":R}=e,y=d.useMemo(()=>{const w=i.filter(L=>L.value!==""&&L.value!==Oe);return w.length!==i.length&&console.warn(`[karni-ui] <Select> option values "" and "${Oe}" are reserved; those options were dropped. Use the \`clearable\` prop for an empty choice.`),w},[i]),f=n==null||n===""?a?Oe:"":n,j=d.useCallback(w=>{s==null||s(w===Oe?null:w)},[s]);return r.jsxs(wn,{value:f,onValueChange:j,disabled:l,name:c,children:[r.jsx(Rt,{ref:t,id:m,className:h,"aria-label":R,children:r.jsx(Nn,{placeholder:o})}),r.jsxs(Tt,{className:b,children:[a?r.jsx(Ie,{value:Oe,className:"text-muted-foreground",children:u}):null,y.map(w=>r.jsx(Ie,{value:w.value,disabled:w.disabled,children:w.label},w.value)),T]})]})});Be.displayName="Select";const et=d.forwardRef(({className:e,...t},n)=>r.jsx(qt.Root,{ref:n,className:p("peer h-4 w-4 shrink-0 rounded-sm border border-primary 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 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",e),...t,children:r.jsx(qt.Indicator,{className:"flex items-center justify-center text-current",children:r.jsx(qe,{className:"h-3.5 w-3.5"})})}));et.displayName="Checkbox";const At=d.forwardRef(({className:e,...t},n)=>r.jsx(Jt.Root,{ref:n,className:p("peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input",e),...t,children:r.jsx(Jt.Thumb,{className:"pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0"})}));At.displayName="Switch";const We=d.forwardRef(({className:e,...t},n)=>r.jsx(Ar.Root,{ref:n,className:p("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70",e),...t}));We.displayName="Label";const Pr=st.Root,Tn=d.forwardRef(({className:e,...t},n)=>r.jsx(st.List,{ref:n,className:p("inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground",e),...t}));Tn.displayName="TabsList";const An=d.forwardRef(({className:e,...t},n)=>r.jsx(st.Trigger,{ref:n,className:p("inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm",e),...t}));An.displayName="TabsTrigger";const Mn=d.forwardRef(({className:e,...t},n)=>r.jsx(st.Content,{ref:n,className:p("mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",e),...t}));Mn.displayName="TabsContent";const Or=ge.Root,$r=ge.Trigger,_r=ge.Group,zr=ge.Portal,Ln=d.forwardRef(({className:e,sideOffset:t=4,...n},s)=>r.jsx(ge.Portal,{children:r.jsx(ge.Content,{ref:s,sideOffset:t,className:p("z-50 min-w-[8rem] overflow-hidden rounded-md border border-border bg-popover p-1 text-popover-foreground shadow-md",e),...n})}));Ln.displayName="DropdownMenuContent";const Dn=d.forwardRef(({className:e,inset:t,...n},s)=>r.jsx(ge.Item,{ref:s,className:p("relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t&&"pl-8",e),...n}));Dn.displayName="DropdownMenuItem";const En=d.forwardRef(({className:e,children:t,checked:n,...s},i)=>r.jsxs(ge.CheckboxItem,{ref:i,checked:n,className:p("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",e),...s,children:[r.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:r.jsx(ge.ItemIndicator,{children:r.jsx(qe,{className:"h-4 w-4"})})}),t]}));En.displayName="DropdownMenuCheckboxItem";const Fn=d.forwardRef(({className:e,inset:t,...n},s)=>r.jsx(ge.Label,{ref:s,className:p("px-2 py-1.5 text-sm font-semibold",t&&"pl-8",e),...n}));Fn.displayName="DropdownMenuLabel";const Pn=d.forwardRef(({className:e,...t},n)=>r.jsx(ge.Separator,{ref:n,className:p("-mx-1 my-1 h-px bg-muted",e),...t}));Pn.displayName="DropdownMenuSeparator";const ce=d.forwardRef(({className:e,...t},n)=>r.jsx("div",{ref:n,className:p("animate-pulse rounded-md bg-muted",e),...t}));ce.displayName="Skeleton";function Zt(e){return typeof e=="string"?e:String(e)}function Br(e){return Array.isArray(e)}function Mt(e){const t={};if(e===void 0)return t;if(e.filters!==void 0)for(const[n,s]of Object.entries(e.filters))s!=null&&(Br(s)?s.length>0&&(t[n]=s.map(Zt)):t[n]=Zt(s));return e.page!==void 0&&(t.page=String(e.page)),e.pageSize!==void 0&&(t.page_size=String(e.pageSize)),e.ordering!==void 0&&e.ordering!==""&&(t.ordering=e.ordering),e.search!==void 0&&e.search!==""&&(t.search=e.search),e.expand!==void 0&&e.expand.length>0&&(t.expand=e.expand.join(",")),t}function On(e){const t={};return(e==null?void 0:e.expand)!==void 0&&e.expand.length>0&&(t.expand=e.expand.join(",")),t}function jt(e){const t={};for(const n of Object.keys(e).sort()){const s=Vr(e[n]);s!==void 0&&(t[n]=s)}return t}function Vr(e){if(e!=null)return Array.isArray(e)?e.filter(t=>t!=null).map(t=>typeof t=="object"&&t!==null?JSON.stringify(t):String(t)):typeof e=="object"?jt(e):String(e)}function Je(e){return`/${e.replace(/^\/+|\/+$/g,"")}/`}function tt(e,t){return`${Je(e)}${encodeURIComponent(String(t))}/`}const ue={schema(){return["karni","$schema"]},resource(e){return["karni",e]},list(e,t){return["karni",e,"list",jt(Mt(t))]},detail(e,t,n){const s=On(n);return Object.keys(s).length>0?["karni",e,"detail",String(t),jt(s)]:["karni",e,"detail",String(t)]}},$n=re.createContext(null);function Ur(e){const{client:t,queryClient:n,children:s}=e,[i]=re.useState(()=>n??new W.QueryClient);return r.jsx(W.QueryClientProvider,{client:n??i,children:r.jsx($n.Provider,{value:t,children:s})})}function de(){const e=re.useContext($n);if(e===null)throw new Error("useKarniClient must be used within <KarniProvider>. Wrap your app in <KarniProvider client={createKarniClient({ baseUrl })}>.");return e}function Lt(e,t,n){const s=de();return W.useQuery({...n,queryKey:ue.list(e,t),queryFn:({signal:i})=>s.request(Je(e),{query:Mt(t),signal:i})})}function vt(e){return typeof File<"u"&&e instanceof File}function Kr(e){return typeof Blob<"u"&&e instanceof Blob}function Hr(e){return Object.values(e).some(t=>vt(t)||Array.isArray(t)&&t.some(n=>vt(n)))}function Gt(e,t,n){if(n!=null){if(vt(n)||Kr(n)){e.append(t,n);return}if(typeof n=="object"){e.append(t,JSON.stringify(n));return}e.append(t,String(n))}}function Qr(e){const t=new FormData;for(const[n,s]of Object.entries(e))if(s!=null)if(Array.isArray(s))for(const i of s)Gt(t,n,i);else Gt(t,n,s);return t}function Yt(e){return Hr(e)?Qr(e):e}function Wr(e,t){const n=new Set;if(typeof e!="object"||e===null)return n;const s=e.resources;if(typeof s!="object"||s===null)return n;const i=s[t];if(typeof i!="object"||i===null)return n;const o=i.fields;if(!Array.isArray(o))return n;for(const a of o){if(typeof a!="object"||a===null)continue;const{name:u,kind:l}=a;typeof u=="string"&&l==="file"&&n.add(u)}return n}function qr(e){return typeof e=="string"?!0:Array.isArray(e)&&e.every(t=>typeof t=="string")}function Jr(e,t){if(t.size===0)return e;const n={};for(const[s,i]of Object.entries(e))t.has(s)&&qr(i)||(n[s]=i);return n}function Dt(e,t){const n=de(),s=W.useQueryClient(),i=t==null?void 0:t.invalidateKeys,o=re.useCallback(async()=>{await s.invalidateQueries({queryKey:ue.resource(e)}),i!==void 0&&await Promise.all(i.map(c=>s.invalidateQueries({queryKey:c})))},[s,e,i]),a=W.useMutation({mutationFn:c=>n.request(Je(e),{method:"POST",body:Yt(c)}),onSuccess:()=>o()}),u=W.useMutation({mutationFn:({id:c,values:m})=>{const h=Wr(s.getQueryData(ue.schema()),e),b=Jr(m,h);return n.request(tt(e,c),{method:"PATCH",body:Yt(b)})},onSuccess:()=>o()}),l=W.useMutation({mutationFn:async c=>{await n.request(tt(e,c),{method:"DELETE"})},onSuccess:()=>o()});return{create:a,update:u,remove:l}}function G(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function _n(e){const t=e.replace(/[_-]+/g," ").trim();return t.length===0?e:t.charAt(0).toUpperCase()+t.slice(1)}const Xt="#/components/schemas/";function Zr(e,t){var n,s;if(t.startsWith(Xt))return(s=(n=e.components)==null?void 0:n.schemas)==null?void 0:s[t.slice(Xt.length)]}function le(e,t,n=[]){if(t!==void 0){if(typeof t.$ref=="string"){if(n.includes(t.$ref))return{};const s=Zr(e,t.$ref);if(s===void 0)return{};const i=le(e,s,[...n,t.$ref])??{},o={...t};return delete o.$ref,{...i,...o}}if(Array.isArray(t.allOf)&&t.allOf.length===1){const s=le(e,t.allOf[0],n)??{},i={...t};return delete i.allOf,{...s,...i}}return t}}function zn(e){return Array.isArray(e.type)?{type:e.type.filter(n=>n!=="null")[0],nullable:e.type.includes("null")||e.nullable===!0}:{type:typeof e.type=="string"?e.type:void 0,nullable:e.nullable===!0}}function Gr(e){const t=e["x-karni-relation"];if(G(t)&&typeof t.resource=="string"&&t.resource.length>0)return{resource:t.resource,many:t.many===!0}}function dt(e){const{type:t}=zn(e);return t==="integer"||t==="number"?"integer":e.format==="uuid"?"uuid":"string"}function Yr(e,t,n){const s=[];let i=!1,o;for(const a of t){const u=le(e,a,n);if(u===void 0||!Array.isArray(u.enum))return;o===void 0&&u.description!==void 0&&s.length===0&&(o=u.description);for(const l of u.enum)l===null?i=!0:l!==""&&s.push(l)}return{values:s,nullable:i,description:o}}const Xr=/^\* `(.+?)` - (.*)$/;function Ir(e){if(e===void 0)return{};const t={},n=[];for(const i of e.split(`
2
- `)){const o=Xr.exec(i.trim());o!==null&&o[1]!==void 0&&o[2]!==void 0?t[o[1]]=o[2].trim():n.push(i)}const s=n.join(`
3
- `).trim();return{...Object.keys(t).length>0?{labels:t}:{},...s!==""?{rest:s}:{}}}function It(e,t){const{labels:n,rest:s}=Ir(t);n!==void 0&&(e.enumLabels=n),e.description=s}function es(e){return e.type===void 0&&e.enum===void 0&&e.properties===void 0&&e.items===void 0&&e.oneOf===void 0&&e.anyOf===void 0&&e.allOf===void 0&&e.$ref===void 0}function mt(e,t){const n=le(e,t)??{},s=Gr(n),{type:i,nullable:o}=zn(n),a={kind:"unknown",nullable:o,format:n.format,description:n.description,title:n.title,default:n.default,readOnly:n.readOnly===!0,writeOnly:n.writeOnly===!0,maxLength:n.maxLength,min:n.minimum,max:n.maximum,relation:s,binary:!1},u=n.oneOf??n.anyOf;if(Array.isArray(u)){const l=Yr(e,u,[]);return l!==void 0&&(a.kind="enum",a.enumValues=l.values,a.nullable=a.nullable||l.nullable,It(a,n.description??l.description)),a}if(Array.isArray(n.enum))return a.kind="enum",a.nullable=a.nullable||n.enum.includes(null),a.enumValues=n.enum.filter(l=>l!==null&&l!==""),It(a,n.description),a;if(s!==void 0&&!s.many)return a.kind="relation",a.relationValueType=dt(n),a;switch(i){case"string":return n.format==="binary"?(a.kind="file",a.binary=!0):n.format==="date"?a.kind="date":n.format==="date-time"?a.kind="datetime":n.format===void 0&&n.maxLength===void 0?a.kind="text":a.kind="string",a;case"integer":return a.kind="integer",a;case"number":return a.kind="number",a;case"boolean":return a.kind="boolean",a;case"array":{if(s!==void 0){a.kind="relation";const l=le(e,n.items)??{};a.relationValueType=dt(l)}else a.kind="array";return a}case"object":return a.kind="json",a;default:return s!==void 0?(a.kind="relation",a.relationValueType=dt(n)):es(n)&&(a.kind="json"),a}}function en(e,t,n,s,i,o){let a;(n==null?void 0:n.binary)===!0?a="file":n!==void 0&&n.kind!=="unknown"?a=n.kind:t!==void 0&&t.kind!=="unknown"?a=t.kind:a="unknown";const u=(n==null?void 0:n.relation)??(t==null?void 0:t.relation),l=(n==null?void 0:n.title)??(t==null?void 0:t.title),c={name:e,label:l!==void 0&&l.length>0?l:_n(e),kind:a,required:s.has(e),readOnly:!i||(t==null?void 0:t.readOnly)===!0||(n==null?void 0:n.readOnly)===!0||i&&t!==void 0&&n===void 0,writeOnly:(n==null?void 0:n.writeOnly)===!0||(t==null?void 0:t.writeOnly)===!0||t===void 0&&n!==void 0,nullable:n!==void 0?n.nullable:(t==null?void 0:t.nullable)??!1,order:o},m=(n==null?void 0:n.enumValues)??(t==null?void 0:t.enumValues),h=(n==null?void 0:n.default)??(t==null?void 0:t.default);h!==void 0&&(c.default=h),m!==void 0&&(c.enumValues=m);const b=(n==null?void 0:n.enumLabels)??(t==null?void 0:t.enumLabels);b!==void 0&&(c.enumLabels=b);const T=(n==null?void 0:n.maxLength)??(t==null?void 0:t.maxLength);T!==void 0&&(c.maxLength=T);const R=(n==null?void 0:n.min)??(t==null?void 0:t.min);R!==void 0&&(c.min=R);const y=(n==null?void 0:n.max)??(t==null?void 0:t.max);y!==void 0&&(c.max=y);const N=(n==null?void 0:n.format)??(t==null?void 0:t.format);N!==void 0&&(c.format=N);const f=(t==null?void 0:t.description)??(n==null?void 0:n.description);if(f!==void 0&&(c.description=f),u!==void 0){c.relation=u;const j=(n==null?void 0:n.relationValueType)??(t==null?void 0:t.relationValueType);j!==void 0&&(c.relationValueType=j)}return c}function ke(e,t,n,s){const i=[];let o;for(const u of s.parameters??[])if(!(!G(u)||u.in!=="query"||typeof u.name!="string")&&(i.push(u.name),u.name==="expand")){const l=le(e,u.schema),c=le(e,l==null?void 0:l.items),m=(l==null?void 0:l.enum)??(c==null?void 0:c.enum);Array.isArray(m)&&(o=m.filter(h=>typeof h=="string"))}const a={path:t,method:n,queryParams:i,hasSearch:i.includes("search")};return typeof s.operationId=="string"&&(a.operationId=s.operationId),o!==void 0&&(a.expandEnum=o),a}function ts(e,t){var a,u,l,c;const n=((a=t.responses)==null?void 0:a["200"])??((u=t.responses)==null?void 0:u["201"])??Object.values(t.responses??{})[0],s=(l=n==null?void 0:n.content)==null?void 0:l["application/json"],i=le(e,s==null?void 0:s.schema);if(i===void 0)return;const o=le(e,(c=i.properties)==null?void 0:c.results);return o!==void 0&&o.type==="array"?le(e,o.items):i.type==="array"?le(e,i.items):i}function ns(e,t){var i;const n=(i=t.requestBody)==null?void 0:i.content;if(!G(n))return;const s=n["application/json"]??n["multipart/form-data"]??Object.values(n)[0];return le(e,s==null?void 0:s.schema)}const rs=["get","post","put","patch","delete"];function ss(e){const t=G(e)?e:{},n=G(t.paths)?t.paths:{},s={},i=t["x-karni-auth-mode"],o=i==="jwt"||i==="session"?i:void 0,a=[];for(const[l,c]of Object.entries(n)){if(!G(c))continue;const m=c.get;G(m)&&typeof m["x-karni-resource"]=="string"&&a.push({resource:m["x-karni-resource"],path:l,item:c})}for(const{resource:l,path:c,item:m}of a){const h=m.get;if(!G(h))continue;const b=Object.entries(n).find(([v])=>{if(!v.startsWith(c))return!1;const P=v.slice(c.length);return/^\{[^/{}]+\}\/?$/.test(P)}),T=b==null?void 0:b[0],R=b!==void 0&&G(b[1])?b[1]:void 0,y={list:ke(t,c,"get",h)},N=G(m.post)?m.post:void 0;N!==void 0&&(y.create=ke(t,c,"post",N));const f=n[`${c}export/`],j=G(f)&&G(f.get)?f.get:void 0;j!==void 0&&(y.export=ke(t,`${c}export/`,"get",j));const w=n[`${c}import/`],L=G(w)&&G(w.post)?w.post:void 0;if(L!==void 0&&(y.import=ke(t,`${c}import/`,"post",L)),T!==void 0&&R!==void 0)for(const v of rs){const P=R[v];G(P)&&(v==="get"?y.detail=ke(t,T,"get",P):v==="patch"?y.update=ke(t,T,"patch",P):v==="put"&&y.update===void 0?y.update=ke(t,T,"put",P):v==="delete"&&(y.remove=ke(t,T,"delete",P)))}const $=ts(t,h),x=N!==void 0?ns(t,N):void 0,S=x!==void 0,F=G($==null?void 0:$.properties)?$.properties:{},z=G(x==null?void 0:x.properties)?x.properties:{},U=new Set(Array.isArray(x==null?void 0:x.required)?x.required:[]),E=[];let A=0;for(const[v,P]of Object.entries(F)){const _=mt(t,P),O=z[v],q=O!==void 0?mt(t,O):void 0;E.push(en(v,_,q,U,S,A)),A+=1}for(const[v,P]of Object.entries(z)){if(v in F)continue;const _=mt(t,P);E.push(en(v,void 0,_,U,S,A)),A+=1}s[l]={resource:l,operations:y,fields:E}}const u={resources:s};return o!==void 0&&(u.authMode=o),u}const is=["karni","$schema"];function os(){const e=de();return W.useQuery({queryKey:is,staleTime:1/0,queryFn:async()=>ss(await e.request(e.schemaUrl))})}function ot(e){const t=os();if(t.data!==void 0){const n=t.data.resources[e];if(n===void 0){const s=Object.keys(t.data.resources).sort();throw new Error(`Unknown resource "${e}". Known resources: ${s.length>0?s.join(", "):"(none — does the schema expose x-karni-resource?)"}.`)}return{data:n,isLoading:!1,error:t.error}}return{data:void 0,isLoading:t.isPending,error:t.error}}Y("empty-state","EmptyState");const nt=d.forwardRef(({icon:e,title:t,description:n,action:s,className:i,children:o,...a},u)=>r.jsxs("div",{ref:u,className:p("flex w-full flex-col items-center justify-center gap-2 rounded-lg border border-dashed border-border bg-background px-6 py-12 text-center",i),...a,children:[e!=null&&r.jsx("div",{"aria-hidden":"true",className:"mb-2 text-muted-foreground [&>svg]:h-10 [&>svg]:w-10",children:e}),r.jsx("h3",{className:"text-base font-semibold text-foreground",children:t}),n!=null&&r.jsx("p",{className:"max-w-sm text-sm text-muted-foreground",children:n}),s!=null&&r.jsx("div",{className:"mt-3 flex items-center gap-2",children:s}),o]}));nt.displayName="EmptyState";const rt=Object.freeze(["id","created_at","updated_at","created_by","updated_by"]);function Et(e){return e.readOnly&&rt.includes(e.name)}function Ft(e){const t=[],n=[];for(const s of e)(Et(s)?n:t).push(s);return n.sort((s,i)=>rt.indexOf(s.name)-rt.indexOf(i.name)),{domain:t,audit:n}}const as=["name","title","label","email","str"];function De(e){for(const n of as){const s=e[n];if(typeof s=="string"&&s.trim().length>0)return s}const t=e.id;return t!=null?String(t):""}function ls(e){const{selectedIds:t,bulkActions:n,onClear:s,className:i}=e;return r.jsxs("div",{role:"toolbar","aria-label":"Bulk actions",className:p("flex flex-wrap items-center gap-2 rounded-md border border-border bg-muted px-3 py-2",i),children:[r.jsxs("p",{className:"text-sm font-medium text-foreground",children:[t.length," selected"]}),r.jsx(Q,{variant:"ghost",size:"sm",onClick:s,children:"Clear"}),r.jsx("div",{className:"ml-auto flex flex-wrap items-center gap-2",children:n.map((o,a)=>r.jsx(Q,{variant:o.destructive===!0?"destructive":"outline",size:"sm",onClick:()=>o.onClick([...t]),children:o.label},a))})]})}function cs(e){if(e.length!==0)return e.map(t=>t.desc?`-${t.id}`:t.id).join(",")}function tn(e){return typeof e=="object"&&e!==null&&"status"in e&&e.status===404}function us(e,t){return e===void 0||e<=0||t<=0?1:Math.max(1,Math.ceil(e/t))}function Ze(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)?e:{}}function ds(e){if(typeof e=="object"&&e!==null){const t=e.data;if(typeof t=="object"&&t!==null){const s=t.detail;if(typeof s=="string"&&s.length>0)return s}const n=e.message;if(typeof n=="string"&&n.length>0)return n}return"Something went wrong while loading this table."}function Bn(e,t){const n=t==null?void 0:t[String(e)];if(n!==void 0)return n;if(typeof e=="number")return String(e);if(/^[A-Za-z0-9_ ]+$/.test(e)&&(e===e.toUpperCase()||e===e.toLowerCase())){const i=e.toLowerCase().replace(/_+/g," ").trim();return i.length===0?e:i.charAt(0).toUpperCase()+i.slice(1)}return e}const ms=new Set(["json","file","unknown"]),fs=new Set(["relation","json","file","array","unknown"]);function ze(){return r.jsx("span",{"aria-hidden":"true",className:"text-muted-foreground",children:"–"})}function hs({value:e}){return e?r.jsxs("span",{className:"inline-flex items-center text-foreground",children:[r.jsx(qe,{className:"h-4 w-4"}),r.jsx("span",{className:"sr-only",children:"Yes"})]}):r.jsxs("span",{className:"inline-flex items-center text-muted-foreground",children:[r.jsx("span",{"aria-hidden":"true",children:"–"}),r.jsx("span",{className:"sr-only",children:"No"})]})}function gs({value:e}){return r.jsx("code",{className:"rounded bg-muted px-1 py-0.5 text-xs",children:String(e)})}function nn(e,t){return e==null?r.jsx(ze,{}):typeof e=="object"&&!Array.isArray(e)?t(Ze(e)):r.jsx(gs,{value:e})}function ps({value:e,label:t}){return e==null?r.jsx(ze,{}):Array.isArray(e)?e.length===0?r.jsx(ze,{}):r.jsx("span",{className:"inline-flex flex-wrap items-center gap-x-2 gap-y-1",children:e.map((n,s)=>r.jsx(d.Fragment,{children:nn(n,t)},s))}):r.jsx(r.Fragment,{children:nn(e,t)})}function rn(e,t){const n=new Date(String(e));return Number.isNaN(n.getTime())?String(e):t?n.toLocaleString():n.toLocaleDateString()}function xs({value:e}){if(typeof e=="string"&&e.length>0){const t=e.split("/").filter(Boolean).pop()??e;return r.jsx("a",{href:e,target:"_blank",rel:"noreferrer",className:"text-primary underline underline-offset-4",onClick:n=>n.stopPropagation(),children:t})}return typeof File<"u"&&e instanceof File?r.jsx(r.Fragment,{children:e.name}):r.jsx(ze,{})}function bs({value:e}){let t;try{t=JSON.stringify(e)??String(e)}catch{t=String(e)}const n=t.length>80?`${t.slice(0,80)}…`:t;return r.jsx("code",{className:"rounded bg-muted px-1 py-0.5 text-xs",title:t,children:n})}function ys(e,t,n){if(t==null)return r.jsx(ze,{});switch(e.kind){case"boolean":return r.jsx(hs,{value:t===!0});case"date":return rn(t,!1);case"datetime":return rn(t,!0);case"enum":return typeof t=="string"||typeof t=="number"?Bn(t,e.enumLabels):String(t);case"relation":return r.jsx(ps,{value:t,label:n??De});case"number":case"integer":return r.jsx("span",{className:"tabular-nums",children:typeof t=="number"?t.toLocaleString():String(t)});case"file":return r.jsx(xs,{value:t});case"json":return r.jsx(bs,{value:t});case"array":return Array.isArray(t)?t.map(s=>String(s)).join(", "):String(t);case"text":return r.jsx("span",{className:"block max-w-xs truncate",title:String(t),children:String(t)});default:return String(t)}}function Vn(e){return typeof e=="string"?e:()=>e}function js(e,t,n){const s=t==null?void 0:t.cell;return{id:e.name,accessorFn:i=>Ze(i)[e.name],header:Vn((t==null?void 0:t.header)??e.label),cell:s!==void 0?i=>s(i.row.original):i=>ys(e,i.getValue(),n),enableSorting:(t==null?void 0:t.sortable)??!fs.has(e.kind)}}function vs(e){const t=new Map((e.columns??[]).map(o=>[o.field,o])),n=[],{domain:s,audit:i}=Ft(e.fields);for(const o of[...s,...i]){const a=t.get(o.name);t.delete(o.name),(a==null?void 0:a.hidden)!==!0&&(a===void 0&&(o.writeOnly||ms.has(o.kind)||e.showAuditFields!==!0&&Et(o))||n.push(js(o,a,e.getRowLabel)))}for(const[o,a]of t){if(a.hidden===!0)continue;const u=a.cell;n.push({id:o,accessorFn:l=>Ze(l)[o],header:Vn(a.header??_n(o)),cell:u!==void 0?l=>u(l.row.original):l=>{const c=l.getValue();return c==null?r.jsx(ze,{}):String(c)},enableSorting:a.sortable??!1})}return n}function Pt(e){return[...ue.resource(e),"import","describe"]}function Ot(e,t){return[...ue.resource(e),"import","job",t]}function $e(e,t=""){return`${Je(e)}import/${t}`}const ws=new Set(["previewing","committing"]);function $t(e){return e!==void 0&&ws.has(e.status)}function Un(e,t){const n=e.headers.get("content-disposition")??"",s=/filename="?([^";]+)"?/i.exec(n);return(s==null?void 0:s[1])??t}async function Kn(e,t,n,s="csv"){const i={...Mt(n),format:s};delete i.page,delete i.page_size;const o=await e.requestRaw(`${Je(t)}export/`,{query:i}),a=await o.blob(),u=Un(o,`${t}.${s}`);return Hn(a,u),u}function Hn(e,t){if(typeof document>"u"||typeof URL.createObjectURL!="function")return;const n=URL.createObjectURL(e),s=document.createElement("a");s.href=n,s.download=t,document.body.appendChild(s),s.click(),s.remove(),URL.revokeObjectURL(n)}async function Qn(e,t,n="xlsx"){const s=await e.requestRaw($e(t,"template/"),{query:{format:n}}),i=await s.blob(),o=Un(s,`${t}-template.${n}`);return Hn(i,o),o}function Wn(e,t){const n=de();return W.useQuery({...t,queryKey:Pt(e),queryFn:({signal:s})=>n.request($e(e),{signal:s})})}function qn(e,t,n){const s=de(),i=(n==null?void 0:n.pollMs)??1500;return W.useQuery({queryKey:Ot(e,t??""),enabled:t!==void 0,queryFn:({signal:o})=>s.request($e(e,`${encodeURIComponent(t??"")}/`),{signal:o}),refetchInterval:o=>$t(o.state.data)?i:!1})}function Jn(e){const t=de(),n=W.useQueryClient(),s=u=>(n.setQueryData(Ot(e,u.id),u),u),i=W.useMutation({mutationFn:async({file:u,mapping:l})=>{const c=new FormData;return c.append("file",u),l!==void 0&&c.append("mapping",JSON.stringify(l)),s(await t.request($e(e),{method:"POST",body:c}))}}),o=W.useMutation({mutationFn:async({jobId:u,mapping:l})=>s(await t.request($e(e,`${encodeURIComponent(u)}/preview/`),{method:"POST",body:{mapping:l}})),onSuccess:()=>{n.invalidateQueries({queryKey:Pt(e)})}}),a=W.useMutation({mutationFn:async u=>s(await t.request($e(e,`${encodeURIComponent(u)}/commit/`),{method:"POST",body:{}})),onSuccess:u=>{u.status==="done"&&n.invalidateQueries({queryKey:ue.resource(e)})}});return{upload:i,preview:o,commit:a}}function Ns(e){if(e instanceof Error){const t=e.data;if(typeof t=="object"&&t!==null&&"detail"in t){const n=t.detail;if(typeof n=="string")return n}return e.message}return"The export failed."}function Ss({resource:e,params:t,formats:n}){const s=de(),[i,o]=d.useState(null),[a,u]=d.useState(null),l=c=>{o(c),u(null),Kn(s,e,t,c).catch(m=>u(Ns(m))).finally(()=>o(null))};return r.jsxs("div",{className:"flex items-center gap-2","data-testid":"resource-table-export",children:[n.map(c=>r.jsx(Q,{type:"button",variant:"outline",size:"sm",disabled:i!==null,onClick:()=>l(c),"aria-label":`Export as ${c.toUpperCase()}`,children:i===c?"Exporting…":`Export ${c.toUpperCase()}`},c)),a!==null&&r.jsx("span",{role:"alert",className:"text-sm text-destructive",children:a})]})}function at(e,t,n,s){const i=de();return W.useQuery({...s,queryKey:ue.detail(e,t,n),queryFn:({signal:o})=>i.request(tt(e,t),{query:On(n),signal:o})})}function ks(e,t){const[n,s]=d.useState(e);return d.useEffect(()=>{if(t<=0){s(e);return}const i=setTimeout(()=>s(e),t);return()=>clearTimeout(i)},[e,t]),n}Y("async-select","ResourceSelect");function ft(e){const t=e.id;return typeof t=="string"||typeof t=="number"?t:String(t)}function sn(e,t){return`${e}-option-${t}`}function on(e){return r.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:!1,...e,children:[r.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),r.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function _t(e){var Ae;const{resource:t,value:n,onChange:s,multiple:i=!1,disabled:o=!1,placeholder:a,getOptionLabel:u,filter:l,id:c,className:m,pageSize:h,clearable:b=!0,searchDebounceMs:T=300}=e,R=d.useId(),y=c??R,N=`${y}-listbox`,[f,j]=d.useState(!1),[w,L]=d.useState(""),[$,x]=d.useState(0),[S,F]=d.useState({}),z=d.useRef(null),U=d.useRef(null),E=d.useRef(null),A=ks(w.trim(),T),v=d.useMemo(()=>n==null?[]:Array.isArray(n)?n:[n],[n]),P=d.useMemo(()=>{const g={page:1};return h!==void 0&&(g.pageSize=h),A!==""&&(g.search=A),l!==void 0&&(g.filters=l),g},[h,A,l]),_=Lt(t,P,{enabled:f&&!o}),O=((Ae=_.data)==null?void 0:Ae.results)??[];d.useEffect(()=>{var C;const g=(C=_.data)==null?void 0:C.results;g===void 0||g.length===0||F(V=>{let ee=!1;const Me={...V};for(const ve of g){const Ve=String(ft(ve));Ve in Me||(Me[Ve]=ve,ee=!0)}return ee?Me:V})},[_.data]);const q=v.find(g=>!(String(g)in S)),ie=at(t,q??"",void 0,{enabled:q!==void 0&&!o,retry:!1}),ae=ie.data,Ce=ie.error;d.useEffect(()=>{q!==void 0&&(ae!==void 0?F(g=>({...g,[String(q)]:ae})):Ce!=null&&F(g=>({...g,[String(q)]:{id:q}})))},[q,ae,Ce]);const Ee=d.useCallback(g=>u!==void 0?u(g):De(g),[u]),Re=d.useCallback(g=>{const C=S[String(g)];if(C===void 0)return String(g);const V=u!==void 0?u(C):De(C);return typeof V=="string"?V:typeof V=="number"?String(V):De(C)},[S,u]),xe=d.useCallback(()=>{o||(L(""),x(0),j(!0))},[o]),X=d.useCallback(()=>{j(!1),L("")},[]),je=d.useCallback(g=>v.some(C=>String(C)===String(g)),[v]),me=g=>{const C=ft(g);if(F(V=>String(C)in V?V:{...V,[String(C)]:g}),i){const V=je(C)?v.filter(ee=>String(ee)!==String(C)):[...v,C];s([...V])}else s(C),X()},Ne=()=>{var g;s(null),L(""),(g=E.current)==null||g.focus()},k=!i&&v.length>0?Re(v[0]):"",D=f?w:i?"":k,be=g=>{const C=g.target.value;if(!f){if(o)return;x(0),j(!0),L(k!==""&&C.startsWith(k)?C.slice(k.length):C);return}x(0),L(C)},H=g=>{if(!o)switch(g.key){case"ArrowDown":g.preventDefault(),f?O.length>0&&x(C=>(C+1)%O.length):xe();break;case"ArrowUp":g.preventDefault(),f?O.length>0&&x(C=>(C-1+O.length)%O.length):xe();break;case"Enter":if(f){g.preventDefault();const C=O[$];C!==void 0&&me(C)}break;case"Escape":f&&(g.preventDefault(),g.stopPropagation(),X());break;case"Backspace":i&&w===""&&v.length>0&&s([...v.slice(0,-1)]);break;case"Tab":f&&X();break}},I=g=>{var V,ee;const C=g.relatedTarget;C!==null&&(((V=z.current)==null?void 0:V.contains(C))===!0||((ee=U.current)==null?void 0:ee.contains(C))===!0)||f&&X()},Te=_.isLoading?r.jsx("div",{className:"px-2 py-1.5 text-sm text-muted-foreground",children:"Loading…"}):_.error!=null?r.jsx("div",{role:"alert",className:"px-2 py-1.5 text-sm text-destructive",children:"Failed to load options."}):O.length===0?r.jsx("div",{className:"px-2 py-1.5 text-sm text-muted-foreground",children:"No results"}):O.map((g,C)=>{const V=ft(g),ee=je(V);return r.jsxs("div",{id:sn(N,C),role:"option","aria-selected":ee,"data-highlighted":C===$?"true":void 0,className:"flex cursor-default select-none items-center justify-between gap-2 rounded-sm px-2 py-1.5 text-sm outline-none data-[highlighted=true]:bg-accent data-[highlighted=true]:text-accent-foreground",onMouseDown:Me=>Me.preventDefault(),onMouseMove:()=>x(C),onClick:()=>me(g),children:[r.jsx("span",{className:"truncate",children:Ee(g)}),ee?r.jsx(qe,{className:"h-4 w-4 shrink-0"}):null]},String(V))});return r.jsxs(Ge.Root,{open:f,onOpenChange:g=>{g||X()},modal:!1,children:[r.jsx(Ge.Anchor,{asChild:!0,children:r.jsxs("div",{ref:z,onClick:()=>{var g;o||((g=E.current)==null||g.focus(),f||xe())},className:p("flex min-h-10 w-full flex-wrap items-center gap-1.5 rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2",o&&"cursor-not-allowed opacity-50",m),children:[i?v.map(g=>{const C=Re(g);return r.jsxs("span",{className:"inline-flex items-center gap-1 rounded-sm bg-secondary px-1.5 py-0.5 text-xs text-secondary-foreground",children:[C,o?null:r.jsx("button",{type:"button","aria-label":`Remove ${C}`,className:"rounded-sm opacity-70 hover:opacity-100 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring",onClick:V=>{V.stopPropagation(),s([...v.filter(ee=>String(ee)!==String(g))])},children:r.jsx(on,{className:"h-3 w-3"})})]},String(g))}):null,r.jsx("input",{ref:E,id:y,type:"text",role:"combobox","aria-expanded":f,"aria-controls":N,"aria-autocomplete":"list","aria-activedescendant":f&&O.length>0?sn(N,$):void 0,"aria-label":e["aria-label"],"aria-labelledby":e["aria-labelledby"],autoComplete:"off",disabled:o,placeholder:v.length===0?a:void 0,value:D,onChange:be,onKeyDown:H,onClick:()=>{f||xe()},onBlur:I,className:"min-w-16 flex-1 bg-transparent outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed"}),b&&v.length>0&&!o?r.jsx("button",{type:"button","aria-label":"Clear selection",className:"rounded-sm p-0.5 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring",onMouseDown:g=>g.preventDefault(),onClick:g=>{g.stopPropagation(),Ne()},children:r.jsx(on,{className:"h-4 w-4"})}):null,r.jsx(it,{className:"h-4 w-4 shrink-0 opacity-50"})]})}),r.jsx(Ge.Portal,{children:r.jsx(Ge.Content,{ref:U,side:"bottom",align:"start",sideOffset:4,onOpenAutoFocus:g=>g.preventDefault(),onCloseAutoFocus:g=>g.preventDefault(),onInteractOutside:g=>{const C=g.target;z.current!==null&&C instanceof Node&&z.current.contains(C)&&g.preventDefault()},className:"z-50 max-h-72 w-[var(--radix-popover-trigger-width)] min-w-[12rem] overflow-y-auto rounded-md border border-border bg-popover p-1 text-popover-foreground shadow-md",children:r.jsx("div",{role:"listbox",id:N,"aria-multiselectable":i||void 0,children:Te})})})]})}function Cs(e){return e==null||typeof e=="object"?null:String(e)}function Rs(e){return e==null||typeof e=="boolean"?null:Array.isArray(e)?e.filter(t=>typeof t=="string"||typeof t=="number"):e}function Ts({field:e,value:t,onFilterChange:n}){const s=(e.enumValues??[]).map(i=>({value:String(i),label:Bn(i,e.enumLabels)}));return r.jsx(Be,{"aria-label":e.label,className:"h-9 w-auto min-w-36",value:Cs(t),options:s,placeholder:e.label,clearable:!0,clearLabel:"All",onValueChange:i=>{if(i===null){n(e,null);return}const o=(e.enumValues??[]).find(a=>String(a)===i);n(e,o??i)}})}function As({field:e,value:t,onFilterChange:n}){return r.jsx(Be,{"aria-label":e.label,className:"h-9 w-auto min-w-36",value:typeof t=="boolean"?String(t):null,options:[{value:"true",label:"Yes"},{value:"false",label:"No"}],placeholder:e.label,clearable:!0,clearLabel:"All",onValueChange:s=>n(e,s===null?null:s==="true")})}function Ms(e){const{searchEnabled:t,searchValue:n,onSearchChange:s,searchPlaceholder:i="Search…",filterFields:o,values:a,onFilterChange:u,className:l}=e;return r.jsxs("div",{className:p("flex flex-wrap items-center gap-2",l),children:[t&&r.jsx(ye,{type:"search","aria-label":"Search",placeholder:i,value:n,onChange:c=>s(c.target.value),className:"h-9 w-full max-w-xs"}),o.map(c=>{const m=a[c.name];return c.kind==="enum"?r.jsx(Ts,{field:c,value:m,onFilterChange:u},c.name):c.kind==="boolean"?r.jsx(As,{field:c,value:m,onFilterChange:u},c.name):c.kind==="relation"&&c.relation!==void 0?r.jsx("div",{className:"min-w-36",children:r.jsx(_t,{resource:c.relation.resource,multiple:c.relation.many,value:Rs(m),placeholder:c.label,onChange:h=>u(c,h)})},c.name):null})]})}function Ls(e){const{page:t,pageCount:n,totalCount:s,hasPrevious:i,hasNext:o,onPageChange:a,className:u}=e;return r.jsxs("nav",{"aria-label":"Pagination",className:p("flex flex-wrap items-center justify-between gap-3",u),children:[r.jsxs("p",{className:"text-sm text-muted-foreground",children:["Page ",t," of ",n," · ",s," ",s===1?"item":"items"]}),r.jsxs("div",{className:"flex items-center gap-2",children:[r.jsx(Q,{variant:"outline",size:"sm",disabled:!i,onClick:()=>a(Math.max(1,t-1)),children:"Previous"}),r.jsx(Q,{variant:"outline",size:"sm",disabled:!o,onClick:()=>a(t+1),children:"Next"})]})]})}function Ds(e,t){const[n,s]=d.useState(e);return d.useEffect(()=>{const i=setTimeout(()=>s(e),t);return()=>clearTimeout(i)},[e,t]),n}Y("data-table","ResourceTable");const Es=25,Fs=300,Ps=4;function Os(){return{id:"__select__",enableSorting:!1,header:({table:e})=>r.jsx(et,{"aria-label":"Select all rows",checked:e.getIsAllPageRowsSelected()?!0:e.getIsSomePageRowsSelected()?"indeterminate":!1,onCheckedChange:t=>e.toggleAllPageRowsSelected(t===!0)}),cell:({row:e})=>r.jsx("div",{className:"flex items-center",onClick:t=>t.stopPropagation(),children:r.jsx(et,{"aria-label":"Select row",checked:e.getIsSelected(),onCheckedChange:t=>e.toggleSelected(t===!0)})})}}function $s(e){const t=Dt(e.resource),n=(e.getRowLabel??De)(e.row);return r.jsx(Q,{variant:"ghost",size:"sm",className:"text-destructive hover:text-destructive",disabled:t.remove.isPending,onClick:()=>{const s=e.row.id;if(s==null)return;(typeof window>"u"||typeof window.confirm!="function"||window.confirm(`Delete "${n}"? This cannot be undone.`))&&t.remove.mutate(s)},children:"Delete"})}function _s(e){const{resource:t,rowActions:n,onEdit:s,enableDelete:i,getRowLabel:o}=e;return{id:"__actions__",enableSorting:!1,header:()=>r.jsx("span",{className:"sr-only",children:"Actions"}),cell:({row:a})=>r.jsxs("div",{className:"flex items-center justify-end gap-1",onClick:u=>u.stopPropagation(),children:[s!==void 0&&r.jsx(Q,{variant:"ghost",size:"sm",onClick:()=>s(a.original),children:"Edit"}),n==null?void 0:n(a.original),i===!0&&r.jsx($s,{resource:t,row:Ze(a.original),getRowLabel:o})]})}}function zs({rows:e=8}){return r.jsxs("div",{role:"status","aria-live":"polite",className:"flex w-full flex-col gap-3 rounded-md border border-border p-4",children:[r.jsx("span",{className:"sr-only",children:"Loading…"}),r.jsx(ce,{className:"h-6 w-1/3"}),Array.from({length:e},(t,n)=>r.jsx(ce,{className:"h-8 w-full"},n))]})}function Zn(e){return r.jsxs("div",{role:"alert",className:"flex w-full flex-col items-center gap-3 rounded-md border border-destructive/50 bg-destructive/10 px-6 py-8 text-center",children:[r.jsx("p",{className:"text-sm font-medium text-destructive",children:ds(e.error)}),e.onRetry!==void 0&&r.jsx(Q,{variant:"outline",size:"sm",onClick:e.onRetry,children:"Retry"})]})}function Bs(e){const t=W.useQueryClient();return r.jsx(Zn,{error:e.error,onRetry:()=>{t.invalidateQueries({queryKey:ue.schema()})}})}function Vs(e){var Vt,Ut,Kt,Ht,Qt,Wt;const{resource:t,columns:n,showAuditFields:s,extraColumns:i,columnsOverride:o,rowActions:a,onEdit:u,enableDelete:l,bulkActions:c,onRowClick:m,expand:h,initialSorting:b,pageSize:T,filters:R,params:y,exportFormats:N,toolbar:f,empty:j,footer:w,getRowLabel:L,className:$}=e,x=ot(t),S=x.data,[F,z]=d.useState(b??[]),[U,E]=d.useState({}),[A,v]=d.useState(1),[P,_]=d.useState(""),[O,q]=d.useState({}),ie=T??Es,ae=Ds(P,Fs),Ce=d.useRef(ae);d.useEffect(()=>{Ce.current!==ae&&(Ce.current=ae,v(1))},[ae]);const Ee=d.useCallback(M=>{z(K=>typeof M=="function"?M(K):M),v(1)},[]),Re=d.useCallback((M,K)=>{q(J=>K==null||K===""||Array.isArray(K)&&K.length===0?Object.fromEntries(Object.entries(J).filter(([te])=>te!==M.name)):{...J,[M.name]:K}),v(1)},[]),xe=d.useMemo(()=>{var K;if(h!==void 0)return h;const M=(K=S==null?void 0:S.operations.list)==null?void 0:K.expandEnum;return S===void 0||M===void 0?[]:S.fields.filter(J=>J.kind==="relation"&&J.relation!==void 0&&!J.relation.many&&M.includes(J.name)).map(J=>J.name)},[h,S]),X=d.useMemo(()=>new Set(Object.keys(y??{})),[y]),je=d.useMemo(()=>{var Ue;if(R===!1||S===void 0)return[];if(R!==void 0){const te=new Map(S.fields.map(Se=>[Se.name,Se]));return R.filter(Se=>!X.has(Se)).map(Se=>te.get(Se)).filter(Se=>Se!==void 0)}const M=new Set(((Ue=S.operations.list)==null?void 0:Ue.queryParams)??[]),{domain:K,audit:J}=Ft(S.fields);return[...K,...J].filter(te=>!te.writeOnly&&!X.has(te.name)&&(s===!0||!Et(te))&&M.has(te.name)&&(te.kind==="enum"||te.kind==="boolean"||te.kind==="relation"&&te.relation!==void 0)).slice(0,Ps)},[R,X,S,s]),me=((Vt=S==null?void 0:S.operations.list)==null?void 0:Vt.hasSearch)===!0,Ne=ae.trim(),k=d.useMemo(()=>({page:A,pageSize:ie,ordering:cs(F),search:me&&Ne.length>0?Ne:void 0,filters:Object.keys(O).length>0||y!==void 0?{...O,...y}:void 0,expand:xe.length>0?xe:void 0}),[A,ie,F,me,Ne,O,y,xe]),D=Lt(t,k,{enabled:S!==void 0,placeholderData:W.keepPreviousData,retry:(M,K)=>!tn(K)&&M<3}),be=tn(D.error)&&A>1;d.useEffect(()=>{be&&v(M=>Math.max(1,M-1))},[be,A]);const H=c!==void 0&&c.length>0,I=a!==void 0||u!==void 0||l===!0,Te=d.useMemo(()=>{if(S===void 0)return[];let M=vs({fields:S.fields,columns:n,getRowLabel:L,showAuditFields:s});i!==void 0&&(M=[...M,...i]),o!==void 0&&(M=o(M));const K=H?[Os()]:[],J=I?[_s({resource:t,rowActions:a,onEdit:u,enableDelete:l,getRowLabel:L})]:[];return[...K,...M,...J]},[S,n,L,s,i,o,H,I,t,a,u,l]),Ae=d.useMemo(()=>{var M;return((M=D.data)==null?void 0:M.results)??[]},[D.data]),g=(Ut=D.data)==null?void 0:Ut.count,C=us(g,ie),V=Ke.useReactTable({data:Ae,columns:Te,state:{sorting:F,rowSelection:U},manualSorting:!0,manualPagination:!0,manualFiltering:!0,pageCount:C,enableRowSelection:H,onSortingChange:Ee,onRowSelectionChange:E,getRowId:M=>String(Ze(M).id),getCoreRowModel:Ke.getCoreRowModel()}),ee=d.useMemo(()=>Object.keys(U).filter(M=>U[M]),[U]),Me=Ne.length>0||Object.keys(O).length>0;let ve;x.error!==null&&x.error!==void 0?ve=r.jsx(Bs,{error:x.error}):x.isLoading||S===void 0||D.isPending||be?ve=r.jsx(zs,{}):D.error!==null&&D.error!==void 0?ve=r.jsx(Zn,{error:D.error,onRetry:()=>{D.refetch()}}):Ae.length===0?ve=j??(Me?r.jsx(nt,{title:"No results",description:"Try adjusting your search or filters."}):r.jsx(nt,{title:"Nothing here yet",description:"Records will appear here once created."})):ve=r.jsxs(r.Fragment,{children:[r.jsx("div",{className:p("w-full overflow-x-auto rounded-md border border-border",D.isFetching&&"opacity-60"),children:r.jsxs("table",{className:"w-full caption-bottom text-sm","aria-busy":D.isFetching,children:[r.jsx("thead",{className:"border-b border-border bg-muted",children:r.jsx("tr",{children:V.getFlatHeaders().map(M=>{const K=M.column.getCanSort(),J=M.column.getIsSorted();return r.jsx("th",{scope:"col","aria-sort":J==="asc"?"ascending":J==="desc"?"descending":void 0,className:"h-10 px-3 text-left align-middle text-xs font-medium text-muted-foreground",children:M.isPlaceholder?null:K?r.jsxs("button",{type:"button",className:"inline-flex items-center gap-1 rounded-sm hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",onClick:Ue=>{var te;return(te=M.column.getToggleSortingHandler())==null?void 0:te(Ue)},children:[Ke.flexRender(M.column.columnDef.header,M.getContext()),J==="asc"?r.jsx(vn,{className:"h-3.5 w-3.5"}):J==="desc"?r.jsx(it,{className:"h-3.5 w-3.5"}):null]}):Ke.flexRender(M.column.columnDef.header,M.getContext())},M.id)})})}),r.jsx("tbody",{children:V.getRowModel().rows.map(M=>r.jsx("tr",{"data-state":M.getIsSelected()?"selected":void 0,onClick:m!==void 0?()=>m(M.original):void 0,className:p("border-b border-border transition-colors last:border-0 hover:bg-muted data-[state=selected]:bg-muted",m!==void 0&&"cursor-pointer"),children:M.getVisibleCells().map(K=>r.jsx("td",{className:"px-3 py-2 align-middle",children:Ke.flexRender(K.column.columnDef.cell,K.getContext())},K.id))},M.id))})]})}),g!==void 0&&g>0&&r.jsx(Ls,{page:A,pageCount:C,totalCount:g,hasPrevious:((Kt=D.data)==null?void 0:Kt.previous)!==null&&((Ht=D.data)==null?void 0:Ht.previous)!==void 0,hasNext:((Qt=D.data)==null?void 0:Qt.next)!==null&&((Wt=D.data)==null?void 0:Wt.next)!==void 0,onPageChange:v})]});const Ve=N===void 0?["csv","xlsx"]:N===!1?[]:N,ct=Ve.length>0&&(S==null?void 0:S.operations.export)!==void 0,fr=S!==void 0&&(me||je.length>0||f!==void 0||ct);return r.jsxs("div",{className:p("flex w-full flex-col gap-3",$),children:[fr&&r.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[r.jsx(Ms,{searchEnabled:me,searchValue:P,onSearchChange:_,filterFields:je,values:O,onFilterChange:Re,className:"min-w-0 flex-1"}),(f!==void 0||ct)&&r.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[ct&&r.jsx(Ss,{resource:t,params:k,formats:Ve}),f]})]}),H&&ee.length>0&&r.jsx(ls,{selectedIds:ee,bulkActions:c,onClear:()=>E({})}),ve,w]})}const Le="This field is required.",Us=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d{1,6})?)?$/;function Ks(e){if(!Us.test(e))return e;const t=new Date(e);return Number.isNaN(t.getTime())?e:t.toISOString()}function Hs(e){if(e.length===0)return B.z.never();if(e.every(n=>typeof n=="string"))return B.z.enum(e);const t=e.map(n=>B.z.literal(n));return t.length===1?t[0]:B.z.union(t)}function Qs(e,t){let n=B.z.string();return e.format==="email"?n=n.email():e.format==="uri"||e.format==="url"?n=n.url():e.format==="uuid"&&(n=n.uuid()),e.maxLength!==void 0&&(n=n.max(e.maxLength)),t&&(n=n.min(1,Le)),n}function an(e,t){let n=B.z.coerce.number();return t&&(n=n.int()),e.min!==void 0&&(n=n.min(e.min)),e.max!==void 0&&(n=n.max(e.max)),n}function Gn(e,t){switch(e.relationValueType){case"uuid":return B.z.string({required_error:Le}).uuid();case"integer":return t?B.z.coerce.number().int():B.z.number({required_error:Le}).int();default:return B.z.string({required_error:Le}).min(1,Le)}}function Ws(e,t){const n=Gn(e,!1);let s=e.nullable?n.nullable():n;return t||(s=s.optional()),B.z.preprocess(i=>{if(i===""||i===null||i===void 0)return e.nullable?null:void 0;if(e.relationValueType==="integer"&&typeof i=="string"&&i.trim()!==""){const o=Number(i);return Number.isNaN(o)?i:o}return i},s)}function qs(){return typeof File>"u"?B.z.string():B.z.union([B.z.instanceof(File),B.z.string()])}function Js(e,t){var n;switch(e.kind){case"string":case"text":return Qs(e,t);case"integer":return an(e,!0);case"number":return an(e,!1);case"boolean":return B.z.boolean();case"date":{const s=B.z.string();return t?s.min(1,Le):s}case"datetime":return(t?B.z.string().min(1,Le):B.z.string()).transform(Ks);case"enum":return Hs(e.enumValues??[]);case"relation":return((n=e.relation)==null?void 0:n.many)===!0?B.z.array(Gn(e,!0)):Ws(e,t);case"file":return qs();case"json":return B.z.unknown();case"array":return B.z.array(B.z.unknown());case"unknown":return B.z.unknown()}}function Yn(e,t){const n={};for(const s of e.fields){if(s.readOnly)continue;const i=s.required;let o=Js(s,i);s.nullable&&(o=o.nullable()),(t==="update"||!s.required)&&(o=o.optional()),n[s.name]=o}return B.z.object(n)}Y("file-upload","FileUpload");function Zs(e,t){if(t===void 0||t.trim()==="")return!0;const n=t.split(",").map(o=>o.trim().toLowerCase()).filter(o=>o!=="");if(n.length===0)return!0;const s=e.name.toLowerCase(),i=e.type.toLowerCase();return n.some(o=>o.startsWith(".")?s.endsWith(o):o.endsWith("/*")?i.startsWith(o.slice(0,-1)):i===o)}function Gs(e){return e<1024?`${e} B`:e<1024*1024?`${Math.round(e/1024)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function Ys(e){const n=(e.split(/[?#]/,1)[0]??e).split("/").filter(s=>s!=="");return n[n.length-1]??e}function Xs(e){return r.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:!1,...e,children:[r.jsx("path",{d:"M21 15v3a3 3 0 0 1-3 3H6a3 3 0 0 1-3-3v-3"}),r.jsx("polyline",{points:"7 8 12 3 17 8"}),r.jsx("line",{x1:"12",y1:"3",x2:"12",y2:"15"})]})}function Is(e){return r.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:!1,...e,children:[r.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),r.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function Xn(e){const{value:t=null,onChange:n,accept:s,multiple:i=!1,disabled:o=!1,maxSize:a,onReject:u,id:l,name:c,className:m,children:h,clearable:b=!0}=e,T=d.useRef(null),[R,y]=d.useState(!1),N=t==null?[]:Array.isArray(t)?t:[t],f=x=>{if(o)return;const S=[];for(const F of Array.from(x)){if(!Zs(F,s)){u==null||u(F,"accept");continue}if(a!==void 0&&F.size>a){u==null||u(F,"size");continue}S.push(F)}S.length!==0&&(n==null||n(i?S:S[0]))},j=x=>{x.target.files!==null&&f(x.target.files),x.target.value=""},w=x=>{x.preventDefault(),y(!1),!o&&f(x.dataTransfer.files)},L=x=>{x.preventDefault(),o||y(!0)},$=x=>{if(n===void 0)return;const S=N.filter((z,U)=>U!==x);if(S.length===0){n(null);return}const F=S.filter(z=>typeof z!="string");n(i?F:F[0]??null)};return r.jsxs("div",{className:p("space-y-2",m),children:[r.jsx("button",{type:"button",id:l,disabled:o,"aria-label":e["aria-label"],onClick:()=>{var x;return(x=T.current)==null?void 0:x.click()},onDragOver:L,onDragEnter:L,onDragLeave:()=>y(!1),onDrop:w,"data-dragging":R?"true":void 0,className:"flex w-full flex-col items-center justify-center gap-1 rounded-md border border-dashed border-input bg-background px-4 py-6 text-sm text-muted-foreground transition-colors hover:border-ring hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[dragging=true]:border-ring data-[dragging=true]:bg-accent data-[dragging=true]:text-accent-foreground",children:h??r.jsxs(r.Fragment,{children:[r.jsx(Xs,{className:"h-5 w-5"}),r.jsx("span",{children:i?"Drag and drop files here, or click to browse":"Drag and drop a file here, or click to browse"})]})}),r.jsx("input",{ref:T,type:"file",name:c,accept:s,multiple:i,disabled:o,onChange:j,tabIndex:-1,"aria-hidden":"true",className:"sr-only"}),N.length>0?r.jsx("ul",{className:"space-y-1",children:N.map((x,S)=>{const F=typeof x=="string"?Ys(x):x.name;return r.jsxs("li",{className:"flex items-center justify-between gap-2 rounded-md border border-border bg-muted/50 px-3 py-1.5 text-sm",children:[typeof x=="string"?r.jsx("a",{href:x,target:"_blank",rel:"noreferrer",className:"truncate font-medium text-primary underline underline-offset-4",children:F}):r.jsxs("span",{className:"truncate",children:[x.name,r.jsx("span",{className:"ml-2 text-xs text-muted-foreground",children:Gs(x.size)})]}),b&&!o?r.jsx("button",{type:"button","aria-label":`Remove ${F}`,onClick:()=>$(S),className:"rounded-sm p-1 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:r.jsx(Is,{className:"h-4 w-4"})}):null]},typeof x=="string"?`url-${x}`:`file-${x.name}-${S}`)})}):null]})}function In(e){const t=e.replace(/[_-]+/g," ").trim();return t===""?e:t.charAt(0).toUpperCase()+t.slice(1)}function he(e){return String(e).padStart(2,"0")}function ei(e){const t=new Date(e);return Number.isNaN(t.getTime())?e:`${t.getFullYear()}-${he(t.getMonth()+1)}-${he(t.getDate())}T${he(t.getHours())}:${he(t.getMinutes())}`}const ti=/(?:Z|[+-]\d{2}:?\d{2})$/i;function ni(e){if(ti.test(e))return e;const t=new Date(e);if(Number.isNaN(t.getTime()))return e;const n=-t.getTimezoneOffset(),s=n>=0?"+":"-",i=Math.abs(n),o=`${s}${he(Math.floor(i/60))}:${he(i%60)}`;return`${t.getFullYear()}-${he(t.getMonth()+1)}-${he(t.getDate())}T${he(t.getHours())}:${he(t.getMinutes())}:${he(t.getSeconds())}${o}`}function wt(e){return e===!0?!0:Array.isArray(e)?e.some(wt):e!==null&&typeof e=="object"?Object.values(e).some(wt):!1}function Qe(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)&&"id"in e?e.id:e}function ri(e,t){var n;switch(e.kind){case"string":case"text":return t==null?"":String(t);case"number":case"integer":return t??"";case"boolean":return!!t;case"date":return t==null||t===""?"":String(t).slice(0,10);case"datetime":return t==null||t===""?"":ei(String(t));case"enum":return t??null;case"relation":return((n=e.relation)==null?void 0:n.many)===!0?Array.isArray(t)?t.map(Qe):[]:t==null?null:Qe(t);case"file":return t??null;case"json":return t==null?"":JSON.stringify(t,null,2);default:return t}}function si({fields:e,item:t,defaultValues:n}){const s={};for(const i of e){let o=n==null?void 0:n[i.name];o===void 0&&(o=i.default),t!==void 0&&i.name in t&&(o=t[i.name]),s[i.name]=ri(i,o)}if(n!==void 0)for(const[i,o]of Object.entries(n))i in s||(s[i]=o);return s}function ne(e){return{kind:"value",value:e}}const er={kind:"omit"};function fe(e){return e.nullable?ne(null):er}function ii(e,t){var n;switch(e.kind){case"string":case"text":{if(t==null)return fe(e);const s=String(t);return s===""&&e.nullable?ne(null):ne(s)}case"number":case"integer":{if(t==null||t==="")return fe(e);const s=typeof t=="number"?t:Number(t);return Number.isFinite(s)?ne(s):fe(e)}case"boolean":return t==null?fe(e):ne(!!t);case"date":return t==null||t===""?fe(e):ne(String(t).slice(0,10));case"datetime":return t==null||t===""?fe(e):ne(ni(String(t)));case"enum":{if(t==null||t==="")return fe(e);const s=(e.enumValues??[]).find(i=>String(i)===String(t));return ne(s??t)}case"relation":return((n=e.relation)==null?void 0:n.many)===!0?t==null?ne([]):ne(Array.isArray(t)?t.map(Qe):[Qe(t)]):t==null||t===""?fe(e):ne(Qe(t));case"file":return t==null?fe(e):typeof t=="string"?er:ne(t);case"json":{if(typeof t!="string")return t==null?fe(e):ne(t);if(t.trim()==="")return fe(e);try{return ne(JSON.parse(t))}catch{return{kind:"error",message:"Enter valid JSON."}}}default:return ne(t)}}function oi({fields:e,raw:t,mode:n,dirtyFields:s}){const i=new Map(e.map(u=>[u.name,u])),o={},a=[];for(const[u,l]of Object.entries(t)){if(n==="update"&&!wt(s==null?void 0:s[u]))continue;const c=i.get(u);if(c===void 0){l!==void 0&&(o[u]=l);continue}const m=ii(c,l);m.kind==="error"?a.push({name:u,message:m.message}):m.kind==="value"&&m.value!==void 0&&(o[u]=m.value)}return{values:o,jsonErrors:a}}function ai(e){switch(e.format){case"email":return"email";case"uri":case"url":return"url";case"password":return"password";default:return"text"}}function li({field:e,control:t,inputId:n,describedBy:s,invalid:i,disabled:o,inputProps:a}){const u={"aria-invalid":i||void 0,"aria-describedby":s};return r.jsx(yt.Controller,{control:t,name:e.name,render:({field:l})=>{switch(e.kind){case"text":return r.jsx(Xe,{id:n,rows:4,maxLength:e.maxLength,disabled:o,value:l.value==null?"":String(l.value),onChange:c=>l.onChange(c.target.value),onBlur:l.onBlur,...u,...a});case"number":case"integer":return r.jsx(ye,{id:n,type:"number",inputMode:e.kind==="integer"?"numeric":"decimal",step:e.kind==="integer"?1:"any",min:e.min,max:e.max,disabled:o,value:l.value==null?"":l.value,onChange:c=>l.onChange(c.target.value),onBlur:l.onBlur,...u,...a});case"boolean":return r.jsx(At,{id:n,disabled:o,checked:!!l.value,onCheckedChange:c=>l.onChange(c),onBlur:l.onBlur,...u,...a});case"date":return r.jsx(ye,{id:n,type:"date",disabled:o,value:l.value==null?"":String(l.value),onChange:c=>l.onChange(c.target.value),onBlur:l.onBlur,...u,...a});case"datetime":return r.jsx(ye,{id:n,type:"datetime-local",disabled:o,value:l.value==null?"":String(l.value),onChange:c=>l.onChange(c.target.value),onBlur:l.onBlur,...u,...a});case"enum":{const c=e.enumValues??[],m=c.map(h=>{var b;return{value:String(h),label:((b=e.enumLabels)==null?void 0:b[String(h)])??In(String(h))}});return r.jsx(Be,{id:n,disabled:o,value:l.value==null?null:String(l.value),options:m,clearable:e.nullable,placeholder:"Select…",onValueChange:h=>{if(h===null){l.onChange(null);return}const b=c.find(T=>String(T)===h);l.onChange(b??h)},...a})}case"relation":{const c=e.relation;return c===void 0?r.jsx(ye,{id:n,type:"text",disabled:o,value:l.value==null?"":String(l.value),onChange:m=>l.onChange(m.target.value),onBlur:l.onBlur,...u,...a}):r.jsx(_t,{id:n,resource:c.resource,multiple:c.many,disabled:o,value:l.value??null,onChange:m=>l.onChange(m),...a})}case"file":return r.jsx(Xn,{id:n,disabled:o,value:l.value??null,onChange:c=>l.onChange(c),...a});case"json":return r.jsx(Xe,{id:n,rows:5,disabled:o,className:"font-mono",value:typeof l.value=="string"?l.value:l.value==null?"":JSON.stringify(l.value,null,2),onChange:c=>l.onChange(c.target.value),onBlur:l.onBlur,...u,...a});default:return r.jsx(ye,{id:n,type:ai(e),maxLength:e.maxLength,disabled:o,value:l.value==null?"":String(l.value),onChange:c=>l.onChange(c.target.value),onBlur:l.onBlur,...u,...a})}}})}Y("resource-form","ResourceForm");const ci=new Set(["string","text","number","integer","boolean","date","datetime","enum","relation","file","json"]);function ui(e){return e instanceof Error?e.message:String(e)}function di({className:e}){return r.jsxs("div",{role:"status","aria-label":"Loading form",className:p("space-y-5",e),children:[[0,1,2].map(t=>r.jsxs("div",{className:"space-y-2",children:[r.jsx(ce,{className:"h-4 w-24"}),r.jsx(ce,{className:"h-10 w-full"})]},t)),r.jsx(ce,{className:"h-10 w-28"})]})}function ln({error:e,className:t}){return r.jsx("div",{role:"alert",className:p("rounded-md border border-destructive/50 bg-destructive/10 p-4 text-sm text-destructive",t),children:ui(e)})}function mi(e,t,n){if(typeof e!="object"||e===null)return;const s=e;if(s.status!==400)return;const i=s.data;if(Array.isArray(i)){n.setError("root.server",{type:"server",message:i.map(String).join(" ")});return}if(typeof i!="object"||i===null)return;const o=[];for(const[a,u]of Object.entries(i)){const l=Array.isArray(u)?u.map(String).join(" "):String(u);a==="non_field_errors"||a==="detail"?o.push(l):t.has(a)?n.setError(a,{type:"server",message:l}):o.push(`${a}: ${l}`)}o.length>0&&n.setError("root.server",{type:"server",message:o.join(" ")})}function fi({field:e,override:t,control:n,error:s,disabled:i}){const o=d.useId(),a=(t==null?void 0:t.label)??e.label;if((t==null?void 0:t.component)!==void 0){const m=t.component;return r.jsx(m,{field:e,name:e.name,label:a,required:e.required,control:n,error:s,disabled:i,props:t.props})}const u=`${o}-error`,l=`${o}-description`,c=[e.description!==void 0?l:null,s!==void 0?u:null].filter(m=>m!==null).join(" ")||void 0;return r.jsxs("div",{className:"space-y-2",children:[r.jsxs(We,{htmlFor:o,children:[a,e.required?r.jsx("span",{"aria-hidden":"true",className:"text-destructive",children:" *"}):null]}),r.jsx(li,{field:e,control:n,inputId:o,describedBy:c,invalid:s!==void 0,disabled:i,inputProps:t==null?void 0:t.props}),e.description!==void 0?r.jsx("p",{id:l,className:"text-sm text-muted-foreground",children:e.description}):null,s!==void 0?r.jsx("p",{id:u,className:"text-sm font-medium text-destructive",children:s}):null]})}function hi(e){var F,z,U;const{resource:t,id:n,defaultValues:s,onSuccess:i,onError:o,fields:a,extraFields:u,transformSubmit:l,actions:c,className:m,schema:h,item:b}=e,T=n===void 0?"create":"update",R=Dt(t),y=d.useMemo(()=>h.fields.filter(E=>{var A;return!E.readOnly&&(ci.has(E.kind)||((A=a==null?void 0:a[E.name])==null?void 0:A.component)!==void 0)}),[h,a]),N=d.useMemo(()=>si({fields:y,item:b,defaultValues:s}),[y,b,s]),f=d.useMemo(()=>{const E=Rr.zodResolver(Yn(h,T)),A=new Set(h.fields.filter(v=>{var P;return!v.required&&!v.nullable&&!(v.kind==="relation"&&((P=v.relation)==null?void 0:P.many)===!0)}).map(v=>v.name));return(v,P,_)=>{const O=Object.fromEntries(Object.entries(v).filter(([q,ie])=>!(ie===null&&A.has(q))));return E(O,P,_)}},[h,T]),j=yt.useForm({resolver:f,values:N,resetOptions:{keepDirtyValues:!0}}),{formState:w}=j,L=w.isSubmitting||R.create.isPending||R.update.isPending,$=j.handleSubmit(async E=>{j.clearErrors("root.server");const{values:A,jsonErrors:v}=oi({fields:y,raw:E,mode:T,dirtyFields:j.formState.dirtyFields});if(v.length>0){for(const _ of v)j.setError(_.name,{type:"validate",message:_.message});return}const P=l!==void 0?l(A):A;try{const _=n===void 0?await R.create.mutateAsync(P):await R.update.mutateAsync({id:n,values:P});n===void 0?j.reset():j.reset(void 0,{keepValues:!0}),i==null||i(_)}catch(_){const O=new Set([...y.map(q=>q.name),...Object.keys(E)]);mi(_,O,j),o==null||o(_)}}),x=((z=(F=w.errors.root)==null?void 0:F.server)==null?void 0:z.message)??((U=w.errors.root)==null?void 0:U.message),S=E=>{const A=w.errors[E];return typeof(A==null?void 0:A.message)=="string"?A.message:void 0};return r.jsx(yt.FormProvider,{...j,children:r.jsxs("form",{onSubmit:E=>{$(E)},noValidate:!0,"aria-busy":L||void 0,className:p("space-y-5",m),children:[typeof x=="string"?r.jsx("div",{role:"alert",className:"rounded-md border border-destructive/50 bg-destructive/10 px-3 py-2 text-sm text-destructive",children:x}):null,y.map(E=>{const A=a==null?void 0:a[E.name];return(A==null?void 0:A.hidden)===!0?null:r.jsx(fi,{field:E,override:A,control:j.control,error:S(E.name),disabled:L},E.name)}),u,c!==void 0?c:r.jsx("div",{className:"flex items-center justify-end gap-3 pt-2",children:r.jsx(Q,{type:"submit",disabled:L,children:n===void 0?"Create":"Save changes"})})]})})}function gi(e){const{resource:t,id:n}=e,s=ot(t),i=n!==void 0,o=at(t,n??"",void 0,{enabled:i});return s.error!=null?r.jsx(ln,{error:s.error,className:e.className}):i&&o.error!=null?r.jsx(ln,{error:o.error,className:e.className}):s.data===void 0||i&&o.data===void 0?r.jsx(di,{className:e.className}):r.jsx(hi,{...e,schema:s.data,item:i?o.data:void 0})}Y("detail-view","ResourceDetail");function pi(e){const n=(e.split(/[?#]/,1)[0]??e).split("/").filter(s=>s!=="");return n[n.length-1]??e}function xi(e){const t=/^(\d{4})-(\d{2})-(\d{2})/.exec(e);if(t!==null)return new Date(Number(t[1]),Number(t[2])-1,Number(t[3])).toLocaleDateString();const n=new Date(e);return Number.isNaN(n.getTime())?e:n.toLocaleDateString()}function bi(e){const t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()}function cn({value:e}){return e!==null&&typeof e=="object"?r.jsx(r.Fragment,{children:De(e)}):r.jsx("code",{className:"rounded bg-muted px-1 py-0.5 font-mono text-xs",children:String(e)})}function yi({value:e}){return Array.isArray(e)?e.length===0?r.jsx(tr,{}):r.jsx("span",{className:"flex flex-wrap gap-1.5",children:e.map((t,n)=>r.jsx("span",{className:"inline-flex items-center rounded-sm bg-secondary px-1.5 py-0.5 text-xs text-secondary-foreground",children:r.jsx(cn,{value:t})},n))}):r.jsx(cn,{value:e})}function tr(){return r.jsx("span",{className:"text-muted-foreground",children:"—"})}function ji({field:e,value:t}){var n;if(t==null||t==="")return r.jsx(tr,{});switch(e.kind){case"boolean":return r.jsx(r.Fragment,{children:t?"Yes":"No"});case"date":return r.jsx(r.Fragment,{children:xi(String(t))});case"datetime":return r.jsx(r.Fragment,{children:bi(String(t))});case"enum":return r.jsx(r.Fragment,{children:((n=e.enumLabels)==null?void 0:n[String(t)])??In(String(t))});case"relation":return r.jsx(yi,{value:t});case"file":return r.jsx("a",{href:String(t),target:"_blank",rel:"noreferrer",className:"font-medium text-primary underline underline-offset-4",children:pi(String(t))});case"json":return r.jsx("pre",{className:"overflow-x-auto rounded-md bg-muted p-3 text-xs",children:JSON.stringify(t,null,2)});case"number":case"integer":return r.jsx(r.Fragment,{children:typeof t=="number"?t.toLocaleString():String(t)});case"array":return r.jsx(r.Fragment,{children:Array.isArray(t)?t.map(String).join(", "):String(t)});default:return r.jsx(r.Fragment,{children:String(t)})}}function vi({className:e}){return r.jsx("div",{role:"status","aria-label":"Loading details",className:p("space-y-4",e),children:[0,1,2,3].map(t=>r.jsxs("div",{className:"grid grid-cols-1 gap-2 sm:grid-cols-3 sm:gap-4",children:[r.jsx(ce,{className:"h-4 w-24"}),r.jsx(ce,{className:"h-4 w-48 sm:col-span-2"})]},t))})}function wi({error:e,onRetry:t,className:n}){return r.jsxs("div",{role:"alert",className:p("space-y-3 rounded-md border border-destructive/50 bg-destructive/10 p-4 text-sm text-destructive",n),children:[r.jsx("p",{children:e instanceof Error?e.message:String(e)}),r.jsx(Q,{variant:"outline",size:"sm",onClick:t,children:"Retry"})]})}function un(e){const{field:t,item:n,override:s,muted:i}=e,o=n[t.name];return r.jsxs("div",{className:p("grid grid-cols-1 gap-1 sm:grid-cols-3 sm:gap-4",i?"py-2 text-xs":"py-3 text-sm"),children:[r.jsx("dt",{className:"font-medium text-muted-foreground",children:(s==null?void 0:s.label)??t.label}),r.jsx("dd",{className:p("sm:col-span-2",i?"text-muted-foreground":"text-foreground"),children:(s==null?void 0:s.render)!==void 0?s.render(o,n):r.jsx(ji,{field:t,value:o})})]})}function Ni(e){const{resource:t,id:n,fields:s,sections:i,expand:o,title:a,actions:u,className:l}=e,c=d.useId(),m=ot(t),h=d.useMemo(()=>o!==void 0&&o.length>0?{expand:o}:void 0,[o]),b=at(t,n,h),T=m.error??b.error;if(T!=null)return r.jsx(wi,{error:T,onRetry:()=>{b.refetch()},className:l});if(m.data===void 0||b.data===void 0)return r.jsx(vi,{className:l});const R=b.data,y=m.data.fields.filter(j=>{var w;return!j.writeOnly&&j.kind!=="unknown"&&((w=s==null?void 0:s[j.name])==null?void 0:w.hidden)!==!0}),{domain:N,audit:f}=Ft(y);return r.jsxs("div",{className:p("space-y-6",l),children:[a!==void 0||u!==void 0?r.jsxs("div",{className:"flex flex-wrap items-center justify-between gap-3",children:[a!==void 0?r.jsx("h2",{className:"text-lg font-semibold tracking-tight",children:a}):r.jsx("div",{}),u!==void 0?r.jsx("div",{className:"flex items-center gap-2",children:u}):null]}):null,r.jsx("dl",{className:"divide-y divide-border",children:N.map(j=>r.jsx(un,{field:j,item:R,override:s==null?void 0:s[j.name],muted:!1},j.name))}),f.length>0?r.jsxs("section",{"aria-labelledby":c,className:"rounded-md border border-border bg-muted/40 px-4 py-2",children:[r.jsx("h3",{id:c,className:"py-1 text-xs font-medium uppercase tracking-wide text-muted-foreground",children:"Record"}),r.jsx("dl",{className:"divide-y divide-border",children:f.map(j=>r.jsx(un,{field:j,item:R,override:s==null?void 0:s[j.name],muted:!0},j.name))})]}):null,i!==void 0&&i.length>0?r.jsx("div",{className:"space-y-6",children:i.map((j,w)=>r.jsx("div",{children:j},w))}):null]})}function nr(e,t,n){return[...ue.resource(e),"history",String(t),n??{}]}function rr(e,t,n,s){const i=de();return W.useQuery({...s,queryKey:nr(e,t,n),queryFn:({signal:o})=>i.request(`${tt(e,t)}history/`,{query:{page_size:n==null?void 0:n.pageSize,page:n==null?void 0:n.page},signal:o})})}Y("change-history","ChangeHistory");const Si={create:"Created",update:"Updated",delete:"Deleted",restore:"Restored"};function ki(e){const t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()}function dn({value:e}){if(e==null||e==="")return r.jsx("span",{className:"text-muted-foreground",children:"—"});if(e==="[redacted]")return r.jsx("span",{className:"italic text-muted-foreground",children:"redacted"});const t=typeof e=="object"?JSON.stringify(e):String(e);return r.jsx("span",{className:"break-words",children:t})}function Ci({entry:e}){var n;const t=Object.entries(e.diff);return r.jsxs("li",{className:"rounded-md border bg-card p-3 text-sm","data-action":e.action,children:[r.jsxs("div",{className:"flex flex-wrap items-baseline gap-x-3 gap-y-1",children:[r.jsx("span",{className:"font-medium",children:Si[e.action]??e.action}),r.jsx("time",{dateTime:e.timestamp,className:"text-muted-foreground",children:ki(e.timestamp)}),r.jsx("span",{className:"text-muted-foreground",children:((n=e.actor)==null?void 0:n.email)??"—"})]}),t.length>0?r.jsx("dl",{className:"mt-2 grid grid-cols-[max-content_1fr] gap-x-3 gap-y-1",children:t.map(([s,[i,o]])=>r.jsxs(d.Fragment,{children:[r.jsx("dt",{className:"font-mono text-xs text-muted-foreground",children:s}),r.jsxs("dd",{className:"flex flex-wrap items-center gap-2",children:[r.jsx(dn,{value:i}),r.jsx("span",{"aria-hidden":"true",className:"text-muted-foreground",children:"→"}),r.jsx(dn,{value:o})]})]},s))}):r.jsx("p",{className:"mt-2 text-muted-foreground",children:"No visible field changed."})]})}function Ri({resource:e,id:t,pageSize:n,title:s="History",empty:i="No changes recorded.",className:o}){const a=rr(e,t,n!==void 0?{pageSize:n}:void 0);return r.jsxs("section",{className:p("space-y-3",o),"aria-label":"Change history",children:[s!==null?r.jsx("h3",{className:"text-base font-semibold",children:s}):null,a.isPending?r.jsxs("div",{className:"space-y-2","data-testid":"change-history-loading",children:[r.jsx(ce,{className:"h-16 w-full"}),r.jsx(ce,{className:"h-16 w-full"})]}):a.error?r.jsx("p",{role:"alert",className:"text-sm text-destructive",children:a.error instanceof Error?a.error.message:"History could not be loaded."}):a.data.results.length===0?r.jsx("p",{className:"text-sm text-muted-foreground",children:i}):r.jsx("ol",{className:"space-y-2",children:a.data.results.map(u=>r.jsx(Ci,{entry:u},u.id))})]})}Y("resource-import","ResourceImport");function ht(e){if(e instanceof Error){const t=e.data;if(typeof t=="object"&&t!==null&&"detail"in t){const n=t.detail;if(typeof n=="string")return n}return e.message}return"Something went wrong."}function Ti({job:e}){if(e.result===null)return null;const{created:t,updated:n,skipped:s,unchanged:i,errors:o}=e.result;return r.jsxs("dl",{className:"flex flex-wrap gap-6","data-testid":"import-stats",children:[r.jsxs("div",{children:[r.jsx("dt",{className:"text-xs uppercase text-muted-foreground",children:"Created"}),r.jsx("dd",{className:"text-2xl font-semibold",children:t})]}),r.jsxs("div",{children:[r.jsx("dt",{className:"text-xs uppercase text-muted-foreground",children:"Updated"}),r.jsx("dd",{className:"text-2xl font-semibold",children:n})]}),r.jsxs("div",{children:[r.jsx("dt",{className:"text-xs uppercase text-muted-foreground",children:"Skipped"}),r.jsxs("dd",{className:"text-2xl font-semibold",children:[s," ",r.jsxs("span",{className:"text-sm font-normal text-muted-foreground",children:["(",i," unchanged, ",o," with errors)"]})]})]})]})}function Ai({job:e}){return e.problems.length===0?null:r.jsx("div",{className:"overflow-x-auto rounded-md border border-border",children:r.jsxs("table",{className:"w-full text-sm","aria-label":"Rows with errors",children:[r.jsx("thead",{className:"bg-muted text-left text-xs uppercase text-muted-foreground",children:r.jsxs("tr",{children:[r.jsx("th",{className:"px-3 py-2",children:"Row"}),r.jsx("th",{className:"px-3 py-2",children:"Field"}),r.jsx("th",{className:"px-3 py-2",children:"Problem"})]})}),r.jsx("tbody",{children:e.problems.map((t,n)=>r.jsxs("tr",{className:"border-t border-border",children:[r.jsx("td",{className:"px-3 py-2 tabular-nums",children:t.row}),r.jsx("td",{className:"px-3 py-2 font-mono text-xs",children:t.field||"—"}),r.jsx("td",{className:"px-3 py-2 text-destructive",children:t.message})]},`${t.row}-${t.field}-${n}`))})]})})}function Mi({job:e}){const t=e.rows_total>0?Math.round(e.rows_done*100/e.rows_total):0;return r.jsxs("div",{className:"space-y-2",role:"status","aria-live":"polite",children:[r.jsxs("p",{className:"text-sm",children:[e.status==="previewing"?"Previewing":"Committing","… ",e.rows_done," /"," ",e.rows_total," rows"]}),r.jsx("div",{className:"h-2 w-full overflow-hidden rounded bg-muted",children:r.jsx("div",{className:"h-full bg-primary transition-all",style:{width:`${t}%`}})})]})}function Li(e){const{job:t,fields:n,mapping:s,onChange:i}=e,o=n.map(a=>({value:a.name,label:`${a.name}${a.required?" *":""}${a.key?" (key)":""}`}));return r.jsx("div",{className:"overflow-x-auto rounded-md border border-border",children:r.jsxs("table",{className:"w-full text-sm","aria-label":"Column mapping",children:[r.jsx("thead",{className:"bg-muted text-left text-xs uppercase text-muted-foreground",children:r.jsxs("tr",{children:[r.jsx("th",{className:"px-3 py-2",children:"Column in the file"}),r.jsx("th",{className:"px-3 py-2",children:"Field"})]})}),r.jsx("tbody",{children:t.columns.map(a=>r.jsxs("tr",{className:"border-t border-border",children:[r.jsx("td",{className:"px-3 py-2",children:a}),r.jsx("td",{className:"px-3 py-2",children:r.jsx(Be,{"aria-label":`Field for ${a}`,className:"h-9 w-auto min-w-48",value:s[a]??"",options:o,clearable:!0,clearLabel:"— ignore —",onValueChange:u=>i(a,u??"")})})]},a))})]})})}function Di({resource:e,title:t="Import",onDone:n,className:s}){var U;const i=de(),o=Wn(e),a=Jn(e),[u,l]=d.useState(void 0),[c,m]=d.useState({}),[h,b]=d.useState(!1),[T,R]=d.useState(null),y=d.useRef(null),N=qn(e,u),f=N.data,j=d.useRef(void 0);d.useEffect(()=>{f!==void 0&&j.current!==f.id&&(j.current=f.id,m(f.mapping))},[f]),d.useEffect(()=>{(f==null?void 0:f.status)==="done"&&(n==null||n(f))},[f==null?void 0:f.status,f==null?void 0:f.id]);const w=(f==null?void 0:f.fields)??((U=o.data)==null?void 0:U.fields)??[],L=a.upload.isPending||a.preview.isPending||a.commit.isPending,$=a.upload.error??a.preview.error??a.commit.error,x=E=>{var v,P;E.preventDefault();const A=(P=(v=y.current)==null?void 0:v.files)==null?void 0:P[0];A!==void 0&&(b(!1),a.upload.mutate({file:A},{onSuccess:_=>l(_.id)}))},S=()=>{f!==void 0&&(b(!1),a.preview.mutate({jobId:f.id,mapping:c}))},F=E=>{R(null),Qn(i,e,E).catch(A=>R(ht(A)))};let z;return o.isPending?z=r.jsx(ce,{className:"h-24 w-full","data-testid":"resource-import-loading"}):f===void 0||u!==void 0&&N.isPending?z=r.jsxs("form",{onSubmit:x,className:"flex flex-wrap items-end gap-3",children:[r.jsxs("label",{className:"flex flex-col gap-1 text-sm",children:[r.jsx("span",{children:"CSV or XLSX file"}),r.jsx("input",{ref:y,type:"file",name:"file",accept:".csv,.xlsx",required:!0,className:"text-sm","aria-label":"File to import"})]}),r.jsx(Q,{type:"submit",disabled:L,children:"Upload"})]}):$t(f)?z=r.jsx(Mi,{job:f}):f.status==="uploaded"||f.status==="failed"||h?z=r.jsxs("div",{className:"space-y-3",children:[f.error!==null&&r.jsx("p",{role:"alert",className:"text-sm text-destructive",children:f.error}),r.jsxs("p",{className:"text-sm text-muted-foreground",children:[f.file_name," — ",f.rows_total," rows. Map each column to a field; blank cells leave a field unchanged."]}),r.jsx(Li,{job:f,fields:w,mapping:c,onChange:(E,A)=>m(v=>({...v,[E]:A}))}),r.jsxs("div",{className:"flex flex-wrap gap-2",children:[r.jsx(Q,{onClick:S,disabled:L,children:"Preview"}),r.jsx(Q,{variant:"outline",onClick:()=>l(void 0),disabled:L,children:"Upload another file"})]})]}):z=r.jsxs("div",{className:"space-y-3",children:[r.jsxs("p",{className:"text-sm text-muted-foreground",children:[f.file_name," — ",f.rows_total," rows,"," ",f.status==="done"?"imported.":"previewed; nothing is saved yet."]}),r.jsx(Ti,{job:f}),r.jsx(Ai,{job:f}),r.jsx("div",{className:"flex flex-wrap gap-2",children:f.status==="previewed"?r.jsxs(r.Fragment,{children:[r.jsx(Q,{onClick:()=>a.commit.mutate(f.id),disabled:L,children:"Commit"}),r.jsx(Q,{variant:"outline",onClick:()=>b(!0),disabled:L,children:"Change the mapping"})]}):r.jsx(Q,{variant:"outline",onClick:()=>l(void 0),children:"Import another file"})})]}),r.jsxs("section",{className:p("space-y-3",s),"aria-label":"Import",children:[r.jsxs("div",{className:"flex flex-wrap items-baseline justify-between gap-2",children:[t!==null?r.jsx("h3",{className:"text-base font-semibold",children:t}):null,r.jsxs("div",{className:"flex gap-2 text-sm",children:[r.jsx("button",{type:"button",className:"text-primary underline-offset-4 hover:underline",onClick:()=>F("xlsx"),children:"Download template (XLSX)"}),r.jsx("button",{type:"button",className:"text-primary underline-offset-4 hover:underline",onClick:()=>F("csv"),children:"CSV"})]})]}),o.error!==null&&o.error!==void 0?r.jsx("p",{role:"alert",className:"text-sm text-destructive",children:ht(o.error)}):null,$!=null?r.jsx("p",{role:"alert",className:"text-sm text-destructive",children:ht($)}):null,T!==null?r.jsx("p",{role:"alert",className:"text-sm text-destructive",children:T}):null,z]})}function Ei(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Fi(e,t){return Ei(t)&&typeof t.detail=="string"?t.detail:`Karni API request failed with status ${e}`}class Nt extends Error{constructor(n,s,i){super(i??Fi(n,s));Z(this,"status");Z(this,"data");this.name="KarniApiError",this.status=n,this.data=s}}function Pi(e){const t=/^(https?:\/\/[^/]+)(\/.*)?$/.exec(e);return t!==null?{origin:t[1]??"",basePath:(t[2]??"").replace(/\/+$/,"")}:{origin:"",basePath:e.replace(/\/+$/,"")}}function Oi(e,t){if(/^https?:\/\//.test(t))return t;const{origin:n,basePath:s}=Pi(e),i=t.startsWith("/")?t:`/${t}`;return s!==""&&(i===s||i.startsWith(`${s}/`))?n+i:n+s+i}function $i(e,t){if(t===void 0)return e;const n=new URLSearchParams;for(const[i,o]of Object.entries(t))if(o!=null)if(Array.isArray(o))for(const a of o)n.append(i,String(a));else n.append(i,String(o));const s=n.toString();return s===""?e:e.includes("?")?`${e}&${s}`:`${e}?${s}`}async function gt(e){if(e.status===204||e.status===205)return;const t=await e.text();if(t==="")return;if((e.headers.get("content-type")??"").includes("json"))try{return JSON.parse(t)}catch{return t}return t}function _i(e){const{baseUrl:t,schemaUrl:n="/api/schema/",fetch:s}=e;let i={};e.getAccessToken!==void 0&&(i={getAccessToken:e.getAccessToken});async function o(u,l){var y,N;const c=new Headers({accept:"application/json"}),m=(y=i.getHeaders)==null?void 0:y.call(i);if(m!==void 0)for(const[f,j]of Object.entries(m))c.set(f,j);if(l.headers!==void 0)for(const[f,j]of Object.entries(l.headers))c.set(f,j);const h=((N=i.getAccessToken)==null?void 0:N.call(i))??null;h!==null&&h!==""&&c.set("authorization",`Bearer ${h}`);let b;typeof FormData<"u"&&l.body instanceof FormData?b=l.body:l.body!==void 0&&(b=JSON.stringify(l.body),c.has("content-type")||c.set("content-type","application/json"));const T={method:l.method??"GET",headers:c};return b!==void 0&&(T.body=b),l.signal!==void 0&&(T.signal=l.signal),i.credentials!==void 0&&(T.credentials=i.credentials),(s??globalThis.fetch)(u,T)}async function a(u,l={}){const c=$i(Oi(t,u),l.query);let m=await o(c,l);if(m.ok)return m;const h=new Nt(m.status,await gt(m));if(m.status===401&&i.onUnauthorized!==void 0&&l.skipAuthRefresh!==!0&&await i.onUnauthorized(h)){if(m=await o(c,l),m.ok)return m;throw new Nt(m.status,await gt(m))}throw h}return{baseUrl:t,schemaUrl:n,async request(u,l={}){const c=await a(u,l);return await gt(c)},requestRaw:a,setAuthHooks(u){i={...i,...u}}}}function mn(e){if(typeof e!="object"||e===null)return;const t=e,n=t.authMode??t["x-karni-auth-mode"];return n==="jwt"||n==="session"?n:void 0}function Ye(e){if(typeof e!="object"||e===null)return null;const t=e,{id:n,email:s}=t;if(typeof n!="string"&&typeof n!="number"||typeof s!="string")return null;const i=Array.isArray(t.roles)?t.roles.filter(o=>typeof o=="string"):[];return{...t,id:n,email:s,roles:i}}function pt(e){if(typeof document>"u")return null;try{for(const t of document.cookie.split(";")){const n=t.trim(),s=n.indexOf("=");if(s!==-1&&n.slice(0,s)===e)return decodeURIComponent(n.slice(s+1))}}catch{}return null}function xt(e){if(typeof e!="object"||e===null)return`a ${typeof e}`;const t=Object.keys(e);return t.length===0?"an empty object":`an object with keys [${t.join(", ")}]`}function fn(e){if(typeof e!="object"||e===null)return null;const t=e;return t.requires_2fa!==!0?null:typeof t.ephemeral_token=="string"?{ephemeralToken:t.ephemeral_token}:null}class zi{constructor(t){Z(this,"client");Z(this,"tokenStorage");Z(this,"modeOverride");Z(this,"csrfCookieName");Z(this,"csrfHeaderName");Z(this,"authBasePath");Z(this,"readCachedSchema");Z(this,"mode");Z(this,"accessToken",null);Z(this,"refreshPromise",null);Z(this,"initPromise",null);Z(this,"listeners",new Set);Z(this,"state");Z(this,"subscribe",t=>(this.listeners.add(t),()=>{this.listeners.delete(t)}));Z(this,"getSnapshot",()=>this.state);this.client=t.client,this.tokenStorage=t.tokenStorage,this.modeOverride=t.modeOverride,this.csrfCookieName=t.csrfCookieName??"csrftoken",this.csrfHeaderName=t.csrfHeaderName??"X-CSRFToken",this.authBasePath=(t.authBasePath??"/auth").replace(/\/+$/,""),this.readCachedSchema=t.readCachedSchema,this.mode=t.modeOverride??null,this.state={status:"loading",user:null,mode:this.mode},this.attach()}attach(){this.client.setAuthHooks({getAccessToken:()=>this.accessToken,onUnauthorized:()=>this.handleUnauthorized(),getHeaders:()=>this.csrfHeaders(),...this.mode==="session"?{credentials:"include"}:{}})}detach(){this.client.setAuthHooks({getAccessToken:void 0,onUnauthorized:void 0,getHeaders:void 0,credentials:void 0})}csrfHeaders(){if(this.mode!=="session")return{};const t=pt(this.csrfCookieName);return t===null?{}:{[this.csrfHeaderName]:t}}async handleUnauthorized(){return await this.ensureInitialized(),this.mode!=="jwt"?(this.state.status==="authenticated"&&this.setState("anonymous",null),!1):this.tokenStorage.get()===null?!1:this.ensureRefresh()}setState(t,n){this.state={status:t,user:n,mode:this.mode};for(const s of this.listeners)s()}ensureInitialized(){return this.initPromise??(this.initPromise=this.initialize()),this.initPromise}async initialize(){var t;try{if(this.mode=this.modeOverride??mn((t=this.readCachedSchema)==null?void 0:t.call(this))??await this.fetchSchemaAuthMode()??"jwt",this.mode==="session"){this.client.setAuthHooks({credentials:"include"}),await this.ensureCsrfToken(),await this.syncUser();return}if(this.tokenStorage.get()===null){this.setState("anonymous",null);return}if(!await this.ensureRefresh())return;await this.syncUser()}catch{this.setState("anonymous",null)}}async fetchSchemaAuthMode(){try{const t=await this.client.request(this.client.schemaUrl,{skipAuthRefresh:!0});return mn(t)}catch{return}}async syncUser(){try{const t=await this.client.request(`${this.authBasePath}/me/`,{skipAuthRefresh:!0}),n=Ye(t);n===null?this.setState("anonymous",null):this.setState("authenticated",n)}catch{this.setState("anonymous",null)}}async ensureCsrfToken(){let t=pt(this.csrfCookieName);if(t===null){try{await this.client.request(`${this.authBasePath}/csrf/`,{method:"GET",skipAuthRefresh:!0})}catch{}t=pt(this.csrfCookieName)}return t}ensureRefresh(){return this.refreshPromise===null&&(this.refreshPromise=this.performRefresh().finally(()=>{this.refreshPromise=null})),this.refreshPromise}async performRefresh(){const t=this.tokenStorage.get();if(t===null)return this.accessToken=null,this.setState("anonymous",null),!1;this.accessToken=null;try{const n=await this.client.request(`${this.authBasePath}/refresh/`,{method:"POST",body:{refresh:t},skipAuthRefresh:!0}),s=typeof n=="object"&&n!==null?n:{},i=s.access;if(typeof i!="string"||i==="")throw new Error(`Karni auth: ${this.authBasePath}/refresh/ returned ${xt(n)} instead of { access, refresh? }.`);const o=s.refresh;return typeof o=="string"&&o!==""&&this.tokenStorage.set(o),this.accessToken=i,!0}catch{return this.tokenStorage.clear(),this.accessToken=null,this.setState("anonymous",null),!1}}async login(t,n){await this.ensureInitialized();const s=`${this.authBasePath}/login/`;if(this.mode==="session"){await this.ensureCsrfToken();const m=await this.client.request(s,{method:"POST",body:{email:t,password:n},skipAuthRefresh:!0}),h=fn(m);if(h!==null)return{requires2fa:!0,ephemeralToken:h.ephemeralToken};const b=Ye(m)??await this.fetchMe(s);return this.setState("authenticated",b),{ok:!0,user:b}}const i=await this.client.request(s,{method:"POST",body:{email:t,password:n},skipAuthRefresh:!0}),o=fn(i);if(o!==null)return{requires2fa:!0,ephemeralToken:o.ephemeralToken};const a=typeof i=="object"&&i!==null?i:{},{access:u,refresh:l}=a;if(typeof u!="string"||typeof l!="string")throw new Error(`Karni auth: unexpected response from POST ${s} — expected { access, refresh } (JWT mode) or { requires_2fa, ephemeral_token }, got ${xt(i)}. Check the backend's KARNI_AUTH_MODE and the AuthProvider "mode" prop.`);this.tokenStorage.set(l),this.accessToken=u;const c=Ye(a.user)??await this.fetchMe(s);return this.setState("authenticated",c),{ok:!0,user:c}}async fetchMe(t){const n=await this.client.request(`${this.authBasePath}/me/`,{skipAuthRefresh:!0}),s=Ye(n);if(s===null)throw new Error(`Karni auth: POST ${t} succeeded but ${this.authBasePath}/me/ returned ${xt(n)} instead of a user object with id and email.`);return s}async logout(){await this.ensureInitialized();try{if(this.mode==="session")await this.ensureCsrfToken(),await this.client.request(`${this.authBasePath}/logout/`,{method:"POST",skipAuthRefresh:!0});else{const t=this.tokenStorage.get();t!==null&&await this.client.request(`${this.authBasePath}/logout/`,{method:"POST",body:{refresh:t},skipAuthRefresh:!0})}}catch{}this.accessToken=null,this.tokenStorage.clear(),this.setState("anonymous",null)}async adoptTokens(t,n){await this.ensureInitialized(),this.mode==="jwt"&&(typeof n=="string"&&n!==""&&this.tokenStorage.set(n),typeof t=="string"&&t!==""&&(this.accessToken=t)),await this.syncUser()}async refresh(){await this.ensureInitialized(),!(this.mode==="jwt"&&!await this.ensureRefresh())&&await this.syncUser()}}function sr(e="karni.refreshToken"){return{get(){try{return globalThis.localStorage.getItem(e)}catch{return null}},set(t){try{globalThis.localStorage.setItem(e,t)}catch{}},clear(){try{globalThis.localStorage.removeItem(e)}catch{}}}}function Bi(){let e=null;return{get:()=>e,set:t=>{e=t},clear:()=>{e=null}}}const ir=re.createContext(null);function Vi({mode:e,tokenStorage:t,csrfCookieName:n,csrfHeaderName:s,authBasePath:i,children:o}){var R;const a=de(),u=W.useQueryClient(),l=re.useMemo(()=>t??sr(),[t]),c=re.useMemo(()=>new zi({client:a,tokenStorage:l,...e!==void 0?{modeOverride:e}:{},...n!==void 0?{csrfCookieName:n}:{},...s!==void 0?{csrfHeaderName:s}:{},...i!==void 0?{authBasePath:i}:{},readCachedSchema:()=>u.getQueryData(ue.schema())}),[a,u,l,e,n,s,i]);re.useEffect(()=>(c.attach(),c.ensureInitialized(),()=>{c.detach()}),[c]);const m=re.useSyncExternalStore(c.subscribe,c.getSnapshot,c.getSnapshot),h=((R=m.user)==null?void 0:R.id)??null,b=re.useRef(h);re.useEffect(()=>{b.current!==h&&(b.current=h,u.invalidateQueries({queryKey:ue.schema()}))},[h,u]);const T=re.useMemo(()=>{var y;return{user:m.user,roles:((y=m.user)==null?void 0:y.roles)??[],status:m.status,login:(N,f)=>c.login(N,f),logout:()=>c.logout(),refresh:()=>c.refresh(),adoptTokens:(N,f)=>c.adoptTokens(N,f)}},[c,m]);return r.jsx(ir.Provider,{value:T,children:o})}function lt(){const e=re.useContext(ir);if(e===null)throw new Error("useAuth must be used within an <AuthProvider> (itself inside <KarniProvider>). Wrap your tree: <KarniProvider client={...}><AuthProvider>...</AuthProvider></KarniProvider>.");return e}Y("auth-guard","AuthGuard");function Ui({roles:e,fallback:t=null,loading:n=null,children:s}){const{status:i,user:o}=lt();return i==="loading"?r.jsx(r.Fragment,{children:n}):i!=="authenticated"||o===null?r.jsx(r.Fragment,{children:t}):e!==void 0&&e.length>0&&!e.some(a=>o.roles.includes(a))?r.jsx(r.Fragment,{children:t}):r.jsx(r.Fragment,{children:s})}Y("login-form","LoginForm");function Ki({onSuccess:e,on2FA:t,title:n="Sign in",description:s,submitLabel:i="Sign in",disabled:o=!1,className:a}){const{login:u}=lt(),l=d.useId(),[c,m]=d.useState(!1),[h,b]=d.useState(null);async function T(R){R.preventDefault();const y=new FormData(R.currentTarget);m(!0),b(null);try{const N=await u(String(y.get("email")??""),String(y.get("password")??""));"ok"in N?e==null||e(N.user):t!==void 0?t(N.ephemeralToken):b("This account needs a two-factor code; the app has not enabled that step.")}catch{b("That email and password do not match.")}finally{m(!1)}}return r.jsxs("form",{className:p("space-y-4",a),onSubmit:R=>void T(R),"aria-busy":c,noValidate:!1,children:[n!==null?r.jsx("h2",{className:"text-lg font-semibold",children:n}):null,s!==void 0?r.jsx("p",{className:"text-sm text-muted-foreground",children:s}):null,r.jsxs("div",{className:"space-y-1",children:[r.jsx(We,{htmlFor:`${l}-email`,children:"Email"}),r.jsx(ye,{id:`${l}-email`,name:"email",type:"email",autoComplete:"email",required:!0,disabled:o||c})]}),r.jsxs("div",{className:"space-y-1",children:[r.jsx(We,{htmlFor:`${l}-password`,children:"Password"}),r.jsx(ye,{id:`${l}-password`,name:"password",type:"password",autoComplete:"current-password",required:!0,disabled:o||c})]}),h!==null?r.jsx("p",{role:"alert",className:"text-sm text-destructive",children:h}):null,r.jsx(Q,{type:"submit",disabled:o||c,children:i})]})}function Hi(){const{roles:e,status:t}=lt();return re.useMemo(()=>({isAuthenticated:t==="authenticated",hasRole:(...n)=>t==="authenticated"&&n.some(s=>e.includes(s))}),[e,t])}Y("page-shell","Page");const or=d.forwardRef(({title:e,description:t,actions:n,header:s,headerClassName:i,contentClassName:o,className:a,children:u,...l},c)=>r.jsxs("section",{ref:c,className:p("flex w-full flex-col gap-6",a),...l,children:[s??r.jsxs("header",{className:p("flex flex-wrap items-start justify-between gap-4",i),children:[r.jsxs("div",{className:"grid gap-1",children:[r.jsx("h1",{className:"text-2xl font-semibold tracking-tight text-foreground",children:e}),t!=null&&r.jsx("p",{className:"text-sm text-muted-foreground",children:t})]}),n!=null&&r.jsx("div",{className:"flex shrink-0 items-center gap-2",children:n})]}),r.jsx("div",{className:p("flex flex-col gap-4",o),children:u})]}));or.displayName="Page";const Qi="0 0 1000 1000",Wi=[{fill:"#000000",d:"M495.8 884.4C366.3 877.9 255.3 816.3 182.4 710.5C128.6 632.2 103.2 521.3 115 415.5C128.3 296.3 188.2 205.8 290.9 150.2C389.1 97 470.1 78.3 564.8 87C689.6 98.4 790.1 167.2 844.3 278.1C896.3 384.6 901.7 498.4 860.4 619.6C833.4 698.7 806.7 746.3 766.3 787.1C699.4 854.6 601.9 889.7 495.8 884.4Z"},{fill:"#FB5D08",d:"M355.6 514.1C355.6 509.2 355.7 507.3 355.8 509.8C355.9 512.3 355.9 516.3 355.8 518.7C355.7 521 355.6 519 355.6 514.1ZM677.1 423C637.3 415.7 624.1 366.4 654.9 340.2C672.8 325 696 324.3 713.7 338.5C741 360.3 735.8 403.2 704.1 418.6C696.1 422.4 684.6 424.3 677.1 423ZM330.5 421.6C299.1 415 283.8 379.9 300.6 352.7C317.1 325.8 352.4 320.7 373.7 342.2C398.9 367.6 387.2 410.3 352.3 420.8C347.4 422.3 335.7 422.7 330.5 421.6ZM504.5 399.6C466.4 392.2 453.2 345.4 481.5 318.2C509.6 291.1 556 308.2 560.5 347.3C564.1 377.9 534.5 405.5 504.5 399.6ZM349.4 395.9C367.2 387.1 367.7 363.1 350.2 354.5C329.3 344.3 308.5 369.4 321.8 388.6C327.9 397.5 339.8 400.7 349.4 395.9ZM694 395.9C716 385.1 709 352 684.8 352C665.4 352 654.8 375.3 667.3 390.4C673.5 397.8 685.2 400.2 694 395.9ZM522.4 373.7C534.6 368 539.9 353.6 534.2 341.9C525.3 323.9 501.3 323.8 492.5 341.8C482.8 361.3 503 382.8 522.4 373.7Z"},{fill:"#FFFFFF",d:"M363 677.8C348.7 675.4 341.3 657.2 334.1 606.9C326.6 554.4 325.7 485.2 332.2 459.2C336.3 442.9 349.3 435.9 362.9 442.6C374.7 448.4 394.4 475.1 427.1 529.5C428.9 532.4 430.5 534.9 430.8 534.9C431 534.9 433.5 530.7 436.3 525.6C486 435.8 497.3 419.9 512.2 419.2C523.9 418.6 531.9 426.3 550 455.6C555.3 464.3 582.5 513.2 591.4 530.3C592.7 532.8 594 534.9 594.2 534.9C594.4 534.9 595.9 532.7 597.5 530C621.8 490.2 643.6 458.3 652.7 449.5C668.6 434.2 686.9 437.8 692.6 457.4C703.9 496.4 693.7 637.6 677.5 666.3C673 674.5 663.4 679.5 655.8 677.8C642.6 674.9 633.9 663.4 598.7 602.7C592.7 592.3 593.3 593.1 592.3 594.4C590.8 596.2 572.8 626.4 560.2 648.2C546.9 671 546 672.4 541.7 674.3C531.2 679.1 519.1 669.5 522.1 658.7C523.4 654.4 551 607 571.8 573.6C575 568.5 577.6 564.2 577.6 564C577.6 563.7 560.8 532.5 547.2 507.4C527.8 471.7 514.9 450.1 513.1 450.1C512.4 450.1 510.6 452.9 504.3 463.4C492.7 482.5 447.9 562.5 447.9 564C447.9 564.3 449.8 567.6 452.1 571.4C475.2 609.2 501.1 653.4 502.6 657.5C506.1 667.6 496.6 677.8 485.8 675.3C479.8 673.9 479.1 673.1 468.6 655.1C464.9 648.8 456 633.6 448.7 621.3C441.5 608.9 434.9 597.8 434.2 596.5C432.8 594 431.8 593 431.5 593.9C431.3 594.5 427.1 601.6 414 623.8C386.6 670 377.1 680.1 363 677.8ZM373.8 636.7C376.1 632.9 382.1 622.9 387.1 614.4C408.9 577.2 413.5 569.4 414.6 567.2L415.7 564.9L411.3 557.5C374 495.9 359.9 473.9 357.6 473.9C355.5 473.9 355.1 527.7 357.1 556.7C359.2 587.2 364.9 630.4 368.5 642.5C369 644.1 369.4 643.7 373.8 636.7ZM658.1 639.2C666.8 598 672.3 509 668.1 476.6C667.7 473.1 667.4 473.2 663.8 478C657.6 486.3 651.5 495.7 631.2 529C626.9 536.1 622.1 543.9 620.5 546.5C618.9 549.1 615.7 554.3 613.4 558.1L609.1 565L610.6 567.5C611.4 568.9 616.6 577.6 622.1 586.9C627.5 596.2 634.1 607.5 636.7 611.9C649.4 633.6 655.7 643.4 656.8 643.4C657 643.4 657.6 641.5 658.1 639.2Z"}],qi=`<path fill="#000000" d="M495.8 884.4C291.9 874.2 135.4 724 114.7 518.5C97.9 351.3 160.2 221 290.9 150.2C372.3 106.1 439.7 86.4 513.6 85.2C686 82.3 812.9 171.5 867 333.5C903.9 444 890.2 573.8 828.6 698.6C766.8 823.4 644.3 891.8 495.8 884.4Z"/>
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,s)=>(s=n==null?{}:e(i(n)),o(r||!n||!n.__esModule||!a.call(n,`default`)?t(s,`default`,{value:n,enumerable:!0}):s,n));const c=require("./script-BVJ9BbPm.cjs");let l=require("clsx"),u=require("tailwind-merge"),d=require("react");d=s(d,1);let f=require("react/jsx-runtime"),p=require("@radix-ui/react-select");p=s(p,1);let m=require("@radix-ui/react-checkbox");m=s(m,1);let h=require("@radix-ui/react-switch");h=s(h,1);let g=require("@radix-ui/react-label");g=s(g,1);let _=require("@radix-ui/react-tabs");_=s(_,1);let v=require("@radix-ui/react-dropdown-menu");v=s(v,1);let y=require("@tanstack/react-query"),b=require("@tanstack/react-table"),x=require("@radix-ui/react-dialog");x=s(x,1);let S=require("@radix-ui/react-popover");S=s(S,1);let C=require("@hookform/resolvers/zod"),w=require("react-hook-form"),T=require("zod"),E=require("@radix-ui/react-toast");E=s(E,1);let ee=require("@radix-ui/react-visually-hidden");ee=s(ee,1);function D(...e){return(0,u.twMerge)((0,l.clsx)(e))}var O=new Map;function k(){try{let e={};return!(!e.hot||e.env?.MODE===`test`||typeof process<`u`&&process.env?.VITEST!==void 0)}catch{return!1}}var A=k;function j(e,t,n){if(n?.replace){let r=n.reason?.trim()??``;if(r===``)throw Error(`[karni] registerComponentRole: replacing role "${e}" requires a non-empty reason. Pass { replace: true, reason: "<why>" }.`);let i=O.get(e);i!==void 0&&i!==t&&console.warn(`[karni] component role "${e}" replaced: "${i}" -> "${t}" (${r})`),O.set(e,t);return}let r=O.get(e);if(r===void 0||r===t){O.set(e,t);return}let i=`[karni] duplicate component role "${e}": already registered by "${r}", now claimed by "${t}". Compose or extend the existing component instead, or replace it on purpose with { replace: true, reason: "<why>" }.`;if(A())console.error(i),O.set(e,t);else throw Error(i)}function te(){return Object.freeze(Object.fromEntries(O))}function M(e){let t=Object.keys(e.variants);return n=>{let{className:r,...i}=n??{},a=i,o={},s=[];e.base&&s.push(e.base);for(let n of t){let t=a[n]??e.defaultVariants?.[n];if(t==null)continue;o[n]=t;let r=e.variants[n][t];r&&s.push(r)}for(let t of e.compoundVariants??[]){let{className:e,...n}=t,r=n;Object.keys(r).every(e=>{let t=r[e];return t!=null&&o[e]===t})&&s.push(e)}return D(...s,r)}}function N(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function P(e,t){return N(t)&&typeof t.detail==`string`?t.detail:`Karni API request failed with status ${e}`}var F=class extends Error{status;data;constructor(e,t,n){super(n??P(e,t)),this.name=`KarniApiError`,this.status=e,this.data=t}};function I(e){let t=/^(https?:\/\/[^/]+)(\/.*)?$/.exec(e);return t===null?{origin:``,basePath:e.replace(/\/+$/,``)}:{origin:t[1]??``,basePath:(t[2]??``).replace(/\/+$/,``)}}function L(e,t){if(/^https?:\/\//.test(t))return t;let{origin:n,basePath:r}=I(e),i=t.startsWith(`/`)?t:`/${t}`;return r!==``&&(i===r||i.startsWith(`${r}/`))?n+i:n+r+i}function ne(e,t){if(t===void 0)return e;let n=new URLSearchParams;for(let[e,r]of Object.entries(t))if(r!=null){if(Array.isArray(r))for(let t of r)n.append(e,String(t));else n.append(e,String(r))}let r=n.toString();return r===``?e:e.includes(`?`)?`${e}&${r}`:`${e}?${r}`}async function re(e){if(e.status===204||e.status===205)return;let t=await e.text();if(t!==``){if((e.headers.get(`content-type`)??``).includes(`json`))try{return JSON.parse(t)}catch{return t}return t}}function ie(e){let{baseUrl:t,schemaUrl:n=`/api/schema/`,fetch:r}=e,i={};e.getAccessToken!==void 0&&(i={getAccessToken:e.getAccessToken});async function a(e,t){let n=new Headers({accept:`application/json`}),a=i.getHeaders?.();if(a!==void 0)for(let[e,t]of Object.entries(a))n.set(e,t);if(t.headers!==void 0)for(let[e,r]of Object.entries(t.headers))n.set(e,r);let o=i.getAccessToken?.()??null;o!==null&&o!==``&&n.set(`authorization`,`Bearer ${o}`);let s;typeof FormData<`u`&&t.body instanceof FormData?s=t.body:t.body!==void 0&&(s=JSON.stringify(t.body),n.has(`content-type`)||n.set(`content-type`,`application/json`));let c={method:t.method??`GET`,headers:n};return s!==void 0&&(c.body=s),t.signal!==void 0&&(c.signal=t.signal),i.credentials!==void 0&&(c.credentials=i.credentials),(r??globalThis.fetch)(e,c)}async function o(e,n={}){let r=ne(L(t,e),n.query),o=await a(r,n);if(o.ok)return o;let s=new F(o.status,await re(o));if(o.status===401&&i.onUnauthorized!==void 0&&n.skipAuthRefresh!==!0&&await i.onUnauthorized(s)){if(o=await a(r,n),o.ok)return o;throw new F(o.status,await re(o))}throw s}return{baseUrl:t,schemaUrl:n,async request(e,t={}){return await re(await o(e,t))},requestRaw:o,setAuthHooks(e){i={...i,...e}}}}var R=new Set([`You do not have permission to perform this action.`,`Authentication credentials were not provided.`,`Not found.`,`No Page matches the given query.`]);function ae(e){return e.charAt(0).toUpperCase()+e.slice(1)}function oe(e){let t=e.data;if(typeof t==`object`&&t&&!Array.isArray(t)){let e=t.detail;if(typeof e==`string`&&e.trim()!==``&&!R.has(e.trim()))return e.trim()}}function z(){return typeof navigator<`u`&&navigator.onLine===!1}function se(e){return e instanceof TypeError}function ce(e){return typeof e==`object`&&!!e&&[`TimeoutError`,`AbortError`].includes(String(e.name))}function le(e,t={}){let{action:n,resource:r}=t;if(e instanceof F){let t=e.status,i=t<500?oe(e):void 0,a={status:t,...i===void 0?{}:{detail:i}};if(t===401)return{...a,kind:`unauthenticated`,title:`Your session has ended`,description:`Sign in again to continue.`,retryable:!1};if(t===403){let e=[n,r].filter(Boolean).join(` `);return{...a,kind:`forbidden`,title:e?`You can't ${e}`:`You don't have access to this`,description:`Your role doesn't allow it. Ask an administrator if you need access.`,retryable:!1}}if(t===404||t===410)return{...a,kind:`not-found`,title:r?`Couldn't find ${r}`:`Not found`,description:`It may have been deleted, or it isn't available to you.`,retryable:!1};if(t===400||t===422)return{...a,kind:`validation`,title:`Some details need attention`,description:`Check the highlighted fields, then try again.`,retryable:!1};if(t===409||t===412)return{...a,kind:`conflict`,title:`This changed while you were working`,description:`Reload to see the latest version, then try again.`,retryable:!1};if(t===429)return{...a,kind:`rate-limited`,title:`Too many requests`,description:`Wait a moment, then try again.`,retryable:!0};if(t===408||t===504)return{...a,kind:`timeout`,title:`The server took too long to answer`,description:`Try again in a moment.`,retryable:!0};if(t>=500)return{...a,kind:`server`,title:`Something went wrong on our side`,description:`Try again. If it keeps happening, tell the site's administrator.`,retryable:!0}}return se(e)?z()?{kind:`offline`,title:`You're offline`,description:`Check your connection, then try again.`,retryable:!0}:{kind:`network`,title:`Couldn't reach the server`,description:`Check your connection, then try again.`,retryable:!0}:ce(e)?{kind:`timeout`,title:`The request took too long`,description:`Try again in a moment.`,retryable:!0}:{kind:`unknown`,title:n?`Couldn't ${n}${r?` ${r}`:``}`:`Something went wrong`,description:`Try again.`,retryable:!0}}function ue(e,t){return ae(le(e,t).title)}function B(e){return{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":!0,focusable:!1,...e}}function V(e){return(0,f.jsx)(`svg`,{...B(e),children:(0,f.jsx)(`polyline`,{points:`20 6 9 17 4 12`})})}function de(e){return(0,f.jsx)(`svg`,{...B(e),children:(0,f.jsx)(`polyline`,{points:`6 9 12 15 18 9`})})}function H(e){return(0,f.jsx)(`svg`,{...B(e),children:(0,f.jsx)(`polyline`,{points:`18 15 12 9 6 15`})})}function U(e){return(0,f.jsxs)(`svg`,{...B(e),children:[(0,f.jsx)(`path`,{d:`M10.3 3.9 1.8 18a2 2 0 0 0 1.7 3h17a2 2 0 0 0 1.7-3L13.7 3.9a2 2 0 0 0-3.4 0z`}),(0,f.jsx)(`line`,{x1:`12`,y1:`9`,x2:`12`,y2:`13`}),(0,f.jsx)(`line`,{x1:`12`,y1:`17`,x2:`12.01`,y2:`17`})]})}function fe(e){return(0,f.jsxs)(`svg`,{...B(e),children:[(0,f.jsx)(`rect`,{x:`3`,y:`11`,width:`18`,height:`11`,rx:`2`,ry:`2`}),(0,f.jsx)(`path`,{d:`M7 11V7a5 5 0 0 1 10 0v4`})]})}function W(e){return(0,f.jsxs)(`svg`,{...B(e),children:[(0,f.jsx)(`line`,{x1:`1`,y1:`1`,x2:`23`,y2:`23`}),(0,f.jsx)(`path`,{d:`M16.7 11.1A10.9 10.9 0 0 1 19 12.6M5 12.6a10.9 10.9 0 0 1 5.2-2.5M10.7 5A16 16 0 0 1 22.6 9M1.4 9a15.9 15.9 0 0 1 4.7-2.9M8.5 16.1a6 6 0 0 1 7 0`}),(0,f.jsx)(`line`,{x1:`12`,y1:`20`,x2:`12.01`,y2:`20`})]})}function pe(e){return(0,f.jsxs)(`svg`,{...B(e),children:[(0,f.jsx)(`circle`,{cx:`11`,cy:`11`,r:`8`}),(0,f.jsx)(`line`,{x1:`21`,y1:`21`,x2:`16.65`,y2:`16.65`})]})}function me(e){return(0,f.jsx)(`svg`,{...B(e),children:(0,f.jsx)(`path`,{d:`M21 12a9 9 0 1 1-6.2-8.6`})})}function he(e){return(0,f.jsxs)(`svg`,{...B(e),children:[(0,f.jsx)(`circle`,{cx:`12`,cy:`12`,r:`4`}),(0,f.jsx)(`path`,{d:`M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4`})]})}function G(e){return(0,f.jsx)(`svg`,{...B(e),children:(0,f.jsx)(`path`,{d:`M21 12.8A9 9 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8z`})})}function ge(e){return(0,f.jsxs)(`svg`,{...B(e),children:[(0,f.jsx)(`rect`,{x:`2`,y:`3`,width:`20`,height:`14`,rx:`2`,ry:`2`}),(0,f.jsx)(`line`,{x1:`8`,y1:`21`,x2:`16`,y2:`21`}),(0,f.jsx)(`line`,{x1:`12`,y1:`17`,x2:`12`,y2:`21`})]})}var K=d.createContext({});function _e({value:e,children:t}){let n=d.useContext(K),r=d.useMemo(()=>({...n,...e}),[n,e]);return(0,f.jsx)(K.Provider,{value:r,children:t})}function q(){return d.useContext(K)}function J(e,t){let n=d.forwardRef((n,r)=>{let i=d.useContext(K),a=d.useMemo(()=>({...i,[e]:void 0}),[i]),o=i[e];return o===void 0?d.createElement(t,{...n,ref:r}):(0,f.jsx)(K.Provider,{value:a,children:d.createElement(o,{...n,ref:r})})});return n.displayName=t.displayName,n}function Y(e,t){let n=d.forwardRef((n,r)=>{let i=d.useContext(K).select,a=i?i[e]:t;return d.createElement(a,e===`Root`?n:{...n,ref:r})});return n.displayName=`Select${e===`Root`?`Root`:e}`,n}var X=M({base:`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`,variants:{variant:{default:`bg-primary text-primary-foreground hover:bg-primary-hover`,destructive:`bg-destructive text-destructive-foreground hover:bg-destructive-hover`,outline:`border border-input bg-background hover:bg-accent hover:text-accent-foreground`,secondary:`bg-secondary text-secondary-foreground hover:bg-secondary-hover`,ghost:`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`}},defaultVariants:{variant:`default`,size:`default`}}),ve=d.forwardRef(({className:e,variant:t,size:n,type:r,...i},a)=>(0,f.jsx)(`button`,{ref:a,type:r??`button`,className:X({variant:t,size:n,className:e}),...i}));ve.displayName=`Button`;var Z=J(`button`,ve),ye=500;function be(e,t=500){let[n,r]=d.useState(!1);return d.useEffect(()=>{if(!e){r(!1);return}let n=setTimeout(()=>r(!0),t);return()=>clearTimeout(n)},[e,t]),e&&n}function xe(e){return window.addEventListener(`online`,e),window.addEventListener(`offline`,e),()=>{window.removeEventListener(`online`,e),window.removeEventListener(`offline`,e)}}function Se(){return d.useSyncExternalStore(xe,()=>navigator.onLine,()=>!0)}var Ce=d.forwardRef(({pending:e=!1,pendingLabel:t=`Working…`,disabled:n,className:r,children:i,...a},o)=>{let s=be(e);return(0,f.jsxs)(f.Fragment,{children:[(0,f.jsxs)(Z,{ref:o,disabled:n===!0||e,"aria-busy":e||void 0,className:D(`relative`,r),...a,children:[(0,f.jsx)(`span`,{className:D(`inline-flex items-center gap-2`,s&&`text-transparent`),children:i}),s&&(0,f.jsx)(`span`,{className:`absolute inset-0 flex items-center justify-center`,"aria-hidden":`true`,children:(0,f.jsx)(me,{className:`h-4 w-4 animate-spin`})})]}),(0,f.jsx)(`span`,{className:`sr-only`,role:`status`,"aria-live":`polite`,children:e?t:``})]})});Ce.displayName=`PendingButton`,j(`error-state`,`ErrorState`),j(`permission-denied`,`PermissionDenied`);var we={forbidden:fe,unauthenticated:fe,offline:W,network:W,"not-found":pe},Te=d.forwardRef(({error:e,context:t,onRetry:n,retrying:r=!1,actions:i,variant:a=`panel`,className:o,...s},c)=>{let l=le(e,t),u=we[l.kind]??U,d=l.retryable&&n!==void 0?(0,f.jsx)(Ce,{variant:`outline`,size:`sm`,onClick:n,pending:r,pendingLabel:`Trying again…`,children:`Try again`}):null,p=a===`inline`;return(0,f.jsxs)(`div`,{ref:c,role:`alert`,"data-error-kind":l.kind,className:D(p?`flex flex-wrap items-center gap-2 text-sm`:`flex w-full flex-col items-center gap-2 rounded-lg border border-destructive-border bg-destructive-subtle px-6 py-8 text-center`,o),...s,children:[(0,f.jsx)(u,{className:D(`shrink-0 text-destructive`,p?`h-4 w-4`:`mb-1 h-8 w-8`)}),(0,f.jsx)(`p`,{className:D(`font-semibold text-foreground`,p?`text-sm`:`text-base`),children:l.title}),(0,f.jsx)(`p`,{className:`max-w-128 text-sm text-muted-foreground`,children:l.description}),l.detail!==void 0&&(0,f.jsx)(`p`,{className:`max-w-128 text-xs text-muted-foreground`,children:l.detail}),(d!==null||i!==void 0)&&(0,f.jsxs)(`div`,{className:D(`flex flex-wrap items-center gap-2`,!p&&`mt-2`),children:[d,i]})]})});Te.displayName=`ErrorState`;var Ee=d.forwardRef(({action:e,resource:t,description:n,actions:r,className:i,...a},o)=>{let s=[e,t].filter(Boolean).join(` `);return(0,f.jsxs)(`div`,{ref:o,"data-error-kind":`forbidden`,className:D(`flex w-full flex-col items-center gap-2 rounded-lg border border-border bg-muted-subtle px-6 py-8 text-center`,i),...a,children:[(0,f.jsx)(fe,{className:`mb-1 h-8 w-8 text-muted-foreground`}),(0,f.jsx)(`p`,{className:`text-base font-semibold text-foreground`,children:s?`You can't ${s}`:`You don't have access to this`}),(0,f.jsx)(`p`,{className:`max-w-128 text-sm text-muted-foreground`,children:n??`Your role doesn't allow it. Ask an administrator if you need access.`}),r!==void 0&&(0,f.jsx)(`div`,{className:`mt-2 flex items-center gap-2`,children:r})]})});Ee.displayName=`PermissionDenied`,j(`theme-toggle`,`ThemeToggle`);var De=d.createContext(null),Oe=`(prefers-color-scheme: dark)`;function ke(e){try{let t=localStorage.getItem(e);return t===`light`||t===`dark`||t===`system`?t:null}catch{return null}}function Ae(){return typeof matchMedia==`function`&&matchMedia(Oe).matches?`dark`:`light`}function je({defaultTheme:e=`system`,storageKey:t=c.n,target:n,children:r}){let[i,a]=d.useState(()=>ke(t)??e),[o,s]=d.useState(Ae);d.useEffect(()=>{if(typeof matchMedia!=`function`)return;let e=matchMedia(Oe),t=()=>s(e.matches?`dark`:`light`);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let l=i===`system`?o:i;d.useEffect(()=>{let e=n?n():document.documentElement;e.classList.toggle(`dark`,l===`dark`),e.style.colorScheme=l},[l,n]);let u=d.useCallback(e=>{a(e);try{localStorage.setItem(t,e)}catch{}},[t]),p=d.useMemo(()=>({theme:i,resolvedTheme:l,setTheme:u}),[i,l,u]);return(0,f.jsx)(De.Provider,{value:p,children:r})}function Me(){let e=d.useContext(De);if(e===null)throw Error(`useTheme must be used within <ThemeProvider>. Wrap your app in <ThemeProvider> (from @karni/ui).`);return e}var Ne={light:`dark`,dark:`system`,system:`light`},Pe={light:`Light`,dark:`Dark`,system:`System`};function Fe({className:e}){let{theme:t,setTheme:n}=Me(),r=t===`light`?he:t===`dark`?G:ge,i=`Theme: ${Pe[t]}. Switch to ${Pe[Ne[t]]}`;return(0,f.jsx)(Z,{variant:`ghost`,size:`icon`,className:e,"aria-label":i,title:i,onClick:()=>n(Ne[t]),children:(0,f.jsx)(r,{className:`h-4 w-4`})})}var Q=d.forwardRef(({className:e,...t},n)=>(0,f.jsx)(`input`,{ref:n,className:D(`flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 aria-[invalid=true]:border-destructive aria-[invalid=true]:focus-visible:ring-destructive`,e),...t}));Q.displayName=`Input`;var Ie=J(`input`,Q),Le=d.forwardRef(({className:e,...t},n)=>(0,f.jsx)(`textarea`,{ref:n,className:D(`flex min-h-20 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 aria-[invalid=true]:border-destructive aria-[invalid=true]:focus-visible:ring-destructive`,e),...t}));Le.displayName=`Textarea`;var Re=J(`textarea`,Le),ze=`empty`,Be=d.forwardRef(({label:e=ze,className:t,...n},r)=>(0,f.jsxs)(`span`,{ref:r,className:D(`text-muted-foreground`,t),...n,children:[(0,f.jsx)(`span`,{"aria-hidden":`true`,children:`–`}),(0,f.jsx)(`span`,{className:`sr-only`,children:e})]}));Be.displayName=`EmptyValue`;var Ve=`__karni_empty__`,He=Y(`Root`,p.Root),Ue=Y(`Group`,p.Group),We=Y(`Value`,p.Value),Ge=d.forwardRef(({className:e,children:t,...n},r)=>(0,f.jsxs)(p.Trigger,{ref:r,className:D(`flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 aria-[invalid=true]:border-destructive aria-[invalid=true]:focus-visible:ring-destructive [&>span]:line-clamp-1`,e),...n,children:[t,(0,f.jsx)(p.Icon,{asChild:!0,children:(0,f.jsx)(de,{className:`h-4 w-4 shrink-0 opacity-50`})})]}));Ge.displayName=`SelectTrigger`;var Ke=Y(`Trigger`,Ge),qe=d.forwardRef(({className:e,...t},n)=>(0,f.jsx)(p.ScrollUpButton,{ref:n,className:D(`flex cursor-default items-center justify-center py-1`,e),...t,children:(0,f.jsx)(H,{className:`h-4 w-4`})}));qe.displayName=`SelectScrollUpButton`;var Je=d.forwardRef(({className:e,...t},n)=>(0,f.jsx)(p.ScrollDownButton,{ref:n,className:D(`flex cursor-default items-center justify-center py-1`,e),...t,children:(0,f.jsx)(de,{className:`h-4 w-4`})}));Je.displayName=`SelectScrollDownButton`;var Ye=d.forwardRef(({className:e,children:t,position:n=`popper`,...r},i)=>(0,f.jsx)(p.Portal,{children:(0,f.jsxs)(p.Content,{ref:i,position:n,className:D(`relative z-popover max-h-96 min-w-32 overflow-hidden rounded-md border border-border bg-popover text-popover-foreground shadow-md`,n===`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),...r,children:[(0,f.jsx)(qe,{}),(0,f.jsx)(p.Viewport,{className:D(`p-1`,n===`popper`&&`h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]`),children:t}),(0,f.jsx)(Je,{})]})}));Ye.displayName=`SelectContent`;var Xe=Y(`Content`,Ye),Ze=d.forwardRef(({className:e,...t},n)=>(0,f.jsx)(p.Label,{ref:n,className:D(`py-1.5 pl-8 pr-2 text-sm font-semibold`,e),...t}));Ze.displayName=`SelectLabel`;var Qe=Y(`Label`,Ze),$e=d.forwardRef(({className:e,children:t,...n},r)=>(0,f.jsxs)(p.Item,{ref:r,className:D(`relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50`,e),...n,children:[(0,f.jsx)(`span`,{className:`absolute left-2 flex h-3.5 w-3.5 items-center justify-center`,children:(0,f.jsx)(p.ItemIndicator,{children:(0,f.jsx)(V,{className:`h-4 w-4`})})}),(0,f.jsx)(p.ItemText,{children:t})]}));$e.displayName=`SelectItem`;var et=Y(`Item`,$e),tt=d.forwardRef(({className:e,...t},n)=>(0,f.jsx)(p.Separator,{ref:n,className:D(`-mx-1 my-1 h-px bg-muted`,e),...t}));tt.displayName=`SelectSeparator`;var nt=Y(`Separator`,tt),rt=d.forwardRef((e,t)=>{let{value:n,onValueChange:r,options:i,placeholder:a,clearable:o=!1,clearLabel:s=(0,f.jsx)(Be,{}),disabled:c,name:l,id:u,className:p,contentClassName:m,children:h,"aria-label":g,"aria-labelledby":_,"aria-describedby":v,"aria-invalid":y,"aria-required":b,onBlur:x,onOpenChange:S}=e,C=d.useRef(!1),w=d.useMemo(()=>{let e=i.filter(e=>e.value!==``&&e.value!==`__karni_empty__`);return e.length!==i.length&&console.warn(`[karni-ui] <Select> option values "" and "${Ve}" are reserved, so those options were dropped. Use the \`clearable\` prop for an empty choice.`),e},[i]),T=n==null||n===``?o?Ve:``:n,E=d.useCallback(e=>{r?.(e===`__karni_empty__`?null:e)},[r]);return(0,f.jsxs)(He,{value:T,onValueChange:E,onOpenChange:e=>{C.current=e,S?.(e)},disabled:c,name:l,children:[(0,f.jsx)(Ke,{ref:t,id:u,className:p,"aria-label":g,"aria-labelledby":_,"aria-describedby":v,"aria-invalid":y,"aria-required":b,onBlur:e=>{if(C.current)return;let t=e.relatedTarget;t instanceof Element&&t.closest(`[role='listbox']`)!==null||x?.(e)},children:(0,f.jsx)(We,{placeholder:a})}),(0,f.jsxs)(Xe,{className:m,children:[o?(0,f.jsx)(et,{value:Ve,className:`text-muted-foreground`,children:s}):null,w.map(e=>(0,f.jsx)(et,{value:e.value,disabled:e.disabled,children:e.label},e.value)),h]})]})});rt.displayName=`Select`;var it=d.forwardRef(({className:e,...t},n)=>(0,f.jsx)(m.Root,{ref:n,className:D(`peer h-4 w-4 shrink-0 rounded-sm border border-primary 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 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground aria-[invalid=true]:border-destructive aria-[invalid=true]:focus-visible:ring-destructive`,e),...t,children:(0,f.jsx)(m.Indicator,{className:`flex items-center justify-center text-current`,children:(0,f.jsx)(V,{className:`h-3.5 w-3.5`})})}));it.displayName=`Checkbox`;var at=J(`checkbox`,it),ot=d.forwardRef(({className:e,...t},n)=>(0,f.jsx)(h.Root,{ref:n,className:D(`peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=unchecked]:bg-input aria-[invalid=true]:ring-2 aria-[invalid=true]:ring-destructive aria-[invalid=true]:ring-offset-2 aria-[invalid=true]:ring-offset-background`,e),...t,children:(0,f.jsx)(h.Thumb,{className:`pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0`})}));ot.displayName=`Switch`;var st=J(`switch`,ot),ct=d.forwardRef(({className:e,...t},n)=>(0,f.jsx)(g.Root,{ref:n,className:D(`text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70`,e),...t}));ct.displayName=`Label`;var lt=J(`label`,ct),ut=_.Root,dt=d.forwardRef(({className:e,...t},n)=>(0,f.jsx)(_.List,{ref:n,className:D(`inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground`,e),...t}));dt.displayName=`TabsList`;var ft=d.forwardRef(({className:e,...t},n)=>(0,f.jsx)(_.Trigger,{ref:n,className:D(`inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm`,e),...t}));ft.displayName=`TabsTrigger`;var pt=d.forwardRef(({className:e,...t},n)=>(0,f.jsx)(_.Content,{ref:n,className:D(`mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2`,e),...t}));pt.displayName=`TabsContent`;var mt=v.Root,ht=v.Trigger,gt=v.Group,_t=v.Portal,vt=d.forwardRef(({className:e,sideOffset:t=4,...n},r)=>(0,f.jsx)(v.Portal,{children:(0,f.jsx)(v.Content,{ref:r,sideOffset:t,className:D(`z-popover min-w-32 overflow-hidden rounded-md border border-border bg-popover p-1 text-popover-foreground shadow-md`,e),...n})}));vt.displayName=`DropdownMenuContent`;var yt=d.forwardRef(({className:e,inset:t,...n},r)=>(0,f.jsx)(v.Item,{ref:r,className:D(`relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50`,t&&`pl-8`,e),...n}));yt.displayName=`DropdownMenuItem`;var bt=d.forwardRef(({className:e,children:t,checked:n,...r},i)=>(0,f.jsxs)(v.CheckboxItem,{ref:i,checked:n,className:D(`relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50`,e),...r,children:[(0,f.jsx)(`span`,{className:`absolute left-2 flex h-3.5 w-3.5 items-center justify-center`,children:(0,f.jsx)(v.ItemIndicator,{children:(0,f.jsx)(V,{className:`h-4 w-4`})})}),t]}));bt.displayName=`DropdownMenuCheckboxItem`;var xt=d.forwardRef(({className:e,inset:t,...n},r)=>(0,f.jsx)(v.Label,{ref:r,className:D(`px-2 py-1.5 text-sm font-semibold`,t&&`pl-8`,e),...n}));xt.displayName=`DropdownMenuLabel`;var St=d.forwardRef(({className:e,...t},n)=>(0,f.jsx)(v.Separator,{ref:n,className:D(`-mx-1 my-1 h-px bg-muted`,e),...t}));St.displayName=`DropdownMenuSeparator`;var Ct=d.forwardRef(({className:e,...t},n)=>(0,f.jsx)(`div`,{ref:n,className:D(`animate-pulse rounded-md bg-muted`,e),...t}));Ct.displayName=`Skeleton`;var $=J(`skeleton`,Ct);function wt(e){return typeof e==`string`?e:String(e)}function Tt(e){return Array.isArray(e)}function Et(e){let t={};if(e===void 0)return t;if(e.filters!==void 0)for(let[n,r]of Object.entries(e.filters))r!=null&&(Tt(r)?r.length>0&&(t[n]=r.map(wt)):t[n]=wt(r));return e.page!==void 0&&(t.page=String(e.page)),e.pageSize!==void 0&&(t.page_size=String(e.pageSize)),e.ordering!==void 0&&e.ordering!==``&&(t.ordering=e.ordering),e.search!==void 0&&e.search!==``&&(t.search=e.search),e.expand!==void 0&&e.expand.length>0&&(t.expand=e.expand.join(`,`)),t}function Dt(e){let t={};return e?.expand!==void 0&&e.expand.length>0&&(t.expand=e.expand.join(`,`)),t}function Ot(e){let t={};for(let n of Object.keys(e).sort()){let r=kt(e[n]);r!==void 0&&(t[n]=r)}return t}function kt(e){if(e!=null)return Array.isArray(e)?e.filter(e=>e!=null).map(e=>typeof e==`object`&&e?JSON.stringify(e):String(e)):typeof e==`object`?Ot(e):String(e)}function At(e){return`/${e.replace(/^\/+|\/+$/g,``)}/`}function jt(e,t){return`${At(e)}${encodeURIComponent(String(t))}/`}var Mt={schema(){return[`karni`,`$schema`]},resource(e){return[`karni`,e]},list(e,t){return[`karni`,e,`list`,Ot(Et(t))]},detail(e,t,n){let r=Dt(n);return Object.keys(r).length>0?[`karni`,e,`detail`,String(t),Ot(r)]:[`karni`,e,`detail`,String(t)]}},Nt=(0,d.createContext)(null),Pt={};function Ft(e){let{client:t,queryClient:n,primitives:r=Pt,children:i}=e,[a]=(0,d.useState)(()=>n??new y.QueryClient);return(0,f.jsx)(y.QueryClientProvider,{client:n??a,children:(0,f.jsx)(Nt.Provider,{value:t,children:(0,f.jsx)(_e,{value:r,children:i})})})}function It(){let e=(0,d.useContext)(Nt);if(e===null)throw Error(`useKarniClient must be used within <KarniProvider>. Wrap your app in <KarniProvider client={createKarniClient({ baseUrl })}>.`);return e}function Lt(e){if(typeof e!=`object`||!e)return;let t=e,n=t.authMode??t[`x-karni-auth-mode`];return n===`jwt`||n===`session`?n:void 0}function Rt(e){if(typeof e!=`object`||!e)return null;let t=e,{id:n,email:r}=t;if(typeof n!=`string`&&typeof n!=`number`||typeof r!=`string`)return null;let i=Array.isArray(t.roles)?t.roles.filter(e=>typeof e==`string`):[];return{...t,id:n,email:r,roles:i}}function zt(e){if(typeof document>`u`)return null;try{for(let t of document.cookie.split(`;`)){let n=t.trim(),r=n.indexOf(`=`);if(r!==-1&&n.slice(0,r)===e)return decodeURIComponent(n.slice(r+1))}}catch{}return null}function Bt(e){if(typeof e!=`object`||!e)return`a ${typeof e}`;let t=Object.keys(e);return t.length===0?`an empty object`:`an object with keys [${t.join(`, `)}]`}function Vt(e){if(typeof e!=`object`||!e)return null;let t=e;return t.requires_2fa===!0&&typeof t.ephemeral_token==`string`?{ephemeralToken:t.ephemeral_token}:null}var Ht=class{client;tokenStorage;modeOverride;csrfCookieName;csrfHeaderName;authBasePath;readCachedSchema;mode;accessToken=null;refreshPromise=null;initPromise=null;listeners=new Set;state;constructor(e){this.client=e.client,this.tokenStorage=e.tokenStorage,this.modeOverride=e.modeOverride,this.csrfCookieName=e.csrfCookieName??`csrftoken`,this.csrfHeaderName=e.csrfHeaderName??`X-CSRFToken`,this.authBasePath=(e.authBasePath??`/auth`).replace(/\/+$/,``),this.readCachedSchema=e.readCachedSchema,this.mode=e.modeOverride??null,this.state={status:`loading`,user:null,mode:this.mode},this.attach()}attach(){this.client.setAuthHooks({getAccessToken:()=>this.accessToken,onUnauthorized:()=>this.handleUnauthorized(),getHeaders:()=>this.csrfHeaders(),...this.mode===`session`?{credentials:`include`}:{}})}detach(){this.client.setAuthHooks({getAccessToken:void 0,onUnauthorized:void 0,getHeaders:void 0,credentials:void 0})}csrfHeaders(){if(this.mode!==`session`)return{};let e=zt(this.csrfCookieName);return e===null?{}:{[this.csrfHeaderName]:e}}async handleUnauthorized(){return await this.ensureInitialized(),this.mode===`jwt`?this.tokenStorage.get()!==null&&this.ensureRefresh():(this.state.status===`authenticated`&&this.setState(`anonymous`,null),!1)}subscribe=e=>(this.listeners.add(e),()=>{this.listeners.delete(e)});getSnapshot=()=>this.state;setState(e,t){this.state={status:e,user:t,mode:this.mode};for(let e of this.listeners)e()}ensureInitialized(){return this.initPromise??=this.initialize(),this.initPromise}async initialize(){try{if(this.mode=this.modeOverride??Lt(this.readCachedSchema?.())??await this.fetchSchemaAuthMode()??`jwt`,this.mode===`session`){this.client.setAuthHooks({credentials:`include`}),await this.ensureCsrfToken(),await this.syncUser();return}if(this.tokenStorage.get()===null){this.setState(`anonymous`,null);return}if(!await this.ensureRefresh())return;await this.syncUser()}catch{this.setState(`anonymous`,null)}}async fetchSchemaAuthMode(){try{return Lt(await this.client.request(this.client.schemaUrl,{skipAuthRefresh:!0}))}catch{return}}async syncUser(){try{let e=Rt(await this.client.request(`${this.authBasePath}/me/`,{skipAuthRefresh:!0}));e===null?this.setState(`anonymous`,null):this.setState(`authenticated`,e)}catch{this.setState(`anonymous`,null)}}async ensureCsrfToken(){let e=zt(this.csrfCookieName);if(e===null){try{await this.client.request(`${this.authBasePath}/csrf/`,{method:`GET`,skipAuthRefresh:!0})}catch{}e=zt(this.csrfCookieName)}return e}ensureRefresh(){return this.refreshPromise===null&&(this.refreshPromise=this.performRefresh().finally(()=>{this.refreshPromise=null})),this.refreshPromise}async performRefresh(){let e=this.tokenStorage.get();if(e===null)return this.accessToken=null,this.setState(`anonymous`,null),!1;this.accessToken=null;try{let t=await this.client.request(`${this.authBasePath}/refresh/`,{method:`POST`,body:{refresh:e},skipAuthRefresh:!0}),n=typeof t==`object`&&t?t:{},r=n.access;if(typeof r!=`string`||r===``)throw Error(`Karni auth: ${this.authBasePath}/refresh/ returned ${Bt(t)} instead of { access, refresh? }.`);let i=n.refresh;return typeof i==`string`&&i!==``&&this.tokenStorage.set(i),this.accessToken=r,!0}catch{return this.tokenStorage.clear(),this.accessToken=null,this.setState(`anonymous`,null),!1}}async login(e,t){await this.ensureInitialized();let n=`${this.authBasePath}/login/`;if(this.mode===`session`){await this.ensureCsrfToken();let r=await this.client.request(n,{method:`POST`,body:{email:e,password:t},skipAuthRefresh:!0}),i=Vt(r);if(i!==null)return{requires2fa:!0,ephemeralToken:i.ephemeralToken};let a=Rt(r)??await this.fetchMe(n);return this.setState(`authenticated`,a),{ok:!0,user:a}}let r=await this.client.request(n,{method:`POST`,body:{email:e,password:t},skipAuthRefresh:!0}),i=Vt(r);if(i!==null)return{requires2fa:!0,ephemeralToken:i.ephemeralToken};let a=typeof r==`object`&&r?r:{},{access:o,refresh:s}=a;if(typeof o!=`string`||typeof s!=`string`)throw Error(`Karni auth: unexpected response from POST ${n}. Expected { access, refresh } (JWT mode) or { requires_2fa, ephemeral_token }, got ${Bt(r)}. Check the backend's KARNI_AUTH_MODE and the AuthProvider "mode" prop.`);this.tokenStorage.set(s),this.accessToken=o;let c=Rt(a.user)??await this.fetchMe(n);return this.setState(`authenticated`,c),{ok:!0,user:c}}async fetchMe(e){let t=await this.client.request(`${this.authBasePath}/me/`,{skipAuthRefresh:!0}),n=Rt(t);if(n===null)throw Error(`Karni auth: POST ${e} succeeded but ${this.authBasePath}/me/ returned ${Bt(t)} instead of a user object with id and email.`);return n}async logout(){await this.ensureInitialized();try{if(this.mode===`session`)await this.ensureCsrfToken(),await this.client.request(`${this.authBasePath}/logout/`,{method:`POST`,skipAuthRefresh:!0});else{let e=this.tokenStorage.get();e!==null&&await this.client.request(`${this.authBasePath}/logout/`,{method:`POST`,body:{refresh:e},skipAuthRefresh:!0})}}catch{}this.accessToken=null,this.tokenStorage.clear(),this.setState(`anonymous`,null)}async adoptTokens(e,t){await this.ensureInitialized(),this.mode===`jwt`&&(typeof t==`string`&&t!==``&&this.tokenStorage.set(t),typeof e==`string`&&e!==``&&(this.accessToken=e)),await this.syncUser()}async refresh(){await this.ensureInitialized(),(this.mode!==`jwt`||await this.ensureRefresh())&&await this.syncUser()}};function Ut(e=`karni.refreshToken`){return{get(){try{return globalThis.localStorage.getItem(e)}catch{return null}},set(t){try{globalThis.localStorage.setItem(e,t)}catch{}},clear(){try{globalThis.localStorage.removeItem(e)}catch{}}}}function Wt(){let e=null;return{get:()=>e,set:t=>{e=t},clear:()=>{e=null}}}var Gt=(0,d.createContext)(null);function Kt({mode:e,tokenStorage:t,csrfCookieName:n,csrfHeaderName:r,authBasePath:i,children:a}){let o=It(),s=(0,y.useQueryClient)(),c=(0,d.useMemo)(()=>t??Ut(),[t]),l=(0,d.useMemo)(()=>new Ht({client:o,tokenStorage:c,...e===void 0?{}:{modeOverride:e},...n===void 0?{}:{csrfCookieName:n},...r===void 0?{}:{csrfHeaderName:r},...i===void 0?{}:{authBasePath:i},readCachedSchema:()=>s.getQueryData(Mt.schema())}),[o,s,c,e,n,r,i]);(0,d.useEffect)(()=>(l.attach(),l.ensureInitialized(),()=>{l.detach()}),[l]);let u=(0,d.useSyncExternalStore)(l.subscribe,l.getSnapshot,l.getSnapshot),p=u.user?.id??null,m=(0,d.useRef)(p);(0,d.useEffect)(()=>{m.current!==p&&(m.current=p,s.invalidateQueries({queryKey:Mt.schema()}))},[p,s]);let h=(0,d.useMemo)(()=>({user:u.user,roles:u.user?.roles??[],status:u.status,login:(e,t)=>l.login(e,t),logout:()=>l.logout(),refresh:()=>l.refresh(),adoptTokens:(e,t)=>l.adoptTokens(e,t)}),[l,u]);return(0,f.jsx)(Gt.Provider,{value:h,children:a})}function qt(){let e=(0,d.useContext)(Gt);if(e===null)throw Error(`useAuth must be used within an <AuthProvider> (itself inside <KarniProvider>). Wrap your tree: <KarniProvider client={...}><AuthProvider>...</AuthProvider></KarniProvider>.`);return e}function Jt(e,t,n){let r=It();return(0,y.useQuery)({...n,queryKey:Mt.list(e,t),queryFn:({signal:n})=>r.request(At(e),{query:Et(t),signal:n})})}function Yt(e){return typeof File<`u`&&e instanceof File}function Xt(e){return typeof Blob<`u`&&e instanceof Blob}function Zt(e){return Object.values(e).some(e=>Yt(e)||Array.isArray(e)&&e.some(e=>Yt(e)))}function Qt(e,t,n){n!=null&&(Yt(n)||Xt(n)?e.append(t,n):typeof n==`object`?e.append(t,JSON.stringify(n)):e.append(t,String(n)))}function $t(e){let t=new FormData;for(let[n,r]of Object.entries(e))if(r!=null){if(Array.isArray(r))for(let e of r)Qt(t,n,e);else Qt(t,n,r)}return t}function en(e){return Zt(e)?$t(e):e}function tn(e,t){let n=new Set;if(typeof e!=`object`||!e)return n;let r=e.resources;if(typeof r!=`object`||!r)return n;let i=r[t];if(typeof i!=`object`||!i)return n;let a=i.fields;if(!Array.isArray(a))return n;for(let e of a){if(typeof e!=`object`||!e)continue;let{name:t,kind:r}=e;typeof t==`string`&&r===`file`&&n.add(t)}return n}function nn(e){return typeof e==`string`||Array.isArray(e)&&e.every(e=>typeof e==`string`)}function rn(e,t){if(t.size===0)return e;let n={};for(let[r,i]of Object.entries(e))t.has(r)&&nn(i)||(n[r]=i);return n}function an(e,t){let n=It(),r=(0,y.useQueryClient)(),i=t?.invalidateKeys,a=(0,d.useCallback)(async()=>{await r.invalidateQueries({queryKey:Mt.resource(e)}),i!==void 0&&await Promise.all(i.map(e=>r.invalidateQueries({queryKey:e})))},[r,e,i]);return{create:(0,y.useMutation)({mutationFn:t=>n.request(At(e),{method:`POST`,body:en(t)}),onSuccess:()=>a()}),update:(0,y.useMutation)({mutationFn:({id:t,values:i})=>{let a=rn(i,tn(r.getQueryData(Mt.schema()),e));return n.request(jt(e,t),{method:`PATCH`,body:en(a)})},onSuccess:()=>a()}),remove:(0,y.useMutation)({mutationFn:async t=>{await n.request(jt(e,t),{method:`DELETE`})},onSuccess:()=>a()})}}function on(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function sn(e){let t=e.replace(/[_-]+/g,` `).trim();return t.length===0?e:t.charAt(0).toUpperCase()+t.slice(1)}var cn=`#/components/schemas/`;function ln(e,t){if(t.startsWith(cn))return e.components?.schemas?.[t.slice(21)]}function un(e,t,n=[]){if(t!==void 0){if(typeof t.$ref==`string`){if(n.includes(t.$ref))return{};let r=ln(e,t.$ref);if(r===void 0)return{};let i=un(e,r,[...n,t.$ref])??{},a={...t};return delete a.$ref,{...i,...a}}if(Array.isArray(t.allOf)&&t.allOf.length===1){let r=un(e,t.allOf[0],n)??{},i={...t};return delete i.allOf,{...r,...i}}return t}}function dn(e){return Array.isArray(e.type)?{type:e.type.filter(e=>e!==`null`)[0],nullable:e.type.includes(`null`)||e.nullable===!0}:{type:typeof e.type==`string`?e.type:void 0,nullable:e.nullable===!0}}function fn(e){let t=e[`x-karni-relation`];if(on(t)&&typeof t.resource==`string`&&t.resource.length>0)return{resource:t.resource,many:t.many===!0}}function pn(e){let{type:t}=dn(e);return t===`integer`||t===`number`?`integer`:e.format===`uuid`?`uuid`:`string`}function mn(e,t,n){let r=[],i=!1,a;for(let o of t){let t=un(e,o,n);if(t===void 0||!Array.isArray(t.enum))return;a===void 0&&t.description!==void 0&&r.length===0&&(a=t.description);for(let e of t.enum)e===null?i=!0:e!==``&&r.push(e)}return{values:r,nullable:i,description:a}}var hn=/^\* `(.+?)` - (.*)$/;function gn(e){if(e===void 0)return{};let t={},n=[];for(let r of e.split(`
2
+ `)){let e=hn.exec(r.trim());e!==null&&e[1]!==void 0&&e[2]!==void 0?t[e[1]]=e[2].trim():n.push(r)}let r=n.join(`
3
+ `).trim();return{...Object.keys(t).length>0?{labels:t}:{},...r===``?{}:{rest:r}}}function _n(e,t){let{labels:n,rest:r}=gn(t);n!==void 0&&(e.enumLabels=n),e.description=r}function vn(e){return e.type===void 0&&e.enum===void 0&&e.properties===void 0&&e.items===void 0&&e.oneOf===void 0&&e.anyOf===void 0&&e.allOf===void 0&&e.$ref===void 0}function yn(e,t){let n=un(e,t)??{},r=fn(n),{type:i,nullable:a}=dn(n),o={kind:`unknown`,nullable:a,format:n.format,description:n.description,title:n.title,default:n.default,readOnly:n.readOnly===!0,writeOnly:n.writeOnly===!0,maxLength:n.maxLength,min:n.minimum,max:n.maximum,relation:r,binary:!1},s=n.oneOf??n.anyOf;if(Array.isArray(s)){let t=mn(e,s,[]);return t===void 0||(o.kind=`enum`,o.enumValues=t.values,o.nullable=o.nullable||t.nullable,_n(o,n.description??t.description)),o}if(Array.isArray(n.enum))return o.kind=`enum`,o.nullable=o.nullable||n.enum.includes(null),o.enumValues=n.enum.filter(e=>e!==null&&e!==``),_n(o,n.description),o;if(r!==void 0&&!r.many)return o.kind=`relation`,o.relationValueType=pn(n),o;switch(i){case`string`:return n.format===`binary`?(o.kind=`file`,o.binary=!0):o.kind=n.format===`date`?`date`:n.format===`date-time`?`datetime`:n.format===void 0&&n.maxLength===void 0?`text`:`string`,o;case`integer`:return o.kind=`integer`,o;case`number`:return o.kind=`number`,o;case`boolean`:return o.kind=`boolean`,o;case`array`:return r===void 0?o.kind=`array`:(o.kind=`relation`,o.relationValueType=pn(un(e,n.items)??{})),o;case`object`:return o.kind=`json`,o;default:return r===void 0?vn(n)&&(o.kind=`json`):(o.kind=`relation`,o.relationValueType=pn(n)),o}}function bn(e,t,n,r,i,a){let o;o=n?.binary===!0?`file`:n!==void 0&&n.kind!==`unknown`?n.kind:t!==void 0&&t.kind!==`unknown`?t.kind:`unknown`;let s=n?.relation??t?.relation,c=n?.title??t?.title,l={name:e,label:c!==void 0&&c.length>0?c:sn(e),kind:o,required:r.has(e),readOnly:!i||t?.readOnly===!0||n?.readOnly===!0||i&&t!==void 0&&n===void 0,writeOnly:n?.writeOnly===!0||t?.writeOnly===!0||t===void 0&&n!==void 0,nullable:n===void 0?t?.nullable??!1:n.nullable,order:a},u=n?.enumValues??t?.enumValues,d=n?.default??t?.default;d!==void 0&&(l.default=d),u!==void 0&&(l.enumValues=u);let f=n?.enumLabels??t?.enumLabels;f!==void 0&&(l.enumLabels=f);let p=n?.maxLength??t?.maxLength;p!==void 0&&(l.maxLength=p);let m=n?.min??t?.min;m!==void 0&&(l.min=m);let h=n?.max??t?.max;h!==void 0&&(l.max=h);let g=n?.format??t?.format;g!==void 0&&(l.format=g);let _=t?.description??n?.description;if(_!==void 0&&(l.description=_),s!==void 0){l.relation=s;let e=n?.relationValueType??t?.relationValueType;e!==void 0&&(l.relationValueType=e)}return l}function xn(e,t,n,r){let i=[],a;for(let t of r.parameters??[])if(on(t)&&t.in===`query`&&typeof t.name==`string`&&(i.push(t.name),t.name===`expand`)){let n=un(e,t.schema),r=un(e,n?.items),i=n?.enum??r?.enum;Array.isArray(i)&&(a=i.filter(e=>typeof e==`string`))}let o={path:t,method:n,queryParams:i,hasSearch:i.includes(`search`)};typeof r.operationId==`string`&&(o.operationId=r.operationId),a!==void 0&&(o.expandEnum=a);let s=r[`x-karni-access`];return on(s)&&(o.access=s),o}function Sn(e,t){let n=(t.responses?.[`200`]??t.responses?.[`201`]??Object.values(t.responses??{})[0])?.content?.[`application/json`],r=un(e,n?.schema);if(r===void 0)return;let i=un(e,r.properties?.results);return i!==void 0&&i.type===`array`?un(e,i.items):r.type===`array`?un(e,r.items):r}function Cn(e,t){let n=t.requestBody?.content;if(on(n))return un(e,(n[`application/json`]??n[`multipart/form-data`]??Object.values(n)[0])?.schema)}var wn=[`get`,`post`,`put`,`patch`,`delete`];function Tn(e){let t=on(e)?e:{},n=on(t.paths)?t.paths:{},r={},i=t[`x-karni-auth-mode`],a=i===`jwt`||i===`session`?i:void 0,o=[];for(let[e,t]of Object.entries(n)){if(!on(t))continue;let n=t.get;on(n)&&typeof n[`x-karni-resource`]==`string`&&o.push({resource:n[`x-karni-resource`],path:e,item:t})}for(let{resource:e,path:i,item:a}of o){let o=a.get;if(!on(o))continue;let s=Object.entries(n).find(([e])=>{if(!e.startsWith(i))return!1;let t=e.slice(i.length);return/^\{[^/{}]+\}\/?$/.test(t)}),c=s?.[0],l=s!==void 0&&on(s[1])?s[1]:void 0,u={list:xn(t,i,`get`,o)},d=on(a.post)?a.post:void 0;d!==void 0&&(u.create=xn(t,i,`post`,d));let f=n[`${i}export/`],p=on(f)&&on(f.get)?f.get:void 0;p!==void 0&&(u.export=xn(t,`${i}export/`,`get`,p));let m=n[`${i}import/`],h=on(m)&&on(m.post)?m.post:void 0;if(h!==void 0&&(u.import=xn(t,`${i}import/`,`post`,h)),c!==void 0&&l!==void 0)for(let e of wn){let n=l[e];on(n)&&(e===`get`?u.detail=xn(t,c,`get`,n):e===`patch`?u.update=xn(t,c,`patch`,n):e===`put`&&u.update===void 0?u.update=xn(t,c,`put`,n):e===`delete`&&(u.remove=xn(t,c,`delete`,n)))}let g=Sn(t,o),_=d===void 0?void 0:Cn(t,d),v=_!==void 0,y=on(g?.properties)?g.properties:{},b=on(_?.properties)?_.properties:{},x=new Set(Array.isArray(_?.required)?_.required:[]),S=[],C=0;for(let[e,n]of Object.entries(y)){let r=yn(t,n),i=b[e],a=i===void 0?void 0:yn(t,i);S.push(bn(e,r,a,x,v,C)),C+=1}for(let[e,n]of Object.entries(b)){if(e in y)continue;let r=yn(t,n);S.push(bn(e,void 0,r,x,v,C)),C+=1}r[e]={resource:e,operations:u,fields:S}}let s={resources:r};return a!==void 0&&(s.authMode=a),s}var En=[`karni`,`$schema`];function Dn(){let e=It();return(0,y.useQuery)({queryKey:En,staleTime:1/0,queryFn:async()=>Tn(await e.request(e.schemaUrl))})}function On(e){let t=Dn();if(t.data!==void 0){let n=t.data.resources[e];if(n===void 0){let n=Object.keys(t.data.resources).sort();throw Error(`Unknown resource "${e}". Known resources: ${n.length>0?n.join(`, `):`none (does the schema expose x-karni-resource?)`}.`)}return{data:n,isLoading:!1,error:t.error}}return{data:void 0,isLoading:t.isPending,error:t.error,refetch:()=>void t.refetch(),isFetching:t.isFetching}}var kn=Object.freeze([`id`,`created_at`,`updated_at`,`created_by`,`updated_by`]);function An(e){return e.readOnly&&kn.includes(e.name)}function jn(e){let t=[],n=[];for(let r of e)(An(r)?n:t).push(r);return n.sort((e,t)=>kn.indexOf(e.name)-kn.indexOf(t.name)),{domain:t,audit:n}}var Mn=[`name`,`title`,`label`,`email`,`str`];function Nn(e){for(let t of Mn){let n=e[t];if(typeof n==`string`&&n.trim().length>0)return n}let t=e.id;return t==null?``:String(t)}function Pn(e){if(e.length!==0)return e.map(e=>e.desc?`-${e.id}`:e.id).join(`,`)}function Fn(e){return e.split(`,`).map(e=>e.trim()).filter(e=>e.length>0&&e!==`-`).map(e=>e.startsWith(`-`)?{id:e.slice(1),desc:!0}:{id:e,desc:!1})}function In(e){if(typeof e!=`object`||!e||!(`status`in e))return;let t=e.status;return typeof t==`number`?t:void 0}function Ln(e){return In(e)===404}function Rn(e){return(t,n)=>{let r=In(n);return r!==void 0&&r>=400&&r<500&&r!==408&&r!==429?!1:e===void 0?t<3:typeof e==`boolean`?e:typeof e==`number`?t<e:e(t,n)}}function zn(e){return e.replace(/[_-]+/g,` `).trim().toLowerCase()}function Bn(e){return/[^aeiou]ies$/.test(e)?`${e.slice(0,-3)}y`:/(?:ss|x|z|ch|sh)es$/.test(e)?e.slice(0,-2):/[^s]s$/.test(e)?e.slice(0,-1):e}function Vn(e){return e.charAt(0).toUpperCase()+e.slice(1)}function Hn(e,t){return e===void 0||e<=0||t<=0?1:Math.max(1,Math.ceil(e/t))}function Un(e){return typeof e==`object`&&e&&!Array.isArray(e)?e:{}}function Wn(e,t){let n=t?.[String(e)];if(n!==void 0)return n;if(typeof e==`number`)return String(e);if(/^[A-Za-z0-9_ ]+$/.test(e)&&(e===e.toUpperCase()||e===e.toLowerCase())){let t=e.toLowerCase().replace(/_+/g,` `).trim();return t.length===0?e:t.charAt(0).toUpperCase()+t.slice(1)}return e}var Gn=`__`;function Kn(e,t){return e==null?!1:typeof e==`object`&&!Array.isArray(e)?Kn(Un(e).id,t):String(e)===String(t)}function qn(e,t,n){if(t.status!==`authenticated`||t.user===null)return t.status!==`anonymous`&&void 0;if(n===void 0||e.includes(Gn))return;let r=Un(n),i=e===`pk`?`id`:e;if(!(i in r))return;let a=r[i],o=t.user.id;return Array.isArray(a)?a.some(e=>Kn(e,o)):Kn(a,o)}function Jn(e,t,n,r){let i=!1;for(let a of e){let e=Yn(Un(a),t,n);if(e===r)return r;e===void 0&&(i=!0)}return i?void 0:!r}function Yn(e,t,n){if(e===void 0)return;if(e.public===!0)return!0;if(`deny`in e)return!1;if(Array.isArray(e.any))return Jn(e.any,t,n,!0);if(Array.isArray(e.all))return Jn(e.all,t,n,!1);if(t===null||t.status===`loading`)return;if(e.authenticated===!0)return t.status===`authenticated`;let r=e.role;if(Array.isArray(r)){if(t.status!==`authenticated`||t.user===null)return!1;let e=new Set(t.user.roles);return r.some(t=>typeof t==`string`&&e.has(t))}let i=e.owned;if(typeof i==`string`)return qn(i,t,n)}var Xn=`__select__`,Zn=`__actions__`;function Qn(e){return e===`__select__`||e===`__actions__`}function $n(e){let{rowLabel:t,resourceLabel:n}=e;return{id:Xn,enableSorting:!1,enableHiding:!1,header:({table:e})=>(0,f.jsx)(at,{"aria-label":`Select all ${n} on this page`,checked:e.getIsAllPageRowsSelected()?!0:e.getIsSomePageRowsSelected()?`indeterminate`:!1,onCheckedChange:t=>e.toggleAllPageRowsSelected(t===!0)}),cell:({row:e})=>(0,f.jsx)(`div`,{className:`flex items-center`,onClick:e=>e.stopPropagation(),children:(0,f.jsx)(at,{"aria-label":`Select ${t(e.original)}`,checked:e.getIsSelected(),onCheckedChange:t=>e.toggleSelected(t===!0)})})}}function er(e){let{row:t,rowActions:n,onEdit:r,canEdit:i,onDelete:a,canDelete:o,buttonClassName:s}=e;return(0,f.jsxs)(f.Fragment,{children:[r!==void 0&&i(t)&&(0,f.jsx)(Z,{variant:`ghost`,size:`sm`,className:s,onClick:()=>r(t),children:`Edit`}),n?.(t),a!==void 0&&o(t)&&(0,f.jsx)(Z,{variant:`ghost`,size:`sm`,className:D(`text-destructive hover:text-destructive`,s),onClick:e=>a(t,e.currentTarget),children:`Delete`})]})}function tr(e){return{id:Zn,enableSorting:!1,enableHiding:!1,header:()=>(0,f.jsx)(`span`,{className:`sr-only`,children:`Actions`}),cell:({row:t})=>(0,f.jsx)(`div`,{className:`flex items-center justify-end gap-1`,onClick:e=>e.stopPropagation(),children:(0,f.jsx)(er,{...e,row:t.original})})}}function nr(e,t){let n=e.getVisibleCells().find(e=>e.column.id===t);return n===void 0?null:(0,b.flexRender)(n.column.columnDef.cell,n.getContext())}function rr(e){let{table:t,caption:n,resourceLabel:r,density:i,Card:a,rowLabel:o,useRowLabelAsTitle:s,onRowClick:c,failures:l,columnLabel:u,ordering:d,onOrderingChange:p,busy:m,dimmed:h,listRef:g}=e,_=t.getVisibleLeafColumns(),v=_.some(e=>e.id===Xn),y=_.some(e=>e.id===Zn),x=_.filter(e=>e.id!==`__select__`&&e.id!==`__actions__`),[S,...C]=x,w=x.filter(e=>e.getCanSort()).flatMap(e=>[{value:e.id,label:`${u(e.id)}, ascending`},{value:`-${e.id}`,label:`${u(e.id)}, descending`}]),T=w.some(e=>e.value===d)?d:null,E=new Map(t.getFlatHeaders().map(e=>[e.column.id,(0,b.flexRender)(e.column.columnDef.header,e.getContext())]));return(0,f.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(v||w.length>0)&&(0,f.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[v?(0,f.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-foreground`,children:[(0,f.jsx)(at,{checked:t.getIsAllPageRowsSelected()?!0:t.getIsSomePageRowsSelected()?`indeterminate`:!1,onCheckedChange:e=>t.toggleAllPageRowsSelected(e===!0)}),`Select all `,r,` on this page`]}):(0,f.jsx)(`span`,{}),w.length>0&&(0,f.jsx)(rt,{"aria-label":`Sort by`,className:`h-9 w-auto min-w-40`,value:T,placeholder:`Sort by`,clearable:!0,clearLabel:`Sort: default order`,options:w,onValueChange:e=>p(e??``)})]}),(0,f.jsx)(`ul`,{ref:g,"aria-label":n,"aria-busy":m||void 0,tabIndex:-1,className:D(`flex flex-col gap-3 rounded-md focus:outline-none focus-visible:ring-2 focus-visible:ring-ring`,h&&`cursor-progress`),children:t.getRowModel().rows.map(e=>{let t=s||S===void 0?o(e.original):nr(e,S.id);return(0,f.jsx)(a,{row:e.original,title:t,fields:C.map(t=>({id:t.id,label:E.get(t.id)??u(t.id),value:nr(e,t.id)})),selection:v?(0,f.jsx)(at,{"aria-label":`Select ${o(e.original)}`,checked:e.getIsSelected(),onCheckedChange:t=>e.toggleSelected(t===!0)}):void 0,actions:y?nr(e,Zn):void 0,onOpen:c===void 0?void 0:()=>c(e.original),selected:e.getIsSelected(),failure:l[e.id],density:i},e.id)})})]})}j(`modal`,`Modal`);function ir(e){return(0,f.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,focusable:!1,...e,children:[(0,f.jsx)(`line`,{x1:`18`,y1:`6`,x2:`6`,y2:`18`}),(0,f.jsx)(`line`,{x1:`6`,y1:`6`,x2:`18`,y2:`18`})]})}var ar=x.Close,or=d.forwardRef(({className:e,...t},n)=>(0,f.jsx)(x.Title,{ref:n,className:D(`text-lg font-semibold leading-none tracking-tight`,e),...t}));or.displayName=`ModalTitle`;var sr=d.forwardRef(({className:e,...t},n)=>(0,f.jsx)(x.Description,{ref:n,className:D(`text-sm text-muted-foreground`,e),...t}));sr.displayName=`ModalDescription`;function cr({title:e,description:t}){return(0,f.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,f.jsx)(or,{children:e}),t!=null&&(0,f.jsx)(sr,{children:t})]})}function lr({children:e}){return(0,f.jsx)(`div`,{className:`flex flex-col-reverse gap-2 sm:flex-row sm:justify-end`,children:e})}function ur({label:e}){return(0,f.jsxs)(x.Close,{className:`absolute right-4 top-4 rounded-sm text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:pointer-events-none`,children:[(0,f.jsx)(ir,{className:`h-4 w-4`}),(0,f.jsx)(`span`,{className:`sr-only`,children:e})]})}var dr={Header:cr,Footer:lr,CloseButton:ur};function fr({title:e,description:t,children:n,footer:r,trigger:i,open:a,defaultOpen:o,onOpenChange:s,hideCloseButton:c=!1,slots:l,className:u,contentProps:d}){let{Header:p,Footer:m,CloseButton:h}={...dr,...l},g=t==null&&d?.[`aria-describedby`]===void 0?{"aria-describedby":void 0}:{};return(0,f.jsxs)(x.Root,{open:a,defaultOpen:o,onOpenChange:s,children:[i!=null&&(0,f.jsx)(x.Trigger,{asChild:!0,children:i}),(0,f.jsxs)(x.Portal,{children:[(0,f.jsx)(x.Overlay,{className:`fixed inset-0 z-modal bg-overlay`}),(0,f.jsxs)(x.Content,{...d,...g,className:D(`fixed inset-x-4 top-1/2 z-modal mx-auto grid max-h-full max-w-128 -translate-y-1/2 gap-4 overflow-y-auto rounded-lg border border-border bg-background p-6 text-foreground shadow-lg`,u),children:[(0,f.jsx)(p,{title:e,description:t??void 0}),n,r!=null&&(0,f.jsx)(m,{children:r}),!c&&(0,f.jsx)(h,{label:`Close`})]})]})]})}function pr(e){let{open:t,title:n,description:r,confirmLabel:i,pendingLabel:a,destructive:o=!1,pending:s,error:c,errorContext:l,onConfirm:u,onCancel:d,returnFocus:p}=e,m=c!=null,h=!m||le(c,l).retryable;return(0,f.jsx)(fr,{open:t,onOpenChange:e=>{!e&&!s&&d()},title:n,description:r,contentProps:{onCloseAutoFocus:e=>{e.preventDefault(),p()?.focus()}},footer:(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(ar,{asChild:!0,children:(0,f.jsx)(Z,{variant:`outline`,disabled:s,children:`Cancel`})}),h&&(0,f.jsx)(Ce,{variant:o?`destructive`:`default`,pending:s,pendingLabel:a,onClick:u,children:m?`Try again`:i})]}),children:m&&(0,f.jsx)(Te,{variant:`inline`,error:c,context:l})})}var mr=new Set([`json`,`file`,`unknown`]),hr=new Set([`relation`,`json`,`file`,`array`,`unknown`]);function gr({value:e}){return e?(0,f.jsxs)(`span`,{className:`inline-flex items-center text-foreground`,children:[(0,f.jsx)(V,{className:`h-4 w-4`}),(0,f.jsx)(`span`,{className:`sr-only`,children:`Yes`})]}):(0,f.jsxs)(`span`,{className:`inline-flex items-center text-muted-foreground`,children:[(0,f.jsx)(`span`,{"aria-hidden":`true`,children:`–`}),(0,f.jsx)(`span`,{className:`sr-only`,children:`No`})]})}function _r({value:e}){return(0,f.jsx)(`code`,{className:`rounded bg-muted px-1 py-0.5 text-xs`,children:String(e)})}function vr(e,t){return e==null?(0,f.jsx)(Be,{}):typeof e==`object`&&!Array.isArray(e)?t(Un(e)):(0,f.jsx)(_r,{value:e})}function yr({value:e,label:t}){return e==null?(0,f.jsx)(Be,{}):Array.isArray(e)?e.length===0?(0,f.jsx)(Be,{}):(0,f.jsx)(`span`,{className:`inline-flex flex-wrap items-center gap-x-2 gap-y-1`,children:e.map((e,n)=>(0,f.jsx)(d.Fragment,{children:vr(e,t)},n))}):(0,f.jsx)(f.Fragment,{children:vr(e,t)})}function br(e,t){let n=new Date(String(e));return Number.isNaN(n.getTime())?String(e):t?n.toLocaleString():n.toLocaleDateString()}function xr({value:e}){if(typeof e==`string`&&e.length>0){let t=e.split(`/`).filter(Boolean).pop()??e;return(0,f.jsx)(`a`,{href:e,target:`_blank`,rel:`noreferrer`,className:`text-primary underline underline-offset-4`,onClick:e=>e.stopPropagation(),children:t})}return typeof File<`u`&&e instanceof File?(0,f.jsx)(f.Fragment,{children:e.name}):(0,f.jsx)(Be,{})}function Sr({value:e}){let t;try{t=JSON.stringify(e)??String(e)}catch{t=String(e)}let n=t.length>80?`${t.slice(0,80)}…`:t;return(0,f.jsx)(`code`,{className:`rounded bg-muted px-1 py-0.5 text-xs`,title:t,children:n})}function Cr(e,t,n){if(t==null||t===``)return(0,f.jsx)(Be,{});switch(e.kind){case`boolean`:return(0,f.jsx)(gr,{value:t===!0});case`date`:return br(t,!1);case`datetime`:return br(t,!0);case`enum`:return typeof t==`string`||typeof t==`number`?Wn(t,e.enumLabels):String(t);case`relation`:return(0,f.jsx)(yr,{value:t,label:n??Nn});case`number`:case`integer`:return(0,f.jsx)(`span`,{className:`tabular-nums`,children:typeof t==`number`?t.toLocaleString():String(t)});case`file`:return(0,f.jsx)(xr,{value:t});case`json`:return(0,f.jsx)(Sr,{value:t});case`array`:return Array.isArray(t)?t.map(e=>String(e)).join(`, `):String(t);case`text`:return(0,f.jsx)(`span`,{className:`block max-w-80 truncate`,title:String(t),children:String(t)});default:return String(t)}}function wr(e){return typeof e==`string`?e:()=>e}function Tr(e,t,n){let r=t?.cell;return{id:e.name,accessorFn:t=>Un(t)[e.name],header:wr(t?.header??e.label),cell:r===void 0?t=>Cr(e,t.getValue(),n):e=>r(e.row.original),enableSorting:t?.sortable??!hr.has(e.kind)}}function Er(e){let t=new Map((e.columns??[]).map(e=>[e.field,e])),n=[],{domain:r,audit:i}=jn(e.fields);for(let a of[...r,...i]){let r=t.get(a.name);t.delete(a.name),r?.hidden!==!0&&(r===void 0&&(a.writeOnly||mr.has(a.kind)||e.showAuditFields!==!0&&An(a))||n.push(Tr(a,r,e.getRowLabel)))}for(let[e,r]of t){if(r.hidden===!0)continue;let t=r.cell;n.push({id:e,accessorFn:t=>Un(t)[e],header:wr(r.header??sn(e)),cell:t===void 0?e=>{let t=e.getValue();return t==null?(0,f.jsx)(Be,{}):String(t)}:e=>t(e.row.original),enableSorting:r.sortable??!1})}return n}function Dr(e){return[...Mt.resource(e),`import`,`describe`]}function Or(e,t){return[...Mt.resource(e),`import`,`job`,t]}function kr(e,t=``){return`${At(e)}import/${t}`}var Ar=new Set([`previewing`,`committing`]);function jr(e){return e!==void 0&&Ar.has(e.status)}function Mr(e,t){let n=e.headers.get(`content-disposition`)??``;return/filename="?([^";]+)"?/i.exec(n)?.[1]??t}async function Nr(e,t,n,r=`csv`){let i={...Et(n),format:r};delete i.page,delete i.page_size;let a=await e.requestRaw(`${At(t)}export/`,{query:i}),o=await a.blob(),s=Mr(a,`${t}.${r}`);return Pr(o,s),s}function Pr(e,t){if(typeof document>`u`||typeof URL.createObjectURL!=`function`)return;let n=URL.createObjectURL(e),r=document.createElement(`a`);r.href=n,r.download=t,document.body.appendChild(r),r.click(),r.remove(),URL.revokeObjectURL(n)}async function Fr(e,t,n=`xlsx`){let r=await e.requestRaw(kr(t,`template/`),{query:{format:n}}),i=await r.blob(),a=Mr(r,`${t}-template.${n}`);return Pr(i,a),a}function Ir(e,t){let n=It();return(0,y.useQuery)({...t,queryKey:Dr(e),queryFn:({signal:t})=>n.request(kr(e),{signal:t})})}function Lr(e,t,n){let r=It(),i=n?.pollMs??1500;return(0,y.useQuery)({queryKey:Or(e,t??``),enabled:t!==void 0,queryFn:({signal:n})=>r.request(kr(e,`${encodeURIComponent(t??``)}/`),{signal:n}),refetchInterval:e=>jr(e.state.data)?i:!1})}function Rr(e){let t=It(),n=(0,y.useQueryClient)(),r=t=>(n.setQueryData(Or(e,t.id),t),t);return{upload:(0,y.useMutation)({mutationFn:async({file:n,mapping:i})=>{let a=new FormData;return a.append(`file`,n),i!==void 0&&a.append(`mapping`,JSON.stringify(i)),r(await t.request(kr(e),{method:`POST`,body:a}))}}),preview:(0,y.useMutation)({mutationFn:async({jobId:n,mapping:i})=>r(await t.request(kr(e,`${encodeURIComponent(n)}/preview/`),{method:`POST`,body:{mapping:i}})),onSuccess:()=>{n.invalidateQueries({queryKey:Dr(e)})}}),commit:(0,y.useMutation)({mutationFn:async n=>r(await t.request(kr(e,`${encodeURIComponent(n)}/commit/`),{method:`POST`,body:{}})),onSuccess:t=>{t.status===`done`&&n.invalidateQueries({queryKey:Mt.resource(e)})}})}}function zr(e){if(e instanceof Error){let t=e.data;if(typeof t==`object`&&t&&`detail`in t){let e=t.detail;if(typeof e==`string`)return e}return e.message}return`The export failed.`}function Br({resource:e,params:t,formats:n}){let r=It(),[i,a]=d.useState(null),[o,s]=d.useState(null),c=n=>{a(n),s(null),Nr(r,e,t,n).catch(e=>s(zr(e))).finally(()=>a(null))};return(0,f.jsxs)(`div`,{className:`flex items-center gap-2`,"data-testid":`resource-table-export`,children:[n.map(e=>(0,f.jsx)(Z,{type:`button`,variant:`outline`,size:`sm`,disabled:i!==null,onClick:()=>c(e),"aria-label":`Export as ${e.toUpperCase()}`,children:i===e?`Exporting…`:`Export ${e.toUpperCase()}`},e)),o!==null&&(0,f.jsx)(`span`,{role:`alert`,className:`text-sm text-destructive`,children:o})]})}function Vr(e){return/ies$/i.test(e)&&e.length>3?`${e.slice(0,-3)}y`:/(?:ss|sh|ch|x|z)es$/i.test(e)?e.slice(0,-2):/ss$/i.test(e)?e:/s$/i.test(e)?e.slice(0,-1):e}function Hr(e,t){let n=(t?.plural??e.replace(/[_-]+/g,` `).trim()).toLowerCase(),r=n.split(` `),i=r.pop()??n;return{singular:t?.singular??[...r,Vr(i)].join(` `),plural:n}}function Ur({label:e,selected:t}){return(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`span`,{className:`truncate`,children:e}),t?(0,f.jsx)(V,{className:`h-4 w-4 shrink-0`}):null]})}function Wr(e){return(0,f.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,focusable:!1,...e,children:[(0,f.jsx)(`line`,{x1:`18`,y1:`6`,x2:`6`,y2:`18`}),(0,f.jsx)(`line`,{x1:`6`,y1:`6`,x2:`18`,y2:`18`})]})}function Gr({label:e,state:t,onRemove:n,removeLabel:r}){return t===`loading`?(0,f.jsx)($,{className:`h-5 w-20 rounded-sm`}):(0,f.jsxs)(`span`,{className:D(`inline-flex max-w-full items-center gap-1 rounded-sm px-1.5 py-0.5 text-xs`,t===`failed`?`border border-destructive-border bg-destructive-subtle text-foreground`:`bg-secondary text-secondary-foreground`),children:[t===`failed`?(0,f.jsx)(U,{className:`h-3 w-3 shrink-0 text-destructive`}):null,(0,f.jsx)(`span`,{className:`truncate`,children:e}),n===void 0?null:(0,f.jsx)(`button`,{type:`button`,"aria-label":r,className:`rounded-sm opacity-70 hover:opacity-100 focus-visible:opacity-100 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`,onClick:e=>{e.stopPropagation(),n()},onKeyDown:e=>{(e.key===`Backspace`||e.key===`Delete`)&&(e.preventDefault(),e.stopPropagation(),n())},children:(0,f.jsx)(Wr,{className:`h-3 w-3`})})]})}var Kr=[`w-3/4`,`w-1/2`,`w-2/3`,`w-3/5`,`w-1/2`];function qr({rows:e}){return(0,f.jsx)(`div`,{"aria-hidden":`true`,children:Array.from({length:e},(e,t)=>(0,f.jsx)(`div`,{className:`flex h-8 items-center px-2`,children:(0,f.jsx)($,{className:D(`h-3.5`,Kr[t%Kr.length])})},t))})}function Jr({reason:e,search:t,names:n,loaded:r}){return e===`no-match`?`No ${n.plural} match “${t}”`:e===`no-loaded-match`?`None of the ${r.toLocaleString()} loaded ${n.plural} match “${t}”`:`No ${n.plural} yet`}function Yr(e){return(0,f.jsx)(`p`,{className:`px-2 py-6 text-center text-sm text-muted-foreground`,children:Jr(e)})}function Xr(e){return(0,f.jsx)(Te,{variant:`inline`,className:`px-2 py-3`,...e})}var Zr={Option:Ur,Chip:Gr,Loading:qr,Empty:Yr,Error:Xr};function Qr(e,t){let[n,r]=d.useState(e);return d.useEffect(()=>{if(t<=0){r(e);return}let n=setTimeout(()=>r(e),t);return()=>clearTimeout(n)},[e,t]),n}function $r(e){let t=new URL(e,`http://karni.invalid`),n={};for(let e of new Set(t.searchParams.keys())){let r=t.searchParams.getAll(e);n[e]=r.length===1?r[0]??``:r}return n}function ei(e){if(Array.isArray(e))return{count:e.length,next:null,results:e};let t=e??{};return{count:typeof t.count==`number`?t.count:void 0,next:typeof t.next==`string`&&t.next!==``?t.next:null,results:Array.isArray(t.results)?t.results:[]}}function ti({resource:e,search:t,filter:n,pageSize:r,enabled:i}){let a=It(),o={page:1};return r!==void 0&&(o.pageSize=r),t!==``&&(o.search=t),n!==void 0&&(o.filters=n),(0,y.useInfiniteQuery)({queryKey:[...Mt.list(e,o),`options`],queryFn:async({pageParam:t,signal:n})=>ei(await a.request(At(e),{query:t??Et(o),signal:n})),initialPageParam:null,getNextPageParam:e=>e.next===null?void 0:$r(e.next),enabled:i,placeholderData:y.keepPreviousData})}var ni=new Set;function ri(e,t,n){let r=It(),{idsFilter:i,enabled:a}=n,o=t.map(String),s=i!==void 0,c=Jt(e,{filters:{[i??`id__in`]:o.join(`,`)},pageSize:Math.max(o.length,1)},{enabled:a&&s&&o.length>0,retry:!1}),l=(0,y.useQueries)({queries:(s?[]:o).map(t=>({queryKey:Mt.detail(e,t),queryFn:({signal:n})=>r.request(jt(e,t),{signal:n}),enabled:a,retry:!1}))}),u={};if(o.length===0)return{rows:u,failed:ni,loading:ni};let d=new Set,f=new Set;if(s){let e=c.data?.results;if(e!==void 0){for(let t of e)u[String(t.id)]=t;for(let e of o)e in u||d.add(e)}else if(c.error!=null)for(let e of o)d.add(e);else for(let e of o)f.add(e)}else o.forEach((e,t)=>{let n=l[t];n?.data===void 0?n?.error==null?f.add(e):d.add(e):u[e]=n.data});return{rows:u,failed:d,loading:f}}j(`async-select`,`ResourceSelect`);var ii=100,ai=6,oi=32,si=256,ci=5;function li(e){let t=e.id;return typeof t==`string`||typeof t==`number`?t:String(t)}function ui(e){let t=String(e);return t.length>12?`${t.slice(0,8)}…`:t}function di(e){return e.charAt(0).toUpperCase()+e.slice(1)}var fi=d.forwardRef(function(e,t){let{resource:n,value:r,onChange:i,multiple:a=!1,disabled:o=!1,placeholder:s,getOptionLabel:c,filter:l,id:u,className:p,pageSize:m,clearable:h=!0,searchDebounceMs:g=300,onBlur:_,slots:v,searchable:y,idsFilter:b,resourceLabel:x}=e,C={...Zr,...v},w=Hr(n,x),T=d.useId(),E=u??T,ee=`${E}-listbox`,O=e=>`${ee}-option-${e}`,k=Dn(),A=k.data?.resources[n]?.operations.list,j=y??(A===void 0||A.hasSearch===!0),te=b===!1?void 0:b??(A?.queryParams.includes(`id__in`)===!0?`id__in`:void 0),[M,N]=d.useState(!1),[P,F]=d.useState(``),[I,L]=d.useState(0),[ne,re]=d.useState({}),[ie,R]=d.useState(0),[ae,oe]=d.useState(oi),[z,se]=d.useState(si),ce=d.useRef(null),ue=d.useRef(null),B=d.useRef(null),V=d.useRef(null),H=d.useRef(!1),fe=d.useCallback(e=>{V.current=e,typeof t==`function`?t(e):t!==null&&(t.current=e)},[t]),W=P.trim(),pe=Qr(W,g),he=j?pe:``,G=ti({resource:n,search:he,filter:l,pageSize:m,enabled:M&&!o}),ge=d.useMemo(()=>{let e=new Set,t=[];for(let n of G.data?.pages??[])for(let r of n.results){let n=String(li(r));e.has(n)||(e.add(n),t.push(r))}return t},[G.data]),K=G.data?.pages[0]?.count,_e=G.hasNextPage;d.useEffect(()=>{ge.length!==0&&re(e=>{let t=!1,n={...e};for(let e of ge){let r=String(li(e));r in n||(n[r]=e,t=!0)}return t?n:e})},[ge]);let q=d.useCallback(e=>c===void 0?Nn(e):c(e),[c]),J=d.useCallback(e=>{let t=q(e);return typeof t==`string`?t:typeof t==`number`?String(t):Nn(e)},[q]),Y=d.useMemo(()=>{if(j||W===``)return ge;let e=W.toLowerCase();return ge.filter(t=>J(t).toLowerCase().includes(e))},[j,W,ge,J]),X=Y.length,ve=d.useMemo(()=>r==null?[]:Array.isArray(r)?r:[r],[r]),Z=ve.map(String).join(`\0`),ye=d.useRef(ne);ye.current=ne;let be=ri(n,d.useMemo(()=>ve.filter(e=>!(String(e)in ye.current)),[Z]),{idsFilter:te,enabled:k.data!==void 0||k.isError}),xe=e=>ne[String(e)]??be.rows[String(e)],Se=e=>xe(e)===void 0?be.failed.has(String(e))?`failed`:`loading`:`loaded`,Ce=e=>`Couldn't load ${w.singular} ${ui(e)}`,we=e=>{let t=xe(e);return t===void 0?be.failed.has(String(e))?Ce(e):``:J(t)},Te=e=>ve.some(t=>String(t)===String(e)),Ee=X>ii,De=Ee?Math.max(0,Math.floor(ie/ae)-ai):0,Oe=Ee?Math.min(X,Math.ceil((ie+z)/ae)+ai):X,ke=X>0;d.useLayoutEffect(()=>{if(!M)return;let e=B.current;if(e===null)return;e.clientHeight>0&&se(e.clientHeight);let t=e.querySelector(`[role='option']`)?.getBoundingClientRect().height??0;t>0&&oe(t)},[M,ke]);let Ae=e=>{let t=e*ae,n=ie;t<n?n=t:t+ae>n+z&&(n=t+ae-z),n!==ie&&(B.current!==null&&(B.current.scrollTop=n),R(n))},je=()=>{G.hasNextPage&&!G.isFetchingNextPage&&!G.isFetchNextPageError&&G.fetchNextPage()},Me=e=>{L(e),Ae(e)},Ne=d.useRef(X);d.useEffect(()=>{H.current&&X>Ne.current?(H.current=!1,Me(Math.min(I+1,X-1))):I>=X&&X>0&&L(X-1),Ne.current=X},[X]);let Pe=()=>{L(0),R(0),B.current!==null&&(B.current.scrollTop=0)};d.useEffect(()=>{L(0),R(0),B.current!==null&&(B.current.scrollTop=0)},[he]);let Fe=()=>{o||(F(``),Pe(),N(!0))},Q=()=>{N(!1),F(``),H.current=!1},Ie=e=>{let t=li(e);if(re(n=>String(t)in n?n:{...n,[String(t)]:e}),a){let e=Te(t)?ve.filter(e=>String(e)!==String(t)):[...ve,t];i([...e])}else i(t),Q()},Le=e=>{i([...ve.filter(t=>String(t)!==String(e))]),V.current?.focus()},Re=()=>{i(null),F(``),V.current?.focus()},ze=!a&&ve.length>0?ve[0]:void 0,Be=ze===void 0?void 0:Se(ze),Ve=ze===void 0?``:we(ze),He=M?P:a?``:Ve,Ue=e=>{let t=e.target.value;if(Pe(),!M){if(o)return;N(!0),F(Ve!==``&&t.startsWith(Ve)?t.slice(Ve.length):t)}else F(t)},We=Math.max(1,Math.floor(z/ae)-1),Ge=e=>{if(!o)switch(e.key){case`ArrowDown`:e.preventDefault(),M?X>0&&(I<X-1?Me(I+1):_e?(H.current=!0,je()):Me(0)):Fe();break;case`ArrowUp`:e.preventDefault(),M?X>0&&(I>0?Me(I-1):_e||Me(X-1)):Fe();break;case`Home`:M&&X>0&&(e.preventDefault(),Me(0));break;case`End`:M&&X>0&&(e.preventDefault(),Me(X-1),je());break;case`PageDown`:if(M&&X>0){e.preventDefault();let t=Math.min(X-1,I+We);Me(t),t===X-1&&je()}break;case`PageUp`:M&&X>0&&(e.preventDefault(),Me(Math.max(0,I-We)));break;case`Enter`:if(M){e.preventDefault();let t=Y[I];t!==void 0&&Ie(t)}break;case`Escape`:M&&(e.preventDefault(),e.stopPropagation(),Q());break;case`Backspace`:a&&P===``&&ve.length>0&&i([...ve.slice(0,-1)]);break;case`Tab`:M&&Q()}},Ke=e=>{let t=e.relatedTarget;(t===null||ce.current?.contains(t)!==!0&&ue.current?.contains(t)!==!0)&&(M&&Q(),_?.())},qe=e=>{let t=e.currentTarget;R(t.scrollTop);let n=t.clientHeight>0?t.clientHeight:z;t.scrollTop+n>=X*ae-ae*5&&je()},Je=G.data===void 0&&G.error==null,Ye=G.data===void 0?G.error:null,Xe=j&&(W!==pe||G.isPlaceholderData&&G.isFetching),Ze=ge.length,Qe=K===void 0?void 0:K.toLocaleString(),$e=X>0||Je||Ye!=null||Xe?null:W===``?`none`:j?`no-match`:`no-loaded-match`,et=$e===null?null:{reason:$e,search:W,names:w,loaded:Ze},tt=Xe?`Searching…`:G.isFetchingNextPage?`Loading more ${w.plural}…`:j?_e?`Showing ${Ze.toLocaleString()}${Qe===void 0?``:` of ${Qe}`}. Type to narrow.`:W===``?`${X.toLocaleString()} ${X===1?w.singular:w.plural}`:`${X.toLocaleString()} ${X===1?`${w.singular} matches`:`${w.plural} match`} “${W}”`:W===``?_e?`Showing ${Ze.toLocaleString()}${Qe===void 0?``:` of ${Qe}`}. Search isn't available, so scroll for more.`:`${Ze.toLocaleString()} ${Ze===1?w.singular:w.plural}`:`Search isn't available for ${w.plural}: ${X.toLocaleString()} of the ${Ze.toLocaleString()} loaded match`,nt=M?Ye==null?Je?`Loading ${w.plural}…`:et===null?tt:Jr(et):le(Ye,{action:`view`,resource:w.plural}).title:``,rt=M&&X>0&&I<X&&!Je?O(I):void 0,it=e[`aria-invalid`]===!0||e[`aria-invalid`]===`true`,at=C.Option,ot=C.Chip,st=C.Loading,ct=C.Empty,lt=C.Error,ut=(0,f.jsx)(`div`,{role:`listbox`,id:ee,"aria-label":e[`aria-labelledby`]===void 0?e[`aria-label`]??di(w.plural):void 0,"aria-labelledby":e[`aria-labelledby`],"aria-multiselectable":a||void 0,"aria-busy":Je||Xe||void 0,className:D(`p-1`,Xe&&`cursor-progress`),style:Ee?{paddingTop:De*ae,paddingBottom:(X-Oe)*ae}:void 0,children:Y.slice(De,Oe).map((e,t)=>{let n=De+t,r=li(e),i=Te(r),a=n===I;return(0,f.jsx)(`div`,{id:O(n),role:`option`,"aria-selected":i,"aria-setsize":_e?K??-1:X,"aria-posinset":n+1,"data-highlighted":a?`true`:void 0,className:`flex h-8 cursor-default select-none items-center justify-between gap-2 rounded-sm px-2 text-sm outline-none data-[highlighted=true]:bg-accent data-[highlighted=true]:text-accent-foreground`,onMouseDown:e=>e.preventDefault(),onMouseMove:()=>{a||L(n)},onClick:()=>Ie(e),children:(0,f.jsx)(at,{item:e,label:q(e),selected:i,active:a})},String(r))})}),dt=Ye==null?Je?(0,f.jsxs)(f.Fragment,{children:[(0,f.jsxs)(`p`,{className:`border-b border-border px-3 py-1.5 text-xs text-muted-foreground`,"aria-hidden":`true`,children:[`Loading `,w.plural,`…`]}),(0,f.jsx)(`div`,{className:`p-1`,children:(0,f.jsx)(st,{rows:ci})}),ut]}):(0,f.jsxs)(f.Fragment,{children:[et===null?(0,f.jsxs)(`p`,{className:`flex items-start gap-2 border-b border-border px-3 py-1.5 text-xs text-muted-foreground`,"aria-hidden":`true`,children:[Xe||G.isFetchingNextPage?(0,f.jsx)(me,{className:`mt-0.5 h-3 w-3 shrink-0 animate-spin`}):null,(0,f.jsx)(`span`,{className:`min-w-0`,children:tt})]}):null,(0,f.jsxs)(`div`,{ref:B,className:`max-h-64 overflow-y-auto`,onScroll:qe,children:[et===null?null:(0,f.jsx)(ct,{...et}),ut,_e?(0,f.jsx)(`div`,{className:`px-1 pb-1`,children:G.isFetchNextPageError?(0,f.jsxs)(`p`,{className:`flex h-8 items-center gap-2 px-2 text-xs text-muted-foreground`,children:[(0,f.jsx)(U,{className:`h-3 w-3 shrink-0 text-destructive`}),(0,f.jsxs)(`span`,{className:`truncate`,children:[`Couldn't load more `,w.plural,`.`]}),(0,f.jsx)(`button`,{type:`button`,tabIndex:-1,className:`font-medium text-foreground underline underline-offset-4`,onMouseDown:e=>e.preventDefault(),onClick:()=>void G.fetchNextPage(),children:`Try again`})]}):(0,f.jsx)(`button`,{type:`button`,tabIndex:-1,disabled:G.isFetchingNextPage,className:`flex h-8 w-full items-center justify-center gap-2 rounded-sm text-xs text-muted-foreground hover:bg-accent hover:text-accent-foreground disabled:pointer-events-none`,onMouseDown:e=>e.preventDefault(),onClick:je,children:G.isFetchingNextPage?(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(me,{className:`h-3 w-3 animate-spin`}),`Loading more…`]}):`Load more ${w.plural}`})}):null]})]}):(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`div`,{className:`p-1`,children:(0,f.jsx)(lt,{error:Ye,context:{action:`view`,resource:w.plural},onRetry:()=>void G.refetch(),retrying:G.isFetching})}),ut]});return(0,f.jsxs)(S.Root,{open:M,onOpenChange:e=>{e||Q()},modal:!1,children:[(0,f.jsx)(S.Anchor,{asChild:!0,children:(0,f.jsxs)(`div`,{ref:ce,onClick:()=>{o||(V.current?.focus(),M||Fe())},onBlur:Ke,"data-invalid":it?`true`:void 0,className:D(`relative flex min-h-10 w-full flex-wrap items-center gap-1.5 rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2 data-[invalid=true]:border-destructive data-[invalid=true]:focus-within:ring-destructive`,o&&`cursor-not-allowed opacity-50`,p),children:[a?ve.map(e=>{let t=Se(e),n=t===`loaded`?we(e):Ce(e);return(0,f.jsx)(ot,{label:t===`loaded`?q(xe(e)??{}):n,state:t,removeLabel:`Remove ${n}`,onRemove:o?void 0:()=>Le(e)},String(e))}):null,Be===`failed`&&!M?(0,f.jsx)(U,{className:`h-4 w-4 shrink-0 text-destructive`}):null,(0,f.jsx)(`input`,{ref:fe,id:E,type:`text`,role:`combobox`,"aria-expanded":M,"aria-controls":ee,"aria-autocomplete":`list`,"aria-activedescendant":rt,"aria-label":e[`aria-label`],"aria-labelledby":e[`aria-labelledby`],"aria-describedby":e[`aria-describedby`],"aria-invalid":e[`aria-invalid`],"aria-required":e[`aria-required`],autoComplete:`off`,disabled:o,placeholder:Be===`loading`?`Loading ${w.singular}…`:ve.length===0?s:void 0,value:He,onChange:Ue,onKeyDown:Ge,onClick:()=>{M||Fe()},className:D(`min-w-16 flex-1 bg-transparent outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed`,Be===`failed`&&!M&&`text-muted-foreground`)}),h&&ve.length>0&&!o?(0,f.jsx)(`button`,{type:`button`,"aria-label":`Clear selection`,className:`rounded-sm p-0.5 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring`,onMouseDown:e=>e.preventDefault(),onClick:e=>{e.stopPropagation(),Re()},children:(0,f.jsx)(Wr,{className:`h-4 w-4`})}):null,(0,f.jsx)(de,{className:`h-4 w-4 shrink-0 opacity-50`}),(0,f.jsx)(`span`,{className:`sr-only`,role:`status`,"aria-live":`polite`,children:nt})]})}),(0,f.jsx)(S.Portal,{children:(0,f.jsx)(S.Content,{ref:ue,side:`bottom`,align:`start`,sideOffset:4,onOpenAutoFocus:e=>e.preventDefault(),onCloseAutoFocus:e=>e.preventDefault(),onInteractOutside:e=>{let t=e.target;ce.current!==null&&t instanceof Node&&ce.current.contains(t)&&e.preventDefault()},className:`z-popover w-[var(--radix-popover-trigger-width)] min-w-48 overflow-hidden rounded-md border border-border bg-popover text-popover-foreground shadow-md`,children:dt})})]})});fi.displayName=`ResourceSelect`;function pi(e){return e==null||typeof e==`object`?null:String(e)}function mi(e){return e==null||typeof e==`boolean`?null:Array.isArray(e)?e.filter(e=>typeof e==`string`||typeof e==`number`):e}function hi({field:e,value:t,onFilterChange:n}){let r=(e.enumValues??[]).map(t=>({value:String(t),label:Wn(t,e.enumLabels)}));return(0,f.jsx)(rt,{"aria-label":e.label,className:`h-9 w-auto min-w-36`,value:pi(t),options:r,placeholder:e.label,clearable:!0,clearLabel:`${e.label}: All`,onValueChange:t=>{t===null?n(e,null):n(e,(e.enumValues??[]).find(e=>String(e)===t)??t)}})}function gi({field:e,value:t,onFilterChange:n}){return(0,f.jsx)(rt,{"aria-label":e.label,className:`h-9 w-auto min-w-36`,value:typeof t==`boolean`?String(t):null,options:[{value:`true`,label:`Yes`},{value:`false`,label:`No`}],placeholder:e.label,clearable:!0,clearLabel:`${e.label}: All`,onValueChange:t=>n(e,t===null?null:t===`true`)})}function _i(e){let{searchEnabled:t,searchValue:n,onSearchChange:r,searchPlaceholder:i=`Search…`,filterFields:a,values:o,onFilterChange:s,className:c}=e;return(0,f.jsxs)(`div`,{className:D(`flex flex-wrap items-center gap-2`,c),children:[t&&(0,f.jsx)(Ie,{type:`search`,"aria-label":`Search`,placeholder:i,value:n,onChange:e=>r(e.target.value),className:`h-9 w-full max-w-80`}),a.map(e=>{let t=o[e.name];return e.kind===`enum`?(0,f.jsx)(hi,{field:e,value:t,onFilterChange:s},e.name):e.kind===`boolean`?(0,f.jsx)(gi,{field:e,value:t,onFilterChange:s},e.name):e.kind===`relation`&&e.relation!==void 0?(0,f.jsx)(`div`,{className:`min-w-36`,children:(0,f.jsx)(fi,{resource:e.relation.resource,multiple:e.relation.many,value:mi(t),placeholder:e.label,"aria-label":e.label,onChange:t=>s(e,t)})},e.name):null})]})}var vi={comfortable:{head:`h-10 px-3`,cell:`h-12 px-3 py-2`,action:`h-8 px-3`,card:`gap-3 p-4`},compact:{head:`h-9 px-2`,cell:`h-9 px-2 py-1`,action:`h-7 px-2`,card:`gap-2 p-3`}},yi=`group/scroll relative w-full max-h-[var(--karni-table-max-height)] overflow-auto rounded-md border border-border bg-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,bi=`w-full border-separate border-spacing-0 text-sm`,xi=`sticky top-0 z-raised`,Si=`whitespace-nowrap border-b border-border bg-muted text-left align-middle text-xs font-medium text-muted-foreground`,Ci=`whitespace-nowrap border-b border-border bg-background align-middle group-hover/row:bg-muted group-data-[state=selected]/row:bg-muted`,wi=`[&>tr:last-child>td]:border-b-0`,Ti=`sticky left-0 w-10 min-w-10 px-3`,Ei=`sticky border-r border-r-transparent group-data-[scrolled=true]/scroll:border-r-border`,Di=`left-0`,Oi=`left-10`,ki=`max-w-72 truncate`,Ai=`karni:table`;function ji(e){return`${Ai}:density:${e===void 0?`anonymous`:String(e)}`}function Mi(e,t){return`${Ai}:columns:${e}:${t===void 0?`anonymous`:String(t)}`}function Ni(e){try{return typeof window>`u`?null:window.localStorage.getItem(e)}catch{return null}}function Pi(e,t){try{window.localStorage.setItem(e,t)}catch{}}function Fi(e,t,n,r){let i=d.useCallback(()=>{let r=Ni(e);return r===null?t:n(r)??t},[e,t,n]),[a,o]=d.useState(()=>({key:e,value:i()})),s=a.key===e?a.value:i();return a.key!==e&&o({key:e,value:s}),[s,d.useCallback(t=>{o({key:e,value:t}),Pi(e,r(t))},[e,r])]}function Ii(e){return e===`compact`||e===`comfortable`?e:void 0}function Li(e){try{let t=JSON.parse(e);return Array.isArray(t)&&t.every(e=>typeof e==`string`)?t:void 0}catch{return}}var Ri=e=>e,zi=e=>JSON.stringify(e);function Bi(e){let{selectedIds:t,bulkActions:n,onClear:r,onAction:i,runningIndex:a=null,outcome:o=null,pageRowCount:s,allPageRowsSelected:c=!1,totalCount:l,resourceLabel:u=`rows`,className:p}=e,m=d.useRef([]),h=t.length,g=c&&l!==void 0&&s!==void 0?l-h:0;return(0,f.jsxs)(`div`,{role:`toolbar`,"aria-label":`Bulk actions`,className:D(`flex flex-col gap-2 rounded-md border border-border bg-muted px-3 py-2`,p),children:[(0,f.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,f.jsxs)(`p`,{className:`text-sm font-medium text-foreground`,children:[h,` selected`]}),(0,f.jsx)(Z,{variant:`ghost`,size:`sm`,onClick:r,children:`Clear`}),(0,f.jsx)(`div`,{className:`ml-auto flex flex-wrap items-center gap-2`,children:n.map((e,n)=>(0,f.jsx)(Ce,{ref:e=>{m.current[n]=e},variant:e.destructive===!0?`destructive`:`outline`,size:`sm`,pending:a===n,pendingLabel:e.pendingLabel??`Working…`,disabled:a!==null&&a!==n,onClick:()=>{i===void 0?e.onClick([...t]):i(n,m.current[n]??null)},children:e.label},n))})]}),g>0&&(0,f.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`All `,h,` `,u,` on this page are selected. The other `,g.toLocaleString(),` `,`matching `,u,` are not.`]}),o?.kind===`partial`&&(0,f.jsxs)(`p`,{role:`alert`,className:`flex items-center gap-2 text-sm text-foreground`,children:[(0,f.jsx)(U,{className:`h-4 w-4 shrink-0 text-destructive`}),o.actionLabel,` failed for `,o.failed,` of `,o.total,` `,u,`. The rows that failed say why and stay selected. The others are done.`]}),o?.kind===`failed`&&(0,f.jsx)(Te,{variant:`inline`,error:o.error,context:{action:o.actionLabel.toLowerCase(),resource:`${o.count} ${u}`}})]})}function Vi({children:e,...t}){return(0,f.jsx)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,focusable:!1,...t,children:e})}function Hi(e){return(0,f.jsx)(Vi,{...e,children:(0,f.jsx)(`polyline`,{points:`15 18 9 12 15 6`})})}function Ui(e){return(0,f.jsx)(Vi,{...e,children:(0,f.jsx)(`polyline`,{points:`9 18 15 12 9 6`})})}function Wi(e){return(0,f.jsxs)(Vi,{...e,children:[(0,f.jsx)(`polyline`,{points:`17 18 11 12 17 6`}),(0,f.jsx)(`line`,{x1:`7`,y1:`6`,x2:`7`,y2:`18`})]})}function Gi(e){return(0,f.jsxs)(Vi,{...e,children:[(0,f.jsx)(`polyline`,{points:`7 18 13 12 7 6`}),(0,f.jsx)(`line`,{x1:`17`,y1:`6`,x2:`17`,y2:`18`})]})}function Ki(e){return(0,f.jsxs)(Vi,{...e,children:[(0,f.jsx)(`line`,{x1:`12`,y1:`5`,x2:`12`,y2:`19`}),(0,f.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`})]})}function qi(e){return(0,f.jsxs)(Vi,{...e,children:[(0,f.jsx)(`line`,{x1:`4`,y1:`6`,x2:`20`,y2:`6`}),(0,f.jsx)(`line`,{x1:`4`,y1:`12`,x2:`20`,y2:`12`}),(0,f.jsx)(`line`,{x1:`4`,y1:`18`,x2:`20`,y2:`18`}),(0,f.jsx)(`circle`,{cx:`9`,cy:`6`,r:`2`}),(0,f.jsx)(`circle`,{cx:`15`,cy:`12`,r:`2`}),(0,f.jsx)(`circle`,{cx:`8`,cy:`18`,r:`2`})]})}function Ji(e){return(0,f.jsx)(Vi,{...e,children:(0,f.jsx)(`polygon`,{points:`22 3 2 3 10 12.5 10 19 14 21 14 12.5 22 3`})})}function Yi(e){return(0,f.jsxs)(Vi,{...e,children:[(0,f.jsx)(`polyline`,{points:`22 12 16 12 14 15 10 15 8 12 2 12`}),(0,f.jsx)(`path`,{d:`M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z`})]})}function Xi(e){let{label:t,text:n,icon:r,iconAfter:i,unavailable:a,busy:o,spinning:s,onActivate:c,buttonRef:l}=e;return(0,f.jsxs)(Z,{ref:l,variant:`outline`,size:`sm`,disabled:a,"aria-label":n===null?t:void 0,title:n===null?t:void 0,"aria-disabled":o||void 0,"aria-busy":s||void 0,className:D(`relative aria-disabled:cursor-wait [&[aria-disabled]:not([aria-busy])]:opacity-50`,n===null&&`w-9 px-0`),onClick:()=>{o||c()},children:[(0,f.jsxs)(`span`,{className:D(`inline-flex items-center gap-1`,s&&`text-transparent`),children:[!i&&r,n,i===!0&&r]}),s&&(0,f.jsx)(`span`,{className:`absolute inset-0 flex items-center justify-center`,"aria-hidden":`true`,children:(0,f.jsx)(me,{className:`h-4 w-4 animate-spin`})})]})}function Zi(e){let{page:t,pageCount:n,totalCount:r,hasPrevious:i,hasNext:a,onPageChange:o,pageSize:s,pageSizeOptions:c,onPageSizeChange:l,busy:u=!1,className:p}=e,[m,h]=d.useState(null),g=be(u),[_,v]=d.useState(``),y=d.useId(),b=d.useRef(null),x=d.useRef(null),[S,C]=d.useState(null);d.useEffect(()=>{S===`next`&&!i&&x.current?.focus(),S===`previous`&&!a&&b.current?.focus(),S!==null&&C(null)},[S,i,a]);let w=(e,r)=>{let i=Math.min(Math.max(1,e),Math.max(1,n));i!==t&&(h(r),i===1&&(r===`first`||r===`previous`)&&C(`next`),i===n&&(r===`last`||r===`next`)&&C(`previous`),o(i))},T=e=>g&&m===e,E=s!==void 0&&c!==void 0?[...new Set([...c,s])].sort((e,t)=>e-t):[];return(0,f.jsxs)(`nav`,{"aria-label":`Pagination`,"aria-busy":u||void 0,className:D(`flex flex-wrap items-center justify-between gap-x-3 gap-y-2`,p),children:[(0,f.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[`Page `,t.toLocaleString(),` of `,n.toLocaleString(),` · `,r.toLocaleString(),` `,r===1?`item`:`items`]}),(0,f.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[E.length>1&&l!==void 0&&s!==void 0&&(0,f.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,f.jsx)(`span`,{className:`text-sm text-muted-foreground`,"aria-hidden":`true`,children:`Rows per page`}),(0,f.jsx)(rt,{"aria-label":`Rows per page`,className:`h-9 w-20`,value:String(s),options:E.map(e=>({value:String(e),label:String(e)})),onValueChange:e=>{e!==null&&!u&&l(Number(e))}})]}),(0,f.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,f.jsx)(Xi,{label:`First page`,text:null,icon:(0,f.jsx)(Wi,{className:`h-4 w-4`}),unavailable:!i,busy:u,spinning:T(`first`),onActivate:()=>w(1,`first`)}),(0,f.jsx)(Xi,{buttonRef:b,label:`Previous`,text:`Previous`,icon:(0,f.jsx)(Hi,{className:`h-4 w-4`}),unavailable:!i,busy:u,spinning:T(`previous`),onActivate:()=>w(t-1,`previous`)}),(0,f.jsx)(Xi,{buttonRef:x,label:`Next`,text:`Next`,icon:(0,f.jsx)(Ui,{className:`h-4 w-4`}),iconAfter:!0,unavailable:!a,busy:u,spinning:T(`next`),onActivate:()=>w(t+1,`next`)}),(0,f.jsx)(Xi,{label:`Last page`,text:null,icon:(0,f.jsx)(Gi,{className:`h-4 w-4`}),unavailable:!a||t>=n,busy:u,spinning:T(`last`),onActivate:()=>w(n,`last`)})]}),n>2&&(0,f.jsxs)(`form`,{className:`flex items-center gap-1`,onSubmit:e=>{e.preventDefault();let t=Number(_);!u&&Number.isInteger(t)&&_.trim()!==``&&(w(t,`jump`),v(``))},children:[(0,f.jsxs)(`label`,{htmlFor:y,className:`sr-only`,children:[`Go to page (1 to `,n,`)`]}),(0,f.jsx)(Ie,{id:y,type:`number`,inputMode:`numeric`,min:1,max:n,placeholder:`Page`,value:_,onChange:e=>v(e.target.value),className:`h-9 w-20`}),(0,f.jsx)(Z,{type:`submit`,variant:`outline`,size:`sm`,"aria-disabled":u||void 0,className:`aria-disabled:cursor-wait aria-disabled:opacity-50`,children:`Go`})]})]})]})}var Qi=8;function $i(e){let{title:t,fields:n,selection:r,actions:i,onOpen:a,selected:o,failure:s,density:c}=e,[l,u]=d.useState(!1),p=d.useId(),m=l?n:n.slice(0,Qi),h=n.length-Qi;return(0,f.jsxs)(`li`,{"data-state":o?`selected`:void 0,className:D(`flex flex-col rounded-lg border border-border bg-card text-card-foreground data-[state=selected]:border-primary`,vi[c].card),children:[(0,f.jsxs)(`div`,{className:`flex items-start gap-3`,children:[r!==void 0&&(0,f.jsx)(`div`,{className:`flex h-6 items-center`,children:r}),(0,f.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,f.jsx)(`h3`,{className:`text-base font-semibold leading-none`,children:a===void 0?(0,f.jsx)(`span`,{className:`block truncate`,children:t}):(0,f.jsx)(`button`,{type:`button`,onClick:a,className:`max-w-full truncate rounded-sm text-left hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,children:t})}),s!==void 0&&(0,f.jsxs)(`p`,{className:`mt-1 flex items-center gap-1 text-xs text-destructive`,children:[(0,f.jsx)(U,{className:`h-3.5 w-3.5 shrink-0`}),s]})]})]}),n.length>0&&(0,f.jsx)(`dl`,{id:p,className:`grid grid-cols-2 gap-x-3 gap-y-1 text-sm`,children:m.map(e=>(0,f.jsxs)(d.Fragment,{children:[(0,f.jsx)(`dt`,{className:`truncate text-muted-foreground`,children:e.label}),(0,f.jsx)(`dd`,{className:`min-w-0 break-words text-foreground`,children:e.value})]},e.id))}),h>0&&(0,f.jsx)(`button`,{type:`button`,"aria-expanded":l,"aria-controls":p,onClick:()=>u(e=>!e),className:`self-start rounded-sm text-sm font-medium text-primary underline-offset-4 hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,children:l?`Show fewer details`:`Show ${h} more details`}),i!==void 0&&(0,f.jsx)(`div`,{className:`hidden flex-wrap items-center justify-end gap-1 border-t border-border pt-2 has-[a]:flex has-[button]:flex`,children:i})]})}j(`empty-state`,`EmptyState`);function ea({children:e}){return(0,f.jsx)(`div`,{"aria-hidden":`true`,className:`mb-2 text-muted-foreground [&>svg]:h-10 [&>svg]:w-10`,children:e})}function ta({children:e}){return(0,f.jsx)(`h3`,{className:`text-base font-semibold text-foreground`,children:e})}function na({children:e}){return(0,f.jsx)(`p`,{className:`max-w-96 text-sm text-muted-foreground`,children:e})}function ra({children:e}){return(0,f.jsx)(`div`,{className:`mt-3 flex items-center gap-2`,children:e})}var ia={Icon:ea,Title:ta,Description:na,Actions:ra},aa=d.forwardRef(({icon:e,title:t,description:n,action:r,slots:i,className:a,children:o,...s},c)=>{let{Icon:l,Title:u,Description:d,Actions:p}={...ia,...i};return(0,f.jsxs)(`div`,{ref:c,className:D(`flex w-full flex-col items-center justify-center gap-2 rounded-lg border border-dashed border-border bg-background px-6 py-12 text-center`,a),...s,children:[e!=null&&(0,f.jsx)(l,{children:e}),(0,f.jsx)(u,{children:t}),n!=null&&(0,f.jsx)(d,{children:n}),r!=null&&(0,f.jsx)(p,{children:r}),o]})});aa.displayName=`EmptyState`;var oa=[`w-3/4`,`w-1/2`,`w-2/3`,`w-5/6`,`w-1/3`];function sa(...e){return oa[e.reduce((e,t)=>e+t,0)%oa.length]??`w-1/2`}function ca(e){let{columnCount:t,rowCount:n,density:r,selectable:i}=e,a=vi[r],o=Array.from({length:Math.max(1,t)},(e,t)=>t),s=e=>i&&e===0?Ti:e===+!!i&&D(Ei,i?Oi:Di);return(0,f.jsx)(`div`,{className:D(yi,`overflow-hidden`),children:(0,f.jsxs)(`table`,{className:bi,children:[(0,f.jsx)(`thead`,{className:xi,children:(0,f.jsx)(`tr`,{children:o.map(e=>(0,f.jsx)(`th`,{scope:`col`,className:D(Si,a.head,s(e)),children:i&&e===0?(0,f.jsx)($,{className:`h-4 w-4 rounded-sm bg-background`}):(0,f.jsx)($,{className:`h-3 w-16 bg-background`})},e))})}),(0,f.jsx)(`tbody`,{className:wi,children:Array.from({length:n},(e,t)=>(0,f.jsx)(`tr`,{className:`group/row`,children:o.map(e=>(0,f.jsx)(`td`,{className:D(Ci,a.cell,s(e)),children:i&&e===0?(0,f.jsx)($,{className:`h-4 w-4 rounded-sm`}):(0,f.jsx)($,{className:D(`h-4 min-w-12`,sa(t,e))})},e))},t))})]})})}function la(e){let{density:t,selectable:n,actions:r}=e,i=vi[t],a=+!!n+ +!!r,o=Math.min(8,Math.max(1,e.columnCount-a-1));return(0,f.jsx)(`ul`,{className:`flex flex-col gap-3`,children:Array.from({length:e.rowCount},(e,t)=>(0,f.jsxs)(`li`,{className:D(`flex flex-col rounded-lg border border-border bg-card`,i.card),children:[(0,f.jsxs)(`div`,{className:`flex h-6 items-center gap-3`,children:[n&&(0,f.jsx)($,{className:`h-4 w-4 rounded-sm`}),(0,f.jsx)($,{className:D(`h-4`,sa(t,0))})]}),(0,f.jsx)(`div`,{className:`grid grid-cols-2 gap-x-3 gap-y-1`,children:Array.from({length:o*2},(e,n)=>(0,f.jsx)(`div`,{className:`flex h-5 items-center`,children:(0,f.jsx)($,{className:D(`h-3.5`,sa(t,n,1))})},n))}),r&&(0,f.jsx)(`div`,{className:`flex justify-end border-t border-border pt-2`,children:(0,f.jsx)($,{className:D(`w-16`,i.action)})})]},t))})}function ua(e){return(0,f.jsxs)(`div`,{"aria-hidden":`true`,"data-testid":`resource-table-skeleton`,className:`flex flex-col gap-3`,children:[e.toolbar&&(0,f.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,f.jsx)($,{className:`h-9 w-full max-w-80`}),(0,f.jsx)($,{className:`h-9 w-40`})]}),e.layout===`cards`?(0,f.jsx)(la,{...e}):(0,f.jsx)(ca,{...e}),(0,f.jsxs)(`div`,{className:`flex min-h-9 flex-wrap items-center justify-between gap-3`,children:[(0,f.jsx)($,{className:`h-4 w-40`}),(0,f.jsx)($,{className:`h-9 w-64`})]})]})}function da(e){let{resourceLabel:t,itemLabel:n,onCreate:r,createLabel:i}=e;return(0,f.jsx)(aa,{"data-empty-reason":`no-records`,icon:(0,f.jsx)(Yi,{}),title:`No ${t} yet`,description:r===void 0?`When ${t} are added, they will appear here.`:`Create the first ${n} and it will appear here.`,action:r===void 0?void 0:(0,f.jsxs)(Z,{size:`sm`,onClick:r,children:[(0,f.jsx)(Ki,{className:`h-4 w-4`}),i]})})}function fa(e){let{resourceLabel:t,search:n,filters:r,onClearFilters:i}=e,a=[...n===``?[]:[`the search “${n}”`],...r.map(e=>`${e.label}: ${e.value}`)];return(0,f.jsx)(aa,{"data-empty-reason":`no-results`,icon:(0,f.jsx)(Ji,{}),title:`No ${t} match`,description:`Nothing matches ${a.join(` and `)}. Try a different search, or clear the filters.`,action:(0,f.jsx)(Z,{variant:`outline`,size:`sm`,onClick:i,children:`Clear filters`}),children:a.length>0&&(0,f.jsxs)(`ul`,{"aria-label":`Active filters`,className:`mt-3 flex flex-wrap justify-center gap-2`,children:[n!==``&&(0,f.jsxs)(`li`,{className:`rounded-md border border-border bg-muted px-2 py-0.5 text-xs text-foreground`,children:[`Search: `,n]}),r.map(e=>(0,f.jsxs)(`li`,{className:`rounded-md border border-border bg-muted px-2 py-0.5 text-xs text-foreground`,children:[e.label,`: `,e.value]},e.field))]})})}function pa(e){return(0,f.jsx)(Te,{...e})}function ma(e){return(0,f.jsx)(Te,{...e,variant:`inline`,className:`rounded-md border border-destructive-border bg-destructive-subtle px-3 py-2`})}function ha(e){return(0,f.jsx)(Ee,{action:`view`,resource:e.resourceLabel})}function ga(e){return e.hasRows?(0,f.jsxs)(`div`,{role:`status`,className:D(`flex items-center gap-2 rounded-md border border-border bg-muted px-3 py-2 text-sm text-foreground`),children:[(0,f.jsx)(W,{className:`h-4 w-4 shrink-0 text-muted-foreground`}),(0,f.jsxs)(`span`,{children:[`You're offline. These `,e.resourceLabel,` may be out of date. The list refreshes by itself when you're back online.`]})]}):(0,f.jsx)(Te,{error:TypeError(`offline`),onRetry:e.onRetry,actions:(0,f.jsx)(`span`,{className:`text-sm text-muted-foreground`,children:`The list loads by itself when you are back online.`})})}var _a={Loading:ua,NoRecords:da,NoResults:fa,Error:pa,RefetchError:ma,Forbidden:ha,Offline:ga,Pagination:Zi,BulkActions:Bi,RowCard:$i},va=[`a[href]`,`button`,`input`,`select`,`textarea`,`summary`,`iframe`,`audio[controls]`,`video[controls]`,`[contenteditable=""]`,`[contenteditable="true"]`,`[tabindex]`].join(`, `),ya=`input:not([type="checkbox"]):not([type="radio"]):not([type="button"]):not([type="submit"]):not([type="reset"]), textarea, select, [contenteditable=""], [contenteditable="true"]`;function ba(e,t){if(e.matches(`:disabled`)||e instanceof HTMLInputElement&&e.type===`hidden`)return!1;for(let n=e;n!==null&&n!==t;){if(n.hidden||n.hasAttribute(`inert`)||n.getAttribute(`aria-hidden`)===`true`)return!1;n=n.parentElement}return!0}function xa(e){let t=Array.from(e.querySelectorAll(va)).filter(t=>ba(t,e));return t.filter(e=>!t.some(t=>t!==e&&t.contains(e)))}function Sa(e,t){let n=xa(e);return n.length===0?e:n[Math.min(t,n.length-1)]??e}function Ca(e){return Array.from(e.cells).flatMap(e=>{let t=xa(e);return t.length===0?[e]:t})}function wa(e,t){let n=t.closest(`td, th`);if(!(n instanceof HTMLTableCellElement))return null;let r=n.parentElement;if(!(r instanceof HTMLTableRowElement)||r.closest(`table`)!==e)return null;let i=xa(n),a=i.findIndex(e=>e.contains(t)),o=i[a]??n;return{row:r,rowIndex:r.rowIndex,cell:n,cellIndex:n.cellIndex,control:Math.max(a,0),stop:o}}var Ta=`data-row-id`;function Ea(e,t){if(t.stop!==null&&t.stop.isConnected&&e.contains(t.stop)){let n=wa(e,t.stop);if(n!==null&&n.stop===t.stop)return t.stop}let n=Array.from(e.rows);if(n.length===0)return null;let r=(t.rowId===null?void 0:n.find(e=>e.getAttribute(Ta)===t.rowId))??n[Math.min(t.rowIndex,n.length-1)];if(r===void 0||r.cells.length===0)return null;let i=r.cells[Math.min(t.cellIndex,r.cells.length-1)];return i===void 0?null:Sa(i,t.control)}function Da(e,t,n){let r=wa(e,n);return r===null?null:(t.stop=r.stop,t.rowId=r.row.getAttribute(Ta),t.rowIndex=r.rowIndex,t.cellIndex=r.cellIndex,t.control=r.control,r.stop)}function Oa(e,t){let n=Ea(e,t);n!==null&&Da(e,t,n);for(let t of Array.from(e.rows))for(let e of Array.from(t.cells)){let t=xa(e);if(t.length===0)ka(e,e===n?0:-1);else{e.hasAttribute(`tabindex`)&&e.removeAttribute(`tabindex`);for(let e of t)ka(e,e===n?0:-1)}}}function ka(e,t){let n=String(t);e.getAttribute(`tabindex`)!==n&&e.setAttribute(`tabindex`,n)}function Aa(e,t,n){let r=Array.from(e.rows),i=Ca(t.row),a=i.indexOf(t.stop),o=e=>{if(e===void 0||e.cells.length===0)return null;let n=e.cells[Math.min(t.cellIndex,e.cells.length-1)];return n===void 0?null:Sa(n,t.control)},s=n.ctrlKey||n.metaKey;switch(n.key){case`ArrowRight`:return i[a+1]??null;case`ArrowLeft`:return a>0?i[a-1]??null:null;case`ArrowDown`:return o(r[t.rowIndex+1]);case`ArrowUp`:return t.rowIndex>0?o(r[t.rowIndex-1]):null;case`Home`:{let e=s?r[0]:t.row;return e===void 0?null:Ca(e)[0]??null}case`End`:{let e=s?r[r.length-1]:t.row;return e===void 0?null:Ca(e).at(-1)??null}default:return null}}var ja=typeof window>`u`?d.useEffect:d.useLayoutEffect,Ma=new Set([`ArrowRight`,`ArrowLeft`,`ArrowDown`,`ArrowUp`,`Home`,`End`]);function Na(e,t){let n=d.useRef({stop:null,rowId:null,rowIndex:1,cellIndex:0,control:0});ja(()=>{let r=e.current;if(!t||r===null)return;Oa(r,n.current);let i=new MutationObserver(()=>Oa(r,n.current));return i.observe(r,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[`disabled`,`hidden`,`inert`,`aria-hidden`,`href`]}),()=>i.disconnect()},[t,e]);let r=d.useCallback(e=>{if(!t)return;let r=e.currentTarget;if(!(e.target instanceof Element)||!r.contains(e.target))return;let i=n.current.stop,a=Da(r,n.current,e.target);a!==null&&(a!==i||a.getAttribute(`tabindex`)!==`0`)&&Oa(r,n.current)},[t]);return{onKeyDown:d.useCallback(e=>{if(!t||e.defaultPrevented||e.altKey||!Ma.has(e.key))return;let r=e.currentTarget,i=e.target;if(!(i instanceof HTMLElement)||!r.contains(i)||i.matches(ya))return;let a=wa(r,i);if(a===null)return;e.preventDefault();let o=Aa(r,a,e);o!==null&&(Da(r,n.current,o),Oa(r,n.current),o.focus())},[t]),onFocus:r}}function Pa(e){return e.getAttribute(`role`)===`checkbox`||e instanceof HTMLInputElement&&e.type===`checkbox`}function Fa(e,t,n){if(e.altKey||e.ctrlKey||e.metaKey||e.shiftKey||e.key!==`Enter`&&e.key!==` `)return;let r=e.target;if(!(r instanceof HTMLElement))return;let i=r.closest(`td`);if(i===null||i.parentElement!==e.currentTarget)return;let a=r===i;e.key===`Enter`?(a||Pa(r))&&n!==void 0&&(e.preventDefault(),n(t.original)):!e.defaultPrevented&&(a||r instanceof HTMLAnchorElement)&&t.getCanSelect()&&(e.preventDefault(),t.toggleSelected())}function Ia(e,t,n){return e===`__select__`?Ti:e===t&&D(Ei,n?Oi:Di)}function La(e){let{table:t,caption:n,density:r,busy:i,sortTarget:a,slow:o,onSort:s,onRowClick:c,failures:l,firstRowIndex:u,totalCount:p,dimmed:m,scrollRef:h,keyboardNavigation:g}=e,_=vi[r],v=d.useId(),y=g===`grid`,x=d.useRef(null),S=Na(x,y),C=t.getVisibleLeafColumns(),w=C.some(e=>e.id===Xn),T=C.find(e=>e.id!==`__select__`&&e.id!==`__actions__`)?.id,E=d.useCallback(e=>{let t=e.currentTarget,n=t.scrollLeft>0;t.dataset.scrolled===`true`!==n&&(t.dataset.scrolled=String(n))},[]);return(0,f.jsxs)(`div`,{className:`relative`,children:[o&&(0,f.jsx)(`div`,{"aria-hidden":`true`,"data-testid":`resource-table-progress`,className:`absolute inset-x-0 top-0 z-drawer h-1 animate-pulse rounded-t-md bg-primary`}),(0,f.jsx)(`div`,{ref:h,role:`region`,"aria-labelledby":v,tabIndex:y?-1:0,onScroll:E,className:D(yi,y&&`scroll-pt-10`,m&&`cursor-progress`),children:(0,f.jsxs)(`table`,{ref:x,role:y?`grid`:void 0,"aria-labelledby":y?v:void 0,"aria-multiselectable":y&&w?!0:void 0,className:bi,"aria-busy":i||void 0,"aria-rowcount":p===void 0?void 0:p+1,onKeyDown:y?S.onKeyDown:void 0,onFocus:y?S.onFocus:void 0,children:[(0,f.jsx)(`caption`,{id:v,className:`sr-only`,children:n}),(0,f.jsx)(`thead`,{className:xi,children:t.getHeaderGroups().map(e=>(0,f.jsx)(`tr`,{"aria-rowindex":1,children:e.headers.map(e=>{let t=e.column.getCanSort(),n=e.column.getIsSorted(),r=o&&i&&a===e.column.id;return(0,f.jsx)(`th`,{scope:`col`,"aria-sort":n===`asc`?`ascending`:n===`desc`?`descending`:void 0,className:D(Si,y&&`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring`,_.head,Ia(e.column.id,T,w),e.column.id===`__actions__`&&`text-right`),children:e.isPlaceholder?null:t?(0,f.jsxs)(`button`,{type:`button`,"aria-disabled":i||void 0,"aria-busy":r||void 0,className:`inline-flex items-center gap-1 rounded-sm hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring aria-disabled:cursor-wait`,onClick:t=>s(e,t),children:[(0,b.flexRender)(e.column.columnDef.header,e.getContext()),r?(0,f.jsx)(me,{className:`h-3.5 w-3.5 animate-spin`}):n===`asc`?(0,f.jsx)(H,{className:`h-3.5 w-3.5`}):n===`desc`?(0,f.jsx)(de,{className:`h-3.5 w-3.5`}):null]}):(0,b.flexRender)(e.column.columnDef.header,e.getContext())},e.id)})},e.id))}),(0,f.jsx)(`tbody`,{className:wi,children:t.getRowModel().rows.map((e,t)=>{let n=l[e.id];return(0,f.jsx)(`tr`,{"data-row-id":e.id,"aria-rowindex":u+t+1,"aria-selected":y&&w?e.getIsSelected():void 0,"data-state":e.getIsSelected()?`selected`:void 0,"data-failed":n===void 0?void 0:`true`,onClick:c===void 0?void 0:()=>c(e.original),onKeyDown:y?t=>Fa(t,e,c):void 0,className:D(`group/row`,c!==void 0&&`cursor-pointer`),children:e.getVisibleCells().map(t=>{let r=t.column.id===T,i=(0,b.flexRender)(t.column.columnDef.cell,t.getContext());return(0,f.jsx)(`td`,{className:D(Ci,y&&`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring`,_.cell,Ia(t.column.id,T,w)),children:r?(0,f.jsxs)(`div`,{className:`flex flex-col`,children:[c===void 0?(0,f.jsx)(`div`,{className:ki,children:i}):(0,f.jsx)(`button`,{type:`button`,className:D(ki,`rounded-sm text-left font-medium hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`),onClick:t=>{t.stopPropagation(),c(e.original)},children:i}),n!==void 0&&(0,f.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-destructive`,children:[(0,f.jsx)(U,{className:`h-3.5 w-3.5 shrink-0`}),n]})]}):i},t.id)})},e.id)})})]})})]})}var Ra=typeof window>`u`?d.useEffect:d.useLayoutEffect;function za(e){let[t,n]=d.useState(void 0);return Ra(()=>{let t=e.current;if(t===null)return;let r=e=>n(e>0?e:void 0);if(r(t.getBoundingClientRect().width),typeof ResizeObserver>`u`)return;let i=new ResizeObserver(e=>{for(let t of e)r(t.contentRect.width)});return i.observe(t),()=>i.disconnect()},[e]),t}function Ba(e,t){let[n,r]=d.useState(e);return d.useEffect(()=>{let n=setTimeout(()=>r(e),t);return()=>clearTimeout(n)},[e,t]),n}var Va=new Set;function Ha(){return{read(){return typeof window>`u`?{}:Object.fromEntries(new URLSearchParams(window.location.search))},write(e,{push:t}){if(typeof window>`u`)return;let n=new URL(window.location.href);for(let[t,r]of Object.entries(e))r===null?n.searchParams.delete(t):n.searchParams.set(t,r);if(n.href!==window.location.href){t?window.history.pushState(window.history.state,``,n):window.history.replaceState(window.history.state,``,n);for(let e of[...Va])e()}},subscribe(e){return Va.add(e),window.addEventListener(`popstate`,e),()=>{Va.delete(e),window.removeEventListener(`popstate`,e)}}}}var Ua=Ha(),Wa=new Set([`page`,`page_size`,`ordering`,`search`]);function Ga(e,t){return e===``?t:`${e}.${t}`}function Ka(e){return e==null?null:Array.isArray(e)?e.length===0?null:e.map(String).join(`,`):String(e)}function qa(e,t){return t.relationValueType===`integer`&&/^-?\d+$/.test(e)?Number(e):e}function Ja(e,t){if(t.kind===`boolean`)return e===`true`||e!==`false`&&void 0;if(t.kind===`enum`)return(t.enumValues??[]).find(t=>String(t)===e);if(t.kind===`relation`&&t.relation!==void 0){if(t.relation.many){let n=e.split(`,`).filter(e=>e.length>0).map(e=>qa(e,t));return n.length>0?n:void 0}return qa(e,t)}return e}function Ya(e){if(e===void 0||!/^\d+$/.test(e))return;let t=Number(e);return t>=1?t:void 0}function Xa(e,t){let n=t===``?``:`${t}.`,r=Object.entries(e.read()).filter(([e])=>n===``||e.startsWith(n)).map(([e,t])=>[e.slice(n.length),t]).sort(([e],[t])=>e<t?-1:+(e>t));return JSON.stringify(r)}function Za(e,t,n){let r=new Map(JSON.parse(e)),i=Ya(r.get(`page_size`)),a={};for(let e of n){let t=r.get(e.name);if(t===void 0||Wa.has(e.name))continue;let n=Ja(t,e);n!==void 0&&(a[e.name]=n)}return{page:Ya(r.get(`page`))??1,pageSize:i!==void 0&&t.pageSizes.includes(i)?i:t.pageSize,ordering:r.get(`ordering`)??t.ordering,search:r.get(`search`)??``,filters:a}}function Qa(e){return e==null||e===``||Array.isArray(e)&&e.length===0}function $a(e){return Object.fromEntries(Object.entries(e).filter(([,e])=>!Qa(e)))}var eo=()=>()=>void 0;function to(e){let{syncUrl:t,namespace:n,defaults:r,filterFields:i}=e,a=e.store??Ua,o=d.useCallback(e=>t?a.subscribe(e):eo(),[a,t]),s=d.useCallback(()=>t?Xa(a,n):`[]`,[a,n,t]),c=d.useSyncExternalStore(o,s,()=>`[]`),[l,u]=d.useState(()=>({page:1,pageSize:r.pageSize,ordering:r.ordering,search:``,filters:{}})),f=d.useMemo(()=>Za(c,r,i),[c,r,i]),p=t?f:l,m=d.useRef(p);return m.current=p,[p,d.useCallback((e,{push:o})=>{let s={...m.current,...e,filters:$a(e.filters??m.current.filters)};if(m.current=s,!t){u(s);return}let c={[Ga(n,`page`)]:s.page===1?null:String(s.page),[Ga(n,`page_size`)]:s.pageSize===r.pageSize?null:String(s.pageSize),[Ga(n,`ordering`)]:s.ordering===r.ordering?null:s.ordering,[Ga(n,`search`)]:s.search===``?null:s.search};for(let e of i)Wa.has(e.name)||(c[Ga(n,e.name)]=Ka(s.filters[e.name]));a.write(c,{push:o})},[a,t,n,r,i])]}function no(e){let{density:t,onDensityChange:n,columns:r,onColumnVisibilityChange:i}=e,a=r.filter(e=>e.visible).length;return(0,f.jsxs)(mt,{children:[(0,f.jsx)(ht,{asChild:!0,children:(0,f.jsxs)(Z,{variant:`outline`,size:`sm`,"aria-label":`View options`,children:[(0,f.jsx)(qi,{className:`h-4 w-4`}),`View`]})}),(0,f.jsxs)(vt,{align:`end`,className:`max-h-96 overflow-y-auto`,children:[(0,f.jsx)(bt,{checked:t===`compact`,onCheckedChange:e=>n(e?`compact`:`comfortable`),children:`Compact rows`}),r.length>1&&(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(St,{}),(0,f.jsx)(xt,{children:`Columns`}),r.map(e=>(0,f.jsx)(bt,{checked:e.visible,disabled:e.visible&&a===1,onCheckedChange:t=>i(e.id,t),onSelect:e=>e.preventDefault(),children:e.label},e.id))]})]})]})}j(`data-table`,`ResourceTable`);var ro=[10,25,50,100],io=300,ao=4,oo=5,so=[];function co(e){return typeof e==`object`&&!!e&&typeof e.then==`function`}function lo(e){return typeof e==`string`||typeof e==`number`?String(e):void 0}function uo(e,t){return e.kind===`boolean`?t===!0?`Yes`:`No`:e.kind===`enum`&&(typeof t==`string`||typeof t==`number`)?Wn(t,e.enumLabels):Array.isArray(t)?`${t.length} chosen`:e.kind===`relation`?`1 chosen`:String(t)}function fo(e){let{resource:t,target:n,rowLabel:r,onClose:i,onDeleted:a,fallbackFocus:o}=e,s=an(t),[c,l]=d.useState(null),u=d.useRef(!1),p=d.useRef(n);n!==null&&(p.current=n),d.useEffect(()=>{l(null),n!==null&&(u.current=!1)},[n]);let m=p.current===null?``:r(p.current.row),h=`“${m}”`;return(0,f.jsx)(pr,{open:n!==null,title:`Delete ${h}?`,description:`This can't be undone.`,confirmLabel:`Delete`,pendingLabel:`Deleting…`,destructive:!0,pending:s.remove.isPending,error:c,errorContext:{action:`delete`,resource:h},onCancel:i,onConfirm:()=>{let e=n===null?void 0:Un(n.row).id;(typeof e==`string`||typeof e==`number`)&&(l(null),s.remove.mutate(e,{onSuccess:()=>{u.current=!0,a(m)},onError:e=>l(e)}))},returnFocus:()=>{let e=p.current?.trigger;return!u.current&&e!==void 0&&e.isConnected?e:o()}})}function po(e){let{resource:t,columns:n,showAuditFields:r,extraColumns:i,columnsOverride:a,rowActions:o,onEdit:s,enableDelete:c,bulkActions:l,onRowClick:u,expand:p,initialSorting:m,pageSize:h,pageSizeOptions:g,filters:_,params:v,exportFormats:x,toolbar:S,empty:C,footer:w,getRowLabel:T,slots:E,resourceLabel:ee,itemLabel:O,caption:k,onCreate:A,createLabel:j,canCreate:te,canEdit:M,canDelete:N,syncUrl:P=!0,urlNamespace:F,stateStore:I,density:L,defaultDensity:ne=`comfortable`,onDensityChange:re,viewOptions:ie=!0,cardBreakpoint:R=640,keyboardNavigation:ae=`grid`,className:oe}=e,z=d.useMemo(()=>({..._a,...E}),[E]),se=(0,y.useQueryClient)(),ce=d.useContext(Gt),le=ce?.status,ue=ce?.user??null,B=d.useMemo(()=>le===void 0?null:{status:le,user:ue},[le,ue]),V=le===`authenticated`?ue?.id:void 0,de=On(t),H=de.data,U=ee??zn(t),fe=O??Bn(U),W=k??Vn(U),pe=F??t,me=d.useMemo(()=>new Set(Object.keys(v??{})),[v]),he=d.useMemo(()=>{if(_===!1||H===void 0)return[];if(_!==void 0){let e=new Map(H.fields.map(e=>[e.name,e]));return _.filter(e=>!me.has(e)).map(t=>e.get(t)).filter(e=>e!==void 0)}let e=new Set(H.operations.list?.queryParams??[]),{domain:t,audit:n}=jn(H.fields);return[...t,...n].filter(t=>!t.writeOnly&&!me.has(t.name)&&(r===!0||!An(t))&&e.has(t.name)&&(t.kind===`enum`||t.kind===`boolean`||t.kind===`relation`&&t.relation!==void 0)).slice(0,ao)},[_,me,H,r]),G=h??25,ge=(g??ro).join(`,`),K=Pn(m??[])??``,_e=d.useMemo(()=>({pageSize:G,ordering:K,pageSizes:[...new Set([...ge.split(`,`).map(Number).filter(Number.isFinite),G])].sort((e,t)=>e-t)}),[G,K,ge]),[q,J]=to({syncUrl:P,store:I,namespace:pe,defaults:_e,filterFields:he}),Y=d.useRef(q);Y.current=q;let X=d.useMemo(()=>Fn(q.ordering),[q.ordering]),[ve,ye]=d.useState(``),xe=d.useRef(null),[Ce,we]=d.useState(q.search),Te=Ba(Ce,io),Ee=d.useRef(q.search);d.useEffect(()=>{q.search!==Ee.current&&(Ee.current=q.search,we(q.search))},[q.search]);let De=d.useRef(Te);d.useEffect(()=>{if(Te===De.current)return;De.current=Te;let e=Te.trim(),t=Y.current;e!==t.search&&(Ee.current=e,xe.current=`results`,J({search:e,page:1},{push:t.search===``}))},[Te,J]);let Oe=d.useCallback((e,t)=>{xe.current=`results`,J({filters:{...Y.current.filters,[e.name]:t},page:1},{push:!0})},[J]),ke=d.useCallback(()=>{xe.current=`results`,we(``),J({search:``,filters:{},page:1},{push:!0})},[J]),Ae=d.useMemo(()=>{if(p!==void 0)return p;let e=H?.operations.list?.expandEnum;return H===void 0||e===void 0?[]:H.fields.filter(t=>t.kind===`relation`&&t.relation!==void 0&&!t.relation.many&&e.includes(t.name)).map(e=>e.name)},[p,H]),je=H?.operations.list?.hasSearch===!0,Me=je?q.search:``,Ne=d.useMemo(()=>({page:q.page,pageSize:q.pageSize,ordering:q.ordering===``?void 0:q.ordering,search:Me.length>0?Me:void 0,filters:Object.keys(q.filters).length>0||v!==void 0?{...q.filters,...v}:void 0,expand:Ae.length>0?Ae:void 0}),[q,Me,v,Ae]),Pe=se.getDefaultOptions().queries?.retry,Fe=d.useMemo(()=>Rn(Pe),[Pe]),Q=Jt(t,Ne,{enabled:H!==void 0,placeholderData:y.keepPreviousData,retry:Fe}),Ie=d.useRef(null);Q.data!==void 0&&(Ie.current={resource:t,data:Q.data});let Le=Ie.current?.resource===t?Ie.current.data:void 0,Re=In(Q.error),ze=Q.error!==null&&Q.error!==void 0,Be=Ln(Q.error)&&q.page>1;d.useEffect(()=>{if(!Be)return;let e=Le===void 0?1:Hn(Le.count,q.pageSize),t=q.page>e?e:q.page-1;J({page:Math.max(1,t)},{push:!1})},[Be,Le,q.page,q.pageSize,J]);let Ve=Re===401||Re===403,He=Q.data??(ze&&!Ve&&!Be?Le:void 0),Ue=Q.data===void 0&&He!==void 0,We=Se(),Ge=Q.fetchStatus===`paused`,Ke=d.useRef(We),qe=Q.refetch;d.useEffect(()=>{We&&!Ke.current&&ze&&qe(),Ke.current=We},[We,ze,qe]);let Je=Q.isFetching&&Q.isPlaceholderData===!0,Ye=be(Q.isFetching),[Xe,Ze]=Fi(ji(V),ne,Ii,Ri),Qe=L??Xe,$e=d.useCallback(e=>{L===void 0&&Ze(e),re?.(e)},[L,Ze,re]),[et,tt]=Fi(Mi(pe,V),so,Li,zi),nt=d.useCallback(e=>(T??Nn)(Un(e)),[T]),rt=H?.operations.update?.access,it=H?.operations.remove?.access,at=H?.operations.create?.access,ot=H!==void 0&&H.operations.detail!==void 0&&H.operations.remove===void 0,st=d.useCallback(e=>typeof M==`function`?M(e):M===void 0?Yn(rt,B,e)!==!1:M,[M,rt,B]),ct=d.useCallback(e=>typeof N==`function`?N(e):N===void 0?!ot&&Yn(it,B,e)!==!1:N,[N,ot,it,B]),lt=A!==void 0&&(te??(H?.operations.create!==void 0&&Yn(at,B)!==!1)),ut=j??`New ${fe}`,[dt,ft]=d.useState(null),pt=d.useCallback((e,t)=>{ft({row:e,trigger:t})},[]),mt=d.useRef(null),ht=d.useRef(null),gt=d.useRef(null),_t=d.useCallback(()=>mt.current??ht.current??gt.current,[]),vt=l!==void 0&&l.length>0,yt=o!==void 0||s!==void 0||c===!0,bt=vi[Qe].action,xt=d.useMemo(()=>{if(H===void 0)return[];let e=Er({fields:H.fields,columns:n,getRowLabel:T,showAuditFields:r});i!==void 0&&(e=[...e,...i]),a!==void 0&&(e=a(e));let t=vt?[$n({rowLabel:nt,resourceLabel:U})]:[],l=yt?[tr({rowActions:o,onEdit:s,canEdit:st,onDelete:c===!0?pt:void 0,canDelete:ct,buttonClassName:bt})]:[];return[...t,...e,...l]},[H,n,T,r,i,a,vt,yt,nt,U,o,s,st,c,pt,ct,bt]),St=d.useCallback(e=>{let t=xt.find(t=>t.id===e);return typeof t?.header==`string`?t.header:H?.fields.find(t=>t.name===e)?.label??sn(e)},[xt,H]),Ct=d.useMemo(()=>Object.fromEntries(et.map(e=>[e,!1])),[et]),$=d.useMemo(()=>He?.results??[],[He]),wt=He?.count,Tt=Hn(wt,q.pageSize),[Et,Dt]=d.useState({}),[Ot,kt]=d.useState(null),At=d.useCallback(e=>{let t=Fn(Y.current.ordering),n=typeof e==`function`?e(t):e,r=n[0];ye(r===void 0?`Sorting cleared.`:`Sorted by ${St(r.id)}, ${r.desc?`descending`:`ascending`}.`),J({ordering:Pn(n)??``,page:1},{push:!0})},[St,J]),jt=(0,b.useReactTable)({data:$,columns:xt,state:{sorting:X,rowSelection:Et,columnVisibility:Ct},manualSorting:!0,manualPagination:!0,manualFiltering:!0,pageCount:Tt,enableRowSelection:vt,onSortingChange:At,onRowSelectionChange:Dt,getRowId:e=>String(Un(e).id),getCoreRowModel:(0,b.getCoreRowModel)()}),Nt=d.useMemo(()=>Object.keys(Et).filter(e=>Et[e]),[Et]),Pt=d.useRef(Nt);Pt.current=Nt,d.useEffect(()=>{if(xe.current===null||Q.isFetching||Q.data===void 0)return;let e=xe.current;xe.current=null;let t=Q.data.count;ye(e===`page`?`Showing page ${q.page.toLocaleString()} of ${Hn(t,q.pageSize).toLocaleString()}.`:t===0?`No ${U} match.`:`${t.toLocaleString()} ${t===1?fe:U} match.`)},[Q.isFetching,Q.data,q.page,q.pageSize,U,fe]);let Ft=d.useRef(!0),It=d.useRef(!1);d.useEffect(()=>{Ft.current||It.current?(Ft.current=!1,It.current=!1):ye(Nt.length===0?`Selection cleared.`:`${Nt.length} selected.`)},[Nt.length]);let[Lt,Rt]=d.useState(null),[zt,Bt]=d.useState(null),[Vt,Ht]=d.useState({}),[Ut,Wt]=d.useState(null),[Kt,qt]=d.useState(null),Yt=d.useCallback(async(e,n)=>{let r=l?.[e];if(r===void 0)return;let i=[...Pt.current],a=lo(r.label)??`The action`;Bt(null),Ht({}),qt(null);let o;try{o=r.onClick(i)}catch(e){n?qt(e):Bt({kind:`failed`,actionLabel:a,error:e,count:i.length});return}if(!co(o))Wt(null);else{Rt(e);try{let e=(await o)?.failed??[];Wt(null),e.length>0?(Ht(Object.fromEntries(e.map(e=>[e.id,e.reason]))),Dt(Object.fromEntries(e.map(e=>[e.id,!0]))),Bt({kind:`partial`,actionLabel:a,failed:e.length,total:i.length})):(It.current=!0,Dt({}),ye(`${a}: done for ${i.length} ${i.length===1?fe:U}.`)),se.invalidateQueries({queryKey:Mt.resource(t)})}catch(e){n?qt(e):Bt({kind:`failed`,actionLabel:a,error:e,count:i.length})}finally{Rt(null)}}},[l,se,t,fe,U]),Xt=d.useCallback((e,t)=>{let n=l?.[e];n!==void 0&&((n.confirm??n.destructive===!0)===!1?Yt(e,!1):(qt(null),Wt({index:e,trigger:t})))},[l,Yt]),Zt=d.useCallback(()=>{Dt({}),Ht({}),Bt(null)},[]),Qt=za(gt),$t=R>0&&Qt!==void 0&&Qt<R?`cards`:`table`,en=d.useCallback(e=>{xe.current=`page`,J({page:e},{push:!0})},[J]),tn=d.useCallback(e=>{xe.current=`page`,J({pageSize:e,page:1},{push:!0})},[J]),nn=d.useCallback((e,t)=>{Je||(kt(e.column.id),e.column.getToggleSortingHandler()?.(t))},[Je]),rn=d.useCallback(()=>{qe()},[qe]),an=d.useCallback(()=>{se.invalidateQueries({queryKey:Mt.schema()})},[se]),on=d.useMemo(()=>Object.entries(q.filters).flatMap(([e,t])=>{let n=he.find(t=>t.name===e);return n===void 0?[]:[{field:e,label:n.label,value:uo(n,t)}]}),[q.filters,he]),cn=(0,f.jsx)(z.Loading,{columnCount:H===void 0?oo+ +!!vt+ +!!yt:jt.getVisibleLeafColumns().length,rowCount:q.pageSize,density:Qe,toolbar:H===void 0,layout:$t,selectable:vt,actions:yt}),ln;if(de.error!==null&&de.error!==void 0)ln=(0,f.jsx)(z.Error,{error:de.error,context:{action:`load`,resource:U},onRetry:an});else if(Ve)ln=Re===403?(0,f.jsx)(z.Forbidden,{resourceLabel:U,error:Q.error}):(0,f.jsx)(z.Error,{error:Q.error,context:{action:`view`,resource:U}});else if(He===void 0&&(Ge||!We&&ze))ln=(0,f.jsx)(z.Offline,{resourceLabel:U,hasRows:!1,onRetry:rn});else if(H===void 0||Be||He===void 0)ln=ze&&!Be&&H!==void 0?(0,f.jsx)(z.Error,{error:Q.error,context:{action:`load`,resource:U},onRetry:rn,retrying:Q.isFetching}):cn;else if($.length===0&&!Ue)ln=C??(Me!==``||on.length>0?(0,f.jsx)(z.NoResults,{resourceLabel:U,search:Me,filters:on,onClearFilters:ke}):(0,f.jsx)(z.NoRecords,{resourceLabel:U,itemLabel:fe,onCreate:lt?A:void 0,createLabel:ut}));else{let e=Ue||Ye&&Je;ln=(0,f.jsxs)(f.Fragment,{children:[$t===`cards`?(0,f.jsx)(rr,{table:jt,caption:W,resourceLabel:U,density:Qe,Card:z.RowCard,rowLabel:nt,useRowLabelAsTitle:T!==void 0,onRowClick:u,failures:Vt,columnLabel:St,ordering:q.ordering,onOrderingChange:e=>At(Fn(e)),busy:Je,dimmed:e,listRef:ht}):(0,f.jsx)(La,{table:jt,caption:W,density:Qe,busy:Je,sortTarget:Ot,slow:Ye,onSort:nn,onRowClick:u,failures:Vt,firstRowIndex:(q.page-1)*q.pageSize+1,totalCount:wt,dimmed:e,scrollRef:mt,keyboardNavigation:ae}),wt!==void 0&&wt>0&&(0,f.jsx)(z.Pagination,{page:q.page,pageCount:Tt,totalCount:wt,hasPrevious:Je?q.page>1:He.previous!==null&&He.previous!==void 0,hasNext:Je?q.page<Tt:He.next!==null&&He.next!==void 0,onPageChange:en,pageSize:q.pageSize,pageSizeOptions:_e.pageSizes,onPageSizeChange:tn,busy:Je})]})}let un=x===void 0?[`csv`,`xlsx`]:x===!1?[]:x,dn=un.length>0&&H?.operations.export!==void 0,fn=jt.getAllLeafColumns().filter(e=>!Qn(e.id)).map(e=>({id:e.id,label:St(e.id),visible:e.getIsVisible()})),pn=H!==void 0&&!Ve&&(je||he.length>0||S!==void 0||dn||ie||lt),mn=Ye?`Loading ${U}…`:ve;return(0,f.jsxs)(`div`,{ref:gt,className:D(`flex w-full min-w-0 flex-col gap-3`,oe),children:[(0,f.jsx)(`div`,{role:`status`,"aria-live":`polite`,"aria-atomic":`true`,className:`sr-only`,children:mn}),pn&&(0,f.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,f.jsx)(_i,{searchEnabled:je,searchValue:Ce,onSearchChange:we,filterFields:he,values:q.filters,onFilterChange:Oe,className:`min-w-64 flex-1`}),(0,f.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2`,children:[ie&&(0,f.jsx)(no,{density:Qe,onDensityChange:$e,columns:fn,onColumnVisibilityChange:(e,t)=>tt(t?et.filter(t=>t!==e):[...et.filter(t=>t!==e),e])}),dn&&(0,f.jsx)(Br,{resource:t,params:Ne,formats:un}),S,lt&&(0,f.jsxs)(Z,{size:`sm`,onClick:A,children:[(0,f.jsx)(Ki,{className:`h-4 w-4`}),ut]})]})]}),!We&&He!==void 0&&(0,f.jsx)(z.Offline,{resourceLabel:U,hasRows:!0,onRetry:rn}),ze&&!Ve&&!Be&&He!==void 0&&We&&(0,f.jsx)(z.RefetchError,{error:Q.error,context:{action:`load`,resource:U},onRetry:rn,retrying:Q.isFetching}),vt&&Nt.length>0&&(0,f.jsx)(z.BulkActions,{selectedIds:Nt,bulkActions:l,onClear:Zt,onAction:Xt,runningIndex:Lt,outcome:zt,pageRowCount:$.length,allPageRowsSelected:$.length>0&&jt.getIsAllPageRowsSelected(),totalCount:wt,resourceLabel:U}),ln,w,vt&&(0,f.jsx)(mo,{target:Ut,actions:l,count:Nt.length,one:fe,plural:U,pending:Ut!==null&&Lt===Ut.index,error:Kt,onConfirm:e=>void Yt(e,!0),onCancel:()=>{Wt(null),qt(null)},fallbackFocus:_t}),c===!0&&(0,f.jsx)(fo,{resource:t,target:dt,rowLabel:nt,onClose:()=>ft(null),onDeleted:e=>{ye(`Deleted “${e}”.`),ft(null)},fallbackFocus:_t})]})}function mo(e){let{target:t,actions:n,one:r,plural:i,pending:a,error:o,onConfirm:s,onCancel:c}=e,l=d.useRef({target:t,count:e.count});t!==null&&(l.current={target:t,count:e.count});let u=l.current.target,p=l.current.count,m=u===null?void 0:n[u.index],h=m===void 0?void 0:lo(m.label),g=typeof m?.confirm==`object`?m.confirm:void 0,_=`${p} ${p===1?r:i}`;return(0,f.jsx)(pr,{open:t!==null,title:g?.title??(h===void 0?`Apply to ${_}?`:`${h} ${_}?`),description:g?.description??(m?.destructive===!0?`This applies to all ${_} you selected, and can't be undone.`:`This applies to all ${_} you selected.`),confirmLabel:g?.confirmLabel??(h===void 0?`Continue`:`${h} ${_}`),pendingLabel:m?.pendingLabel,destructive:m?.destructive===!0,pending:a,error:o===null?void 0:o,errorContext:{action:(h??`change`).toLowerCase(),resource:_},onConfirm:()=>{t!==null&&s(t.index)},onCancel:c,returnFocus:()=>{let t=l.current.target?.trigger;return t!=null&&t.isConnected?t:e.fallbackFocus()}})}function ho(e,t,n,r){let i=It();return(0,y.useQuery)({...r,queryKey:Mt.detail(e,t,n),queryFn:({signal:r})=>i.request(jt(e,t),{query:Dt(n),signal:r})})}var go=`You have unsaved changes. Leave without saving them?`;function _o(e={}){let{dirty:t,enabled:n=!0,beforeUnload:r=!0,message:i=go,confirm:a}=e,[o,s]=d.useState(!1),c=n&&(t??o),l=d.useRef(c);l.current=c;let u=d.useRef(a);u.current=a;let f=d.useCallback(e=>{l.current=n&&e,s(e)},[n]);return d.useEffect(()=>{if(!c||!r)return;let e=e=>{l.current&&(e.preventDefault(),e.returnValue=``)};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[c,r]),{dirty:c,setDirty:f,isDirty:d.useCallback(()=>l.current,[]),shouldBlock:d.useCallback(()=>l.current?!(u.current??(e=>window.confirm(e)))(i):!1,[i]),message:i}}var vo=`This field is required.`,yo=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d{1,6})?)?$/;function bo(e){if(!yo.test(e))return e;let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toISOString()}function xo(e){if(e.length===0)return T.z.never();if(e.every(e=>typeof e==`string`))return T.z.enum(e);let t=e.map(e=>T.z.literal(e));return t.length===1?t[0]:T.z.union(t)}function So(e,t){let n=T.z.string();return e.format===`email`?n=n.email(`Enter a valid email address.`):e.format===`uri`||e.format===`url`?n=n.url(`Enter a valid URL.`):e.format===`uuid`&&(n=n.uuid(`Must be a valid UUID.`)),e.maxLength!==void 0&&(n=n.max(e.maxLength,`Ensure this field has no more than ${e.maxLength} characters.`)),t&&(n=n.min(1,vo)),n}function Co(e,t){let n=T.z.coerce.number();return t&&(n=n.int()),e.min!==void 0&&(n=n.min(e.min)),e.max!==void 0&&(n=n.max(e.max)),n}function wo(e,t){switch(e.relationValueType){case`uuid`:return T.z.string({required_error:vo}).uuid();case`integer`:return t?T.z.coerce.number().int():T.z.number({required_error:vo}).int();default:return T.z.string({required_error:vo}).min(1,vo)}}function To(e,t){let n=wo(e,!1),r=e.nullable?n.nullable():n;return t||(r=r.optional()),T.z.preprocess(t=>{if(t===``||t==null)return e.nullable?null:void 0;if(e.relationValueType===`integer`&&typeof t==`string`&&t.trim()!==``){let e=Number(t);return Number.isNaN(e)?t:e}return t},r)}function Eo(){return typeof File>`u`?T.z.string():T.z.union([T.z.instanceof(File),T.z.string()])}function Do(e,t){switch(e.kind){case`string`:case`text`:return So(e,t);case`integer`:return Co(e,!0);case`number`:return Co(e,!1);case`boolean`:return T.z.boolean();case`date`:{let e=T.z.string();return t?e.min(1,vo):e}case`datetime`:return(t?T.z.string().min(1,vo):T.z.string()).transform(bo);case`enum`:return xo(e.enumValues??[]);case`relation`:return e.relation?.many===!0?T.z.array(wo(e,!0)):To(e,t);case`file`:return Eo();case`json`:return T.z.unknown();case`array`:return T.z.array(T.z.unknown());case`unknown`:return T.z.unknown()}}function Oo(e,t){let n={};for(let r of e.fields){if(r.readOnly)continue;let e=r.required,i=Do(r,e);r.nullable&&(i=i.nullable()),(t===`update`||!r.required)&&(i=i.optional()),n[r.name]=i}return T.z.object(n)}j(`file-upload`,`FileUpload`);function ko(e,t){if(t===void 0||t.trim()===``)return!0;let n=t.split(`,`).map(e=>e.trim().toLowerCase()).filter(e=>e!==``);if(n.length===0)return!0;let r=e.name.toLowerCase(),i=e.type.toLowerCase();return n.some(e=>e.startsWith(`.`)?r.endsWith(e):e.endsWith(`/*`)?i.startsWith(e.slice(0,-1)):i===e)}function Ao(e){return e<1024?`${e} B`:e<1048576?`${Math.round(e/1024)} KB`:`${(e/1048576).toFixed(1)} MB`}function jo(e){let t=(e.split(/[?#]/,1)[0]??e).split(`/`).filter(e=>e!==``);return t[t.length-1]??e}function Mo(e,t,n){return t===`size`&&n.maxSize!==void 0?`${e.name} is larger than ${Ao(n.maxSize)}.`:`${e.name} isn't an accepted file type.`}function No(e){return(0,f.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,focusable:!1,...e,children:[(0,f.jsx)(`path`,{d:`M21 15v3a3 3 0 0 1-3 3H6a3 3 0 0 1-3-3v-3`}),(0,f.jsx)(`polyline`,{points:`7 8 12 3 17 8`}),(0,f.jsx)(`line`,{x1:`12`,y1:`3`,x2:`12`,y2:`15`})]})}function Po(e){return(0,f.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,focusable:!1,...e,children:[(0,f.jsx)(`line`,{x1:`18`,y1:`6`,x2:`6`,y2:`18`}),(0,f.jsx)(`line`,{x1:`6`,y1:`6`,x2:`18`,y2:`18`})]})}function Fo({buttonRef:e,dragging:t,multiple:n,uploading:r,children:i,className:a,...o}){let s=i;return r?s=(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(me,{className:`h-5 w-5 animate-spin`}),(0,f.jsx)(`span`,{children:`Uploading…`})]}):s===void 0&&(s=(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(No,{className:`h-5 w-5`}),(0,f.jsx)(`span`,{children:n?`Drag and drop files here, or click to browse`:`Drag and drop a file here, or click to browse`})]})),(0,f.jsx)(`button`,{ref:e,type:`button`,"data-dragging":t?`true`:void 0,className:D(`flex w-full flex-col items-center justify-center gap-1 rounded-md border border-dashed border-input bg-background px-4 py-6 text-sm text-muted-foreground ring-offset-background transition-colors hover:border-ring hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 aria-[invalid=true]:border-destructive data-[dragging=true]:border-ring data-[dragging=true]:bg-accent data-[dragging=true]:text-accent-foreground`,r&&`disabled:cursor-progress disabled:opacity-100`,a),...o,children:s})}function Io({file:e,name:t,size:n,onRemove:r}){return(0,f.jsxs)(`li`,{className:`flex items-center justify-between gap-2 rounded-md border border-border bg-muted-subtle px-3 py-1.5 text-sm`,children:[typeof e==`string`?(0,f.jsx)(`a`,{href:e,target:`_blank`,rel:`noreferrer`,className:`truncate font-medium text-primary underline underline-offset-4 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,children:t}):(0,f.jsxs)(`span`,{className:`truncate`,children:[t,(0,f.jsx)(`span`,{className:`ml-2 text-xs text-muted-foreground`,children:n})]}),r===void 0?null:(0,f.jsx)(`button`,{type:`button`,"aria-label":`Remove ${t}`,onClick:r,className:`rounded-sm p-1 text-muted-foreground hover:text-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,children:(0,f.jsx)(Po,{className:`h-4 w-4`})})]})}var Lo={Dropzone:Fo,FileRow:Io},Ro=d.forwardRef(function(e,t){let{value:n=null,onChange:r,accept:i,multiple:a=!1,disabled:o=!1,maxSize:s,onReject:c,rejectionMessage:l=Mo,error:u,uploading:p=!1,id:m,name:h,className:g,children:_,clearable:v=!0,slots:y}=e,{Dropzone:b,FileRow:x}={...Lo,...y},S=d.useRef(null),C=d.useRef(null);d.useImperativeHandle(t,()=>C.current,[]);let w=d.useId(),[T,E]=d.useState(!1),[ee,O]=d.useState([]),k=o||p,A=n==null?[]:Array.isArray(n)?n:[n],j=e=>{if(k)return;let t=[],n=[];for(let r of Array.from(e)){let e=null;if(ko(r,i)?s!==void 0&&r.size>s&&(e=`size`):e=`accept`,e===null){t.push(r);continue}c?.(r,e);let a=l(r,e,{accept:i,maxSize:s});a!=null&&a!==!1&&n.push(a)}O(n),t.length!==0&&r?.(a?t:t[0])},te=e=>{e.target.files!==null&&j(e.target.files),e.target.value=``},M=e=>{e.preventDefault(),E(!1),!k&&j(e.dataTransfer.files)},N=e=>{e.preventDefault(),k||E(!0)},P=e=>{if(r===void 0)return;C.current?.focus();let t=A.filter((t,n)=>n!==e);if(t.length===0){r(null);return}let n=t.filter(e=>typeof e!=`string`);r(a?n:n[0]??null)},F=u!=null&&u!==!1?[u]:[];F.push(...ee);let I=[e[`aria-describedby`],F.length>0?w:void 0].filter(Boolean).join(` `)||void 0,L=e[`aria-invalid`]??(u!=null&&u!==!1||void 0);return(0,f.jsxs)(`div`,{className:D(`space-y-2`,g),children:[(0,f.jsx)(b,{buttonRef:C,id:m,disabled:k,"aria-label":e[`aria-label`],"aria-labelledby":e[`aria-labelledby`],"aria-describedby":I,"aria-invalid":L,"aria-busy":p||void 0,onBlur:e.onBlur,onClick:()=>S.current?.click(),onDragOver:N,onDragEnter:N,onDragLeave:()=>E(!1),onDrop:M,dragging:T,multiple:a,uploading:p,children:_}),(0,f.jsx)(`input`,{ref:S,type:`file`,name:h,accept:i,multiple:a,disabled:k,onChange:te,tabIndex:-1,"aria-hidden":`true`,className:`sr-only`}),(0,f.jsx)(`span`,{className:`sr-only`,role:`status`,children:p?`Uploading…`:``}),F.length>0?(0,f.jsx)(`div`,{id:w,className:`space-y-1`,children:F.map((e,t)=>(0,f.jsx)(`p`,{role:`alert`,className:`text-sm text-destructive`,children:e},t))}):null,A.length>0?(0,f.jsx)(`ul`,{className:`space-y-1`,children:A.map((e,t)=>{let n=typeof e==`string`?jo(e):e.name;return(0,f.jsx)(x,{file:e,name:n,size:typeof e==`string`?void 0:Ao(e.size),onRemove:v&&!k?()=>P(t):void 0},typeof e==`string`?`url-${e}`:`file-${e.name}-${t}`)})}):null]})});function zo(e){let t=e.replace(/[_-]+/g,` `).trim();return t===``?e:t.charAt(0).toUpperCase()+t.slice(1)}function Bo(e){return String(e).padStart(2,`0`)}function Vo(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:`${t.getFullYear()}-${Bo(t.getMonth()+1)}-${Bo(t.getDate())}T${Bo(t.getHours())}:${Bo(t.getMinutes())}`}var Ho=/(?:Z|[+-]\d{2}:?\d{2})$/i;function Uo(e){if(Ho.test(e))return e;let t=new Date(e);if(Number.isNaN(t.getTime()))return e;let n=-t.getTimezoneOffset(),r=n>=0?`+`:`-`,i=Math.abs(n),a=`${r}${Bo(Math.floor(i/60))}:${Bo(i%60)}`;return`${t.getFullYear()}-${Bo(t.getMonth()+1)}-${Bo(t.getDate())}T${Bo(t.getHours())}:${Bo(t.getMinutes())}:${Bo(t.getSeconds())}${a}`}function Wo(e){return e===!0?!0:Array.isArray(e)?e.some(Wo):typeof e==`object`&&e?Object.values(e).some(Wo):!1}function Go(e){return typeof e==`object`&&e&&!Array.isArray(e)&&`id`in e?e.id:e}function Ko(e,t){switch(e.kind){case`string`:case`text`:return t==null?``:String(t);case`number`:case`integer`:return t??``;case`boolean`:return!!t;case`date`:return t==null||t===``?``:String(t).slice(0,10);case`datetime`:return t==null||t===``?``:Vo(String(t));case`enum`:return t??null;case`relation`:return e.relation?.many===!0?Array.isArray(t)?t.map(Go):[]:t==null?null:Go(t);case`file`:return t??null;case`json`:return t==null?``:JSON.stringify(t,null,2);default:return t}}function qo({fields:e,item:t,defaultValues:n}){let r={};for(let i of e){let e=n?.[i.name];e===void 0&&(e=i.default),t!==void 0&&i.name in t&&(e=t[i.name]),r[i.name]=Ko(i,e)}if(n!==void 0)for(let[e,t]of Object.entries(n))e in r||(r[e]=t);return r}function Jo(e){return{kind:`value`,value:e}}var Yo={kind:`omit`};function Xo(e){return e.nullable?Jo(null):Yo}function Zo(e,t){switch(e.kind){case`string`:case`text`:{if(t==null)return Xo(e);let n=String(t);return n===``&&e.nullable?Jo(null):Jo(n)}case`number`:case`integer`:{if(t==null||t===``)return Xo(e);let n=typeof t==`number`?t:Number(t);return Number.isFinite(n)?Jo(n):Xo(e)}case`boolean`:return t==null?Xo(e):Jo(!!t);case`date`:return t==null||t===``?Xo(e):Jo(String(t).slice(0,10));case`datetime`:return t==null||t===``?Xo(e):Jo(Uo(String(t)));case`enum`:return t==null||t===``?Xo(e):Jo((e.enumValues??[]).find(e=>String(e)===String(t))??t);case`relation`:return e.relation?.many===!0?Jo(t==null?[]:Array.isArray(t)?t.map(Go):[Go(t)]):t==null||t===``?Xo(e):Jo(Go(t));case`file`:return t==null?Xo(e):typeof t==`string`?Yo:Jo(t);case`json`:if(typeof t!=`string`)return t==null?Xo(e):Jo(t);if(t.trim()===``)return Xo(e);try{return Jo(JSON.parse(t))}catch{return{kind:`error`,message:`Enter valid JSON.`}}default:return Jo(t)}}function Qo({fields:e,raw:t,mode:n,dirtyFields:r}){let i=new Map(e.map(e=>[e.name,e])),a={},o=[];for(let[e,s]of Object.entries(t)){if(n===`update`&&!Wo(r?.[e]))continue;let t=i.get(e);if(t===void 0){s!==void 0&&(a[e]=s);continue}let c=Zo(t,s);c.kind===`error`?o.push({name:e,message:c.message}):c.kind===`value`&&c.value!==void 0&&(a[e]=c.value)}return{values:a,jsonErrors:o}}var $o=new Set([`boolean`,`file`]);function es(e){switch(e.format){case`email`:return`email`;case`uri`:case`url`:return`url`;case`password`:return`password`;default:return`text`}}function ts(e){return e==null?``:String(e)}function ns({field:e,control:t,inputId:n,labelId:r,describedBy:i,invalid:a,required:o=!1,disabled:s,revalidateWhileInvalid:c=!0,inputProps:l}){let{trigger:u}=(0,w.useFormContext)(),d={"aria-invalid":a||void 0,"aria-describedby":i},p=o&&!$o.has(e.kind)?!0:void 0;return(0,f.jsx)(w.Controller,{control:t,name:e.name,render:({field:t,fieldState:i})=>rs({field:e,rhf:t,change:n=>{t.onChange(n),c&&i.invalid&&u(e.name)},inputId:n,labelId:r,aria:d,ariaRequired:p,disabled:s,inputProps:l})})}function rs({field:e,rhf:t,change:n,inputId:r,labelId:i,aria:a,ariaRequired:o,disabled:s,inputProps:c}){switch(e.kind){case`text`:return(0,f.jsx)(Re,{ref:t.ref,id:r,name:t.name,rows:4,maxLength:e.maxLength,disabled:s,value:ts(t.value),onChange:e=>n(e.target.value),onBlur:t.onBlur,"aria-required":o,...a,...c});case`number`:case`integer`:return(0,f.jsx)(Ie,{ref:t.ref,id:r,name:t.name,type:`number`,inputMode:e.kind===`integer`?`numeric`:`decimal`,step:e.kind===`integer`?1:`any`,min:e.min,max:e.max,disabled:s,value:t.value==null?``:t.value,onChange:e=>n(e.target.value),onBlur:t.onBlur,"aria-required":o,...a,...c});case`boolean`:return(0,f.jsx)(`div`,{children:(0,f.jsx)(st,{ref:t.ref,id:r,disabled:s,checked:!!t.value,onCheckedChange:e=>n(e),onBlur:t.onBlur,...a,...c})});case`date`:case`datetime`:return(0,f.jsx)(Ie,{ref:t.ref,id:r,name:t.name,type:e.kind===`date`?`date`:`datetime-local`,disabled:s,value:ts(t.value),onChange:e=>n(e.target.value),onBlur:t.onBlur,"aria-required":o,...a,...c});case`enum`:{let i=e.enumValues??[],l=i.map(t=>({value:String(t),label:e.enumLabels?.[String(t)]??zo(String(t))}));return(0,f.jsx)(rt,{ref:t.ref,id:r,disabled:s,value:t.value==null?null:String(t.value),options:l,clearable:e.nullable,placeholder:`Select…`,onValueChange:e=>{n(e===null?null:i.find(t=>String(t)===e)??e)},onBlur:t.onBlur,"aria-required":o,...a,...c})}case`relation`:{let l=e.relation;return l===void 0?(0,f.jsx)(Ie,{ref:t.ref,id:r,name:t.name,type:`text`,disabled:s,value:ts(t.value),onChange:e=>n(e.target.value),onBlur:t.onBlur,"aria-required":o,...a,...c}):(0,f.jsx)(fi,{ref:t.ref,id:r,resource:l.resource,multiple:l.many,disabled:s,value:t.value??null,onChange:e=>n(e),onBlur:t.onBlur,"aria-labelledby":i,"aria-required":o,...a,...c})}case`file`:return(0,f.jsx)(Ro,{ref:t.ref,id:r,name:t.name,disabled:s,value:t.value??null,onChange:e=>n(e),onBlur:t.onBlur,...a,...c});case`json`:return(0,f.jsx)(Re,{ref:t.ref,id:r,name:t.name,rows:5,disabled:s,className:`font-mono`,value:typeof t.value==`string`?t.value:t.value==null?``:JSON.stringify(t.value,null,2),onChange:e=>n(e.target.value),onBlur:t.onBlur,"aria-required":o,...a,...c});default:return(0,f.jsx)(Ie,{ref:t.ref,id:r,name:t.name,type:es(e),maxLength:e.maxLength,disabled:s,value:ts(t.value),onChange:e=>n(e.target.value),onBlur:t.onBlur,"aria-required":o,...a,...c})}}var is=`[&>:not([hidden])~:not([hidden])]:mt-2`,as=`flex items-center justify-end gap-3 pt-2`;function os({field:e}){let t=e?.kind??`string`,n;switch(t){case`text`:n=(0,f.jsx)(Re,{rows:4,disabled:!0,tabIndex:-1});break;case`json`:n=(0,f.jsx)(Re,{rows:5,disabled:!0,tabIndex:-1,className:`font-mono`});break;case`boolean`:n=(0,f.jsx)(st,{disabled:!0,tabIndex:-1});break;case`file`:n=(0,f.jsx)(Ro,{disabled:!0});break;default:n=(0,f.jsx)(Ie,{disabled:!0,tabIndex:-1})}return(0,f.jsxs)(`div`,{className:D(`relative`,t===`boolean`?`w-fit`:`w-full`),children:[(0,f.jsx)(`div`,{className:`invisible`,children:n}),(0,f.jsx)($,{className:D(`absolute inset-0`,t===`boolean`?`rounded-full`:`rounded-md`)})]})}var ss=[0,1,2,3];function cs({fields:e,submitLabel:t,showSubmitRow:n}){return(0,f.jsxs)(`div`,{role:`status`,"aria-label":`Loading form`,"aria-busy":`true`,className:`space-y-5`,children:[(0,f.jsx)(`div`,{className:`space-y-5`,"aria-hidden":`true`,children:e===void 0?ss.map(e=>(0,f.jsxs)(`div`,{className:is,children:[(0,f.jsx)($,{className:D(`h-3.5`,e%2==0?`w-24`:`w-32`)}),(0,f.jsx)(os,{})]},e)):e.map(e=>(0,f.jsxs)(`div`,{className:is,children:[(0,f.jsxs)(lt,{children:[e.label,e.required&&e.kind!==`boolean`?(0,f.jsx)(`span`,{className:`text-destructive`,children:` *`}):null]}),(0,f.jsx)(os,{field:e}),e.description===void 0?null:(0,f.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e.description})]},e.name))}),n?(0,f.jsx)(`div`,{className:as,"aria-hidden":`true`,children:(0,f.jsxs)(`div`,{className:`relative`,children:[(0,f.jsx)(Z,{type:`button`,disabled:!0,tabIndex:-1,className:`invisible`,children:t}),(0,f.jsx)($,{className:`absolute inset-0 rounded-md`})]})}):null]})}function ls({action:e,resource:t}){return(0,f.jsx)(Ee,{action:e,resource:t})}function us(e){return(0,f.jsx)(Te,{...e})}function ds({title:e,errors:t}){let n=d.useId();return(0,f.jsxs)(`div`,{role:`alert`,"aria-labelledby":n,className:`rounded-md border border-destructive-border bg-destructive-subtle px-4 py-3 text-sm`,children:[(0,f.jsxs)(`p`,{id:n,className:`flex items-center gap-2 font-semibold text-foreground`,children:[(0,f.jsx)(U,{className:`h-4 w-4 shrink-0 text-destructive`}),e]}),(0,f.jsx)(`ul`,{className:`mt-2 list-disc space-y-1 pl-10 text-foreground marker:text-destructive`,children:t.map((e,t)=>(0,f.jsx)(`li`,{children:e.focus===void 0?(0,f.jsx)(`span`,{children:e.message}):(0,f.jsxs)(`a`,{href:e.href??`#`,onClick:t=>{t.preventDefault(),e.focus?.()},className:`rounded-sm underline decoration-destructive underline-offset-4 hover:no-underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`,children:[e.label,`: `,e.message]})},e.name??`form-${t}`))})]})}var fs={offline:W,network:W,forbidden:fe,unauthenticated:fe};function ps({error:e,context:t,onRetry:n,retrying:r=!1,onReload:i,reloading:a=!1}){let o=le(e,t),s=fs[o.kind]??U,c=o.retryable&&n!==void 0,l=o.kind===`conflict`&&i!==void 0;return(0,f.jsxs)(`div`,{role:`alert`,"data-error-kind":o.kind,className:`flex gap-3 rounded-md border border-destructive-border bg-destructive-subtle px-4 py-3 text-sm`,children:[(0,f.jsx)(s,{className:`mt-0.5 h-4 w-4 shrink-0 text-destructive`}),(0,f.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,f.jsx)(`p`,{className:`font-semibold text-foreground`,children:o.title}),(0,f.jsx)(`p`,{className:`mt-1 text-muted-foreground`,children:o.description}),o.detail===void 0?null:(0,f.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:o.detail}),c||l?(0,f.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-2`,children:[c?(0,f.jsx)(Ce,{variant:`outline`,size:`sm`,onClick:n,pending:r,pendingLabel:`Trying again…`,children:`Try again`}):null,l?(0,f.jsx)(Ce,{variant:`outline`,size:`sm`,onClick:i,pending:a,pendingLabel:`Loading the latest version…`,children:`Load the latest version`}):null]}):null]})]})}var ms=new Set([`non_field_errors`,`detail`,`__all__`]);function hs(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function gs(e){return zo(e.split(`.`).map(e=>/^\d+$/.test(e)?`item ${Number(e)+1}`:e).join(` `))}function _s(e){return e==null?[]:typeof e==`string`?e.trim()===``?[]:[e]:typeof e==`number`||typeof e==`boolean`?[String(e)]:Array.isArray(e)?e.flatMap((e,t)=>hs(e)&&!(`message`in e)?_s(e).map(e=>`Item ${t+1}: ${e}`):_s(e)):hs(e)?typeof e.message==`string`?[e.message]:Object.entries(e).flatMap(([e,t])=>_s(t).map(t=>ms.has(e)?t:`${gs(e)}: ${t}`)):[]}function vs(e){return/^\s*</.test(e)}function ys(e,{isField:t,labelOf:n=gs}){let r={},i=[],a=(e,t)=>{for(let r of _s(t))i.push(`${n(e)}: ${r}`)},o=(e,n)=>{if(t(e)){let t=_s(n);t.length>0&&(r[e]??=[]).push(...t)}else if(hs(n)&&typeof n.message!=`string`)for(let[t,r]of Object.entries(n))ms.has(t)?i.push(..._s(r)):o(`${e}.${t}`,r);else Array.isArray(n)&&n.some(hs)?n.forEach((t,n)=>{hs(t)?o(`${e}.${n}`,t):a(e,t)}):a(e,n)};if(typeof e==`string`)e.trim()!==``&&!vs(e)&&i.push(e.trim());else if(Array.isArray(e))i.push(..._s(e));else if(hs(e))for(let[t,n]of Object.entries(e))if(ms.has(t))i.push(..._s(n));else if(t===`code`&&typeof n==`string`&&`detail`in e)continue;else o(t,n);return{fields:Object.fromEntries(Object.entries(r).map(([e,t])=>[e,t.join(` `)])),root:i}}j(`resource-form`,`ResourceForm`);var bs={Loading:cs,Error:us,Forbidden:ls,ErrorSummary:ds,SubmitError:ps},xs=new Set([`string`,`text`,`number`,`integer`,`boolean`,`date`,`datetime`,`enum`,`relation`,`file`,`json`]);function Ss(e,t){return e.fields.filter(e=>!e.readOnly&&(xs.has(e.kind)||t?.[e.name]?.component!==void 0))}function Cs(e,t){return e.filter(e=>t?.[e.name]?.hidden!==!0).map(e=>{let n=t?.[e.name]?.label;return n===void 0?e:{...e,label:n}})}function ws(e){if(typeof e!=`object`||!e)return null;let t=e;return typeof t.status==`number`?{status:t.status,data:t.data}:null}var Ts=new Set([`invalid_type`,`invalid_enum_value`,`invalid_union`,`invalid_literal`]);function Es(e){return e==null||e===``||Array.isArray(e)&&e.length===0}function Ds(e,t){let n=e;for(let e of t.split(`.`)){if(typeof n!=`object`||!n)return!1;n=n[e]}return n!==void 0}function Os(e,t){let n=e;for(let e of t.split(`.`)){if(typeof n!=`object`||!n)return;n=n[e]}let r=n;return typeof r?.message==`string`?r:void 0}function ks(e,t,n){return e===1?t:n}function As({field:e,inputId:t,override:n,control:r,error:i,disabled:a}){if(n?.component!==void 0){let t=n.component;return(0,f.jsx)(t,{field:e,name:e.name,label:e.label,required:e.required,control:r,error:i,disabled:a,props:n.props})}let o=`${t}-label`,s=`${t}-error`,c=`${t}-description`,l=[e.description===void 0?null:c,i===void 0?null:s].filter(e=>e!==null).join(` `)||void 0,u=e.required&&e.kind!==`boolean`;return(0,f.jsxs)(`div`,{className:is,"data-karni-field":e.name,children:[(0,f.jsxs)(lt,{htmlFor:t,id:o,children:[e.label,u?(0,f.jsx)(`span`,{"aria-hidden":`true`,className:`text-destructive`,children:` *`}):null,u&&$o.has(e.kind)?(0,f.jsx)(`span`,{className:`sr-only`,children:` (required)`}):null]}),(0,f.jsx)(ns,{field:e,control:r,inputId:t,labelId:o,describedBy:l,invalid:i!==void 0,required:u,disabled:a,inputProps:n?.props}),e.description===void 0?null:(0,f.jsx)(`p`,{id:c,className:`text-sm text-muted-foreground`,children:e.description}),i===void 0?null:(0,f.jsxs)(`p`,{id:s,className:`flex items-start gap-1.5 text-sm font-medium text-foreground`,children:[(0,f.jsx)(U,{className:`mt-0.5 h-4 w-4 shrink-0 text-destructive`}),i]})]})}function js(e){let{resource:t,id:n,defaultValues:r,onSuccess:i,onError:a,fields:o,extraFields:s,transformSubmit:c,actions:l,submitLabel:u,className:p,schema:m,item:h,names:g,slotsResolved:_,validationMode:v=`onBlur`,reValidateMode:y=`onBlur`,autoFocus:b,guardUnsavedChanges:x=!0,onDirtyChange:S,reloadItem:T}=e,E=n===void 0?`create`:`update`,ee=an(t),O=d.useId(),k=d.useCallback(e=>`${O}-${e}`,[O]),A=d.useMemo(()=>Ss(m,o),[m,o]),j=d.useMemo(()=>Cs(A,o),[A,o]),te=d.useMemo(()=>qo({fields:A,item:h,defaultValues:r}),[A,h,r]),M=d.useMemo(()=>{let e=(0,C.zodResolver)(Oo(m,E)),t=new Set(m.fields.filter(e=>!e.required&&!e.nullable&&(e.kind!==`relation`||e.relation?.many!==!0)).map(e=>e.name)),n=new Set(m.fields.filter(e=>e.required).map(e=>e.name)),r=new Set(m.fields.filter(e=>!e.required&&(e.kind===`string`||e.kind===`text`)).map(e=>e.name));return async(i,a,o)=>{let s=Object.keys(i).filter(e=>i[e]===``&&r.has(e)),c=Object.fromEntries(Object.entries(i).filter(([e,n])=>!(n===null&&t.has(e))&&!(n===``&&r.has(e)))),l=await e(c,a,o);if(Object.keys(l.errors).length===0)for(let e of s)l.values[e]=``;for(let[e,t]of Object.entries(l.errors)){let r=t;r!==void 0&&n.has(e)&&Es(i[e])&&Ts.has(String(r.type))&&(r.message=`This field is required.`)}return l}},[m,E]),N=(0,w.useForm)({resolver:M,values:te,resetOptions:{keepDirtyValues:!0},mode:v,reValidateMode:y,shouldFocusError:!1}),{formState:P}=N,F=P.isSubmitting||ee.create.isPending||ee.update.isPending,I=d.useRef(null),L=P.isDirty&&I.current===null,ne=_o({dirty:L,enabled:x}),re=d.useRef(S);re.current=S,d.useEffect(()=>{re.current?.(L)},[L]);let[ie,R]=d.useState(null),[ae,oe]=d.useState([]),[z,se]=d.useState(!1),[ce,le]=d.useState(!1),[ue,B]=d.useState(``),V=d.useRef(null),[de,H]=d.useState(0),U=d.useRef(null),fe=d.useRef(null),W=d.useRef(null),pe=d.useRef(!1),me=d.useRef(null),he=e=>{V.current=e,H(e=>e+1)},G=d.useCallback(e=>j.find(t=>t.name===e)?.label??zo(e.replace(/\./g,` `)),[j]),ge=d.useCallback(e=>{N.setFocus(e);let t=document.getElementById(k(e));t!==null&&document.activeElement!==t&&t.focus()},[N,k]),K=[];for(let e of j){let t=Os(P.errors,e.name);t?.message!==void 0&&K.push({name:e.name,label:e.label,message:t.message,focus:()=>ge(e.name),href:`#${k(e.name)}`})}for(let[e,t]of Object.entries(P.errors)){if(e===`root`||j.some(t=>t.name===e))continue;let n=t?.message;typeof n==`string`&&K.push({name:e,label:G(e),message:n,focus:()=>ge(e),href:`#${k(e)}`})}let _e=K.length+ae.length,q=E===`create`?`create`:`save`,J=E===`create`?{action:`create`,resource:g.plural}:{action:`save`,resource:`this ${g.singular}`},Y=(e,t)=>{if(R(null),e.length+t.length>1||t.length>0){se(!0),B(``),he({kind:`summary`});return}let n=e[0];n!==void 0&&(se(!1),B(`${G(n.name)}: ${n.message}`),he({kind:`field`,name:n.name}))},X=e=>{let t=j.map(e=>e.name),n=Object.keys(e).filter(e=>e!==`root`&&!t.includes(e));return[...t,...n].flatMap(t=>{let n=Os(e,t)?.message;return n===void 0?[]:[{name:t,message:n}]})},ve=(e,t)=>{let n=ws(e);if(n===null||n.status!==400&&n.status!==422)return!1;let r=new Set(j.map(e=>e.name)),i=new Set(m.fields.map(e=>e.name)),a=ys(n.data,{isField:e=>r.has(e)||!i.has(e.split(`.`)[0])&&Ds(t,e),labelOf:G}),o=Object.keys(a.fields);if(o.length===0&&a.root.length===0)return!1;for(let[e,t]of Object.entries(a.fields))N.setError(e,{type:`server`,message:t});a.root.length>0&&N.setError(`root.server`,{type:`server`,message:a.root.join(` `)}),oe(a.root);let s=[...j.map(e=>e.name).filter(e=>o.includes(e)),...o.filter(e=>!r.has(e))].map(e=>({name:e,message:a.fields[e]??``}));return Y(s,a.root),!0},Z=N.handleSubmit(async e=>{oe([]),N.clearErrors(`root.server`);let{values:t,jsonErrors:r}=Qo({fields:A,raw:e,mode:E,dirtyFields:N.formState.dirtyFields});if(r.length>0){for(let e of r)N.setError(e.name,{type:`validate`,message:e.message});Y(r,[]);return}let o=c===void 0?t:c(t),s;try{s=n===void 0?await ee.create.mutateAsync(o):await ee.update.mutateAsync({id:n,values:o})}catch(t){ve(t,e)||(se(!1),R(t),he({kind:`banner`})),a?.(t);return}se(!1),R(null),I.current=E,ne.setDirty(!1),re.current?.(!1),B(E===`create`?`${zo(g.singular)} created.`:`Saved.`),he({kind:`restore`,element:me.current}),i?.(s)},e=>{oe([]),N.clearErrors(`root.server`),Y(X(e),[])}),ye=()=>{pe.current||(pe.current=!0,me.current=document.activeElement instanceof HTMLElement?document.activeElement:null,Z().finally(()=>{pe.current=!1}))};d.useEffect(()=>{let e=I.current;e===null||F||(e===`create`?N.reset(te,{keepDirtyValues:!1}):N.reset(N.getValues(),{keepDirtyValues:!1}),I.current=null)},[de,F,N,te]),d.useEffect(()=>{let e=V.current;if(!(e===null||F))switch(V.current=null,e.kind){case`field`:ge(e.name);break;case`summary`:U.current?.focus();break;case`banner`:fe.current?.focus();break;case`restore`:e.element!==null&&e.element.isConnected&&(document.activeElement===null||document.activeElement===document.body)&&e.element.focus()}},[de,F,ge]),d.useEffect(()=>{z&&_e===0&&se(!1)},[z,_e]);let be=K.map(e=>`${e.name}:${e.message}`).join(`|`),xe=d.useRef(new Set);d.useEffect(()=>{let e=new Set(K.map(e=>e.name??``)),t=K.find(e=>!xe.current.has(e.name??``));xe.current=e,t!==void 0&&!z&&B(`${t.label}: ${t.message}`)},[be]);let Se=b??E===`create`,we=j[0]?.name;d.useEffect(()=>{Se&&we!==void 0&&ge(we)},[]);let Te=T===void 0?void 0:()=>{le(!0),T().finally(()=>{le(!1),R(null)})},Ee=e=>{e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&!e.nativeEvent.isComposing&&(e.preventDefault(),e.stopPropagation(),ye())},De=e=>{if(e.key!==`Enter`||e.defaultPrevented||e.nativeEvent.isComposing)return;let t=e.target;t instanceof HTMLInputElement&&([`checkbox`,`radio`,`file`,`button`,`submit`,`reset`].includes(t.type)||(W.current?.querySelector(`[type='submit']:not(:disabled)`)??(e.preventDefault(),ye())))},Oe=e=>Os(P.errors,e)?.message,ke=_.SubmitError,Ae=_.ErrorSummary,je=K.length>0?`${K.length} ${ks(K.length,`field needs`,`fields need`)} attention`:`Couldn't ${q} ${E===`create`?g.singular:`this ${g.singular}`}`;return(0,f.jsx)(w.FormProvider,{...N,children:(0,f.jsxs)(`form`,{ref:W,onSubmit:e=>{e.preventDefault(),ye()},onKeyDownCapture:Ee,onKeyDown:De,noValidate:!0,"aria-busy":F||void 0,className:D(`space-y-5`,p),children:[ie===null?null:(0,f.jsx)(`div`,{ref:fe,tabIndex:-1,className:`rounded-md outline-none`,children:(0,f.jsx)(ke,{error:ie,context:J,onRetry:ye,retrying:F,onReload:Te,reloading:ce})}),z&&_e>0?(0,f.jsx)(`div`,{ref:U,tabIndex:-1,className:`rounded-md outline-none`,children:(0,f.jsx)(Ae,{title:je,errors:[...K,...ae.map(e=>({message:e}))]})}):null,(0,f.jsxs)(`fieldset`,{disabled:F,className:`m-0 min-w-0 space-y-5 border-0 p-0`,children:[A.map(e=>{let t=o?.[e.name];if(t?.hidden===!0)return null;let n=j.find(t=>t.name===e.name)??e;return(0,f.jsx)(As,{field:n,inputId:k(e.name),override:t,control:N.control,error:Oe(e.name),disabled:F},e.name)}),s]}),l===void 0?(0,f.jsx)(`div`,{className:as,children:(0,f.jsx)(Ce,{type:`submit`,pending:F,pendingLabel:E===`create`?`Creating…`:`Saving…`,children:u??(E===`create`?`Create`:`Save changes`)})}):l,(0,f.jsx)(`p`,{className:`sr-only`,role:`status`,"aria-live":`polite`,"aria-atomic":`true`,children:ue})]})})}function Ms(e){let{resource:t,id:n,slots:r,resourceLabel:i,className:a}=e,o=d.useMemo(()=>({...bs,...r}),[r]),s=Hr(t,i),c=On(t),l=n!==void 0,u=ho(t,n??``,void 0,{enabled:l}),p=l?`update`:`create`;if(c.error!=null&&c.data===void 0){let e=o.Error;return(0,f.jsx)(`div`,{className:a,children:(0,f.jsx)(e,{error:c.error,context:{action:`load`,resource:`this form`},onRetry:c.refetch,retrying:c.isFetching})})}if(l&&u.error!=null&&u.data===void 0){if(le(u.error).kind===`forbidden`||ws(u.error)?.status===403){let e=o.Forbidden;return(0,f.jsx)(`div`,{className:a,children:(0,f.jsx)(e,{action:`edit`,resource:`this ${s.singular}`})})}let e=o.Error;return(0,f.jsx)(`div`,{className:a,children:(0,f.jsx)(e,{error:u.error,context:{action:`load`,resource:`this ${s.singular}`},onRetry:()=>void u.refetch(),retrying:u.isFetching})})}if(c.data===void 0||l&&u.data===void 0){let t=o.Loading,n=c.data===void 0?void 0:Cs(Ss(c.data,e.fields),e.fields);return(0,f.jsx)(`div`,{className:a,children:(0,f.jsx)(t,{fields:n,mode:p,submitLabel:e.submitLabel??(l?`Save changes`:`Create`),showSubmitRow:e.actions===void 0})})}return(0,f.jsx)(js,{...e,schema:c.data,item:l?u.data:void 0,names:s,slotsResolved:o,reloadItem:l?()=>u.refetch():void 0})}function Ns(e){let t=e.replace(/[_-]+/g,` `).trim().toLowerCase();return t===``?e:t}function Ps(e){let t=Ns(e),n=t.split(` `),r=n.pop()??t,i=r;return/[^aeiou]ies$/.test(r)?i=`${r.slice(0,-3)}y`:/(?:ss|sh|ch|x|z)es$/.test(r)?i=r.slice(0,-2):/[^s]s$/.test(r)&&(i=r.slice(0,-1)),[...n,i].join(` `)}function Fs(e){return e instanceof F&&e.status>=400&&e.status<500}function Is(){let e=(0,y.useQueryClient)().getDefaultOptions().queries?.retry;return d.useCallback((t,n)=>Fs(n)?!1:typeof e==`function`?e(t,n):typeof e==`number`?t<e:typeof e==`boolean`?e:t<3,[e])}function Ls(){return TypeError(`The browser is offline.`)}function Rs(e,t){let n=Se(),r=d.useRef(n),i=d.useRef(t);i.current=t;let a=e!=null&&[`offline`,`network`].includes(le(e).kind);d.useEffect(()=>{let e=n&&!r.current;r.current=n,e&&a&&i.current()},[n,a])}j(`detail-view`,`ResourceDetail`);function zs(e){let t=(e.split(/[?#]/,1)[0]??e).split(`/`).filter(e=>e!==``);return t[t.length-1]??e}function Bs(e){let t=/^(\d{4})-(\d{2})-(\d{2})/.exec(e);if(t!==null)return new Date(Number(t[1]),Number(t[2])-1,Number(t[3])).toLocaleDateString();let n=new Date(e);return Number.isNaN(n.getTime())?e:n.toLocaleDateString()}function Vs(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()}function Hs({value:e}){return typeof e==`object`&&e?(0,f.jsx)(f.Fragment,{children:Nn(e)}):(0,f.jsx)(`code`,{className:`rounded bg-muted px-1 py-0.5 font-mono text-xs`,children:String(e)})}function Us({value:e}){return Array.isArray(e)?(0,f.jsx)(`span`,{className:`flex flex-wrap gap-1.5`,children:e.map((e,t)=>(0,f.jsx)(`span`,{className:`inline-flex items-center rounded-sm bg-secondary px-1.5 py-0.5 text-xs text-secondary-foreground`,children:(0,f.jsx)(Hs,{value:e})},t))}):(0,f.jsx)(Hs,{value:e})}function Ws(e){return e==null||e===``||Array.isArray(e)&&e.length===0}function Gs(e){let{field:t,value:n,Empty:r}=e;if(Ws(n))return(0,f.jsx)(r,{field:t});switch(t.kind){case`boolean`:return(0,f.jsx)(f.Fragment,{children:n?`Yes`:`No`});case`date`:return(0,f.jsx)(f.Fragment,{children:Bs(String(n))});case`datetime`:return(0,f.jsx)(f.Fragment,{children:Vs(String(n))});case`enum`:return(0,f.jsx)(f.Fragment,{children:t.enumLabels?.[String(n)]??zo(String(n))});case`relation`:return(0,f.jsx)(Us,{value:n});case`file`:return(0,f.jsx)(`a`,{href:String(n),target:`_blank`,rel:`noreferrer`,className:`rounded-sm font-medium text-primary underline underline-offset-4 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2`,children:zs(String(n))});case`json`:return(0,f.jsx)(`pre`,{className:`overflow-x-auto rounded-md bg-muted p-3 text-xs`,children:JSON.stringify(n,null,2)});case`number`:case`integer`:return(0,f.jsx)(f.Fragment,{children:typeof n==`number`?n.toLocaleString():String(n)});case`array`:return(0,f.jsx)(f.Fragment,{children:Array.isArray(n)?n.map(String).join(`, `):String(n)});default:return(0,f.jsx)(f.Fragment,{children:String(n)})}}function Ks(){return(0,f.jsx)(Be,{})}var qs=5,Js=[`w-48`,`w-64`,`w-32`,`w-56`,`w-40`];function Ys(e,t){switch(e?.kind){case`boolean`:return`w-10`;case`number`:case`integer`:return`w-16`;case`date`:return`w-24`;case`datetime`:return`w-40`;default:return Js[t%Js.length]??`w-48`}}function Xs(e){let{field:t,index:n,muted:r}=e,i=r?`my-0.5 h-3`:`my-0.5 h-4`;return(0,f.jsxs)(`div`,{className:D(`grid grid-cols-1 gap-1 sm:grid-cols-3 sm:gap-4`,r?`py-2`:`py-3`),children:[(0,f.jsx)(`div`,{children:(0,f.jsx)($,{className:D(i,r?`w-20`:`w-24`)})}),(0,f.jsx)(`div`,{className:`sm:col-span-2`,children:t?.kind===`json`&&!r?(0,f.jsx)($,{className:`h-16 w-full`}):(0,f.jsx)($,{className:D(i,Ys(t,n))})})]})}function Zs({fields:e,auditFields:t,slow:n}){let r=e??Array.from({length:qs},()=>void 0);return(0,f.jsxs)(`div`,{className:D(`space-y-6`,!n&&`invisible`),"aria-hidden":`true`,"data-testid":`resource-detail-skeleton`,children:[(0,f.jsx)(`div`,{className:`[&>*+*]:border-t [&>*+*]:border-border`,children:r.map((e,t)=>(0,f.jsx)(Xs,{field:e,index:t,muted:!1},e?.name??t))}),t!==void 0&&t.length>0?(0,f.jsxs)(`div`,{className:`rounded-md border border-border bg-muted-subtle px-4 py-2`,children:[(0,f.jsx)(`div`,{className:`py-1`,children:(0,f.jsx)($,{className:`my-0.5 h-3 w-14`})}),(0,f.jsx)(`div`,{className:`[&>*+*]:border-t [&>*+*]:border-border`,children:t.map((e,t)=>(0,f.jsx)(Xs,{field:e,index:t,muted:!0},e.name))})]}):null]})}function Qs({back:e,...t}){return(0,f.jsx)(Te,{...t,actions:e})}var $s=`flex w-full flex-col items-center gap-2 rounded-lg border border-border bg-muted-subtle px-6 py-8 text-center`;function ec({resourceLabel:e,back:t}){return(0,f.jsxs)(`div`,{role:`alert`,"data-error-kind":`not-found`,className:$s,children:[(0,f.jsx)(pe,{className:`mb-1 h-8 w-8 text-muted-foreground`}),(0,f.jsxs)(`p`,{className:`text-base font-semibold text-foreground`,children:[`Couldn't find this `,e]}),(0,f.jsxs)(`p`,{className:`max-w-128 text-sm text-muted-foreground`,children:[`The link may be wrong, or the `,e,` may have been deleted or not shared with you.`]}),t==null?null:(0,f.jsx)(`div`,{className:`mt-2 flex flex-wrap items-center gap-2`,children:t})]})}function tc({resourceLabel:e,back:t}){return(0,f.jsxs)(`div`,{className:$s,children:[(0,f.jsx)(V,{className:`mb-1 h-8 w-8 text-muted-foreground`}),(0,f.jsxs)(`p`,{className:`text-base font-semibold text-foreground`,children:[`The `,e,` was deleted`]}),t==null?null:(0,f.jsx)(`div`,{className:`mt-2 flex flex-wrap items-center gap-2`,children:t})]})}function nc(e){let{open:t,onOpenChange:n,itemLabel:r,resourceLabel:i,onConfirm:a,pending:o,error:s}=e,c=d.useRef(null),l=s!=null;return d.useEffect(()=>{l&&c.current?.focus()},[l,s]),(0,f.jsx)(fr,{open:t,onOpenChange:n,title:`Delete this ${i}?`,description:(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`span`,{className:`font-medium text-foreground`,children:r}),` will be deleted. This can't be undone.`]}),footer:(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(ar,{asChild:!0,children:(0,f.jsx)(Z,{variant:`outline`,disabled:o,children:`Cancel`})}),(0,f.jsx)(Ce,{variant:`destructive`,pending:o,pendingLabel:`Deleting…`,onClick:a,children:`Delete`})]}),children:l?(0,f.jsx)(Te,{ref:c,tabIndex:-1,variant:`inline`,className:`rounded-md border border-destructive-border bg-destructive-subtle p-3 focus:outline-none`,error:s,context:{action:`delete`,resource:`this ${i}`}}):null})}var rc={Loading:Zs,Error:Qs,NotFound:ec,EmptyValue:Ks,DeleteDialog:nc,Deleted:tc};function ic(e){let{field:t,item:n,override:r,muted:i,Empty:a}=e,o=n[t.name];return(0,f.jsxs)(`div`,{className:D(`grid grid-cols-1 gap-1 sm:grid-cols-3 sm:gap-4`,i?`py-2 text-xs`:`py-3 text-sm`),children:[(0,f.jsx)(`dt`,{className:`font-medium text-muted-foreground`,children:r?.label??t.label}),(0,f.jsx)(`dd`,{className:D(`sm:col-span-2`,i?`text-muted-foreground`:`text-foreground`),children:r?.render===void 0?(0,f.jsx)(Gs,{field:t,value:o,Empty:a}):r.render(o,n)})]})}function ac(e,t){return e===void 0?!0:typeof e==`function`?e(t):e}function oc(e,t,n){return e.filter(e=>!e.writeOnly&&e.kind!==`unknown`&&t?.[e.name]?.hidden!==!0&&(n===void 0||e.name in n))}function sc(e){let{resource:t,id:n,fields:r,sections:i,expand:a,title:o,actions:s,resourceLabel:c,back:l,onEdit:u,canEdit:p,enableDelete:m=!1,canDelete:h,onDeleted:g,slots:_,className:v}=e,b={...rc,..._},x=c??Ps(t),S=d.useId(),C=(0,y.useQueryClient)(),w=Se(),T=Is(),E=On(t),ee=(0,y.useIsFetching)({queryKey:Mt.schema()})>0,{remove:O}=an(t),k=ho(t,n,d.useMemo(()=>a!==void 0&&a.length>0?{expand:a}:void 0,[a]),{retry:T,enabled:!O.isSuccess}),[A,j]=d.useState(!1),te=d.useRef(null),M=O.isSuccess?k.data:void 0,N=M!==void 0;d.useEffect(()=>{N&&te.current?.focus()},[N]);let P=d.useRef(null),F=d.useRef(!1);d.useEffect(()=>{let e=F.current&&!A;if(F.current=A,!e||O.isSuccess)return;let t=setTimeout(()=>P.current?.focus(),0);return()=>clearTimeout(t)},[A,O.isSuccess]);let I=E.data,L=k.data,ne=I===void 0?E.error:void 0,re=k.error,ie=!(O.isPending||O.isSuccess)&&re!=null&&(L===void 0||!le(re).retryable),R=ne??(ie?re:void 0),ae=I===void 0||L===void 0,oe=R===void 0&&ae&&(!w||k.fetchStatus===`paused`),z=be(ae&&R===void 0&&!oe),se=d.useCallback(()=>{E.error!=null&&E.data===void 0&&C.refetchQueries({queryKey:Mt.schema()}),(k.error!=null||k.data===void 0)&&k.refetch()},[C,E.error,E.data,k]);Rs(R,se);let ce=k.isFetching||ee;if(M!==void 0)return(0,f.jsx)(`div`,{ref:te,tabIndex:-1,role:`status`,className:D(`focus:outline-none`,v),children:(0,f.jsx)(b.Deleted,{item:M,resourceLabel:x,back:l})});if(R!==void 0)return R===re&&le(R).kind===`not-found`?(0,f.jsx)(`div`,{className:v,children:(0,f.jsx)(b.NotFound,{error:R,resourceLabel:x,back:l})}):(0,f.jsx)(`div`,{className:v,children:(0,f.jsx)(b.Error,{error:R,context:{action:`view`,resource:`this ${x}`},onRetry:se,retrying:ce,back:l})});if(oe)return(0,f.jsx)(`div`,{className:v,children:(0,f.jsx)(b.Error,{error:Ls(),context:{action:`view`,resource:`this ${x}`},onRetry:se,retrying:!1,back:l})});let ue=I===void 0?void 0:jn(oc(I.fields,r,L)),B=u!==void 0&&p!==!1,V=m&&h!==!1,de=o!==void 0||s!==void 0||B||V?(0,f.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[o===void 0?(0,f.jsx)(`div`,{}):typeof o==`function`?L===void 0?(0,f.jsx)(`div`,{className:`py-1`,children:(0,f.jsx)($,{className:D(`h-5 w-32 sm:w-48`,!z&&`invisible`)})}):(0,f.jsx)(`h2`,{className:`text-lg font-semibold tracking-tight`,children:o(L)}):(0,f.jsx)(`h2`,{className:`text-lg font-semibold tracking-tight`,children:o}),s!==void 0||B||V?(0,f.jsx)(`div`,{className:`flex flex-wrap items-center gap-2`,children:L===void 0?(0,f.jsxs)(f.Fragment,{children:[typeof s==`function`?(0,f.jsx)($,{className:D(`h-10 w-24`,!z&&`invisible`)}):s,B?(0,f.jsx)($,{className:D(`h-10 w-16`,!z&&`invisible`)}):null,V?(0,f.jsx)($,{className:D(`h-10 w-20`,!z&&`invisible`)}):null]}):(0,f.jsxs)(f.Fragment,{children:[typeof s==`function`?s(L):s,u!==void 0&&B&&ac(p,L)?(0,f.jsx)(Z,{variant:`outline`,onClick:()=>u(L),children:`Edit`}):null,V&&ac(h,L)?(0,f.jsx)(Z,{ref:P,variant:`outline`,onClick:()=>{O.reset(),j(!0)},children:`Delete`}):null]})}):null]}):null,H=i!==void 0&&i.length>0?(0,f.jsx)(`div`,{className:`space-y-6`,children:i.map((e,t)=>(0,f.jsx)(`div`,{children:e},t))}):null;if(L===void 0||ue===void 0){let e=I===void 0?void 0:jn(oc(I.fields,r,void 0));return(0,f.jsxs)(`div`,{className:D(`space-y-6`,v),"aria-busy":`true`,children:[(0,f.jsx)(`span`,{role:`status`,"aria-label":`Loading details`,className:`sr-only`,children:z?`Loading this ${x}…`:``}),de,(0,f.jsx)(b.Loading,{fields:e?.domain,auditFields:e?.audit,slow:z}),H]})}let{domain:U,audit:fe}=ue;return(0,f.jsxs)(`div`,{className:D(`space-y-6`,v),children:[de,(0,f.jsx)(`dl`,{className:`[&>*+*]:border-t [&>*+*]:border-border`,children:U.map(e=>(0,f.jsx)(ic,{field:e,item:L,override:r?.[e.name],muted:!1,Empty:b.EmptyValue},e.name))}),fe.length>0?(0,f.jsxs)(`section`,{"aria-labelledby":S,className:`rounded-md border border-border bg-muted-subtle px-4 py-2`,children:[(0,f.jsx)(`h3`,{id:S,className:`py-1 text-xs font-medium uppercase tracking-wide text-muted-foreground`,children:`Record`}),(0,f.jsx)(`dl`,{className:`[&>*+*]:border-t [&>*+*]:border-border`,children:fe.map(e=>(0,f.jsx)(ic,{field:e,item:L,override:r?.[e.name],muted:!0,Empty:b.EmptyValue},e.name))})]}):null,H,V?(0,f.jsx)(b.DeleteDialog,{open:A,onOpenChange:e=>{O.isPending||j(e)},item:L,itemLabel:Nn(L),resourceLabel:x,pending:O.isPending,error:O.error,onConfirm:()=>O.mutate(n,{onSuccess:()=>{j(!1),g?.(L)}})}):null]})}function cc(e,t,n){return[...Mt.resource(e),`history`,String(t),n??{}]}function lc(e,t,n,r){let i=It();return(0,y.useQuery)({...r,queryKey:cc(e,t,n),queryFn:({signal:r})=>i.request(`${jt(e,t)}history/`,{query:{page_size:n?.pageSize,page:n?.page},signal:r})})}j(`change-history`,`ChangeHistory`);var uc={create:`Created`,update:`Updated`,delete:`Deleted`,restore:`Restored`,transition:`Transitioned`};function dc(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:t.toLocaleString()}function fc({value:e}){if(e==null||e===``)return(0,f.jsx)(Be,{});if(e===`[redacted]`)return(0,f.jsx)(`span`,{className:`italic text-muted-foreground`,children:`redacted`});let t=typeof e==`object`?JSON.stringify(e):String(e);return(0,f.jsx)(`span`,{className:`break-words`,children:t})}function pc({entry:e}){let t=Object.entries(e.diff);return(0,f.jsxs)(f.Fragment,{children:[(0,f.jsxs)(`div`,{className:`flex flex-wrap items-baseline gap-x-3 gap-y-1`,children:[(0,f.jsx)(`span`,{className:`font-medium`,children:uc[e.action]??e.action}),(0,f.jsx)(`time`,{dateTime:e.timestamp,className:`text-muted-foreground`,children:dc(e.timestamp)}),(0,f.jsx)(`span`,{className:`text-muted-foreground`,children:e.actor?.email??(0,f.jsx)(Be,{label:`no user recorded`})})]}),t.length>0?(0,f.jsx)(`dl`,{className:`mt-2 grid grid-cols-[max-content_1fr] items-baseline gap-x-3 gap-y-1`,children:t.map(([e,[t,n]])=>(0,f.jsxs)(d.Fragment,{children:[(0,f.jsx)(`dt`,{className:`font-mono text-xs text-muted-foreground`,children:e}),(0,f.jsxs)(`dd`,{className:`flex flex-wrap items-center gap-2`,children:[(0,f.jsx)(fc,{value:t}),(0,f.jsx)(`span`,{"aria-hidden":`true`,className:`text-muted-foreground`,children:`→`}),(0,f.jsx)(`span`,{className:`sr-only`,children:`changed to`}),(0,f.jsx)(fc,{value:n})]})]},e))}):(0,f.jsx)(`p`,{className:`mt-2 text-muted-foreground`,children:`No visible field changed.`})]})}function mc({rows:e,slow:t}){return(0,f.jsx)(`div`,{className:D(`space-y-2`,!t&&`invisible`),"aria-hidden":`true`,"data-testid":`change-history-loading`,children:Array.from({length:e},(e,t)=>(0,f.jsxs)(`div`,{className:`rounded-md border bg-card p-3 text-sm`,children:[(0,f.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1`,children:[(0,f.jsx)($,{className:`my-0.5 h-4 w-16`}),(0,f.jsx)($,{className:`my-0.5 h-4 w-36`}),(0,f.jsx)($,{className:`my-0.5 h-4 w-28`})]}),(0,f.jsxs)(`div`,{className:`mt-2 grid grid-cols-[max-content_1fr] items-center gap-x-3 gap-y-1`,children:[(0,f.jsx)($,{className:`h-3 w-16`}),(0,f.jsx)($,{className:D(`my-0.5 h-4`,t%2==0?`w-40`:`w-32`)}),(0,f.jsx)($,{className:`h-3 w-12`}),(0,f.jsx)($,{className:D(`my-0.5 h-4`,t%2==0?`w-32`:`w-48`)})]})]},t))})}function hc({children:e}){return(0,f.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e})}var gc={Loading:mc,Error:Te,Empty:hc,Entry:pc},_c=3;function vc({resource:e,id:t,pageSize:n,title:r=`History`,empty:i=`No changes recorded.`,resourceLabel:a,slots:o,className:s}){let c={...gc,...o},l=a??Ps(e),u=Is(),p=Se(),m=lc(e,t,n===void 0?void 0:{pageSize:n},{retry:u}),h=m.data===void 0?m.error:null,g=m.data===void 0&&h==null&&(!p||m.fetchStatus===`paused`),_=m.data===void 0&&h==null&&!g,v=be(_),y=d.useCallback(()=>{m.refetch()},[m]);Rs(h,y);let b={action:`view`,resource:`the history of this ${l}`},x;return x=h==null?g?(0,f.jsx)(c.Error,{error:Ls(),context:b,onRetry:y,retrying:!1}):m.data===void 0?(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`span`,{role:`status`,className:`sr-only`,children:v?`Loading the history…`:``}),(0,f.jsx)(c.Loading,{rows:Math.min(n??_c,_c),slow:v})]}):m.data.results.length===0?(0,f.jsx)(c.Empty,{children:i}):(0,f.jsx)(`ol`,{className:`space-y-2`,children:m.data.results.map(e=>(0,f.jsx)(`li`,{className:`rounded-md border bg-card p-3 text-sm`,"data-action":e.action,children:(0,f.jsx)(c.Entry,{entry:e})},e.id))}):(0,f.jsx)(c.Error,{error:h,context:b,onRetry:y,retrying:m.isFetching}),(0,f.jsxs)(`section`,{className:D(`space-y-3`,s),"aria-label":`Change history`,"aria-busy":_||void 0,children:[r===null?null:(0,f.jsx)(`h3`,{className:`text-base font-semibold`,children:r}),x]})}j(`resource-import`,`ResourceImport`);function yc(e,t,n){return`${e.toLocaleString()} ${e===1?t:n}`}function bc(e){if(!(e instanceof F)||typeof e.data!=`object`||e.data===null)return;let t=e.data;if(typeof t.detail==`string`)return t.detail;for(let e of Object.values(t)){if(typeof e==`string`)return e;if(Array.isArray(e)&&typeof e[0]==`string`)return e[0]}}var xc={upload:`This file can't be imported`,preview:`This mapping can't be previewed`,commit:`This import can't be committed`},Sc={forbidden:fe,offline:W,network:W};function Cc(e){let{error:t,context:n,onRetry:r,retrying:i=!1}=e;if(n?.action===`import`)return(0,f.jsx)(Te,{...e});let a=le(t,n),o=a.kind===`validation`,s=Sc[a.kind]??U;return(0,f.jsxs)(`div`,{role:`alert`,"data-error-kind":a.kind,className:`flex items-start gap-2 rounded-md border border-destructive-border bg-destructive-subtle p-3 text-sm`,children:[(0,f.jsx)(s,{className:`mt-0.5 h-4 w-4 shrink-0 text-destructive`}),(0,f.jsxs)(`div`,{className:`min-w-0 flex-1 space-y-1`,children:[(0,f.jsx)(`p`,{className:`font-medium text-foreground`,children:o?xc[n?.action??``]??`This can't be imported`:a.title}),(0,f.jsx)(`p`,{className:`text-muted-foreground`,children:o?bc(t)??`Check the file against the template, then try again.`:a.description}),!o&&a.detail!==void 0?(0,f.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:a.detail}):null,a.retryable&&r!==void 0?(0,f.jsx)(`div`,{className:`pt-2`,children:(0,f.jsx)(Ce,{variant:`outline`,size:`sm`,onClick:r,pending:i,pendingLabel:`Trying again…`,children:`Try again`})}):null]})]})}function wc({slow:e}){return(0,f.jsxs)(`div`,{className:D(`space-y-3`,!e&&`invisible`),"aria-hidden":`true`,"data-testid":`resource-import-loading`,children:[(0,f.jsxs)(`div`,{className:`flex flex-wrap items-end gap-3`,children:[(0,f.jsxs)(`div`,{className:`grid w-full max-w-96 gap-1.5`,children:[(0,f.jsx)($,{className:`h-3.5 w-24`}),(0,f.jsx)($,{className:`h-10 w-full`})]}),(0,f.jsx)($,{className:`h-10 w-20`})]}),(0,f.jsxs)(`div`,{className:`space-y-1`,children:[(0,f.jsx)($,{className:`my-0.5 h-3 w-96 max-w-full`}),(0,f.jsx)($,{className:`my-0.5 h-3 w-40 sm:hidden`})]})]})}function Tc({label:e,value:t}){return(0,f.jsxs)(`div`,{children:[(0,f.jsx)(`dt`,{className:`text-xs uppercase text-muted-foreground`,children:e}),(0,f.jsx)(`dd`,{className:`text-2xl font-semibold tabular-nums`,children:t})]})}function Ec({result:e}){let{created:t,updated:n,skipped:r,unchanged:i,errors:a}=e;return(0,f.jsxs)(`dl`,{className:`flex flex-wrap gap-6`,"data-testid":`import-stats`,children:[(0,f.jsx)(Tc,{label:`Created`,value:t}),(0,f.jsx)(Tc,{label:`Updated`,value:n}),(0,f.jsx)(Tc,{label:`Skipped`,value:(0,f.jsxs)(f.Fragment,{children:[r,` `,(0,f.jsxs)(`span`,{className:`text-sm font-normal text-muted-foreground`,children:[`(`,i,` unchanged, `,a,` with errors)`]})]})})]})}function Dc({problems:e}){return(0,f.jsx)(`div`,{className:`overflow-x-auto rounded-md border border-border`,children:(0,f.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,f.jsx)(`caption`,{className:`px-3 py-2 text-left text-sm font-medium text-foreground`,children:`Rows with errors`}),(0,f.jsx)(`thead`,{className:`bg-muted text-left text-xs uppercase text-muted-foreground`,children:(0,f.jsxs)(`tr`,{children:[(0,f.jsx)(`th`,{scope:`col`,className:`px-3 py-2 font-medium`,children:`Row`}),(0,f.jsx)(`th`,{scope:`col`,className:`px-3 py-2 font-medium`,children:`Field`}),(0,f.jsx)(`th`,{scope:`col`,className:`px-3 py-2 font-medium`,children:`Problem`})]})}),(0,f.jsx)(`tbody`,{children:e.map((e,t)=>(0,f.jsxs)(`tr`,{className:`border-t border-border`,children:[(0,f.jsx)(`th`,{scope:`row`,className:`px-3 py-2 text-left font-normal tabular-nums`,children:e.row}),(0,f.jsx)(`td`,{className:`px-3 py-2 font-mono text-xs`,children:e.field||(0,f.jsx)(Be,{label:`the whole row`})}),(0,f.jsx)(`td`,{className:`px-3 py-2`,children:e.message})]},`${e.row}-${e.field}-${t}`))})]})})}function Oc({job:e}){let t=e.rows_total>0?Math.round(e.rows_done*100/e.rows_total):0,n=e.status===`previewing`?`Previewing`:`Committing`,r=Math.min(100,Math.floor(t/25)*25);return(0,f.jsxs)(`div`,{className:`space-y-2`,children:[(0,f.jsxs)(`p`,{className:`text-sm tabular-nums`,children:[n,`… `,e.rows_done.toLocaleString(),` / `,e.rows_total.toLocaleString(),` rows`]}),(0,f.jsx)(`div`,{role:`progressbar`,"aria-label":`${n} ${e.file_name}`,"aria-valuemin":0,"aria-valuemax":100,"aria-valuenow":t,"aria-valuetext":`${e.rows_done} of ${e.rows_total} rows`,className:`h-2 w-full overflow-hidden rounded-full bg-muted`,children:(0,f.jsx)(`div`,{className:`h-full bg-primary transition-all`,style:{width:`${t}%`}})}),(0,f.jsx)(`span`,{role:`status`,className:`sr-only`,children:`${n} ${yc(e.rows_total,`row`,`rows`)}: ${r}% done.`})]})}function kc(e){let{open:t,onOpenChange:n,job:r,result:i,resourceLabel:a,onConfirm:o,pending:s,error:c}=e,l=d.useRef(null),u=c!=null;d.useEffect(()=>{u&&l.current?.focus()},[u,c]);let p=i.created+i.updated;return(0,f.jsxs)(fr,{open:t,onOpenChange:n,title:`Commit this import?`,description:`${r.file_name}: ${yc(p,`row`,`rows`)} will be saved to ${a}.`,footer:(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(ar,{asChild:!0,children:(0,f.jsx)(Z,{variant:`outline`,disabled:s,children:`Cancel`})}),(0,f.jsx)(Ce,{pending:s,pendingLabel:`Committing…`,onClick:o,children:`Commit import`})]}),children:[(0,f.jsxs)(`dl`,{className:`grid grid-cols-2 gap-4 sm:grid-cols-4`,"data-testid":`import-confirm-counts`,children:[(0,f.jsx)(Tc,{label:`Created`,value:i.created}),(0,f.jsx)(Tc,{label:`Updated`,value:i.updated}),(0,f.jsx)(Tc,{label:`Unchanged`,value:i.unchanged}),(0,f.jsx)(Tc,{label:`Failed`,value:i.errors})]}),i.errors>0?(0,f.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[yc(i.errors,`row has`,`rows have`),` errors and will not be imported. Fix them in the file and import it again.`]}):null,u?(0,f.jsx)(`div`,{ref:l,tabIndex:-1,className:`focus:outline-none`,children:(0,f.jsx)(Te,{variant:`inline`,className:`rounded-md border border-destructive-border bg-destructive-subtle p-3`,error:c,context:{action:`import`,resource:a}})}):null]})}var Ac={Loading:wc,Error:Cc,Progress:Oc,Summary:Ec,Problems:Dc,ConfirmCommit:kc};function jc(e){let{job:t,fields:n,mapping:r,onChange:i}=e,a=n.map(e=>({value:e.name,label:`${e.name}${e.required?` *`:``}${e.key?` (key)`:``}`}));return(0,f.jsx)(`div`,{className:`overflow-x-auto rounded-md border border-border`,children:(0,f.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,f.jsx)(`caption`,{className:`sr-only`,children:`Column mapping`}),(0,f.jsx)(`thead`,{className:`bg-muted text-left text-xs uppercase text-muted-foreground`,children:(0,f.jsxs)(`tr`,{children:[(0,f.jsx)(`th`,{scope:`col`,className:`px-3 py-2 font-medium`,children:`Column in the file`}),(0,f.jsx)(`th`,{scope:`col`,className:`px-3 py-2 font-medium`,children:`Field`})]})}),(0,f.jsx)(`tbody`,{children:t.columns.map(e=>(0,f.jsxs)(`tr`,{className:`border-t border-border`,children:[(0,f.jsx)(`th`,{scope:`row`,className:`px-3 py-2 text-left font-normal`,children:e}),(0,f.jsx)(`td`,{className:`px-3 py-2`,children:(0,f.jsx)(rt,{"aria-label":`Field for ${e}`,className:`h-9 w-auto min-w-48`,value:r[e]??``,options:a,clearable:!0,clearLabel:`Ignore this column`,onValueChange:t=>i(e,t??``)})})]},e))})]})})}function Mc({what:e}){return(0,f.jsxs)(`p`,{role:`status`,className:`text-sm text-muted-foreground`,children:[`You're offline. The `,e,` will be sent when you're back online.`]})}function Nc(e,t){return e===void 0?`upload`:jr(e)?`progress`:e.status===`uploaded`||e.status===`failed`||t?`map`:e.status===`done`?`done`:`previewed`}function Pc({resource:e,title:t=`Import`,onDone:n,resourceLabel:r,slots:i,className:a}){let o={...Ac,...i},s=r??Ns(e),c=It(),l=Is(),u=Se(),p=Ir(e,{retry:l}),m=Rr(e),[h,g]=d.useState(void 0),[_,v]=d.useState({}),[y,b]=d.useState(!1),[x,S]=d.useState(null),[C,w]=d.useState(!1),[T,E]=d.useState(null),ee=d.useId(),O=d.useId(),k=d.useRef(null),A=d.useRef(null),j=Lr(e,h).data,te=d.useRef(void 0);d.useEffect(()=>{j!==void 0&&te.current!==j.id&&(te.current=j.id,v(j.mapping))},[j]),d.useEffect(()=>{j?.status===`done`&&n?.(j)},[j?.status,j?.id]);let{upload:M,preview:N,commit:P}=m,F=M.isPending||N.isPending||P.isPending,I=Nc(j,y),L=d.useRef(I);d.useEffect(()=>{if(L.current===I)return;L.current=I;let e=setTimeout(()=>A.current?.focus(),0);return()=>clearTimeout(e)},[I]);let ne=d.useRef(null),re=d.useRef(!1);d.useEffect(()=>{let e=re.current&&!C;if(re.current=C,!e)return;let t=setTimeout(()=>ne.current?.focus(),0);return()=>clearTimeout(t)},[C]),d.useEffect(()=>{M.error!==null&&M.error!==void 0&&k.current?.focus()},[M.error]);let ie=p.data===void 0&&p.isPending,R=p.data===void 0&&p.error==null&&(!u||p.fetchStatus===`paused`),ae=p.data===void 0?p.error:null,oe=be(ie&&!R),z=d.useCallback(()=>{p.refetch()},[p]);Rs(ae,z);let se=e=>{b(!1),M.mutate({file:e},{onSuccess:e=>g(e.id)})},ce=e=>{e.preventDefault(),x!==null&&se(x)},ue=()=>{j!==void 0&&(b(!1),N.mutate({jobId:j.id,mapping:_}))},B=()=>{g(void 0),S(null),b(!1),M.reset(),N.reset(),P.reset()},V=t=>{E(null),Fr(c,e,t).catch(e=>E(e))},de=(0,f.jsxs)(`div`,{className:`flex flex-wrap items-baseline justify-between gap-2`,children:[t===null?null:(0,f.jsx)(`h3`,{className:`text-base font-semibold`,children:t}),p.data===void 0?ie?(0,f.jsx)($,{className:D(`h-5 w-56`,!oe&&`invisible`),"aria-hidden":`true`}):null:(0,f.jsxs)(`div`,{className:`flex items-baseline gap-3 text-sm`,children:[(0,f.jsx)(Z,{variant:`link`,size:`sm`,className:`h-auto px-0 underline`,onClick:()=>V(`xlsx`),children:`Download template (XLSX)`}),(0,f.jsx)(Z,{variant:`link`,size:`sm`,className:`h-auto px-0 underline`,"aria-label":`CSV template`,onClick:()=>V(`csv`),children:`CSV`})]})]}),H;if(ae!=null)H=(0,f.jsx)(o.Error,{error:ae,context:{action:`import`,resource:s},onRetry:z,retrying:p.isFetching});else if(R)H=(0,f.jsx)(o.Error,{error:Ls(),context:{action:`import`,resource:s},onRetry:z,retrying:!1});else if(p.data===void 0)H=(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`span`,{role:`status`,className:`sr-only`,children:oe?`Loading the import form…`:``}),(0,f.jsx)(o.Loading,{slow:oe})]});else if(I===`upload`){let e=M.error;H=(0,f.jsxs)(`div`,{className:`space-y-3`,children:[(0,f.jsxs)(`form`,{onSubmit:ce,className:`space-y-2`,children:[(0,f.jsxs)(`div`,{className:`flex flex-wrap items-end gap-3`,children:[(0,f.jsxs)(`div`,{className:`grid w-full max-w-96 gap-1.5`,children:[(0,f.jsx)(lt,{htmlFor:ee,children:`File to import`}),(0,f.jsx)(Ie,{id:ee,type:`file`,name:`file`,accept:`.csv,.xlsx`,required:!0,className:`cursor-pointer`,"aria-describedby":O,"aria-invalid":e!=null&&le(e).kind===`validation`||void 0,onChange:e=>S(e.target.files?.[0]??null)})]}),(0,f.jsx)(Ce,{type:`submit`,pending:M.isPending,pendingLabel:`Uploading…`,children:`Upload`})]}),(0,f.jsxs)(`p`,{id:O,className:`text-xs text-muted-foreground`,children:[`CSV or XLSX with a header row, up to `,p.data.max_rows.toLocaleString(),` rows. The template lists the columns.`]})]}),M.isPaused?(0,f.jsx)(Mc,{what:`file`}):null,e==null?null:(0,f.jsx)(`div`,{ref:k,tabIndex:-1,className:`focus:outline-none`,children:(0,f.jsx)(o.Error,{error:e,context:{action:`upload`,resource:s},onRetry:x===null?void 0:()=>se(x),retrying:M.isPending})})]})}else if(j===void 0)H=null;else if(I===`progress`)H=(0,f.jsx)(o.Progress,{job:j});else if(I===`map`){let e=j.fields??p.data.fields;H=(0,f.jsxs)(`div`,{className:`space-y-3`,children:[j.error===null?null:(0,f.jsxs)(`div`,{role:`alert`,className:`flex items-start gap-2 rounded-md border border-destructive-border bg-destructive-subtle p-3 text-sm`,children:[(0,f.jsx)(U,{className:`mt-0.5 h-4 w-4 shrink-0 text-destructive`}),(0,f.jsxs)(`div`,{className:`space-y-1`,children:[(0,f.jsx)(`p`,{className:`font-medium text-foreground`,children:`The import failed`}),(0,f.jsx)(`p`,{className:`text-muted-foreground`,children:j.error})]})]}),(0,f.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[j.file_name,` has `,j.rows_total,` rows. Map each column to a field. Blank cells leave a field unchanged.`]}),(0,f.jsx)(jc,{job:j,fields:e,mapping:_,onChange:(e,t)=>v(n=>({...n,[e]:t}))}),N.isPaused?(0,f.jsx)(Mc,{what:`preview`}):null,N.error!==null&&N.error!==void 0?(0,f.jsx)(o.Error,{error:N.error,context:{action:`preview`,resource:s},onRetry:ue,retrying:N.isPending}):null,(0,f.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,f.jsx)(Ce,{onClick:ue,pending:N.isPending,pendingLabel:`Previewing…`,children:`Preview`}),(0,f.jsx)(Z,{variant:`outline`,onClick:B,disabled:F,children:`Upload another file`})]})]})}else{let e=j.result,t=I===`done`;H=(0,f.jsxs)(`div`,{className:`space-y-3`,children:[(0,f.jsxs)(`p`,{role:`status`,className:`text-sm text-muted-foreground`,children:[t?`Imported`:`Previewed`,` `,j.file_name,` (`,j.rows_total,` rows).`,t?null:` Nothing is saved yet.`]}),e===null?null:(0,f.jsx)(o.Summary,{job:j,result:e}),j.problems.length>0?(0,f.jsx)(o.Problems,{job:j,problems:j.problems}):null,(0,f.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:t?(0,f.jsx)(Z,{variant:`outline`,onClick:B,children:`Import another file`}):(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(Z,{ref:ne,onClick:()=>{P.reset(),w(!0)},disabled:F||e===null,children:`Commit`}),(0,f.jsx)(Z,{variant:`outline`,onClick:()=>b(!0),disabled:F,children:`Change the mapping`})]})}),!t&&e!==null?(0,f.jsx)(o.ConfirmCommit,{open:C,onOpenChange:e=>{P.isPending||w(e)},job:j,result:e,resourceLabel:s,pending:P.isPending,error:P.isPaused?Ls():P.error,onConfirm:()=>P.mutate(j.id,{onSuccess:()=>w(!1)})}):null]})}return(0,f.jsxs)(`section`,{className:D(`space-y-3`,a),"aria-label":`Import`,"aria-busy":ie||void 0,children:[de,T===null?null:(0,f.jsx)(Te,{variant:`inline`,error:T,context:{action:`download the template for`,resource:s}}),(0,f.jsx)(`div`,{ref:A,tabIndex:-1,className:`focus:outline-none`,"data-step":I,children:H})]})}j(`login-form`,`LoginForm`);var Fc=`[&>:not([hidden])~:not([hidden])]:mt-1`,Ic=class extends Error{constructor(){super(`This account needs a two-factor code, but the app has not enabled that step.`),this.name=`TwoFactorUnavailable`}};function Lc(e){let t=e.data,n=typeof t==`object`&&t?t.detail:t,r=typeof n==`string`?/available in (\d+) seconds?/i.exec(n):null;return r?.[1]===void 0?void 0:Number(r[1])}function Rc(e){if(typeof e==`object`&&e)for(let t of Object.values(e)){if(typeof t==`string`)return t;if(Array.isArray(t)&&typeof t[0]==`string`)return t[0]}}function zc(e){if(e instanceof Ic)return{kind:`unauthenticated`,title:`This account needs a two-factor code`,description:`The app has not enabled that step. Ask the site's administrator.`,retryable:!1};if(e instanceof F){if(e.status===401)return{kind:`unauthenticated`,title:`That email and password do not match`,description:`Check both and try again.`,retryable:!1,status:401};if(e.status===400)return{kind:`validation`,title:`Check your email and password`,description:Rc(e.data)??`Fill in both fields, then try again.`,retryable:!1,status:400};if(e.status===429){let t=Lc(e);return{kind:`rate-limited`,title:`Too many sign-in attempts`,description:t===void 0?`Wait a few minutes, then try again.`:`Wait ${t} ${t===1?`second`:`seconds`}, then try again.`,retryable:!0,status:429}}}return le(e,{action:`sign in`})}function Bc({id:e,described:t}){let n=t.kind===`offline`||t.kind===`network`?W:U;return(0,f.jsxs)(`div`,{id:e,role:`alert`,"data-error-kind":t.kind,className:`flex items-start gap-2 rounded-md border border-destructive-border bg-destructive-subtle p-3 text-sm`,children:[(0,f.jsx)(n,{className:`mt-0.5 h-4 w-4 shrink-0 text-destructive`}),(0,f.jsxs)(`div`,{className:`space-y-1`,children:[(0,f.jsx)(`p`,{className:`font-medium text-foreground`,children:t.title}),(0,f.jsx)(`p`,{className:`text-muted-foreground`,children:t.description}),t.detail!==void 0&&t.kind!==`rate-limited`?(0,f.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:t.detail}):null]})]})}var Vc={Error:Bc};function Hc({onSuccess:e,on2FA:t,title:n=`Sign in`,description:r,submitLabel:i=`Sign in`,disabled:a=!1,autoFocus:o=!0,slots:s,className:c}){let l={...Vc,...s},{login:u}=qt(),p=d.useId(),m=`${p}-error`,[h,g]=d.useState(!1),[_,v]=d.useState(null),y=d.useRef(null),b=d.useRef(null),x=d.useRef(null),S=d.useRef(0),C=_===null?null:zc(_.error),w=_!==null&&_.error instanceof F&&(_.error.status===401||_.error.status===400);d.useEffect(()=>{if(_===null||h)return;let e=zc(_.error);_.error instanceof F&&_.error.status===401?b.current?.focus():e.kind===`validation`?y.current?.focus():x.current?.focus()},[_,h]);async function T(n){n.preventDefault();let r=new FormData(n.currentTarget);S.current+=1;let i=S.current;g(!0),v(null);try{let n=await u(String(r.get(`email`)??``),String(r.get(`password`)??``));`ok`in n?e?.(n.user):t===void 0?v({error:new Ic,attempt:i}):t(n.ephemeralToken)}catch(e){e instanceof F&&e.status===401&&b.current!==null&&(b.current.value=``),v({error:e,attempt:i})}finally{g(!1)}}return(0,f.jsxs)(`form`,{className:D(`space-y-4`,c),onSubmit:e=>void T(e),"aria-busy":h,noValidate:!1,children:[n===null?null:(0,f.jsx)(`h2`,{className:`text-lg font-semibold`,children:n}),r===void 0?null:(0,f.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:r}),(0,f.jsxs)(`div`,{className:Fc,children:[(0,f.jsx)(lt,{htmlFor:`${p}-email`,children:`Email`}),(0,f.jsx)(Ie,{ref:y,id:`${p}-email`,name:`email`,type:`email`,autoComplete:`email`,autoFocus:o,required:!0,disabled:a||h,className:D(w&&`border-destructive`),"aria-invalid":w||void 0,"aria-describedby":_===null?void 0:m})]}),(0,f.jsxs)(`div`,{className:Fc,children:[(0,f.jsx)(lt,{htmlFor:`${p}-password`,children:`Password`}),(0,f.jsx)(Ie,{ref:b,id:`${p}-password`,name:`password`,type:`password`,autoComplete:`current-password`,required:!0,disabled:a||h,className:D(w&&`border-destructive`),"aria-invalid":w||void 0,"aria-describedby":_===null?void 0:m})]}),_!==null&&C!==null?(0,f.jsx)(d.Fragment,{children:(0,f.jsx)(l.Error,{id:m,error:_.error,context:{action:`sign in`},described:C})},_.attempt):null,(0,f.jsx)(Ce,{ref:x,type:`submit`,disabled:a,pending:h,pendingLabel:`Signing in…`,children:i})]})}j(`auth-guard`,`AuthGuard`);function Uc({className:e}){let t=d.useId();return(0,f.jsxs)(`section`,{"aria-labelledby":t,className:D(`mx-auto w-full max-w-96 space-y-4 rounded-lg border border-border bg-card p-6 text-card-foreground`,e),children:[(0,f.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,f.jsx)(fe,{className:`mt-0.5 h-5 w-5 shrink-0 text-muted-foreground`}),(0,f.jsxs)(`div`,{className:`space-y-1`,children:[(0,f.jsx)(`h2`,{id:t,className:`text-lg font-semibold`,children:`Sign in to continue`}),(0,f.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`You need to be signed in to see this.`})]})]}),(0,f.jsx)(Hc,{title:null})]})}function Wc({user:e,className:t}){return(0,f.jsx)(Ee,{className:t,description:(0,f.jsxs)(f.Fragment,{children:[`You're signed in as `,(0,f.jsx)(`span`,{className:`font-medium text-foreground`,children:e.email}),`, and your role doesn't include this. Ask an administrator if you need access.`]})})}var Gc={Anonymous:Uc,Denied:Wc},Kc=[],qc=!1;function Jc(){qc||(typeof process>`u`?void 0:process.env.NODE_ENV)!==`production`&&(qc=!0,console.warn("[karni-ui] An <AuthGuard> refused and rendered nothing because it has no fallback. From @karni/ui 1.0 a guard explains a refusal by default (a sign-in prompt, or PermissionDenied). Pass `explain` to opt in now, or `fallback={null}` to keep rendering nothing. See https://cbsshekhawat18-lab.github.io/karni/migrations/0.4/"))}function Yc(e){let{roles:t,fallback:n,anonymous:r,denied:i,loading:a=null,slots:o,className:s,children:c}=e,l={...Gc,...o},u=e.explain===!0||o!==void 0,{status:d,user:p}=qt(),m=t??Kc,h=n!==void 0;return d===`loading`?(0,f.jsx)(f.Fragment,{children:a}):d!==`authenticated`||p===null?r===void 0?h?(0,f.jsx)(f.Fragment,{children:n}):u?(0,f.jsx)(l.Anonymous,{roles:m,className:s}):(Jc(),null):(0,f.jsx)(f.Fragment,{children:r}):m.length>0&&!m.some(e=>p.roles.includes(e))?i===void 0?h?(0,f.jsx)(f.Fragment,{children:n}):u?(0,f.jsx)(l.Denied,{user:p,roles:m,className:s}):(Jc(),null):(0,f.jsx)(f.Fragment,{children:i}):(0,f.jsx)(f.Fragment,{children:c})}function Xc(){let{roles:e,status:t}=qt();return(0,d.useMemo)(()=>({isAuthenticated:t===`authenticated`,hasRole:(...n)=>t===`authenticated`&&n.some(t=>e.includes(t))}),[e,t])}j(`page-shell`,`Page`);function Zc({title:e,description:t,actions:n,className:r}){return(0,f.jsxs)(`header`,{className:D(`flex flex-wrap items-start justify-between gap-4`,r),children:[(0,f.jsxs)(`div`,{className:`grid gap-1`,children:[e,t]}),n]})}function Qc({children:e}){return(0,f.jsx)(`h1`,{className:`text-2xl font-semibold tracking-tight text-foreground`,children:e})}function $c({children:e}){return(0,f.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:e})}function el({children:e}){return(0,f.jsx)(`div`,{className:`flex shrink-0 items-center gap-2`,children:e})}var tl={Header:Zc,Title:Qc,Description:$c,Actions:el},nl=d.forwardRef(({title:e,description:t,actions:n,header:r,slots:i,headerClassName:a,contentClassName:o,className:s,children:c,...l},u)=>{let{Header:d,Title:p,Description:m,Actions:h}={...tl,...i};return(0,f.jsxs)(`section`,{ref:u,className:D(`flex w-full flex-col gap-6`,s),...l,children:[r??(0,f.jsx)(d,{className:a,title:(0,f.jsx)(p,{children:e}),description:t==null?null:(0,f.jsx)(m,{children:t}),actions:n==null?null:(0,f.jsx)(h,{children:n})}),(0,f.jsx)(`div`,{className:D(`flex flex-col gap-4`,o),children:c})]})});nl.displayName=`Page`;var rl=`0 0 1000 1000`,il=[{fill:`#000000`,d:`M495.8 884.4C366.3 877.9 255.3 816.3 182.4 710.5C128.6 632.2 103.2 521.3 115 415.5C128.3 296.3 188.2 205.8 290.9 150.2C389.1 97 470.1 78.3 564.8 87C689.6 98.4 790.1 167.2 844.3 278.1C896.3 384.6 901.7 498.4 860.4 619.6C833.4 698.7 806.7 746.3 766.3 787.1C699.4 854.6 601.9 889.7 495.8 884.4Z`},{fill:`#FB5D08`,d:`M355.6 514.1C355.6 509.2 355.7 507.3 355.8 509.8C355.9 512.3 355.9 516.3 355.8 518.7C355.7 521 355.6 519 355.6 514.1ZM677.1 423C637.3 415.7 624.1 366.4 654.9 340.2C672.8 325 696 324.3 713.7 338.5C741 360.3 735.8 403.2 704.1 418.6C696.1 422.4 684.6 424.3 677.1 423ZM330.5 421.6C299.1 415 283.8 379.9 300.6 352.7C317.1 325.8 352.4 320.7 373.7 342.2C398.9 367.6 387.2 410.3 352.3 420.8C347.4 422.3 335.7 422.7 330.5 421.6ZM504.5 399.6C466.4 392.2 453.2 345.4 481.5 318.2C509.6 291.1 556 308.2 560.5 347.3C564.1 377.9 534.5 405.5 504.5 399.6ZM349.4 395.9C367.2 387.1 367.7 363.1 350.2 354.5C329.3 344.3 308.5 369.4 321.8 388.6C327.9 397.5 339.8 400.7 349.4 395.9ZM694 395.9C716 385.1 709 352 684.8 352C665.4 352 654.8 375.3 667.3 390.4C673.5 397.8 685.2 400.2 694 395.9ZM522.4 373.7C534.6 368 539.9 353.6 534.2 341.9C525.3 323.9 501.3 323.8 492.5 341.8C482.8 361.3 503 382.8 522.4 373.7Z`},{fill:`#FFFFFF`,d:`M363 677.8C348.7 675.4 341.3 657.2 334.1 606.9C326.6 554.4 325.7 485.2 332.2 459.2C336.3 442.9 349.3 435.9 362.9 442.6C374.7 448.4 394.4 475.1 427.1 529.5C428.9 532.4 430.5 534.9 430.8 534.9C431 534.9 433.5 530.7 436.3 525.6C486 435.8 497.3 419.9 512.2 419.2C523.9 418.6 531.9 426.3 550 455.6C555.3 464.3 582.5 513.2 591.4 530.3C592.7 532.8 594 534.9 594.2 534.9C594.4 534.9 595.9 532.7 597.5 530C621.8 490.2 643.6 458.3 652.7 449.5C668.6 434.2 686.9 437.8 692.6 457.4C703.9 496.4 693.7 637.6 677.5 666.3C673 674.5 663.4 679.5 655.8 677.8C642.6 674.9 633.9 663.4 598.7 602.7C592.7 592.3 593.3 593.1 592.3 594.4C590.8 596.2 572.8 626.4 560.2 648.2C546.9 671 546 672.4 541.7 674.3C531.2 679.1 519.1 669.5 522.1 658.7C523.4 654.4 551 607 571.8 573.6C575 568.5 577.6 564.2 577.6 564C577.6 563.7 560.8 532.5 547.2 507.4C527.8 471.7 514.9 450.1 513.1 450.1C512.4 450.1 510.6 452.9 504.3 463.4C492.7 482.5 447.9 562.5 447.9 564C447.9 564.3 449.8 567.6 452.1 571.4C475.2 609.2 501.1 653.4 502.6 657.5C506.1 667.6 496.6 677.8 485.8 675.3C479.8 673.9 479.1 673.1 468.6 655.1C464.9 648.8 456 633.6 448.7 621.3C441.5 608.9 434.9 597.8 434.2 596.5C432.8 594 431.8 593 431.5 593.9C431.3 594.5 427.1 601.6 414 623.8C386.6 670 377.1 680.1 363 677.8ZM373.8 636.7C376.1 632.9 382.1 622.9 387.1 614.4C408.9 577.2 413.5 569.4 414.6 567.2L415.7 564.9L411.3 557.5C374 495.9 359.9 473.9 357.6 473.9C355.5 473.9 355.1 527.7 357.1 556.7C359.2 587.2 364.9 630.4 368.5 642.5C369 644.1 369.4 643.7 373.8 636.7ZM658.1 639.2C666.8 598 672.3 509 668.1 476.6C667.7 473.1 667.4 473.2 663.8 478C657.6 486.3 651.5 495.7 631.2 529C626.9 536.1 622.1 543.9 620.5 546.5C618.9 549.1 615.7 554.3 613.4 558.1L609.1 565L610.6 567.5C611.4 568.9 616.6 577.6 622.1 586.9C627.5 596.2 634.1 607.5 636.7 611.9C649.4 633.6 655.7 643.4 656.8 643.4C657 643.4 657.6 641.5 658.1 639.2Z`}],al=`<path fill="#000000" d="M495.8 884.4C291.9 874.2 135.4 724 114.7 518.5C97.9 351.3 160.2 221 290.9 150.2C372.3 106.1 439.7 86.4 513.6 85.2C686 82.3 812.9 171.5 867 333.5C903.9 444 890.2 573.8 828.6 698.6C766.8 823.4 644.3 891.8 495.8 884.4Z"/>
4
4
  <circle cx="340" cy="300" r="44" fill="#FB5D08"/>
5
5
  <circle cx="500" cy="276" r="44" fill="#FB5D08"/>
6
6
  <circle cx="660" cy="300" r="44" fill="#FB5D08"/>
7
7
  <path fill="none" stroke="#FFFFFF" stroke-width="58" stroke-linecap="round" stroke-linejoin="round"
8
- d="M318 420v280l182-250 182 250V420M500 450 410 700M500 450l90 250"/>`,zt=d.forwardRef(({size:e=28,variant:t="auto",title:n="Karni",className:s,...i},o)=>{const a=t==="simple"||t==="auto"&&e<=32,u=n!=="";return r.jsx("svg",{ref:o,viewBox:Qi,width:e,height:e,role:u?"img":void 0,"aria-hidden":u?void 0:!0,"aria-label":u?n:void 0,className:p("shrink-0",s),...i,...a?{dangerouslySetInnerHTML:{__html:qi}}:{},children:a?null:Wi.map(l=>r.jsx("path",{fill:l.fill,d:l.d},l.fill+l.d.length))})});zt.displayName="KarniMark";Y("layout-shell","Layout");function Ji(e){return r.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:!1,...e,children:[r.jsx("line",{x1:"4",y1:"6",x2:"20",y2:"6"}),r.jsx("line",{x1:"4",y1:"12",x2:"20",y2:"12"}),r.jsx("line",{x1:"4",y1:"18",x2:"20",y2:"18"})]})}function Zi(e){return r.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:!1,...e,children:[r.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),r.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}const Gi="flex items-center gap-3 rounded-md px-3 py-2 text-sm font-medium text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground [&_svg]:h-4 [&_svg]:w-4",Yi="bg-accent text-accent-foreground",hn="karni-layout-sidebar",ar=d.forwardRef(({navItems:e=[],renderNavItem:t,sidebar:n,sidebarHeader:s=r.jsx(zt,{className:"mx-3"}),sidebarFooter:i,header:o,navLabel:a="Main",sidebarClassName:u,headerClassName:l,contentClassName:c,className:m,children:h,...b},T)=>{const[R,y]=d.useState(!1),N=d.useCallback(()=>{y(!1)},[]);d.useEffect(()=>{if(!R)return;const w=L=>{L.key==="Escape"&&y(!1)};return document.addEventListener("keydown",w),()=>{document.removeEventListener("keydown",w)}},[R]);const f=n??r.jsx("nav",{"aria-label":a,className:"grid gap-1",children:e.map(w=>{const L=p(Gi,w.active===!0&&Yi),$=r.jsxs("a",{href:w.href,"aria-current":w.active===!0?"page":void 0,className:L,onClick:N,children:[w.icon!=null&&r.jsx("span",{"aria-hidden":"true",children:w.icon}),w.label]});return r.jsx(d.Fragment,{children:t?t(w,{defaultNode:$,defaultClassName:L}):$},w.key??w.href)})}),j=r.jsxs(r.Fragment,{children:[s!=null&&r.jsx("div",{className:"mb-4",children:s}),r.jsx("div",{className:"flex-1 overflow-y-auto",children:f}),i!=null&&r.jsx("div",{className:"mt-4",children:i})]});return r.jsxs("div",{ref:T,className:p("flex min-h-screen w-full bg-background text-foreground",m),...b,children:[r.jsx("aside",{className:p("hidden w-64 shrink-0 flex-col border-r border-border bg-card p-4 md:flex",u),children:j}),R&&r.jsxs("div",{className:"fixed inset-0 z-40 md:hidden",children:[r.jsx("div",{"data-testid":"karni-layout-backdrop","aria-hidden":"true",className:"absolute inset-0 bg-foreground/40",onClick:N}),r.jsxs("aside",{id:hn,className:p("absolute inset-y-0 left-0 flex w-64 flex-col border-r border-border bg-card p-4 shadow-lg",u),children:[r.jsx("div",{className:"mb-2 flex justify-end",children:r.jsxs("button",{type:"button",onClick:N,className:"inline-flex h-8 w-8 items-center justify-center rounded-md text-muted-foreground hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[r.jsx(Zi,{className:"h-4 w-4"}),r.jsx("span",{className:"sr-only",children:"Close navigation"})]})}),j]})]}),r.jsxs("div",{className:"flex min-w-0 flex-1 flex-col",children:[r.jsxs("header",{className:p("flex h-14 shrink-0 items-center gap-3 border-b border-border px-4",l),children:[r.jsxs("button",{type:"button","aria-expanded":R,"aria-controls":hn,onClick:()=>{y(w=>!w)},className:"inline-flex h-9 w-9 items-center justify-center rounded-md text-muted-foreground hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring md:hidden",children:[r.jsx(Ji,{className:"h-5 w-5"}),r.jsx("span",{className:"sr-only",children:"Open navigation"})]}),o!=null&&r.jsx("div",{className:"flex min-w-0 flex-1 items-center gap-3",children:o})]}),r.jsx("main",{className:p("flex-1 p-6",c),children:h})]})]})});ar.displayName="Layout";Y("modal","Modal");function Xi(e){return r.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:!1,...e,children:[r.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),r.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}const Ii=we.Close;function eo({title:e,description:t,children:n,footer:s,trigger:i,open:o,defaultOpen:a,onOpenChange:u,hideCloseButton:l=!1,className:c,contentProps:m}){const h=t==null&&(m==null?void 0:m["aria-describedby"])===void 0?{"aria-describedby":void 0}:{};return r.jsxs(we.Root,{open:o,defaultOpen:a,onOpenChange:u,children:[i!=null&&r.jsx(we.Trigger,{asChild:!0,children:i}),r.jsxs(we.Portal,{children:[r.jsx(we.Overlay,{className:"fixed inset-0 z-50 bg-foreground/40"}),r.jsxs(we.Content,{...m,...h,className:p("fixed left-1/2 top-1/2 z-50 grid w-full max-w-lg -translate-x-1/2 -translate-y-1/2 gap-4 rounded-lg border border-border bg-background p-6 text-foreground shadow-lg",c),children:[r.jsxs("div",{className:"grid gap-1.5",children:[r.jsx(we.Title,{className:"text-lg font-semibold leading-none tracking-tight",children:e}),t!=null&&r.jsx(we.Description,{className:"text-sm text-muted-foreground",children:t})]}),n,s!=null&&r.jsx("div",{className:"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",children:s}),!l&&r.jsxs(we.Close,{className:"absolute right-4 top-4 rounded-sm text-muted-foreground opacity-70 transition-opacity hover:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none",children:[r.jsx(Xi,{className:"h-4 w-4"}),r.jsx("span",{className:"sr-only",children:"Close"})]})]})]})]})}let _e=[];const St=new Set;let gn=0;function lr(){for(const e of St)e()}function to(e){return St.add(e),()=>{St.delete(e)}}function pn(){return _e}function Bt(e){const t=e===void 0?[]:_e.filter(n=>n.id!==e);t.length!==_e.length&&(_e=t,lr())}function cr(e){gn+=1;const t=e.id??`karni-toast-${String(gn)}`,n={...e,id:t,variant:e.variant??"default"};return _e=[..._e.filter(s=>s.id!==t),n].slice(-5),lr(),{id:t,dismiss:()=>{Bt(t)}}}function bt(e){return(t,n)=>cr({...n,title:t,variant:e})}const no={toast:cr,success:bt("success"),error:bt("error"),info:bt("info"),dismiss:Bt};function ur(){const e=d.useSyncExternalStore(to,pn,pn);return d.useMemo(()=>({toasts:e,...no}),[e])}Y("toast","Toaster");function ro(e){return r.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:!1,...e,children:[r.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),r.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}const dr=kt({base:"pointer-events-auto relative flex w-full items-start gap-3 overflow-hidden rounded-md border p-4 pr-8 shadow-lg",variants:{variant:{default:"border-border bg-background text-foreground",success:"border-primary bg-background text-foreground",error:"border-destructive bg-destructive text-destructive-foreground",info:"border-border bg-muted text-foreground"}},defaultVariants:{variant:"default"}});function so({duration:e=5e3,swipeDirection:t="right",label:n="Notification",viewportClassName:s,toastClassName:i}){const{toasts:o}=ur();return r.jsxs(Fe.Provider,{duration:e,swipeDirection:t,label:n,children:[o.map(a=>r.jsxs(Fe.Root,{duration:a.duration,"data-variant":a.variant,onOpenChange:u=>{u||Bt(a.id)},className:dr({variant:a.variant,className:i}),children:[r.jsxs("div",{className:"grid flex-1 gap-1",children:[a.title!=null&&r.jsx(Fe.Title,{className:"text-sm font-semibold",children:a.title}),a.description!=null&&r.jsx(Fe.Description,{className:"text-sm opacity-90",children:a.description})]}),a.action!=null&&r.jsx("div",{className:"flex shrink-0 items-center",children:a.action}),r.jsx(Fe.Close,{"aria-label":"Dismiss",className:"absolute right-2 top-2 rounded-md p-1 opacity-70 transition-opacity hover:opacity-100 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:r.jsx(ro,{className:"h-4 w-4"})})]},a.id)),r.jsx(Fe.Viewport,{className:p("fixed bottom-0 right-0 z-[100] flex w-full max-w-sm flex-col gap-2 p-4 outline-none",s)})]})}Y("stat","Stat");function io(e){return r.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:!1,...e,children:[r.jsx("line",{x1:"12",y1:"19",x2:"12",y2:"5"}),r.jsx("polyline",{points:"5 12 12 5 19 12"})]})}function oo(e){return r.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",focusable:!1,...e,children:[r.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),r.jsx("polyline",{points:"19 12 12 19 5 12"})]})}function ao(e){const t=Math.abs(e).toLocaleString();return e>=0?`+${t}`:`-${t}`}const mr=d.forwardRef(({label:e,value:t,delta:n,formatDelta:s=ao,icon:i,className:o,...a},u)=>{let l=null;if(typeof n=="number"&&Number.isFinite(n)){const c=n<0;l=r.jsxs("p",{className:p("flex items-center gap-1 text-sm font-medium",c?"text-destructive":"text-muted-foreground"),children:[c?r.jsx(oo,{className:"h-3.5 w-3.5"}):r.jsx(io,{className:"h-3.5 w-3.5"}),r.jsxs("span",{className:"sr-only",children:[c?"Decreased by":"Increased by"," "]}),s(n)]})}else n!=null&&(l=r.jsx("div",{className:"text-sm text-muted-foreground",children:n}));return r.jsxs("div",{ref:u,className:p("flex flex-col gap-1 rounded-lg border border-border bg-card p-4 text-card-foreground",o),...a,children:[r.jsxs("div",{className:"flex items-start justify-between gap-2",children:[r.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:e}),i!=null&&r.jsx("span",{"aria-hidden":"true",className:"text-muted-foreground [&>svg]:h-4 [&>svg]:w-4",children:i})]}),r.jsx("p",{className:"text-2xl font-semibold tracking-tight",children:t}),l]})});mr.displayName="Stat";Y("chart","DataChart");const lo=["stroke-chart-1","stroke-chart-2","stroke-chart-3","stroke-chart-4","stroke-chart-5"],xn=["fill-chart-1","fill-chart-2","fill-chart-3","fill-chart-4","fill-chart-5"],bn=["bg-chart-1","bg-chart-2","bg-chart-3","bg-chart-4","bg-chart-5"];function He(e,t){return e[t%e.length]??e[0]??""}const oe={top:8,right:12,bottom:28,left:48};function yn(e,t){const n=Math.floor(Math.log10(e)),s=e/10**n;let i;return t?i=s<1.5?1:s<3?2:s<7?5:10:i=s<=1?1:s<=2?2:s<=5?5:10,i*10**n}function co(e,t,n){const s=t>e?t-e:1,i=yn(yn(s,!1)/Math.max(1,n),!0),o=Math.floor(e/i)*i,a=Math.ceil(t/i)*i,u=[];for(let l=o;l<=a+i/2;l+=i)u.push(Number(l.toFixed(10)));return u}function uo(e,t){const n=t??(e!==void 0?[{name:"Value",data:e}]:[]),s=[],i=new Set;for(const a of n)for(const u of a.data)i.has(u.label)||(i.add(u.label),s.push(u.label));const o=n.map(a=>{const u=new Map;for(const l of a.data)Number.isFinite(l.value)&&u.set(l.label,l.value);return s.map(l=>u.get(l)??null)});return{categories:s,seriesNames:n.map(a=>a.name),matrix:o}}function mo(e){return e.toLocaleString()}function fo({kind:e,data:t,series:n,title:s,description:i,valueFormatter:o=mo,xTickFormatter:a,renderTooltip:u,width:l=640,height:c=240,yTickCount:m=4,showLegend:h,showTooltip:b=!0,categoryHeader:T="Label",emptyLabel:R="No data",className:y}){const N=d.useId(),f=d.useId(),[j,w]=d.useState(null),{categories:L,seriesNames:$,matrix:x}=d.useMemo(()=>uo(t,n),[t,n]),S=x.flat().filter(k=>k!==null);if(L.length===0||S.length===0)return r.jsx("div",{className:p("flex w-full items-center justify-center rounded-lg border border-dashed border-border px-6 py-10 text-sm text-muted-foreground",y),children:R});const F=Math.min(0,...S),z=Math.max(0,...S),U=co(F,z,m),E=U[0]??F,A=U[U.length-1]??z,v=A-E||1,P=l-oe.left-oe.right,_=c-oe.top-oe.bottom,O=k=>oe.top+(A-k)/v*_,q=P/L.length,ie=k=>oe.left+(k+.5)*q,ae=O(Math.max(E,Math.min(A,0))),Ce=Math.max(1,x.length),Ee=q*.7,Re=Ee/Ce,xe=x.map((k,D)=>{if(e==="bar")return r.jsx("g",{className:He(xn,D),children:k.map((H,I)=>{if(H===null)return null;const Te=ie(I)-Ee/2+D*Re,Ae=Math.min(O(H),ae),g=Math.abs(O(H)-ae);return r.jsx("rect",{x:Te,y:Ae,width:Math.max(1,Re-2),height:g,rx:2},I)})},D);const be=k.map((H,I)=>H===null?null:[ie(I),O(H)]).filter(H=>H!==null);return r.jsxs("g",{children:[r.jsx("polyline",{className:He(lo,D),fill:"none",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",points:be.map(([H,I])=>`${String(H)},${String(I)}`).join(" ")}),be.map(([H,I],Te)=>r.jsx("circle",{className:He(xn,D),cx:H,cy:I,r:3},Te))]},D)}),X=(k,D)=>`${String(k/D*100)}%`,je=j===null?[]:x.map((k,D)=>({seriesName:$[D]??"",value:k[j]??null,swatchClassName:He(bn,D)})).filter(k=>k.value!==null),me=j===null?void 0:L[j],Ne=$.length>1;return r.jsxs("div",{className:p("w-full",y),children:[r.jsxs("div",{className:"relative w-full",children:[r.jsxs("svg",{role:"img","aria-label":s,"aria-labelledby":N,"aria-describedby":i!==void 0?f:void 0,viewBox:`0 0 ${String(l)} ${String(c)}`,className:"block h-auto w-full text-muted-foreground",children:[r.jsx("title",{id:N,children:s}),i!==void 0&&r.jsx("desc",{id:f,children:i}),U.map(k=>r.jsxs("g",{children:[r.jsx("line",{x1:oe.left,x2:l-oe.right,y1:O(k),y2:O(k),stroke:"currentColor",strokeOpacity:k===0?.6:.2}),r.jsx("text",{x:oe.left-6,y:O(k),textAnchor:"end",dominantBaseline:"middle",fontSize:10,fill:"currentColor",children:o(k)})]},k)),L.map((k,D)=>r.jsx("text",{x:ie(D),y:c-oe.bottom+14,textAnchor:"middle",fontSize:10,fill:"currentColor",children:a?a(k):k},k)),xe]}),b&&r.jsxs("div",{"aria-hidden":"true",className:"absolute inset-0",children:[r.jsx("div",{className:"absolute flex",style:{left:X(oe.left,l),width:X(P,l),top:X(oe.top,c),height:X(_,c)},onMouseLeave:()=>{w(null)},children:L.map((k,D)=>r.jsx("div",{"data-karni-chart-hit":D,className:"h-full flex-1",onMouseEnter:()=>{w(D)}},k))}),j!==null&&me!==void 0&&je.length>0&&r.jsx("div",{"data-karni-chart-tooltip":"",className:"pointer-events-none absolute z-10 min-w-24 -translate-x-1/2 rounded-md border border-border bg-popover px-2.5 py-1.5 text-xs text-popover-foreground shadow-md",style:{left:X(ie(j),l),top:X(oe.top,c)},children:u?u({label:me,points:je}):r.jsxs(r.Fragment,{children:[r.jsx("p",{className:"mb-1 font-medium",children:me}),je.map(k=>r.jsxs("p",{className:"flex items-center gap-1.5",children:[r.jsx("span",{className:p("h-2 w-2 shrink-0 rounded-full",k.swatchClassName)}),r.jsx("span",{className:"text-muted-foreground",children:k.seriesName}),r.jsx("span",{className:"ml-auto font-medium",children:o(k.value)})]},k.seriesName))]})})]})]}),(h??Ne)&&r.jsx("div",{"aria-hidden":"true",className:"mt-2 flex flex-wrap items-center gap-x-4 gap-y-1",children:$.map((k,D)=>r.jsxs("span",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[r.jsx("span",{className:p("h-2 w-2 rounded-full",He(bn,D))}),k]},k))}),r.jsx(Mr.Root,{asChild:!0,children:r.jsx("div",{children:r.jsxs("table",{children:[r.jsx("caption",{children:s}),r.jsx("thead",{children:r.jsxs("tr",{children:[r.jsx("th",{scope:"col",children:T}),$.map(k=>r.jsx("th",{scope:"col",children:k},k))]})}),r.jsx("tbody",{children:L.map((k,D)=>r.jsxs("tr",{children:[r.jsx("th",{scope:"row",children:k}),x.map((be,H)=>{const I=be[D]??null;return r.jsx("td",{children:I===null?"—":o(I)},H)})]},k))})]})})})]})}exports.AUDIT_FIELDS=rt;exports.AuthGuard=Ui;exports.AuthProvider=Vi;exports.Button=Q;exports.ChangeHistory=Ri;exports.Checkbox=et;exports.DataChart=fo;exports.DropdownMenu=Or;exports.DropdownMenuCheckboxItem=En;exports.DropdownMenuContent=Ln;exports.DropdownMenuGroup=_r;exports.DropdownMenuItem=Dn;exports.DropdownMenuLabel=Fn;exports.DropdownMenuPortal=zr;exports.DropdownMenuSeparator=Pn;exports.DropdownMenuTrigger=$r;exports.EmptyState=nt;exports.FileUpload=Xn;exports.Input=ye;exports.KARNI_SELECT_EMPTY=Oe;exports.KarniApiError=Nt;exports.KarniMark=zt;exports.KarniProvider=Ur;exports.Label=We;exports.Layout=ar;exports.LoginForm=Ki;exports.Modal=eo;exports.ModalClose=Ii;exports.Page=or;exports.ResourceDetail=Ni;exports.ResourceForm=gi;exports.ResourceImport=Di;exports.ResourceSelect=_t;exports.ResourceTable=Vs;exports.Select=Be;exports.SelectContent=Tt;exports.SelectGroup=Fr;exports.SelectItem=Ie;exports.SelectLabel=Cn;exports.SelectRoot=wn;exports.SelectSeparator=Rn;exports.SelectTrigger=Rt;exports.SelectValue=Nn;exports.Skeleton=ce;exports.Stat=mr;exports.Switch=At;exports.Tabs=Pr;exports.TabsContent=Mn;exports.TabsList=Tn;exports.TabsTrigger=An;exports.Textarea=Xe;exports.Toaster=so;exports.buttonVariants=jn;exports.changeHistoryKey=nr;exports.cn=p;exports.createKarniClient=_i;exports.createLocalStorageTokenStorage=sr;exports.createMemoryTokenStorage=Bi;exports.displayLabel=De;exports.downloadImportTemplate=Qn;exports.downloadResourceExport=Kn;exports.getRoleRegistry=Er;exports.importDescribeKey=Pt;exports.importJobKey=Ot;exports.isImportInFlight=$t;exports.karniKeys=ue;exports.registerComponentRole=Y;exports.toastVariants=dr;exports.useAuth=lt;exports.useChangeHistory=rr;exports.useImportActions=Jn;exports.useImportDescribe=Wn;exports.useImportJob=qn;exports.useKarniClient=de;exports.usePermission=Hi;exports.useResourceItem=at;exports.useResourceList=Lt;exports.useResourceMutations=Dt;exports.useSchema=ot;exports.useToast=ur;exports.variants=kt;exports.zodFor=Yn;
9
- //# sourceMappingURL=index.cjs.map
8
+ d="M318 420v280l182-250 182 250V420M500 450 410 700M500 450l90 250"/>`,ol=d.forwardRef(({size:e=28,variant:t=`auto`,title:n=`Karni`,className:r,...i},a)=>{let o=t===`simple`||t===`auto`&&e<=32,s=n!==``;return(0,f.jsx)(`svg`,{ref:a,viewBox:rl,width:e,height:e,role:s?`img`:void 0,"aria-hidden":!s||void 0,"aria-label":s?n:void 0,className:D(`shrink-0`,r),...i,...o?{dangerouslySetInnerHTML:{__html:al}}:{},children:o?null:il.map(e=>(0,f.jsx)(`path`,{fill:e.fill,d:e.d},e.fill+e.d.length))})});ol.displayName=`KarniMark`;function sl(){let{pathname:e,hash:t}=window.location;return`${e}${t.startsWith(`#/`)||t.startsWith(`#!/`)?t.split(`?`)[0]:``}`}function cl(e){return e.querySelector(`h1`)}function ll(e){return e?.textContent?.trim()??``}var ul=`input, textarea, select, [contenteditable=""], [contenteditable="true"]`;function dl(e,t){let n=document.activeElement;return!(n instanceof HTMLElement)||n===document.body||n===e||n===t?!1:n.closest(`[role="dialog"], [role="alertdialog"], dialog`)!==null||n.closest(ul)!==null||e.contains(n)}function fl(e,t,n){let r=document.title.trim();if(r!==``&&r!==n.title)return r;let i=e===t?``:ll(e);return i===``?r:i}var pl=[`keydown`,`pointerdown`,`popstate`];function ml(e,t){let{enabled:n}=t,[r,i]=d.useState(``),a=d.useRef(t);a.current=t;let o=d.useRef(null),s=d.useRef(null),c=d.useRef(null),l=d.useRef(!1),u=d.useCallback((e,t)=>{let n=(a.current.getTarget??cl)(t);return{key:e,heading:n,text:ll(n),title:document.title.trim()}},[]),f=d.useCallback(()=>{c.current=null;let t=e.current,n=s.current,r=o.current;if(t===null||n===null||r===null)return;let{getTarget:l,getAnnouncement:d}=a.current,f=(l??cl)(t)??t,p=f===r.heading&&ll(f)===r.text;(n.mutated||!p)&&(s.current=null,dl(t,f)||(f.tabIndex<0&&!f.hasAttribute(`tabindex`)&&f.setAttribute(`tabindex`,`-1`),f.focus({preventScroll:!0})),i(d===void 0?fl(f,t,r):d(f)),o.current=u(n.key,t))},[e,u]),p=d.useCallback(t=>{let n=e.current;if(n===null)return;let r=a.current.routeKey??sl(),d=o.current;d===null||!l.current?o.current=u(r,n):r===d.key?(s.current!==null&&(s.current=null,c.current!==null&&clearTimeout(c.current),c.current=null),o.current=u(r,n)):(s.current?.key!==r&&(s.current={key:r,mutated:!1},i(``)),t&&(s.current.mutated=!0),c.current!==null&&clearTimeout(c.current),c.current=setTimeout(f,0))},[e,u,f]);return d.useEffect(()=>{if(!n||l.current)return;let e=()=>{for(let e of pl)window.removeEventListener(e,t,!0)},t=()=>{l.current=!0,e()};for(let e of pl)window.addEventListener(e,t,!0);return e},[n]),d.useEffect(()=>{let t=e.current;if(!n||t===null)return;let r=new MutationObserver(()=>p(!0));return r.observe(t,{childList:!0,subtree:!0,characterData:!0}),()=>{r.disconnect(),c.current!==null&&clearTimeout(c.current),c.current=null}},[n,e,p]),d.useEffect(()=>{n&&p(!1)}),d.useEffect(()=>{n||(o.current=null,s.current=null)},[n]),n?r:``}j(`layout-shell`,`Layout`);function hl(e){return(0,f.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,focusable:!1,...e,children:[(0,f.jsx)(`line`,{x1:`4`,y1:`6`,x2:`20`,y2:`6`}),(0,f.jsx)(`line`,{x1:`4`,y1:`12`,x2:`20`,y2:`12`}),(0,f.jsx)(`line`,{x1:`4`,y1:`18`,x2:`20`,y2:`18`})]})}function gl(e){return(0,f.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,focusable:!1,...e,children:[(0,f.jsx)(`line`,{x1:`18`,y1:`6`,x2:`6`,y2:`18`}),(0,f.jsx)(`line`,{x1:`6`,y1:`6`,x2:`18`,y2:`18`})]})}var _l=`flex items-center gap-3 rounded-md px-3 py-2 text-sm font-medium text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring [&_svg]:h-4 [&_svg]:w-4`,vl=`bg-accent text-accent-foreground`,yl=`inline-flex items-center justify-center rounded-md text-muted-foreground hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring`;function bl({header:e,nav:t,footer:n}){return(0,f.jsxs)(f.Fragment,{children:[e!=null&&(0,f.jsx)(`div`,{className:`mb-4`,children:e}),(0,f.jsx)(`div`,{className:`flex-1 overflow-y-auto`,children:t}),n!=null&&(0,f.jsx)(`div`,{className:`mt-4`,children:n})]})}function xl({menuButton:e,children:t,className:n}){return(0,f.jsxs)(`header`,{className:D(`flex h-14 shrink-0 items-center gap-3 border-b border-border px-4`,n),children:[e,t!=null&&(0,f.jsx)(`div`,{className:`flex min-w-0 flex-1 items-center gap-3`,children:t})]})}function Sl(e){return(0,f.jsx)(`aside`,{className:D(`hidden w-64 shrink-0 flex-col border-r border-border bg-card p-4 md:flex`,e.className),children:(0,f.jsx)(bl,{...e})})}function Cl(e){return(0,f.jsx)(`a`,{href:e.href,className:e.className,"aria-current":e[`aria-current`],onClick:e.onClick,children:e.children})}function wl({open:e,onOpenChange:t,id:n,returnFocusRef:r,className:i,...a}){return(0,f.jsx)(x.Root,{open:e,onOpenChange:t,children:(0,f.jsxs)(x.Portal,{children:[(0,f.jsx)(x.Overlay,{"data-testid":`karni-layout-backdrop`,className:`fixed inset-0 z-drawer bg-overlay md:hidden`}),(0,f.jsxs)(x.Content,{id:n,"aria-describedby":void 0,onCloseAutoFocus:e=>{let t=r.current;t!==null&&(e.preventDefault(),t.focus())},className:D(`fixed inset-y-0 left-0 z-drawer flex w-64 flex-col border-r border-border bg-card p-4 shadow-lg focus:outline-none md:hidden`,i),children:[(0,f.jsx)(x.Title,{className:`sr-only`,children:`Navigation`}),(0,f.jsx)(`div`,{className:`mb-2 flex justify-end`,children:(0,f.jsxs)(x.Close,{className:D(yl,`h-8 w-8`),children:[(0,f.jsx)(gl,{className:`h-4 w-4`}),(0,f.jsx)(`span`,{className:`sr-only`,children:`Close navigation`})]})}),(0,f.jsx)(bl,{...a})]})]})})}function Tl({href:e,onClick:t,children:n}){return(0,f.jsx)(`a`,{href:e,onClick:t,className:`sr-only focus:not-sr-only focus:fixed focus:left-4 focus:top-4 focus:z-popover focus:rounded-md focus:bg-background focus:px-4 focus:py-2 focus:text-sm focus:font-medium focus:text-foreground focus:shadow-md focus:outline-none focus:ring-2 focus:ring-ring`,children:n})}var El={Header:xl,Sidebar:Sl,NavLink:Cl,MobileDrawer:wl,SkipLink:Tl},Dl=d.forwardRef(({navItems:e=[],renderNavItem:t,sidebar:n,sidebarHeader:r=(0,f.jsx)(ol,{className:`mx-3`}),sidebarFooter:i,header:a,navLabel:o=`Main`,mobileNavOpen:s,defaultMobileNavOpen:c=!1,onMobileNavOpenChange:l,slots:u,routeFocus:p=!0,sidebarClassName:m,headerClassName:h,contentClassName:g,className:_,children:v,...y},b)=>{let{Header:x,Sidebar:S,NavLink:C,MobileDrawer:w,SkipLink:T}={...El,...u},[E,ee]=d.useState(c),O=s??E,k=d.useCallback(e=>{s===void 0&&ee(e),l?.(e)},[s,l]),A=d.useCallback(()=>k(!1),[k]),j=d.useRef(null),te=d.useId(),M=d.useId(),N=d.useRef(null),P=d.useCallback(e=>{let t=N.current;t!==null&&(e.preventDefault(),t.focus())},[]),F=p!==!1,I=ml(N,{...typeof p==`object`?p:{},enabled:F});d.useEffect(()=>{if(!O)return;let e=()=>{let e=j.current;e!==null&&window.getComputedStyle(e).display===`none`&&k(!1)};return e(),window.addEventListener(`resize`,e),()=>window.removeEventListener(`resize`,e)},[O,k]);let L={header:r,nav:n??(0,f.jsx)(`nav`,{"aria-label":o,className:`grid gap-1`,children:e.map(e=>{let n=D(_l,e.active===!0&&vl),r=(0,f.jsxs)(C,{item:e,href:e.href,"aria-current":e.active===!0?`page`:void 0,className:n,onClick:A,children:[e.icon!=null&&(0,f.jsx)(`span`,{"aria-hidden":`true`,children:e.icon}),e.label]});return(0,f.jsx)(d.Fragment,{children:t?t(e,{defaultNode:r,defaultClassName:n}):r},e.key??e.href)})}),footer:i},ne=(0,f.jsxs)(`button`,{ref:j,type:`button`,"aria-haspopup":`dialog`,"aria-expanded":O,"aria-controls":O?te:void 0,onClick:()=>k(!O),className:D(yl,`h-9 w-9 md:hidden`),children:[(0,f.jsx)(hl,{className:`h-5 w-5`}),(0,f.jsx)(`span`,{className:`sr-only`,children:`Open navigation`})]});return(0,f.jsxs)(`div`,{ref:b,className:D(`flex min-h-screen w-full bg-background text-foreground`,_),...y,children:[(0,f.jsx)(T,{href:`#${M}`,onClick:P,children:`Skip to content`}),(0,f.jsx)(S,{...L,className:m}),(0,f.jsx)(w,{...L,className:m,open:O,onOpenChange:k,id:te,returnFocusRef:j}),(0,f.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-col`,children:[(0,f.jsx)(x,{menuButton:ne,className:h,children:a}),(0,f.jsx)(`main`,{ref:N,id:M,tabIndex:-1,className:D(`flex-1 p-6 focus:outline-none`,g),children:v})]}),F&&(0,f.jsx)(`div`,{role:`status`,"aria-live":`polite`,"aria-atomic":`true`,className:`sr-only`,children:I})]})});Dl.displayName=`Layout`;var Ol=[],kl=new Set,Al=0;function jl(){for(let e of kl)e()}function Ml(e){return kl.add(e),()=>{kl.delete(e)}}function Nl(){return Ol}function Pl(e){let t=e===void 0?[]:Ol.filter(t=>t.id!==e);t.length!==Ol.length&&(Ol=t,jl())}function Fl(e){Al+=1;let t=e.id??`karni-toast-${String(Al)}`,n={...e,id:t,variant:e.variant??`default`};return Ol=[...Ol.filter(e=>e.id!==t),n].slice(-5),jl(),{id:t,dismiss:()=>{Pl(t)}}}function Il(e){return(t,n)=>Fl({...n,title:t,variant:e})}var Ll={toast:Fl,success:Il(`success`),error:Il(`error`),info:Il(`info`),dismiss:Pl};function Rl(){let e=d.useSyncExternalStore(Ml,Nl,Nl);return d.useMemo(()=>({toasts:e,...Ll}),[e])}j(`toast`,`Toaster`);function zl(e){return(0,f.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,focusable:!1,...e,children:[(0,f.jsx)(`line`,{x1:`18`,y1:`6`,x2:`6`,y2:`18`}),(0,f.jsx)(`line`,{x1:`6`,y1:`6`,x2:`18`,y2:`18`})]})}var Bl=M({base:`pointer-events-auto relative flex w-full items-start gap-3 overflow-hidden rounded-md border p-4 pr-8 shadow-lg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background`,variants:{variant:{default:`border-border bg-background text-foreground`,success:`border-primary bg-background text-foreground`,error:`border-destructive bg-destructive text-destructive-foreground`,info:`border-border bg-muted text-foreground`}},defaultVariants:{variant:`default`}});function Vl({children:e}){return(0,f.jsx)(E.Title,{className:`text-sm font-semibold`,children:e})}function Hl({children:e}){return(0,f.jsx)(E.Description,{className:`text-sm opacity-90`,children:e})}function Ul({label:e}){return(0,f.jsx)(E.Close,{"aria-label":e,className:`absolute right-2 top-2 rounded-md p-1 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-current`,children:(0,f.jsx)(zl,{className:`h-4 w-4`})})}var Wl={Title:Vl,Description:Hl,CloseButton:Ul},Gl={default:`background`,success:`background`,info:`background`,error:`foreground`};function Kl({duration:e=5e3,swipeDirection:t=`right`,label:n=`Notification`,className:r,viewportClassName:i,toastClassName:a,slots:o}){let{toasts:s}=Rl(),{Title:c,Description:l,CloseButton:u}={...Wl,...o};return(0,f.jsxs)(E.Provider,{duration:e,swipeDirection:t,label:n,children:[s.map(e=>(0,f.jsxs)(E.Root,{duration:e.duration,type:Gl[e.variant],"data-variant":e.variant,onOpenChange:t=>{t||Pl(e.id)},className:Bl({variant:e.variant,className:a}),children:[(0,f.jsxs)(`div`,{className:`grid flex-1 gap-1`,children:[e.title!=null&&(0,f.jsx)(c,{variant:e.variant,children:e.title}),e.description!=null&&(0,f.jsx)(l,{variant:e.variant,children:e.description})]}),e.action!=null&&(0,f.jsx)(`div`,{className:`flex shrink-0 items-center`,children:e.action}),(0,f.jsx)(u,{label:`Dismiss`,variant:e.variant,dismiss:()=>Pl(e.id)})]},e.id)),(0,f.jsx)(E.Viewport,{className:D(`fixed bottom-0 right-0 z-toast flex w-full max-w-96 flex-col gap-2 p-4 outline-none`,i,r)})]})}j(`stat`,`Stat`);function ql(e){return{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":!0,focusable:!1,...e}}function Jl(e){return(0,f.jsxs)(`svg`,{...ql(e),children:[(0,f.jsx)(`line`,{x1:`12`,y1:`19`,x2:`12`,y2:`5`}),(0,f.jsx)(`polyline`,{points:`5 12 12 5 19 12`})]})}function Yl(e){return(0,f.jsxs)(`svg`,{...ql(e),children:[(0,f.jsx)(`line`,{x1:`12`,y1:`5`,x2:`12`,y2:`19`}),(0,f.jsx)(`polyline`,{points:`19 12 12 19 5 12`})]})}function Xl(e){return(0,f.jsx)(`svg`,{...ql(e),children:(0,f.jsx)(`line`,{x1:`5`,y1:`12`,x2:`19`,y2:`12`})})}function Zl(e){let t=Math.abs(e).toLocaleString();return e===0?t:e>0?`+${t}`:`-${t}`}function Ql({children:e}){return(0,f.jsx)(`p`,{className:`text-sm font-medium text-muted-foreground`,children:e})}function $l({children:e}){return(0,f.jsx)(`p`,{className:`text-2xl font-semibold tracking-tight`,children:e})}function eu({children:e}){return(0,f.jsx)(`span`,{"aria-hidden":`true`,className:`text-muted-foreground [&>svg]:h-4 [&>svg]:w-4`,children:e})}function tu({delta:e,formatDelta:t}){if(typeof e==`number`){if(!Number.isFinite(e))return null;let n=e<0?`down`:e>0?`up`:`flat`,r=n===`down`?Yl:n===`up`?Jl:Xl,i=n===`down`?`Decreased by`:n===`up`?`Increased by`:`Unchanged:`;return(0,f.jsxs)(`p`,{"data-trend":n,className:D(`flex items-center gap-1 text-sm font-medium`,n===`down`?`text-destructive`:`text-muted-foreground`),children:[(0,f.jsx)(r,{className:`h-3.5 w-3.5`}),(0,f.jsxs)(`span`,{className:`sr-only`,children:[i,` `]}),t(e)]})}return e==null?null:(0,f.jsx)(`div`,{className:`text-sm text-muted-foreground`,children:e})}var nu={Label:Ql,Value:$l,Delta:tu,Icon:eu},ru=d.forwardRef(({label:e,value:t,delta:n,formatDelta:r=Zl,icon:i,loading:a=!1,slots:o,className:s,...c},l)=>{let{Label:u,Value:d,Delta:p,Icon:m}={...nu,...o};return(0,f.jsxs)(`div`,{ref:l,"aria-busy":a||void 0,className:D(`flex flex-col gap-1 rounded-lg border border-border bg-card p-4 text-card-foreground`,s),...c,children:[(0,f.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,f.jsx)(u,{children:e}),i!=null&&(0,f.jsx)(m,{children:i})]}),a?(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)($,{className:`h-8 w-24`}),(0,f.jsx)(`span`,{className:`sr-only`,children:`Loading`})]}):(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(d,{children:t}),n!=null&&(0,f.jsx)(p,{delta:n,formatDelta:r})]})]})});ru.displayName=`Stat`,j(`chart`,`DataChart`);var iu=[`stroke-chart-1`,`stroke-chart-2`,`stroke-chart-3`,`stroke-chart-4`,`stroke-chart-5`],au=[`fill-chart-1`,`fill-chart-2`,`fill-chart-3`,`fill-chart-4`,`fill-chart-5`],ou=[`bg-chart-1`,`bg-chart-2`,`bg-chart-3`,`bg-chart-4`,`bg-chart-5`];function su(e,t){return e[t%e.length]??e[0]??``}var cu={top:8,right:12,bottom:28,left:48},lu=10,uu=11;function du(e,t){let n=Math.floor(Math.log10(e)),r=e/10**n,i;return i=t?r<1.5?1:r<3?2:r<7?5:10:r<=1?1:r<=2?2:r<=5?5:10,i*10**n}function fu(e,t,n){let r=du(du(t>e?t-e:1,!1)/Math.max(1,n),!0),i=Math.floor(e/r)*r,a=Math.ceil(t/r)*r,o=[];for(let e=i;e<=a+r/2;e+=r)o.push(Number(e.toFixed(10)));return o}function pu(e,t){let n=t??(e===void 0?[]:[{name:`Value`,data:e}]),r=[],i=new Set;for(let e of n)for(let t of e.data)i.has(t.label)||(i.add(t.label),r.push(t.label));let a=n.map(e=>{let t=new Map;for(let n of e.data)Number.isFinite(n.value)&&t.set(n.label,n.value);return r.map(e=>t.get(e)??null)});return{categories:r,seriesNames:n.map(e=>e.name),matrix:a}}function mu(e){return e.toLocaleString()}function hu(e,t,n){let{categories:r,seriesNames:i,matrix:a}=t,o=r.length>1?`${r[0]??``} to ${r[r.length-1]??``}`:r[0]??``,s=[`${e===`line`?`Line`:`Bar`} chart, ${o}.`];return a.forEach((e,t)=>{let o=-1,c=-1;for(let t=0;t<e.length;t+=1){let n=e[t]??null;n!==null&&((o===-1||n<(e[o]??n))&&(o=t),(c===-1||n>(e[c]??n))&&(c=t))}if(o===-1||c===-1)return;let l=a.length>1?`${i[t]??``}: lowest`:`Lowest`;s.push(`${l} ${n(e[o]??0)} (${r[o]??``}), highest ${n(e[c]??0)} (${r[c]??``}).`)}),s.join(` `)}function gu({label:e,points:t,valueFormatter:n}){return(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)(`p`,{className:`mb-1 font-medium`,children:e}),t.map(e=>(0,f.jsxs)(`p`,{className:`flex items-center gap-1.5`,children:[(0,f.jsx)(`span`,{className:D(`h-2 w-2 shrink-0 rounded-full`,e.swatchClassName)}),(0,f.jsx)(`span`,{className:`text-muted-foreground`,children:e.seriesName}),(0,f.jsx)(`span`,{className:`ml-auto font-medium`,children:n(e.value)})]},e.seriesName))]})}function _u({series:e}){return(0,f.jsx)(`div`,{"aria-hidden":`true`,className:`mt-2 flex flex-wrap items-center gap-x-4 gap-y-1`,children:e.map(({name:e,swatchClassName:t})=>(0,f.jsxs)(`span`,{className:`flex items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,f.jsx)(`span`,{className:D(`h-2 w-2 rounded-full`,t)}),e]},e))})}function vu({title:e,label:t}){return(0,f.jsxs)(`div`,{className:`flex w-full items-center justify-center rounded-lg border border-dashed border-border px-6 py-10 text-sm text-muted-foreground`,children:[(0,f.jsxs)(`span`,{className:`sr-only`,children:[e,`: `]}),t]})}function yu({title:e,width:t,height:n}){return(0,f.jsxs)(f.Fragment,{children:[(0,f.jsx)($,{className:`w-full`,style:{aspectRatio:`${String(t)} / ${String(n)}`}}),(0,f.jsxs)(`span`,{className:`sr-only`,children:[`Loading `,e]})]})}var bu={Tooltip:gu,Legend:_u,Empty:vu,Loading:yu};function xu(e,t){let[n,r]=d.useState(null);return d.useEffect(()=>{let n=e.current;if(!t||n===null||typeof ResizeObserver>`u`)return;let i=new ResizeObserver(e=>{let t=e[0]?.contentRect.width;t!==void 0&&t>0&&r(t)});return i.observe(n),()=>i.disconnect()},[e,t]),n}function Su({kind:e,data:t,series:n,title:r,description:i,summary:a,valueFormatter:o=mu,xTickFormatter:s,renderTooltip:c,width:l=640,height:u=240,yTickCount:p=4,showLegend:m,showTooltip:h=!0,categoryHeader:g=`Label`,emptyLabel:_=`No data`,loading:v=!1,slots:y,className:b}){let{Tooltip:x,Legend:S,Empty:C,Loading:w}={...bu,...y},T=d.useId(),E=d.useId(),O=d.useId(),[k,A]=d.useState(null),j=d.useRef(null),te=d.useCallback(e=>{j.current=e,A(e)},[]),[M,N]=d.useState(``),P=d.useRef(null),F=d.useMemo(()=>pu(t,n),[t,n]),{categories:I,seriesNames:L,matrix:ne}=F,re=ne.flat().filter(e=>e!==null),ie=!v&&I.length>0&&re.length>0,R=xu(P,ie);if(v)return(0,f.jsx)(`div`,{"aria-busy":`true`,className:D(`w-full`,b),children:(0,f.jsx)(w,{title:r,width:l,height:u})});if(!ie)return(0,f.jsx)(`div`,{className:D(`w-full`,b),children:(0,f.jsx)(C,{title:r,label:_})});let ae=R===null?1:R/l,oe=R===null?lu:Math.max(lu,uu/ae),z=Math.max(2,1.5/ae),se=Math.max(3,2.5/ae),ce=Math.min(0,...re),le=Math.max(0,...re),ue=fu(ce,le,p),B=ue[0]??ce,V=ue[ue.length-1]??le,de=V-B||1,H=Math.max(...ue.map(e=>o(e).length)),U={top:Math.max(cu.top,oe*.6),right:cu.right,left:Math.max(cu.left,Math.ceil(H*oe*.6)+6),bottom:Math.max(cu.bottom,Math.ceil(oe*2))},fe=l-U.left-U.right,W=u-U.top-U.bottom,pe=e=>U.top+(V-e)/de*W,me=fe/I.length,he=e=>U.left+(e+.5)*me,G=pe(Math.max(B,Math.min(V,0))),ge=Math.max(1,ne.length),K=me*.7,_e=K/ge,q=ne.map((t,n)=>{if(e===`bar`)return(0,f.jsx)(`g`,{className:su(au,n),children:t.map((e,t)=>{if(e===null)return null;let r=he(t)-K/2+n*_e,i=Math.min(pe(e),G),a=Math.abs(pe(e)-G);return(0,f.jsx)(`rect`,{x:r,y:i,width:Math.max(1,_e-2),height:a,rx:2},t)})},n);let r=t.map((e,t)=>e===null?null:[he(t),pe(e)]).filter(e=>e!==null);return(0,f.jsxs)(`g`,{children:[(0,f.jsx)(`polyline`,{className:su(iu,n),fill:`none`,strokeWidth:z,strokeLinecap:`round`,strokeLinejoin:`round`,points:r.map(([e,t])=>`${String(e)},${String(t)}`).join(` `)}),r.map(([e,t],r)=>(0,f.jsx)(`circle`,{className:su(au,n),cx:e,cy:t,r:se},r))]},n)}),J=e=>ne.map((t,n)=>({seriesName:L[n]??``,value:t[e]??null,swatchClassName:su(ou,n)})).filter(e=>e.value!==null),Y=(e,t)=>`${String(e/t*100)}%`,X=k===null?[]:J(k),ve=k===null?void 0:I[k],Z=e=>{if(te(e),e===null){N(``);return}let t=J(e).map(e=>ne.length>1?`${e.seriesName} ${o(e.value)}`:o(e.value)).join(`, `);N(`${I[e]??``}: ${t}`)},ye=e=>{let t=I.length-1,n=j.current,r;switch(e.key){case`ArrowRight`:case`ArrowDown`:r=n===null?0:Math.min(t,n+1);break;case`ArrowLeft`:case`ArrowUp`:r=n===null?t:Math.max(0,n-1);break;case`Home`:r=0;break;case`End`:r=t;break;case`Escape`:r=null;break;default:return}e.preventDefault(),Z(r)},be=a??`${hu(e,F,o)}${h?` Use the arrow keys to read each value.`:``}`,xe=[i===void 0?null:E,be===``?null:O].filter(Boolean).join(` `)||void 0,Se=L.length>1;return(0,f.jsxs)(`div`,{className:D(`w-full`,b),children:[(0,f.jsxs)(`div`,{className:`relative w-full rounded-md ring-offset-background has-[svg:focus-visible]:ring-2 has-[svg:focus-visible]:ring-ring has-[svg:focus-visible]:ring-offset-2`,children:[(0,f.jsxs)(`svg`,{ref:P,role:`img`,"aria-label":r,"aria-labelledby":T,"aria-describedby":xe,tabIndex:h?0:void 0,onKeyDown:h?ye:void 0,onBlur:h?()=>Z(null):void 0,viewBox:`0 0 ${String(l)} ${String(u)}`,className:`block h-auto w-full text-muted-foreground focus-visible:outline-none`,children:[(0,f.jsx)(`title`,{id:T,children:r}),i!==void 0&&(0,f.jsx)(`desc`,{id:E,children:i}),ue.map(e=>(0,f.jsxs)(`g`,{children:[(0,f.jsx)(`line`,{x1:U.left,x2:l-U.right,y1:pe(e),y2:pe(e),stroke:`currentColor`,strokeOpacity:e===0?.6:.2}),(0,f.jsx)(`text`,{x:U.left-6,y:pe(e),textAnchor:`end`,dominantBaseline:`middle`,fontSize:oe,fill:`currentColor`,children:o(e)})]},e)),I.map((e,t)=>(0,f.jsx)(`text`,{x:he(t),y:u-U.bottom+oe*1.4,textAnchor:`middle`,fontSize:oe,fill:`currentColor`,children:s?s(e):e},e)),q]}),h&&(0,f.jsxs)(`div`,{"aria-hidden":`true`,className:`absolute inset-0`,children:[(0,f.jsx)(`div`,{className:`absolute flex`,style:{left:Y(U.left,l),width:Y(fe,l),top:Y(U.top,u),height:Y(W,u)},onMouseLeave:()=>{te(null)},children:I.map((e,t)=>(0,f.jsx)(`div`,{"data-karni-chart-hit":t,className:`h-full flex-1`,onMouseEnter:()=>{te(t)}},e))}),k!==null&&ve!==void 0&&X.length>0&&(0,f.jsx)(`div`,{"data-karni-chart-tooltip":``,className:`pointer-events-none absolute z-raised min-w-24 -translate-x-1/2 rounded-md border border-border bg-popover px-2.5 py-1.5 text-xs text-popover-foreground shadow-md`,style:{left:Y(he(k),l),top:Y(U.top,u)},children:c?c({label:ve,points:X}):(0,f.jsx)(x,{label:ve,points:X,valueFormatter:o})})]})]}),(m??Se)&&(0,f.jsx)(S,{series:L.map((e,t)=>({name:e,swatchClassName:su(ou,t)}))}),(0,f.jsx)(ee.Root,{asChild:!0,children:(0,f.jsxs)(`div`,{children:[be!==``&&(0,f.jsx)(`p`,{id:O,children:be}),(0,f.jsx)(`p`,{role:`status`,children:M}),(0,f.jsxs)(`table`,{children:[(0,f.jsx)(`caption`,{children:r}),(0,f.jsx)(`thead`,{children:(0,f.jsxs)(`tr`,{children:[(0,f.jsx)(`th`,{scope:`col`,children:g}),L.map(e=>(0,f.jsx)(`th`,{scope:`col`,children:e},e))]})}),(0,f.jsx)(`tbody`,{children:I.map((e,t)=>(0,f.jsxs)(`tr`,{children:[(0,f.jsx)(`th`,{scope:`row`,children:e}),ne.map((e,n)=>{let r=e[t]??null;return(0,f.jsx)(`td`,{children:r===null?(0,f.jsx)(Be,{}):o(r)},n)})]},e))})]})]})})]})}exports.AUDIT_FIELDS=kn,exports.AuthGuard=Yc,exports.AuthProvider=Kt,exports.Button=Z,exports.ChangeHistory=vc,exports.Checkbox=at,exports.DataChart=Su,exports.DropdownMenu=mt,exports.DropdownMenuCheckboxItem=bt,exports.DropdownMenuContent=vt,exports.DropdownMenuGroup=gt,exports.DropdownMenuItem=yt,exports.DropdownMenuLabel=xt,exports.DropdownMenuPortal=_t,exports.DropdownMenuSeparator=St,exports.DropdownMenuTrigger=ht,exports.EMPTY_VALUE_LABEL=ze,exports.EmptyState=aa,exports.EmptyValue=Be,exports.ErrorState=Te,exports.FileUpload=Ro,exports.Input=Ie,exports.KARNI_SELECT_EMPTY=Ve,exports.KARNI_THEME_SCRIPT=c.t,exports.KarniApiError=F,exports.KarniMark=ol,exports.KarniPrimitivesProvider=_e,exports.KarniProvider=Ft,exports.Label=lt,exports.Layout=Dl,exports.LoginForm=Hc,exports.Modal=fr,exports.ModalClose=ar,exports.ModalDescription=sr,exports.ModalTitle=or,exports.Page=nl,exports.PendingButton=Ce,exports.PermissionDenied=Ee,exports.ResourceDetail=sc,exports.ResourceForm=Ms,exports.ResourceImport=Pc,exports.ResourceSelect=fi,exports.ResourceTable=po,exports.SLOW_AFTER_MS=ye,exports.Select=rt,exports.SelectContent=Xe,exports.SelectGroup=Ue,exports.SelectItem=et,exports.SelectLabel=Qe,exports.SelectRoot=He,exports.SelectSeparator=nt,exports.SelectTrigger=Ke,exports.SelectValue=We,exports.Skeleton=$,exports.Stat=ru,exports.Switch=st,exports.THEME_STORAGE_KEY=c.n,exports.Tabs=ut,exports.TabsContent=pt,exports.TabsList=dt,exports.TabsTrigger=ft,exports.Textarea=Re,exports.ThemeProvider=je,exports.ThemeToggle=Fe,exports.Toaster=Kl,exports.UNSAVED_CHANGES_MESSAGE=go,exports.buttonVariants=X,exports.changeHistoryKey=cc,exports.cn=D,exports.createHistoryStateStore=Ha,exports.createKarniClient=ie,exports.createLocalStorageTokenStorage=Ut,exports.createMemoryTokenStorage=Wt,exports.defaultAuthGuardSlots=Gc,exports.defaultChangeHistorySlots=gc,exports.defaultDataChartSlots=bu,exports.defaultEmptyStateSlots=ia,exports.defaultFileUploadSlots=Lo,exports.defaultLayoutSlots=El,exports.defaultLoginFormSlots=Vc,exports.defaultModalSlots=dr,exports.defaultPageSlots=tl,exports.defaultResourceDetailSlots=rc,exports.defaultResourceFormSlots=bs,exports.defaultResourceImportSlots=Ac,exports.defaultResourceSelectSlots=Zr,exports.defaultResourceTableSlots=_a,exports.defaultStatSlots=nu,exports.defaultToasterSlots=Wl,exports.describeError=le,exports.displayLabel=Nn,exports.downloadImportTemplate=Fr,exports.downloadResourceExport=Nr,exports.errorSummary=ue,exports.getRoleRegistry=te,exports.importDescribeKey=Dr,exports.importJobKey=Or,exports.isImportInFlight=jr,exports.karniKeys=Mt,exports.registerComponentRole=j,exports.toastVariants=Bl,exports.useAuth=qt,exports.useChangeHistory=lc,exports.useDelayedFlag=be,exports.useImportActions=Rr,exports.useImportDescribe=Ir,exports.useImportJob=Lr,exports.useKarniClient=It,exports.useKarniPrimitives=q,exports.useOnlineStatus=Se,exports.usePermission=Xc,exports.useResourceItem=ho,exports.useResourceList=Jt,exports.useResourceMutations=an,exports.useSchema=On,exports.useTheme=Me,exports.useToast=Rl,exports.useUnsavedChangesGuard=_o,exports.variants=M,exports.zodFor=Oo;
9
+ //# sourceMappingURL=index.cjs.map