@karni/ui 0.0.0-stage → 0.3.1

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 (96) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +288 -2
  3. package/dist/index.cjs +9 -0
  4. package/dist/index.cjs.map +1 -0
  5. package/dist/index.js +4764 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/manifest.json +85 -0
  8. package/dist/mockServiceWorker.js +361 -0
  9. package/dist/src/auth/AuthGuard.d.ts +12 -0
  10. package/dist/src/auth/LoginForm.d.ts +29 -0
  11. package/dist/src/auth/engine.d.ts +99 -0
  12. package/dist/src/auth/provider.d.ts +43 -0
  13. package/dist/src/auth/storage.d.ts +26 -0
  14. package/dist/src/auth/types.d.ts +32 -0
  15. package/dist/src/auth/usePermission.d.ts +7 -0
  16. package/dist/src/components/brand/karni-mark.d.ts +21 -0
  17. package/dist/src/components/brand/mark-paths.d.ts +8 -0
  18. package/dist/src/components/chart/data-chart.d.ts +74 -0
  19. package/dist/src/components/empty-state/empty-state.d.ts +20 -0
  20. package/dist/src/components/file-upload/FileUpload.d.ts +44 -0
  21. package/dist/src/components/layout/layout.d.ts +55 -0
  22. package/dist/src/components/modal/modal.d.ts +45 -0
  23. package/dist/src/components/page/page.d.ts +29 -0
  24. package/dist/src/components/primitives/button.d.ts +44 -0
  25. package/dist/src/components/primitives/checkbox.d.ts +5 -0
  26. package/dist/src/components/primitives/dropdown-menu.d.ts +24 -0
  27. package/dist/src/components/primitives/icons.d.ts +11 -0
  28. package/dist/src/components/primitives/input.d.ts +4 -0
  29. package/dist/src/components/primitives/label.d.ts +5 -0
  30. package/dist/src/components/primitives/select.d.ts +63 -0
  31. package/dist/src/components/primitives/skeleton.d.ts +4 -0
  32. package/dist/src/components/primitives/switch.d.ts +5 -0
  33. package/dist/src/components/primitives/tabs.d.ts +10 -0
  34. package/dist/src/components/primitives/textarea.d.ts +4 -0
  35. package/dist/src/components/resource/ResourceDetail.d.ts +7 -0
  36. package/dist/src/components/resource/ResourceForm.d.ts +7 -0
  37. package/dist/src/components/resource/ResourceSelect.d.ts +7 -0
  38. package/dist/src/components/resource/ResourceTable.d.ts +11 -0
  39. package/dist/src/components/resource/audit-fields.d.ts +17 -0
  40. package/dist/src/components/resource/detail/ResourceDetail.d.ts +30 -0
  41. package/dist/src/components/resource/displayLabel.d.ts +12 -0
  42. package/dist/src/components/resource/form/ResourceForm.d.ts +50 -0
  43. package/dist/src/components/resource/form/field-inputs.d.ts +20 -0
  44. package/dist/src/components/resource/form/fixtures.d.ts +24 -0
  45. package/dist/src/components/resource/form/prepare.d.ts +54 -0
  46. package/dist/src/components/resource/history/ChangeHistory.d.ts +18 -0
  47. package/dist/src/components/resource/import/ResourceImport.d.ts +18 -0
  48. package/dist/src/components/resource/select/ResourceSelect.d.ts +36 -0
  49. package/dist/src/components/resource/select/use-debounced-value.d.ts +2 -0
  50. package/dist/src/components/resource/table/BulkActionsBar.d.ts +20 -0
  51. package/dist/src/components/resource/table/ExportButtons.d.ts +17 -0
  52. package/dist/src/components/resource/table/FilterBar.d.ts +29 -0
  53. package/dist/src/components/resource/table/PaginationControls.d.ts +19 -0
  54. package/dist/src/components/resource/table/ResourceTable.d.ts +72 -0
  55. package/dist/src/components/resource/table/demo-fixtures.d.ts +25 -0
  56. package/dist/src/components/resource/table/derive-columns.d.ts +33 -0
  57. package/dist/src/components/resource/table/table-utils.d.ts +24 -0
  58. package/dist/src/components/resource/table/use-debounced-value.d.ts +1 -0
  59. package/dist/src/components/stat/stat.d.ts +24 -0
  60. package/dist/src/components/toast/toast-store.d.ts +36 -0
  61. package/dist/src/components/toast/toaster.d.ts +33 -0
  62. package/dist/src/components/toast/use-toast.d.ts +24 -0
  63. package/dist/src/hooks/keys.d.ts +24 -0
  64. package/dist/src/hooks/multipart.d.ts +44 -0
  65. package/dist/src/hooks/params.d.ts +25 -0
  66. package/dist/src/hooks/types.d.ts +41 -0
  67. package/dist/src/hooks/useChangeHistory.d.ts +29 -0
  68. package/dist/src/hooks/useResourceImport.d.ts +107 -0
  69. package/dist/src/hooks/useResourceItem.d.ts +4 -0
  70. package/dist/src/hooks/useResourceList.d.ts +4 -0
  71. package/dist/src/hooks/useResourceMutations.d.ts +13 -0
  72. package/dist/src/index.d.ts +95 -0
  73. package/dist/src/lib/cn.d.ts +8 -0
  74. package/dist/src/lib/roles.d.ts +45 -0
  75. package/dist/src/lib/variants.d.ts +33 -0
  76. package/dist/src/schema/client.d.ts +90 -0
  77. package/dist/src/schema/parse.d.ts +101 -0
  78. package/dist/src/schema/provider.d.ts +13 -0
  79. package/dist/src/schema/types.d.ts +84 -0
  80. package/dist/src/schema/useSchema.d.ts +17 -0
  81. package/dist/src/schema/zod.d.ts +4 -0
  82. package/dist/styles.css +87 -0
  83. package/dist/tailwind-preset.cjs +2 -0
  84. package/dist/tailwind-preset.cjs.map +1 -0
  85. package/dist/tailwind-preset.d.ts +58 -0
  86. package/dist/tailwind-preset.js +64 -0
  87. package/dist/tailwind-preset.js.map +1 -0
  88. package/eslint-plugin/index.js +72 -0
  89. package/eslint-plugin/lib/docs.js +11 -0
  90. package/eslint-plugin/lib/glob.js +51 -0
  91. package/eslint-plugin/rules/max-page-lines.js +65 -0
  92. package/eslint-plugin/rules/no-deep-imports.js +61 -0
  93. package/eslint-plugin/rules/no-direct-http.js +128 -0
  94. package/eslint-plugin/rules/no-raw-elements.js +65 -0
  95. package/eslint-plugin/rules.json +26 -0
  96. package/package.json +153 -4
package/dist/index.cjs ADDED
@@ -0,0 +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"/>
4
+ <circle cx="340" cy="300" r="44" fill="#FB5D08"/>
5
+ <circle cx="500" cy="276" r="44" fill="#FB5D08"/>
6
+ <circle cx="660" cy="300" r="44" fill="#FB5D08"/>
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