@sito/dashboard-app 0.0.53 → 0.0.54
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.
- package/README.md +142 -7
- package/dist/dashboard-app.cjs +1 -1
- package/dist/dashboard-app.js +1590 -1198
- package/dist/lib/api/IndexedDBClient.d.ts +2 -0
- package/dist/lib/api/SupabaseDataClient.d.ts +43 -0
- package/dist/lib/api/index.d.ts +2 -0
- package/dist/lib/api/supabaseAuth.d.ts +10 -0
- package/dist/lib/entities/base/BaseFilterDto.d.ts +2 -0
- package/dist/lib/entities/base/index.d.ts +2 -2
- package/dist/providers/{AuthProvider.d.ts → Auth/AuthProvider.d.ts} +2 -2
- package/dist/providers/Auth/authContext.d.ts +3 -0
- package/dist/providers/Auth/index.d.ts +3 -0
- package/dist/providers/Auth/types.d.ts +17 -0
- package/dist/providers/Supbase/SupabaseAuthProvider.d.ts +3 -0
- package/dist/providers/Supbase/SupabaseContext.d.ts +3 -0
- package/dist/providers/Supbase/SupabaseManagerProvider.d.ts +3 -0
- package/dist/providers/Supbase/index.d.ts +4 -0
- package/dist/providers/Supbase/types.d.ts +15 -0
- package/dist/providers/index.d.ts +2 -1
- package/dist/providers/types.d.ts +1 -16
- package/package.json +18 -11
package/README.md
CHANGED
|
@@ -18,16 +18,17 @@ pnpm add @sito/dashboard-app
|
|
|
18
18
|
- React `18.3.1`
|
|
19
19
|
- React DOM `18.3.1`
|
|
20
20
|
- `@tanstack/react-query` `5.83.0`
|
|
21
|
+
- `@supabase/supabase-js` `2.100.0` (optional; only if using Supabase backend)
|
|
21
22
|
- `react-hook-form` `7.61.1`
|
|
22
|
-
- `@sito/dashboard` `^0.0.
|
|
23
|
-
- Font Awesome
|
|
23
|
+
- `@sito/dashboard` `^0.0.73`
|
|
24
|
+
- Font Awesome peers defined in `package.json`
|
|
24
25
|
|
|
25
26
|
Install all peers in consumer apps:
|
|
26
27
|
|
|
27
28
|
```bash
|
|
28
29
|
npm install \
|
|
29
30
|
react@18.3.1 react-dom@18.3.1 \
|
|
30
|
-
@sito/dashboard@^0.0.
|
|
31
|
+
@sito/dashboard@^0.0.73 \
|
|
31
32
|
@tanstack/react-query@5.83.0 \
|
|
32
33
|
react-hook-form@7.61.1 \
|
|
33
34
|
@fortawesome/fontawesome-svg-core@7.0.0 \
|
|
@@ -37,6 +38,12 @@ npm install \
|
|
|
37
38
|
@fortawesome/react-fontawesome@0.2.3
|
|
38
39
|
```
|
|
39
40
|
|
|
41
|
+
If your app uses the Supabase backend:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
npm install @supabase/supabase-js@2.100.0
|
|
45
|
+
```
|
|
46
|
+
|
|
40
47
|
## Core exports
|
|
41
48
|
|
|
42
49
|
- Layout and navigation: `Page`, `Navbar`, `Drawer`, `TabsLayout`, `PrettyGrid`, `ToTop`
|
|
@@ -44,7 +51,7 @@ npm install \
|
|
|
44
51
|
- Dialogs and forms: `Dialog`, `FormDialog`, `ImportDialog`, form inputs
|
|
45
52
|
- Feedback: `Notification`, `Loading`, `Empty`, `Error`, `Onboarding`
|
|
46
53
|
- Hooks: `useFormDialog` (generic state/entity), `usePostDialog`, `usePutDialog`, `useImportDialog`, `useDeleteDialog`, `usePostForm`, `useDeleteAction`, `useNavbar`, and more — all action hooks ship with default `sticky`, `multiple`, `id`, `icon`, and `tooltip` values so only `onClick` is required
|
|
47
|
-
- Providers and utilities: `ConfigProvider`, `ManagerProvider`, `AuthProvider`, `NotificationProvider`, `DrawerMenuProvider`, `NavbarProvider`, DTOs, API clients
|
|
54
|
+
- Providers and utilities: `ConfigProvider`, `ManagerProvider`, `SupabaseManagerProvider`, `AuthProvider`, `SupabaseAuthProvider`, `NotificationProvider`, `DrawerMenuProvider`, `NavbarProvider`, DTOs, API clients (`BaseClient`, `IndexedDBClient`, `SupabaseDataClient`), and `useSupabase`
|
|
48
55
|
|
|
49
56
|
## Component usage patterns
|
|
50
57
|
|
|
@@ -319,6 +326,132 @@ Notes:
|
|
|
319
326
|
- `NavbarProvider` is required when using `Navbar` or `useNavbar`; otherwise it can be omitted.
|
|
320
327
|
- If you customize auth storage keys in `AuthProvider`, pass the same keys to `IManager`/`BaseClient` auth config.
|
|
321
328
|
|
|
329
|
+
## Supabase setup (optional backend)
|
|
330
|
+
|
|
331
|
+
The library does not read `.env` values directly. The consumer app must create the Supabase client and pass it to `SupabaseManagerProvider`.
|
|
332
|
+
|
|
333
|
+
Use frontend-safe keys only:
|
|
334
|
+
|
|
335
|
+
- `VITE_SUPABASE_URL`
|
|
336
|
+
- `VITE_SUPABASE_ANON_KEY`
|
|
337
|
+
|
|
338
|
+
Do not expose service-role keys in the browser.
|
|
339
|
+
|
|
340
|
+
```tsx
|
|
341
|
+
import type { ReactNode } from "react";
|
|
342
|
+
import { createClient } from "@supabase/supabase-js";
|
|
343
|
+
import { Link } from "react-router-dom";
|
|
344
|
+
import {
|
|
345
|
+
ConfigProvider,
|
|
346
|
+
SupabaseManagerProvider,
|
|
347
|
+
SupabaseAuthProvider,
|
|
348
|
+
NotificationProvider,
|
|
349
|
+
DrawerMenuProvider,
|
|
350
|
+
NavbarProvider,
|
|
351
|
+
} from "@sito/dashboard-app";
|
|
352
|
+
|
|
353
|
+
const supabase = createClient(
|
|
354
|
+
import.meta.env.VITE_SUPABASE_URL,
|
|
355
|
+
import.meta.env.VITE_SUPABASE_ANON_KEY,
|
|
356
|
+
);
|
|
357
|
+
|
|
358
|
+
function AppProviders({ children }: { children: ReactNode }) {
|
|
359
|
+
return (
|
|
360
|
+
<ConfigProvider
|
|
361
|
+
location={window.location}
|
|
362
|
+
navigate={() => {}}
|
|
363
|
+
linkComponent={Link}
|
|
364
|
+
>
|
|
365
|
+
<SupabaseManagerProvider supabase={supabase}>
|
|
366
|
+
<SupabaseAuthProvider>
|
|
367
|
+
<NotificationProvider>
|
|
368
|
+
<DrawerMenuProvider>
|
|
369
|
+
<NavbarProvider>{children}</NavbarProvider>
|
|
370
|
+
</DrawerMenuProvider>
|
|
371
|
+
</NotificationProvider>
|
|
372
|
+
</SupabaseAuthProvider>
|
|
373
|
+
</SupabaseManagerProvider>
|
|
374
|
+
</ConfigProvider>
|
|
375
|
+
);
|
|
376
|
+
}
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
`useAuth` keeps the same contract with `SupabaseAuthProvider` (`account`, `logUser`, `logoutUser`, `logUserFromLocal`, `isInGuestMode`, `setGuestMode`).
|
|
380
|
+
|
|
381
|
+
`SupabaseDataClient` follows the same generic surface as `BaseClient` and `IndexedDBClient`, so entity clients can switch backend with minimal UI/hook changes.
|
|
382
|
+
It also supports optional configuration for conventional columns: `idColumn` (default `"id"`), `deletedAtColumn` (default `"deletedAt"`), and `defaultSortColumn`.
|
|
383
|
+
|
|
384
|
+
### Supabase entity client example
|
|
385
|
+
|
|
386
|
+
```ts
|
|
387
|
+
import type { SupabaseClient } from "@supabase/supabase-js";
|
|
388
|
+
import {
|
|
389
|
+
BaseCommonEntityDto,
|
|
390
|
+
BaseEntityDto,
|
|
391
|
+
BaseFilterDto,
|
|
392
|
+
DeleteDto,
|
|
393
|
+
ImportPreviewDto,
|
|
394
|
+
SupabaseDataClient,
|
|
395
|
+
} from "@sito/dashboard-app";
|
|
396
|
+
|
|
397
|
+
interface ProductDto extends BaseEntityDto {
|
|
398
|
+
name: string;
|
|
399
|
+
price: number;
|
|
400
|
+
categoryId?: number;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
interface ProductCommonDto extends BaseCommonEntityDto {
|
|
404
|
+
name: string;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
interface CreateProductDto {
|
|
408
|
+
name: string;
|
|
409
|
+
price: number;
|
|
410
|
+
categoryId?: number;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
interface UpdateProductDto extends DeleteDto {
|
|
414
|
+
name?: string;
|
|
415
|
+
price?: number;
|
|
416
|
+
categoryId?: number;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
interface ProductFilterDto extends BaseFilterDto {
|
|
420
|
+
categoryId?: number;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
interface ProductImportPreviewDto extends ImportPreviewDto {
|
|
424
|
+
id: number;
|
|
425
|
+
name: string;
|
|
426
|
+
price: number;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
class ProductsSupabaseClient extends SupabaseDataClient<
|
|
430
|
+
"products",
|
|
431
|
+
ProductDto,
|
|
432
|
+
ProductCommonDto,
|
|
433
|
+
CreateProductDto,
|
|
434
|
+
UpdateProductDto,
|
|
435
|
+
ProductFilterDto,
|
|
436
|
+
ProductImportPreviewDto
|
|
437
|
+
> {
|
|
438
|
+
constructor(supabase: SupabaseClient) {
|
|
439
|
+
super("products", supabase, {
|
|
440
|
+
defaultSortColumn: "id",
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
const productsClient = new ProductsSupabaseClient(supabase);
|
|
446
|
+
```
|
|
447
|
+
|
|
448
|
+
### Compatibility and incremental migration
|
|
449
|
+
|
|
450
|
+
- The REST flow stays intact: existing apps using `ManagerProvider` + `AuthProvider` + `BaseClient` do not need changes.
|
|
451
|
+
- You can migrate entity by entity: move one resource client at a time from `BaseClient` to `SupabaseDataClient`.
|
|
452
|
+
- During migration, mixed data backends are valid (`BaseClient` for some entities, `SupabaseDataClient` for others) as long as each UI flow uses the corresponding client methods.
|
|
453
|
+
- If you switch auth to Supabase, use `SupabaseManagerProvider` + `SupabaseAuthProvider`; if you keep REST auth, continue with `ManagerProvider` + `AuthProvider`.
|
|
454
|
+
|
|
322
455
|
## Built-in auth refresh behavior
|
|
323
456
|
|
|
324
457
|
`APIClient` and `BaseClient` already include refresh/retry behavior for secured requests:
|
|
@@ -453,9 +586,11 @@ Contract and filtering notes:
|
|
|
453
586
|
- Preferred update contract is `update(value)` (aligned with `BaseClient.update(value)`).
|
|
454
587
|
- Legacy `update(id, value)` remains temporarily supported for backward compatibility.
|
|
455
588
|
- Filtering uses strict equality for regular keys.
|
|
456
|
-
- `deletedAt`
|
|
457
|
-
|
|
458
|
-
- `
|
|
589
|
+
- `deletedAt` remains a date filter (`Date | null`) for exact-match filtering.
|
|
590
|
+
- Use `softDeleteScope` for trash filters:
|
|
591
|
+
- `softDeleteScope: "ACTIVE"` => active rows (`deletedAt` null/undefined)
|
|
592
|
+
- `softDeleteScope: "DELETED"` => deleted rows (`deletedAt` not null/undefined)
|
|
593
|
+
- `softDeleteScope: "ALL"` => all rows
|
|
459
594
|
|
|
460
595
|
## Tests
|
|
461
596
|
|
package/dist/dashboard-app.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var Xe=Object.defineProperty;var Ze=(n,e,t)=>e in n?Xe(n,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[e]=t;var A=(n,e,t)=>Ze(n,typeof e!="symbol"?e+"":e,t);var rs=require("./main.css");Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("@sito/dashboard"),l=require("react/jsx-runtime"),M=require("@fortawesome/react-fontawesome"),d=require("react"),j=require("@fortawesome/free-solid-svg-icons"),ve=require("react-dom"),$=require("@tanstack/react-query"),et=require("@fortawesome/free-regular-svg-icons"),Ee=require("react-hook-form"),ke=n=>n==null?!1:`${n}`.length>0,tt=d.forwardRef(function(n,e){const{value:t,defaultValue:s,onChange:r,state:a=w.State.default,name:o="",id:c="",label:i="",disabled:m=!1,required:u=!1,containerClassName:f="",inputClassName:p="",labelClassName:g="",helperText:h="",helperTextClassName:b="",...y}=n,x=t!==void 0,[C,v]=d.useState(()=>ke(s)),N=x?ke(t):C,T=P=>{x||v(P.currentTarget.value.length>0),r==null||r(P)};return l.jsxs("div",{className:`form-paragraph-container group ${f}`,children:[l.jsx("textarea",{ref:e,name:o,id:c,className:`text-input text-area form-paragraph-textarea peer ${w.inputStateClassName(a)} ${N?"has-value":""} ${y.placeholder?"has-placeholder":""} ${p}`,required:u,defaultValue:s,...x?{value:t}:{},onChange:T,disabled:m,...y}),l.jsxs("label",{htmlFor:c,className:`text-input-label ${w.labelStateClassName(a)} ${g}`,children:[i,u?" *":""]}),!!h&&l.jsx("p",{className:`text-input-helper-text ${w.helperTextStateClassName(a)} ${b}`,children:h})]})}),st=n=>{const{t:e}=w.useTranslation(),{children:t,handleSubmit:s,onSubmit:r,isLoading:a=!1,buttonEnd:o=!0,reset:c}=n;return l.jsxs("form",{className:"form-container",onSubmit:s(r),children:[t,l.jsxs("div",{className:`form-actions ${o?"end":""}`,children:[l.jsxs(w.Button,{type:"submit",color:"primary",variant:"submit",disabled:a,name:e("_accessibility:buttons.submit"),"aria-label":e("_accessibility:ariaLabels.submit"),children:[a?l.jsx(w.Loading,{color:"stroke-base",loaderClass:"!w-6 mt-1",strokeWidth:"6"}):null,e("_accessibility:buttons.submit")]}),l.jsx(w.Button,{type:"button",variant:"outlined",onClick:()=>c==null?void 0:c(),name:e("_accessibility:buttons.cancel"),"aria-label":e("_accessibility:ariaLabels.cancel"),children:e("_accessibility:buttons.cancel")})]})]})},nt=d.forwardRef(function(n,e){const{t}=w.useTranslation(),[s,r]=d.useState(!1);return l.jsx(w.TextInput,{...n,type:s?"text":"password",ref:e,children:l.jsx(q,{type:"button",tabIndex:-1,"aria-label":t(s?"_accessibility:ariaLabels.hidePassword":"_accessibility:ariaLabels.showPassword"),className:"password-icon",onClick:()=>r(!s),icon:s?j.faEyeSlash:j.faEye})})}),ie=n=>{const{t:e}=w.useTranslation(),{title:t,children:s,handleClose:r,open:a=!1,containerClassName:o="",className:c="",animationClass:i="appear"}=n,m=d.useCallback(f=>{f.key==="Escape"&&a&&r()},[a,r]);d.useEffect(()=>(window.addEventListener("keydown",m),()=>{window.removeEventListener("keydown",m)}),[m]);const u=d.useCallback(f=>{f.target===f.currentTarget&&r()},[r]);return d.useEffect(()=>{const f=p=>{p?document.body.style.overflow="hidden":document.body.style.overflow="auto"};return f(a),()=>{f(!1)}},[a]),ve.createPortal(l.jsx("div",{"aria-label":e("_accessibility:ariaLabels.closeDialog"),"aria-hidden":!a,onClick:u,className:`dialog-backdrop animated ${a?`opened ${i}`:"closed"} ${o}`,children:l.jsxs("div",{className:`dialog elevated animated ${a?`opened ${i}`:"closed"} ${c}`,children:[l.jsxs("div",{className:"dialog-header",children:[l.jsx("h3",{className:"dialog-title",children:t}),l.jsx(q,{icon:j.faClose,disabled:!a,"aria-disabled":!a,onClick:r,variant:"text",color:"error",className:"icon-button dialog-close-btn",name:e("_accessibility:buttons.closeDialog"),"aria-label":e("_accessibility:ariaLabels.closeDialog")})]}),s]})}),document.body)},ce=n=>{const{primaryText:e,cancelText:t,onPrimaryClick:s,onCancel:r,isLoading:a=!1,disabled:o=!1,primaryType:c="submit",containerClassName:i="",primaryClassName:m="",alignEnd:u=!1,primaryName:f,primaryAriaLabel:p,cancelName:g,cancelAriaLabel:h,extraActions:b=[]}=n;return l.jsxs("div",{className:`dialog-actions ${u?"end":""} ${i}`,children:[l.jsxs(w.Button,{type:c,color:"primary",variant:"submit",className:m,disabled:o,onClick:s,name:f,"aria-label":p,children:[a?l.jsx(w.Loading,{color:"stroke-base",loaderClass:"!w-6 mt-1",strokeWidth:"6"}):null,e]}),b==null?void 0:b.map(y=>l.jsx(w.Button,{...y},y.id)),l.jsx(w.Button,{type:"button",variant:"outlined",disabled:o,onClick:r,name:g,"aria-label":h,children:t})]})},rt=n=>{const{t:e}=w.useTranslation(),{children:t,handleSubmit:s,onSubmit:r,handleClose:a,isLoading:o=!1,buttonEnd:c=!0,extraActions:i=[],...m}=n;return l.jsx(ie,{...m,handleClose:a,children:l.jsxs("form",{onSubmit:s(r),children:[l.jsx("div",{className:"form-container",children:t}),l.jsx(ce,{primaryType:"submit",primaryText:e("_accessibility:buttons.submit"),cancelText:e("_accessibility:buttons.cancel"),onCancel:a,isLoading:o,disabled:o,primaryClassName:"dialog-form-primary",alignEnd:c,primaryName:e("_accessibility:buttons.submit"),primaryAriaLabel:e("_accessibility:ariaLabels.submit"),cancelName:e("_accessibility:buttons.cancel"),cancelAriaLabel:e("_accessibility:ariaLabels.cancel"),extraActions:i})]})})},at=n=>{const{t:e}=w.useTranslation(),{children:t,handleSubmit:s,handleClose:r,isLoading:a=!1,extraActions:o=[],...c}=n;return l.jsxs(ie,{...c,handleClose:r,children:[t,l.jsx(ce,{primaryText:e("_accessibility:buttons.ok"),cancelText:e("_accessibility:buttons.cancel"),onPrimaryClick:s,onCancel:r,isLoading:a,disabled:a,primaryType:"button",containerClassName:"mt-5",primaryName:e("_accessibility:buttons.ok"),primaryAriaLabel:e("_accessibility:ariaLabels.ok"),cancelName:e("_accessibility:buttons.cancel"),cancelAriaLabel:e("_accessibility:ariaLabels.cancel"),extraActions:o})]})};function ot(n){const{message:e,className:t=""}=n,{t:s}=w.useTranslation();return l.jsx("p",{className:`import-error-message ${t}`,children:e??s("_messages:errors.parseFile",{defaultValue:"Failed to process file"})})}function it(n){const{message:e,className:t=""}=n,{t:s}=w.useTranslation();return l.jsxs("div",{className:`import-loading ${t}`,children:[l.jsx(w.Loading,{loaderClass:"w-5 h-5",className:"!w-auto"}),l.jsx("span",{children:e??s("_messages:loading.processingFile",{defaultValue:"Processing file..."})})]})}function ct(n){const{items:e,max:t=5,className:s=""}=n,{t:r}=w.useTranslation();if(!e||e.length===0)return null;const a=e.slice(0,t);return l.jsxs("div",{className:`import-preview ${s}`,children:[l.jsx("p",{className:"import-preview-count",children:r("_pages:common.actions.import.previewCount",{count:e.length,defaultValue:`Preview: ${e.length} items`})}),l.jsx("pre",{className:"import-preview-content",children:JSON.stringify(a,null,2)})]})}const Ne=()=>({file:null,previewItems:null,parseError:null,processing:!1,overrideExisting:!1,inputKey:0});function lt(n,e){switch(e.type){case"SET_FILE":return{...n,file:e.file,previewItems:null,parseError:null,processing:!1};case"START_PROCESSING":return{...n,processing:!0};case"SET_PREVIEW":return{...n,previewItems:e.items,parseError:null,processing:!1};case"SET_ERROR":return{...n,previewItems:null,parseError:e.message,processing:!1};case"SET_OVERRIDE":return{...n,overrideExisting:e.value};case"RESET":return{...Ne(),inputKey:n.inputKey+1}}}const ut=n=>{const{t:e}=w.useTranslation(),{children:t,handleSubmit:s,handleClose:r,isLoading:a=!1,fileProcessor:o,onFileProcessed:c,renderCustomPreview:i,onOverrideChange:m,open:u,extraActions:f=[],...p}=n,[g,h]=d.useReducer(lt,Ne()),{file:b,previewItems:y,parseError:x,processing:C,overrideExisting:v,inputKey:N}=g,T=d.useRef(c),P=d.useRef(o);d.useEffect(()=>{T.current=c},[c]),d.useEffect(()=>{P.current=o},[o]),d.useEffect(()=>{u||h({type:"RESET"})},[u]);const K=d.useCallback(async(k,E)=>{var L;if(P.current){h({type:"START_PROCESSING"});try{const R=await P.current(k,{override:E});h({type:"SET_PREVIEW",items:R??[]}),(L=T.current)==null||L.call(T,R??[])}catch(R){console.error(R);const O=R instanceof Error?R.message:"Failed to parse file";h({type:"SET_ERROR",message:O})}}},[]);return l.jsxs(ie,{...p,open:u,handleClose:r,children:[l.jsx(w.FileInput,{onClear:()=>{var k;h({type:"SET_FILE",file:null}),(k=T.current)==null||k.call(T,[])},onChange:k=>{var L,R;const E=(L=k.target.files)==null?void 0:L[0];if(!E){h({type:"SET_FILE",file:null}),(R=T.current)==null||R.call(T,[]);return}h({type:"SET_FILE",file:E}),K(E,v)},label:e("_accessibility:labels.file")},N),l.jsxs("label",{className:"import-override-label",children:[l.jsx("input",{type:"checkbox",checked:v,onChange:k=>{const E=k.target.checked;h({type:"SET_OVERRIDE",value:E}),m==null||m(E),b&&K(b,E)}}),l.jsx("span",{children:e("_pages:common.actions.import.override",{defaultValue:"Override existing items"})})]}),l.jsx(ot,{message:x}),C&&l.jsx(it,{}),i?i(y):!!y&&y.length>0&&l.jsx(ct,{items:y}),t,l.jsx(ce,{primaryText:e("_accessibility:buttons.ok"),cancelText:e("_accessibility:buttons.cancel"),onPrimaryClick:()=>{(!o||!!y&&y.length>0)&&s()},onCancel:r,isLoading:a,primaryType:"button",containerClassName:"import-dialog-actions",primaryName:e("_accessibility:buttons.ok"),primaryAriaLabel:e("_accessibility:ariaLabels.ok"),cancelName:e("_accessibility:buttons.cancel"),cancelAriaLabel:e("_accessibility:ariaLabels.cancel"),extraActions:f})]})};var I=(n=>(n[n.success=0]="success",n[n.error=1]="error",n[n.warning=2]="warning",n[n.info=3]="info",n))(I||{}),F=(n=>(n.GET="GET",n.POST="POST",n.PUT="PUT",n.PATCH="PATCH",n.DELETE="DELETE",n))(F||{});const dt=n=>Array.isArray(n)||n instanceof Headers?!1:typeof n=="object"&&n!==null&&("headers"in n||"credentials"in n),mt=n=>n?dt(n)?n:{headers:n}:{},ft=n=>n?n instanceof Headers?Object.fromEntries(n.entries()):Array.isArray(n)?Object.fromEntries(n):n:{};async function oe(n,e="GET",t,s){const r=mt(s),a={...t!==void 0?{"Content-Type":"application/json"}:{},...ft(r.headers)};try{const o=await fetch(n,{method:e,headers:a,...r.credentials?{credentials:r.credentials}:{},...t!==void 0?{body:JSON.stringify(t)}:{}}),c=await o.text();let i=null;try{i=c?JSON.parse(c):null}catch{i=null}if(!o.ok){const m=typeof i=="object"&&i!==null?i.message??i.error??c:c||o.statusText;return{data:null,status:o.status,error:{status:o.status,message:m||"Unknown error occurred"}}}return{data:o.status!==204&&i!==null?i:null,status:o.status,error:null}}catch(o){return{data:null,status:500,error:{status:500,message:o instanceof Error?o.message:"Unknown error occurred"}}}}function je(n,e){if(e){const t=Object.entries(e).filter(([,s])=>s!=null).map(([s,r])=>`${encodeURIComponent(s)}=${encodeURIComponent(String(r))}`).join("&");return t?`${n}?${t}`:n}return n}const fe=(n,e,t)=>{const s=[];if(e){const{sortingBy:r,sortingOrder:a,currentPage:o,pageSize:c}=e;r!==void 0&&s.push(`sort=${String(r)}`),a!==void 0&&s.push(`order=${a}`),o!==void 0&&s.push(`page=${o}`),c!==void 0&&s.push(`pageSize=${c}`)}if(t){const r=Object.entries(t).filter(([,a])=>a!=null&&a!=="").flatMap(([a,o])=>{if(Array.isArray(o))return o.map(c=>`${a}==${encodeURIComponent((c==null?void 0:c.id)??c)}`);if(typeof o=="object"&&o!==null&&"start"in o&&"end"in o){const c=[];return o.start!=null&&o.start!==""&&c.push(`${a}>=${encodeURIComponent(o.start)}`),o.end!=null&&o.end!==""&&c.push(`${a}<=${encodeURIComponent(o.end)}`),c}return typeof o=="object"&&o!==null?`${a}==${encodeURIComponent(o.id??"")}`:`${a}==${encodeURIComponent(o)}`});r.length>0&&s.push(`filters=${r.join(",")}`)}return s.length?`${n}?${s.join("&")}`:n},J=class J{constructor(e,t="user",s=!0,r,a={}){A(this,"baseUrl");A(this,"userKey");A(this,"rememberKey");A(this,"refreshTokenKey");A(this,"accessTokenExpiresAtKey");A(this,"refreshEndpoint");A(this,"refreshExpirySkewMs");A(this,"secured");A(this,"tokenAcquirer");this.baseUrl=e,this.secured=s,this.userKey=t,this.rememberKey=a.rememberKey??"remember",this.refreshTokenKey=a.refreshTokenKey??"refreshToken",this.accessTokenExpiresAtKey=a.accessTokenExpiresAtKey??"accessTokenExpiresAt",this.refreshEndpoint=a.refreshEndpoint??"auth/refresh",this.refreshExpirySkewMs=a.refreshExpirySkewMs??5e3,this.tokenAcquirer=r??this.defaultTokenAcquirer}defaultTokenAcquirer(e){if(e)return{credentials:"include"};const t=V(this.userKey);if(t&&t.length)return{Authorization:`Bearer ${t}`}}getRefreshLockKey(){return`${this.baseUrl}|${this.userKey}|${this.refreshTokenKey}|${this.accessTokenExpiresAtKey}`}buildUrl(e){const t=this.baseUrl.endsWith("/")?this.baseUrl.slice(0,-1):this.baseUrl,s=e.startsWith("/")?e:`/${e}`;return`${t}${s}`}getRefreshToken(){const e=V(this.refreshTokenKey);if(typeof e=="string"&&e.length)return e}getAccessTokenExpiresAt(){const e=V(this.accessTokenExpiresAtKey);if(typeof e=="string"&&e.length)return e}canRefresh(){return!!this.getRefreshToken()}shouldRefreshBeforeRequest(){const e=this.getRefreshToken(),t=this.getAccessTokenExpiresAt();if(!e||!t)return!1;const s=Date.parse(t);return Number.isNaN(s)?!1:Date.now()>=s-this.refreshExpirySkewMs}clearStoredSession(){_(this.userKey),_(this.rememberKey),_(this.refreshTokenKey),_(this.accessTokenExpiresAtKey)}storeSession(e,t){Q(this.userKey,e.token);const s=e.refreshToken===void 0?t:e.refreshToken;typeof s=="string"&&s.length?Q(this.refreshTokenKey,s):_(this.refreshTokenKey),typeof e.accessTokenExpiresAt=="string"&&e.accessTokenExpiresAt.length?Q(this.accessTokenExpiresAtKey,e.accessTokenExpiresAt):_(this.accessTokenExpiresAtKey)}async refreshAccessTokenWithMutex(){const e=this.getRefreshToken();if(!e)throw{status:401,message:"Missing refresh token"};const t=this.getRefreshLockKey(),s=J.refreshInFlight.get(t);if(s){await s;return}const r=(async()=>{const{data:a,status:o,error:c}=await oe(this.buildUrl(this.refreshEndpoint),F.POST,{refreshToken:e});if(c||!(a!=null&&a.token))throw this.clearStoredSession(),c??{status:o,message:"Unable to refresh session"};this.storeSession(a,e)})();J.refreshInFlight.set(t,r);try{await r}finally{J.refreshInFlight.delete(t)}}isRequestOptions(e){return Array.isArray(e)||e instanceof Headers?!1:typeof e=="object"&&e!==null&&("headers"in e||"credentials"in e)}toRequestOptions(e){return e?this.isRequestOptions(e)?e:{headers:e}:{}}toHeaderRecord(e){return e?e instanceof Headers?Object.fromEntries(e.entries()):Array.isArray(e)?Object.fromEntries(e):e:{}}mergeRequestConfig(e){const t=this.secured?this.tokenAcquirer():void 0,s=this.toRequestOptions(t),r=this.toRequestOptions(e),a={...this.toHeaderRecord(s.headers),...this.toHeaderRecord(r.headers)},o=r.credentials??s.credentials,c=Object.keys(a).length>0;if(o)return c?{headers:a,credentials:o}:{credentials:o};if(c)return a}async makeRequestWithRefresh(e,t,s,r){this.secured&&this.shouldRefreshBeforeRequest()&&await this.refreshAccessTokenWithMutex();let a=await oe(this.buildUrl(e),t,s,this.mergeRequestConfig(r));return this.secured&&a.status===401&&this.canRefresh()&&(await this.refreshAccessTokenWithMutex(),a=await oe(this.buildUrl(e),t,s,this.mergeRequestConfig(r))),a}async doQuery(e,t=F.GET,s,r){const{data:a,status:o,error:c}=await this.makeRequestWithRefresh(e,t,s,r);if(c||o<200||o>=300)throw c??{status:o,message:String(o)};return a}async get(e,t,s){const r=fe(e,t,s),{data:a,error:o,status:c}=await this.makeRequestWithRefresh(r,F.GET);if(o||c<200||c>=300||!a)throw o??{status:c,message:String(c)};return a}async patch(e,t){const{error:s,data:r,status:a}=await this.makeRequestWithRefresh(e,F.PATCH,t);if(s||r===null||r===void 0)throw s??{status:a,message:"Unknown error"};return r}async delete(e,t){const{error:s,data:r,status:a}=await this.makeRequestWithRefresh(e,F.DELETE,t);if(s||r===null||r===void 0)throw s??{status:a,message:"Unknown error"};return r}async post(e,t){const{error:s,data:r,status:a}=await this.makeRequestWithRefresh(e,F.POST,t);if(s||r===null||r===void 0)throw s??{status:a,message:"Unknown error"};return r}};A(J,"refreshInFlight",new Map);let Z=J;class Ae{constructor(e,t="user",s={}){A(this,"api");this.api=new Z(e,t,!1,void 0,s)}async login(e){const t="auth/sign-in",s=e;return await this.api.doQuery(t,F.POST,s)}async refresh(e){return await this.api.doQuery("auth/refresh",F.POST,e)}async logout(e){const t="auth/sign-out",s=e!=null&&e.accessToken?{Authorization:`Bearer ${e.accessToken}`}:void 0,r=e!=null&&e.refreshToken?{refreshToken:e.refreshToken}:void 0;return await this.api.doQuery(t,F.POST,r,s)}async register(e){return await this.api.doQuery("auth/sign-up",F.POST,e)}async getSession(){return await this.api.doQuery("auth/session",F.GET,void 0,this.api.defaultTokenAcquirer())}}class ht{constructor(e,t,s={}){A(this,"auth");this.auth=new Ae(e,t,s)}get Auth(){return this.auth}}class pt{constructor(e,t,s="user",r=!0,a={}){A(this,"table");A(this,"secured");A(this,"api");this.table=e,this.secured=r,this.api=new Z(t,s,r,void 0,a)}async insert(e){return await this.api.post(`${this.table}`,e)}async insertMany(e){return await this.api.doQuery(`${this.table}/batch`,F.POST,e)}async update(e){return await this.api.patch(`${this.table}/${e.id}`,e)}async get(e,t){return await this.api.get(`${this.table}`,e,t)}async export(e){const t=fe(`${this.table}/export`,void 0,e);return await this.api.doQuery(t,F.GET,void 0)}async import(e){return await this.api.doQuery(`${this.table}/import`,F.POST,e)}async commonGet(e){return await this.api.doQuery(je(`${this.table}/common`,e),F.GET)}async getById(e){return await this.api.doQuery(`${this.table}/${e}`)}async softDelete(e){return await this.api.delete(`${this.table}`,e)}async restore(e){return await this.api.patch(`${this.table}/restore`,e)}}class gt{constructor(e,t,s=1){A(this,"table");A(this,"dbName");A(this,"version");A(this,"db",null);this.table=e,this.dbName=t,this.version=s}close(){this.db&&(this.db.onversionchange=null,this.db.close(),this.db=null)}open(){return this.db?Promise.resolve(this.db):new Promise((e,t)=>{const s=indexedDB.open(this.dbName,this.version);s.onupgradeneeded=r=>{const a=r.target.result;a.objectStoreNames.contains(this.table)||a.createObjectStore(this.table,{keyPath:"id",autoIncrement:!0})},s.onsuccess=r=>{this.db=r.target.result,this.db.onversionchange=()=>{this.close()},e(this.db)},s.onerror=r=>{t(r.target.error)}})}async transaction(e){return(await this.open()).transaction(this.table,e).objectStore(this.table)}request(e){return new Promise((t,s)=>{e.onsuccess=()=>t(e.result),e.onerror=()=>s(e.error)})}async insert(e){const t=await this.transaction("readwrite"),s=await this.request(t.add(e));return{...e,id:s}}async insertMany(e){const t=await this.transaction("readwrite");let s=0;for(const r of e)s=await this.request(t.add(r));return{...e[e.length-1],id:s}}async update(e,t){const s=typeof e=="number"?t:e;if(!s)throw new Error("IndexedDBClient.update requires a value payload");const r=typeof e=="number"?{...s,id:s.id??e}:s,a=await this.transaction("readwrite");return await this.request(a.put(r)),r}async get(e,t){var g;const s=await this.transaction("readonly"),r=await this.request(s.getAll()),a=this.applyFilter(r,t),o=(e==null?void 0:e.sortingBy)??"id",c=((g=e==null?void 0:e.sortingOrder)==null?void 0:g.toLowerCase())??"asc";a.sort((h,b)=>{const y=h[o],x=b[o];return y<x?c==="asc"?-1:1:y>x?c==="asc"?1:-1:0});const i=(e==null?void 0:e.pageSize)??10,m=(e==null?void 0:e.currentPage)??0,u=a.length,f=Math.ceil(u/i),p=a.slice(m*i,m*i+i);return{sort:o,order:c,currentPage:m,pageSize:i,totalElements:u,totalPages:f,items:p}}async export(e){const t=await this.transaction("readonly"),s=await this.request(t.getAll());return this.applyFilter(s,e)}async import(e){const t=await this.transaction("readwrite");let s=0;for(const r of e.items)e.override?await this.request(t.put(r)):await this.request(t.add(r)),s++;return s}async commonGet(e){const t=await this.transaction("readonly"),s=await this.request(t.getAll());return this.applyFilter(s,e)}async getById(e){const t=await this.transaction("readonly"),s=await this.request(t.get(e));if(!s)throw new Error(`Record ${e} not found in ${this.table}`);return s}async softDelete(e){const t=await this.transaction("readwrite");let s=0;for(const r of e){const a=await this.request(t.get(r));a&&(await this.request(t.put({...a,deletedAt:new Date})),s++)}return s}async restore(e){const t=await this.transaction("readwrite");let s=0;for(const r of e){const a=await this.request(t.get(r));a&&(await this.request(t.put({...a,deletedAt:null})),s++)}return s}applyFilter(e,t){return t?e.filter(s=>Object.entries(t).every(([r,a])=>this.matchesFilterValue(r,a,s[r]))):e}matchesFilterValue(e,t,s){if(t===void 0)return!0;if(e==="deletedAt"&&typeof t=="boolean"){const r=s!=null;return t?r:!r}return s===t}}function yt(n){return Object.keys(n).filter(e=>isNaN(Number(e))).map(e=>({key:e,value:n[e]}))}const V=(n,e="")=>{const t=localStorage.getItem(n)??void 0;if(t&&e.length)switch(e){case"object":return JSON.parse(t);case"number":return Number(t);case"boolean":return t==="true"||t==="1";default:return t}return t},Q=(n,e)=>localStorage.setItem(n,typeof e=="object"?JSON.stringify(e):e),_=n=>localStorage.removeItem(n);function bt(n){const e=n?new Date(n):new Date,t={weekday:"long",day:"numeric",month:"long",year:"numeric",hour:"numeric",minute:"2-digit",hour12:!0};return e.toLocaleString(navigator.language||"es-ES",t)}function wt(n){const e=n?new Date(n):new Date,t=String(e.getDate()).padStart(2,"0"),s=String(e.getMonth()+1).padStart(2,"0"),r=String(e.getFullYear()).slice(-2),a=String(e.getHours()).padStart(2,"0"),o=String(e.getMinutes()).padStart(2,"0");return`${t}/${s}/${r} ${a}:${o}`}function xt(n){const e=n?new Date(n):new Date,t=e.getFullYear(),s=String(e.getMonth()+1).padStart(2,"0"),r=String(e.getDate()).padStart(2,"0"),a=String(e.getHours()).padStart(2,"0"),o=String(e.getMinutes()).padStart(2,"0");return`${t}-${s}-${r}T${a}:${o}`}const $e=()=>{var t;const n=navigator,e=((t=n==null?void 0:n.userAgentData)==null?void 0:t.platform)||(n==null?void 0:n.platform)||"";return/Mac|iPhone|iPod|iPad/i.test(e)};function ee(n){if(!n||typeof n!="object")return!1;const e=n;return Array.isArray(e.errors)&&e.errors.every(t=>Array.isArray(t)&&t.length===2&&typeof t[0]=="string")}function te(n){if(!n||typeof n!="object")return!1;const e=n;return typeof(e==null?void 0:e.status)=="number"&&typeof(e==null?void 0:e.message)=="string"}function Ct(n,e){return n!=null&&n.errors?n.errors.map(([t,s])=>e(t,s)):[]}const Le=d.createContext(void 0);function kt(n){const{children:e}=n,t=d.useRef(0),[s,r]=d.useReducer((p,g)=>{const{type:h,items:b,id:y}=g;switch(h){case"set":return b??[];case"remove":return y!==void 0?p.filter(x=>x.id!==y):[]}return p},[],()=>[]),a=p=>p.map(g=>({...g,id:t.current++})),o=d.useCallback(p=>r({type:"set",items:a([{...p,type:I.error}])}),[]),c=d.useCallback(p=>r({type:"set",items:a([{...p}])}),[]),i=d.useCallback(p=>r({type:"set",items:a(p)}),[]),m=d.useCallback(p=>r({type:"set",items:a([{...p,type:I.success}])}),[]),u=p=>r({type:"remove",id:p}),f=d.useMemo(()=>({notification:s,removeNotification:u,showErrorNotification:o,showNotification:c,showSuccessNotification:m,showStackNotifications:i}),[s,o,c,i,m]);return l.jsx(Le.Provider,{value:f,children:e})}const W=()=>{const n=d.useContext(Le);if(!n)throw new Error("NotificationContext must be used within a Provider");return n},he=()=>new $.QueryClient({defaultOptions:{queries:{refetchInterval:!1,refetchOnMount:!0,refetchOnReconnect:!1,retry:!1,retryOnMount:!0,refetchOnWindowFocus:!1}}}),St=he(),Re=d.createContext(void 0),Tt=n=>{const{children:e,manager:t,queryClient:s}=n,[r]=d.useState(he),a=s??r;return l.jsx(Re.Provider,{value:{client:t},children:l.jsx($.QueryClientProvider,{client:a,children:e})})},Ie=()=>{const n=d.useContext(Re);if(!n)throw new Error("managerContext must be used within a Provider");return n.client},Fe=d.createContext(void 0),vt=n=>{const{children:e,guestMode:t="guest_mode",user:s="user",remember:r="remember",refreshTokenKey:a="refreshToken",accessTokenExpiresAtKey:o="accessTokenExpiresAt"}=n,c=Ie(),[i,m]=d.useState({}),u=d.useCallback(()=>{_(s),_(r),_(a),_(o)},[o,a,r,s]),f=d.useCallback(()=>!!V(t,"boolean")&&i.token===void 0,[i.token,t]),p=d.useCallback(x=>{Q(t,x)},[t]),g=d.useCallback((x,C)=>{if(!x)return;const v=V(r,"boolean"),N=C??(typeof v=="boolean"?v:!1);m(x),_(t),Q(s,x.token),Q(r,N),typeof x.refreshToken=="string"&&x.refreshToken.length?Q(a,x.refreshToken):_(a),typeof x.accessTokenExpiresAt=="string"&&x.accessTokenExpiresAt.length?Q(o,x.accessTokenExpiresAt):_(o)},[o,t,a,r,s]),h=d.useCallback(async()=>{const x=V(s)??i.token,C=V(a)??(typeof i.refreshToken=="string"?i.refreshToken:void 0);try{await c.Auth.logout({accessToken:x,refreshToken:C})}catch(v){console.error(v)}m({}),u()},[i.refreshToken,i.token,u,c.Auth,a,s]),b=d.useCallback(async()=>{try{const x=await c.Auth.getSession();g(x)}catch(x){console.error(x),h()}},[g,h,c.Auth]),y=d.useMemo(()=>({account:i,logUser:g,logoutUser:h,logUserFromLocal:b,isInGuestMode:f,setGuestMode:p}),[i,g,h,b,f,p]);return l.jsx(Fe.Provider,{value:y,children:e})},pe=()=>{const n=d.useContext(Fe);if(!n)throw new Error("authContext must be used within a Provider");return n},_e=d.createContext({}),Et=n=>{const{children:e,location:t,navigate:s,linkComponent:r,searchComponent:a}=n;return l.jsx(_e.Provider,{value:{location:t,navigate:s,linkComponent:r,searchComponent:a},children:e})},Y=()=>{const n=d.useContext(_e);if(n===void 0||Object.keys(n).length===0)throw new Error("Config provider has not been set. This step is required and cannot be skipped.");return n},Nt={addChildItem:()=>{},removeChildItem:()=>{},clearDynamicItems:()=>{},dynamicItems:{}},ge=d.createContext(Nt),jt=n=>{const{children:e}=n,[t,s]=d.useState({}),r=d.useCallback((i,m)=>s(u=>({...u,[i]:[...u[i]??[],m]})),[]),a=d.useCallback((i,m)=>s(u=>({...u,[i]:(u[i]??[]).filter((f,p)=>p!==m)})),[]),o=d.useCallback(i=>{s(i?m=>({...m,[i]:[]}):{})},[]),c=d.useMemo(()=>({dynamicItems:t,addChildItem:r,removeChildItem:a,clearDynamicItems:o}),[t,o,a,r]);return l.jsx(ge.Provider,{value:c,children:e})},De=()=>d.useContext(ge);function At(n){const{t:e}=w.useTranslation(),{open:t,onClose:s,menuMap:r,logo:a}=n,{account:o}=pe(),{dynamicItems:c}=De(),{linkComponent:i,location:m}=Y(),u=i,f=d.useMemo(()=>r.filter(y=>{const x=y.auth,C=!!(o!=null&&o.email);return x==null||x&&C||!x&&!C}),[o==null?void 0:o.email,r]),p=d.useCallback(y=>{y.key==="Escape"&&t&&s()},[s,t]);d.useEffect(()=>(document.addEventListener("keydown",p),()=>{document.removeEventListener("keydown",p)}),[p]);const g=d.useCallback((y,x)=>x?y===`${m.pathname}${m.search}`:y===m.pathname,[m.pathname,m.search]),h=d.useCallback(y=>l.jsx("li",{className:`drawer-list-item-child ${g(y.path,!0)?"active":""} animated`,children:y.path?l.jsx(u,{tabIndex:t?0:-1,to:y.path??"/","aria-label":e(`_accessibility:ariaLabels.${y.id}`,{defaultValue:y.label}),className:"drawer-link",children:y.label}):y.label},y.id),[u,t,e,g]),b=d.useMemo(()=>f.map((y,x)=>{const C=y.page??String(x),v=`drawer-list-item ${g(y.path)?"active":""} animated`;if(y.type==="divider")return l.jsx("li",{className:v,children:l.jsx("hr",{className:"drawer-divider"})},C);const N=y.children??(y.page&&c?c[y.page]:null);return l.jsxs("li",{className:v,children:[l.jsxs(u,{tabIndex:t?0:-1,to:y.path??"/","aria-label":e(`_accessibility:ariaLabels.${String(y.page)}`,{defaultValue:e(`_pages:${String(y.page)}.title`)}),className:"drawer-link",children:[y.icon,e(`_pages:${y.page}.title`)]}),N&&l.jsx("ul",{className:"drawer-children-list",children:N.map(h)})]},C)}),[u,c,g,t,f,h,e]);return l.jsx("div",{"aria-label":e("_accessibility:ariaLabels.closeMenu"),"aria-disabled":!t,className:`${t?"opened":"closed"} drawer-backdrop`,onClick:()=>s(),children:l.jsxs("aside",{className:`${t?"opened":"closed"} drawer animated`,children:[l.jsxs("div",{className:"drawer-header-container",children:[a,l.jsx("h2",{className:"drawer-header poppins",children:e("_pages:home.appName")})]}),l.jsx("ul",{className:"drawer-menu-list",children:b})]})})}const q=({icon:n,...e})=>l.jsx(w.IconButton,{icon:l.jsx(M.FontAwesomeIcon,{icon:n}),...e});var de,Se;function $t(){if(Se)return de;Se=1;const n=(c,i="local",m=void 0)=>{if(i==="local"){if(localStorage.getItem(c)!==void 0&&localStorage.getItem(c)!=="undefined"&&localStorage.getItem(c)!==null)return m===void 0||m!==void 0&&localStorage.getItem(c)===m}else if(i==="session"&&sessionStorage.getItem(c)!==void 0&&sessionStorage.getItem(c)!=="undefined"&&sessionStorage.getItem(c)!==null)return m===void 0||m!==void 0&&sessionStorage.getItem(c)===m;return!1},e=c=>{const i={};return c.substring(1).split("&").forEach(u=>{const[f,p]=u.split("=");i[f]=p}),i},t=(c="")=>{if(a(c)&&c.length)return a(c);{let i=navigator.language||navigator.userLanguage;if(i.indexOf("en")<0&&i.indexOf("es")<0&&(i="en-US"),i=i.split("-")[0],i)return c.length&&r(c,730,i),i}return"en"},s=(c=0,i=0,m=window,u="smooth")=>m.scroll({top:c,left:i,behavior:u}),r=(c,i,m,u="/",f="Lax")=>{var p=new Date;p.setTime(p.getTime()+i*24*60*60*1e3);const g="; expires="+p.toUTCString();document.cookie=`${c}=${m||""}${g};path=${u};SameSite=${f}`},a=c=>{const i=`${c}=`,u=decodeURIComponent(document.cookie).split(";");for(let f=0;f<u.length;f+=1){let p=u[f];for(;p.charAt(0)===" ";)p=p.substring(1);if(p.indexOf(i)===0)return p.substring(i.length,p.length)}return""};return de={getCookie:a,createCookie:r,deleteCookie:c=>document.cookie=`${c}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`,getUserLanguage:t,scrollTo:s,parseQueries:e,validation:n},de}var Lt=$t();function Rt(){const{t:n,language:e}=w.useTranslation();return{timeAge:d.useCallback(s=>{const a=new Date-s,o=Math.floor(a/(1e3*60)),c=Math.floor(o/60),i=e==="es",m=n("_accessibility:labels.ago"),u=n("_accessibility:labels.minute"),f=n("_accessibility:labels.minutes"),p=n("_accessibility:labels.hour"),g=n("_accessibility:labels.hours"),h=n("_accessibility:labels.yesterday"),b=n("_accessibility:labels.justNow");return a<1e3*60?b:o<60?`${i?m:""} ${o} ${o===1?u:f} ${i?"":m}`:c<24?`${i?m:""} ${c} ${c===1?p:g} ${i?"":m}`:c<48?h:s.toLocaleDateString(navigator.language||"es-ES",{day:"2-digit",month:"2-digit",year:"numeric"})},[n,e])}}const ye=n=>{const{showSuccessNotification:e}=W(),{mutationFn:t,onError:s,onSuccess:r,onSuccessMessage:a}=n,[o,c]=d.useState([]),{open:i,handleClose:m,handleOpen:u}=be(),f=()=>{m(),c([])},p=async h=>{c(h),u()},g=$.useMutation({mutationFn:()=>t(Array.isArray(o)?o:[o]),onError:h=>{console.error(h),s&&s(h),f()},onSuccess:async h=>{r&&r(h),e({message:a}),f()}});return{open:i,onClick:p,close:f,dialogFn:g,isLoading:g.isPending}},It=n=>{const{t:e}=w.useTranslation(),{showStackNotifications:t,showSuccessNotification:s,showErrorNotification:r}=W(),a=$.useQueryClient(),{defaultValues:o,mutationFn:c,formToDto:i,onError:m,onSuccess:u,queryKey:f,onSuccessMessage:p}=n,{control:g,handleSubmit:h,reset:b,setError:y,getValues:x,setValue:C}=Ee.useForm({defaultValues:o}),v=d.useRef(null),N=d.useCallback(()=>{const k=document.activeElement;if(!(k instanceof HTMLElement)){v.current=null;return}v.current=k.closest("form")},[]),T=d.useCallback(k=>{const E=k==null?void 0:k.errors,L=[],R=v.current;if(!R)return L;let O=!1;return E&&E.forEach(([ne,le])=>{const H=R.querySelector(`[name="${ne}"]`);(H instanceof HTMLInputElement||H instanceof HTMLTextAreaElement||H instanceof HTMLSelectElement)&&(O||(H.focus(),O=!0),H.classList.add("error"),L.push(e(`_entities:${f}.${ne}.${le}`)))}),L},[e,f]),P=d.useCallback(()=>{const k=v.current;if(!k)return;k.querySelectorAll("input, textarea, select").forEach(L=>{L.classList.remove("error")})},[]),K=$.useMutation({mutationFn:c,onError:k=>{console.error(k);const E=k;if(m)m(k);else if(ee(E)){const L=T(E);t(L.map(R=>({message:R,type:I.error})))}else if(te(E)){const L=E.message||e("_accessibility:errors.500"),R=e(`_accessibility:errors.${E.status}`);r({message:R||L})}else r({message:e("_accessibility:errors.500")})},onSuccess:async k=>{await a.invalidateQueries({queryKey:f}),u&&u(k),p&&s({message:p})}});return{control:g,getValues:x,setValue:C,handleSubmit:h,onSubmit:k=>{N(),P(),K.mutate(i?i(k):k)},reset:b,setError:y,isLoading:K.isPending}},Me=n=>{const{t:e}=w.useTranslation(),{onClick:t,icon:s=j.faTrash,sticky:r=!0,hidden:a=!1,multiple:o=!0,disabled:c=!1,id:i=B.Delete,tooltip:m=e("_pages:common.actions.delete.text")}=n;return{action:d.useCallback(f=>({id:i,sticky:r,tooltip:m,multiple:o,onClick:()=>t([f==null?void 0:f.id]),hidden:!!f.deletedAt||a,disabled:!!f.deletedAt||c,icon:l.jsx(M.FontAwesomeIcon,{className:"text-bg-error",icon:s}),onMultipleClick:p=>t(p.map(g=>g.id))}),[c,a,s,i,o,t,r,m])}},Pe=n=>{const{t:e}=w.useTranslation(),{onClick:t,sticky:s=!0,hidden:r=!1,disabled:a=!1,multiple:o=!1,icon:c=j.faRotateLeft,id:i=B.Restore,tooltip:m=e("_pages:common.actions.restore.text")}=n;return{action:d.useCallback(f=>({id:i,sticky:s,tooltip:m,multiple:o,onClick:()=>t([f==null?void 0:f.id]),hidden:!f.deletedAt||r,disabled:!f.deletedAt||a,icon:l.jsx(M.FontAwesomeIcon,{className:"text-bg-error",icon:c}),onMultipleClick:p=>t(p.map(g=>g.id))}),[a,r,c,i,o,t,s,m])}},Ft=n=>{const{t:e}=w.useTranslation(),{onClick:t,hidden:s=!1,sticky:r=!0,disabled:a=!1,id:o=B.Edit,icon:c=j.faPencil,tooltip:i=e("_pages:common.actions.edit.text")}=n;return{action:d.useCallback(u=>({id:o,sticky:r,tooltip:i,onClick:()=>t(u==null?void 0:u.id),hidden:!!u.deletedAt||s,disabled:!!u.deletedAt||a,icon:l.jsx(M.FontAwesomeIcon,{className:"primary",icon:c})}),[a,s,c,o,t,r,i])}};var B=(n=>(n.Add="add",n.Edit="edit",n.Delete="delete",n.Restore="restore",n.Refresh="refresh",n.Export="export",n.Import="import",n))(B||{});const Oe=n=>{const{t:e}=w.useTranslation(),{onClick:t,hidden:s=!1,disabled:r=!1,isLoading:a=!1}=n;return{action:d.useCallback(()=>({id:B.Export,hidden:s,disabled:r,icon:l.jsx(M.FontAwesomeIcon,{className:`${a?"rotate":""}`,icon:a?j.faCircleNotch:j.faCloudArrowDown}),tooltip:e("_pages:common.actions.export.text"),onClick:t}),[r,s,a,t,e])}},qe=n=>{const{t:e}=w.useTranslation(),{onClick:t,hidden:s=!1,disabled:r=!1,isLoading:a=!1}=n;return{action:d.useCallback(()=>({id:B.Import,hidden:s,disabled:r,icon:l.jsx(M.FontAwesomeIcon,{className:`${a?"rotate":""}`,icon:a?j.faCircleNotch:j.faCloudUpload}),tooltip:e("_pages:common.actions.import.text"),onClick:t}),[r,s,a,t,e])}},_t=n=>{const{queryKey:e,onSuccess:t,...s}=n,r=$.useQueryClient(),{showStackNotifications:a}=W(),{t:o}=w.useTranslation(),{open:c,onClick:i,close:m,dialogFn:u,isLoading:f}=ye({onSuccessMessage:o("_pages:common.actions.delete.successMessage"),onError:g=>{const h=g;if(ee(h))a(h.errors.map(([b,y])=>({message:o(`_pages:${b}.errors.${y}`),type:I.error})));else if(te(h)){const b=h.message||o("_accessibility:errors.500"),y=o(`_accessibility:errors.${h.status}`);a([{message:y||b,type:I.error}])}},onSuccess:async g=>{await r.invalidateQueries({queryKey:e}),t&&t(g)},...s}),{action:p}=Me({onClick:i});return{onClick:i,title:o("_pages:common.actions.delete.dialog.title"),open:c,isLoading:f,handleSubmit:()=>u.mutate(),handleClose:m,action:p}},be=()=>{const[n,e]=d.useState(!1);return{open:n,setOpen:e,handleClose:()=>e(!1),handleOpen:()=>e(!0)}},Dt=n=>"mutationFn"in n&&"queryKey"in n,se=n=>{const e=Dt(n),t=e?n:void 0,s=e?void 0:n,r=e?"entity":(s==null?void 0:s.mode)??"state",{t:a}=w.useTranslation(),o=$.useQueryClient(),{showErrorNotification:c,showStackNotifications:i,showSuccessNotification:m}=W(),[u,f]=d.useState(),[p,g]=d.useState(!1),h=d.useRef(!1),b=d.useRef(),{open:y,handleClose:x,handleOpen:C}=be(),{control:v,handleSubmit:N,reset:T,setError:P,getValues:K,setValue:k}=Ee.useForm({defaultValues:(t==null?void 0:t.defaultValues)||(s==null?void 0:s.defaultValues)||{}}),E=d.useRef(null),L=d.useCallback(()=>{const S=document.activeElement;if(!(S instanceof HTMLElement)){E.current=null;return}E.current=S.closest("form")},[]),R=t?[...t.queryKey,u??0]:["__legacy-form-dialog-disabled__",u??0],{data:O,isLoading:ne}=$.useQuery({queryFn:async()=>{if(!(!(t!=null&&t.getFunction)||!u))return t.getFunction(u)},queryKey:R,enabled:!!(t!=null&&t.getFunction)&&!!u});d.useEffect(()=>{!t||!O||!t.dtoToForm||b.current!==O&&(T({...t.dtoToForm(O)}),b.current=O)},[O,t,T]),d.useEffect(()=>{if(s){if(!y){h.current=!1;return}if(!h.current){if(h.current=!0,s.reinitializeOnOpen&&s.mapIn){T(s.mapIn());return}if(s.reinitializeOnOpen&&s.defaultValues){T(s.defaultValues);return}s.resetOnOpen&&T(s.defaultValues||{})}}},[s,y,T]);const le=d.useCallback(S=>{const D=S==null?void 0:S.errors,U=[],z=E.current;if(!z||!t)return U;let xe=!1;return D&&D.forEach(([Ce,Ye])=>{const X=z.querySelector(`[name="${Ce}"]`);(X instanceof HTMLInputElement||X instanceof HTMLTextAreaElement||X instanceof HTMLSelectElement)&&(xe||(X.focus(),xe=!0),X.classList.add("error"),U.push(a(`_entities:${t.queryKey}.${Ce}.${Ye}`)))}),U},[t,a]),H=d.useCallback(()=>{const S=E.current;if(!S)return;S.querySelectorAll("input, textarea, select").forEach(U=>{U.classList.remove("error")})},[]),G=d.useCallback(()=>{H(),E.current=null,x(),T()},[x,H,T]),We=d.useCallback(S=>{f(S),C()},[C]),ue=$.useMutation({mutationFn:async S=>{if(t)return t.mutationFn(S)},onError:S=>{if(t)if(t.onError)t.onError(S);else{const D=S;if(ee(D)){const U=le(D);i(U.map(z=>({message:z,type:I.error})))}else if(te(D)){const U=D.message||a("_accessibility:errors.500"),z=a(`_accessibility:errors.${D.status}`);c({message:z||U})}else c({message:a("_accessibility:errors.500")})}},onSuccess:async S=>{t&&(await o.invalidateQueries({queryKey:t.queryKey}),t.onSuccess&&await t.onSuccess(S),m({message:t.onSuccessMessage}),G())}}),re=d.useCallback(S=>t?S:s!=null&&s.mapOut?s.mapOut(S,{id:u}):S,[s,u,t]),Ge=d.useCallback(async()=>{if(!(s!=null&&s.onApply))return;const S=K(),D=re(S);g(!0);try{await s.onApply(D,{close:G,id:u,values:S})}finally{g(!1)}},[G,s,K,u,re]),ze=d.useCallback(async()=>{if(s){if(s.onClear){g(!0);try{await s.onClear()}finally{g(!1)}}T(s.defaultValues||{})}},[s,T]),Je=d.useCallback(async S=>{if(t){L(),ue.mutate(t.formToDto?t.formToDto(S):S);return}const D=re(S);g(!0);try{s!=null&&s.onSubmit&&await s.onSubmit(D,{close:G,id:u,values:S}),((s==null?void 0:s.closeOnSubmit)??!0)&&G()}finally{g(!1)}},[L,G,s,u,ue,t,re]);return{open:y,mode:r,id:u,openDialog:We,handleClose:G,control:v,getValues:K,setValue:k,handleSubmit:N,onSubmit:Je,reset:T,setError:P,title:n.title,isSubmitting:p,onApply:Ge,onClear:ze,isLoading:ne||ue.isPending||p}},Mt=se,Pt=n=>se(n),Ot=n=>{const e=$.useQueryClient(),{mutationFn:t,queryKey:s,onSuccess:r,onError:a,mapOut:o,...c}=n,i=$.useMutation({mutationFn:t});return se({...c,mode:"entity",mapOut:o,onSubmit:async m=>{try{const u=await i.mutateAsync(m);s&&await e.invalidateQueries({queryKey:s}),r&&await r(u)}catch(u){throw a&&a(u),u}}})},qt=n=>{const e=$.useQueryClient(),t=d.useRef(),s=d.useRef(),{mutationFn:r,queryKey:a,onSuccess:o,onError:c,mapOut:i,getFunction:m,dtoToForm:u,title:f,...p}=n,g=d.useRef(u);d.useEffect(()=>{g.current=u},[u]);const h=$.useMutation({mutationFn:r}),b=se({...p,mode:"entity",title:f,onSubmit:async v=>{try{const N=await h.mutateAsync(v);a&&await e.invalidateQueries({queryKey:a}),o&&await o(N)}catch(N){throw c&&c(N),N}},mapOut:v=>i?i(v,t.current):v}),{reset:y}=b,x=a||["put-dialog",f],C=$.useQuery({queryFn:()=>m(b.id),queryKey:[...x,b.id],enabled:b.open&&!!b.id});return d.useEffect(()=>{if(C.data&&s.current!==C.data){if(t.current=C.data,s.current=C.data,g.current&&y){y(g.current(C.data));return}y==null||y(C.data)}},[C.data,y]),{...b,isLoading:b.isLoading||h.isPending||C.isFetching||C.isLoading}},Kt=n=>{const{queryKey:e,onSuccess:t,...s}=n,r=$.useQueryClient(),{showStackNotifications:a}=W(),{t:o}=w.useTranslation(),{open:c,onClick:i,close:m,dialogFn:u,isLoading:f}=ye({onSuccessMessage:o("_pages:common.actions.restore.successMessage"),onError:g=>{const h=g;if(ee(h))a(h.errors.map(([b,y])=>({message:o(`_pages:${b}.errors.${y}`),type:I.error})));else if(te(h)){const b=h.message||o("_accessibility:errors.500"),y=o(`_accessibility:errors.${h.status}`);a([{message:y||b,type:I.error}])}},onSuccess:async g=>{await r.invalidateQueries({queryKey:e}),t&&t(g)},...s}),{action:p}=Pe({onClick:i});return{onClick:i,title:o("_pages:common.actions.restore.dialog.title"),open:c,isLoading:f,handleSubmit:()=>u.mutate(),handleClose:m,action:p}};function Ut(n){const{t:e}=w.useTranslation(),t=$.useQueryClient(),{queryKey:s,mutationFn:r,entity:a,fileProcessor:o,renderCustomPreview:c,onError:i}=n,[m,u]=d.useState(!1),[f,p]=d.useState(null),[g,h]=d.useState(!1),b=$.useMutation({mutationFn:r,onError:x=>{console.error(x),i==null||i(x)},onSuccess:async()=>{await t.invalidateQueries({queryKey:s})}}),{action:y}=qe({onClick:()=>u(!0)});return{handleSubmit:async()=>{if(!(!f||f.length===0))try{await b.mutateAsync({items:f,override:g}),u(!1),p(null),h(!1)}catch(x){console.error(x)}},isLoading:b.isPending,fileProcessor:o,onFileProcessed:x=>p(x),renderCustomPreview:c,onOverrideChange:x=>h(x),open:m,title:e("_pages:common.actions.import.dialog.title",{entity:e(`_pages:${a}.title`)}),handleClose:()=>{u(!1),p(null),h(!1)},action:y}}const Qt=n=>{const{showSuccessNotification:e}=W(),{t}=w.useTranslation(),{entity:s,mutationFn:r,onError:a,onSuccess:o,onSuccessMessage:c=t("_pages:common.actions.export.successMessage")}=n,i=$.useMutation({mutationFn:()=>r(),onError:f=>{console.error(f),a&&a(f)},onSuccess:async f=>{const p=JSON.stringify(f,null,2),g=new Blob([p],{type:"application/json"}),h=URL.createObjectURL(g),b=document.createElement("a");b.href=h,b.download=`${s}.json`,b.click(),URL.revokeObjectURL(h),o&&o(f),e({message:c})}}),m=d.useCallback(()=>{i.mutate()},[i]),{action:u}=Oe({onClick:m,isLoading:i.isPending});return{action:u}},Te=()=>typeof window<"u"?window.scrollY:0;function Ke(n){const[e,t]=d.useState(Te),s=d.useCallback(()=>{t(Te())},[]);return d.useEffect(()=>(window.addEventListener("scroll",s),()=>{window.removeEventListener("scroll",s)}),[s]),e>n}const Bt=n=>{const{t:e}=w.useTranslation(),{icon:t=j.faArrowUp,threshold:s=200,scrollTop:r=0,scrollLeft:a=0,tooltip:o=e("_accessibility:buttons.toTop"),scrollOnClick:c=!0,onClick:i,className:m="",variant:u="submit",color:f="primary",...p}=n,g=Ke(s),h=()=>{i==null||i(),c&&Lt.scrollTo(a,r)};return l.jsx(q,{variant:u,color:f,icon:t,"data-tooltip-id":"tooltip",onClick:h,className:`to-top ${g?"show":"hide"} ${m}`.trim(),"data-tooltip-content":o,...p})};function Ht(n){const{t:e}=w.useTranslation();if("children"in n){const{children:N,className:T}=n;return l.jsx("div",{className:`error-container${T?` ${T}`:""}`,children:N})}const{error:s,message:r,iconProps:a,onRetry:o,retryLabel:c,retryButtonProps:i,messageProps:m,className:u,resetErrorBoundary:f}=n,p=o??f,{className:g,children:h,onClick:b,...y}=i??{},{className:x,...C}=m??{},v=a!==null;return l.jsxs("div",{className:`error-container${u?` ${u}`:""}`,children:[v&&l.jsx(M.FontAwesomeIcon,{...a,icon:(a==null?void 0:a.icon)??et.faSadTear,className:`error-icon${a!=null&&a.className?` ${a.className}`:""}`}),l.jsx("p",{...C,className:`error-message${x?` ${x}`:""}`,children:r??(s==null?void 0:s.message)??e("_accessibility:errors.unknownError")}),p&&l.jsx(w.Button,{type:"button",variant:"submit",color:"primary",...y,className:`error-retry ${g?` ${g}`:""}`,onClick:N=>{b==null||b(N),N.defaultPrevented||p()},children:h??c??e("_accessibility:actions.retry",{defaultValue:"Retry"})})]})}const Vt=n=>{const{showBackButton:e,title:t,actions:s}=n,{t:r}=w.useTranslation(),{navigate:a}=Y();return l.jsxs("div",{className:"page-header",children:[l.jsxs("div",{className:"page-header-left",children:[e&&l.jsx(q,{icon:j.faArrowLeft,onClick:()=>a(-1),className:"page-header-back",name:r("_accessibility:buttons.back"),"data-tooltip-id":"tooltip","data-tooltip-content":r("_accessibility:buttons.back")}),l.jsx("h2",{className:"page-header-title",children:t})]}),l.jsxs("div",{children:[l.jsx(w.Actions,{className:"page-header-actions-desktop",actions:s??[]}),l.jsx(w.ActionsDropdown,{className:"page-header-actions-mobile",actions:s??[]})]})]})},Wt=n=>{const{title:e,children:t,addOptions:s,filterOptions:r,actions:a,queryKey:o,isLoading:c=!1,isAnimated:i=!0,showBackButton:m=!1}=n,{t:u}=w.useTranslation(),f=$.useQueryClient(),{countOfFilters:p}=w.useTableOptions(),g=d.useMemo(()=>{const h=Array.isArray(a)?[...a]:[];if(o){const b={id:B.Refresh,onClick:()=>f.invalidateQueries({queryKey:o}),icon:l.jsx(M.FontAwesomeIcon,{icon:j.faRotateLeft}),tooltip:u("_pages:common.actions.refresh.text")};h.unshift(b)}if(s){const b={...s,id:B.Add,icon:l.jsx(M.FontAwesomeIcon,{icon:j.faAdd})};h.unshift(b)}if(r){const b={...r,id:"filter",icon:l.jsx(M.FontAwesomeIcon,{icon:j.faFilter}),children:l.jsx(w.Badge,{className:`${p>0?"show":"hide"} `,count:p})};h.push(b)}return h},[a,s,p,r,f,o,u]);return l.jsxs("main",{className:"page-main",children:[l.jsx(Vt,{showBackButton:m,actions:g,title:e}),l.jsx("div",{className:`page-main-content ${i?"appear":""}`,children:c?l.jsx(w.Loading,{className:"page-loading"}):t}),s&&l.jsx(q,{icon:s.icon??j.faAdd,color:s.color??"primary",variant:s.variant??"submit",onClick:()=>{var h;return(h=s.onClick)==null?void 0:h.call(s)},className:`button page-fab ${s.className??""}`})]})},Gt=n=>{const{t:e}=w.useTranslation(),{className:t="",itemClassName:s="",loading:r=!1,emptyComponent:a=null,emptyMessage:o=e("_accessibility:messages.empty"),renderComponent:c,data:i=[],hasMore:m=!1,loadingMore:u=!1,onLoadMore:f,loadMoreComponent:p=null,observerRootMargin:g="0px 0px 200px 0px",observerThreshold:h=0}=n,b=d.useRef(!1),y=d.useRef(null),x=d.useCallback(async()=>{if(!(!m||!f)&&!(u||b.current)){b.current=!0;try{await f()}finally{b.current=!1}}},[m,u,f]);return d.useEffect(()=>{if(!m||!f||!y.current||typeof IntersectionObserver>"u")return;const C=new IntersectionObserver(v=>{v.some(N=>N.isIntersecting)&&x()},{rootMargin:g,threshold:h});return C.observe(y.current),()=>C.disconnect()},[m,f,g,h,x]),r?l.jsx(w.Loading,{}):l.jsx(l.Fragment,{children:i!=null&&i.length?l.jsxs("ul",{className:`pretty-grid-main ${t}`,children:[i==null?void 0:i.map(C=>l.jsx("li",{className:`pretty-grid-item ${s}`,children:c(C)},C.id)),m&&f&&l.jsx("li",{className:"pretty-grid-load-more",ref:y,children:p})]}):l.jsx(l.Fragment,{children:a||l.jsx(Ve,{message:o})})})},we=d.createContext({title:"",setTitle:()=>{},rightContent:null,setRightContent:()=>{}}),zt=n=>{const{children:e}=n,[t,s]=d.useState(""),[r,a]=d.useState(null),o=d.useCallback(m=>{s(m)},[]),c=d.useCallback(m=>{a(m)},[]),i=d.useMemo(()=>({title:t,setTitle:o,rightContent:r,setRightContent:c}),[t,o,r,c]);return l.jsx(we.Provider,{value:i,children:e})},Ue=()=>d.useContext(we);function Jt(n){const{t:e}=w.useTranslation(),{openDrawer:t,showSearch:s=!0,menuButtonProps:r}=n,{searchComponent:a,location:o}=Y(),{title:c,rightContent:i}=Ue(),[m,u]=d.useState(!1),f=d.useCallback(h=>{($e()?h.metaKey:h.ctrlKey)&&h.shiftKey&&h.key.toLowerCase()==="f"&&(u(!0),h.preventDefault())},[]);d.useEffect(()=>(window.addEventListener("keydown",f),()=>{window.removeEventListener("keydown",f)}),[f]);const p=a,g=s&&!!p;return l.jsxs(l.Fragment,{children:[o.pathname!=="/"&&!!p&&l.jsx(p,{open:m,onClose:()=>u(!1)}),l.jsxs("header",{id:"header",className:"header",children:[l.jsxs("div",{className:"navbar-left",children:[l.jsx(q,{...r,type:(r==null?void 0:r.type)??"button",icon:(r==null?void 0:r.icon)??j.faBars,onClick:h=>{var b;(b=r==null?void 0:r.onClick)==null||b.call(r,h),t()},name:(r==null?void 0:r.name)??e("_accessibility:buttons.openMenu"),"aria-label":(r==null?void 0:r["aria-label"])??e("_accessibility:ariaLabels.openMenu"),className:`navbar-menu animated ${(r==null?void 0:r.className)??""}`}),l.jsx("h1",{className:"poppins navbar-title",children:c||e("_pages:home.appName")})]}),l.jsxs("div",{className:"navbar-right",children:[i,g&&l.jsx(q,{icon:j.faSearch,className:"navbar-search-btn",onClick:()=>u(!0)})]})]})]})}const ae=300,Yt=n=>n??I.error,Xt=n=>{switch(n){case I.error:return j.faWarning;default:return j.faCircleCheck}},me=n=>{switch(n){case I.success:return"!text-success";case I.error:return"!text-error";case I.warning:return"!text-warning";default:return"!text-info"}},Zt=n=>{switch(n){case I.success:return"bg-bg-success";case I.error:return"bg-bg-error";case I.warning:return"bg-bg-warning";default:return"bg-bg-info"}};function es(){const{t:n}=w.useTranslation(),{notification:e,removeNotification:t}=W(),[s,r]=d.useState([]),a=d.useRef(s);d.useLayoutEffect(()=>{a.current=s});const o=d.useRef(null),c=d.useCallback(i=>{r(m=>i!==void 0?m.map(u=>u.id===i?{...u,closing:!0}:u):m.map(u=>({...u,closing:!0}))),i!==void 0?setTimeout(()=>{t(i),r(m=>m.filter(u=>u.id!==i))},ae):(o.current&&clearTimeout(o.current),o.current=setTimeout(()=>{t(),r([]),o.current=null},ae))},[t]);return d.useEffect(()=>{let i=null;const m=()=>{i&&clearTimeout(i),o.current&&(clearTimeout(o.current),o.current=null)};if(e.length===0)return a.current.length===0?void 0:(o.current&&clearTimeout(o.current),i=setTimeout(()=>{r(g=>g.map(h=>({...h,closing:!0}))),i=null},0),o.current=setTimeout(()=>{r([]),o.current=null},ae),m);const u=new Set(a.current.map(g=>g.id));if(!e.some(g=>g.id!==void 0&&!u.has(g.id)))return;if(a.current.length===0){const g=[...e];return i=setTimeout(()=>{r(g.map(h=>({...h,closing:!1}))),i=null},0),()=>{i&&clearTimeout(i)}}o.current&&clearTimeout(o.current),i=setTimeout(()=>{r(g=>g.every(h=>h.closing)?g:g.map(h=>({...h,closing:!0}))),i=null},0);const p=[...e];return o.current=setTimeout(()=>{r(p.map(g=>({...g,closing:!1}))),o.current=null},ae),m},[e]),d.useEffect(()=>{if(!s.length)return;let i;const m=window.setTimeout(()=>{i=()=>c(),window.addEventListener("click",i)},0),u=f=>{f.key==="Escape"&&c()};return window.addEventListener("keydown",u),()=>{window.clearTimeout(m),i&&window.removeEventListener("click",i),window.removeEventListener("keydown",u)}},[s.length,c]),ve.createPortal(l.jsx("div",{className:`notification-portal ${s.length?"active":""}`,children:s.map(({id:i,type:m,message:u,closing:f})=>{const p=Yt(m);return l.jsxs("div",{className:`notification ${f?"closing":""} ${Zt(p)}`,onClick:g=>g.stopPropagation(),children:[l.jsxs("div",{className:"notification-body",children:[l.jsx(M.FontAwesomeIcon,{icon:Xt(p),className:`notification-icon ${me(p)}`}),l.jsx("p",{className:`notification-text ${me(p)}`,children:u})]}),l.jsx(q,{type:"button",icon:j.faClose,color:"error",className:"notification-close group",onClick:g=>{g.stopPropagation(),i!==void 0&&c(i)},iconClassName:`${me(p)} notification-close-icon`,name:n("_accessibility:buttons.closeNotification"),"aria-label":n("_accessibility:ariaLabels.closeNotification")})]},i)})}),document.body)}function ts(n){const{className:e,...t}=n;return l.jsx("div",{className:"splash-screen",children:l.jsx(w.Loading,{className:`blur-appear ${e?` ${e}`:""}`,...t})})}const Qe=n=>{const{id:e,active:t,onClick:s,children:r,to:a,useLinks:o=!0,tabButtonProps:c}=n,{linkComponent:i}=Y(),m=i;if(!o){const{className:f="",variant:p=t?"submit":"outlined",color:g=t?"primary":"default",...h}=c??{};return l.jsx(w.Button,{type:"button",variant:p,color:g,className:`tab ${f}`,onClick:s,...h,children:r})}const u=`button submit tab ${t?"primary":"outlined"} ${(c==null?void 0:c.className)??""}`.trim();return l.jsx(m,{to:a??`#${e}`,onClick:()=>s(),className:u,children:r})},Be=n=>{var g;const{tabs:e=[],defaultTab:t,currentTab:s,onTabChange:r,className:a="",tabsContainerClassName:o="",useLinks:c=!0,tabButtonProps:i}=n,[m,u]=d.useState(t??((g=e[0])==null?void 0:g.id)),f=s??m,p=d.useMemo(()=>e.find(h=>h.id===f),[e,f]);return l.jsxs("div",{className:`tabs-layout-main ${a}`,children:[l.jsx("ul",{className:`horizontal tabs tabs-container ${o}`,children:e.map(({id:h,to:b,label:y})=>l.jsx("li",{children:l.jsx(Qe,{onClick:()=>{s===void 0&&u(h),r==null||r(h)},id:h,to:b,siblings:e.length>1,active:f===h,useLinks:c,tabButtonProps:i,children:y})},h))}),p==null?void 0:p.content]})},He=n=>{const{title:e,body:t,content:s,onClickNext:r,onSkip:a,onStartAsGuest:o,onSignIn:c,image:i="",alt:m="",final:u=!1}=n,{t:f}=w.useTranslation();return l.jsxs("div",{className:"big-appear step-container",children:[i&&l.jsx("img",{src:i,alt:m}),e!=null&&l.jsx("h2",{className:"step-title",children:e}),t!=null&&l.jsx("div",{className:"step-body",children:t}),s!=null&&l.jsx("div",{className:"step-content",children:s}),l.jsx("div",{className:"step-actions",children:u?l.jsxs(l.Fragment,{children:[l.jsx(w.Button,{color:"primary",className:"step-button",variant:"outlined",onClick:o,"aria-label":f("_accessibility:ariaLabels.start"),children:f("_accessibility:buttons.startAsGuest")}),l.jsx(w.Button,{color:"primary",variant:"submit",className:"step-button","aria-label":f("_accessibility:ariaLabels.start"),onClick:c,children:f("_accessibility:buttons.signIn")})]}):l.jsxs(l.Fragment,{children:[l.jsx(w.Button,{color:"primary",className:"step-button",variant:"outlined",onClick:a,"aria-label":f("_accessibility:ariaLabels.skip"),children:f("_accessibility:buttons.skip")}),l.jsx(w.Button,{color:"primary",className:"step-button",variant:"outlined",onClick:()=>r(),"aria-label":f("_accessibility:ariaLabels.next"),children:f("_accessibility:buttons.next")})]})})]})},ss=n=>{const{steps:e,signInPath:t="/auth/sign-in",guestPath:s="/",onSkip:r,onSignIn:a,onStartAsGuest:o}=n,{setGuestMode:c}=pe(),{navigate:i}=Y(),[m,u]=d.useState(1),f=d.useCallback(()=>{if(r){r();return}i(t)},[i,r,t]),p=d.useCallback(()=>{if(a){a();return}i(t)},[i,a,t]),g=d.useCallback(()=>{if(o){o();return}c(!0),i(s)},[s,i,o,c]),h=d.useMemo(()=>e.map((b,y)=>({id:y+1,label:"",content:l.jsx(He,{...b,final:y===e.length-1,onClickNext:()=>u(x=>x+1),onSkip:f,onStartAsGuest:g,onSignIn:p})})),[p,f,g,e]);return l.jsx("div",{className:"onboarding-main",children:l.jsx(Be,{currentTab:m,onTabChange:b=>u(Number(b)),tabs:h,useLinks:!1})})},Ve=n=>{const{message:e,messageProps:t={className:"empty-message"},action:s,iconProps:r}=n;return l.jsxs("div",{className:"empty-container",children:[r&&l.jsx(M.FontAwesomeIcon,{...r}),l.jsx("p",{...t,children:e}),s&&l.jsx(w.Action,{showTooltips:!1,showText:!0,...s})]})};Object.defineProperty(exports,"Action",{enumerable:!0,get:()=>w.Action});Object.defineProperty(exports,"Actions",{enumerable:!0,get:()=>w.Actions});Object.defineProperty(exports,"ActionsDropdown",{enumerable:!0,get:()=>w.ActionsDropdown});Object.defineProperty(exports,"Button",{enumerable:!0,get:()=>w.Button});exports.APIClient=Z;exports.AppIconButton=q;exports.AuthClient=Ae;exports.AuthProvider=vt;exports.BaseClient=pt;exports.ConfigProvider=Et;exports.ConfirmationDialog=at;exports.Dialog=ie;exports.DialogActions=ce;exports.Drawer=At;exports.DrawerMenuContext=ge;exports.DrawerMenuProvider=jt;exports.Empty=Ve;exports.Error=Ht;exports.FormContainer=st;exports.FormDialog=rt;exports.GlobalActions=B;exports.IManager=ht;exports.IconButton=q;exports.ImportDialog=ut;exports.IndexedDBClient=gt;exports.ManagerProvider=Tt;exports.Methods=F;exports.Navbar=Jt;exports.NavbarContext=we;exports.NavbarProvider=zt;exports.Notification=es;exports.NotificationEnumType=I;exports.NotificationProvider=kt;exports.Onboarding=ss;exports.Page=Wt;exports.ParagraphInput=tt;exports.PasswordInput=nt;exports.PrettyGrid=Gt;exports.SplashScreen=ts;exports.Step=He;exports.Tab=Qe;exports.TabsLayout=Be;exports.ToTop=Bt;exports.buildQueryUrl=je;exports.createQueryClient=he;exports.enumToKeyValueArray=yt;exports.formatForDatetimeLocal=xt;exports.fromLocal=V;exports.getFormattedDateTime=bt;exports.getShortFormattedDateTime=wt;exports.isHttpError=te;exports.isMac=$e;exports.isValidationError=ee;exports.makeRequest=oe;exports.mapValidationErrors=Ct;exports.parseQueries=fe;exports.queryClient=St;exports.removeFromLocal=_;exports.toLocal=Q;exports.useAuth=pe;exports.useConfig=Y;exports.useConfirmationForm=ye;exports.useDeleteAction=Me;exports.useDeleteDialog=_t;exports.useDialog=be;exports.useDrawerMenu=De;exports.useEditAction=Ft;exports.useEntityFormDialog=Pt;exports.useExportAction=Oe;exports.useExportActionMutate=Qt;exports.useFormDialog=se;exports.useFormDialogLegacy=Mt;exports.useImportAction=qe;exports.useImportDialog=Ut;exports.useManager=Ie;exports.useNavbar=Ue;exports.useNotification=W;exports.usePostDialog=Ot;exports.usePostForm=It;exports.usePutDialog=qt;exports.useRestoreAction=Pe;exports.useRestoreDialog=Kt;exports.useScrollTrigger=Ke;exports.useTimeAge=Rt;Object.keys(w).forEach(n=>{n!=="default"&&!Object.prototype.hasOwnProperty.call(exports,n)&&Object.defineProperty(exports,n,{enumerable:!0,get:()=>w[n]})});
|
|
1
|
+
var at=Object.defineProperty;var it=(n,e,s)=>e in n?at(n,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):n[e]=s;var N=(n,e,s)=>it(n,typeof e!="symbol"?e+"":e,s);var Ss=require("./main.css");Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const C=require("@sito/dashboard"),l=require("react/jsx-runtime"),U=require("@fortawesome/react-fontawesome"),d=require("react"),$=require("@fortawesome/free-solid-svg-icons"),Le=require("react-dom"),D=require("@tanstack/react-query"),ct=require("@fortawesome/free-regular-svg-icons"),Re=require("react-hook-form"),je=n=>n==null?!1:`${n}`.length>0,lt=d.forwardRef(function(n,e){const{value:s,defaultValue:t,onChange:r,state:o=C.State.default,name:a="",id:c="",label:i="",disabled:m=!1,required:u=!1,containerClassName:f="",inputClassName:h="",labelClassName:g="",helperText:p="",helperTextClassName:y="",...b}=n,w=s!==void 0,[S,x]=d.useState(()=>je(t)),k=w?je(s):S,T=_=>{w||x(_.currentTarget.value.length>0),r==null||r(_)};return l.jsxs("div",{className:`form-paragraph-container group ${f}`,children:[l.jsx("textarea",{ref:e,name:a,id:c,className:`text-input text-area form-paragraph-textarea peer ${C.inputStateClassName(o)} ${k?"has-value":""} ${b.placeholder?"has-placeholder":""} ${h}`,required:u,defaultValue:t,...w?{value:s}:{},onChange:T,disabled:m,...b}),l.jsxs("label",{htmlFor:c,className:`text-input-label ${C.labelStateClassName(o)} ${g}`,children:[i,u?" *":""]}),!!p&&l.jsx("p",{className:`text-input-helper-text ${C.helperTextStateClassName(o)} ${y}`,children:p})]})}),ut=n=>{const{t:e}=C.useTranslation(),{children:s,handleSubmit:t,onSubmit:r,isLoading:o=!1,buttonEnd:a=!0,reset:c}=n;return l.jsxs("form",{className:"form-container",onSubmit:t(r),children:[s,l.jsxs("div",{className:`form-actions ${a?"end":""}`,children:[l.jsxs(C.Button,{type:"submit",color:"primary",variant:"submit",disabled:o,name:e("_accessibility:buttons.submit"),"aria-label":e("_accessibility:ariaLabels.submit"),children:[o?l.jsx(C.Loading,{color:"stroke-base",loaderClass:"!w-6 mt-1",strokeWidth:"6"}):null,e("_accessibility:buttons.submit")]}),l.jsx(C.Button,{type:"button",variant:"outlined",onClick:()=>c==null?void 0:c(),name:e("_accessibility:buttons.cancel"),"aria-label":e("_accessibility:ariaLabels.cancel"),children:e("_accessibility:buttons.cancel")})]})]})},dt=d.forwardRef(function(n,e){const{t:s}=C.useTranslation(),[t,r]=d.useState(!1);return l.jsx(C.TextInput,{...n,type:t?"text":"password",ref:e,children:l.jsx(Q,{type:"button",tabIndex:-1,"aria-label":s(t?"_accessibility:ariaLabels.hidePassword":"_accessibility:ariaLabels.showPassword"),className:"password-icon",onClick:()=>r(!t),icon:t?$.faEyeSlash:$.faEye})})}),le=n=>{const{t:e}=C.useTranslation(),{title:s,children:t,handleClose:r,open:o=!1,containerClassName:a="",className:c="",animationClass:i="appear"}=n,m=d.useCallback(f=>{f.key==="Escape"&&o&&r()},[o,r]);d.useEffect(()=>(window.addEventListener("keydown",m),()=>{window.removeEventListener("keydown",m)}),[m]);const u=d.useCallback(f=>{f.target===f.currentTarget&&r()},[r]);return d.useEffect(()=>{const f=h=>{h?document.body.style.overflow="hidden":document.body.style.overflow="auto"};return f(o),()=>{f(!1)}},[o]),Le.createPortal(l.jsx("div",{"aria-label":e("_accessibility:ariaLabels.closeDialog"),"aria-hidden":!o,onClick:u,className:`dialog-backdrop animated ${o?`opened ${i}`:"closed"} ${a}`,children:l.jsxs("div",{className:`dialog elevated animated ${o?`opened ${i}`:"closed"} ${c}`,children:[l.jsxs("div",{className:"dialog-header",children:[l.jsx("h3",{className:"dialog-title",children:s}),l.jsx(Q,{icon:$.faClose,disabled:!o,"aria-disabled":!o,onClick:r,variant:"text",color:"error",className:"icon-button dialog-close-btn",name:e("_accessibility:buttons.closeDialog"),"aria-label":e("_accessibility:ariaLabels.closeDialog")})]}),t]})}),document.body)},ue=n=>{const{primaryText:e,cancelText:s,onPrimaryClick:t,onCancel:r,isLoading:o=!1,disabled:a=!1,primaryType:c="submit",containerClassName:i="",primaryClassName:m="",alignEnd:u=!1,primaryName:f,primaryAriaLabel:h,cancelName:g,cancelAriaLabel:p,extraActions:y=[]}=n;return l.jsxs("div",{className:`dialog-actions ${u?"end":""} ${i}`,children:[l.jsxs(C.Button,{type:c,color:"primary",variant:"submit",className:m,disabled:a,onClick:t,name:f,"aria-label":h,children:[o?l.jsx(C.Loading,{color:"stroke-base",loaderClass:"!w-6 mt-1",strokeWidth:"6"}):null,e]}),y==null?void 0:y.map(b=>l.jsx(C.Button,{...b},b.id)),l.jsx(C.Button,{type:"button",variant:"outlined",disabled:a,onClick:r,name:g,"aria-label":p,children:s})]})},mt=n=>{const{t:e}=C.useTranslation(),{children:s,handleSubmit:t,onSubmit:r,handleClose:o,isLoading:a=!1,buttonEnd:c=!0,extraActions:i=[],...m}=n;return l.jsx(le,{...m,handleClose:o,children:l.jsxs("form",{onSubmit:t(r),children:[l.jsx("div",{className:"form-container",children:s}),l.jsx(ue,{primaryType:"submit",primaryText:e("_accessibility:buttons.submit"),cancelText:e("_accessibility:buttons.cancel"),onCancel:o,isLoading:a,disabled:a,primaryClassName:"dialog-form-primary",alignEnd:c,primaryName:e("_accessibility:buttons.submit"),primaryAriaLabel:e("_accessibility:ariaLabels.submit"),cancelName:e("_accessibility:buttons.cancel"),cancelAriaLabel:e("_accessibility:ariaLabels.cancel"),extraActions:i})]})})},ft=n=>{const{t:e}=C.useTranslation(),{children:s,handleSubmit:t,handleClose:r,isLoading:o=!1,extraActions:a=[],...c}=n;return l.jsxs(le,{...c,handleClose:r,children:[s,l.jsx(ue,{primaryText:e("_accessibility:buttons.ok"),cancelText:e("_accessibility:buttons.cancel"),onPrimaryClick:t,onCancel:r,isLoading:o,disabled:o,primaryType:"button",containerClassName:"mt-5",primaryName:e("_accessibility:buttons.ok"),primaryAriaLabel:e("_accessibility:ariaLabels.ok"),cancelName:e("_accessibility:buttons.cancel"),cancelAriaLabel:e("_accessibility:ariaLabels.cancel"),extraActions:a})]})};function ht(n){const{message:e,className:s=""}=n,{t}=C.useTranslation();return l.jsx("p",{className:`import-error-message ${s}`,children:e??t("_messages:errors.parseFile",{defaultValue:"Failed to process file"})})}function pt(n){const{message:e,className:s=""}=n,{t}=C.useTranslation();return l.jsxs("div",{className:`import-loading ${s}`,children:[l.jsx(C.Loading,{loaderClass:"w-5 h-5",className:"!w-auto"}),l.jsx("span",{children:e??t("_messages:loading.processingFile",{defaultValue:"Processing file..."})})]})}function gt(n){const{items:e,max:s=5,className:t=""}=n,{t:r}=C.useTranslation();if(!e||e.length===0)return null;const o=e.slice(0,s);return l.jsxs("div",{className:`import-preview ${t}`,children:[l.jsx("p",{className:"import-preview-count",children:r("_pages:common.actions.import.previewCount",{count:e.length,defaultValue:`Preview: ${e.length} items`})}),l.jsx("pre",{className:"import-preview-content",children:JSON.stringify(o,null,2)})]})}const Ie=()=>({file:null,previewItems:null,parseError:null,processing:!1,overrideExisting:!1,inputKey:0});function bt(n,e){switch(e.type){case"SET_FILE":return{...n,file:e.file,previewItems:null,parseError:null,processing:!1};case"START_PROCESSING":return{...n,processing:!0};case"SET_PREVIEW":return{...n,previewItems:e.items,parseError:null,processing:!1};case"SET_ERROR":return{...n,previewItems:null,parseError:e.message,processing:!1};case"SET_OVERRIDE":return{...n,overrideExisting:e.value};case"RESET":return{...Ie(),inputKey:n.inputKey+1}}}const yt=n=>{const{t:e}=C.useTranslation(),{children:s,handleSubmit:t,handleClose:r,isLoading:o=!1,fileProcessor:a,onFileProcessed:c,renderCustomPreview:i,onOverrideChange:m,open:u,extraActions:f=[],...h}=n,[g,p]=d.useReducer(bt,Ie()),{file:y,previewItems:b,parseError:w,processing:S,overrideExisting:x,inputKey:k}=g,T=d.useRef(c),_=d.useRef(a);d.useEffect(()=>{T.current=c},[c]),d.useEffect(()=>{_.current=a},[a]),d.useEffect(()=>{u||p({type:"RESET"})},[u]);const O=d.useCallback(async(E,A)=>{var L;if(_.current){p({type:"START_PROCESSING"});try{const R=await _.current(E,{override:A});p({type:"SET_PREVIEW",items:R??[]}),(L=T.current)==null||L.call(T,R??[])}catch(R){console.error(R);const K=R instanceof Error?R.message:"Failed to parse file";p({type:"SET_ERROR",message:K})}}},[]);return l.jsxs(le,{...h,open:u,handleClose:r,children:[l.jsx(C.FileInput,{onClear:()=>{var E;p({type:"SET_FILE",file:null}),(E=T.current)==null||E.call(T,[])},onChange:E=>{var L,R;const A=(L=E.target.files)==null?void 0:L[0];if(!A){p({type:"SET_FILE",file:null}),(R=T.current)==null||R.call(T,[]);return}p({type:"SET_FILE",file:A}),O(A,x)},label:e("_accessibility:labels.file")},k),l.jsxs("label",{className:"import-override-label",children:[l.jsx("input",{type:"checkbox",checked:x,onChange:E=>{const A=E.target.checked;p({type:"SET_OVERRIDE",value:A}),m==null||m(A),y&&O(y,A)}}),l.jsx("span",{children:e("_pages:common.actions.import.override",{defaultValue:"Override existing items"})})]}),l.jsx(ht,{message:w}),S&&l.jsx(pt,{}),i?i(b):!!b&&b.length>0&&l.jsx(gt,{items:b}),s,l.jsx(ue,{primaryText:e("_accessibility:buttons.ok"),cancelText:e("_accessibility:buttons.cancel"),onPrimaryClick:()=>{(!a||!!b&&b.length>0)&&t()},onCancel:r,isLoading:o,primaryType:"button",containerClassName:"import-dialog-actions",primaryName:e("_accessibility:buttons.ok"),primaryAriaLabel:e("_accessibility:ariaLabels.ok"),cancelName:e("_accessibility:buttons.cancel"),cancelAriaLabel:e("_accessibility:ariaLabels.cancel"),extraActions:f})]})};var I=(n=>(n[n.success=0]="success",n[n.error=1]="error",n[n.warning=2]="warning",n[n.info=3]="info",n))(I||{}),F=(n=>(n.GET="GET",n.POST="POST",n.PUT="PUT",n.PATCH="PATCH",n.DELETE="DELETE",n))(F||{});const wt=n=>Array.isArray(n)||n instanceof Headers?!1:typeof n=="object"&&n!==null&&("headers"in n||"credentials"in n),Ct=n=>n?wt(n)?n:{headers:n}:{},xt=n=>n?n instanceof Headers?Object.fromEntries(n.entries()):Array.isArray(n)?Object.fromEntries(n):n:{};async function ce(n,e="GET",s,t){const r=Ct(t),o={...s!==void 0?{"Content-Type":"application/json"}:{},...xt(r.headers)};try{const a=await fetch(n,{method:e,headers:o,...r.credentials?{credentials:r.credentials}:{},...s!==void 0?{body:JSON.stringify(s)}:{}}),c=await a.text();let i=null;try{i=c?JSON.parse(c):null}catch{i=null}if(!a.ok){const m=typeof i=="object"&&i!==null?i.message??i.error??c:c||a.statusText;return{data:null,status:a.status,error:{status:a.status,message:m||"Unknown error occurred"}}}return{data:a.status!==204&&i!==null?i:null,status:a.status,error:null}}catch(a){return{data:null,status:500,error:{status:500,message:a instanceof Error?a.message:"Unknown error occurred"}}}}function Fe(n,e){const s=t=>t instanceof Date?t.toISOString():String(t);if(e){const t=Object.entries(e).filter(([,r])=>r!=null).map(([r,o])=>`${encodeURIComponent(r)}=${encodeURIComponent(s(o))}`).join("&");return t?`${n}?${t}`:n}return n}const pe=n=>typeof n=="object"&&n!==null,G=n=>n instanceof Date?encodeURIComponent(n.toISOString()):encodeURIComponent(String(n)),St=n=>{if(typeof n!="string")return;const e=n.trim().toUpperCase();if(e==="ACTIVE"||e==="DELETED"||e==="ALL")return e},Ce=(n,e,s)=>{const t=[];if(e){const{sortingBy:r,sortingOrder:o,currentPage:a,pageSize:c}=e;r!==void 0&&t.push(`sort=${String(r)}`),o!==void 0&&t.push(`order=${o}`),a!==void 0&&t.push(`page=${a}`),c!==void 0&&t.push(`pageSize=${c}`)}if(s){const r=St(s.softDeleteScope);r&&t.push(`softDeleteScope=${encodeURIComponent(r)}`);const o=Object.entries(s).filter(([a,c])=>a!=="softDeleteScope"&&c!==null&&c!==void 0&&c!=="").flatMap(([a,c])=>{if(Array.isArray(c))return c.map(i=>i instanceof Date?`${a}==${G(i)}`:pe(i)?`${a}==${G(i.id??"")}`:`${a}==${G(i)}`);if(pe(c)&&"start"in c&&"end"in c){const i=[];return c.start!=null&&c.start!==""&&i.push(`${a}>=${G(c.start)}`),c.end!=null&&c.end!==""&&i.push(`${a}<=${G(c.end)}`),i}return c instanceof Date?`${a}==${G(c)}`:pe(c)?`${a}==${G(c.id??"")}`:`${a}==${G(c)}`});o.length>0&&t.push(`filters=${o.join(",")}`)}return t.length?`${n}?${t.join("&")}`:n},Y=class Y{constructor(e,s="user",t=!0,r,o={}){N(this,"baseUrl");N(this,"userKey");N(this,"rememberKey");N(this,"refreshTokenKey");N(this,"accessTokenExpiresAtKey");N(this,"refreshEndpoint");N(this,"refreshExpirySkewMs");N(this,"secured");N(this,"tokenAcquirer");this.baseUrl=e,this.secured=t,this.userKey=s,this.rememberKey=o.rememberKey??"remember",this.refreshTokenKey=o.refreshTokenKey??"refreshToken",this.accessTokenExpiresAtKey=o.accessTokenExpiresAtKey??"accessTokenExpiresAt",this.refreshEndpoint=o.refreshEndpoint??"auth/refresh",this.refreshExpirySkewMs=o.refreshExpirySkewMs??5e3,this.tokenAcquirer=r??this.defaultTokenAcquirer}defaultTokenAcquirer(e){if(e)return{credentials:"include"};const s=q(this.userKey);if(s&&s.length)return{Authorization:`Bearer ${s}`}}getRefreshLockKey(){return`${this.baseUrl}|${this.userKey}|${this.refreshTokenKey}|${this.accessTokenExpiresAtKey}`}buildUrl(e){const s=this.baseUrl.endsWith("/")?this.baseUrl.slice(0,-1):this.baseUrl,t=e.startsWith("/")?e:`/${e}`;return`${s}${t}`}getRefreshToken(){const e=q(this.refreshTokenKey);if(typeof e=="string"&&e.length)return e}getAccessTokenExpiresAt(){const e=q(this.accessTokenExpiresAtKey);if(typeof e=="string"&&e.length)return e}canRefresh(){return!!this.getRefreshToken()}shouldRefreshBeforeRequest(){const e=this.getRefreshToken(),s=this.getAccessTokenExpiresAt();if(!e||!s)return!1;const t=Date.parse(s);return Number.isNaN(t)?!1:Date.now()>=t-this.refreshExpirySkewMs}clearStoredSession(){j(this.userKey),j(this.rememberKey),j(this.refreshTokenKey),j(this.accessTokenExpiresAtKey)}storeSession(e,s){M(this.userKey,e.token);const t=e.refreshToken===void 0?s:e.refreshToken;typeof t=="string"&&t.length?M(this.refreshTokenKey,t):j(this.refreshTokenKey),typeof e.accessTokenExpiresAt=="string"&&e.accessTokenExpiresAt.length?M(this.accessTokenExpiresAtKey,e.accessTokenExpiresAt):j(this.accessTokenExpiresAtKey)}async refreshAccessTokenWithMutex(){const e=this.getRefreshToken();if(!e)throw{status:401,message:"Missing refresh token"};const s=this.getRefreshLockKey(),t=Y.refreshInFlight.get(s);if(t){await t;return}const r=(async()=>{const{data:o,status:a,error:c}=await ce(this.buildUrl(this.refreshEndpoint),F.POST,{refreshToken:e});if(c||!(o!=null&&o.token))throw this.clearStoredSession(),c??{status:a,message:"Unable to refresh session"};this.storeSession(o,e)})();Y.refreshInFlight.set(s,r);try{await r}finally{Y.refreshInFlight.delete(s)}}isRequestOptions(e){return Array.isArray(e)||e instanceof Headers?!1:typeof e=="object"&&e!==null&&("headers"in e||"credentials"in e)}toRequestOptions(e){return e?this.isRequestOptions(e)?e:{headers:e}:{}}toHeaderRecord(e){return e?e instanceof Headers?Object.fromEntries(e.entries()):Array.isArray(e)?Object.fromEntries(e):e:{}}mergeRequestConfig(e){const s=this.secured?this.tokenAcquirer():void 0,t=this.toRequestOptions(s),r=this.toRequestOptions(e),o={...this.toHeaderRecord(t.headers),...this.toHeaderRecord(r.headers)},a=r.credentials??t.credentials,c=Object.keys(o).length>0;if(a)return c?{headers:o,credentials:a}:{credentials:a};if(c)return o}async makeRequestWithRefresh(e,s,t,r){this.secured&&this.shouldRefreshBeforeRequest()&&await this.refreshAccessTokenWithMutex();let o=await ce(this.buildUrl(e),s,t,this.mergeRequestConfig(r));return this.secured&&o.status===401&&this.canRefresh()&&(await this.refreshAccessTokenWithMutex(),o=await ce(this.buildUrl(e),s,t,this.mergeRequestConfig(r))),o}async doQuery(e,s=F.GET,t,r){const{data:o,status:a,error:c}=await this.makeRequestWithRefresh(e,s,t,r);if(c||a<200||a>=300)throw c??{status:a,message:String(a)};return o}async get(e,s,t){const r=Ce(e,s,t),{data:o,error:a,status:c}=await this.makeRequestWithRefresh(r,F.GET);if(a||c<200||c>=300||!o)throw a??{status:c,message:String(c)};return o}async patch(e,s){const{error:t,data:r,status:o}=await this.makeRequestWithRefresh(e,F.PATCH,s);if(t||r===null||r===void 0)throw t??{status:o,message:"Unknown error"};return r}async delete(e,s){const{error:t,data:r,status:o}=await this.makeRequestWithRefresh(e,F.DELETE,s);if(t||r===null||r===void 0)throw t??{status:o,message:"Unknown error"};return r}async post(e,s){const{error:t,data:r,status:o}=await this.makeRequestWithRefresh(e,F.POST,s);if(t||r===null||r===void 0)throw t??{status:o,message:"Unknown error"};return r}};N(Y,"refreshInFlight",new Map);let te=Y;class Me{constructor(e,s="user",t={}){N(this,"api");this.api=new te(e,s,!1,void 0,t)}async login(e){const s="auth/sign-in",t=e;return await this.api.doQuery(s,F.POST,t)}async refresh(e){return await this.api.doQuery("auth/refresh",F.POST,e)}async logout(e){const s="auth/sign-out",t=e!=null&&e.accessToken?{Authorization:`Bearer ${e.accessToken}`}:void 0,r=e!=null&&e.refreshToken?{refreshToken:e.refreshToken}:void 0;return await this.api.doQuery(s,F.POST,r,t)}async register(e){return await this.api.doQuery("auth/sign-up",F.POST,e)}async getSession(){return await this.api.doQuery("auth/session",F.GET,void 0,this.api.defaultTokenAcquirer())}}class Tt{constructor(e,s,t={}){N(this,"auth");this.auth=new Me(e,s,t)}get Auth(){return this.auth}}class kt{constructor(e,s,t="user",r=!0,o={}){N(this,"table");N(this,"secured");N(this,"api");this.table=e,this.secured=r,this.api=new te(s,t,r,void 0,o)}async insert(e){return await this.api.post(`${this.table}`,e)}async insertMany(e){return await this.api.doQuery(`${this.table}/batch`,F.POST,e)}async update(e){return await this.api.patch(`${this.table}/${e.id}`,e)}async get(e,s){return await this.api.get(`${this.table}`,e,s)}async export(e){const s=Ce(`${this.table}/export`,void 0,e);return await this.api.doQuery(s,F.GET,void 0)}async import(e){return await this.api.doQuery(`${this.table}/import`,F.POST,e)}async commonGet(e){return await this.api.doQuery(Fe(`${this.table}/common`,e),F.GET)}async getById(e){return await this.api.doQuery(`${this.table}/${e}`)}async softDelete(e){return await this.api.delete(`${this.table}`,e)}async restore(e){return await this.api.patch(`${this.table}/restore`,e)}}class Et{constructor(e,s,t=1){N(this,"table");N(this,"dbName");N(this,"version");N(this,"db",null);this.table=e,this.dbName=s,this.version=t}close(){this.db&&(this.db.onversionchange=null,this.db.close(),this.db=null)}open(){return this.db?Promise.resolve(this.db):new Promise((e,s)=>{const t=indexedDB.open(this.dbName,this.version);t.onupgradeneeded=r=>{const o=r.target.result;o.objectStoreNames.contains(this.table)||o.createObjectStore(this.table,{keyPath:"id",autoIncrement:!0})},t.onsuccess=r=>{this.db=r.target.result,this.db.onversionchange=()=>{this.close()},e(this.db)},t.onerror=r=>{s(r.target.error)}})}async transaction(e){return(await this.open()).transaction(this.table,e).objectStore(this.table)}request(e){return new Promise((s,t)=>{e.onsuccess=()=>s(e.result),e.onerror=()=>t(e.error)})}async insert(e){const s=await this.transaction("readwrite"),t=await this.request(s.add(e));return{...e,id:t}}async insertMany(e){const s=await this.transaction("readwrite");let t=0;for(const r of e)t=await this.request(s.add(r));return{...e[e.length-1],id:t}}async update(e,s){const t=typeof e=="number"?s:e;if(!t)throw new Error("IndexedDBClient.update requires a value payload");const r=typeof e=="number"?{...t,id:t.id??e}:t,o=await this.transaction("readwrite");return await this.request(o.put(r)),r}async get(e,s){var g;const t=await this.transaction("readonly"),r=await this.request(t.getAll()),o=this.applyFilter(r,s),a=(e==null?void 0:e.sortingBy)??"id",c=((g=e==null?void 0:e.sortingOrder)==null?void 0:g.toLowerCase())??"asc";o.sort((p,y)=>{const b=p[a],w=y[a];return b<w?c==="asc"?-1:1:b>w?c==="asc"?1:-1:0});const i=(e==null?void 0:e.pageSize)??10,m=(e==null?void 0:e.currentPage)??0,u=o.length,f=Math.ceil(u/i),h=o.slice(m*i,m*i+i);return{sort:a,order:c,currentPage:m,pageSize:i,totalElements:u,totalPages:f,items:h}}async export(e){const s=await this.transaction("readonly"),t=await this.request(s.getAll());return this.applyFilter(t,e)}async import(e){const s=await this.transaction("readwrite");let t=0;for(const r of e.items)e.override?await this.request(s.put(r)):await this.request(s.add(r)),t++;return t}async commonGet(e){const s=await this.transaction("readonly"),t=await this.request(s.getAll());return this.applyFilter(t,e)}async getById(e){const s=await this.transaction("readonly"),t=await this.request(s.get(e));if(!t)throw new Error(`Record ${e} not found in ${this.table}`);return t}async softDelete(e){const s=await this.transaction("readwrite");let t=0;for(const r of e){const o=await this.request(s.get(r));o&&(await this.request(s.put({...o,deletedAt:new Date})),t++)}return t}async restore(e){const s=await this.transaction("readwrite");let t=0;for(const r of e){const o=await this.request(s.get(r));o&&(await this.request(s.put({...o,deletedAt:null})),t++)}return t}applyFilter(e,s){if(!s)return e;const t=this.resolveSoftDeleteScope(s.softDeleteScope),r=t===void 0?e:e.filter(a=>this.matchesSoftDeleteScope(t,a.deletedAt)),o=Object.entries(s).filter(([a,c])=>a!=="softDeleteScope"&&c!==void 0);return o.length===0?r:r.filter(a=>o.every(([c,i])=>this.matchesFilterValue(i,a[c])))}matchesFilterValue(e,s){if(e instanceof Date){if(s instanceof Date)return s.getTime()===e.getTime();if(typeof s=="string"||typeof s=="number"){const t=new Date(s);return Number.isNaN(t.getTime())?!1:t.getTime()===e.getTime()}return!1}return s===e}resolveSoftDeleteScope(e){if(typeof e!="string")return;const s=e.trim().toUpperCase();if(s==="ACTIVE")return"ACTIVE";if(s==="DELETED")return"DELETED";if(s==="ALL")return"ALL"}matchesSoftDeleteScope(e,s){if(e==="ALL")return!0;const t=s!=null;return e==="DELETED"?t:!t}}const ye=n=>typeof n=="object"&&n!==null,vt=n=>ye(n)?"start"in n||"end"in n:!1,Nt=n=>n!==void 0,ee=n=>n instanceof Date?n.toISOString():n,At=n=>{if(typeof n!="string")return;const e=n.trim().toUpperCase();if(e==="ACTIVE")return"ACTIVE";if(e==="DELETED")return"DELETED";if(e==="ALL")return"ALL"};class jt{constructor(e,s,t={}){N(this,"table");N(this,"supabase");N(this,"idColumn");N(this,"deletedAtColumn");N(this,"defaultSortColumn");N(this,"options");this.table=e,this.supabase=s,this.options=t,this.idColumn=t.idColumn??"id",this.deletedAtColumn=t.deletedAtColumn??"deletedAt",this.defaultSortColumn=t.defaultSortColumn??this.idColumn}resolveStatus(e){return typeof e=="number"&&Number.isFinite(e)?e:500}throwHttpError(e,s,t,r="Unknown error"){throw{status:this.resolveStatus(s),message:(e==null?void 0:e.message)||t||r}}assertNoError(e,s,t,r){e&&this.throwHttpError(e,s,t,r)}toDto(e){return this.options.mapRowToDto?this.options.mapRowToDto(e):e}toCommonDto(e){return this.options.mapRowToCommonDto?this.options.mapRowToCommonDto(e):e}toAddRow(e){return this.options.mapAddDtoToRow?this.options.mapAddDtoToRow(e):e}toUpdateRow(e){return this.options.mapUpdateDtoToRow?this.options.mapUpdateDtoToRow(e):e}toImportRow(e){return this.options.mapImportPreviewToRow?this.options.mapImportPreviewToRow(e):e}resolveObjectFilterValue(e){return"id"in e?ee(e.id):""}applyFilters(e,s){if(!s)return e;let t=e;const r=At(s.softDeleteScope);return r==="ACTIVE"?t=t.is(this.deletedAtColumn,null):r==="DELETED"&&(t=t.not(this.deletedAtColumn,"is",null)),Object.entries(s).forEach(([o,a])=>{if(o==="softDeleteScope"||a===void 0||a===null||a==="")return;const c=o==="deletedAt"?this.deletedAtColumn:o;if(Array.isArray(a)){const i=a.map(m=>m instanceof Date?m.toISOString():ye(m)?this.resolveObjectFilterValue(m):ee(m)).filter(Nt);i.length>0&&(t=t.in(c,i));return}if(vt(a)){a.start!==void 0&&a.start!==""&&(t=t.gte(c,ee(a.start))),a.end!==void 0&&a.end!==""&&(t=t.lte(c,ee(a.end)));return}if(a instanceof Date){t=t.eq(c,a.toISOString());return}if(ye(a)){t=t.eq(c,this.resolveObjectFilterValue(a));return}t=t.eq(c,ee(a))}),t}async insert(e){const s=await this.supabase.from(this.table).insert(this.toAddRow(e)).select("*").single();return this.assertNoError(s.error,s.status,s.statusText,"Unable to insert"),s.data||this.throwHttpError(null,s.status,s.statusText,"Unable to insert"),this.toDto(s.data)}async insertMany(e){var o;e.length===0&&this.throwHttpError(null,400,void 0,"insertMany requires items");const s=e.map(a=>this.toAddRow(a)),t=await this.supabase.from(this.table).insert(s).select("*");this.assertNoError(t.error,t.status,t.statusText,"Unable to insert many rows");const r=(o=t.data)==null?void 0:o.at(-1);return r||this.throwHttpError(null,t.status,t.statusText,"Unable to insert many rows"),this.toDto(r)}async update(e){const s={[this.idColumn]:e.id},t=await this.supabase.from(this.table).update(this.toUpdateRow(e)).match(s).select("*").maybeSingle();return this.assertNoError(t.error,t.status,t.statusText,"Unable to update"),t.data||this.throwHttpError(null,404,t.statusText,`Record ${e.id} not found`),this.toDto(t.data)}async get(e,s){const t=(e==null?void 0:e.pageSize)??10,r=(e==null?void 0:e.currentPage)??0,o=String((e==null?void 0:e.sortingBy)??this.defaultSortColumn),a=String((e==null?void 0:e.sortingOrder)??"asc").toLowerCase()==="desc"?"desc":"asc",c=r*t,i=c+t-1;let m=this.supabase.from(this.table).select("*",{count:"exact"});m=this.applyFilters(m,s).order(o,{ascending:a==="asc"}).range(c,i);const u=await m;this.assertNoError(u.error,u.status,u.statusText,"Unable to load list");const f=(u.data??[]).map(g=>this.toDto(g)),h=u.count??f.length;return{sort:o,order:a,currentPage:r,pageSize:t,totalElements:h,totalPages:t>0?Math.ceil(h/t):0,items:f}}async export(e){let s=this.supabase.from(this.table).select("*");s=this.applyFilters(s,e);const t=await s;return this.assertNoError(t.error,t.status,t.statusText,"Unable to export"),(t.data??[]).map(r=>this.toDto(r))}async import(e){var o;if(e.items.length===0)return 0;const s=e.items.map(a=>this.toImportRow(a)),r=await(e.override?this.supabase.from(this.table).upsert(s,{onConflict:this.idColumn}).select(this.idColumn):this.supabase.from(this.table).insert(s).select(this.idColumn));return this.assertNoError(r.error,r.status,r.statusText,"Unable to import rows"),((o=r.data)==null?void 0:o.length)??0}async commonGet(e){let s=this.supabase.from(this.table).select("*");s=this.applyFilters(s,e);const t=await s;return this.assertNoError(t.error,t.status,t.statusText,"Unable to load common data"),(t.data??[]).map(r=>this.toCommonDto(r))}async getById(e){const s={[this.idColumn]:e},t=await this.supabase.from(this.table).select("*").match(s).maybeSingle();return this.assertNoError(t.error,t.status,t.statusText,"Unable to load item"),t.data||this.throwHttpError(null,404,t.statusText,`Record ${e} not found`),this.toDto(t.data)}async softDelete(e){var a,c,i;if(e.length===0)return 0;const s=((c=(a=this.options).nowFactory)==null?void 0:c.call(a).toISOString())??new Date().toISOString(),t=this.supabase.from(this.table).update({[this.deletedAtColumn]:s}),r=`(${e.join(",")})`,o=await t.filter(this.idColumn,"in",r).select(this.idColumn);return this.assertNoError(o.error,o.status,o.statusText,"Unable to soft delete"),((i=o.data)==null?void 0:i.length)??0}async restore(e){var o;if(e.length===0)return 0;const s=this.supabase.from(this.table).update({[this.deletedAtColumn]:null}),t=`(${e.join(",")})`,r=await s.filter(this.idColumn,"in",t).select(this.idColumn);return this.assertNoError(r.error,r.status,r.statusText,"Unable to restore"),((o=r.data)==null?void 0:o.length)??0}}const $t=n=>typeof n=="object"&&n!==null,Dt=(n,e)=>{if($t(n))for(const s of e){const t=n[s];if(typeof t=="string"&&t.trim().length>0)return t.trim()}},Lt=(n,e)=>{if(!n)return e;const s=Number(n);return Number.isFinite(s)?s:e},we=(n,e)=>{const{defaultId:s=0,defaultUsername:t="",defaultEmail:r="",usernameMetadataKeys:o=["username","name","full_name"]}=e??{},a=Dt(n.user.user_metadata,o);return{id:Lt(n.user.id,s),username:a??t,email:n.user.email??r,token:n.access_token,refreshToken:n.refresh_token??null,accessTokenExpiresAt:typeof n.expires_at=="number"?new Date(n.expires_at*1e3).toISOString():null}};function Rt(n){return Object.keys(n).filter(e=>isNaN(Number(e))).map(e=>({key:e,value:n[e]}))}const q=(n,e="")=>{const s=localStorage.getItem(n)??void 0;if(s&&e.length)switch(e){case"object":return JSON.parse(s);case"number":return Number(s);case"boolean":return s==="true"||s==="1";default:return s}return s},M=(n,e)=>localStorage.setItem(n,typeof e=="object"?JSON.stringify(e):e),j=n=>localStorage.removeItem(n);function It(n){const e=n?new Date(n):new Date,s={weekday:"long",day:"numeric",month:"long",year:"numeric",hour:"numeric",minute:"2-digit",hour12:!0};return e.toLocaleString(navigator.language||"es-ES",s)}function Ft(n){const e=n?new Date(n):new Date,s=String(e.getDate()).padStart(2,"0"),t=String(e.getMonth()+1).padStart(2,"0"),r=String(e.getFullYear()).slice(-2),o=String(e.getHours()).padStart(2,"0"),a=String(e.getMinutes()).padStart(2,"0");return`${s}/${t}/${r} ${o}:${a}`}function Mt(n){const e=n?new Date(n):new Date,s=e.getFullYear(),t=String(e.getMonth()+1).padStart(2,"0"),r=String(e.getDate()).padStart(2,"0"),o=String(e.getHours()).padStart(2,"0"),a=String(e.getMinutes()).padStart(2,"0");return`${s}-${t}-${r}T${o}:${a}`}const _e=()=>{var s;const n=navigator,e=((s=n==null?void 0:n.userAgentData)==null?void 0:s.platform)||(n==null?void 0:n.platform)||"";return/Mac|iPhone|iPod|iPad/i.test(e)};function se(n){if(!n||typeof n!="object")return!1;const e=n;return Array.isArray(e.errors)&&e.errors.every(s=>Array.isArray(s)&&s.length===2&&typeof s[0]=="string")}function ne(n){if(!n||typeof n!="object")return!1;const e=n;return typeof(e==null?void 0:e.status)=="number"&&typeof(e==null?void 0:e.message)=="string"}function _t(n,e){return n!=null&&n.errors?n.errors.map(([s,t])=>e(s,t)):[]}const Pe=d.createContext(void 0);function Pt(n){const{children:e}=n,s=d.useRef(0),[t,r]=d.useReducer((h,g)=>{const{type:p,items:y,id:b}=g;switch(p){case"set":return y??[];case"remove":return b!==void 0?h.filter(w=>w.id!==b):[]}return h},[],()=>[]),o=h=>h.map(g=>({...g,id:s.current++})),a=d.useCallback(h=>r({type:"set",items:o([{...h,type:I.error}])}),[]),c=d.useCallback(h=>r({type:"set",items:o([{...h}])}),[]),i=d.useCallback(h=>r({type:"set",items:o(h)}),[]),m=d.useCallback(h=>r({type:"set",items:o([{...h,type:I.success}])}),[]),u=h=>r({type:"remove",id:h}),f=d.useMemo(()=>({notification:t,removeNotification:u,showErrorNotification:a,showNotification:c,showSuccessNotification:m,showStackNotifications:i}),[t,a,c,i,m]);return l.jsx(Pe.Provider,{value:f,children:e})}const z=()=>{const n=d.useContext(Pe);if(!n)throw new Error("NotificationContext must be used within a Provider");return n},de=()=>new D.QueryClient({defaultOptions:{queries:{refetchInterval:!1,refetchOnMount:!0,refetchOnReconnect:!1,retry:!1,retryOnMount:!0,refetchOnWindowFocus:!1}}}),Ot=de(),Oe=d.createContext(void 0),Ut=n=>{const{children:e,manager:s,queryClient:t}=n,[r]=d.useState(de),o=t??r;return l.jsx(Oe.Provider,{value:{client:s},children:l.jsx(D.QueryClientProvider,{client:o,children:e})})},Ue=()=>{const n=d.useContext(Oe);if(!n)throw new Error("managerContext must be used within a Provider");return n.client},me=d.createContext(void 0),Ke=()=>{const n=d.useContext(me);if(!n)throw new Error("authContext must be used within a Provider");return n},Kt=n=>{const{children:e,guestMode:s="guest_mode",user:t="user",remember:r="remember",refreshTokenKey:o="refreshToken",accessTokenExpiresAtKey:a="accessTokenExpiresAt"}=n,c=Ue(),[i,m]=d.useState({}),u=d.useCallback(()=>{j(t),j(r),j(o),j(a)},[a,o,r,t]),f=d.useCallback(()=>!!q(s,"boolean")&&i.token===void 0,[i.token,s]),h=d.useCallback(w=>{M(s,w)},[s]),g=d.useCallback((w,S)=>{if(!w)return;const x=q(r,"boolean"),k=S??(typeof x=="boolean"?x:!1);m(w),j(s),M(t,w.token),M(r,k),typeof w.refreshToken=="string"&&w.refreshToken.length?M(o,w.refreshToken):j(o),typeof w.accessTokenExpiresAt=="string"&&w.accessTokenExpiresAt.length?M(a,w.accessTokenExpiresAt):j(a)},[a,s,o,r,t]),p=d.useCallback(async()=>{const w=q(t)??i.token,S=q(o)??(typeof i.refreshToken=="string"?i.refreshToken:void 0);try{await c.Auth.logout({accessToken:w,refreshToken:S})}catch(x){console.error(x)}m({}),u()},[i.refreshToken,i.token,u,c.Auth,o,t]),y=d.useCallback(async()=>{try{const w=await c.Auth.getSession();g(w)}catch(w){console.error(w),p()}},[g,p,c.Auth]),b=d.useMemo(()=>({account:i,logUser:g,logoutUser:p,logUserFromLocal:y,isInGuestMode:f,setGuestMode:h}),[i,g,p,y,f,h]);return l.jsx(me.Provider,{value:b,children:e})},xe=()=>Ke(),Se=d.createContext(void 0),qe=()=>{const n=d.useContext(Se);if(!n)throw new Error("supabaseManagerContext must be used within a Provider");return n.client},qt=n=>{const{children:e,guestMode:s="guest_mode",user:t="user",remember:r="remember",refreshTokenKey:o="refreshToken",accessTokenExpiresAtKey:a="accessTokenExpiresAt",sessionMapper:c}=n,i=qe(),m=d.useRef(c??we);d.useEffect(()=>{m.current=c??we},[c]);const[u,f]=d.useState({}),h=d.useCallback(()=>{j(t),j(r),j(o),j(a)},[a,o,r,t]),g=d.useCallback(()=>!!q(s,"boolean")&&u.token===void 0,[u.token,s]),p=d.useCallback(x=>{M(s,x)},[s]),y=d.useCallback((x,k)=>{if(!x)return;const T=q(r,"boolean"),_=k??(typeof T=="boolean"?T:!1);f(x),j(s),M(t,x.token),M(r,_),typeof x.refreshToken=="string"&&x.refreshToken.length?M(o,x.refreshToken):j(o),typeof x.accessTokenExpiresAt=="string"&&x.accessTokenExpiresAt.length?M(a,x.accessTokenExpiresAt):j(a)},[a,s,o,r,t]),b=d.useCallback(async()=>{try{await i.auth.signOut()}catch(x){console.error(x)}f({}),h()},[h,i.auth]),w=d.useCallback(async()=>{try{const{data:x,error:k}=await i.auth.getSession();if(k)throw k;if(!x.session){f({}),h();return}y(m.current(x.session))}catch(x){console.error(x),await b()}},[h,y,b,i.auth]);d.useEffect(()=>{let x=!0;(async()=>{x&&await w()})();const{data:T}=i.auth.onAuthStateChange((_,O)=>{if(x){if(!O){f({}),h();return}y(m.current(O))}});return()=>{x=!1,T.subscription.unsubscribe()}},[h,y,w,i.auth]);const S=d.useMemo(()=>({account:u,logUser:y,logoutUser:b,logUserFromLocal:w,isInGuestMode:g,setGuestMode:p}),[u,y,b,w,g,p]);return l.jsx(me.Provider,{value:S,children:e})},Qt=n=>{const{children:e,supabase:s,queryClient:t}=n,[r]=d.useState(de),o=t??r;return l.jsx(Se.Provider,{value:{client:s},children:l.jsx(D.QueryClientProvider,{client:o,children:e})})},Qe=d.createContext({}),Ht=n=>{const{children:e,location:s,navigate:t,linkComponent:r,searchComponent:o}=n;return l.jsx(Qe.Provider,{value:{location:s,navigate:t,linkComponent:r,searchComponent:o},children:e})},X=()=>{const n=d.useContext(Qe);if(n===void 0||Object.keys(n).length===0)throw new Error("Config provider has not been set. This step is required and cannot be skipped.");return n},Bt={addChildItem:()=>{},removeChildItem:()=>{},clearDynamicItems:()=>{},dynamicItems:{}},Te=d.createContext(Bt),Vt=n=>{const{children:e}=n,[s,t]=d.useState({}),r=d.useCallback((i,m)=>t(u=>({...u,[i]:[...u[i]??[],m]})),[]),o=d.useCallback((i,m)=>t(u=>({...u,[i]:(u[i]??[]).filter((f,h)=>h!==m)})),[]),a=d.useCallback(i=>{t(i?m=>({...m,[i]:[]}):{})},[]),c=d.useMemo(()=>({dynamicItems:s,addChildItem:r,removeChildItem:o,clearDynamicItems:a}),[s,a,o,r]);return l.jsx(Te.Provider,{value:c,children:e})},He=()=>d.useContext(Te);function Gt(n){const{t:e}=C.useTranslation(),{open:s,onClose:t,menuMap:r,logo:o}=n,{account:a}=xe(),{dynamicItems:c}=He(),{linkComponent:i,location:m}=X(),u=i,f=d.useMemo(()=>r.filter(b=>{const w=b.auth,S=!!(a!=null&&a.email);return w==null||w&&S||!w&&!S}),[a==null?void 0:a.email,r]),h=d.useCallback(b=>{b.key==="Escape"&&s&&t()},[t,s]);d.useEffect(()=>(document.addEventListener("keydown",h),()=>{document.removeEventListener("keydown",h)}),[h]);const g=d.useCallback((b,w)=>w?b===`${m.pathname}${m.search}`:b===m.pathname,[m.pathname,m.search]),p=d.useCallback(b=>l.jsx("li",{className:`drawer-list-item-child ${g(b.path,!0)?"active":""} animated`,children:b.path?l.jsx(u,{tabIndex:s?0:-1,to:b.path??"/","aria-label":e(`_accessibility:ariaLabels.${b.id}`,{defaultValue:b.label}),className:"drawer-link",children:b.label}):b.label},b.id),[u,s,e,g]),y=d.useMemo(()=>f.map((b,w)=>{const S=b.page??String(w),x=`drawer-list-item ${g(b.path)?"active":""} animated`;if(b.type==="divider")return l.jsx("li",{className:x,children:l.jsx("hr",{className:"drawer-divider"})},S);const k=b.children??(b.page&&c?c[b.page]:null);return l.jsxs("li",{className:x,children:[l.jsxs(u,{tabIndex:s?0:-1,to:b.path??"/","aria-label":e(`_accessibility:ariaLabels.${String(b.page)}`,{defaultValue:e(`_pages:${String(b.page)}.title`)}),className:"drawer-link",children:[b.icon,e(`_pages:${b.page}.title`)]}),k&&l.jsx("ul",{className:"drawer-children-list",children:k.map(p)})]},S)}),[u,c,g,s,f,p,e]);return l.jsx("div",{"aria-label":e("_accessibility:ariaLabels.closeMenu"),"aria-disabled":!s,className:`${s?"opened":"closed"} drawer-backdrop`,onClick:()=>t(),children:l.jsxs("aside",{className:`${s?"opened":"closed"} drawer animated`,children:[l.jsxs("div",{className:"drawer-header-container",children:[o,l.jsx("h2",{className:"drawer-header poppins",children:e("_pages:home.appName")})]}),l.jsx("ul",{className:"drawer-menu-list",children:y})]})})}const Q=({icon:n,...e})=>l.jsx(C.IconButton,{icon:l.jsx(U.FontAwesomeIcon,{icon:n}),...e});var ge,$e;function zt(){if($e)return ge;$e=1;const n=(c,i="local",m=void 0)=>{if(i==="local"){if(localStorage.getItem(c)!==void 0&&localStorage.getItem(c)!=="undefined"&&localStorage.getItem(c)!==null)return m===void 0||m!==void 0&&localStorage.getItem(c)===m}else if(i==="session"&&sessionStorage.getItem(c)!==void 0&&sessionStorage.getItem(c)!=="undefined"&&sessionStorage.getItem(c)!==null)return m===void 0||m!==void 0&&sessionStorage.getItem(c)===m;return!1},e=c=>{const i={};return c.substring(1).split("&").forEach(u=>{const[f,h]=u.split("=");i[f]=h}),i},s=(c="")=>{if(o(c)&&c.length)return o(c);{let i=navigator.language||navigator.userLanguage;if(i.indexOf("en")<0&&i.indexOf("es")<0&&(i="en-US"),i=i.split("-")[0],i)return c.length&&r(c,730,i),i}return"en"},t=(c=0,i=0,m=window,u="smooth")=>m.scroll({top:c,left:i,behavior:u}),r=(c,i,m,u="/",f="Lax")=>{var h=new Date;h.setTime(h.getTime()+i*24*60*60*1e3);const g="; expires="+h.toUTCString();document.cookie=`${c}=${m||""}${g};path=${u};SameSite=${f}`},o=c=>{const i=`${c}=`,u=decodeURIComponent(document.cookie).split(";");for(let f=0;f<u.length;f+=1){let h=u[f];for(;h.charAt(0)===" ";)h=h.substring(1);if(h.indexOf(i)===0)return h.substring(i.length,h.length)}return""};return ge={getCookie:o,createCookie:r,deleteCookie:c=>document.cookie=`${c}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`,getUserLanguage:s,scrollTo:t,parseQueries:e,validation:n},ge}var Wt=zt();function Jt(){const{t:n,language:e}=C.useTranslation();return{timeAge:d.useCallback(t=>{const o=new Date-t,a=Math.floor(o/(1e3*60)),c=Math.floor(a/60),i=e==="es",m=n("_accessibility:labels.ago"),u=n("_accessibility:labels.minute"),f=n("_accessibility:labels.minutes"),h=n("_accessibility:labels.hour"),g=n("_accessibility:labels.hours"),p=n("_accessibility:labels.yesterday"),y=n("_accessibility:labels.justNow");return o<1e3*60?y:a<60?`${i?m:""} ${a} ${a===1?u:f} ${i?"":m}`:c<24?`${i?m:""} ${c} ${c===1?h:g} ${i?"":m}`:c<48?p:t.toLocaleDateString(navigator.language||"es-ES",{day:"2-digit",month:"2-digit",year:"numeric"})},[n,e])}}const ke=n=>{const{showSuccessNotification:e}=z(),{mutationFn:s,onError:t,onSuccess:r,onSuccessMessage:o}=n,[a,c]=d.useState([]),{open:i,handleClose:m,handleOpen:u}=Ee(),f=()=>{m(),c([])},h=async p=>{c(p),u()},g=D.useMutation({mutationFn:()=>s(Array.isArray(a)?a:[a]),onError:p=>{console.error(p),t&&t(p),f()},onSuccess:async p=>{r&&r(p),e({message:o}),f()}});return{open:i,onClick:h,close:f,dialogFn:g,isLoading:g.isPending}},Yt=n=>{const{t:e}=C.useTranslation(),{showStackNotifications:s,showSuccessNotification:t,showErrorNotification:r}=z(),o=D.useQueryClient(),{defaultValues:a,mutationFn:c,formToDto:i,onError:m,onSuccess:u,queryKey:f,onSuccessMessage:h}=n,{control:g,handleSubmit:p,reset:y,setError:b,getValues:w,setValue:S}=Re.useForm({defaultValues:a}),x=d.useRef(null),k=d.useCallback(()=>{const E=document.activeElement;if(!(E instanceof HTMLElement)){x.current=null;return}x.current=E.closest("form")},[]),T=d.useCallback(E=>{const A=E==null?void 0:E.errors,L=[],R=x.current;if(!R)return L;let K=!1;return A&&A.forEach(([oe,fe])=>{const V=R.querySelector(`[name="${oe}"]`);(V instanceof HTMLInputElement||V instanceof HTMLTextAreaElement||V instanceof HTMLSelectElement)&&(K||(V.focus(),K=!0),V.classList.add("error"),L.push(e(`_entities:${f}.${oe}.${fe}`)))}),L},[e,f]),_=d.useCallback(()=>{const E=x.current;if(!E)return;E.querySelectorAll("input, textarea, select").forEach(L=>{L.classList.remove("error")})},[]),O=D.useMutation({mutationFn:c,onError:E=>{console.error(E);const A=E;if(m)m(E);else if(se(A)){const L=T(A);s(L.map(R=>({message:R,type:I.error})))}else if(ne(A)){const L=A.message||e("_accessibility:errors.500"),R=e(`_accessibility:errors.${A.status}`);r({message:R||L})}else r({message:e("_accessibility:errors.500")})},onSuccess:async E=>{await o.invalidateQueries({queryKey:f}),u&&u(E),h&&t({message:h})}});return{control:g,getValues:w,setValue:S,handleSubmit:p,onSubmit:E=>{k(),_(),O.mutate(i?i(E):E)},reset:y,setError:b,isLoading:O.isPending}},Be=n=>{const{t:e}=C.useTranslation(),{onClick:s,icon:t=$.faTrash,sticky:r=!0,hidden:o=!1,multiple:a=!0,disabled:c=!1,id:i=B.Delete,tooltip:m=e("_pages:common.actions.delete.text")}=n;return{action:d.useCallback(f=>({id:i,sticky:r,tooltip:m,multiple:a,onClick:()=>s([f==null?void 0:f.id]),hidden:!!f.deletedAt||o,disabled:!!f.deletedAt||c,icon:l.jsx(U.FontAwesomeIcon,{className:"text-bg-error",icon:t}),onMultipleClick:h=>s(h.map(g=>g.id))}),[c,o,t,i,a,s,r,m])}},Ve=n=>{const{t:e}=C.useTranslation(),{onClick:s,sticky:t=!0,hidden:r=!1,disabled:o=!1,multiple:a=!1,icon:c=$.faRotateLeft,id:i=B.Restore,tooltip:m=e("_pages:common.actions.restore.text")}=n;return{action:d.useCallback(f=>({id:i,sticky:t,tooltip:m,multiple:a,onClick:()=>s([f==null?void 0:f.id]),hidden:!f.deletedAt||r,disabled:!f.deletedAt||o,icon:l.jsx(U.FontAwesomeIcon,{className:"text-bg-error",icon:c}),onMultipleClick:h=>s(h.map(g=>g.id))}),[o,r,c,i,a,s,t,m])}},Xt=n=>{const{t:e}=C.useTranslation(),{onClick:s,hidden:t=!1,sticky:r=!0,disabled:o=!1,id:a=B.Edit,icon:c=$.faPencil,tooltip:i=e("_pages:common.actions.edit.text")}=n;return{action:d.useCallback(u=>({id:a,sticky:r,tooltip:i,onClick:()=>s(u==null?void 0:u.id),hidden:!!u.deletedAt||t,disabled:!!u.deletedAt||o,icon:l.jsx(U.FontAwesomeIcon,{className:"primary",icon:c})}),[o,t,c,a,s,r,i])}};var B=(n=>(n.Add="add",n.Edit="edit",n.Delete="delete",n.Restore="restore",n.Refresh="refresh",n.Export="export",n.Import="import",n))(B||{});const Ge=n=>{const{t:e}=C.useTranslation(),{onClick:s,hidden:t=!1,disabled:r=!1,isLoading:o=!1}=n;return{action:d.useCallback(()=>({id:B.Export,hidden:t,disabled:r,icon:l.jsx(U.FontAwesomeIcon,{className:`${o?"rotate":""}`,icon:o?$.faCircleNotch:$.faCloudArrowDown}),tooltip:e("_pages:common.actions.export.text"),onClick:s}),[r,t,o,s,e])}},ze=n=>{const{t:e}=C.useTranslation(),{onClick:s,hidden:t=!1,disabled:r=!1,isLoading:o=!1}=n;return{action:d.useCallback(()=>({id:B.Import,hidden:t,disabled:r,icon:l.jsx(U.FontAwesomeIcon,{className:`${o?"rotate":""}`,icon:o?$.faCircleNotch:$.faCloudUpload}),tooltip:e("_pages:common.actions.import.text"),onClick:s}),[r,t,o,s,e])}},Zt=n=>{const{queryKey:e,onSuccess:s,...t}=n,r=D.useQueryClient(),{showStackNotifications:o}=z(),{t:a}=C.useTranslation(),{open:c,onClick:i,close:m,dialogFn:u,isLoading:f}=ke({onSuccessMessage:a("_pages:common.actions.delete.successMessage"),onError:g=>{const p=g;if(se(p))o(p.errors.map(([y,b])=>({message:a(`_pages:${y}.errors.${b}`),type:I.error})));else if(ne(p)){const y=p.message||a("_accessibility:errors.500"),b=a(`_accessibility:errors.${p.status}`);o([{message:b||y,type:I.error}])}},onSuccess:async g=>{await r.invalidateQueries({queryKey:e}),s&&s(g)},...t}),{action:h}=Be({onClick:i});return{onClick:i,title:a("_pages:common.actions.delete.dialog.title"),open:c,isLoading:f,handleSubmit:()=>u.mutate(),handleClose:m,action:h}},Ee=()=>{const[n,e]=d.useState(!1);return{open:n,setOpen:e,handleClose:()=>e(!1),handleOpen:()=>e(!0)}},es=n=>"mutationFn"in n&&"queryKey"in n,re=n=>{const e=es(n),s=e?n:void 0,t=e?void 0:n,r=e?"entity":(t==null?void 0:t.mode)??"state",{t:o}=C.useTranslation(),a=D.useQueryClient(),{showErrorNotification:c,showStackNotifications:i,showSuccessNotification:m}=z(),[u,f]=d.useState(),[h,g]=d.useState(!1),p=d.useRef(!1),y=d.useRef(),{open:b,handleClose:w,handleOpen:S}=Ee(),{control:x,handleSubmit:k,reset:T,setError:_,getValues:O,setValue:E}=Re.useForm({defaultValues:(s==null?void 0:s.defaultValues)||(t==null?void 0:t.defaultValues)||{}}),A=d.useRef(null),L=d.useCallback(()=>{const v=document.activeElement;if(!(v instanceof HTMLElement)){A.current=null;return}A.current=v.closest("form")},[]),R=s?[...s.queryKey,u??0]:["__legacy-form-dialog-disabled__",u??0],{data:K,isLoading:oe}=D.useQuery({queryFn:async()=>{if(!(!(s!=null&&s.getFunction)||!u))return s.getFunction(u)},queryKey:R,enabled:!!(s!=null&&s.getFunction)&&!!u});d.useEffect(()=>{!s||!K||!s.dtoToForm||y.current!==K&&(T({...s.dtoToForm(K)}),y.current=K)},[K,s,T]),d.useEffect(()=>{if(t){if(!b){p.current=!1;return}if(!p.current){if(p.current=!0,t.reinitializeOnOpen&&t.mapIn){T(t.mapIn());return}if(t.reinitializeOnOpen&&t.defaultValues){T(t.defaultValues);return}t.resetOnOpen&&T(t.defaultValues||{})}}},[t,b,T]);const fe=d.useCallback(v=>{const P=v==null?void 0:v.errors,H=[],J=A.current;if(!J||!s)return H;let Ne=!1;return P&&P.forEach(([Ae,ot])=>{const Z=J.querySelector(`[name="${Ae}"]`);(Z instanceof HTMLInputElement||Z instanceof HTMLTextAreaElement||Z instanceof HTMLSelectElement)&&(Ne||(Z.focus(),Ne=!0),Z.classList.add("error"),H.push(o(`_entities:${s.queryKey}.${Ae}.${ot}`)))}),H},[s,o]),V=d.useCallback(()=>{const v=A.current;if(!v)return;v.querySelectorAll("input, textarea, select").forEach(H=>{H.classList.remove("error")})},[]),W=d.useCallback(()=>{V(),A.current=null,w(),T()},[w,V,T]),tt=d.useCallback(v=>{f(v),S()},[S]),he=D.useMutation({mutationFn:async v=>{if(s)return s.mutationFn(v)},onError:v=>{if(s)if(s.onError)s.onError(v);else{const P=v;if(se(P)){const H=fe(P);i(H.map(J=>({message:J,type:I.error})))}else if(ne(P)){const H=P.message||o("_accessibility:errors.500"),J=o(`_accessibility:errors.${P.status}`);c({message:J||H})}else c({message:o("_accessibility:errors.500")})}},onSuccess:async v=>{s&&(await a.invalidateQueries({queryKey:s.queryKey}),s.onSuccess&&await s.onSuccess(v),m({message:s.onSuccessMessage}),W())}}),ae=d.useCallback(v=>s?v:t!=null&&t.mapOut?t.mapOut(v,{id:u}):v,[t,u,s]),st=d.useCallback(async()=>{if(!(t!=null&&t.onApply))return;const v=O(),P=ae(v);g(!0);try{await t.onApply(P,{close:W,id:u,values:v})}finally{g(!1)}},[W,t,O,u,ae]),nt=d.useCallback(async()=>{if(t){if(t.onClear){g(!0);try{await t.onClear()}finally{g(!1)}}T(t.defaultValues||{})}},[t,T]),rt=d.useCallback(async v=>{if(s){L(),he.mutate(s.formToDto?s.formToDto(v):v);return}const P=ae(v);g(!0);try{t!=null&&t.onSubmit&&await t.onSubmit(P,{close:W,id:u,values:v}),((t==null?void 0:t.closeOnSubmit)??!0)&&W()}finally{g(!1)}},[L,W,t,u,he,s,ae]);return{open:b,mode:r,id:u,openDialog:tt,handleClose:W,control:x,getValues:O,setValue:E,handleSubmit:k,onSubmit:rt,reset:T,setError:_,title:n.title,isSubmitting:h,onApply:st,onClear:nt,isLoading:oe||he.isPending||h}},ts=re,ss=n=>re(n),ns=n=>{const e=D.useQueryClient(),{mutationFn:s,queryKey:t,onSuccess:r,onError:o,mapOut:a,...c}=n,i=D.useMutation({mutationFn:s});return re({...c,mode:"entity",mapOut:a,onSubmit:async m=>{try{const u=await i.mutateAsync(m);t&&await e.invalidateQueries({queryKey:t}),r&&await r(u)}catch(u){throw o&&o(u),u}}})},rs=n=>{const e=D.useQueryClient(),s=d.useRef(),t=d.useRef(),{mutationFn:r,queryKey:o,onSuccess:a,onError:c,mapOut:i,getFunction:m,dtoToForm:u,title:f,...h}=n,g=d.useRef(u);d.useEffect(()=>{g.current=u},[u]);const p=D.useMutation({mutationFn:r}),y=re({...h,mode:"entity",title:f,onSubmit:async x=>{try{const k=await p.mutateAsync(x);o&&await e.invalidateQueries({queryKey:o}),a&&await a(k)}catch(k){throw c&&c(k),k}},mapOut:x=>i?i(x,s.current):x}),{reset:b}=y,w=o||["put-dialog",f],S=D.useQuery({queryFn:()=>m(y.id),queryKey:[...w,y.id],enabled:y.open&&!!y.id});return d.useEffect(()=>{if(S.data&&t.current!==S.data){if(s.current=S.data,t.current=S.data,g.current&&b){b(g.current(S.data));return}b==null||b(S.data)}},[S.data,b]),{...y,isLoading:y.isLoading||p.isPending||S.isFetching||S.isLoading}},os=n=>{const{queryKey:e,onSuccess:s,...t}=n,r=D.useQueryClient(),{showStackNotifications:o}=z(),{t:a}=C.useTranslation(),{open:c,onClick:i,close:m,dialogFn:u,isLoading:f}=ke({onSuccessMessage:a("_pages:common.actions.restore.successMessage"),onError:g=>{const p=g;if(se(p))o(p.errors.map(([y,b])=>({message:a(`_pages:${y}.errors.${b}`),type:I.error})));else if(ne(p)){const y=p.message||a("_accessibility:errors.500"),b=a(`_accessibility:errors.${p.status}`);o([{message:b||y,type:I.error}])}},onSuccess:async g=>{await r.invalidateQueries({queryKey:e}),s&&s(g)},...t}),{action:h}=Ve({onClick:i});return{onClick:i,title:a("_pages:common.actions.restore.dialog.title"),open:c,isLoading:f,handleSubmit:()=>u.mutate(),handleClose:m,action:h}};function as(n){const{t:e}=C.useTranslation(),s=D.useQueryClient(),{queryKey:t,mutationFn:r,entity:o,fileProcessor:a,renderCustomPreview:c,onError:i}=n,[m,u]=d.useState(!1),[f,h]=d.useState(null),[g,p]=d.useState(!1),y=D.useMutation({mutationFn:r,onError:w=>{console.error(w),i==null||i(w)},onSuccess:async()=>{await s.invalidateQueries({queryKey:t})}}),{action:b}=ze({onClick:()=>u(!0)});return{handleSubmit:async()=>{if(!(!f||f.length===0))try{await y.mutateAsync({items:f,override:g}),u(!1),h(null),p(!1)}catch(w){console.error(w)}},isLoading:y.isPending,fileProcessor:a,onFileProcessed:w=>h(w),renderCustomPreview:c,onOverrideChange:w=>p(w),open:m,title:e("_pages:common.actions.import.dialog.title",{entity:e(`_pages:${o}.title`)}),handleClose:()=>{u(!1),h(null),p(!1)},action:b}}const is=n=>{const{showSuccessNotification:e}=z(),{t:s}=C.useTranslation(),{entity:t,mutationFn:r,onError:o,onSuccess:a,onSuccessMessage:c=s("_pages:common.actions.export.successMessage")}=n,i=D.useMutation({mutationFn:()=>r(),onError:f=>{console.error(f),o&&o(f)},onSuccess:async f=>{const h=JSON.stringify(f,null,2),g=new Blob([h],{type:"application/json"}),p=URL.createObjectURL(g),y=document.createElement("a");y.href=p,y.download=`${t}.json`,y.click(),URL.revokeObjectURL(p),a&&a(f),e({message:c})}}),m=d.useCallback(()=>{i.mutate()},[i]),{action:u}=Ge({onClick:m,isLoading:i.isPending});return{action:u}},De=()=>typeof window<"u"?window.scrollY:0;function We(n){const[e,s]=d.useState(De),t=d.useCallback(()=>{s(De())},[]);return d.useEffect(()=>(window.addEventListener("scroll",t),()=>{window.removeEventListener("scroll",t)}),[t]),e>n}const cs=n=>{const{t:e}=C.useTranslation(),{icon:s=$.faArrowUp,threshold:t=200,scrollTop:r=0,scrollLeft:o=0,tooltip:a=e("_accessibility:buttons.toTop"),scrollOnClick:c=!0,onClick:i,className:m="",variant:u="submit",color:f="primary",...h}=n,g=We(t),p=()=>{i==null||i(),c&&Wt.scrollTo(o,r)};return l.jsx(Q,{variant:u,color:f,icon:s,"data-tooltip-id":"tooltip",onClick:p,className:`to-top ${g?"show":"hide"} ${m}`.trim(),"data-tooltip-content":a,...h})};function ls(n){const{t:e}=C.useTranslation();if("children"in n){const{children:k,className:T}=n;return l.jsx("div",{className:`error-container${T?` ${T}`:""}`,children:k})}const{error:t,message:r,iconProps:o,onRetry:a,retryLabel:c,retryButtonProps:i,messageProps:m,className:u,resetErrorBoundary:f}=n,h=a??f,{className:g,children:p,onClick:y,...b}=i??{},{className:w,...S}=m??{},x=o!==null;return l.jsxs("div",{className:`error-container${u?` ${u}`:""}`,children:[x&&l.jsx(U.FontAwesomeIcon,{...o,icon:(o==null?void 0:o.icon)??ct.faSadTear,className:`error-icon${o!=null&&o.className?` ${o.className}`:""}`}),l.jsx("p",{...S,className:`error-message${w?` ${w}`:""}`,children:r??(t==null?void 0:t.message)??e("_accessibility:errors.unknownError")}),h&&l.jsx(C.Button,{type:"button",variant:"submit",color:"primary",...b,className:`error-retry ${g?` ${g}`:""}`,onClick:k=>{y==null||y(k),k.defaultPrevented||h()},children:p??c??e("_accessibility:actions.retry",{defaultValue:"Retry"})})]})}const us=n=>{const{showBackButton:e,title:s,actions:t}=n,{t:r}=C.useTranslation(),{navigate:o}=X();return l.jsxs("div",{className:"page-header",children:[l.jsxs("div",{className:"page-header-left",children:[e&&l.jsx(Q,{icon:$.faArrowLeft,onClick:()=>o(-1),className:"page-header-back",name:r("_accessibility:buttons.back"),"data-tooltip-id":"tooltip","data-tooltip-content":r("_accessibility:buttons.back")}),l.jsx("h2",{className:"page-header-title",children:s})]}),l.jsxs("div",{children:[l.jsx(C.Actions,{className:"page-header-actions-desktop",actions:t??[]}),l.jsx(C.ActionsDropdown,{className:"page-header-actions-mobile",actions:t??[]})]})]})},ds=n=>{const{title:e,children:s,addOptions:t,filterOptions:r,actions:o,queryKey:a,isLoading:c=!1,isAnimated:i=!0,showBackButton:m=!1}=n,{t:u}=C.useTranslation(),f=D.useQueryClient(),{countOfFilters:h}=C.useTableOptions(),g=d.useMemo(()=>{const p=Array.isArray(o)?[...o]:[];if(a){const y={id:B.Refresh,onClick:()=>f.invalidateQueries({queryKey:a}),icon:l.jsx(U.FontAwesomeIcon,{icon:$.faRotateLeft}),tooltip:u("_pages:common.actions.refresh.text")};p.unshift(y)}if(t){const y={...t,id:B.Add,icon:l.jsx(U.FontAwesomeIcon,{icon:$.faAdd})};p.unshift(y)}if(r){const y={...r,id:"filter",icon:l.jsx(U.FontAwesomeIcon,{icon:$.faFilter}),children:l.jsx(C.Badge,{className:`${h>0?"show":"hide"} `,count:h})};p.push(y)}return p},[o,t,h,r,f,a,u]);return l.jsxs("main",{className:"page-main",children:[l.jsx(us,{showBackButton:m,actions:g,title:e}),l.jsx("div",{className:`page-main-content ${i?"appear":""}`,children:c?l.jsx(C.Loading,{className:"page-loading"}):s}),t&&l.jsx(Q,{icon:t.icon??$.faAdd,color:t.color??"primary",variant:t.variant??"submit",onClick:()=>{var p;return(p=t.onClick)==null?void 0:p.call(t)},className:`button page-fab ${t.className??""}`})]})},ms=n=>{const{t:e}=C.useTranslation(),{className:s="",itemClassName:t="",loading:r=!1,emptyComponent:o=null,emptyMessage:a=e("_accessibility:messages.empty"),renderComponent:c,data:i=[],hasMore:m=!1,loadingMore:u=!1,onLoadMore:f,loadMoreComponent:h=null,observerRootMargin:g="0px 0px 200px 0px",observerThreshold:p=0}=n,y=d.useRef(!1),b=d.useRef(null),w=d.useCallback(async()=>{if(!(!m||!f)&&!(u||y.current)){y.current=!0;try{await f()}finally{y.current=!1}}},[m,u,f]);return d.useEffect(()=>{if(!m||!f||!b.current||typeof IntersectionObserver>"u")return;const S=new IntersectionObserver(x=>{x.some(k=>k.isIntersecting)&&w()},{rootMargin:g,threshold:p});return S.observe(b.current),()=>S.disconnect()},[m,f,g,p,w]),r?l.jsx(C.Loading,{}):l.jsx(l.Fragment,{children:i!=null&&i.length?l.jsxs("ul",{className:`pretty-grid-main ${s}`,children:[i==null?void 0:i.map(S=>l.jsx("li",{className:`pretty-grid-item ${t}`,children:c(S)},S.id)),m&&f&&l.jsx("li",{className:"pretty-grid-load-more",ref:b,children:h})]}):l.jsx(l.Fragment,{children:o||l.jsx(et,{message:a})})})},ve=d.createContext({title:"",setTitle:()=>{},rightContent:null,setRightContent:()=>{}}),fs=n=>{const{children:e}=n,[s,t]=d.useState(""),[r,o]=d.useState(null),a=d.useCallback(m=>{t(m)},[]),c=d.useCallback(m=>{o(m)},[]),i=d.useMemo(()=>({title:s,setTitle:a,rightContent:r,setRightContent:c}),[s,a,r,c]);return l.jsx(ve.Provider,{value:i,children:e})},Je=()=>d.useContext(ve);function hs(n){const{t:e}=C.useTranslation(),{openDrawer:s,showSearch:t=!0,menuButtonProps:r}=n,{searchComponent:o,location:a}=X(),{title:c,rightContent:i}=Je(),[m,u]=d.useState(!1),f=d.useCallback(p=>{(_e()?p.metaKey:p.ctrlKey)&&p.shiftKey&&p.key.toLowerCase()==="f"&&(u(!0),p.preventDefault())},[]);d.useEffect(()=>(window.addEventListener("keydown",f),()=>{window.removeEventListener("keydown",f)}),[f]);const h=o,g=t&&!!h;return l.jsxs(l.Fragment,{children:[a.pathname!=="/"&&!!h&&l.jsx(h,{open:m,onClose:()=>u(!1)}),l.jsxs("header",{id:"header",className:"header",children:[l.jsxs("div",{className:"navbar-left",children:[l.jsx(Q,{...r,type:(r==null?void 0:r.type)??"button",icon:(r==null?void 0:r.icon)??$.faBars,onClick:p=>{var y;(y=r==null?void 0:r.onClick)==null||y.call(r,p),s()},name:(r==null?void 0:r.name)??e("_accessibility:buttons.openMenu"),"aria-label":(r==null?void 0:r["aria-label"])??e("_accessibility:ariaLabels.openMenu"),className:`navbar-menu animated ${(r==null?void 0:r.className)??""}`}),l.jsx("h1",{className:"poppins navbar-title",children:c||e("_pages:home.appName")})]}),l.jsxs("div",{className:"navbar-right",children:[i,g&&l.jsx(Q,{icon:$.faSearch,className:"navbar-search-btn",onClick:()=>u(!0)})]})]})]})}const ie=300,ps=n=>n??I.error,gs=n=>{switch(n){case I.error:return $.faWarning;default:return $.faCircleCheck}},be=n=>{switch(n){case I.success:return"!text-success";case I.error:return"!text-error";case I.warning:return"!text-warning";default:return"!text-info"}},bs=n=>{switch(n){case I.success:return"bg-bg-success";case I.error:return"bg-bg-error";case I.warning:return"bg-bg-warning";default:return"bg-bg-info"}};function ys(){const{t:n}=C.useTranslation(),{notification:e,removeNotification:s}=z(),[t,r]=d.useState([]),o=d.useRef(t);d.useLayoutEffect(()=>{o.current=t});const a=d.useRef(null),c=d.useCallback(i=>{r(m=>i!==void 0?m.map(u=>u.id===i?{...u,closing:!0}:u):m.map(u=>({...u,closing:!0}))),i!==void 0?setTimeout(()=>{s(i),r(m=>m.filter(u=>u.id!==i))},ie):(a.current&&clearTimeout(a.current),a.current=setTimeout(()=>{s(),r([]),a.current=null},ie))},[s]);return d.useEffect(()=>{let i=null;const m=()=>{i&&clearTimeout(i),a.current&&(clearTimeout(a.current),a.current=null)};if(e.length===0)return o.current.length===0?void 0:(a.current&&clearTimeout(a.current),i=setTimeout(()=>{r(g=>g.map(p=>({...p,closing:!0}))),i=null},0),a.current=setTimeout(()=>{r([]),a.current=null},ie),m);const u=new Set(o.current.map(g=>g.id));if(!e.some(g=>g.id!==void 0&&!u.has(g.id)))return;if(o.current.length===0){const g=[...e];return i=setTimeout(()=>{r(g.map(p=>({...p,closing:!1}))),i=null},0),()=>{i&&clearTimeout(i)}}a.current&&clearTimeout(a.current),i=setTimeout(()=>{r(g=>g.every(p=>p.closing)?g:g.map(p=>({...p,closing:!0}))),i=null},0);const h=[...e];return a.current=setTimeout(()=>{r(h.map(g=>({...g,closing:!1}))),a.current=null},ie),m},[e]),d.useEffect(()=>{if(!t.length)return;let i;const m=window.setTimeout(()=>{i=()=>c(),window.addEventListener("click",i)},0),u=f=>{f.key==="Escape"&&c()};return window.addEventListener("keydown",u),()=>{window.clearTimeout(m),i&&window.removeEventListener("click",i),window.removeEventListener("keydown",u)}},[t.length,c]),Le.createPortal(l.jsx("div",{className:`notification-portal ${t.length?"active":""}`,children:t.map(({id:i,type:m,message:u,closing:f})=>{const h=ps(m);return l.jsxs("div",{className:`notification ${f?"closing":""} ${bs(h)}`,onClick:g=>g.stopPropagation(),children:[l.jsxs("div",{className:"notification-body",children:[l.jsx(U.FontAwesomeIcon,{icon:gs(h),className:`notification-icon ${be(h)}`}),l.jsx("p",{className:`notification-text ${be(h)}`,children:u})]}),l.jsx(Q,{type:"button",icon:$.faClose,color:"error",className:"notification-close group",onClick:g=>{g.stopPropagation(),i!==void 0&&c(i)},iconClassName:`${be(h)} notification-close-icon`,name:n("_accessibility:buttons.closeNotification"),"aria-label":n("_accessibility:ariaLabels.closeNotification")})]},i)})}),document.body)}function ws(n){const{className:e,...s}=n;return l.jsx("div",{className:"splash-screen",children:l.jsx(C.Loading,{className:`blur-appear ${e?` ${e}`:""}`,...s})})}const Ye=n=>{const{id:e,active:s,onClick:t,children:r,to:o,useLinks:a=!0,tabButtonProps:c}=n,{linkComponent:i}=X(),m=i;if(!a){const{className:f="",variant:h=s?"submit":"outlined",color:g=s?"primary":"default",...p}=c??{};return l.jsx(C.Button,{type:"button",variant:h,color:g,className:`tab ${f}`,onClick:t,...p,children:r})}const u=`button submit tab ${s?"primary":"outlined"} ${(c==null?void 0:c.className)??""}`.trim();return l.jsx(m,{to:o??`#${e}`,onClick:()=>t(),className:u,children:r})},Xe=n=>{var g;const{tabs:e=[],defaultTab:s,currentTab:t,onTabChange:r,className:o="",tabsContainerClassName:a="",useLinks:c=!0,tabButtonProps:i}=n,[m,u]=d.useState(s??((g=e[0])==null?void 0:g.id)),f=t??m,h=d.useMemo(()=>e.find(p=>p.id===f),[e,f]);return l.jsxs("div",{className:`tabs-layout-main ${o}`,children:[l.jsx("ul",{className:`horizontal tabs tabs-container ${a}`,children:e.map(({id:p,to:y,label:b})=>l.jsx("li",{children:l.jsx(Ye,{onClick:()=>{t===void 0&&u(p),r==null||r(p)},id:p,to:y,siblings:e.length>1,active:f===p,useLinks:c,tabButtonProps:i,children:b})},p))}),h==null?void 0:h.content]})},Ze=n=>{const{title:e,body:s,content:t,onClickNext:r,onSkip:o,onStartAsGuest:a,onSignIn:c,image:i="",alt:m="",final:u=!1}=n,{t:f}=C.useTranslation();return l.jsxs("div",{className:"big-appear step-container",children:[i&&l.jsx("img",{src:i,alt:m}),e!=null&&l.jsx("h2",{className:"step-title",children:e}),s!=null&&l.jsx("div",{className:"step-body",children:s}),t!=null&&l.jsx("div",{className:"step-content",children:t}),l.jsx("div",{className:"step-actions",children:u?l.jsxs(l.Fragment,{children:[l.jsx(C.Button,{color:"primary",className:"step-button",variant:"outlined",onClick:a,"aria-label":f("_accessibility:ariaLabels.start"),children:f("_accessibility:buttons.startAsGuest")}),l.jsx(C.Button,{color:"primary",variant:"submit",className:"step-button","aria-label":f("_accessibility:ariaLabels.start"),onClick:c,children:f("_accessibility:buttons.signIn")})]}):l.jsxs(l.Fragment,{children:[l.jsx(C.Button,{color:"primary",className:"step-button",variant:"outlined",onClick:o,"aria-label":f("_accessibility:ariaLabels.skip"),children:f("_accessibility:buttons.skip")}),l.jsx(C.Button,{color:"primary",className:"step-button",variant:"outlined",onClick:()=>r(),"aria-label":f("_accessibility:ariaLabels.next"),children:f("_accessibility:buttons.next")})]})})]})},Cs=n=>{const{steps:e,signInPath:s="/auth/sign-in",guestPath:t="/",onSkip:r,onSignIn:o,onStartAsGuest:a}=n,{setGuestMode:c}=xe(),{navigate:i}=X(),[m,u]=d.useState(1),f=d.useCallback(()=>{if(r){r();return}i(s)},[i,r,s]),h=d.useCallback(()=>{if(o){o();return}i(s)},[i,o,s]),g=d.useCallback(()=>{if(a){a();return}c(!0),i(t)},[t,i,a,c]),p=d.useMemo(()=>e.map((y,b)=>({id:b+1,label:"",content:l.jsx(Ze,{...y,final:b===e.length-1,onClickNext:()=>u(w=>w+1),onSkip:f,onStartAsGuest:g,onSignIn:h})})),[h,f,g,e]);return l.jsx("div",{className:"onboarding-main",children:l.jsx(Xe,{currentTab:m,onTabChange:y=>u(Number(y)),tabs:p,useLinks:!1})})},et=n=>{const{message:e,messageProps:s={className:"empty-message"},action:t,iconProps:r}=n;return l.jsxs("div",{className:"empty-container",children:[r&&l.jsx(U.FontAwesomeIcon,{...r}),l.jsx("p",{...s,children:e}),t&&l.jsx(C.Action,{showTooltips:!1,showText:!0,...t})]})};Object.defineProperty(exports,"Action",{enumerable:!0,get:()=>C.Action});Object.defineProperty(exports,"Actions",{enumerable:!0,get:()=>C.Actions});Object.defineProperty(exports,"ActionsDropdown",{enumerable:!0,get:()=>C.ActionsDropdown});Object.defineProperty(exports,"Button",{enumerable:!0,get:()=>C.Button});exports.APIClient=te;exports.AppIconButton=Q;exports.AuthClient=Me;exports.AuthContext=me;exports.AuthProvider=Kt;exports.BaseClient=kt;exports.ConfigProvider=Ht;exports.ConfirmationDialog=ft;exports.Dialog=le;exports.DialogActions=ue;exports.Drawer=Gt;exports.DrawerMenuContext=Te;exports.DrawerMenuProvider=Vt;exports.Empty=et;exports.Error=ls;exports.FormContainer=ut;exports.FormDialog=mt;exports.GlobalActions=B;exports.IManager=Tt;exports.IconButton=Q;exports.ImportDialog=yt;exports.IndexedDBClient=Et;exports.ManagerProvider=Ut;exports.Methods=F;exports.Navbar=hs;exports.NavbarContext=ve;exports.NavbarProvider=fs;exports.Notification=ys;exports.NotificationEnumType=I;exports.NotificationProvider=Pt;exports.Onboarding=Cs;exports.Page=ds;exports.ParagraphInput=lt;exports.PasswordInput=dt;exports.PrettyGrid=ms;exports.SplashScreen=ws;exports.Step=Ze;exports.SupabaseAuthProvider=qt;exports.SupabaseDataClient=jt;exports.SupabaseManagerContext=Se;exports.SupabaseManagerProvider=Qt;exports.Tab=Ye;exports.TabsLayout=Xe;exports.ToTop=cs;exports.buildQueryUrl=Fe;exports.createQueryClient=de;exports.enumToKeyValueArray=Rt;exports.formatForDatetimeLocal=Mt;exports.fromLocal=q;exports.getFormattedDateTime=It;exports.getShortFormattedDateTime=Ft;exports.isHttpError=ne;exports.isMac=_e;exports.isValidationError=se;exports.makeRequest=ce;exports.mapSupabaseSessionToSessionDto=we;exports.mapValidationErrors=_t;exports.parseQueries=Ce;exports.queryClient=Ot;exports.removeFromLocal=j;exports.toLocal=M;exports.useAuth=xe;exports.useAuthContext=Ke;exports.useConfig=X;exports.useConfirmationForm=ke;exports.useDeleteAction=Be;exports.useDeleteDialog=Zt;exports.useDialog=Ee;exports.useDrawerMenu=He;exports.useEditAction=Xt;exports.useEntityFormDialog=ss;exports.useExportAction=Ge;exports.useExportActionMutate=is;exports.useFormDialog=re;exports.useFormDialogLegacy=ts;exports.useImportAction=ze;exports.useImportDialog=as;exports.useManager=Ue;exports.useNavbar=Je;exports.useNotification=z;exports.usePostDialog=ns;exports.usePostForm=Yt;exports.usePutDialog=rs;exports.useRestoreAction=Ve;exports.useRestoreDialog=os;exports.useScrollTrigger=We;exports.useSupabase=qe;exports.useTimeAge=Jt;Object.keys(C).forEach(n=>{n!=="default"&&!Object.prototype.hasOwnProperty.call(exports,n)&&Object.defineProperty(exports,n,{enumerable:!0,get:()=>C[n]})});
|