@sito/dashboard 0.0.76 → 0.0.78

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,569 +0,0 @@
1
- import "./SelectInput.css";
2
- import { jsxs as S, jsx as a, Fragment as Z } from "react/jsx-runtime";
3
- import { c as i } from "./classNames-DDRjbGA1.js";
4
- import { forwardRef as V, useState as R, useEffect as K, useMemo as $, useRef as B, useCallback as A, useLayoutEffect as ee } from "react";
5
- import { C as q } from "./Chip-6bEZ7uwv.js";
6
- import { I as te } from "./IconButton-CqPk_OXG.js";
7
- import { C as ne } from "./Close-rKC9AcNX.js";
8
- const ue = V(function(l, m) {
9
- const {
10
- state: f,
11
- value: t,
12
- onChange: r,
13
- options: w = [],
14
- name: D = "",
15
- id: b = "",
16
- label: N = "",
17
- containerClassName: I = "",
18
- inputContainerClassName: v = "",
19
- helperText: E = "",
20
- placeholder: F = "",
21
- multiple: h = !1,
22
- ...T
23
- } = l, [o, g] = R("");
24
- K(() => {
25
- if (!h && t && !Array.isArray(t)) {
26
- g(String(t.value ?? t.name ?? ""));
27
- return;
28
- }
29
- g("");
30
- }, [h, t]);
31
- const [C, y] = R(!1), [k, x] = R(-1), s = $(
32
- () => w.filter((e) => {
33
- const n = String(e.value ?? e.name).toLowerCase().includes(o?.toLowerCase());
34
- return Array.isArray(t) && t.length ? n && !t.some((u) => u.id === e.id) : t && !Array.isArray(t) ? n && t.id !== e.id : n;
35
- }),
36
- [w, t, o]
37
- );
38
- K(() => {
39
- if (!C || !s.length) {
40
- x(-1);
41
- return;
42
- }
43
- x(0);
44
- }, [C, s]);
45
- const c = B(null), p = B(null), [H, L] = R(!1), d = B(null);
46
- K(() => {
47
- const e = (u) => {
48
- c.current && !c.current.contains(u.target) && y(!1);
49
- }, n = (u) => {
50
- u.key === "Escape" && y(!1);
51
- };
52
- return document.addEventListener("mousedown", e), document.addEventListener("keydown", n), () => {
53
- document.removeEventListener("mousedown", e), document.removeEventListener("keydown", n);
54
- };
55
- }, []);
56
- const U = A((e) => {
57
- g(e.target.value);
58
- }, []), O = A(
59
- (e) => {
60
- e ? h ? (g(""), Array.isArray(t) && t.length ? r([...t, e]) : r([e])) : (g(String(e.name ?? e.value ?? "")), r(e)) : r(null), y(!1);
61
- },
62
- [h, r, t]
63
- ), W = A(
64
- (e) => {
65
- if (!s.length) {
66
- e.key === "Escape" && y(!1);
67
- return;
68
- }
69
- if (e.key === "ArrowDown" || e.key === "ArrowUp") {
70
- if (e.preventDefault(), !C) {
71
- y(!0), x(0);
72
- return;
73
- }
74
- x((n) => {
75
- const u = n >= 0 ? n : 0;
76
- return e.key === "ArrowDown" ? (u + 1 + s.length) % s.length : (u - 1 + s.length) % s.length;
77
- });
78
- return;
79
- }
80
- if (e.key === "Enter" && C) {
81
- e.preventDefault();
82
- const n = k >= 0 ? k : 0;
83
- O(s[n]);
84
- return;
85
- }
86
- e.key === "Escape" && C && (e.preventDefault(), y(!1));
87
- },
88
- [
89
- O,
90
- k,
91
- C,
92
- s
93
- ]
94
- ), P = A(
95
- (e) => {
96
- if (!Array.isArray(t)) {
97
- r(null);
98
- return;
99
- }
100
- const n = t.filter((u, G) => G !== e);
101
- n.length ? r(n) : r(null);
102
- },
103
- [r, t]
104
- ), j = A(() => {
105
- Array.isArray(t) && r([t[0]]);
106
- }, [r, t]);
107
- return ee(() => {
108
- const e = d.current?.offsetWidth ?? 0, n = c.current?.offsetWidth ?? 0;
109
- L(e > n * 0.4);
110
- }, [t]), /* @__PURE__ */ S(
111
- "div",
112
- {
113
- className: i("autocomplete-input-container", I),
114
- ref: c,
115
- children: [
116
- /* @__PURE__ */ S("div", { className: "autocomplete-value-input-container", children: [
117
- /* @__PURE__ */ a(
118
- X,
119
- {
120
- state: f,
121
- name: D,
122
- id: b,
123
- value: o,
124
- onChange: U,
125
- placeholder: F,
126
- helperText: E,
127
- onFocus: () => y(!0),
128
- onKeyDown: W,
129
- label: N,
130
- containerClassName: i(
131
- "autocomplete-text-input",
132
- v
133
- ),
134
- ref: m ?? p,
135
- ...T,
136
- children: !h && t && !Array.isArray(t) && (t.value || t.name) && /* @__PURE__ */ a(
137
- te,
138
- {
139
- icon: /* @__PURE__ */ a(ne, {}),
140
- className: "autocomplete-delete-button",
141
- onClick: (e) => {
142
- O(), e.stopPropagation();
143
- }
144
- }
145
- )
146
- }
147
- ),
148
- h && Array.isArray(t) && t.length ? /* @__PURE__ */ a("ul", { ref: d, className: "autocomplete-value-container", children: H ? /* @__PURE__ */ S(Z, { children: [
149
- /* @__PURE__ */ a("li", { children: /* @__PURE__ */ a(
150
- q,
151
- {
152
- text: t[0]?.value ?? t[0]?.name,
153
- onDelete: (e) => {
154
- P(0), e.stopPropagation();
155
- }
156
- }
157
- ) }),
158
- t.length > 1 && /* @__PURE__ */ a("li", { children: /* @__PURE__ */ a(
159
- q,
160
- {
161
- text: `+${t.length - 1}`,
162
- onDelete: (e) => {
163
- j(), e.stopPropagation();
164
- }
165
- }
166
- ) })
167
- ] }) : t.map((e, n) => /* @__PURE__ */ a("li", { children: /* @__PURE__ */ a(
168
- q,
169
- {
170
- text: String(e.value ?? e.name),
171
- onDelete: (u) => {
172
- P(n), u.stopPropagation();
173
- }
174
- }
175
- ) }, e.id ?? e.value ?? e.name)) }) : null
176
- ] }),
177
- C && /* @__PURE__ */ a(
178
- "ul",
179
- {
180
- className: "autocomplete-suggestions-container",
181
- style: { width: c.current?.offsetWidth },
182
- children: s.map((e) => /* @__PURE__ */ a(
183
- "li",
184
- {
185
- className: i(
186
- "autocomplete-suggestion-item",
187
- e.id === s[k]?.id ? "highlighted" : ""
188
- ),
189
- onMouseEnter: () => x(
190
- s.findIndex((n) => n.id === e.id)
191
- ),
192
- onClick: (n) => {
193
- O(e), n.stopPropagation();
194
- },
195
- children: e.value ?? e.name
196
- },
197
- e.id ?? e.value ?? e.name
198
- ))
199
- }
200
- )
201
- ]
202
- }
203
- );
204
- });
205
- var M = /* @__PURE__ */ ((l) => (l.error = "error", l.good = "good", l.default = "default", l))(M || {});
206
- const _ = (l) => {
207
- switch (l) {
208
- case "error":
209
- return "input-error";
210
- case "good":
211
- return "input-good";
212
- default:
213
- return "input-normal";
214
- }
215
- }, z = (l) => {
216
- switch (l) {
217
- case "error":
218
- return "input-label-error";
219
- case "good":
220
- return "input-label-good";
221
- default:
222
- return "input-label-normal";
223
- }
224
- }, Q = (l) => {
225
- switch (l) {
226
- case "error":
227
- return "input-helper-text-error";
228
- case "good":
229
- return "input-helper-text-good";
230
- default:
231
- return "input-helper-text-normal";
232
- }
233
- }, de = V(function(l, m) {
234
- const {
235
- checked: f,
236
- onChange: t,
237
- name: r = "",
238
- id: w = "",
239
- label: D = "",
240
- state: b = M.default,
241
- containerClassName: N = "",
242
- inputClassName: I = "",
243
- labelClassName: v = "",
244
- ...E
245
- } = l;
246
- return /* @__PURE__ */ S("label", { className: i("input-check-container", N), children: [
247
- /* @__PURE__ */ a(
248
- "input",
249
- {
250
- id: w,
251
- ref: m,
252
- name: r,
253
- type: "checkbox",
254
- checked: f,
255
- onChange: t,
256
- className: i(
257
- "input-check",
258
- _(b),
259
- I
260
- ),
261
- ...E
262
- }
263
- ),
264
- /* @__PURE__ */ a(
265
- "span",
266
- {
267
- className: i(
268
- "input-check-label",
269
- z(b),
270
- v
271
- ),
272
- children: D
273
- }
274
- )
275
- ] });
276
- }), J = (l) => l == null ? !1 : Array.isArray(l) ? l.length > 0 : `${l}`.length > 0, X = V(function(l, m) {
277
- const {
278
- children: f,
279
- state: t = M.default,
280
- label: r = "",
281
- containerClassName: w = "",
282
- inputClassName: D = "",
283
- labelClassName: b = "",
284
- helperText: N = "",
285
- helperTextClassName: I = "",
286
- value: v,
287
- defaultValue: E,
288
- onChange: F,
289
- onFocus: h,
290
- onBlur: T,
291
- ...o
292
- } = l, g = v !== void 0, [C, y] = R(
293
- () => J(E)
294
- ), k = g ? J(v) : C, x = o.type === "date", s = !!o.placeholder || x, c = (p) => {
295
- g || y(p.currentTarget.value.length > 0), F?.(p);
296
- };
297
- return /* @__PURE__ */ S("div", { className: i("text-input-container", w), children: [
298
- /* @__PURE__ */ S("div", { className: "text-input-field", children: [
299
- /* @__PURE__ */ a(
300
- "input",
301
- {
302
- ref: m,
303
- defaultValue: E,
304
- onChange: c,
305
- onFocus: h,
306
- onBlur: T,
307
- ...g ? { value: v } : {},
308
- className: i(
309
- "text-input",
310
- _(t),
311
- D,
312
- k ? "has-value" : "",
313
- o.placeholder ? "has-placeholder" : "",
314
- s ? "keep-label-up" : ""
315
- ),
316
- ...o
317
- }
318
- ),
319
- !!r && /* @__PURE__ */ S(
320
- "label",
321
- {
322
- htmlFor: o.id,
323
- className: i(
324
- "text-input-label",
325
- z(t),
326
- b
327
- ),
328
- children: [
329
- r,
330
- o.required ? " *" : ""
331
- ]
332
- }
333
- ),
334
- f
335
- ] }),
336
- !!N && /* @__PURE__ */ a(
337
- "p",
338
- {
339
- className: i(
340
- "text-input-helper-text",
341
- Q(t),
342
- I
343
- ),
344
- children: N
345
- }
346
- )
347
- ] });
348
- }), he = V(function(l, m) {
349
- const {
350
- value: f,
351
- onChange: t,
352
- options: r,
353
- containerClassName: w = "",
354
- inputClassName: D = "",
355
- labelClassName: b = "",
356
- helperText: N = "",
357
- helperTextClassName: I = "",
358
- label: v = "",
359
- placeholder: E = "",
360
- name: F = "",
361
- id: h = "",
362
- state: T = M.default,
363
- native: o = !0,
364
- disabled: g,
365
- required: C,
366
- autoFocus: y,
367
- children: k,
368
- ...x
369
- } = l, s = B(null), [c, p] = R(!1), [H, L] = R(-1), d = $(
370
- () => r.findIndex(
371
- (e) => String(e.id) === String(f ?? r[0]?.id ?? "")
372
- ),
373
- [r, f]
374
- ), U = $(
375
- () => d >= 0 ? r[d] : void 0,
376
- [r, d]
377
- );
378
- K(() => {
379
- if (!(o || !c)) {
380
- if (!r.length) {
381
- L(-1);
382
- return;
383
- }
384
- L(d >= 0 ? d : 0);
385
- }
386
- }, [o, r.length, d, c]), K(() => {
387
- if (o) return;
388
- const e = (n) => {
389
- s.current && !s.current.contains(n.target) && p(!1);
390
- };
391
- return document.addEventListener("mousedown", e), () => {
392
- document.removeEventListener("mousedown", e);
393
- };
394
- }, [o]);
395
- const O = A(
396
- (e) => {
397
- m && (typeof m == "function" ? m(e) : m.current = e);
398
- },
399
- [m]
400
- ), W = A(
401
- (e) => {
402
- if (!t) return;
403
- const n = {
404
- target: { value: String(e) },
405
- currentTarget: { value: String(e) }
406
- };
407
- t(n);
408
- },
409
- [t]
410
- ), P = A(
411
- (e) => {
412
- const n = r[e];
413
- n && (W(n.id), p(!1));
414
- },
415
- [W, r]
416
- ), j = A(
417
- (e) => {
418
- if (r.length) {
419
- if (e.key === "ArrowDown" || e.key === "ArrowUp") {
420
- if (e.preventDefault(), !c) {
421
- p(!0);
422
- const n = d >= 0 ? d : 0;
423
- L(n);
424
- return;
425
- }
426
- L((n) => {
427
- const u = n >= 0 ? n : d;
428
- return e.key === "ArrowDown" ? (u + 1 + r.length) % r.length : (u - 1 + r.length) % r.length;
429
- });
430
- return;
431
- }
432
- if (e.key === "Enter") {
433
- if (!c) {
434
- e.preventDefault(), p(!0), L(d >= 0 ? d : 0);
435
- return;
436
- }
437
- e.preventDefault(), P(H >= 0 ? H : 0);
438
- return;
439
- }
440
- e.key === "Escape" && c && (e.preventDefault(), p(!1));
441
- }
442
- },
443
- [H, r, P, d, c]
444
- );
445
- return o ? /* @__PURE__ */ S("div", { className: i("select-input-container", w), children: [
446
- /* @__PURE__ */ a(
447
- "select",
448
- {
449
- ...x,
450
- id: h,
451
- ref: O,
452
- name: F,
453
- value: f,
454
- onChange: t,
455
- className: i(
456
- "select-input",
457
- _(T),
458
- "peer",
459
- D
460
- ),
461
- children: r?.map((e) => /* @__PURE__ */ a("option", { value: e.id, children: e.value ?? e.name ?? e.id }, e.id))
462
- }
463
- ),
464
- /* @__PURE__ */ a(
465
- "label",
466
- {
467
- htmlFor: h,
468
- className: i(
469
- "select-input-label",
470
- z(T),
471
- b
472
- ),
473
- children: v
474
- }
475
- ),
476
- k,
477
- N && /* @__PURE__ */ a(
478
- "p",
479
- {
480
- className: i(
481
- "select-input-helper-text",
482
- Q(T),
483
- I
484
- ),
485
- children: N
486
- }
487
- )
488
- ] }) : /* @__PURE__ */ S(
489
- "div",
490
- {
491
- ref: s,
492
- className: i("select-input-container", w),
493
- children: [
494
- /* @__PURE__ */ a(
495
- "select",
496
- {
497
- ...x,
498
- ref: O,
499
- name: F,
500
- id: h,
501
- value: f,
502
- onChange: t,
503
- className: "select-input-native-hidden",
504
- tabIndex: -1,
505
- "aria-hidden": !0,
506
- children: r?.map((e) => /* @__PURE__ */ a("option", { value: e.id, children: e.value ?? e.name ?? e.id }, e.id))
507
- }
508
- ),
509
- /* @__PURE__ */ a(
510
- X,
511
- {
512
- id: h,
513
- name: F,
514
- state: T,
515
- value: String(U?.value ?? U?.name ?? ""),
516
- readOnly: !0,
517
- label: v,
518
- helperText: N,
519
- containerClassName: "select-input-text-container",
520
- inputClassName: i("select-input-text", D),
521
- labelClassName: b,
522
- helperTextClassName: I,
523
- placeholder: E,
524
- disabled: g,
525
- required: C,
526
- autoFocus: y,
527
- onClick: () => p((e) => !e),
528
- onKeyDown: j,
529
- onFocus: () => p(!0),
530
- role: "combobox",
531
- "aria-expanded": c,
532
- "aria-haspopup": "listbox",
533
- children: k
534
- }
535
- ),
536
- c && /* @__PURE__ */ a("ul", { className: "select-input-options-container", role: "listbox", children: r.map((e, n) => {
537
- const u = String(e.id) === String(f);
538
- return /* @__PURE__ */ a(
539
- "li",
540
- {
541
- role: "option",
542
- "aria-selected": u,
543
- className: i(
544
- "select-input-option-item",
545
- n === H ? "highlighted" : ""
546
- ),
547
- onMouseEnter: () => L(n),
548
- onClick: (Y) => {
549
- P(n), Y.stopPropagation();
550
- },
551
- children: e.value ?? e.name ?? e.id
552
- },
553
- e.id
554
- );
555
- }) })
556
- ]
557
- }
558
- );
559
- });
560
- export {
561
- ue as A,
562
- de as C,
563
- he as S,
564
- X as T,
565
- M as a,
566
- Q as h,
567
- _ as i,
568
- z as l
569
- };
@@ -1 +0,0 @@
1
- var Y=require("./SelectInput.css");const n=require("react/jsx-runtime"),c=require("./classNames-DHAzUjfZ.cjs"),l=require("react"),U=require("./Chip-N4r2Xf9l.cjs"),z=require("./IconButton-DVZCHIHB.cjs"),G=require("./Close-O9P7wJGf.cjs"),J=l.forwardRef(function(r,f){const{state:x,value:t,onChange:s,options:v=[],name:S="",id:w="",label:y="",containerClassName:A="",inputContainerClassName:b="",helperText:I="",placeholder:T="",multiple:p=!1,...D}=r,[o,g]=l.useState("");l.useEffect(()=>{if(!p&&t&&!Array.isArray(t)){g(String(t.value??t.name??""));return}g("")},[p,t]);const[N,C]=l.useState(!1),[j,k]=l.useState(-1),i=l.useMemo(()=>v.filter(e=>{const a=String(e.value??e.name).toLowerCase().includes(o?.toLowerCase());return Array.isArray(t)&&t.length?a&&!t.some(d=>d.id===e.id):t&&!Array.isArray(t)?a&&t.id!==e.id:a}),[v,t,o]);l.useEffect(()=>{if(!N||!i.length){k(-1);return}k(0)},[N,i]);const u=l.useRef(null),m=l.useRef(null),[L,E]=l.useState(!1),h=l.useRef(null);l.useEffect(()=>{const e=d=>{u.current&&!u.current.contains(d.target)&&C(!1)},a=d=>{d.key==="Escape"&&C(!1)};return document.addEventListener("mousedown",e),document.addEventListener("keydown",a),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",a)}},[]);const O=l.useCallback(e=>{g(e.target.value)},[]),R=l.useCallback(e=>{e?p?(g(""),Array.isArray(t)&&t.length?s([...t,e]):s([e])):(g(String(e.name??e.value??"")),s(e)):s(null),C(!1)},[p,s,t]),P=l.useCallback(e=>{if(!i.length){e.key==="Escape"&&C(!1);return}if(e.key==="ArrowDown"||e.key==="ArrowUp"){if(e.preventDefault(),!N){C(!0),k(0);return}k(a=>{const d=a>=0?a:0;return e.key==="ArrowDown"?(d+1+i.length)%i.length:(d-1+i.length)%i.length});return}if(e.key==="Enter"&&N){e.preventDefault();const a=j>=0?j:0;R(i[a]);return}e.key==="Escape"&&N&&(e.preventDefault(),C(!1))},[R,j,N,i]),F=l.useCallback(e=>{if(!Array.isArray(t)){s(null);return}const a=t.filter((d,M)=>M!==e);a.length?s(a):s(null)},[s,t]),K=l.useCallback(()=>{Array.isArray(t)&&s([t[0]])},[s,t]);return l.useLayoutEffect(()=>{const e=h.current?.offsetWidth??0,a=u.current?.offsetWidth??0;E(e>a*.4)},[t]),n.jsxs("div",{className:c.classNames("autocomplete-input-container",A),ref:u,children:[n.jsxs("div",{className:"autocomplete-value-input-container",children:[n.jsx(V,{state:x,name:S,id:w,value:o,onChange:O,placeholder:T,helperText:I,onFocus:()=>C(!0),onKeyDown:P,label:y,containerClassName:c.classNames("autocomplete-text-input",b),ref:f??m,...D,children:!p&&t&&!Array.isArray(t)&&(t.value||t.name)&&n.jsx(z.IconButton,{icon:n.jsx(G.Close,{}),className:"autocomplete-delete-button",onClick:e=>{R(),e.stopPropagation()}})}),p&&Array.isArray(t)&&t.length?n.jsx("ul",{ref:h,className:"autocomplete-value-container",children:L?n.jsxs(n.Fragment,{children:[n.jsx("li",{children:n.jsx(U.Chip,{text:t[0]?.value??t[0]?.name,onDelete:e=>{F(0),e.stopPropagation()}})}),t.length>1&&n.jsx("li",{children:n.jsx(U.Chip,{text:`+${t.length-1}`,onDelete:e=>{K(),e.stopPropagation()}})})]}):t.map((e,a)=>n.jsx("li",{children:n.jsx(U.Chip,{text:String(e.value??e.name),onDelete:d=>{F(a),d.stopPropagation()}})},e.id??e.value??e.name))}):null]}),N&&n.jsx("ul",{className:"autocomplete-suggestions-container",style:{width:u.current?.offsetWidth},children:i.map(e=>n.jsx("li",{className:c.classNames("autocomplete-suggestion-item",e.id===i[j]?.id?"highlighted":""),onMouseEnter:()=>k(i.findIndex(a=>a.id===e.id)),onClick:a=>{R(e),a.stopPropagation()},children:e.value??e.name},e.id??e.value??e.name))})]})});var q=(r=>(r.error="error",r.good="good",r.default="default",r))(q||{});const B=r=>{switch(r){case"error":return"input-error";case"good":return"input-good";default:return"input-normal"}},H=r=>{switch(r){case"error":return"input-label-error";case"good":return"input-label-good";default:return"input-label-normal"}},W=r=>{switch(r){case"error":return"input-helper-text-error";case"good":return"input-helper-text-good";default:return"input-helper-text-normal"}},Q=l.forwardRef(function(r,f){const{checked:x,onChange:t,name:s="",id:v="",label:S="",state:w=q.default,containerClassName:y="",inputClassName:A="",labelClassName:b="",...I}=r;return n.jsxs("label",{className:c.classNames("input-check-container",y),children:[n.jsx("input",{id:v,ref:f,name:s,type:"checkbox",checked:x,onChange:t,className:c.classNames("input-check",B(w),A),...I}),n.jsx("span",{className:c.classNames("input-check-label",H(w),b),children:S})]})}),$=r=>r==null?!1:Array.isArray(r)?r.length>0:`${r}`.length>0,V=l.forwardRef(function(r,f){const{children:x,state:t=q.default,label:s="",containerClassName:v="",inputClassName:S="",labelClassName:w="",helperText:y="",helperTextClassName:A="",value:b,defaultValue:I,onChange:T,onFocus:p,onBlur:D,...o}=r,g=b!==void 0,[N,C]=l.useState(()=>$(I)),j=g?$(b):N,k=o.type==="date",i=!!o.placeholder||k,u=m=>{g||C(m.currentTarget.value.length>0),T?.(m)};return n.jsxs("div",{className:c.classNames("text-input-container",v),children:[n.jsxs("div",{className:"text-input-field",children:[n.jsx("input",{ref:f,defaultValue:I,onChange:u,onFocus:p,onBlur:D,...g?{value:b}:{},className:c.classNames("text-input",B(t),S,j?"has-value":"",o.placeholder?"has-placeholder":"",i?"keep-label-up":""),...o}),!!s&&n.jsxs("label",{htmlFor:o.id,className:c.classNames("text-input-label",H(t),w),children:[s,o.required?" *":""]}),x]}),!!y&&n.jsx("p",{className:c.classNames("text-input-helper-text",W(t),A),children:y})]})}),X=l.forwardRef(function(r,f){const{value:x,onChange:t,options:s,containerClassName:v="",inputClassName:S="",labelClassName:w="",helperText:y="",helperTextClassName:A="",label:b="",placeholder:I="",name:T="",id:p="",state:D=q.default,native:o=!0,disabled:g,required:N,autoFocus:C,children:j,...k}=r,i=l.useRef(null),[u,m]=l.useState(!1),[L,E]=l.useState(-1),h=l.useMemo(()=>s.findIndex(e=>String(e.id)===String(x??s[0]?.id??"")),[s,x]),O=l.useMemo(()=>h>=0?s[h]:void 0,[s,h]);l.useEffect(()=>{if(!(o||!u)){if(!s.length){E(-1);return}E(h>=0?h:0)}},[o,s.length,h,u]),l.useEffect(()=>{if(o)return;const e=a=>{i.current&&!i.current.contains(a.target)&&m(!1)};return document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[o]);const R=l.useCallback(e=>{f&&(typeof f=="function"?f(e):f.current=e)},[f]),P=l.useCallback(e=>{if(!t)return;const a={target:{value:String(e)},currentTarget:{value:String(e)}};t(a)},[t]),F=l.useCallback(e=>{const a=s[e];a&&(P(a.id),m(!1))},[P,s]),K=l.useCallback(e=>{if(s.length){if(e.key==="ArrowDown"||e.key==="ArrowUp"){if(e.preventDefault(),!u){m(!0);const a=h>=0?h:0;E(a);return}E(a=>{const d=a>=0?a:h;return e.key==="ArrowDown"?(d+1+s.length)%s.length:(d-1+s.length)%s.length});return}if(e.key==="Enter"){if(!u){e.preventDefault(),m(!0),E(h>=0?h:0);return}e.preventDefault(),F(L>=0?L:0);return}e.key==="Escape"&&u&&(e.preventDefault(),m(!1))}},[L,s,F,h,u]);return o?n.jsxs("div",{className:c.classNames("select-input-container",v),children:[n.jsx("select",{...k,id:p,ref:R,name:T,value:x,onChange:t,className:c.classNames("select-input",B(D),"peer",S),children:s?.map(e=>n.jsx("option",{value:e.id,children:e.value??e.name??e.id},e.id))}),n.jsx("label",{htmlFor:p,className:c.classNames("select-input-label",H(D),w),children:b}),j,y&&n.jsx("p",{className:c.classNames("select-input-helper-text",W(D),A),children:y})]}):n.jsxs("div",{ref:i,className:c.classNames("select-input-container",v),children:[n.jsx("select",{...k,ref:R,name:T,id:p,value:x,onChange:t,className:"select-input-native-hidden",tabIndex:-1,"aria-hidden":!0,children:s?.map(e=>n.jsx("option",{value:e.id,children:e.value??e.name??e.id},e.id))}),n.jsx(V,{id:p,name:T,state:D,value:String(O?.value??O?.name??""),readOnly:!0,label:b,helperText:y,containerClassName:"select-input-text-container",inputClassName:c.classNames("select-input-text",S),labelClassName:w,helperTextClassName:A,placeholder:I,disabled:g,required:N,autoFocus:C,onClick:()=>m(e=>!e),onKeyDown:K,onFocus:()=>m(!0),role:"combobox","aria-expanded":u,"aria-haspopup":"listbox",children:j}),u&&n.jsx("ul",{className:"select-input-options-container",role:"listbox",children:s.map((e,a)=>{const d=String(e.id)===String(x),M=a===L;return n.jsx("li",{role:"option","aria-selected":d,className:c.classNames("select-input-option-item",M?"highlighted":""),onMouseEnter:()=>E(a),onClick:_=>{F(a),_.stopPropagation()},children:e.value??e.name??e.id},e.id)})})]})});exports.AutocompleteInput=J;exports.CheckInput=Q;exports.SelectInput=X;exports.State=q;exports.TextInput=V;exports.helperTextStateClassName=W;exports.inputStateClassName=B;exports.labelStateClassName=H;