@sito/dashboard-app 0.0.53 → 0.0.55

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