finance-shared 0.0.14 → 0.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2467 +1,18 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
3
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
+ import i18next from "i18next";
5
+ import { default as default2 } from "i18next";
4
6
  import { jsxs, jsx, Fragment } from "react/jsx-runtime";
5
- import { Dialog as Dialog$1, DialogTitle, DialogContent as DialogContent$1, DialogContentText, DialogActions as DialogActions$1, Button as Button$1, Typography as Typography$1, IconButton as IconButton$1, Box as Box$1, Tooltip, Zoom, TextField as TextField$1, Paper as Paper$1, Grid as Grid$1, styled as styled$3, CircularProgress as CircularProgress$1, Autocomplete as Autocomplete$1, Badge, Checkbox as Checkbox$1, Chip as Chip$1, Divider, RadioGroup, FormControlLabel, Radio, Popover as Popover$1 } from "@mui/material";
7
+ import { Dialog as Dialog$1, DialogTitle, DialogContent as DialogContent$1, DialogContentText, DialogActions as DialogActions$1, Button as Button$1, Typography as Typography$1, IconButton as IconButton$1, Box as Box$1, Tooltip, Zoom, TextField as TextField$1, Paper as Paper$1, Grid as Grid$1, styled as styled$3, CircularProgress as CircularProgress$1, Autocomplete as Autocomplete$1, Badge, Checkbox as Checkbox$1, Chip as Chip$1, Divider, RadioGroup, FormControlLabel, Radio, Grid2, Popover as Popover$1 } from "@mui/material";
8
+ import { useTranslation } from "react-i18next";
6
9
  import * as React from "react";
7
- import React__default, { createContext, useContext, useCallback, useState, useRef, useEffect, isValidElement, cloneElement, Children, memo, createElement, useMemo } from "react";
10
+ import React__default, { useState, isValidElement, cloneElement, Children, useEffect, memo, createElement, useRef, useCallback, useMemo, createContext, useContext } from "react";
8
11
  import { unstable_createGetCssVar, createSpacing as createSpacing$1, useTheme as useTheme$3, GlobalStyles as GlobalStyles$1, unstable_memoTheme, css, keyframes, styled as styled$2, createBox, darken as darken$1, unstable_resolveBreakpointValues, handleBreakpoints as handleBreakpoints$1, alpha as alpha$1 } from "@mui/system";
9
12
  import emStyled from "@emotion/styled";
10
13
  import { ThemeContext } from "@emotion/react";
11
14
  import * as ReactDOM from "react-dom";
12
15
  import ReactDOM__default from "react-dom";
13
- const isString$3 = (obj) => typeof obj === "string";
14
- const defer = () => {
15
- let res;
16
- let rej;
17
- const promise = new Promise((resolve, reject) => {
18
- res = resolve;
19
- rej = reject;
20
- });
21
- promise.resolve = res;
22
- promise.reject = rej;
23
- return promise;
24
- };
25
- const makeString = (object2) => {
26
- if (object2 == null) return "";
27
- return "" + object2;
28
- };
29
- const copy = (a3, s4, t2) => {
30
- a3.forEach((m3) => {
31
- if (s4[m3]) t2[m3] = s4[m3];
32
- });
33
- };
34
- const lastOfPathSeparatorRegExp = /###/g;
35
- const cleanKey = (key) => key && key.indexOf("###") > -1 ? key.replace(lastOfPathSeparatorRegExp, ".") : key;
36
- const canNotTraverseDeeper = (object2) => !object2 || isString$3(object2);
37
- const getLastOfPath = (object2, path, Empty) => {
38
- const stack = !isString$3(path) ? path : path.split(".");
39
- let stackIndex = 0;
40
- while (stackIndex < stack.length - 1) {
41
- if (canNotTraverseDeeper(object2)) return {};
42
- const key = cleanKey(stack[stackIndex]);
43
- if (!object2[key] && Empty) object2[key] = new Empty();
44
- if (Object.prototype.hasOwnProperty.call(object2, key)) {
45
- object2 = object2[key];
46
- } else {
47
- object2 = {};
48
- }
49
- ++stackIndex;
50
- }
51
- if (canNotTraverseDeeper(object2)) return {};
52
- return {
53
- obj: object2,
54
- k: cleanKey(stack[stackIndex])
55
- };
56
- };
57
- const setPath = (object2, path, newValue) => {
58
- const {
59
- obj,
60
- k: k2
61
- } = getLastOfPath(object2, path, Object);
62
- if (obj !== void 0 || path.length === 1) {
63
- obj[k2] = newValue;
64
- return;
65
- }
66
- let e2 = path[path.length - 1];
67
- let p = path.slice(0, path.length - 1);
68
- let last = getLastOfPath(object2, p, Object);
69
- while (last.obj === void 0 && p.length) {
70
- e2 = `${p[p.length - 1]}.${e2}`;
71
- p = p.slice(0, p.length - 1);
72
- last = getLastOfPath(object2, p, Object);
73
- if ((last == null ? void 0 : last.obj) && typeof last.obj[`${last.k}.${e2}`] !== "undefined") {
74
- last.obj = void 0;
75
- }
76
- }
77
- last.obj[`${last.k}.${e2}`] = newValue;
78
- };
79
- const pushPath = (object2, path, newValue, concat) => {
80
- const {
81
- obj,
82
- k: k2
83
- } = getLastOfPath(object2, path, Object);
84
- obj[k2] = obj[k2] || [];
85
- obj[k2].push(newValue);
86
- };
87
- const getPath$1 = (object2, path) => {
88
- const {
89
- obj,
90
- k: k2
91
- } = getLastOfPath(object2, path);
92
- if (!obj) return void 0;
93
- if (!Object.prototype.hasOwnProperty.call(obj, k2)) return void 0;
94
- return obj[k2];
95
- };
96
- const getPathWithDefaults = (data, defaultData, key) => {
97
- const value = getPath$1(data, key);
98
- if (value !== void 0) {
99
- return value;
100
- }
101
- return getPath$1(defaultData, key);
102
- };
103
- const deepExtend = (target, source, overwrite) => {
104
- for (const prop in source) {
105
- if (prop !== "__proto__" && prop !== "constructor") {
106
- if (prop in target) {
107
- if (isString$3(target[prop]) || target[prop] instanceof String || isString$3(source[prop]) || source[prop] instanceof String) {
108
- if (overwrite) target[prop] = source[prop];
109
- } else {
110
- deepExtend(target[prop], source[prop], overwrite);
111
- }
112
- } else {
113
- target[prop] = source[prop];
114
- }
115
- }
116
- }
117
- return target;
118
- };
119
- const regexEscape = (str) => str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
120
- var _entityMap = {
121
- "&": "&amp;",
122
- "<": "&lt;",
123
- ">": "&gt;",
124
- '"': "&quot;",
125
- "'": "&#39;",
126
- "/": "&#x2F;"
127
- };
128
- const escape = (data) => {
129
- if (isString$3(data)) {
130
- return data.replace(/[&<>"'\/]/g, (s4) => _entityMap[s4]);
131
- }
132
- return data;
133
- };
134
- class RegExpCache {
135
- constructor(capacity) {
136
- this.capacity = capacity;
137
- this.regExpMap = /* @__PURE__ */ new Map();
138
- this.regExpQueue = [];
139
- }
140
- getRegExp(pattern) {
141
- const regExpFromCache = this.regExpMap.get(pattern);
142
- if (regExpFromCache !== void 0) {
143
- return regExpFromCache;
144
- }
145
- const regExpNew = new RegExp(pattern);
146
- if (this.regExpQueue.length === this.capacity) {
147
- this.regExpMap.delete(this.regExpQueue.shift());
148
- }
149
- this.regExpMap.set(pattern, regExpNew);
150
- this.regExpQueue.push(pattern);
151
- return regExpNew;
152
- }
153
- }
154
- const chars = [" ", ",", "?", "!", ";"];
155
- const looksLikeObjectPathRegExpCache = new RegExpCache(20);
156
- const looksLikeObjectPath = (key, nsSeparator, keySeparator) => {
157
- nsSeparator = nsSeparator || "";
158
- keySeparator = keySeparator || "";
159
- const possibleChars = chars.filter((c2) => nsSeparator.indexOf(c2) < 0 && keySeparator.indexOf(c2) < 0);
160
- if (possibleChars.length === 0) return true;
161
- const r2 = looksLikeObjectPathRegExpCache.getRegExp(`(${possibleChars.map((c2) => c2 === "?" ? "\\?" : c2).join("|")})`);
162
- let matched = !r2.test(key);
163
- if (!matched) {
164
- const ki = key.indexOf(keySeparator);
165
- if (ki > 0 && !r2.test(key.substring(0, ki))) {
166
- matched = true;
167
- }
168
- }
169
- return matched;
170
- };
171
- const deepFind = (obj, path, keySeparator = ".") => {
172
- if (!obj) return void 0;
173
- if (obj[path]) {
174
- if (!Object.prototype.hasOwnProperty.call(obj, path)) return void 0;
175
- return obj[path];
176
- }
177
- const tokens = path.split(keySeparator);
178
- let current2 = obj;
179
- for (let i3 = 0; i3 < tokens.length; ) {
180
- if (!current2 || typeof current2 !== "object") {
181
- return void 0;
182
- }
183
- let next;
184
- let nextPath = "";
185
- for (let j = i3; j < tokens.length; ++j) {
186
- if (j !== i3) {
187
- nextPath += keySeparator;
188
- }
189
- nextPath += tokens[j];
190
- next = current2[nextPath];
191
- if (next !== void 0) {
192
- if (["string", "number", "boolean"].indexOf(typeof next) > -1 && j < tokens.length - 1) {
193
- continue;
194
- }
195
- i3 += j - i3 + 1;
196
- break;
197
- }
198
- }
199
- current2 = next;
200
- }
201
- return current2;
202
- };
203
- const getCleanedCode = (code) => code == null ? void 0 : code.replace("_", "-");
204
- const consoleLogger = {
205
- type: "logger",
206
- log(args) {
207
- this.output("log", args);
208
- },
209
- warn(args) {
210
- this.output("warn", args);
211
- },
212
- error(args) {
213
- this.output("error", args);
214
- },
215
- output(type, args) {
216
- var _a, _b;
217
- (_b = (_a = console == null ? void 0 : console[type]) == null ? void 0 : _a.apply) == null ? void 0 : _b.call(_a, console, args);
218
- }
219
- };
220
- class Logger {
221
- constructor(concreteLogger, options = {}) {
222
- this.init(concreteLogger, options);
223
- }
224
- init(concreteLogger, options = {}) {
225
- this.prefix = options.prefix || "i18next:";
226
- this.logger = concreteLogger || consoleLogger;
227
- this.options = options;
228
- this.debug = options.debug;
229
- }
230
- log(...args) {
231
- return this.forward(args, "log", "", true);
232
- }
233
- warn(...args) {
234
- return this.forward(args, "warn", "", true);
235
- }
236
- error(...args) {
237
- return this.forward(args, "error", "");
238
- }
239
- deprecate(...args) {
240
- return this.forward(args, "warn", "WARNING DEPRECATED: ", true);
241
- }
242
- forward(args, lvl, prefix, debugOnly) {
243
- if (debugOnly && !this.debug) return null;
244
- if (isString$3(args[0])) args[0] = `${prefix}${this.prefix} ${args[0]}`;
245
- return this.logger[lvl](args);
246
- }
247
- create(moduleName) {
248
- return new Logger(this.logger, {
249
- ...{
250
- prefix: `${this.prefix}:${moduleName}:`
251
- },
252
- ...this.options
253
- });
254
- }
255
- clone(options) {
256
- options = options || this.options;
257
- options.prefix = options.prefix || this.prefix;
258
- return new Logger(this.logger, options);
259
- }
260
- }
261
- var baseLogger = new Logger();
262
- class EventEmitter {
263
- constructor() {
264
- this.observers = {};
265
- }
266
- on(events, listener) {
267
- events.split(" ").forEach((event) => {
268
- if (!this.observers[event]) this.observers[event] = /* @__PURE__ */ new Map();
269
- const numListeners = this.observers[event].get(listener) || 0;
270
- this.observers[event].set(listener, numListeners + 1);
271
- });
272
- return this;
273
- }
274
- off(event, listener) {
275
- if (!this.observers[event]) return;
276
- if (!listener) {
277
- delete this.observers[event];
278
- return;
279
- }
280
- this.observers[event].delete(listener);
281
- }
282
- emit(event, ...args) {
283
- if (this.observers[event]) {
284
- const cloned = Array.from(this.observers[event].entries());
285
- cloned.forEach(([observer, numTimesAdded]) => {
286
- for (let i3 = 0; i3 < numTimesAdded; i3++) {
287
- observer(...args);
288
- }
289
- });
290
- }
291
- if (this.observers["*"]) {
292
- const cloned = Array.from(this.observers["*"].entries());
293
- cloned.forEach(([observer, numTimesAdded]) => {
294
- for (let i3 = 0; i3 < numTimesAdded; i3++) {
295
- observer.apply(observer, [event, ...args]);
296
- }
297
- });
298
- }
299
- }
300
- }
301
- class ResourceStore extends EventEmitter {
302
- constructor(data, options = {
303
- ns: ["translation"],
304
- defaultNS: "translation"
305
- }) {
306
- super();
307
- this.data = data || {};
308
- this.options = options;
309
- if (this.options.keySeparator === void 0) {
310
- this.options.keySeparator = ".";
311
- }
312
- if (this.options.ignoreJSONStructure === void 0) {
313
- this.options.ignoreJSONStructure = true;
314
- }
315
- }
316
- addNamespaces(ns) {
317
- if (this.options.ns.indexOf(ns) < 0) {
318
- this.options.ns.push(ns);
319
- }
320
- }
321
- removeNamespaces(ns) {
322
- const index = this.options.ns.indexOf(ns);
323
- if (index > -1) {
324
- this.options.ns.splice(index, 1);
325
- }
326
- }
327
- getResource(lng, ns, key, options = {}) {
328
- var _a, _b;
329
- const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
330
- const ignoreJSONStructure = options.ignoreJSONStructure !== void 0 ? options.ignoreJSONStructure : this.options.ignoreJSONStructure;
331
- let path;
332
- if (lng.indexOf(".") > -1) {
333
- path = lng.split(".");
334
- } else {
335
- path = [lng, ns];
336
- if (key) {
337
- if (Array.isArray(key)) {
338
- path.push(...key);
339
- } else if (isString$3(key) && keySeparator) {
340
- path.push(...key.split(keySeparator));
341
- } else {
342
- path.push(key);
343
- }
344
- }
345
- }
346
- const result = getPath$1(this.data, path);
347
- if (!result && !ns && !key && lng.indexOf(".") > -1) {
348
- lng = path[0];
349
- ns = path[1];
350
- key = path.slice(2).join(".");
351
- }
352
- if (result || !ignoreJSONStructure || !isString$3(key)) return result;
353
- return deepFind((_b = (_a = this.data) == null ? void 0 : _a[lng]) == null ? void 0 : _b[ns], key, keySeparator);
354
- }
355
- addResource(lng, ns, key, value, options = {
356
- silent: false
357
- }) {
358
- const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
359
- let path = [lng, ns];
360
- if (key) path = path.concat(keySeparator ? key.split(keySeparator) : key);
361
- if (lng.indexOf(".") > -1) {
362
- path = lng.split(".");
363
- value = ns;
364
- ns = path[1];
365
- }
366
- this.addNamespaces(ns);
367
- setPath(this.data, path, value);
368
- if (!options.silent) this.emit("added", lng, ns, key, value);
369
- }
370
- addResources(lng, ns, resources2, options = {
371
- silent: false
372
- }) {
373
- for (const m3 in resources2) {
374
- if (isString$3(resources2[m3]) || Array.isArray(resources2[m3])) this.addResource(lng, ns, m3, resources2[m3], {
375
- silent: true
376
- });
377
- }
378
- if (!options.silent) this.emit("added", lng, ns, resources2);
379
- }
380
- addResourceBundle(lng, ns, resources2, deep, overwrite, options = {
381
- silent: false,
382
- skipCopy: false
383
- }) {
384
- let path = [lng, ns];
385
- if (lng.indexOf(".") > -1) {
386
- path = lng.split(".");
387
- deep = resources2;
388
- resources2 = ns;
389
- ns = path[1];
390
- }
391
- this.addNamespaces(ns);
392
- let pack = getPath$1(this.data, path) || {};
393
- if (!options.skipCopy) resources2 = JSON.parse(JSON.stringify(resources2));
394
- if (deep) {
395
- deepExtend(pack, resources2, overwrite);
396
- } else {
397
- pack = {
398
- ...pack,
399
- ...resources2
400
- };
401
- }
402
- setPath(this.data, path, pack);
403
- if (!options.silent) this.emit("added", lng, ns, resources2);
404
- }
405
- removeResourceBundle(lng, ns) {
406
- if (this.hasResourceBundle(lng, ns)) {
407
- delete this.data[lng][ns];
408
- }
409
- this.removeNamespaces(ns);
410
- this.emit("removed", lng, ns);
411
- }
412
- hasResourceBundle(lng, ns) {
413
- return this.getResource(lng, ns) !== void 0;
414
- }
415
- getResourceBundle(lng, ns) {
416
- if (!ns) ns = this.options.defaultNS;
417
- return this.getResource(lng, ns);
418
- }
419
- getDataByLanguage(lng) {
420
- return this.data[lng];
421
- }
422
- hasLanguageSomeTranslations(lng) {
423
- const data = this.getDataByLanguage(lng);
424
- const n2 = data && Object.keys(data) || [];
425
- return !!n2.find((v) => data[v] && Object.keys(data[v]).length > 0);
426
- }
427
- toJSON() {
428
- return this.data;
429
- }
430
- }
431
- var postProcessor = {
432
- processors: {},
433
- addPostProcessor(module) {
434
- this.processors[module.name] = module;
435
- },
436
- handle(processors, value, key, options, translator) {
437
- processors.forEach((processor) => {
438
- var _a;
439
- value = ((_a = this.processors[processor]) == null ? void 0 : _a.process(value, key, options, translator)) ?? value;
440
- });
441
- return value;
442
- }
443
- };
444
- const PATH_KEY = Symbol("i18next/PATH_KEY");
445
- function createProxy$1() {
446
- const state = [];
447
- const handler = /* @__PURE__ */ Object.create(null);
448
- let proxy;
449
- handler.get = (target, key) => {
450
- var _a;
451
- (_a = proxy == null ? void 0 : proxy.revoke) == null ? void 0 : _a.call(proxy);
452
- if (key === PATH_KEY) return state;
453
- state.push(key);
454
- proxy = Proxy.revocable(target, handler);
455
- return proxy.proxy;
456
- };
457
- return Proxy.revocable(/* @__PURE__ */ Object.create(null), handler).proxy;
458
- }
459
- function keysFromSelector(selector, opts) {
460
- const {
461
- [PATH_KEY]: path
462
- } = selector(createProxy$1());
463
- return path.join((opts == null ? void 0 : opts.keySeparator) ?? ".");
464
- }
465
- const checkedLoadedFor = {};
466
- const shouldHandleAsObject = (res) => !isString$3(res) && typeof res !== "boolean" && typeof res !== "number";
467
- class Translator extends EventEmitter {
468
- constructor(services, options = {}) {
469
- super();
470
- copy(["resourceStore", "languageUtils", "pluralResolver", "interpolator", "backendConnector", "i18nFormat", "utils"], services, this);
471
- this.options = options;
472
- if (this.options.keySeparator === void 0) {
473
- this.options.keySeparator = ".";
474
- }
475
- this.logger = baseLogger.create("translator");
476
- }
477
- changeLanguage(lng) {
478
- if (lng) this.language = lng;
479
- }
480
- exists(key, o2 = {
481
- interpolation: {}
482
- }) {
483
- const opt = {
484
- ...o2
485
- };
486
- if (key == null) return false;
487
- const resolved = this.resolve(key, opt);
488
- if ((resolved == null ? void 0 : resolved.res) === void 0) return false;
489
- const isObject2 = shouldHandleAsObject(resolved.res);
490
- if (opt.returnObjects === false && isObject2) {
491
- return false;
492
- }
493
- return true;
494
- }
495
- extractFromKey(key, opt) {
496
- let nsSeparator = opt.nsSeparator !== void 0 ? opt.nsSeparator : this.options.nsSeparator;
497
- if (nsSeparator === void 0) nsSeparator = ":";
498
- const keySeparator = opt.keySeparator !== void 0 ? opt.keySeparator : this.options.keySeparator;
499
- let namespaces = opt.ns || this.options.defaultNS || [];
500
- const wouldCheckForNsInKey = nsSeparator && key.indexOf(nsSeparator) > -1;
501
- const seemsNaturalLanguage = !this.options.userDefinedKeySeparator && !opt.keySeparator && !this.options.userDefinedNsSeparator && !opt.nsSeparator && !looksLikeObjectPath(key, nsSeparator, keySeparator);
502
- if (wouldCheckForNsInKey && !seemsNaturalLanguage) {
503
- const m3 = key.match(this.interpolator.nestingRegexp);
504
- if (m3 && m3.length > 0) {
505
- return {
506
- key,
507
- namespaces: isString$3(namespaces) ? [namespaces] : namespaces
508
- };
509
- }
510
- const parts = key.split(nsSeparator);
511
- if (nsSeparator !== keySeparator || nsSeparator === keySeparator && this.options.ns.indexOf(parts[0]) > -1) namespaces = parts.shift();
512
- key = parts.join(keySeparator);
513
- }
514
- return {
515
- key,
516
- namespaces: isString$3(namespaces) ? [namespaces] : namespaces
517
- };
518
- }
519
- translate(keys, o2, lastKey) {
520
- let opt = typeof o2 === "object" ? {
521
- ...o2
522
- } : o2;
523
- if (typeof opt !== "object" && this.options.overloadTranslationOptionHandler) {
524
- opt = this.options.overloadTranslationOptionHandler(arguments);
525
- }
526
- if (typeof opt === "object") opt = {
527
- ...opt
528
- };
529
- if (!opt) opt = {};
530
- if (keys == null) return "";
531
- if (typeof keys === "function") keys = keysFromSelector(keys, {
532
- ...this.options,
533
- ...opt
534
- });
535
- if (!Array.isArray(keys)) keys = [String(keys)];
536
- const returnDetails = opt.returnDetails !== void 0 ? opt.returnDetails : this.options.returnDetails;
537
- const keySeparator = opt.keySeparator !== void 0 ? opt.keySeparator : this.options.keySeparator;
538
- const {
539
- key,
540
- namespaces
541
- } = this.extractFromKey(keys[keys.length - 1], opt);
542
- const namespace = namespaces[namespaces.length - 1];
543
- let nsSeparator = opt.nsSeparator !== void 0 ? opt.nsSeparator : this.options.nsSeparator;
544
- if (nsSeparator === void 0) nsSeparator = ":";
545
- const lng = opt.lng || this.language;
546
- const appendNamespaceToCIMode = opt.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode;
547
- if ((lng == null ? void 0 : lng.toLowerCase()) === "cimode") {
548
- if (appendNamespaceToCIMode) {
549
- if (returnDetails) {
550
- return {
551
- res: `${namespace}${nsSeparator}${key}`,
552
- usedKey: key,
553
- exactUsedKey: key,
554
- usedLng: lng,
555
- usedNS: namespace,
556
- usedParams: this.getUsedParamsDetails(opt)
557
- };
558
- }
559
- return `${namespace}${nsSeparator}${key}`;
560
- }
561
- if (returnDetails) {
562
- return {
563
- res: key,
564
- usedKey: key,
565
- exactUsedKey: key,
566
- usedLng: lng,
567
- usedNS: namespace,
568
- usedParams: this.getUsedParamsDetails(opt)
569
- };
570
- }
571
- return key;
572
- }
573
- const resolved = this.resolve(keys, opt);
574
- let res = resolved == null ? void 0 : resolved.res;
575
- const resUsedKey = (resolved == null ? void 0 : resolved.usedKey) || key;
576
- const resExactUsedKey = (resolved == null ? void 0 : resolved.exactUsedKey) || key;
577
- const noObject = ["[object Number]", "[object Function]", "[object RegExp]"];
578
- const joinArrays = opt.joinArrays !== void 0 ? opt.joinArrays : this.options.joinArrays;
579
- const handleAsObjectInI18nFormat = !this.i18nFormat || this.i18nFormat.handleAsObject;
580
- const needsPluralHandling = opt.count !== void 0 && !isString$3(opt.count);
581
- const hasDefaultValue = Translator.hasDefaultValue(opt);
582
- const defaultValueSuffix = needsPluralHandling ? this.pluralResolver.getSuffix(lng, opt.count, opt) : "";
583
- const defaultValueSuffixOrdinalFallback = opt.ordinal && needsPluralHandling ? this.pluralResolver.getSuffix(lng, opt.count, {
584
- ordinal: false
585
- }) : "";
586
- const needsZeroSuffixLookup = needsPluralHandling && !opt.ordinal && opt.count === 0;
587
- const defaultValue = needsZeroSuffixLookup && opt[`defaultValue${this.options.pluralSeparator}zero`] || opt[`defaultValue${defaultValueSuffix}`] || opt[`defaultValue${defaultValueSuffixOrdinalFallback}`] || opt.defaultValue;
588
- let resForObjHndl = res;
589
- if (handleAsObjectInI18nFormat && !res && hasDefaultValue) {
590
- resForObjHndl = defaultValue;
591
- }
592
- const handleAsObject = shouldHandleAsObject(resForObjHndl);
593
- const resType = Object.prototype.toString.apply(resForObjHndl);
594
- if (handleAsObjectInI18nFormat && resForObjHndl && handleAsObject && noObject.indexOf(resType) < 0 && !(isString$3(joinArrays) && Array.isArray(resForObjHndl))) {
595
- if (!opt.returnObjects && !this.options.returnObjects) {
596
- if (!this.options.returnedObjectHandler) {
597
- this.logger.warn("accessing an object - but returnObjects options is not enabled!");
598
- }
599
- const r2 = this.options.returnedObjectHandler ? this.options.returnedObjectHandler(resUsedKey, resForObjHndl, {
600
- ...opt,
601
- ns: namespaces
602
- }) : `key '${key} (${this.language})' returned an object instead of string.`;
603
- if (returnDetails) {
604
- resolved.res = r2;
605
- resolved.usedParams = this.getUsedParamsDetails(opt);
606
- return resolved;
607
- }
608
- return r2;
609
- }
610
- if (keySeparator) {
611
- const resTypeIsArray = Array.isArray(resForObjHndl);
612
- const copy2 = resTypeIsArray ? [] : {};
613
- const newKeyToUse = resTypeIsArray ? resExactUsedKey : resUsedKey;
614
- for (const m3 in resForObjHndl) {
615
- if (Object.prototype.hasOwnProperty.call(resForObjHndl, m3)) {
616
- const deepKey = `${newKeyToUse}${keySeparator}${m3}`;
617
- if (hasDefaultValue && !res) {
618
- copy2[m3] = this.translate(deepKey, {
619
- ...opt,
620
- defaultValue: shouldHandleAsObject(defaultValue) ? defaultValue[m3] : void 0,
621
- ...{
622
- joinArrays: false,
623
- ns: namespaces
624
- }
625
- });
626
- } else {
627
- copy2[m3] = this.translate(deepKey, {
628
- ...opt,
629
- ...{
630
- joinArrays: false,
631
- ns: namespaces
632
- }
633
- });
634
- }
635
- if (copy2[m3] === deepKey) copy2[m3] = resForObjHndl[m3];
636
- }
637
- }
638
- res = copy2;
639
- }
640
- } else if (handleAsObjectInI18nFormat && isString$3(joinArrays) && Array.isArray(res)) {
641
- res = res.join(joinArrays);
642
- if (res) res = this.extendTranslation(res, keys, opt, lastKey);
643
- } else {
644
- let usedDefault = false;
645
- let usedKey = false;
646
- if (!this.isValidLookup(res) && hasDefaultValue) {
647
- usedDefault = true;
648
- res = defaultValue;
649
- }
650
- if (!this.isValidLookup(res)) {
651
- usedKey = true;
652
- res = key;
653
- }
654
- const missingKeyNoValueFallbackToKey = opt.missingKeyNoValueFallbackToKey || this.options.missingKeyNoValueFallbackToKey;
655
- const resForMissing = missingKeyNoValueFallbackToKey && usedKey ? void 0 : res;
656
- const updateMissing = hasDefaultValue && defaultValue !== res && this.options.updateMissing;
657
- if (usedKey || usedDefault || updateMissing) {
658
- this.logger.log(updateMissing ? "updateKey" : "missingKey", lng, namespace, key, updateMissing ? defaultValue : res);
659
- if (keySeparator) {
660
- const fk = this.resolve(key, {
661
- ...opt,
662
- keySeparator: false
663
- });
664
- if (fk && fk.res) this.logger.warn("Seems the loaded translations were in flat JSON format instead of nested. Either set keySeparator: false on init or make sure your translations are published in nested format.");
665
- }
666
- let lngs = [];
667
- const fallbackLngs = this.languageUtils.getFallbackCodes(this.options.fallbackLng, opt.lng || this.language);
668
- if (this.options.saveMissingTo === "fallback" && fallbackLngs && fallbackLngs[0]) {
669
- for (let i3 = 0; i3 < fallbackLngs.length; i3++) {
670
- lngs.push(fallbackLngs[i3]);
671
- }
672
- } else if (this.options.saveMissingTo === "all") {
673
- lngs = this.languageUtils.toResolveHierarchy(opt.lng || this.language);
674
- } else {
675
- lngs.push(opt.lng || this.language);
676
- }
677
- const send = (l, k2, specificDefaultValue) => {
678
- var _a;
679
- const defaultForMissing = hasDefaultValue && specificDefaultValue !== res ? specificDefaultValue : resForMissing;
680
- if (this.options.missingKeyHandler) {
681
- this.options.missingKeyHandler(l, namespace, k2, defaultForMissing, updateMissing, opt);
682
- } else if ((_a = this.backendConnector) == null ? void 0 : _a.saveMissing) {
683
- this.backendConnector.saveMissing(l, namespace, k2, defaultForMissing, updateMissing, opt);
684
- }
685
- this.emit("missingKey", l, namespace, k2, res);
686
- };
687
- if (this.options.saveMissing) {
688
- if (this.options.saveMissingPlurals && needsPluralHandling) {
689
- lngs.forEach((language) => {
690
- const suffixes = this.pluralResolver.getSuffixes(language, opt);
691
- if (needsZeroSuffixLookup && opt[`defaultValue${this.options.pluralSeparator}zero`] && suffixes.indexOf(`${this.options.pluralSeparator}zero`) < 0) {
692
- suffixes.push(`${this.options.pluralSeparator}zero`);
693
- }
694
- suffixes.forEach((suffix) => {
695
- send([language], key + suffix, opt[`defaultValue${suffix}`] || defaultValue);
696
- });
697
- });
698
- } else {
699
- send(lngs, key, defaultValue);
700
- }
701
- }
702
- }
703
- res = this.extendTranslation(res, keys, opt, resolved, lastKey);
704
- if (usedKey && res === key && this.options.appendNamespaceToMissingKey) {
705
- res = `${namespace}${nsSeparator}${key}`;
706
- }
707
- if ((usedKey || usedDefault) && this.options.parseMissingKeyHandler) {
708
- res = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? `${namespace}${nsSeparator}${key}` : key, usedDefault ? res : void 0, opt);
709
- }
710
- }
711
- if (returnDetails) {
712
- resolved.res = res;
713
- resolved.usedParams = this.getUsedParamsDetails(opt);
714
- return resolved;
715
- }
716
- return res;
717
- }
718
- extendTranslation(res, key, opt, resolved, lastKey) {
719
- var _a, _b;
720
- if ((_a = this.i18nFormat) == null ? void 0 : _a.parse) {
721
- res = this.i18nFormat.parse(res, {
722
- ...this.options.interpolation.defaultVariables,
723
- ...opt
724
- }, opt.lng || this.language || resolved.usedLng, resolved.usedNS, resolved.usedKey, {
725
- resolved
726
- });
727
- } else if (!opt.skipInterpolation) {
728
- if (opt.interpolation) this.interpolator.init({
729
- ...opt,
730
- ...{
731
- interpolation: {
732
- ...this.options.interpolation,
733
- ...opt.interpolation
734
- }
735
- }
736
- });
737
- const skipOnVariables = isString$3(res) && (((_b = opt == null ? void 0 : opt.interpolation) == null ? void 0 : _b.skipOnVariables) !== void 0 ? opt.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables);
738
- let nestBef;
739
- if (skipOnVariables) {
740
- const nb = res.match(this.interpolator.nestingRegexp);
741
- nestBef = nb && nb.length;
742
- }
743
- let data = opt.replace && !isString$3(opt.replace) ? opt.replace : opt;
744
- if (this.options.interpolation.defaultVariables) data = {
745
- ...this.options.interpolation.defaultVariables,
746
- ...data
747
- };
748
- res = this.interpolator.interpolate(res, data, opt.lng || this.language || resolved.usedLng, opt);
749
- if (skipOnVariables) {
750
- const na = res.match(this.interpolator.nestingRegexp);
751
- const nestAft = na && na.length;
752
- if (nestBef < nestAft) opt.nest = false;
753
- }
754
- if (!opt.lng && resolved && resolved.res) opt.lng = this.language || resolved.usedLng;
755
- if (opt.nest !== false) res = this.interpolator.nest(res, (...args) => {
756
- if ((lastKey == null ? void 0 : lastKey[0]) === args[0] && !opt.context) {
757
- this.logger.warn(`It seems you are nesting recursively key: ${args[0]} in key: ${key[0]}`);
758
- return null;
759
- }
760
- return this.translate(...args, key);
761
- }, opt);
762
- if (opt.interpolation) this.interpolator.reset();
763
- }
764
- const postProcess = opt.postProcess || this.options.postProcess;
765
- const postProcessorNames = isString$3(postProcess) ? [postProcess] : postProcess;
766
- if (res != null && (postProcessorNames == null ? void 0 : postProcessorNames.length) && opt.applyPostProcessor !== false) {
767
- res = postProcessor.handle(postProcessorNames, res, key, this.options && this.options.postProcessPassResolved ? {
768
- i18nResolved: {
769
- ...resolved,
770
- usedParams: this.getUsedParamsDetails(opt)
771
- },
772
- ...opt
773
- } : opt, this);
774
- }
775
- return res;
776
- }
777
- resolve(keys, opt = {}) {
778
- let found;
779
- let usedKey;
780
- let exactUsedKey;
781
- let usedLng;
782
- let usedNS;
783
- if (isString$3(keys)) keys = [keys];
784
- keys.forEach((k2) => {
785
- if (this.isValidLookup(found)) return;
786
- const extracted = this.extractFromKey(k2, opt);
787
- const key = extracted.key;
788
- usedKey = key;
789
- let namespaces = extracted.namespaces;
790
- if (this.options.fallbackNS) namespaces = namespaces.concat(this.options.fallbackNS);
791
- const needsPluralHandling = opt.count !== void 0 && !isString$3(opt.count);
792
- const needsZeroSuffixLookup = needsPluralHandling && !opt.ordinal && opt.count === 0;
793
- const needsContextHandling = opt.context !== void 0 && (isString$3(opt.context) || typeof opt.context === "number") && opt.context !== "";
794
- const codes = opt.lngs ? opt.lngs : this.languageUtils.toResolveHierarchy(opt.lng || this.language, opt.fallbackLng);
795
- namespaces.forEach((ns) => {
796
- var _a, _b;
797
- if (this.isValidLookup(found)) return;
798
- usedNS = ns;
799
- if (!checkedLoadedFor[`${codes[0]}-${ns}`] && ((_a = this.utils) == null ? void 0 : _a.hasLoadedNamespace) && !((_b = this.utils) == null ? void 0 : _b.hasLoadedNamespace(usedNS))) {
800
- checkedLoadedFor[`${codes[0]}-${ns}`] = true;
801
- this.logger.warn(`key "${usedKey}" for languages "${codes.join(", ")}" won't get resolved as namespace "${usedNS}" was not yet loaded`, "This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!");
802
- }
803
- codes.forEach((code) => {
804
- var _a2;
805
- if (this.isValidLookup(found)) return;
806
- usedLng = code;
807
- const finalKeys = [key];
808
- if ((_a2 = this.i18nFormat) == null ? void 0 : _a2.addLookupKeys) {
809
- this.i18nFormat.addLookupKeys(finalKeys, key, code, ns, opt);
810
- } else {
811
- let pluralSuffix;
812
- if (needsPluralHandling) pluralSuffix = this.pluralResolver.getSuffix(code, opt.count, opt);
813
- const zeroSuffix = `${this.options.pluralSeparator}zero`;
814
- const ordinalPrefix = `${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;
815
- if (needsPluralHandling) {
816
- if (opt.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
817
- finalKeys.push(key + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
818
- }
819
- finalKeys.push(key + pluralSuffix);
820
- if (needsZeroSuffixLookup) {
821
- finalKeys.push(key + zeroSuffix);
822
- }
823
- }
824
- if (needsContextHandling) {
825
- const contextKey = `${key}${this.options.contextSeparator || "_"}${opt.context}`;
826
- finalKeys.push(contextKey);
827
- if (needsPluralHandling) {
828
- if (opt.ordinal && pluralSuffix.indexOf(ordinalPrefix) === 0) {
829
- finalKeys.push(contextKey + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
830
- }
831
- finalKeys.push(contextKey + pluralSuffix);
832
- if (needsZeroSuffixLookup) {
833
- finalKeys.push(contextKey + zeroSuffix);
834
- }
835
- }
836
- }
837
- }
838
- let possibleKey;
839
- while (possibleKey = finalKeys.pop()) {
840
- if (!this.isValidLookup(found)) {
841
- exactUsedKey = possibleKey;
842
- found = this.getResource(code, ns, possibleKey, opt);
843
- }
844
- }
845
- });
846
- });
847
- });
848
- return {
849
- res: found,
850
- usedKey,
851
- exactUsedKey,
852
- usedLng,
853
- usedNS
854
- };
855
- }
856
- isValidLookup(res) {
857
- return res !== void 0 && !(!this.options.returnNull && res === null) && !(!this.options.returnEmptyString && res === "");
858
- }
859
- getResource(code, ns, key, options = {}) {
860
- var _a;
861
- if ((_a = this.i18nFormat) == null ? void 0 : _a.getResource) return this.i18nFormat.getResource(code, ns, key, options);
862
- return this.resourceStore.getResource(code, ns, key, options);
863
- }
864
- getUsedParamsDetails(options = {}) {
865
- const optionsKeys = ["defaultValue", "ordinal", "context", "replace", "lng", "lngs", "fallbackLng", "ns", "keySeparator", "nsSeparator", "returnObjects", "returnDetails", "joinArrays", "postProcess", "interpolation"];
866
- const useOptionsReplaceForData = options.replace && !isString$3(options.replace);
867
- let data = useOptionsReplaceForData ? options.replace : options;
868
- if (useOptionsReplaceForData && typeof options.count !== "undefined") {
869
- data.count = options.count;
870
- }
871
- if (this.options.interpolation.defaultVariables) {
872
- data = {
873
- ...this.options.interpolation.defaultVariables,
874
- ...data
875
- };
876
- }
877
- if (!useOptionsReplaceForData) {
878
- data = {
879
- ...data
880
- };
881
- for (const key of optionsKeys) {
882
- delete data[key];
883
- }
884
- }
885
- return data;
886
- }
887
- static hasDefaultValue(options) {
888
- const prefix = "defaultValue";
889
- for (const option in options) {
890
- if (Object.prototype.hasOwnProperty.call(options, option) && prefix === option.substring(0, prefix.length) && void 0 !== options[option]) {
891
- return true;
892
- }
893
- }
894
- return false;
895
- }
896
- }
897
- class LanguageUtil {
898
- constructor(options) {
899
- this.options = options;
900
- this.supportedLngs = this.options.supportedLngs || false;
901
- this.logger = baseLogger.create("languageUtils");
902
- }
903
- getScriptPartFromCode(code) {
904
- code = getCleanedCode(code);
905
- if (!code || code.indexOf("-") < 0) return null;
906
- const p = code.split("-");
907
- if (p.length === 2) return null;
908
- p.pop();
909
- if (p[p.length - 1].toLowerCase() === "x") return null;
910
- return this.formatLanguageCode(p.join("-"));
911
- }
912
- getLanguagePartFromCode(code) {
913
- code = getCleanedCode(code);
914
- if (!code || code.indexOf("-") < 0) return code;
915
- const p = code.split("-");
916
- return this.formatLanguageCode(p[0]);
917
- }
918
- formatLanguageCode(code) {
919
- if (isString$3(code) && code.indexOf("-") > -1) {
920
- let formattedCode;
921
- try {
922
- formattedCode = Intl.getCanonicalLocales(code)[0];
923
- } catch (e2) {
924
- }
925
- if (formattedCode && this.options.lowerCaseLng) {
926
- formattedCode = formattedCode.toLowerCase();
927
- }
928
- if (formattedCode) return formattedCode;
929
- if (this.options.lowerCaseLng) {
930
- return code.toLowerCase();
931
- }
932
- return code;
933
- }
934
- return this.options.cleanCode || this.options.lowerCaseLng ? code.toLowerCase() : code;
935
- }
936
- isSupportedCode(code) {
937
- if (this.options.load === "languageOnly" || this.options.nonExplicitSupportedLngs) {
938
- code = this.getLanguagePartFromCode(code);
939
- }
940
- return !this.supportedLngs || !this.supportedLngs.length || this.supportedLngs.indexOf(code) > -1;
941
- }
942
- getBestMatchFromCodes(codes) {
943
- if (!codes) return null;
944
- let found;
945
- codes.forEach((code) => {
946
- if (found) return;
947
- const cleanedLng = this.formatLanguageCode(code);
948
- if (!this.options.supportedLngs || this.isSupportedCode(cleanedLng)) found = cleanedLng;
949
- });
950
- if (!found && this.options.supportedLngs) {
951
- codes.forEach((code) => {
952
- if (found) return;
953
- const lngScOnly = this.getScriptPartFromCode(code);
954
- if (this.isSupportedCode(lngScOnly)) return found = lngScOnly;
955
- const lngOnly = this.getLanguagePartFromCode(code);
956
- if (this.isSupportedCode(lngOnly)) return found = lngOnly;
957
- found = this.options.supportedLngs.find((supportedLng) => {
958
- if (supportedLng === lngOnly) return supportedLng;
959
- if (supportedLng.indexOf("-") < 0 && lngOnly.indexOf("-") < 0) return;
960
- if (supportedLng.indexOf("-") > 0 && lngOnly.indexOf("-") < 0 && supportedLng.substring(0, supportedLng.indexOf("-")) === lngOnly) return supportedLng;
961
- if (supportedLng.indexOf(lngOnly) === 0 && lngOnly.length > 1) return supportedLng;
962
- });
963
- });
964
- }
965
- if (!found) found = this.getFallbackCodes(this.options.fallbackLng)[0];
966
- return found;
967
- }
968
- getFallbackCodes(fallbacks, code) {
969
- if (!fallbacks) return [];
970
- if (typeof fallbacks === "function") fallbacks = fallbacks(code);
971
- if (isString$3(fallbacks)) fallbacks = [fallbacks];
972
- if (Array.isArray(fallbacks)) return fallbacks;
973
- if (!code) return fallbacks.default || [];
974
- let found = fallbacks[code];
975
- if (!found) found = fallbacks[this.getScriptPartFromCode(code)];
976
- if (!found) found = fallbacks[this.formatLanguageCode(code)];
977
- if (!found) found = fallbacks[this.getLanguagePartFromCode(code)];
978
- if (!found) found = fallbacks.default;
979
- return found || [];
980
- }
981
- toResolveHierarchy(code, fallbackCode) {
982
- const fallbackCodes = this.getFallbackCodes((fallbackCode === false ? [] : fallbackCode) || this.options.fallbackLng || [], code);
983
- const codes = [];
984
- const addCode = (c2) => {
985
- if (!c2) return;
986
- if (this.isSupportedCode(c2)) {
987
- codes.push(c2);
988
- } else {
989
- this.logger.warn(`rejecting language code not found in supportedLngs: ${c2}`);
990
- }
991
- };
992
- if (isString$3(code) && (code.indexOf("-") > -1 || code.indexOf("_") > -1)) {
993
- if (this.options.load !== "languageOnly") addCode(this.formatLanguageCode(code));
994
- if (this.options.load !== "languageOnly" && this.options.load !== "currentOnly") addCode(this.getScriptPartFromCode(code));
995
- if (this.options.load !== "currentOnly") addCode(this.getLanguagePartFromCode(code));
996
- } else if (isString$3(code)) {
997
- addCode(this.formatLanguageCode(code));
998
- }
999
- fallbackCodes.forEach((fc) => {
1000
- if (codes.indexOf(fc) < 0) addCode(this.formatLanguageCode(fc));
1001
- });
1002
- return codes;
1003
- }
1004
- }
1005
- const suffixesOrder = {
1006
- zero: 0,
1007
- one: 1,
1008
- two: 2,
1009
- few: 3,
1010
- many: 4,
1011
- other: 5
1012
- };
1013
- const dummyRule = {
1014
- select: (count) => count === 1 ? "one" : "other",
1015
- resolvedOptions: () => ({
1016
- pluralCategories: ["one", "other"]
1017
- })
1018
- };
1019
- class PluralResolver {
1020
- constructor(languageUtils, options = {}) {
1021
- this.languageUtils = languageUtils;
1022
- this.options = options;
1023
- this.logger = baseLogger.create("pluralResolver");
1024
- this.pluralRulesCache = {};
1025
- }
1026
- addRule(lng, obj) {
1027
- this.rules[lng] = obj;
1028
- }
1029
- clearCache() {
1030
- this.pluralRulesCache = {};
1031
- }
1032
- getRule(code, options = {}) {
1033
- const cleanedCode = getCleanedCode(code === "dev" ? "en" : code);
1034
- const type = options.ordinal ? "ordinal" : "cardinal";
1035
- const cacheKey = JSON.stringify({
1036
- cleanedCode,
1037
- type
1038
- });
1039
- if (cacheKey in this.pluralRulesCache) {
1040
- return this.pluralRulesCache[cacheKey];
1041
- }
1042
- let rule;
1043
- try {
1044
- rule = new Intl.PluralRules(cleanedCode, {
1045
- type
1046
- });
1047
- } catch (err) {
1048
- if (!Intl) {
1049
- this.logger.error("No Intl support, please use an Intl polyfill!");
1050
- return dummyRule;
1051
- }
1052
- if (!code.match(/-|_/)) return dummyRule;
1053
- const lngPart = this.languageUtils.getLanguagePartFromCode(code);
1054
- rule = this.getRule(lngPart, options);
1055
- }
1056
- this.pluralRulesCache[cacheKey] = rule;
1057
- return rule;
1058
- }
1059
- needsPlural(code, options = {}) {
1060
- let rule = this.getRule(code, options);
1061
- if (!rule) rule = this.getRule("dev", options);
1062
- return (rule == null ? void 0 : rule.resolvedOptions().pluralCategories.length) > 1;
1063
- }
1064
- getPluralFormsOfKey(code, key, options = {}) {
1065
- return this.getSuffixes(code, options).map((suffix) => `${key}${suffix}`);
1066
- }
1067
- getSuffixes(code, options = {}) {
1068
- let rule = this.getRule(code, options);
1069
- if (!rule) rule = this.getRule("dev", options);
1070
- if (!rule) return [];
1071
- return rule.resolvedOptions().pluralCategories.sort((pluralCategory1, pluralCategory2) => suffixesOrder[pluralCategory1] - suffixesOrder[pluralCategory2]).map((pluralCategory) => `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ""}${pluralCategory}`);
1072
- }
1073
- getSuffix(code, count, options = {}) {
1074
- const rule = this.getRule(code, options);
1075
- if (rule) {
1076
- return `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ""}${rule.select(count)}`;
1077
- }
1078
- this.logger.warn(`no plural rule found for: ${code}`);
1079
- return this.getSuffix("dev", count, options);
1080
- }
1081
- }
1082
- const deepFindWithDefaults = (data, defaultData, key, keySeparator = ".", ignoreJSONStructure = true) => {
1083
- let path = getPathWithDefaults(data, defaultData, key);
1084
- if (!path && ignoreJSONStructure && isString$3(key)) {
1085
- path = deepFind(data, key, keySeparator);
1086
- if (path === void 0) path = deepFind(defaultData, key, keySeparator);
1087
- }
1088
- return path;
1089
- };
1090
- const regexSafe = (val) => val.replace(/\$/g, "$$$$");
1091
- class Interpolator {
1092
- constructor(options = {}) {
1093
- var _a;
1094
- this.logger = baseLogger.create("interpolator");
1095
- this.options = options;
1096
- this.format = ((_a = options == null ? void 0 : options.interpolation) == null ? void 0 : _a.format) || ((value) => value);
1097
- this.init(options);
1098
- }
1099
- init(options = {}) {
1100
- if (!options.interpolation) options.interpolation = {
1101
- escapeValue: true
1102
- };
1103
- const {
1104
- escape: escape$1,
1105
- escapeValue,
1106
- useRawValueToEscape,
1107
- prefix,
1108
- prefixEscaped,
1109
- suffix,
1110
- suffixEscaped,
1111
- formatSeparator,
1112
- unescapeSuffix,
1113
- unescapePrefix,
1114
- nestingPrefix,
1115
- nestingPrefixEscaped,
1116
- nestingSuffix,
1117
- nestingSuffixEscaped,
1118
- nestingOptionsSeparator,
1119
- maxReplaces,
1120
- alwaysFormat
1121
- } = options.interpolation;
1122
- this.escape = escape$1 !== void 0 ? escape$1 : escape;
1123
- this.escapeValue = escapeValue !== void 0 ? escapeValue : true;
1124
- this.useRawValueToEscape = useRawValueToEscape !== void 0 ? useRawValueToEscape : false;
1125
- this.prefix = prefix ? regexEscape(prefix) : prefixEscaped || "{{";
1126
- this.suffix = suffix ? regexEscape(suffix) : suffixEscaped || "}}";
1127
- this.formatSeparator = formatSeparator || ",";
1128
- this.unescapePrefix = unescapeSuffix ? "" : unescapePrefix || "-";
1129
- this.unescapeSuffix = this.unescapePrefix ? "" : unescapeSuffix || "";
1130
- this.nestingPrefix = nestingPrefix ? regexEscape(nestingPrefix) : nestingPrefixEscaped || regexEscape("$t(");
1131
- this.nestingSuffix = nestingSuffix ? regexEscape(nestingSuffix) : nestingSuffixEscaped || regexEscape(")");
1132
- this.nestingOptionsSeparator = nestingOptionsSeparator || ",";
1133
- this.maxReplaces = maxReplaces || 1e3;
1134
- this.alwaysFormat = alwaysFormat !== void 0 ? alwaysFormat : false;
1135
- this.resetRegExp();
1136
- }
1137
- reset() {
1138
- if (this.options) this.init(this.options);
1139
- }
1140
- resetRegExp() {
1141
- const getOrResetRegExp = (existingRegExp, pattern) => {
1142
- if ((existingRegExp == null ? void 0 : existingRegExp.source) === pattern) {
1143
- existingRegExp.lastIndex = 0;
1144
- return existingRegExp;
1145
- }
1146
- return new RegExp(pattern, "g");
1147
- };
1148
- this.regexp = getOrResetRegExp(this.regexp, `${this.prefix}(.+?)${this.suffix}`);
1149
- this.regexpUnescape = getOrResetRegExp(this.regexpUnescape, `${this.prefix}${this.unescapePrefix}(.+?)${this.unescapeSuffix}${this.suffix}`);
1150
- this.nestingRegexp = getOrResetRegExp(this.nestingRegexp, `${this.nestingPrefix}((?:[^()"']+|"[^"]*"|'[^']*'|\\((?:[^()]|"[^"]*"|'[^']*')*\\))*?)${this.nestingSuffix}`);
1151
- }
1152
- interpolate(str, data, lng, options) {
1153
- var _a;
1154
- let match2;
1155
- let value;
1156
- let replaces;
1157
- const defaultData = this.options && this.options.interpolation && this.options.interpolation.defaultVariables || {};
1158
- const handleFormat = (key) => {
1159
- if (key.indexOf(this.formatSeparator) < 0) {
1160
- const path = deepFindWithDefaults(data, defaultData, key, this.options.keySeparator, this.options.ignoreJSONStructure);
1161
- return this.alwaysFormat ? this.format(path, void 0, lng, {
1162
- ...options,
1163
- ...data,
1164
- interpolationkey: key
1165
- }) : path;
1166
- }
1167
- const p = key.split(this.formatSeparator);
1168
- const k2 = p.shift().trim();
1169
- const f = p.join(this.formatSeparator).trim();
1170
- return this.format(deepFindWithDefaults(data, defaultData, k2, this.options.keySeparator, this.options.ignoreJSONStructure), f, lng, {
1171
- ...options,
1172
- ...data,
1173
- interpolationkey: k2
1174
- });
1175
- };
1176
- this.resetRegExp();
1177
- const missingInterpolationHandler = (options == null ? void 0 : options.missingInterpolationHandler) || this.options.missingInterpolationHandler;
1178
- const skipOnVariables = ((_a = options == null ? void 0 : options.interpolation) == null ? void 0 : _a.skipOnVariables) !== void 0 ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables;
1179
- const todos = [{
1180
- regex: this.regexpUnescape,
1181
- safeValue: (val) => regexSafe(val)
1182
- }, {
1183
- regex: this.regexp,
1184
- safeValue: (val) => this.escapeValue ? regexSafe(this.escape(val)) : regexSafe(val)
1185
- }];
1186
- todos.forEach((todo) => {
1187
- replaces = 0;
1188
- while (match2 = todo.regex.exec(str)) {
1189
- const matchedVar = match2[1].trim();
1190
- value = handleFormat(matchedVar);
1191
- if (value === void 0) {
1192
- if (typeof missingInterpolationHandler === "function") {
1193
- const temp = missingInterpolationHandler(str, match2, options);
1194
- value = isString$3(temp) ? temp : "";
1195
- } else if (options && Object.prototype.hasOwnProperty.call(options, matchedVar)) {
1196
- value = "";
1197
- } else if (skipOnVariables) {
1198
- value = match2[0];
1199
- continue;
1200
- } else {
1201
- this.logger.warn(`missed to pass in variable ${matchedVar} for interpolating ${str}`);
1202
- value = "";
1203
- }
1204
- } else if (!isString$3(value) && !this.useRawValueToEscape) {
1205
- value = makeString(value);
1206
- }
1207
- const safeValue = todo.safeValue(value);
1208
- str = str.replace(match2[0], safeValue);
1209
- if (skipOnVariables) {
1210
- todo.regex.lastIndex += value.length;
1211
- todo.regex.lastIndex -= match2[0].length;
1212
- } else {
1213
- todo.regex.lastIndex = 0;
1214
- }
1215
- replaces++;
1216
- if (replaces >= this.maxReplaces) {
1217
- break;
1218
- }
1219
- }
1220
- });
1221
- return str;
1222
- }
1223
- nest(str, fc, options = {}) {
1224
- let match2;
1225
- let value;
1226
- let clonedOptions;
1227
- const handleHasOptions = (key, inheritedOptions) => {
1228
- const sep = this.nestingOptionsSeparator;
1229
- if (key.indexOf(sep) < 0) return key;
1230
- const c2 = key.split(new RegExp(`${sep}[ ]*{`));
1231
- let optionsString = `{${c2[1]}`;
1232
- key = c2[0];
1233
- optionsString = this.interpolate(optionsString, clonedOptions);
1234
- const matchedSingleQuotes = optionsString.match(/'/g);
1235
- const matchedDoubleQuotes = optionsString.match(/"/g);
1236
- if (((matchedSingleQuotes == null ? void 0 : matchedSingleQuotes.length) ?? 0) % 2 === 0 && !matchedDoubleQuotes || matchedDoubleQuotes.length % 2 !== 0) {
1237
- optionsString = optionsString.replace(/'/g, '"');
1238
- }
1239
- try {
1240
- clonedOptions = JSON.parse(optionsString);
1241
- if (inheritedOptions) clonedOptions = {
1242
- ...inheritedOptions,
1243
- ...clonedOptions
1244
- };
1245
- } catch (e2) {
1246
- this.logger.warn(`failed parsing options string in nesting for key ${key}`, e2);
1247
- return `${key}${sep}${optionsString}`;
1248
- }
1249
- if (clonedOptions.defaultValue && clonedOptions.defaultValue.indexOf(this.prefix) > -1) delete clonedOptions.defaultValue;
1250
- return key;
1251
- };
1252
- while (match2 = this.nestingRegexp.exec(str)) {
1253
- let formatters2 = [];
1254
- clonedOptions = {
1255
- ...options
1256
- };
1257
- clonedOptions = clonedOptions.replace && !isString$3(clonedOptions.replace) ? clonedOptions.replace : clonedOptions;
1258
- clonedOptions.applyPostProcessor = false;
1259
- delete clonedOptions.defaultValue;
1260
- const keyEndIndex = /{.*}/.test(match2[1]) ? match2[1].lastIndexOf("}") + 1 : match2[1].indexOf(this.formatSeparator);
1261
- if (keyEndIndex !== -1) {
1262
- formatters2 = match2[1].slice(keyEndIndex).split(this.formatSeparator).map((elem) => elem.trim()).filter(Boolean);
1263
- match2[1] = match2[1].slice(0, keyEndIndex);
1264
- }
1265
- value = fc(handleHasOptions.call(this, match2[1].trim(), clonedOptions), clonedOptions);
1266
- if (value && match2[0] === str && !isString$3(value)) return value;
1267
- if (!isString$3(value)) value = makeString(value);
1268
- if (!value) {
1269
- this.logger.warn(`missed to resolve ${match2[1]} for nesting ${str}`);
1270
- value = "";
1271
- }
1272
- if (formatters2.length) {
1273
- value = formatters2.reduce((v, f) => this.format(v, f, options.lng, {
1274
- ...options,
1275
- interpolationkey: match2[1].trim()
1276
- }), value.trim());
1277
- }
1278
- str = str.replace(match2[0], value);
1279
- this.regexp.lastIndex = 0;
1280
- }
1281
- return str;
1282
- }
1283
- }
1284
- const parseFormatStr = (formatStr) => {
1285
- let formatName = formatStr.toLowerCase().trim();
1286
- const formatOptions = {};
1287
- if (formatStr.indexOf("(") > -1) {
1288
- const p = formatStr.split("(");
1289
- formatName = p[0].toLowerCase().trim();
1290
- const optStr = p[1].substring(0, p[1].length - 1);
1291
- if (formatName === "currency" && optStr.indexOf(":") < 0) {
1292
- if (!formatOptions.currency) formatOptions.currency = optStr.trim();
1293
- } else if (formatName === "relativetime" && optStr.indexOf(":") < 0) {
1294
- if (!formatOptions.range) formatOptions.range = optStr.trim();
1295
- } else {
1296
- const opts = optStr.split(";");
1297
- opts.forEach((opt) => {
1298
- if (opt) {
1299
- const [key, ...rest] = opt.split(":");
1300
- const val = rest.join(":").trim().replace(/^'+|'+$/g, "");
1301
- const trimmedKey = key.trim();
1302
- if (!formatOptions[trimmedKey]) formatOptions[trimmedKey] = val;
1303
- if (val === "false") formatOptions[trimmedKey] = false;
1304
- if (val === "true") formatOptions[trimmedKey] = true;
1305
- if (!isNaN(val)) formatOptions[trimmedKey] = parseInt(val, 10);
1306
- }
1307
- });
1308
- }
1309
- }
1310
- return {
1311
- formatName,
1312
- formatOptions
1313
- };
1314
- };
1315
- const createCachedFormatter = (fn2) => {
1316
- const cache = {};
1317
- return (v, l, o2) => {
1318
- let optForCache = o2;
1319
- if (o2 && o2.interpolationkey && o2.formatParams && o2.formatParams[o2.interpolationkey] && o2[o2.interpolationkey]) {
1320
- optForCache = {
1321
- ...optForCache,
1322
- [o2.interpolationkey]: void 0
1323
- };
1324
- }
1325
- const key = l + JSON.stringify(optForCache);
1326
- let frm = cache[key];
1327
- if (!frm) {
1328
- frm = fn2(getCleanedCode(l), o2);
1329
- cache[key] = frm;
1330
- }
1331
- return frm(v);
1332
- };
1333
- };
1334
- const createNonCachedFormatter = (fn2) => (v, l, o2) => fn2(getCleanedCode(l), o2)(v);
1335
- class Formatter {
1336
- constructor(options = {}) {
1337
- this.logger = baseLogger.create("formatter");
1338
- this.options = options;
1339
- this.init(options);
1340
- }
1341
- init(services, options = {
1342
- interpolation: {}
1343
- }) {
1344
- this.formatSeparator = options.interpolation.formatSeparator || ",";
1345
- const cf = options.cacheInBuiltFormats ? createCachedFormatter : createNonCachedFormatter;
1346
- this.formats = {
1347
- number: cf((lng, opt) => {
1348
- const formatter = new Intl.NumberFormat(lng, {
1349
- ...opt
1350
- });
1351
- return (val) => formatter.format(val);
1352
- }),
1353
- currency: cf((lng, opt) => {
1354
- const formatter = new Intl.NumberFormat(lng, {
1355
- ...opt,
1356
- style: "currency"
1357
- });
1358
- return (val) => formatter.format(val);
1359
- }),
1360
- datetime: cf((lng, opt) => {
1361
- const formatter = new Intl.DateTimeFormat(lng, {
1362
- ...opt
1363
- });
1364
- return (val) => formatter.format(val);
1365
- }),
1366
- relativetime: cf((lng, opt) => {
1367
- const formatter = new Intl.RelativeTimeFormat(lng, {
1368
- ...opt
1369
- });
1370
- return (val) => formatter.format(val, opt.range || "day");
1371
- }),
1372
- list: cf((lng, opt) => {
1373
- const formatter = new Intl.ListFormat(lng, {
1374
- ...opt
1375
- });
1376
- return (val) => formatter.format(val);
1377
- })
1378
- };
1379
- }
1380
- add(name, fc) {
1381
- this.formats[name.toLowerCase().trim()] = fc;
1382
- }
1383
- addCached(name, fc) {
1384
- this.formats[name.toLowerCase().trim()] = createCachedFormatter(fc);
1385
- }
1386
- format(value, format2, lng, options = {}) {
1387
- const formats = format2.split(this.formatSeparator);
1388
- if (formats.length > 1 && formats[0].indexOf("(") > 1 && formats[0].indexOf(")") < 0 && formats.find((f) => f.indexOf(")") > -1)) {
1389
- const lastIndex = formats.findIndex((f) => f.indexOf(")") > -1);
1390
- formats[0] = [formats[0], ...formats.splice(1, lastIndex)].join(this.formatSeparator);
1391
- }
1392
- const result = formats.reduce((mem, f) => {
1393
- var _a;
1394
- const {
1395
- formatName,
1396
- formatOptions
1397
- } = parseFormatStr(f);
1398
- if (this.formats[formatName]) {
1399
- let formatted = mem;
1400
- try {
1401
- const valOptions = ((_a = options == null ? void 0 : options.formatParams) == null ? void 0 : _a[options.interpolationkey]) || {};
1402
- const l = valOptions.locale || valOptions.lng || options.locale || options.lng || lng;
1403
- formatted = this.formats[formatName](mem, l, {
1404
- ...formatOptions,
1405
- ...options,
1406
- ...valOptions
1407
- });
1408
- } catch (error) {
1409
- this.logger.warn(error);
1410
- }
1411
- return formatted;
1412
- } else {
1413
- this.logger.warn(`there was no format function for ${formatName}`);
1414
- }
1415
- return mem;
1416
- }, value);
1417
- return result;
1418
- }
1419
- }
1420
- const removePending = (q2, name) => {
1421
- if (q2.pending[name] !== void 0) {
1422
- delete q2.pending[name];
1423
- q2.pendingCount--;
1424
- }
1425
- };
1426
- class Connector extends EventEmitter {
1427
- constructor(backend, store, services, options = {}) {
1428
- var _a, _b;
1429
- super();
1430
- this.backend = backend;
1431
- this.store = store;
1432
- this.services = services;
1433
- this.languageUtils = services.languageUtils;
1434
- this.options = options;
1435
- this.logger = baseLogger.create("backendConnector");
1436
- this.waitingReads = [];
1437
- this.maxParallelReads = options.maxParallelReads || 10;
1438
- this.readingCalls = 0;
1439
- this.maxRetries = options.maxRetries >= 0 ? options.maxRetries : 5;
1440
- this.retryTimeout = options.retryTimeout >= 1 ? options.retryTimeout : 350;
1441
- this.state = {};
1442
- this.queue = [];
1443
- (_b = (_a = this.backend) == null ? void 0 : _a.init) == null ? void 0 : _b.call(_a, services, options.backend, options);
1444
- }
1445
- queueLoad(languages, namespaces, options, callback) {
1446
- const toLoad = {};
1447
- const pending = {};
1448
- const toLoadLanguages = {};
1449
- const toLoadNamespaces = {};
1450
- languages.forEach((lng) => {
1451
- let hasAllNamespaces = true;
1452
- namespaces.forEach((ns) => {
1453
- const name = `${lng}|${ns}`;
1454
- if (!options.reload && this.store.hasResourceBundle(lng, ns)) {
1455
- this.state[name] = 2;
1456
- } else if (this.state[name] < 0) ;
1457
- else if (this.state[name] === 1) {
1458
- if (pending[name] === void 0) pending[name] = true;
1459
- } else {
1460
- this.state[name] = 1;
1461
- hasAllNamespaces = false;
1462
- if (pending[name] === void 0) pending[name] = true;
1463
- if (toLoad[name] === void 0) toLoad[name] = true;
1464
- if (toLoadNamespaces[ns] === void 0) toLoadNamespaces[ns] = true;
1465
- }
1466
- });
1467
- if (!hasAllNamespaces) toLoadLanguages[lng] = true;
1468
- });
1469
- if (Object.keys(toLoad).length || Object.keys(pending).length) {
1470
- this.queue.push({
1471
- pending,
1472
- pendingCount: Object.keys(pending).length,
1473
- loaded: {},
1474
- errors: [],
1475
- callback
1476
- });
1477
- }
1478
- return {
1479
- toLoad: Object.keys(toLoad),
1480
- pending: Object.keys(pending),
1481
- toLoadLanguages: Object.keys(toLoadLanguages),
1482
- toLoadNamespaces: Object.keys(toLoadNamespaces)
1483
- };
1484
- }
1485
- loaded(name, err, data) {
1486
- const s4 = name.split("|");
1487
- const lng = s4[0];
1488
- const ns = s4[1];
1489
- if (err) this.emit("failedLoading", lng, ns, err);
1490
- if (!err && data) {
1491
- this.store.addResourceBundle(lng, ns, data, void 0, void 0, {
1492
- skipCopy: true
1493
- });
1494
- }
1495
- this.state[name] = err ? -1 : 2;
1496
- if (err && data) this.state[name] = 0;
1497
- const loaded = {};
1498
- this.queue.forEach((q2) => {
1499
- pushPath(q2.loaded, [lng], ns);
1500
- removePending(q2, name);
1501
- if (err) q2.errors.push(err);
1502
- if (q2.pendingCount === 0 && !q2.done) {
1503
- Object.keys(q2.loaded).forEach((l) => {
1504
- if (!loaded[l]) loaded[l] = {};
1505
- const loadedKeys = q2.loaded[l];
1506
- if (loadedKeys.length) {
1507
- loadedKeys.forEach((n2) => {
1508
- if (loaded[l][n2] === void 0) loaded[l][n2] = true;
1509
- });
1510
- }
1511
- });
1512
- q2.done = true;
1513
- if (q2.errors.length) {
1514
- q2.callback(q2.errors);
1515
- } else {
1516
- q2.callback();
1517
- }
1518
- }
1519
- });
1520
- this.emit("loaded", loaded);
1521
- this.queue = this.queue.filter((q2) => !q2.done);
1522
- }
1523
- read(lng, ns, fcName, tried = 0, wait = this.retryTimeout, callback) {
1524
- if (!lng.length) return callback(null, {});
1525
- if (this.readingCalls >= this.maxParallelReads) {
1526
- this.waitingReads.push({
1527
- lng,
1528
- ns,
1529
- fcName,
1530
- tried,
1531
- wait,
1532
- callback
1533
- });
1534
- return;
1535
- }
1536
- this.readingCalls++;
1537
- const resolver = (err, data) => {
1538
- this.readingCalls--;
1539
- if (this.waitingReads.length > 0) {
1540
- const next = this.waitingReads.shift();
1541
- this.read(next.lng, next.ns, next.fcName, next.tried, next.wait, next.callback);
1542
- }
1543
- if (err && data && tried < this.maxRetries) {
1544
- setTimeout(() => {
1545
- this.read.call(this, lng, ns, fcName, tried + 1, wait * 2, callback);
1546
- }, wait);
1547
- return;
1548
- }
1549
- callback(err, data);
1550
- };
1551
- const fc = this.backend[fcName].bind(this.backend);
1552
- if (fc.length === 2) {
1553
- try {
1554
- const r2 = fc(lng, ns);
1555
- if (r2 && typeof r2.then === "function") {
1556
- r2.then((data) => resolver(null, data)).catch(resolver);
1557
- } else {
1558
- resolver(null, r2);
1559
- }
1560
- } catch (err) {
1561
- resolver(err);
1562
- }
1563
- return;
1564
- }
1565
- return fc(lng, ns, resolver);
1566
- }
1567
- prepareLoading(languages, namespaces, options = {}, callback) {
1568
- if (!this.backend) {
1569
- this.logger.warn("No backend was added via i18next.use. Will not load resources.");
1570
- return callback && callback();
1571
- }
1572
- if (isString$3(languages)) languages = this.languageUtils.toResolveHierarchy(languages);
1573
- if (isString$3(namespaces)) namespaces = [namespaces];
1574
- const toLoad = this.queueLoad(languages, namespaces, options, callback);
1575
- if (!toLoad.toLoad.length) {
1576
- if (!toLoad.pending.length) callback();
1577
- return null;
1578
- }
1579
- toLoad.toLoad.forEach((name) => {
1580
- this.loadOne(name);
1581
- });
1582
- }
1583
- load(languages, namespaces, callback) {
1584
- this.prepareLoading(languages, namespaces, {}, callback);
1585
- }
1586
- reload(languages, namespaces, callback) {
1587
- this.prepareLoading(languages, namespaces, {
1588
- reload: true
1589
- }, callback);
1590
- }
1591
- loadOne(name, prefix = "") {
1592
- const s4 = name.split("|");
1593
- const lng = s4[0];
1594
- const ns = s4[1];
1595
- this.read(lng, ns, "read", void 0, void 0, (err, data) => {
1596
- if (err) this.logger.warn(`${prefix}loading namespace ${ns} for language ${lng} failed`, err);
1597
- if (!err && data) this.logger.log(`${prefix}loaded namespace ${ns} for language ${lng}`, data);
1598
- this.loaded(name, err, data);
1599
- });
1600
- }
1601
- saveMissing(languages, namespace, key, fallbackValue, isUpdate, options = {}, clb = () => {
1602
- }) {
1603
- var _a, _b, _c, _d, _e;
1604
- if (((_b = (_a = this.services) == null ? void 0 : _a.utils) == null ? void 0 : _b.hasLoadedNamespace) && !((_d = (_c = this.services) == null ? void 0 : _c.utils) == null ? void 0 : _d.hasLoadedNamespace(namespace))) {
1605
- this.logger.warn(`did not save key "${key}" as the namespace "${namespace}" was not yet loaded`, "This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!");
1606
- return;
1607
- }
1608
- if (key === void 0 || key === null || key === "") return;
1609
- if ((_e = this.backend) == null ? void 0 : _e.create) {
1610
- const opts = {
1611
- ...options,
1612
- isUpdate
1613
- };
1614
- const fc = this.backend.create.bind(this.backend);
1615
- if (fc.length < 6) {
1616
- try {
1617
- let r2;
1618
- if (fc.length === 5) {
1619
- r2 = fc(languages, namespace, key, fallbackValue, opts);
1620
- } else {
1621
- r2 = fc(languages, namespace, key, fallbackValue);
1622
- }
1623
- if (r2 && typeof r2.then === "function") {
1624
- r2.then((data) => clb(null, data)).catch(clb);
1625
- } else {
1626
- clb(null, r2);
1627
- }
1628
- } catch (err) {
1629
- clb(err);
1630
- }
1631
- } else {
1632
- fc(languages, namespace, key, fallbackValue, clb, opts);
1633
- }
1634
- }
1635
- if (!languages || !languages[0]) return;
1636
- this.store.addResource(languages[0], namespace, key, fallbackValue);
1637
- }
1638
- }
1639
- const get$1 = () => ({
1640
- debug: false,
1641
- initAsync: true,
1642
- ns: ["translation"],
1643
- defaultNS: ["translation"],
1644
- fallbackLng: ["dev"],
1645
- fallbackNS: false,
1646
- supportedLngs: false,
1647
- nonExplicitSupportedLngs: false,
1648
- load: "all",
1649
- preload: false,
1650
- simplifyPluralSuffix: true,
1651
- keySeparator: ".",
1652
- nsSeparator: ":",
1653
- pluralSeparator: "_",
1654
- contextSeparator: "_",
1655
- partialBundledLanguages: false,
1656
- saveMissing: false,
1657
- updateMissing: false,
1658
- saveMissingTo: "fallback",
1659
- saveMissingPlurals: true,
1660
- missingKeyHandler: false,
1661
- missingInterpolationHandler: false,
1662
- postProcess: false,
1663
- postProcessPassResolved: false,
1664
- returnNull: false,
1665
- returnEmptyString: true,
1666
- returnObjects: false,
1667
- joinArrays: false,
1668
- returnedObjectHandler: false,
1669
- parseMissingKeyHandler: false,
1670
- appendNamespaceToMissingKey: false,
1671
- appendNamespaceToCIMode: false,
1672
- overloadTranslationOptionHandler: (args) => {
1673
- let ret = {};
1674
- if (typeof args[1] === "object") ret = args[1];
1675
- if (isString$3(args[1])) ret.defaultValue = args[1];
1676
- if (isString$3(args[2])) ret.tDescription = args[2];
1677
- if (typeof args[2] === "object" || typeof args[3] === "object") {
1678
- const options = args[3] || args[2];
1679
- Object.keys(options).forEach((key) => {
1680
- ret[key] = options[key];
1681
- });
1682
- }
1683
- return ret;
1684
- },
1685
- interpolation: {
1686
- escapeValue: true,
1687
- format: (value) => value,
1688
- prefix: "{{",
1689
- suffix: "}}",
1690
- formatSeparator: ",",
1691
- unescapePrefix: "-",
1692
- nestingPrefix: "$t(",
1693
- nestingSuffix: ")",
1694
- nestingOptionsSeparator: ",",
1695
- maxReplaces: 1e3,
1696
- skipOnVariables: true
1697
- },
1698
- cacheInBuiltFormats: true
1699
- });
1700
- const transformOptions = (options) => {
1701
- var _a, _b;
1702
- if (isString$3(options.ns)) options.ns = [options.ns];
1703
- if (isString$3(options.fallbackLng)) options.fallbackLng = [options.fallbackLng];
1704
- if (isString$3(options.fallbackNS)) options.fallbackNS = [options.fallbackNS];
1705
- if (((_b = (_a = options.supportedLngs) == null ? void 0 : _a.indexOf) == null ? void 0 : _b.call(_a, "cimode")) < 0) {
1706
- options.supportedLngs = options.supportedLngs.concat(["cimode"]);
1707
- }
1708
- if (typeof options.initImmediate === "boolean") options.initAsync = options.initImmediate;
1709
- return options;
1710
- };
1711
- const noop$5 = () => {
1712
- };
1713
- const bindMemberFunctions = (inst) => {
1714
- const mems = Object.getOwnPropertyNames(Object.getPrototypeOf(inst));
1715
- mems.forEach((mem) => {
1716
- if (typeof inst[mem] === "function") {
1717
- inst[mem] = inst[mem].bind(inst);
1718
- }
1719
- });
1720
- };
1721
- class I18n extends EventEmitter {
1722
- constructor(options = {}, callback) {
1723
- super();
1724
- this.options = transformOptions(options);
1725
- this.services = {};
1726
- this.logger = baseLogger;
1727
- this.modules = {
1728
- external: []
1729
- };
1730
- bindMemberFunctions(this);
1731
- if (callback && !this.isInitialized && !options.isClone) {
1732
- if (!this.options.initAsync) {
1733
- this.init(options, callback);
1734
- return this;
1735
- }
1736
- setTimeout(() => {
1737
- this.init(options, callback);
1738
- }, 0);
1739
- }
1740
- }
1741
- init(options = {}, callback) {
1742
- this.isInitializing = true;
1743
- if (typeof options === "function") {
1744
- callback = options;
1745
- options = {};
1746
- }
1747
- if (options.defaultNS == null && options.ns) {
1748
- if (isString$3(options.ns)) {
1749
- options.defaultNS = options.ns;
1750
- } else if (options.ns.indexOf("translation") < 0) {
1751
- options.defaultNS = options.ns[0];
1752
- }
1753
- }
1754
- const defOpts = get$1();
1755
- this.options = {
1756
- ...defOpts,
1757
- ...this.options,
1758
- ...transformOptions(options)
1759
- };
1760
- this.options.interpolation = {
1761
- ...defOpts.interpolation,
1762
- ...this.options.interpolation
1763
- };
1764
- if (options.keySeparator !== void 0) {
1765
- this.options.userDefinedKeySeparator = options.keySeparator;
1766
- }
1767
- if (options.nsSeparator !== void 0) {
1768
- this.options.userDefinedNsSeparator = options.nsSeparator;
1769
- }
1770
- const createClassOnDemand = (ClassOrObject) => {
1771
- if (!ClassOrObject) return null;
1772
- if (typeof ClassOrObject === "function") return new ClassOrObject();
1773
- return ClassOrObject;
1774
- };
1775
- if (!this.options.isClone) {
1776
- if (this.modules.logger) {
1777
- baseLogger.init(createClassOnDemand(this.modules.logger), this.options);
1778
- } else {
1779
- baseLogger.init(null, this.options);
1780
- }
1781
- let formatter;
1782
- if (this.modules.formatter) {
1783
- formatter = this.modules.formatter;
1784
- } else {
1785
- formatter = Formatter;
1786
- }
1787
- const lu = new LanguageUtil(this.options);
1788
- this.store = new ResourceStore(this.options.resources, this.options);
1789
- const s4 = this.services;
1790
- s4.logger = baseLogger;
1791
- s4.resourceStore = this.store;
1792
- s4.languageUtils = lu;
1793
- s4.pluralResolver = new PluralResolver(lu, {
1794
- prepend: this.options.pluralSeparator,
1795
- simplifyPluralSuffix: this.options.simplifyPluralSuffix
1796
- });
1797
- const usingLegacyFormatFunction = this.options.interpolation.format && this.options.interpolation.format !== defOpts.interpolation.format;
1798
- if (usingLegacyFormatFunction) {
1799
- this.logger.deprecate(`init: you are still using the legacy format function, please use the new approach: https://www.i18next.com/translation-function/formatting`);
1800
- }
1801
- if (formatter && (!this.options.interpolation.format || this.options.interpolation.format === defOpts.interpolation.format)) {
1802
- s4.formatter = createClassOnDemand(formatter);
1803
- if (s4.formatter.init) s4.formatter.init(s4, this.options);
1804
- this.options.interpolation.format = s4.formatter.format.bind(s4.formatter);
1805
- }
1806
- s4.interpolator = new Interpolator(this.options);
1807
- s4.utils = {
1808
- hasLoadedNamespace: this.hasLoadedNamespace.bind(this)
1809
- };
1810
- s4.backendConnector = new Connector(createClassOnDemand(this.modules.backend), s4.resourceStore, s4, this.options);
1811
- s4.backendConnector.on("*", (event, ...args) => {
1812
- this.emit(event, ...args);
1813
- });
1814
- if (this.modules.languageDetector) {
1815
- s4.languageDetector = createClassOnDemand(this.modules.languageDetector);
1816
- if (s4.languageDetector.init) s4.languageDetector.init(s4, this.options.detection, this.options);
1817
- }
1818
- if (this.modules.i18nFormat) {
1819
- s4.i18nFormat = createClassOnDemand(this.modules.i18nFormat);
1820
- if (s4.i18nFormat.init) s4.i18nFormat.init(this);
1821
- }
1822
- this.translator = new Translator(this.services, this.options);
1823
- this.translator.on("*", (event, ...args) => {
1824
- this.emit(event, ...args);
1825
- });
1826
- this.modules.external.forEach((m3) => {
1827
- if (m3.init) m3.init(this);
1828
- });
1829
- }
1830
- this.format = this.options.interpolation.format;
1831
- if (!callback) callback = noop$5;
1832
- if (this.options.fallbackLng && !this.services.languageDetector && !this.options.lng) {
1833
- const codes = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
1834
- if (codes.length > 0 && codes[0] !== "dev") this.options.lng = codes[0];
1835
- }
1836
- if (!this.services.languageDetector && !this.options.lng) {
1837
- this.logger.warn("init: no languageDetector is used and no lng is defined");
1838
- }
1839
- const storeApi = ["getResource", "hasResourceBundle", "getResourceBundle", "getDataByLanguage"];
1840
- storeApi.forEach((fcName) => {
1841
- this[fcName] = (...args) => this.store[fcName](...args);
1842
- });
1843
- const storeApiChained = ["addResource", "addResources", "addResourceBundle", "removeResourceBundle"];
1844
- storeApiChained.forEach((fcName) => {
1845
- this[fcName] = (...args) => {
1846
- this.store[fcName](...args);
1847
- return this;
1848
- };
1849
- });
1850
- const deferred = defer();
1851
- const load = () => {
1852
- const finish = (err, t2) => {
1853
- this.isInitializing = false;
1854
- if (this.isInitialized && !this.initializedStoreOnce) this.logger.warn("init: i18next is already initialized. You should call init just once!");
1855
- this.isInitialized = true;
1856
- if (!this.options.isClone) this.logger.log("initialized", this.options);
1857
- this.emit("initialized", this.options);
1858
- deferred.resolve(t2);
1859
- callback(err, t2);
1860
- };
1861
- if (this.languages && !this.isInitialized) return finish(null, this.t.bind(this));
1862
- this.changeLanguage(this.options.lng, finish);
1863
- };
1864
- if (this.options.resources || !this.options.initAsync) {
1865
- load();
1866
- } else {
1867
- setTimeout(load, 0);
1868
- }
1869
- return deferred;
1870
- }
1871
- loadResources(language, callback = noop$5) {
1872
- var _a, _b;
1873
- let usedCallback = callback;
1874
- const usedLng = isString$3(language) ? language : this.language;
1875
- if (typeof language === "function") usedCallback = language;
1876
- if (!this.options.resources || this.options.partialBundledLanguages) {
1877
- if ((usedLng == null ? void 0 : usedLng.toLowerCase()) === "cimode" && (!this.options.preload || this.options.preload.length === 0)) return usedCallback();
1878
- const toLoad = [];
1879
- const append2 = (lng) => {
1880
- if (!lng) return;
1881
- if (lng === "cimode") return;
1882
- const lngs = this.services.languageUtils.toResolveHierarchy(lng);
1883
- lngs.forEach((l) => {
1884
- if (l === "cimode") return;
1885
- if (toLoad.indexOf(l) < 0) toLoad.push(l);
1886
- });
1887
- };
1888
- if (!usedLng) {
1889
- const fallbacks = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
1890
- fallbacks.forEach((l) => append2(l));
1891
- } else {
1892
- append2(usedLng);
1893
- }
1894
- (_b = (_a = this.options.preload) == null ? void 0 : _a.forEach) == null ? void 0 : _b.call(_a, (l) => append2(l));
1895
- this.services.backendConnector.load(toLoad, this.options.ns, (e2) => {
1896
- if (!e2 && !this.resolvedLanguage && this.language) this.setResolvedLanguage(this.language);
1897
- usedCallback(e2);
1898
- });
1899
- } else {
1900
- usedCallback(null);
1901
- }
1902
- }
1903
- reloadResources(lngs, ns, callback) {
1904
- const deferred = defer();
1905
- if (typeof lngs === "function") {
1906
- callback = lngs;
1907
- lngs = void 0;
1908
- }
1909
- if (typeof ns === "function") {
1910
- callback = ns;
1911
- ns = void 0;
1912
- }
1913
- if (!lngs) lngs = this.languages;
1914
- if (!ns) ns = this.options.ns;
1915
- if (!callback) callback = noop$5;
1916
- this.services.backendConnector.reload(lngs, ns, (err) => {
1917
- deferred.resolve();
1918
- callback(err);
1919
- });
1920
- return deferred;
1921
- }
1922
- use(module) {
1923
- if (!module) throw new Error("You are passing an undefined module! Please check the object you are passing to i18next.use()");
1924
- if (!module.type) throw new Error("You are passing a wrong module! Please check the object you are passing to i18next.use()");
1925
- if (module.type === "backend") {
1926
- this.modules.backend = module;
1927
- }
1928
- if (module.type === "logger" || module.log && module.warn && module.error) {
1929
- this.modules.logger = module;
1930
- }
1931
- if (module.type === "languageDetector") {
1932
- this.modules.languageDetector = module;
1933
- }
1934
- if (module.type === "i18nFormat") {
1935
- this.modules.i18nFormat = module;
1936
- }
1937
- if (module.type === "postProcessor") {
1938
- postProcessor.addPostProcessor(module);
1939
- }
1940
- if (module.type === "formatter") {
1941
- this.modules.formatter = module;
1942
- }
1943
- if (module.type === "3rdParty") {
1944
- this.modules.external.push(module);
1945
- }
1946
- return this;
1947
- }
1948
- setResolvedLanguage(l) {
1949
- if (!l || !this.languages) return;
1950
- if (["cimode", "dev"].indexOf(l) > -1) return;
1951
- for (let li = 0; li < this.languages.length; li++) {
1952
- const lngInLngs = this.languages[li];
1953
- if (["cimode", "dev"].indexOf(lngInLngs) > -1) continue;
1954
- if (this.store.hasLanguageSomeTranslations(lngInLngs)) {
1955
- this.resolvedLanguage = lngInLngs;
1956
- break;
1957
- }
1958
- }
1959
- if (!this.resolvedLanguage && this.languages.indexOf(l) < 0 && this.store.hasLanguageSomeTranslations(l)) {
1960
- this.resolvedLanguage = l;
1961
- this.languages.unshift(l);
1962
- }
1963
- }
1964
- changeLanguage(lng, callback) {
1965
- this.isLanguageChangingTo = lng;
1966
- const deferred = defer();
1967
- this.emit("languageChanging", lng);
1968
- const setLngProps = (l) => {
1969
- this.language = l;
1970
- this.languages = this.services.languageUtils.toResolveHierarchy(l);
1971
- this.resolvedLanguage = void 0;
1972
- this.setResolvedLanguage(l);
1973
- };
1974
- const done = (err, l) => {
1975
- if (l) {
1976
- if (this.isLanguageChangingTo === lng) {
1977
- setLngProps(l);
1978
- this.translator.changeLanguage(l);
1979
- this.isLanguageChangingTo = void 0;
1980
- this.emit("languageChanged", l);
1981
- this.logger.log("languageChanged", l);
1982
- }
1983
- } else {
1984
- this.isLanguageChangingTo = void 0;
1985
- }
1986
- deferred.resolve((...args) => this.t(...args));
1987
- if (callback) callback(err, (...args) => this.t(...args));
1988
- };
1989
- const setLng = (lngs) => {
1990
- var _a, _b;
1991
- if (!lng && !lngs && this.services.languageDetector) lngs = [];
1992
- const fl = isString$3(lngs) ? lngs : lngs && lngs[0];
1993
- const l = this.store.hasLanguageSomeTranslations(fl) ? fl : this.services.languageUtils.getBestMatchFromCodes(isString$3(lngs) ? [lngs] : lngs);
1994
- if (l) {
1995
- if (!this.language) {
1996
- setLngProps(l);
1997
- }
1998
- if (!this.translator.language) this.translator.changeLanguage(l);
1999
- (_b = (_a = this.services.languageDetector) == null ? void 0 : _a.cacheUserLanguage) == null ? void 0 : _b.call(_a, l);
2000
- }
2001
- this.loadResources(l, (err) => {
2002
- done(err, l);
2003
- });
2004
- };
2005
- if (!lng && this.services.languageDetector && !this.services.languageDetector.async) {
2006
- setLng(this.services.languageDetector.detect());
2007
- } else if (!lng && this.services.languageDetector && this.services.languageDetector.async) {
2008
- if (this.services.languageDetector.detect.length === 0) {
2009
- this.services.languageDetector.detect().then(setLng);
2010
- } else {
2011
- this.services.languageDetector.detect(setLng);
2012
- }
2013
- } else {
2014
- setLng(lng);
2015
- }
2016
- return deferred;
2017
- }
2018
- getFixedT(lng, ns, keyPrefix) {
2019
- const fixedT = (key, opts, ...rest) => {
2020
- let o2;
2021
- if (typeof opts !== "object") {
2022
- o2 = this.options.overloadTranslationOptionHandler([key, opts].concat(rest));
2023
- } else {
2024
- o2 = {
2025
- ...opts
2026
- };
2027
- }
2028
- o2.lng = o2.lng || fixedT.lng;
2029
- o2.lngs = o2.lngs || fixedT.lngs;
2030
- o2.ns = o2.ns || fixedT.ns;
2031
- if (o2.keyPrefix !== "") o2.keyPrefix = o2.keyPrefix || keyPrefix || fixedT.keyPrefix;
2032
- const keySeparator = this.options.keySeparator || ".";
2033
- let resultKey;
2034
- if (o2.keyPrefix && Array.isArray(key)) {
2035
- resultKey = key.map((k2) => {
2036
- if (typeof k2 === "function") k2 = keysFromSelector(k2, {
2037
- ...this.options,
2038
- ...opts
2039
- });
2040
- return `${o2.keyPrefix}${keySeparator}${k2}`;
2041
- });
2042
- } else {
2043
- if (typeof key === "function") key = keysFromSelector(key, {
2044
- ...this.options,
2045
- ...opts
2046
- });
2047
- resultKey = o2.keyPrefix ? `${o2.keyPrefix}${keySeparator}${key}` : key;
2048
- }
2049
- return this.t(resultKey, o2);
2050
- };
2051
- if (isString$3(lng)) {
2052
- fixedT.lng = lng;
2053
- } else {
2054
- fixedT.lngs = lng;
2055
- }
2056
- fixedT.ns = ns;
2057
- fixedT.keyPrefix = keyPrefix;
2058
- return fixedT;
2059
- }
2060
- t(...args) {
2061
- var _a;
2062
- return (_a = this.translator) == null ? void 0 : _a.translate(...args);
2063
- }
2064
- exists(...args) {
2065
- var _a;
2066
- return (_a = this.translator) == null ? void 0 : _a.exists(...args);
2067
- }
2068
- setDefaultNamespace(ns) {
2069
- this.options.defaultNS = ns;
2070
- }
2071
- hasLoadedNamespace(ns, options = {}) {
2072
- if (!this.isInitialized) {
2073
- this.logger.warn("hasLoadedNamespace: i18next was not initialized", this.languages);
2074
- return false;
2075
- }
2076
- if (!this.languages || !this.languages.length) {
2077
- this.logger.warn("hasLoadedNamespace: i18n.languages were undefined or empty", this.languages);
2078
- return false;
2079
- }
2080
- const lng = options.lng || this.resolvedLanguage || this.languages[0];
2081
- const fallbackLng = this.options ? this.options.fallbackLng : false;
2082
- const lastLng = this.languages[this.languages.length - 1];
2083
- if (lng.toLowerCase() === "cimode") return true;
2084
- const loadNotPending = (l, n2) => {
2085
- const loadState = this.services.backendConnector.state[`${l}|${n2}`];
2086
- return loadState === -1 || loadState === 0 || loadState === 2;
2087
- };
2088
- if (options.precheck) {
2089
- const preResult = options.precheck(this, loadNotPending);
2090
- if (preResult !== void 0) return preResult;
2091
- }
2092
- if (this.hasResourceBundle(lng, ns)) return true;
2093
- if (!this.services.backendConnector.backend || this.options.resources && !this.options.partialBundledLanguages) return true;
2094
- if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
2095
- return false;
2096
- }
2097
- loadNamespaces(ns, callback) {
2098
- const deferred = defer();
2099
- if (!this.options.ns) {
2100
- if (callback) callback();
2101
- return Promise.resolve();
2102
- }
2103
- if (isString$3(ns)) ns = [ns];
2104
- ns.forEach((n2) => {
2105
- if (this.options.ns.indexOf(n2) < 0) this.options.ns.push(n2);
2106
- });
2107
- this.loadResources((err) => {
2108
- deferred.resolve();
2109
- if (callback) callback(err);
2110
- });
2111
- return deferred;
2112
- }
2113
- loadLanguages(lngs, callback) {
2114
- const deferred = defer();
2115
- if (isString$3(lngs)) lngs = [lngs];
2116
- const preloaded = this.options.preload || [];
2117
- const newLngs = lngs.filter((lng) => preloaded.indexOf(lng) < 0 && this.services.languageUtils.isSupportedCode(lng));
2118
- if (!newLngs.length) {
2119
- if (callback) callback();
2120
- return Promise.resolve();
2121
- }
2122
- this.options.preload = preloaded.concat(newLngs);
2123
- this.loadResources((err) => {
2124
- deferred.resolve();
2125
- if (callback) callback(err);
2126
- });
2127
- return deferred;
2128
- }
2129
- dir(lng) {
2130
- var _a, _b;
2131
- if (!lng) lng = this.resolvedLanguage || (((_a = this.languages) == null ? void 0 : _a.length) > 0 ? this.languages[0] : this.language);
2132
- if (!lng) return "rtl";
2133
- try {
2134
- const l = new Intl.Locale(lng);
2135
- if (l && l.getTextInfo) {
2136
- const ti = l.getTextInfo();
2137
- if (ti && ti.direction) return ti.direction;
2138
- }
2139
- } catch (e2) {
2140
- }
2141
- const rtlLngs = ["ar", "shu", "sqr", "ssh", "xaa", "yhd", "yud", "aao", "abh", "abv", "acm", "acq", "acw", "acx", "acy", "adf", "ads", "aeb", "aec", "afb", "ajp", "apc", "apd", "arb", "arq", "ars", "ary", "arz", "auz", "avl", "ayh", "ayl", "ayn", "ayp", "bbz", "pga", "he", "iw", "ps", "pbt", "pbu", "pst", "prp", "prd", "ug", "ur", "ydd", "yds", "yih", "ji", "yi", "hbo", "men", "xmn", "fa", "jpr", "peo", "pes", "prs", "dv", "sam", "ckb"];
2142
- const languageUtils = ((_b = this.services) == null ? void 0 : _b.languageUtils) || new LanguageUtil(get$1());
2143
- if (lng.toLowerCase().indexOf("-latn") > 1) return "ltr";
2144
- return rtlLngs.indexOf(languageUtils.getLanguagePartFromCode(lng)) > -1 || lng.toLowerCase().indexOf("-arab") > 1 ? "rtl" : "ltr";
2145
- }
2146
- static createInstance(options = {}, callback) {
2147
- return new I18n(options, callback);
2148
- }
2149
- cloneInstance(options = {}, callback = noop$5) {
2150
- const forkResourceStore = options.forkResourceStore;
2151
- if (forkResourceStore) delete options.forkResourceStore;
2152
- const mergedOptions = {
2153
- ...this.options,
2154
- ...options,
2155
- ...{
2156
- isClone: true
2157
- }
2158
- };
2159
- const clone2 = new I18n(mergedOptions);
2160
- if (options.debug !== void 0 || options.prefix !== void 0) {
2161
- clone2.logger = clone2.logger.clone(options);
2162
- }
2163
- const membersToCopy = ["store", "services", "language"];
2164
- membersToCopy.forEach((m3) => {
2165
- clone2[m3] = this[m3];
2166
- });
2167
- clone2.services = {
2168
- ...this.services
2169
- };
2170
- clone2.services.utils = {
2171
- hasLoadedNamespace: clone2.hasLoadedNamespace.bind(clone2)
2172
- };
2173
- if (forkResourceStore) {
2174
- const clonedData = Object.keys(this.store.data).reduce((prev, l) => {
2175
- prev[l] = {
2176
- ...this.store.data[l]
2177
- };
2178
- prev[l] = Object.keys(prev[l]).reduce((acc, n2) => {
2179
- acc[n2] = {
2180
- ...prev[l][n2]
2181
- };
2182
- return acc;
2183
- }, prev[l]);
2184
- return prev;
2185
- }, {});
2186
- clone2.store = new ResourceStore(clonedData, mergedOptions);
2187
- clone2.services.resourceStore = clone2.store;
2188
- }
2189
- clone2.translator = new Translator(clone2.services, mergedOptions);
2190
- clone2.translator.on("*", (event, ...args) => {
2191
- clone2.emit(event, ...args);
2192
- });
2193
- clone2.init(mergedOptions, callback);
2194
- clone2.translator.options = mergedOptions;
2195
- clone2.translator.backendConnector.services.utils = {
2196
- hasLoadedNamespace: clone2.hasLoadedNamespace.bind(clone2)
2197
- };
2198
- return clone2;
2199
- }
2200
- toJSON() {
2201
- return {
2202
- options: this.options,
2203
- store: this.store,
2204
- language: this.language,
2205
- languages: this.languages,
2206
- resolvedLanguage: this.resolvedLanguage
2207
- };
2208
- }
2209
- }
2210
- const instance = I18n.createInstance();
2211
- instance.createInstance = I18n.createInstance;
2212
- instance.createInstance;
2213
- instance.dir;
2214
- instance.init;
2215
- instance.loadResources;
2216
- instance.reloadResources;
2217
- instance.use;
2218
- instance.changeLanguage;
2219
- instance.getFixedT;
2220
- instance.t;
2221
- instance.exists;
2222
- instance.setDefaultNamespace;
2223
- instance.hasLoadedNamespace;
2224
- instance.loadNamespaces;
2225
- instance.loadLanguages;
2226
- var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
2227
- function getDefaultExportFromCjs(x2) {
2228
- return x2 && x2.__esModule && Object.prototype.hasOwnProperty.call(x2, "default") ? x2["default"] : x2;
2229
- }
2230
- const warn = (i18n, code, msg, rest) => {
2231
- var _a, _b, _c, _d;
2232
- const args = [msg, {
2233
- code,
2234
- ...rest || {}
2235
- }];
2236
- if ((_b = (_a = i18n == null ? void 0 : i18n.services) == null ? void 0 : _a.logger) == null ? void 0 : _b.forward) {
2237
- return i18n.services.logger.forward(args, "warn", "react-i18next::", true);
2238
- }
2239
- if (isString$2(args[0])) args[0] = `react-i18next:: ${args[0]}`;
2240
- if ((_d = (_c = i18n == null ? void 0 : i18n.services) == null ? void 0 : _c.logger) == null ? void 0 : _d.warn) {
2241
- i18n.services.logger.warn(...args);
2242
- } else if (console == null ? void 0 : console.warn) {
2243
- console.warn(...args);
2244
- }
2245
- };
2246
- const alreadyWarned = {};
2247
- const warnOnce = (i18n, code, msg, rest) => {
2248
- if (isString$2(msg) && alreadyWarned[msg]) return;
2249
- if (isString$2(msg)) alreadyWarned[msg] = /* @__PURE__ */ new Date();
2250
- warn(i18n, code, msg, rest);
2251
- };
2252
- const loadedClb = (i18n, cb) => () => {
2253
- if (i18n.isInitialized) {
2254
- cb();
2255
- } else {
2256
- const initialized = () => {
2257
- setTimeout(() => {
2258
- i18n.off("initialized", initialized);
2259
- }, 0);
2260
- cb();
2261
- };
2262
- i18n.on("initialized", initialized);
2263
- }
2264
- };
2265
- const loadNamespaces = (i18n, ns, cb) => {
2266
- i18n.loadNamespaces(ns, loadedClb(i18n, cb));
2267
- };
2268
- const loadLanguages = (i18n, lng, ns, cb) => {
2269
- if (isString$2(ns)) ns = [ns];
2270
- if (i18n.options.preload && i18n.options.preload.indexOf(lng) > -1) return loadNamespaces(i18n, ns, cb);
2271
- ns.forEach((n2) => {
2272
- if (i18n.options.ns.indexOf(n2) < 0) i18n.options.ns.push(n2);
2273
- });
2274
- i18n.loadLanguages(lng, loadedClb(i18n, cb));
2275
- };
2276
- const hasLoadedNamespace = (ns, i18n, options = {}) => {
2277
- if (!i18n.languages || !i18n.languages.length) {
2278
- warnOnce(i18n, "NO_LANGUAGES", "i18n.languages were undefined or empty", {
2279
- languages: i18n.languages
2280
- });
2281
- return true;
2282
- }
2283
- return i18n.hasLoadedNamespace(ns, {
2284
- lng: options.lng,
2285
- precheck: (i18nInstance2, loadNotPending) => {
2286
- if (options.bindI18n && options.bindI18n.indexOf("languageChanging") > -1 && i18nInstance2.services.backendConnector.backend && i18nInstance2.isLanguageChangingTo && !loadNotPending(i18nInstance2.isLanguageChangingTo, ns)) return false;
2287
- }
2288
- });
2289
- };
2290
- const isString$2 = (obj) => typeof obj === "string";
2291
- const isObject$3 = (obj) => typeof obj === "object" && obj !== null;
2292
- const matchHtmlEntity = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g;
2293
- const htmlEntities = {
2294
- "&amp;": "&",
2295
- "&#38;": "&",
2296
- "&lt;": "<",
2297
- "&#60;": "<",
2298
- "&gt;": ">",
2299
- "&#62;": ">",
2300
- "&apos;": "'",
2301
- "&#39;": "'",
2302
- "&quot;": '"',
2303
- "&#34;": '"',
2304
- "&nbsp;": " ",
2305
- "&#160;": " ",
2306
- "&copy;": "©",
2307
- "&#169;": "©",
2308
- "&reg;": "®",
2309
- "&#174;": "®",
2310
- "&hellip;": "…",
2311
- "&#8230;": "…",
2312
- "&#x2F;": "/",
2313
- "&#47;": "/"
2314
- };
2315
- const unescapeHtmlEntity = (m3) => htmlEntities[m3];
2316
- const unescape$1 = (text) => text.replace(matchHtmlEntity, unescapeHtmlEntity);
2317
- let defaultOptions$2 = {
2318
- bindI18n: "languageChanged",
2319
- bindI18nStore: "",
2320
- transEmptyNodeValue: "",
2321
- transSupportBasicHtmlNodes: true,
2322
- transWrapTextNodes: "",
2323
- transKeepBasicHtmlNodesFor: ["br", "strong", "i", "p"],
2324
- useSuspense: true,
2325
- unescape: unescape$1
2326
- };
2327
- const setDefaults = (options = {}) => {
2328
- defaultOptions$2 = {
2329
- ...defaultOptions$2,
2330
- ...options
2331
- };
2332
- };
2333
- const getDefaults = () => defaultOptions$2;
2334
- let i18nInstance;
2335
- const setI18n = (instance2) => {
2336
- i18nInstance = instance2;
2337
- };
2338
- const getI18n = () => i18nInstance;
2339
- const initReactI18next = {
2340
- type: "3rdParty",
2341
- init(instance2) {
2342
- setDefaults(instance2.options.react);
2343
- setI18n(instance2);
2344
- }
2345
- };
2346
- const I18nContext = createContext();
2347
- class ReportNamespaces {
2348
- constructor() {
2349
- this.usedNamespaces = {};
2350
- }
2351
- addUsedNamespaces(namespaces) {
2352
- namespaces.forEach((ns) => {
2353
- if (!this.usedNamespaces[ns]) this.usedNamespaces[ns] = true;
2354
- });
2355
- }
2356
- getUsedNamespaces() {
2357
- return Object.keys(this.usedNamespaces);
2358
- }
2359
- }
2360
- const usePrevious = (value, ignore) => {
2361
- const ref = useRef();
2362
- useEffect(() => {
2363
- ref.current = value;
2364
- }, [value, ignore]);
2365
- return ref.current;
2366
- };
2367
- const alwaysNewT = (i18n, language, namespace, keyPrefix) => i18n.getFixedT(language, namespace, keyPrefix);
2368
- const useMemoizedT = (i18n, language, namespace, keyPrefix) => useCallback(alwaysNewT(i18n, language, namespace, keyPrefix), [i18n, language, namespace, keyPrefix]);
2369
- const useTranslation = (ns, props = {}) => {
2370
- var _a, _b, _c, _d;
2371
- const {
2372
- i18n: i18nFromProps
2373
- } = props;
2374
- const {
2375
- i18n: i18nFromContext,
2376
- defaultNS: defaultNSFromContext
2377
- } = useContext(I18nContext) || {};
2378
- const i18n = i18nFromProps || i18nFromContext || getI18n();
2379
- if (i18n && !i18n.reportNamespaces) i18n.reportNamespaces = new ReportNamespaces();
2380
- if (!i18n) {
2381
- warnOnce(i18n, "NO_I18NEXT_INSTANCE", "useTranslation: You will need to pass in an i18next instance by using initReactI18next");
2382
- const notReadyT = (k2, optsOrDefaultValue) => {
2383
- if (isString$2(optsOrDefaultValue)) return optsOrDefaultValue;
2384
- if (isObject$3(optsOrDefaultValue) && isString$2(optsOrDefaultValue.defaultValue)) return optsOrDefaultValue.defaultValue;
2385
- return Array.isArray(k2) ? k2[k2.length - 1] : k2;
2386
- };
2387
- const retNotReady = [notReadyT, {}, false];
2388
- retNotReady.t = notReadyT;
2389
- retNotReady.i18n = {};
2390
- retNotReady.ready = false;
2391
- return retNotReady;
2392
- }
2393
- if ((_a = i18n.options.react) == null ? void 0 : _a.wait) warnOnce(i18n, "DEPRECATED_OPTION", "useTranslation: It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");
2394
- const i18nOptions = {
2395
- ...getDefaults(),
2396
- ...i18n.options.react,
2397
- ...props
2398
- };
2399
- const {
2400
- useSuspense,
2401
- keyPrefix
2402
- } = i18nOptions;
2403
- let namespaces = ns || defaultNSFromContext || ((_b = i18n.options) == null ? void 0 : _b.defaultNS);
2404
- namespaces = isString$2(namespaces) ? [namespaces] : namespaces || ["translation"];
2405
- (_d = (_c = i18n.reportNamespaces).addUsedNamespaces) == null ? void 0 : _d.call(_c, namespaces);
2406
- const ready = (i18n.isInitialized || i18n.initializedStoreOnce) && namespaces.every((n2) => hasLoadedNamespace(n2, i18n, i18nOptions));
2407
- const memoGetT = useMemoizedT(i18n, props.lng || null, i18nOptions.nsMode === "fallback" ? namespaces : namespaces[0], keyPrefix);
2408
- const getT = () => memoGetT;
2409
- const getNewT = () => alwaysNewT(i18n, props.lng || null, i18nOptions.nsMode === "fallback" ? namespaces : namespaces[0], keyPrefix);
2410
- const [t2, setT] = useState(getT);
2411
- let joinedNS = namespaces.join();
2412
- if (props.lng) joinedNS = `${props.lng}${joinedNS}`;
2413
- const previousJoinedNS = usePrevious(joinedNS);
2414
- const isMounted = useRef(true);
2415
- useEffect(() => {
2416
- const {
2417
- bindI18n,
2418
- bindI18nStore
2419
- } = i18nOptions;
2420
- isMounted.current = true;
2421
- if (!ready && !useSuspense) {
2422
- if (props.lng) {
2423
- loadLanguages(i18n, props.lng, namespaces, () => {
2424
- if (isMounted.current) setT(getNewT);
2425
- });
2426
- } else {
2427
- loadNamespaces(i18n, namespaces, () => {
2428
- if (isMounted.current) setT(getNewT);
2429
- });
2430
- }
2431
- }
2432
- if (ready && previousJoinedNS && previousJoinedNS !== joinedNS && isMounted.current) {
2433
- setT(getNewT);
2434
- }
2435
- const boundReset = () => {
2436
- if (isMounted.current) setT(getNewT);
2437
- };
2438
- if (bindI18n) i18n == null ? void 0 : i18n.on(bindI18n, boundReset);
2439
- if (bindI18nStore) i18n == null ? void 0 : i18n.store.on(bindI18nStore, boundReset);
2440
- return () => {
2441
- isMounted.current = false;
2442
- if (i18n && bindI18n) bindI18n == null ? void 0 : bindI18n.split(" ").forEach((e2) => i18n.off(e2, boundReset));
2443
- if (bindI18nStore && i18n) bindI18nStore.split(" ").forEach((e2) => i18n.store.off(e2, boundReset));
2444
- };
2445
- }, [i18n, joinedNS]);
2446
- useEffect(() => {
2447
- if (isMounted.current && ready) {
2448
- setT(getT);
2449
- }
2450
- }, [i18n, keyPrefix, ready]);
2451
- const ret = [t2, i18n, ready];
2452
- ret.t = t2;
2453
- ret.i18n = i18n;
2454
- ret.ready = ready;
2455
- if (ready) return ret;
2456
- if (!ready && !useSuspense) return ret;
2457
- throw new Promise((resolve) => {
2458
- if (props.lng) {
2459
- loadLanguages(i18n, props.lng, namespaces, () => resolve());
2460
- } else {
2461
- loadNamespaces(i18n, namespaces, () => resolve());
2462
- }
2463
- });
2464
- };
2465
16
  const confirmDialog$1 = { "cancel": "Cancel", "ok": "Ok", "confirm": "Confirm", "delete": "Delete", "save": "Save", "yes": "Yes", "no": "No" };
2466
17
  const en$1 = {
2467
18
  confirmDialog: confirmDialog$1
@@ -2470,22 +21,8 @@ const confirmDialog = { "cancel": "Batal", "ok": "Ok", "confirm": "Sahkan", "del
2470
21
  const ms$1 = {
2471
22
  confirmDialog
2472
23
  };
2473
- const resources = {
2474
- en: {
2475
- translation: en$1
2476
- },
2477
- ms: {
2478
- translation: ms$1
2479
- }
2480
- };
2481
- instance.use(initReactI18next).init({
2482
- resources,
2483
- lng: "en",
2484
- fallbackLng: "en",
2485
- interpolation: {
2486
- escapeValue: false
2487
- }
2488
- });
24
+ i18next.addResourceBundle("en", "translation", en$1, true, true);
25
+ i18next.addResourceBundle("ms", "translation", ms$1, true, true);
2489
26
  const locale$3 = {
2490
27
  CHANGE_DETECT_TITLE: "Are you sure want discard changes?",
2491
28
  CHANGE_DETECT_BUTTON: "Keep Editing",
@@ -2544,9 +81,16 @@ const locale$3 = {
2544
81
  DOCUMENTS_REMARKS: "Documents Remarks",
2545
82
  LOAN_AMOUNT: "Loan Amount",
2546
83
  INTEREST_RATE: "Interest Rate",
2547
- FEES_DEDUCTION: "Fees Deduction",
84
+ INTEREST_FEES: "Interest Fees",
2548
85
  REPAYMENT_AMOUNT: "Repayment Amount",
2549
- CASH_IN_HAND: "Cash In Hand"
86
+ DISBURSEMENT: "Disbursement",
87
+ CONFIRM_INFORMATION_READ: "I confirm that I have read, understood, and agree to the loan amount, interest rate, repayment terms, deductions, tenure, and all related loan details.",
88
+ PDF_PREVIEW_TITLE: "Summary of loan application",
89
+ TOTAL_INTEREST_RATE: "Total Interest Rate",
90
+ DURATION: "Duration",
91
+ STAMP_DUTY: "Stamp Duty",
92
+ LEGAL_FEES: "Legal Fees",
93
+ MONTHS: "Months"
2550
94
  };
2551
95
  const locale$2 = {
2552
96
  CHANGE_DETECT_TITLE: "Adakah anda pasti mahu membuang perubahan?",
@@ -2605,12 +149,19 @@ const locale$2 = {
2605
149
  DOCUMENTS_REMARKS: "Documents Remarks",
2606
150
  LOAN_AMOUNT: "Jumlah Pinjaman",
2607
151
  INTEREST_RATE: "Kadar Faedah",
2608
- FEES_DEDUCTION: "Potongan Yuran",
152
+ INTEREST_FEES: "Yuran Faedah",
2609
153
  REPAYMENT_AMOUNT: "Amaun Bayaran Balik",
2610
- CASH_IN_HAND: "Wang tunai di tangan"
2611
- };
2612
- instance.addResourceBundle("en", "Dialog", locale$3);
2613
- instance.addResourceBundle("ms", "Dialog", locale$2);
154
+ DISBURSEMENT: "Pengeluaran",
155
+ CONFIRM_INFORMATION_READ: "Saya mengesahkan bahawa saya telah membaca, memahami, dan bersetuju dengan jumlah pinjaman, kadar faedah, terma pembayaran balik, potongan, tempoh pinjaman, serta semua butiran pinjaman yang berkaitan.",
156
+ PDF_PREVIEW_TITLE: "Ringkasan permohonan pinjaman",
157
+ TOTAL_INTEREST_RATE: "Jumlah Kadar Faedah",
158
+ DURATION: "Tempoh",
159
+ STAMP_DUTY: "Duti Setem",
160
+ LEGAL_FEES: "Yuran Guaman",
161
+ MONTHS: "Bulan"
162
+ };
163
+ i18next.addResourceBundle("en", "Dialog", locale$3);
164
+ i18next.addResourceBundle("ms", "Dialog", locale$2);
2614
165
  const ConfirmDialog = ({
2615
166
  open,
2616
167
  title,
@@ -2648,6 +199,10 @@ function chainPropTypes(propType1, propType2) {
2648
199
  return propType1(...args) || propType2(...args);
2649
200
  };
2650
201
  }
202
+ var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
203
+ function getDefaultExportFromCjs(x2) {
204
+ return x2 && x2.__esModule && Object.prototype.hasOwnProperty.call(x2, "default") ? x2["default"] : x2;
205
+ }
2651
206
  var reactIs$1 = { exports: {} };
2652
207
  var reactIs_production = {};
2653
208
  /**
@@ -4123,19 +1678,19 @@ function useEventCallback$1(fn2) {
4123
1678
  }
4124
1679
  function useForkRef$2(...refs) {
4125
1680
  const cleanupRef = React.useRef(void 0);
4126
- const refEffect = React.useCallback((instance2) => {
1681
+ const refEffect = React.useCallback((instance) => {
4127
1682
  const cleanups = refs.map((ref) => {
4128
1683
  if (ref == null) {
4129
1684
  return null;
4130
1685
  }
4131
1686
  if (typeof ref === "function") {
4132
1687
  const refCallback = ref;
4133
- const refCleanup = refCallback(instance2);
1688
+ const refCleanup = refCallback(instance);
4134
1689
  return typeof refCleanup === "function" ? refCleanup : () => {
4135
1690
  refCallback(null);
4136
1691
  };
4137
1692
  }
4138
- ref.current = instance2;
1693
+ ref.current = instance;
4139
1694
  return () => {
4140
1695
  ref.current = null;
4141
1696
  };
@@ -9664,22 +7219,22 @@ function currentImpl(value) {
9664
7219
  if (!isDraftable(value) || isFrozen(value))
9665
7220
  return value;
9666
7221
  const state = value[DRAFT_STATE];
9667
- let copy2;
7222
+ let copy;
9668
7223
  if (state) {
9669
7224
  if (!state.modified_)
9670
7225
  return state.base_;
9671
7226
  state.finalized_ = true;
9672
- copy2 = shallowCopy(value, state.scope_.immer_.useStrictShallowCopy_);
7227
+ copy = shallowCopy(value, state.scope_.immer_.useStrictShallowCopy_);
9673
7228
  } else {
9674
- copy2 = shallowCopy(value, true);
7229
+ copy = shallowCopy(value, true);
9675
7230
  }
9676
- each(copy2, (key, childValue) => {
9677
- set$1(copy2, key, currentImpl(childValue));
7231
+ each(copy, (key, childValue) => {
7232
+ set$1(copy, key, currentImpl(childValue));
9678
7233
  });
9679
7234
  if (state) {
9680
7235
  state.finalized_ = false;
9681
7236
  }
9682
- return copy2;
7237
+ return copy;
9683
7238
  }
9684
7239
  var immer = new Immer2();
9685
7240
  var produce = immer.produce;
@@ -12534,13 +10089,13 @@ Object.entries(HttpStatusCode$1).forEach(([key, value]) => {
12534
10089
  });
12535
10090
  function createInstance(defaultConfig2) {
12536
10091
  const context = new Axios$1(defaultConfig2);
12537
- const instance2 = bind(Axios$1.prototype.request, context);
12538
- utils$1.extend(instance2, Axios$1.prototype, context, { allOwnKeys: true });
12539
- utils$1.extend(instance2, context, null, { allOwnKeys: true });
12540
- instance2.create = function create(instanceConfig) {
10092
+ const instance = bind(Axios$1.prototype.request, context);
10093
+ utils$1.extend(instance, Axios$1.prototype, context, { allOwnKeys: true });
10094
+ utils$1.extend(instance, context, null, { allOwnKeys: true });
10095
+ instance.create = function create(instanceConfig) {
12541
10096
  return createInstance(mergeConfig$1(defaultConfig2, instanceConfig));
12542
10097
  };
12543
- return instance2;
10098
+ return instance;
12544
10099
  }
12545
10100
  const axios = createInstance(defaults);
12546
10101
  axios.Axios = Axios$1;
@@ -12837,7 +10392,8 @@ const DigitalProcessSignature = (request_data) => async (dispatch) => {
12837
10392
  if (applicationDetails) {
12838
10393
  dispatch(setActiveFinanceDetail(applicationDetails));
12839
10394
  }
12840
- dispatch(setDocumentSignJPDF(response.result));
10395
+ dispatch(setDocumentSignJPDF(""));
10396
+ dispatch(setSignedDocumentJPDF(response.result));
12841
10397
  }
12842
10398
  } catch (error) {
12843
10399
  dispatch(showMessage({ message: error.message, variant: "error" }));
@@ -12909,6 +10465,10 @@ const getDocumentSignJPDF = (state) => {
12909
10465
  var _a;
12910
10466
  return ((_a = state.dialogs) == null ? void 0 : _a.documentSignJPDF) || "";
12911
10467
  };
10468
+ const getSignedDocumentJPDF = (state) => {
10469
+ var _a;
10470
+ return ((_a = state.dialogs) == null ? void 0 : _a.signedDocumentJPDF) || "";
10471
+ };
12912
10472
  const getActiveFinanceDetail = (state) => {
12913
10473
  var _a;
12914
10474
  return ((_a = state.dialogs) == null ? void 0 : _a.activeFinanceDetail) || null;
@@ -12939,6 +10499,7 @@ const initialState$1 = {
12939
10499
  },
12940
10500
  remarksList: [],
12941
10501
  documentSignJPDF: "",
10502
+ signedDocumentJPDF: "",
12942
10503
  activeFinanceDetail: null,
12943
10504
  imagePath: "",
12944
10505
  selectedMediaFilePath: ""
@@ -12960,6 +10521,9 @@ const dialogsSlice = createSlice({
12960
10521
  setDocumentSignJPDF: (state, action) => {
12961
10522
  state.documentSignJPDF = action.payload;
12962
10523
  },
10524
+ setSignedDocumentJPDF: (state, action) => {
10525
+ state.signedDocumentJPDF = action.payload;
10526
+ },
12963
10527
  setActiveFinanceDetail: (state, action) => {
12964
10528
  state.activeFinanceDetail = action.payload;
12965
10529
  },
@@ -12975,6 +10539,7 @@ const {
12975
10539
  setLoading: setLoading$1,
12976
10540
  setRemarkList,
12977
10541
  setDocumentSignJPDF,
10542
+ setSignedDocumentJPDF,
12978
10543
  setActiveFinanceDetail,
12979
10544
  setImagePath,
12980
10545
  setSelectedMediaFilePath
@@ -12992,8 +10557,8 @@ const uploadFile = (file) => async (dispatch) => {
12992
10557
  console.log(error);
12993
10558
  }
12994
10559
  };
12995
- instance.addResourceBundle("en", "Dialog", locale$3);
12996
- instance.addResourceBundle("ms", "Dialog", locale$2);
10560
+ i18next.addResourceBundle("en", "Dialog", locale$3);
10561
+ i18next.addResourceBundle("ms", "Dialog", locale$2);
12997
10562
  const ChangeDetectDialog = ({
12998
10563
  open,
12999
10564
  onClose,
@@ -13029,26 +10594,26 @@ var isPlainObject = (tempObject) => {
13029
10594
  };
13030
10595
  var isWeb = typeof window !== "undefined" && typeof window.HTMLElement !== "undefined" && typeof document !== "undefined";
13031
10596
  function cloneObject(data) {
13032
- let copy2;
10597
+ let copy;
13033
10598
  const isArray2 = Array.isArray(data);
13034
10599
  const isFileListInstance = typeof FileList !== "undefined" ? data instanceof FileList : false;
13035
10600
  if (data instanceof Date) {
13036
- copy2 = new Date(data);
10601
+ copy = new Date(data);
13037
10602
  } else if (!(isWeb && (data instanceof Blob || isFileListInstance)) && (isArray2 || isObject$1(data))) {
13038
- copy2 = isArray2 ? [] : Object.create(Object.getPrototypeOf(data));
10603
+ copy = isArray2 ? [] : Object.create(Object.getPrototypeOf(data));
13039
10604
  if (!isArray2 && !isPlainObject(data)) {
13040
- copy2 = data;
10605
+ copy = data;
13041
10606
  } else {
13042
10607
  for (const key in data) {
13043
10608
  if (data.hasOwnProperty(key)) {
13044
- copy2[key] = cloneObject(data[key]);
10609
+ copy[key] = cloneObject(data[key]);
13045
10610
  }
13046
10611
  }
13047
10612
  }
13048
10613
  } else {
13049
10614
  return data;
13050
10615
  }
13051
- return copy2;
10616
+ return copy;
13052
10617
  }
13053
10618
  var isKey = (value) => /^\w*$/.test(value);
13054
10619
  var isUndefined = (val) => val === void 0;
@@ -15494,33 +13059,33 @@ class ReferenceSet extends Set {
15494
13059
  function clone(src, seen = /* @__PURE__ */ new Map()) {
15495
13060
  if (isSchema(src) || !src || typeof src !== "object") return src;
15496
13061
  if (seen.has(src)) return seen.get(src);
15497
- let copy2;
13062
+ let copy;
15498
13063
  if (src instanceof Date) {
15499
- copy2 = new Date(src.getTime());
15500
- seen.set(src, copy2);
13064
+ copy = new Date(src.getTime());
13065
+ seen.set(src, copy);
15501
13066
  } else if (src instanceof RegExp) {
15502
- copy2 = new RegExp(src);
15503
- seen.set(src, copy2);
13067
+ copy = new RegExp(src);
13068
+ seen.set(src, copy);
15504
13069
  } else if (Array.isArray(src)) {
15505
- copy2 = new Array(src.length);
15506
- seen.set(src, copy2);
15507
- for (let i3 = 0; i3 < src.length; i3++) copy2[i3] = clone(src[i3], seen);
13070
+ copy = new Array(src.length);
13071
+ seen.set(src, copy);
13072
+ for (let i3 = 0; i3 < src.length; i3++) copy[i3] = clone(src[i3], seen);
15508
13073
  } else if (src instanceof Map) {
15509
- copy2 = /* @__PURE__ */ new Map();
15510
- seen.set(src, copy2);
15511
- for (const [k2, v] of src.entries()) copy2.set(k2, clone(v, seen));
13074
+ copy = /* @__PURE__ */ new Map();
13075
+ seen.set(src, copy);
13076
+ for (const [k2, v] of src.entries()) copy.set(k2, clone(v, seen));
15512
13077
  } else if (src instanceof Set) {
15513
- copy2 = /* @__PURE__ */ new Set();
15514
- seen.set(src, copy2);
15515
- for (const v of src) copy2.add(clone(v, seen));
13078
+ copy = /* @__PURE__ */ new Set();
13079
+ seen.set(src, copy);
13080
+ for (const v of src) copy.add(clone(v, seen));
15516
13081
  } else if (src instanceof Object) {
15517
- copy2 = {};
15518
- seen.set(src, copy2);
15519
- for (const [k2, v] of Object.entries(src)) copy2[k2] = clone(v, seen);
13082
+ copy = {};
13083
+ seen.set(src, copy);
13084
+ for (const [k2, v] of Object.entries(src)) copy[k2] = clone(v, seen);
15520
13085
  } else {
15521
13086
  throw Error(`Unable to clone ${src}`);
15522
13087
  }
15523
- return copy2;
13088
+ return copy;
15524
13089
  }
15525
13090
  function createStandardPath(path) {
15526
13091
  if (!(path != null && path.length)) {
@@ -19539,8 +17104,8 @@ const SaveButton = React__default.memo(({
19539
17104
  );
19540
17105
  });
19541
17106
  SaveButton.displayName = "SaveButton";
19542
- instance.addResourceBundle("en", "Dialog", locale$3);
19543
- instance.addResourceBundle("ms", "Dialog", locale$2);
17107
+ i18next.addResourceBundle("en", "Dialog", locale$3);
17108
+ i18next.addResourceBundle("ms", "Dialog", locale$2);
19544
17109
  const defaultValues$2 = {
19545
17110
  password: ""
19546
17111
  };
@@ -19606,8 +17171,8 @@ function ChangePasswordDialog({ userId }) {
19606
17171
  }
19607
17172
  ) }) }) });
19608
17173
  }
19609
- instance.addResourceBundle("en", "Dialog", locale$3);
19610
- instance.addResourceBundle("ms", "Dialog", locale$2);
17174
+ i18next.addResourceBundle("en", "Dialog", locale$3);
17175
+ i18next.addResourceBundle("ms", "Dialog", locale$2);
19611
17176
  const DeleteUserDialog = ({
19612
17177
  open,
19613
17178
  deleteUserId,
@@ -21940,8 +19505,8 @@ const ms = {
21940
19505
  FINANCE_APPLICATION_NUMBER: "Nombor Permohonan Kewangan",
21941
19506
  TENANT: "Penyewa"
21942
19507
  };
21943
- instance.addResourceBundle("en", "Autocomplete", en);
21944
- instance.addResourceBundle("ms", "Autocomplete", ms);
19508
+ i18next.addResourceBundle("en", "Autocomplete", en);
19509
+ i18next.addResourceBundle("ms", "Autocomplete", ms);
21945
19510
  const CustomAutocomplete = React.memo(
21946
19511
  ({
21947
19512
  label,
@@ -24464,14 +22029,14 @@ function requireLodash() {
24464
22029
  });
24465
22030
  });
24466
22031
  }
24467
- function createPadding(length, chars2) {
24468
- chars2 = chars2 === undefined$1 ? " " : baseToString(chars2);
24469
- var charsLength = chars2.length;
22032
+ function createPadding(length, chars) {
22033
+ chars = chars === undefined$1 ? " " : baseToString(chars);
22034
+ var charsLength = chars.length;
24470
22035
  if (charsLength < 2) {
24471
- return charsLength ? baseRepeat(chars2, length) : chars2;
22036
+ return charsLength ? baseRepeat(chars, length) : chars;
24472
22037
  }
24473
- var result2 = baseRepeat(chars2, nativeCeil(length / stringSize(chars2)));
24474
- return hasUnicode(chars2) ? castSlice(stringToArray(result2), 0, length).join("") : result2.slice(0, length);
22038
+ var result2 = baseRepeat(chars, nativeCeil(length / stringSize(chars)));
22039
+ return hasUnicode(chars) ? castSlice(stringToArray(result2), 0, length).join("") : result2.slice(0, length);
24475
22040
  }
24476
22041
  function createPartial(func, bitmask, thisArg, partials) {
24477
22042
  var isBind = bitmask & WRAP_BIND_FLAG, Ctor = createCtor(func);
@@ -25975,7 +23540,7 @@ function requireLodash() {
25975
23540
  debounced.flush = flush;
25976
23541
  return debounced;
25977
23542
  }
25978
- var defer2 = baseRest(function(func, args) {
23543
+ var defer = baseRest(function(func, args) {
25979
23544
  return baseDelay(func, 1, args);
25980
23545
  });
25981
23546
  var delay = baseRest(function(func, wait, args) {
@@ -26629,7 +24194,7 @@ function requireLodash() {
26629
24194
  position -= target.length;
26630
24195
  return position >= 0 && string2.slice(position, end2) == target;
26631
24196
  }
26632
- function escape2(string2) {
24197
+ function escape(string2) {
26633
24198
  string2 = toString3(string2);
26634
24199
  return string2 && reHasUnescapedHtml.test(string2) ? string2.replace(reUnescapedHtml, escapeHtmlChar) : string2;
26635
24200
  }
@@ -26644,7 +24209,7 @@ function requireLodash() {
26644
24209
  return result2 + (index ? " " : "") + word.toLowerCase();
26645
24210
  });
26646
24211
  var lowerFirst = createCaseFirst("toLowerCase");
26647
- function pad(string2, length, chars2) {
24212
+ function pad(string2, length, chars) {
26648
24213
  string2 = toString3(string2);
26649
24214
  length = toInteger2(length);
26650
24215
  var strLength = length ? stringSize(string2) : 0;
@@ -26652,19 +24217,19 @@ function requireLodash() {
26652
24217
  return string2;
26653
24218
  }
26654
24219
  var mid = (length - strLength) / 2;
26655
- return createPadding(nativeFloor(mid), chars2) + string2 + createPadding(nativeCeil(mid), chars2);
24220
+ return createPadding(nativeFloor(mid), chars) + string2 + createPadding(nativeCeil(mid), chars);
26656
24221
  }
26657
- function padEnd(string2, length, chars2) {
24222
+ function padEnd(string2, length, chars) {
26658
24223
  string2 = toString3(string2);
26659
24224
  length = toInteger2(length);
26660
24225
  var strLength = length ? stringSize(string2) : 0;
26661
- return length && strLength < length ? string2 + createPadding(length - strLength, chars2) : string2;
24226
+ return length && strLength < length ? string2 + createPadding(length - strLength, chars) : string2;
26662
24227
  }
26663
- function padStart(string2, length, chars2) {
24228
+ function padStart(string2, length, chars) {
26664
24229
  string2 = toString3(string2);
26665
24230
  length = toInteger2(length);
26666
24231
  var strLength = length ? stringSize(string2) : 0;
26667
- return length && strLength < length ? createPadding(length - strLength, chars2) + string2 : string2;
24232
+ return length && strLength < length ? createPadding(length - strLength, chars) + string2 : string2;
26668
24233
  }
26669
24234
  function parseInt2(string2, radix, guard) {
26670
24235
  if (guard || radix == null) {
@@ -26770,37 +24335,37 @@ function requireLodash() {
26770
24335
  function toUpper(value) {
26771
24336
  return toString3(value).toUpperCase();
26772
24337
  }
26773
- function trim2(string2, chars2, guard) {
24338
+ function trim2(string2, chars, guard) {
26774
24339
  string2 = toString3(string2);
26775
- if (string2 && (guard || chars2 === undefined$1)) {
24340
+ if (string2 && (guard || chars === undefined$1)) {
26776
24341
  return baseTrim(string2);
26777
24342
  }
26778
- if (!string2 || !(chars2 = baseToString(chars2))) {
24343
+ if (!string2 || !(chars = baseToString(chars))) {
26779
24344
  return string2;
26780
24345
  }
26781
- var strSymbols = stringToArray(string2), chrSymbols = stringToArray(chars2), start2 = charsStartIndex(strSymbols, chrSymbols), end2 = charsEndIndex(strSymbols, chrSymbols) + 1;
24346
+ var strSymbols = stringToArray(string2), chrSymbols = stringToArray(chars), start2 = charsStartIndex(strSymbols, chrSymbols), end2 = charsEndIndex(strSymbols, chrSymbols) + 1;
26782
24347
  return castSlice(strSymbols, start2, end2).join("");
26783
24348
  }
26784
- function trimEnd(string2, chars2, guard) {
24349
+ function trimEnd(string2, chars, guard) {
26785
24350
  string2 = toString3(string2);
26786
- if (string2 && (guard || chars2 === undefined$1)) {
24351
+ if (string2 && (guard || chars === undefined$1)) {
26787
24352
  return string2.slice(0, trimmedEndIndex(string2) + 1);
26788
24353
  }
26789
- if (!string2 || !(chars2 = baseToString(chars2))) {
24354
+ if (!string2 || !(chars = baseToString(chars))) {
26790
24355
  return string2;
26791
24356
  }
26792
- var strSymbols = stringToArray(string2), end2 = charsEndIndex(strSymbols, stringToArray(chars2)) + 1;
24357
+ var strSymbols = stringToArray(string2), end2 = charsEndIndex(strSymbols, stringToArray(chars)) + 1;
26793
24358
  return castSlice(strSymbols, 0, end2).join("");
26794
24359
  }
26795
- function trimStart(string2, chars2, guard) {
24360
+ function trimStart(string2, chars, guard) {
26796
24361
  string2 = toString3(string2);
26797
- if (string2 && (guard || chars2 === undefined$1)) {
24362
+ if (string2 && (guard || chars === undefined$1)) {
26798
24363
  return string2.replace(reTrimStart, "");
26799
24364
  }
26800
- if (!string2 || !(chars2 = baseToString(chars2))) {
24365
+ if (!string2 || !(chars = baseToString(chars))) {
26801
24366
  return string2;
26802
24367
  }
26803
- var strSymbols = stringToArray(string2), start2 = charsStartIndex(strSymbols, stringToArray(chars2));
24368
+ var strSymbols = stringToArray(string2), start2 = charsStartIndex(strSymbols, stringToArray(chars));
26804
24369
  return castSlice(strSymbols, start2).join("");
26805
24370
  }
26806
24371
  function truncate(string2, options) {
@@ -27091,7 +24656,7 @@ function requireLodash() {
27091
24656
  lodash2.debounce = debounce2;
27092
24657
  lodash2.defaults = defaults2;
27093
24658
  lodash2.defaultsDeep = defaultsDeep;
27094
- lodash2.defer = defer2;
24659
+ lodash2.defer = defer;
27095
24660
  lodash2.delay = delay;
27096
24661
  lodash2.difference = difference;
27097
24662
  lodash2.differenceBy = differenceBy;
@@ -27235,7 +24800,7 @@ function requireLodash() {
27235
24800
  lodash2.divide = divide;
27236
24801
  lodash2.endsWith = endsWith2;
27237
24802
  lodash2.eq = eq;
27238
- lodash2.escape = escape2;
24803
+ lodash2.escape = escape;
27239
24804
  lodash2.escapeRegExp = escapeRegExp;
27240
24805
  lodash2.every = every;
27241
24806
  lodash2.find = find;
@@ -28297,6 +25862,43 @@ const CommonStatusChangeDialog = ({
28297
25862
  }
28298
25863
  );
28299
25864
  };
25865
+ const CustomCheckbox = ({
25866
+ label,
25867
+ onChange,
25868
+ checked: controlledChecked,
25869
+ ...props
25870
+ }) => {
25871
+ const [internalChecked, setInternalChecked] = React__default.useState(false);
25872
+ const isControlled = controlledChecked !== void 0;
25873
+ const isChecked = isControlled ? controlledChecked : internalChecked;
25874
+ const handleChange = (newChecked) => {
25875
+ if (!isControlled) {
25876
+ setInternalChecked(newChecked);
25877
+ }
25878
+ onChange == null ? void 0 : onChange(newChecked);
25879
+ };
25880
+ return /* @__PURE__ */ jsx(Fragment, { children: label ? /* @__PURE__ */ jsx(
25881
+ FormControlLabel,
25882
+ {
25883
+ control: /* @__PURE__ */ jsx(
25884
+ Checkbox$1,
25885
+ {
25886
+ checked: isChecked,
25887
+ onChange: (event) => handleChange(event.target.checked),
25888
+ ...props
25889
+ }
25890
+ ),
25891
+ label
25892
+ }
25893
+ ) : /* @__PURE__ */ jsx(
25894
+ Checkbox$1,
25895
+ {
25896
+ checked: isChecked,
25897
+ onChange: (event) => handleChange(event.target.checked),
25898
+ ...props
25899
+ }
25900
+ ) });
25901
+ };
28300
25902
  function shouldShowButton(loginUserDetail, loginUserRoles2, applicationDetailsData) {
28301
25903
  var _a, _b, _c, _d, _e, _f;
28302
25904
  const isAdmin = ((_a = loginUserDetail == null ? void 0 : loginUserDetail.data) == null ? void 0 : _a.slug) === loginUserRoles2.Admin;
@@ -28318,125 +25920,141 @@ const PDFPreviewForTheSignature = ({
28318
25920
  loginUserDetail,
28319
25921
  loginUserRoles: loginUserRoles2,
28320
25922
  ColoredSubmitButton,
25923
+ dialogTitle,
28321
25924
  financeCalculation,
28322
- t: t2 = (key) => key
25925
+ t: t2 = (key) => key,
25926
+ showConfirmCheckbox = false,
25927
+ pdfOnly = false,
25928
+ ...props
28323
25929
  }) => {
28324
25930
  const showButton = shouldShowButton(
28325
25931
  loginUserDetail,
28326
25932
  loginUserRoles2,
28327
25933
  applicationDetailsData
28328
25934
  );
28329
- return /* @__PURE__ */ jsx(Dialog$1, { open, onClose, maxWidth: "lg", fullWidth: true, children: /* @__PURE__ */ jsxs(DialogContent$1, { className: "p-0", children: [
28330
- /* @__PURE__ */ jsx(
28331
- "embed",
28332
- {
28333
- src: filePath,
28334
- type: "application/pdf",
28335
- width: "100%",
28336
- style: { height: "80vh" }
28337
- }
28338
- ),
28339
- showButton && /* @__PURE__ */ jsxs("div", { className: "sticky bottom-0 bg-white w-full border-t-1 border-solid border-grey-500 px-10 py-10 text-end", children: [
28340
- financeCalculation && /* @__PURE__ */ jsxs(Grid$1, { container: true, spacing: 2, children: [
28341
- /* @__PURE__ */ jsx(Grid$1, { item: true, xs: 12, sm: 12, md: 4, className: "flex justify-start", children: /* @__PURE__ */ jsxs(Typography$1, { variant: "body1", children: [
25935
+ const [isTermsConfirmed, setIsTermsConfirmed] = useState(false);
25936
+ return /* @__PURE__ */ jsx(Dialog$1, { open, onClose, maxWidth: "lg", fullWidth: true, ...props, children: /* @__PURE__ */ jsxs(DialogContent$1, { className: "p-0", children: [
25937
+ !pdfOnly && (dialogTitle || financeCalculation) && /* @__PURE__ */ jsxs("div", { className: "px-16 pt-12 pb-16", children: [
25938
+ dialogTitle && /* @__PURE__ */ jsx(Typography$1, { variant: "h6", className: "font-semibold mb-12", children: dialogTitle }),
25939
+ financeCalculation && /* @__PURE__ */ jsxs(Grid2, { container: true, spacing: 2, children: [
25940
+ financeCalculation.loanAmount !== void 0 && /* @__PURE__ */ jsx(Grid2, { size: { xs: 12, sm: 4 }, children: /* @__PURE__ */ jsxs(Typography$1, { variant: "body2", children: [
28342
25941
  /* @__PURE__ */ jsxs("strong", { children: [
28343
25942
  t2("LOAN_AMOUNT"),
28344
25943
  ": "
28345
25944
  ] }),
28346
- formatAmount(financeCalculation == null ? void 0 : financeCalculation.loanAmount)
25945
+ formatAmount(financeCalculation.loanAmount)
28347
25946
  ] }) }),
28348
- /* @__PURE__ */ jsx(Grid$1, { item: true, xs: 12, sm: 12, md: 4, className: "flex justify-start", children: /* @__PURE__ */ jsxs(Typography$1, { variant: "body1", children: [
25947
+ financeCalculation.totalInterestRate !== void 0 && /* @__PURE__ */ jsx(Grid2, { size: { xs: 12, sm: 4 }, children: /* @__PURE__ */ jsxs(Typography$1, { variant: "body2", children: [
28349
25948
  /* @__PURE__ */ jsxs("strong", { children: [
28350
- t2("INTEREST_RATE"),
25949
+ t2("TOTAL_INTEREST_RATE"),
28351
25950
  ": "
28352
25951
  ] }),
28353
- formatAmount(financeCalculation == null ? void 0 : financeCalculation.interestFees)
25952
+ financeCalculation.totalInterestRate,
25953
+ " %"
28354
25954
  ] }) }),
28355
- /* @__PURE__ */ jsx(Grid$1, { item: true, xs: 12, sm: 12, md: 4, className: "flex justify-start", children: /* @__PURE__ */ jsxs(Typography$1, { variant: "body1", children: [
25955
+ financeCalculation.interestFees !== void 0 && /* @__PURE__ */ jsx(Grid2, { size: { xs: 12, sm: 4 }, children: /* @__PURE__ */ jsxs(Typography$1, { variant: "body2", children: [
28356
25956
  /* @__PURE__ */ jsxs("strong", { children: [
28357
- t2("FEES_DEDUCTION"),
25957
+ t2("INTEREST_FEES"),
28358
25958
  ": "
28359
25959
  ] }),
28360
- formatAmount(financeCalculation == null ? void 0 : financeCalculation.feesDeduction)
25960
+ formatAmount(financeCalculation.interestFees)
28361
25961
  ] }) }),
28362
- /* @__PURE__ */ jsx(Grid$1, { item: true, xs: 12, sm: 12, md: 4, className: "flex justify-start", children: /* @__PURE__ */ jsxs(Typography$1, { variant: "body1", children: [
25962
+ financeCalculation.repaymentAmount !== void 0 && /* @__PURE__ */ jsx(Grid2, { size: { xs: 12, sm: 4 }, children: /* @__PURE__ */ jsxs(Typography$1, { variant: "body2", children: [
28363
25963
  /* @__PURE__ */ jsxs("strong", { children: [
28364
25964
  t2("REPAYMENT_AMOUNT"),
28365
25965
  ": "
28366
25966
  ] }),
28367
- formatAmount(financeCalculation == null ? void 0 : financeCalculation.repaymentAmount)
25967
+ formatAmount(financeCalculation.repaymentAmount)
25968
+ ] }) }),
25969
+ financeCalculation.durationMonths !== void 0 && /* @__PURE__ */ jsx(Grid2, { size: { xs: 12, sm: 4 }, children: /* @__PURE__ */ jsxs(Typography$1, { variant: "body2", children: [
25970
+ /* @__PURE__ */ jsxs("strong", { children: [
25971
+ t2("DURATION"),
25972
+ ": "
25973
+ ] }),
25974
+ financeCalculation.durationMonths,
25975
+ " ",
25976
+ t2("MONTHS")
28368
25977
  ] }) }),
28369
- /* @__PURE__ */ jsx(Grid$1, { item: true, xs: 12, sm: 12, md: 4, className: "flex justify-start", children: /* @__PURE__ */ jsxs(Typography$1, { variant: "body1", children: [
25978
+ financeCalculation.stampDuty !== void 0 && /* @__PURE__ */ jsx(Grid2, { size: { xs: 12, sm: 4 }, children: /* @__PURE__ */ jsxs(Typography$1, { variant: "body2", children: [
28370
25979
  /* @__PURE__ */ jsxs("strong", { children: [
28371
- t2("CASH_IN_HAND"),
25980
+ t2("STAMP_DUTY"),
28372
25981
  ": "
28373
25982
  ] }),
28374
- formatAmount(financeCalculation == null ? void 0 : financeCalculation.cashInHand)
25983
+ formatAmount(financeCalculation.stampDuty)
25984
+ ] }) }),
25985
+ financeCalculation.legalFee !== void 0 && /* @__PURE__ */ jsx(Grid2, { size: { xs: 12, sm: 4 }, children: /* @__PURE__ */ jsxs(Typography$1, { variant: "body2", children: [
25986
+ /* @__PURE__ */ jsxs("strong", { children: [
25987
+ t2("LEGAL_FEES"),
25988
+ ": "
25989
+ ] }),
25990
+ formatAmount(financeCalculation.legalFee)
25991
+ ] }) }),
25992
+ financeCalculation.cashInHand !== void 0 && /* @__PURE__ */ jsx(Grid2, { size: { xs: 12, sm: 4 }, children: /* @__PURE__ */ jsxs(Typography$1, { variant: "body2", children: [
25993
+ /* @__PURE__ */ jsxs("strong", { children: [
25994
+ t2("DISBURSEMENT"),
25995
+ ": "
25996
+ ] }),
25997
+ formatAmount(financeCalculation.cashInHand)
28375
25998
  ] }) })
28376
- ] }),
28377
- /* @__PURE__ */ jsx("div", { className: "flex justify-end mt-10", children: /* @__PURE__ */ jsx(
25999
+ ] })
26000
+ ] }),
26001
+ /* @__PURE__ */ jsx("div", { className: "px-16 py-12", children: /* @__PURE__ */ jsx(
26002
+ "embed",
26003
+ {
26004
+ src: filePath,
26005
+ type: "application/pdf",
26006
+ width: "100%",
26007
+ style: { height: pdfOnly ? "85vh" : "70vh" }
26008
+ }
26009
+ ) }),
26010
+ !pdfOnly && (showButton || showConfirmCheckbox) && /* @__PURE__ */ jsx("div", { className: "sticky bottom-0 bg-white w-full px-16 py-10", children: showConfirmCheckbox ? /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-8", children: [
26011
+ /* @__PURE__ */ jsx(
26012
+ CustomCheckbox,
26013
+ {
26014
+ label: t2("CONFIRM_INFORMATION_READ"),
26015
+ checked: isTermsConfirmed,
26016
+ onChange: (checked) => setIsTermsConfirmed(checked),
26017
+ "data-test-id": "pdf-confirm-information-checkbox"
26018
+ }
26019
+ ),
26020
+ /* @__PURE__ */ jsx("div", { className: "flex justify-end", children: /* @__PURE__ */ jsx(
28378
26021
  ColoredSubmitButton,
28379
26022
  {
28380
26023
  variant: "contained",
28381
- disabled: isButtonLoading,
26024
+ disabled: isButtonLoading || !isTermsConfirmed,
28382
26025
  onClick: onConfirm,
28383
26026
  isLoading: isButtonLoading,
28384
26027
  className: "rounded-6",
28385
26028
  text: bottomButtonLabel
28386
26029
  }
28387
26030
  ) })
28388
- ] })
26031
+ ] }) : /* @__PURE__ */ jsx("div", { className: "flex justify-end", children: /* @__PURE__ */ jsx(
26032
+ ColoredSubmitButton,
26033
+ {
26034
+ variant: "contained",
26035
+ disabled: isButtonLoading,
26036
+ onClick: onConfirm,
26037
+ isLoading: isButtonLoading,
26038
+ className: "rounded-6",
26039
+ text: bottomButtonLabel
26040
+ }
26041
+ ) }) })
28389
26042
  ] }) });
28390
26043
  };
28391
- const CustomCheckbox = ({
28392
- label,
28393
- onChange,
28394
- checked: controlledChecked,
28395
- ...props
28396
- }) => {
28397
- const [internalChecked, setInternalChecked] = React__default.useState(false);
28398
- const isControlled = controlledChecked !== void 0;
28399
- const isChecked = isControlled ? controlledChecked : internalChecked;
28400
- const handleChange = (newChecked) => {
28401
- if (!isControlled) {
28402
- setInternalChecked(newChecked);
28403
- }
28404
- onChange == null ? void 0 : onChange(newChecked);
28405
- };
28406
- return /* @__PURE__ */ jsx(Fragment, { children: label ? /* @__PURE__ */ jsx(
28407
- FormControlLabel,
28408
- {
28409
- control: /* @__PURE__ */ jsx(
28410
- Checkbox$1,
28411
- {
28412
- checked: isChecked,
28413
- onChange: (event) => handleChange(event.target.checked),
28414
- ...props
28415
- }
28416
- ),
28417
- label
28418
- }
28419
- ) : /* @__PURE__ */ jsx(
28420
- Checkbox$1,
28421
- {
28422
- checked: isChecked,
28423
- onChange: (event) => handleChange(event.target.checked),
28424
- ...props
28425
- }
28426
- ) });
28427
- };
28428
- instance.addResourceBundle("en", "Dialog", locale$3);
28429
- instance.addResourceBundle("ms", "Dialog", locale$2);
26044
+ i18next.addResourceBundle("en", "Dialog", locale$3);
26045
+ i18next.addResourceBundle("ms", "Dialog", locale$2);
28430
26046
  function DocumentSigningDialog({
28431
26047
  financeDetail,
28432
26048
  loginUserDetail,
28433
26049
  digitalSignatureRole,
28434
26050
  ColoredSubmitButton,
28435
- financeCalculation
26051
+ financeCalculation,
26052
+ showConfirmCheckbox = false
28436
26053
  }) {
28437
26054
  const { t: t2 } = useTranslation("Dialog");
28438
26055
  const open = useSelector(getIsDocumentSignatureDialogOpen);
28439
26056
  const documentSignJPDF = useSelector(getDocumentSignJPDF);
26057
+ const signedDocumentJPDF = useSelector(getSignedDocumentJPDF);
28440
26058
  const isProcessSignatureLoading = useSelector(getIsProcessSignatureLoading);
28441
26059
  const activeFinanceDetail = useSelector(getActiveFinanceDetail);
28442
26060
  const dispatch = useDispatch();
@@ -28485,6 +26103,11 @@ function DocumentSigningDialog({
28485
26103
  dispatch(setActiveFinanceDetail(null));
28486
26104
  dispatch(setIsDocumentSignatureDialogOpen(false));
28487
26105
  };
26106
+ const handleSignedPDFClose = () => {
26107
+ dispatch(setSignedDocumentJPDF(""));
26108
+ dispatch(setActiveFinanceDetail(null));
26109
+ dispatch(setIsDocumentSignatureDialogOpen(false));
26110
+ };
28488
26111
  return /* @__PURE__ */ jsx(Fragment, { children: /* @__PURE__ */ jsx(Dialog$1, { open, onClose: handleClose, maxWidth: "xs", children: /* @__PURE__ */ jsxs("div", { className: "flex flex-col p-16", children: [
28489
26112
  /* @__PURE__ */ jsx("div", { className: "flex flex-col items-center", children: /* @__PURE__ */ jsx(
28490
26113
  "img",
@@ -28553,10 +26176,10 @@ function DocumentSigningDialog({
28553
26176
  /* @__PURE__ */ jsx(
28554
26177
  PDFPreviewForTheSignature,
28555
26178
  {
28556
- filePath: documentSignJPDF,
28557
- open: !!documentSignJPDF,
26179
+ filePath: signedDocumentJPDF || documentSignJPDF,
26180
+ open: !!(signedDocumentJPDF || documentSignJPDF),
28558
26181
  isButtonLoading: isProcessSignatureLoading,
28559
- onClose: () => handlePDFPreviewClose(),
26182
+ onClose: signedDocumentJPDF ? handleSignedPDFClose : handlePDFPreviewClose,
28560
26183
  bottomButtonLabel: t2("SIGN_DOCUMENT"),
28561
26184
  onConfirm: handleButtonClick,
28562
26185
  applicationDetailsData: activeFinanceDetail || financeDetail,
@@ -28564,7 +26187,10 @@ function DocumentSigningDialog({
28564
26187
  loginUserRoles,
28565
26188
  ColoredSubmitButton,
28566
26189
  financeCalculation,
28567
- t: t2
26190
+ t: t2,
26191
+ dialogTitle: t2("PDF_PREVIEW_TITLE"),
26192
+ showConfirmCheckbox,
26193
+ pdfOnly: !!signedDocumentJPDF
28568
26194
  }
28569
26195
  )
28570
26196
  ] })
@@ -29344,16 +26970,16 @@ function useAutocomplete(props) {
29344
26970
  let groupedOptions = filteredOptions;
29345
26971
  if (groupBy) {
29346
26972
  const indexBy = /* @__PURE__ */ new Map();
29347
- let warn2 = false;
26973
+ let warn = false;
29348
26974
  groupedOptions = filteredOptions.reduce((acc, option, index) => {
29349
26975
  const group = groupBy(option);
29350
26976
  if (acc.length > 0 && acc[acc.length - 1].group === group) {
29351
26977
  acc[acc.length - 1].options.push(option);
29352
26978
  } else {
29353
26979
  if (process.env.NODE_ENV !== "production") {
29354
- if (indexBy.get(group) && !warn2) {
26980
+ if (indexBy.get(group) && !warn) {
29355
26981
  console.warn(`MUI: The options provided combined with the \`groupBy\` method of ${componentName} returns duplicated headers.`, "You can solve the issue by sorting the options with the output of `groupBy`.");
29356
- warn2 = true;
26982
+ warn = true;
29357
26983
  }
29358
26984
  indexBy.set(group, true);
29359
26985
  }
@@ -29949,26 +27575,26 @@ var passive = {
29949
27575
  passive: true
29950
27576
  };
29951
27577
  function effect(_ref) {
29952
- var state = _ref.state, instance2 = _ref.instance, options = _ref.options;
27578
+ var state = _ref.state, instance = _ref.instance, options = _ref.options;
29953
27579
  var _options$scroll = options.scroll, scroll = _options$scroll === void 0 ? true : _options$scroll, _options$resize = options.resize, resize = _options$resize === void 0 ? true : _options$resize;
29954
27580
  var window2 = getWindow(state.elements.popper);
29955
27581
  var scrollParents = [].concat(state.scrollParents.reference, state.scrollParents.popper);
29956
27582
  if (scroll) {
29957
27583
  scrollParents.forEach(function(scrollParent) {
29958
- scrollParent.addEventListener("scroll", instance2.update, passive);
27584
+ scrollParent.addEventListener("scroll", instance.update, passive);
29959
27585
  });
29960
27586
  }
29961
27587
  if (resize) {
29962
- window2.addEventListener("resize", instance2.update, passive);
27588
+ window2.addEventListener("resize", instance.update, passive);
29963
27589
  }
29964
27590
  return function() {
29965
27591
  if (scroll) {
29966
27592
  scrollParents.forEach(function(scrollParent) {
29967
- scrollParent.removeEventListener("scroll", instance2.update, passive);
27593
+ scrollParent.removeEventListener("scroll", instance.update, passive);
29968
27594
  });
29969
27595
  }
29970
27596
  if (resize) {
29971
- window2.removeEventListener("resize", instance2.update, passive);
27597
+ window2.removeEventListener("resize", instance.update, passive);
29972
27598
  }
29973
27599
  };
29974
27600
  }
@@ -30705,7 +28331,7 @@ function popperGenerator(generatorOptions) {
30705
28331
  };
30706
28332
  var effectCleanupFns = [];
30707
28333
  var isDestroyed = false;
30708
- var instance2 = {
28334
+ var instance = {
30709
28335
  state,
30710
28336
  setOptions: function setOptions(setOptionsAction) {
30711
28337
  var options2 = typeof setOptionsAction === "function" ? setOptionsAction(state.options) : setOptionsAction;
@@ -30720,7 +28346,7 @@ function popperGenerator(generatorOptions) {
30720
28346
  return m3.enabled;
30721
28347
  });
30722
28348
  runModifierEffects();
30723
- return instance2.update();
28349
+ return instance.update();
30724
28350
  },
30725
28351
  // Sync update – it will always be executed, even if not necessary. This
30726
28352
  // is useful for low frequency updates where sync behavior simplifies the
@@ -30756,7 +28382,7 @@ function popperGenerator(generatorOptions) {
30756
28382
  state,
30757
28383
  options: _options,
30758
28384
  name,
30759
- instance: instance2
28385
+ instance
30760
28386
  }) || state;
30761
28387
  }
30762
28388
  }
@@ -30765,7 +28391,7 @@ function popperGenerator(generatorOptions) {
30765
28391
  // not necessary (debounced to run at most once-per-tick)
30766
28392
  update: debounce(function() {
30767
28393
  return new Promise(function(resolve) {
30768
- instance2.forceUpdate();
28394
+ instance.forceUpdate();
30769
28395
  resolve(state);
30770
28396
  });
30771
28397
  }),
@@ -30775,9 +28401,9 @@ function popperGenerator(generatorOptions) {
30775
28401
  }
30776
28402
  };
30777
28403
  if (!areValidElements(reference2, popper2)) {
30778
- return instance2;
28404
+ return instance;
30779
28405
  }
30780
- instance2.setOptions(options).then(function(state2) {
28406
+ instance.setOptions(options).then(function(state2) {
30781
28407
  if (!isDestroyed && options.onFirstUpdate) {
30782
28408
  options.onFirstUpdate(state2);
30783
28409
  }
@@ -30789,7 +28415,7 @@ function popperGenerator(generatorOptions) {
30789
28415
  var cleanupFn = effect2({
30790
28416
  state,
30791
28417
  name,
30792
- instance: instance2,
28418
+ instance,
30793
28419
  options: options2
30794
28420
  });
30795
28421
  var noopFn = function noopFn2() {
@@ -30804,7 +28430,7 @@ function popperGenerator(generatorOptions) {
30804
28430
  });
30805
28431
  effectCleanupFns = [];
30806
28432
  }
30807
- return instance2;
28433
+ return instance;
30808
28434
  };
30809
28435
  }
30810
28436
  var defaultModifiers = [eventListeners, popperOffsets$1, computeStyles$1, applyStyles$1, offset$1, flip$1, preventOverflow$1, arrow$1, hide$1];
@@ -32898,9 +30524,9 @@ const InputBase = /* @__PURE__ */ React.forwardRef(function InputBase2(inProps,
32898
30524
  current: isControlled
32899
30525
  } = React.useRef(value != null);
32900
30526
  const inputRef = React.useRef();
32901
- const handleInputRefWarning = React.useCallback((instance2) => {
30527
+ const handleInputRefWarning = React.useCallback((instance) => {
32902
30528
  if (process.env.NODE_ENV !== "production") {
32903
- if (instance2 && instance2.nodeName !== "INPUT" && !instance2.focus) {
30529
+ if (instance && instance.nodeName !== "INPUT" && !instance.focus) {
32904
30530
  console.error(["MUI: You have provided a `inputComponent` to the input component", "that does not correctly handle the `ref` prop.", "Make sure the `ref` prop is called with a HTMLInputElement."].join("\n"));
32905
30531
  }
32906
30532
  }
@@ -41920,9 +39546,9 @@ function useForkRef$1(...refs) {
41920
39546
  if (refs.every((ref) => ref == null)) {
41921
39547
  return null;
41922
39548
  }
41923
- return (instance2) => {
39549
+ return (instance) => {
41924
39550
  refs.forEach((ref) => {
41925
- setRef$1(ref, instance2);
39551
+ setRef$1(ref, instance);
41926
39552
  });
41927
39553
  };
41928
39554
  }, refs);
@@ -43091,9 +40717,9 @@ function useForkRef(...refs) {
43091
40717
  if (refs.every((ref) => ref == null)) {
43092
40718
  return null;
43093
40719
  }
43094
- return (instance2) => {
40720
+ return (instance) => {
43095
40721
  refs.forEach((ref) => {
43096
- setRef(ref, instance2);
40722
+ setRef(ref, instance);
43097
40723
  });
43098
40724
  };
43099
40725
  }, refs);
@@ -43515,7 +41141,7 @@ const useUtilityClasses$m = (ownerState) => {
43515
41141
  };
43516
41142
  return composeClasses$1(slots, getGridUtilityClass, classes);
43517
41143
  };
43518
- const Grid = /* @__PURE__ */ React.forwardRef(function Grid2(inProps, ref) {
41144
+ const Grid = /* @__PURE__ */ React.forwardRef(function Grid3(inProps, ref) {
43519
41145
  const themeProps = useDefaultProps({
43520
41146
  props: inProps,
43521
41147
  name: "MuiGrid"
@@ -46479,11 +44105,11 @@ const usePickerLayoutProps = ({
46479
44105
  };
46480
44106
  };
46481
44107
  const buildWarning = (message, gravity = "warning") => {
46482
- let alreadyWarned2 = false;
44108
+ let alreadyWarned = false;
46483
44109
  const cleanMessage = Array.isArray(message) ? message.join("\n") : message;
46484
44110
  return () => {
46485
- if (!alreadyWarned2) {
46486
- alreadyWarned2 = true;
44111
+ if (!alreadyWarned) {
44112
+ alreadyWarned = true;
46487
44113
  if (gravity === "error") {
46488
44114
  console.error(cleanMessage);
46489
44115
  } else {
@@ -57577,7 +55203,7 @@ export {
57577
55203
  getRemarkListData,
57578
55204
  getSelectedMediaFilePath,
57579
55205
  hideMessage,
57580
- instance as i18n,
55206
+ default2 as i18n,
57581
55207
  reassignStaffMember,
57582
55208
  setActiveFinanceDetail,
57583
55209
  setDocumentSignJPDF,