@sito/dashboard-app 0.0.56 → 0.0.57

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
@@ -297,7 +297,7 @@ const createDialog = usePostDialog<CreateProductDto, ProductDto, ProductForm>({
297
297
  title: "Create product",
298
298
  defaultValues: { name: "", price: 0 },
299
299
  mutationFn: (dto) => api.products.insert(dto),
300
- mapOut: (form) => ({ name: form.name, price: form.price }),
300
+ formToDto: (form) => ({ name: form.name, price: form.price }),
301
301
  queryKey: ["products"],
302
302
  });
303
303
  ```
@@ -331,7 +331,7 @@ const editDialog = usePutDialog<
331
331
  getFunction: (id) => api.products.getById(id),
332
332
  dtoToForm: (dto) => ({ name: dto.name, price: dto.price }),
333
333
  mutationFn: (dto) => api.products.update(dto),
334
- mapOut: (form, dto) => ({ id: dto?.id ?? 0, ...form }),
334
+ formToDto: (form, dto) => ({ id: dto?.id ?? 0, ...form }),
335
335
  queryKey: ["products"],
336
336
  });
337
337
  ```
@@ -384,7 +384,7 @@ const reopenWithLastSubmitted = () => {
384
384
  };
385
385
  ```
386
386
 
387
- If both `openDialog({ values })` and `reinitializeOnOpen`/`mapIn` are configured, explicit `values` passed to `openDialog` take priority for that opening.
387
+ If both `openDialog({ values })` and `reinitializeOnOpen`/`dtoToForm` are configured, explicit `values` passed to `openDialog` take priority for that opening.
388
388
 
389
389
  Storybook reference: `Hooks/Dialogs/FormDialogs` includes `StateModeSetValuesOnOpen` and `StateModeReopenWithSubmittedValues` scenarios.
390
390
 
@@ -1 +1 @@
1
- var Ye=Object.defineProperty;var Xe=(n,e,s)=>e in n?Ye(n,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):n[e]=s;var E=(n,e,s)=>Xe(n,typeof e!="symbol"?e+"":e,s);var us=require("./main.css");Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const C=require("@sito/dashboard"),l=require("react/jsx-runtime"),K=require("@fortawesome/react-fontawesome"),d=require("react"),R=require("@fortawesome/free-solid-svg-icons"),Ee=require("react-dom"),P=require("@tanstack/react-query"),Ze=require("@fortawesome/free-regular-svg-icons"),ve=require("react-hook-form"),Se=n=>n==null?!1:`${n}`.length>0,et=d.forwardRef(function(n,e){const{value:s,defaultValue:t,onChange:r,state:o=C.State.default,name:a="",id:c="",label:i="",disabled:u=!1,required:m=!1,containerClassName:h="",inputClassName:f="",labelClassName:g="",helperText:p="",helperTextClassName:y="",...b}=n,w=s!==void 0,[S,x]=d.useState(()=>Se(t)),k=w?Se(s):S,v=_=>{w||x(_.currentTarget.value.length>0),r==null||r(_)};return l.jsxs("div",{className:`form-paragraph-container group ${h}`,children:[l.jsx("textarea",{ref:e,name:a,id:c,className:`text-input text-area form-paragraph-textarea peer ${C.inputStateClassName(o)} ${k?"has-value":""} ${b.placeholder?"has-placeholder":""} ${f}`,required:m,defaultValue:t,...w?{value:s}:{},onChange:v,disabled:u,...b}),l.jsxs("label",{htmlFor:c,className:`text-input-label ${C.labelStateClassName(o)} ${g}`,children:[i,m?" *":""]}),!!p&&l.jsx("p",{className:`text-input-helper-text ${C.helperTextStateClassName(o)} ${y}`,children:p})]})}),tt=n=>{const{t:e}=C.useTranslation(),{children:s,handleSubmit:t,onSubmit:r,isLoading:o=!1,buttonEnd:a=!0,reset:c}=n;return l.jsxs("form",{className:"form-container",onSubmit:t(r),children:[s,l.jsxs("div",{className:`form-actions ${a?"end":""}`,children:[l.jsxs(C.Button,{type:"submit",color:"primary",variant:"submit",disabled:o,name:e("_accessibility:buttons.submit"),"aria-label":e("_accessibility:ariaLabels.submit"),children:[o?l.jsx(C.Loading,{color:"stroke-base",loaderClass:"!w-6 mt-1",strokeWidth:"6"}):null,e("_accessibility:buttons.submit")]}),l.jsx(C.Button,{type:"button",variant:"outlined",onClick:()=>c==null?void 0:c(),name:e("_accessibility:buttons.cancel"),"aria-label":e("_accessibility:ariaLabels.cancel"),children:e("_accessibility:buttons.cancel")})]})]})},st=d.forwardRef(function(n,e){const{t:s}=C.useTranslation(),[t,r]=d.useState(!1);return l.jsx(C.TextInput,{...n,type:t?"text":"password",ref:e,children:l.jsx(B,{type:"button",tabIndex:-1,"aria-label":s(t?"_accessibility:ariaLabels.hidePassword":"_accessibility:ariaLabels.showPassword"),className:"password-icon",onClick:()=>r(!t),icon:t?R.faEyeSlash:R.faEye})})}),ne=n=>{const{t:e}=C.useTranslation(),{title:s,children:t,handleClose:r,open:o=!1,containerClassName:a="",className:c="",animationClass:i="appear"}=n,u=d.useCallback(h=>{h.key==="Escape"&&o&&r()},[o,r]);d.useEffect(()=>(window.addEventListener("keydown",u),()=>{window.removeEventListener("keydown",u)}),[u]);const m=d.useCallback(h=>{h.target===h.currentTarget&&r()},[r]);return d.useEffect(()=>{const h=f=>{f?document.body.style.overflow="hidden":document.body.style.overflow="auto"};return h(o),()=>{h(!1)}},[o]),Ee.createPortal(l.jsx("div",{"aria-label":e("_accessibility:ariaLabels.closeDialog"),"aria-hidden":!o,onClick:m,className:`dialog-backdrop animated ${o?`opened ${i}`:"closed"} ${a}`,children:l.jsxs("div",{className:`dialog elevated animated ${o?`opened ${i}`:"closed"} ${c}`,children:[l.jsxs("div",{className:"dialog-header",children:[l.jsx("h3",{className:"dialog-title",children:s}),l.jsx(B,{icon:R.faClose,disabled:!o,"aria-disabled":!o,onClick:r,variant:"text",color:"error",className:"icon-button dialog-close-btn",name:e("_accessibility:buttons.closeDialog"),"aria-label":e("_accessibility:ariaLabels.closeDialog")})]}),t]})}),document.body)},re=n=>{const{primaryText:e,cancelText:s,onPrimaryClick:t,onCancel:r,isLoading:o=!1,disabled:a=!1,primaryType:c="submit",containerClassName:i="",primaryClassName:u="",alignEnd:m=!1,primaryName:h,primaryAriaLabel:f,cancelName:g,cancelAriaLabel:p,extraActions:y=[]}=n;return l.jsxs("div",{className:`dialog-actions ${m?"end":""} ${i}`,children:[l.jsxs(C.Button,{type:c,color:"primary",variant:"submit",className:u,disabled:a,onClick:t,name:h,"aria-label":f,children:[o?l.jsx(C.Loading,{color:"stroke-base",loaderClass:"!w-6 mt-1",strokeWidth:"6"}):null,e]}),y==null?void 0:y.map(b=>l.jsx(C.Button,{...b},b.id)),l.jsx(C.Button,{type:"button",variant:"outlined",disabled:a,onClick:r,name:g,"aria-label":p,children:s})]})},nt=n=>{const{t:e}=C.useTranslation(),{children:s,handleSubmit:t,onSubmit:r,handleClose:o,isLoading:a=!1,buttonEnd:c=!0,extraActions:i=[],...u}=n;return l.jsx(ne,{...u,handleClose:o,children:l.jsxs("form",{onSubmit:t(r),children:[l.jsx("div",{className:"form-container",children:s}),l.jsx(re,{primaryType:"submit",primaryText:e("_accessibility:buttons.submit"),cancelText:e("_accessibility:buttons.cancel"),onCancel:o,isLoading:a,disabled:a,primaryClassName:"dialog-form-primary",alignEnd:c,primaryName:e("_accessibility:buttons.submit"),primaryAriaLabel:e("_accessibility:ariaLabels.submit"),cancelName:e("_accessibility:buttons.cancel"),cancelAriaLabel:e("_accessibility:ariaLabels.cancel"),extraActions:i})]})})},rt=n=>{const{t:e}=C.useTranslation(),{children:s,handleSubmit:t,handleClose:r,isLoading:o=!1,extraActions:a=[],...c}=n;return l.jsxs(ne,{...c,handleClose:r,children:[s,l.jsx(re,{primaryText:e("_accessibility:buttons.ok"),cancelText:e("_accessibility:buttons.cancel"),onPrimaryClick:t,onCancel:r,isLoading:o,disabled:o,primaryType:"button",containerClassName:"mt-5",primaryName:e("_accessibility:buttons.ok"),primaryAriaLabel:e("_accessibility:ariaLabels.ok"),cancelName:e("_accessibility:buttons.cancel"),cancelAriaLabel:e("_accessibility:ariaLabels.cancel"),extraActions:a})]})};function ot(n){const{message:e,className:s=""}=n,{t}=C.useTranslation();return l.jsx("p",{className:`import-error-message ${s}`,children:e??t("_messages:errors.parseFile",{defaultValue:"Failed to process file"})})}function at(n){const{message:e,className:s=""}=n,{t}=C.useTranslation();return l.jsxs("div",{className:`import-loading ${s}`,children:[l.jsx(C.Loading,{loaderClass:"w-5 h-5",className:"!w-auto"}),l.jsx("span",{children:e??t("_messages:loading.processingFile",{defaultValue:"Processing file..."})})]})}function it(n){const{items:e,max:s=5,className:t=""}=n,{t:r}=C.useTranslation();if(!e||e.length===0)return null;const o=e.slice(0,s);return l.jsxs("div",{className:`import-preview ${t}`,children:[l.jsx("p",{className:"import-preview-count",children:r("_pages:common.actions.import.previewCount",{count:e.length,defaultValue:`Preview: ${e.length} items`})}),l.jsx("pre",{className:"import-preview-content",children:JSON.stringify(o,null,2)})]})}const Ne=()=>({file:null,previewItems:null,parseError:null,processing:!1,overrideExisting:!1,inputKey:0});function ct(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 lt=n=>{const{t:e}=C.useTranslation(),{children:s,handleSubmit:t,handleClose:r,isLoading:o=!1,fileProcessor:a,onFileProcessed:c,renderCustomPreview:i,onOverrideChange:u,open:m,extraActions:h=[],...f}=n,[g,p]=d.useReducer(ct,Ne()),{file:y,previewItems:b,parseError:w,processing:S,overrideExisting:x,inputKey:k}=g,v=d.useRef(c),_=d.useRef(a);d.useEffect(()=>{v.current=c},[c]),d.useEffect(()=>{_.current=a},[a]),d.useEffect(()=>{m||p({type:"RESET"})},[m]);const Q=d.useCallback(async(T,N)=>{var A;if(_.current){p({type:"START_PROCESSING"});try{const L=await _.current(T,{override:N});p({type:"SET_PREVIEW",items:L??[]}),(A=v.current)==null||A.call(v,L??[])}catch(L){console.error(L);const O=L instanceof Error?L.message:"Failed to parse file";p({type:"SET_ERROR",message:O})}}},[]);return l.jsxs(ne,{...f,open:m,handleClose:r,children:[l.jsx(C.FileInput,{onClear:()=>{var T;p({type:"SET_FILE",file:null}),(T=v.current)==null||T.call(v,[])},onChange:T=>{var A,L;const N=(A=T.target.files)==null?void 0:A[0];if(!N){p({type:"SET_FILE",file:null}),(L=v.current)==null||L.call(v,[]);return}p({type:"SET_FILE",file:N}),Q(N,x)},label:e("_accessibility:labels.file")},k),l.jsxs("label",{className:"import-override-label",children:[l.jsx("input",{type:"checkbox",checked:x,onChange:T=>{const N=T.target.checked;p({type:"SET_OVERRIDE",value:N}),u==null||u(N),y&&Q(y,N)}}),l.jsx("span",{children:e("_pages:common.actions.import.override",{defaultValue:"Override existing items"})})]}),l.jsx(ot,{message:w}),S&&l.jsx(at,{}),i?i(b):!!b&&b.length>0&&l.jsx(it,{items:b}),s,l.jsx(re,{primaryText:e("_accessibility:buttons.ok"),cancelText:e("_accessibility:buttons.cancel"),onPrimaryClick:()=>{(!a||!!b&&b.length>0)&&t()},onCancel:r,isLoading:o,primaryType:"button",containerClassName:"import-dialog-actions",primaryName:e("_accessibility:buttons.ok"),primaryAriaLabel:e("_accessibility:ariaLabels.ok"),cancelName:e("_accessibility:buttons.cancel"),cancelAriaLabel:e("_accessibility:ariaLabels.cancel"),extraActions:h})]})};var F=(n=>(n[n.success=0]="success",n[n.error=1]="error",n[n.warning=2]="warning",n[n.info=3]="info",n))(F||{}),I=(n=>(n.GET="GET",n.POST="POST",n.PUT="PUT",n.PATCH="PATCH",n.DELETE="DELETE",n))(I||{});const ut=n=>Array.isArray(n)||n instanceof Headers?!1:typeof n=="object"&&n!==null&&("headers"in n||"credentials"in n),dt=n=>n?ut(n)?n:{headers:n}:{},mt=n=>n?n instanceof Headers?Object.fromEntries(n.entries()):Array.isArray(n)?Object.fromEntries(n):n:{};async function se(n,e="GET",s,t){const r=dt(t),o={...s!==void 0?{"Content-Type":"application/json"}:{},...mt(r.headers)};try{const a=await fetch(n,{method:e,headers:o,...r.credentials?{credentials:r.credentials}:{},...s!==void 0?{body:JSON.stringify(s)}:{}}),c=await a.text();let i=null;try{i=c?JSON.parse(c):null}catch{i=null}if(!a.ok){const 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 Ae(n,e){const s=t=>t instanceof Date?t.toISOString():String(t);if(e){const t=Object.entries(e).filter(([,r])=>r!=null).map(([r,o])=>`${encodeURIComponent(r)}=${encodeURIComponent(s(o))}`).join("&");return t?`${n}?${t}`:n}return n}const le=n=>typeof n=="object"&&n!==null,V=n=>n instanceof Date?encodeURIComponent(n.toISOString()):encodeURIComponent(String(n)),ht=n=>{if(typeof n!="string")return;const e=n.trim().toUpperCase();if(e==="ACTIVE"||e==="DELETED"||e==="ALL")return e},fe=(n,e,s)=>{const t=[];if(e){const{sortingBy:r,sortingOrder:o,currentPage:a,pageSize:c}=e;r!==void 0&&t.push(`sort=${String(r)}`),o!==void 0&&t.push(`order=${o}`),a!==void 0&&t.push(`page=${a}`),c!==void 0&&t.push(`pageSize=${c}`)}if(s){const r=ht(s.softDeleteScope);r&&t.push(`softDeleteScope=${encodeURIComponent(r)}`);const o=Object.entries(s).filter(([a,c])=>a!=="softDeleteScope"&&c!==null&&c!==void 0&&c!=="").flatMap(([a,c])=>{if(Array.isArray(c))return c.map(i=>i instanceof Date?`${a}==${V(i)}`:le(i)?`${a}==${V(i.id??"")}`:`${a}==${V(i)}`);if(le(c)&&"start"in c&&"end"in c){const i=[];return c.start!=null&&c.start!==""&&i.push(`${a}>=${V(c.start)}`),c.end!=null&&c.end!==""&&i.push(`${a}<=${V(c.end)}`),i}return c instanceof Date?`${a}==${V(c)}`:le(c)?`${a}==${V(c.id??"")}`:`${a}==${V(c)}`});o.length>0&&t.push(`filters=${o.join(",")}`)}return t.length?`${n}?${t.join("&")}`:n},J=class J{constructor(e,s="user",t=!0,r,o={}){E(this,"baseUrl");E(this,"userKey");E(this,"rememberKey");E(this,"refreshTokenKey");E(this,"accessTokenExpiresAtKey");E(this,"refreshEndpoint");E(this,"refreshExpirySkewMs");E(this,"secured");E(this,"tokenAcquirer");this.baseUrl=e,this.secured=t,this.userKey=s,this.rememberKey=o.rememberKey??"remember",this.refreshTokenKey=o.refreshTokenKey??"refreshToken",this.accessTokenExpiresAtKey=o.accessTokenExpiresAtKey??"accessTokenExpiresAt",this.refreshEndpoint=o.refreshEndpoint??"auth/refresh",this.refreshExpirySkewMs=o.refreshExpirySkewMs??5e3,this.tokenAcquirer=r??this.defaultTokenAcquirer}defaultTokenAcquirer(e){if(e)return{credentials:"include"};const s=q(this.userKey);if(s&&s.length)return{Authorization:`Bearer ${s}`}}getRefreshLockKey(){return`${this.baseUrl}|${this.userKey}|${this.refreshTokenKey}|${this.accessTokenExpiresAtKey}`}buildUrl(e){const s=this.baseUrl.endsWith("/")?this.baseUrl.slice(0,-1):this.baseUrl,t=e.startsWith("/")?e:`/${e}`;return`${s}${t}`}getRefreshToken(){const e=q(this.refreshTokenKey);if(typeof e=="string"&&e.length)return e}getAccessTokenExpiresAt(){const e=q(this.accessTokenExpiresAtKey);if(typeof e=="string"&&e.length)return e}canRefresh(){return!!this.getRefreshToken()}shouldRefreshBeforeRequest(){const e=this.getRefreshToken(),s=this.getAccessTokenExpiresAt();if(!e||!s)return!1;const t=Date.parse(s);return Number.isNaN(t)?!1:Date.now()>=t-this.refreshExpirySkewMs}clearStoredSession(){D(this.userKey),D(this.rememberKey),D(this.refreshTokenKey),D(this.accessTokenExpiresAtKey)}storeSession(e,s){M(this.userKey,e.token);const t=e.refreshToken===void 0?s:e.refreshToken;typeof t=="string"&&t.length?M(this.refreshTokenKey,t):D(this.refreshTokenKey),typeof e.accessTokenExpiresAt=="string"&&e.accessTokenExpiresAt.length?M(this.accessTokenExpiresAtKey,e.accessTokenExpiresAt):D(this.accessTokenExpiresAtKey)}async refreshAccessTokenWithMutex(){const e=this.getRefreshToken();if(!e)throw{status:401,message:"Missing refresh token"};const s=this.getRefreshLockKey(),t=J.refreshInFlight.get(s);if(t){await t;return}const r=(async()=>{const{data:o,status:a,error:c}=await se(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)})();J.refreshInFlight.set(s,r);try{await r}finally{J.refreshInFlight.delete(s)}}isRequestOptions(e){return Array.isArray(e)||e instanceof Headers?!1:typeof e=="object"&&e!==null&&("headers"in e||"credentials"in e)}toRequestOptions(e){return e?this.isRequestOptions(e)?e:{headers:e}:{}}toHeaderRecord(e){return e?e instanceof Headers?Object.fromEntries(e.entries()):Array.isArray(e)?Object.fromEntries(e):e:{}}mergeRequestConfig(e){const s=this.secured?this.tokenAcquirer():void 0,t=this.toRequestOptions(s),r=this.toRequestOptions(e),o={...this.toHeaderRecord(t.headers),...this.toHeaderRecord(r.headers)},a=r.credentials??t.credentials,c=Object.keys(o).length>0;if(a)return c?{headers:o,credentials:a}:{credentials:a};if(c)return o}async makeRequestWithRefresh(e,s,t,r){this.secured&&this.shouldRefreshBeforeRequest()&&await this.refreshAccessTokenWithMutex();let o=await se(this.buildUrl(e),s,t,this.mergeRequestConfig(r));return this.secured&&o.status===401&&this.canRefresh()&&(await this.refreshAccessTokenWithMutex(),o=await se(this.buildUrl(e),s,t,this.mergeRequestConfig(r))),o}async doQuery(e,s=I.GET,t,r){const{data:o,status:a,error:c}=await this.makeRequestWithRefresh(e,s,t,r);if(c||a<200||a>=300)throw c??{status:a,message:String(a)};return o}async get(e,s,t){const r=fe(e,s,t),{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,s){const{error:t,data:r,status:o}=await this.makeRequestWithRefresh(e,I.PATCH,s);if(t||r===null||r===void 0)throw t??{status:o,message:"Unknown error"};return r}async delete(e,s){const{error:t,data:r,status:o}=await this.makeRequestWithRefresh(e,I.DELETE,s);if(t||r===null||r===void 0)throw t??{status:o,message:"Unknown error"};return r}async post(e,s){const{error:t,data:r,status:o}=await this.makeRequestWithRefresh(e,I.POST,s);if(t||r===null||r===void 0)throw t??{status:o,message:"Unknown error"};return r}};E(J,"refreshInFlight",new Map);let Z=J;class je{constructor(e,s="user",t={}){E(this,"api");this.api=new Z(e,s,!1,void 0,t)}async login(e){const s="auth/sign-in",t=e;return await this.api.doQuery(s,I.POST,t)}async refresh(e){return await this.api.doQuery("auth/refresh",I.POST,e)}async logout(e){const s="auth/sign-out",t=e!=null&&e.accessToken?{Authorization:`Bearer ${e.accessToken}`}:void 0,r=e!=null&&e.refreshToken?{refreshToken:e.refreshToken}:void 0;return await this.api.doQuery(s,I.POST,r,t)}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 ft{constructor(e,s,t={}){E(this,"auth");this.auth=new je(e,s,t)}get Auth(){return this.auth}}class pt{constructor(e,s,t="user",r=!0,o={}){E(this,"table");E(this,"secured");E(this,"api");this.table=e,this.secured=r,this.api=new Z(s,t,r,void 0,o)}async insert(e){return await this.api.post(`${this.table}`,e)}async insertMany(e){return await this.api.doQuery(`${this.table}/batch`,I.POST,e)}async update(e){return await this.api.patch(`${this.table}/${e.id}`,e)}async get(e,s){return await this.api.get(`${this.table}`,e,s)}async export(e){const s=fe(`${this.table}/export`,void 0,e);return await this.api.doQuery(s,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(Ae(`${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,s,t=1){E(this,"table");E(this,"dbName");E(this,"version");E(this,"db",null);this.table=e,this.dbName=s,this.version=t}close(){this.db&&(this.db.onversionchange=null,this.db.close(),this.db=null)}open(){return this.db?Promise.resolve(this.db):new Promise((e,s)=>{const t=indexedDB.open(this.dbName,this.version);t.onupgradeneeded=r=>{const o=r.target.result;o.objectStoreNames.contains(this.table)||o.createObjectStore(this.table,{keyPath:"id",autoIncrement:!0})},t.onsuccess=r=>{this.db=r.target.result,this.db.onversionchange=()=>{this.close()},e(this.db)},t.onerror=r=>{s(r.target.error)}})}async transaction(e){return(await this.open()).transaction(this.table,e).objectStore(this.table)}request(e){return new Promise((s,t)=>{e.onsuccess=()=>s(e.result),e.onerror=()=>t(e.error)})}async insert(e){const s=await this.transaction("readwrite"),t=await this.request(s.add(e));return{...e,id:t}}async insertMany(e){const s=await this.transaction("readwrite");let t=0;for(const r of e)t=await this.request(s.add(r));return{...e[e.length-1],id:t}}async update(e,s){const t=typeof e=="number"?s:e;if(!t)throw new Error("IndexedDBClient.update requires a value payload");const r=typeof e=="number"?{...t,id:t.id??e}:t,o=await this.transaction("readwrite");return await this.request(o.put(r)),r}async get(e,s){var g;const t=await this.transaction("readonly"),r=await this.request(t.getAll()),o=this.applyFilter(r,s),a=(e==null?void 0:e.sortingBy)??"id",c=((g=e==null?void 0:e.sortingOrder)==null?void 0:g.toLowerCase())??"asc";o.sort((p,y)=>{const b=p[a],w=y[a];return b<w?c==="asc"?-1:1:b>w?c==="asc"?1:-1:0});const i=(e==null?void 0:e.pageSize)??10,u=(e==null?void 0:e.currentPage)??0,m=o.length,h=Math.ceil(m/i),f=o.slice(u*i,u*i+i);return{sort:a,order:c,currentPage:u,pageSize:i,totalElements:m,totalPages:h,items:f}}async export(e){const s=await this.transaction("readonly"),t=await this.request(s.getAll());return this.applyFilter(t,e)}async import(e){const s=await this.transaction("readwrite");let t=0;for(const r of e.items)e.override?await this.request(s.put(r)):await this.request(s.add(r)),t++;return t}async commonGet(e){const s=await this.transaction("readonly"),t=await this.request(s.getAll());return this.applyFilter(t,e)}async getById(e){const s=await this.transaction("readonly"),t=await this.request(s.get(e));if(!t)throw new Error(`Record ${e} not found in ${this.table}`);return t}async softDelete(e){const s=await this.transaction("readwrite");let t=0;for(const r of e){const o=await this.request(s.get(r));o&&(await this.request(s.put({...o,deletedAt:new Date})),t++)}return t}async restore(e){const s=await this.transaction("readwrite");let t=0;for(const r of e){const o=await this.request(s.get(r));o&&(await this.request(s.put({...o,deletedAt:null})),t++)}return t}applyFilter(e,s){if(!s)return e;const t=this.resolveSoftDeleteScope(s.softDeleteScope),r=t===void 0?e:e.filter(a=>this.matchesSoftDeleteScope(t,a.deletedAt)),o=Object.entries(s).filter(([a,c])=>a!=="softDeleteScope"&&c!==void 0);return o.length===0?r:r.filter(a=>o.every(([c,i])=>this.matchesFilterValue(i,a[c])))}matchesFilterValue(e,s){if(e instanceof Date){if(s instanceof Date)return s.getTime()===e.getTime();if(typeof s=="string"||typeof s=="number"){const t=new Date(s);return Number.isNaN(t.getTime())?!1:t.getTime()===e.getTime()}return!1}return s===e}resolveSoftDeleteScope(e){if(typeof e!="string")return;const s=e.trim().toUpperCase();if(s==="ACTIVE")return"ACTIVE";if(s==="DELETED")return"DELETED";if(s==="ALL")return"ALL"}matchesSoftDeleteScope(e,s){if(e==="ALL")return!0;const t=s!=null;return e==="DELETED"?t:!t}}const me=n=>typeof n=="object"&&n!==null,bt=n=>me(n)?"start"in n||"end"in n:!1,yt=n=>n!==void 0,X=n=>n instanceof Date?n.toISOString():n,wt=n=>{if(typeof n!="string")return;const e=n.trim().toUpperCase();if(e==="ACTIVE")return"ACTIVE";if(e==="DELETED")return"DELETED";if(e==="ALL")return"ALL"};class Ct{constructor(e,s,t={}){E(this,"table");E(this,"supabase");E(this,"idColumn");E(this,"deletedAtColumn");E(this,"defaultSortColumn");E(this,"options");this.table=e,this.supabase=s,this.options=t,this.idColumn=t.idColumn??"id",this.deletedAtColumn=t.deletedAtColumn??"deletedAt",this.defaultSortColumn=t.defaultSortColumn??this.idColumn}resolveStatus(e){return typeof e=="number"&&Number.isFinite(e)?e:500}throwHttpError(e,s,t,r="Unknown error"){throw{status:this.resolveStatus(s),message:(e==null?void 0:e.message)||t||r}}assertNoError(e,s,t,r){e&&this.throwHttpError(e,s,t,r)}toDto(e){return this.options.mapRowToDto?this.options.mapRowToDto(e):e}toCommonDto(e){return this.options.mapRowToCommonDto?this.options.mapRowToCommonDto(e):e}toAddRow(e){return this.options.mapAddDtoToRow?this.options.mapAddDtoToRow(e):e}toUpdateRow(e){return this.options.mapUpdateDtoToRow?this.options.mapUpdateDtoToRow(e):e}toImportRow(e){return this.options.mapImportPreviewToRow?this.options.mapImportPreviewToRow(e):e}resolveObjectFilterValue(e){return"id"in e?X(e.id):""}applyFilters(e,s){if(!s)return e;let t=e;const r=wt(s.softDeleteScope);return r==="ACTIVE"?t=t.is(this.deletedAtColumn,null):r==="DELETED"&&(t=t.not(this.deletedAtColumn,"is",null)),Object.entries(s).forEach(([o,a])=>{if(o==="softDeleteScope"||a===void 0||a===null||a==="")return;const c=o==="deletedAt"?this.deletedAtColumn:o;if(Array.isArray(a)){const i=a.map(u=>u instanceof Date?u.toISOString():me(u)?this.resolveObjectFilterValue(u):X(u)).filter(yt);i.length>0&&(t=t.in(c,i));return}if(bt(a)){a.start!==void 0&&a.start!==""&&(t=t.gte(c,X(a.start))),a.end!==void 0&&a.end!==""&&(t=t.lte(c,X(a.end)));return}if(a instanceof Date){t=t.eq(c,a.toISOString());return}if(me(a)){t=t.eq(c,this.resolveObjectFilterValue(a));return}t=t.eq(c,X(a))}),t}async insert(e){const s=await this.supabase.from(this.table).insert(this.toAddRow(e)).select("*").single();return this.assertNoError(s.error,s.status,s.statusText,"Unable to insert"),s.data||this.throwHttpError(null,s.status,s.statusText,"Unable to insert"),this.toDto(s.data)}async insertMany(e){var o;e.length===0&&this.throwHttpError(null,400,void 0,"insertMany requires items");const s=e.map(a=>this.toAddRow(a)),t=await this.supabase.from(this.table).insert(s).select("*");this.assertNoError(t.error,t.status,t.statusText,"Unable to insert many rows");const r=(o=t.data)==null?void 0:o.at(-1);return r||this.throwHttpError(null,t.status,t.statusText,"Unable to insert many rows"),this.toDto(r)}async update(e){const s={[this.idColumn]:e.id},t=await this.supabase.from(this.table).update(this.toUpdateRow(e)).match(s).select("*").maybeSingle();return this.assertNoError(t.error,t.status,t.statusText,"Unable to update"),t.data||this.throwHttpError(null,404,t.statusText,`Record ${e.id} not found`),this.toDto(t.data)}async get(e,s){const t=(e==null?void 0:e.pageSize)??10,r=(e==null?void 0:e.currentPage)??0,o=String((e==null?void 0:e.sortingBy)??this.defaultSortColumn),a=String((e==null?void 0:e.sortingOrder)??"asc").toLowerCase()==="desc"?"desc":"asc",c=r*t,i=c+t-1;let u=this.supabase.from(this.table).select("*",{count:"exact"});u=this.applyFilters(u,s).order(o,{ascending:a==="asc"}).range(c,i);const m=await u;this.assertNoError(m.error,m.status,m.statusText,"Unable to load list");const h=(m.data??[]).map(g=>this.toDto(g)),f=m.count??h.length;return{sort:o,order:a,currentPage:r,pageSize:t,totalElements:f,totalPages:t>0?Math.ceil(f/t):0,items:h}}async export(e){let s=this.supabase.from(this.table).select("*");s=this.applyFilters(s,e);const t=await s;return this.assertNoError(t.error,t.status,t.statusText,"Unable to export"),(t.data??[]).map(r=>this.toDto(r))}async import(e){var o;if(e.items.length===0)return 0;const s=e.items.map(a=>this.toImportRow(a)),r=await(e.override?this.supabase.from(this.table).upsert(s,{onConflict:this.idColumn}).select(this.idColumn):this.supabase.from(this.table).insert(s).select(this.idColumn));return this.assertNoError(r.error,r.status,r.statusText,"Unable to import rows"),((o=r.data)==null?void 0:o.length)??0}async commonGet(e){let s=this.supabase.from(this.table).select("*");s=this.applyFilters(s,e);const t=await s;return this.assertNoError(t.error,t.status,t.statusText,"Unable to load common data"),(t.data??[]).map(r=>this.toCommonDto(r))}async getById(e){const s={[this.idColumn]:e},t=await this.supabase.from(this.table).select("*").match(s).maybeSingle();return this.assertNoError(t.error,t.status,t.statusText,"Unable to load item"),t.data||this.throwHttpError(null,404,t.statusText,`Record ${e} not found`),this.toDto(t.data)}async softDelete(e){var a,c,i;if(e.length===0)return 0;const s=((c=(a=this.options).nowFactory)==null?void 0:c.call(a).toISOString())??new Date().toISOString(),t=this.supabase.from(this.table).update({[this.deletedAtColumn]:s}),r=`(${e.join(",")})`,o=await t.filter(this.idColumn,"in",r).select(this.idColumn);return this.assertNoError(o.error,o.status,o.statusText,"Unable to soft delete"),((i=o.data)==null?void 0:i.length)??0}async restore(e){var o;if(e.length===0)return 0;const s=this.supabase.from(this.table).update({[this.deletedAtColumn]:null}),t=`(${e.join(",")})`,r=await s.filter(this.idColumn,"in",t).select(this.idColumn);return this.assertNoError(r.error,r.status,r.statusText,"Unable to restore"),((o=r.data)==null?void 0:o.length)??0}}const xt=n=>typeof n=="object"&&n!==null,St=(n,e)=>{if(xt(n))for(const s of e){const t=n[s];if(typeof t=="string"&&t.trim().length>0)return t.trim()}},Tt=(n,e)=>{if(!n)return e;const s=Number(n);return Number.isFinite(s)?s:e},he=(n,e)=>{const{defaultId:s=0,defaultUsername:t="",defaultEmail:r="",usernameMetadataKeys:o=["username","name","full_name"]}=e??{},a=St(n.user.user_metadata,o);return{id:Tt(n.user.id,s),username:a??t,email:n.user.email??r,token:n.access_token,refreshToken:n.refresh_token??null,accessTokenExpiresAt:typeof n.expires_at=="number"?new Date(n.expires_at*1e3).toISOString():null}};function kt(n){return Object.keys(n).filter(e=>isNaN(Number(e))).map(e=>({key:e,value:n[e]}))}const q=(n,e="")=>{const s=localStorage.getItem(n)??void 0;if(s&&e.length)switch(e){case"object":return JSON.parse(s);case"number":return Number(s);case"boolean":return s==="true"||s==="1";default:return s}return s},M=(n,e)=>localStorage.setItem(n,typeof e=="object"?JSON.stringify(e):e),D=n=>localStorage.removeItem(n);function Et(n){const e=n?new Date(n):new Date,s={weekday:"long",day:"numeric",month:"long",year:"numeric",hour:"numeric",minute:"2-digit",hour12:!0};return e.toLocaleString(navigator.language||"es-ES",s)}function vt(n){const e=n?new Date(n):new Date,s=String(e.getDate()).padStart(2,"0"),t=String(e.getMonth()+1).padStart(2,"0"),r=String(e.getFullYear()).slice(-2),o=String(e.getHours()).padStart(2,"0"),a=String(e.getMinutes()).padStart(2,"0");return`${s}/${t}/${r} ${o}:${a}`}function Nt(n){const e=n?new Date(n):new Date,s=e.getFullYear(),t=String(e.getMonth()+1).padStart(2,"0"),r=String(e.getDate()).padStart(2,"0"),o=String(e.getHours()).padStart(2,"0"),a=String(e.getMinutes()).padStart(2,"0");return`${s}-${t}-${r}T${o}:${a}`}const $e=()=>{var s;const n=navigator,e=((s=n==null?void 0:n.userAgentData)==null?void 0:s.platform)||(n==null?void 0:n.platform)||"";return/Mac|iPhone|iPod|iPad/i.test(e)};function oe(n){if(!n||typeof n!="object")return!1;const e=n;return Array.isArray(e.errors)&&e.errors.every(s=>Array.isArray(s)&&s.length===2&&typeof s[0]=="string")}function ae(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 At(n,e){return n!=null&&n.errors?n.errors.map(([s,t])=>e(s,t)):[]}const De=d.createContext(void 0);function jt(n){const{children:e}=n,s=d.useRef(0),[t,r]=d.useReducer((f,g)=>{const{type:p,items:y,id:b}=g;switch(p){case"set":return y??[];case"remove":return b!==void 0?f.filter(w=>w.id!==b):[]}return f},[],()=>[]),o=f=>f.map(g=>({...g,id:s.current++})),a=d.useCallback(f=>r({type:"set",items:o([{...f,type:F.error}])}),[]),c=d.useCallback(f=>r({type:"set",items:o([{...f}])}),[]),i=d.useCallback(f=>r({type:"set",items:o(f)}),[]),u=d.useCallback(f=>r({type:"set",items:o([{...f,type:F.success}])}),[]),m=f=>r({type:"remove",id:f}),h=d.useMemo(()=>({notification:t,removeNotification:m,showErrorNotification:a,showNotification:c,showSuccessNotification:u,showStackNotifications:i}),[t,a,c,i,u]);return l.jsx(De.Provider,{value:h,children:e})}const G=()=>{const n=d.useContext(De);if(!n)throw new Error("NotificationContext must be used within a Provider");return n},ie=()=>new P.QueryClient({defaultOptions:{queries:{refetchInterval:!1,refetchOnMount:!0,refetchOnReconnect:!1,retry:!1,retryOnMount:!0,refetchOnWindowFocus:!1}}}),$t=ie(),Re=d.createContext(void 0),Dt=n=>{const{children:e,manager:s,queryClient:t}=n,[r]=d.useState(ie),o=t??r;return l.jsx(Re.Provider,{value:{client:s},children:l.jsx(P.QueryClientProvider,{client:o,children:e})})},Le=()=>{const n=d.useContext(Re);if(!n)throw new Error("managerContext must be used within a Provider");return n.client},ce=d.createContext(void 0),Ie=()=>{const n=d.useContext(ce);if(!n)throw new Error("authContext must be used within a Provider");return n},Rt=n=>{const{children:e,guestMode:s="guest_mode",user:t="user",remember:r="remember",refreshTokenKey:o="refreshToken",accessTokenExpiresAtKey:a="accessTokenExpiresAt"}=n,c=Le(),[i,u]=d.useState({}),m=d.useCallback(()=>{D(t),D(r),D(o),D(a)},[a,o,r,t]),h=d.useCallback(()=>!!q(s,"boolean")&&i.token===void 0,[i.token,s]),f=d.useCallback(w=>{M(s,w)},[s]),g=d.useCallback((w,S)=>{if(!w)return;const x=q(r,"boolean"),k=S??(typeof x=="boolean"?x:!1);u(w),D(s),M(t,w.token),M(r,k),typeof w.refreshToken=="string"&&w.refreshToken.length?M(o,w.refreshToken):D(o),typeof w.accessTokenExpiresAt=="string"&&w.accessTokenExpiresAt.length?M(a,w.accessTokenExpiresAt):D(a)},[a,s,o,r,t]),p=d.useCallback(async()=>{const w=q(t)??i.token,S=q(o)??(typeof i.refreshToken=="string"?i.refreshToken:void 0);try{await c.Auth.logout({accessToken:w,refreshToken:S})}catch(x){console.error(x)}u({}),m()},[i.refreshToken,i.token,m,c.Auth,o,t]),y=d.useCallback(async()=>{try{const w=await c.Auth.getSession();g(w)}catch(w){console.error(w),p()}},[g,p,c.Auth]),b=d.useMemo(()=>({account:i,logUser:g,logoutUser:p,logUserFromLocal:y,isInGuestMode:h,setGuestMode:f}),[i,g,p,y,h,f]);return l.jsx(ce.Provider,{value:b,children:e})},pe=()=>Ie(),ge=d.createContext(void 0),Pe=()=>{const n=d.useContext(ge);if(!n)throw new Error("supabaseManagerContext must be used within a Provider");return n.client},Lt=n=>{const{children:e,guestMode:s="guest_mode",user:t="user",remember:r="remember",refreshTokenKey:o="refreshToken",accessTokenExpiresAtKey:a="accessTokenExpiresAt",sessionMapper:c}=n,i=Pe(),u=d.useRef(c??he);d.useEffect(()=>{u.current=c??he},[c]);const[m,h]=d.useState({}),f=d.useCallback(()=>{D(t),D(r),D(o),D(a)},[a,o,r,t]),g=d.useCallback(()=>!!q(s,"boolean")&&m.token===void 0,[m.token,s]),p=d.useCallback(x=>{M(s,x)},[s]),y=d.useCallback((x,k)=>{if(!x)return;const v=q(r,"boolean"),_=k??(typeof v=="boolean"?v:!1);h(x),D(s),M(t,x.token),M(r,_),typeof x.refreshToken=="string"&&x.refreshToken.length?M(o,x.refreshToken):D(o),typeof x.accessTokenExpiresAt=="string"&&x.accessTokenExpiresAt.length?M(a,x.accessTokenExpiresAt):D(a)},[a,s,o,r,t]),b=d.useCallback(async()=>{try{await i.auth.signOut()}catch(x){console.error(x)}h({}),f()},[f,i.auth]),w=d.useCallback(async()=>{try{const{data:x,error:k}=await i.auth.getSession();if(k)throw k;if(!x.session){h({}),f();return}y(u.current(x.session))}catch(x){console.error(x),await b()}},[f,y,b,i.auth]);d.useEffect(()=>{let x=!0;(async()=>{x&&await w()})();const{data:v}=i.auth.onAuthStateChange((_,Q)=>{if(x){if(!Q){h({}),f();return}y(u.current(Q))}});return()=>{x=!1,v.subscription.unsubscribe()}},[f,y,w,i.auth]);const S=d.useMemo(()=>({account:m,logUser:y,logoutUser:b,logUserFromLocal:w,isInGuestMode:g,setGuestMode:p}),[m,y,b,w,g,p]);return l.jsx(ce.Provider,{value:S,children:e})},It=n=>{const{children:e,supabase:s,queryClient:t}=n,[r]=d.useState(ie),o=t??r;return l.jsx(ge.Provider,{value:{client:s},children:l.jsx(P.QueryClientProvider,{client:o,children:e})})},Fe=d.createContext({}),Pt=n=>{const{children:e,location:s,navigate:t,linkComponent:r,searchComponent:o}=n;return l.jsx(Fe.Provider,{value:{location:s,navigate:t,linkComponent:r,searchComponent:o},children:e})},Y=()=>{const n=d.useContext(Fe);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},Ft={addChildItem:()=>{},removeChildItem:()=>{},clearDynamicItems:()=>{},dynamicItems:{}},be=d.createContext(Ft),Mt=n=>{const{children:e}=n,[s,t]=d.useState({}),r=d.useCallback((i,u)=>t(m=>({...m,[i]:[...m[i]??[],u]})),[]),o=d.useCallback((i,u)=>t(m=>({...m,[i]:(m[i]??[]).filter((h,f)=>f!==u)})),[]),a=d.useCallback(i=>{t(i?u=>({...u,[i]:[]}):{})},[]),c=d.useMemo(()=>({dynamicItems:s,addChildItem:r,removeChildItem:o,clearDynamicItems:a}),[s,a,o,r]);return l.jsx(be.Provider,{value:c,children:e})},Me=()=>d.useContext(be);function _t(n){const{t:e}=C.useTranslation(),{open:s,onClose:t,menuMap:r,logo:o}=n,{account:a}=pe(),{dynamicItems:c}=Me(),{linkComponent:i,location:u}=Y(),m=i,h=d.useMemo(()=>r.filter(b=>{const w=b.auth,S=!!(a!=null&&a.email);return w==null||w&&S||!w&&!S}),[a==null?void 0:a.email,r]),f=d.useCallback(b=>{b.key==="Escape"&&s&&t()},[t,s]);d.useEffect(()=>(document.addEventListener("keydown",f),()=>{document.removeEventListener("keydown",f)}),[f]);const g=d.useCallback((b,w)=>w?b===`${u.pathname}${u.search}`:b===u.pathname,[u.pathname,u.search]),p=d.useCallback(b=>l.jsx("li",{className:`drawer-list-item-child ${g(b.path,!0)?"active":""} animated`,children:b.path?l.jsx(m,{tabIndex:s?0:-1,to:b.path??"/","aria-label":e(`_accessibility:ariaLabels.${b.id}`,{defaultValue:b.label}),className:"drawer-link",children:b.label}):b.label},b.id),[m,s,e,g]),y=d.useMemo(()=>h.map((b,w)=>{const S=b.page??String(w),x=`drawer-list-item ${g(b.path)?"active":""} animated`;if(b.type==="divider")return l.jsx("li",{className:x,children:l.jsx("hr",{className:"drawer-divider"})},S);const k=b.children??(b.page&&c?c[b.page]:null);return l.jsxs("li",{className:x,children:[l.jsxs(m,{tabIndex:s?0:-1,to:b.path??"/","aria-label":e(`_accessibility:ariaLabels.${String(b.page)}`,{defaultValue:e(`_pages:${String(b.page)}.title`)}),className:"drawer-link",children:[b.icon,e(`_pages:${b.page}.title`)]}),k&&l.jsx("ul",{className:"drawer-children-list",children:k.map(p)})]},S)}),[m,c,g,s,h,p,e]);return l.jsx("div",{"aria-label":e("_accessibility:ariaLabels.closeMenu"),"aria-disabled":!s,className:`${s?"opened":"closed"} drawer-backdrop`,onClick:()=>t(),children:l.jsxs("aside",{className:`${s?"opened":"closed"} drawer animated`,children:[l.jsxs("div",{className:"drawer-header-container",children:[o,l.jsx("h2",{className:"drawer-header poppins",children:e("_pages:home.appName")})]}),l.jsx("ul",{className:"drawer-menu-list",children:y})]})})}const B=({icon:n,...e})=>l.jsx(C.IconButton,{icon:l.jsx(K.FontAwesomeIcon,{icon:n}),...e});var ue,Te;function Ot(){if(Te)return ue;Te=1;const n=(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(m=>{const[h,f]=m.split("=");i[h]=f}),i},s=(c="")=>{if(o(c)&&c.length)return o(c);{let i=navigator.language||navigator.userLanguage;if(i.indexOf("en")<0&&i.indexOf("es")<0&&(i="en-US"),i=i.split("-")[0],i)return c.length&&r(c,730,i),i}return"en"},t=(c=0,i=0,u=window,m="smooth")=>u.scroll({top:c,left:i,behavior:m}),r=(c,i,u,m="/",h="Lax")=>{var f=new Date;f.setTime(f.getTime()+i*24*60*60*1e3);const g="; expires="+f.toUTCString();document.cookie=`${c}=${u||""}${g};path=${m};SameSite=${h}`},o=c=>{const i=`${c}=`,m=decodeURIComponent(document.cookie).split(";");for(let h=0;h<m.length;h+=1){let f=m[h];for(;f.charAt(0)===" ";)f=f.substring(1);if(f.indexOf(i)===0)return f.substring(i.length,f.length)}return""};return ue={getCookie:o,createCookie:r,deleteCookie:c=>document.cookie=`${c}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`,getUserLanguage:s,scrollTo:t,parseQueries:e,validation:n},ue}var Ut=Ot();function Kt(){const{t:n,language:e}=C.useTranslation();return{timeAge:d.useCallback(t=>{const o=new Date-t,a=Math.floor(o/(1e3*60)),c=Math.floor(a/60),i=e==="es",u=n("_accessibility:labels.ago"),m=n("_accessibility:labels.minute"),h=n("_accessibility:labels.minutes"),f=n("_accessibility:labels.hour"),g=n("_accessibility:labels.hours"),p=n("_accessibility:labels.yesterday"),y=n("_accessibility:labels.justNow");return o<1e3*60?y:a<60?`${i?u:""} ${a} ${a===1?m:h} ${i?"":u}`:c<24?`${i?u:""} ${c} ${c===1?f:g} ${i?"":u}`:c<48?p:t.toLocaleDateString(navigator.language||"es-ES",{day:"2-digit",month:"2-digit",year:"numeric"})},[n,e])}}const ye=n=>{const{showSuccessNotification:e}=G(),{mutationFn:s,onError:t,onSuccess:r,onSuccessMessage:o}=n,[a,c]=d.useState([]),{open:i,handleClose:u,handleOpen:m}=we(),h=()=>{u(),c([])},f=async p=>{c(p),m()},g=P.useMutation({mutationFn:()=>s(Array.isArray(a)?a:[a]),onError:p=>{console.error(p),t&&t(p),h()},onSuccess:async p=>{r&&r(p),e({message:o}),h()}});return{open:i,onClick:f,close:h,dialogFn:g,isLoading:g.isPending}},Qt=n=>{const{t:e}=C.useTranslation(),{showStackNotifications:s,showSuccessNotification:t,showErrorNotification:r}=G(),o=P.useQueryClient(),{defaultValues:a,mutationFn:c,formToDto:i,onError:u,onSuccess:m,queryKey:h,onSuccessMessage:f}=n,{control:g,handleSubmit:p,reset:y,setError:b,getValues:w,setValue:S}=ve.useForm({defaultValues:a}),x=d.useRef(null),k=d.useCallback(()=>{const T=document.activeElement;if(!(T instanceof HTMLElement)){x.current=null;return}x.current=T.closest("form")},[]),v=d.useCallback(T=>{const N=T==null?void 0:T.errors,A=[],L=x.current;if(!L)return A;let O=!1;return N&&N.forEach(([ee,W])=>{const U=L.querySelector(`[name="${ee}"]`);(U instanceof HTMLInputElement||U instanceof HTMLTextAreaElement||U instanceof HTMLSelectElement)&&(O||(U.focus(),O=!0),U.classList.add("error"),A.push(e(`_entities:${h}.${ee}.${W}`)))}),A},[e,h]),_=d.useCallback(()=>{const T=x.current;if(!T)return;T.querySelectorAll("input, textarea, select").forEach(A=>{A.classList.remove("error")})},[]),Q=P.useMutation({mutationFn:c,onError:T=>{console.error(T);const N=T;if(u)u(T);else if(oe(N)){const A=v(N);s(A.map(L=>({message:L,type:F.error})))}else if(ae(N)){const A=N.message||e("_accessibility:errors.500"),L=e(`_accessibility:errors.${N.status}`);r({message:L||A})}else r({message:e("_accessibility:errors.500")})},onSuccess:async T=>{await o.invalidateQueries({queryKey:h}),m&&m(T),f&&t({message:f})}});return{control:g,getValues:w,setValue:S,handleSubmit:p,onSubmit:T=>{k(),_(),Q.mutate(i?i(T):T)},reset:y,setError:b,isLoading:Q.isPending}},_e=n=>{const{t:e}=C.useTranslation(),{onClick:s,icon:t=R.faTrash,sticky:r=!0,hidden:o=!1,multiple:a=!0,disabled:c=!1,id:i=H.Delete,tooltip:u=e("_pages:common.actions.delete.text")}=n;return{action:d.useCallback(h=>({id:i,sticky:r,tooltip:u,multiple:a,onClick:()=>s([h==null?void 0:h.id]),hidden:!!h.deletedAt||o,disabled:!!h.deletedAt||c,icon:l.jsx(K.FontAwesomeIcon,{className:"text-bg-error",icon:t}),onMultipleClick:f=>s(f.map(g=>g.id))}),[c,o,t,i,a,s,r,u])}},Oe=n=>{const{t:e}=C.useTranslation(),{onClick:s,sticky:t=!0,hidden:r=!1,disabled:o=!1,multiple:a=!1,icon:c=R.faRotateLeft,id:i=H.Restore,tooltip:u=e("_pages:common.actions.restore.text")}=n;return{action:d.useCallback(h=>({id:i,sticky:t,tooltip:u,multiple:a,onClick:()=>s([h==null?void 0:h.id]),hidden:!h.deletedAt||r,disabled:!h.deletedAt||o,icon:l.jsx(K.FontAwesomeIcon,{className:"text-bg-error",icon:c}),onMultipleClick:f=>s(f.map(g=>g.id))}),[o,r,c,i,a,s,t,u])}},qt=n=>{const{t:e}=C.useTranslation(),{onClick:s,hidden:t=!1,sticky:r=!0,disabled:o=!1,id:a=H.Edit,icon:c=R.faPencil,tooltip:i=e("_pages:common.actions.edit.text")}=n;return{action:d.useCallback(m=>({id:a,sticky:r,tooltip:i,onClick:()=>s(m==null?void 0:m.id),hidden:!!m.deletedAt||t,disabled:!!m.deletedAt||o,icon:l.jsx(K.FontAwesomeIcon,{className:"primary",icon:c})}),[o,t,c,a,s,r,i])}};var H=(n=>(n.Add="add",n.Edit="edit",n.Delete="delete",n.Restore="restore",n.Refresh="refresh",n.Export="export",n.Import="import",n))(H||{});const Ue=n=>{const{t:e}=C.useTranslation(),{onClick:s,hidden:t=!1,disabled:r=!1,isLoading:o=!1}=n;return{action:d.useCallback(()=>({id:H.Export,hidden:t,disabled:r,icon:l.jsx(K.FontAwesomeIcon,{className:`${o?"rotate":""}`,icon:o?R.faCircleNotch:R.faCloudArrowDown}),tooltip:e("_pages:common.actions.export.text"),onClick:s}),[r,t,o,s,e])}},Ke=n=>{const{t:e}=C.useTranslation(),{onClick:s,hidden:t=!1,disabled:r=!1,isLoading:o=!1}=n;return{action:d.useCallback(()=>({id:H.Import,hidden:t,disabled:r,icon:l.jsx(K.FontAwesomeIcon,{className:`${o?"rotate":""}`,icon:o?R.faCircleNotch:R.faCloudUpload}),tooltip:e("_pages:common.actions.import.text"),onClick:s}),[r,t,o,s,e])}},Bt=n=>{const{queryKey:e,onSuccess:s,...t}=n,r=P.useQueryClient(),{showStackNotifications:o}=G(),{t:a}=C.useTranslation(),{open:c,onClick:i,close:u,dialogFn:m,isLoading:h}=ye({onSuccessMessage:a("_pages:common.actions.delete.successMessage"),onError:g=>{const p=g;if(oe(p))o(p.errors.map(([y,b])=>({message:a(`_pages:${y}.errors.${b}`),type:F.error})));else if(ae(p)){const y=p.message||a("_accessibility:errors.500"),b=a(`_accessibility:errors.${p.status}`);o([{message:b||y,type:F.error}])}},onSuccess:async g=>{await r.invalidateQueries({queryKey:e}),s&&s(g)},...t}),{action:f}=_e({onClick:i});return{onClick:i,title:a("_pages:common.actions.delete.dialog.title"),open:c,isLoading:h,handleSubmit:()=>m.mutate(),handleClose:u,action:f}},we=()=>{const[n,e]=d.useState(!1);return{open:n,setOpen:e,handleClose:()=>e(!1),handleOpen:()=>e(!0)}},Ce=n=>{const{closeOnSubmit:e=!0,defaultValues:s,mapIn:t,mapOut:r,mode:o="state",onApply:a,onClear:c,onError:i,onSubmit:u,reinitializeOnOpen:m,resetOnOpen:h,title:f}=n,[g,p]=d.useState(),[y,b]=d.useState(!1),w=d.useRef(!1),S=d.useRef(null),{open:x,handleClose:k,handleOpen:v}=we(),{control:_,handleSubmit:Q,reset:T,setError:N,getValues:A,setValue:L}=ve.useForm({defaultValues:s||{}});d.useEffect(()=>{if(!x){w.current=!1,S.current=null;return}if(!w.current){if(w.current=!0,S.current){T(S.current),S.current=null;return}if(m&&t){T(t());return}if(m&&s){T(s);return}h&&T(s||{})}},[s,t,x,m,T,h]);const O=d.useCallback(()=>{k(),T()},[k,T]),ee=d.useCallback(j=>{let $,z;typeof j=="number"||j==null?$=j:($=j.id,z=j.values),p($),z?x?T(z):S.current=z:S.current=null,x||v()},[v,x,T]),W=d.useCallback(j=>r?r(j,{id:g}):j,[g,r]),U=d.useCallback(async(j,$,z)=>{i&&await i(j,{close:O,id:g,phase:$,values:z})},[O,g,i]),We=d.useCallback(async()=>{if(!a)return;const j=A();b(!0);try{const $=W(j);await a($,{close:O,id:g,values:j})}catch($){throw await U($,"apply",j).catch(()=>{}),$}finally{b(!1)}},[O,A,U,g,W,a]),ze=d.useCallback(async()=>{const j=A();if(c){b(!0);try{await c()}catch($){throw await U($,"clear",j).catch(()=>{}),$}finally{b(!1)}}try{T(s||{})}catch($){throw await U($,"clear",j).catch(()=>{}),$}},[s,A,U,c,T]),Je=d.useCallback(async j=>{b(!0);try{const $=W(j);u&&await u($,{close:O,id:g,values:j}),e&&O()}catch($){throw await U($,"submit",j).catch(()=>{}),$}finally{b(!1)}},[O,e,U,g,W,u]);return{open:x,mode:o,id:g,openDialog:ee,handleClose:O,control:_,getValues:A,setValue:L,handleSubmit:Q,onSubmit:Je,reset:T,setError:N,title:f,isSubmitting:y,onApply:We,onClear:ze,isLoading:y}},Ht=n=>{const e=P.useQueryClient(),{mutationFn:s,queryKey:t,onSuccess:r,onError:o,mapOut:a,...c}=n,i=P.useMutation({mutationFn:s});return Ce({...c,mode:"entity",mapOut:a,onSubmit:async u=>{try{const m=await i.mutateAsync(u);t&&await e.invalidateQueries({queryKey:t}),r&&await r(m)}catch(m){throw o&&o(m),m}}})},Vt=n=>{const e=P.useQueryClient(),s=d.useRef(),t=d.useRef(),{mutationFn:r,queryKey:o,onSuccess:a,onError:c,mapOut:i,getFunction:u,dtoToForm:m,title:h,...f}=n,g=d.useRef(m);d.useEffect(()=>{g.current=m},[m]);const p=P.useMutation({mutationFn:r}),y=Ce({...f,mode:"entity",title:h,onSubmit:async x=>{try{const k=await p.mutateAsync(x);o&&await e.invalidateQueries({queryKey:o}),a&&await a(k)}catch(k){throw c&&c(k),k}},mapOut:x=>i?i(x,s.current):x}),{reset:b}=y,w=o||["put-dialog",h],S=P.useQuery({queryFn:()=>u(y.id),queryKey:[...w,y.id],enabled:y.open&&!!y.id});return d.useEffect(()=>{if(S.data&&t.current!==S.data){if(s.current=S.data,t.current=S.data,g.current&&b){b(g.current(S.data));return}b==null||b(S.data)}},[S.data,b]),{...y,isLoading:y.isLoading||p.isPending||S.isFetching||S.isLoading}},Gt=n=>{const{queryKey:e,onSuccess:s,...t}=n,r=P.useQueryClient(),{showStackNotifications:o}=G(),{t:a}=C.useTranslation(),{open:c,onClick:i,close:u,dialogFn:m,isLoading:h}=ye({onSuccessMessage:a("_pages:common.actions.restore.successMessage"),onError:g=>{const p=g;if(oe(p))o(p.errors.map(([y,b])=>({message:a(`_pages:${y}.errors.${b}`),type:F.error})));else if(ae(p)){const y=p.message||a("_accessibility:errors.500"),b=a(`_accessibility:errors.${p.status}`);o([{message:b||y,type:F.error}])}},onSuccess:async g=>{await r.invalidateQueries({queryKey:e}),s&&s(g)},...t}),{action:f}=Oe({onClick:i});return{onClick:i,title:a("_pages:common.actions.restore.dialog.title"),open:c,isLoading:h,handleSubmit:()=>m.mutate(),handleClose:u,action:f}};function Wt(n){const{t:e}=C.useTranslation(),s=P.useQueryClient(),{queryKey:t,mutationFn:r,entity:o,fileProcessor:a,renderCustomPreview:c,onError:i}=n,[u,m]=d.useState(!1),[h,f]=d.useState(null),[g,p]=d.useState(!1),y=P.useMutation({mutationFn:r,onError:w=>{console.error(w),i==null||i(w)},onSuccess:async()=>{await s.invalidateQueries({queryKey:t})}}),{action:b}=Ke({onClick:()=>m(!0)});return{handleSubmit:async()=>{if(!(!h||h.length===0))try{await y.mutateAsync({items:h,override:g}),m(!1),f(null),p(!1)}catch(w){console.error(w)}},isLoading:y.isPending,fileProcessor:a,onFileProcessed:w=>f(w),renderCustomPreview:c,onOverrideChange:w=>p(w),open:u,title:e("_pages:common.actions.import.dialog.title",{entity:e(`_pages:${o}.title`)}),handleClose:()=>{m(!1),f(null),p(!1)},action:b}}const zt=n=>{const{showSuccessNotification:e}=G(),{t:s}=C.useTranslation(),{entity:t,mutationFn:r,onError:o,onSuccess:a,onSuccessMessage:c=s("_pages:common.actions.export.successMessage")}=n,i=P.useMutation({mutationFn:()=>r(),onError:h=>{console.error(h),o&&o(h)},onSuccess:async h=>{const f=JSON.stringify(h,null,2),g=new Blob([f],{type:"application/json"}),p=URL.createObjectURL(g),y=document.createElement("a");y.href=p,y.download=`${t}.json`,y.click(),URL.revokeObjectURL(p),a&&a(h),e({message:c})}}),u=d.useCallback(()=>{i.mutate()},[i]),{action:m}=Ue({onClick:u,isLoading:i.isPending});return{action:m}},ke=()=>typeof window<"u"?window.scrollY:0;function Qe(n){const[e,s]=d.useState(ke),t=d.useCallback(()=>{s(ke())},[]);return d.useEffect(()=>(window.addEventListener("scroll",t),()=>{window.removeEventListener("scroll",t)}),[t]),e>n}const Jt=n=>{const{t:e}=C.useTranslation(),{icon:s=R.faArrowUp,threshold:t=200,scrollTop:r=0,scrollLeft:o=0,tooltip:a=e("_accessibility:buttons.toTop"),scrollOnClick:c=!0,onClick:i,className:u="",variant:m="submit",color:h="primary",...f}=n,g=Qe(t),p=()=>{i==null||i(),c&&Ut.scrollTo(o,r)};return l.jsx(B,{variant:m,color:h,icon:s,"data-tooltip-id":"tooltip",onClick:p,className:`to-top ${g?"show":"hide"} ${u}`.trim(),"data-tooltip-content":a,...f})};function Yt(n){const{t:e}=C.useTranslation();if("children"in n){const{children:k,className:v}=n;return l.jsx("div",{className:`error-container${v?` ${v}`:""}`,children:k})}const{error:t,message:r,iconProps:o,onRetry:a,retryLabel:c,retryButtonProps:i,messageProps:u,className:m,resetErrorBoundary:h}=n,f=a??h,{className:g,children:p,onClick:y,...b}=i??{},{className:w,...S}=u??{},x=o!==null;return l.jsxs("div",{className:`error-container${m?` ${m}`:""}`,children:[x&&l.jsx(K.FontAwesomeIcon,{...o,icon:(o==null?void 0:o.icon)??Ze.faSadTear,className:`error-icon${o!=null&&o.className?` ${o.className}`:""}`}),l.jsx("p",{...S,className:`error-message${w?` ${w}`:""}`,children:r??(t==null?void 0:t.message)??e("_accessibility:errors.unknownError")}),f&&l.jsx(C.Button,{type:"button",variant:"submit",color:"primary",...b,className:`error-retry ${g?` ${g}`:""}`,onClick:k=>{y==null||y(k),k.defaultPrevented||f()},children:p??c??e("_accessibility:actions.retry",{defaultValue:"Retry"})})]})}const Xt=n=>{const{showBackButton:e,title:s,actions:t}=n,{t:r}=C.useTranslation(),{navigate:o}=Y();return l.jsxs("div",{className:"page-header",children:[l.jsxs("div",{className:"page-header-left",children:[e&&l.jsx(B,{icon:R.faArrowLeft,onClick:()=>o(-1),className:"page-header-back",name:r("_accessibility:buttons.back"),"data-tooltip-id":"tooltip","data-tooltip-content":r("_accessibility:buttons.back")}),l.jsx("h2",{className:"page-header-title",children:s})]}),l.jsxs("div",{children:[l.jsx(C.Actions,{className:"page-header-actions-desktop",actions:t??[]}),l.jsx(C.ActionsDropdown,{className:"page-header-actions-mobile",actions:t??[]})]})]})},Zt=n=>{const{title:e,children:s,addOptions:t,filterOptions:r,actions:o,queryKey:a,isLoading:c=!1,isAnimated:i=!0,showBackButton:u=!1}=n,{t:m}=C.useTranslation(),h=P.useQueryClient(),{countOfFilters:f}=C.useTableOptions(),g=d.useMemo(()=>{const p=Array.isArray(o)?[...o]:[];if(a){const y={id:H.Refresh,onClick:()=>h.invalidateQueries({queryKey:a}),icon:l.jsx(K.FontAwesomeIcon,{icon:R.faRotateLeft}),tooltip:m("_pages:common.actions.refresh.text")};p.unshift(y)}if(t){const y={...t,id:H.Add,icon:l.jsx(K.FontAwesomeIcon,{icon:R.faAdd})};p.unshift(y)}if(r){const y={...r,id:"filter",icon:l.jsx(K.FontAwesomeIcon,{icon:R.faFilter}),children:l.jsx(C.Badge,{className:`${f>0?"show":"hide"} `,count:f})};p.push(y)}return p},[o,t,f,r,h,a,m]);return l.jsxs("main",{className:"page-main",children:[l.jsx(Xt,{showBackButton:u,actions:g,title:e}),l.jsx("div",{className:`page-main-content ${i?"appear":""}`,children:c?l.jsx(C.Loading,{className:"page-loading"}):s}),t&&l.jsx(B,{icon:t.icon??R.faAdd,color:t.color??"primary",variant:t.variant??"submit",onClick:()=>{var p;return(p=t.onClick)==null?void 0:p.call(t)},className:`button page-fab ${t.className??""}`})]})},es=n=>{const{t:e}=C.useTranslation(),{className:s="",itemClassName:t="",loading:r=!1,emptyComponent:o=null,emptyMessage:a=e("_accessibility:messages.empty"),renderComponent:c,data:i=[],hasMore:u=!1,loadingMore:m=!1,onLoadMore:h,loadMoreComponent:f=null,observerRootMargin:g="0px 0px 200px 0px",observerThreshold:p=0}=n,y=d.useRef(!1),b=d.useRef(null),w=d.useCallback(async()=>{if(!(!u||!h)&&!(m||y.current)){y.current=!0;try{await h()}finally{y.current=!1}}},[u,m,h]);return d.useEffect(()=>{if(!u||!h||!b.current||typeof IntersectionObserver>"u")return;const S=new IntersectionObserver(x=>{x.some(k=>k.isIntersecting)&&w()},{rootMargin:g,threshold:p});return S.observe(b.current),()=>S.disconnect()},[u,h,g,p,w]),r?l.jsx(C.Loading,{}):l.jsx(l.Fragment,{children:i!=null&&i.length?l.jsxs("ul",{className:`pretty-grid-main ${s}`,children:[i==null?void 0:i.map(S=>l.jsx("li",{className:`pretty-grid-item ${t}`,children:c(S)},S.id)),u&&h&&l.jsx("li",{className:"pretty-grid-load-more",ref:b,children:f})]}):l.jsx(l.Fragment,{children:o||l.jsx(Ge,{message:a})})})},xe=d.createContext({title:"",setTitle:()=>{},rightContent:null,setRightContent:()=>{}}),ts=n=>{const{children:e}=n,[s,t]=d.useState(""),[r,o]=d.useState(null),a=d.useCallback(u=>{t(u)},[]),c=d.useCallback(u=>{o(u)},[]),i=d.useMemo(()=>({title:s,setTitle:a,rightContent:r,setRightContent:c}),[s,a,r,c]);return l.jsx(xe.Provider,{value:i,children:e})},qe=()=>d.useContext(xe);function ss(n){const{t:e}=C.useTranslation(),{openDrawer:s,showSearch:t=!0,menuButtonProps:r}=n,{searchComponent:o,location:a}=Y(),{title:c,rightContent:i}=qe(),[u,m]=d.useState(!1),h=d.useCallback(p=>{($e()?p.metaKey:p.ctrlKey)&&p.shiftKey&&p.key.toLowerCase()==="f"&&(m(!0),p.preventDefault())},[]);d.useEffect(()=>(window.addEventListener("keydown",h),()=>{window.removeEventListener("keydown",h)}),[h]);const f=o,g=t&&!!f;return l.jsxs(l.Fragment,{children:[a.pathname!=="/"&&!!f&&l.jsx(f,{open:u,onClose:()=>m(!1)}),l.jsxs("header",{id:"header",className:"header",children:[l.jsxs("div",{className:"navbar-left",children:[l.jsx(B,{...r,type:(r==null?void 0:r.type)??"button",icon:(r==null?void 0:r.icon)??R.faBars,onClick:p=>{var y;(y=r==null?void 0:r.onClick)==null||y.call(r,p),s()},name:(r==null?void 0:r.name)??e("_accessibility:buttons.openMenu"),"aria-label":(r==null?void 0:r["aria-label"])??e("_accessibility:ariaLabels.openMenu"),className:`navbar-menu animated ${(r==null?void 0:r.className)??""}`}),l.jsx("h1",{className:"poppins navbar-title",children:c||e("_pages:home.appName")})]}),l.jsxs("div",{className:"navbar-right",children:[i,g&&l.jsx(B,{icon:R.faSearch,className:"navbar-search-btn",onClick:()=>m(!0)})]})]})]})}const te=300,ns=n=>n??F.error,rs=n=>{switch(n){case F.error:return R.faWarning;default:return R.faCircleCheck}},de=n=>{switch(n){case F.success:return"!text-success";case F.error:return"!text-error";case F.warning:return"!text-warning";default:return"!text-info"}},os=n=>{switch(n){case F.success:return"bg-bg-success";case F.error:return"bg-bg-error";case F.warning:return"bg-bg-warning";default:return"bg-bg-info"}};function as(){const{t:n}=C.useTranslation(),{notification:e,removeNotification:s}=G(),[t,r]=d.useState([]),o=d.useRef(t);d.useLayoutEffect(()=>{o.current=t});const a=d.useRef(null),c=d.useCallback(i=>{r(u=>i!==void 0?u.map(m=>m.id===i?{...m,closing:!0}:m):u.map(m=>({...m,closing:!0}))),i!==void 0?setTimeout(()=>{s(i),r(u=>u.filter(m=>m.id!==i))},te):(a.current&&clearTimeout(a.current),a.current=setTimeout(()=>{s(),r([]),a.current=null},te))},[s]);return d.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(g=>g.map(p=>({...p,closing:!0}))),i=null},0),a.current=setTimeout(()=>{r([]),a.current=null},te),u);const m=new Set(o.current.map(g=>g.id));if(!e.some(g=>g.id!==void 0&&!m.has(g.id)))return;if(o.current.length===0){const g=[...e];return i=setTimeout(()=>{r(g.map(p=>({...p,closing:!1}))),i=null},0),()=>{i&&clearTimeout(i)}}a.current&&clearTimeout(a.current),i=setTimeout(()=>{r(g=>g.every(p=>p.closing)?g:g.map(p=>({...p,closing:!0}))),i=null},0);const f=[...e];return a.current=setTimeout(()=>{r(f.map(g=>({...g,closing:!1}))),a.current=null},te),u},[e]),d.useEffect(()=>{if(!t.length)return;let i;const u=window.setTimeout(()=>{i=()=>c(),window.addEventListener("click",i)},0),m=h=>{h.key==="Escape"&&c()};return window.addEventListener("keydown",m),()=>{window.clearTimeout(u),i&&window.removeEventListener("click",i),window.removeEventListener("keydown",m)}},[t.length,c]),Ee.createPortal(l.jsx("div",{className:`notification-portal ${t.length?"active":""}`,children:t.map(({id:i,type:u,message:m,closing:h})=>{const f=ns(u);return l.jsxs("div",{className:`notification ${h?"closing":""} ${os(f)}`,onClick:g=>g.stopPropagation(),children:[l.jsxs("div",{className:"notification-body",children:[l.jsx(K.FontAwesomeIcon,{icon:rs(f),className:`notification-icon ${de(f)}`}),l.jsx("p",{className:`notification-text ${de(f)}`,children:m})]}),l.jsx(B,{type:"button",icon:R.faClose,color:"error",className:"notification-close group",onClick:g=>{g.stopPropagation(),i!==void 0&&c(i)},iconClassName:`${de(f)} notification-close-icon`,name:n("_accessibility:buttons.closeNotification"),"aria-label":n("_accessibility:ariaLabels.closeNotification")})]},i)})}),document.body)}function is(n){const{className:e,...s}=n;return l.jsx("div",{className:"splash-screen",children:l.jsx(C.Loading,{className:`blur-appear ${e?` ${e}`:""}`,...s})})}const Be=n=>{const{id:e,active:s,onClick:t,children:r,to:o,useLinks:a=!0,tabButtonProps:c}=n,{linkComponent:i}=Y(),u=i;if(!a){const{className:h="",variant:f=s?"submit":"outlined",color:g=s?"primary":"default",...p}=c??{};return l.jsx(C.Button,{type:"button",variant:f,color:g,className:`tab ${h}`,onClick:t,...p,children:r})}const m=`button submit tab ${s?"primary":"outlined"} ${(c==null?void 0:c.className)??""}`.trim();return l.jsx(u,{to:o??`#${e}`,onClick:()=>t(),className:m,children:r})},He=n=>{var g;const{tabs:e=[],defaultTab:s,currentTab:t,onTabChange:r,className:o="",tabsContainerClassName:a="",useLinks:c=!0,tabButtonProps:i}=n,[u,m]=d.useState(s??((g=e[0])==null?void 0:g.id)),h=t??u,f=d.useMemo(()=>e.find(p=>p.id===h),[e,h]);return l.jsxs("div",{className:`tabs-layout-main ${o}`,children:[l.jsx("ul",{className:`horizontal tabs tabs-container ${a}`,children:e.map(({id:p,to:y,label:b})=>l.jsx("li",{children:l.jsx(Be,{onClick:()=>{t===void 0&&m(p),r==null||r(p)},id:p,to:y,siblings:e.length>1,active:h===p,useLinks:c,tabButtonProps:i,children:b})},p))}),f==null?void 0:f.content]})},Ve=n=>{const{title:e,body:s,content:t,onClickNext:r,onSkip:o,onStartAsGuest:a,onSignIn:c,image:i="",alt:u="",final:m=!1}=n,{t:h}=C.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}),s!=null&&l.jsx("div",{className:"step-body",children:s}),t!=null&&l.jsx("div",{className:"step-content",children:t}),l.jsx("div",{className:"step-actions",children:m?l.jsxs(l.Fragment,{children:[l.jsx(C.Button,{color:"primary",className:"step-button",variant:"outlined",onClick:a,"aria-label":h("_accessibility:ariaLabels.start"),children:h("_accessibility:buttons.startAsGuest")}),l.jsx(C.Button,{color:"primary",variant:"submit",className:"step-button","aria-label":h("_accessibility:ariaLabels.start"),onClick:c,children:h("_accessibility:buttons.signIn")})]}):l.jsxs(l.Fragment,{children:[l.jsx(C.Button,{color:"primary",className:"step-button",variant:"outlined",onClick:o,"aria-label":h("_accessibility:ariaLabels.skip"),children:h("_accessibility:buttons.skip")}),l.jsx(C.Button,{color:"primary",className:"step-button",variant:"outlined",onClick:()=>r(),"aria-label":h("_accessibility:ariaLabels.next"),children:h("_accessibility:buttons.next")})]})})]})},cs=n=>{const{steps:e,signInPath:s="/auth/sign-in",guestPath:t="/",onSkip:r,onSignIn:o,onStartAsGuest:a}=n,{setGuestMode:c}=pe(),{navigate:i}=Y(),[u,m]=d.useState(1),h=d.useCallback(()=>{if(r){r();return}i(s)},[i,r,s]),f=d.useCallback(()=>{if(o){o();return}i(s)},[i,o,s]),g=d.useCallback(()=>{if(a){a();return}c(!0),i(t)},[t,i,a,c]),p=d.useMemo(()=>e.map((y,b)=>({id:b+1,label:"",content:l.jsx(Ve,{...y,final:b===e.length-1,onClickNext:()=>m(w=>w+1),onSkip:h,onStartAsGuest:g,onSignIn:f})})),[f,h,g,e]);return l.jsx("div",{className:"onboarding-main",children:l.jsx(He,{currentTab:u,onTabChange:y=>m(Number(y)),tabs:p,useLinks:!1})})},Ge=n=>{const{message:e,messageProps:s={className:"empty-message"},action:t,iconProps:r}=n;return l.jsxs("div",{className:"empty-container",children:[r&&l.jsx(K.FontAwesomeIcon,{...r}),l.jsx("p",{...s,children:e}),t&&l.jsx(C.Action,{showTooltips:!1,showText:!0,...t})]})};Object.defineProperty(exports,"Action",{enumerable:!0,get:()=>C.Action});Object.defineProperty(exports,"Actions",{enumerable:!0,get:()=>C.Actions});Object.defineProperty(exports,"ActionsDropdown",{enumerable:!0,get:()=>C.ActionsDropdown});Object.defineProperty(exports,"Button",{enumerable:!0,get:()=>C.Button});exports.APIClient=Z;exports.AppIconButton=B;exports.AuthClient=je;exports.AuthContext=ce;exports.AuthProvider=Rt;exports.BaseClient=pt;exports.ConfigProvider=Pt;exports.ConfirmationDialog=rt;exports.Dialog=ne;exports.DialogActions=re;exports.Drawer=_t;exports.DrawerMenuContext=be;exports.DrawerMenuProvider=Mt;exports.Empty=Ge;exports.Error=Yt;exports.FormContainer=tt;exports.FormDialog=nt;exports.GlobalActions=H;exports.IManager=ft;exports.IconButton=B;exports.ImportDialog=lt;exports.IndexedDBClient=gt;exports.ManagerProvider=Dt;exports.Methods=I;exports.Navbar=ss;exports.NavbarContext=xe;exports.NavbarProvider=ts;exports.Notification=as;exports.NotificationEnumType=F;exports.NotificationProvider=jt;exports.Onboarding=cs;exports.Page=Zt;exports.ParagraphInput=et;exports.PasswordInput=st;exports.PrettyGrid=es;exports.SplashScreen=is;exports.Step=Ve;exports.SupabaseAuthProvider=Lt;exports.SupabaseDataClient=Ct;exports.SupabaseManagerContext=ge;exports.SupabaseManagerProvider=It;exports.Tab=Be;exports.TabsLayout=He;exports.ToTop=Jt;exports.buildQueryUrl=Ae;exports.createQueryClient=ie;exports.enumToKeyValueArray=kt;exports.formatForDatetimeLocal=Nt;exports.fromLocal=q;exports.getFormattedDateTime=Et;exports.getShortFormattedDateTime=vt;exports.isHttpError=ae;exports.isMac=$e;exports.isValidationError=oe;exports.makeRequest=se;exports.mapSupabaseSessionToSessionDto=he;exports.mapValidationErrors=At;exports.parseQueries=fe;exports.queryClient=$t;exports.removeFromLocal=D;exports.toLocal=M;exports.useAuth=pe;exports.useAuthContext=Ie;exports.useConfig=Y;exports.useConfirmationForm=ye;exports.useDeleteAction=_e;exports.useDeleteDialog=Bt;exports.useDialog=we;exports.useDrawerMenu=Me;exports.useEditAction=qt;exports.useExportAction=Ue;exports.useExportActionMutate=zt;exports.useFormDialog=Ce;exports.useImportAction=Ke;exports.useImportDialog=Wt;exports.useManager=Le;exports.useNavbar=qe;exports.useNotification=G;exports.usePostDialog=Ht;exports.usePostForm=Qt;exports.usePutDialog=Vt;exports.useRestoreAction=Oe;exports.useRestoreDialog=Gt;exports.useScrollTrigger=Qe;exports.useSupabase=Pe;exports.useTimeAge=Kt;Object.keys(C).forEach(n=>{n!=="default"&&!Object.prototype.hasOwnProperty.call(exports,n)&&Object.defineProperty(exports,n,{enumerable:!0,get:()=>C[n]})});
1
+ var Ye=Object.defineProperty;var Xe=(n,e,s)=>e in n?Ye(n,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):n[e]=s;var E=(n,e,s)=>Xe(n,typeof e!="symbol"?e+"":e,s);var us=require("./main.css");Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const C=require("@sito/dashboard"),l=require("react/jsx-runtime"),K=require("@fortawesome/react-fontawesome"),d=require("react"),R=require("@fortawesome/free-solid-svg-icons"),Ee=require("react-dom"),P=require("@tanstack/react-query"),Ze=require("@fortawesome/free-regular-svg-icons"),ve=require("react-hook-form"),Se=n=>n==null?!1:`${n}`.length>0,et=d.forwardRef(function(n,e){const{value:s,defaultValue:t,onChange:r,state:o=C.State.default,name:a="",id:c="",label:i="",disabled:u=!1,required:m=!1,containerClassName:h="",inputClassName:f="",labelClassName:g="",helperText:p="",helperTextClassName:y="",...b}=n,w=s!==void 0,[S,x]=d.useState(()=>Se(t)),k=w?Se(s):S,v=_=>{w||x(_.currentTarget.value.length>0),r==null||r(_)};return l.jsxs("div",{className:`form-paragraph-container group ${h}`,children:[l.jsx("textarea",{ref:e,name:a,id:c,className:`text-input text-area form-paragraph-textarea peer ${C.inputStateClassName(o)} ${k?"has-value":""} ${b.placeholder?"has-placeholder":""} ${f}`,required:m,defaultValue:t,...w?{value:s}:{},onChange:v,disabled:u,...b}),l.jsxs("label",{htmlFor:c,className:`text-input-label ${C.labelStateClassName(o)} ${g}`,children:[i,m?" *":""]}),!!p&&l.jsx("p",{className:`text-input-helper-text ${C.helperTextStateClassName(o)} ${y}`,children:p})]})}),tt=n=>{const{t:e}=C.useTranslation(),{children:s,handleSubmit:t,onSubmit:r,isLoading:o=!1,buttonEnd:a=!0,reset:c}=n;return l.jsxs("form",{className:"form-container",onSubmit:t(r),children:[s,l.jsxs("div",{className:`form-actions ${a?"end":""}`,children:[l.jsxs(C.Button,{type:"submit",color:"primary",variant:"submit",disabled:o,name:e("_accessibility:buttons.submit"),"aria-label":e("_accessibility:ariaLabels.submit"),children:[o?l.jsx(C.Loading,{color:"stroke-base",loaderClass:"!w-6 mt-1",strokeWidth:"6"}):null,e("_accessibility:buttons.submit")]}),l.jsx(C.Button,{type:"button",variant:"outlined",onClick:()=>c==null?void 0:c(),name:e("_accessibility:buttons.cancel"),"aria-label":e("_accessibility:ariaLabels.cancel"),children:e("_accessibility:buttons.cancel")})]})]})},st=d.forwardRef(function(n,e){const{t:s}=C.useTranslation(),[t,r]=d.useState(!1);return l.jsx(C.TextInput,{...n,type:t?"text":"password",ref:e,children:l.jsx(B,{type:"button",tabIndex:-1,"aria-label":s(t?"_accessibility:ariaLabels.hidePassword":"_accessibility:ariaLabels.showPassword"),className:"password-icon",onClick:()=>r(!t),icon:t?R.faEyeSlash:R.faEye})})}),ne=n=>{const{t:e}=C.useTranslation(),{title:s,children:t,handleClose:r,open:o=!1,containerClassName:a="",className:c="",animationClass:i="appear"}=n,u=d.useCallback(h=>{h.key==="Escape"&&o&&r()},[o,r]);d.useEffect(()=>(window.addEventListener("keydown",u),()=>{window.removeEventListener("keydown",u)}),[u]);const m=d.useCallback(h=>{h.target===h.currentTarget&&r()},[r]);return d.useEffect(()=>{const h=f=>{f?document.body.style.overflow="hidden":document.body.style.overflow="auto"};return h(o),()=>{h(!1)}},[o]),Ee.createPortal(l.jsx("div",{"aria-label":e("_accessibility:ariaLabels.closeDialog"),"aria-hidden":!o,onClick:m,className:`dialog-backdrop animated ${o?`opened ${i}`:"closed"} ${a}`,children:l.jsxs("div",{className:`dialog elevated animated ${o?`opened ${i}`:"closed"} ${c}`,children:[l.jsxs("div",{className:"dialog-header",children:[l.jsx("h3",{className:"dialog-title",children:s}),l.jsx(B,{icon:R.faClose,disabled:!o,"aria-disabled":!o,onClick:r,variant:"text",color:"error",className:"icon-button dialog-close-btn",name:e("_accessibility:buttons.closeDialog"),"aria-label":e("_accessibility:ariaLabels.closeDialog")})]}),t]})}),document.body)},re=n=>{const{primaryText:e,cancelText:s,onPrimaryClick:t,onCancel:r,isLoading:o=!1,disabled:a=!1,primaryType:c="submit",containerClassName:i="",primaryClassName:u="",alignEnd:m=!1,primaryName:h,primaryAriaLabel:f,cancelName:g,cancelAriaLabel:p,extraActions:y=[]}=n;return l.jsxs("div",{className:`dialog-actions ${m?"end":""} ${i}`,children:[l.jsxs(C.Button,{type:c,color:"primary",variant:"submit",className:u,disabled:a,onClick:t,name:h,"aria-label":f,children:[o?l.jsx(C.Loading,{color:"stroke-base",loaderClass:"!w-6 mt-1",strokeWidth:"6"}):null,e]}),y==null?void 0:y.map(b=>l.jsx(C.Button,{...b},b.id)),l.jsx(C.Button,{type:"button",variant:"outlined",disabled:a,onClick:r,name:g,"aria-label":p,children:s})]})},nt=n=>{const{t:e}=C.useTranslation(),{children:s,handleSubmit:t,onSubmit:r,handleClose:o,isLoading:a=!1,buttonEnd:c=!0,extraActions:i=[],...u}=n;return l.jsx(ne,{...u,handleClose:o,children:l.jsxs("form",{onSubmit:t(r),children:[l.jsx("div",{className:"form-container",children:s}),l.jsx(re,{primaryType:"submit",primaryText:e("_accessibility:buttons.submit"),cancelText:e("_accessibility:buttons.cancel"),onCancel:o,isLoading:a,disabled:a,primaryClassName:"dialog-form-primary",alignEnd:c,primaryName:e("_accessibility:buttons.submit"),primaryAriaLabel:e("_accessibility:ariaLabels.submit"),cancelName:e("_accessibility:buttons.cancel"),cancelAriaLabel:e("_accessibility:ariaLabels.cancel"),extraActions:i})]})})},rt=n=>{const{t:e}=C.useTranslation(),{children:s,handleSubmit:t,handleClose:r,isLoading:o=!1,extraActions:a=[],...c}=n;return l.jsxs(ne,{...c,handleClose:r,children:[s,l.jsx(re,{primaryText:e("_accessibility:buttons.ok"),cancelText:e("_accessibility:buttons.cancel"),onPrimaryClick:t,onCancel:r,isLoading:o,disabled:o,primaryType:"button",containerClassName:"mt-5",primaryName:e("_accessibility:buttons.ok"),primaryAriaLabel:e("_accessibility:ariaLabels.ok"),cancelName:e("_accessibility:buttons.cancel"),cancelAriaLabel:e("_accessibility:ariaLabels.cancel"),extraActions:a})]})};function ot(n){const{message:e,className:s=""}=n,{t}=C.useTranslation();return l.jsx("p",{className:`import-error-message ${s}`,children:e??t("_messages:errors.parseFile",{defaultValue:"Failed to process file"})})}function at(n){const{message:e,className:s=""}=n,{t}=C.useTranslation();return l.jsxs("div",{className:`import-loading ${s}`,children:[l.jsx(C.Loading,{loaderClass:"w-5 h-5",className:"!w-auto"}),l.jsx("span",{children:e??t("_messages:loading.processingFile",{defaultValue:"Processing file..."})})]})}function it(n){const{items:e,max:s=5,className:t=""}=n,{t:r}=C.useTranslation();if(!e||e.length===0)return null;const o=e.slice(0,s);return l.jsxs("div",{className:`import-preview ${t}`,children:[l.jsx("p",{className:"import-preview-count",children:r("_pages:common.actions.import.previewCount",{count:e.length,defaultValue:`Preview: ${e.length} items`})}),l.jsx("pre",{className:"import-preview-content",children:JSON.stringify(o,null,2)})]})}const Ne=()=>({file:null,previewItems:null,parseError:null,processing:!1,overrideExisting:!1,inputKey:0});function ct(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 lt=n=>{const{t:e}=C.useTranslation(),{children:s,handleSubmit:t,handleClose:r,isLoading:o=!1,fileProcessor:a,onFileProcessed:c,renderCustomPreview:i,onOverrideChange:u,open:m,extraActions:h=[],...f}=n,[g,p]=d.useReducer(ct,Ne()),{file:y,previewItems:b,parseError:w,processing:S,overrideExisting:x,inputKey:k}=g,v=d.useRef(c),_=d.useRef(a);d.useEffect(()=>{v.current=c},[c]),d.useEffect(()=>{_.current=a},[a]),d.useEffect(()=>{m||p({type:"RESET"})},[m]);const Q=d.useCallback(async(T,j)=>{var $;if(_.current){p({type:"START_PROCESSING"});try{const L=await _.current(T,{override:j});p({type:"SET_PREVIEW",items:L??[]}),($=v.current)==null||$.call(v,L??[])}catch(L){console.error(L);const O=L instanceof Error?L.message:"Failed to parse file";p({type:"SET_ERROR",message:O})}}},[]);return l.jsxs(ne,{...f,open:m,handleClose:r,children:[l.jsx(C.FileInput,{onClear:()=>{var T;p({type:"SET_FILE",file:null}),(T=v.current)==null||T.call(v,[])},onChange:T=>{var $,L;const j=($=T.target.files)==null?void 0:$[0];if(!j){p({type:"SET_FILE",file:null}),(L=v.current)==null||L.call(v,[]);return}p({type:"SET_FILE",file:j}),Q(j,x)},label:e("_accessibility:labels.file")},k),l.jsxs("label",{className:"import-override-label",children:[l.jsx("input",{type:"checkbox",checked:x,onChange:T=>{const j=T.target.checked;p({type:"SET_OVERRIDE",value:j}),u==null||u(j),y&&Q(y,j)}}),l.jsx("span",{children:e("_pages:common.actions.import.override",{defaultValue:"Override existing items"})})]}),l.jsx(ot,{message:w}),S&&l.jsx(at,{}),i?i(b):!!b&&b.length>0&&l.jsx(it,{items:b}),s,l.jsx(re,{primaryText:e("_accessibility:buttons.ok"),cancelText:e("_accessibility:buttons.cancel"),onPrimaryClick:()=>{(!a||!!b&&b.length>0)&&t()},onCancel:r,isLoading:o,primaryType:"button",containerClassName:"import-dialog-actions",primaryName:e("_accessibility:buttons.ok"),primaryAriaLabel:e("_accessibility:ariaLabels.ok"),cancelName:e("_accessibility:buttons.cancel"),cancelAriaLabel:e("_accessibility:ariaLabels.cancel"),extraActions:h})]})};var M=(n=>(n[n.success=0]="success",n[n.error=1]="error",n[n.warning=2]="warning",n[n.info=3]="info",n))(M||{}),I=(n=>(n.GET="GET",n.POST="POST",n.PUT="PUT",n.PATCH="PATCH",n.DELETE="DELETE",n))(I||{});const ut=n=>Array.isArray(n)||n instanceof Headers?!1:typeof n=="object"&&n!==null&&("headers"in n||"credentials"in n),dt=n=>n?ut(n)?n:{headers:n}:{},mt=n=>n?n instanceof Headers?Object.fromEntries(n.entries()):Array.isArray(n)?Object.fromEntries(n):n:{};async function se(n,e="GET",s,t){const r=dt(t),o={...s!==void 0?{"Content-Type":"application/json"}:{},...mt(r.headers)};try{const a=await fetch(n,{method:e,headers:o,...r.credentials?{credentials:r.credentials}:{},...s!==void 0?{body:JSON.stringify(s)}:{}}),c=await a.text();let i=null;try{i=c?JSON.parse(c):null}catch{i=null}if(!a.ok){const 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 Ae(n,e){const s=t=>t instanceof Date?t.toISOString():String(t);if(e){const t=Object.entries(e).filter(([,r])=>r!=null).map(([r,o])=>`${encodeURIComponent(r)}=${encodeURIComponent(s(o))}`).join("&");return t?`${n}?${t}`:n}return n}const le=n=>typeof n=="object"&&n!==null,V=n=>n instanceof Date?encodeURIComponent(n.toISOString()):encodeURIComponent(String(n)),ht=n=>{if(typeof n!="string")return;const e=n.trim().toUpperCase();if(e==="ACTIVE"||e==="DELETED"||e==="ALL")return e},fe=(n,e,s)=>{const t=[];if(e){const{sortingBy:r,sortingOrder:o,currentPage:a,pageSize:c}=e;r!==void 0&&t.push(`sort=${String(r)}`),o!==void 0&&t.push(`order=${o}`),a!==void 0&&t.push(`page=${a}`),c!==void 0&&t.push(`pageSize=${c}`)}if(s){const r=ht(s.softDeleteScope);r&&t.push(`softDeleteScope=${encodeURIComponent(r)}`);const o=Object.entries(s).filter(([a,c])=>a!=="softDeleteScope"&&c!==null&&c!==void 0&&c!=="").flatMap(([a,c])=>{if(Array.isArray(c))return c.map(i=>i instanceof Date?`${a}==${V(i)}`:le(i)?`${a}==${V(i.id??"")}`:`${a}==${V(i)}`);if(le(c)&&"start"in c&&"end"in c){const i=[];return c.start!=null&&c.start!==""&&i.push(`${a}>=${V(c.start)}`),c.end!=null&&c.end!==""&&i.push(`${a}<=${V(c.end)}`),i}return c instanceof Date?`${a}==${V(c)}`:le(c)?`${a}==${V(c.id??"")}`:`${a}==${V(c)}`});o.length>0&&t.push(`filters=${o.join(",")}`)}return t.length?`${n}?${t.join("&")}`:n},J=class J{constructor(e,s="user",t=!0,r,o={}){E(this,"baseUrl");E(this,"userKey");E(this,"rememberKey");E(this,"refreshTokenKey");E(this,"accessTokenExpiresAtKey");E(this,"refreshEndpoint");E(this,"refreshExpirySkewMs");E(this,"secured");E(this,"tokenAcquirer");this.baseUrl=e,this.secured=t,this.userKey=s,this.rememberKey=o.rememberKey??"remember",this.refreshTokenKey=o.refreshTokenKey??"refreshToken",this.accessTokenExpiresAtKey=o.accessTokenExpiresAtKey??"accessTokenExpiresAt",this.refreshEndpoint=o.refreshEndpoint??"auth/refresh",this.refreshExpirySkewMs=o.refreshExpirySkewMs??5e3,this.tokenAcquirer=r??this.defaultTokenAcquirer}defaultTokenAcquirer(e){if(e)return{credentials:"include"};const s=q(this.userKey);if(s&&s.length)return{Authorization:`Bearer ${s}`}}getRefreshLockKey(){return`${this.baseUrl}|${this.userKey}|${this.refreshTokenKey}|${this.accessTokenExpiresAtKey}`}buildUrl(e){const s=this.baseUrl.endsWith("/")?this.baseUrl.slice(0,-1):this.baseUrl,t=e.startsWith("/")?e:`/${e}`;return`${s}${t}`}getRefreshToken(){const e=q(this.refreshTokenKey);if(typeof e=="string"&&e.length)return e}getAccessTokenExpiresAt(){const e=q(this.accessTokenExpiresAtKey);if(typeof e=="string"&&e.length)return e}canRefresh(){return!!this.getRefreshToken()}shouldRefreshBeforeRequest(){const e=this.getRefreshToken(),s=this.getAccessTokenExpiresAt();if(!e||!s)return!1;const t=Date.parse(s);return Number.isNaN(t)?!1:Date.now()>=t-this.refreshExpirySkewMs}clearStoredSession(){D(this.userKey),D(this.rememberKey),D(this.refreshTokenKey),D(this.accessTokenExpiresAtKey)}storeSession(e,s){F(this.userKey,e.token);const t=e.refreshToken===void 0?s:e.refreshToken;typeof t=="string"&&t.length?F(this.refreshTokenKey,t):D(this.refreshTokenKey),typeof e.accessTokenExpiresAt=="string"&&e.accessTokenExpiresAt.length?F(this.accessTokenExpiresAtKey,e.accessTokenExpiresAt):D(this.accessTokenExpiresAtKey)}async refreshAccessTokenWithMutex(){const e=this.getRefreshToken();if(!e)throw{status:401,message:"Missing refresh token"};const s=this.getRefreshLockKey(),t=J.refreshInFlight.get(s);if(t){await t;return}const r=(async()=>{const{data:o,status:a,error:c}=await se(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)})();J.refreshInFlight.set(s,r);try{await r}finally{J.refreshInFlight.delete(s)}}isRequestOptions(e){return Array.isArray(e)||e instanceof Headers?!1:typeof e=="object"&&e!==null&&("headers"in e||"credentials"in e)}toRequestOptions(e){return e?this.isRequestOptions(e)?e:{headers:e}:{}}toHeaderRecord(e){return e?e instanceof Headers?Object.fromEntries(e.entries()):Array.isArray(e)?Object.fromEntries(e):e:{}}mergeRequestConfig(e){const s=this.secured?this.tokenAcquirer():void 0,t=this.toRequestOptions(s),r=this.toRequestOptions(e),o={...this.toHeaderRecord(t.headers),...this.toHeaderRecord(r.headers)},a=r.credentials??t.credentials,c=Object.keys(o).length>0;if(a)return c?{headers:o,credentials:a}:{credentials:a};if(c)return o}async makeRequestWithRefresh(e,s,t,r){this.secured&&this.shouldRefreshBeforeRequest()&&await this.refreshAccessTokenWithMutex();let o=await se(this.buildUrl(e),s,t,this.mergeRequestConfig(r));return this.secured&&o.status===401&&this.canRefresh()&&(await this.refreshAccessTokenWithMutex(),o=await se(this.buildUrl(e),s,t,this.mergeRequestConfig(r))),o}async doQuery(e,s=I.GET,t,r){const{data:o,status:a,error:c}=await this.makeRequestWithRefresh(e,s,t,r);if(c||a<200||a>=300)throw c??{status:a,message:String(a)};return o}async get(e,s,t){const r=fe(e,s,t),{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,s){const{error:t,data:r,status:o}=await this.makeRequestWithRefresh(e,I.PATCH,s);if(t||r===null||r===void 0)throw t??{status:o,message:"Unknown error"};return r}async delete(e,s){const{error:t,data:r,status:o}=await this.makeRequestWithRefresh(e,I.DELETE,s);if(t||r===null||r===void 0)throw t??{status:o,message:"Unknown error"};return r}async post(e,s){const{error:t,data:r,status:o}=await this.makeRequestWithRefresh(e,I.POST,s);if(t||r===null||r===void 0)throw t??{status:o,message:"Unknown error"};return r}};E(J,"refreshInFlight",new Map);let Z=J;class je{constructor(e,s="user",t={}){E(this,"api");this.api=new Z(e,s,!1,void 0,t)}async login(e){const s="auth/sign-in",t=e;return await this.api.doQuery(s,I.POST,t)}async refresh(e){return await this.api.doQuery("auth/refresh",I.POST,e)}async logout(e){const s="auth/sign-out",t=e!=null&&e.accessToken?{Authorization:`Bearer ${e.accessToken}`}:void 0,r=e!=null&&e.refreshToken?{refreshToken:e.refreshToken}:void 0;return await this.api.doQuery(s,I.POST,r,t)}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 ft{constructor(e,s,t={}){E(this,"auth");this.auth=new je(e,s,t)}get Auth(){return this.auth}}class pt{constructor(e,s,t="user",r=!0,o={}){E(this,"table");E(this,"secured");E(this,"api");this.table=e,this.secured=r,this.api=new Z(s,t,r,void 0,o)}async insert(e){return await this.api.post(`${this.table}`,e)}async insertMany(e){return await this.api.doQuery(`${this.table}/batch`,I.POST,e)}async update(e){return await this.api.patch(`${this.table}/${e.id}`,e)}async get(e,s){return await this.api.get(`${this.table}`,e,s)}async export(e){const s=fe(`${this.table}/export`,void 0,e);return await this.api.doQuery(s,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(Ae(`${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,s,t=1){E(this,"table");E(this,"dbName");E(this,"version");E(this,"db",null);this.table=e,this.dbName=s,this.version=t}close(){this.db&&(this.db.onversionchange=null,this.db.close(),this.db=null)}open(){return this.db?Promise.resolve(this.db):new Promise((e,s)=>{const t=indexedDB.open(this.dbName,this.version);t.onupgradeneeded=r=>{const o=r.target.result;o.objectStoreNames.contains(this.table)||o.createObjectStore(this.table,{keyPath:"id",autoIncrement:!0})},t.onsuccess=r=>{this.db=r.target.result,this.db.onversionchange=()=>{this.close()},e(this.db)},t.onerror=r=>{s(r.target.error)}})}async transaction(e){return(await this.open()).transaction(this.table,e).objectStore(this.table)}request(e){return new Promise((s,t)=>{e.onsuccess=()=>s(e.result),e.onerror=()=>t(e.error)})}async insert(e){const s=await this.transaction("readwrite"),t=await this.request(s.add(e));return{...e,id:t}}async insertMany(e){const s=await this.transaction("readwrite");let t=0;for(const r of e)t=await this.request(s.add(r));return{...e[e.length-1],id:t}}async update(e,s){const t=typeof e=="number"?s:e;if(!t)throw new Error("IndexedDBClient.update requires a value payload");const r=typeof e=="number"?{...t,id:t.id??e}:t,o=await this.transaction("readwrite");return await this.request(o.put(r)),r}async get(e,s){var g;const t=await this.transaction("readonly"),r=await this.request(t.getAll()),o=this.applyFilter(r,s),a=(e==null?void 0:e.sortingBy)??"id",c=((g=e==null?void 0:e.sortingOrder)==null?void 0:g.toLowerCase())??"asc";o.sort((p,y)=>{const b=p[a],w=y[a];return b<w?c==="asc"?-1:1:b>w?c==="asc"?1:-1:0});const i=(e==null?void 0:e.pageSize)??10,u=(e==null?void 0:e.currentPage)??0,m=o.length,h=Math.ceil(m/i),f=o.slice(u*i,u*i+i);return{sort:a,order:c,currentPage:u,pageSize:i,totalElements:m,totalPages:h,items:f}}async export(e){const s=await this.transaction("readonly"),t=await this.request(s.getAll());return this.applyFilter(t,e)}async import(e){const s=await this.transaction("readwrite");let t=0;for(const r of e.items)e.override?await this.request(s.put(r)):await this.request(s.add(r)),t++;return t}async commonGet(e){const s=await this.transaction("readonly"),t=await this.request(s.getAll());return this.applyFilter(t,e)}async getById(e){const s=await this.transaction("readonly"),t=await this.request(s.get(e));if(!t)throw new Error(`Record ${e} not found in ${this.table}`);return t}async softDelete(e){const s=await this.transaction("readwrite");let t=0;for(const r of e){const o=await this.request(s.get(r));o&&(await this.request(s.put({...o,deletedAt:new Date})),t++)}return t}async restore(e){const s=await this.transaction("readwrite");let t=0;for(const r of e){const o=await this.request(s.get(r));o&&(await this.request(s.put({...o,deletedAt:null})),t++)}return t}applyFilter(e,s){if(!s)return e;const t=this.resolveSoftDeleteScope(s.softDeleteScope),r=t===void 0?e:e.filter(a=>this.matchesSoftDeleteScope(t,a.deletedAt)),o=Object.entries(s).filter(([a,c])=>a!=="softDeleteScope"&&c!==void 0);return o.length===0?r:r.filter(a=>o.every(([c,i])=>this.matchesFilterValue(i,a[c])))}matchesFilterValue(e,s){if(e instanceof Date){if(s instanceof Date)return s.getTime()===e.getTime();if(typeof s=="string"||typeof s=="number"){const t=new Date(s);return Number.isNaN(t.getTime())?!1:t.getTime()===e.getTime()}return!1}return s===e}resolveSoftDeleteScope(e){if(typeof e!="string")return;const s=e.trim().toUpperCase();if(s==="ACTIVE")return"ACTIVE";if(s==="DELETED")return"DELETED";if(s==="ALL")return"ALL"}matchesSoftDeleteScope(e,s){if(e==="ALL")return!0;const t=s!=null;return e==="DELETED"?t:!t}}const me=n=>typeof n=="object"&&n!==null,bt=n=>me(n)?"start"in n||"end"in n:!1,yt=n=>n!==void 0,X=n=>n instanceof Date?n.toISOString():n,wt=n=>{if(typeof n!="string")return;const e=n.trim().toUpperCase();if(e==="ACTIVE")return"ACTIVE";if(e==="DELETED")return"DELETED";if(e==="ALL")return"ALL"};class Ct{constructor(e,s,t={}){E(this,"table");E(this,"supabase");E(this,"idColumn");E(this,"deletedAtColumn");E(this,"defaultSortColumn");E(this,"options");this.table=e,this.supabase=s,this.options=t,this.idColumn=t.idColumn??"id",this.deletedAtColumn=t.deletedAtColumn??"deletedAt",this.defaultSortColumn=t.defaultSortColumn??this.idColumn}resolveStatus(e){return typeof e=="number"&&Number.isFinite(e)?e:500}throwHttpError(e,s,t,r="Unknown error"){throw{status:this.resolveStatus(s),message:(e==null?void 0:e.message)||t||r}}assertNoError(e,s,t,r){e&&this.throwHttpError(e,s,t,r)}toDto(e){return this.options.mapRowToDto?this.options.mapRowToDto(e):e}toCommonDto(e){return this.options.mapRowToCommonDto?this.options.mapRowToCommonDto(e):e}toAddRow(e){return this.options.mapAddDtoToRow?this.options.mapAddDtoToRow(e):e}toUpdateRow(e){return this.options.mapUpdateDtoToRow?this.options.mapUpdateDtoToRow(e):e}toImportRow(e){return this.options.mapImportPreviewToRow?this.options.mapImportPreviewToRow(e):e}resolveObjectFilterValue(e){return"id"in e?X(e.id):""}applyFilters(e,s){if(!s)return e;let t=e;const r=wt(s.softDeleteScope);return r==="ACTIVE"?t=t.is(this.deletedAtColumn,null):r==="DELETED"&&(t=t.not(this.deletedAtColumn,"is",null)),Object.entries(s).forEach(([o,a])=>{if(o==="softDeleteScope"||a===void 0||a===null||a==="")return;const c=o==="deletedAt"?this.deletedAtColumn:o;if(Array.isArray(a)){const i=a.map(u=>u instanceof Date?u.toISOString():me(u)?this.resolveObjectFilterValue(u):X(u)).filter(yt);i.length>0&&(t=t.in(c,i));return}if(bt(a)){a.start!==void 0&&a.start!==""&&(t=t.gte(c,X(a.start))),a.end!==void 0&&a.end!==""&&(t=t.lte(c,X(a.end)));return}if(a instanceof Date){t=t.eq(c,a.toISOString());return}if(me(a)){t=t.eq(c,this.resolveObjectFilterValue(a));return}t=t.eq(c,X(a))}),t}async insert(e){const s=await this.supabase.from(this.table).insert(this.toAddRow(e)).select("*").single();return this.assertNoError(s.error,s.status,s.statusText,"Unable to insert"),s.data||this.throwHttpError(null,s.status,s.statusText,"Unable to insert"),this.toDto(s.data)}async insertMany(e){var o;e.length===0&&this.throwHttpError(null,400,void 0,"insertMany requires items");const s=e.map(a=>this.toAddRow(a)),t=await this.supabase.from(this.table).insert(s).select("*");this.assertNoError(t.error,t.status,t.statusText,"Unable to insert many rows");const r=(o=t.data)==null?void 0:o.at(-1);return r||this.throwHttpError(null,t.status,t.statusText,"Unable to insert many rows"),this.toDto(r)}async update(e){const s={[this.idColumn]:e.id},t=await this.supabase.from(this.table).update(this.toUpdateRow(e)).match(s).select("*").maybeSingle();return this.assertNoError(t.error,t.status,t.statusText,"Unable to update"),t.data||this.throwHttpError(null,404,t.statusText,`Record ${e.id} not found`),this.toDto(t.data)}async get(e,s){const t=(e==null?void 0:e.pageSize)??10,r=(e==null?void 0:e.currentPage)??0,o=String((e==null?void 0:e.sortingBy)??this.defaultSortColumn),a=String((e==null?void 0:e.sortingOrder)??"asc").toLowerCase()==="desc"?"desc":"asc",c=r*t,i=c+t-1;let u=this.supabase.from(this.table).select("*",{count:"exact"});u=this.applyFilters(u,s).order(o,{ascending:a==="asc"}).range(c,i);const m=await u;this.assertNoError(m.error,m.status,m.statusText,"Unable to load list");const h=(m.data??[]).map(g=>this.toDto(g)),f=m.count??h.length;return{sort:o,order:a,currentPage:r,pageSize:t,totalElements:f,totalPages:t>0?Math.ceil(f/t):0,items:h}}async export(e){let s=this.supabase.from(this.table).select("*");s=this.applyFilters(s,e);const t=await s;return this.assertNoError(t.error,t.status,t.statusText,"Unable to export"),(t.data??[]).map(r=>this.toDto(r))}async import(e){var o;if(e.items.length===0)return 0;const s=e.items.map(a=>this.toImportRow(a)),r=await(e.override?this.supabase.from(this.table).upsert(s,{onConflict:this.idColumn}).select(this.idColumn):this.supabase.from(this.table).insert(s).select(this.idColumn));return this.assertNoError(r.error,r.status,r.statusText,"Unable to import rows"),((o=r.data)==null?void 0:o.length)??0}async commonGet(e){let s=this.supabase.from(this.table).select("*");s=this.applyFilters(s,e);const t=await s;return this.assertNoError(t.error,t.status,t.statusText,"Unable to load common data"),(t.data??[]).map(r=>this.toCommonDto(r))}async getById(e){const s={[this.idColumn]:e},t=await this.supabase.from(this.table).select("*").match(s).maybeSingle();return this.assertNoError(t.error,t.status,t.statusText,"Unable to load item"),t.data||this.throwHttpError(null,404,t.statusText,`Record ${e} not found`),this.toDto(t.data)}async softDelete(e){var a,c,i;if(e.length===0)return 0;const s=((c=(a=this.options).nowFactory)==null?void 0:c.call(a).toISOString())??new Date().toISOString(),t=this.supabase.from(this.table).update({[this.deletedAtColumn]:s}),r=`(${e.join(",")})`,o=await t.filter(this.idColumn,"in",r).select(this.idColumn);return this.assertNoError(o.error,o.status,o.statusText,"Unable to soft delete"),((i=o.data)==null?void 0:i.length)??0}async restore(e){var o;if(e.length===0)return 0;const s=this.supabase.from(this.table).update({[this.deletedAtColumn]:null}),t=`(${e.join(",")})`,r=await s.filter(this.idColumn,"in",t).select(this.idColumn);return this.assertNoError(r.error,r.status,r.statusText,"Unable to restore"),((o=r.data)==null?void 0:o.length)??0}}const xt=n=>typeof n=="object"&&n!==null,St=(n,e)=>{if(xt(n))for(const s of e){const t=n[s];if(typeof t=="string"&&t.trim().length>0)return t.trim()}},Tt=(n,e)=>{if(!n)return e;const s=Number(n);return Number.isFinite(s)?s:e},he=(n,e)=>{const{defaultId:s=0,defaultUsername:t="",defaultEmail:r="",usernameMetadataKeys:o=["username","name","full_name"]}=e??{},a=St(n.user.user_metadata,o);return{id:Tt(n.user.id,s),username:a??t,email:n.user.email??r,token:n.access_token,refreshToken:n.refresh_token??null,accessTokenExpiresAt:typeof n.expires_at=="number"?new Date(n.expires_at*1e3).toISOString():null}};function kt(n){return Object.keys(n).filter(e=>isNaN(Number(e))).map(e=>({key:e,value:n[e]}))}const q=(n,e="")=>{const s=localStorage.getItem(n)??void 0;if(s&&e.length)switch(e){case"object":return JSON.parse(s);case"number":return Number(s);case"boolean":return s==="true"||s==="1";default:return s}return s},F=(n,e)=>localStorage.setItem(n,typeof e=="object"?JSON.stringify(e):e),D=n=>localStorage.removeItem(n);function Et(n){const e=n?new Date(n):new Date,s={weekday:"long",day:"numeric",month:"long",year:"numeric",hour:"numeric",minute:"2-digit",hour12:!0};return e.toLocaleString(navigator.language||"es-ES",s)}function vt(n){const e=n?new Date(n):new Date,s=String(e.getDate()).padStart(2,"0"),t=String(e.getMonth()+1).padStart(2,"0"),r=String(e.getFullYear()).slice(-2),o=String(e.getHours()).padStart(2,"0"),a=String(e.getMinutes()).padStart(2,"0");return`${s}/${t}/${r} ${o}:${a}`}function Nt(n){const e=n?new Date(n):new Date,s=e.getFullYear(),t=String(e.getMonth()+1).padStart(2,"0"),r=String(e.getDate()).padStart(2,"0"),o=String(e.getHours()).padStart(2,"0"),a=String(e.getMinutes()).padStart(2,"0");return`${s}-${t}-${r}T${o}:${a}`}const $e=()=>{var s;const n=navigator,e=((s=n==null?void 0:n.userAgentData)==null?void 0:s.platform)||(n==null?void 0:n.platform)||"";return/Mac|iPhone|iPod|iPad/i.test(e)};function oe(n){if(!n||typeof n!="object")return!1;const e=n;return Array.isArray(e.errors)&&e.errors.every(s=>Array.isArray(s)&&s.length===2&&typeof s[0]=="string")}function ae(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 At(n,e){return n!=null&&n.errors?n.errors.map(([s,t])=>e(s,t)):[]}const De=d.createContext(void 0);function jt(n){const{children:e}=n,s=d.useRef(0),[t,r]=d.useReducer((f,g)=>{const{type:p,items:y,id:b}=g;switch(p){case"set":return y??[];case"remove":return b!==void 0?f.filter(w=>w.id!==b):[]}return f},[],()=>[]),o=f=>f.map(g=>({...g,id:s.current++})),a=d.useCallback(f=>r({type:"set",items:o([{...f,type:M.error}])}),[]),c=d.useCallback(f=>r({type:"set",items:o([{...f}])}),[]),i=d.useCallback(f=>r({type:"set",items:o(f)}),[]),u=d.useCallback(f=>r({type:"set",items:o([{...f,type:M.success}])}),[]),m=f=>r({type:"remove",id:f}),h=d.useMemo(()=>({notification:t,removeNotification:m,showErrorNotification:a,showNotification:c,showSuccessNotification:u,showStackNotifications:i}),[t,a,c,i,u]);return l.jsx(De.Provider,{value:h,children:e})}const G=()=>{const n=d.useContext(De);if(!n)throw new Error("NotificationContext must be used within a Provider");return n},ie=()=>new P.QueryClient({defaultOptions:{queries:{refetchInterval:!1,refetchOnMount:!0,refetchOnReconnect:!1,retry:!1,retryOnMount:!0,refetchOnWindowFocus:!1}}}),$t=ie(),Re=d.createContext(void 0),Dt=n=>{const{children:e,manager:s,queryClient:t}=n,[r]=d.useState(ie),o=t??r;return l.jsx(Re.Provider,{value:{client:s},children:l.jsx(P.QueryClientProvider,{client:o,children:e})})},Le=()=>{const n=d.useContext(Re);if(!n)throw new Error("managerContext must be used within a Provider");return n.client},ce=d.createContext(void 0),Ie=()=>{const n=d.useContext(ce);if(!n)throw new Error("authContext must be used within a Provider");return n},Rt=n=>{const{children:e,guestMode:s="guest_mode",user:t="user",remember:r="remember",refreshTokenKey:o="refreshToken",accessTokenExpiresAtKey:a="accessTokenExpiresAt"}=n,c=Le(),[i,u]=d.useState({}),m=d.useCallback(()=>{D(t),D(r),D(o),D(a)},[a,o,r,t]),h=d.useCallback(()=>!!q(s,"boolean")&&i.token===void 0,[i.token,s]),f=d.useCallback(w=>{F(s,w)},[s]),g=d.useCallback((w,S)=>{if(!w)return;const x=q(r,"boolean"),k=S??(typeof x=="boolean"?x:!1);u(w),D(s),F(t,w.token),F(r,k),typeof w.refreshToken=="string"&&w.refreshToken.length?F(o,w.refreshToken):D(o),typeof w.accessTokenExpiresAt=="string"&&w.accessTokenExpiresAt.length?F(a,w.accessTokenExpiresAt):D(a)},[a,s,o,r,t]),p=d.useCallback(async()=>{const w=q(t)??i.token,S=q(o)??(typeof i.refreshToken=="string"?i.refreshToken:void 0);try{await c.Auth.logout({accessToken:w,refreshToken:S})}catch(x){console.error(x)}u({}),m()},[i.refreshToken,i.token,m,c.Auth,o,t]),y=d.useCallback(async()=>{try{const w=await c.Auth.getSession();g(w)}catch(w){console.error(w),p()}},[g,p,c.Auth]),b=d.useMemo(()=>({account:i,logUser:g,logoutUser:p,logUserFromLocal:y,isInGuestMode:h,setGuestMode:f}),[i,g,p,y,h,f]);return l.jsx(ce.Provider,{value:b,children:e})},pe=()=>Ie(),ge=d.createContext(void 0),Pe=()=>{const n=d.useContext(ge);if(!n)throw new Error("supabaseManagerContext must be used within a Provider");return n.client},Lt=n=>{const{children:e,guestMode:s="guest_mode",user:t="user",remember:r="remember",refreshTokenKey:o="refreshToken",accessTokenExpiresAtKey:a="accessTokenExpiresAt",sessionMapper:c}=n,i=Pe(),u=d.useRef(c??he);d.useEffect(()=>{u.current=c??he},[c]);const[m,h]=d.useState({}),f=d.useCallback(()=>{D(t),D(r),D(o),D(a)},[a,o,r,t]),g=d.useCallback(()=>!!q(s,"boolean")&&m.token===void 0,[m.token,s]),p=d.useCallback(x=>{F(s,x)},[s]),y=d.useCallback((x,k)=>{if(!x)return;const v=q(r,"boolean"),_=k??(typeof v=="boolean"?v:!1);h(x),D(s),F(t,x.token),F(r,_),typeof x.refreshToken=="string"&&x.refreshToken.length?F(o,x.refreshToken):D(o),typeof x.accessTokenExpiresAt=="string"&&x.accessTokenExpiresAt.length?F(a,x.accessTokenExpiresAt):D(a)},[a,s,o,r,t]),b=d.useCallback(async()=>{try{await i.auth.signOut()}catch(x){console.error(x)}h({}),f()},[f,i.auth]),w=d.useCallback(async()=>{try{const{data:x,error:k}=await i.auth.getSession();if(k)throw k;if(!x.session){h({}),f();return}y(u.current(x.session))}catch(x){console.error(x),await b()}},[f,y,b,i.auth]);d.useEffect(()=>{let x=!0;(async()=>{x&&await w()})();const{data:v}=i.auth.onAuthStateChange((_,Q)=>{if(x){if(!Q){h({}),f();return}y(u.current(Q))}});return()=>{x=!1,v.subscription.unsubscribe()}},[f,y,w,i.auth]);const S=d.useMemo(()=>({account:m,logUser:y,logoutUser:b,logUserFromLocal:w,isInGuestMode:g,setGuestMode:p}),[m,y,b,w,g,p]);return l.jsx(ce.Provider,{value:S,children:e})},It=n=>{const{children:e,supabase:s,queryClient:t}=n,[r]=d.useState(ie),o=t??r;return l.jsx(ge.Provider,{value:{client:s},children:l.jsx(P.QueryClientProvider,{client:o,children:e})})},Me=d.createContext({}),Pt=n=>{const{children:e,location:s,navigate:t,linkComponent:r,searchComponent:o}=n;return l.jsx(Me.Provider,{value:{location:s,navigate:t,linkComponent:r,searchComponent:o},children:e})},Y=()=>{const n=d.useContext(Me);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},Mt={addChildItem:()=>{},removeChildItem:()=>{},clearDynamicItems:()=>{},dynamicItems:{}},be=d.createContext(Mt),Ft=n=>{const{children:e}=n,[s,t]=d.useState({}),r=d.useCallback((i,u)=>t(m=>({...m,[i]:[...m[i]??[],u]})),[]),o=d.useCallback((i,u)=>t(m=>({...m,[i]:(m[i]??[]).filter((h,f)=>f!==u)})),[]),a=d.useCallback(i=>{t(i?u=>({...u,[i]:[]}):{})},[]),c=d.useMemo(()=>({dynamicItems:s,addChildItem:r,removeChildItem:o,clearDynamicItems:a}),[s,a,o,r]);return l.jsx(be.Provider,{value:c,children:e})},Fe=()=>d.useContext(be);function _t(n){const{t:e}=C.useTranslation(),{open:s,onClose:t,menuMap:r,logo:o}=n,{account:a}=pe(),{dynamicItems:c}=Fe(),{linkComponent:i,location:u}=Y(),m=i,h=d.useMemo(()=>r.filter(b=>{const w=b.auth,S=!!(a!=null&&a.email);return w==null||w&&S||!w&&!S}),[a==null?void 0:a.email,r]),f=d.useCallback(b=>{b.key==="Escape"&&s&&t()},[t,s]);d.useEffect(()=>(document.addEventListener("keydown",f),()=>{document.removeEventListener("keydown",f)}),[f]);const g=d.useCallback((b,w)=>w?b===`${u.pathname}${u.search}`:b===u.pathname,[u.pathname,u.search]),p=d.useCallback(b=>l.jsx("li",{className:`drawer-list-item-child ${g(b.path,!0)?"active":""} animated`,children:b.path?l.jsx(m,{tabIndex:s?0:-1,to:b.path??"/","aria-label":e(`_accessibility:ariaLabels.${b.id}`,{defaultValue:b.label}),className:"drawer-link",children:b.label}):b.label},b.id),[m,s,e,g]),y=d.useMemo(()=>h.map((b,w)=>{const S=b.page??String(w),x=`drawer-list-item ${g(b.path)?"active":""} animated`;if(b.type==="divider")return l.jsx("li",{className:x,children:l.jsx("hr",{className:"drawer-divider"})},S);const k=b.children??(b.page&&c?c[b.page]:null);return l.jsxs("li",{className:x,children:[l.jsxs(m,{tabIndex:s?0:-1,to:b.path??"/","aria-label":e(`_accessibility:ariaLabels.${String(b.page)}`,{defaultValue:e(`_pages:${String(b.page)}.title`)}),className:"drawer-link",children:[b.icon,e(`_pages:${b.page}.title`)]}),k&&l.jsx("ul",{className:"drawer-children-list",children:k.map(p)})]},S)}),[m,c,g,s,h,p,e]);return l.jsx("div",{"aria-label":e("_accessibility:ariaLabels.closeMenu"),"aria-disabled":!s,className:`${s?"opened":"closed"} drawer-backdrop`,onClick:()=>t(),children:l.jsxs("aside",{className:`${s?"opened":"closed"} drawer animated`,children:[l.jsxs("div",{className:"drawer-header-container",children:[o,l.jsx("h2",{className:"drawer-header poppins",children:e("_pages:home.appName")})]}),l.jsx("ul",{className:"drawer-menu-list",children:y})]})})}const B=({icon:n,...e})=>l.jsx(C.IconButton,{icon:l.jsx(K.FontAwesomeIcon,{icon:n}),...e});var ue,Te;function Ot(){if(Te)return ue;Te=1;const n=(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(m=>{const[h,f]=m.split("=");i[h]=f}),i},s=(c="")=>{if(o(c)&&c.length)return o(c);{let i=navigator.language||navigator.userLanguage;if(i.indexOf("en")<0&&i.indexOf("es")<0&&(i="en-US"),i=i.split("-")[0],i)return c.length&&r(c,730,i),i}return"en"},t=(c=0,i=0,u=window,m="smooth")=>u.scroll({top:c,left:i,behavior:m}),r=(c,i,u,m="/",h="Lax")=>{var f=new Date;f.setTime(f.getTime()+i*24*60*60*1e3);const g="; expires="+f.toUTCString();document.cookie=`${c}=${u||""}${g};path=${m};SameSite=${h}`},o=c=>{const i=`${c}=`,m=decodeURIComponent(document.cookie).split(";");for(let h=0;h<m.length;h+=1){let f=m[h];for(;f.charAt(0)===" ";)f=f.substring(1);if(f.indexOf(i)===0)return f.substring(i.length,f.length)}return""};return ue={getCookie:o,createCookie:r,deleteCookie:c=>document.cookie=`${c}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;`,getUserLanguage:s,scrollTo:t,parseQueries:e,validation:n},ue}var Ut=Ot();function Kt(){const{t:n,language:e}=C.useTranslation();return{timeAge:d.useCallback(t=>{const o=new Date-t,a=Math.floor(o/(1e3*60)),c=Math.floor(a/60),i=e==="es",u=n("_accessibility:labels.ago"),m=n("_accessibility:labels.minute"),h=n("_accessibility:labels.minutes"),f=n("_accessibility:labels.hour"),g=n("_accessibility:labels.hours"),p=n("_accessibility:labels.yesterday"),y=n("_accessibility:labels.justNow");return o<1e3*60?y:a<60?`${i?u:""} ${a} ${a===1?m:h} ${i?"":u}`:c<24?`${i?u:""} ${c} ${c===1?f:g} ${i?"":u}`:c<48?p:t.toLocaleDateString(navigator.language||"es-ES",{day:"2-digit",month:"2-digit",year:"numeric"})},[n,e])}}const ye=n=>{const{showSuccessNotification:e}=G(),{mutationFn:s,onError:t,onSuccess:r,onSuccessMessage:o}=n,[a,c]=d.useState([]),{open:i,handleClose:u,handleOpen:m}=we(),h=()=>{u(),c([])},f=async p=>{c(p),m()},g=P.useMutation({mutationFn:()=>s(Array.isArray(a)?a:[a]),onError:p=>{console.error(p),t&&t(p),h()},onSuccess:async p=>{r&&r(p),e({message:o}),h()}});return{open:i,onClick:f,close:h,dialogFn:g,isLoading:g.isPending}},Qt=n=>{const{t:e}=C.useTranslation(),{showStackNotifications:s,showSuccessNotification:t,showErrorNotification:r}=G(),o=P.useQueryClient(),{defaultValues:a,mutationFn:c,formToDto:i,onError:u,onSuccess:m,queryKey:h,onSuccessMessage:f}=n,{control:g,handleSubmit:p,reset:y,setError:b,getValues:w,setValue:S}=ve.useForm({defaultValues:a}),x=d.useRef(null),k=d.useCallback(()=>{const T=document.activeElement;if(!(T instanceof HTMLElement)){x.current=null;return}x.current=T.closest("form")},[]),v=d.useCallback(T=>{const j=T==null?void 0:T.errors,$=[],L=x.current;if(!L)return $;let O=!1;return j&&j.forEach(([ee,W])=>{const U=L.querySelector(`[name="${ee}"]`);(U instanceof HTMLInputElement||U instanceof HTMLTextAreaElement||U instanceof HTMLSelectElement)&&(O||(U.focus(),O=!0),U.classList.add("error"),$.push(e(`_entities:${h}.${ee}.${W}`)))}),$},[e,h]),_=d.useCallback(()=>{const T=x.current;if(!T)return;T.querySelectorAll("input, textarea, select").forEach($=>{$.classList.remove("error")})},[]),Q=P.useMutation({mutationFn:c,onError:T=>{console.error(T);const j=T;if(u)u(T);else if(oe(j)){const $=v(j);s($.map(L=>({message:L,type:M.error})))}else if(ae(j)){const $=j.message||e("_accessibility:errors.500"),L=e(`_accessibility:errors.${j.status}`);r({message:L||$})}else r({message:e("_accessibility:errors.500")})},onSuccess:async T=>{await o.invalidateQueries({queryKey:h}),m&&m(T),f&&t({message:f})}});return{control:g,getValues:w,setValue:S,handleSubmit:p,onSubmit:T=>{k(),_(),Q.mutate(i?i(T):T)},reset:y,setError:b,isLoading:Q.isPending}},_e=n=>{const{t:e}=C.useTranslation(),{onClick:s,icon:t=R.faTrash,sticky:r=!0,hidden:o=!1,multiple:a=!0,disabled:c=!1,id:i=H.Delete,tooltip:u=e("_pages:common.actions.delete.text")}=n;return{action:d.useCallback(h=>({id:i,sticky:r,tooltip:u,multiple:a,onClick:()=>s([h==null?void 0:h.id]),hidden:!!h.deletedAt||o,disabled:!!h.deletedAt||c,icon:l.jsx(K.FontAwesomeIcon,{className:"text-bg-error",icon:t}),onMultipleClick:f=>s(f.map(g=>g.id))}),[c,o,t,i,a,s,r,u])}},Oe=n=>{const{t:e}=C.useTranslation(),{onClick:s,sticky:t=!0,hidden:r=!1,disabled:o=!1,multiple:a=!1,icon:c=R.faRotateLeft,id:i=H.Restore,tooltip:u=e("_pages:common.actions.restore.text")}=n;return{action:d.useCallback(h=>({id:i,sticky:t,tooltip:u,multiple:a,onClick:()=>s([h==null?void 0:h.id]),hidden:!h.deletedAt||r,disabled:!h.deletedAt||o,icon:l.jsx(K.FontAwesomeIcon,{className:"text-bg-error",icon:c}),onMultipleClick:f=>s(f.map(g=>g.id))}),[o,r,c,i,a,s,t,u])}},qt=n=>{const{t:e}=C.useTranslation(),{onClick:s,hidden:t=!1,sticky:r=!0,disabled:o=!1,id:a=H.Edit,icon:c=R.faPencil,tooltip:i=e("_pages:common.actions.edit.text")}=n;return{action:d.useCallback(m=>({id:a,sticky:r,tooltip:i,onClick:()=>s(m==null?void 0:m.id),hidden:!!m.deletedAt||t,disabled:!!m.deletedAt||o,icon:l.jsx(K.FontAwesomeIcon,{className:"primary",icon:c})}),[o,t,c,a,s,r,i])}};var H=(n=>(n.Add="add",n.Edit="edit",n.Delete="delete",n.Restore="restore",n.Refresh="refresh",n.Export="export",n.Import="import",n))(H||{});const Ue=n=>{const{t:e}=C.useTranslation(),{onClick:s,hidden:t=!1,disabled:r=!1,isLoading:o=!1}=n;return{action:d.useCallback(()=>({id:H.Export,hidden:t,disabled:r,icon:l.jsx(K.FontAwesomeIcon,{className:`${o?"rotate":""}`,icon:o?R.faCircleNotch:R.faCloudArrowDown}),tooltip:e("_pages:common.actions.export.text"),onClick:s}),[r,t,o,s,e])}},Ke=n=>{const{t:e}=C.useTranslation(),{onClick:s,hidden:t=!1,disabled:r=!1,isLoading:o=!1}=n;return{action:d.useCallback(()=>({id:H.Import,hidden:t,disabled:r,icon:l.jsx(K.FontAwesomeIcon,{className:`${o?"rotate":""}`,icon:o?R.faCircleNotch:R.faCloudUpload}),tooltip:e("_pages:common.actions.import.text"),onClick:s}),[r,t,o,s,e])}},Bt=n=>{const{queryKey:e,onSuccess:s,...t}=n,r=P.useQueryClient(),{showStackNotifications:o}=G(),{t:a}=C.useTranslation(),{open:c,onClick:i,close:u,dialogFn:m,isLoading:h}=ye({onSuccessMessage:a("_pages:common.actions.delete.successMessage"),onError:g=>{const p=g;if(oe(p))o(p.errors.map(([y,b])=>({message:a(`_pages:${y}.errors.${b}`),type:M.error})));else if(ae(p)){const y=p.message||a("_accessibility:errors.500"),b=a(`_accessibility:errors.${p.status}`);o([{message:b||y,type:M.error}])}},onSuccess:async g=>{await r.invalidateQueries({queryKey:e}),s&&s(g)},...t}),{action:f}=_e({onClick:i});return{onClick:i,title:a("_pages:common.actions.delete.dialog.title"),open:c,isLoading:h,handleSubmit:()=>m.mutate(),handleClose:u,action:f}},we=()=>{const[n,e]=d.useState(!1);return{open:n,setOpen:e,handleClose:()=>e(!1),handleOpen:()=>e(!0)}},Ce=n=>{const{closeOnSubmit:e=!0,defaultValues:s,dtoToForm:t,formToDto:r,mode:o="state",onApply:a,onClear:c,onError:i,onSubmit:u,reinitializeOnOpen:m,resetOnOpen:h,title:f}=n,[g,p]=d.useState(),[y,b]=d.useState(!1),w=d.useRef(!1),S=d.useRef(null),{open:x,handleClose:k,handleOpen:v}=we(),{control:_,handleSubmit:Q,reset:T,setError:j,getValues:$,setValue:L}=ve.useForm({defaultValues:s||{}});d.useEffect(()=>{if(!x){w.current=!1,S.current=null;return}if(w.current)return;if(w.current=!0,S.current){T(S.current),S.current=null;return}const A=t;if(m&&A){T(A(s||{}));return}if(m&&s){T(s);return}h&&T(s||{})},[s,t,x,m,T,h]);const O=d.useCallback(()=>{k(),T()},[k,T]),ee=d.useCallback(A=>{let N,z;typeof A=="number"||A==null?N=A:(N=A.id,z=A.values),p(N),z?x?T(z):S.current=z:S.current=null,x||v()},[v,x,T]),W=d.useCallback(A=>{const N=r;return N?N(A,{id:g}):A},[r,g]),U=d.useCallback(async(A,N,z)=>{i&&await i(A,{close:O,id:g,phase:N,values:z})},[O,g,i]),We=d.useCallback(async()=>{if(!a)return;const A=$();b(!0);try{const N=W(A);await a(N,{close:O,id:g,values:A})}catch(N){throw await U(N,"apply",A).catch(()=>{}),N}finally{b(!1)}},[O,$,U,g,W,a]),ze=d.useCallback(async()=>{const A=$();if(c){b(!0);try{await c()}catch(N){throw await U(N,"clear",A).catch(()=>{}),N}finally{b(!1)}}try{T(s||{})}catch(N){throw await U(N,"clear",A).catch(()=>{}),N}},[s,$,U,c,T]),Je=d.useCallback(async A=>{b(!0);try{const N=W(A);u&&await u(N,{close:O,id:g,values:A}),e&&O()}catch(N){throw await U(N,"submit",A).catch(()=>{}),N}finally{b(!1)}},[O,e,U,g,W,u]);return{open:x,mode:o,id:g,openDialog:ee,handleClose:O,control:_,getValues:$,setValue:L,handleSubmit:Q,onSubmit:Je,reset:T,setError:j,title:f,isSubmitting:y,onApply:We,onClear:ze,isLoading:y}},Ht=n=>{const e=P.useQueryClient(),{mutationFn:s,queryKey:t,onSuccess:r,onError:o,formToDto:a,...c}=n,i=P.useMutation({mutationFn:s});return Ce({...c,mode:"entity",formToDto:a,onSubmit:async u=>{try{const m=await i.mutateAsync(u);t&&await e.invalidateQueries({queryKey:t}),r&&await r(m)}catch(m){throw o&&o(m),m}}})},Vt=n=>{const e=P.useQueryClient(),s=d.useRef(),t=d.useRef(),{mutationFn:r,queryKey:o,onSuccess:a,onError:c,formToDto:i,getFunction:u,dtoToForm:m,title:h,...f}=n,g=d.useRef(m);d.useEffect(()=>{g.current=m},[m]);const p=P.useMutation({mutationFn:r}),y=Ce({...f,mode:"entity",title:h,onSubmit:async x=>{try{const k=await p.mutateAsync(x);o&&await e.invalidateQueries({queryKey:o}),a&&await a(k)}catch(k){throw c&&c(k),k}},formToDto:x=>{const k=i;return k?k(x,s.current):x}}),{reset:b}=y,w=o||["put-dialog",h],S=P.useQuery({queryFn:()=>u(y.id),queryKey:[...w,y.id],enabled:y.open&&!!y.id});return d.useEffect(()=>{if(S.data&&t.current!==S.data){if(s.current=S.data,t.current=S.data,g.current&&b){b(g.current(S.data));return}b==null||b(S.data)}},[S.data,b]),{...y,isLoading:y.isLoading||p.isPending||S.isFetching||S.isLoading}},Gt=n=>{const{queryKey:e,onSuccess:s,...t}=n,r=P.useQueryClient(),{showStackNotifications:o}=G(),{t:a}=C.useTranslation(),{open:c,onClick:i,close:u,dialogFn:m,isLoading:h}=ye({onSuccessMessage:a("_pages:common.actions.restore.successMessage"),onError:g=>{const p=g;if(oe(p))o(p.errors.map(([y,b])=>({message:a(`_pages:${y}.errors.${b}`),type:M.error})));else if(ae(p)){const y=p.message||a("_accessibility:errors.500"),b=a(`_accessibility:errors.${p.status}`);o([{message:b||y,type:M.error}])}},onSuccess:async g=>{await r.invalidateQueries({queryKey:e}),s&&s(g)},...t}),{action:f}=Oe({onClick:i});return{onClick:i,title:a("_pages:common.actions.restore.dialog.title"),open:c,isLoading:h,handleSubmit:()=>m.mutate(),handleClose:u,action:f}};function Wt(n){const{t:e}=C.useTranslation(),s=P.useQueryClient(),{queryKey:t,mutationFn:r,entity:o,fileProcessor:a,renderCustomPreview:c,onError:i}=n,[u,m]=d.useState(!1),[h,f]=d.useState(null),[g,p]=d.useState(!1),y=P.useMutation({mutationFn:r,onError:w=>{console.error(w),i==null||i(w)},onSuccess:async()=>{await s.invalidateQueries({queryKey:t})}}),{action:b}=Ke({onClick:()=>m(!0)});return{handleSubmit:async()=>{if(!(!h||h.length===0))try{await y.mutateAsync({items:h,override:g}),m(!1),f(null),p(!1)}catch(w){console.error(w)}},isLoading:y.isPending,fileProcessor:a,onFileProcessed:w=>f(w),renderCustomPreview:c,onOverrideChange:w=>p(w),open:u,title:e("_pages:common.actions.import.dialog.title",{entity:e(`_pages:${o}.title`)}),handleClose:()=>{m(!1),f(null),p(!1)},action:b}}const zt=n=>{const{showSuccessNotification:e}=G(),{t:s}=C.useTranslation(),{entity:t,mutationFn:r,onError:o,onSuccess:a,onSuccessMessage:c=s("_pages:common.actions.export.successMessage")}=n,i=P.useMutation({mutationFn:()=>r(),onError:h=>{console.error(h),o&&o(h)},onSuccess:async h=>{const f=JSON.stringify(h,null,2),g=new Blob([f],{type:"application/json"}),p=URL.createObjectURL(g),y=document.createElement("a");y.href=p,y.download=`${t}.json`,y.click(),URL.revokeObjectURL(p),a&&a(h),e({message:c})}}),u=d.useCallback(()=>{i.mutate()},[i]),{action:m}=Ue({onClick:u,isLoading:i.isPending});return{action:m}},ke=()=>typeof window<"u"?window.scrollY:0;function Qe(n){const[e,s]=d.useState(ke),t=d.useCallback(()=>{s(ke())},[]);return d.useEffect(()=>(window.addEventListener("scroll",t),()=>{window.removeEventListener("scroll",t)}),[t]),e>n}const Jt=n=>{const{t:e}=C.useTranslation(),{icon:s=R.faArrowUp,threshold:t=200,scrollTop:r=0,scrollLeft:o=0,tooltip:a=e("_accessibility:buttons.toTop"),scrollOnClick:c=!0,onClick:i,className:u="",variant:m="submit",color:h="primary",...f}=n,g=Qe(t),p=()=>{i==null||i(),c&&Ut.scrollTo(o,r)};return l.jsx(B,{variant:m,color:h,icon:s,"data-tooltip-id":"tooltip",onClick:p,className:`to-top ${g?"show":"hide"} ${u}`.trim(),"data-tooltip-content":a,...f})};function Yt(n){const{t:e}=C.useTranslation();if("children"in n){const{children:k,className:v}=n;return l.jsx("div",{className:`error-container${v?` ${v}`:""}`,children:k})}const{error:t,message:r,iconProps:o,onRetry:a,retryLabel:c,retryButtonProps:i,messageProps:u,className:m,resetErrorBoundary:h}=n,f=a??h,{className:g,children:p,onClick:y,...b}=i??{},{className:w,...S}=u??{},x=o!==null;return l.jsxs("div",{className:`error-container${m?` ${m}`:""}`,children:[x&&l.jsx(K.FontAwesomeIcon,{...o,icon:(o==null?void 0:o.icon)??Ze.faSadTear,className:`error-icon${o!=null&&o.className?` ${o.className}`:""}`}),l.jsx("p",{...S,className:`error-message${w?` ${w}`:""}`,children:r??(t==null?void 0:t.message)??e("_accessibility:errors.unknownError")}),f&&l.jsx(C.Button,{type:"button",variant:"submit",color:"primary",...b,className:`error-retry ${g?` ${g}`:""}`,onClick:k=>{y==null||y(k),k.defaultPrevented||f()},children:p??c??e("_accessibility:actions.retry",{defaultValue:"Retry"})})]})}const Xt=n=>{const{showBackButton:e,title:s,actions:t}=n,{t:r}=C.useTranslation(),{navigate:o}=Y();return l.jsxs("div",{className:"page-header",children:[l.jsxs("div",{className:"page-header-left",children:[e&&l.jsx(B,{icon:R.faArrowLeft,onClick:()=>o(-1),className:"page-header-back",name:r("_accessibility:buttons.back"),"data-tooltip-id":"tooltip","data-tooltip-content":r("_accessibility:buttons.back")}),l.jsx("h2",{className:"page-header-title",children:s})]}),l.jsxs("div",{children:[l.jsx(C.Actions,{className:"page-header-actions-desktop",actions:t??[]}),l.jsx(C.ActionsDropdown,{className:"page-header-actions-mobile",actions:t??[]})]})]})},Zt=n=>{const{title:e,children:s,addOptions:t,filterOptions:r,actions:o,queryKey:a,isLoading:c=!1,isAnimated:i=!0,showBackButton:u=!1}=n,{t:m}=C.useTranslation(),h=P.useQueryClient(),{countOfFilters:f}=C.useTableOptions(),g=d.useMemo(()=>{const p=Array.isArray(o)?[...o]:[];if(a){const y={id:H.Refresh,onClick:()=>h.invalidateQueries({queryKey:a}),icon:l.jsx(K.FontAwesomeIcon,{icon:R.faRotateLeft}),tooltip:m("_pages:common.actions.refresh.text")};p.unshift(y)}if(t){const y={...t,id:H.Add,icon:l.jsx(K.FontAwesomeIcon,{icon:R.faAdd})};p.unshift(y)}if(r){const y={...r,id:"filter",icon:l.jsx(K.FontAwesomeIcon,{icon:R.faFilter}),children:l.jsx(C.Badge,{className:`${f>0?"show":"hide"} `,count:f})};p.push(y)}return p},[o,t,f,r,h,a,m]);return l.jsxs("main",{className:"page-main",children:[l.jsx(Xt,{showBackButton:u,actions:g,title:e}),l.jsx("div",{className:`page-main-content ${i?"appear":""}`,children:c?l.jsx(C.Loading,{className:"page-loading"}):s}),t&&l.jsx(B,{icon:t.icon??R.faAdd,color:t.color??"primary",variant:t.variant??"submit",onClick:()=>{var p;return(p=t.onClick)==null?void 0:p.call(t)},className:`button page-fab ${t.className??""}`})]})},es=n=>{const{t:e}=C.useTranslation(),{className:s="",itemClassName:t="",loading:r=!1,emptyComponent:o=null,emptyMessage:a=e("_accessibility:messages.empty"),renderComponent:c,data:i=[],hasMore:u=!1,loadingMore:m=!1,onLoadMore:h,loadMoreComponent:f=null,observerRootMargin:g="0px 0px 200px 0px",observerThreshold:p=0}=n,y=d.useRef(!1),b=d.useRef(null),w=d.useCallback(async()=>{if(!(!u||!h)&&!(m||y.current)){y.current=!0;try{await h()}finally{y.current=!1}}},[u,m,h]);return d.useEffect(()=>{if(!u||!h||!b.current||typeof IntersectionObserver>"u")return;const S=new IntersectionObserver(x=>{x.some(k=>k.isIntersecting)&&w()},{rootMargin:g,threshold:p});return S.observe(b.current),()=>S.disconnect()},[u,h,g,p,w]),r?l.jsx(C.Loading,{}):l.jsx(l.Fragment,{children:i!=null&&i.length?l.jsxs("ul",{className:`pretty-grid-main ${s}`,children:[i==null?void 0:i.map(S=>l.jsx("li",{className:`pretty-grid-item ${t}`,children:c(S)},S.id)),u&&h&&l.jsx("li",{className:"pretty-grid-load-more",ref:b,children:f})]}):l.jsx(l.Fragment,{children:o||l.jsx(Ge,{message:a})})})},xe=d.createContext({title:"",setTitle:()=>{},rightContent:null,setRightContent:()=>{}}),ts=n=>{const{children:e}=n,[s,t]=d.useState(""),[r,o]=d.useState(null),a=d.useCallback(u=>{t(u)},[]),c=d.useCallback(u=>{o(u)},[]),i=d.useMemo(()=>({title:s,setTitle:a,rightContent:r,setRightContent:c}),[s,a,r,c]);return l.jsx(xe.Provider,{value:i,children:e})},qe=()=>d.useContext(xe);function ss(n){const{t:e}=C.useTranslation(),{openDrawer:s,showSearch:t=!0,menuButtonProps:r}=n,{searchComponent:o,location:a}=Y(),{title:c,rightContent:i}=qe(),[u,m]=d.useState(!1),h=d.useCallback(p=>{($e()?p.metaKey:p.ctrlKey)&&p.shiftKey&&p.key.toLowerCase()==="f"&&(m(!0),p.preventDefault())},[]);d.useEffect(()=>(window.addEventListener("keydown",h),()=>{window.removeEventListener("keydown",h)}),[h]);const f=o,g=t&&!!f;return l.jsxs(l.Fragment,{children:[a.pathname!=="/"&&!!f&&l.jsx(f,{open:u,onClose:()=>m(!1)}),l.jsxs("header",{id:"header",className:"header",children:[l.jsxs("div",{className:"navbar-left",children:[l.jsx(B,{...r,type:(r==null?void 0:r.type)??"button",icon:(r==null?void 0:r.icon)??R.faBars,onClick:p=>{var y;(y=r==null?void 0:r.onClick)==null||y.call(r,p),s()},name:(r==null?void 0:r.name)??e("_accessibility:buttons.openMenu"),"aria-label":(r==null?void 0:r["aria-label"])??e("_accessibility:ariaLabels.openMenu"),className:`navbar-menu animated ${(r==null?void 0:r.className)??""}`}),l.jsx("h1",{className:"poppins navbar-title",children:c||e("_pages:home.appName")})]}),l.jsxs("div",{className:"navbar-right",children:[i,g&&l.jsx(B,{icon:R.faSearch,className:"navbar-search-btn",onClick:()=>m(!0)})]})]})]})}const te=300,ns=n=>n??M.error,rs=n=>{switch(n){case M.error:return R.faWarning;default:return R.faCircleCheck}},de=n=>{switch(n){case M.success:return"!text-success";case M.error:return"!text-error";case M.warning:return"!text-warning";default:return"!text-info"}},os=n=>{switch(n){case M.success:return"bg-bg-success";case M.error:return"bg-bg-error";case M.warning:return"bg-bg-warning";default:return"bg-bg-info"}};function as(){const{t:n}=C.useTranslation(),{notification:e,removeNotification:s}=G(),[t,r]=d.useState([]),o=d.useRef(t);d.useLayoutEffect(()=>{o.current=t});const a=d.useRef(null),c=d.useCallback(i=>{r(u=>i!==void 0?u.map(m=>m.id===i?{...m,closing:!0}:m):u.map(m=>({...m,closing:!0}))),i!==void 0?setTimeout(()=>{s(i),r(u=>u.filter(m=>m.id!==i))},te):(a.current&&clearTimeout(a.current),a.current=setTimeout(()=>{s(),r([]),a.current=null},te))},[s]);return d.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(g=>g.map(p=>({...p,closing:!0}))),i=null},0),a.current=setTimeout(()=>{r([]),a.current=null},te),u);const m=new Set(o.current.map(g=>g.id));if(!e.some(g=>g.id!==void 0&&!m.has(g.id)))return;if(o.current.length===0){const g=[...e];return i=setTimeout(()=>{r(g.map(p=>({...p,closing:!1}))),i=null},0),()=>{i&&clearTimeout(i)}}a.current&&clearTimeout(a.current),i=setTimeout(()=>{r(g=>g.every(p=>p.closing)?g:g.map(p=>({...p,closing:!0}))),i=null},0);const f=[...e];return a.current=setTimeout(()=>{r(f.map(g=>({...g,closing:!1}))),a.current=null},te),u},[e]),d.useEffect(()=>{if(!t.length)return;let i;const u=window.setTimeout(()=>{i=()=>c(),window.addEventListener("click",i)},0),m=h=>{h.key==="Escape"&&c()};return window.addEventListener("keydown",m),()=>{window.clearTimeout(u),i&&window.removeEventListener("click",i),window.removeEventListener("keydown",m)}},[t.length,c]),Ee.createPortal(l.jsx("div",{className:`notification-portal ${t.length?"active":""}`,children:t.map(({id:i,type:u,message:m,closing:h})=>{const f=ns(u);return l.jsxs("div",{className:`notification ${h?"closing":""} ${os(f)}`,onClick:g=>g.stopPropagation(),children:[l.jsxs("div",{className:"notification-body",children:[l.jsx(K.FontAwesomeIcon,{icon:rs(f),className:`notification-icon ${de(f)}`}),l.jsx("p",{className:`notification-text ${de(f)}`,children:m})]}),l.jsx(B,{type:"button",icon:R.faClose,color:"error",className:"notification-close group",onClick:g=>{g.stopPropagation(),i!==void 0&&c(i)},iconClassName:`${de(f)} notification-close-icon`,name:n("_accessibility:buttons.closeNotification"),"aria-label":n("_accessibility:ariaLabels.closeNotification")})]},i)})}),document.body)}function is(n){const{className:e,...s}=n;return l.jsx("div",{className:"splash-screen",children:l.jsx(C.Loading,{className:`blur-appear ${e?` ${e}`:""}`,...s})})}const Be=n=>{const{id:e,active:s,onClick:t,children:r,to:o,useLinks:a=!0,tabButtonProps:c}=n,{linkComponent:i}=Y(),u=i;if(!a){const{className:h="",variant:f=s?"submit":"outlined",color:g=s?"primary":"default",...p}=c??{};return l.jsx(C.Button,{type:"button",variant:f,color:g,className:`tab ${h}`,onClick:t,...p,children:r})}const m=`button submit tab ${s?"primary":"outlined"} ${(c==null?void 0:c.className)??""}`.trim();return l.jsx(u,{to:o??`#${e}`,onClick:()=>t(),className:m,children:r})},He=n=>{var g;const{tabs:e=[],defaultTab:s,currentTab:t,onTabChange:r,className:o="",tabsContainerClassName:a="",useLinks:c=!0,tabButtonProps:i}=n,[u,m]=d.useState(s??((g=e[0])==null?void 0:g.id)),h=t??u,f=d.useMemo(()=>e.find(p=>p.id===h),[e,h]);return l.jsxs("div",{className:`tabs-layout-main ${o}`,children:[l.jsx("ul",{className:`horizontal tabs tabs-container ${a}`,children:e.map(({id:p,to:y,label:b})=>l.jsx("li",{children:l.jsx(Be,{onClick:()=>{t===void 0&&m(p),r==null||r(p)},id:p,to:y,siblings:e.length>1,active:h===p,useLinks:c,tabButtonProps:i,children:b})},p))}),f==null?void 0:f.content]})},Ve=n=>{const{title:e,body:s,content:t,onClickNext:r,onSkip:o,onStartAsGuest:a,onSignIn:c,image:i="",alt:u="",final:m=!1}=n,{t:h}=C.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}),s!=null&&l.jsx("div",{className:"step-body",children:s}),t!=null&&l.jsx("div",{className:"step-content",children:t}),l.jsx("div",{className:"step-actions",children:m?l.jsxs(l.Fragment,{children:[l.jsx(C.Button,{color:"primary",className:"step-button",variant:"outlined",onClick:a,"aria-label":h("_accessibility:ariaLabels.start"),children:h("_accessibility:buttons.startAsGuest")}),l.jsx(C.Button,{color:"primary",variant:"submit",className:"step-button","aria-label":h("_accessibility:ariaLabels.start"),onClick:c,children:h("_accessibility:buttons.signIn")})]}):l.jsxs(l.Fragment,{children:[l.jsx(C.Button,{color:"primary",className:"step-button",variant:"outlined",onClick:o,"aria-label":h("_accessibility:ariaLabels.skip"),children:h("_accessibility:buttons.skip")}),l.jsx(C.Button,{color:"primary",className:"step-button",variant:"outlined",onClick:()=>r(),"aria-label":h("_accessibility:ariaLabels.next"),children:h("_accessibility:buttons.next")})]})})]})},cs=n=>{const{steps:e,signInPath:s="/auth/sign-in",guestPath:t="/",onSkip:r,onSignIn:o,onStartAsGuest:a}=n,{setGuestMode:c}=pe(),{navigate:i}=Y(),[u,m]=d.useState(1),h=d.useCallback(()=>{if(r){r();return}i(s)},[i,r,s]),f=d.useCallback(()=>{if(o){o();return}i(s)},[i,o,s]),g=d.useCallback(()=>{if(a){a();return}c(!0),i(t)},[t,i,a,c]),p=d.useMemo(()=>e.map((y,b)=>({id:b+1,label:"",content:l.jsx(Ve,{...y,final:b===e.length-1,onClickNext:()=>m(w=>w+1),onSkip:h,onStartAsGuest:g,onSignIn:f})})),[f,h,g,e]);return l.jsx("div",{className:"onboarding-main",children:l.jsx(He,{currentTab:u,onTabChange:y=>m(Number(y)),tabs:p,useLinks:!1})})},Ge=n=>{const{message:e,messageProps:s={className:"empty-message"},action:t,iconProps:r}=n;return l.jsxs("div",{className:"empty-container",children:[r&&l.jsx(K.FontAwesomeIcon,{...r}),l.jsx("p",{...s,children:e}),t&&l.jsx(C.Action,{showTooltips:!1,showText:!0,...t})]})};Object.defineProperty(exports,"Action",{enumerable:!0,get:()=>C.Action});Object.defineProperty(exports,"Actions",{enumerable:!0,get:()=>C.Actions});Object.defineProperty(exports,"ActionsDropdown",{enumerable:!0,get:()=>C.ActionsDropdown});Object.defineProperty(exports,"Button",{enumerable:!0,get:()=>C.Button});exports.APIClient=Z;exports.AppIconButton=B;exports.AuthClient=je;exports.AuthContext=ce;exports.AuthProvider=Rt;exports.BaseClient=pt;exports.ConfigProvider=Pt;exports.ConfirmationDialog=rt;exports.Dialog=ne;exports.DialogActions=re;exports.Drawer=_t;exports.DrawerMenuContext=be;exports.DrawerMenuProvider=Ft;exports.Empty=Ge;exports.Error=Yt;exports.FormContainer=tt;exports.FormDialog=nt;exports.GlobalActions=H;exports.IManager=ft;exports.IconButton=B;exports.ImportDialog=lt;exports.IndexedDBClient=gt;exports.ManagerProvider=Dt;exports.Methods=I;exports.Navbar=ss;exports.NavbarContext=xe;exports.NavbarProvider=ts;exports.Notification=as;exports.NotificationEnumType=M;exports.NotificationProvider=jt;exports.Onboarding=cs;exports.Page=Zt;exports.ParagraphInput=et;exports.PasswordInput=st;exports.PrettyGrid=es;exports.SplashScreen=is;exports.Step=Ve;exports.SupabaseAuthProvider=Lt;exports.SupabaseDataClient=Ct;exports.SupabaseManagerContext=ge;exports.SupabaseManagerProvider=It;exports.Tab=Be;exports.TabsLayout=He;exports.ToTop=Jt;exports.buildQueryUrl=Ae;exports.createQueryClient=ie;exports.enumToKeyValueArray=kt;exports.formatForDatetimeLocal=Nt;exports.fromLocal=q;exports.getFormattedDateTime=Et;exports.getShortFormattedDateTime=vt;exports.isHttpError=ae;exports.isMac=$e;exports.isValidationError=oe;exports.makeRequest=se;exports.mapSupabaseSessionToSessionDto=he;exports.mapValidationErrors=At;exports.parseQueries=fe;exports.queryClient=$t;exports.removeFromLocal=D;exports.toLocal=F;exports.useAuth=pe;exports.useAuthContext=Ie;exports.useConfig=Y;exports.useConfirmationForm=ye;exports.useDeleteAction=_e;exports.useDeleteDialog=Bt;exports.useDialog=we;exports.useDrawerMenu=Fe;exports.useEditAction=qt;exports.useExportAction=Ue;exports.useExportActionMutate=zt;exports.useFormDialog=Ce;exports.useImportAction=Ke;exports.useImportDialog=Wt;exports.useManager=Le;exports.useNavbar=qe;exports.useNotification=G;exports.usePostDialog=Ht;exports.usePostForm=Qt;exports.usePutDialog=Vt;exports.useRestoreAction=Oe;exports.useRestoreDialog=Gt;exports.useScrollTrigger=Qe;exports.useSupabase=Pe;exports.useTimeAge=Kt;Object.keys(C).forEach(n=>{n!=="default"&&!Object.prototype.hasOwnProperty.call(exports,n)&&Object.defineProperty(exports,n,{enumerable:!0,get:()=>C[n]})});