@ciscode/ui-authentication-kit 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.umd.js CHANGED
@@ -1,49 +1,49 @@
1
- (function(I,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("react"),require("axios"),require("jwt-decode"),require("react-dom"),require("react-router")):typeof define=="function"&&define.amd?define(["exports","react","axios","jwt-decode","react-dom","react-router"],o):(I=typeof globalThis<"u"?globalThis:I||self,o(I["ciscode-model"]={},I.React,I.axios,I.jwtDecode,I.ReactDOM,I.reactRouter))})(this,function(I,o,ue,et,tt,U){"use strict";function st(r){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const t in r)if(t!=="default"){const s=Object.getOwnPropertyDescriptor(r,t);Object.defineProperty(e,t,s.get?s:{enumerable:!0,get:()=>r[t]})}}return e.default=r,Object.freeze(e)}const Z=st(o),Ne=o.createContext(null);function Se(){const r=o.useContext(Ne);if(!r)throw new Error("useAuthConfig must be used within an AuthConfigProvider");return r}const ve=o.createContext(null);function G(){const r=o.useContext(ve);if(!r)throw new Error("useAuthState must be inside <AuthProvider>");return r}function ce(r){const e=et.jwtDecode(r);return{id:e.sub,email:e.email??"",roles:e.roles??[],permissions:e.permissions??[],modules:e.modules??[],tenantId:e.tenantId??""}}let de=!1;function nt(){de=!1}function rt(r,e){r.defaults.withCredentials=!0;const t=`${e.baseUrl}${e.refreshEndpoint??"/auth/refresh-token"}`;r.interceptors.request.use(i=>{const a=e.getAccessToken();return a&&(i.headers.Authorization=`Bearer ${a}`),i});let s=!1,n=[];return r.interceptors.response.use(i=>i,async i=>{var l;const a=i.config;if(((l=i.response)==null?void 0:l.status)!==401||!a||a._retry)return Promise.reject(i);if(a._retry=!0,!s){s=!0;try{const{data:c}=await ue.post(t,{},{withCredentials:!0});return e.setAccessToken(c.accessToken),n.forEach(u=>u(c.accessToken)),n=[],r.request(a)}catch(c){return!!e.getAccessToken()&&!de&&(de=!0,e.logout()),n.forEach(d=>d(null)),n=[],Promise.reject(c)}finally{s=!1}}return new Promise((c,u)=>{n.push(d=>{if(!d)return u(i);(a.headers??(a.headers={})).Authorization=`Bearer ${d}`,c(r.request(a))})})}),r}const x=r=>typeof r=="string",_=()=>{let r,e;const t=new Promise((s,n)=>{r=s,e=n});return t.resolve=r,t.reject=e,t},Ee=r=>r==null?"":""+r,it=(r,e,t)=>{r.forEach(s=>{e[s]&&(t[s]=e[s])})},at=/###/g,Le=r=>r&&r.indexOf("###")>-1?r.replace(at,"."):r,Ce=r=>!r||x(r),Q=(r,e,t)=>{const s=x(e)?e.split("."):e;let n=0;for(;n<s.length-1;){if(Ce(r))return{};const i=Le(s[n]);!r[i]&&t&&(r[i]=new t),Object.prototype.hasOwnProperty.call(r,i)?r=r[i]:r={},++n}return Ce(r)?{}:{obj:r,k:Le(s[n])}},ke=(r,e,t)=>{const{obj:s,k:n}=Q(r,e,Object);if(s!==void 0||e.length===1){s[n]=t;return}let i=e[e.length-1],a=e.slice(0,e.length-1),l=Q(r,a,Object);for(;l.obj===void 0&&a.length;)i=`${a[a.length-1]}.${i}`,a=a.slice(0,a.length-1),l=Q(r,a,Object),l!=null&&l.obj&&typeof l.obj[`${l.k}.${i}`]<"u"&&(l.obj=void 0);l.obj[`${l.k}.${i}`]=t},ot=(r,e,t,s)=>{const{obj:n,k:i}=Q(r,e,Object);n[i]=n[i]||[],n[i].push(t)},se=(r,e)=>{const{obj:t,k:s}=Q(r,e);if(t&&Object.prototype.hasOwnProperty.call(t,s))return t[s]},lt=(r,e,t)=>{const s=se(r,t);return s!==void 0?s:se(e,t)},Ie=(r,e,t)=>{for(const s in e)s!=="__proto__"&&s!=="constructor"&&(s in r?x(r[s])||r[s]instanceof String||x(e[s])||e[s]instanceof String?t&&(r[s]=e[s]):Ie(r[s],e[s],t):r[s]=e[s]);return r},J=r=>r.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&");var ut={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;","/":"&#x2F;"};const ct=r=>x(r)?r.replace(/[&<>"'\/]/g,e=>ut[e]):r;class dt{constructor(e){this.capacity=e,this.regExpMap=new Map,this.regExpQueue=[]}getRegExp(e){const t=this.regExpMap.get(e);if(t!==void 0)return t;const s=new RegExp(e);return this.regExpQueue.length===this.capacity&&this.regExpMap.delete(this.regExpQueue.shift()),this.regExpMap.set(e,s),this.regExpQueue.push(e),s}}const ft=[" ",",","?","!",";"],ht=new dt(20),gt=(r,e,t)=>{e=e||"",t=t||"";const s=ft.filter(a=>e.indexOf(a)<0&&t.indexOf(a)<0);if(s.length===0)return!0;const n=ht.getRegExp(`(${s.map(a=>a==="?"?"\\?":a).join("|")})`);let i=!n.test(r);if(!i){const a=r.indexOf(t);a>0&&!n.test(r.substring(0,a))&&(i=!0)}return i},fe=(r,e,t=".")=>{if(!r)return;if(r[e])return Object.prototype.hasOwnProperty.call(r,e)?r[e]:void 0;const s=e.split(t);let n=r;for(let i=0;i<s.length;){if(!n||typeof n!="object")return;let a,l="";for(let c=i;c<s.length;++c)if(c!==i&&(l+=t),l+=s[c],a=n[l],a!==void 0){if(["string","number","boolean"].indexOf(typeof a)>-1&&c<s.length-1)continue;i+=c-i+1;break}n=a}return n},q=r=>r==null?void 0:r.replace("_","-"),mt={type:"logger",log(r){this.output("log",r)},warn(r){this.output("warn",r)},error(r){this.output("error",r)},output(r,e){var t,s;(s=(t=console==null?void 0:console[r])==null?void 0:t.apply)==null||s.call(t,console,e)}};class ne{constructor(e,t={}){this.init(e,t)}init(e,t={}){this.prefix=t.prefix||"i18next:",this.logger=e||mt,this.options=t,this.debug=t.debug}log(...e){return this.forward(e,"log","",!0)}warn(...e){return this.forward(e,"warn","",!0)}error(...e){return this.forward(e,"error","")}deprecate(...e){return this.forward(e,"warn","WARNING DEPRECATED: ",!0)}forward(e,t,s,n){return n&&!this.debug?null:(x(e[0])&&(e[0]=`${s}${this.prefix} ${e[0]}`),this.logger[t](e))}create(e){return new ne(this.logger,{prefix:`${this.prefix}:${e}:`,...this.options})}clone(e){return e=e||this.options,e.prefix=e.prefix||this.prefix,new ne(this.logger,e)}}var K=new ne;class re{constructor(){this.observers={}}on(e,t){return e.split(" ").forEach(s=>{this.observers[s]||(this.observers[s]=new Map);const n=this.observers[s].get(t)||0;this.observers[s].set(t,n+1)}),this}off(e,t){if(this.observers[e]){if(!t){delete this.observers[e];return}this.observers[e].delete(t)}}emit(e,...t){this.observers[e]&&Array.from(this.observers[e].entries()).forEach(([n,i])=>{for(let a=0;a<i;a++)n(...t)}),this.observers["*"]&&Array.from(this.observers["*"].entries()).forEach(([n,i])=>{for(let a=0;a<i;a++)n.apply(n,[e,...t])})}}class je extends re{constructor(e,t={ns:["translation"],defaultNS:"translation"}){super(),this.data=e||{},this.options=t,this.options.keySeparator===void 0&&(this.options.keySeparator="."),this.options.ignoreJSONStructure===void 0&&(this.options.ignoreJSONStructure=!0)}addNamespaces(e){this.options.ns.indexOf(e)<0&&this.options.ns.push(e)}removeNamespaces(e){const t=this.options.ns.indexOf(e);t>-1&&this.options.ns.splice(t,1)}getResource(e,t,s,n={}){var u,d;const i=n.keySeparator!==void 0?n.keySeparator:this.options.keySeparator,a=n.ignoreJSONStructure!==void 0?n.ignoreJSONStructure:this.options.ignoreJSONStructure;let l;e.indexOf(".")>-1?l=e.split("."):(l=[e,t],s&&(Array.isArray(s)?l.push(...s):x(s)&&i?l.push(...s.split(i)):l.push(s)));const c=se(this.data,l);return!c&&!t&&!s&&e.indexOf(".")>-1&&(e=l[0],t=l[1],s=l.slice(2).join(".")),c||!a||!x(s)?c:fe((d=(u=this.data)==null?void 0:u[e])==null?void 0:d[t],s,i)}addResource(e,t,s,n,i={silent:!1}){const a=i.keySeparator!==void 0?i.keySeparator:this.options.keySeparator;let l=[e,t];s&&(l=l.concat(a?s.split(a):s)),e.indexOf(".")>-1&&(l=e.split("."),n=t,t=l[1]),this.addNamespaces(t),ke(this.data,l,n),i.silent||this.emit("added",e,t,s,n)}addResources(e,t,s,n={silent:!1}){for(const i in s)(x(s[i])||Array.isArray(s[i]))&&this.addResource(e,t,i,s[i],{silent:!0});n.silent||this.emit("added",e,t,s)}addResourceBundle(e,t,s,n,i,a={silent:!1,skipCopy:!1}){let l=[e,t];e.indexOf(".")>-1&&(l=e.split("."),n=s,s=t,t=l[1]),this.addNamespaces(t);let c=se(this.data,l)||{};a.skipCopy||(s=JSON.parse(JSON.stringify(s))),n?Ie(c,s,i):c={...c,...s},ke(this.data,l,c),a.silent||this.emit("added",e,t,s)}removeResourceBundle(e,t){this.hasResourceBundle(e,t)&&delete this.data[e][t],this.removeNamespaces(t),this.emit("removed",e,t)}hasResourceBundle(e,t){return this.getResource(e,t)!==void 0}getResourceBundle(e,t){return t||(t=this.options.defaultNS),this.getResource(e,t)}getDataByLanguage(e){return this.data[e]}hasLanguageSomeTranslations(e){const t=this.getDataByLanguage(e);return!!(t&&Object.keys(t)||[]).find(n=>t[n]&&Object.keys(t[n]).length>0)}toJSON(){return this.data}}var Oe={processors:{},addPostProcessor(r){this.processors[r.name]=r},handle(r,e,t,s,n){return r.forEach(i=>{var a;e=((a=this.processors[i])==null?void 0:a.process(e,t,s,n))??e}),e}};const Pe=Symbol("i18next/PATH_KEY");function pt(){const r=[],e=Object.create(null);let t;return e.get=(s,n)=>{var i;return(i=t==null?void 0:t.revoke)==null||i.call(t),n===Pe?r:(r.push(n),t=Proxy.revocable(s,e),t.proxy)},Proxy.revocable(Object.create(null),e).proxy}function he(r,e){const{[Pe]:t}=r(pt());return t.join((e==null?void 0:e.keySeparator)??".")}const Me={},ge=r=>!x(r)&&typeof r!="boolean"&&typeof r!="number";class ie extends re{constructor(e,t={}){super(),it(["resourceStore","languageUtils","pluralResolver","interpolator","backendConnector","i18nFormat","utils"],e,this),this.options=t,this.options.keySeparator===void 0&&(this.options.keySeparator="."),this.logger=K.create("translator")}changeLanguage(e){e&&(this.language=e)}exists(e,t={interpolation:{}}){const s={...t};if(e==null)return!1;const n=this.resolve(e,s);if((n==null?void 0:n.res)===void 0)return!1;const i=ge(n.res);return!(s.returnObjects===!1&&i)}extractFromKey(e,t){let s=t.nsSeparator!==void 0?t.nsSeparator:this.options.nsSeparator;s===void 0&&(s=":");const n=t.keySeparator!==void 0?t.keySeparator:this.options.keySeparator;let i=t.ns||this.options.defaultNS||[];const a=s&&e.indexOf(s)>-1,l=!this.options.userDefinedKeySeparator&&!t.keySeparator&&!this.options.userDefinedNsSeparator&&!t.nsSeparator&&!gt(e,s,n);if(a&&!l){const c=e.match(this.interpolator.nestingRegexp);if(c&&c.length>0)return{key:e,namespaces:x(i)?[i]:i};const u=e.split(s);(s!==n||s===n&&this.options.ns.indexOf(u[0])>-1)&&(i=u.shift()),e=u.join(n)}return{key:e,namespaces:x(i)?[i]:i}}translate(e,t,s){let n=typeof t=="object"?{...t}:t;if(typeof n!="object"&&this.options.overloadTranslationOptionHandler&&(n=this.options.overloadTranslationOptionHandler(arguments)),typeof n=="object"&&(n={...n}),n||(n={}),e==null)return"";typeof e=="function"&&(e=he(e,{...this.options,...n})),Array.isArray(e)||(e=[String(e)]);const i=n.returnDetails!==void 0?n.returnDetails:this.options.returnDetails,a=n.keySeparator!==void 0?n.keySeparator:this.options.keySeparator,{key:l,namespaces:c}=this.extractFromKey(e[e.length-1],n),u=c[c.length-1];let d=n.nsSeparator!==void 0?n.nsSeparator:this.options.nsSeparator;d===void 0&&(d=":");const f=n.lng||this.language,m=n.appendNamespaceToCIMode||this.options.appendNamespaceToCIMode;if((f==null?void 0:f.toLowerCase())==="cimode")return m?i?{res:`${u}${d}${l}`,usedKey:l,exactUsedKey:l,usedLng:f,usedNS:u,usedParams:this.getUsedParamsDetails(n)}:`${u}${d}${l}`:i?{res:l,usedKey:l,exactUsedKey:l,usedLng:f,usedNS:u,usedParams:this.getUsedParamsDetails(n)}:l;const g=this.resolve(e,n);let h=g==null?void 0:g.res;const p=(g==null?void 0:g.usedKey)||l,y=(g==null?void 0:g.exactUsedKey)||l,L=["[object Number]","[object Function]","[object RegExp]"],b=n.joinArrays!==void 0?n.joinArrays:this.options.joinArrays,E=!this.i18nFormat||this.i18nFormat.handleAsObject,w=n.count!==void 0&&!x(n.count),C=ie.hasDefaultValue(n),F=w?this.pluralResolver.getSuffix(f,n.count,n):"",P=n.ordinal&&w?this.pluralResolver.getSuffix(f,n.count,{ordinal:!1}):"",v=w&&!n.ordinal&&n.count===0,S=v&&n[`defaultValue${this.options.pluralSeparator}zero`]||n[`defaultValue${F}`]||n[`defaultValue${P}`]||n.defaultValue;let N=h;E&&!h&&C&&(N=S);const z=ge(N),M=Object.prototype.toString.apply(N);if(E&&N&&z&&L.indexOf(M)<0&&!(x(b)&&Array.isArray(N))){if(!n.returnObjects&&!this.options.returnObjects){this.options.returnedObjectHandler||this.logger.warn("accessing an object - but returnObjects options is not enabled!");const D=this.options.returnedObjectHandler?this.options.returnedObjectHandler(p,N,{...n,ns:c}):`key '${l} (${this.language})' returned an object instead of string.`;return i?(g.res=D,g.usedParams=this.getUsedParamsDetails(n),g):D}if(a){const D=Array.isArray(N),j=D?[]:{},k=D?y:p;for(const $ in N)if(Object.prototype.hasOwnProperty.call(N,$)){const T=`${k}${a}${$}`;C&&!h?j[$]=this.translate(T,{...n,defaultValue:ge(S)?S[$]:void 0,joinArrays:!1,ns:c}):j[$]=this.translate(T,{...n,joinArrays:!1,ns:c}),j[$]===T&&(j[$]=N[$])}h=j}}else if(E&&x(b)&&Array.isArray(h))h=h.join(b),h&&(h=this.extendTranslation(h,e,n,s));else{let D=!1,j=!1;!this.isValidLookup(h)&&C&&(D=!0,h=S),this.isValidLookup(h)||(j=!0,h=l);const $=(n.missingKeyNoValueFallbackToKey||this.options.missingKeyNoValueFallbackToKey)&&j?void 0:h,T=C&&S!==h&&this.options.updateMissing;if(j||D||T){if(this.logger.log(T?"updateKey":"missingKey",f,u,l,T?S:h),a){const A=this.resolve(l,{...n,keySeparator:!1});A&&A.res&&this.logger.warn("Seems the loaded translations were in flat JSON format instead of nested. Either set keySeparator: false on init or make sure your translations are published in nested format.")}let V=[];const O=this.languageUtils.getFallbackCodes(this.options.fallbackLng,n.lng||this.language);if(this.options.saveMissingTo==="fallback"&&O&&O[0])for(let A=0;A<O.length;A++)V.push(O[A]);else this.options.saveMissingTo==="all"?V=this.languageUtils.toResolveHierarchy(n.lng||this.language):V.push(n.lng||this.language);const W=(A,H,te)=>{var Re;const Xe=C&&te!==h?te:$;this.options.missingKeyHandler?this.options.missingKeyHandler(A,u,H,Xe,T,n):(Re=this.backendConnector)!=null&&Re.saveMissing&&this.backendConnector.saveMissing(A,u,H,Xe,T,n),this.emit("missingKey",A,u,H,h)};this.options.saveMissing&&(this.options.saveMissingPlurals&&w?V.forEach(A=>{const H=this.pluralResolver.getSuffixes(A,n);v&&n[`defaultValue${this.options.pluralSeparator}zero`]&&H.indexOf(`${this.options.pluralSeparator}zero`)<0&&H.push(`${this.options.pluralSeparator}zero`),H.forEach(te=>{W([A],l+te,n[`defaultValue${te}`]||S)})}):W(V,l,S))}h=this.extendTranslation(h,e,n,g,s),j&&h===l&&this.options.appendNamespaceToMissingKey&&(h=`${u}${d}${l}`),(j||D)&&this.options.parseMissingKeyHandler&&(h=this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey?`${u}${d}${l}`:l,D?h:void 0,n))}return i?(g.res=h,g.usedParams=this.getUsedParamsDetails(n),g):h}extendTranslation(e,t,s,n,i){var c,u;if((c=this.i18nFormat)!=null&&c.parse)e=this.i18nFormat.parse(e,{...this.options.interpolation.defaultVariables,...s},s.lng||this.language||n.usedLng,n.usedNS,n.usedKey,{resolved:n});else if(!s.skipInterpolation){s.interpolation&&this.interpolator.init({...s,interpolation:{...this.options.interpolation,...s.interpolation}});const d=x(e)&&(((u=s==null?void 0:s.interpolation)==null?void 0:u.skipOnVariables)!==void 0?s.interpolation.skipOnVariables:this.options.interpolation.skipOnVariables);let f;if(d){const g=e.match(this.interpolator.nestingRegexp);f=g&&g.length}let m=s.replace&&!x(s.replace)?s.replace:s;if(this.options.interpolation.defaultVariables&&(m={...this.options.interpolation.defaultVariables,...m}),e=this.interpolator.interpolate(e,m,s.lng||this.language||n.usedLng,s),d){const g=e.match(this.interpolator.nestingRegexp),h=g&&g.length;f<h&&(s.nest=!1)}!s.lng&&n&&n.res&&(s.lng=this.language||n.usedLng),s.nest!==!1&&(e=this.interpolator.nest(e,(...g)=>(i==null?void 0:i[0])===g[0]&&!s.context?(this.logger.warn(`It seems you are nesting recursively key: ${g[0]} in key: ${t[0]}`),null):this.translate(...g,t),s)),s.interpolation&&this.interpolator.reset()}const a=s.postProcess||this.options.postProcess,l=x(a)?[a]:a;return e!=null&&(l!=null&&l.length)&&s.applyPostProcessor!==!1&&(e=Oe.handle(l,e,t,this.options&&this.options.postProcessPassResolved?{i18nResolved:{...n,usedParams:this.getUsedParamsDetails(s)},...s}:s,this)),e}resolve(e,t={}){let s,n,i,a,l;return x(e)&&(e=[e]),e.forEach(c=>{if(this.isValidLookup(s))return;const u=this.extractFromKey(c,t),d=u.key;n=d;let f=u.namespaces;this.options.fallbackNS&&(f=f.concat(this.options.fallbackNS));const m=t.count!==void 0&&!x(t.count),g=m&&!t.ordinal&&t.count===0,h=t.context!==void 0&&(x(t.context)||typeof t.context=="number")&&t.context!=="",p=t.lngs?t.lngs:this.languageUtils.toResolveHierarchy(t.lng||this.language,t.fallbackLng);f.forEach(y=>{var L,b;this.isValidLookup(s)||(l=y,!Me[`${p[0]}-${y}`]&&((L=this.utils)!=null&&L.hasLoadedNamespace)&&!((b=this.utils)!=null&&b.hasLoadedNamespace(l))&&(Me[`${p[0]}-${y}`]=!0,this.logger.warn(`key "${n}" for languages "${p.join(", ")}" won't get resolved as namespace "${l}" was not yet loaded`,"This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!")),p.forEach(E=>{var F;if(this.isValidLookup(s))return;a=E;const w=[d];if((F=this.i18nFormat)!=null&&F.addLookupKeys)this.i18nFormat.addLookupKeys(w,d,E,y,t);else{let P;m&&(P=this.pluralResolver.getSuffix(E,t.count,t));const v=`${this.options.pluralSeparator}zero`,S=`${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;if(m&&(t.ordinal&&P.indexOf(S)===0&&w.push(d+P.replace(S,this.options.pluralSeparator)),w.push(d+P),g&&w.push(d+v)),h){const N=`${d}${this.options.contextSeparator||"_"}${t.context}`;w.push(N),m&&(t.ordinal&&P.indexOf(S)===0&&w.push(N+P.replace(S,this.options.pluralSeparator)),w.push(N+P),g&&w.push(N+v))}}let C;for(;C=w.pop();)this.isValidLookup(s)||(i=C,s=this.getResource(E,y,C,t))}))})}),{res:s,usedKey:n,exactUsedKey:i,usedLng:a,usedNS:l}}isValidLookup(e){return e!==void 0&&!(!this.options.returnNull&&e===null)&&!(!this.options.returnEmptyString&&e==="")}getResource(e,t,s,n={}){var i;return(i=this.i18nFormat)!=null&&i.getResource?this.i18nFormat.getResource(e,t,s,n):this.resourceStore.getResource(e,t,s,n)}getUsedParamsDetails(e={}){const t=["defaultValue","ordinal","context","replace","lng","lngs","fallbackLng","ns","keySeparator","nsSeparator","returnObjects","returnDetails","joinArrays","postProcess","interpolation"],s=e.replace&&!x(e.replace);let n=s?e.replace:e;if(s&&typeof e.count<"u"&&(n.count=e.count),this.options.interpolation.defaultVariables&&(n={...this.options.interpolation.defaultVariables,...n}),!s){n={...n};for(const i of t)delete n[i]}return n}static hasDefaultValue(e){const t="defaultValue";for(const s in e)if(Object.prototype.hasOwnProperty.call(e,s)&&t===s.substring(0,t.length)&&e[s]!==void 0)return!0;return!1}}class Te{constructor(e){this.options=e,this.supportedLngs=this.options.supportedLngs||!1,this.logger=K.create("languageUtils")}getScriptPartFromCode(e){if(e=q(e),!e||e.indexOf("-")<0)return null;const t=e.split("-");return t.length===2||(t.pop(),t[t.length-1].toLowerCase()==="x")?null:this.formatLanguageCode(t.join("-"))}getLanguagePartFromCode(e){if(e=q(e),!e||e.indexOf("-")<0)return e;const t=e.split("-");return this.formatLanguageCode(t[0])}formatLanguageCode(e){if(x(e)&&e.indexOf("-")>-1){let t;try{t=Intl.getCanonicalLocales(e)[0]}catch{}return t&&this.options.lowerCaseLng&&(t=t.toLowerCase()),t||(this.options.lowerCaseLng?e.toLowerCase():e)}return this.options.cleanCode||this.options.lowerCaseLng?e.toLowerCase():e}isSupportedCode(e){return(this.options.load==="languageOnly"||this.options.nonExplicitSupportedLngs)&&(e=this.getLanguagePartFromCode(e)),!this.supportedLngs||!this.supportedLngs.length||this.supportedLngs.indexOf(e)>-1}getBestMatchFromCodes(e){if(!e)return null;let t;return e.forEach(s=>{if(t)return;const n=this.formatLanguageCode(s);(!this.options.supportedLngs||this.isSupportedCode(n))&&(t=n)}),!t&&this.options.supportedLngs&&e.forEach(s=>{if(t)return;const n=this.getScriptPartFromCode(s);if(this.isSupportedCode(n))return t=n;const i=this.getLanguagePartFromCode(s);if(this.isSupportedCode(i))return t=i;t=this.options.supportedLngs.find(a=>{if(a===i)return a;if(!(a.indexOf("-")<0&&i.indexOf("-")<0)&&(a.indexOf("-")>0&&i.indexOf("-")<0&&a.substring(0,a.indexOf("-"))===i||a.indexOf(i)===0&&i.length>1))return a})}),t||(t=this.getFallbackCodes(this.options.fallbackLng)[0]),t}getFallbackCodes(e,t){if(!e)return[];if(typeof e=="function"&&(e=e(t)),x(e)&&(e=[e]),Array.isArray(e))return e;if(!t)return e.default||[];let s=e[t];return s||(s=e[this.getScriptPartFromCode(t)]),s||(s=e[this.formatLanguageCode(t)]),s||(s=e[this.getLanguagePartFromCode(t)]),s||(s=e.default),s||[]}toResolveHierarchy(e,t){const s=this.getFallbackCodes((t===!1?[]:t)||this.options.fallbackLng||[],e),n=[],i=a=>{a&&(this.isSupportedCode(a)?n.push(a):this.logger.warn(`rejecting language code not found in supportedLngs: ${a}`))};return x(e)&&(e.indexOf("-")>-1||e.indexOf("_")>-1)?(this.options.load!=="languageOnly"&&i(this.formatLanguageCode(e)),this.options.load!=="languageOnly"&&this.options.load!=="currentOnly"&&i(this.getScriptPartFromCode(e)),this.options.load!=="currentOnly"&&i(this.getLanguagePartFromCode(e))):x(e)&&i(this.formatLanguageCode(e)),s.forEach(a=>{n.indexOf(a)<0&&i(this.formatLanguageCode(a))}),n}}const $e={zero:0,one:1,two:2,few:3,many:4,other:5},De={select:r=>r===1?"one":"other",resolvedOptions:()=>({pluralCategories:["one","other"]})};class xt{constructor(e,t={}){this.languageUtils=e,this.options=t,this.logger=K.create("pluralResolver"),this.pluralRulesCache={}}clearCache(){this.pluralRulesCache={}}getRule(e,t={}){const s=q(e==="dev"?"en":e),n=t.ordinal?"ordinal":"cardinal",i=JSON.stringify({cleanedCode:s,type:n});if(i in this.pluralRulesCache)return this.pluralRulesCache[i];let a;try{a=new Intl.PluralRules(s,{type:n})}catch{if(!Intl)return this.logger.error("No Intl support, please use an Intl polyfill!"),De;if(!e.match(/-|_/))return De;const c=this.languageUtils.getLanguagePartFromCode(e);a=this.getRule(c,t)}return this.pluralRulesCache[i]=a,a}needsPlural(e,t={}){let s=this.getRule(e,t);return s||(s=this.getRule("dev",t)),(s==null?void 0:s.resolvedOptions().pluralCategories.length)>1}getPluralFormsOfKey(e,t,s={}){return this.getSuffixes(e,s).map(n=>`${t}${n}`)}getSuffixes(e,t={}){let s=this.getRule(e,t);return s||(s=this.getRule("dev",t)),s?s.resolvedOptions().pluralCategories.sort((n,i)=>$e[n]-$e[i]).map(n=>`${this.options.prepend}${t.ordinal?`ordinal${this.options.prepend}`:""}${n}`):[]}getSuffix(e,t,s={}){const n=this.getRule(e,s);return n?`${this.options.prepend}${s.ordinal?`ordinal${this.options.prepend}`:""}${n.select(t)}`:(this.logger.warn(`no plural rule found for: ${e}`),this.getSuffix("dev",t,s))}}const Ae=(r,e,t,s=".",n=!0)=>{let i=lt(r,e,t);return!i&&n&&x(t)&&(i=fe(r,t,s),i===void 0&&(i=fe(e,t,s))),i},me=r=>r.replace(/\$/g,"$$$$");class Ue{constructor(e={}){var t;this.logger=K.create("interpolator"),this.options=e,this.format=((t=e==null?void 0:e.interpolation)==null?void 0:t.format)||(s=>s),this.init(e)}init(e={}){e.interpolation||(e.interpolation={escapeValue:!0});const{escape:t,escapeValue:s,useRawValueToEscape:n,prefix:i,prefixEscaped:a,suffix:l,suffixEscaped:c,formatSeparator:u,unescapeSuffix:d,unescapePrefix:f,nestingPrefix:m,nestingPrefixEscaped:g,nestingSuffix:h,nestingSuffixEscaped:p,nestingOptionsSeparator:y,maxReplaces:L,alwaysFormat:b}=e.interpolation;this.escape=t!==void 0?t:ct,this.escapeValue=s!==void 0?s:!0,this.useRawValueToEscape=n!==void 0?n:!1,this.prefix=i?J(i):a||"{{",this.suffix=l?J(l):c||"}}",this.formatSeparator=u||",",this.unescapePrefix=d?"":f||"-",this.unescapeSuffix=this.unescapePrefix?"":d||"",this.nestingPrefix=m?J(m):g||J("$t("),this.nestingSuffix=h?J(h):p||J(")"),this.nestingOptionsSeparator=y||",",this.maxReplaces=L||1e3,this.alwaysFormat=b!==void 0?b:!1,this.resetRegExp()}reset(){this.options&&this.init(this.options)}resetRegExp(){const e=(t,s)=>(t==null?void 0:t.source)===s?(t.lastIndex=0,t):new RegExp(s,"g");this.regexp=e(this.regexp,`${this.prefix}(.+?)${this.suffix}`),this.regexpUnescape=e(this.regexpUnescape,`${this.prefix}${this.unescapePrefix}(.+?)${this.unescapeSuffix}${this.suffix}`),this.nestingRegexp=e(this.nestingRegexp,`${this.nestingPrefix}((?:[^()"']+|"[^"]*"|'[^']*'|\\((?:[^()]|"[^"]*"|'[^']*')*\\))*?)${this.nestingSuffix}`)}interpolate(e,t,s,n){var g;let i,a,l;const c=this.options&&this.options.interpolation&&this.options.interpolation.defaultVariables||{},u=h=>{if(h.indexOf(this.formatSeparator)<0){const b=Ae(t,c,h,this.options.keySeparator,this.options.ignoreJSONStructure);return this.alwaysFormat?this.format(b,void 0,s,{...n,...t,interpolationkey:h}):b}const p=h.split(this.formatSeparator),y=p.shift().trim(),L=p.join(this.formatSeparator).trim();return this.format(Ae(t,c,y,this.options.keySeparator,this.options.ignoreJSONStructure),L,s,{...n,...t,interpolationkey:y})};this.resetRegExp();const d=(n==null?void 0:n.missingInterpolationHandler)||this.options.missingInterpolationHandler,f=((g=n==null?void 0:n.interpolation)==null?void 0:g.skipOnVariables)!==void 0?n.interpolation.skipOnVariables:this.options.interpolation.skipOnVariables;return[{regex:this.regexpUnescape,safeValue:h=>me(h)},{regex:this.regexp,safeValue:h=>this.escapeValue?me(this.escape(h)):me(h)}].forEach(h=>{for(l=0;i=h.regex.exec(e);){const p=i[1].trim();if(a=u(p),a===void 0)if(typeof d=="function"){const L=d(e,i,n);a=x(L)?L:""}else if(n&&Object.prototype.hasOwnProperty.call(n,p))a="";else if(f){a=i[0];continue}else this.logger.warn(`missed to pass in variable ${p} for interpolating ${e}`),a="";else!x(a)&&!this.useRawValueToEscape&&(a=Ee(a));const y=h.safeValue(a);if(e=e.replace(i[0],y),f?(h.regex.lastIndex+=a.length,h.regex.lastIndex-=i[0].length):h.regex.lastIndex=0,l++,l>=this.maxReplaces)break}}),e}nest(e,t,s={}){let n,i,a;const l=(c,u)=>{const d=this.nestingOptionsSeparator;if(c.indexOf(d)<0)return c;const f=c.split(new RegExp(`${d}[ ]*{`));let m=`{${f[1]}`;c=f[0],m=this.interpolate(m,a);const g=m.match(/'/g),h=m.match(/"/g);(((g==null?void 0:g.length)??0)%2===0&&!h||h.length%2!==0)&&(m=m.replace(/'/g,'"'));try{a=JSON.parse(m),u&&(a={...u,...a})}catch(p){return this.logger.warn(`failed parsing options string in nesting for key ${c}`,p),`${c}${d}${m}`}return a.defaultValue&&a.defaultValue.indexOf(this.prefix)>-1&&delete a.defaultValue,c};for(;n=this.nestingRegexp.exec(e);){let c=[];a={...s},a=a.replace&&!x(a.replace)?a.replace:a,a.applyPostProcessor=!1,delete a.defaultValue;const u=/{.*}/.test(n[1])?n[1].lastIndexOf("}")+1:n[1].indexOf(this.formatSeparator);if(u!==-1&&(c=n[1].slice(u).split(this.formatSeparator).map(d=>d.trim()).filter(Boolean),n[1]=n[1].slice(0,u)),i=t(l.call(this,n[1].trim(),a),a),i&&n[0]===e&&!x(i))return i;x(i)||(i=Ee(i)),i||(this.logger.warn(`missed to resolve ${n[1]} for nesting ${e}`),i=""),c.length&&(i=c.reduce((d,f)=>this.format(d,f,s.lng,{...s,interpolationkey:n[1].trim()}),i.trim())),e=e.replace(n[0],i),this.regexp.lastIndex=0}return e}}const yt=r=>{let e=r.toLowerCase().trim();const t={};if(r.indexOf("(")>-1){const s=r.split("(");e=s[0].toLowerCase().trim();const n=s[1].substring(0,s[1].length-1);e==="currency"&&n.indexOf(":")<0?t.currency||(t.currency=n.trim()):e==="relativetime"&&n.indexOf(":")<0?t.range||(t.range=n.trim()):n.split(";").forEach(a=>{if(a){const[l,...c]=a.split(":"),u=c.join(":").trim().replace(/^'+|'+$/g,""),d=l.trim();t[d]||(t[d]=u),u==="false"&&(t[d]=!1),u==="true"&&(t[d]=!0),isNaN(u)||(t[d]=parseInt(u,10))}})}return{formatName:e,formatOptions:t}},Fe=r=>{const e={};return(t,s,n)=>{let i=n;n&&n.interpolationkey&&n.formatParams&&n.formatParams[n.interpolationkey]&&n[n.interpolationkey]&&(i={...i,[n.interpolationkey]:void 0});const a=s+JSON.stringify(i);let l=e[a];return l||(l=r(q(s),n),e[a]=l),l(t)}},bt=r=>(e,t,s)=>r(q(t),s)(e);class wt{constructor(e={}){this.logger=K.create("formatter"),this.options=e,this.init(e)}init(e,t={interpolation:{}}){this.formatSeparator=t.interpolation.formatSeparator||",";const s=t.cacheInBuiltFormats?Fe:bt;this.formats={number:s((n,i)=>{const a=new Intl.NumberFormat(n,{...i});return l=>a.format(l)}),currency:s((n,i)=>{const a=new Intl.NumberFormat(n,{...i,style:"currency"});return l=>a.format(l)}),datetime:s((n,i)=>{const a=new Intl.DateTimeFormat(n,{...i});return l=>a.format(l)}),relativetime:s((n,i)=>{const a=new Intl.RelativeTimeFormat(n,{...i});return l=>a.format(l,i.range||"day")}),list:s((n,i)=>{const a=new Intl.ListFormat(n,{...i});return l=>a.format(l)})}}add(e,t){this.formats[e.toLowerCase().trim()]=t}addCached(e,t){this.formats[e.toLowerCase().trim()]=Fe(t)}format(e,t,s,n={}){const i=t.split(this.formatSeparator);if(i.length>1&&i[0].indexOf("(")>1&&i[0].indexOf(")")<0&&i.find(l=>l.indexOf(")")>-1)){const l=i.findIndex(c=>c.indexOf(")")>-1);i[0]=[i[0],...i.splice(1,l)].join(this.formatSeparator)}return i.reduce((l,c)=>{var f;const{formatName:u,formatOptions:d}=yt(c);if(this.formats[u]){let m=l;try{const g=((f=n==null?void 0:n.formatParams)==null?void 0:f[n.interpolationkey])||{},h=g.locale||g.lng||n.locale||n.lng||s;m=this.formats[u](l,h,{...d,...n,...g})}catch(g){this.logger.warn(g)}return m}else this.logger.warn(`there was no format function for ${u}`);return l},e)}}const Nt=(r,e)=>{r.pending[e]!==void 0&&(delete r.pending[e],r.pendingCount--)};class St extends re{constructor(e,t,s,n={}){var i,a;super(),this.backend=e,this.store=t,this.services=s,this.languageUtils=s.languageUtils,this.options=n,this.logger=K.create("backendConnector"),this.waitingReads=[],this.maxParallelReads=n.maxParallelReads||10,this.readingCalls=0,this.maxRetries=n.maxRetries>=0?n.maxRetries:5,this.retryTimeout=n.retryTimeout>=1?n.retryTimeout:350,this.state={},this.queue=[],(a=(i=this.backend)==null?void 0:i.init)==null||a.call(i,s,n.backend,n)}queueLoad(e,t,s,n){const i={},a={},l={},c={};return e.forEach(u=>{let d=!0;t.forEach(f=>{const m=`${u}|${f}`;!s.reload&&this.store.hasResourceBundle(u,f)?this.state[m]=2:this.state[m]<0||(this.state[m]===1?a[m]===void 0&&(a[m]=!0):(this.state[m]=1,d=!1,a[m]===void 0&&(a[m]=!0),i[m]===void 0&&(i[m]=!0),c[f]===void 0&&(c[f]=!0)))}),d||(l[u]=!0)}),(Object.keys(i).length||Object.keys(a).length)&&this.queue.push({pending:a,pendingCount:Object.keys(a).length,loaded:{},errors:[],callback:n}),{toLoad:Object.keys(i),pending:Object.keys(a),toLoadLanguages:Object.keys(l),toLoadNamespaces:Object.keys(c)}}loaded(e,t,s){const n=e.split("|"),i=n[0],a=n[1];t&&this.emit("failedLoading",i,a,t),!t&&s&&this.store.addResourceBundle(i,a,s,void 0,void 0,{skipCopy:!0}),this.state[e]=t?-1:2,t&&s&&(this.state[e]=0);const l={};this.queue.forEach(c=>{ot(c.loaded,[i],a),Nt(c,e),t&&c.errors.push(t),c.pendingCount===0&&!c.done&&(Object.keys(c.loaded).forEach(u=>{l[u]||(l[u]={});const d=c.loaded[u];d.length&&d.forEach(f=>{l[u][f]===void 0&&(l[u][f]=!0)})}),c.done=!0,c.errors.length?c.callback(c.errors):c.callback())}),this.emit("loaded",l),this.queue=this.queue.filter(c=>!c.done)}read(e,t,s,n=0,i=this.retryTimeout,a){if(!e.length)return a(null,{});if(this.readingCalls>=this.maxParallelReads){this.waitingReads.push({lng:e,ns:t,fcName:s,tried:n,wait:i,callback:a});return}this.readingCalls++;const l=(u,d)=>{if(this.readingCalls--,this.waitingReads.length>0){const f=this.waitingReads.shift();this.read(f.lng,f.ns,f.fcName,f.tried,f.wait,f.callback)}if(u&&d&&n<this.maxRetries){setTimeout(()=>{this.read.call(this,e,t,s,n+1,i*2,a)},i);return}a(u,d)},c=this.backend[s].bind(this.backend);if(c.length===2){try{const u=c(e,t);u&&typeof u.then=="function"?u.then(d=>l(null,d)).catch(l):l(null,u)}catch(u){l(u)}return}return c(e,t,l)}prepareLoading(e,t,s={},n){if(!this.backend)return this.logger.warn("No backend was added via i18next.use. Will not load resources."),n&&n();x(e)&&(e=this.languageUtils.toResolveHierarchy(e)),x(t)&&(t=[t]);const i=this.queueLoad(e,t,s,n);if(!i.toLoad.length)return i.pending.length||n(),null;i.toLoad.forEach(a=>{this.loadOne(a)})}load(e,t,s){this.prepareLoading(e,t,{},s)}reload(e,t,s){this.prepareLoading(e,t,{reload:!0},s)}loadOne(e,t=""){const s=e.split("|"),n=s[0],i=s[1];this.read(n,i,"read",void 0,void 0,(a,l)=>{a&&this.logger.warn(`${t}loading namespace ${i} for language ${n} failed`,a),!a&&l&&this.logger.log(`${t}loaded namespace ${i} for language ${n}`,l),this.loaded(e,a,l)})}saveMissing(e,t,s,n,i,a={},l=()=>{}){var c,u,d,f,m;if((u=(c=this.services)==null?void 0:c.utils)!=null&&u.hasLoadedNamespace&&!((f=(d=this.services)==null?void 0:d.utils)!=null&&f.hasLoadedNamespace(t))){this.logger.warn(`did not save key "${s}" as the namespace "${t}" was not yet loaded`,"This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!");return}if(!(s==null||s==="")){if((m=this.backend)!=null&&m.create){const g={...a,isUpdate:i},h=this.backend.create.bind(this.backend);if(h.length<6)try{let p;h.length===5?p=h(e,t,s,n,g):p=h(e,t,s,n),p&&typeof p.then=="function"?p.then(y=>l(null,y)).catch(l):l(null,p)}catch(p){l(p)}else h(e,t,s,n,l,g)}!e||!e[0]||this.store.addResource(e[0],t,s,n)}}}const pe=()=>({debug:!1,initAsync:!0,ns:["translation"],defaultNS:["translation"],fallbackLng:["dev"],fallbackNS:!1,supportedLngs:!1,nonExplicitSupportedLngs:!1,load:"all",preload:!1,simplifyPluralSuffix:!0,keySeparator:".",nsSeparator:":",pluralSeparator:"_",contextSeparator:"_",partialBundledLanguages:!1,saveMissing:!1,updateMissing:!1,saveMissingTo:"fallback",saveMissingPlurals:!0,missingKeyHandler:!1,missingInterpolationHandler:!1,postProcess:!1,postProcessPassResolved:!1,returnNull:!1,returnEmptyString:!0,returnObjects:!1,joinArrays:!1,returnedObjectHandler:!1,parseMissingKeyHandler:!1,appendNamespaceToMissingKey:!1,appendNamespaceToCIMode:!1,overloadTranslationOptionHandler:r=>{let e={};if(typeof r[1]=="object"&&(e=r[1]),x(r[1])&&(e.defaultValue=r[1]),x(r[2])&&(e.tDescription=r[2]),typeof r[2]=="object"||typeof r[3]=="object"){const t=r[3]||r[2];Object.keys(t).forEach(s=>{e[s]=t[s]})}return e},interpolation:{escapeValue:!0,format:r=>r,prefix:"{{",suffix:"}}",formatSeparator:",",unescapePrefix:"-",nestingPrefix:"$t(",nestingSuffix:")",nestingOptionsSeparator:",",maxReplaces:1e3,skipOnVariables:!0},cacheInBuiltFormats:!0}),ze=r=>{var e,t;return x(r.ns)&&(r.ns=[r.ns]),x(r.fallbackLng)&&(r.fallbackLng=[r.fallbackLng]),x(r.fallbackNS)&&(r.fallbackNS=[r.fallbackNS]),((t=(e=r.supportedLngs)==null?void 0:e.indexOf)==null?void 0:t.call(e,"cimode"))<0&&(r.supportedLngs=r.supportedLngs.concat(["cimode"])),typeof r.initImmediate=="boolean"&&(r.initAsync=r.initImmediate),r},ae=()=>{},vt=r=>{Object.getOwnPropertyNames(Object.getPrototypeOf(r)).forEach(t=>{typeof r[t]=="function"&&(r[t]=r[t].bind(r))})};class X extends re{constructor(e={},t){if(super(),this.options=ze(e),this.services={},this.logger=K,this.modules={external:[]},vt(this),t&&!this.isInitialized&&!e.isClone){if(!this.options.initAsync)return this.init(e,t),this;setTimeout(()=>{this.init(e,t)},0)}}init(e={},t){this.isInitializing=!0,typeof e=="function"&&(t=e,e={}),e.defaultNS==null&&e.ns&&(x(e.ns)?e.defaultNS=e.ns:e.ns.indexOf("translation")<0&&(e.defaultNS=e.ns[0]));const s=pe();this.options={...s,...this.options,...ze(e)},this.options.interpolation={...s.interpolation,...this.options.interpolation},e.keySeparator!==void 0&&(this.options.userDefinedKeySeparator=e.keySeparator),e.nsSeparator!==void 0&&(this.options.userDefinedNsSeparator=e.nsSeparator),typeof this.options.overloadTranslationOptionHandler!="function"&&(this.options.overloadTranslationOptionHandler=s.overloadTranslationOptionHandler),this.options.debug===!0&&typeof console<"u"&&console.warn("i18next is maintained with support from locize.com — consider powering your project with managed localization (AI, CDN, integrations): https://locize.com");const n=u=>u?typeof u=="function"?new u:u:null;if(!this.options.isClone){this.modules.logger?K.init(n(this.modules.logger),this.options):K.init(null,this.options);let u;this.modules.formatter?u=this.modules.formatter:u=wt;const d=new Te(this.options);this.store=new je(this.options.resources,this.options);const f=this.services;f.logger=K,f.resourceStore=this.store,f.languageUtils=d,f.pluralResolver=new xt(d,{prepend:this.options.pluralSeparator,simplifyPluralSuffix:this.options.simplifyPluralSuffix}),this.options.interpolation.format&&this.options.interpolation.format!==s.interpolation.format&&this.logger.deprecate("init: you are still using the legacy format function, please use the new approach: https://www.i18next.com/translation-function/formatting"),u&&(!this.options.interpolation.format||this.options.interpolation.format===s.interpolation.format)&&(f.formatter=n(u),f.formatter.init&&f.formatter.init(f,this.options),this.options.interpolation.format=f.formatter.format.bind(f.formatter)),f.interpolator=new Ue(this.options),f.utils={hasLoadedNamespace:this.hasLoadedNamespace.bind(this)},f.backendConnector=new St(n(this.modules.backend),f.resourceStore,f,this.options),f.backendConnector.on("*",(g,...h)=>{this.emit(g,...h)}),this.modules.languageDetector&&(f.languageDetector=n(this.modules.languageDetector),f.languageDetector.init&&f.languageDetector.init(f,this.options.detection,this.options)),this.modules.i18nFormat&&(f.i18nFormat=n(this.modules.i18nFormat),f.i18nFormat.init&&f.i18nFormat.init(this)),this.translator=new ie(this.services,this.options),this.translator.on("*",(g,...h)=>{this.emit(g,...h)}),this.modules.external.forEach(g=>{g.init&&g.init(this)})}if(this.format=this.options.interpolation.format,t||(t=ae),this.options.fallbackLng&&!this.services.languageDetector&&!this.options.lng){const u=this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);u.length>0&&u[0]!=="dev"&&(this.options.lng=u[0])}!this.services.languageDetector&&!this.options.lng&&this.logger.warn("init: no languageDetector is used and no lng is defined"),["getResource","hasResourceBundle","getResourceBundle","getDataByLanguage"].forEach(u=>{this[u]=(...d)=>this.store[u](...d)}),["addResource","addResources","addResourceBundle","removeResourceBundle"].forEach(u=>{this[u]=(...d)=>(this.store[u](...d),this)});const l=_(),c=()=>{const u=(d,f)=>{this.isInitializing=!1,this.isInitialized&&!this.initializedStoreOnce&&this.logger.warn("init: i18next is already initialized. You should call init just once!"),this.isInitialized=!0,this.options.isClone||this.logger.log("initialized",this.options),this.emit("initialized",this.options),l.resolve(f),t(d,f)};if(this.languages&&!this.isInitialized)return u(null,this.t.bind(this));this.changeLanguage(this.options.lng,u)};return this.options.resources||!this.options.initAsync?c():setTimeout(c,0),l}loadResources(e,t=ae){var i,a;let s=t;const n=x(e)?e:this.language;if(typeof e=="function"&&(s=e),!this.options.resources||this.options.partialBundledLanguages){if((n==null?void 0:n.toLowerCase())==="cimode"&&(!this.options.preload||this.options.preload.length===0))return s();const l=[],c=u=>{if(!u||u==="cimode")return;this.services.languageUtils.toResolveHierarchy(u).forEach(f=>{f!=="cimode"&&l.indexOf(f)<0&&l.push(f)})};n?c(n):this.services.languageUtils.getFallbackCodes(this.options.fallbackLng).forEach(d=>c(d)),(a=(i=this.options.preload)==null?void 0:i.forEach)==null||a.call(i,u=>c(u)),this.services.backendConnector.load(l,this.options.ns,u=>{!u&&!this.resolvedLanguage&&this.language&&this.setResolvedLanguage(this.language),s(u)})}else s(null)}reloadResources(e,t,s){const n=_();return typeof e=="function"&&(s=e,e=void 0),typeof t=="function"&&(s=t,t=void 0),e||(e=this.languages),t||(t=this.options.ns),s||(s=ae),this.services.backendConnector.reload(e,t,i=>{n.resolve(),s(i)}),n}use(e){if(!e)throw new Error("You are passing an undefined module! Please check the object you are passing to i18next.use()");if(!e.type)throw new Error("You are passing a wrong module! Please check the object you are passing to i18next.use()");return e.type==="backend"&&(this.modules.backend=e),(e.type==="logger"||e.log&&e.warn&&e.error)&&(this.modules.logger=e),e.type==="languageDetector"&&(this.modules.languageDetector=e),e.type==="i18nFormat"&&(this.modules.i18nFormat=e),e.type==="postProcessor"&&Oe.addPostProcessor(e),e.type==="formatter"&&(this.modules.formatter=e),e.type==="3rdParty"&&this.modules.external.push(e),this}setResolvedLanguage(e){if(!(!e||!this.languages)&&!(["cimode","dev"].indexOf(e)>-1)){for(let t=0;t<this.languages.length;t++){const s=this.languages[t];if(!(["cimode","dev"].indexOf(s)>-1)&&this.store.hasLanguageSomeTranslations(s)){this.resolvedLanguage=s;break}}!this.resolvedLanguage&&this.languages.indexOf(e)<0&&this.store.hasLanguageSomeTranslations(e)&&(this.resolvedLanguage=e,this.languages.unshift(e))}}changeLanguage(e,t){this.isLanguageChangingTo=e;const s=_();this.emit("languageChanging",e);const n=l=>{this.language=l,this.languages=this.services.languageUtils.toResolveHierarchy(l),this.resolvedLanguage=void 0,this.setResolvedLanguage(l)},i=(l,c)=>{c?this.isLanguageChangingTo===e&&(n(c),this.translator.changeLanguage(c),this.isLanguageChangingTo=void 0,this.emit("languageChanged",c),this.logger.log("languageChanged",c)):this.isLanguageChangingTo=void 0,s.resolve((...u)=>this.t(...u)),t&&t(l,(...u)=>this.t(...u))},a=l=>{var d,f;!e&&!l&&this.services.languageDetector&&(l=[]);const c=x(l)?l:l&&l[0],u=this.store.hasLanguageSomeTranslations(c)?c:this.services.languageUtils.getBestMatchFromCodes(x(l)?[l]:l);u&&(this.language||n(u),this.translator.language||this.translator.changeLanguage(u),(f=(d=this.services.languageDetector)==null?void 0:d.cacheUserLanguage)==null||f.call(d,u)),this.loadResources(u,m=>{i(m,u)})};return!e&&this.services.languageDetector&&!this.services.languageDetector.async?a(this.services.languageDetector.detect()):!e&&this.services.languageDetector&&this.services.languageDetector.async?this.services.languageDetector.detect.length===0?this.services.languageDetector.detect().then(a):this.services.languageDetector.detect(a):a(e),s}getFixedT(e,t,s){const n=(i,a,...l)=>{let c;typeof a!="object"?c=this.options.overloadTranslationOptionHandler([i,a].concat(l)):c={...a},c.lng=c.lng||n.lng,c.lngs=c.lngs||n.lngs,c.ns=c.ns||n.ns,c.keyPrefix!==""&&(c.keyPrefix=c.keyPrefix||s||n.keyPrefix);const u=this.options.keySeparator||".";let d;return c.keyPrefix&&Array.isArray(i)?d=i.map(f=>(typeof f=="function"&&(f=he(f,{...this.options,...a})),`${c.keyPrefix}${u}${f}`)):(typeof i=="function"&&(i=he(i,{...this.options,...a})),d=c.keyPrefix?`${c.keyPrefix}${u}${i}`:i),this.t(d,c)};return x(e)?n.lng=e:n.lngs=e,n.ns=t,n.keyPrefix=s,n}t(...e){var t;return(t=this.translator)==null?void 0:t.translate(...e)}exists(...e){var t;return(t=this.translator)==null?void 0:t.exists(...e)}setDefaultNamespace(e){this.options.defaultNS=e}hasLoadedNamespace(e,t={}){if(!this.isInitialized)return this.logger.warn("hasLoadedNamespace: i18next was not initialized",this.languages),!1;if(!this.languages||!this.languages.length)return this.logger.warn("hasLoadedNamespace: i18n.languages were undefined or empty",this.languages),!1;const s=t.lng||this.resolvedLanguage||this.languages[0],n=this.options?this.options.fallbackLng:!1,i=this.languages[this.languages.length-1];if(s.toLowerCase()==="cimode")return!0;const a=(l,c)=>{const u=this.services.backendConnector.state[`${l}|${c}`];return u===-1||u===0||u===2};if(t.precheck){const l=t.precheck(this,a);if(l!==void 0)return l}return!!(this.hasResourceBundle(s,e)||!this.services.backendConnector.backend||this.options.resources&&!this.options.partialBundledLanguages||a(s,e)&&(!n||a(i,e)))}loadNamespaces(e,t){const s=_();return this.options.ns?(x(e)&&(e=[e]),e.forEach(n=>{this.options.ns.indexOf(n)<0&&this.options.ns.push(n)}),this.loadResources(n=>{s.resolve(),t&&t(n)}),s):(t&&t(),Promise.resolve())}loadLanguages(e,t){const s=_();x(e)&&(e=[e]);const n=this.options.preload||[],i=e.filter(a=>n.indexOf(a)<0&&this.services.languageUtils.isSupportedCode(a));return i.length?(this.options.preload=n.concat(i),this.loadResources(a=>{s.resolve(),t&&t(a)}),s):(t&&t(),Promise.resolve())}dir(e){var n,i;if(e||(e=this.resolvedLanguage||(((n=this.languages)==null?void 0:n.length)>0?this.languages[0]:this.language)),!e)return"rtl";try{const a=new Intl.Locale(e);if(a&&a.getTextInfo){const l=a.getTextInfo();if(l&&l.direction)return l.direction}}catch{}const t=["ar","shu","sqr","ssh","xaa","yhd","yud","aao","abh","abv","acm","acq","acw","acx","acy","adf","ads","aeb","aec","afb","ajp","apc","apd","arb","arq","ars","ary","arz","auz","avl","ayh","ayl","ayn","ayp","bbz","pga","he","iw","ps","pbt","pbu","pst","prp","prd","ug","ur","ydd","yds","yih","ji","yi","hbo","men","xmn","fa","jpr","peo","pes","prs","dv","sam","ckb"],s=((i=this.services)==null?void 0:i.languageUtils)||new Te(pe());return e.toLowerCase().indexOf("-latn")>1?"ltr":t.indexOf(s.getLanguagePartFromCode(e))>-1||e.toLowerCase().indexOf("-arab")>1?"rtl":"ltr"}static createInstance(e={},t){const s=new X(e,t);return s.createInstance=X.createInstance,s}cloneInstance(e={},t=ae){const s=e.forkResourceStore;s&&delete e.forkResourceStore;const n={...this.options,...e,isClone:!0},i=new X(n);if((e.debug!==void 0||e.prefix!==void 0)&&(i.logger=i.logger.clone(e)),["store","services","language"].forEach(l=>{i[l]=this[l]}),i.services={...this.services},i.services.utils={hasLoadedNamespace:i.hasLoadedNamespace.bind(i)},s){const l=Object.keys(this.store.data).reduce((c,u)=>(c[u]={...this.store.data[u]},c[u]=Object.keys(c[u]).reduce((d,f)=>(d[f]={...c[u][f]},d),c[u]),c),{});i.store=new je(l,n),i.services.resourceStore=i.store}if(e.interpolation){const c={...pe().interpolation,...this.options.interpolation,...e.interpolation},u={...n,interpolation:c};i.services.interpolator=new Ue(u)}return i.translator=new ie(i.services,n),i.translator.on("*",(l,...c)=>{i.emit(l,...c)}),i.init(n,t),i.translator.options=n,i.translator.backendConnector.services.utils={hasLoadedNamespace:i.hasLoadedNamespace.bind(i)},i}toJSON(){return{options:this.options,store:this.store,language:this.language,languages:this.languages,resolvedLanguage:this.resolvedLanguage}}}const B=X.createInstance();B.createInstance,B.dir,B.init,B.loadResources,B.reloadResources,B.use,B.changeLanguage,B.getFixedT,B.t,B.exists,B.setDefaultNamespace,B.hasLoadedNamespace,B.loadNamespaces,B.loadLanguages;const Et=(r,e,t,s)=>{var i,a,l,c;const n=[t,{code:e,...s||{}}];if((a=(i=r==null?void 0:r.services)==null?void 0:i.logger)!=null&&a.forward)return r.services.logger.forward(n,"warn","react-i18next::",!0);Y(n[0])&&(n[0]=`react-i18next:: ${n[0]}`),(c=(l=r==null?void 0:r.services)==null?void 0:l.logger)!=null&&c.warn?r.services.logger.warn(...n):console!=null&&console.warn&&console.warn(...n)},Ve={},xe=(r,e,t,s)=>{Y(t)&&Ve[t]||(Y(t)&&(Ve[t]=new Date),Et(r,e,t,s))},Be=(r,e)=>()=>{if(r.isInitialized)e();else{const t=()=>{setTimeout(()=>{r.off("initialized",t)},0),e()};r.on("initialized",t)}},ye=(r,e,t)=>{r.loadNamespaces(e,Be(r,t))},He=(r,e,t,s)=>{if(Y(t)&&(t=[t]),r.options.preload&&r.options.preload.indexOf(e)>-1)return ye(r,t,s);t.forEach(n=>{r.options.ns.indexOf(n)<0&&r.options.ns.push(n)}),r.loadLanguages(e,Be(r,s))},Lt=(r,e,t={})=>!e.languages||!e.languages.length?(xe(e,"NO_LANGUAGES","i18n.languages were undefined or empty",{languages:e.languages}),!0):e.hasLoadedNamespace(r,{lng:t.lng,precheck:(s,n)=>{if(t.bindI18n&&t.bindI18n.indexOf("languageChanging")>-1&&s.services.backendConnector.backend&&s.isLanguageChangingTo&&!n(s.isLanguageChangingTo,r))return!1}}),Y=r=>typeof r=="string",Ct=r=>typeof r=="object"&&r!==null,kt=/&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g,It={"&amp;":"&","&#38;":"&","&lt;":"<","&#60;":"<","&gt;":">","&#62;":">","&apos;":"'","&#39;":"'","&quot;":'"',"&#34;":'"',"&nbsp;":" ","&#160;":" ","&copy;":"©","&#169;":"©","&reg;":"®","&#174;":"®","&hellip;":"…","&#8230;":"…","&#x2F;":"/","&#47;":"/"},jt=r=>It[r];let Ot={bindI18n:"languageChanged",bindI18nStore:"",transEmptyNodeValue:"",transSupportBasicHtmlNodes:!0,transWrapTextNodes:"",transKeepBasicHtmlNodesFor:["br","strong","i","p"],useSuspense:!0,unescape:r=>r.replace(kt,jt)};const Pt=()=>Ot;let Mt;const Tt=()=>Mt,$t=o.createContext();class Dt{constructor(){this.usedNamespaces={}}addUsedNamespaces(e){e.forEach(t=>{this.usedNamespaces[t]||(this.usedNamespaces[t]=!0)})}getUsedNamespaces(){return Object.keys(this.usedNamespaces)}}const At=(r,e)=>{const t=o.useRef();return o.useEffect(()=>{t.current=e?t.current:r},[r,e]),t.current},Ke=(r,e,t,s)=>r.getFixedT(e,t,s),Ut=(r,e,t,s)=>o.useCallback(Ke(r,e,t,s),[r,e,t,s]),Ft=(r,e={})=>{var w,C,F,P;const{i18n:t}=e,{i18n:s,defaultNS:n}=o.useContext($t)||{},i=t||s||Tt();if(i&&!i.reportNamespaces&&(i.reportNamespaces=new Dt),!i){xe(i,"NO_I18NEXT_INSTANCE","useTranslation: You will need to pass in an i18next instance by using initReactI18next");const v=(N,z)=>Y(z)?z:Ct(z)&&Y(z.defaultValue)?z.defaultValue:Array.isArray(N)?N[N.length-1]:N,S=[v,{},!1];return S.t=v,S.i18n={},S.ready=!1,S}(w=i.options.react)!=null&&w.wait&&xe(i,"DEPRECATED_OPTION","useTranslation: It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");const a={...Pt(),...i.options.react,...e},{useSuspense:l,keyPrefix:c}=a;let u=r||n||((C=i.options)==null?void 0:C.defaultNS);u=Y(u)?[u]:u||["translation"],(P=(F=i.reportNamespaces).addUsedNamespaces)==null||P.call(F,u);const d=(i.isInitialized||i.initializedStoreOnce)&&u.every(v=>Lt(v,i,a)),f=Ut(i,e.lng||null,a.nsMode==="fallback"?u:u[0],c),m=()=>f,g=()=>Ke(i,e.lng||null,a.nsMode==="fallback"?u:u[0],c),[h,p]=o.useState(m);let y=u.join();e.lng&&(y=`${e.lng}${y}`);const L=At(y),b=o.useRef(!0);o.useEffect(()=>{const{bindI18n:v,bindI18nStore:S}=a;b.current=!0,!d&&!l&&(e.lng?He(i,e.lng,u,()=>{b.current&&p(g)}):ye(i,u,()=>{b.current&&p(g)})),d&&L&&L!==y&&b.current&&p(g);const N=()=>{b.current&&p(g)};return v&&(i==null||i.on(v,N)),S&&(i==null||i.store.on(S,N)),()=>{b.current=!1,i&&v&&(v==null||v.split(" ").forEach(z=>i.off(z,N))),S&&i&&S.split(" ").forEach(z=>i.store.off(z,N))}},[i,y]),o.useEffect(()=>{b.current&&d&&p(m)},[i,c,d]);const E=[h,i,d];if(E.t=h,E.i18n=i,E.ready=d,d||!d&&!l)return E;throw new Promise(v=>{e.lng?He(i,e.lng,u,()=>v()):ye(i,u,()=>v())})};let zt=!1;try{document.cookie,zt=!0}catch{}function oe(r){const{t:e}=Ft(r);return e}const Vt=({onConfirm:r})=>{const e=oe("authLib");return o.useEffect(()=>{const{body:t}=document,s=t.style.overflow,n=t.style.pointerEvents;return t.style.overflow="hidden",t.style.pointerEvents="none",()=>{t.style.overflow=s,t.style.pointerEvents=n}},[]),tt.createPortal(o.createElement("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-black/40 backdrop-blur-sm"},o.createElement("div",{className:"pointer-events-auto w-full max-w-sm rounded-xl bg-white p-6 shadow-xl"},o.createElement("h2",{className:"mb-4 text-xl font-semibold text-gray-800 ltr:text-left rtl:text-center"},e("sessionExpired.title")),o.createElement("p",{className:"mb-8 text-sm text-gray-600 ltr:text-left rtl:text-center"},e("sessionExpired.message")),o.createElement("div",{className:"flex justify-end"},o.createElement("button",{onClick:r,className:`
1
+ (function(m,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("react"),require("axios"),require("jwt-decode"),require("react-dom"),require("@ciscode/ui-translate-core"),require("react-router")):typeof define=="function"&&define.amd?define(["exports","react","axios","jwt-decode","react-dom","@ciscode/ui-translate-core","react-router"],e):(m=typeof globalThis<"u"?globalThis:m||self,e(m["ciscode-model"]={},m.React,m.axios,m.jwtDecode,m.ReactDOM,m.uiTranslateCore,m.reactRouter))})(this,function(m,e,H,me,ue,O,p){"use strict";function de(t){const l=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const n in t)if(n!=="default"){const r=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(l,n,r.get?r:{enumerable:!0,get:()=>t[n]})}}return l.default=t,Object.freeze(l)}const z=de(e),R=e.createContext(null);function ee(){const t=e.useContext(R);if(!t)throw new Error("useAuthConfig must be used within an AuthConfigProvider");return t}const te=e.createContext(null);function j(){const t=e.useContext(te);if(!t)throw new Error("useAuthState must be inside <AuthProvider>");return t}function Q(t){const l=me.jwtDecode(t);return{id:l.sub,email:l.email??"",roles:l.roles??[],permissions:l.permissions??[],modules:l.modules??[],tenantId:l.tenantId??""}}let q=!1;function ge(){q=!1}function fe(t,l){t.defaults.withCredentials=!0;const n=`${l.baseUrl}${l.refreshEndpoint??"/auth/refresh-token"}`;t.interceptors.request.use(s=>{const a=l.getAccessToken();return a&&(s.headers.Authorization=`Bearer ${a}`),s});let r=!1,o=[];return t.interceptors.response.use(s=>s,async s=>{var c;const a=s.config;if(((c=s.response)==null?void 0:c.status)!==401||!a||a._retry)return Promise.reject(s);if(a._retry=!0,!r){r=!0;try{const{data:i}=await H.post(n,{},{withCredentials:!0});return l.setAccessToken(i.accessToken),o.forEach(u=>u(i.accessToken)),o=[],t.request(a)}catch(i){return!!l.getAccessToken()&&!q&&(q=!0,l.logout()),o.forEach(b=>b(null)),o=[],Promise.reject(i)}finally{r=!1}}return new Promise((i,u)=>{o.push(b=>{if(!b)return u(s);(a.headers??(a.headers={})).Authorization=`Bearer ${b}`,i(t.request(a))})})}),t}const he=({onConfirm:t})=>{const l=O.useT("authLib");return e.useEffect(()=>{const{body:n}=document,r=n.style.overflow,o=n.style.pointerEvents;return n.style.overflow="hidden",n.style.pointerEvents="none",()=>{n.style.overflow=r,n.style.pointerEvents=o}},[]),ue.createPortal(e.createElement("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-black/40 backdrop-blur-sm"},e.createElement("div",{className:"pointer-events-auto w-full max-w-sm rounded-xl bg-white p-6 shadow-xl"},e.createElement("h2",{className:"mb-4 text-xl font-semibold text-gray-800 ltr:text-left rtl:text-center"},l("sessionExpired.title")),e.createElement("p",{className:"mb-8 text-sm text-gray-600 ltr:text-left rtl:text-center"},l("sessionExpired.message")),e.createElement("div",{className:"flex justify-end"},e.createElement("button",{onClick:t,className:`
2
2
  rounded-lg bg-red-600 px-4 py-2 text-sm font-medium text-white
3
3
  hover:bg-red-700 focus-visible:outline focus-visible:outline-2
4
4
  focus-visible:outline-offset-2 focus-visible:outline-red-600
5
- `},e("sessionExpired.button"))))),document.body)},R=({label:r,type:e="text",placeholder:t,color:s="",value:n,onChange:i})=>{const a=Z.useId();return Z.createElement("div",{className:"mt-8 flex flex-col"},r&&Z.createElement("label",{htmlFor:a,className:"self-start text-base text-black dark:text-white block ltr:text-left rtl:text-right"},r),Z.createElement("input",{id:a,type:e,placeholder:t||void 0,value:n,onChange:l=>i==null?void 0:i(l.target.value),className:`
5
+ `},l("sessionExpired.button"))))),document.body)},W=({label:t,type:l="text",placeholder:n,color:r="",value:o,onChange:s})=>{const a=z.useId();return z.createElement("div",{className:"mt-8 flex flex-col"},t&&z.createElement("label",{htmlFor:a,className:"self-start text-base text-black dark:text-white block ltr:text-left rtl:text-right"},t),z.createElement("input",{id:a,type:l,placeholder:n||void 0,value:o,onChange:c=>s==null?void 0:s(c.target.value),className:`
6
6
  px-4 py-4 mt-3.5 text-sm font-light rounded-lg border border-solid w-full
7
7
  ltr:text-left rtl:text-right
8
- ${s}
9
- `}))},We=({icon:r,label:e})=>Z.createElement("div",{className:"flex gap-5 px-8 py-3 items-center bg-indigo-50 rounded-lg max-md:px-5"},Z.createElement("img",{loading:"lazy",src:r,alt:e||"",className:"object-contain shrink-0 aspect-square w-[26px]"}),e&&Z.createElement("div",{className:"basis-auto text-sm hidden md:block ltr:text-left rtl:text-right"},e)),Ge="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48IS0tIFVwbG9hZGVkIHRvOiBTVkcgUmVwbywgd3d3LnN2Z3JlcG8uY29tLCBHZW5lcmF0b3I6IFNWRyBSZXBvIE1peGVyIFRvb2xzIC0tPgo8c3ZnIHdpZHRoPSI4MDBweCIgaGVpZ2h0PSI4MDBweCIgdmlld0JveD0iLTMgMCAyNjIgMjYyIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHByZXNlcnZlQXNwZWN0UmF0aW89InhNaWRZTWlkIj48cGF0aCBkPSJNMjU1Ljg3OCAxMzMuNDUxYzAtMTAuNzM0LS44NzEtMTguNTY3LTIuNzU2LTI2LjY5SDEzMC41NXY0OC40NDhoNzEuOTQ3Yy0xLjQ1IDEyLjA0LTkuMjgzIDMwLjE3Mi0yNi42OSA0Mi4zNTZsLS4yNDQgMS42MjIgMzguNzU1IDMwLjAyMyAyLjY4NS4yNjhjMjQuNjU5LTIyLjc3NCAzOC44NzUtNTYuMjgyIDM4Ljg3NS05Ni4wMjciIGZpbGw9IiM0Mjg1RjQiLz48cGF0aCBkPSJNMTMwLjU1IDI2MS4xYzM1LjI0OCAwIDY0LjgzOS0xMS42MDUgODYuNDUzLTMxLjYyMmwtNDEuMTk2LTMxLjkxM2MtMTEuMDI0IDcuNjg4LTI1LjgyIDEzLjA1NS00NS4yNTcgMTMuMDU1LTM0LjUyMyAwLTYzLjgyNC0yMi43NzMtNzQuMjY5LTU0LjI1bC0xLjUzMS4xMy00MC4yOTggMzEuMTg3LS41MjcgMS40NjVDMzUuMzkzIDIzMS43OTggNzkuNDkgMjYxLjEgMTMwLjU1IDI2MS4xIiBmaWxsPSIjMzRBODUzIi8+PHBhdGggZD0iTTU2LjI4MSAxNTYuMzdjLTIuNzU2LTguMTIzLTQuMzUxLTE2LjgyNy00LjM1MS0yNS44MiAwLTguOTk0IDEuNTk1LTE3LjY5NyA0LjIwNi0yNS44MmwtLjA3My0xLjczTDE1LjI2IDcxLjMxMmwtMS4zMzUuNjM1QzUuMDc3IDg5LjY0NCAwIDEwOS41MTcgMCAxMzAuNTVzNS4wNzcgNDAuOTA1IDEzLjkyNSA1OC42MDJsNDIuMzU2LTMyLjc4MiIgZmlsbD0iI0ZCQkMwNSIvPjxwYXRoIGQ9Ik0xMzAuNTUgNTAuNDc5YzI0LjUxNCAwIDQxLjA1IDEwLjU4OSA1MC40NzkgMTkuNDM4bDM2Ljg0NC0zNS45NzRDMTk1LjI0NSAxMi45MSAxNjUuNzk4IDAgMTMwLjU1IDAgNzkuNDkgMCAzNS4zOTMgMjkuMzAxIDEzLjkyNSA3MS45NDdsNDIuMjExIDMyLjc4M2MxMC41OS0zMS40NzcgMzkuODkxLTU0LjI1MSA3NC40MTQtNTQuMjUxIiBmaWxsPSIjRUI0MzM1Ii8+PC9zdmc+",Ze="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48IS0tIFVwbG9hZGVkIHRvOiBTVkcgUmVwbywgd3d3LnN2Z3JlcG8uY29tLCBHZW5lcmF0b3I6IFNWRyBSZXBvIE1peGVyIFRvb2xzIC0tPgo8c3ZnIHdpZHRoPSI4MDBweCIgaGVpZ2h0PSI4MDBweCIgdmlld0JveD0iMCAwIDE2IDE2IiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGZpbGw9Im5vbmUiPjxwYXRoIGZpbGw9IiNGMzUzMjUiIGQ9Ik0xIDFoNi41djYuNUgxVjF6Ii8+PHBhdGggZmlsbD0iIzgxQkMwNiIgZD0iTTguNSAxSDE1djYuNUg4LjVWMXoiLz48cGF0aCBmaWxsPSIjMDVBNkYwIiBkPSJNMSA4LjVoNi41VjE1SDFWOC41eiIvPjxwYXRoIGZpbGw9IiNGRkJBMDgiIGQ9Ik04LjUgOC41SDE1VjE1SDguNVY4LjV6Ii8+PC9zdmc+";function ee(r,e,t){return r?r.startsWith(`${e}-`)?r:r.startsWith("#")?`${r}`:t:t}function Ye(r,e){const t=(e==null?void 0:e.bg)||"bg-sky-500",s=(e==null?void 0:e.text)||"text-gray-800",n=(e==null?void 0:e.border)||"border-gray-300",i=(e==null?void 0:e.fill)||"fill-current",a=(e==null?void 0:e.stroke)||"stroke-current";return{bgClass:ee(r.bg??"","bg",t),textClass:ee(r.text??"","text",s),borderClass:ee(r.border??"","border",n),fillClass:ee(r.fill??"","fill",i),strokeClass:ee(r.stroke??"","stroke",a)}}/**
8
+ ${r}
9
+ `}))},le=({icon:t,label:l})=>z.createElement("div",{className:"flex gap-5 px-8 py-3 items-center bg-indigo-50 rounded-lg max-md:px-5"},z.createElement("img",{loading:"lazy",src:t,alt:l||"",className:"object-contain shrink-0 aspect-square w-[26px]"}),l&&z.createElement("div",{className:"basis-auto text-sm hidden md:block ltr:text-left rtl:text-right"},l)),re="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48IS0tIFVwbG9hZGVkIHRvOiBTVkcgUmVwbywgd3d3LnN2Z3JlcG8uY29tLCBHZW5lcmF0b3I6IFNWRyBSZXBvIE1peGVyIFRvb2xzIC0tPgo8c3ZnIHdpZHRoPSI4MDBweCIgaGVpZ2h0PSI4MDBweCIgdmlld0JveD0iLTMgMCAyNjIgMjYyIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHByZXNlcnZlQXNwZWN0UmF0aW89InhNaWRZTWlkIj48cGF0aCBkPSJNMjU1Ljg3OCAxMzMuNDUxYzAtMTAuNzM0LS44NzEtMTguNTY3LTIuNzU2LTI2LjY5SDEzMC41NXY0OC40NDhoNzEuOTQ3Yy0xLjQ1IDEyLjA0LTkuMjgzIDMwLjE3Mi0yNi42OSA0Mi4zNTZsLS4yNDQgMS42MjIgMzguNzU1IDMwLjAyMyAyLjY4NS4yNjhjMjQuNjU5LTIyLjc3NCAzOC44NzUtNTYuMjgyIDM4Ljg3NS05Ni4wMjciIGZpbGw9IiM0Mjg1RjQiLz48cGF0aCBkPSJNMTMwLjU1IDI2MS4xYzM1LjI0OCAwIDY0LjgzOS0xMS42MDUgODYuNDUzLTMxLjYyMmwtNDEuMTk2LTMxLjkxM2MtMTEuMDI0IDcuNjg4LTI1LjgyIDEzLjA1NS00NS4yNTcgMTMuMDU1LTM0LjUyMyAwLTYzLjgyNC0yMi43NzMtNzQuMjY5LTU0LjI1bC0xLjUzMS4xMy00MC4yOTggMzEuMTg3LS41MjcgMS40NjVDMzUuMzkzIDIzMS43OTggNzkuNDkgMjYxLjEgMTMwLjU1IDI2MS4xIiBmaWxsPSIjMzRBODUzIi8+PHBhdGggZD0iTTU2LjI4MSAxNTYuMzdjLTIuNzU2LTguMTIzLTQuMzUxLTE2LjgyNy00LjM1MS0yNS44MiAwLTguOTk0IDEuNTk1LTE3LjY5NyA0LjIwNi0yNS44MmwtLjA3My0xLjczTDE1LjI2IDcxLjMxMmwtMS4zMzUuNjM1QzUuMDc3IDg5LjY0NCAwIDEwOS41MTcgMCAxMzAuNTVzNS4wNzcgNDAuOTA1IDEzLjkyNSA1OC42MDJsNDIuMzU2LTMyLjc4MiIgZmlsbD0iI0ZCQkMwNSIvPjxwYXRoIGQ9Ik0xMzAuNTUgNTAuNDc5YzI0LjUxNCAwIDQxLjA1IDEwLjU4OSA1MC40NzkgMTkuNDM4bDM2Ljg0NC0zNS45NzRDMTk1LjI0NSAxMi45MSAxNjUuNzk4IDAgMTMwLjU1IDAgNzkuNDkgMCAzNS4zOTMgMjkuMzAxIDEzLjkyNSA3MS45NDdsNDIuMjExIDMyLjc4M2MxMC41OS0zMS40NzcgMzkuODkxLTU0LjI1MSA3NC40MTQtNTQuMjUxIiBmaWxsPSIjRUI0MzM1Ii8+PC9zdmc+",ne="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48IS0tIFVwbG9hZGVkIHRvOiBTVkcgUmVwbywgd3d3LnN2Z3JlcG8uY29tLCBHZW5lcmF0b3I6IFNWRyBSZXBvIE1peGVyIFRvb2xzIC0tPgo8c3ZnIHdpZHRoPSI4MDBweCIgaGVpZ2h0PSI4MDBweCIgdmlld0JveD0iMCAwIDE2IDE2IiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIGZpbGw9Im5vbmUiPjxwYXRoIGZpbGw9IiNGMzUzMjUiIGQ9Ik0xIDFoNi41djYuNUgxVjF6Ii8+PHBhdGggZmlsbD0iIzgxQkMwNiIgZD0iTTguNSAxSDE1djYuNUg4LjVWMXoiLz48cGF0aCBmaWxsPSIjMDVBNkYwIiBkPSJNMSA4LjVoNi41VjE1SDFWOC41eiIvPjxwYXRoIGZpbGw9IiNGRkJBMDgiIGQ9Ik04LjUgOC41SDE1VjE1SDguNVY4LjV6Ii8+PC9zdmc+";function Z(t,l,n){return t?t.startsWith(`${l}-`)?t:t.startsWith("#")?`${t}`:n:n}function se(t,l){const n=(l==null?void 0:l.bg)||"bg-sky-500",r=(l==null?void 0:l.text)||"text-gray-800",o=(l==null?void 0:l.border)||"border-gray-300",s=(l==null?void 0:l.fill)||"fill-current",a=(l==null?void 0:l.stroke)||"stroke-current";return{bgClass:Z(t.bg??"","bg",n),textClass:Z(t.text??"","text",r),borderClass:Z(t.border??"","border",o),fillClass:Z(t.fill??"","fill",s),strokeClass:Z(t.stroke??"","stroke",a)}}/**
10
10
  * @license lucide-react v0.481.0 - ISC
11
11
  *
12
12
  * This source code is licensed under the ISC license.
13
13
  * See the LICENSE file in the root directory of this source tree.
14
- */const Bt=r=>r.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),Je=(...r)=>r.filter((e,t,s)=>!!e&&e.trim()!==""&&s.indexOf(e)===t).join(" ").trim();/**
14
+ */const xe=t=>t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),oe=(...t)=>t.filter((l,n,r)=>!!l&&l.trim()!==""&&r.indexOf(l)===n).join(" ").trim();/**
15
15
  * @license lucide-react v0.481.0 - ISC
16
16
  *
17
17
  * This source code is licensed under the ISC license.
18
18
  * See the LICENSE file in the root directory of this source tree.
19
- */var Ht={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};/**
19
+ */var pe={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};/**
20
20
  * @license lucide-react v0.481.0 - ISC
21
21
  *
22
22
  * This source code is licensed under the ISC license.
23
23
  * See the LICENSE file in the root directory of this source tree.
24
- */const Kt=o.forwardRef(({color:r="currentColor",size:e=24,strokeWidth:t=2,absoluteStrokeWidth:s,className:n="",children:i,iconNode:a,...l},c)=>o.createElement("svg",{ref:c,...Ht,width:e,height:e,stroke:r,strokeWidth:s?Number(t)*24/Number(e):t,className:Je("lucide",n),...l},[...a.map(([u,d])=>o.createElement(u,d)),...Array.isArray(i)?i:[i]]));/**
24
+ */const be=e.forwardRef(({color:t="currentColor",size:l=24,strokeWidth:n=2,absoluteStrokeWidth:r,className:o="",children:s,iconNode:a,...c},i)=>e.createElement("svg",{ref:i,...pe,width:l,height:l,stroke:t,strokeWidth:r?Number(n)*24/Number(l):n,className:oe("lucide",o),...c},[...a.map(([u,b])=>e.createElement(u,b)),...Array.isArray(s)?s:[s]]));/**
25
25
  * @license lucide-react v0.481.0 - ISC
26
26
  *
27
27
  * This source code is licensed under the ISC license.
28
28
  * See the LICENSE file in the root directory of this source tree.
29
- */const _e=(r,e)=>{const t=o.forwardRef(({className:s,...n},i)=>o.createElement(Kt,{ref:i,iconNode:e,className:Je(`lucide-${Bt(r)}`,s),...n}));return t.displayName=`${r}`,t};/**
29
+ */const ae=(t,l)=>{const n=e.forwardRef(({className:r,...o},s)=>e.createElement(be,{ref:s,iconNode:l,className:oe(`lucide-${xe(t)}`,r),...o}));return n.displayName=`${t}`,n};/**
30
30
  * @license lucide-react v0.481.0 - ISC
31
31
  *
32
32
  * This source code is licensed under the ISC license.
33
33
  * See the LICENSE file in the root directory of this source tree.
34
- */const Wt=_e("TriangleAlert",[["path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3",key:"wmoenq"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]]);/**
34
+ */const we=ae("TriangleAlert",[["path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3",key:"wmoenq"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]]);/**
35
35
  * @license lucide-react v0.481.0 - ISC
36
36
  *
37
37
  * This source code is licensed under the ISC license.
38
38
  * See the LICENSE file in the root directory of this source tree.
39
- */const Gt=_e("X",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]),Qe=({message:r,dismissAfterMs:e=4e3})=>{const t=oe("authLib"),[s,n]=o.useState(!1);return o.useEffect(()=>{if(n(!!r),r&&e>0){const i=window.setTimeout(()=>n(!1),e);return()=>window.clearTimeout(i)}},[r,e]),!s||!r?null:o.createElement("div",{role:"alert","aria-live":"assertive",className:`
39
+ */const ye=ae("X",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]),ie=({message:t,dismissAfterMs:l=4e3})=>{const n=O.useT("authLib"),[r,o]=e.useState(!1);return e.useEffect(()=>{if(o(!!t),t&&l>0){const s=window.setTimeout(()=>o(!1),l);return()=>window.clearTimeout(s)}},[t,l]),!r||!t?null:e.createElement("div",{role:"alert","aria-live":"assertive",className:`
40
40
  relative isolate flex w-full max-w-md items-start gap-2 overflow-hidden
41
41
  rounded-lg border border-red-300 bg-red-50/80 p-4 pr-6 text-sm text-red-800
42
42
  shadow-lg backdrop-blur
43
43
  transition-all duration-300 ease-out
44
- ${s?"translate-y-0 opacity-100":"-translate-y-2 opacity-0"}
45
- `},o.createElement("span",{className:"absolute ltr:left-0 rtl:right-0 top-0 h-full w-1 bg-gradient-to-b from-red-500 to-red-400"}),o.createElement(Wt,{className:"mt-0.5 h-5 w-5 flex-none"}),o.createElement("span",{className:"grow leading-5 ltr:text-left rtl:text-right"},r),o.createElement("button",{onClick:()=>n(!1),"aria-label":t("inlineError.dismiss"),className:`
44
+ ${r?"translate-y-0 opacity-100":"-translate-y-2 opacity-0"}
45
+ `},e.createElement("span",{className:"absolute ltr:left-0 rtl:right-0 top-0 h-full w-1 bg-gradient-to-b from-red-500 to-red-400"}),e.createElement(we,{className:"mt-0.5 h-5 w-5 flex-none"}),e.createElement("span",{className:"grow leading-5 ltr:text-left rtl:text-right"},t),e.createElement("button",{onClick:()=>o(!1),"aria-label":n("inlineError.dismiss"),className:`
46
46
  absolute ltr:right-2 rtl:left-2 top-2 rounded p-1 text-red-600/70
47
47
  hover:bg-red-100 hover:text-red-700 focus:outline-none
48
48
  focus-visible:ring focus-visible:ring-red-500/50
49
- `},o.createElement(Gt,{className:"h-4 w-4"})))},Zt=()=>{const r=oe("authLib"),e=U.useNavigate(),t=U.useLocation(),{brandName:s=r("brandName",{defaultValue:"MyBrand"}),colors:n={bg:"bg-sky-500",text:"text-white",border:"border-sky-500"},logoUrl:i,oauthProviders:a=[],illustrationUrl:l=r("community.illustrationUrl",{defaultValue:"https://cdn.builder.io/api/v1/image/assets/TEMP/35ba84b8335fda2819c3a14ea3d00321a0fd0e79e571caa31108468010868ca5?placeholderIfAbsent=true&apiKey=a460e9a46e514356ac1106eada03046c"}),communityContent:c={title:r("community.title"),description:r("community.description")},baseUrl:u}=Se(),{login:d}=G(),[f,m]=o.useState(""),[g,h]=o.useState(""),[p,y]=o.useState(!1),[L,b]=o.useState(null),E={google:{icon:Ge,label:r("social.google")},microsoft:{icon:Ze,label:r("social.microsoft")}},w=a.filter(M=>M in E).map(M=>({id:M,icon:E[M].icon,label:E[M].label})),{bgClass:C,textClass:F,borderClass:P}=Ye(n),v=`${C} bg-gradient-to-r from-white/10 via-white/0 to-white/0`;async function S(M){var D;if(M.preventDefault(),!p){b(null),y(!0);try{await d({email:f,password:g})}catch(j){((D=j==null?void 0:j.response)==null?void 0:D.status)===401?b(r("errors.invalidCredentials")):b(r("errors.generic"))}finally{y(!1)}}}function N(M){var j,k,$;if(!u){console.error("Auth baseUrl is not configured.");return}const D=((k=(j=t.state)==null?void 0:j.from)==null?void 0:k.pathname)||(($=t.state)==null?void 0:$.from)||"/";if(sessionStorage.setItem("postLoginRedirect",D),M==="google"){const T="/oauth/google/callback",V=`${window.location.origin}${T}`,O=new URL(`${u}/auth/google`);O.searchParams.set("redirect",V),window.location.href=O.toString();return}if(M==="microsoft"){const T="/oauth/microsoft/callback",V=`${window.location.origin}${T}`,O=new URL(`${u}/auth/microsoft`);O.searchParams.set("redirect",V),window.location.href=O.toString();return}}const z=o.createElement("svg",{className:"h-4 w-4 animate-spin stroke-current",viewBox:"0 0 24 24",fill:"none"},o.createElement("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",strokeWidth:"4"}),o.createElement("path",{className:"opacity-75",d:"M4 12a8 8 0 018-8",strokeWidth:"4",strokeLinecap:"round"}));return o.createElement("div",{className:`flex items-center justify-center min-h-screen p-4 ${v}`},o.createElement("div",{className:"flex w-full max-w-5xl bg-white rounded-2xl shadow-2xl overflow-hidden"},o.createElement("div",{className:`hidden md:flex md:w-1/2 p-12 flex-col justify-between text-white ${C}`},o.createElement("div",null,i?o.createElement("div",{className:"flex items-center gap-4"},o.createElement("img",{loading:"lazy",src:i,alt:"Brand Logo",className:"bg-white h-8 md:h-22 rounded-lg"}),o.createElement("h2",{className:"text-sm md:text-2xl font-bold uppercase"},s)):o.createElement("h2",{className:"text-sm md:text-2xl font-bold"},s)),o.createElement("div",{className:"flex-1 space-y-4 mt-6 py-4"},o.createElement("h3",{className:"text-2xl font-semibold leading-tight"},c.title),o.createElement("p",{className:"text-base leading-relaxed opacity-90 ltr:text-left rtl:text-right"},c.description),o.createElement("div",{className:"relative"},o.createElement("div",{className:"absolute -left-4 -top-4 w-20 h-20 bg-white/20 rounded-full blur-xl"}),o.createElement("div",{className:"absolute -right-4 -bottom-4 w-20 h-20 bg-white/20 rounded-full blur-xl"}),o.createElement("img",{loading:"lazy",src:l,alt:"Sign in illustration",className:"max-w-sm w-full mx-auto rounded-lg shadow-lg transform hover:scale-105 transition-transform duration-300 p-6"})))),o.createElement("div",{className:"w-full md:w-1/2 p-4 md:p-8 m-auto"},o.createElement("div",{className:"flex flex-col md:flex-row justify-between items-center mb-8"},o.createElement("div",{className:"flex items-center justify-center md:hidden mb-5"},i?o.createElement("img",{loading:"lazy",src:i,alt:"Brand Logo",className:`h-22 rounded-full border ${P}`}):o.createElement("h2",{className:"text-2xl font-bold"},s)),o.createElement("div",{className:"w-full md:w-auto mb-4 md:mb-0 text-center md:text-left ltr:text-center rtl:text-center md:ltr:text-left md:rtl:text-right"},o.createElement("p",{className:"text-sm md:text-lg"},r("SignInPage.welcome")," ",o.createElement("span",{className:`font-semibold ${F} uppercase`},s)),o.createElement("h1",{className:"text-2xl md:text-4xl font-bold text-gray-800"},r("SignInPage.signIn"))),o.createElement("div",{className:"text-sm text-gray-500 text-center md:text-right"},r("SignInPage.noAccount"),o.createElement("br",null),o.createElement("button",{type:"button",onClick:()=>e("/signup"),className:F},r("SignInPage.signUp")))),L&&o.createElement(Qe,{message:L}),o.createElement("form",{className:"space-y-6",onSubmit:S},o.createElement(R,{label:r("form.emailLabel"),type:"email",placeholder:r("form.emailPlaceholder"),color:P,value:f,onChange:m}),o.createElement(R,{label:r("form.passwordLabel"),type:"password",placeholder:r("form.passwordPlaceholder"),color:P,value:g,onChange:h}),o.createElement("div",{className:"ltr:text-right rtl:text-left"},o.createElement("button",{className:`text-sm ${F}`},r("SignInPage.forgotPassword"))),o.createElement("button",{type:"submit",disabled:p,className:`relative flex w-full items-center justify-center gap-2 py-3 rounded-lg font-medium transition-colors ${p?"opacity-60 cursor-not-allowed":""} ${C} text-white`},p&&z,r(p?"SignInPage.signInSubmitting":"SignInPage.signIn")),w.length>0&&o.createElement(o.Fragment,null,o.createElement("div",{className:"flex items-center pt-2"},o.createElement("div",{className:`flex-grow h-px ${C}`}),o.createElement("span",{className:`${F} mx-3 text-sm`},r("SignInPage.orLoginWith")),o.createElement("div",{className:`flex-grow h-px ${C}`})),o.createElement("div",{className:"flex gap-3 mb-6 justify-center md:justify-start"},w.map(M=>o.createElement("button",{key:M.id,type:"button",onClick:()=>N(M.id),className:"flex-1"},o.createElement(We,{icon:M.icon,label:M.label})))))))))},Yt=()=>{const r=oe("authLib"),e=U.useNavigate(),t=U.useLocation(),{brandName:s=r("brandName",{defaultValue:"MyBrand"}),colors:n={bg:"bg-sky-500",text:"text-white",border:"border-sky-500"},logoUrl:i,oauthProviders:a=[],illustrationUrl:l=r("community.illustrationUrl",{defaultValue:"https://cdn.builder.io/api/v1/image/assets/TEMP/35ba84b8335fda2819c3a14ea3d00321a0fd0e79e571caa31108468010868ca5?placeholderIfAbsent=true&apiKey=a460e9a46e514356ac1106eada03046c"}),communityContent:c={title:r("community.title"),description:r("community.description")},baseUrl:u}=Se(),{login:d,api:f}=G(),[m,g]=o.useState(""),[h,p]=o.useState(""),[y,L]=o.useState(""),[b,E]=o.useState(!1),[w,C]=o.useState(null),F={google:{icon:Ge,label:r("social.google")},microsoft:{icon:Ze,label:r("social.microsoft")}},P=a.filter(k=>k in F).map(k=>({id:k,icon:F[k].icon,label:F[k].label})),{bgClass:v,textClass:S,borderClass:N}=Ye(n),z=`${v} bg-gradient-to-r from-white/10 via-white/0 to-white/0`;async function M(k){var $,T,V;if(k.preventDefault(),!b){C(null),E(!0);try{await f.post("/auth/clients/register",{email:h,password:y,name:m||void 0}),await d({email:h,password:y})}catch(O){const W=($=O==null?void 0:O.response)==null?void 0:$.status;C(W===400?((V=(T=O==null?void 0:O.response)==null?void 0:T.data)==null?void 0:V.message)||r("errors.invalidData",{defaultValue:"Please check the fields and try again."}):W===409?r("errors.emailInUse",{defaultValue:"This email is already in use."}):r("errors.generic",{defaultValue:"Something went wrong. Please try again."}))}finally{E(!1)}}}function D(k){var T,V,O;if(!u){console.error("Auth baseUrl is not configured.");return}const $=((V=(T=t.state)==null?void 0:T.from)==null?void 0:V.pathname)||((O=t.state)==null?void 0:O.from)||"/";if(sessionStorage.setItem("postLoginRedirect",$),k==="google"){const W="/oauth/google/callback",A=`${window.location.origin}${W}`,H=new URL(`${u}/auth/google`);H.searchParams.set("redirect",A),window.location.href=H.toString();return}if(k==="microsoft"){const W="/oauth/microsoft/callback",A=`${window.location.origin}${W}`,H=new URL(`${u}/auth/microsoft`);H.searchParams.set("redirect",A),window.location.href=H.toString();return}}const j=o.createElement("svg",{className:"h-4 w-4 animate-spin stroke-current",viewBox:"0 0 24 24",fill:"none"},o.createElement("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",strokeWidth:"4"}),o.createElement("path",{className:"opacity-75",d:"M4 12a8 8 0 018-8",strokeWidth:"4",strokeLinecap:"round"}));return o.createElement("div",{className:`flex items-center justify-center min-h-screen p-4 ${z}`},o.createElement("div",{className:"flex w-full max-w-5xl bg-white rounded-2xl shadow-2xl overflow-hidden"},o.createElement("div",{className:`hidden md:flex md:w-1/2 p-12 flex-col justify-between text-white ${v}`},o.createElement("div",null,i?o.createElement("div",{className:"flex items-center gap-4"},o.createElement("img",{loading:"lazy",src:i,alt:"Brand Logo",className:"bg-white h-8 md:h-22 rounded-lg"}),o.createElement("h2",{className:"text-sm md:text-2xl font-bold uppercase"},s)):o.createElement("h2",{className:"text-sm md:text-2xl font-bold"},s)),o.createElement("div",{className:"flex-1 space-y-4 mt-6 py-4"},o.createElement("h3",{className:"text-2xl font-semibold leading-tight"},c.title),o.createElement("p",{className:"text-base leading-relaxed opacity-90 ltr:text-left rtl:text-right"},c.description),o.createElement("div",{className:"relative"},o.createElement("div",{className:"absolute -left-4 -top-4 w-20 h-20 bg-white/20 rounded-full blur-xl"}),o.createElement("div",{className:"absolute -right-4 -bottom-4 w-20 h-20 bg-white/20 rounded-full blur-xl"}),o.createElement("img",{loading:"lazy",src:l,alt:"Sign up illustration",className:"max-w-sm w-full mx-auto rounded-lg shadow-lg transform hover:scale-105 transition-transform duration-300 p-6"})))),o.createElement("div",{className:"w-full md:w-1/2 p-4 md:p-8 m-auto"},o.createElement("div",{className:"flex flex-col md:flex-row justify-between items-center mb-8"},o.createElement("div",{className:"flex items-center justify-center md:hidden mb-5"},i?o.createElement("img",{loading:"lazy",src:i,alt:"Brand Logo",className:`h-22 rounded-full border ${N}`}):o.createElement("h2",{className:"text-2xl font-bold"},s)),o.createElement("div",{className:"w-full md:w-auto mb-4 md:mb-0 text-center md:text-left ltr:text-center rtl:text-center md:ltr:text-left md:rtl:text-right"},o.createElement("p",{className:"text-sm md:text-lg"},r("SignUpPage.welcome",{defaultValue:"Join"})," ",o.createElement("span",{className:`font-semibold ${S} uppercase`},s)),o.createElement("h1",{className:"text-2xl md:text-4xl font-bold text-gray-800"},r("SignUpPage.signUp",{defaultValue:"Sign up"}))),o.createElement("div",{className:"text-sm text-gray-500 text-center md:text-right"},r("SignUpPage.alreadyHaveAccount",{defaultValue:"Already have an account?"}),o.createElement("br",null),o.createElement("button",{type:"button",onClick:()=>e("/login"),className:S},r("SignUpPage.signIn",{defaultValue:"Sign in"})))),w&&o.createElement(Qe,{message:w}),o.createElement("form",{className:"space-y-6",onSubmit:M},o.createElement(R,{label:r("form.nameLabel",{defaultValue:"Name"}),type:"text",placeholder:r("form.namePlaceholder",{defaultValue:"Enter your name"}),color:N,value:m,onChange:g}),o.createElement(R,{label:r("form.emailLabel"),type:"email",placeholder:r("form.emailPlaceholder"),color:N,value:h,onChange:p}),o.createElement(R,{label:r("form.passwordLabel"),type:"password",placeholder:r("form.passwordPlaceholder"),color:N,value:y,onChange:L}),o.createElement("button",{type:"submit",disabled:b,className:`relative flex w-full items-center justify-center gap-2 py-3 rounded-lg font-medium transition-colors ${b?"opacity-60 cursor-not-allowed":""} ${v} text-white`},b&&j,b?r("SignUpPage.signUpSubmitting",{defaultValue:"Creating account..."}):r("SignUpPage.signUp",{defaultValue:"Sign up"})),P.length>0&&o.createElement(o.Fragment,null,o.createElement("div",{className:"flex items-center pt-2"},o.createElement("div",{className:`flex-grow h-px ${v}`}),o.createElement("span",{className:`${S} mx-3 text-sm`},r("SignUpPage.orContinueWith",{defaultValue:"Or continue with"})),o.createElement("div",{className:`flex-grow h-px ${v}`})),o.createElement("div",{className:"flex gap-3 mb-6 justify-center md:justify-start"},P.map(k=>o.createElement("button",{key:k.id,type:"button",onClick:()=>D(k.id),className:"flex-1"},o.createElement(We,{icon:k.icon,label:k.label})))))))))},qe=()=>(o.useEffect(()=>{const r=new URLSearchParams(window.location.search),e=r.get("accessToken"),t=r.get("refreshToken");e&&localStorage.setItem("authToken",e),t&&localStorage.setItem("refreshToken",t);const s=sessionStorage.getItem("postLoginRedirect")||"/";sessionStorage.removeItem("postLoginRedirect"),window.location.replace(s)},[]),o.createElement("div",{className:"flex items-center justify-center min-h-screen text-gray-700"},"Finishing Google sign-in…")),Jt=({children:r})=>{const{isAuthenticated:e}=G(),t=U.useLocation();return e?r:o.createElement(U.Navigate,{to:"/login",state:{from:t},replace:!0})},_t=({config:r,children:e})=>{const t=U.useNavigate(),[s,n]=o.useState(()=>localStorage.getItem("authToken")),[i,a]=o.useState(null),[l,c]=o.useState(!0),[u,d]=o.useState(!1);async function f(){try{await m.post("/auth/logout")}catch(p){console.warn("Logout endpoint failed, proceeding with local logout:",p)}n(null),a(null),localStorage.removeItem("authToken"),sessionStorage.clear(),d(!1),t("/login",{replace:!0})}const m=o.useMemo(()=>{const p=ue.create({baseURL:r.baseUrl,withCredentials:!0});return rt(p,{baseUrl:r.baseUrl,getAccessToken:()=>s,setAccessToken:y=>n(y),logout:()=>d(!0)}),p},[r.baseUrl,s]);o.useEffect(()=>{(async()=>{if(s){a(ce(s)),c(!1);return}try{const{data:y}=await ue.post(`${r.baseUrl}/auth/refresh-token`,{},{withCredentials:!0});n(y.accessToken),a(ce(y.accessToken)),localStorage.setItem("authToken",y.accessToken)}catch{}finally{c(!1)}})()},[s,r.baseUrl]);async function g(p){const{data:y}=await m.post("/auth/clients/login",p);n(y.accessToken),a(ce(y.accessToken)),localStorage.setItem("authToken",y.accessToken),nt(),t("/",{replace:!0})}const h=o.useMemo(()=>({isAuthenticated:!!s,accessToken:s,user:i,login:g,logout:f,api:m,setUser:a}),[s,i,m]);return o.createElement(Ne.Provider,{value:r},o.createElement(ve.Provider,{value:h},o.createElement(U.Routes,null,o.createElement(U.Route,{path:"login",element:s?o.createElement(U.Navigate,{to:"/",replace:!0}):o.createElement(Zt,{baseUrl:r.baseUrl,colors:r.colors})}),o.createElement(U.Route,{path:"signup",element:s?o.createElement(U.Navigate,{to:"/",replace:!0}):o.createElement(Yt,null)}),o.createElement(U.Route,{path:"oauth/google/callback",element:o.createElement(qe,null)}),o.createElement(U.Route,{path:"/oauth/microsoft/callback",element:o.createElement(qe,null)}),o.createElement(U.Route,{path:"*",element:o.createElement(Jt,null,e)})),u&&o.createElement(Vt,{onConfirm:f})))};function be(...r){const{user:e}=G(),t=(e==null?void 0:e.roles)??[];return r.some(s=>t.includes(s))}function Qt(r){const{user:e}=G();return(e==null?void 0:e.modules.includes(r))??!1}function le(...r){const{user:e}=G(),t=(e==null?void 0:e.permissions)??[];return r.every(s=>t.includes(s))}const qt=({children:r,fallbackpermessions:e=[],anyPermessions:t=[],fallbackRoles:s=["super-admin"],redirectTo:n="/dashboard"})=>{if(s.some(c=>be(c)))return o.createElement(o.Fragment,null,r);const a=e.length===0||e.every(c=>le(c)),l=t.length===0||t.some(c=>le(c));return a&&l?o.createElement(o.Fragment,null,r):o.createElement(U.Navigate,{to:n,replace:!0})},we=o.createContext({}),Xt=we.Provider;function Rt(r,e){var n,i,a;const s=(n=o.useContext(we)[r])==null?void 0:n[e];return s?!!((i=s.perms)!=null&&i.some(l=>le(l))||(a=s.fallbackRoles)!=null&&a.some(l=>be(l))):!1}const es=()=>{const{user:r,api:e,setUser:t}=G(),[s,n]=o.useState((r==null?void 0:r.name)??""),[i,a]=o.useState((r==null?void 0:r.email)??""),[l,c]=o.useState(!1),[u,d]=o.useState(!1),[f,m]=o.useState({open:!1,type:"success",title:"",message:""}),g="+971 50 827 8229";o.useEffect(()=>{if(!f.open)return;const b=window.setTimeout(()=>m(E=>({...E,open:!1})),3e3);return()=>window.clearTimeout(b)},[f.open]),o.useEffect(()=>{let b=!1;async function E(){try{const{data:w}=await e.get("/auth/client/me");if(b)return;t(w),n((w==null?void 0:w.name)??""),a((w==null?void 0:w.email)??"")}catch(w){console.error("Failed to load profile details:",w)}}return E(),()=>{b=!0}},[e,t]);const h=o.useMemo(()=>(s||(r==null?void 0:r.name)||(r==null?void 0:r.email)||"").trim(),[s,r==null?void 0:r.name,r==null?void 0:r.email]),p=o.useMemo(()=>h.charAt(0).toUpperCase()||"?",[h]);async function y(){if(r){d(!0);try{await e.patch("/auth/client/me",{name:s}),t({...r,name:s}),c(!1),m({open:!0,type:"success",title:"Changes saved",message:"Your profile was updated successfully."})}catch(b){console.error("Failed to update profile:",b),m({open:!0,type:"error",title:"Save failed",message:"Failed to save changes. Please try again."})}finally{d(!1)}}}if(!r)return o.createElement("p",{className:"text-sm text-gray-500"},"No user data available.");const L=f.type==="success";return o.createElement("div",{className:"max-w-3xl mx-auto"},f.open&&o.createElement("div",{className:"fixed top-6 right-6 z-[999999] flex items-center gap-3 rounded-xl border bg-white px-4 py-3 shadow-lg",role:"status","aria-live":"polite",style:{borderColor:L?"#BBF7D0":"#FECACA"}},o.createElement("div",{className:"flex h-9 w-9 items-center justify-center rounded-full",style:{backgroundColor:L?"#ECFDF5":"#FEF2F2"}},L?o.createElement("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:"text-green-600"},o.createElement("path",{d:"M20 6L9 17L4 12",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})):o.createElement("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:"text-red-600"},o.createElement("path",{d:"M12 9V13",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"}),o.createElement("path",{d:"M12 17H12.01",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"}),o.createElement("path",{d:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0Z",stroke:"currentColor",strokeWidth:"2",strokeLinejoin:"round"}))),o.createElement("div",{className:"flex flex-col"},o.createElement("span",{className:"text-sm font-semibold",style:{color:L?"#15803D":"#B91C1C"}},f.title),f.message&&o.createElement("span",{className:"text-xs text-gray-500"},f.message)),o.createElement("button",{type:"button",onClick:()=>m(b=>({...b,open:!1})),className:"ml-2 rounded-md px-2 py-1 text-gray-500 hover:bg-gray-100","aria-label":"Close",title:"Close"},o.createElement("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},o.createElement("path",{d:"M18 6L6 18",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"}),o.createElement("path",{d:"M6 6L18 18",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})))),o.createElement("div",{className:"rounded-2xl border border-gray-200 bg-white shadow-sm"},o.createElement("div",{className:"px-6 pt-6 pb-4"},o.createElement("div",{className:"flex items-center justify-between"},o.createElement("div",{className:"flex items-center gap-4"},o.createElement("div",{className:"relative"},o.createElement("div",{className:"h-16 w-16 rounded-full bg-blue-600 flex items-center justify-center text-white text-2xl font-semibold"},p),o.createElement("button",{type:"button",className:"absolute -bottom-1 -right-1 h-8 w-8 rounded-full border border-gray-200 bg-white shadow-sm flex items-center justify-center hover:bg-gray-50",title:"Change avatar"},o.createElement("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},o.createElement("path",{d:"M12 20H21",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"}),o.createElement("path",{d:"M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4 12.5-12.5Z",stroke:"currentColor",strokeWidth:"2",strokeLinejoin:"round"})))),o.createElement("div",null,o.createElement("h1",{className:"text-2xl font-semibold"},"My Profile"),o.createElement("p",{className:"text-sm text-gray-500"},"Personal details"))),l?o.createElement("button",{type:"button",onClick:y,disabled:u,className:"rounded-full border border-blue-200 bg-blue-50 px-4 py-2 text-sm font-medium text-blue-700 hover:bg-blue-100 disabled:opacity-60"},u?"Saving…":"Save changes"):o.createElement("button",{type:"button",onClick:()=>c(!0),title:"Edit profile",className:"h-9 w-9 rounded-full border border-gray-200 bg-white shadow-sm flex items-center justify-center hover:bg-gray-50"},o.createElement("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},o.createElement("path",{d:"M12 20H21",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"}),o.createElement("path",{d:"M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4 12.5-12.5Z",stroke:"currentColor",strokeWidth:"2",strokeLinejoin:"round"}))))),o.createElement("div",{className:"px-6 pb-6 border-t border-gray-100 pt-6"},o.createElement("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-5"},o.createElement("div",null,o.createElement("label",{className:"block text-xs font-medium text-gray-500 mb-2"},"Username"),o.createElement("input",{type:"text",value:s,disabled:!l||u,onChange:b=>n(b.target.value),className:`w-full rounded-lg border px-3 py-2 text-sm outline-none ${l?"border-gray-300 bg-white focus:border-blue-500 focus:ring-2 focus:ring-blue-100":"border-gray-200 bg-gray-50 text-gray-700"}`})),o.createElement("div",null,o.createElement("label",{className:"block text-xs font-medium text-gray-500 mb-2"},"Email ID"),o.createElement("input",{type:"email",value:i,disabled:!0,className:"w-full rounded-lg border border-gray-200 bg-gray-50 px-3 py-2 text-sm text-gray-700 cursor-not-allowed"})),o.createElement("div",null,o.createElement("label",{className:"block text-xs font-medium text-gray-500 mb-2"},"Mobile number"),o.createElement("input",{type:"text",value:g,disabled:!0,className:"w-full rounded-lg border border-gray-200 bg-gray-50 px-3 py-2 text-sm text-gray-700 cursor-not-allowed"}))),l&&o.createElement("button",{type:"button",disabled:u,onClick:()=>{c(!1),n((r==null?void 0:r.name)??"")},className:"mt-6 text-sm font-medium text-gray-600 hover:text-gray-900"},"Cancel"))))};I.AuthProvider=_t,I.ProfilePage=es,I.RbacContext=we,I.RbacProvider=Xt,I.RequirePermissions=qt,I.useAuthState=G,I.useCan=le,I.useGrant=Rt,I.useHasModule=Qt,I.useHasRole=be,Object.defineProperty(I,Symbol.toStringTag,{value:"Module"})});
49
+ `},e.createElement(ye,{className:"h-4 w-4"})))},Ee=()=>{const t=O.useT("authLib"),l=p.useNavigate(),n=p.useLocation(),{brandName:r=t("brandName",{defaultValue:"MyBrand"}),colors:o={bg:"bg-sky-500",text:"text-white",border:"border-sky-500"},logoUrl:s,oauthProviders:a=[],illustrationUrl:c=t("community.illustrationUrl",{defaultValue:"https://cdn.builder.io/api/v1/image/assets/TEMP/35ba84b8335fda2819c3a14ea3d00321a0fd0e79e571caa31108468010868ca5?placeholderIfAbsent=true&apiKey=a460e9a46e514356ac1106eada03046c"}),communityContent:i={title:t("community.title"),description:t("community.description")},baseUrl:u}=ee(),{login:b}=j(),[w,N]=e.useState(""),[C,v]=e.useState(""),[h,g]=e.useState(!1),[k,d]=e.useState(null),M={google:{icon:re,label:t("social.google")},microsoft:{icon:ne,label:t("social.microsoft")}},y=a.filter(x=>x in M).map(x=>({id:x,icon:M[x].icon,label:M[x].label})),{bgClass:I,textClass:T,borderClass:A}=se(o),U=`${I} bg-gradient-to-r from-white/10 via-white/0 to-white/0`;async function F(x){var $;if(x.preventDefault(),!h){d(null),g(!0);try{await b({email:w,password:C})}catch(P){(($=P==null?void 0:P.response)==null?void 0:$.status)===401?d(t("errors.invalidCredentials")):d(t("errors.generic"))}finally{g(!1)}}}function B(x){var P,f,D;if(!u){console.error("Auth baseUrl is not configured.");return}const $=((f=(P=n.state)==null?void 0:P.from)==null?void 0:f.pathname)||((D=n.state)==null?void 0:D.from)||"/";if(sessionStorage.setItem("postLoginRedirect",$),x==="google"){const S="/oauth/google/callback",L=`${window.location.origin}${S}`,E=new URL(`${u}/auth/google`);E.searchParams.set("redirect",L),window.location.href=E.toString();return}if(x==="microsoft"){const S="/oauth/microsoft/callback",L=`${window.location.origin}${S}`,E=new URL(`${u}/auth/microsoft`);E.searchParams.set("redirect",L),window.location.href=E.toString();return}}const J=e.createElement("svg",{className:"h-4 w-4 animate-spin stroke-current",viewBox:"0 0 24 24",fill:"none"},e.createElement("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",strokeWidth:"4"}),e.createElement("path",{className:"opacity-75",d:"M4 12a8 8 0 018-8",strokeWidth:"4",strokeLinecap:"round"}));return e.createElement("div",{className:`flex items-center justify-center min-h-screen p-4 ${U}`},e.createElement("div",{className:"flex w-full max-w-5xl bg-white rounded-2xl shadow-2xl overflow-hidden"},e.createElement("div",{className:`hidden md:flex md:w-1/2 p-12 flex-col justify-between text-white ${I}`},e.createElement("div",null,s?e.createElement("div",{className:"flex items-center gap-4"},e.createElement("img",{loading:"lazy",src:s,alt:"Brand Logo",className:"bg-white h-8 md:h-22 rounded-lg"}),e.createElement("h2",{className:"text-sm md:text-2xl font-bold uppercase"},r)):e.createElement("h2",{className:"text-sm md:text-2xl font-bold"},r)),e.createElement("div",{className:"flex-1 space-y-4 mt-6 py-4"},e.createElement("h3",{className:"text-2xl font-semibold leading-tight"},i.title),e.createElement("p",{className:"text-base leading-relaxed opacity-90 ltr:text-left rtl:text-right"},i.description),e.createElement("div",{className:"relative"},e.createElement("div",{className:"absolute -left-4 -top-4 w-20 h-20 bg-white/20 rounded-full blur-xl"}),e.createElement("div",{className:"absolute -right-4 -bottom-4 w-20 h-20 bg-white/20 rounded-full blur-xl"}),e.createElement("img",{loading:"lazy",src:c,alt:"Sign in illustration",className:"max-w-sm w-full mx-auto rounded-lg shadow-lg transform hover:scale-105 transition-transform duration-300 p-6"})))),e.createElement("div",{className:"w-full md:w-1/2 p-4 md:p-8 m-auto"},e.createElement("div",{className:"flex flex-col md:flex-row justify-between items-center mb-8"},e.createElement("div",{className:"flex items-center justify-center md:hidden mb-5"},s?e.createElement("img",{loading:"lazy",src:s,alt:"Brand Logo",className:`h-22 rounded-full border ${A}`}):e.createElement("h2",{className:"text-2xl font-bold"},r)),e.createElement("div",{className:"w-full md:w-auto mb-4 md:mb-0 text-center md:text-left ltr:text-center rtl:text-center md:ltr:text-left md:rtl:text-right"},e.createElement("p",{className:"text-sm md:text-lg"},t("SignInPage.welcome")," ",e.createElement("span",{className:`font-semibold ${T} uppercase`},r)),e.createElement("h1",{className:"text-2xl md:text-4xl font-bold text-gray-800"},t("SignInPage.signIn"))),e.createElement("div",{className:"text-sm text-gray-500 text-center md:text-right"},t("SignInPage.noAccount"),e.createElement("br",null),e.createElement("button",{type:"button",onClick:()=>l("/signup"),className:T},t("SignInPage.signUp")))),k&&e.createElement(ie,{message:k}),e.createElement("form",{className:"space-y-6",onSubmit:F},e.createElement(W,{label:t("form.emailLabel"),type:"email",placeholder:t("form.emailPlaceholder"),color:A,value:w,onChange:N}),e.createElement(W,{label:t("form.passwordLabel"),type:"password",placeholder:t("form.passwordPlaceholder"),color:A,value:C,onChange:v}),e.createElement("div",{className:"ltr:text-right rtl:text-left"},e.createElement("button",{className:`text-sm ${T}`},t("SignInPage.forgotPassword"))),e.createElement("button",{type:"submit",disabled:h,className:`relative flex w-full items-center justify-center gap-2 py-3 rounded-lg font-medium transition-colors ${h?"opacity-60 cursor-not-allowed":""} ${I} text-white`},h&&J,t(h?"SignInPage.signInSubmitting":"SignInPage.signIn")),y.length>0&&e.createElement(e.Fragment,null,e.createElement("div",{className:"flex items-center pt-2"},e.createElement("div",{className:`flex-grow h-px ${I}`}),e.createElement("span",{className:`${T} mx-3 text-sm`},t("SignInPage.orLoginWith")),e.createElement("div",{className:`flex-grow h-px ${I}`})),e.createElement("div",{className:"flex gap-3 mb-6 justify-center md:justify-start"},y.map(x=>e.createElement("button",{key:x.id,type:"button",onClick:()=>B(x.id),className:"flex-1"},e.createElement(le,{icon:x.icon,label:x.label})))))))))},Ne=()=>{const t=O.useT("authLib"),l=p.useNavigate(),n=p.useLocation(),{brandName:r=t("brandName",{defaultValue:"MyBrand"}),colors:o={bg:"bg-sky-500",text:"text-white",border:"border-sky-500"},logoUrl:s,oauthProviders:a=[],illustrationUrl:c=t("community.illustrationUrl",{defaultValue:"https://cdn.builder.io/api/v1/image/assets/TEMP/35ba84b8335fda2819c3a14ea3d00321a0fd0e79e571caa31108468010868ca5?placeholderIfAbsent=true&apiKey=a460e9a46e514356ac1106eada03046c"}),communityContent:i={title:t("community.title"),description:t("community.description")},baseUrl:u}=ee(),{login:b,api:w}=j(),[N,C]=e.useState(""),[v,h]=e.useState(""),[g,k]=e.useState(""),[d,M]=e.useState(!1),[y,I]=e.useState(null),T={google:{icon:re,label:t("social.google")},microsoft:{icon:ne,label:t("social.microsoft")}},A=a.filter(f=>f in T).map(f=>({id:f,icon:T[f].icon,label:T[f].label})),{bgClass:U,textClass:F,borderClass:B}=se(o),J=`${U} bg-gradient-to-r from-white/10 via-white/0 to-white/0`;async function x(f){var D,S,L;if(f.preventDefault(),!d){I(null),M(!0);try{await w.post("/auth/clients/register",{email:v,password:g,name:N||void 0}),await b({email:v,password:g})}catch(E){const V=(D=E==null?void 0:E.response)==null?void 0:D.status;I(V===400?((L=(S=E==null?void 0:E.response)==null?void 0:S.data)==null?void 0:L.message)||t("errors.invalidData",{defaultValue:"Please check the fields and try again."}):V===409?t("errors.emailInUse",{defaultValue:"This email is already in use."}):t("errors.generic",{defaultValue:"Something went wrong. Please try again."}))}finally{M(!1)}}}function $(f){var S,L,E;if(!u){console.error("Auth baseUrl is not configured.");return}const D=((L=(S=n.state)==null?void 0:S.from)==null?void 0:L.pathname)||((E=n.state)==null?void 0:E.from)||"/";if(sessionStorage.setItem("postLoginRedirect",D),f==="google"){const V="/oauth/google/callback",K=`${window.location.origin}${V}`,G=new URL(`${u}/auth/google`);G.searchParams.set("redirect",K),window.location.href=G.toString();return}if(f==="microsoft"){const V="/oauth/microsoft/callback",K=`${window.location.origin}${V}`,G=new URL(`${u}/auth/microsoft`);G.searchParams.set("redirect",K),window.location.href=G.toString();return}}const P=e.createElement("svg",{className:"h-4 w-4 animate-spin stroke-current",viewBox:"0 0 24 24",fill:"none"},e.createElement("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",strokeWidth:"4"}),e.createElement("path",{className:"opacity-75",d:"M4 12a8 8 0 018-8",strokeWidth:"4",strokeLinecap:"round"}));return e.createElement("div",{className:`flex items-center justify-center min-h-screen p-4 ${J}`},e.createElement("div",{className:"flex w-full max-w-5xl bg-white rounded-2xl shadow-2xl overflow-hidden"},e.createElement("div",{className:`hidden md:flex md:w-1/2 p-12 flex-col justify-between text-white ${U}`},e.createElement("div",null,s?e.createElement("div",{className:"flex items-center gap-4"},e.createElement("img",{loading:"lazy",src:s,alt:"Brand Logo",className:"bg-white h-8 md:h-22 rounded-lg"}),e.createElement("h2",{className:"text-sm md:text-2xl font-bold uppercase"},r)):e.createElement("h2",{className:"text-sm md:text-2xl font-bold"},r)),e.createElement("div",{className:"flex-1 space-y-4 mt-6 py-4"},e.createElement("h3",{className:"text-2xl font-semibold leading-tight"},i.title),e.createElement("p",{className:"text-base leading-relaxed opacity-90 ltr:text-left rtl:text-right"},i.description),e.createElement("div",{className:"relative"},e.createElement("div",{className:"absolute -left-4 -top-4 w-20 h-20 bg-white/20 rounded-full blur-xl"}),e.createElement("div",{className:"absolute -right-4 -bottom-4 w-20 h-20 bg-white/20 rounded-full blur-xl"}),e.createElement("img",{loading:"lazy",src:c,alt:"Sign up illustration",className:"max-w-sm w-full mx-auto rounded-lg shadow-lg transform hover:scale-105 transition-transform duration-300 p-6"})))),e.createElement("div",{className:"w-full md:w-1/2 p-4 md:p-8 m-auto"},e.createElement("div",{className:"flex flex-col md:flex-row justify-between items-center mb-8"},e.createElement("div",{className:"flex items-center justify-center md:hidden mb-5"},s?e.createElement("img",{loading:"lazy",src:s,alt:"Brand Logo",className:`h-22 rounded-full border ${B}`}):e.createElement("h2",{className:"text-2xl font-bold"},r)),e.createElement("div",{className:"w-full md:w-auto mb-4 md:mb-0 text-center md:text-left ltr:text-center rtl:text-center md:ltr:text-left md:rtl:text-right"},e.createElement("p",{className:"text-sm md:text-lg"},t("SignUpPage.welcome",{defaultValue:"Join"})," ",e.createElement("span",{className:`font-semibold ${F} uppercase`},r)),e.createElement("h1",{className:"text-2xl md:text-4xl font-bold text-gray-800"},t("SignUpPage.signUp",{defaultValue:"Sign up"}))),e.createElement("div",{className:"text-sm text-gray-500 text-center md:text-right"},t("SignUpPage.alreadyHaveAccount",{defaultValue:"Already have an account?"}),e.createElement("br",null),e.createElement("button",{type:"button",onClick:()=>l("/login"),className:F},t("SignUpPage.signIn",{defaultValue:"Sign in"})))),y&&e.createElement(ie,{message:y}),e.createElement("form",{className:"space-y-6",onSubmit:x},e.createElement(W,{label:t("form.nameLabel",{defaultValue:"Name"}),type:"text",placeholder:t("form.namePlaceholder",{defaultValue:"Enter your name"}),color:B,value:N,onChange:C}),e.createElement(W,{label:t("form.emailLabel"),type:"email",placeholder:t("form.emailPlaceholder"),color:B,value:v,onChange:h}),e.createElement(W,{label:t("form.passwordLabel"),type:"password",placeholder:t("form.passwordPlaceholder"),color:B,value:g,onChange:k}),e.createElement("button",{type:"submit",disabled:d,className:`relative flex w-full items-center justify-center gap-2 py-3 rounded-lg font-medium transition-colors ${d?"opacity-60 cursor-not-allowed":""} ${U} text-white`},d&&P,d?t("SignUpPage.signUpSubmitting",{defaultValue:"Creating account..."}):t("SignUpPage.signUp",{defaultValue:"Sign up"})),A.length>0&&e.createElement(e.Fragment,null,e.createElement("div",{className:"flex items-center pt-2"},e.createElement("div",{className:`flex-grow h-px ${U}`}),e.createElement("span",{className:`${F} mx-3 text-sm`},t("SignUpPage.orContinueWith",{defaultValue:"Or continue with"})),e.createElement("div",{className:`flex-grow h-px ${U}`})),e.createElement("div",{className:"flex gap-3 mb-6 justify-center md:justify-start"},A.map(f=>e.createElement("button",{key:f.id,type:"button",onClick:()=>$(f.id),className:"flex-1"},e.createElement(le,{icon:f.icon,label:f.label})))))))))},ce=()=>(e.useEffect(()=>{const t=new URLSearchParams(window.location.search),l=t.get("accessToken"),n=t.get("refreshToken");l&&localStorage.setItem("authToken",l),n&&localStorage.setItem("refreshToken",n);const r=sessionStorage.getItem("postLoginRedirect")||"/";sessionStorage.removeItem("postLoginRedirect"),window.location.replace(r)},[]),e.createElement("div",{className:"flex items-center justify-center min-h-screen text-gray-700"},"Finishing Google sign-in…")),ve=({children:t})=>{const{isAuthenticated:l}=j(),n=p.useLocation();return l?t:e.createElement(p.Navigate,{to:"/login",state:{from:n},replace:!0})},Me=({config:t,children:l})=>{const n=p.useNavigate(),[r,o]=e.useState(()=>localStorage.getItem("authToken")),[s,a]=e.useState(null),[c,i]=e.useState(!0),[u,b]=e.useState(!1);async function w(){try{await N.post("/auth/logout")}catch(h){console.warn("Logout endpoint failed, proceeding with local logout:",h)}o(null),a(null),localStorage.removeItem("authToken"),sessionStorage.clear(),b(!1),n("/login",{replace:!0})}const N=e.useMemo(()=>{const h=H.create({baseURL:t.baseUrl,withCredentials:!0});return fe(h,{baseUrl:t.baseUrl,getAccessToken:()=>r,setAccessToken:g=>o(g),logout:()=>b(!0)}),h},[t.baseUrl,r]);e.useEffect(()=>{(async()=>{if(r){a(Q(r)),i(!1);return}try{const{data:g}=await H.post(`${t.baseUrl}/auth/refresh-token`,{},{withCredentials:!0});o(g.accessToken),a(Q(g.accessToken)),localStorage.setItem("authToken",g.accessToken)}catch{}finally{i(!1)}})()},[r,t.baseUrl]);async function C(h){const{data:g}=await N.post("/auth/clients/login",h);o(g.accessToken),a(Q(g.accessToken)),localStorage.setItem("authToken",g.accessToken),ge(),n("/",{replace:!0})}const v=e.useMemo(()=>({isAuthenticated:!!r,accessToken:r,user:s,login:C,logout:w,api:N,setUser:a}),[r,s,N]);return e.createElement(R.Provider,{value:t},e.createElement(te.Provider,{value:v},e.createElement(p.Routes,null,e.createElement(p.Route,{path:"login",element:r?e.createElement(p.Navigate,{to:"/",replace:!0}):e.createElement(Ee,{baseUrl:t.baseUrl,colors:t.colors})}),e.createElement(p.Route,{path:"signup",element:r?e.createElement(p.Navigate,{to:"/",replace:!0}):e.createElement(Ne,null)}),e.createElement(p.Route,{path:"oauth/google/callback",element:e.createElement(ce,null)}),e.createElement(p.Route,{path:"/oauth/microsoft/callback",element:e.createElement(ce,null)}),e.createElement(p.Route,{path:"*",element:e.createElement(ve,null,l)})),u&&e.createElement(he,{onConfirm:w})))};function X(...t){const{user:l}=j(),n=(l==null?void 0:l.roles)??[];return t.some(r=>n.includes(r))}function Ie(t){const{user:l}=j();return(l==null?void 0:l.modules.includes(t))??!1}function Y(...t){const{user:l}=j(),n=(l==null?void 0:l.permissions)??[];return t.every(r=>n.includes(r))}const ke=({children:t,fallbackpermessions:l=[],anyPermessions:n=[],fallbackRoles:r=["super-admin"],redirectTo:o="/dashboard"})=>{if(r.some(i=>X(i)))return e.createElement(e.Fragment,null,t);const a=l.length===0||l.every(i=>Y(i)),c=n.length===0||n.some(i=>Y(i));return a&&c?e.createElement(e.Fragment,null,t):e.createElement(p.Navigate,{to:o,replace:!0})},_=e.createContext({}),Se=_.Provider;function Le(t,l){var o,s,a;const r=(o=e.useContext(_)[t])==null?void 0:o[l];return r?!!((s=r.perms)!=null&&s.some(c=>Y(c))||(a=r.fallbackRoles)!=null&&a.some(c=>X(c))):!1}const je=()=>{const{user:t,api:l,setUser:n}=j(),[r,o]=e.useState((t==null?void 0:t.name)??""),[s,a]=e.useState((t==null?void 0:t.email)??""),[c,i]=e.useState(!1),[u,b]=e.useState(!1),[w,N]=e.useState({open:!1,type:"success",title:"",message:""}),C="+971 50 827 8229";e.useEffect(()=>{if(!w.open)return;const d=window.setTimeout(()=>N(M=>({...M,open:!1})),3e3);return()=>window.clearTimeout(d)},[w.open]),e.useEffect(()=>{let d=!1;async function M(){try{const{data:y}=await l.get("/auth/client/me");if(d)return;n(y),o((y==null?void 0:y.name)??""),a((y==null?void 0:y.email)??"")}catch(y){console.error("Failed to load profile details:",y)}}return M(),()=>{d=!0}},[l,n]);const v=e.useMemo(()=>(r||(t==null?void 0:t.name)||(t==null?void 0:t.email)||"").trim(),[r,t==null?void 0:t.name,t==null?void 0:t.email]),h=e.useMemo(()=>v.charAt(0).toUpperCase()||"?",[v]);async function g(){if(t){b(!0);try{await l.patch("/auth/client/me",{name:r}),n({...t,name:r}),i(!1),N({open:!0,type:"success",title:"Changes saved",message:"Your profile was updated successfully."})}catch(d){console.error("Failed to update profile:",d),N({open:!0,type:"error",title:"Save failed",message:"Failed to save changes. Please try again."})}finally{b(!1)}}}if(!t)return e.createElement("p",{className:"text-sm text-gray-500"},"No user data available.");const k=w.type==="success";return e.createElement("div",{className:"max-w-3xl mx-auto"},w.open&&e.createElement("div",{className:"fixed top-6 right-6 z-[999999] flex items-center gap-3 rounded-xl border bg-white px-4 py-3 shadow-lg",role:"status","aria-live":"polite",style:{borderColor:k?"#BBF7D0":"#FECACA"}},e.createElement("div",{className:"flex h-9 w-9 items-center justify-center rounded-full",style:{backgroundColor:k?"#ECFDF5":"#FEF2F2"}},k?e.createElement("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:"text-green-600"},e.createElement("path",{d:"M20 6L9 17L4 12",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})):e.createElement("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg",className:"text-red-600"},e.createElement("path",{d:"M12 9V13",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"}),e.createElement("path",{d:"M12 17H12.01",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"}),e.createElement("path",{d:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0Z",stroke:"currentColor",strokeWidth:"2",strokeLinejoin:"round"}))),e.createElement("div",{className:"flex flex-col"},e.createElement("span",{className:"text-sm font-semibold",style:{color:k?"#15803D":"#B91C1C"}},w.title),w.message&&e.createElement("span",{className:"text-xs text-gray-500"},w.message)),e.createElement("button",{type:"button",onClick:()=>N(d=>({...d,open:!1})),className:"ml-2 rounded-md px-2 py-1 text-gray-500 hover:bg-gray-100","aria-label":"Close",title:"Close"},e.createElement("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},e.createElement("path",{d:"M18 6L6 18",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"}),e.createElement("path",{d:"M6 6L18 18",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})))),e.createElement("div",{className:"rounded-2xl border border-gray-200 bg-white shadow-sm"},e.createElement("div",{className:"px-6 pt-6 pb-4"},e.createElement("div",{className:"flex items-center justify-between"},e.createElement("div",{className:"flex items-center gap-4"},e.createElement("div",{className:"relative"},e.createElement("div",{className:"h-16 w-16 rounded-full bg-blue-600 flex items-center justify-center text-white text-2xl font-semibold"},h),e.createElement("button",{type:"button",className:"absolute -bottom-1 -right-1 h-8 w-8 rounded-full border border-gray-200 bg-white shadow-sm flex items-center justify-center hover:bg-gray-50",title:"Change avatar"},e.createElement("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},e.createElement("path",{d:"M12 20H21",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"}),e.createElement("path",{d:"M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4 12.5-12.5Z",stroke:"currentColor",strokeWidth:"2",strokeLinejoin:"round"})))),e.createElement("div",null,e.createElement("h1",{className:"text-2xl font-semibold"},"My Profile"),e.createElement("p",{className:"text-sm text-gray-500"},"Personal details"))),c?e.createElement("button",{type:"button",onClick:g,disabled:u,className:"rounded-full border border-blue-200 bg-blue-50 px-4 py-2 text-sm font-medium text-blue-700 hover:bg-blue-100 disabled:opacity-60"},u?"Saving…":"Save changes"):e.createElement("button",{type:"button",onClick:()=>i(!0),title:"Edit profile",className:"h-9 w-9 rounded-full border border-gray-200 bg-white shadow-sm flex items-center justify-center hover:bg-gray-50"},e.createElement("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",xmlns:"http://www.w3.org/2000/svg"},e.createElement("path",{d:"M12 20H21",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"}),e.createElement("path",{d:"M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4 12.5-12.5Z",stroke:"currentColor",strokeWidth:"2",strokeLinejoin:"round"}))))),e.createElement("div",{className:"px-6 pb-6 border-t border-gray-100 pt-6"},e.createElement("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-5"},e.createElement("div",null,e.createElement("label",{className:"block text-xs font-medium text-gray-500 mb-2"},"Username"),e.createElement("input",{type:"text",value:r,disabled:!c||u,onChange:d=>o(d.target.value),className:`w-full rounded-lg border px-3 py-2 text-sm outline-none ${c?"border-gray-300 bg-white focus:border-blue-500 focus:ring-2 focus:ring-blue-100":"border-gray-200 bg-gray-50 text-gray-700"}`})),e.createElement("div",null,e.createElement("label",{className:"block text-xs font-medium text-gray-500 mb-2"},"Email ID"),e.createElement("input",{type:"email",value:s,disabled:!0,className:"w-full rounded-lg border border-gray-200 bg-gray-50 px-3 py-2 text-sm text-gray-700 cursor-not-allowed"})),e.createElement("div",null,e.createElement("label",{className:"block text-xs font-medium text-gray-500 mb-2"},"Mobile number"),e.createElement("input",{type:"text",value:C,disabled:!0,className:"w-full rounded-lg border border-gray-200 bg-gray-50 px-3 py-2 text-sm text-gray-700 cursor-not-allowed"}))),c&&e.createElement("button",{type:"button",disabled:u,onClick:()=>{i(!1),o((t==null?void 0:t.name)??"")},className:"mt-6 text-sm font-medium text-gray-600 hover:text-gray-900"},"Cancel"))))};m.AuthProvider=Me,m.ProfilePage=je,m.RbacContext=_,m.RbacProvider=Se,m.RequirePermissions=ke,m.useAuthState=j,m.useCan=Y,m.useGrant=Le,m.useHasModule=Ie,m.useHasRole=X,Object.defineProperty(m,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ciscode/ui-authentication-kit",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "",
5
5
  "main": "dist/index.umd.js",
6
6
  "module": "dist/index.mjs",
@@ -32,7 +32,8 @@
32
32
  "react": ">=18.0.0 <20.0.0 || ^19.0.0",
33
33
  "react-cookie": "^8.0.1",
34
34
  "react-dom": ">=18.0.0 <20.0.0 || ^19.0.0",
35
- "react-router": "^7.3.0"
35
+ "react-router": "^7.0.0",
36
+ "react-router-dom": "^7.0.0"
36
37
  },
37
38
  "devDependencies": {
38
39
  "@types/node": "^22.13.1",
@@ -42,6 +43,8 @@
42
43
  "autoprefixer": "^10.4.20",
43
44
  "postcss": "^8.5.2",
44
45
  "typescript": "^5.2.2",
45
- "vite": "^4.5.9"
46
+ "vite": "^4.5.9",
47
+ "react-router": "^7.13.0",
48
+ "react-router-dom": "^7.13.0"
46
49
  }
47
50
  }