@skylabs-digital/react-identity-access 2.23.0 → 2.24.0

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.es.js CHANGED
@@ -1,7 +1,7 @@
1
- import { jsx as s, Fragment as _, jsxs as d } from "react/jsx-runtime";
2
- import { createContext as me, useMemo as Z, useState as T, useCallback as ie, useEffect as ee, useContext as le, useRef as Ke } from "react";
3
- import { useLocation as Ae, Navigate as Te, useNavigate as gt, useSearchParams as mt } from "react-router-dom";
4
- class ce {
1
+ import { jsx as s, Fragment as _, jsxs as u } from "react/jsx-runtime";
2
+ import { createContext as pe, useMemo as K, useState as k, useCallback as se, useEffect as re, useContext as ae, useRef as Me } from "react";
3
+ import { useLocation as ke, Navigate as Se, useNavigate as ft, useSearchParams as pt } from "react-router-dom";
4
+ class le {
5
5
  constructor(e, t = 1e4) {
6
6
  this.baseUrl = e.replace(/\/$/, ""), this.timeout = t;
7
7
  }
@@ -13,28 +13,28 @@ class ce {
13
13
  }
14
14
  async executeRequest(e, t, r, i) {
15
15
  const o = `${this.baseUrl}${t.startsWith("/") ? t : `/${t}`}`, a = (i == null ? void 0 : i.timeout) || this.timeout;
16
- let h = {
16
+ let f = {
17
17
  "Content-Type": "application/json",
18
18
  ...i == null ? void 0 : i.headers
19
19
  };
20
20
  if (!(i != null && i.skipAuth) && this.sessionManager) {
21
21
  const c = await this.sessionManager.getValidAccessToken();
22
- h = { ...h, Authorization: `Bearer ${c}` };
22
+ f = { ...f, Authorization: `Bearer ${c}` };
23
23
  }
24
- const g = new AbortController(), w = setTimeout(() => g.abort(), a);
24
+ const m = new AbortController(), b = setTimeout(() => m.abort(), a);
25
25
  try {
26
26
  const c = await fetch(o, {
27
27
  method: e,
28
- headers: h,
28
+ headers: f,
29
29
  body: r ? JSON.stringify(r) : void 0,
30
- signal: g.signal
30
+ signal: m.signal
31
31
  });
32
- if (clearTimeout(w), !c.ok)
32
+ if (clearTimeout(b), !c.ok)
33
33
  throw new Error(`HTTP ${c.status}: ${c.statusText}`);
34
- const I = c.headers.get("content-type");
35
- return !I || !I.includes("application/json") ? {} : await c.json();
34
+ const L = c.headers.get("content-type");
35
+ return !L || !L.includes("application/json") ? {} : await c.json();
36
36
  } catch (c) {
37
- throw clearTimeout(w), c instanceof Error && c.name === "AbortError" ? new Error(`Request timeout after ${a}ms`) : c;
37
+ throw clearTimeout(b), c instanceof Error && c.name === "AbortError" ? new Error(`Request timeout after ${a}ms`) : c;
38
38
  }
39
39
  }
40
40
  async get(e, t) {
@@ -50,7 +50,7 @@ class ce {
50
50
  return this.executeRequest("DELETE", e, void 0, t);
51
51
  }
52
52
  }
53
- class ze {
53
+ class Oe {
54
54
  constructor(e, t) {
55
55
  this.httpService = e, this.sessionManager = t;
56
56
  }
@@ -109,30 +109,30 @@ class ze {
109
109
  })).data;
110
110
  }
111
111
  }
112
- const Fe = me(null);
113
- function yr({ config: n, children: e }) {
114
- const t = Z(
112
+ const Le = pe(null);
113
+ function gr({ config: n, children: e }) {
114
+ const t = K(
115
115
  () => {
116
- var p, x, R;
116
+ var p, R, I;
117
117
  return {
118
118
  enabled: ((p = n.cache) == null ? void 0 : p.enabled) ?? !0,
119
- ttl: ((x = n.cache) == null ? void 0 : x.ttl) ?? 3e5,
119
+ ttl: ((R = n.cache) == null ? void 0 : R.ttl) ?? 3e5,
120
120
  // 5 minutes default
121
- storageKey: ((R = n.cache) == null ? void 0 : R.storageKey) ?? `app_cache_${n.appId}`
121
+ storageKey: ((I = n.cache) == null ? void 0 : I.storageKey) ?? `app_cache_${n.appId}`
122
122
  };
123
123
  },
124
124
  [n.cache, n.appId]
125
- ), [r, i] = T(() => {
125
+ ), [r, i] = k(() => {
126
126
  if (!t.enabled) return null;
127
127
  try {
128
128
  const p = localStorage.getItem(t.storageKey);
129
129
  if (!p) return null;
130
- const x = JSON.parse(p);
131
- return Date.now() - x.timestamp < t.ttl && x.appId === n.appId ? x.data : (localStorage.removeItem(t.storageKey), null);
130
+ const R = JSON.parse(p);
131
+ return Date.now() - R.timestamp < t.ttl && R.appId === n.appId ? R.data : (localStorage.removeItem(t.storageKey), null);
132
132
  } catch {
133
133
  return null;
134
134
  }
135
- }), [o, a] = T(!r), [h, g] = T(null), w = Z(() => {
135
+ }), [o, a] = k(!r), [f, m] = k(null), b = K(() => {
136
136
  const p = () => {
137
137
  c();
138
138
  };
@@ -142,19 +142,19 @@ function yr({ config: n, children: e }) {
142
142
  // App info
143
143
  appInfo: r,
144
144
  isAppLoading: o,
145
- appError: h,
145
+ appError: f,
146
146
  retryApp: p
147
147
  };
148
- }, [n, r, o, h]), c = ie(
148
+ }, [n, r, o, f]), c = se(
149
149
  async (p = !1) => {
150
150
  if (!(!p && t.enabled && r))
151
151
  try {
152
- a(!0), g(null);
153
- const x = new ce(n.baseUrl), F = await new ze(x, {}).getPublicAppInfo(n.appId);
154
- if (i(F), t.enabled)
152
+ a(!0), m(null);
153
+ const R = new le(n.baseUrl), M = await new Oe(R, {}).getPublicAppInfo(n.appId);
154
+ if (i(M), t.enabled)
155
155
  try {
156
156
  const E = {
157
- data: F,
157
+ data: M,
158
158
  timestamp: Date.now(),
159
159
  appId: n.appId
160
160
  };
@@ -162,49 +162,49 @@ function yr({ config: n, children: e }) {
162
162
  } catch (E) {
163
163
  console.warn("Failed to cache app info:", E);
164
164
  }
165
- } catch (x) {
166
- const R = x instanceof Error ? x : new Error("Failed to load app information");
167
- g(R), i(null);
165
+ } catch (R) {
166
+ const I = R instanceof Error ? R : new Error("Failed to load app information");
167
+ m(I), i(null);
168
168
  } finally {
169
169
  a(!1);
170
170
  }
171
171
  },
172
172
  [n.baseUrl, n.appId, t, r]
173
- ), I = ie(async () => {
173
+ ), L = se(async () => {
174
174
  if (!(!t.enabled || !r))
175
175
  try {
176
176
  const p = localStorage.getItem(t.storageKey);
177
177
  if (!p) return;
178
- const x = JSON.parse(p);
179
- if (Date.now() - x.timestamp > t.ttl * 0.5) {
180
- const F = new ce(n.baseUrl), A = await new ze(F, {}).getPublicAppInfo(n.appId);
181
- i(A);
182
- const u = {
183
- data: A,
178
+ const R = JSON.parse(p);
179
+ if (Date.now() - R.timestamp > t.ttl * 0.5) {
180
+ const M = new le(n.baseUrl), x = await new Oe(M, {}).getPublicAppInfo(n.appId);
181
+ i(x);
182
+ const h = {
183
+ data: x,
184
184
  timestamp: Date.now(),
185
185
  appId: n.appId
186
186
  };
187
- localStorage.setItem(t.storageKey, JSON.stringify(u));
187
+ localStorage.setItem(t.storageKey, JSON.stringify(h));
188
188
  }
189
189
  } catch (p) {
190
190
  console.warn("Background app refresh failed:", p);
191
191
  }
192
192
  }, [n, t, r]);
193
- return ee(() => {
194
- r ? I() : c();
195
- }, []), /* @__PURE__ */ s(Fe.Provider, { value: w, children: e });
193
+ return re(() => {
194
+ r ? L() : c();
195
+ }, []), /* @__PURE__ */ s(Le.Provider, { value: b, children: e });
196
196
  }
197
- function ke() {
198
- const n = le(Fe);
197
+ function ve() {
198
+ const n = ae(Le);
199
199
  if (!n)
200
200
  throw new Error("useApp must be used within an AppProvider");
201
201
  return n;
202
202
  }
203
- function Ze() {
204
- return le(Fe);
203
+ function Qe() {
204
+ return ae(Le);
205
205
  }
206
- const wr = ke;
207
- class se extends Error {
206
+ const mr = ve;
207
+ class ne extends Error {
208
208
  constructor(e, t) {
209
209
  const r = {
210
210
  token_expired: "Refresh token has expired",
@@ -214,19 +214,19 @@ class se extends Error {
214
214
  super(t || r[e]), this.name = "SessionExpiredError", this.reason = e;
215
215
  }
216
216
  }
217
- class yt extends Error {
217
+ class gt extends Error {
218
218
  constructor(e) {
219
219
  super(`Token refresh timed out after ${e}ms`), this.name = "TokenRefreshTimeoutError", this.timeoutMs = e;
220
220
  }
221
221
  }
222
- class wt extends Error {
222
+ class mt extends Error {
223
223
  constructor(e, t) {
224
224
  super(
225
225
  `Token refresh failed after ${e} attempts: ${(t == null ? void 0 : t.message) || "Unknown error"}`
226
226
  ), this.name = "TokenRefreshError", this.attempts = e, this.lastError = t;
227
227
  }
228
228
  }
229
- const oe = class oe {
229
+ const ie = class ie {
230
230
  constructor(e = {}) {
231
231
  this.refreshPromise = null, this.refreshQueue = [], this.proactiveTimerId = null, this.backgroundRetryTimerId = null, this.isDestroyed = !1, this.sessionGeneration = 0, e.tenantSlug !== void 0 ? this.storageKey = e.tenantSlug ? `auth_tokens_${e.tenantSlug}` : "auth_tokens" : this.storageKey = e.storageKey || "auth_tokens", this.autoRefresh = e.autoRefresh ?? !0, this.refreshThreshold = e.refreshThreshold || 3e5, this.onRefreshFailed = e.onRefreshFailed, this.onSessionExpired = e.onSessionExpired, this.baseUrl = e.baseUrl || "", this.proactiveRefreshMargin = e.proactiveRefreshMargin ?? 6e4, this.refreshQueueTimeout = e.refreshQueueTimeout ?? 1e4, this.maxRefreshRetries = e.maxRefreshRetries ?? 3, this.retryBackoffBase = e.retryBackoffBase ?? 1e3, this.tokenStorage = e.tokenStorage || this.createTokenStorage(this.storageKey), this.scheduleProactiveRefresh();
232
232
  }
@@ -236,17 +236,17 @@ const oe = class oe {
236
236
  * Mutable config (callbacks, baseUrl) is updated on the existing instance.
237
237
  */
238
238
  static getInstance(e = {}) {
239
- const t = oe.resolveStorageKey(e), r = oe.instances.get(t);
239
+ const t = ie.resolveStorageKey(e), r = ie.instances.get(t);
240
240
  if (r)
241
241
  return r.updateConfig(e), r;
242
- const i = new oe(e);
243
- return oe.instances.set(t, i), i;
242
+ const i = new ie(e);
243
+ return ie.instances.set(t, i), i;
244
244
  }
245
245
  /** Reset all singleton instances. For testing only. */
246
246
  static resetAllInstances() {
247
- for (const e of oe.instances.values())
247
+ for (const e of ie.instances.values())
248
248
  e.destroy();
249
- oe.instances.clear();
249
+ ie.instances.clear();
250
250
  }
251
251
  static resolveStorageKey(e) {
252
252
  return e.storageKey ? e.storageKey : e.tenantSlug !== void 0 && e.tenantSlug ? `auth_tokens_${e.tenantSlug}` : "auth_tokens";
@@ -296,7 +296,7 @@ const oe = class oe {
296
296
  }
297
297
  }
298
298
  setTokens(e) {
299
- const t = e.expiresAt || (e.expiresIn ? Date.now() + e.expiresIn * 1e3 : void 0) || oe.extractJwtExpiry(e.accessToken), r = {
299
+ const t = e.expiresAt || (e.expiresIn ? Date.now() + e.expiresIn * 1e3 : void 0) || ie.extractJwtExpiry(e.accessToken), r = {
300
300
  ...e,
301
301
  expiresAt: t
302
302
  }, i = this.tokenStorage.get() || {};
@@ -306,7 +306,7 @@ const oe = class oe {
306
306
  const { accessToken: e, refreshToken: t, expiresAt: r, expiresIn: i, tokenType: o } = this.tokenStorage.get() || {};
307
307
  if (!e)
308
308
  return null;
309
- const a = r || oe.extractJwtExpiry(e);
309
+ const a = r || ie.extractJwtExpiry(e);
310
310
  return {
311
311
  accessToken: e,
312
312
  refreshToken: t,
@@ -354,7 +354,7 @@ const oe = class oe {
354
354
  const t = this.sessionGeneration;
355
355
  this.startRefreshAndResolveQueue(e.refreshToken).then(() => {
356
356
  }).catch((r) => {
357
- r instanceof se || this.sessionGeneration === t && (console.warn(
357
+ r instanceof ne || this.sessionGeneration === t && (console.warn(
358
358
  "[SessionManager] Background refresh failed, retrying in 30s:",
359
359
  r.message
360
360
  ), this.backgroundRetryTimerId = setTimeout(() => {
@@ -386,13 +386,13 @@ const oe = class oe {
386
386
  async getValidAccessToken() {
387
387
  const e = this.getTokens();
388
388
  if (!(e != null && e.accessToken)) {
389
- const t = new se("token_invalid", "No tokens available");
389
+ const t = new ne("token_invalid", "No tokens available");
390
390
  throw this.handleSessionExpired(t), t;
391
391
  }
392
392
  if (!this.shouldRefreshToken(e) && !this.isTokenExpired(e))
393
393
  return e.accessToken;
394
394
  if (!e.refreshToken) {
395
- const t = new se("token_invalid", "No refresh token available");
395
+ const t = new ne("token_invalid", "No refresh token available");
396
396
  throw this.handleSessionExpired(t), t;
397
397
  }
398
398
  return this.refreshPromise ? this.enqueueForToken() : this.startRefreshAndResolveQueue(e.refreshToken);
@@ -404,14 +404,14 @@ const oe = class oe {
404
404
  try {
405
405
  return { Authorization: `Bearer ${await this.getValidAccessToken()}` };
406
406
  } catch (e) {
407
- return e instanceof se && this.onRefreshFailed && this.onRefreshFailed(), {};
407
+ return e instanceof ne && this.onRefreshFailed && this.onRefreshFailed(), {};
408
408
  }
409
409
  }
410
410
  enqueueForToken() {
411
411
  return new Promise((e, t) => {
412
412
  const r = setTimeout(() => {
413
413
  const i = this.refreshQueue.findIndex((o) => o.timeoutId === r);
414
- i !== -1 && this.refreshQueue.splice(i, 1), t(new yt(this.refreshQueueTimeout));
414
+ i !== -1 && this.refreshQueue.splice(i, 1), t(new gt(this.refreshQueueTimeout));
415
415
  }, this.refreshQueueTimeout);
416
416
  this.refreshQueue.push({ resolve: e, reject: t, timeoutId: r });
417
417
  });
@@ -424,7 +424,7 @@ const oe = class oe {
424
424
  return this.resolveQueue(r), r;
425
425
  } catch (t) {
426
426
  const r = t instanceof Error ? t : new Error("Token refresh failed");
427
- throw r instanceof se ? (this.rejectQueue(r), this.handleSessionExpired(r)) : this.rejectQueue(r), r;
427
+ throw r instanceof ne ? (this.rejectQueue(r), this.handleSessionExpired(r)) : this.rejectQueue(r), r;
428
428
  } finally {
429
429
  this.refreshPromise = null;
430
430
  }
@@ -447,21 +447,21 @@ const oe = class oe {
447
447
  const r = this.sessionGeneration;
448
448
  for (let i = 0; i <= this.maxRefreshRetries; i++) {
449
449
  if (this.sessionGeneration !== r)
450
- throw new se("token_invalid", "Session cleared during refresh");
450
+ throw new ne("token_invalid", "Session cleared during refresh");
451
451
  try {
452
452
  await this.performTokenRefresh(e, r);
453
453
  return;
454
454
  } catch (o) {
455
455
  const a = o instanceof Error ? o : new Error(String(o));
456
- if (a instanceof se)
456
+ if (a instanceof ne)
457
457
  throw a;
458
458
  if (t = a, i < this.maxRefreshRetries) {
459
- const h = this.retryBackoffBase * Math.pow(2, i);
460
- await this.sleep(h);
459
+ const f = this.retryBackoffBase * Math.pow(2, i);
460
+ await this.sleep(f);
461
461
  }
462
462
  }
463
463
  }
464
- throw new wt(this.maxRefreshRetries + 1, t);
464
+ throw new mt(this.maxRefreshRetries + 1, t);
465
465
  }
466
466
  /**
467
467
  * Single refresh attempt with error classification.
@@ -485,15 +485,15 @@ const oe = class oe {
485
485
  if (!i.ok) {
486
486
  let a = "";
487
487
  try {
488
- const h = await i.json();
489
- a = (h.message || h.error || "").toLowerCase();
488
+ const f = await i.json();
489
+ a = (f.message || f.error || "").toLowerCase();
490
490
  } catch {
491
491
  a = i.statusText.toLowerCase();
492
492
  }
493
- throw i.status === 401 ? a.includes("expired") ? new se("token_expired") : a.includes("invalid") ? new se("token_invalid") : new se("token_invalid", `Unauthorized: ${a}`) : i.status === 400 ? a.includes("inactive") ? new se("user_inactive") : a.includes("expired") || a.includes("invalid") ? new se("token_invalid", a) : new Error(`Token refresh failed (400): ${a}`) : new Error(`Token refresh failed: ${i.status} ${a}`);
493
+ throw i.status === 401 ? a.includes("expired") ? new ne("token_expired") : a.includes("invalid") ? new ne("token_invalid") : new ne("token_invalid", `Unauthorized: ${a}`) : i.status === 400 ? a.includes("inactive") ? new ne("user_inactive") : a.includes("expired") || a.includes("invalid") ? new ne("token_invalid", a) : new Error(`Token refresh failed (400): ${a}`) : new Error(`Token refresh failed: ${i.status} ${a}`);
494
494
  }
495
495
  if (this.sessionGeneration !== t)
496
- throw new se("token_invalid", "Session cleared during refresh");
496
+ throw new ne("token_invalid", "Session cleared during refresh");
497
497
  const o = await i.json();
498
498
  this.setTokens({
499
499
  accessToken: o.accessToken,
@@ -521,7 +521,7 @@ const oe = class oe {
521
521
  // --- Session lifecycle ---
522
522
  clearSession() {
523
523
  this.sessionGeneration++, this.cancelProactiveTimer(), this.clearTokens();
524
- const e = new se("token_invalid", "Session cleared");
524
+ const e = new ne("token_invalid", "Session cleared");
525
525
  this.rejectQueue(e);
526
526
  }
527
527
  /**
@@ -529,8 +529,8 @@ const oe = class oe {
529
529
  * Cancels all timers and rejects pending queue entries.
530
530
  */
531
531
  destroy() {
532
- this.isDestroyed = !0, oe.instances.delete(this.storageKey), this.cancelProactiveTimer();
533
- const e = new se("token_invalid", "SessionManager destroyed");
532
+ this.isDestroyed = !0, ie.instances.delete(this.storageKey), this.cancelProactiveTimer();
533
+ const e = new ne("token_invalid", "SessionManager destroyed");
534
534
  this.rejectQueue(e);
535
535
  }
536
536
  // --- JWT helpers ---
@@ -568,9 +568,9 @@ const oe = class oe {
568
568
  return new Promise((t) => setTimeout(t, e));
569
569
  }
570
570
  };
571
- oe.instances = /* @__PURE__ */ new Map();
572
- let Se = oe;
573
- class bt {
571
+ ie.instances = /* @__PURE__ */ new Map();
572
+ let we = ie;
573
+ class yt {
574
574
  constructor(e) {
575
575
  this.httpService = e;
576
576
  }
@@ -626,7 +626,7 @@ class bt {
626
626
  });
627
627
  }
628
628
  }
629
- class _e {
629
+ class ze {
630
630
  constructor(e, t) {
631
631
  this.httpService = e, this.sessionManager = t;
632
632
  }
@@ -702,7 +702,7 @@ class _e {
702
702
  };
703
703
  }
704
704
  }
705
- class St {
705
+ class wt {
706
706
  constructor(e, t) {
707
707
  this.httpService = e, this.sessionManager = t;
708
708
  }
@@ -742,7 +742,7 @@ class St {
742
742
  });
743
743
  }
744
744
  }
745
- class ve {
745
+ class be {
746
746
  constructor(e, t, r) {
747
747
  this.httpService = e, this.appId = t, this.sessionManager = r;
748
748
  }
@@ -820,7 +820,7 @@ class ve {
820
820
  )).data;
821
821
  }
822
822
  }
823
- function vt(n, e) {
823
+ function bt(n, e) {
824
824
  if (n === "localhost" || n.startsWith("127.") || n.startsWith("192.168."))
825
825
  return null;
826
826
  if (e) {
@@ -836,26 +836,26 @@ function vt(n, e) {
836
836
  const r = n.split(".");
837
837
  return r.length >= 3 && r[0] !== "www" ? r[0] : null;
838
838
  }
839
- function Tt(n, e = "tenant", t) {
839
+ function St(n, e = "tenant", t) {
840
840
  const i = new URLSearchParams(n).get(e);
841
841
  return i ? (t && t.setItem("tenant", i), i) : t ? t.getItem("tenant") : null;
842
842
  }
843
- function kt(n, e, t) {
843
+ function vt(n, e, t) {
844
844
  const { tenantMode: r, baseDomain: i, selectorParam: o, fixedTenantSlug: a } = n;
845
- return r === "fixed" ? a || null : r === "subdomain" ? vt(e.hostname, i) : r === "selector" ? Tt(e.search, o, t) : null;
845
+ return r === "fixed" ? a || null : r === "subdomain" ? bt(e.hostname, i) : r === "selector" ? St(e.search, o, t) : null;
846
846
  }
847
- function xt(n, e, t) {
847
+ function Tt(n, e, t) {
848
848
  if (t)
849
849
  return `${n}.${t}`;
850
850
  const r = e.split(".");
851
851
  return r.length === 2 ? `${n}.${e}` : r.length >= 3 ? (r[0] = n, r.join(".")) : null;
852
852
  }
853
- const ge = "_auth";
854
- function We(n) {
853
+ const fe = "_auth";
854
+ function _e(n) {
855
855
  const e = JSON.stringify(n);
856
856
  return btoa(e).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
857
857
  }
858
- function At(n) {
858
+ function kt(n) {
859
859
  try {
860
860
  let e = n.replace(/-/g, "+").replace(/_/g, "/");
861
861
  for (; e.length % 4; )
@@ -866,16 +866,16 @@ function At(n) {
866
866
  return null;
867
867
  }
868
868
  }
869
- function Pt() {
869
+ function xt() {
870
870
  if (typeof window > "u")
871
871
  return console.log("[CrossDomainAuth] SSR environment, skipping URL token extraction"), null;
872
- const e = new URLSearchParams(window.location.search).get(ge);
872
+ const e = new URLSearchParams(window.location.search).get(fe);
873
873
  if (console.log("[CrossDomainAuth] extractAuthTokensFromUrl called", {
874
874
  hasAuthParam: !!e,
875
875
  searchParams: window.location.search,
876
876
  encodedLength: e == null ? void 0 : e.length
877
877
  }), !e) return null;
878
- const t = At(e);
878
+ const t = kt(e);
879
879
  return console.log("[CrossDomainAuth] Token decode result:", {
880
880
  success: !!t,
881
881
  hasAccessToken: !!(t != null && t.accessToken),
@@ -883,17 +883,17 @@ function Pt() {
883
883
  expiresIn: t == null ? void 0 : t.expiresIn
884
884
  }), t;
885
885
  }
886
- function Rt() {
886
+ function At() {
887
887
  if (typeof window > "u") return;
888
888
  const n = new URL(window.location.href);
889
- n.searchParams.delete(ge), console.log("[CrossDomainAuth] Clearing auth tokens from URL", {
889
+ n.searchParams.delete(fe), console.log("[CrossDomainAuth] Clearing auth tokens from URL", {
890
890
  oldUrl: window.location.href,
891
891
  newUrl: n.toString()
892
892
  }), window.history.replaceState({}, "", n.toString());
893
893
  }
894
- const De = me(null);
895
- function br({ config: n, children: e }) {
896
- const { baseUrl: t, appInfo: r, appId: i } = ke(), o = ie(() => typeof window > "u" ? null : kt(
894
+ const Fe = pe(null);
895
+ function yr({ config: n, children: e }) {
896
+ const { baseUrl: t, appInfo: r, appId: i } = ve(), o = se(() => typeof window > "u" ? null : vt(
897
897
  {
898
898
  tenantMode: n.tenantMode || "selector",
899
899
  baseDomain: n.baseDomain,
@@ -905,119 +905,119 @@ function br({ config: n, children: e }) {
905
905
  search: window.location.search
906
906
  },
907
907
  window.localStorage
908
- ), [n.tenantMode, n.baseDomain, n.selectorParam, n.fixedTenantSlug]), [a, h] = T(() => o()), g = Z(
908
+ ), [n.tenantMode, n.baseDomain, n.selectorParam, n.fixedTenantSlug]), [a, f] = k(() => o()), m = K(
909
909
  () => {
910
- var f, C, S;
910
+ var d, U, F;
911
911
  return {
912
- enabled: ((f = n.cache) == null ? void 0 : f.enabled) ?? !0,
913
- ttl: ((C = n.cache) == null ? void 0 : C.ttl) ?? 5 * 60 * 1e3,
912
+ enabled: ((d = n.cache) == null ? void 0 : d.enabled) ?? !0,
913
+ ttl: ((U = n.cache) == null ? void 0 : U.ttl) ?? 5 * 60 * 1e3,
914
914
  // 5 minutes default
915
- storageKey: ((S = n.cache) == null ? void 0 : S.storageKey) ?? `tenant_cache_${a || "default"}`
915
+ storageKey: ((F = n.cache) == null ? void 0 : F.storageKey) ?? `tenant_cache_${a || "default"}`
916
916
  };
917
917
  },
918
918
  [n.cache, a]
919
- ), [w, c] = T(() => {
919
+ ), [b, c] = k(() => {
920
920
  if (n.initialTenant) return n.initialTenant;
921
- if (!g.enabled || !a) return null;
921
+ if (!m.enabled || !a) return null;
922
922
  try {
923
- const f = localStorage.getItem(g.storageKey);
924
- if (!f) return null;
925
- const C = JSON.parse(f);
926
- return Date.now() - C.timestamp < g.ttl && C.tenantSlug === a ? C.data : (localStorage.removeItem(g.storageKey), null);
923
+ const d = localStorage.getItem(m.storageKey);
924
+ if (!d) return null;
925
+ const U = JSON.parse(d);
926
+ return Date.now() - U.timestamp < m.ttl && U.tenantSlug === a ? U.data : (localStorage.removeItem(m.storageKey), null);
927
927
  } catch {
928
928
  return null;
929
929
  }
930
- }), [I, p] = T(!w && !n.initialTenant), [x, R] = T(null), [F, E] = T(null), [A, u] = T(!1), [k, m] = T(null);
931
- ee(() => {
930
+ }), [L, p] = k(!b && !n.initialTenant), [R, I] = k(null), [M, E] = k(null), [x, h] = k(!1), [A, w] = k(null);
931
+ re(() => {
932
932
  if (n.tenantMode === "fixed") return;
933
- const f = o();
934
- h(f);
933
+ const d = o();
934
+ f(d);
935
935
  }, [o, n.tenantMode]);
936
- const M = (r == null ? void 0 : r.settingsSchema) || null, L = ie(
937
- async (f, C = !1) => {
938
- if (!(!C && g.enabled && w && w.domain === f))
936
+ const v = (r == null ? void 0 : r.settingsSchema) || null, N = se(
937
+ async (d, U = !1) => {
938
+ if (!(!U && m.enabled && b && b.domain === d))
939
939
  try {
940
- p(!0), R(null);
941
- const S = new ce(t), y = await new ve(S, i).getPublicTenantInfo(f);
942
- if (c(y), g.enabled)
940
+ p(!0), I(null);
941
+ const F = new le(t), g = await new be(F, i).getPublicTenantInfo(d);
942
+ if (c(g), m.enabled)
943
943
  try {
944
- const v = {
945
- data: y,
944
+ const S = {
945
+ data: g,
946
946
  timestamp: Date.now(),
947
- tenantSlug: f
947
+ tenantSlug: d
948
948
  };
949
- localStorage.setItem(g.storageKey, JSON.stringify(v));
950
- } catch (v) {
951
- console.warn("Failed to cache tenant info:", v);
949
+ localStorage.setItem(m.storageKey, JSON.stringify(S));
950
+ } catch (S) {
951
+ console.warn("Failed to cache tenant info:", S);
952
952
  }
953
- } catch (S) {
954
- const b = S instanceof Error ? S : new Error("Failed to load tenant information");
955
- R(b), c(null);
953
+ } catch (F) {
954
+ const y = F instanceof Error ? F : new Error("Failed to load tenant information");
955
+ I(y), c(null);
956
956
  } finally {
957
957
  p(!1);
958
958
  }
959
959
  },
960
- [t, i, g, w]
961
- ), D = ie(async () => {
962
- if (!(!g.enabled || !w || !a))
960
+ [t, i, m, b]
961
+ ), B = se(async () => {
962
+ if (!(!m.enabled || !b || !a))
963
963
  try {
964
- const f = localStorage.getItem(g.storageKey);
965
- if (!f) return;
966
- const C = JSON.parse(f);
967
- if (Date.now() - C.timestamp > g.ttl * 0.5) {
968
- const b = new ce(t), v = await new ve(b, i).getPublicTenantInfo(a);
969
- c(v);
970
- const G = {
971
- data: v,
964
+ const d = localStorage.getItem(m.storageKey);
965
+ if (!d) return;
966
+ const U = JSON.parse(d);
967
+ if (Date.now() - U.timestamp > m.ttl * 0.5) {
968
+ const y = new le(t), S = await new be(y, i).getPublicTenantInfo(a);
969
+ c(S);
970
+ const Q = {
971
+ data: S,
972
972
  timestamp: Date.now(),
973
973
  tenantSlug: a
974
974
  };
975
- localStorage.setItem(g.storageKey, JSON.stringify(G));
975
+ localStorage.setItem(m.storageKey, JSON.stringify(Q));
976
976
  }
977
- } catch (f) {
978
- console.warn("Background tenant refresh failed:", f);
977
+ } catch (d) {
978
+ console.warn("Background tenant refresh failed:", d);
979
979
  }
980
- }, [t, i, g, w, a]), P = ie(async () => {
981
- if (w != null && w.id)
980
+ }, [t, i, m, b, a]), l = se(async () => {
981
+ if (b != null && b.id)
982
982
  try {
983
- u(!0), m(null);
984
- const f = new ce(t), S = await new ve(f, w.appId).getTenantSettings(w.id);
985
- E(S);
986
- } catch (f) {
987
- const C = f instanceof Error ? f : new Error("Failed to load tenant settings");
988
- m(C), E(null);
983
+ h(!0), w(null);
984
+ const d = new le(t), F = await new be(d, b.appId).getTenantSettings(b.id);
985
+ E(F);
986
+ } catch (d) {
987
+ const U = d instanceof Error ? d : new Error("Failed to load tenant settings");
988
+ w(U), E(null);
989
989
  } finally {
990
- u(!1);
990
+ h(!1);
991
991
  }
992
- }, [t, w]), U = ie(() => {
993
- P();
994
- }, [P]), l = ie(
995
- (f) => {
996
- if (!M)
992
+ }, [t, b]), H = se(() => {
993
+ l();
994
+ }, [l]), P = se(
995
+ (d) => {
996
+ if (!v)
997
997
  return { isValid: !0, errors: [] };
998
- const C = [];
998
+ const U = [];
999
999
  try {
1000
- return M.properties && Object.entries(M.properties).forEach(([S, b]) => {
1001
- var v;
1002
- const y = f[S];
1003
- if ((v = M.required) != null && v.includes(S) && y == null) {
1004
- C.push(`Field '${S}' is required`);
1000
+ return v.properties && Object.entries(v.properties).forEach(([F, y]) => {
1001
+ var S;
1002
+ const g = d[F];
1003
+ if ((S = v.required) != null && S.includes(F) && g == null) {
1004
+ U.push(`Field '${F}' is required`);
1005
1005
  return;
1006
1006
  }
1007
- if (y != null) {
1008
- if (b.type) {
1009
- const G = b.type, Q = typeof y;
1010
- G === "string" && Q !== "string" ? C.push(`Field '${S}' must be a string`) : (G === "number" || G === "integer") && Q !== "number" ? C.push(`Field '${S}' must be a number`) : G === "boolean" && Q !== "boolean" ? C.push(`Field '${S}' must be a boolean`) : G === "array" && !Array.isArray(y) && C.push(`Field '${S}' must be an array`);
1007
+ if (g != null) {
1008
+ if (y.type) {
1009
+ const Q = y.type, J = typeof g;
1010
+ Q === "string" && J !== "string" ? U.push(`Field '${F}' must be a string`) : (Q === "number" || Q === "integer") && J !== "number" ? U.push(`Field '${F}' must be a number`) : Q === "boolean" && J !== "boolean" ? U.push(`Field '${F}' must be a boolean`) : Q === "array" && !Array.isArray(g) && U.push(`Field '${F}' must be an array`);
1011
1011
  }
1012
- b.minLength !== void 0 && typeof y == "string" && y.length < b.minLength && C.push(
1013
- `Field '${S}' must be at least ${b.minLength} characters long`
1014
- ), b.maxLength !== void 0 && typeof y == "string" && y.length > b.maxLength && C.push(
1015
- `Field '${S}' must be no more than ${b.maxLength} characters long`
1016
- ), b.minimum !== void 0 && typeof y == "number" && y < b.minimum && C.push(`Field '${S}' must be at least ${b.minimum}`), b.maximum !== void 0 && typeof y == "number" && y > b.maximum && C.push(`Field '${S}' must be no more than ${b.maximum}`), b.pattern && typeof y == "string" && (new RegExp(b.pattern).test(y) || C.push(`Field '${S}' does not match the required pattern`)), b.enum && !b.enum.includes(y) && C.push(`Field '${S}' must be one of: ${b.enum.join(", ")}`);
1012
+ y.minLength !== void 0 && typeof g == "string" && g.length < y.minLength && U.push(
1013
+ `Field '${F}' must be at least ${y.minLength} characters long`
1014
+ ), y.maxLength !== void 0 && typeof g == "string" && g.length > y.maxLength && U.push(
1015
+ `Field '${F}' must be no more than ${y.maxLength} characters long`
1016
+ ), y.minimum !== void 0 && typeof g == "number" && g < y.minimum && U.push(`Field '${F}' must be at least ${y.minimum}`), y.maximum !== void 0 && typeof g == "number" && g > y.maximum && U.push(`Field '${F}' must be no more than ${y.maximum}`), y.pattern && typeof g == "string" && (new RegExp(y.pattern).test(g) || U.push(`Field '${F}' does not match the required pattern`)), y.enum && !y.enum.includes(g) && U.push(`Field '${F}' must be one of: ${y.enum.join(", ")}`);
1017
1017
  }
1018
1018
  }), {
1019
- isValid: C.length === 0,
1020
- errors: C
1019
+ isValid: U.length === 0,
1020
+ errors: U
1021
1021
  };
1022
1022
  } catch {
1023
1023
  return {
@@ -1026,98 +1026,98 @@ function br({ config: n, children: e }) {
1026
1026
  };
1027
1027
  }
1028
1028
  },
1029
- [M]
1029
+ [v]
1030
1030
  );
1031
- ee(() => {
1032
- !n.initialTenant && a ? w ? D() : L(a) : !n.initialTenant && !a && (c(null), R(null), p(!1));
1033
- }, [n.initialTenant, a, w, L, D]), ee(() => {
1034
- w != null && w.id ? P() : (E(null), m(null), u(!1));
1035
- }, [w == null ? void 0 : w.id, P]);
1036
- const N = ie(
1037
- (f, C) => {
1038
- const { mode: S = "reload", tokens: b, redirectPath: y } = C || {}, v = n.tenantMode || "selector";
1039
- if (v === "fixed") {
1031
+ re(() => {
1032
+ !n.initialTenant && a ? b ? B() : N(a) : !n.initialTenant && !a && (c(null), I(null), p(!1));
1033
+ }, [n.initialTenant, a, b, N, B]), re(() => {
1034
+ b != null && b.id ? l() : (E(null), w(null), h(!1));
1035
+ }, [b == null ? void 0 : b.id, l]);
1036
+ const D = se(
1037
+ (d, U) => {
1038
+ const { mode: F = "reload", tokens: y, redirectPath: g } = U || {}, S = n.tenantMode || "selector";
1039
+ if (S === "fixed") {
1040
1040
  console.warn(
1041
1041
  "[TenantProvider] switchTenant is a no-op in fixed mode. Tenant is always:",
1042
1042
  n.fixedTenantSlug
1043
- ), y && (window.location.href = y);
1043
+ ), g && (window.location.href = g);
1044
1044
  return;
1045
1045
  }
1046
- if (localStorage.setItem("tenant", f), v === "subdomain") {
1047
- const G = window.location.hostname, Q = xt(
1048
- f,
1049
- G,
1046
+ if (localStorage.setItem("tenant", d), S === "subdomain") {
1047
+ const Q = window.location.hostname, J = Tt(
1048
+ d,
1049
+ Q,
1050
1050
  n.baseDomain
1051
1051
  );
1052
- if (!Q) {
1052
+ if (!J) {
1053
1053
  console.warn(
1054
1054
  "[TenantProvider] Cannot switch subdomain, invalid hostname:",
1055
- G
1055
+ Q
1056
1056
  );
1057
1057
  return;
1058
1058
  }
1059
- const O = y || window.location.pathname, q = new URL(`${window.location.protocol}//${Q}${O}`);
1060
- new URLSearchParams(window.location.search).forEach((B, X) => {
1061
- X !== ge && q.searchParams.set(X, B);
1062
- }), b && q.searchParams.set(ge, We(b)), window.location.href = q.toString();
1063
- } else if (v === "selector") {
1064
- const G = y || window.location.pathname, Q = new URLSearchParams(window.location.search);
1065
- if (Q.set(n.selectorParam || "tenant", f), Q.delete(ge), b && Q.set(ge, We(b)), S === "reload") {
1066
- const O = `${G}?${Q.toString()}${window.location.hash}`;
1067
- window.location.href = O;
1059
+ const q = g || window.location.pathname, O = new URL(`${window.location.protocol}//${J}${q}`);
1060
+ new URLSearchParams(window.location.search).forEach((T, V) => {
1061
+ V !== fe && O.searchParams.set(V, T);
1062
+ }), y && O.searchParams.set(fe, _e(y)), window.location.href = O.toString();
1063
+ } else if (S === "selector") {
1064
+ const Q = g || window.location.pathname, J = new URLSearchParams(window.location.search);
1065
+ if (J.set(n.selectorParam || "tenant", d), J.delete(fe), y && J.set(fe, _e(y)), F === "reload") {
1066
+ const q = `${Q}?${J.toString()}${window.location.hash}`;
1067
+ window.location.href = q;
1068
1068
  } else {
1069
- const O = `${G}?${Q.toString()}${window.location.hash}`;
1070
- window.history.pushState({}, "", O), h(f), L(f);
1069
+ const q = `${Q}?${J.toString()}${window.location.hash}`;
1070
+ window.history.pushState({}, "", q), f(d), N(d);
1071
1071
  }
1072
1072
  }
1073
1073
  },
1074
- [n.tenantMode, n.selectorParam, n.baseDomain, L]
1075
- ), H = Z(() => ({
1074
+ [n.tenantMode, n.selectorParam, n.baseDomain, N]
1075
+ ), C = K(() => ({
1076
1076
  // Tenant info
1077
- tenant: w,
1077
+ tenant: b,
1078
1078
  tenantSlug: a,
1079
- isTenantLoading: I,
1080
- tenantError: x,
1079
+ isTenantLoading: L,
1080
+ tenantError: R,
1081
1081
  retryTenant: () => {
1082
- a && L(a);
1082
+ a && N(a);
1083
1083
  },
1084
1084
  // Settings
1085
- settings: F,
1086
- settingsSchema: M,
1087
- isSettingsLoading: A,
1088
- settingsError: k,
1085
+ settings: M,
1086
+ settingsSchema: v,
1087
+ isSettingsLoading: x,
1088
+ settingsError: A,
1089
1089
  // Actions
1090
- refreshSettings: U,
1091
- switchTenant: N,
1090
+ refreshSettings: H,
1091
+ switchTenant: D,
1092
1092
  // Validation
1093
- validateSettings: l
1093
+ validateSettings: P
1094
1094
  }), [
1095
- w,
1095
+ b,
1096
1096
  a,
1097
- I,
1098
- x,
1099
- F,
1097
+ L,
1098
+ R,
1100
1099
  M,
1100
+ v,
1101
+ x,
1101
1102
  A,
1102
- k,
1103
- U,
1104
- N,
1105
- l
1103
+ H,
1104
+ D,
1105
+ P
1106
1106
  ]);
1107
- return /* @__PURE__ */ s(De.Provider, { value: H, children: e });
1107
+ return /* @__PURE__ */ s(Fe.Provider, { value: C, children: e });
1108
1108
  }
1109
- function ye() {
1110
- const n = le(De);
1109
+ function ge() {
1110
+ const n = ae(Fe);
1111
1111
  if (!n)
1112
1112
  throw new Error("useTenant must be used within a TenantProvider");
1113
1113
  return n;
1114
1114
  }
1115
- function Pe() {
1116
- return le(De);
1115
+ function xe() {
1116
+ return ae(Fe);
1117
1117
  }
1118
- const Sr = ye;
1119
- function vr() {
1120
- const { settings: n, settingsSchema: e, isSettingsLoading: t, settingsError: r, validateSettings: i } = ye();
1118
+ const wr = ge;
1119
+ function br() {
1120
+ const { settings: n, settingsSchema: e, isSettingsLoading: t, settingsError: r, validateSettings: i } = ge();
1121
1121
  return {
1122
1122
  settings: n,
1123
1123
  settingsSchema: e,
@@ -1126,8 +1126,8 @@ function vr() {
1126
1126
  validateSettings: i
1127
1127
  };
1128
1128
  }
1129
- function we() {
1130
- const { tenant: n, tenantSlug: e, isTenantLoading: t, tenantError: r, retryTenant: i } = ye();
1129
+ function me() {
1130
+ const { tenant: n, tenantSlug: e, isTenantLoading: t, tenantError: r, retryTenant: i } = ge();
1131
1131
  return {
1132
1132
  tenant: n,
1133
1133
  tenantSlug: e,
@@ -1136,216 +1136,214 @@ function we() {
1136
1136
  retry: i
1137
1137
  };
1138
1138
  }
1139
- const Ne = me(null);
1140
- function Tr({ config: n = {}, children: e }) {
1141
- const { appId: t, baseUrl: r } = ke(), { tenant: i, tenantSlug: o, switchTenant: a } = ye(), [h, g] = T(n.initialRoles || []), [w, c] = T(!n.initialRoles), [I, p] = T(null), [x, R] = T(!1), [F, E] = T(null), [A, u] = T(0), [k, m] = T(() => {
1139
+ const Ne = pe(null);
1140
+ function Sr({ config: n = {}, children: e }) {
1141
+ const { appId: t, baseUrl: r } = ve(), { tenant: i, tenantSlug: o, switchTenant: a } = ge(), [f, m] = k(n.initialRoles || []), [b, c] = k(!n.initialRoles), [L, p] = k(null), [R, I] = k(!1), [M, E] = k(null), [x, h] = k(() => {
1142
1142
  try {
1143
- const V = localStorage.getItem("userTenants");
1144
- return V ? JSON.parse(V) : [];
1143
+ const T = localStorage.getItem("userTenants");
1144
+ return T ? JSON.parse(T) : [];
1145
1145
  } catch {
1146
1146
  return [];
1147
1147
  }
1148
- }), [M, L] = T(!1), D = Ke({ done: !1, urlTokens: null });
1149
- D.current.done || (D.current.done = !0, D.current.urlTokens = Pt(), D.current.urlTokens && console.log(
1148
+ }), [A, w] = k(!1), v = Me({ done: !1, urlTokens: null });
1149
+ v.current.done || (v.current.done = !0, v.current.urlTokens = xt(), v.current.urlTokens && console.log(
1150
1150
  "[AuthProvider] SYNC: URL tokens found, will block isAuthReady until user loaded"
1151
1151
  ));
1152
- const [P, U] = T(() => {
1153
- const V = D.current.urlTokens !== null;
1154
- return console.log("[AuthProvider] SYNC: isLoadingAfterUrlTokens initial:", V), V;
1155
- }), l = Z(() => {
1156
- const V = Se.getInstance({
1152
+ const [N, B] = k(() => {
1153
+ const T = v.current.urlTokens !== null;
1154
+ return console.log("[AuthProvider] SYNC: isLoadingAfterUrlTokens initial:", T), T;
1155
+ }), l = K(() => {
1156
+ const T = we.getInstance({
1157
1157
  tenantSlug: o,
1158
1158
  baseUrl: r,
1159
1159
  refreshQueueTimeout: n.refreshQueueTimeout,
1160
1160
  proactiveRefreshMargin: n.proactiveRefreshMargin,
1161
- onSessionExpired: (he) => {
1162
- p(null), E(null), m([]), L(!1);
1161
+ onSessionExpired: (V) => {
1162
+ p(null), E(null), h([]), w(!1);
1163
1163
  try {
1164
1164
  localStorage.removeItem("userTenants");
1165
1165
  } catch {
1166
1166
  }
1167
- n.onSessionExpired ? n.onSessionExpired(he) : n.onRefreshFailed && n.onRefreshFailed();
1167
+ n.onSessionExpired ? n.onSessionExpired(V) : n.onRefreshFailed && n.onRefreshFailed();
1168
1168
  }
1169
1169
  });
1170
- return D.current.urlTokens && (console.log("[AuthProvider] SYNC: Saving URL tokens to session manager"), V.setTokens({
1171
- accessToken: D.current.urlTokens.accessToken,
1172
- refreshToken: D.current.urlTokens.refreshToken,
1173
- expiresIn: D.current.urlTokens.expiresIn
1174
- }), console.log("[AuthProvider] SYNC: Session valid:", V.hasValidSession())), V;
1175
- }, [o, r, n.refreshQueueTimeout, n.proactiveRefreshMargin]), [N, H] = T(() => {
1176
- if (D.current.urlTokens) return !1;
1177
- const V = l.getTokens();
1178
- return V ? l.hasValidSession() || !!V.refreshToken : !1;
1179
- }), f = D.current.done && !P && !N, C = Z(() => {
1180
- const V = new ce(r);
1181
- return V.setSessionManager(l), V;
1182
- }, [r, l]), S = Z(() => new bt(new ce(r)), [r]), b = Z(() => new St(C, l), [C, l]), y = Z(() => new _e(new ce(r)), [r]), v = Z(() => I || l.getUser(), [I, l]), G = Z(() => v != null && v.roleId && h.find((V) => V.id === v.roleId) || null, [v, h]), Q = Z(() => (G == null ? void 0 : G.permissions) || [], [G]), O = Z(() => l.hasValidSession() && I !== null, [l, I]), q = 5 * 60 * 1e3, W = Z(() => {
1183
- const V = async ($ = !1) => {
1170
+ return v.current.urlTokens && (console.log("[AuthProvider] SYNC: Saving URL tokens to session manager"), T.setTokens({
1171
+ accessToken: v.current.urlTokens.accessToken,
1172
+ refreshToken: v.current.urlTokens.refreshToken,
1173
+ expiresIn: v.current.urlTokens.expiresIn
1174
+ }), console.log("[AuthProvider] SYNC: Session valid:", T.hasValidSession())), T;
1175
+ }, [o, r, n.refreshQueueTimeout, n.proactiveRefreshMargin]), [H, P] = k(() => {
1176
+ if (v.current.urlTokens) return !1;
1177
+ const T = l.getTokens();
1178
+ return T ? l.hasValidSession() || !!T.refreshToken : !1;
1179
+ }), D = v.current.done && !N && !H, C = K(() => {
1180
+ const T = new le(r);
1181
+ return T.setSessionManager(l), T;
1182
+ }, [r, l]), d = K(() => new yt(new le(r)), [r]), U = K(() => new wt(C, l), [C, l]), F = K(() => new ze(new le(r)), [r]), y = K(() => L || l.getUser(), [L, l]), g = K(() => y != null && y.roleId && f.find((T) => T.id === y.roleId) || null, [y, f]), S = K(() => (g == null ? void 0 : g.permissions) || [], [g]), Q = K(() => l.hasValidSession() && L !== null, [l, L]), J = Me(async () => {
1183
+ }), q = K(() => {
1184
+ const T = async ($ = !1) => {
1184
1185
  try {
1185
- if (!l.hasValidSession())
1186
- return;
1187
- const z = Date.now();
1188
- if (!$ && z - A < q && I)
1186
+ if (!l.hasValidSession() || !$ && L)
1189
1187
  return;
1190
- const j = l.getUserId();
1191
- if (!j) {
1188
+ const z = l.getUserId();
1189
+ if (!z) {
1192
1190
  console.warn("[AuthProvider] No userId available in token or storage");
1193
1191
  return;
1194
1192
  }
1195
- R(!0), E(null);
1196
- const J = await b.getUserById(j);
1197
- p(J), l.setUser(J), u(Date.now());
1193
+ I(!0), E(null);
1194
+ const Z = await U.getUserById(z);
1195
+ p(Z), l.setUser(Z);
1198
1196
  } catch (z) {
1199
- const Y = z instanceof Error ? z : new Error("Failed to load user data");
1200
- E(Y), console.error("[AuthProvider] Failed to load user data:", Y);
1197
+ const Z = z instanceof Error ? z : new Error("Failed to load user data");
1198
+ E(Z), console.error("[AuthProvider] Failed to load user data:", Z);
1201
1199
  } finally {
1202
- R(!1);
1200
+ I(!1);
1203
1201
  }
1204
- }, he = async () => {
1205
- await V();
1206
- }, fe = async ($) => {
1207
- var qe;
1208
- const { username: z, password: Y, tenantSlug: j, redirectPath: J } = $;
1209
- let te = i == null ? void 0 : i.id, re = o, ne = l;
1210
- j && (te = (await new ve(C, t).getPublicTenantInfo(j)).id, re = j);
1211
- const K = await S.login({
1202
+ }, V = async () => {
1203
+ await T();
1204
+ }, de = async ($) => {
1205
+ var Be;
1206
+ const { username: z, password: Z, tenantSlug: W, redirectPath: Y } = $;
1207
+ let X = i == null ? void 0 : i.id, ee = o, te = l;
1208
+ W && (X = (await new be(C, t).getPublicTenantInfo(W)).id, ee = W);
1209
+ const G = await d.login({
1212
1210
  username: z,
1213
- password: Y,
1211
+ password: Z,
1214
1212
  appId: t,
1215
- tenantId: te
1216
- }), be = j && j !== o;
1217
- if (be && (ne = new Se({
1218
- tenantSlug: re,
1213
+ tenantId: X
1214
+ }), ye = W && W !== o;
1215
+ if (ye && (te = new we({
1216
+ tenantSlug: ee,
1219
1217
  baseUrl: r
1220
- })), ne.setTokens({
1221
- accessToken: K.accessToken,
1222
- refreshToken: K.refreshToken,
1223
- expiresIn: K.expiresIn
1224
- }), K.user) {
1225
- ne.setUser(K.user), p(K.user);
1218
+ })), te.setTokens({
1219
+ accessToken: G.accessToken,
1220
+ refreshToken: G.refreshToken,
1221
+ expiresIn: G.expiresIn
1222
+ }), G.user) {
1223
+ te.setUser(G.user), p(G.user);
1226
1224
  try {
1227
- await V();
1228
- } catch (xe) {
1229
- console.warn("Failed to load complete user data after login:", xe);
1225
+ await T();
1226
+ } catch (Te) {
1227
+ console.warn("Failed to load complete user data after login:", Te);
1230
1228
  }
1231
1229
  }
1232
- if (K.tenants && K.tenants.length > 0) {
1233
- m(K.tenants);
1230
+ if (G.tenants && G.tenants.length > 0) {
1231
+ h(G.tenants);
1234
1232
  try {
1235
- localStorage.setItem("userTenants", JSON.stringify(K.tenants));
1233
+ localStorage.setItem("userTenants", JSON.stringify(G.tenants));
1236
1234
  } catch {
1237
1235
  }
1238
1236
  }
1239
- const Ie = ((qe = K.user) == null ? void 0 : qe.tenantId) !== null;
1240
- L(Ie);
1241
- const Ee = {
1242
- accessToken: K.accessToken,
1243
- refreshToken: K.refreshToken,
1244
- expiresIn: K.expiresIn
1237
+ const Pe = ((Be = G.user) == null ? void 0 : Be.tenantId) !== null;
1238
+ w(Pe);
1239
+ const Re = {
1240
+ accessToken: G.accessToken,
1241
+ refreshToken: G.refreshToken,
1242
+ expiresIn: G.expiresIn
1245
1243
  };
1246
- if (be && re)
1247
- return a(re, { tokens: Ee, redirectPath: J }), K;
1248
- if (J && J !== window.location.pathname)
1249
- return a(re || o || "", { tokens: Ee, redirectPath: J }), K;
1250
- if (!Ie && K.tenants && K.tenants.length > 0) {
1251
- const xe = $.autoSwitch !== !1 && n.autoSwitchSingleTenant !== !1;
1252
- if (K.tenants.length === 1 && xe) {
1253
- const Oe = K.tenants[0];
1254
- return a(Oe.subdomain, { tokens: Ee, redirectPath: J }), K;
1255
- } else K.tenants.length > 1 && n.onTenantSelectionRequired && n.onTenantSelectionRequired(K.tenants);
1244
+ if (ye && ee)
1245
+ return a(ee, { tokens: Re, redirectPath: Y }), G;
1246
+ if (Y && Y !== window.location.pathname)
1247
+ return a(ee || o || "", { tokens: Re, redirectPath: Y }), G;
1248
+ if (!Pe && G.tenants && G.tenants.length > 0) {
1249
+ const Te = $.autoSwitch !== !1 && n.autoSwitchSingleTenant !== !1;
1250
+ if (G.tenants.length === 1 && Te) {
1251
+ const qe = G.tenants[0];
1252
+ return a(qe.subdomain, { tokens: Re, redirectPath: Y }), G;
1253
+ } else G.tenants.length > 1 && n.onTenantSelectionRequired && n.onTenantSelectionRequired(G.tenants);
1256
1254
  }
1257
- return K;
1258
- }, pe = async ($) => {
1259
- const { email: z, phoneNumber: Y, name: j, password: J, lastName: te, tenantId: re } = $;
1260
- if (!z && !Y)
1255
+ return G;
1256
+ }, he = async ($) => {
1257
+ const { email: z, phoneNumber: Z, name: W, password: Y, lastName: X, tenantId: ee } = $;
1258
+ if (!z && !Z)
1261
1259
  throw new Error("Either email or phoneNumber is required");
1262
- if (!j || !J)
1260
+ if (!W || !Y)
1263
1261
  throw new Error("Name and password are required");
1264
- const ne = re ?? (i == null ? void 0 : i.id);
1265
- return await S.signup({
1262
+ const te = ee ?? (i == null ? void 0 : i.id);
1263
+ return await d.signup({
1266
1264
  email: z,
1267
- phoneNumber: Y,
1268
- name: j,
1269
- password: J,
1270
- tenantId: ne,
1271
- lastName: te,
1265
+ phoneNumber: Z,
1266
+ name: W,
1267
+ password: Y,
1268
+ tenantId: te,
1269
+ lastName: X,
1272
1270
  appId: t
1273
1271
  });
1274
- }, rt = async ($) => {
1275
- const { email: z, phoneNumber: Y, name: j, password: J, tenantName: te, lastName: re } = $;
1276
- if (!z && !Y)
1272
+ }, et = async ($) => {
1273
+ const { email: z, phoneNumber: Z, name: W, password: Y, tenantName: X, lastName: ee } = $;
1274
+ if (!z && !Z)
1277
1275
  throw new Error("Either email or phoneNumber is required");
1278
- if (!j || !J || !te)
1276
+ if (!W || !Y || !X)
1279
1277
  throw new Error("Name, password, and tenantName are required");
1280
- return await S.signupTenantAdmin({
1278
+ return await d.signupTenantAdmin({
1281
1279
  email: z,
1282
- phoneNumber: Y,
1283
- name: j,
1284
- password: J,
1285
- tenantName: te,
1280
+ phoneNumber: Z,
1281
+ name: W,
1282
+ password: Y,
1283
+ tenantName: X,
1286
1284
  appId: t,
1287
- lastName: re
1285
+ lastName: ee
1288
1286
  });
1287
+ }, tt = async ($) => {
1288
+ const { currentPassword: z, newPassword: Z } = $, W = await l.getAuthHeaders();
1289
+ await d.changePassword({ currentPassword: z, newPassword: Z }, W);
1290
+ }, rt = async ($) => {
1291
+ const { email: z, tenantId: Z } = $, W = Z ?? (i == null ? void 0 : i.id);
1292
+ if (!W)
1293
+ throw new Error("tenantId is required for password reset");
1294
+ await d.requestPasswordReset({ email: z, tenantId: W });
1289
1295
  }, nt = async ($) => {
1290
- const { currentPassword: z, newPassword: Y } = $, j = await l.getAuthHeaders();
1291
- await S.changePassword({ currentPassword: z, newPassword: Y }, j);
1296
+ const { token: z, newPassword: Z } = $;
1297
+ await d.confirmPasswordReset({ token: z, newPassword: Z });
1292
1298
  }, st = async ($) => {
1293
- const { email: z, tenantId: Y } = $, j = Y ?? (i == null ? void 0 : i.id);
1294
- if (!j)
1295
- throw new Error("tenantId is required for password reset");
1296
- await S.requestPasswordReset({ email: z, tenantId: j });
1297
- }, it = async ($) => {
1298
- const { token: z, newPassword: Y } = $;
1299
- await S.confirmPasswordReset({ token: z, newPassword: Y });
1300
- }, ot = async ($) => {
1301
- const { email: z, frontendUrl: Y, name: j, lastName: J, tenantId: te } = $, re = te ?? (i == null ? void 0 : i.id);
1302
- if (!re)
1299
+ const { email: z, frontendUrl: Z, name: W, lastName: Y, tenantId: X } = $, ee = X ?? (i == null ? void 0 : i.id);
1300
+ if (!ee)
1303
1301
  throw new Error("tenantId is required for magic link authentication");
1304
- return await S.sendMagicLink({
1302
+ return await d.sendMagicLink({
1305
1303
  email: z,
1306
- tenantId: re,
1307
- frontendUrl: Y,
1308
- name: j,
1309
- lastName: J,
1304
+ tenantId: ee,
1305
+ frontendUrl: Z,
1306
+ name: W,
1307
+ lastName: Y,
1310
1308
  appId: t
1311
1309
  });
1312
- }, at = async ($) => {
1313
- const { token: z, email: Y, tenantSlug: j } = $;
1314
- let J = i == null ? void 0 : i.id, te = o, re = l;
1315
- j && (J = (await new ve(C, t).getPublicTenantInfo(j)).id, te = j);
1316
- const ne = await S.verifyMagicLink({
1310
+ }, it = async ($) => {
1311
+ const { token: z, email: Z, tenantSlug: W } = $;
1312
+ let Y = i == null ? void 0 : i.id, X = o, ee = l;
1313
+ W && (Y = (await new be(C, t).getPublicTenantInfo(W)).id, X = W);
1314
+ const te = await d.verifyMagicLink({
1317
1315
  token: z,
1318
- email: Y,
1316
+ email: Z,
1319
1317
  appId: t,
1320
- tenantId: J
1321
- }), K = j && j !== o;
1322
- if (K && (re = new Se({
1323
- tenantSlug: te,
1318
+ tenantId: Y
1319
+ }), G = W && W !== o;
1320
+ if (G && (ee = new we({
1321
+ tenantSlug: X,
1324
1322
  baseUrl: r
1325
- })), re.setTokens({
1326
- accessToken: ne.accessToken,
1327
- refreshToken: ne.refreshToken,
1328
- expiresIn: ne.expiresIn
1329
- }), ne.user) {
1330
- re.setUser(ne.user), p(ne.user);
1323
+ })), ee.setTokens({
1324
+ accessToken: te.accessToken,
1325
+ refreshToken: te.refreshToken,
1326
+ expiresIn: te.expiresIn
1327
+ }), te.user) {
1328
+ ee.setUser(te.user), p(te.user);
1331
1329
  try {
1332
- await V();
1333
- } catch (be) {
1334
- console.warn("Failed to load complete user data after magic link login:", be);
1330
+ await T();
1331
+ } catch (ye) {
1332
+ console.warn("Failed to load complete user data after magic link login:", ye);
1335
1333
  }
1336
1334
  }
1337
- return K && te && te !== o && a(te, {
1335
+ return G && X && X !== o && a(X, {
1338
1336
  tokens: {
1339
- accessToken: ne.accessToken,
1340
- refreshToken: ne.refreshToken,
1341
- expiresIn: ne.expiresIn
1337
+ accessToken: te.accessToken,
1338
+ refreshToken: te.refreshToken,
1339
+ expiresIn: te.expiresIn
1342
1340
  }
1343
- }), ne;
1344
- }, lt = async () => {
1341
+ }), te;
1342
+ }, ot = async () => {
1345
1343
  const $ = l.getTokens();
1346
1344
  if (!($ != null && $.refreshToken))
1347
1345
  throw new Error("No refresh token available");
1348
- const z = await S.refreshToken({
1346
+ const z = await d.refreshToken({
1349
1347
  refreshToken: $.refreshToken
1350
1348
  });
1351
1349
  l.setTokens({
@@ -1353,101 +1351,101 @@ function Tr({ config: n = {}, children: e }) {
1353
1351
  refreshToken: z.refreshToken || $.refreshToken,
1354
1352
  expiresIn: z.expiresIn
1355
1353
  });
1356
- }, ct = () => {
1357
- l.clearSession(), p(null), E(null), m([]), L(!1);
1354
+ }, at = () => {
1355
+ l.clearSession(), p(null), E(null), h([]), w(!1);
1358
1356
  try {
1359
1357
  localStorage.removeItem("userTenants");
1360
1358
  } catch {
1361
1359
  }
1362
- }, dt = ($) => {
1360
+ }, lt = ($) => {
1363
1361
  l.setTokens($);
1364
- }, ut = () => l.hasValidSession(), ht = () => {
1362
+ }, ct = () => l.hasValidSession(), dt = () => {
1365
1363
  l.clearSession(), p(null), E(null);
1366
- }, ft = async () => {
1364
+ }, ut = async () => {
1367
1365
  if (t)
1368
1366
  try {
1369
1367
  c(!0);
1370
- const { roles: $ } = await y.getRolesByApp(t);
1371
- g($);
1368
+ const { roles: $ } = await F.getRolesByApp(t);
1369
+ m($);
1372
1370
  } catch ($) {
1373
1371
  console.error("Failed to fetch roles:", $);
1374
1372
  } finally {
1375
1373
  c(!1);
1376
1374
  }
1377
- }, pt = async () => {
1378
- await ft();
1379
- }, Re = ($) => {
1380
- if (!Q || Q.length === 0)
1375
+ }, ht = async () => {
1376
+ await ut();
1377
+ }, Ae = ($) => {
1378
+ if (!S || S.length === 0)
1381
1379
  return !1;
1382
1380
  if (typeof $ == "string")
1383
- return Q.includes($);
1381
+ return S.includes($);
1384
1382
  const z = `${$.resource}.${$.action}`;
1385
- return Q.includes(z);
1383
+ return S.includes(z);
1386
1384
  };
1387
1385
  return {
1388
1386
  // RFC-003: Authentication state
1389
- isAuthenticated: O,
1387
+ isAuthenticated: Q,
1390
1388
  sessionManager: l,
1391
1389
  authenticatedHttpService: C,
1392
- login: fe,
1393
- signup: pe,
1394
- signupTenantAdmin: rt,
1395
- sendMagicLink: ot,
1396
- verifyMagicLink: at,
1397
- changePassword: nt,
1398
- requestPasswordReset: st,
1399
- confirmPasswordReset: it,
1400
- refreshToken: lt,
1401
- logout: ct,
1402
- setTokens: dt,
1403
- hasValidSession: ut,
1404
- clearSession: ht,
1405
- currentUser: I,
1406
- isUserLoading: x,
1407
- userError: F,
1408
- loadUserData: V,
1409
- refreshUser: he,
1410
- isAuthInitializing: !f,
1411
- isAuthReady: f,
1412
- userRole: G,
1413
- userPermissions: Q,
1414
- availableRoles: h,
1415
- rolesLoading: w,
1416
- hasPermission: Re,
1417
- hasAnyPermission: ($) => $.some((z) => Re(z)),
1418
- hasAllPermissions: ($) => $.every((z) => Re(z)),
1419
- getUserPermissionStrings: () => Q || [],
1420
- refreshRoles: pt,
1390
+ login: de,
1391
+ signup: he,
1392
+ signupTenantAdmin: et,
1393
+ sendMagicLink: st,
1394
+ verifyMagicLink: it,
1395
+ changePassword: tt,
1396
+ requestPasswordReset: rt,
1397
+ confirmPasswordReset: nt,
1398
+ refreshToken: ot,
1399
+ logout: at,
1400
+ setTokens: lt,
1401
+ hasValidSession: ct,
1402
+ clearSession: dt,
1403
+ currentUser: L,
1404
+ isUserLoading: R,
1405
+ userError: M,
1406
+ loadUserData: T,
1407
+ refreshUser: V,
1408
+ isAuthInitializing: !D,
1409
+ isAuthReady: D,
1410
+ userRole: g,
1411
+ userPermissions: S,
1412
+ availableRoles: f,
1413
+ rolesLoading: b,
1414
+ hasPermission: Ae,
1415
+ hasAnyPermission: ($) => $.some((z) => Ae(z)),
1416
+ hasAllPermissions: ($) => $.every((z) => Ae(z)),
1417
+ getUserPermissionStrings: () => S || [],
1418
+ refreshRoles: ht,
1421
1419
  // RFC-004: Multi-tenant user membership
1422
- userTenants: k,
1423
- hasTenantContext: M,
1420
+ userTenants: x,
1421
+ hasTenantContext: A,
1424
1422
  switchToTenant: async ($, z) => {
1425
- const { redirectPath: Y } = z || {}, j = l.getTokens();
1426
- if (!(j != null && j.refreshToken))
1423
+ const { redirectPath: Z } = z || {}, W = l.getTokens();
1424
+ if (!(W != null && W.refreshToken))
1427
1425
  throw new Error("No refresh token available for tenant switch");
1428
- const J = await S.switchTenant({
1429
- refreshToken: j.refreshToken,
1426
+ const Y = await d.switchTenant({
1427
+ refreshToken: W.refreshToken,
1430
1428
  tenantId: $
1431
1429
  });
1432
1430
  l.setTokens({
1433
- accessToken: J.accessToken,
1434
- refreshToken: j.refreshToken,
1431
+ accessToken: Y.accessToken,
1432
+ refreshToken: W.refreshToken,
1435
1433
  // Keep the same refresh token
1436
- expiresIn: J.expiresIn
1437
- }), p(J.user), l.setUser(J.user), L(!0);
1438
- const te = k.find((re) => re.id === $);
1439
- te && a(te.subdomain, {
1434
+ expiresIn: Y.expiresIn
1435
+ }), p(Y.user), l.setUser(Y.user), w(!0);
1436
+ const X = x.find((ee) => ee.id === $);
1437
+ X && a(X.subdomain, {
1440
1438
  tokens: {
1441
- accessToken: J.accessToken,
1442
- refreshToken: j.refreshToken,
1443
- expiresIn: J.expiresIn
1439
+ accessToken: Y.accessToken,
1440
+ refreshToken: W.refreshToken,
1441
+ expiresIn: Y.expiresIn
1444
1442
  },
1445
- redirectPath: Y
1443
+ redirectPath: Z
1446
1444
  });
1447
1445
  },
1448
1446
  refreshUserTenants: async () => {
1449
- const $ = await l.getAuthHeaders(), z = await S.getUserTenants($);
1450
- m(z);
1447
+ const $ = await l.getAuthHeaders(), z = await d.getUserTenants($);
1448
+ h(z);
1451
1449
  try {
1452
1450
  localStorage.setItem("userTenants", JSON.stringify(z));
1453
1451
  } catch {
@@ -1456,83 +1454,73 @@ function Tr({ config: n = {}, children: e }) {
1456
1454
  }
1457
1455
  };
1458
1456
  }, [
1459
- O,
1457
+ Q,
1460
1458
  l,
1461
1459
  C,
1462
- S,
1463
- b,
1464
- y,
1460
+ d,
1461
+ U,
1462
+ F,
1465
1463
  t,
1466
1464
  i,
1467
1465
  o,
1468
1466
  a,
1469
- h,
1470
- I,
1471
- x,
1472
- F,
1473
- k,
1474
- M,
1475
1467
  f,
1476
- G,
1477
- Q,
1468
+ L,
1469
+ R,
1470
+ M,
1471
+ x,
1478
1472
  A,
1479
- q
1473
+ D,
1474
+ g,
1475
+ S
1480
1476
  ]);
1481
- ee(() => {
1477
+ J.current = q.loadUserData, re(() => {
1482
1478
  !n.initialRoles && t && (async () => {
1483
1479
  try {
1484
1480
  c(!0);
1485
- const he = new ce(r), fe = new _e(he), { roles: pe } = await fe.getRolesByApp(t);
1486
- g(pe);
1487
- } catch (he) {
1488
- console.error("Failed to fetch roles:", he);
1481
+ const V = new le(r), de = new ze(V), { roles: he } = await de.getRolesByApp(t);
1482
+ m(he);
1483
+ } catch (V) {
1484
+ console.error("Failed to fetch roles:", V);
1489
1485
  } finally {
1490
1486
  c(!1);
1491
1487
  }
1492
1488
  })();
1493
1489
  }, [t, r, n.initialRoles]);
1494
- const [B, X] = T(!1);
1495
- return ee(() => {
1496
- B || (X(!0), D.current.urlTokens && (console.log("[AuthProvider] EFFECT: Cleaning up URL after sync token processing"), Rt(), U(!0), console.log("[AuthProvider] EFFECT: Loading user data (blocking isAuthReady)..."), W.loadUserData().catch((V) => {
1497
- console.error("[AuthProvider] Failed to load user data:", V);
1490
+ const [O, j] = k(!1);
1491
+ return re(() => {
1492
+ O || (j(!0), v.current.urlTokens && (console.log("[AuthProvider] EFFECT: Cleaning up URL after sync token processing"), At(), B(!0), console.log("[AuthProvider] EFFECT: Loading user data (blocking isAuthReady)..."), q.loadUserData().catch((T) => {
1493
+ console.error("[AuthProvider] Failed to load user data:", T);
1498
1494
  }).finally(() => {
1499
- console.log("[AuthProvider] EFFECT: User data loaded, releasing isAuthReady"), U(!1);
1495
+ console.log("[AuthProvider] EFFECT: User data loaded, releasing isAuthReady"), B(!1);
1500
1496
  })));
1501
- }, [W, B]), ee(() => {
1502
- let V = !1;
1497
+ }, [q, O]), re(() => {
1498
+ let T = !1;
1503
1499
  return (async () => {
1504
- var pe;
1505
- if (!l.hasValidSession() && ((pe = l.getTokens()) != null && pe.refreshToken) && await l.waitForPendingRefresh(), V) return;
1506
- const fe = l.getUser();
1507
- fe && l.hasValidSession() && p(fe), H(!1);
1500
+ var he;
1501
+ if (!l.hasValidSession() && ((he = l.getTokens()) != null && he.refreshToken) && await l.waitForPendingRefresh(), T) return;
1502
+ const de = l.getUser();
1503
+ de && l.hasValidSession() && p(de), P(!1);
1508
1504
  })(), () => {
1509
- V = !0;
1505
+ T = !0;
1510
1506
  };
1511
- }, [l]), ee(() => {
1512
- B && (D.current.urlTokens || (!I && !x && l.hasValidSession() ? (console.log("[AuthProvider] Auto-loading user data..."), W.loadUserData().catch(() => {
1507
+ }, [l]), re(() => {
1508
+ O && (v.current.urlTokens || (!L && !R && !M && l.hasValidSession() ? (console.log("[AuthProvider] Auto-loading user data..."), J.current().catch(() => {
1513
1509
  }).finally(() => {
1514
- H(!1);
1515
- })) : I && H(!1)));
1516
- }, [I, x, W, l, B]), ee(() => {
1517
- if (!l.hasValidSession() || !I)
1518
- return;
1519
- const V = setInterval(() => {
1520
- W.loadUserData().catch(() => {
1521
- });
1522
- }, q);
1523
- return () => clearInterval(V);
1524
- }, [l, I, W, q]), /* @__PURE__ */ s(Ne.Provider, { value: W, children: e });
1510
+ P(!1);
1511
+ })) : P(!1)));
1512
+ }, [L, R, M, l, O]), /* @__PURE__ */ s(Ne.Provider, { value: q, children: e });
1525
1513
  }
1526
1514
  function ue() {
1527
- const n = le(Ne);
1515
+ const n = ae(Ne);
1528
1516
  if (!n)
1529
1517
  throw new Error("useAuth must be used within an AuthProvider");
1530
1518
  return n;
1531
1519
  }
1532
- function Ce() {
1533
- return le(Ne);
1520
+ function De() {
1521
+ return ae(Ne);
1534
1522
  }
1535
- class It {
1523
+ class Pt {
1536
1524
  constructor(e, t) {
1537
1525
  this.httpService = e, this.sessionManager = t;
1538
1526
  }
@@ -1612,66 +1600,66 @@ class It {
1612
1600
  })).data;
1613
1601
  }
1614
1602
  }
1615
- const Ue = me(null);
1616
- function kr({ config: n = {}, children: e }) {
1617
- const t = Ze(), r = Pe(), i = (t == null ? void 0 : t.baseUrl) ?? "", o = (t == null ? void 0 : t.appId) ?? "", a = (r == null ? void 0 : r.tenant) ?? null, [h, g] = T([]), [w, c] = T(!1), [I, p] = T(null), [x, R] = T(!1), F = Z(() => {
1618
- const u = new ce(i);
1619
- return new It(u);
1603
+ const Ce = pe(null);
1604
+ function vr({ config: n = {}, children: e }) {
1605
+ const t = Qe(), r = xe(), i = (t == null ? void 0 : t.baseUrl) ?? "", o = (t == null ? void 0 : t.appId) ?? "", a = (r == null ? void 0 : r.tenant) ?? null, [f, m] = k([]), [b, c] = k(!1), [L, p] = k(null), [R, I] = k(!1), M = K(() => {
1606
+ const h = new le(i);
1607
+ return new Pt(h);
1620
1608
  }, [i]), E = async () => {
1621
1609
  if (!(a != null && a.id)) {
1622
- g([]);
1610
+ m([]);
1623
1611
  return;
1624
1612
  }
1625
1613
  c(!0), p(null);
1626
1614
  try {
1627
- const u = await F.getTenantFeatureFlags(a.id, o);
1628
- g(u);
1629
- } catch (u) {
1630
- const k = u instanceof Error ? u.message : "Failed to fetch feature flags";
1631
- p(k), n.onError && n.onError(u instanceof Error ? u : new Error(k));
1615
+ const h = await M.getTenantFeatureFlags(a.id, o);
1616
+ m(h);
1617
+ } catch (h) {
1618
+ const A = h instanceof Error ? h.message : "Failed to fetch feature flags";
1619
+ p(A), n.onError && n.onError(h instanceof Error ? h : new Error(A));
1632
1620
  } finally {
1633
1621
  c(!1);
1634
1622
  }
1635
1623
  };
1636
- ee(() => {
1624
+ re(() => {
1637
1625
  if (!i || !o) return;
1638
- E().finally(() => R(!0));
1639
- const u = n.refreshInterval || 5 * 60 * 1e3, k = setInterval(E, u);
1640
- return () => clearInterval(k);
1626
+ E().finally(() => I(!0));
1627
+ const h = n.refreshInterval || 5 * 60 * 1e3, A = setInterval(E, h);
1628
+ return () => clearInterval(A);
1641
1629
  }, [a == null ? void 0 : a.id, i, o, n.refreshInterval]);
1642
- const A = Z(() => {
1643
- const u = (D) => {
1644
- const P = h.find((U) => U.key === D);
1645
- return (P == null ? void 0 : P.value) === !0;
1646
- }, k = (D) => h.find((P) => P.key === D), m = (D) => {
1647
- const P = h.find((U) => U.key === D);
1648
- return P ? P.value ? "enabled" : "disabled" : "not_found";
1649
- }, M = async () => {
1630
+ const x = K(() => {
1631
+ const h = (B) => {
1632
+ const l = f.find((H) => H.key === B);
1633
+ return (l == null ? void 0 : l.value) === !0;
1634
+ }, A = (B) => f.find((l) => l.key === B), w = (B) => {
1635
+ const l = f.find((H) => H.key === B);
1636
+ return l ? l.value ? "enabled" : "disabled" : "not_found";
1637
+ }, v = async () => {
1650
1638
  await E();
1651
- }, L = !!(i && o) && (x || !(a != null && a.id));
1639
+ }, N = !!(i && o) && (R || !(a != null && a.id));
1652
1640
  return {
1653
- featureFlags: h,
1654
- loading: w,
1655
- error: I,
1656
- isReady: L,
1657
- isEnabled: u,
1658
- getFlag: k,
1659
- getFlagState: m,
1660
- refresh: M
1641
+ featureFlags: f,
1642
+ loading: b,
1643
+ error: L,
1644
+ isReady: N,
1645
+ isEnabled: h,
1646
+ getFlag: A,
1647
+ getFlagState: w,
1648
+ refresh: v
1661
1649
  };
1662
- }, [h, w, I, i, o, a == null ? void 0 : a.id, x]);
1663
- return /* @__PURE__ */ s(Ue.Provider, { value: A, children: e });
1650
+ }, [f, b, L, i, o, a == null ? void 0 : a.id, R]);
1651
+ return /* @__PURE__ */ s(Ce.Provider, { value: x, children: e });
1664
1652
  }
1665
- function Et() {
1666
- const n = le(Ue);
1653
+ function Rt() {
1654
+ const n = ae(Ce);
1667
1655
  if (!n)
1668
1656
  throw new Error("useFeatureFlags must be used within a FeatureFlagProvider");
1669
1657
  return n;
1670
1658
  }
1671
- function Je() {
1672
- return le(Ue);
1659
+ function Ke() {
1660
+ return ae(Ce);
1673
1661
  }
1674
- class Mt {
1662
+ class It {
1675
1663
  constructor(e, t) {
1676
1664
  this.httpService = e, this.sessionManager = t;
1677
1665
  }
@@ -1737,68 +1725,68 @@ class Mt {
1737
1725
  )).data;
1738
1726
  }
1739
1727
  }
1740
- const $e = me(void 0);
1741
- function xr({ config: n = {}, children: e }) {
1742
- const t = Ze(), r = Pe(), i = (t == null ? void 0 : t.baseUrl) ?? "", o = (r == null ? void 0 : r.tenant) ?? null, [a, h] = T(null), [g, w] = T(!1), [c, I] = T(null), [p, x] = T(!1), R = Z(() => {
1743
- const A = new ce(i);
1744
- return new Mt(A);
1745
- }, [i]), F = async () => {
1728
+ const Ue = pe(void 0);
1729
+ function Tr({ config: n = {}, children: e }) {
1730
+ const t = Qe(), r = xe(), i = (t == null ? void 0 : t.baseUrl) ?? "", o = (r == null ? void 0 : r.tenant) ?? null, [a, f] = k(null), [m, b] = k(!1), [c, L] = k(null), [p, R] = k(!1), I = K(() => {
1731
+ const x = new le(i);
1732
+ return new It(x);
1733
+ }, [i]), M = async () => {
1746
1734
  if (!(o != null && o.id)) {
1747
- h(null);
1735
+ f(null);
1748
1736
  return;
1749
1737
  }
1750
- w(!0), I(null);
1738
+ b(!0), L(null);
1751
1739
  try {
1752
- const A = await R.getTenantSubscriptionFeatures(o.id);
1753
- h(A);
1754
- } catch (A) {
1755
- const u = A instanceof Error ? A.message : "Failed to fetch subscription";
1756
- I(u), n.onError && n.onError(A instanceof Error ? A : new Error(u));
1740
+ const x = await I.getTenantSubscriptionFeatures(o.id);
1741
+ f(x);
1742
+ } catch (x) {
1743
+ const h = x instanceof Error ? x.message : "Failed to fetch subscription";
1744
+ L(h), n.onError && n.onError(x instanceof Error ? x : new Error(h));
1757
1745
  } finally {
1758
- w(!1);
1746
+ b(!1);
1759
1747
  }
1760
1748
  };
1761
- ee(() => {
1762
- if (!i || (F().finally(() => x(!0)), !n.refreshInterval)) return;
1763
- const A = n.refreshInterval || 10 * 60 * 1e3, u = setInterval(F, A);
1764
- return () => clearInterval(u);
1749
+ re(() => {
1750
+ if (!i || (M().finally(() => R(!0)), !n.refreshInterval)) return;
1751
+ const x = n.refreshInterval || 10 * 60 * 1e3, h = setInterval(M, x);
1752
+ return () => clearInterval(h);
1765
1753
  }, [o == null ? void 0 : o.id, i, n.refreshInterval]);
1766
- const E = Z(() => {
1767
- const A = (a == null ? void 0 : a.features) || [], u = (P) => {
1768
- const U = A.find((l) => l.key === P);
1769
- return U ? U.type === "BOOLEAN" || U.type === "boolean" ? U.value === !0 : !!U.value : !1;
1770
- }, k = (P) => A.find((U) => U.key === P), m = (P, U) => {
1771
- const l = A.find((N) => N.key === P);
1772
- return l ? l.value : U;
1773
- }, M = (P) => !a || !a.isActive ? !1 : P.includes(a.planId), L = async () => {
1774
- await F();
1775
- }, D = !!i && (p || !(o != null && o.id));
1754
+ const E = K(() => {
1755
+ const x = (a == null ? void 0 : a.features) || [], h = (l) => {
1756
+ const H = x.find((P) => P.key === l);
1757
+ return H ? H.type === "BOOLEAN" || H.type === "boolean" ? H.value === !0 : !!H.value : !1;
1758
+ }, A = (l) => x.find((H) => H.key === l), w = (l, H) => {
1759
+ const P = x.find((D) => D.key === l);
1760
+ return P ? P.value : H;
1761
+ }, v = (l) => !a || !a.isActive ? !1 : l.includes(a.planId), N = async () => {
1762
+ await M();
1763
+ }, B = !!i && (p || !(o != null && o.id));
1776
1764
  return {
1777
1765
  subscription: a,
1778
- features: A,
1779
- loading: g,
1766
+ features: x,
1767
+ loading: m,
1780
1768
  error: c,
1781
- isReady: D,
1782
- isFeatureEnabled: u,
1783
- getFeature: k,
1784
- getFeatureValue: m,
1785
- hasAllowedPlan: M,
1786
- refresh: L
1769
+ isReady: B,
1770
+ isFeatureEnabled: h,
1771
+ getFeature: A,
1772
+ getFeatureValue: w,
1773
+ hasAllowedPlan: v,
1774
+ refresh: N
1787
1775
  };
1788
- }, [a, g, c, i, o == null ? void 0 : o.id, p]);
1789
- return /* @__PURE__ */ s($e.Provider, { value: E, children: e });
1776
+ }, [a, m, c, i, o == null ? void 0 : o.id, p]);
1777
+ return /* @__PURE__ */ s(Ue.Provider, { value: E, children: e });
1790
1778
  }
1791
- function Lt() {
1792
- const n = le($e);
1779
+ function Et() {
1780
+ const n = ae(Ue);
1793
1781
  if (n === void 0)
1794
1782
  throw new Error("useSubscription must be used within a SubscriptionProvider");
1795
1783
  return n;
1796
1784
  }
1797
- function Ye() {
1798
- return le($e) ?? null;
1785
+ function Ze() {
1786
+ return ae(Ue) ?? null;
1799
1787
  }
1800
- var ae = /* @__PURE__ */ ((n) => (n.SUPERUSER = "SUPERUSER", n.TENANT_ADMIN = "TENANT_ADMIN", n.USER = "USER", n))(ae || {});
1801
- const He = {
1788
+ var oe = /* @__PURE__ */ ((n) => (n.SUPERUSER = "SUPERUSER", n.TENANT_ADMIN = "TENANT_ADMIN", n.USER = "USER", n))(oe || {});
1789
+ const $e = {
1802
1790
  publicGuest: "/",
1803
1791
  publicUser: "/account",
1804
1792
  publicAdmin: "/admin",
@@ -1806,7 +1794,7 @@ const He = {
1806
1794
  tenantUser: "/dashboard",
1807
1795
  tenantAdmin: "/admin/dashboard",
1808
1796
  default: "/"
1809
- }, Xe = {
1797
+ }, Je = {
1810
1798
  // Public/Landing zones
1811
1799
  landing: { tenant: "forbidden", auth: "optional" },
1812
1800
  publicOnly: { tenant: "forbidden", auth: "forbidden" },
@@ -1819,18 +1807,18 @@ const He = {
1819
1807
  tenantOpen: { tenant: "required", auth: "optional" },
1820
1808
  tenantAuth: { tenant: "required", auth: "required" },
1821
1809
  // User type zones
1822
- user: { tenant: "required", auth: "required", userType: ae.USER },
1823
- admin: { tenant: "required", auth: "required", userType: ae.TENANT_ADMIN },
1810
+ user: { tenant: "required", auth: "required", userType: oe.USER },
1811
+ admin: { tenant: "required", auth: "required", userType: oe.TENANT_ADMIN },
1824
1812
  // Fully open
1825
1813
  open: { tenant: "optional", auth: "optional" }
1826
- }, Be = me(null);
1827
- function Ar({ config: n = {}, children: e }) {
1828
- const t = Z(() => {
1814
+ }, He = pe(null);
1815
+ function kr({ config: n = {}, children: e }) {
1816
+ const t = K(() => {
1829
1817
  const r = {
1830
- ...He,
1818
+ ...$e,
1831
1819
  ...n.zoneRoots
1832
1820
  }, i = {
1833
- ...Xe,
1821
+ ...Je,
1834
1822
  ...n.presets
1835
1823
  };
1836
1824
  return {
@@ -1843,19 +1831,19 @@ function Ar({ config: n = {}, children: e }) {
1843
1831
  returnToStorage: n.returnToStorage ?? "url"
1844
1832
  };
1845
1833
  }, [n]);
1846
- return /* @__PURE__ */ s(Be.Provider, { value: t, children: e });
1834
+ return /* @__PURE__ */ s(He.Provider, { value: t, children: e });
1847
1835
  }
1848
- function Pr() {
1849
- const n = le(Be);
1836
+ function xr() {
1837
+ const n = ae(He);
1850
1838
  if (!n)
1851
1839
  throw new Error("useRouting must be used within a RoutingProvider");
1852
1840
  return n;
1853
1841
  }
1854
- function Ft() {
1855
- const n = le(Be);
1842
+ function Mt() {
1843
+ const n = ae(He);
1856
1844
  return n || {
1857
- zoneRoots: He,
1858
- presets: Xe,
1845
+ zoneRoots: $e,
1846
+ presets: Je,
1859
1847
  loadingFallback: null,
1860
1848
  accessDeniedFallback: null,
1861
1849
  onAccessDenied: void 0,
@@ -1863,7 +1851,7 @@ function Ft() {
1863
1851
  returnToStorage: "url"
1864
1852
  };
1865
1853
  }
1866
- const Ve = () => /* @__PURE__ */ d(
1854
+ const We = () => /* @__PURE__ */ u(
1867
1855
  "div",
1868
1856
  {
1869
1857
  style: {
@@ -1900,11 +1888,11 @@ const Ve = () => /* @__PURE__ */ d(
1900
1888
  )
1901
1889
  ]
1902
1890
  }
1903
- ), je = ({
1891
+ ), Ve = ({
1904
1892
  userType: n,
1905
1893
  minUserType: e,
1906
1894
  missingPermissions: t
1907
- }) => /* @__PURE__ */ d(
1895
+ }) => /* @__PURE__ */ u(
1908
1896
  "div",
1909
1897
  {
1910
1898
  style: {
@@ -1922,55 +1910,55 @@ const Ve = () => /* @__PURE__ */ d(
1922
1910
  children: [
1923
1911
  /* @__PURE__ */ s("div", { style: { fontSize: "2rem", marginBottom: "10px" }, children: "⚠️" }),
1924
1912
  /* @__PURE__ */ s("h3", { style: { color: "#856404", marginBottom: "10px" }, children: "Insufficient Permissions" }),
1925
- e && n ? /* @__PURE__ */ d(_, { children: [
1926
- /* @__PURE__ */ d("p", { style: { color: "#856404", fontSize: "14px", marginBottom: "10px" }, children: [
1913
+ e && n ? /* @__PURE__ */ u(_, { children: [
1914
+ /* @__PURE__ */ u("p", { style: { color: "#856404", fontSize: "14px", marginBottom: "10px" }, children: [
1927
1915
  "This content requires ",
1928
1916
  /* @__PURE__ */ s("strong", { children: e }),
1929
1917
  " access level or higher."
1930
1918
  ] }),
1931
- /* @__PURE__ */ d("p", { style: { color: "#6c757d", fontSize: "12px" }, children: [
1919
+ /* @__PURE__ */ u("p", { style: { color: "#6c757d", fontSize: "12px" }, children: [
1932
1920
  "Your current access level: ",
1933
1921
  /* @__PURE__ */ s("strong", { children: n })
1934
1922
  ] })
1935
- ] }) : /* @__PURE__ */ d(_, { children: [
1923
+ ] }) : /* @__PURE__ */ u(_, { children: [
1936
1924
  /* @__PURE__ */ s("p", { style: { color: "#856404", fontSize: "14px", marginBottom: "10px" }, children: "You don't have the required permissions to view this content." }),
1937
- t && t.length > 0 && /* @__PURE__ */ d("p", { style: { color: "#6c757d", fontSize: "12px" }, children: [
1925
+ t && t.length > 0 && /* @__PURE__ */ u("p", { style: { color: "#6c757d", fontSize: "12px" }, children: [
1938
1926
  "Required permissions: ",
1939
1927
  /* @__PURE__ */ s("strong", { children: t.join(", ") })
1940
1928
  ] })
1941
1929
  ] })
1942
1930
  ]
1943
1931
  }
1944
- ), Dt = (n, e) => {
1932
+ ), Lt = (n, e) => {
1945
1933
  const t = {
1946
- [ae.USER]: 1,
1947
- [ae.TENANT_ADMIN]: 2,
1948
- [ae.SUPERUSER]: 3
1934
+ [oe.USER]: 1,
1935
+ [oe.TENANT_ADMIN]: 2,
1936
+ [oe.SUPERUSER]: 3
1949
1937
  };
1950
1938
  return t[n] >= t[e];
1951
1939
  };
1952
- function Rr({
1940
+ function Ar({
1953
1941
  children: n,
1954
1942
  fallback: e,
1955
1943
  minUserType: t,
1956
1944
  requiredPermissions: r,
1957
1945
  requireAllPermissions: i = !1
1958
1946
  }) {
1959
- const { hasValidSession: o, sessionManager: a, hasPermission: h, hasAnyPermission: g, hasAllPermissions: w } = ue();
1947
+ const { hasValidSession: o, sessionManager: a, hasPermission: f, hasAnyPermission: m, hasAllPermissions: b } = ue();
1960
1948
  if (!o())
1961
- return /* @__PURE__ */ s(_, { children: e || /* @__PURE__ */ s(Ve, {}) });
1949
+ return /* @__PURE__ */ s(_, { children: e || /* @__PURE__ */ s(We, {}) });
1962
1950
  const c = a.getUser();
1963
1951
  if (!c)
1964
- return /* @__PURE__ */ s(_, { children: e || /* @__PURE__ */ s(Ve, {}) });
1965
- if (t && !Dt(c.userType, t))
1966
- return /* @__PURE__ */ s(je, { userType: c.userType, minUserType: t });
1967
- if (r && r.length > 0 && !(i ? w(r) : g(r))) {
1968
- const p = r.filter((x) => !h(x)).map((x) => typeof x == "string" ? x : x.name);
1969
- return /* @__PURE__ */ s(je, { missingPermissions: p });
1952
+ return /* @__PURE__ */ s(_, { children: e || /* @__PURE__ */ s(We, {}) });
1953
+ if (t && !Lt(c.userType, t))
1954
+ return /* @__PURE__ */ s(Ve, { userType: c.userType, minUserType: t });
1955
+ if (r && r.length > 0 && !(i ? b(r) : m(r))) {
1956
+ const p = r.filter((R) => !f(R)).map((R) => typeof R == "string" ? R : R.name);
1957
+ return /* @__PURE__ */ s(Ve, { missingPermissions: p });
1970
1958
  }
1971
1959
  return /* @__PURE__ */ s(_, { children: n });
1972
1960
  }
1973
- const Nt = ({ redirectPath: n }) => /* @__PURE__ */ s(
1961
+ const Ft = ({ redirectPath: n }) => /* @__PURE__ */ s(
1974
1962
  "div",
1975
1963
  {
1976
1964
  style: {
@@ -1983,7 +1971,7 @@ const Nt = ({ redirectPath: n }) => /* @__PURE__ */ s(
1983
1971
  backgroundColor: "#f9fafb",
1984
1972
  textAlign: "center"
1985
1973
  },
1986
- children: /* @__PURE__ */ d(
1974
+ children: /* @__PURE__ */ u(
1987
1975
  "div",
1988
1976
  {
1989
1977
  style: {
@@ -1997,7 +1985,7 @@ const Nt = ({ redirectPath: n }) => /* @__PURE__ */ s(
1997
1985
  /* @__PURE__ */ s("div", { style: { fontSize: "3rem", marginBottom: "1rem" }, children: "🔒" }),
1998
1986
  /* @__PURE__ */ s("h2", { style: { color: "#374151", marginBottom: "1rem" }, children: "Access Required" }),
1999
1987
  /* @__PURE__ */ s("p", { style: { color: "#6b7280", marginBottom: "1.5rem" }, children: "You need to be signed in to access this page." }),
2000
- /* @__PURE__ */ d("p", { style: { fontSize: "0.875rem", color: "#9ca3af" }, children: [
1988
+ /* @__PURE__ */ u("p", { style: { fontSize: "0.875rem", color: "#9ca3af" }, children: [
2001
1989
  "Redirecting to ",
2002
1990
  n,
2003
1991
  "..."
@@ -2006,7 +1994,7 @@ const Nt = ({ redirectPath: n }) => /* @__PURE__ */ s(
2006
1994
  }
2007
1995
  )
2008
1996
  }
2009
- ), Ge = ({
1997
+ ), je = ({
2010
1998
  userType: n,
2011
1999
  requiredUserType: e,
2012
2000
  missingPermissions: t
@@ -2023,7 +2011,7 @@ const Nt = ({ redirectPath: n }) => /* @__PURE__ */ s(
2023
2011
  backgroundColor: "#f9fafb",
2024
2012
  textAlign: "center"
2025
2013
  },
2026
- children: /* @__PURE__ */ d(
2014
+ children: /* @__PURE__ */ u(
2027
2015
  "div",
2028
2016
  {
2029
2017
  style: {
@@ -2036,19 +2024,19 @@ const Nt = ({ redirectPath: n }) => /* @__PURE__ */ s(
2036
2024
  children: [
2037
2025
  /* @__PURE__ */ s("div", { style: { fontSize: "3rem", marginBottom: "1rem" }, children: "⚠️" }),
2038
2026
  /* @__PURE__ */ s("h2", { style: { color: "#374151", marginBottom: "1rem" }, children: "Insufficient Permissions" }),
2039
- e && n ? /* @__PURE__ */ d(_, { children: [
2040
- /* @__PURE__ */ d("p", { style: { color: "#6b7280", marginBottom: "1rem" }, children: [
2027
+ e && n ? /* @__PURE__ */ u(_, { children: [
2028
+ /* @__PURE__ */ u("p", { style: { color: "#6b7280", marginBottom: "1rem" }, children: [
2041
2029
  "This page requires ",
2042
2030
  /* @__PURE__ */ s("strong", { children: e }),
2043
2031
  " access."
2044
2032
  ] }),
2045
- /* @__PURE__ */ d("p", { style: { color: "#9ca3af", fontSize: "0.875rem" }, children: [
2033
+ /* @__PURE__ */ u("p", { style: { color: "#9ca3af", fontSize: "0.875rem" }, children: [
2046
2034
  "Your current user type: ",
2047
2035
  /* @__PURE__ */ s("strong", { children: n })
2048
2036
  ] })
2049
- ] }) : /* @__PURE__ */ d(_, { children: [
2037
+ ] }) : /* @__PURE__ */ u(_, { children: [
2050
2038
  /* @__PURE__ */ s("p", { style: { color: "#6b7280", marginBottom: "1rem" }, children: "You don't have the required permissions to access this page." }),
2051
- t && t.length > 0 && /* @__PURE__ */ d("p", { style: { color: "#9ca3af", fontSize: "0.875rem" }, children: [
2039
+ t && t.length > 0 && /* @__PURE__ */ u("p", { style: { color: "#9ca3af", fontSize: "0.875rem" }, children: [
2052
2040
  "Required permissions: ",
2053
2041
  /* @__PURE__ */ s("strong", { children: t.join(", ") })
2054
2042
  ] })
@@ -2057,8 +2045,8 @@ const Nt = ({ redirectPath: n }) => /* @__PURE__ */ s(
2057
2045
  }
2058
2046
  )
2059
2047
  }
2060
- ), Ct = (n, e) => n === e;
2061
- function Ir({
2048
+ ), Nt = (n, e) => n === e;
2049
+ function Pr({
2062
2050
  children: n,
2063
2051
  redirectTo: e = "/login",
2064
2052
  requiredUserType: t,
@@ -2066,34 +2054,34 @@ function Ir({
2066
2054
  requireAllPermissions: i = !1,
2067
2055
  fallback: o
2068
2056
  }) {
2069
- const { hasValidSession: a, sessionManager: h, hasPermission: g, hasAnyPermission: w, hasAllPermissions: c } = ue(), I = Ae();
2070
- if (ee(() => {
2057
+ const { hasValidSession: a, sessionManager: f, hasPermission: m, hasAnyPermission: b, hasAllPermissions: c } = ue(), L = ke();
2058
+ if (re(() => {
2071
2059
  process.env.NODE_ENV === "development" && console.warn(
2072
2060
  "[react-identity-access] ProtectedRoute is deprecated. Use AuthenticatedZone or AdminZone from ZoneRoute instead."
2073
2061
  );
2074
2062
  }, []), !a())
2075
- return o ? /* @__PURE__ */ s(_, { children: o }) : /* @__PURE__ */ d(_, { children: [
2076
- /* @__PURE__ */ s(Nt, { redirectPath: e }),
2077
- /* @__PURE__ */ s(Te, { to: e, state: { from: I.pathname }, replace: !0 })
2063
+ return o ? /* @__PURE__ */ s(_, { children: o }) : /* @__PURE__ */ u(_, { children: [
2064
+ /* @__PURE__ */ s(Ft, { redirectPath: e }),
2065
+ /* @__PURE__ */ s(Se, { to: e, state: { from: L.pathname }, replace: !0 })
2078
2066
  ] });
2079
- const p = h.getUser();
2067
+ const p = f.getUser();
2080
2068
  if (!p)
2081
- return /* @__PURE__ */ s(Te, { to: e, state: { from: I.pathname }, replace: !0 });
2082
- if (t && !Ct(p.userType, t))
2069
+ return /* @__PURE__ */ s(Se, { to: e, state: { from: L.pathname }, replace: !0 });
2070
+ if (t && !Nt(p.userType, t))
2083
2071
  return /* @__PURE__ */ s(
2084
- Ge,
2072
+ je,
2085
2073
  {
2086
2074
  userType: p.userType,
2087
2075
  requiredUserType: t
2088
2076
  }
2089
2077
  );
2090
- if (r && r.length > 0 && !(i ? c(r) : w(r))) {
2091
- const R = r.filter((F) => !g(F)).map((F) => typeof F == "string" ? F : F.name);
2092
- return /* @__PURE__ */ s(Ge, { missingPermissions: R });
2078
+ if (r && r.length > 0 && !(i ? c(r) : b(r))) {
2079
+ const I = r.filter((M) => !m(M)).map((M) => typeof M == "string" ? M : M.name);
2080
+ return /* @__PURE__ */ s(je, { missingPermissions: I });
2093
2081
  }
2094
2082
  return /* @__PURE__ */ s(_, { children: n });
2095
2083
  }
2096
- const Ut = ({ redirectPath: n }) => /* @__PURE__ */ s(
2084
+ const Dt = ({ redirectPath: n }) => /* @__PURE__ */ s(
2097
2085
  "div",
2098
2086
  {
2099
2087
  style: {
@@ -2106,7 +2094,7 @@ const Ut = ({ redirectPath: n }) => /* @__PURE__ */ s(
2106
2094
  backgroundColor: "#f9fafb",
2107
2095
  textAlign: "center"
2108
2096
  },
2109
- children: /* @__PURE__ */ d(
2097
+ children: /* @__PURE__ */ u(
2110
2098
  "div",
2111
2099
  {
2112
2100
  style: {
@@ -2120,7 +2108,7 @@ const Ut = ({ redirectPath: n }) => /* @__PURE__ */ s(
2120
2108
  /* @__PURE__ */ s("div", { style: { fontSize: "3rem", marginBottom: "1rem" }, children: "🏢" }),
2121
2109
  /* @__PURE__ */ s("h2", { style: { color: "#374151", marginBottom: "1rem" }, children: "Tenant Required" }),
2122
2110
  /* @__PURE__ */ s("p", { style: { color: "#6b7280", marginBottom: "1.5rem" }, children: "This page requires a tenant context to access." }),
2123
- /* @__PURE__ */ d("p", { style: { fontSize: "0.875rem", color: "#9ca3af" }, children: [
2111
+ /* @__PURE__ */ u("p", { style: { fontSize: "0.875rem", color: "#9ca3af" }, children: [
2124
2112
  "Redirecting to ",
2125
2113
  n,
2126
2114
  "..."
@@ -2130,18 +2118,18 @@ const Ut = ({ redirectPath: n }) => /* @__PURE__ */ s(
2130
2118
  )
2131
2119
  }
2132
2120
  );
2133
- function Er({ children: n, redirectTo: e = "/", fallback: t }) {
2134
- const { tenant: r, isLoading: i, error: o } = we(), a = Ae();
2135
- return ee(() => {
2121
+ function Rr({ children: n, redirectTo: e = "/", fallback: t }) {
2122
+ const { tenant: r, isLoading: i, error: o } = me(), a = ke();
2123
+ return re(() => {
2136
2124
  process.env.NODE_ENV === "development" && console.warn(
2137
2125
  "[react-identity-access] TenantRoute is deprecated. Use TenantZone from ZoneRoute instead."
2138
2126
  );
2139
- }, []), i || o ? null : r ? /* @__PURE__ */ s(_, { children: n }) : t ? /* @__PURE__ */ s(_, { children: t }) : /* @__PURE__ */ d(_, { children: [
2140
- /* @__PURE__ */ s(Ut, { redirectPath: e }),
2141
- /* @__PURE__ */ s(Te, { to: e, state: { from: a.pathname }, replace: !0 })
2127
+ }, []), i || o ? null : r ? /* @__PURE__ */ s(_, { children: n }) : t ? /* @__PURE__ */ s(_, { children: t }) : /* @__PURE__ */ u(_, { children: [
2128
+ /* @__PURE__ */ s(Dt, { redirectPath: e }),
2129
+ /* @__PURE__ */ s(Se, { to: e, state: { from: a.pathname }, replace: !0 })
2142
2130
  ] });
2143
2131
  }
2144
- const $t = ({ redirectPath: n }) => /* @__PURE__ */ s(
2132
+ const Ct = ({ redirectPath: n }) => /* @__PURE__ */ s(
2145
2133
  "div",
2146
2134
  {
2147
2135
  style: {
@@ -2154,7 +2142,7 @@ const $t = ({ redirectPath: n }) => /* @__PURE__ */ s(
2154
2142
  backgroundColor: "#f9fafb",
2155
2143
  textAlign: "center"
2156
2144
  },
2157
- children: /* @__PURE__ */ d(
2145
+ children: /* @__PURE__ */ u(
2158
2146
  "div",
2159
2147
  {
2160
2148
  style: {
@@ -2168,7 +2156,7 @@ const $t = ({ redirectPath: n }) => /* @__PURE__ */ s(
2168
2156
  /* @__PURE__ */ s("div", { style: { fontSize: "3rem", marginBottom: "1rem" }, children: "🚀" }),
2169
2157
  /* @__PURE__ */ s("h2", { style: { color: "#374151", marginBottom: "1rem" }, children: "Tenant Detected" }),
2170
2158
  /* @__PURE__ */ s("p", { style: { color: "#6b7280", marginBottom: "1.5rem" }, children: "You are accessing a tenant-specific context. Redirecting to the appropriate page." }),
2171
- /* @__PURE__ */ d("p", { style: { fontSize: "0.875rem", color: "#9ca3af" }, children: [
2159
+ /* @__PURE__ */ u("p", { style: { fontSize: "0.875rem", color: "#9ca3af" }, children: [
2172
2160
  "Redirecting to ",
2173
2161
  n,
2174
2162
  "..."
@@ -2178,41 +2166,41 @@ const $t = ({ redirectPath: n }) => /* @__PURE__ */ s(
2178
2166
  )
2179
2167
  }
2180
2168
  );
2181
- function Mr({ children: n, redirectTo: e = "/dashboard", fallback: t }) {
2182
- const { tenant: r, isLoading: i, error: o } = we(), a = Ae();
2183
- return ee(() => {
2169
+ function Ir({ children: n, redirectTo: e = "/dashboard", fallback: t }) {
2170
+ const { tenant: r, isLoading: i, error: o } = me(), a = ke();
2171
+ return re(() => {
2184
2172
  process.env.NODE_ENV === "development" && console.warn(
2185
2173
  "[react-identity-access] LandingRoute is deprecated. Use PublicZone from ZoneRoute instead."
2186
2174
  );
2187
- }, []), i || o ? null : r ? t ? /* @__PURE__ */ s(_, { children: t }) : /* @__PURE__ */ d(_, { children: [
2188
- /* @__PURE__ */ s($t, { redirectPath: e }),
2189
- /* @__PURE__ */ s(Te, { to: e, state: { from: a.pathname }, replace: !0 })
2175
+ }, []), i || o ? null : r ? t ? /* @__PURE__ */ s(_, { children: t }) : /* @__PURE__ */ u(_, { children: [
2176
+ /* @__PURE__ */ s(Ct, { redirectPath: e }),
2177
+ /* @__PURE__ */ s(Se, { to: e, state: { from: a.pathname }, replace: !0 })
2190
2178
  ] }) : /* @__PURE__ */ s(_, { children: n });
2191
2179
  }
2192
- function Ht(n, e) {
2180
+ function Ut(n, e) {
2193
2181
  return e ? n ? Array.isArray(e) ? e.includes(n) : n === e : !1 : !0;
2194
2182
  }
2195
- function Qe(n, e) {
2183
+ function Ge(n, e) {
2196
2184
  return !n || n === "optional" ? "skip" : n === "required" ? e ? "pass" : "fail" : n === "forbidden" ? e ? "fail" : "pass" : "skip";
2197
2185
  }
2198
- function Bt(n, e) {
2199
- return Qe(n.tenant, e.hasTenant) === "fail" ? e.hasTenant ? "has_tenant" : "no_tenant" : Qe(n.auth, e.isAuthenticated) === "fail" ? e.isAuthenticated ? "already_authenticated" : "not_authenticated" : n.userType && e.isAuthenticated && !Ht(e.userType, n.userType) ? "wrong_user_type" : n.permissions && n.permissions.length > 0 && !(n.requireAllPermissions !== !1 ? (o) => o.every((a) => e.permissions.includes(a)) : (o) => o.some((a) => e.permissions.includes(a)))(n.permissions) ? "missing_permissions" : null;
2186
+ function $t(n, e) {
2187
+ return Ge(n.tenant, e.hasTenant) === "fail" ? e.hasTenant ? "has_tenant" : "no_tenant" : Ge(n.auth, e.isAuthenticated) === "fail" ? e.isAuthenticated ? "already_authenticated" : "not_authenticated" : n.userType && e.isAuthenticated && !Ut(e.userType, n.userType) ? "wrong_user_type" : n.permissions && n.permissions.length > 0 && !(n.requireAllPermissions !== !1 ? (o) => o.every((a) => e.permissions.includes(a)) : (o) => o.some((a) => e.permissions.includes(a)))(n.permissions) ? "missing_permissions" : null;
2200
2188
  }
2201
- function qt(n, e) {
2202
- return n.hasTenant ? n.isAuthenticated ? n.userType === ae.TENANT_ADMIN ? e.tenantAdmin : e.tenantUser : e.tenantGuest : n.isAuthenticated ? n.userType === ae.TENANT_ADMIN ? e.publicAdmin : e.publicUser : e.publicGuest;
2189
+ function Ht(n, e) {
2190
+ return n.hasTenant ? n.isAuthenticated ? n.userType === oe.TENANT_ADMIN ? e.tenantAdmin : e.tenantUser : e.tenantGuest : n.isAuthenticated ? n.userType === oe.TENANT_ADMIN ? e.publicAdmin : e.publicUser : e.publicGuest;
2203
2191
  }
2204
- function Ot(n, e, t, r, i) {
2192
+ function Bt(n, e, t, r, i) {
2205
2193
  if (!e || i !== "url")
2206
2194
  return n;
2207
2195
  const o = typeof e == "string" ? e : t, a = n.includes("?") ? "&" : "?";
2208
2196
  return `${n}${a}${r}=${encodeURIComponent(o)}`;
2209
2197
  }
2210
- function zt(n, e, t) {
2198
+ function qt(n, e, t) {
2211
2199
  if (!n || t === "url") return;
2212
2200
  const r = typeof n == "string" ? n : e, i = "zone_return_to";
2213
2201
  t === "session" ? sessionStorage.setItem(i, r) : t === "local" && localStorage.setItem(i, r);
2214
2202
  }
2215
- const de = ({
2203
+ const ce = ({
2216
2204
  children: n,
2217
2205
  preset: e,
2218
2206
  tenant: t,
@@ -2220,83 +2208,83 @@ const de = ({
2220
2208
  userType: i,
2221
2209
  requiredPermissions: o,
2222
2210
  requireAllPermissions: a = !0,
2223
- returnTo: h,
2224
- onAccessDenied: g,
2225
- redirectTo: w,
2211
+ returnTo: f,
2212
+ onAccessDenied: m,
2213
+ redirectTo: b,
2226
2214
  loadingFallback: c,
2227
- accessDeniedFallback: I
2215
+ accessDeniedFallback: L
2228
2216
  }) => {
2229
- const p = Ae(), { isAuthenticated: x, isAuthInitializing: R, currentUser: F, userPermissions: E } = ue(), { tenant: A, isTenantLoading: u } = ye(), k = Ft(), m = Z(() => {
2217
+ const p = ke(), { isAuthenticated: R, isAuthInitializing: I, currentUser: M, userPermissions: E } = ue(), { tenant: x, isTenantLoading: h } = ge(), A = Mt(), w = K(() => {
2230
2218
  if (e)
2231
- return k.presets[e];
2232
- }, [e, k.presets]), M = Z(
2219
+ return A.presets[e];
2220
+ }, [e, A.presets]), v = K(
2233
2221
  () => ({
2234
- tenant: t ?? (m == null ? void 0 : m.tenant),
2235
- auth: r ?? (m == null ? void 0 : m.auth),
2236
- userType: i ?? (m == null ? void 0 : m.userType),
2237
- permissions: o ?? (m == null ? void 0 : m.requiredPermissions),
2222
+ tenant: t ?? (w == null ? void 0 : w.tenant),
2223
+ auth: r ?? (w == null ? void 0 : w.auth),
2224
+ userType: i ?? (w == null ? void 0 : w.userType),
2225
+ permissions: o ?? (w == null ? void 0 : w.requiredPermissions),
2238
2226
  requireAllPermissions: a
2239
2227
  }),
2240
- [t, r, i, o, m, a]
2241
- ), L = Z(
2228
+ [t, r, i, o, w, a]
2229
+ ), N = K(
2242
2230
  () => ({
2243
- hasTenant: !!A,
2244
- isAuthenticated: x,
2245
- userType: F == null ? void 0 : F.userType,
2231
+ hasTenant: !!x,
2232
+ isAuthenticated: R,
2233
+ userType: M == null ? void 0 : M.userType,
2246
2234
  permissions: E,
2247
- isLoading: R || u
2235
+ isLoading: I || h
2248
2236
  }),
2249
2237
  [
2250
- A,
2251
2238
  x,
2252
- F == null ? void 0 : F.userType,
2253
- E,
2254
2239
  R,
2255
- u
2240
+ M == null ? void 0 : M.userType,
2241
+ E,
2242
+ I,
2243
+ h
2256
2244
  ]
2257
- ), D = Z(() => L.isLoading ? null : Bt(M, L), [M, L]), P = Z(() => D ? w || qt(L, k.zoneRoots) : null, [D, w, L, k.zoneRoots]), U = Z(() => !D || !P ? null : {
2258
- type: D,
2245
+ ), B = K(() => N.isLoading ? null : $t(v, N), [v, N]), l = K(() => B ? b || Ht(N, A.zoneRoots) : null, [B, b, N, A.zoneRoots]), H = K(() => !B || !l ? null : {
2246
+ type: B,
2259
2247
  required: {
2260
- tenant: M.tenant,
2261
- auth: M.auth,
2262
- userType: M.userType,
2263
- permissions: M.permissions
2248
+ tenant: v.tenant,
2249
+ auth: v.auth,
2250
+ userType: v.userType,
2251
+ permissions: v.permissions
2264
2252
  },
2265
2253
  current: {
2266
- hasTenant: L.hasTenant,
2267
- isAuthenticated: L.isAuthenticated,
2268
- userType: L.userType,
2269
- permissions: L.permissions
2254
+ hasTenant: N.hasTenant,
2255
+ isAuthenticated: N.isAuthenticated,
2256
+ userType: N.userType,
2257
+ permissions: N.permissions
2270
2258
  },
2271
- redirectTo: P
2272
- }, [D, P, M, L]);
2273
- if (ee(() => {
2274
- U && (g ? g(U) : k.onAccessDenied && k.onAccessDenied(U));
2275
- }, [U, g, k]), ee(() => {
2276
- U && h && zt(h, p.pathname + p.search, k.returnToStorage);
2259
+ redirectTo: l
2260
+ }, [B, l, v, N]);
2261
+ if (re(() => {
2262
+ H && (m ? m(H) : A.onAccessDenied && A.onAccessDenied(H));
2263
+ }, [H, m, A]), re(() => {
2264
+ H && f && qt(f, p.pathname + p.search, A.returnToStorage);
2277
2265
  }, [
2278
- U,
2279
- h,
2266
+ H,
2267
+ f,
2280
2268
  p.pathname,
2281
2269
  p.search,
2282
- k.returnToStorage
2283
- ]), L.isLoading)
2284
- return /* @__PURE__ */ s(_, { children: c ?? k.loadingFallback ?? null });
2285
- if (U && P) {
2286
- const l = I ?? k.accessDeniedFallback;
2287
- if (l)
2288
- return /* @__PURE__ */ s(_, { children: l });
2289
- const N = Ot(
2290
- P,
2291
- h,
2270
+ A.returnToStorage
2271
+ ]), N.isLoading)
2272
+ return /* @__PURE__ */ s(_, { children: c ?? A.loadingFallback ?? null });
2273
+ if (H && l) {
2274
+ const P = L ?? A.accessDeniedFallback;
2275
+ if (P)
2276
+ return /* @__PURE__ */ s(_, { children: P });
2277
+ const D = Bt(
2278
+ l,
2279
+ f,
2292
2280
  p.pathname + p.search,
2293
- k.returnToParam,
2294
- k.returnToStorage
2281
+ A.returnToParam,
2282
+ A.returnToStorage
2295
2283
  );
2296
- return /* @__PURE__ */ s(Te, { to: N, replace: !0 });
2284
+ return /* @__PURE__ */ s(Se, { to: D, replace: !0 });
2297
2285
  }
2298
2286
  return /* @__PURE__ */ s(_, { children: n });
2299
- }, Lr = (n) => /* @__PURE__ */ s(de, { tenant: "required", ...n }), Fr = (n) => /* @__PURE__ */ s(de, { tenant: "forbidden", ...n }), Dr = (n) => /* @__PURE__ */ s(de, { auth: "required", ...n }), Nr = (n) => /* @__PURE__ */ s(de, { auth: "forbidden", ...n }), Cr = (n) => /* @__PURE__ */ s(de, { auth: "required", userType: ae.TENANT_ADMIN, ...n }), Ur = (n) => /* @__PURE__ */ s(de, { auth: "required", userType: ae.USER, ...n }), $r = (n) => /* @__PURE__ */ s(de, { tenant: "optional", auth: "optional", ...n }), Hr = (n) => /* @__PURE__ */ s(de, { tenant: "required", auth: "required", ...n }), Br = (n) => /* @__PURE__ */ s(de, { tenant: "required", auth: "optional", ...n }), qr = (n) => /* @__PURE__ */ s(de, { tenant: "required", auth: "forbidden", ...n }), _t = () => /* @__PURE__ */ d(
2287
+ }, Er = (n) => /* @__PURE__ */ s(ce, { tenant: "required", ...n }), Mr = (n) => /* @__PURE__ */ s(ce, { tenant: "forbidden", ...n }), Lr = (n) => /* @__PURE__ */ s(ce, { auth: "required", ...n }), Fr = (n) => /* @__PURE__ */ s(ce, { auth: "forbidden", ...n }), Nr = (n) => /* @__PURE__ */ s(ce, { auth: "required", userType: oe.TENANT_ADMIN, ...n }), Dr = (n) => /* @__PURE__ */ s(ce, { auth: "required", userType: oe.USER, ...n }), Cr = (n) => /* @__PURE__ */ s(ce, { tenant: "optional", auth: "optional", ...n }), Ur = (n) => /* @__PURE__ */ s(ce, { tenant: "required", auth: "required", ...n }), $r = (n) => /* @__PURE__ */ s(ce, { tenant: "required", auth: "optional", ...n }), Hr = (n) => /* @__PURE__ */ s(ce, { tenant: "required", auth: "forbidden", ...n }), Ot = () => /* @__PURE__ */ u(
2300
2288
  "div",
2301
2289
  {
2302
2290
  style: {
@@ -2313,14 +2301,14 @@ const de = ({
2313
2301
  ]
2314
2302
  }
2315
2303
  );
2316
- function Or({
2304
+ function Br({
2317
2305
  children: n,
2318
- fallback: e = /* @__PURE__ */ s(_t, {}),
2306
+ fallback: e = /* @__PURE__ */ s(Ot, {}),
2319
2307
  allowedPlans: t,
2320
2308
  requiredFeature: r
2321
2309
  }) {
2322
- const { subscription: i, hasAllowedPlan: o, isFeatureEnabled: a, loading: h } = Lt();
2323
- return h ? /* @__PURE__ */ s(
2310
+ const { subscription: i, hasAllowedPlan: o, isFeatureEnabled: a, loading: f } = Et();
2311
+ return f ? /* @__PURE__ */ s(
2324
2312
  "div",
2325
2313
  {
2326
2314
  style: {
@@ -2332,7 +2320,7 @@ function Or({
2332
2320
  }
2333
2321
  ) : i ? i.isActive ? t && t.length > 0 && !o(t) ? /* @__PURE__ */ s(_, { children: e }) : r && !a(r) ? /* @__PURE__ */ s(_, { children: e }) : /* @__PURE__ */ s(_, { children: n }) : /* @__PURE__ */ s(_, { children: e }) : /* @__PURE__ */ s(_, { children: e });
2334
2322
  }
2335
- const Wt = ({ flagName: n }) => /* @__PURE__ */ d(
2323
+ const zt = ({ flagName: n }) => /* @__PURE__ */ u(
2336
2324
  "div",
2337
2325
  {
2338
2326
  style: {
@@ -2351,7 +2339,7 @@ const Wt = ({ flagName: n }) => /* @__PURE__ */ d(
2351
2339
  children: [
2352
2340
  /* @__PURE__ */ s("div", { style: { fontSize: "24px", marginBottom: "8px" }, children: "🚧" }),
2353
2341
  /* @__PURE__ */ s("div", { style: { fontSize: "14px", fontWeight: "500", marginBottom: "4px" }, children: "Feature Not Available" }),
2354
- /* @__PURE__ */ d("div", { style: { fontSize: "12px", opacity: 0.7 }, children: [
2342
+ /* @__PURE__ */ u("div", { style: { fontSize: "12px", opacity: 0.7 }, children: [
2355
2343
  'Feature flag "',
2356
2344
  n,
2357
2345
  '" is disabled'
@@ -2359,8 +2347,8 @@ const Wt = ({ flagName: n }) => /* @__PURE__ */ d(
2359
2347
  ]
2360
2348
  }
2361
2349
  );
2362
- function zr({ name: n, children: e, fallback: t }) {
2363
- const { isEnabled: r, loading: i } = Et();
2350
+ function qr({ name: n, children: e, fallback: t }) {
2351
+ const { isEnabled: r, loading: i } = Rt();
2364
2352
  return i ? /* @__PURE__ */ s(
2365
2353
  "div",
2366
2354
  {
@@ -2374,9 +2362,9 @@ function zr({ name: n, children: e, fallback: t }) {
2374
2362
  },
2375
2363
  children: "Loading feature flags..."
2376
2364
  }
2377
- ) : r(n) ? /* @__PURE__ */ s(_, { children: e }) : /* @__PURE__ */ s(_, { children: t || /* @__PURE__ */ s(Wt, { flagName: n }) });
2365
+ ) : r(n) ? /* @__PURE__ */ s(_, { children: e }) : /* @__PURE__ */ s(_, { children: t || /* @__PURE__ */ s(zt, { flagName: n }) });
2378
2366
  }
2379
- const Vt = () => /* @__PURE__ */ d(
2367
+ const _t = () => /* @__PURE__ */ u(
2380
2368
  "svg",
2381
2369
  {
2382
2370
  width: "16",
@@ -2393,7 +2381,7 @@ const Vt = () => /* @__PURE__ */ d(
2393
2381
  /* @__PURE__ */ s("circle", { cx: "12", cy: "12", r: "3" })
2394
2382
  ]
2395
2383
  }
2396
- ), jt = () => /* @__PURE__ */ d(
2384
+ ), Wt = () => /* @__PURE__ */ u(
2397
2385
  "svg",
2398
2386
  {
2399
2387
  width: "16",
@@ -2410,10 +2398,10 @@ const Vt = () => /* @__PURE__ */ d(
2410
2398
  /* @__PURE__ */ s("line", { x1: "1", y1: "1", x2: "23", y2: "23" })
2411
2399
  ]
2412
2400
  }
2413
- ), Gt = {
2414
- showPassword: /* @__PURE__ */ s(Vt, {}),
2415
- hidePassword: /* @__PURE__ */ s(jt, {})
2416
- }, Qt = {
2401
+ ), Vt = {
2402
+ showPassword: /* @__PURE__ */ s(_t, {}),
2403
+ hidePassword: /* @__PURE__ */ s(Wt, {})
2404
+ }, jt = {
2417
2405
  title: "Sign In",
2418
2406
  usernameLabel: "Email or Phone",
2419
2407
  usernamePlaceholder: "Enter your email or phone number",
@@ -2427,7 +2415,7 @@ const Vt = () => /* @__PURE__ */ d(
2427
2415
  magicLinkLink: "Use Magic Link",
2428
2416
  errorMessage: "Invalid credentials",
2429
2417
  loadingText: "Signing in..."
2430
- }, Kt = {
2418
+ }, Gt = {
2431
2419
  container: {
2432
2420
  maxWidth: "400px",
2433
2421
  width: "100%",
@@ -2534,7 +2522,7 @@ const Vt = () => /* @__PURE__ */ d(
2534
2522
  fontSize: "0.875rem"
2535
2523
  }
2536
2524
  };
2537
- function _r({
2525
+ function Or({
2538
2526
  copy: n = {},
2539
2527
  styles: e = {},
2540
2528
  icons: t = {},
@@ -2542,49 +2530,49 @@ function _r({
2542
2530
  onError: i,
2543
2531
  onForgotPassword: o,
2544
2532
  onSignupClick: a,
2545
- onMagicLinkClick: h,
2546
- showForgotPassword: g = !0,
2547
- showSignupLink: w = !0,
2533
+ onMagicLinkClick: f,
2534
+ showForgotPassword: m = !0,
2535
+ showSignupLink: b = !0,
2548
2536
  showMagicLinkOption: c = !0,
2549
- className: I
2537
+ className: L
2550
2538
  }) {
2551
- const [p, x] = T(""), [R, F] = T(""), [E, A] = T(!1), [u, k] = T(!1), [m, M] = T(""), [L, D] = T({}), { login: P } = ue(), { tenant: U } = we(), l = { ...Qt, ...n }, N = { ...Kt, ...e }, H = { ...Gt, ...t }, f = () => {
2552
- const y = {};
2553
- return p.trim() || (y.username = !0), R.trim() || (y.password = !0), D(y), Object.keys(y).length === 0;
2554
- }, C = async (y) => {
2555
- if (y.preventDefault(), !!f()) {
2556
- if (!(U != null && U.id)) {
2557
- M("Tenant not found");
2539
+ const [p, R] = k(""), [I, M] = k(""), [E, x] = k(!1), [h, A] = k(!1), [w, v] = k(""), [N, B] = k({}), { login: l } = ue(), { tenant: H } = me(), P = { ...jt, ...n }, D = { ...Gt, ...e }, C = { ...Vt, ...t }, d = () => {
2540
+ const g = {};
2541
+ return p.trim() || (g.username = !0), I.trim() || (g.password = !0), B(g), Object.keys(g).length === 0;
2542
+ }, U = async (g) => {
2543
+ if (g.preventDefault(), !!d()) {
2544
+ if (!(H != null && H.id)) {
2545
+ v("Tenant not found");
2558
2546
  return;
2559
2547
  }
2560
- k(!0), M("");
2548
+ A(!0), v("");
2561
2549
  try {
2562
- const v = await P({
2550
+ const S = await l({
2563
2551
  username: p,
2564
- password: R
2552
+ password: I
2565
2553
  // tenantId inferred from context automatically
2566
2554
  });
2567
- r == null || r(v);
2568
- } catch (v) {
2569
- const G = v.message || l.errorMessage;
2570
- M(G), i == null || i(G);
2555
+ r == null || r(S);
2556
+ } catch (S) {
2557
+ const Q = S.message || P.errorMessage;
2558
+ v(Q), i == null || i(Q);
2571
2559
  } finally {
2572
- k(!1);
2560
+ A(!1);
2573
2561
  }
2574
2562
  }
2575
- }, S = (y) => ({
2576
- ...N.input,
2577
- ...L[y] ? N.inputError : {}
2578
- }), b = () => ({
2579
- ...N.button,
2580
- ...u ? N.buttonLoading : {},
2581
- ...!p || !R || u ? N.buttonDisabled : {}
2563
+ }, F = (g) => ({
2564
+ ...D.input,
2565
+ ...N[g] ? D.inputError : {}
2566
+ }), y = () => ({
2567
+ ...D.button,
2568
+ ...h ? D.buttonLoading : {},
2569
+ ...!p || !I || h ? D.buttonDisabled : {}
2582
2570
  });
2583
- return /* @__PURE__ */ d("div", { className: I, style: N.container, children: [
2584
- /* @__PURE__ */ s("h2", { style: N.title, children: l.title }),
2585
- /* @__PURE__ */ d("form", { onSubmit: C, style: N.form, children: [
2586
- /* @__PURE__ */ d("div", { style: N.fieldGroup, children: [
2587
- /* @__PURE__ */ s("label", { style: N.label, children: l.usernameLabel }),
2571
+ return /* @__PURE__ */ u("div", { className: L, style: D.container, children: [
2572
+ /* @__PURE__ */ s("h2", { style: D.title, children: P.title }),
2573
+ /* @__PURE__ */ u("form", { onSubmit: U, style: D.form, children: [
2574
+ /* @__PURE__ */ u("div", { style: D.fieldGroup, children: [
2575
+ /* @__PURE__ */ s("label", { style: D.label, children: P.usernameLabel }),
2588
2576
  /* @__PURE__ */ s(
2589
2577
  "input",
2590
2578
  {
@@ -2592,75 +2580,75 @@ function _r({
2592
2580
  name: "username",
2593
2581
  type: "text",
2594
2582
  value: p,
2595
- onChange: (y) => {
2596
- x(y.target.value), L.username && D((v) => ({ ...v, username: !1 }));
2583
+ onChange: (g) => {
2584
+ R(g.target.value), N.username && B((S) => ({ ...S, username: !1 }));
2597
2585
  },
2598
- placeholder: l.usernamePlaceholder,
2599
- style: S("username"),
2600
- disabled: u
2586
+ placeholder: P.usernamePlaceholder,
2587
+ style: F("username"),
2588
+ disabled: h
2601
2589
  }
2602
2590
  )
2603
2591
  ] }),
2604
- /* @__PURE__ */ d("div", { style: N.fieldGroup, children: [
2605
- /* @__PURE__ */ s("label", { style: N.label, children: l.passwordLabel }),
2606
- /* @__PURE__ */ d("div", { style: N.inputContainer, children: [
2592
+ /* @__PURE__ */ u("div", { style: D.fieldGroup, children: [
2593
+ /* @__PURE__ */ s("label", { style: D.label, children: P.passwordLabel }),
2594
+ /* @__PURE__ */ u("div", { style: D.inputContainer, children: [
2607
2595
  /* @__PURE__ */ s(
2608
2596
  "input",
2609
2597
  {
2610
2598
  id: "password",
2611
2599
  name: "password",
2612
2600
  type: E ? "text" : "password",
2613
- value: R,
2614
- onChange: (y) => {
2615
- F(y.target.value), L.password && D((v) => ({ ...v, password: !1 }));
2601
+ value: I,
2602
+ onChange: (g) => {
2603
+ M(g.target.value), N.password && B((S) => ({ ...S, password: !1 }));
2616
2604
  },
2617
- placeholder: l.passwordPlaceholder,
2605
+ placeholder: P.passwordPlaceholder,
2618
2606
  style: {
2619
- ...S("password"),
2607
+ ...F("password"),
2620
2608
  paddingRight: "2.5rem"
2621
2609
  // Make room for the icon
2622
2610
  },
2623
- disabled: u
2611
+ disabled: h
2624
2612
  }
2625
2613
  ),
2626
2614
  /* @__PURE__ */ s(
2627
2615
  "button",
2628
2616
  {
2629
2617
  type: "button",
2630
- onClick: () => A(!E),
2631
- style: N.passwordToggle,
2632
- disabled: u,
2618
+ onClick: () => x(!E),
2619
+ style: D.passwordToggle,
2620
+ disabled: h,
2633
2621
  "aria-label": E ? "Hide password" : "Show password",
2634
- children: E ? H.hidePassword : H.showPassword
2622
+ children: E ? C.hidePassword : C.showPassword
2635
2623
  }
2636
2624
  )
2637
2625
  ] })
2638
2626
  ] }),
2639
- /* @__PURE__ */ s("button", { type: "submit", disabled: !p || !R || u, style: b(), children: u ? l.loadingText : l.submitButton }),
2640
- m && /* @__PURE__ */ s("div", { style: N.errorText, children: m })
2627
+ /* @__PURE__ */ s("button", { type: "submit", disabled: !p || !I || h, style: y(), children: h ? P.loadingText : P.submitButton }),
2628
+ w && /* @__PURE__ */ s("div", { style: D.errorText, children: w })
2641
2629
  ] }),
2642
- (g || w || c) && /* @__PURE__ */ d("div", { style: N.linkContainer, children: [
2643
- c && /* @__PURE__ */ d("div", { children: [
2644
- /* @__PURE__ */ d("span", { style: N.divider, children: [
2645
- l.magicLinkText,
2630
+ (m || b || c) && /* @__PURE__ */ u("div", { style: D.linkContainer, children: [
2631
+ c && /* @__PURE__ */ u("div", { children: [
2632
+ /* @__PURE__ */ u("span", { style: D.divider, children: [
2633
+ P.magicLinkText,
2646
2634
  " "
2647
2635
  ] }),
2648
- /* @__PURE__ */ s("a", { onClick: h, style: N.link, children: l.magicLinkLink })
2636
+ /* @__PURE__ */ s("a", { onClick: f, style: D.link, children: P.magicLinkLink })
2649
2637
  ] }),
2650
- c && (g || w) && /* @__PURE__ */ s("div", { style: N.divider, children: "•" }),
2651
- g && /* @__PURE__ */ s("a", { onClick: o, style: N.link, children: l.forgotPasswordLink }),
2652
- g && w && /* @__PURE__ */ s("div", { style: N.divider, children: "•" }),
2653
- w && /* @__PURE__ */ d("div", { children: [
2654
- /* @__PURE__ */ d("span", { style: N.divider, children: [
2655
- l.signupText,
2638
+ c && (m || b) && /* @__PURE__ */ s("div", { style: D.divider, children: "•" }),
2639
+ m && /* @__PURE__ */ s("a", { onClick: o, style: D.link, children: P.forgotPasswordLink }),
2640
+ m && b && /* @__PURE__ */ s("div", { style: D.divider, children: "•" }),
2641
+ b && /* @__PURE__ */ u("div", { children: [
2642
+ /* @__PURE__ */ u("span", { style: D.divider, children: [
2643
+ P.signupText,
2656
2644
  " "
2657
2645
  ] }),
2658
- /* @__PURE__ */ s("a", { onClick: a, style: N.link, children: l.signupLink })
2646
+ /* @__PURE__ */ s("a", { onClick: a, style: D.link, children: P.signupLink })
2659
2647
  ] })
2660
2648
  ] })
2661
2649
  ] });
2662
2650
  }
2663
- const Zt = {
2651
+ const Qt = {
2664
2652
  title: "Create Account",
2665
2653
  nameLabel: "First Name",
2666
2654
  namePlaceholder: "Enter your first name",
@@ -2686,7 +2674,7 @@ const Zt = {
2686
2674
  passwordMismatchError: "Passwords do not match",
2687
2675
  isAdminLabel: "Create new organization",
2688
2676
  isAdminDescription: "Check this if you want to create a new organization"
2689
- }, Jt = {
2677
+ }, Kt = {
2690
2678
  container: {
2691
2679
  maxWidth: "400px",
2692
2680
  width: "100%",
@@ -2785,7 +2773,7 @@ const Zt = {
2785
2773
  fontSize: "0.875rem"
2786
2774
  }
2787
2775
  };
2788
- function Wr({
2776
+ function zr({
2789
2777
  copy: n = {},
2790
2778
  styles: e = {},
2791
2779
  signupType: t = "user",
@@ -2793,61 +2781,61 @@ function Wr({
2793
2781
  onError: i,
2794
2782
  onLoginClick: o,
2795
2783
  onMagicLinkClick: a,
2796
- showLoginLink: h = !0,
2797
- showMagicLinkOption: g = !0,
2798
- className: w
2784
+ showLoginLink: f = !0,
2785
+ showMagicLinkOption: m = !0,
2786
+ className: b
2799
2787
  }) {
2800
- const [c, I] = T(""), [p, x] = T(""), [R, F] = T(""), [E, A] = T(""), [u, k] = T(""), [m, M] = T(""), [L, D] = T(""), [P, U] = T(!1), [l, N] = T(""), [H, f] = T({}), { signup: C, signupTenantAdmin: S } = ue(), { tenant: b } = we(), y = { ...Zt, ...n }, v = { ...Jt, ...e }, G = () => {
2801
- const B = {};
2802
- return c.trim() || (B.name = !0), !R.trim() && !E.trim() && (B.email = !0, B.phoneNumber = !0), u.trim() || (B.password = !0), m.trim() || (B.confirmPassword = !0), t === "tenant" && !L.trim() && (B.tenantName = !0), f(B), Object.keys(B).length === 0;
2803
- }, Q = async (B) => {
2804
- if (B.preventDefault(), !!G()) {
2805
- if (u !== m) {
2806
- N(y.passwordMismatchError), f({ confirmPassword: !0 });
2788
+ const [c, L] = k(""), [p, R] = k(""), [I, M] = k(""), [E, x] = k(""), [h, A] = k(""), [w, v] = k(""), [N, B] = k(""), [l, H] = k(!1), [P, D] = k(""), [C, d] = k({}), { signup: U, signupTenantAdmin: F } = ue(), { tenant: y } = me(), g = { ...Qt, ...n }, S = { ...Kt, ...e }, Q = () => {
2789
+ const T = {};
2790
+ return c.trim() || (T.name = !0), !I.trim() && !E.trim() && (T.email = !0, T.phoneNumber = !0), h.trim() || (T.password = !0), w.trim() || (T.confirmPassword = !0), t === "tenant" && !N.trim() && (T.tenantName = !0), d(T), Object.keys(T).length === 0;
2791
+ }, J = async (T) => {
2792
+ if (T.preventDefault(), !!Q()) {
2793
+ if (h !== w) {
2794
+ D(g.passwordMismatchError), d({ confirmPassword: !0 });
2807
2795
  return;
2808
2796
  }
2809
- if (t === "user" && !(b != null && b.id)) {
2810
- N("Tenant not found");
2797
+ if (t === "user" && !(y != null && y.id)) {
2798
+ D("Tenant not found");
2811
2799
  return;
2812
2800
  }
2813
- U(!0), N("");
2801
+ H(!0), D("");
2814
2802
  try {
2815
- let X;
2816
- t === "tenant" ? X = await S({
2817
- email: R || void 0,
2803
+ let V;
2804
+ t === "tenant" ? V = await F({
2805
+ email: I || void 0,
2818
2806
  phoneNumber: E || void 0,
2819
2807
  name: c,
2820
- password: u,
2821
- tenantName: L,
2808
+ password: h,
2809
+ tenantName: N,
2822
2810
  lastName: p || void 0
2823
- }) : X = await C({
2824
- email: R || void 0,
2811
+ }) : V = await U({
2812
+ email: I || void 0,
2825
2813
  phoneNumber: E || void 0,
2826
2814
  name: c,
2827
- password: u,
2828
- tenantId: b.id,
2815
+ password: h,
2816
+ tenantId: y.id,
2829
2817
  lastName: p || void 0
2830
- }), r == null || r(X);
2831
- } catch (X) {
2832
- const V = X.message || y.errorMessage;
2833
- N(V), i == null || i(V);
2818
+ }), r == null || r(V);
2819
+ } catch (V) {
2820
+ const de = V.message || g.errorMessage;
2821
+ D(de), i == null || i(de);
2834
2822
  } finally {
2835
- U(!1);
2823
+ H(!1);
2836
2824
  }
2837
2825
  }
2838
- }, O = (B) => ({
2839
- ...v.input,
2840
- ...H[B] ? v.inputError : {}
2841
- }), q = () => ({
2842
- ...v.button,
2843
- ...P ? v.buttonLoading : {},
2844
- ...!c || !R && !E || !u || !m || P || t === "tenant" && !L ? v.buttonDisabled : {}
2845
- }), W = c && (R || E) && u && m && (t === "user" || L);
2846
- return /* @__PURE__ */ d("div", { className: w, style: v.container, children: [
2847
- /* @__PURE__ */ s("h2", { style: v.title, children: y.title }),
2848
- /* @__PURE__ */ d("form", { onSubmit: Q, style: v.form, children: [
2849
- /* @__PURE__ */ d("div", { style: v.fieldGroup, children: [
2850
- /* @__PURE__ */ s("label", { style: v.label, children: y.nameLabel }),
2826
+ }, q = (T) => ({
2827
+ ...S.input,
2828
+ ...C[T] ? S.inputError : {}
2829
+ }), O = () => ({
2830
+ ...S.button,
2831
+ ...l ? S.buttonLoading : {},
2832
+ ...!c || !I && !E || !h || !w || l || t === "tenant" && !N ? S.buttonDisabled : {}
2833
+ }), j = c && (I || E) && h && w && (t === "user" || N);
2834
+ return /* @__PURE__ */ u("div", { className: b, style: S.container, children: [
2835
+ /* @__PURE__ */ s("h2", { style: S.title, children: g.title }),
2836
+ /* @__PURE__ */ u("form", { onSubmit: J, style: S.form, children: [
2837
+ /* @__PURE__ */ u("div", { style: S.fieldGroup, children: [
2838
+ /* @__PURE__ */ s("label", { style: S.label, children: g.nameLabel }),
2851
2839
  /* @__PURE__ */ s(
2852
2840
  "input",
2853
2841
  {
@@ -2855,17 +2843,17 @@ function Wr({
2855
2843
  name: "name",
2856
2844
  type: "text",
2857
2845
  value: c,
2858
- onChange: (B) => {
2859
- I(B.target.value), H.name && f((X) => ({ ...X, name: !1 }));
2846
+ onChange: (T) => {
2847
+ L(T.target.value), C.name && d((V) => ({ ...V, name: !1 }));
2860
2848
  },
2861
- placeholder: y.namePlaceholder,
2862
- style: O("name"),
2863
- disabled: P
2849
+ placeholder: g.namePlaceholder,
2850
+ style: q("name"),
2851
+ disabled: l
2864
2852
  }
2865
2853
  )
2866
2854
  ] }),
2867
- /* @__PURE__ */ d("div", { style: v.fieldGroup, children: [
2868
- /* @__PURE__ */ s("label", { style: v.label, children: y.lastNameLabel }),
2855
+ /* @__PURE__ */ u("div", { style: S.fieldGroup, children: [
2856
+ /* @__PURE__ */ s("label", { style: S.label, children: g.lastNameLabel }),
2869
2857
  /* @__PURE__ */ s(
2870
2858
  "input",
2871
2859
  {
@@ -2873,33 +2861,33 @@ function Wr({
2873
2861
  name: "lastName",
2874
2862
  type: "text",
2875
2863
  value: p,
2876
- onChange: (B) => x(B.target.value),
2877
- placeholder: y.lastNamePlaceholder,
2878
- style: v.input,
2879
- disabled: P
2864
+ onChange: (T) => R(T.target.value),
2865
+ placeholder: g.lastNamePlaceholder,
2866
+ style: S.input,
2867
+ disabled: l
2880
2868
  }
2881
2869
  )
2882
2870
  ] }),
2883
- /* @__PURE__ */ d("div", { style: v.fieldGroup, children: [
2884
- /* @__PURE__ */ s("label", { style: v.label, children: y.emailLabel }),
2871
+ /* @__PURE__ */ u("div", { style: S.fieldGroup, children: [
2872
+ /* @__PURE__ */ s("label", { style: S.label, children: g.emailLabel }),
2885
2873
  /* @__PURE__ */ s(
2886
2874
  "input",
2887
2875
  {
2888
2876
  id: "email",
2889
2877
  name: "email",
2890
2878
  type: "email",
2891
- value: R,
2892
- onChange: (B) => {
2893
- F(B.target.value), H.email && f((X) => ({ ...X, email: !1, phoneNumber: !1 }));
2879
+ value: I,
2880
+ onChange: (T) => {
2881
+ M(T.target.value), C.email && d((V) => ({ ...V, email: !1, phoneNumber: !1 }));
2894
2882
  },
2895
- placeholder: y.emailPlaceholder,
2896
- style: O("email"),
2897
- disabled: P
2883
+ placeholder: g.emailPlaceholder,
2884
+ style: q("email"),
2885
+ disabled: l
2898
2886
  }
2899
2887
  )
2900
2888
  ] }),
2901
- /* @__PURE__ */ d("div", { style: v.fieldGroup, children: [
2902
- /* @__PURE__ */ s("label", { style: v.label, children: y.phoneNumberLabel }),
2889
+ /* @__PURE__ */ u("div", { style: S.fieldGroup, children: [
2890
+ /* @__PURE__ */ s("label", { style: S.label, children: g.phoneNumberLabel }),
2903
2891
  /* @__PURE__ */ s(
2904
2892
  "input",
2905
2893
  {
@@ -2907,12 +2895,12 @@ function Wr({
2907
2895
  name: "phoneNumber",
2908
2896
  type: "tel",
2909
2897
  value: E,
2910
- onChange: (B) => {
2911
- A(B.target.value), H.phoneNumber && f((X) => ({ ...X, email: !1, phoneNumber: !1 }));
2898
+ onChange: (T) => {
2899
+ x(T.target.value), C.phoneNumber && d((V) => ({ ...V, email: !1, phoneNumber: !1 }));
2912
2900
  },
2913
- placeholder: y.phoneNumberPlaceholder,
2914
- style: O("phoneNumber"),
2915
- disabled: P
2901
+ placeholder: g.phoneNumberPlaceholder,
2902
+ style: q("phoneNumber"),
2903
+ disabled: l
2916
2904
  }
2917
2905
  )
2918
2906
  ] }),
@@ -2928,83 +2916,83 @@ function Wr({
2928
2916
  children: "At least one contact method (email or phone) is required"
2929
2917
  }
2930
2918
  ),
2931
- /* @__PURE__ */ d("div", { style: v.fieldGroup, children: [
2932
- /* @__PURE__ */ s("label", { style: v.label, children: y.passwordLabel }),
2919
+ /* @__PURE__ */ u("div", { style: S.fieldGroup, children: [
2920
+ /* @__PURE__ */ s("label", { style: S.label, children: g.passwordLabel }),
2933
2921
  /* @__PURE__ */ s(
2934
2922
  "input",
2935
2923
  {
2936
2924
  id: "password",
2937
2925
  name: "password",
2938
2926
  type: "password",
2939
- value: u,
2940
- onChange: (B) => {
2941
- k(B.target.value), H.password && f((X) => ({ ...X, password: !1 }));
2927
+ value: h,
2928
+ onChange: (T) => {
2929
+ A(T.target.value), C.password && d((V) => ({ ...V, password: !1 }));
2942
2930
  },
2943
- placeholder: y.passwordPlaceholder,
2944
- style: O("password"),
2945
- disabled: P
2931
+ placeholder: g.passwordPlaceholder,
2932
+ style: q("password"),
2933
+ disabled: l
2946
2934
  }
2947
2935
  )
2948
2936
  ] }),
2949
- /* @__PURE__ */ d("div", { style: v.fieldGroup, children: [
2950
- /* @__PURE__ */ s("label", { style: v.label, children: y.confirmPasswordLabel }),
2937
+ /* @__PURE__ */ u("div", { style: S.fieldGroup, children: [
2938
+ /* @__PURE__ */ s("label", { style: S.label, children: g.confirmPasswordLabel }),
2951
2939
  /* @__PURE__ */ s(
2952
2940
  "input",
2953
2941
  {
2954
2942
  id: "confirmPassword",
2955
2943
  name: "confirmPassword",
2956
2944
  type: "password",
2957
- value: m,
2958
- onChange: (B) => {
2959
- M(B.target.value), H.confirmPassword && f((X) => ({ ...X, confirmPassword: !1 })), l === y.passwordMismatchError && N("");
2945
+ value: w,
2946
+ onChange: (T) => {
2947
+ v(T.target.value), C.confirmPassword && d((V) => ({ ...V, confirmPassword: !1 })), P === g.passwordMismatchError && D("");
2960
2948
  },
2961
- placeholder: y.confirmPasswordPlaceholder,
2962
- style: O("confirmPassword"),
2963
- disabled: P
2949
+ placeholder: g.confirmPasswordPlaceholder,
2950
+ style: q("confirmPassword"),
2951
+ disabled: l
2964
2952
  }
2965
2953
  )
2966
2954
  ] }),
2967
- t === "tenant" && /* @__PURE__ */ d("div", { style: v.fieldGroup, children: [
2968
- /* @__PURE__ */ s("label", { style: v.label, children: y.tenantNameLabel }),
2955
+ t === "tenant" && /* @__PURE__ */ u("div", { style: S.fieldGroup, children: [
2956
+ /* @__PURE__ */ s("label", { style: S.label, children: g.tenantNameLabel }),
2969
2957
  /* @__PURE__ */ s(
2970
2958
  "input",
2971
2959
  {
2972
2960
  id: "tenantName",
2973
2961
  name: "tenantName",
2974
2962
  type: "text",
2975
- value: L,
2976
- onChange: (B) => {
2977
- D(B.target.value), H.tenantName && f((X) => ({ ...X, tenantName: !1 }));
2963
+ value: N,
2964
+ onChange: (T) => {
2965
+ B(T.target.value), C.tenantName && d((V) => ({ ...V, tenantName: !1 }));
2978
2966
  },
2979
- placeholder: y.tenantNamePlaceholder,
2980
- style: O("tenantName"),
2981
- disabled: P
2967
+ placeholder: g.tenantNamePlaceholder,
2968
+ style: q("tenantName"),
2969
+ disabled: l
2982
2970
  }
2983
2971
  )
2984
2972
  ] }),
2985
- /* @__PURE__ */ s("button", { type: "submit", disabled: !W || P, style: q(), children: P ? y.loadingText : y.submitButton }),
2986
- l && /* @__PURE__ */ s("div", { style: v.errorText, children: l })
2973
+ /* @__PURE__ */ s("button", { type: "submit", disabled: !j || l, style: O(), children: l ? g.loadingText : g.submitButton }),
2974
+ P && /* @__PURE__ */ s("div", { style: S.errorText, children: P })
2987
2975
  ] }),
2988
- (h || g) && /* @__PURE__ */ d("div", { style: v.linkContainer, children: [
2989
- g && /* @__PURE__ */ d("div", { children: [
2990
- /* @__PURE__ */ d("span", { style: v.divider, children: [
2991
- y.magicLinkText,
2976
+ (f || m) && /* @__PURE__ */ u("div", { style: S.linkContainer, children: [
2977
+ m && /* @__PURE__ */ u("div", { children: [
2978
+ /* @__PURE__ */ u("span", { style: S.divider, children: [
2979
+ g.magicLinkText,
2992
2980
  " "
2993
2981
  ] }),
2994
- /* @__PURE__ */ s("a", { onClick: a, style: v.link, children: y.magicLinkLink })
2982
+ /* @__PURE__ */ s("a", { onClick: a, style: S.link, children: g.magicLinkLink })
2995
2983
  ] }),
2996
- g && h && /* @__PURE__ */ s("div", { style: v.divider, children: "•" }),
2997
- h && /* @__PURE__ */ d("div", { children: [
2998
- /* @__PURE__ */ d("span", { style: v.divider, children: [
2999
- y.loginText,
2984
+ m && f && /* @__PURE__ */ s("div", { style: S.divider, children: "•" }),
2985
+ f && /* @__PURE__ */ u("div", { children: [
2986
+ /* @__PURE__ */ u("span", { style: S.divider, children: [
2987
+ g.loginText,
3000
2988
  " "
3001
2989
  ] }),
3002
- /* @__PURE__ */ s("a", { onClick: o, style: v.link, children: y.loginLink })
2990
+ /* @__PURE__ */ s("a", { onClick: o, style: S.link, children: g.loginLink })
3003
2991
  ] })
3004
2992
  ] })
3005
2993
  ] });
3006
2994
  }
3007
- const Yt = {
2995
+ const Zt = {
3008
2996
  title: "Sign In with Magic Link",
3009
2997
  emailLabel: "Email",
3010
2998
  emailPlaceholder: "Enter your email",
@@ -3022,7 +3010,7 @@ const Yt = {
3022
3010
  loadingText: "Sending magic link...",
3023
3011
  verifyingText: "Verifying magic link...",
3024
3012
  description: "Enter your email to receive a magic link. If you don't have an account, we'll create one for you."
3025
- }, Xt = {
3013
+ }, Jt = {
3026
3014
  container: {
3027
3015
  maxWidth: "400px",
3028
3016
  width: "100%",
@@ -3125,7 +3113,7 @@ const Yt = {
3125
3113
  fontSize: "0.875rem"
3126
3114
  }
3127
3115
  };
3128
- function Vr({
3116
+ function _r({
3129
3117
  copy: n = {},
3130
3118
  styles: e = {},
3131
3119
  onSuccess: t,
@@ -3133,76 +3121,76 @@ function Vr({
3133
3121
  onLoginClick: i,
3134
3122
  onSignupClick: o,
3135
3123
  showTraditionalLinks: a = !0,
3136
- className: h,
3137
- verifyToken: g,
3138
- frontendUrl: w
3124
+ className: f,
3125
+ verifyToken: m,
3126
+ frontendUrl: b
3139
3127
  }) {
3140
- const [c, I] = T(""), [p, x] = T(""), [R, F] = T(""), [E, A] = T(!1), [u, k] = T(!1), [m, M] = T(""), [L, D] = T(""), [P, U] = T({}), [l, N] = T(!1), { sendMagicLink: H, verifyMagicLink: f } = ue(), { tenant: C } = we(), S = { ...Yt, ...n }, b = { ...Xt, ...e };
3141
- ee(() => {
3142
- g && y(g);
3143
- }, [g]);
3144
- const y = async (q) => {
3145
- if (!C || !c) {
3146
- M("Missing tenant or email");
3128
+ const [c, L] = k(""), [p, R] = k(""), [I, M] = k(""), [E, x] = k(!1), [h, A] = k(!1), [w, v] = k(""), [N, B] = k(""), [l, H] = k({}), [P, D] = k(!1), { sendMagicLink: C, verifyMagicLink: d } = ue(), { tenant: U } = me(), F = { ...Zt, ...n }, y = { ...Jt, ...e };
3129
+ re(() => {
3130
+ m && g(m);
3131
+ }, [m]);
3132
+ const g = async (O) => {
3133
+ if (!U || !c) {
3134
+ v("Missing tenant or email");
3147
3135
  return;
3148
3136
  }
3149
- k(!0), M("");
3137
+ A(!0), v("");
3150
3138
  try {
3151
- const W = await f({
3152
- token: q,
3139
+ const j = await d({
3140
+ token: O,
3153
3141
  email: c
3154
3142
  // tenantId inferred from context automatically
3155
3143
  });
3156
- t == null || t(W);
3157
- } catch (W) {
3158
- const B = W.message || "Failed to verify magic link";
3159
- M(B), r == null || r(B);
3144
+ t == null || t(j);
3145
+ } catch (j) {
3146
+ const T = j.message || "Failed to verify magic link";
3147
+ v(T), r == null || r(T);
3160
3148
  } finally {
3161
- k(!1);
3149
+ A(!1);
3162
3150
  }
3163
- }, v = () => {
3164
- const q = {};
3165
- return c.trim() || (q.email = !0), l && !p.trim() && (q.name = !0), U(q), Object.keys(q).length === 0;
3166
- }, G = async (q) => {
3167
- if (q.preventDefault(), !!v()) {
3168
- if (!(C != null && C.id)) {
3169
- M("Tenant not found");
3151
+ }, S = () => {
3152
+ const O = {};
3153
+ return c.trim() || (O.email = !0), P && !p.trim() && (O.name = !0), H(O), Object.keys(O).length === 0;
3154
+ }, Q = async (O) => {
3155
+ if (O.preventDefault(), !!S()) {
3156
+ if (!(U != null && U.id)) {
3157
+ v("Tenant not found");
3170
3158
  return;
3171
3159
  }
3172
- A(!0), M(""), D("");
3160
+ x(!0), v(""), B("");
3173
3161
  try {
3174
- const W = w || (typeof window < "u" ? window.location.origin : ""), B = await H({
3162
+ const j = b || (typeof window < "u" ? window.location.origin : ""), T = await C({
3175
3163
  email: c,
3176
- tenantId: C.id,
3177
- frontendUrl: W,
3178
- name: l ? p : void 0,
3179
- lastName: l ? R : void 0
3164
+ tenantId: U.id,
3165
+ frontendUrl: j,
3166
+ name: P ? p : void 0,
3167
+ lastName: P ? I : void 0
3180
3168
  });
3181
- D(S.successMessage), t == null || t(B);
3182
- } catch (W) {
3183
- const B = W.message || S.errorMessage;
3184
- M(B), r == null || r(B);
3169
+ B(F.successMessage), t == null || t(T);
3170
+ } catch (j) {
3171
+ const T = j.message || F.errorMessage;
3172
+ v(T), r == null || r(T);
3185
3173
  } finally {
3186
- A(!1);
3174
+ x(!1);
3187
3175
  }
3188
3176
  }
3189
- }, Q = (q) => ({
3190
- ...b.input,
3191
- ...P[q] ? b.inputError : {}
3192
- }), O = () => ({
3193
- ...b.button,
3194
- ...E || u ? b.buttonLoading : {},
3195
- ...!c || E || u ? b.buttonDisabled : {}
3177
+ }, J = (O) => ({
3178
+ ...y.input,
3179
+ ...l[O] ? y.inputError : {}
3180
+ }), q = () => ({
3181
+ ...y.button,
3182
+ ...E || h ? y.buttonLoading : {},
3183
+ ...!c || E || h ? y.buttonDisabled : {}
3196
3184
  });
3197
- return u ? /* @__PURE__ */ d("div", { className: h, style: b.container, children: [
3198
- /* @__PURE__ */ s("h2", { style: b.title, children: S.verifyingText }),
3185
+ return h ? /* @__PURE__ */ u("div", { className: f, style: y.container, children: [
3186
+ /* @__PURE__ */ s("h2", { style: y.title, children: F.verifyingText }),
3199
3187
  /* @__PURE__ */ s("div", { style: { textAlign: "center", padding: "2rem" }, children: /* @__PURE__ */ s("div", { style: { fontSize: "1rem", color: "#6b7280" }, children: "Please wait while we verify your magic link..." }) })
3200
- ] }) : /* @__PURE__ */ d("div", { className: h, style: b.container, children: [
3201
- /* @__PURE__ */ s("h2", { style: b.title, children: S.title }),
3202
- /* @__PURE__ */ s("p", { style: b.description, children: S.description }),
3203
- /* @__PURE__ */ d("form", { onSubmit: G, style: b.form, children: [
3204
- /* @__PURE__ */ d("div", { style: b.fieldGroup, children: [
3205
- /* @__PURE__ */ s("label", { style: b.label, children: S.emailLabel }),
3188
+ ] }) : /* @__PURE__ */ u("div", { className: f, style: y.container, children: [
3189
+ /* @__PURE__ */ s("h2", { style: y.title, children: F.title }),
3190
+ /* @__PURE__ */ s("p", { style: y.description, children: F.description }),
3191
+ /* @__PURE__ */ u("form", { onSubmit: Q, style: y.form, children: [
3192
+ /* @__PURE__ */ u("div", { style: y.fieldGroup, children: [
3193
+ /* @__PURE__ */ s("label", { style: y.label, children: F.emailLabel }),
3206
3194
  /* @__PURE__ */ s(
3207
3195
  "input",
3208
3196
  {
@@ -3210,20 +3198,20 @@ function Vr({
3210
3198
  name: "email",
3211
3199
  type: "email",
3212
3200
  value: c,
3213
- onChange: (q) => {
3214
- I(q.target.value), P.email && U((W) => ({ ...W, email: !1 }));
3201
+ onChange: (O) => {
3202
+ L(O.target.value), l.email && H((j) => ({ ...j, email: !1 }));
3215
3203
  },
3216
- placeholder: S.emailPlaceholder,
3217
- style: Q("email"),
3218
- disabled: E || u
3204
+ placeholder: F.emailPlaceholder,
3205
+ style: J("email"),
3206
+ disabled: E || h
3219
3207
  }
3220
3208
  )
3221
3209
  ] }),
3222
- !l && /* @__PURE__ */ s("div", { style: { textAlign: "center", marginTop: "0.5rem" }, children: /* @__PURE__ */ s(
3210
+ !P && /* @__PURE__ */ s("div", { style: { textAlign: "center", marginTop: "0.5rem" }, children: /* @__PURE__ */ s(
3223
3211
  "button",
3224
3212
  {
3225
3213
  type: "button",
3226
- onClick: () => N(!0),
3214
+ onClick: () => D(!0),
3227
3215
  style: {
3228
3216
  background: "none",
3229
3217
  border: "none",
@@ -3235,9 +3223,9 @@ function Vr({
3235
3223
  children: "New user? Add your name"
3236
3224
  }
3237
3225
  ) }),
3238
- l && /* @__PURE__ */ d(_, { children: [
3239
- /* @__PURE__ */ d("div", { style: b.fieldGroup, children: [
3240
- /* @__PURE__ */ s("label", { style: b.label, children: S.nameLabel }),
3226
+ P && /* @__PURE__ */ u(_, { children: [
3227
+ /* @__PURE__ */ u("div", { style: y.fieldGroup, children: [
3228
+ /* @__PURE__ */ s("label", { style: y.label, children: F.nameLabel }),
3241
3229
  /* @__PURE__ */ s(
3242
3230
  "input",
3243
3231
  {
@@ -3245,28 +3233,28 @@ function Vr({
3245
3233
  name: "name",
3246
3234
  type: "text",
3247
3235
  value: p,
3248
- onChange: (q) => {
3249
- x(q.target.value), P.name && U((W) => ({ ...W, name: !1 }));
3236
+ onChange: (O) => {
3237
+ R(O.target.value), l.name && H((j) => ({ ...j, name: !1 }));
3250
3238
  },
3251
- placeholder: S.namePlaceholder,
3252
- style: Q("name"),
3253
- disabled: E || u
3239
+ placeholder: F.namePlaceholder,
3240
+ style: J("name"),
3241
+ disabled: E || h
3254
3242
  }
3255
3243
  )
3256
3244
  ] }),
3257
- /* @__PURE__ */ d("div", { style: b.fieldGroup, children: [
3258
- /* @__PURE__ */ s("label", { style: b.label, children: S.lastNameLabel }),
3245
+ /* @__PURE__ */ u("div", { style: y.fieldGroup, children: [
3246
+ /* @__PURE__ */ s("label", { style: y.label, children: F.lastNameLabel }),
3259
3247
  /* @__PURE__ */ s(
3260
3248
  "input",
3261
3249
  {
3262
3250
  id: "lastName",
3263
3251
  name: "lastName",
3264
3252
  type: "text",
3265
- value: R,
3266
- onChange: (q) => F(q.target.value),
3267
- placeholder: S.lastNamePlaceholder,
3268
- style: b.input,
3269
- disabled: E || u
3253
+ value: I,
3254
+ onChange: (O) => M(O.target.value),
3255
+ placeholder: F.lastNamePlaceholder,
3256
+ style: y.input,
3257
+ disabled: E || h
3270
3258
  }
3271
3259
  )
3272
3260
  ] }),
@@ -3275,7 +3263,7 @@ function Vr({
3275
3263
  {
3276
3264
  type: "button",
3277
3265
  onClick: () => {
3278
- N(!1), x(""), F("");
3266
+ D(!1), R(""), M("");
3279
3267
  },
3280
3268
  style: {
3281
3269
  background: "none",
@@ -3289,30 +3277,30 @@ function Vr({
3289
3277
  }
3290
3278
  ) })
3291
3279
  ] }),
3292
- /* @__PURE__ */ s("button", { type: "submit", disabled: !c || E || u, style: O(), children: E ? S.loadingText : S.submitButton }),
3293
- m && /* @__PURE__ */ s("div", { style: b.errorText, children: m }),
3294
- L && /* @__PURE__ */ s("div", { style: b.successText, children: L })
3280
+ /* @__PURE__ */ s("button", { type: "submit", disabled: !c || E || h, style: q(), children: E ? F.loadingText : F.submitButton }),
3281
+ w && /* @__PURE__ */ s("div", { style: y.errorText, children: w }),
3282
+ N && /* @__PURE__ */ s("div", { style: y.successText, children: N })
3295
3283
  ] }),
3296
- a && /* @__PURE__ */ d("div", { style: b.linkContainer, children: [
3297
- /* @__PURE__ */ d("div", { children: [
3298
- /* @__PURE__ */ d("span", { style: b.divider, children: [
3299
- S.loginText,
3284
+ a && /* @__PURE__ */ u("div", { style: y.linkContainer, children: [
3285
+ /* @__PURE__ */ u("div", { children: [
3286
+ /* @__PURE__ */ u("span", { style: y.divider, children: [
3287
+ F.loginText,
3300
3288
  " "
3301
3289
  ] }),
3302
- /* @__PURE__ */ s("a", { onClick: i, style: b.link, children: S.loginLink })
3290
+ /* @__PURE__ */ s("a", { onClick: i, style: y.link, children: F.loginLink })
3303
3291
  ] }),
3304
- /* @__PURE__ */ s("div", { style: b.divider, children: "•" }),
3305
- /* @__PURE__ */ d("div", { children: [
3306
- /* @__PURE__ */ d("span", { style: b.divider, children: [
3307
- S.signupText,
3292
+ /* @__PURE__ */ s("div", { style: y.divider, children: "•" }),
3293
+ /* @__PURE__ */ u("div", { children: [
3294
+ /* @__PURE__ */ u("span", { style: y.divider, children: [
3295
+ F.signupText,
3308
3296
  " "
3309
3297
  ] }),
3310
- /* @__PURE__ */ s("a", { onClick: o, style: b.link, children: S.signupLink })
3298
+ /* @__PURE__ */ s("a", { onClick: o, style: y.link, children: F.signupLink })
3311
3299
  ] })
3312
3300
  ] })
3313
3301
  ] });
3314
3302
  }
3315
- const er = {
3303
+ const Yt = {
3316
3304
  title: "Verifying Magic Link",
3317
3305
  verifyingMessage: "Please wait while we verify your magic link...",
3318
3306
  successMessage: "Magic link verified successfully! You are now logged in.",
@@ -3320,7 +3308,7 @@ const er = {
3320
3308
  redirectingMessage: "Redirecting you to the dashboard...",
3321
3309
  retryButton: "Try Again",
3322
3310
  backToLoginButton: "Back to Login"
3323
- }, et = {
3311
+ }, Ye = {
3324
3312
  container: {
3325
3313
  maxWidth: "400px",
3326
3314
  width: "100%",
@@ -3407,7 +3395,7 @@ const er = {
3407
3395
  cursor: "pointer",
3408
3396
  transition: "all 0.15s ease-in-out"
3409
3397
  }
3410
- }, tr = () => /* @__PURE__ */ s("div", { style: et.spinner }), rr = () => /* @__PURE__ */ d(
3398
+ }, Xt = () => /* @__PURE__ */ s("div", { style: Ye.spinner }), er = () => /* @__PURE__ */ u(
3411
3399
  "svg",
3412
3400
  {
3413
3401
  width: "48",
@@ -3424,7 +3412,7 @@ const er = {
3424
3412
  /* @__PURE__ */ s("polyline", { points: "22,4 12,14.01 9,11.01" })
3425
3413
  ]
3426
3414
  }
3427
- ), nr = () => /* @__PURE__ */ d(
3415
+ ), tr = () => /* @__PURE__ */ u(
3428
3416
  "svg",
3429
3417
  {
3430
3418
  width: "48",
@@ -3442,12 +3430,12 @@ const er = {
3442
3430
  /* @__PURE__ */ s("line", { x1: "9", y1: "9", x2: "15", y2: "15" })
3443
3431
  ]
3444
3432
  }
3445
- ), sr = {
3446
- loading: /* @__PURE__ */ s(tr, {}),
3447
- success: /* @__PURE__ */ s(rr, {}),
3448
- error: /* @__PURE__ */ s(nr, {})
3433
+ ), rr = {
3434
+ loading: /* @__PURE__ */ s(Xt, {}),
3435
+ success: /* @__PURE__ */ s(er, {}),
3436
+ error: /* @__PURE__ */ s(tr, {})
3449
3437
  };
3450
- function jr({
3438
+ function Wr({
3451
3439
  copy: n = {},
3452
3440
  styles: e = {},
3453
3441
  icons: t = {},
@@ -3455,96 +3443,96 @@ function jr({
3455
3443
  onError: i,
3456
3444
  onRetry: o,
3457
3445
  onBackToLogin: a,
3458
- className: h,
3459
- token: g,
3460
- email: w,
3446
+ className: f,
3447
+ token: m,
3448
+ email: b,
3461
3449
  appId: c,
3462
- tenantSlug: I,
3450
+ tenantSlug: L,
3463
3451
  autoRedirectDelay: p = 3e3
3464
3452
  }) {
3465
- const [x, R] = T("verifying"), [F, E] = T(""), { verifyMagicLink: A } = ue(), u = { ...er, ...n }, k = { ...et, ...e }, m = { ...sr, ...t }, M = () => {
3453
+ const [R, I] = k("verifying"), [M, E] = k(""), { verifyMagicLink: x } = ue(), h = { ...Yt, ...n }, A = { ...Ye, ...e }, w = { ...rr, ...t }, v = () => {
3466
3454
  if (typeof window > "u") return {};
3467
- const l = new URLSearchParams(window.location.search);
3455
+ const P = new URLSearchParams(window.location.search);
3468
3456
  return {
3469
- token: g || l.get("token") || "",
3470
- email: w || l.get("email") || "",
3471
- appId: c || l.get("appId") || "",
3472
- tenantSlug: I || l.get("tenantSlug") || void 0
3457
+ token: m || P.get("token") || "",
3458
+ email: b || P.get("email") || "",
3459
+ appId: c || P.get("appId") || "",
3460
+ tenantSlug: L || P.get("tenantSlug") || void 0
3473
3461
  };
3474
- }, L = async () => {
3475
- R("verifying"), E("");
3462
+ }, N = async () => {
3463
+ I("verifying"), E("");
3476
3464
  try {
3477
- const l = M();
3478
- if (!l.token || !l.email)
3465
+ const P = v();
3466
+ if (!P.token || !P.email)
3479
3467
  throw new Error("Missing required parameters: token or email");
3480
- const N = await A({
3481
- token: l.token,
3482
- email: l.email,
3483
- tenantSlug: l.tenantSlug
3468
+ const D = await x({
3469
+ token: P.token,
3470
+ email: P.email,
3471
+ tenantSlug: P.tenantSlug
3484
3472
  });
3485
- R("success"), r == null || r(N), p > 0 && setTimeout(() => {
3486
- R("redirecting");
3473
+ I("success"), r == null || r(D), p > 0 && setTimeout(() => {
3474
+ I("redirecting");
3487
3475
  }, p);
3488
- } catch (l) {
3489
- const N = l.message || u.errorMessage;
3490
- E(N), R("error"), i == null || i(N);
3476
+ } catch (P) {
3477
+ const D = P.message || h.errorMessage;
3478
+ E(D), I("error"), i == null || i(D);
3491
3479
  }
3492
- }, D = () => {
3493
- o == null || o(), L();
3494
- }, P = () => {
3480
+ }, B = () => {
3481
+ o == null || o(), N();
3482
+ }, l = () => {
3495
3483
  a == null || a();
3496
3484
  };
3497
- ee(() => {
3498
- L();
3485
+ re(() => {
3486
+ N();
3499
3487
  }, []);
3500
- const U = () => {
3501
- switch (x) {
3488
+ const H = () => {
3489
+ switch (R) {
3502
3490
  case "verifying":
3503
- return /* @__PURE__ */ d("div", { style: k.message, children: [
3504
- m.loading,
3505
- u.verifyingMessage
3491
+ return /* @__PURE__ */ u("div", { style: A.message, children: [
3492
+ w.loading,
3493
+ h.verifyingMessage
3506
3494
  ] });
3507
3495
  case "success":
3508
- return /* @__PURE__ */ d(_, { children: [
3509
- m.success,
3510
- /* @__PURE__ */ s("div", { style: k.successMessage, children: u.successMessage })
3496
+ return /* @__PURE__ */ u(_, { children: [
3497
+ w.success,
3498
+ /* @__PURE__ */ s("div", { style: A.successMessage, children: h.successMessage })
3511
3499
  ] });
3512
3500
  case "redirecting":
3513
- return /* @__PURE__ */ d(_, { children: [
3514
- m.loading,
3515
- /* @__PURE__ */ s("div", { style: k.message, children: u.redirectingMessage })
3501
+ return /* @__PURE__ */ u(_, { children: [
3502
+ w.loading,
3503
+ /* @__PURE__ */ s("div", { style: A.message, children: h.redirectingMessage })
3516
3504
  ] });
3517
3505
  case "error":
3518
- return /* @__PURE__ */ d(_, { children: [
3519
- m.error,
3520
- /* @__PURE__ */ s("div", { style: k.errorMessage, children: F || u.errorMessage }),
3521
- /* @__PURE__ */ d("div", { style: k.buttonContainer, children: [
3506
+ return /* @__PURE__ */ u(_, { children: [
3507
+ w.error,
3508
+ /* @__PURE__ */ s("div", { style: A.errorMessage, children: M || h.errorMessage }),
3509
+ /* @__PURE__ */ u("div", { style: A.buttonContainer, children: [
3522
3510
  /* @__PURE__ */ s(
3523
3511
  "button",
3524
3512
  {
3525
- onClick: D,
3526
- style: k.retryButton,
3527
- onMouseOver: (l) => {
3528
- l.currentTarget.style.backgroundColor = "#2563eb";
3513
+ onClick: B,
3514
+ style: A.retryButton,
3515
+ onMouseOver: (P) => {
3516
+ P.currentTarget.style.backgroundColor = "#2563eb";
3529
3517
  },
3530
- onMouseOut: (l) => {
3531
- l.currentTarget.style.backgroundColor = "#3b82f6";
3518
+ onMouseOut: (P) => {
3519
+ P.currentTarget.style.backgroundColor = "#3b82f6";
3532
3520
  },
3533
- children: u.retryButton
3521
+ children: h.retryButton
3534
3522
  }
3535
3523
  ),
3536
3524
  /* @__PURE__ */ s(
3537
3525
  "button",
3538
3526
  {
3539
- onClick: P,
3540
- style: k.backButton,
3541
- onMouseOver: (l) => {
3542
- l.currentTarget.style.backgroundColor = "#e5e7eb";
3527
+ onClick: l,
3528
+ style: A.backButton,
3529
+ onMouseOver: (P) => {
3530
+ P.currentTarget.style.backgroundColor = "#e5e7eb";
3543
3531
  },
3544
- onMouseOut: (l) => {
3545
- l.currentTarget.style.backgroundColor = "#f3f4f6";
3532
+ onMouseOut: (P) => {
3533
+ P.currentTarget.style.backgroundColor = "#f3f4f6";
3546
3534
  },
3547
- children: u.backToLoginButton
3535
+ children: h.backToLoginButton
3548
3536
  }
3549
3537
  )
3550
3538
  ] })
@@ -3553,18 +3541,18 @@ function jr({
3553
3541
  return null;
3554
3542
  }
3555
3543
  };
3556
- return /* @__PURE__ */ d("div", { style: k.container, className: h, children: [
3544
+ return /* @__PURE__ */ u("div", { style: A.container, className: f, children: [
3557
3545
  /* @__PURE__ */ s("style", { children: `
3558
3546
  @keyframes spin {
3559
3547
  0% { transform: rotate(0deg); }
3560
3548
  100% { transform: rotate(360deg); }
3561
3549
  }
3562
3550
  ` }),
3563
- /* @__PURE__ */ s("h1", { style: k.title, children: u.title }),
3564
- U()
3551
+ /* @__PURE__ */ s("h1", { style: A.title, children: h.title }),
3552
+ H()
3565
3553
  ] });
3566
3554
  }
3567
- const ir = {
3555
+ const nr = {
3568
3556
  title: "Reset Password",
3569
3557
  subtitle: "Enter your email address and we'll send you a link to reset your password.",
3570
3558
  emailLabel: "Email",
@@ -3586,7 +3574,7 @@ const ir = {
3586
3574
  resetLoadingText: "Resetting...",
3587
3575
  resetSuccessMessage: "Password reset successfully!",
3588
3576
  passwordMismatchError: "Passwords do not match"
3589
- }, or = {
3577
+ }, sr = {
3590
3578
  container: {
3591
3579
  maxWidth: "400px",
3592
3580
  margin: "0 auto",
@@ -3678,7 +3666,7 @@ const ir = {
3678
3666
  cursor: "pointer"
3679
3667
  }
3680
3668
  };
3681
- function Gr({
3669
+ function Vr({
3682
3670
  copy: n = {},
3683
3671
  styles: e = {},
3684
3672
  mode: t = "request",
@@ -3686,105 +3674,105 @@ function Gr({
3686
3674
  onSuccess: i,
3687
3675
  onError: o,
3688
3676
  onBackToLogin: a,
3689
- onModeChange: h,
3690
- className: g
3677
+ onModeChange: f,
3678
+ className: m
3691
3679
  }) {
3692
- const [w, c] = T(""), [I, p] = T(r), [x, R] = T(""), [F, E] = T(""), [A, u] = T(!1), [k, m] = T(""), [M, L] = T(""), [D, P] = T({}), { requestPasswordReset: U, confirmPasswordReset: l } = ue(), { tenant: N } = we(), H = { ...ir, ...n }, f = { ...or, ...e }, C = () => {
3693
- const O = {};
3694
- return w.trim() || (O.email = !0), P(O), Object.keys(O).length === 0;
3695
- }, S = () => {
3696
- const O = {};
3697
- return I.trim() || (O.token = !0), x.trim() || (O.newPassword = !0), F.trim() || (O.confirmPassword = !0), P(O), Object.keys(O).length === 0;
3698
- }, b = async (O) => {
3699
- if (O.preventDefault(), !!C()) {
3700
- if (!(N != null && N.id)) {
3701
- m("Tenant not found");
3680
+ const [b, c] = k(""), [L, p] = k(r), [R, I] = k(""), [M, E] = k(""), [x, h] = k(!1), [A, w] = k(""), [v, N] = k(""), [B, l] = k({}), { requestPasswordReset: H, confirmPasswordReset: P } = ue(), { tenant: D } = me(), C = { ...nr, ...n }, d = { ...sr, ...e }, U = () => {
3681
+ const q = {};
3682
+ return b.trim() || (q.email = !0), l(q), Object.keys(q).length === 0;
3683
+ }, F = () => {
3684
+ const q = {};
3685
+ return L.trim() || (q.token = !0), R.trim() || (q.newPassword = !0), M.trim() || (q.confirmPassword = !0), l(q), Object.keys(q).length === 0;
3686
+ }, y = async (q) => {
3687
+ if (q.preventDefault(), !!U()) {
3688
+ if (!(D != null && D.id)) {
3689
+ w("Tenant not found");
3702
3690
  return;
3703
3691
  }
3704
- u(!0), m(""), L("");
3692
+ h(!0), w(""), N("");
3705
3693
  try {
3706
- await U({ email: w, tenantId: N.id }), L(H.successMessage), i == null || i();
3707
- } catch (q) {
3708
- const W = q.message || H.errorMessage;
3709
- m(W), o == null || o(W);
3694
+ await H({ email: b, tenantId: D.id }), N(C.successMessage), i == null || i();
3695
+ } catch (O) {
3696
+ const j = O.message || C.errorMessage;
3697
+ w(j), o == null || o(j);
3710
3698
  } finally {
3711
- u(!1);
3699
+ h(!1);
3712
3700
  }
3713
3701
  }
3714
- }, y = async (O) => {
3715
- if (O.preventDefault(), !!S()) {
3716
- if (x !== F) {
3717
- m(H.passwordMismatchError), P({ confirmPassword: !0 });
3702
+ }, g = async (q) => {
3703
+ if (q.preventDefault(), !!F()) {
3704
+ if (R !== M) {
3705
+ w(C.passwordMismatchError), l({ confirmPassword: !0 });
3718
3706
  return;
3719
3707
  }
3720
- u(!0), m(""), L("");
3708
+ h(!0), w(""), N("");
3721
3709
  try {
3722
- await l({ token: I, newPassword: x }), L(H.resetSuccessMessage), i == null || i();
3723
- } catch (q) {
3724
- const W = q.message || H.errorMessage;
3725
- m(W), o == null || o(W);
3710
+ await P({ token: L, newPassword: R }), N(C.resetSuccessMessage), i == null || i();
3711
+ } catch (O) {
3712
+ const j = O.message || C.errorMessage;
3713
+ w(j), o == null || o(j);
3726
3714
  } finally {
3727
- u(!1);
3715
+ h(!1);
3728
3716
  }
3729
3717
  }
3730
- }, v = (O) => ({
3731
- ...f.input,
3732
- ...D[O] ? f.inputError : {}
3733
- }), G = () => ({
3734
- ...f.button,
3735
- ...A ? f.buttonLoading : {}
3718
+ }, S = (q) => ({
3719
+ ...d.input,
3720
+ ...B[q] ? d.inputError : {}
3721
+ }), Q = () => ({
3722
+ ...d.button,
3723
+ ...x ? d.buttonLoading : {}
3736
3724
  });
3737
3725
  if (t === "reset") {
3738
- const O = I && x && F;
3739
- return /* @__PURE__ */ d("div", { className: g, style: f.container, children: [
3740
- /* @__PURE__ */ s("h2", { style: f.title, children: H.resetTitle }),
3741
- /* @__PURE__ */ s("p", { style: f.subtitle, children: H.resetSubtitle }),
3742
- /* @__PURE__ */ d("form", { onSubmit: y, style: f.form, children: [
3743
- /* @__PURE__ */ d("div", { style: f.fieldGroup, children: [
3744
- /* @__PURE__ */ s("label", { style: f.label, children: H.tokenLabel }),
3726
+ const q = L && R && M;
3727
+ return /* @__PURE__ */ u("div", { className: m, style: d.container, children: [
3728
+ /* @__PURE__ */ s("h2", { style: d.title, children: C.resetTitle }),
3729
+ /* @__PURE__ */ s("p", { style: d.subtitle, children: C.resetSubtitle }),
3730
+ /* @__PURE__ */ u("form", { onSubmit: g, style: d.form, children: [
3731
+ /* @__PURE__ */ u("div", { style: d.fieldGroup, children: [
3732
+ /* @__PURE__ */ s("label", { style: d.label, children: C.tokenLabel }),
3745
3733
  /* @__PURE__ */ s(
3746
3734
  "input",
3747
3735
  {
3748
3736
  type: "text",
3749
- value: I,
3750
- onChange: (q) => {
3751
- p(q.target.value), D.token && P((W) => ({ ...W, token: !1 }));
3737
+ value: L,
3738
+ onChange: (O) => {
3739
+ p(O.target.value), B.token && l((j) => ({ ...j, token: !1 }));
3752
3740
  },
3753
- placeholder: H.tokenPlaceholder,
3754
- style: v("token"),
3755
- disabled: A
3741
+ placeholder: C.tokenPlaceholder,
3742
+ style: S("token"),
3743
+ disabled: x
3756
3744
  }
3757
3745
  )
3758
3746
  ] }),
3759
- /* @__PURE__ */ d("div", { style: f.fieldGroup, children: [
3760
- /* @__PURE__ */ s("label", { style: f.label, children: H.newPasswordLabel }),
3747
+ /* @__PURE__ */ u("div", { style: d.fieldGroup, children: [
3748
+ /* @__PURE__ */ s("label", { style: d.label, children: C.newPasswordLabel }),
3761
3749
  /* @__PURE__ */ s(
3762
3750
  "input",
3763
3751
  {
3764
3752
  type: "password",
3765
- value: x,
3766
- onChange: (q) => {
3767
- R(q.target.value), D.newPassword && P((W) => ({ ...W, newPassword: !1 }));
3753
+ value: R,
3754
+ onChange: (O) => {
3755
+ I(O.target.value), B.newPassword && l((j) => ({ ...j, newPassword: !1 }));
3768
3756
  },
3769
- placeholder: H.newPasswordPlaceholder,
3770
- style: v("newPassword"),
3771
- disabled: A
3757
+ placeholder: C.newPasswordPlaceholder,
3758
+ style: S("newPassword"),
3759
+ disabled: x
3772
3760
  }
3773
3761
  )
3774
3762
  ] }),
3775
- /* @__PURE__ */ d("div", { style: f.fieldGroup, children: [
3776
- /* @__PURE__ */ s("label", { style: f.label, children: H.confirmPasswordLabel }),
3763
+ /* @__PURE__ */ u("div", { style: d.fieldGroup, children: [
3764
+ /* @__PURE__ */ s("label", { style: d.label, children: C.confirmPasswordLabel }),
3777
3765
  /* @__PURE__ */ s(
3778
3766
  "input",
3779
3767
  {
3780
3768
  type: "password",
3781
- value: F,
3782
- onChange: (q) => {
3783
- E(q.target.value), D.confirmPassword && P((W) => ({ ...W, confirmPassword: !1 })), k === H.passwordMismatchError && m("");
3769
+ value: M,
3770
+ onChange: (O) => {
3771
+ E(O.target.value), B.confirmPassword && l((j) => ({ ...j, confirmPassword: !1 })), A === C.passwordMismatchError && w("");
3784
3772
  },
3785
- placeholder: H.confirmPasswordPlaceholder,
3786
- style: v("confirmPassword"),
3787
- disabled: A
3773
+ placeholder: C.confirmPasswordPlaceholder,
3774
+ style: S("confirmPassword"),
3775
+ disabled: x
3788
3776
  }
3789
3777
  )
3790
3778
  ] }),
@@ -3792,44 +3780,44 @@ function Gr({
3792
3780
  "button",
3793
3781
  {
3794
3782
  type: "submit",
3795
- disabled: !O || A,
3783
+ disabled: !q || x,
3796
3784
  style: {
3797
- ...G(),
3798
- ...!O || A ? f.buttonDisabled : {}
3785
+ ...Q(),
3786
+ ...!q || x ? d.buttonDisabled : {}
3799
3787
  },
3800
- children: A ? H.resetLoadingText : H.resetSubmitButton
3788
+ children: x ? C.resetLoadingText : C.resetSubmitButton
3801
3789
  }
3802
3790
  ),
3803
- k && /* @__PURE__ */ s("div", { style: f.errorText, children: k }),
3804
- M && /* @__PURE__ */ s("div", { style: f.successText, children: M })
3791
+ A && /* @__PURE__ */ s("div", { style: d.errorText, children: A }),
3792
+ v && /* @__PURE__ */ s("div", { style: d.successText, children: v })
3805
3793
  ] }),
3806
- /* @__PURE__ */ d("div", { style: f.linkContainer, children: [
3807
- /* @__PURE__ */ s("a", { onClick: a, style: f.link, children: H.backToLoginLink }),
3808
- h && /* @__PURE__ */ d(_, { children: [
3794
+ /* @__PURE__ */ u("div", { style: d.linkContainer, children: [
3795
+ /* @__PURE__ */ s("a", { onClick: a, style: d.link, children: C.backToLoginLink }),
3796
+ f && /* @__PURE__ */ u(_, { children: [
3809
3797
  /* @__PURE__ */ s("span", { style: { margin: "0 0.5rem", color: "#6b7280" }, children: "•" }),
3810
- /* @__PURE__ */ s("a", { onClick: () => h("request"), style: f.link, children: "Request New Link" })
3798
+ /* @__PURE__ */ s("a", { onClick: () => f("request"), style: d.link, children: "Request New Link" })
3811
3799
  ] })
3812
3800
  ] })
3813
3801
  ] });
3814
3802
  }
3815
- const Q = w;
3816
- return /* @__PURE__ */ d("div", { className: g, style: f.container, children: [
3817
- /* @__PURE__ */ s("h2", { style: f.title, children: H.title }),
3818
- /* @__PURE__ */ s("p", { style: f.subtitle, children: H.subtitle }),
3819
- /* @__PURE__ */ d("form", { onSubmit: b, style: f.form, children: [
3820
- /* @__PURE__ */ d("div", { style: f.fieldGroup, children: [
3821
- /* @__PURE__ */ s("label", { style: f.label, children: H.emailLabel }),
3803
+ const J = b;
3804
+ return /* @__PURE__ */ u("div", { className: m, style: d.container, children: [
3805
+ /* @__PURE__ */ s("h2", { style: d.title, children: C.title }),
3806
+ /* @__PURE__ */ s("p", { style: d.subtitle, children: C.subtitle }),
3807
+ /* @__PURE__ */ u("form", { onSubmit: y, style: d.form, children: [
3808
+ /* @__PURE__ */ u("div", { style: d.fieldGroup, children: [
3809
+ /* @__PURE__ */ s("label", { style: d.label, children: C.emailLabel }),
3822
3810
  /* @__PURE__ */ s(
3823
3811
  "input",
3824
3812
  {
3825
3813
  type: "email",
3826
- value: w,
3827
- onChange: (O) => {
3828
- c(O.target.value), D.email && P((q) => ({ ...q, email: !1 }));
3814
+ value: b,
3815
+ onChange: (q) => {
3816
+ c(q.target.value), B.email && l((O) => ({ ...O, email: !1 }));
3829
3817
  },
3830
- placeholder: H.emailPlaceholder,
3831
- style: v("email"),
3832
- disabled: A
3818
+ placeholder: C.emailPlaceholder,
3819
+ style: S("email"),
3820
+ disabled: x
3833
3821
  }
3834
3822
  )
3835
3823
  ] }),
@@ -3837,27 +3825,27 @@ function Gr({
3837
3825
  "button",
3838
3826
  {
3839
3827
  type: "submit",
3840
- disabled: !Q || A,
3828
+ disabled: !J || x,
3841
3829
  style: {
3842
- ...G(),
3843
- ...!Q || A ? f.buttonDisabled : {}
3830
+ ...Q(),
3831
+ ...!J || x ? d.buttonDisabled : {}
3844
3832
  },
3845
- children: A ? H.loadingText : H.submitButton
3833
+ children: x ? C.loadingText : C.submitButton
3846
3834
  }
3847
3835
  ),
3848
- k && /* @__PURE__ */ s("div", { style: f.errorText, children: k }),
3849
- M && /* @__PURE__ */ s("div", { style: f.successText, children: M })
3836
+ A && /* @__PURE__ */ s("div", { style: d.errorText, children: A }),
3837
+ v && /* @__PURE__ */ s("div", { style: d.successText, children: v })
3850
3838
  ] }),
3851
- /* @__PURE__ */ d("div", { style: f.linkContainer, children: [
3852
- /* @__PURE__ */ s("a", { onClick: a, style: f.link, children: H.backToLoginLink }),
3853
- h && /* @__PURE__ */ d(_, { children: [
3839
+ /* @__PURE__ */ u("div", { style: d.linkContainer, children: [
3840
+ /* @__PURE__ */ s("a", { onClick: a, style: d.link, children: C.backToLoginLink }),
3841
+ f && /* @__PURE__ */ u(_, { children: [
3854
3842
  /* @__PURE__ */ s("span", { style: { margin: "0 0.5rem", color: "#6b7280" }, children: "•" }),
3855
- /* @__PURE__ */ s("a", { onClick: () => h("reset"), style: f.link, children: "I have a token" })
3843
+ /* @__PURE__ */ s("a", { onClick: () => f("reset"), style: d.link, children: "I have a token" })
3856
3844
  ] })
3857
3845
  ] })
3858
3846
  ] });
3859
3847
  }
3860
- const ar = () => /* @__PURE__ */ s(
3848
+ const ir = () => /* @__PURE__ */ s(
3861
3849
  "div",
3862
3850
  {
3863
3851
  style: {
@@ -3869,7 +3857,7 @@ const ar = () => /* @__PURE__ */ s(
3869
3857
  },
3870
3858
  children: /* @__PURE__ */ s("div", { children: "Loading..." })
3871
3859
  }
3872
- ), lr = ({ error: n, retry: e }) => /* @__PURE__ */ d(
3860
+ ), or = ({ error: n, retry: e }) => /* @__PURE__ */ u(
3873
3861
  "div",
3874
3862
  {
3875
3863
  style: {
@@ -3903,43 +3891,43 @@ const ar = () => /* @__PURE__ */ s(
3903
3891
  ]
3904
3892
  }
3905
3893
  );
3906
- function Qr({
3894
+ function jr({
3907
3895
  children: n,
3908
3896
  loadingFallback: e,
3909
3897
  errorFallback: t,
3910
3898
  requireTenant: r = !0
3911
3899
  }) {
3912
- const { isAppLoading: i, appError: o, retryApp: a } = ke(), h = Pe(), g = Ce(), w = Je(), c = Ye(), I = (h == null ? void 0 : h.isTenantLoading) ?? !1, p = (h == null ? void 0 : h.tenantError) ?? null, x = (h == null ? void 0 : h.tenantSlug) ?? null, R = (h == null ? void 0 : h.retryTenant) ?? (() => {
3913
- }), F = (g == null ? void 0 : g.isAuthReady) ?? !0, E = (w == null ? void 0 : w.isReady) ?? !0, A = (c == null ? void 0 : c.isReady) ?? !0, u = r && h && x, L = i || u && I || g && !F || w && !E || c && !A, D = o || (u ? p : null), P = () => {
3914
- o && a(), p && h && R();
3900
+ const { isAppLoading: i, appError: o, retryApp: a } = ve(), f = xe(), m = De(), b = Ke(), c = Ze(), L = (f == null ? void 0 : f.isTenantLoading) ?? !1, p = (f == null ? void 0 : f.tenantError) ?? null, R = (f == null ? void 0 : f.tenantSlug) ?? null, I = (f == null ? void 0 : f.retryTenant) ?? (() => {
3901
+ }), M = (m == null ? void 0 : m.isAuthReady) ?? !0, E = (b == null ? void 0 : b.isReady) ?? !0, x = (c == null ? void 0 : c.isReady) ?? !0, h = r && f && R, N = i || h && L || m && !M || b && !E || c && !x, B = o || (h ? p : null), l = () => {
3902
+ o && a(), p && f && I();
3915
3903
  };
3916
- if (L)
3917
- return /* @__PURE__ */ s(_, { children: e || /* @__PURE__ */ s(ar, {}) });
3918
- if (D) {
3919
- const U = typeof t == "function" ? t(D, P) : t || /* @__PURE__ */ s(lr, { error: D, retry: P });
3920
- return /* @__PURE__ */ s(_, { children: U });
3904
+ if (N)
3905
+ return /* @__PURE__ */ s(_, { children: e || /* @__PURE__ */ s(ir, {}) });
3906
+ if (B) {
3907
+ const H = typeof t == "function" ? t(B, l) : t || /* @__PURE__ */ s(or, { error: B, retry: l });
3908
+ return /* @__PURE__ */ s(_, { children: H });
3921
3909
  }
3922
3910
  return /* @__PURE__ */ s(_, { children: n });
3923
3911
  }
3924
- function Kr(n = !0) {
3925
- const { isAppLoading: e, appError: t, retryApp: r, appInfo: i } = ke(), o = Pe(), a = Ce(), h = Je(), g = Ye(), w = (o == null ? void 0 : o.isTenantLoading) ?? !1, c = (o == null ? void 0 : o.tenantError) ?? null, I = (o == null ? void 0 : o.tenant) ?? null, p = (o == null ? void 0 : o.tenantSlug) ?? null, x = (o == null ? void 0 : o.retryTenant) ?? (() => {
3926
- }), R = (a == null ? void 0 : a.isAuthReady) ?? !0, F = (h == null ? void 0 : h.isReady) ?? !0, E = (g == null ? void 0 : g.isReady) ?? !0, A = n && o && p, M = e || A && w || a && !R || h && !F || g && !E, L = t || (A ? c : null);
3912
+ function Gr(n = !0) {
3913
+ const { isAppLoading: e, appError: t, retryApp: r, appInfo: i } = ve(), o = xe(), a = De(), f = Ke(), m = Ze(), b = (o == null ? void 0 : o.isTenantLoading) ?? !1, c = (o == null ? void 0 : o.tenantError) ?? null, L = (o == null ? void 0 : o.tenant) ?? null, p = (o == null ? void 0 : o.tenantSlug) ?? null, R = (o == null ? void 0 : o.retryTenant) ?? (() => {
3914
+ }), I = (a == null ? void 0 : a.isAuthReady) ?? !0, M = (f == null ? void 0 : f.isReady) ?? !0, E = (m == null ? void 0 : m.isReady) ?? !0, x = n && o && p, v = e || x && b || a && !I || f && !M || m && !E, N = t || (x ? c : null);
3927
3915
  return {
3928
- isLoading: M,
3929
- error: L,
3930
- isReady: !M && !L && i !== null && (!A || I !== null),
3916
+ isLoading: v,
3917
+ error: N,
3918
+ isReady: !v && !N && i !== null && (!x || L !== null),
3931
3919
  retry: () => {
3932
- t && r(), c && o && x();
3920
+ t && r(), c && o && R();
3933
3921
  },
3934
3922
  // Individual states
3935
3923
  app: { isLoading: e, error: t, data: i },
3936
- tenant: o ? { isLoading: w, error: c, data: I } : null,
3937
- auth: a ? { isReady: R } : null,
3938
- featureFlags: h ? { isReady: F } : null,
3939
- subscription: g ? { isReady: E } : null
3924
+ tenant: o ? { isLoading: b, error: c, data: L } : null,
3925
+ auth: a ? { isReady: I } : null,
3926
+ featureFlags: f ? { isReady: M } : null,
3927
+ subscription: m ? { isReady: E } : null
3940
3928
  };
3941
3929
  }
3942
- function Zr({
3930
+ function Qr({
3943
3931
  tenants: n,
3944
3932
  currentTenantId: e,
3945
3933
  onSelect: t,
@@ -3947,51 +3935,51 @@ function Zr({
3947
3935
  dropdownClassName: i = "",
3948
3936
  itemClassName: o = "",
3949
3937
  renderItem: a,
3950
- placeholder: h = "Select tenant",
3951
- disabled: g = !1,
3952
- showCurrentTenant: w = !0
3938
+ placeholder: f = "Select tenant",
3939
+ disabled: m = !1,
3940
+ showCurrentTenant: b = !0
3953
3941
  }) {
3954
- var k;
3955
- const c = Ce(), [I, p] = T(!1), x = Ke(null), R = n ?? (c == null ? void 0 : c.userTenants) ?? [], F = e ?? ((k = c == null ? void 0 : c.currentUser) == null ? void 0 : k.tenantId) ?? null, E = async (m) => {
3956
- p(!1), t ? t(m) : c != null && c.switchToTenant && await c.switchToTenant(m);
3942
+ var A;
3943
+ const c = De(), [L, p] = k(!1), R = Me(null), I = n ?? (c == null ? void 0 : c.userTenants) ?? [], M = e ?? ((A = c == null ? void 0 : c.currentUser) == null ? void 0 : A.tenantId) ?? null, E = async (w) => {
3944
+ p(!1), t ? t(w) : c != null && c.switchToTenant && await c.switchToTenant(w);
3957
3945
  };
3958
- ee(() => {
3959
- const m = (M) => {
3960
- x.current && !x.current.contains(M.target) && p(!1);
3946
+ re(() => {
3947
+ const w = (v) => {
3948
+ R.current && !R.current.contains(v.target) && p(!1);
3961
3949
  };
3962
- return document.addEventListener("mousedown", m), () => document.removeEventListener("mousedown", m);
3950
+ return document.addEventListener("mousedown", w), () => document.removeEventListener("mousedown", w);
3963
3951
  }, []);
3964
- const A = R.find((m) => m.id === F);
3965
- if (R.length === 0)
3952
+ const x = I.find((w) => w.id === M);
3953
+ if (I.length === 0)
3966
3954
  return null;
3967
- if (R.length === 1 && w)
3968
- return /* @__PURE__ */ s("div", { className: r, children: /* @__PURE__ */ s("span", { children: R[0].name }) });
3969
- const u = (m, M) => /* @__PURE__ */ d("span", { style: { fontWeight: M ? "bold" : "normal" }, children: [
3970
- m.name,
3971
- m.role && /* @__PURE__ */ d("span", { style: { opacity: 0.7, marginLeft: 8 }, children: [
3955
+ if (I.length === 1 && b)
3956
+ return /* @__PURE__ */ s("div", { className: r, children: /* @__PURE__ */ s("span", { children: I[0].name }) });
3957
+ const h = (w, v) => /* @__PURE__ */ u("span", { style: { fontWeight: v ? "bold" : "normal" }, children: [
3958
+ w.name,
3959
+ w.role && /* @__PURE__ */ u("span", { style: { opacity: 0.7, marginLeft: 8 }, children: [
3972
3960
  "(",
3973
- m.role,
3961
+ w.role,
3974
3962
  ")"
3975
3963
  ] })
3976
3964
  ] });
3977
- return /* @__PURE__ */ d("div", { ref: x, className: r, style: { position: "relative" }, children: [
3978
- /* @__PURE__ */ d(
3965
+ return /* @__PURE__ */ u("div", { ref: R, className: r, style: { position: "relative" }, children: [
3966
+ /* @__PURE__ */ u(
3979
3967
  "button",
3980
3968
  {
3981
3969
  type: "button",
3982
- onClick: () => !g && p(!I),
3983
- disabled: g,
3970
+ onClick: () => !m && p(!L),
3971
+ disabled: m,
3984
3972
  style: {
3985
- cursor: g ? "not-allowed" : "pointer",
3986
- opacity: g ? 0.6 : 1
3973
+ cursor: m ? "not-allowed" : "pointer",
3974
+ opacity: m ? 0.6 : 1
3987
3975
  },
3988
3976
  children: [
3989
- A ? A.name : h,
3990
- /* @__PURE__ */ s("span", { style: { marginLeft: 8 }, children: I ? "▲" : "▼" })
3977
+ x ? x.name : f,
3978
+ /* @__PURE__ */ s("span", { style: { marginLeft: 8 }, children: L ? "▲" : "▼" })
3991
3979
  ]
3992
3980
  }
3993
3981
  ),
3994
- I && /* @__PURE__ */ s(
3982
+ L && /* @__PURE__ */ s(
3995
3983
  "div",
3996
3984
  {
3997
3985
  className: i,
@@ -4008,34 +3996,34 @@ function Zr({
4008
3996
  maxHeight: 300,
4009
3997
  overflowY: "auto"
4010
3998
  },
4011
- children: R.map((m) => {
4012
- const M = m.id === F;
3999
+ children: I.map((w) => {
4000
+ const v = w.id === M;
4013
4001
  return /* @__PURE__ */ s(
4014
4002
  "div",
4015
4003
  {
4016
4004
  className: o,
4017
- onClick: () => E(m.id),
4005
+ onClick: () => E(w.id),
4018
4006
  style: {
4019
4007
  padding: "8px 12px",
4020
4008
  cursor: "pointer",
4021
- backgroundColor: M ? "#f0f0f0" : "transparent"
4009
+ backgroundColor: v ? "#f0f0f0" : "transparent"
4022
4010
  },
4023
- onMouseEnter: (L) => {
4024
- M || (L.target.style.backgroundColor = "#f5f5f5");
4011
+ onMouseEnter: (N) => {
4012
+ v || (N.target.style.backgroundColor = "#f5f5f5");
4025
4013
  },
4026
- onMouseLeave: (L) => {
4027
- M || (L.target.style.backgroundColor = "transparent");
4014
+ onMouseLeave: (N) => {
4015
+ v || (N.target.style.backgroundColor = "transparent");
4028
4016
  },
4029
- children: a ? a(m, M) : u(m, M)
4017
+ children: a ? a(w, v) : h(w, v)
4030
4018
  },
4031
- m.id
4019
+ w.id
4032
4020
  );
4033
4021
  })
4034
4022
  }
4035
4023
  )
4036
4024
  ] });
4037
4025
  }
4038
- class Jr {
4026
+ class Kr {
4039
4027
  constructor(e, t) {
4040
4028
  this.httpService = e, this.sessionManager = t;
4041
4029
  }
@@ -4103,7 +4091,7 @@ class Jr {
4103
4091
  };
4104
4092
  }
4105
4093
  }
4106
- class Yr {
4094
+ class Zr {
4107
4095
  constructor(e, t) {
4108
4096
  this.httpService = e, this.sessionManager = t;
4109
4097
  }
@@ -4154,7 +4142,7 @@ class Yr {
4154
4142
  });
4155
4143
  }
4156
4144
  }
4157
- class Xr {
4145
+ class Jr {
4158
4146
  constructor(e) {
4159
4147
  this.httpService = e;
4160
4148
  }
@@ -4163,7 +4151,7 @@ class Xr {
4163
4151
  return await this.httpService.get("/health");
4164
4152
  }
4165
4153
  }
4166
- class en {
4154
+ class Yr {
4167
4155
  // Date string to Date object
4168
4156
  static toDate(e) {
4169
4157
  return new Date(e);
@@ -4285,139 +4273,139 @@ class en {
4285
4273
  }), t;
4286
4274
  }
4287
4275
  }
4288
- const tt = "returnTo", Me = "zone_return_to", Le = "zone_return_to";
4289
- function tn(n = {}) {
4276
+ const Xe = "returnTo", Ie = "zone_return_to", Ee = "zone_return_to";
4277
+ function Xr(n = {}) {
4290
4278
  const {
4291
4279
  zoneRoots: e = {},
4292
- returnToParam: t = tt,
4280
+ returnToParam: t = Xe,
4293
4281
  returnToStorage: r = "url"
4294
- } = n, i = gt(), [o, a] = mt(), { isAuthenticated: h, currentUser: g } = ue(), { tenant: w } = ye(), c = Z(() => ({ ...He, ...e }), [e]), I = !!w, p = g == null ? void 0 : g.userType, x = Z(() => {
4282
+ } = n, i = ft(), [o, a] = pt(), { isAuthenticated: f, currentUser: m } = ue(), { tenant: b } = ge(), c = K(() => ({ ...$e, ...e }), [e]), L = !!b, p = m == null ? void 0 : m.userType, R = K(() => {
4295
4283
  switch (r) {
4296
4284
  case "url":
4297
4285
  return o.get(t);
4298
4286
  case "session":
4299
- return sessionStorage.getItem(Me);
4287
+ return sessionStorage.getItem(Ie);
4300
4288
  case "local":
4301
- return localStorage.getItem(Le);
4289
+ return localStorage.getItem(Ee);
4302
4290
  default:
4303
4291
  return null;
4304
4292
  }
4305
- }, [r, o, t]), R = ie(() => {
4293
+ }, [r, o, t]), I = se(() => {
4306
4294
  switch (r) {
4307
4295
  case "url": {
4308
- const u = new URLSearchParams(o);
4309
- u.delete(t), a(u, { replace: !0 });
4296
+ const h = new URLSearchParams(o);
4297
+ h.delete(t), a(h, { replace: !0 });
4310
4298
  break;
4311
4299
  }
4312
4300
  case "session":
4313
- sessionStorage.removeItem(Me);
4301
+ sessionStorage.removeItem(Ie);
4314
4302
  break;
4315
4303
  case "local":
4316
- localStorage.removeItem(Le);
4304
+ localStorage.removeItem(Ee);
4317
4305
  break;
4318
4306
  }
4319
- }, [r, o, t, a]), F = ie(
4320
- (u) => {
4307
+ }, [r, o, t, a]), M = se(
4308
+ (h) => {
4321
4309
  switch (r) {
4322
4310
  case "url": {
4323
- const k = new URLSearchParams(o);
4324
- k.set(t, u), a(k, { replace: !0 });
4311
+ const A = new URLSearchParams(o);
4312
+ A.set(t, h), a(A, { replace: !0 });
4325
4313
  break;
4326
4314
  }
4327
4315
  case "session":
4328
- sessionStorage.setItem(Me, u);
4316
+ sessionStorage.setItem(Ie, h);
4329
4317
  break;
4330
4318
  case "local":
4331
- localStorage.setItem(Le, u);
4319
+ localStorage.setItem(Ee, h);
4332
4320
  break;
4333
4321
  }
4334
4322
  },
4335
4323
  [r, o, t, a]
4336
- ), E = ie(
4337
- (u) => {
4338
- const k = c[u] || c.default;
4339
- i(k);
4324
+ ), E = se(
4325
+ (h) => {
4326
+ const A = c[h] || c.default;
4327
+ i(A);
4340
4328
  },
4341
4329
  [i, c]
4342
- ), A = ie(() => I ? h ? p === ae.TENANT_ADMIN ? c.tenantAdmin : c.tenantUser : c.tenantGuest : h ? p === ae.TENANT_ADMIN ? c.publicAdmin : c.publicUser : c.publicGuest, [I, h, p, c]);
4330
+ ), x = se(() => L ? f ? p === oe.TENANT_ADMIN ? c.tenantAdmin : c.tenantUser : c.tenantGuest : f ? p === oe.TENANT_ADMIN ? c.publicAdmin : c.publicUser : c.publicGuest, [L, f, p, c]);
4343
4331
  return {
4344
- returnToUrl: x,
4345
- clearReturnTo: R,
4346
- setReturnTo: F,
4332
+ returnToUrl: R,
4333
+ clearReturnTo: I,
4334
+ setReturnTo: M,
4347
4335
  navigateToZone: E,
4348
- getSmartRedirect: A
4336
+ getSmartRedirect: x
4349
4337
  };
4350
4338
  }
4351
- function rn(n, e, t = tt, r = "url") {
4339
+ function en(n, e, t = Xe, r = "url") {
4352
4340
  if (!e || r !== "url")
4353
4341
  return n;
4354
4342
  const i = new URL(n, window.location.origin);
4355
4343
  return i.searchParams.set(t, e), i.pathname + i.search;
4356
4344
  }
4357
4345
  export {
4358
- Cr as AdminZone,
4359
- en as ApiMappers,
4360
- ze as AppApiService,
4361
- Qr as AppLoader,
4362
- yr as AppProvider,
4363
- bt as AuthApiService,
4364
- Tr as AuthProvider,
4365
- Dr as AuthenticatedZone,
4366
- Xe as DEFAULT_ZONE_PRESETS,
4367
- He as DEFAULT_ZONE_ROOTS,
4368
- zr as FeatureFlag,
4369
- It as FeatureFlagApiService,
4370
- kr as FeatureFlagProvider,
4371
- Nr as GuestZone,
4372
- Xr as HealthApiService,
4373
- ce as HttpService,
4374
- Mr as LandingRoute,
4375
- _r as LoginForm,
4376
- Vr as MagicLinkForm,
4377
- jr as MagicLinkVerify,
4378
- $r as OpenZone,
4379
- Gr as PasswordRecoveryForm,
4380
- Jr as PermissionApiService,
4381
- Rr as Protected,
4382
- Ir as ProtectedRoute,
4383
- Fr as PublicZone,
4384
- _e as RoleApiService,
4385
- Ar as RoutingProvider,
4386
- se as SessionExpiredError,
4387
- Se as SessionManager,
4388
- Wr as SignupForm,
4389
- Mt as SubscriptionApiService,
4390
- Or as SubscriptionGuard,
4391
- Yr as SubscriptionPlanApiService,
4392
- xr as SubscriptionProvider,
4393
- ve as TenantApiService,
4394
- Hr as TenantAuthenticatedZone,
4395
- qr as TenantGuestZone,
4396
- Br as TenantOpenZone,
4397
- br as TenantProvider,
4398
- Er as TenantRoute,
4399
- Zr as TenantSelector,
4400
- Lr as TenantZone,
4401
- wt as TokenRefreshError,
4402
- yt as TokenRefreshTimeoutError,
4403
- St as UserApiService,
4404
- ae as UserType,
4405
- Ur as UserZone,
4406
- de as ZoneRoute,
4407
- rn as buildRedirectUrl,
4408
- wr as useApi,
4409
- ke as useApp,
4410
- Kr as useAppLoaderState,
4346
+ Nr as AdminZone,
4347
+ Yr as ApiMappers,
4348
+ Oe as AppApiService,
4349
+ jr as AppLoader,
4350
+ gr as AppProvider,
4351
+ yt as AuthApiService,
4352
+ Sr as AuthProvider,
4353
+ Lr as AuthenticatedZone,
4354
+ Je as DEFAULT_ZONE_PRESETS,
4355
+ $e as DEFAULT_ZONE_ROOTS,
4356
+ qr as FeatureFlag,
4357
+ Pt as FeatureFlagApiService,
4358
+ vr as FeatureFlagProvider,
4359
+ Fr as GuestZone,
4360
+ Jr as HealthApiService,
4361
+ le as HttpService,
4362
+ Ir as LandingRoute,
4363
+ Or as LoginForm,
4364
+ _r as MagicLinkForm,
4365
+ Wr as MagicLinkVerify,
4366
+ Cr as OpenZone,
4367
+ Vr as PasswordRecoveryForm,
4368
+ Kr as PermissionApiService,
4369
+ Ar as Protected,
4370
+ Pr as ProtectedRoute,
4371
+ Mr as PublicZone,
4372
+ ze as RoleApiService,
4373
+ kr as RoutingProvider,
4374
+ ne as SessionExpiredError,
4375
+ we as SessionManager,
4376
+ zr as SignupForm,
4377
+ It as SubscriptionApiService,
4378
+ Br as SubscriptionGuard,
4379
+ Zr as SubscriptionPlanApiService,
4380
+ Tr as SubscriptionProvider,
4381
+ be as TenantApiService,
4382
+ Ur as TenantAuthenticatedZone,
4383
+ Hr as TenantGuestZone,
4384
+ $r as TenantOpenZone,
4385
+ yr as TenantProvider,
4386
+ Rr as TenantRoute,
4387
+ Qr as TenantSelector,
4388
+ Er as TenantZone,
4389
+ mt as TokenRefreshError,
4390
+ gt as TokenRefreshTimeoutError,
4391
+ wt as UserApiService,
4392
+ oe as UserType,
4393
+ Dr as UserZone,
4394
+ ce as ZoneRoute,
4395
+ en as buildRedirectUrl,
4396
+ mr as useApi,
4397
+ ve as useApp,
4398
+ Gr as useAppLoaderState,
4411
4399
  ue as useAuth,
4412
- Et as useFeatureFlags,
4413
- Pr as useRouting,
4414
- Ft as useRoutingOptional,
4415
- vr as useSettings,
4416
- Lt as useSubscription,
4417
- ye as useTenant,
4418
- we as useTenantInfo,
4419
- Pe as useTenantOptional,
4420
- Sr as useTenantSettings,
4421
- tn as useZoneNavigation
4400
+ Rt as useFeatureFlags,
4401
+ xr as useRouting,
4402
+ Mt as useRoutingOptional,
4403
+ br as useSettings,
4404
+ Et as useSubscription,
4405
+ ge as useTenant,
4406
+ me as useTenantInfo,
4407
+ xe as useTenantOptional,
4408
+ wr as useTenantSettings,
4409
+ Xr as useZoneNavigation
4422
4410
  };
4423
4411
  //# sourceMappingURL=index.es.js.map