@sito/dashboard-app 0.0.50 → 0.0.52

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 CHANGED
@@ -19,7 +19,7 @@ pnpm add @sito/dashboard-app
19
19
  - React DOM `18.3.1`
20
20
  - `@tanstack/react-query` `5.83.0`
21
21
  - `react-hook-form` `7.61.1`
22
- - `@sito/dashboard` `^0.0.68`
22
+ - `@sito/dashboard` `^0.0.71`
23
23
  - Font Awesome + Emotion peers defined in `package.json`
24
24
 
25
25
  Install all peers in consumer apps:
@@ -27,7 +27,7 @@ Install all peers in consumer apps:
27
27
  ```bash
28
28
  npm install \
29
29
  react@18.3.1 react-dom@18.3.1 \
30
- @sito/dashboard@^0.0.68 \
30
+ @sito/dashboard@^0.0.71 \
31
31
  @tanstack/react-query@5.83.0 \
32
32
  react-hook-form@7.61.1 \
33
33
  @fortawesome/fontawesome-svg-core@7.0.0 \
@@ -43,7 +43,7 @@ npm install \
43
43
  - Actions and menus: `Actions`, `Action`, `Dropdown`, button components
44
44
  - Dialogs and forms: `Dialog`, `FormDialog`, `ImportDialog`, form inputs
45
45
  - Feedback: `Notification`, `Loading`, `Empty`, `Error`, `Onboarding`
46
- - Hooks: `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
46
+ - 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
47
  - Providers and utilities: `ConfigProvider`, `ManagerProvider`, `AuthProvider`, `NotificationProvider`, `DrawerMenuProvider`, `NavbarProvider`, DTOs, API clients
48
48
 
49
49
  ## Component usage patterns
@@ -1 +1 @@
1
- var Ge=Object.defineProperty;var ze=(s,e,t)=>e in s?Ge(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var j=(s,e,t)=>ze(s,typeof e!="symbol"?e+"":e,t);var Jt=require("./main.css");Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("@sito/dashboard"),l=require("react/jsx-runtime"),F=require("@fortawesome/react-fontawesome"),m=require("react"),E=require("@fortawesome/free-solid-svg-icons"),Te=require("react-dom"),P=require("@tanstack/react-query"),Je=require("@fortawesome/free-regular-svg-icons"),ve=require("react-hook-form"),Ce=s=>s==null?!1:`${s}`.length>0,Ye=m.forwardRef(function(s,e){const{value:t,defaultValue:n,onChange:r,state:o=y.State.default,name:a="",id:c="",label:i="",disabled:u=!1,required:h=!1,containerClassName:d="",inputClassName:f="",labelClassName:p="",helperText:g="",helperTextClassName:w="",...b}=s,x=t!==void 0,[S,T]=m.useState(()=>Ce(n)),k=x?Ce(t):S,M=O=>{x||T(O.currentTarget.value.length>0),r==null||r(O)};return l.jsxs("div",{className:`form-paragraph-container group ${d}`,children:[l.jsx("textarea",{ref:e,name:a,id:c,className:`text-input text-area form-paragraph-textarea peer ${y.inputStateClassName(o)} ${k?"has-value":""} ${b.placeholder?"has-placeholder":""} ${f}`,required:h,defaultValue:n,...x?{value:t}:{},onChange:M,disabled:u,...b}),l.jsxs("label",{htmlFor:c,className:`text-input-label ${y.labelStateClassName(o)} ${p}`,children:[i,h?" *":""]}),!!g&&l.jsx("p",{className:`text-input-helper-text ${y.helperTextStateClassName(o)} ${w}`,children:g})]})}),Xe=s=>{const{t:e}=y.useTranslation(),{children:t,handleSubmit:n,onSubmit:r,isLoading:o=!1,buttonEnd:a=!0,reset:c}=s;return l.jsxs("form",{className:"form-container",onSubmit:n(r),children:[t,l.jsxs("div",{className:`form-actions ${a?"end":""}`,children:[l.jsxs(y.Button,{type:"submit",color:"primary",variant:"submit",disabled:o,name:e("_accessibility:buttons.submit"),"aria-label":e("_accessibility:ariaLabels.submit"),children:[o?l.jsx(y.Loading,{color:"stroke-base",loaderClass:"!w-6 mt-1",strokeWidth:"6"}):null,e("_accessibility:buttons.submit")]}),l.jsx(y.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")})]})]})},Ze=m.forwardRef(function(s,e){const{t}=y.useTranslation(),[n,r]=m.useState(!1);return l.jsx(y.TextInput,{...s,type:n?"text":"password",ref:e,children:l.jsx(D,{type:"button",tabIndex:-1,"aria-label":t(n?"_accessibility:ariaLabels.hidePassword":"_accessibility:ariaLabels.showPassword"),className:"password-icon",onClick:()=>r(!n),icon:n?E.faEyeSlash:E.faEye})})}),re=s=>{const{t:e}=y.useTranslation(),{title:t,children:n,handleClose:r,open:o=!1,containerClassName:a="",className:c="",animationClass:i="appear"}=s,u=m.useCallback(d=>{d.key==="Escape"&&o&&r()},[o,r]);m.useEffect(()=>(window.addEventListener("keydown",u),()=>{window.removeEventListener("keydown",u)}),[u]);const h=m.useCallback(d=>{d.target===d.currentTarget&&r()},[r]);return m.useEffect(()=>{const d=f=>{f?document.body.style.overflow="hidden":document.body.style.overflow="auto"};return d(o),()=>{d(!1)}},[o]),Te.createPortal(l.jsx("div",{"aria-label":e("_accessibility:ariaLabels.closeDialog"),"aria-hidden":!o,onClick:h,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:t}),l.jsx(D,{icon:E.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")})]}),n]})}),document.body)},oe=s=>{const{primaryText:e,cancelText:t,onPrimaryClick:n,onCancel:r,isLoading:o=!1,disabled:a=!1,primaryType:c="submit",containerClassName:i="",primaryClassName:u="",alignEnd:h=!1,primaryName:d,primaryAriaLabel:f,cancelName:p,cancelAriaLabel:g}=s;return l.jsxs("div",{className:`dialog-actions ${h?"end":""} ${i}`,children:[l.jsxs(y.Button,{type:c,color:"primary",variant:"submit",className:u,disabled:a,onClick:n,name:d,"aria-label":f,children:[o?l.jsx(y.Loading,{color:"stroke-base",loaderClass:"!w-6 mt-1",strokeWidth:"6"}):null,e]}),l.jsx(y.Button,{type:"button",variant:"outlined",disabled:a,onClick:r,name:p,"aria-label":g,children:t})]})},et=s=>{const{t:e}=y.useTranslation(),{children:t,handleSubmit:n,onSubmit:r,handleClose:o,isLoading:a=!1,buttonEnd:c=!0,...i}=s;return l.jsx(re,{...i,handleClose:o,children:l.jsxs("form",{onSubmit:n(r),children:[l.jsx("div",{className:"form-container",children:t}),l.jsx(oe,{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")})]})})},tt=s=>{const{t:e}=y.useTranslation(),{children:t,handleSubmit:n,handleClose:r,isLoading:o=!1,...a}=s;return l.jsxs(re,{...a,handleClose:r,children:[t,l.jsx(oe,{primaryText:e("_accessibility:buttons.ok"),cancelText:e("_accessibility:buttons.cancel"),onPrimaryClick:n,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")})]})};function st(s){const{message:e,className:t=""}=s,{t:n}=y.useTranslation();return l.jsx("p",{className:`import-error-message ${t}`,children:e??n("_messages:errors.parseFile",{defaultValue:"Failed to process file"})})}function nt(s){const{message:e,className:t=""}=s,{t:n}=y.useTranslation();return l.jsxs("div",{className:`import-loading ${t}`,children:[l.jsx(y.Loading,{loaderClass:"w-5 h-5",className:"!w-auto"}),l.jsx("span",{children:e??n("_messages:loading.processingFile",{defaultValue:"Processing file..."})})]})}function rt(s){const{items:e,max:t=5,className:n=""}=s,{t:r}=y.useTranslation();if(!e||e.length===0)return null;const o=e.slice(0,t);return l.jsxs("div",{className:`import-preview ${n}`,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 Ee=()=>({file:null,previewItems:null,parseError:null,processing:!1,overrideExisting:!1,inputKey:0});function ot(s,e){switch(e.type){case"SET_FILE":return{...s,file:e.file,previewItems:null,parseError:null,processing:!1};case"START_PROCESSING":return{...s,processing:!0};case"SET_PREVIEW":return{...s,previewItems:e.items,parseError:null,processing:!1};case"SET_ERROR":return{...s,previewItems:null,parseError:e.message,processing:!1};case"SET_OVERRIDE":return{...s,overrideExisting:e.value};case"RESET":return{...Ee(),inputKey:s.inputKey+1}}}const at=s=>{const{t:e}=y.useTranslation(),{children:t,handleSubmit:n,handleClose:r,isLoading:o=!1,fileProcessor:a,onFileProcessed:c,renderCustomPreview:i,onOverrideChange:u,open:h,...d}=s,[f,p]=m.useReducer(ot,Ee()),{file:g,previewItems:w,parseError:b,processing:x,overrideExisting:S,inputKey:T}=f,k=m.useRef(c),M=m.useRef(a);m.useEffect(()=>{k.current=c},[c]),m.useEffect(()=>{M.current=a},[a]),m.useEffect(()=>{h||p({type:"RESET"})},[h]);const O=m.useCallback(async($,C)=>{var L;if(M.current){p({type:"START_PROCESSING"});try{const v=await M.current($,{override:C});p({type:"SET_PREVIEW",items:v??[]}),(L=k.current)==null||L.call(k,v??[])}catch(v){console.error(v);const R=v instanceof Error?v.message:"Failed to parse file";p({type:"SET_ERROR",message:R})}}},[]);return l.jsxs(re,{...d,open:h,handleClose:r,children:[l.jsx(y.FileInput,{onClear:()=>{var $;p({type:"SET_FILE",file:null}),($=k.current)==null||$.call(k,[])},onChange:$=>{var L,v;const C=(L=$.target.files)==null?void 0:L[0];if(!C){p({type:"SET_FILE",file:null}),(v=k.current)==null||v.call(k,[]);return}p({type:"SET_FILE",file:C}),O(C,S)},label:e("_accessibility:labels.file")},T),l.jsxs("label",{className:"import-override-label",children:[l.jsx("input",{type:"checkbox",checked:S,onChange:$=>{const C=$.target.checked;p({type:"SET_OVERRIDE",value:C}),u==null||u(C),g&&O(g,C)}}),l.jsx("span",{children:e("_pages:common.actions.import.override",{defaultValue:"Override existing items"})})]}),l.jsx(st,{message:b}),x&&l.jsx(nt,{}),i?i(w):!!w&&w.length>0&&l.jsx(rt,{items:w}),t,l.jsx(oe,{primaryText:e("_accessibility:buttons.ok"),cancelText:e("_accessibility:buttons.cancel"),onPrimaryClick:()=>{(!a||!!w&&w.length>0)&&n()},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")})]})};var A=(s=>(s[s.success=0]="success",s[s.error=1]="error",s[s.warning=2]="warning",s[s.info=3]="info",s))(A||{}),I=(s=>(s.GET="GET",s.POST="POST",s.PUT="PUT",s.PATCH="PATCH",s.DELETE="DELETE",s))(I||{});const it=s=>Array.isArray(s)||s instanceof Headers?!1:typeof s=="object"&&s!==null&&("headers"in s||"credentials"in s),ct=s=>s?it(s)?s:{headers:s}:{},lt=s=>s?s instanceof Headers?Object.fromEntries(s.entries()):Array.isArray(s)?Object.fromEntries(s):s:{};async function ne(s,e="GET",t,n){const r=ct(n),o={...t!==void 0?{"Content-Type":"application/json"}:{},...lt(r.headers)};try{const a=await fetch(s,{method:e,headers:o,...r.credentials?{credentials:r.credentials}:{},...t!==void 0?{body:JSON.stringify(t)}:{}}),c=await a.text();let i=null;try{i=c?JSON.parse(c):null}catch{i=null}if(!a.ok){const u=typeof i=="object"&&i!==null?i.message??i.error??c:c||a.statusText;return{data:null,status:a.status,error:{status:a.status,message:u||"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 Ne(s,e){if(e){const t=Object.entries(e).filter(([,n])=>n!=null).map(([n,r])=>`${encodeURIComponent(n)}=${encodeURIComponent(String(r))}`).join("&");return t?`${s}?${t}`:s}return s}const le=(s,e,t)=>{const n=[];if(e){const{sortingBy:r,sortingOrder:o,currentPage:a,pageSize:c}=e;r!==void 0&&n.push(`sort=${String(r)}`),o!==void 0&&n.push(`order=${o}`),a!==void 0&&n.push(`page=${a}`),c!==void 0&&n.push(`pageSize=${c}`)}if(t){const r=Object.entries(t).filter(([,o])=>o!=null&&o!=="").flatMap(([o,a])=>{if(Array.isArray(a))return a.map(c=>`${o}==${encodeURIComponent((c==null?void 0:c.id)??c)}`);if(typeof a=="object"&&a!==null&&"start"in a&&"end"in a){const c=[];return a.start!=null&&a.start!==""&&c.push(`${o}>=${encodeURIComponent(a.start)}`),a.end!=null&&a.end!==""&&c.push(`${o}<=${encodeURIComponent(a.end)}`),c}return typeof a=="object"&&a!==null?`${o}==${encodeURIComponent(a.id??"")}`:`${o}==${encodeURIComponent(a)}`});r.length>0&&n.push(`filters=${r.join(",")}`)}return n.length?`${s}?${n.join("&")}`:s},z=class z{constructor(e,t="user",n=!0,r,o={}){j(this,"baseUrl");j(this,"userKey");j(this,"rememberKey");j(this,"refreshTokenKey");j(this,"accessTokenExpiresAtKey");j(this,"refreshEndpoint");j(this,"refreshExpirySkewMs");j(this,"secured");j(this,"tokenAcquirer");this.baseUrl=e,this.secured=n,this.userKey=t,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 t=B(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,n=e.startsWith("/")?e:`/${e}`;return`${t}${n}`}getRefreshToken(){const e=B(this.refreshTokenKey);if(typeof e=="string"&&e.length)return e}getAccessTokenExpiresAt(){const e=B(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 n=Date.parse(t);return Number.isNaN(n)?!1:Date.now()>=n-this.refreshExpirySkewMs}clearStoredSession(){_(this.userKey),_(this.rememberKey),_(this.refreshTokenKey),_(this.accessTokenExpiresAtKey)}storeSession(e,t){U(this.userKey,e.token);const n=e.refreshToken===void 0?t:e.refreshToken;typeof n=="string"&&n.length?U(this.refreshTokenKey,n):_(this.refreshTokenKey),typeof e.accessTokenExpiresAt=="string"&&e.accessTokenExpiresAt.length?U(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(),n=z.refreshInFlight.get(t);if(n){await n;return}const r=(async()=>{const{data:o,status:a,error:c}=await ne(this.buildUrl(this.refreshEndpoint),I.POST,{refreshToken:e});if(c||!(o!=null&&o.token))throw this.clearStoredSession(),c??{status:a,message:"Unable to refresh session"};this.storeSession(o,e)})();z.refreshInFlight.set(t,r);try{await r}finally{z.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,n=this.toRequestOptions(t),r=this.toRequestOptions(e),o={...this.toHeaderRecord(n.headers),...this.toHeaderRecord(r.headers)},a=r.credentials??n.credentials,c=Object.keys(o).length>0;if(a)return c?{headers:o,credentials:a}:{credentials:a};if(c)return o}async makeRequestWithRefresh(e,t,n,r){this.secured&&this.shouldRefreshBeforeRequest()&&await this.refreshAccessTokenWithMutex();let o=await ne(this.buildUrl(e),t,n,this.mergeRequestConfig(r));return this.secured&&o.status===401&&this.canRefresh()&&(await this.refreshAccessTokenWithMutex(),o=await ne(this.buildUrl(e),t,n,this.mergeRequestConfig(r))),o}async doQuery(e,t=I.GET,n,r){const{data:o,status:a,error:c}=await this.makeRequestWithRefresh(e,t,n,r);if(c||a<200||a>=300)throw c??{status:a,message:String(a)};return o}async get(e,t,n){const r=le(e,t,n),{data:o,error:a,status:c}=await this.makeRequestWithRefresh(r,I.GET);if(a||c<200||c>=300||!o)throw a??{status:c,message:String(c)};return o}async patch(e,t){const{error:n,data:r,status:o}=await this.makeRequestWithRefresh(e,I.PATCH,t);if(n||r===null||r===void 0)throw n??{status:o,message:"Unknown error"};return r}async delete(e,t){const{error:n,data:r,status:o}=await this.makeRequestWithRefresh(e,I.DELETE,t);if(n||r===null||r===void 0)throw n??{status:o,message:"Unknown error"};return r}async post(e,t){const{error:n,data:r,status:o}=await this.makeRequestWithRefresh(e,I.POST,t);if(n||r===null||r===void 0)throw n??{status:o,message:"Unknown error"};return r}};j(z,"refreshInFlight",new Map);let X=z;class je{constructor(e,t="user",n={}){j(this,"api");this.api=new X(e,t,!1,void 0,n)}async login(e){const t="auth/sign-in",n=e;return await this.api.doQuery(t,I.POST,n)}async refresh(e){return await this.api.doQuery("auth/refresh",I.POST,e)}async logout(e){const t="auth/sign-out",n=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,I.POST,r,n)}async register(e){return await this.api.doQuery("auth/sign-up",I.POST,e)}async getSession(){return await this.api.doQuery("auth/session",I.GET,void 0,this.api.defaultTokenAcquirer())}}class ut{constructor(e,t,n={}){j(this,"auth");this.auth=new je(e,t,n)}get Auth(){return this.auth}}class dt{constructor(e,t,n="user",r=!0,o={}){j(this,"table");j(this,"secured");j(this,"api");this.table=e,this.secured=r,this.api=new X(t,n,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`,I.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=le(`${this.table}/export`,void 0,e);return await this.api.doQuery(t,I.GET,void 0)}async import(e){return await this.api.doQuery(`${this.table}/import`,I.POST,e)}async commonGet(e){return await this.api.doQuery(Ne(`${this.table}/common`,e),I.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 mt{constructor(e,t,n=1){j(this,"table");j(this,"dbName");j(this,"version");j(this,"db",null);this.table=e,this.dbName=t,this.version=n}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 n=indexedDB.open(this.dbName,this.version);n.onupgradeneeded=r=>{const o=r.target.result;o.objectStoreNames.contains(this.table)||o.createObjectStore(this.table,{keyPath:"id",autoIncrement:!0})},n.onsuccess=r=>{this.db=r.target.result,this.db.onversionchange=()=>{this.close()},e(this.db)},n.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,n)=>{e.onsuccess=()=>t(e.result),e.onerror=()=>n(e.error)})}async insert(e){const t=await this.transaction("readwrite"),n=await this.request(t.add(e));return{...e,id:n}}async insertMany(e){const t=await this.transaction("readwrite");let n=0;for(const r of e)n=await this.request(t.add(r));return{...e[e.length-1],id:n}}async update(e,t){const n=typeof e=="number"?t:e;if(!n)throw new Error("IndexedDBClient.update requires a value payload");const r=typeof e=="number"?{...n,id:n.id??e}:n,o=await this.transaction("readwrite");return await this.request(o.put(r)),r}async get(e,t){var p;const n=await this.transaction("readonly"),r=await this.request(n.getAll()),o=this.applyFilter(r,t),a=(e==null?void 0:e.sortingBy)??"id",c=((p=e==null?void 0:e.sortingOrder)==null?void 0:p.toLowerCase())??"asc";o.sort((g,w)=>{const b=g[a],x=w[a];return b<x?c==="asc"?-1:1:b>x?c==="asc"?1:-1:0});const i=(e==null?void 0:e.pageSize)??10,u=(e==null?void 0:e.currentPage)??0,h=o.length,d=Math.ceil(h/i),f=o.slice(u*i,u*i+i);return{sort:a,order:c,currentPage:u,pageSize:i,totalElements:h,totalPages:d,items:f}}async export(e){const t=await this.transaction("readonly"),n=await this.request(t.getAll());return this.applyFilter(n,e)}async import(e){const t=await this.transaction("readwrite");let n=0;for(const r of e.items)e.override?await this.request(t.put(r)):await this.request(t.add(r)),n++;return n}async commonGet(e){const t=await this.transaction("readonly"),n=await this.request(t.getAll());return this.applyFilter(n,e)}async getById(e){const t=await this.transaction("readonly"),n=await this.request(t.get(e));if(!n)throw new Error(`Record ${e} not found in ${this.table}`);return n}async softDelete(e){const t=await this.transaction("readwrite");let n=0;for(const r of e){const o=await this.request(t.get(r));o&&(await this.request(t.put({...o,deletedAt:new Date})),n++)}return n}async restore(e){const t=await this.transaction("readwrite");let n=0;for(const r of e){const o=await this.request(t.get(r));o&&(await this.request(t.put({...o,deletedAt:null})),n++)}return n}applyFilter(e,t){return t?e.filter(n=>Object.entries(t).every(([r,o])=>this.matchesFilterValue(r,o,n[r]))):e}matchesFilterValue(e,t,n){if(t===void 0)return!0;if(e==="deletedAt"&&typeof t=="boolean"){const r=n!=null;return t?r:!r}return n===t}}function ht(s){return Object.keys(s).filter(e=>isNaN(Number(e))).map(e=>({key:e,value:s[e]}))}const B=(s,e="")=>{const t=localStorage.getItem(s)??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},U=(s,e)=>localStorage.setItem(s,typeof e=="object"?JSON.stringify(e):e),_=s=>localStorage.removeItem(s);function ft(s){const e=s?new Date(s):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 pt(s){const e=s?new Date(s):new Date,t=String(e.getDate()).padStart(2,"0"),n=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`${t}/${n}/${r} ${o}:${a}`}function gt(s){const e=s?new Date(s):new Date,t=e.getFullYear(),n=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`${t}-${n}-${r}T${o}:${a}`}const Ae=()=>{var t;const s=navigator,e=((t=s==null?void 0:s.userAgentData)==null?void 0:t.platform)||(s==null?void 0:s.platform)||"";return/Mac|iPhone|iPod|iPad/i.test(e)};function Z(s){if(!s||typeof s!="object")return!1;const e=s;return Array.isArray(e.errors)&&e.errors.every(t=>Array.isArray(t)&&t.length===2&&typeof t[0]=="string")}function ee(s){if(!s||typeof s!="object")return!1;const e=s;return typeof(e==null?void 0:e.status)=="number"&&typeof(e==null?void 0:e.message)=="string"}function bt(s,e){return s!=null&&s.errors?s.errors.map(([t,n])=>e(t,n)):[]}const $e=m.createContext(void 0);function yt(s){const{children:e}=s,t=m.useRef(0),[n,r]=m.useReducer((f,p)=>{const{type:g,items:w,id:b}=p;switch(g){case"set":return w??[];case"remove":return b!==void 0?f.filter(x=>x.id!==b):[]}return f},[],()=>[]),o=f=>f.map(p=>({...p,id:t.current++})),a=m.useCallback(f=>r({type:"set",items:o([{...f,type:A.error}])}),[]),c=m.useCallback(f=>r({type:"set",items:o([{...f}])}),[]),i=m.useCallback(f=>r({type:"set",items:o(f)}),[]),u=m.useCallback(f=>r({type:"set",items:o([{...f,type:A.success}])}),[]),h=f=>r({type:"remove",id:f}),d=m.useMemo(()=>({notification:n,removeNotification:h,showErrorNotification:a,showNotification:c,showSuccessNotification:u,showStackNotifications:i}),[n,a,c,i,u]);return l.jsx($e.Provider,{value:d,children:e})}const H=()=>{const s=m.useContext($e);if(!s)throw new Error("NotificationContext must be used within a Provider");return s},ue=()=>new P.QueryClient({defaultOptions:{queries:{refetchInterval:!1,refetchOnMount:!0,refetchOnReconnect:!1,retry:!1,retryOnMount:!0,refetchOnWindowFocus:!1}}}),wt=ue(),Le=m.createContext(void 0),xt=s=>{const{children:e,manager:t,queryClient:n}=s,[r]=m.useState(ue),o=n??r;return l.jsx(Le.Provider,{value:{client:t},children:l.jsx(P.QueryClientProvider,{client:o,children:e})})},Ie=()=>{const s=m.useContext(Le);if(!s)throw new Error("managerContext must be used within a Provider");return s.client},Re=m.createContext(void 0),Ct=s=>{const{children:e,guestMode:t="guest_mode",user:n="user",remember:r="remember",refreshTokenKey:o="refreshToken",accessTokenExpiresAtKey:a="accessTokenExpiresAt"}=s,c=Ie(),[i,u]=m.useState({}),h=m.useCallback(()=>{_(n),_(r),_(o),_(a)},[a,o,r,n]),d=m.useCallback(()=>!!B(t,"boolean")&&i.token===void 0,[i.token,t]),f=m.useCallback(x=>{U(t,x)},[t]),p=m.useCallback((x,S)=>{if(!x)return;const T=B(r,"boolean"),k=S??(typeof T=="boolean"?T:!1);u(x),_(t),U(n,x.token),U(r,k),typeof x.refreshToken=="string"&&x.refreshToken.length?U(o,x.refreshToken):_(o),typeof x.accessTokenExpiresAt=="string"&&x.accessTokenExpiresAt.length?U(a,x.accessTokenExpiresAt):_(a)},[a,t,o,r,n]),g=m.useCallback(async()=>{const x=B(n)??i.token,S=B(o)??(typeof i.refreshToken=="string"?i.refreshToken:void 0);try{await c.Auth.logout({accessToken:x,refreshToken:S})}catch(T){console.error(T)}u({}),h()},[i.refreshToken,i.token,h,c.Auth,o,n]),w=m.useCallback(async()=>{try{const x=await c.Auth.getSession();p(x)}catch(x){console.error(x),g()}},[p,g,c.Auth]),b=m.useMemo(()=>({account:i,logUser:p,logoutUser:g,logUserFromLocal:w,isInGuestMode:d,setGuestMode:f}),[i,p,g,w,d,f]);return l.jsx(Re.Provider,{value:b,children:e})},de=()=>{const s=m.useContext(Re);if(!s)throw new Error("authContext must be used within a Provider");return s},_e=m.createContext({}),kt=s=>{const{children:e,location:t,navigate:n,linkComponent:r,searchComponent:o}=s;return l.jsx(_e.Provider,{value:{location:t,navigate:n,linkComponent:r,searchComponent:o},children:e})},J=()=>{const s=m.useContext(_e);if(s===void 0||Object.keys(s).length===0)throw new Error("Config provider has not been set. This step is required and cannot be skipped.");return s},St={addChildItem:()=>{},removeChildItem:()=>{},clearDynamicItems:()=>{},dynamicItems:{}},me=m.createContext(St),Tt=s=>{const{children:e}=s,[t,n]=m.useState({}),r=m.useCallback((i,u)=>n(h=>({...h,[i]:[...h[i]??[],u]})),[]),o=m.useCallback((i,u)=>n(h=>({...h,[i]:(h[i]??[]).filter((d,f)=>f!==u)})),[]),a=m.useCallback(i=>{n(i?u=>({...u,[i]:[]}):{})},[]),c=m.useMemo(()=>({dynamicItems:t,addChildItem:r,removeChildItem:o,clearDynamicItems:a}),[t,a,o,r]);return l.jsx(me.Provider,{value:c,children:e})},Pe=()=>m.useContext(me);function vt(s){const{t:e}=y.useTranslation(),{open:t,onClose:n,menuMap:r,logo:o}=s,{account:a}=de(),{dynamicItems:c}=Pe(),{linkComponent:i,location:u}=J(),h=i,d=m.useMemo(()=>r.filter(b=>{const x=b.auth,S=!!(a!=null&&a.email);return x==null||x&&S||!x&&!S}),[a==null?void 0:a.email,r]),f=m.useCallback(b=>{b.key==="Escape"&&t&&n()},[n,t]);m.useEffect(()=>(document.addEventListener("keydown",f),()=>{document.removeEventListener("keydown",f)}),[f]);const p=m.useCallback((b,x)=>x?b===`${u.pathname}${u.search}`:b===u.pathname,[u.pathname,u.search]),g=m.useCallback(b=>l.jsx("li",{className:`drawer-list-item-child ${p(b.path,!0)?"active":""} animated`,children:b.path?l.jsx(h,{tabIndex:t?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),[h,t,e,p]),w=m.useMemo(()=>d.map((b,x)=>{const S=b.page??String(x),T=`drawer-list-item ${p(b.path)?"active":""} animated`;if(b.type==="divider")return l.jsx("li",{className:T,children:l.jsx("hr",{className:"drawer-divider"})},S);const k=b.children??(b.page&&c?c[b.page]:null);return l.jsxs("li",{className:T,children:[l.jsxs(h,{tabIndex:t?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(g)})]},S)}),[h,c,p,t,d,g,e]);return l.jsx("div",{"aria-label":e("_accessibility:ariaLabels.closeMenu"),"aria-disabled":!t,className:`${t?"opened":"closed"} drawer-backdrop`,onClick:()=>n(),children:l.jsxs("aside",{className:`${t?"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:w})]})})}const D=({icon:s,...e})=>l.jsx(y.IconButton,{icon:l.jsx(F.FontAwesomeIcon,{icon:s}),...e});var ie,ke;function Et(){if(ke)return ie;ke=1;const s=(c,i="local",u=void 0)=>{if(i==="local"){if(localStorage.getItem(c)!==void 0&&localStorage.getItem(c)!=="undefined"&&localStorage.getItem(c)!==null)return u===void 0||u!==void 0&&localStorage.getItem(c)===u}else if(i==="session"&&sessionStorage.getItem(c)!==void 0&&sessionStorage.getItem(c)!=="undefined"&&sessionStorage.getItem(c)!==null)return u===void 0||u!==void 0&&sessionStorage.getItem(c)===u;return!1},e=c=>{const i={};return c.substring(1).split("&").forEach(h=>{const[d,f]=h.split("=");i[d]=f}),i},t=(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"},n=(c=0,i=0,u=window,h="smooth")=>u.scroll({top:c,left:i,behavior:h}),r=(c,i,u,h="/",d="Lax")=>{var f=new Date;f.setTime(f.getTime()+i*24*60*60*1e3);const p="; expires="+f.toUTCString();document.cookie=`${c}=${u||""}${p};path=${h};SameSite=${d}`},o=c=>{const i=`${c}=`,h=decodeURIComponent(document.cookie).split(";");for(let d=0;d<h.length;d+=1){let f=h[d];for(;f.charAt(0)===" ";)f=f.substring(1);if(f.indexOf(i)===0)return f.substring(i.length,f.length)}return""};return ie={getCookie:o,createCookie:r,deleteCookie:c=>document.cookie=`${c}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`,getUserLanguage:t,scrollTo:n,parseQueries:e,validation:s},ie}var Nt=Et();function jt(){const{t:s,language:e}=y.useTranslation();return{timeAge:m.useCallback(n=>{const o=new Date-n,a=Math.floor(o/(1e3*60)),c=Math.floor(a/60),i=e==="es",u=s("_accessibility:labels.ago"),h=s("_accessibility:labels.minute"),d=s("_accessibility:labels.minutes"),f=s("_accessibility:labels.hour"),p=s("_accessibility:labels.hours"),g=s("_accessibility:labels.yesterday"),w=s("_accessibility:labels.justNow");return o<1e3*60?w:a<60?`${i?u:""} ${a} ${a===1?h:d} ${i?"":u}`:c<24?`${i?u:""} ${c} ${c===1?f:p} ${i?"":u}`:c<48?g:n.toLocaleDateString(navigator.language||"es-ES",{day:"2-digit",month:"2-digit",year:"numeric"})},[s,e])}}const he=s=>{const{showSuccessNotification:e}=H(),{mutationFn:t,onError:n,onSuccess:r,onSuccessMessage:o}=s,[a,c]=m.useState([]),{open:i,handleClose:u,handleOpen:h}=fe(),d=()=>{u(),c([])},f=async g=>{c(g),h()},p=P.useMutation({mutationFn:()=>t(Array.isArray(a)?a:[a]),onError:g=>{console.error(g),n&&n(g),d()},onSuccess:async g=>{r&&r(g),e({message:o}),d()}});return{open:i,onClick:f,close:d,dialogFn:p,isLoading:p.isPending}},At=s=>{const{t:e}=y.useTranslation(),{showStackNotifications:t,showSuccessNotification:n,showErrorNotification:r}=H(),o=P.useQueryClient(),{defaultValues:a,mutationFn:c,formToDto:i,onError:u,onSuccess:h,queryKey:d,onSuccessMessage:f}=s,{control:p,handleSubmit:g,reset:w,setError:b,getValues:x,setValue:S}=ve.useForm({defaultValues:a}),T=m.useRef(null),k=m.useCallback(()=>{const C=document.activeElement;if(!(C instanceof HTMLElement)){T.current=null;return}T.current=C.closest("form")},[]),M=m.useCallback(C=>{const L=C==null?void 0:C.errors,v=[],R=T.current;if(!R)return v;let te=!1;return L&&L.forEach(([W,ae])=>{const V=R.querySelector(`[name="${W}"]`);(V instanceof HTMLInputElement||V instanceof HTMLTextAreaElement||V instanceof HTMLSelectElement)&&(te||(V.focus(),te=!0),V.classList.add("error"),v.push(e(`_entities:${d}.${W}.${ae}`)))}),v},[e,d]),O=m.useCallback(()=>{const C=T.current;if(!C)return;C.querySelectorAll("input, textarea, select").forEach(v=>{v.classList.remove("error")})},[]),$=P.useMutation({mutationFn:c,onError:C=>{console.error(C);const L=C;if(u)u(C);else if(Z(L)){const v=M(L);t(v.map(R=>({message:R,type:A.error})))}else if(ee(L)){const v=L.message||e("_accessibility:errors.500"),R=e(`_accessibility:errors.${L.status}`);r({message:R||v})}else r({message:e("_accessibility:errors.500")})},onSuccess:async C=>{await o.invalidateQueries({queryKey:d}),h&&h(C),f&&n({message:f})}});return{control:p,getValues:x,setValue:S,handleSubmit:g,onSubmit:C=>{k(),O(),$.mutate(i?i(C):C)},reset:w,setError:b,isLoading:$.isPending}},Me=s=>{const{t:e}=y.useTranslation(),{onClick:t,icon:n=E.faTrash,sticky:r=!0,hidden:o=!1,multiple:a=!0,disabled:c=!1,id:i=Q.Delete,tooltip:u=e("_pages:common.actions.delete.text")}=s;return{action:m.useCallback(d=>({id:i,sticky:r,tooltip:u,multiple:a,onClick:()=>t([d==null?void 0:d.id]),hidden:!!d.deletedAt||o,disabled:!!d.deletedAt||c,icon:l.jsx(F.FontAwesomeIcon,{className:"text-bg-error",icon:n}),onMultipleClick:f=>t(f.map(p=>p.id))}),[c,o,n,i,a,t,r,u])}},Fe=s=>{const{t:e}=y.useTranslation(),{onClick:t,sticky:n=!0,hidden:r=!1,disabled:o=!1,multiple:a=!1,icon:c=E.faRotateLeft,id:i=Q.Restore,tooltip:u=e("_pages:common.actions.restore.text")}=s;return{action:m.useCallback(d=>({id:i,sticky:n,tooltip:u,multiple:a,onClick:()=>t([d==null?void 0:d.id]),hidden:!d.deletedAt||r,disabled:!d.deletedAt||o,icon:l.jsx(F.FontAwesomeIcon,{className:"text-bg-error",icon:c}),onMultipleClick:f=>t(f.map(p=>p.id))}),[o,r,c,i,a,t,n,u])}},$t=s=>{const{t:e}=y.useTranslation(),{onClick:t,hidden:n=!1,sticky:r=!0,disabled:o=!1,id:a=Q.Edit,icon:c=E.faPencil,tooltip:i=e("_pages:common.actions.edit.text")}=s;return{action:m.useCallback(h=>({id:a,sticky:r,tooltip:i,onClick:()=>t(h==null?void 0:h.id),hidden:!!h.deletedAt||n,disabled:!!h.deletedAt||o,icon:l.jsx(F.FontAwesomeIcon,{className:"primary",icon:c})}),[o,n,c,a,t,r,i])}};var Q=(s=>(s.Add="add",s.Edit="edit",s.Delete="delete",s.Restore="restore",s.Refresh="refresh",s.Export="export",s.Import="import",s))(Q||{});const De=s=>{const{t:e}=y.useTranslation(),{onClick:t,hidden:n=!1,disabled:r=!1,isLoading:o=!1}=s;return{action:m.useCallback(()=>({id:Q.Export,hidden:n,disabled:r,icon:l.jsx(F.FontAwesomeIcon,{className:`${o?"rotate":""}`,icon:o?E.faCircleNotch:E.faCloudArrowDown}),tooltip:e("_pages:common.actions.export.text"),onClick:t}),[r,n,o,t,e])}},Oe=s=>{const{t:e}=y.useTranslation(),{onClick:t,hidden:n=!1,disabled:r=!1,isLoading:o=!1}=s;return{action:m.useCallback(()=>({id:Q.Import,hidden:n,disabled:r,icon:l.jsx(F.FontAwesomeIcon,{className:`${o?"rotate":""}`,icon:o?E.faCircleNotch:E.faCloudUpload}),tooltip:e("_pages:common.actions.import.text"),onClick:t}),[r,n,o,t,e])}},Lt=s=>{const{queryKey:e,onSuccess:t,...n}=s,r=P.useQueryClient(),{showStackNotifications:o}=H(),{t:a}=y.useTranslation(),{open:c,onClick:i,close:u,dialogFn:h,isLoading:d}=he({onSuccessMessage:a("_pages:common.actions.delete.successMessage"),onError:p=>{const g=p;if(Z(g))o(g.errors.map(([w,b])=>({message:a(`_pages:${w}.errors.${b}`),type:A.error})));else if(ee(g)){const w=g.message||a("_accessibility:errors.500"),b=a(`_accessibility:errors.${g.status}`);o([{message:b||w,type:A.error}])}},onSuccess:async p=>{await r.invalidateQueries({queryKey:e}),t&&t(p)},...n}),{action:f}=Me({onClick:i});return{onClick:i,title:a("_pages:common.actions.delete.dialog.title"),open:c,isLoading:d,handleSubmit:()=>h.mutate(),handleClose:u,action:f}},fe=()=>{const[s,e]=m.useState(!1);return{open:s,setOpen:e,handleClose:()=>e(!1),handleOpen:()=>e(!0)}},It=s=>{const{t:e}=y.useTranslation(),t=P.useQueryClient(),{showErrorNotification:n,showStackNotifications:r,showSuccessNotification:o}=H(),{defaultValues:a,getFunction:c,mutationFn:i,formToDto:u,dtoToForm:h,onError:d,onSuccess:f,queryKey:p,onSuccessMessage:g,title:w}=s,[b,x]=m.useState(0),{open:S,handleClose:T,handleOpen:k}=fe(),{control:M,handleSubmit:O,reset:$,setError:C,getValues:L,setValue:v}=ve.useForm({defaultValues:a}),R=m.useRef(null),te=m.useCallback(()=>{const N=document.activeElement;if(!(N instanceof HTMLElement)){R.current=null;return}R.current=N.closest("form")},[]),{data:W,isLoading:ae}=P.useQuery({queryFn:()=>c==null?void 0:c(b),queryKey:[...p,b],enabled:!!c&&!!p&&!!b});m.useEffect(()=>{W&&h&&$({...h(W)})},[W]);const V=m.useCallback(N=>{const q=N==null?void 0:N.errors,K=[],G=R.current;if(!G)return K;let we=!1;return q&&q.forEach(([xe,We])=>{const Y=G.querySelector(`[name="${xe}"]`);(Y instanceof HTMLInputElement||Y instanceof HTMLTextAreaElement||Y instanceof HTMLSelectElement)&&(we||(Y.focus(),we=!0),Y.classList.add("error"),K.push(e(`_entities:${p}.${xe}.${We}`)))}),K},[e,p]),ge=m.useCallback(()=>{const N=R.current;if(!N)return;N.querySelectorAll("input, textarea, select").forEach(K=>{K.classList.remove("error")})},[]),Ve=m.useCallback(N=>{x(N??0),k()},[k]),be=m.useCallback(()=>{ge(),R.current=null,T(),$()},[$,ge,T]),ye=P.useMutation({mutationFn:i,onError:N=>{if(console.error(N),d)d(N);else{const q=N;if(Z(q)){const K=V(q);r(K.map(G=>({message:G,type:A.error})))}else if(ee(q)){const K=q.message||e("_accessibility:errors.500"),G=e(`_accessibility:errors.${q.status}`);n({message:G||K})}else n({message:e("_accessibility:errors.500")})}},onSuccess:async N=>{await t.invalidateQueries({queryKey:p}),f&&f(N),o({message:g}),be()}});return{open:S,openDialog:Ve,handleClose:be,control:M,getValues:L,setValue:v,handleSubmit:O,onSubmit:N=>{te(),ye.mutate(u?u(N):N)},reset:$,setError:C,title:w,isLoading:ae||ye.isPending}},Rt=s=>{const{queryKey:e,onSuccess:t,...n}=s,r=P.useQueryClient(),{showStackNotifications:o}=H(),{t:a}=y.useTranslation(),{open:c,onClick:i,close:u,dialogFn:h,isLoading:d}=he({onSuccessMessage:a("_pages:common.actions.restore.successMessage"),onError:p=>{const g=p;if(Z(g))o(g.errors.map(([w,b])=>({message:a(`_pages:${w}.errors.${b}`),type:A.error})));else if(ee(g)){const w=g.message||a("_accessibility:errors.500"),b=a(`_accessibility:errors.${g.status}`);o([{message:b||w,type:A.error}])}},onSuccess:async p=>{await r.invalidateQueries({queryKey:e}),t&&t(p)},...n}),{action:f}=Fe({onClick:i});return{onClick:i,title:a("_pages:common.actions.restore.dialog.title"),open:c,isLoading:d,handleSubmit:()=>h.mutate(),handleClose:u,action:f}};function _t(s){const{t:e}=y.useTranslation(),t=P.useQueryClient(),{queryKey:n,mutationFn:r,entity:o,fileProcessor:a,renderCustomPreview:c,onError:i}=s,[u,h]=m.useState(!1),[d,f]=m.useState(null),[p,g]=m.useState(!1),w=P.useMutation({mutationFn:r,onError:x=>{console.error(x),i==null||i(x)},onSuccess:async()=>{await t.invalidateQueries({queryKey:n})}}),{action:b}=Oe({onClick:()=>h(!0)});return{handleSubmit:async()=>{if(!(!d||d.length===0))try{await w.mutateAsync({items:d,override:p}),h(!1),f(null),g(!1)}catch(x){console.error(x)}},isLoading:w.isPending,fileProcessor:a,onFileProcessed:x=>f(x),renderCustomPreview:c,onOverrideChange:x=>g(x),open:u,title:e("_pages:common.actions.import.dialog.title",{entity:e(`_pages:${o}.title`)}),handleClose:()=>{h(!1),f(null),g(!1)},action:b}}const Pt=s=>{const{showSuccessNotification:e}=H(),{t}=y.useTranslation(),{entity:n,mutationFn:r,onError:o,onSuccess:a,onSuccessMessage:c=t("_pages:common.actions.export.successMessage")}=s,i=P.useMutation({mutationFn:()=>r(),onError:d=>{console.error(d),o&&o(d)},onSuccess:async d=>{const f=JSON.stringify(d,null,2),p=new Blob([f],{type:"application/json"}),g=URL.createObjectURL(p),w=document.createElement("a");w.href=g,w.download=`${n}.json`,w.click(),URL.revokeObjectURL(g),a&&a(d),e({message:c})}}),u=m.useCallback(()=>{i.mutate()},[i]),{action:h}=De({onClick:u,isLoading:i.isPending});return{action:h}},Se=()=>typeof window<"u"?window.scrollY:0;function qe(s){const[e,t]=m.useState(Se),n=m.useCallback(()=>{t(Se())},[]);return m.useEffect(()=>(window.addEventListener("scroll",n),()=>{window.removeEventListener("scroll",n)}),[n]),e>s}const Mt=s=>{const{t:e}=y.useTranslation(),{icon:t=E.faArrowUp,threshold:n=200,scrollTop:r=0,scrollLeft:o=0,tooltip:a=e("_accessibility:buttons.toTop"),scrollOnClick:c=!0,onClick:i,className:u="",variant:h="submit",color:d="primary",...f}=s,p=qe(n),g=()=>{i==null||i(),c&&Nt.scrollTo(o,r)};return l.jsx(D,{variant:h,color:d,icon:t,"data-tooltip-id":"tooltip",onClick:g,className:`to-top ${p?"show":"hide"} ${u}`.trim(),"data-tooltip-content":a,...f})};function Ft(s){const{t:e}=y.useTranslation();if("children"in s){const{children:k,className:M}=s;return l.jsx("div",{className:`error-container${M?` ${M}`:""}`,children:k})}const{error:n,message:r,iconProps:o,onRetry:a,retryLabel:c,retryButtonProps:i,messageProps:u,className:h,resetErrorBoundary:d}=s,f=a??d,{className:p,children:g,onClick:w,...b}=i??{},{className:x,...S}=u??{},T=o!==null;return l.jsxs("div",{className:`error-container${h?` ${h}`:""}`,children:[T&&l.jsx(F.FontAwesomeIcon,{...o,icon:(o==null?void 0:o.icon)??Je.faSadTear,className:`error-icon${o!=null&&o.className?` ${o.className}`:""}`}),l.jsx("p",{...S,className:`error-message${x?` ${x}`:""}`,children:r??(n==null?void 0:n.message)??e("_accessibility:errors.unknownError")}),f&&l.jsx(y.Button,{type:"button",variant:"submit",color:"primary",...b,className:`error-retry ${p?` ${p}`:""}`,onClick:k=>{w==null||w(k),k.defaultPrevented||f()},children:g??c??e("_accessibility:actions.retry",{defaultValue:"Retry"})})]})}const Dt=s=>{const{showBackButton:e,title:t,actions:n}=s,{t:r}=y.useTranslation(),{navigate:o}=J();return l.jsxs("div",{className:"page-header",children:[l.jsxs("div",{className:"page-header-left",children:[e&&l.jsx(D,{icon:E.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:t})]}),l.jsxs("div",{children:[l.jsx(y.Actions,{className:"page-header-actions-desktop",actions:n??[]}),l.jsx(y.ActionsDropdown,{className:"page-header-actions-mobile",actions:n??[]})]})]})},Ot=s=>{const{title:e,children:t,addOptions:n,filterOptions:r,actions:o,queryKey:a,isLoading:c=!1,isAnimated:i=!0,showBackButton:u=!1}=s,{t:h}=y.useTranslation(),d=P.useQueryClient(),{countOfFilters:f}=y.useTableOptions(),p=m.useMemo(()=>{const g=Array.isArray(o)?[...o]:[];if(a){const w={id:Q.Refresh,onClick:()=>d.invalidateQueries({queryKey:a}),icon:l.jsx(F.FontAwesomeIcon,{icon:E.faRotateLeft}),tooltip:h("_pages:common.actions.refresh.text")};g.unshift(w)}if(n){const w={...n,id:Q.Add,icon:l.jsx(F.FontAwesomeIcon,{icon:E.faAdd})};g.unshift(w)}if(r){const w={...r,id:"filter",icon:l.jsx(F.FontAwesomeIcon,{icon:E.faFilter}),children:l.jsx(y.Badge,{className:`${f>0?"show":"hide"} `,count:f})};g.push(w)}return g},[o,n,f,r,d,a,h]);return l.jsxs("main",{className:"page-main",children:[l.jsx(Dt,{showBackButton:u,actions:p,title:e}),l.jsx("div",{className:`page-main-content ${i?"appear":""}`,children:c?l.jsx(y.Loading,{className:"page-loading"}):t}),n&&l.jsx(D,{icon:n.icon??E.faAdd,color:n.color??"primary",variant:n.variant??"submit",onClick:()=>{var g;return(g=n.onClick)==null?void 0:g.call(n)},className:`button fab ${n.className??""}`})]})},qt=s=>{const{t:e}=y.useTranslation(),{className:t="",itemClassName:n="",loading:r=!1,emptyComponent:o=null,emptyMessage:a=e("_accessibility:messages.empty"),renderComponent:c,data:i=[],hasMore:u=!1,loadingMore:h=!1,onLoadMore:d,loadMoreComponent:f=null,observerRootMargin:p="0px 0px 200px 0px",observerThreshold:g=0}=s,w=m.useRef(!1),b=m.useRef(null),x=m.useCallback(async()=>{if(!(!u||!d)&&!(h||w.current)){w.current=!0;try{await d()}finally{w.current=!1}}},[u,h,d]);return m.useEffect(()=>{if(!u||!d||!b.current||typeof IntersectionObserver>"u")return;const S=new IntersectionObserver(T=>{T.some(k=>k.isIntersecting)&&x()},{rootMargin:p,threshold:g});return S.observe(b.current),()=>S.disconnect()},[u,d,p,g,x]),r?l.jsx(y.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(S=>l.jsx("li",{className:`pretty-grid-item ${n}`,children:c(S)},S.id)),u&&d&&l.jsx("li",{className:"pretty-grid-load-more",ref:b,children:f})]}):l.jsx(l.Fragment,{children:o||l.jsx(He,{message:a})})})},pe=m.createContext({title:"",setTitle:()=>{},rightContent:null,setRightContent:()=>{}}),Kt=s=>{const{children:e}=s,[t,n]=m.useState(""),[r,o]=m.useState(null),a=m.useCallback(u=>{n(u)},[]),c=m.useCallback(u=>{o(u)},[]),i=m.useMemo(()=>({title:t,setTitle:a,rightContent:r,setRightContent:c}),[t,a,r,c]);return l.jsx(pe.Provider,{value:i,children:e})},Ke=()=>m.useContext(pe);function Ut(s){const{t:e}=y.useTranslation(),{openDrawer:t,showSearch:n=!0,menuButtonProps:r}=s,{searchComponent:o,location:a}=J(),{title:c,rightContent:i}=Ke(),[u,h]=m.useState(!1),d=m.useCallback(g=>{(Ae()?g.metaKey:g.ctrlKey)&&g.shiftKey&&g.key.toLowerCase()==="f"&&(h(!0),g.preventDefault())},[]);m.useEffect(()=>(window.addEventListener("keydown",d),()=>{window.removeEventListener("keydown",d)}),[d]);const f=o,p=n&&!!f;return l.jsxs(l.Fragment,{children:[a.pathname!=="/"&&!!f&&l.jsx(f,{open:u,onClose:()=>h(!1)}),l.jsxs("header",{id:"header",className:"header",children:[l.jsxs("div",{className:"navbar-left",children:[l.jsx(D,{...r,type:(r==null?void 0:r.type)??"button",icon:(r==null?void 0:r.icon)??E.faBars,onClick:g=>{var w;(w=r==null?void 0:r.onClick)==null||w.call(r,g),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,p&&l.jsx(D,{icon:E.faSearch,className:"navbar-search-btn",onClick:()=>h(!0)})]})]})]})}const se=300,Qt=s=>s??A.error,Bt=s=>{switch(s){case A.error:return E.faWarning;default:return E.faCircleCheck}},ce=s=>{switch(s){case A.success:return"!text-success";case A.error:return"!text-error";case A.warning:return"!text-warning";default:return"!text-info"}},Ht=s=>{switch(s){case A.success:return"bg-bg-success";case A.error:return"bg-bg-error";case A.warning:return"bg-bg-warning";default:return"bg-bg-info"}};function Vt(){const{t:s}=y.useTranslation(),{notification:e,removeNotification:t}=H(),[n,r]=m.useState([]),o=m.useRef(n);m.useLayoutEffect(()=>{o.current=n});const a=m.useRef(null),c=m.useCallback(i=>{r(u=>i!==void 0?u.map(h=>h.id===i?{...h,closing:!0}:h):u.map(h=>({...h,closing:!0}))),i!==void 0?setTimeout(()=>{t(i),r(u=>u.filter(h=>h.id!==i))},se):(a.current&&clearTimeout(a.current),a.current=setTimeout(()=>{t(),r([]),a.current=null},se))},[t]);return m.useEffect(()=>{let i=null;const u=()=>{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(p=>p.map(g=>({...g,closing:!0}))),i=null},0),a.current=setTimeout(()=>{r([]),a.current=null},se),u);const h=new Set(o.current.map(p=>p.id));if(!e.some(p=>p.id!==void 0&&!h.has(p.id)))return;if(o.current.length===0){const p=[...e];return i=setTimeout(()=>{r(p.map(g=>({...g,closing:!1}))),i=null},0),()=>{i&&clearTimeout(i)}}a.current&&clearTimeout(a.current),i=setTimeout(()=>{r(p=>p.every(g=>g.closing)?p:p.map(g=>({...g,closing:!0}))),i=null},0);const f=[...e];return a.current=setTimeout(()=>{r(f.map(p=>({...p,closing:!1}))),a.current=null},se),u},[e]),m.useEffect(()=>{if(!n.length)return;let i;const u=window.setTimeout(()=>{i=()=>c(),window.addEventListener("click",i)},0),h=d=>{d.key==="Escape"&&c()};return window.addEventListener("keydown",h),()=>{window.clearTimeout(u),i&&window.removeEventListener("click",i),window.removeEventListener("keydown",h)}},[n.length,c]),Te.createPortal(l.jsx("div",{className:`notification-portal ${n.length?"active":""}`,children:n.map(({id:i,type:u,message:h,closing:d})=>{const f=Qt(u);return l.jsxs("div",{className:`notification ${d?"closing":""} ${Ht(f)}`,onClick:p=>p.stopPropagation(),children:[l.jsxs("div",{className:"notification-body",children:[l.jsx(F.FontAwesomeIcon,{icon:Bt(f),className:`notification-icon ${ce(f)}`}),l.jsx("p",{className:`notification-text ${ce(f)}`,children:h})]}),l.jsx(D,{type:"button",icon:E.faClose,color:"error",className:"notification-close group",onClick:p=>{p.stopPropagation(),i!==void 0&&c(i)},iconClassName:`${ce(f)} notification-close-icon`,name:s("_accessibility:buttons.closeNotification"),"aria-label":s("_accessibility:ariaLabels.closeNotification")})]},i)})}),document.body)}function Wt(s){const{className:e,...t}=s;return l.jsx("div",{className:"splash-screen",children:l.jsx(y.Loading,{className:`blur-appear ${e?` ${e}`:""}`,...t})})}const Ue=s=>{const{id:e,active:t,onClick:n,children:r,to:o,useLinks:a=!0,tabButtonProps:c}=s,{linkComponent:i}=J(),u=i;if(!a){const{className:d="",variant:f=t?"submit":"outlined",color:p=t?"primary":"default",...g}=c??{};return l.jsx(y.Button,{type:"button",variant:f,color:p,className:`tab ${d}`,onClick:n,...g,children:r})}const h=`button submit tab ${t?"primary":"outlined"} ${(c==null?void 0:c.className)??""}`.trim();return l.jsx(u,{to:o??`#${e}`,onClick:()=>n(),className:h,children:r})},Qe=s=>{var p;const{tabs:e=[],defaultTab:t,currentTab:n,onTabChange:r,className:o="",tabsContainerClassName:a="",useLinks:c=!0,tabButtonProps:i}=s,[u,h]=m.useState(t??((p=e[0])==null?void 0:p.id)),d=n??u,f=m.useMemo(()=>e.find(g=>g.id===d),[e,d]);return l.jsxs("div",{className:`tabs-layout-main ${o}`,children:[l.jsx("ul",{className:`horizontal tabs tabs-container ${a}`,children:e.map(({id:g,to:w,label:b})=>l.jsx("li",{children:l.jsx(Ue,{onClick:()=>{n===void 0&&h(g),r==null||r(g)},id:g,to:w,siblings:e.length>1,active:d===g,useLinks:c,tabButtonProps:i,children:b})},g))}),f==null?void 0:f.content]})},Be=s=>{const{title:e,body:t,content:n,onClickNext:r,onSkip:o,onStartAsGuest:a,onSignIn:c,image:i="",alt:u="",final:h=!1}=s,{t:d}=y.useTranslation();return l.jsxs("div",{className:"big-appear step-container",children:[i&&l.jsx("img",{src:i,alt:u}),e!=null&&l.jsx("h2",{className:"step-title",children:e}),t!=null&&l.jsx("div",{className:"step-body",children:t}),n!=null&&l.jsx("div",{className:"step-content",children:n}),l.jsx("div",{className:"step-actions",children:h?l.jsxs(l.Fragment,{children:[l.jsx(y.Button,{color:"primary",className:"step-button",variant:"outlined",onClick:a,"aria-label":d("_accessibility:ariaLabels.start"),children:d("_accessibility:buttons.startAsGuest")}),l.jsx(y.Button,{color:"primary",variant:"submit",className:"step-button","aria-label":d("_accessibility:ariaLabels.start"),onClick:c,children:d("_accessibility:buttons.signIn")})]}):l.jsxs(l.Fragment,{children:[l.jsx(y.Button,{color:"primary",className:"step-button",variant:"outlined",onClick:o,"aria-label":d("_accessibility:ariaLabels.skip"),children:d("_accessibility:buttons.skip")}),l.jsx(y.Button,{color:"primary",className:"step-button",variant:"outlined",onClick:()=>r(),"aria-label":d("_accessibility:ariaLabels.next"),children:d("_accessibility:buttons.next")})]})})]})},Gt=s=>{const{steps:e,signInPath:t="/auth/sign-in",guestPath:n="/",onSkip:r,onSignIn:o,onStartAsGuest:a}=s,{setGuestMode:c}=de(),{navigate:i}=J(),[u,h]=m.useState(1),d=m.useCallback(()=>{if(r){r();return}i(t)},[i,r,t]),f=m.useCallback(()=>{if(o){o();return}i(t)},[i,o,t]),p=m.useCallback(()=>{if(a){a();return}c(!0),i(n)},[n,i,a,c]),g=m.useMemo(()=>e.map((w,b)=>({id:b+1,label:"",content:l.jsx(Be,{...w,final:b===e.length-1,onClickNext:()=>h(x=>x+1),onSkip:d,onStartAsGuest:p,onSignIn:f})})),[f,d,p,e]);return l.jsx("div",{className:"onboarding-main",children:l.jsx(Qe,{currentTab:u,onTabChange:w=>h(Number(w)),tabs:g,useLinks:!1})})},He=s=>{const{message:e,messageProps:t={className:"empty-message"},action:n,iconProps:r}=s;return l.jsxs("div",{className:"empty-container",children:[r&&l.jsx(F.FontAwesomeIcon,{...r}),l.jsx("p",{...t,children:e}),n&&l.jsx(y.Action,{showTooltips:!1,showText:!0,...n})]})};Object.defineProperty(exports,"Action",{enumerable:!0,get:()=>y.Action});Object.defineProperty(exports,"Actions",{enumerable:!0,get:()=>y.Actions});Object.defineProperty(exports,"ActionsDropdown",{enumerable:!0,get:()=>y.ActionsDropdown});Object.defineProperty(exports,"Button",{enumerable:!0,get:()=>y.Button});exports.APIClient=X;exports.AppIconButton=D;exports.AuthClient=je;exports.AuthProvider=Ct;exports.BaseClient=dt;exports.ConfigProvider=kt;exports.ConfirmationDialog=tt;exports.Dialog=re;exports.DialogActions=oe;exports.Drawer=vt;exports.DrawerMenuContext=me;exports.DrawerMenuProvider=Tt;exports.Empty=He;exports.Error=Ft;exports.FormContainer=Xe;exports.FormDialog=et;exports.GlobalActions=Q;exports.IManager=ut;exports.IconButton=D;exports.ImportDialog=at;exports.IndexedDBClient=mt;exports.ManagerProvider=xt;exports.Methods=I;exports.Navbar=Ut;exports.NavbarContext=pe;exports.NavbarProvider=Kt;exports.Notification=Vt;exports.NotificationEnumType=A;exports.NotificationProvider=yt;exports.Onboarding=Gt;exports.Page=Ot;exports.ParagraphInput=Ye;exports.PasswordInput=Ze;exports.PrettyGrid=qt;exports.SplashScreen=Wt;exports.Step=Be;exports.Tab=Ue;exports.TabsLayout=Qe;exports.ToTop=Mt;exports.buildQueryUrl=Ne;exports.createQueryClient=ue;exports.enumToKeyValueArray=ht;exports.formatForDatetimeLocal=gt;exports.fromLocal=B;exports.getFormattedDateTime=ft;exports.getShortFormattedDateTime=pt;exports.isHttpError=ee;exports.isMac=Ae;exports.isValidationError=Z;exports.makeRequest=ne;exports.mapValidationErrors=bt;exports.parseQueries=le;exports.queryClient=wt;exports.removeFromLocal=_;exports.toLocal=U;exports.useAuth=de;exports.useConfig=J;exports.useConfirmationForm=he;exports.useDeleteAction=Me;exports.useDeleteDialog=Lt;exports.useDialog=fe;exports.useDrawerMenu=Pe;exports.useEditAction=$t;exports.useExportAction=De;exports.useExportActionMutate=Pt;exports.useFormDialog=It;exports.useImportAction=Oe;exports.useImportDialog=_t;exports.useManager=Ie;exports.useNavbar=Ke;exports.useNotification=H;exports.usePostForm=At;exports.useRestoreAction=Fe;exports.useRestoreDialog=Rt;exports.useScrollTrigger=qe;exports.useTimeAge=jt;Object.keys(y).forEach(s=>{s!=="default"&&!Object.prototype.hasOwnProperty.call(exports,s)&&Object.defineProperty(exports,s,{enumerable:!0,get:()=>y[s]})});
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 $=(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"),A=require("@fortawesome/free-solid-svg-icons"),ve=require("react-dom"),L=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:h="",labelClassName:p="",helperText:g="",helperTextClassName:b="",...y}=n,x=t!==void 0,[C,v]=d.useState(()=>ke(s)),k=x?ke(t):C,E=q=>{x||v(q.currentTarget.value.length>0),r==null||r(q)};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)} ${k?"has-value":""} ${y.placeholder?"has-placeholder":""} ${h}`,required:u,defaultValue:s,...x?{value:t}:{},onChange:E,disabled:m,...y}),l.jsxs("label",{htmlFor:c,className:`text-input-label ${w.labelStateClassName(a)} ${p}`,children:[i,u?" *":""]}),!!g&&l.jsx("p",{className:`text-input-helper-text ${w.helperTextStateClassName(a)} ${b}`,children:g})]})}),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(O,{type:"button",tabIndex:-1,"aria-label":t(s?"_accessibility:ariaLabels.hidePassword":"_accessibility:ariaLabels.showPassword"),className:"password-icon",onClick:()=>r(!s),icon:s?A.faEyeSlash:A.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=h=>{h?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(O,{icon:A.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:h,cancelName:p,cancelAriaLabel:g}=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":h,children:[a?l.jsx(w.Loading,{color:"stroke-base",loaderClass:"!w-6 mt-1",strokeWidth:"6"}):null,e]}),l.jsx(w.Button,{type:"button",variant:"outlined",disabled:o,onClick:r,name:p,"aria-label":g,children:t})]})},rt=n=>{const{t:e}=w.useTranslation(),{children:t,handleSubmit:s,onSubmit:r,handleClose:a,isLoading:o=!1,buttonEnd:c=!0,...i}=n;return l.jsx(ie,{...i,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")})]})})},at=n=>{const{t:e}=w.useTranslation(),{children:t,handleSubmit:s,handleClose:r,isLoading:a=!1,...o}=n;return l.jsxs(ie,{...o,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")})]})};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,...f}=n,[h,p]=d.useReducer(lt,Ne()),{file:g,previewItems:b,parseError:y,processing:x,overrideExisting:C,inputKey:v}=h,k=d.useRef(c),E=d.useRef(o);d.useEffect(()=>{k.current=c},[c]),d.useEffect(()=>{E.current=o},[o]),d.useEffect(()=>{u||p({type:"RESET"})},[u]);const q=d.useCallback(async(F,S)=>{var j;if(E.current){p({type:"START_PROCESSING"});try{const N=await E.current(F,{override:S});p({type:"SET_PREVIEW",items:N??[]}),(j=k.current)==null||j.call(k,N??[])}catch(N){console.error(N);const P=N instanceof Error?N.message:"Failed to parse file";p({type:"SET_ERROR",message:P})}}},[]);return l.jsxs(ie,{...f,open:u,handleClose:r,children:[l.jsx(w.FileInput,{onClear:()=>{var F;p({type:"SET_FILE",file:null}),(F=k.current)==null||F.call(k,[])},onChange:F=>{var j,N;const S=(j=F.target.files)==null?void 0:j[0];if(!S){p({type:"SET_FILE",file:null}),(N=k.current)==null||N.call(k,[]);return}p({type:"SET_FILE",file:S}),q(S,C)},label:e("_accessibility:labels.file")},v),l.jsxs("label",{className:"import-override-label",children:[l.jsx("input",{type:"checkbox",checked:C,onChange:F=>{const S=F.target.checked;p({type:"SET_OVERRIDE",value:S}),m==null||m(S),g&&q(g,S)}}),l.jsx("span",{children:e("_pages:common.actions.import.override",{defaultValue:"Override existing items"})})]}),l.jsx(ot,{message:y}),x&&l.jsx(it,{}),i?i(b):!!b&&b.length>0&&l.jsx(ct,{items:b}),t,l.jsx(ce,{primaryText:e("_accessibility:buttons.ok"),cancelText:e("_accessibility:buttons.cancel"),onPrimaryClick:()=>{(!o||!!b&&b.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")})]})};var R=(n=>(n[n.success=0]="success",n[n.error=1]="error",n[n.warning=2]="warning",n[n.info=3]="info",n))(R||{}),I=(n=>(n.GET="GET",n.POST="POST",n.PUT="PUT",n.PATCH="PATCH",n.DELETE="DELETE",n))(I||{});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={}){$(this,"baseUrl");$(this,"userKey");$(this,"rememberKey");$(this,"refreshTokenKey");$(this,"accessTokenExpiresAtKey");$(this,"refreshEndpoint");$(this,"refreshExpirySkewMs");$(this,"secured");$(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){U(this.userKey,e.token);const s=e.refreshToken===void 0?t:e.refreshToken;typeof s=="string"&&s.length?U(this.refreshTokenKey,s):_(this.refreshTokenKey),typeof e.accessTokenExpiresAt=="string"&&e.accessTokenExpiresAt.length?U(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),I.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=I.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,I.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,I.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,I.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,I.POST,t);if(s||r===null||r===void 0)throw s??{status:a,message:"Unknown error"};return r}};$(J,"refreshInFlight",new Map);let Z=J;class Ae{constructor(e,t="user",s={}){$(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,I.POST,s)}async refresh(e){return await this.api.doQuery("auth/refresh",I.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,I.POST,r,s)}async register(e){return await this.api.doQuery("auth/sign-up",I.POST,e)}async getSession(){return await this.api.doQuery("auth/session",I.GET,void 0,this.api.defaultTokenAcquirer())}}class ht{constructor(e,t,s={}){$(this,"auth");this.auth=new Ae(e,t,s)}get Auth(){return this.auth}}class pt{constructor(e,t,s="user",r=!0,a={}){$(this,"table");$(this,"secured");$(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`,I.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,I.GET,void 0)}async import(e){return await this.api.doQuery(`${this.table}/import`,I.POST,e)}async commonGet(e){return await this.api.doQuery(je(`${this.table}/common`,e),I.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){$(this,"table");$(this,"dbName");$(this,"version");$(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 p;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=((p=e==null?void 0:e.sortingOrder)==null?void 0:p.toLowerCase())??"asc";a.sort((g,b)=>{const y=g[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),h=a.slice(m*i,m*i+i);return{sort:o,order:c,currentPage:m,pageSize:i,totalElements:u,totalPages:f,items:h}}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},U=(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((h,p)=>{const{type:g,items:b,id:y}=p;switch(g){case"set":return b??[];case"remove":return y!==void 0?h.filter(x=>x.id!==y):[]}return h},[],()=>[]),a=h=>h.map(p=>({...p,id:t.current++})),o=d.useCallback(h=>r({type:"set",items:a([{...h,type:R.error}])}),[]),c=d.useCallback(h=>r({type:"set",items:a([{...h}])}),[]),i=d.useCallback(h=>r({type:"set",items:a(h)}),[]),m=d.useCallback(h=>r({type:"set",items:a([{...h,type:R.success}])}),[]),u=h=>r({type:"remove",id:h}),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 L.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(L.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]),h=d.useCallback(x=>{U(t,x)},[t]),p=d.useCallback((x,C)=>{if(!x)return;const v=V(r,"boolean"),k=C??(typeof v=="boolean"?v:!1);m(x),_(t),U(s,x.token),U(r,k),typeof x.refreshToken=="string"&&x.refreshToken.length?U(a,x.refreshToken):_(a),typeof x.accessTokenExpiresAt=="string"&&x.accessTokenExpiresAt.length?U(o,x.accessTokenExpiresAt):_(o)},[o,t,a,r,s]),g=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();p(x)}catch(x){console.error(x),g()}},[p,g,c.Auth]),y=d.useMemo(()=>({account:i,logUser:p,logoutUser:g,logUserFromLocal:b,isInGuestMode:f,setGuestMode:h}),[i,p,g,b,f,h]);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,h)=>h!==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]),h=d.useCallback(y=>{y.key==="Escape"&&t&&s()},[s,t]);d.useEffect(()=>(document.addEventListener("keydown",h),()=>{document.removeEventListener("keydown",h)}),[h]);const p=d.useCallback((y,x)=>x?y===`${m.pathname}${m.search}`:y===m.pathname,[m.pathname,m.search]),g=d.useCallback(y=>l.jsx("li",{className:`drawer-list-item-child ${p(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,p]),b=d.useMemo(()=>f.map((y,x)=>{const C=y.page??String(x),v=`drawer-list-item ${p(y.path)?"active":""} animated`;if(y.type==="divider")return l.jsx("li",{className:v,children:l.jsx("hr",{className:"drawer-divider"})},C);const k=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`)]}),k&&l.jsx("ul",{className:"drawer-children-list",children:k.map(g)})]},C)}),[u,c,p,t,f,g,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 O=({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,h]=u.split("=");i[f]=h}),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 h=new Date;h.setTime(h.getTime()+i*24*60*60*1e3);const p="; expires="+h.toUTCString();document.cookie=`${c}=${m||""}${p};path=${u};SameSite=${f}`},a=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 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"),h=n("_accessibility:labels.hour"),p=n("_accessibility:labels.hours"),g=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?h:p} ${i?"":m}`:c<48?g: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([])},h=async g=>{c(g),u()},p=L.useMutation({mutationFn:()=>t(Array.isArray(o)?o:[o]),onError:g=>{console.error(g),s&&s(g),f()},onSuccess:async g=>{r&&r(g),e({message:a}),f()}});return{open:i,onClick:h,close:f,dialogFn:p,isLoading:p.isPending}},It=n=>{const{t:e}=w.useTranslation(),{showStackNotifications:t,showSuccessNotification:s,showErrorNotification:r}=W(),a=L.useQueryClient(),{defaultValues:o,mutationFn:c,formToDto:i,onError:m,onSuccess:u,queryKey:f,onSuccessMessage:h}=n,{control:p,handleSubmit:g,reset:b,setError:y,getValues:x,setValue:C}=Ee.useForm({defaultValues:o}),v=d.useRef(null),k=d.useCallback(()=>{const S=document.activeElement;if(!(S instanceof HTMLElement)){v.current=null;return}v.current=S.closest("form")},[]),E=d.useCallback(S=>{const j=S==null?void 0:S.errors,N=[],P=v.current;if(!P)return N;let B=!1;return j&&j.forEach(([ne,le])=>{const H=P.querySelector(`[name="${ne}"]`);(H instanceof HTMLInputElement||H instanceof HTMLTextAreaElement||H instanceof HTMLSelectElement)&&(B||(H.focus(),B=!0),H.classList.add("error"),N.push(e(`_entities:${f}.${ne}.${le}`)))}),N},[e,f]),q=d.useCallback(()=>{const S=v.current;if(!S)return;S.querySelectorAll("input, textarea, select").forEach(N=>{N.classList.remove("error")})},[]),F=L.useMutation({mutationFn:c,onError:S=>{console.error(S);const j=S;if(m)m(S);else if(ee(j)){const N=E(j);t(N.map(P=>({message:P,type:R.error})))}else if(te(j)){const N=j.message||e("_accessibility:errors.500"),P=e(`_accessibility:errors.${j.status}`);r({message:P||N})}else r({message:e("_accessibility:errors.500")})},onSuccess:async S=>{await a.invalidateQueries({queryKey:f}),u&&u(S),h&&s({message:h})}});return{control:p,getValues:x,setValue:C,handleSubmit:g,onSubmit:S=>{k(),q(),F.mutate(i?i(S):S)},reset:b,setError:y,isLoading:F.isPending}},Me=n=>{const{t:e}=w.useTranslation(),{onClick:t,icon:s=A.faTrash,sticky:r=!0,hidden:a=!1,multiple:o=!0,disabled:c=!1,id:i=Q.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:h=>t(h.map(p=>p.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=A.faRotateLeft,id:i=Q.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:h=>t(h.map(p=>p.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=Q.Edit,icon:c=A.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 Q=(n=>(n.Add="add",n.Edit="edit",n.Delete="delete",n.Restore="restore",n.Refresh="refresh",n.Export="export",n.Import="import",n))(Q||{});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:Q.Export,hidden:s,disabled:r,icon:l.jsx(M.FontAwesomeIcon,{className:`${a?"rotate":""}`,icon:a?A.faCircleNotch:A.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:Q.Import,hidden:s,disabled:r,icon:l.jsx(M.FontAwesomeIcon,{className:`${a?"rotate":""}`,icon:a?A.faCircleNotch:A.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=L.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:p=>{const g=p;if(ee(g))a(g.errors.map(([b,y])=>({message:o(`_pages:${b}.errors.${y}`),type:R.error})));else if(te(g)){const b=g.message||o("_accessibility:errors.500"),y=o(`_accessibility:errors.${g.status}`);a([{message:y||b,type:R.error}])}},onSuccess:async p=>{await r.invalidateQueries({queryKey:e}),t&&t(p)},...s}),{action:h}=Me({onClick:i});return{onClick:i,title:o("_pages:common.actions.delete.dialog.title"),open:c,isLoading:f,handleSubmit:()=>u.mutate(),handleClose:m,action:h}},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=L.useQueryClient(),{showErrorNotification:c,showStackNotifications:i,showSuccessNotification:m}=W(),[u,f]=d.useState(),[h,p]=d.useState(!1),g=d.useRef(!1),b=d.useRef(),{open:y,handleClose:x,handleOpen:C}=be(),{control:v,handleSubmit:k,reset:E,setError:q,getValues:F,setValue:S}=Ee.useForm({defaultValues:(t==null?void 0:t.defaultValues)||(s==null?void 0:s.defaultValues)||{}}),j=d.useRef(null),N=d.useCallback(()=>{const T=document.activeElement;if(!(T instanceof HTMLElement)){j.current=null;return}j.current=T.closest("form")},[]),P=t?[...t.queryKey,u??0]:["__legacy-form-dialog-disabled__",u??0],{data:B,isLoading:ne}=L.useQuery({queryFn:async()=>{if(!(!(t!=null&&t.getFunction)||!u))return t.getFunction(u)},queryKey:P,enabled:!!(t!=null&&t.getFunction)&&!!u});d.useEffect(()=>{!t||!B||!t.dtoToForm||b.current!==B&&(E({...t.dtoToForm(B)}),b.current=B)},[B,t,E]),d.useEffect(()=>{if(s){if(!y){g.current=!1;return}if(!g.current){if(g.current=!0,s.reinitializeOnOpen&&s.mapIn){E(s.mapIn());return}if(s.reinitializeOnOpen&&s.defaultValues){E(s.defaultValues);return}s.resetOnOpen&&E(s.defaultValues||{})}}},[s,y,E]);const le=d.useCallback(T=>{const D=T==null?void 0:T.errors,K=[],z=j.current;if(!z||!t)return K;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"),K.push(a(`_entities:${t.queryKey}.${Ce}.${Ye}`)))}),K},[t,a]),H=d.useCallback(()=>{const T=j.current;if(!T)return;T.querySelectorAll("input, textarea, select").forEach(K=>{K.classList.remove("error")})},[]),G=d.useCallback(()=>{H(),j.current=null,x(),E()},[x,H,E]),We=d.useCallback(T=>{f(T),C()},[C]),ue=L.useMutation({mutationFn:async T=>{if(t)return t.mutationFn(T)},onError:T=>{if(t)if(t.onError)t.onError(T);else{const D=T;if(ee(D)){const K=le(D);i(K.map(z=>({message:z,type:R.error})))}else if(te(D)){const K=D.message||a("_accessibility:errors.500"),z=a(`_accessibility:errors.${D.status}`);c({message:z||K})}else c({message:a("_accessibility:errors.500")})}},onSuccess:async T=>{t&&(await o.invalidateQueries({queryKey:t.queryKey}),t.onSuccess&&await t.onSuccess(T),m({message:t.onSuccessMessage}),G())}}),re=d.useCallback(T=>t?T:s!=null&&s.mapOut?s.mapOut(T,{id:u}):T,[s,u,t]),Ge=d.useCallback(async()=>{if(!(s!=null&&s.onApply))return;const T=F(),D=re(T);p(!0);try{await s.onApply(D,{close:G,id:u,values:T})}finally{p(!1)}},[G,s,F,u,re]),ze=d.useCallback(async()=>{if(s){if(s.onClear){p(!0);try{await s.onClear()}finally{p(!1)}}E(s.defaultValues||{})}},[s,E]),Je=d.useCallback(async T=>{if(t){N(),ue.mutate(t.formToDto?t.formToDto(T):T);return}const D=re(T);p(!0);try{s!=null&&s.onSubmit&&await s.onSubmit(D,{close:G,id:u,values:T}),((s==null?void 0:s.closeOnSubmit)??!0)&&G()}finally{p(!1)}},[N,G,s,u,ue,t,re]);return{open:y,mode:r,id:u,openDialog:We,handleClose:G,control:v,getValues:F,setValue:S,handleSubmit:k,onSubmit:Je,reset:E,setError:q,title:n.title,isSubmitting:h,onApply:Ge,onClear:ze,isLoading:ne||ue.isPending||h}},Mt=se,Pt=n=>se(n),Ot=n=>{const e=L.useQueryClient(),{mutationFn:t,queryKey:s,onSuccess:r,onError:a,mapOut:o,...c}=n,i=L.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=L.useQueryClient(),t=d.useRef(),s=d.useRef(),{mutationFn:r,queryKey:a,onSuccess:o,onError:c,mapOut:i,getFunction:m,dtoToForm:u,title:f,...h}=n,p=d.useRef(u);d.useEffect(()=>{p.current=u},[u]);const g=L.useMutation({mutationFn:r}),b=se({...h,mode:"entity",title:f,onSubmit:async v=>{try{const k=await g.mutateAsync(v);a&&await e.invalidateQueries({queryKey:a}),o&&await o(k)}catch(k){throw c&&c(k),k}},mapOut:v=>i?i(v,t.current):v}),{reset:y}=b,x=a||["put-dialog",f],C=L.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,p.current&&y){y(p.current(C.data));return}y==null||y(C.data)}},[C.data,y]),{...b,isLoading:b.isLoading||g.isPending||C.isFetching||C.isLoading}},Kt=n=>{const{queryKey:e,onSuccess:t,...s}=n,r=L.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:p=>{const g=p;if(ee(g))a(g.errors.map(([b,y])=>({message:o(`_pages:${b}.errors.${y}`),type:R.error})));else if(te(g)){const b=g.message||o("_accessibility:errors.500"),y=o(`_accessibility:errors.${g.status}`);a([{message:y||b,type:R.error}])}},onSuccess:async p=>{await r.invalidateQueries({queryKey:e}),t&&t(p)},...s}),{action:h}=Pe({onClick:i});return{onClick:i,title:o("_pages:common.actions.restore.dialog.title"),open:c,isLoading:f,handleSubmit:()=>u.mutate(),handleClose:m,action:h}};function Ut(n){const{t:e}=w.useTranslation(),t=L.useQueryClient(),{queryKey:s,mutationFn:r,entity:a,fileProcessor:o,renderCustomPreview:c,onError:i}=n,[m,u]=d.useState(!1),[f,h]=d.useState(null),[p,g]=d.useState(!1),b=L.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:p}),u(!1),h(null),g(!1)}catch(x){console.error(x)}},isLoading:b.isPending,fileProcessor:o,onFileProcessed:x=>h(x),renderCustomPreview:c,onOverrideChange:x=>g(x),open:m,title:e("_pages:common.actions.import.dialog.title",{entity:e(`_pages:${a}.title`)}),handleClose:()=>{u(!1),h(null),g(!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=L.useMutation({mutationFn:()=>r(),onError:f=>{console.error(f),a&&a(f)},onSuccess:async f=>{const h=JSON.stringify(f,null,2),p=new Blob([h],{type:"application/json"}),g=URL.createObjectURL(p),b=document.createElement("a");b.href=g,b.download=`${s}.json`,b.click(),URL.revokeObjectURL(g),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=A.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",...h}=n,p=Ke(s),g=()=>{i==null||i(),c&&Lt.scrollTo(a,r)};return l.jsx(O,{variant:u,color:f,icon:t,"data-tooltip-id":"tooltip",onClick:g,className:`to-top ${p?"show":"hide"} ${m}`.trim(),"data-tooltip-content":o,...h})};function Ht(n){const{t:e}=w.useTranslation();if("children"in n){const{children:k,className:E}=n;return l.jsx("div",{className:`error-container${E?` ${E}`:""}`,children:k})}const{error:s,message:r,iconProps:a,onRetry:o,retryLabel:c,retryButtonProps:i,messageProps:m,className:u,resetErrorBoundary:f}=n,h=o??f,{className:p,children:g,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")}),h&&l.jsx(w.Button,{type:"button",variant:"submit",color:"primary",...y,className:`error-retry ${p?` ${p}`:""}`,onClick:k=>{b==null||b(k),k.defaultPrevented||h()},children:g??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(O,{icon:A.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=L.useQueryClient(),{countOfFilters:h}=w.useTableOptions(),p=d.useMemo(()=>{const g=Array.isArray(a)?[...a]:[];if(o){const b={id:Q.Refresh,onClick:()=>f.invalidateQueries({queryKey:o}),icon:l.jsx(M.FontAwesomeIcon,{icon:A.faRotateLeft}),tooltip:u("_pages:common.actions.refresh.text")};g.unshift(b)}if(s){const b={...s,id:Q.Add,icon:l.jsx(M.FontAwesomeIcon,{icon:A.faAdd})};g.unshift(b)}if(r){const b={...r,id:"filter",icon:l.jsx(M.FontAwesomeIcon,{icon:A.faFilter}),children:l.jsx(w.Badge,{className:`${h>0?"show":"hide"} `,count:h})};g.push(b)}return g},[a,s,h,r,f,o,u]);return l.jsxs("main",{className:"page-main",children:[l.jsx(Vt,{showBackButton:m,actions:p,title:e}),l.jsx("div",{className:`page-main-content ${i?"appear":""}`,children:c?l.jsx(w.Loading,{className:"page-loading"}):t}),s&&l.jsx(O,{icon:s.icon??A.faAdd,color:s.color??"primary",variant:s.variant??"submit",onClick:()=>{var g;return(g=s.onClick)==null?void 0:g.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:h=null,observerRootMargin:p="0px 0px 200px 0px",observerThreshold:g=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(k=>k.isIntersecting)&&x()},{rootMargin:p,threshold:g});return C.observe(y.current),()=>C.disconnect()},[m,f,p,g,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:h})]}):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(g=>{($e()?g.metaKey:g.ctrlKey)&&g.shiftKey&&g.key.toLowerCase()==="f"&&(u(!0),g.preventDefault())},[]);d.useEffect(()=>(window.addEventListener("keydown",f),()=>{window.removeEventListener("keydown",f)}),[f]);const h=a,p=s&&!!h;return l.jsxs(l.Fragment,{children:[o.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(O,{...r,type:(r==null?void 0:r.type)??"button",icon:(r==null?void 0:r.icon)??A.faBars,onClick:g=>{var b;(b=r==null?void 0:r.onClick)==null||b.call(r,g),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,p&&l.jsx(O,{icon:A.faSearch,className:"navbar-search-btn",onClick:()=>u(!0)})]})]})]})}const ae=300,Yt=n=>n??R.error,Xt=n=>{switch(n){case R.error:return A.faWarning;default:return A.faCircleCheck}},me=n=>{switch(n){case R.success:return"!text-success";case R.error:return"!text-error";case R.warning:return"!text-warning";default:return"!text-info"}},Zt=n=>{switch(n){case R.success:return"bg-bg-success";case R.error:return"bg-bg-error";case R.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(p=>p.map(g=>({...g,closing:!0}))),i=null},0),o.current=setTimeout(()=>{r([]),o.current=null},ae),m);const u=new Set(a.current.map(p=>p.id));if(!e.some(p=>p.id!==void 0&&!u.has(p.id)))return;if(a.current.length===0){const p=[...e];return i=setTimeout(()=>{r(p.map(g=>({...g,closing:!1}))),i=null},0),()=>{i&&clearTimeout(i)}}o.current&&clearTimeout(o.current),i=setTimeout(()=>{r(p=>p.every(g=>g.closing)?p:p.map(g=>({...g,closing:!0}))),i=null},0);const h=[...e];return o.current=setTimeout(()=>{r(h.map(p=>({...p,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 h=Yt(m);return l.jsxs("div",{className:`notification ${f?"closing":""} ${Zt(h)}`,onClick:p=>p.stopPropagation(),children:[l.jsxs("div",{className:"notification-body",children:[l.jsx(M.FontAwesomeIcon,{icon:Xt(h),className:`notification-icon ${me(h)}`}),l.jsx("p",{className:`notification-text ${me(h)}`,children:u})]}),l.jsx(O,{type:"button",icon:A.faClose,color:"error",className:"notification-close group",onClick:p=>{p.stopPropagation(),i!==void 0&&c(i)},iconClassName:`${me(h)} 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:h=t?"submit":"outlined",color:p=t?"primary":"default",...g}=c??{};return l.jsx(w.Button,{type:"button",variant:h,color:p,className:`tab ${f}`,onClick:s,...g,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 p;const{tabs:e=[],defaultTab:t,currentTab:s,onTabChange:r,className:a="",tabsContainerClassName:o="",useLinks:c=!0,tabButtonProps:i}=n,[m,u]=d.useState(t??((p=e[0])==null?void 0:p.id)),f=s??m,h=d.useMemo(()=>e.find(g=>g.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:g,to:b,label:y})=>l.jsx("li",{children:l.jsx(Qe,{onClick:()=>{s===void 0&&u(g),r==null||r(g)},id:g,to:b,siblings:e.length>1,active:f===g,useLinks:c,tabButtonProps:i,children:y})},g))}),h==null?void 0:h.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]),h=d.useCallback(()=>{if(a){a();return}i(t)},[i,a,t]),p=d.useCallback(()=>{if(o){o();return}c(!0),i(s)},[s,i,o,c]),g=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:p,onSignIn:h})})),[h,f,p,e]);return l.jsx("div",{className:"onboarding-main",children:l.jsx(Be,{currentTab:m,onTabChange:b=>u(Number(b)),tabs:g,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=O;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=Q;exports.IManager=ht;exports.IconButton=O;exports.ImportDialog=ut;exports.IndexedDBClient=gt;exports.ManagerProvider=Tt;exports.Methods=I;exports.Navbar=Jt;exports.NavbarContext=we;exports.NavbarProvider=zt;exports.Notification=es;exports.NotificationEnumType=R;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=U;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]})});