@starasia/date 7.1.0 → 7.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/date.es.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { jsxs as z, jsx as s, Fragment as yn } from "react/jsx-runtime";
2
- import wn, { useState as G, useRef as _, useEffect as O, forwardRef as xn, useMemo as tn } from "react";
2
+ import wn, { useState as U, useRef as _, useEffect as O, forwardRef as xn, useMemo as tn } from "react";
3
3
  const mn = `/* Cascade layer \`starasia.components\` — lihat @starasia/css (urutan: theme, base,
4
4
  starasia, components, utilities). CSS app/Tailwind utility selalu bisa
5
5
  menimpa aturan di sini. Isi sengaja tidak di-indent (diff minimal). */
@@ -32,6 +32,9 @@ const mn = `/* Cascade layer \`starasia.components\` — lihat @starasia/css (ur
32
32
  --sa-date-border-warning: var(--sa-color-warning-400, #ed9f30);
33
33
  --sa-date-accent-subtle: var(--sa-background-neutral, #f0f1f2);
34
34
  --sa-date-border-subtle: var(--sa-border-subtle, rgba(11, 18, 14, 0.14));
35
+ /* Batas field (outline/flushed) — ≥ 3:1 terhadap kanvas (WCAG 1.4.11).
36
+ --sa-date-border-color (alpha ≈1.3:1) tetap untuk thumb scrollbar Time. */
37
+ --sa-date-border-field: var(--sa-border-input, #8c8f97);
35
38
  }
36
39
  .sa-calendar-wrapper {
37
40
  position: relative;
@@ -365,7 +368,7 @@ const mn = `/* Cascade layer \`starasia.components\` — lihat @starasia/css (ur
365
368
  }
366
369
 
367
370
  .sa-calendar-input-outline {
368
- border-color: var(--sa-date-border-color);
371
+ border-color: var(--sa-date-border-field);
369
372
  background-color: transparent;
370
373
  border-width: var(--sa-border, 1px);
371
374
  border-style: solid;
@@ -415,7 +418,7 @@ const mn = `/* Cascade layer \`starasia.components\` — lihat @starasia/css (ur
415
418
  border-top: none;
416
419
  border-left: none;
417
420
  border-right: none;
418
- border-bottom: 1px solid var(--sa-date-border-color);
421
+ border-bottom: 1px solid var(--sa-date-border-field);
419
422
  border-radius: 0;
420
423
  padding-inline: 0;
421
424
  }
@@ -605,6 +608,16 @@ const mn = `/* Cascade layer \`starasia.components\` — lihat @starasia/css (ur
605
608
  height: 32px;
606
609
  }
607
610
 
611
+ /* Forced colors (Windows High Contrast): fokus field ditandai ganti warna
612
+ border + ring box-shadow — keduanya hilang di mode ini. Ganti outline
613
+ warna sistem. */
614
+ @media (forced-colors: active) {
615
+ .sa-calendar-input-container:has(input:focus) {
616
+ outline: 2px solid Highlight;
617
+ outline-offset: 1px;
618
+ }
619
+ }
620
+
608
621
  } /* @layer starasia.components */
609
622
  `, Vn = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], Q = [
610
623
  "January",
@@ -634,7 +647,7 @@ const mn = `/* Cascade layer \`starasia.components\` — lihat @starasia/css (ur
634
647
  "Dec"
635
648
  ];
636
649
  function En(n) {
637
- const [e, a] = G(n), o = _(null), r = (d) => {
650
+ const [e, a] = U(n), o = _(null), r = (d) => {
638
651
  o.current && !o.current.contains(d.target) && a(!1);
639
652
  };
640
653
  return O(() => (document.addEventListener("click", r, !0), () => {
@@ -768,7 +781,7 @@ const rn = (n) => {
768
781
  input: p
769
782
  }) => {
770
783
  var T, y, k;
771
- const [h, l] = G(null);
784
+ const [h, l] = U(null);
772
785
  let c = new Date(n.getFullYear(), n.getMonth(), 1), w = c.getDay(), M = [];
773
786
  const E = n.getMonth(), x = (/* @__PURE__ */ new Date()).toDateString(), b = !!(a.from && !a.to), m = b && h ? h : null;
774
787
  for (let v = 0; v < 42; v++) {
@@ -989,7 +1002,7 @@ const rn = (n) => {
989
1002
  }
990
1003
  )
991
1004
  }
992
- ), qn = ({
1005
+ ), Gn = ({
993
1006
  setViews: n,
994
1007
  views: e,
995
1008
  filter: a,
@@ -1053,7 +1066,7 @@ function $n(n, e) {
1053
1066
  const a = String(n.getDate()).padStart(2, "0"), o = String(n.getMonth() + 1).padStart(2, "0"), r = n.getFullYear();
1054
1067
  return e === "years" ? `${r}` : e === "months" ? `${o}/${r}` : `${a}/${o}/${r}`;
1055
1068
  }
1056
- function Un(n, e) {
1069
+ function qn(n, e) {
1057
1070
  const a = n.from ? $n(n.from, e) : "", o = n.to ? $n(n.to, e) : "";
1058
1071
  return a ? o ? `${a} ~ ${o}` : a : "";
1059
1072
  }
@@ -1079,7 +1092,7 @@ function bn(n, e) {
1079
1092
  const h = kn(p), l = new Date(h, i, d);
1080
1093
  return l.getFullYear() !== h || l.getMonth() !== i || l.getDate() !== d ? null : l;
1081
1094
  }
1082
- function Gn(n, e) {
1095
+ function Un(n, e) {
1083
1096
  const a = n.indexOf("~");
1084
1097
  if (a === -1) {
1085
1098
  const d = bn(n, e);
@@ -1172,17 +1185,17 @@ const _n = xn(
1172
1185
  helperText: v,
1173
1186
  errorText: N
1174
1187
  }, B) => {
1175
- const H = N ? "error" : c, { ref: V, isComponentVisible: F, setIsComponentVisible: $ } = En(!1), g = _(null), [Y, L] = G("days"), [S, I] = G(/* @__PURE__ */ new Date()), W = typeof m == "function" || b != null, A = !o && !W, J = !A, [D, K] = G({
1188
+ const H = N ? "error" : c, { ref: V, isComponentVisible: F, setIsComponentVisible: $ } = En(!1), g = _(null), [Y, L] = U("days"), [S, I] = U(/* @__PURE__ */ new Date()), W = typeof m == "function" || b != null, A = !o && !W, J = !A, [D, K] = U({
1176
1189
  from: (n == null ? void 0 : n.from) ?? null,
1177
1190
  to: (n == null ? void 0 : n.to) ?? null
1178
- }), [q, U] = G(null);
1191
+ }), [G, q] = U(null);
1179
1192
  O(() => {
1180
1193
  if (n) {
1181
1194
  const t = n;
1182
1195
  t.from && I(t.from), K(t);
1183
1196
  } else
1184
1197
  I(/* @__PURE__ */ new Date()), K({ from: null, to: null });
1185
- U(null);
1198
+ q(null);
1186
1199
  }, [n]), O(() => {
1187
1200
  a && L(a);
1188
1201
  }, [a]), O(() => {
@@ -1215,19 +1228,19 @@ const _n = xn(
1215
1228
  window.removeEventListener("scroll", j, !0), window.removeEventListener("resize", j);
1216
1229
  }), []);
1217
1230
  const ln = () => $(!0), dn = () => $(!1), nn = () => $((t) => !t), cn = () => {
1218
- x && U(Un(D, a));
1231
+ x && q(qn(D, a));
1219
1232
  }, en = () => {
1220
- if (q === null)
1233
+ if (G === null)
1221
1234
  return;
1222
- const t = q.trim();
1235
+ const t = G.trim();
1223
1236
  if (!t) {
1224
- e(void 0), U(null);
1237
+ e(void 0), q(null);
1225
1238
  return;
1226
1239
  }
1227
- const f = Gn(t, a), P = f && Dn(f.from, d, i) && (!f.to || Dn(f.to, d, i));
1228
- f && P && (e(f), K(f), I(f.from)), U(null);
1240
+ const f = Un(t, a), P = f && Dn(f.from, d, i) && (!f.to || Dn(f.to, d, i));
1241
+ f && P && (e(f), K(f), I(f.from)), q(null);
1229
1242
  }, un = (t) => {
1230
- t.key === "Enter" ? (en(), $(!1)) : t.key === "Escape" && (U(null), $(!1));
1243
+ t.key === "Enter" ? (en(), $(!1)) : t.key === "Escape" && (q(null), $(!1));
1231
1244
  }, pn = {
1232
1245
  isOpen: F,
1233
1246
  open: ln,
@@ -1263,13 +1276,13 @@ const _n = xn(
1263
1276
  })() : o ? /* @__PURE__ */ s(
1264
1277
  Wn,
1265
1278
  {
1266
- value: x && q !== null ? q : X(),
1279
+ value: x && G !== null ? G : X(),
1267
1280
  inputMode: x ? "text" : "none",
1268
1281
  readOnly: !x,
1269
1282
  onClick: () => {
1270
1283
  $(!0);
1271
1284
  },
1272
- onChange: x ? (t) => U(t.target.value) : () => {
1285
+ onChange: x ? (t) => q(t.target.value) : () => {
1273
1286
  },
1274
1287
  onFocus: x ? cn : void 0,
1275
1288
  onBlur: x ? en : void 0,
@@ -1291,7 +1304,7 @@ const _n = xn(
1291
1304
  ref: g,
1292
1305
  children: [
1293
1306
  /* @__PURE__ */ s(
1294
- qn,
1307
+ Gn,
1295
1308
  {
1296
1309
  setViews: L,
1297
1310
  views: Y,
@@ -1711,7 +1724,7 @@ const se = xn(
1711
1724
  helperText: v,
1712
1725
  errorText: N
1713
1726
  }, B) => {
1714
- const H = N ? "error" : c, { ref: V, isComponentVisible: F, setIsComponentVisible: $ } = En(!1), g = _(null), [Y, L] = G("days"), [S, I] = G(/* @__PURE__ */ new Date()), [W, A] = G(/* @__PURE__ */ new Date()), [J, D] = G(null), K = typeof m == "function" || b != null, q = !o && !K, U = !q;
1727
+ const H = N ? "error" : c, { ref: V, isComponentVisible: F, setIsComponentVisible: $ } = En(!1), g = _(null), [Y, L] = U("days"), [S, I] = U(/* @__PURE__ */ new Date()), [W, A] = U(/* @__PURE__ */ new Date()), [J, D] = U(null), K = typeof m == "function" || b != null, G = !o && !K, q = !G;
1715
1728
  O(() => {
1716
1729
  n ? (I(n), A(n)) : (I(/* @__PURE__ */ new Date()), A(/* @__PURE__ */ new Date())), D(null);
1717
1730
  }, [n]), O(() => {
@@ -1719,16 +1732,16 @@ const se = xn(
1719
1732
  }, [a]), O(() => {
1720
1733
  a || L("days");
1721
1734
  }, [F]), O(() => {
1722
- q && $(!0);
1723
- }, [q]);
1735
+ G && $(!0);
1736
+ }, [G]);
1724
1737
  const X = () => n ? a === "days" ? on(S) : a === "months" ? `${Q[S.getMonth()]} ${S.getFullYear()}` : a === "years" ? S.getFullYear() : on(S) : "", j = () => {
1725
- if (g.current && V.current && U) {
1738
+ if (g.current && V.current && q) {
1726
1739
  const t = V.current.getBoundingClientRect(), f = g.current.getBoundingClientRect();
1727
1740
  window.innerWidth < t.left + f.width ? g.current.style.left = `${t.left - f.width + t.width}px` : g.current.style.left = `${t.left}px`, t.top + f.height > window.innerHeight ? g.current.style.top = `${t.y - (t.height + f.height - 28)}px` : g.current.style.top = `${t.y + t.height}px`;
1728
1741
  }
1729
1742
  };
1730
1743
  O(() => {
1731
- g.current && V.current && U && j();
1744
+ g.current && V.current && q && j();
1732
1745
  }, [g, V, F]), O(() => (window.addEventListener("scroll", j, !0), window.addEventListener("resize", j), () => {
1733
1746
  window.removeEventListener("scroll", j, !0), window.removeEventListener("resize", j);
1734
1747
  }), []);
@@ -1760,9 +1773,9 @@ const se = xn(
1760
1773
  "div",
1761
1774
  {
1762
1775
  className: `sa-calendar-wrapper${K ? " sa-calendar-wrapper-custom" : ""}`,
1763
- style: { height: q ? "100%" : "auto" },
1776
+ style: { height: G ? "100%" : "auto" },
1764
1777
  ref: (t) => {
1765
- V.current = U ? t : null, typeof B == "function" ? B(t) : B && (B.current = t);
1778
+ V.current = q ? t : null, typeof B == "function" ? B(t) : B && (B.current = t);
1766
1779
  },
1767
1780
  children: [
1768
1781
  K ? (() => {
@@ -1802,7 +1815,7 @@ const se = xn(
1802
1815
  F ? /* @__PURE__ */ z(
1803
1816
  "div",
1804
1817
  {
1805
- className: `sa-calendar sa-calendar-size-${h || "sm"} ${q ? "sa-calendar-no-input" : ""} ${E ? "" : "sa-calendar-no-padding"}`,
1818
+ className: `sa-calendar sa-calendar-size-${h || "sm"} ${G ? "sa-calendar-no-input" : ""} ${E ? "" : "sa-calendar-no-padding"}`,
1806
1819
  style: r ? { pointerEvents: "none" } : void 0,
1807
1820
  ref: g,
1808
1821
  children: [
@@ -2183,7 +2196,7 @@ const ce = (n) => n === "xs" ? 14 : n === "lg" ? 20 : 16, Bn = ({ s: n }) => /*
2183
2196
  helperText: k,
2184
2197
  errorText: v
2185
2198
  }, N) => {
2186
- const B = v ? "error" : E, { ref: H, isComponentVisible: V, setIsComponentVisible: F } = En(!1), $ = _(null), g = tn(() => Mn(n), [n]), Y = tn(() => Mn(d), [d]), L = tn(() => Mn(i), [i]), [S, I] = G(null);
2199
+ const B = v ? "error" : E, { ref: H, isComponentVisible: V, setIsComponentVisible: F } = En(!1), $ = _(null), g = tn(() => Mn(n), [n]), Y = tn(() => Mn(d), [d]), L = tn(() => Mn(i), [i]), [S, I] = U(null);
2187
2200
  O(() => {
2188
2201
  p || F(!0);
2189
2202
  }, [p]);
@@ -2214,7 +2227,7 @@ const ce = (n) => n === "xs" ? 14 : n === "lg" ? 20 : 16, Bn = ({ s: n }) => /*
2214
2227
  }
2215
2228
  const t = de(S, a, o);
2216
2229
  t && A(t) ? J(t) : I(null);
2217
- }, q = g ? ie(g, a, o) : "", U = S ?? q, X = c && !!g && !l, j = g && g.h >= 12 ? "PM" : "AM", ln = tn(() => a === "12h" ? gn(12).map((t) => {
2230
+ }, G = g ? ie(g, a, o) : "", q = S ?? G, X = c && !!g && !l, j = g && g.h >= 12 ? "PM" : "AM", ln = tn(() => a === "12h" ? gn(12).map((t) => {
2218
2231
  const f = t === 0 ? 12 : t, P = j === "PM" ? f % 12 + 12 : f % 12;
2219
2232
  return {
2220
2233
  value: f,
@@ -2265,7 +2278,7 @@ const ce = (n) => n === "xs" ? 14 : n === "lg" ? 20 : 16, Bn = ({ s: n }) => /*
2265
2278
  "input",
2266
2279
  {
2267
2280
  className: "sa-calendar-input",
2268
- value: U,
2281
+ value: q,
2269
2282
  placeholder: h,
2270
2283
  disabled: l,
2271
2284
  onChange: (t) => I(t.target.value),
package/dist/date.umd.js CHANGED
@@ -1,4 +1,4 @@
1
- (function(G,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],e):(G=typeof globalThis<"u"?globalThis:G||self,e(G.Date={},G.jsxRuntime,G.React))})(this,function(G,e,g){"use strict";const sn=`/* Cascade layer \`starasia.components\` — lihat @starasia/css (urutan: theme, base,
1
+ (function(U,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react"],e):(U=typeof globalThis<"u"?globalThis:U||self,e(U.Date={},U.jsxRuntime,U.React))})(this,function(U,e,g){"use strict";const sn=`/* Cascade layer \`starasia.components\` — lihat @starasia/css (urutan: theme, base,
2
2
  starasia, components, utilities). CSS app/Tailwind utility selalu bisa
3
3
  menimpa aturan di sini. Isi sengaja tidak di-indent (diff minimal). */
4
4
  @layer starasia.components {
@@ -30,6 +30,9 @@
30
30
  --sa-date-border-warning: var(--sa-color-warning-400, #ed9f30);
31
31
  --sa-date-accent-subtle: var(--sa-background-neutral, #f0f1f2);
32
32
  --sa-date-border-subtle: var(--sa-border-subtle, rgba(11, 18, 14, 0.14));
33
+ /* Batas field (outline/flushed) — ≥ 3:1 terhadap kanvas (WCAG 1.4.11).
34
+ --sa-date-border-color (alpha ≈1.3:1) tetap untuk thumb scrollbar Time. */
35
+ --sa-date-border-field: var(--sa-border-input, #8c8f97);
33
36
  }
34
37
  .sa-calendar-wrapper {
35
38
  position: relative;
@@ -363,7 +366,7 @@
363
366
  }
364
367
 
365
368
  .sa-calendar-input-outline {
366
- border-color: var(--sa-date-border-color);
369
+ border-color: var(--sa-date-border-field);
367
370
  background-color: transparent;
368
371
  border-width: var(--sa-border, 1px);
369
372
  border-style: solid;
@@ -413,7 +416,7 @@
413
416
  border-top: none;
414
417
  border-left: none;
415
418
  border-right: none;
416
- border-bottom: 1px solid var(--sa-date-border-color);
419
+ border-bottom: 1px solid var(--sa-date-border-field);
417
420
  border-radius: 0;
418
421
  padding-inline: 0;
419
422
  }
@@ -603,8 +606,18 @@
603
606
  height: 32px;
604
607
  }
605
608
 
609
+ /* Forced colors (Windows High Contrast): fokus field ditandai ganti warna
610
+ border + ring box-shadow — keduanya hilang di mode ini. Ganti outline
611
+ warna sistem. */
612
+ @media (forced-colors: active) {
613
+ .sa-calendar-input-container:has(input:focus) {
614
+ outline: 2px solid Highlight;
615
+ outline-offset: 1px;
616
+ }
617
+ }
618
+
606
619
  } /* @layer starasia.components */
607
- `,$n=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],_=["January","February","March","April","May","June","July","August","September","October","November","December"],Bn=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function vn(n){const[a,r]=g.useState(n),o=g.useRef(null),s=d=>{o.current&&!o.current.contains(d.target)&&r(!1)};return g.useEffect(()=>(document.addEventListener("click",s,!0),()=>{document.removeEventListener("click",s,!0)}),[]),{ref:o,isComponentVisible:a,setIsComponentVisible:r}}const Cn="sa-calendar-input-styles";(n=>{if(!(typeof document>"u")&&!document.getElementById(Cn)){const a=document.createElement("style");a.id=Cn,a.textContent=n,document.head.appendChild(a)}})(sn);const an=n=>{if(n==="xs")return 14;if(n==="sm")return 16;if(n==="md")return 16;if(n==="lg")return 20},Vn=n=>{const{size:a="sm",status:r="default",variant:o="outline",clearable:s,onClear:d,...i}=n,p=g.useRef(null),h=()=>{p.current&&i.onClick&&(p.current.focus(),i.onClick(""))},l=r==="disable"||i.disabled,c=!!i.value,x=s&&c&&!l,$=E=>{E.stopPropagation(),d==null||d()};return e.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${o} sa-calendar-input-container-${r} ${a} `,onClick:h,children:[e.jsx("div",{className:"sa-calendar-input-container-icon-left",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:an(a),height:an(a),viewBox:"0 0 20 20",fill:"none",children:e.jsx("path",{d:"M12.5 2.08301V5.41634M7.50002 2.08301V5.41634M17.0688 9.58301H2.93113M17.0688 9.58301C16.8953 4.82698 15.1284 3.33301 10 3.33301C4.87165 3.33301 3.10469 4.82698 2.93113 9.58301M17.0688 9.58301C17.0786 9.85037 17.0834 10.128 17.0834 10.4163C17.0834 15.833 15.4167 17.4997 10 17.4997C4.58335 17.4997 2.91669 15.833 2.91669 10.4163C2.91669 10.128 2.92138 9.85037 2.93113 9.58301",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),e.jsx("div",{className:"sa-calendar-input-preview-container",children:e.jsx("input",{className:"sa-calendar-input",...i,disabled:l,value:i.value,ref:p})}),x?e.jsx("button",{type:"button","aria-label":"Clear date",className:"sa-calendar-input-clear",onClick:$,children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:an(a),height:an(a),viewBox:"0 0 20 20",fill:"none",children:e.jsx("path",{d:"M5 5L15 15M15 5L5 15",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}):e.jsx("div",{className:"sa-calendar-input-container-icon-right",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:an(a),height:an(a),viewBox:"0 0 20 20",fill:"none",children:e.jsx("path",{d:"M3.33331 7.5L9.99998 14.1667L16.6666 7.5",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]})},Pn=({date:n,setDate:a,dateRange:r,setDateRange:o,onChange:s,minDate:d,maxDate:i,input:p})=>{var T,w,M;const[h,l]=g.useState(null);let c=new Date(n.getFullYear(),n.getMonth(),1),x=c.getDay(),$=[];const E=n.getMonth(),k=new Date().toDateString(),y=!!(r.from&&!r.to),v=y&&h?h:null;for(let m=0;m<42;m++){m===0&&x===0?c.setDate(c.getDate()-7):m===0?c.setDate(c.getDate()+(m-x)):c.setDate(c.getDate()+1);let N={currentMonth:c.getMonth()===E,date:new Date(c),month:c.getMonth(),number:c.getDate(),selected:c.toDateString()===((T=r.from)==null?void 0:T.toDateString())||c.toDateString()===(((w=r.to)==null?void 0:w.toDateString())||((M=r.from)==null?void 0:M.toDateString())),isToday:c.toDateString()===k,year:c.getFullYear(),isDisabled:d&&c<d||i&&c>i};$.push(N)}const u=m=>{a(m)},C=m=>{let N={...r};if(N.from&&N.to)N={from:m,to:null};else if(!N.from)N={from:m,to:null};else{const B=N.from.getTime();m.getTime()>B?N={from:N.from,to:m}:N={from:m,to:N.from}}o(N),s(N)};return e.jsxs("div",{className:"sa-calendar-days-preivew",onMouseLeave:()=>l(null),children:[e.jsx("div",{className:"sa-calendar-days-name-preivew",children:$n.map((m,N)=>e.jsx("p",{children:m},N))}),e.jsx("div",{className:"sa-calendar-days-number-preivew",children:$.map((m,N)=>{const B=r.from&&r.to&&m.date.getTime()>r.from.getTime()&&m.date.getTime()<r.to.getTime(),H=(()=>{if(!v||!r.from)return!1;const S=m.date.getTime(),Y=r.from.getTime(),L=v.getTime();return L>Y?S>Y&&S<L:S<Y&&S>L})(),V=y&&h&&m.date.toDateString()===h.toDateString(),F=m.isDisabled,D=()=>B||H?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",b=()=>F?"var(--sa-color-gray-400, #b7b9be)":B||H?"var(--sa-color-gray-500, #8c8f97)":"";return e.jsx("p",{className:`${m.currentMonth?"sa-calendar-days-current":"sa-calendar-days"} ${m.selected||V?"sa-calendar-days-active":""} ${m.isToday&&!m.selected?"sa-calendar-days-today":""}`,style:{backgroundColor:D(),pointerEvents:F?"none":void 0,cursor:F?"not-allowed":"pointer",color:b(),opacity:V&&!m.selected?.75:1,...p?{}:{width:"100%"}},onClick:()=>{F||(u(m.date),C(m.date))},onMouseEnter:()=>{F||l(m.date)},children:m.number},N)})})]})},jn=({date:n,setDate:a,filter:r,setViews:o,dateRange:s,setDateRange:d,onChange:i,minDate:p,maxDate:h,input:l})=>{var k;const c=(k=s.from)==null?void 0:k.getFullYear(),x=n.getFullYear(),$=y=>{r?(E(y),a(y)):(o("days"),a(y))},E=y=>{let v={...s};if(v.from&&v.to)v={from:y,to:null};else if(!v.from)v={from:y,to:null};else{const u=v.from.getTime();y.getTime()>u?v={from:v.from,to:y}:v={from:y,to:v.from}}d(v),i(v)};return e.jsx("div",{className:"sa-calendar-months-preview",children:_.map((y,v)=>{var T,w,M;const u=s.from!=null&&new Date(x,v).getTime()>s.from.getTime()&&new Date(x,v).getTime()<(((T=s.to)==null?void 0:T.getTime())||s.from.getTime()),C=p&&new Date(x,v)<p||h&&new Date(x,v)>h;return e.jsx("p",{className:c===x&&(v===((w=s.from)==null?void 0:w.getMonth())||v===((M=s.to)==null?void 0:M.getMonth()))?"sa-calendar-months-active":"",style:{backgroundColor:u?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",pointerEvents:C?"none":void 0,cursor:C?"not-allowed":"pointer",color:C?"var(--sa-color-gray-400, #b7b9be)":u?"var(--sa-color-gray-500, #8c8f97)":"",...l?{}:{width:"100%"}},onClick:()=>{C||$(new Date(x,v))},children:y.slice(0,3)},v)})})},bn=n=>{const a=Math.floor(n/10)*10,r=a+10;return{start:a,end:r}},On=({date:n,filter:a,setViews:r,setDate:o,dateRange:s,setDateRange:d,onChange:i,minDate:p,maxDate:h,input:l})=>{var C,T;let c=[];const x=n.getFullYear(),{start:$,end:E}=bn(x),k=(C=s.from)==null?void 0:C.getFullYear(),y=(T=s.to)==null?void 0:T.getFullYear();for(let w=$;w<E;w++){const M=new Date(w,0),m=(!p||M>=p)&&(!h||M<=h),N=k!=null&&w===k||y!=null&&w===y,B=s.from!=null&&s.to!=null&&M>s.from&&M<s.to;c.push({year:w,active:N&&m,highlight:B&&m,disabled:!m})}const v=w=>{a?(u(w),o(w)):(o(w),r("months"))},u=w=>{let M={...s};if(M.from&&M.to)M={from:w,to:null};else if(!M.from)M={from:w,to:null};else{const m=M.from.getTime();w.getTime()>m?M={from:M.from,to:w}:M={from:w,to:M.from}}d(M),i(M)};return e.jsx("div",{className:"sa-calendar-years-preview",children:c.map((w,M)=>e.jsx("p",{className:`${w.active?"sa-calendar-months-active":""} ${w.highlight?"sa-calendar-months-highlight":""} ${w.disabled?"sa-calendar-disabled":""}`,onClick:()=>{w.disabled||v(new Date(w.year,0))},style:{backgroundColor:w.highlight?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",color:w.highlight?"var(--sa-color-gray-500, #8c8f97)":w.active?"":w.disabled?"var(--sa-color-gray-400, #b7b9be)":"",cursor:w.disabled?"not-allowed":"pointer",pointerEvents:w.disbled?"none":"all",...l?{}:{width:"100%"}},children:w.year},M))})},Dn=({...n})=>e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...n,children:e.jsx("path",{d:"M12.5 3.33334L5.83337 10L12.5 16.6667",stroke:"var(--sa-color-brand-700, #031f43)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),zn=({...n})=>e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...n,children:e.jsx("path",{d:"M7.5 16.6667L14.1667 10L7.5 3.33334",stroke:"var(--sa-color-brand-700, #031f43)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),An=({setViews:n,views:a,filter:r,date:o,setDate:s})=>{const d=()=>{r||n(l=>l==="days"?"months":l==="months"?"years":"days")},i=()=>{if(a==="years"){s(l=>new Date(l.getFullYear()+10,0));return}if(a==="months"){s(l=>new Date(l.getFullYear()+1,l.getMonth()));return}s(l=>new Date(l.getFullYear(),l.getMonth()+1))},p=()=>{if(a==="years"){s(l=>new Date(l.getFullYear()-10,0));return}if(a==="months"){s(l=>new Date(l.getFullYear()-1,l.getMonth()));return}s(l=>new Date(l.getMonth()===0?l.getFullYear()-1:l.getFullYear(),l.getMonth()===0?11:l.getMonth()-1))},h=()=>{if(a==="days")return`${_[o.getMonth()]} ${o.getFullYear()}`;if(a==="months")return`${o.getFullYear()}`;if(a==="years")return`${bn(o.getFullYear()).start} ~ ${bn(o.getFullYear()).end}`};return e.jsxs("div",{className:"sa-calendar-header",children:[e.jsx("div",{className:"sa-calendar-header-title",onClick:d,children:h()}),e.jsxs("div",{className:"sa-calendar-header-nav",children:[e.jsx("button",{className:"sa-calendar-nav-btn",onClick:p,children:e.jsx(Dn,{})}),e.jsx("button",{className:"sa-calendar-nav-btn",onClick:i,children:e.jsx(zn,{})})]})]})};function rn(n){const a=new Date(n),r=a.getFullYear(),o=a.getMonth();return`${a.getDate().toString().padStart(2,"0")} ${Bn[o]} ${r}`}const En=(()=>{const n={};return _.forEach((a,r)=>{n[a.toLowerCase()]=r,n[a.slice(0,3).toLowerCase()]=r}),n})(),mn=n=>n<100?2e3+n:n;function yn(n,a){const r=String(n.getDate()).padStart(2,"0"),o=String(n.getMonth()+1).padStart(2,"0"),s=n.getFullYear();return a==="years"?`${s}`:a==="months"?`${o}/${s}`:`${r}/${o}/${s}`}function Hn(n,a){const r=n.from?yn(n.from,a):"",o=n.to?yn(n.to,a):"";return r?o?`${r} ~ ${o}`:r:""}function fn(n,a){const r=n.trim().toLowerCase().split(/[\s/.\-,]+/).filter(Boolean);if(!r.length)return null;let o=null;const s=[];for(const c of r)c in En?o=En[c]:/^\d+$/.test(c)&&s.push(parseInt(c,10));if(a==="years"){const c=s[0];return c==null?null:new Date(mn(c),0,1)}if(a==="months"){const c=o??s[0]-1,x=o!=null?s[0]:s[1];return c==null||isNaN(c)||c<0||c>11||x==null?null:new Date(mn(x),c,1)}let d,i,p;if(o!=null?(d=s[0],p=s[1],i=o):(d=s[0],i=s[1]!=null?s[1]-1:void 0,p=s[2]),d==null||i==null||p==null)return null;const h=mn(p),l=new Date(h,i,d);return l.getFullYear()!==h||l.getMonth()!==i||l.getDate()!==d?null:l}function Wn(n,a){const r=n.indexOf("~");if(r===-1){const d=fn(n,a);return d?{from:d,to:null}:null}const o=fn(n.slice(0,r),a);if(!o)return null;const s=fn(n.slice(r+1),a);return{from:o,to:s??null}}function wn(n,a,r){const o=d=>new Date(d.getFullYear(),d.getMonth(),d.getDate()).getTime(),s=o(n);return!(a&&s<o(a)||r&&s>o(r))}const xn=({label:n,labelPosition:a="outside-top",required:r,optional:o,description:s,helperText:d,errorText:i,fullWidth:p,size:h="sm",children:l})=>{const c=["sa-date-field",`sa-date-field-size-${h}`,p?"sa-date-field-fullwidth":""].filter(Boolean).join(" "),x=n?e.jsxs("div",{className:"sa-date-field-label-row",children:[e.jsx("span",{className:"sa-date-field-label-text",children:n}),o&&e.jsx("span",{className:"sa-date-field-optional-badge",children:"Optional"}),r&&e.jsx("span",{className:"sa-date-field-required",children:"*"})]}):null,$=e.jsxs(e.Fragment,{children:[d&&!i&&e.jsx("p",{className:"sa-date-field-helper",children:d}),i&&e.jsx("p",{className:"sa-date-field-error-msg",children:i})]});return n?a==="outside-left"?e.jsxs("div",{className:`${c} sa-date-field-left`,children:[e.jsxs("div",{className:"sa-date-field-left-label",children:[x,s&&e.jsx("p",{className:"sa-date-field-helper-top",children:s})]}),e.jsxs("div",{className:"sa-date-field-input-wrap",children:[l,$]})]}):e.jsxs("div",{className:c,children:[x,s&&e.jsx("p",{className:"sa-date-field-helper-top",children:s}),l,$]}):e.jsxs("div",{className:c,children:[s&&e.jsx("p",{className:"sa-date-field-helper-top",children:s}),l,$]})},Sn="sa-calendar-styles";(n=>{if(!(typeof document>"u")&&!document.getElementById(Sn)){const a=document.createElement("style");a.id=Sn,a.textContent=n,document.head.appendChild(a)}})(sn);const Jn=g.forwardRef(({value:n,onChange:a,filter:r,input:o=!0,disabled:s,minDate:d,maxDate:i,placeholder:p,size:h="sm",variant:l,status:c,clearable:x,fullWidth:$=!0,withPadding:E=!0,editable:k=!1,trigger:y,renderTrigger:v,label:u,labelPosition:C,required:T,optional:w,description:M,helperText:m,errorText:N},B)=>{const H=N?"error":c,{ref:V,isComponentVisible:F,setIsComponentVisible:D}=vn(!1),b=g.useRef(null),[S,Y]=g.useState("days"),[L,I]=g.useState(new Date),W=typeof v=="function"||y!=null,O=!o&&!W,J=!O,[z,q]=g.useState({from:(n==null?void 0:n.from)??null,to:(n==null?void 0:n.to)??null}),[K,U]=g.useState(null);g.useEffect(()=>{if(n){const t=n;t.from&&I(t.from),q(t)}else I(new Date),q({from:null,to:null});U(null)},[n]),g.useEffect(()=>{r&&Y(r)},[r]),g.useEffect(()=>{r||Y("days")},[F]),g.useEffect(()=>{O&&D(!0)},[O]);const Q=()=>{var t,f;if(!n)return"";if(r){if(S==="days")return`${rn(z.from)} ~ ${rn(z.to||z.from)||"-"}`;if(S==="months")return`${_[z.from.getMonth()]} ~ ${z.to?_[z.to.getMonth()]:"-"}`;if(S==="years")return`${(t=z.from)==null?void 0:t.getFullYear()} ~ ${((f=z.to)==null?void 0:f.getFullYear())||"-"}`}else return`${rn(z.from)} ~ ${rn(z.to||z.from)||"-"}`},j=()=>{if(b.current&&V.current&&J){const t=V.current.getBoundingClientRect(),f=b.current.getBoundingClientRect();window.innerWidth<t.left+f.width?b.current.style.left=`${t.left-f.width+t.width}px`:b.current.style.left=`${t.left}px`,t.top+f.height>window.innerHeight?b.current.style.top=`${t.y-(t.height+f.height-28)}px`:b.current.style.top=`${t.y+t.height}px`}};g.useEffect(()=>{b.current&&V.current&&J&&j()},[b,V,F]),g.useEffect(()=>(window.addEventListener("scroll",j,!0),window.addEventListener("resize",j),()=>{window.removeEventListener("scroll",j,!0),window.removeEventListener("resize",j)}),[]);const on=()=>D(!0),ln=()=>D(!1),X=()=>D(t=>!t),dn=()=>{k&&U(Hn(z,r))},R=()=>{if(K===null)return;const t=K.trim();if(!t){a(void 0),U(null);return}const f=Wn(t,r),P=f&&wn(f.from,d,i)&&(!f.to||wn(f.to,d,i));f&&P&&(a(f),q(f),I(f.from)),U(null)},cn=t=>{t.key==="Enter"?(R(),D(!1)):t.key==="Escape"&&(U(null),D(!1))},un={isOpen:F,open:on,close:ln,toggle:X,value:n,formattedValue:String(Q()??""),clear:()=>a(void 0),disabled:s,placeholder:p},nn=()=>{if(typeof v=="function")return v(un);if(g.isValidElement(y)){const t=y;return g.cloneElement(t,{onClick:f=>{var P,en;(en=(P=t.props)==null?void 0:P.onClick)==null||en.call(P,f),s||X()}})}return y},pn=e.jsxs("div",{className:`sa-calendar-wrapper${W?" sa-calendar-wrapper-custom":""}`,style:{height:O?"100%":"auto"},ref:t=>{V.current=J?t:null,typeof B=="function"?B(t):B&&(B.current=t)},children:[W?nn():o?e.jsx(Vn,{value:k&&K!==null?K:Q(),inputMode:k?"text":"none",readOnly:!k,onClick:()=>{D(!0)},onChange:k?t=>U(t.target.value):()=>{},onFocus:k?dn:void 0,onBlur:k?R:void 0,onKeyDown:k?cn:void 0,disabled:s,placeholder:p,size:h,variant:l,status:H,clearable:x,onClear:()=>a(void 0)}):null,F?e.jsxs("div",{className:`sa-calendar sa-calendar-size-${h||"sm"} ${O?"sa-calendar-no-input":""} ${E?"":"sa-calendar-no-padding"}`,style:s?{pointerEvents:"none"}:void 0,ref:b,children:[e.jsx(An,{setViews:Y,views:S,filter:r,date:L,setDate:I}),e.jsx("div",{className:"sa-calendar-body",children:S==="days"?e.jsx(Pn,{date:L,setDate:I,setIsComponentVisible:D,dateRange:z,setDateRange:q,input:o,onChange:a,minDate:d,maxDate:i}):S==="months"?e.jsx(jn,{date:L,setDate:I,filter:r,setViews:Y,dateRange:z,setDateRange:q,setIsComponentVisible:D,input:o,onChange:a,minDate:d,maxDate:i}):e.jsx(On,{date:L,setDate:I,filter:r,setViews:Y,dateRange:z,setDateRange:q,setIsComponentVisible:D,input:o,onChange:a,minDate:d,maxDate:i})})]}):null]});return e.jsx(xn,{label:u,labelPosition:C,required:T,optional:w,description:M,helperText:m,errorText:N,fullWidth:$,size:h,children:pn})}),Yn="sa-calendar-input-styles";(n=>{if(!(typeof document>"u")&&!document.getElementById(Yn)){const a=document.createElement("style");a.id=Yn,a.textContent=n,document.head.appendChild(a)}})(sn);const tn=n=>{if(n==="xs")return 14;if(n==="sm")return 16;if(n==="md")return 16;if(n==="lg")return 20},qn=n=>{const{size:a="sm",status:r="default",variant:o="outline",clearable:s,onClear:d,...i}=n,p=g.useRef(null),h=()=>{p.current&&i.onClick&&(p.current.focus(),i.onClick(""))},l=r==="disable"||i.disabled,c=!!i.value,x=s&&c&&!l,$=E=>{E.stopPropagation(),d==null||d()};return e.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${o} sa-calendar-input-container-${r} ${a} `,onClick:h,children:[e.jsx("div",{className:"sa-calendar-input-container-icon-left",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:tn(a),height:tn(a),viewBox:"0 0 20 20",fill:"none",children:e.jsx("path",{d:"M12.5 2.08301V5.41634M7.50002 2.08301V5.41634M17.0688 9.58301H2.93113M17.0688 9.58301C16.8953 4.82698 15.1284 3.33301 10 3.33301C4.87165 3.33301 3.10469 4.82698 2.93113 9.58301M17.0688 9.58301C17.0786 9.85037 17.0834 10.128 17.0834 10.4163C17.0834 15.833 15.4167 17.4997 10 17.4997C4.58335 17.4997 2.91669 15.833 2.91669 10.4163C2.91669 10.128 2.92138 9.85037 2.93113 9.58301",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),e.jsx("div",{className:"sa-calendar-input-preview-container",children:e.jsx("input",{className:"sa-calendar-input",...i,disabled:l,value:i.value,ref:p})}),x?e.jsx("button",{type:"button","aria-label":"Clear date",className:"sa-calendar-input-clear",onClick:$,children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:tn(a),height:tn(a),viewBox:"0 0 20 20",fill:"none",children:e.jsx("path",{d:"M5 5L15 15M15 5L5 15",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}):e.jsx("div",{className:"sa-calendar-input-container-icon-right",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:tn(a),height:tn(a),viewBox:"0 0 20 20",fill:"none",children:e.jsx("path",{d:"M3.33331 7.5L9.99998 14.1667L16.6666 7.5",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]})},Kn=({date:n,setDate:a,previewDate:r,setPreviewDate:o,setIsComponentVisible:s,minDate:d,maxDate:i,input:p,onChange:h,hasValue:l})=>{let c=new Date(r.getFullYear(),r.getMonth(),1),x=c.getDay(),$=[];const E=n.toDateString(),k=new Date().toDateString(),y=r.getMonth();for(let u=0;u<42;u++){u===0&&x===0?c.setDate(c.getDate()-7):u===0?c.setDate(c.getDate()+(u-x)):c.setDate(c.getDate()+1);let C={currentMonth:c.getMonth()===y,date:new Date(c),month:c.getMonth(),number:c.getDate(),selected:l&&c.toDateString()===E,isToday:c.toDateString()===k,year:c.getFullYear(),isDisabled:d&&c<d||i&&c>i};$.push(C)}const v=u=>{(!d||u>=d)&&(!i||u<=i)&&(a(u),h(u),o(u),p&&s(!1))};return e.jsxs("div",{className:"sa-calendar-days-preivew",children:[e.jsx("div",{className:"sa-calendar-days-name-preivew",children:$n.map((u,C)=>e.jsx("p",{children:u},C))}),e.jsx("div",{className:"sa-calendar-days-number-preivew",children:$.map((u,C)=>{const T=u.isDisabled;return e.jsx("p",{className:`${u.currentMonth?"sa-calendar-days-current":"sa-calendar-days"} ${u.selected?"sa-calendar-days-active":""} ${u.isToday&&!u.selected?"sa-calendar-days-today":""}`,style:{color:T?"var(--sa-text-disable, #181a198f)":void 0,pointerEvents:T?"none":void 0,cursor:T?"not-allowed":"pointer",...p?{}:{width:"100%"}},onClick:()=>{T||v(u.date)},children:u.number},C)})})]})},Un=({date:n,setDate:a,filter:r,setViews:o,onChange:s,previewDate:d,setPreviewDate:i,minDate:p,maxDate:h,input:l,hasValue:c})=>{const x=n.getMonth(),$=n.getFullYear(),E=d.getFullYear(),k=y=>{(!p||y>=p)&&(!h||y<=h)&&(r?(s(y),a(y),i(y)):(o("days"),i(y)))};return e.jsx("div",{className:"sa-calendar-months-preview",children:_.map((y,v)=>{const u=p&&new Date(E,v,1)<p||h&&new Date(E,v+1,0)>h;return e.jsx("p",{className:c&&v===x&&E===$?"sa-calendar-months-active":"",style:{color:u?"var(--sa-text-disable, #181a198f)":void 0,pointerEvents:u?"none":void 0,cursor:u?"not-allowed":"pointer",...l?{}:{width:"100%"}},onClick:()=>{u||k(new Date(E,v))},children:y.slice(0,3)},v)})})},kn=n=>{const a=Math.floor(n/10)*10,r=a+10;return{start:a,end:r}},Gn=({date:n,filter:a,setViews:r,setDate:o,onChange:s,previewDate:d,setPreviewDate:i,minDate:p,maxDate:h,input:l,hasValue:c})=>{let x=[];const $=d.getFullYear(),{start:E,end:k}=kn($),y=n.getFullYear();for(let u=E;u<k;u++){let C=p&&new Date(u,0,1)<p||h&&new Date(u,11,31)>h;x.push({year:u,active:!!c&&u===y,isDisabled:C})}const v=u=>{(!p||u>=p)&&(!h||u<=h)&&(a?(s(u),o(u),i(u)):(r("months"),i(u)))};return e.jsx("div",{className:"sa-calendar-years-preview",children:x.map((u,C)=>e.jsx("p",{className:u.active?"sa-calendar-months-active":"",style:{color:u.isDisabled?"var(--sa-text-disable, #181a198f)":void 0,pointerEvents:u.isDisabled?"none":void 0,cursor:u.isDisabled?"not-allowed":"pointer",...l?{}:{width:"100%"}},onClick:()=>{u.isDisabled||v(new Date(u.year,0))},children:u.year},C))})},Zn=({setViews:n,views:a,filter:r,previewDate:o,setPreviewDate:s})=>{const d=()=>{r||n(l=>l==="days"?"months":l==="months"?"years":"days")},i=()=>{if(a==="years"){s(l=>new Date(l.getFullYear()+10,0));return}if(a==="months"){s(l=>new Date(l.getFullYear()+1,l.getMonth()));return}s(l=>new Date(l.getFullYear(),l.getMonth()+1))},p=()=>{if(a==="years"){s(l=>new Date(l.getFullYear()-10,0));return}if(a==="months"){s(l=>new Date(l.getFullYear()-1,l.getMonth()));return}s(l=>new Date(l.getMonth()===0?l.getFullYear()-1:l.getFullYear(),l.getMonth()===0?11:l.getMonth()-1))},h=()=>{if(a==="days")return`${_[o.getMonth()]} ${o.getFullYear()}`;if(a==="months")return`${o.getFullYear()}`;if(a==="years")return`${kn(o.getFullYear()).start} ~ ${kn(o.getFullYear()).end}`};return e.jsxs("div",{className:"sa-calendar-header",children:[e.jsx("div",{className:"sa-calendar-header-title",onClick:d,children:h()}),e.jsxs("div",{className:"sa-calendar-header-nav",children:[e.jsx("button",{className:"sa-calendar-nav-btn",onClick:p,children:e.jsx(Dn,{})}),e.jsx("button",{className:"sa-calendar-nav-btn",onClick:i,children:e.jsx(zn,{})})]})]})},Fn="sa-calendar-styles";(n=>{if(!(typeof document>"u")&&!document.getElementById(Fn)){const a=document.createElement("style");a.id=Fn,a.textContent=n,document.head.appendChild(a)}})(sn);const _n=g.forwardRef(({value:n,onChange:a,filter:r,input:o=!0,disabled:s,minDate:d,maxDate:i,placeholder:p,size:h="sm",variant:l,status:c,clearable:x,fullWidth:$=!0,withPadding:E=!0,editable:k=!1,trigger:y,renderTrigger:v,label:u,labelPosition:C,required:T,optional:w,description:M,helperText:m,errorText:N},B)=>{const H=N?"error":c,{ref:V,isComponentVisible:F,setIsComponentVisible:D}=vn(!1),b=g.useRef(null),[S,Y]=g.useState("days"),[L,I]=g.useState(new Date),[W,O]=g.useState(new Date),[J,z]=g.useState(null),q=typeof v=="function"||y!=null,K=!o&&!q,U=!K;g.useEffect(()=>{n?(I(n),O(n)):(I(new Date),O(new Date)),z(null)},[n]),g.useEffect(()=>{r&&Y(r)},[r]),g.useEffect(()=>{r||Y("days")},[F]),g.useEffect(()=>{K&&D(!0)},[K]);const Q=()=>n?r==="days"?rn(L):r==="months"?`${_[L.getMonth()]} ${L.getFullYear()}`:r==="years"?L.getFullYear():rn(L):"",j=()=>{if(b.current&&V.current&&U){const t=V.current.getBoundingClientRect(),f=b.current.getBoundingClientRect();window.innerWidth<t.left+f.width?b.current.style.left=`${t.left-f.width+t.width}px`:b.current.style.left=`${t.left}px`,t.top+f.height>window.innerHeight?b.current.style.top=`${t.y-(t.height+f.height-28)}px`:b.current.style.top=`${t.y+t.height}px`}};g.useEffect(()=>{b.current&&V.current&&U&&j()},[b,V,F]),g.useEffect(()=>(window.addEventListener("scroll",j,!0),window.addEventListener("resize",j),()=>{window.removeEventListener("scroll",j,!0),window.removeEventListener("resize",j)}),[]);const on=()=>D(!0),ln=()=>D(!1),X=()=>D(t=>!t),dn=()=>{k&&z(n?yn(n,r):"")},R=()=>{if(J===null)return;const t=J.trim();if(!t){a(void 0),z(null);return}const f=fn(t,r);f&&wn(f,d,i)&&(a(f),I(f),O(f)),z(null)},cn=t=>{t.key==="Enter"?(R(),D(!1)):t.key==="Escape"&&(z(null),D(!1))},un={isOpen:F,open:on,close:ln,toggle:X,value:n,formattedValue:String(Q()??""),clear:()=>a(void 0),disabled:s,placeholder:p},nn=()=>{if(typeof v=="function")return v(un);if(g.isValidElement(y)){const t=y;return g.cloneElement(t,{onClick:f=>{var P,en;(en=(P=t.props)==null?void 0:P.onClick)==null||en.call(P,f),s||X()}})}return y},pn=e.jsxs("div",{className:`sa-calendar-wrapper${q?" sa-calendar-wrapper-custom":""}`,style:{height:K?"100%":"auto"},ref:t=>{V.current=U?t:null,typeof B=="function"?B(t):B&&(B.current=t)},children:[q?nn():o?e.jsx(qn,{value:k&&J!==null?J:Q(),onClick:()=>D(!0),onChange:k?t=>z(t.target.value):()=>{},onFocus:k?dn:void 0,onBlur:k?R:void 0,onKeyDown:k?cn:void 0,placeholder:p,disabled:s,size:h,variant:l,status:H,inputMode:k?"text":"none",readOnly:!k,clearable:x,onClear:()=>a(void 0)}):null,F?e.jsxs("div",{className:`sa-calendar sa-calendar-size-${h||"sm"} ${K?"sa-calendar-no-input":""} ${E?"":"sa-calendar-no-padding"}`,style:s?{pointerEvents:"none"}:void 0,ref:b,children:[e.jsx(Zn,{setViews:Y,views:S,filter:r,previewDate:W,setPreviewDate:O,isComponentVisible:F}),e.jsx("div",{className:"sa-calendar-body",children:S==="days"?e.jsx(Kn,{date:L,setDate:I,previewDate:W,setPreviewDate:O,setIsComponentVisible:D,input:o,minDate:d,maxDate:i,onChange:a,hasValue:n!=null}):S==="months"?e.jsx(Un,{date:L,setDate:I,previewDate:W,setPreviewDate:O,filter:r,setViews:Y,onChange:a,minDate:d,maxDate:i,input:o,hasValue:n!=null}):e.jsx(Gn,{date:L,setDate:I,previewDate:W,setPreviewDate:O,filter:r,setViews:Y,onChange:a,minDate:d,maxDate:i,input:o,hasValue:n!=null})})]}):null]});return e.jsx(xn,{label:u,labelPosition:C,required:T,optional:w,description:M,helperText:m,errorText:N,fullWidth:$,size:h,children:pn})}),Qn=g.forwardRef(({value:n,onChange:a,filter:r,input:o=!0,rangedDate:s,disabled:d,minDate:i,maxDate:p,placeholder:h,size:l,variant:c,status:x,clearable:$,fullWidth:E,withPadding:k,editable:y,trigger:v,renderTrigger:u,label:C,labelPosition:T,required:w,optional:M,description:m,helperText:N,errorText:B},H)=>{const V={onChange:a,value:n,input:o,filter:r,disabled:d,minDate:i,maxDate:p,placeholder:h,size:l,variant:c,status:x,clearable:$,fullWidth:E,withPadding:k,editable:y,trigger:v,renderTrigger:u,label:C,labelPosition:T,required:w,optional:M,description:m,helperText:N,errorText:B};return e.jsx(e.Fragment,{children:s?e.jsx(Jn,{...V,ref:H}):e.jsx(_n,{...V,ref:H})})}),Xn=`/* Cascade layer \`starasia.components\` — lihat @starasia/css (urutan: theme, base,
620
+ `,Cn=["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],_=["January","February","March","April","May","June","July","August","September","October","November","December"],Bn=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function vn(n){const[a,r]=g.useState(n),o=g.useRef(null),s=d=>{o.current&&!o.current.contains(d.target)&&r(!1)};return g.useEffect(()=>(document.addEventListener("click",s,!0),()=>{document.removeEventListener("click",s,!0)}),[]),{ref:o,isComponentVisible:a,setIsComponentVisible:r}}const $n="sa-calendar-input-styles";(n=>{if(!(typeof document>"u")&&!document.getElementById($n)){const a=document.createElement("style");a.id=$n,a.textContent=n,document.head.appendChild(a)}})(sn);const an=n=>{if(n==="xs")return 14;if(n==="sm")return 16;if(n==="md")return 16;if(n==="lg")return 20},Vn=n=>{const{size:a="sm",status:r="default",variant:o="outline",clearable:s,onClear:d,...i}=n,p=g.useRef(null),h=()=>{p.current&&i.onClick&&(p.current.focus(),i.onClick(""))},l=r==="disable"||i.disabled,c=!!i.value,x=s&&c&&!l,C=E=>{E.stopPropagation(),d==null||d()};return e.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${o} sa-calendar-input-container-${r} ${a} `,onClick:h,children:[e.jsx("div",{className:"sa-calendar-input-container-icon-left",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:an(a),height:an(a),viewBox:"0 0 20 20",fill:"none",children:e.jsx("path",{d:"M12.5 2.08301V5.41634M7.50002 2.08301V5.41634M17.0688 9.58301H2.93113M17.0688 9.58301C16.8953 4.82698 15.1284 3.33301 10 3.33301C4.87165 3.33301 3.10469 4.82698 2.93113 9.58301M17.0688 9.58301C17.0786 9.85037 17.0834 10.128 17.0834 10.4163C17.0834 15.833 15.4167 17.4997 10 17.4997C4.58335 17.4997 2.91669 15.833 2.91669 10.4163C2.91669 10.128 2.92138 9.85037 2.93113 9.58301",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),e.jsx("div",{className:"sa-calendar-input-preview-container",children:e.jsx("input",{className:"sa-calendar-input",...i,disabled:l,value:i.value,ref:p})}),x?e.jsx("button",{type:"button","aria-label":"Clear date",className:"sa-calendar-input-clear",onClick:C,children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:an(a),height:an(a),viewBox:"0 0 20 20",fill:"none",children:e.jsx("path",{d:"M5 5L15 15M15 5L5 15",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}):e.jsx("div",{className:"sa-calendar-input-container-icon-right",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:an(a),height:an(a),viewBox:"0 0 20 20",fill:"none",children:e.jsx("path",{d:"M3.33331 7.5L9.99998 14.1667L16.6666 7.5",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]})},Pn=({date:n,setDate:a,dateRange:r,setDateRange:o,onChange:s,minDate:d,maxDate:i,input:p})=>{var T,w,M;const[h,l]=g.useState(null);let c=new Date(n.getFullYear(),n.getMonth(),1),x=c.getDay(),C=[];const E=n.getMonth(),k=new Date().toDateString(),y=!!(r.from&&!r.to),v=y&&h?h:null;for(let m=0;m<42;m++){m===0&&x===0?c.setDate(c.getDate()-7):m===0?c.setDate(c.getDate()+(m-x)):c.setDate(c.getDate()+1);let N={currentMonth:c.getMonth()===E,date:new Date(c),month:c.getMonth(),number:c.getDate(),selected:c.toDateString()===((T=r.from)==null?void 0:T.toDateString())||c.toDateString()===(((w=r.to)==null?void 0:w.toDateString())||((M=r.from)==null?void 0:M.toDateString())),isToday:c.toDateString()===k,year:c.getFullYear(),isDisabled:d&&c<d||i&&c>i};C.push(N)}const u=m=>{a(m)},$=m=>{let N={...r};if(N.from&&N.to)N={from:m,to:null};else if(!N.from)N={from:m,to:null};else{const B=N.from.getTime();m.getTime()>B?N={from:N.from,to:m}:N={from:m,to:N.from}}o(N),s(N)};return e.jsxs("div",{className:"sa-calendar-days-preivew",onMouseLeave:()=>l(null),children:[e.jsx("div",{className:"sa-calendar-days-name-preivew",children:Cn.map((m,N)=>e.jsx("p",{children:m},N))}),e.jsx("div",{className:"sa-calendar-days-number-preivew",children:C.map((m,N)=>{const B=r.from&&r.to&&m.date.getTime()>r.from.getTime()&&m.date.getTime()<r.to.getTime(),H=(()=>{if(!v||!r.from)return!1;const S=m.date.getTime(),F=r.from.getTime(),L=v.getTime();return L>F?S>F&&S<L:S<F&&S>L})(),V=y&&h&&m.date.toDateString()===h.toDateString(),Y=m.isDisabled,D=()=>B||H?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",b=()=>Y?"var(--sa-color-gray-400, #b7b9be)":B||H?"var(--sa-color-gray-500, #8c8f97)":"";return e.jsx("p",{className:`${m.currentMonth?"sa-calendar-days-current":"sa-calendar-days"} ${m.selected||V?"sa-calendar-days-active":""} ${m.isToday&&!m.selected?"sa-calendar-days-today":""}`,style:{backgroundColor:D(),pointerEvents:Y?"none":void 0,cursor:Y?"not-allowed":"pointer",color:b(),opacity:V&&!m.selected?.75:1,...p?{}:{width:"100%"}},onClick:()=>{Y||(u(m.date),$(m.date))},onMouseEnter:()=>{Y||l(m.date)},children:m.number},N)})})]})},jn=({date:n,setDate:a,filter:r,setViews:o,dateRange:s,setDateRange:d,onChange:i,minDate:p,maxDate:h,input:l})=>{var k;const c=(k=s.from)==null?void 0:k.getFullYear(),x=n.getFullYear(),C=y=>{r?(E(y),a(y)):(o("days"),a(y))},E=y=>{let v={...s};if(v.from&&v.to)v={from:y,to:null};else if(!v.from)v={from:y,to:null};else{const u=v.from.getTime();y.getTime()>u?v={from:v.from,to:y}:v={from:y,to:v.from}}d(v),i(v)};return e.jsx("div",{className:"sa-calendar-months-preview",children:_.map((y,v)=>{var T,w,M;const u=s.from!=null&&new Date(x,v).getTime()>s.from.getTime()&&new Date(x,v).getTime()<(((T=s.to)==null?void 0:T.getTime())||s.from.getTime()),$=p&&new Date(x,v)<p||h&&new Date(x,v)>h;return e.jsx("p",{className:c===x&&(v===((w=s.from)==null?void 0:w.getMonth())||v===((M=s.to)==null?void 0:M.getMonth()))?"sa-calendar-months-active":"",style:{backgroundColor:u?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",pointerEvents:$?"none":void 0,cursor:$?"not-allowed":"pointer",color:$?"var(--sa-color-gray-400, #b7b9be)":u?"var(--sa-color-gray-500, #8c8f97)":"",...l?{}:{width:"100%"}},onClick:()=>{$||C(new Date(x,v))},children:y.slice(0,3)},v)})})},bn=n=>{const a=Math.floor(n/10)*10,r=a+10;return{start:a,end:r}},On=({date:n,filter:a,setViews:r,setDate:o,dateRange:s,setDateRange:d,onChange:i,minDate:p,maxDate:h,input:l})=>{var $,T;let c=[];const x=n.getFullYear(),{start:C,end:E}=bn(x),k=($=s.from)==null?void 0:$.getFullYear(),y=(T=s.to)==null?void 0:T.getFullYear();for(let w=C;w<E;w++){const M=new Date(w,0),m=(!p||M>=p)&&(!h||M<=h),N=k!=null&&w===k||y!=null&&w===y,B=s.from!=null&&s.to!=null&&M>s.from&&M<s.to;c.push({year:w,active:N&&m,highlight:B&&m,disabled:!m})}const v=w=>{a?(u(w),o(w)):(o(w),r("months"))},u=w=>{let M={...s};if(M.from&&M.to)M={from:w,to:null};else if(!M.from)M={from:w,to:null};else{const m=M.from.getTime();w.getTime()>m?M={from:M.from,to:w}:M={from:w,to:M.from}}d(M),i(M)};return e.jsx("div",{className:"sa-calendar-years-preview",children:c.map((w,M)=>e.jsx("p",{className:`${w.active?"sa-calendar-months-active":""} ${w.highlight?"sa-calendar-months-highlight":""} ${w.disabled?"sa-calendar-disabled":""}`,onClick:()=>{w.disabled||v(new Date(w.year,0))},style:{backgroundColor:w.highlight?"var(--sa-color-info-alpha-a10, #64b5f61a)":"",color:w.highlight?"var(--sa-color-gray-500, #8c8f97)":w.active?"":w.disabled?"var(--sa-color-gray-400, #b7b9be)":"",cursor:w.disabled?"not-allowed":"pointer",pointerEvents:w.disbled?"none":"all",...l?{}:{width:"100%"}},children:w.year},M))})},Dn=({...n})=>e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...n,children:e.jsx("path",{d:"M12.5 3.33334L5.83337 10L12.5 16.6667",stroke:"var(--sa-color-brand-700, #031f43)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),zn=({...n})=>e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",...n,children:e.jsx("path",{d:"M7.5 16.6667L14.1667 10L7.5 3.33334",stroke:"var(--sa-color-brand-700, #031f43)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),An=({setViews:n,views:a,filter:r,date:o,setDate:s})=>{const d=()=>{r||n(l=>l==="days"?"months":l==="months"?"years":"days")},i=()=>{if(a==="years"){s(l=>new Date(l.getFullYear()+10,0));return}if(a==="months"){s(l=>new Date(l.getFullYear()+1,l.getMonth()));return}s(l=>new Date(l.getFullYear(),l.getMonth()+1))},p=()=>{if(a==="years"){s(l=>new Date(l.getFullYear()-10,0));return}if(a==="months"){s(l=>new Date(l.getFullYear()-1,l.getMonth()));return}s(l=>new Date(l.getMonth()===0?l.getFullYear()-1:l.getFullYear(),l.getMonth()===0?11:l.getMonth()-1))},h=()=>{if(a==="days")return`${_[o.getMonth()]} ${o.getFullYear()}`;if(a==="months")return`${o.getFullYear()}`;if(a==="years")return`${bn(o.getFullYear()).start} ~ ${bn(o.getFullYear()).end}`};return e.jsxs("div",{className:"sa-calendar-header",children:[e.jsx("div",{className:"sa-calendar-header-title",onClick:d,children:h()}),e.jsxs("div",{className:"sa-calendar-header-nav",children:[e.jsx("button",{className:"sa-calendar-nav-btn",onClick:p,children:e.jsx(Dn,{})}),e.jsx("button",{className:"sa-calendar-nav-btn",onClick:i,children:e.jsx(zn,{})})]})]})};function rn(n){const a=new Date(n),r=a.getFullYear(),o=a.getMonth();return`${a.getDate().toString().padStart(2,"0")} ${Bn[o]} ${r}`}const En=(()=>{const n={};return _.forEach((a,r)=>{n[a.toLowerCase()]=r,n[a.slice(0,3).toLowerCase()]=r}),n})(),mn=n=>n<100?2e3+n:n;function yn(n,a){const r=String(n.getDate()).padStart(2,"0"),o=String(n.getMonth()+1).padStart(2,"0"),s=n.getFullYear();return a==="years"?`${s}`:a==="months"?`${o}/${s}`:`${r}/${o}/${s}`}function Hn(n,a){const r=n.from?yn(n.from,a):"",o=n.to?yn(n.to,a):"";return r?o?`${r} ~ ${o}`:r:""}function fn(n,a){const r=n.trim().toLowerCase().split(/[\s/.\-,]+/).filter(Boolean);if(!r.length)return null;let o=null;const s=[];for(const c of r)c in En?o=En[c]:/^\d+$/.test(c)&&s.push(parseInt(c,10));if(a==="years"){const c=s[0];return c==null?null:new Date(mn(c),0,1)}if(a==="months"){const c=o??s[0]-1,x=o!=null?s[0]:s[1];return c==null||isNaN(c)||c<0||c>11||x==null?null:new Date(mn(x),c,1)}let d,i,p;if(o!=null?(d=s[0],p=s[1],i=o):(d=s[0],i=s[1]!=null?s[1]-1:void 0,p=s[2]),d==null||i==null||p==null)return null;const h=mn(p),l=new Date(h,i,d);return l.getFullYear()!==h||l.getMonth()!==i||l.getDate()!==d?null:l}function Wn(n,a){const r=n.indexOf("~");if(r===-1){const d=fn(n,a);return d?{from:d,to:null}:null}const o=fn(n.slice(0,r),a);if(!o)return null;const s=fn(n.slice(r+1),a);return{from:o,to:s??null}}function wn(n,a,r){const o=d=>new Date(d.getFullYear(),d.getMonth(),d.getDate()).getTime(),s=o(n);return!(a&&s<o(a)||r&&s>o(r))}const xn=({label:n,labelPosition:a="outside-top",required:r,optional:o,description:s,helperText:d,errorText:i,fullWidth:p,size:h="sm",children:l})=>{const c=["sa-date-field",`sa-date-field-size-${h}`,p?"sa-date-field-fullwidth":""].filter(Boolean).join(" "),x=n?e.jsxs("div",{className:"sa-date-field-label-row",children:[e.jsx("span",{className:"sa-date-field-label-text",children:n}),o&&e.jsx("span",{className:"sa-date-field-optional-badge",children:"Optional"}),r&&e.jsx("span",{className:"sa-date-field-required",children:"*"})]}):null,C=e.jsxs(e.Fragment,{children:[d&&!i&&e.jsx("p",{className:"sa-date-field-helper",children:d}),i&&e.jsx("p",{className:"sa-date-field-error-msg",children:i})]});return n?a==="outside-left"?e.jsxs("div",{className:`${c} sa-date-field-left`,children:[e.jsxs("div",{className:"sa-date-field-left-label",children:[x,s&&e.jsx("p",{className:"sa-date-field-helper-top",children:s})]}),e.jsxs("div",{className:"sa-date-field-input-wrap",children:[l,C]})]}):e.jsxs("div",{className:c,children:[x,s&&e.jsx("p",{className:"sa-date-field-helper-top",children:s}),l,C]}):e.jsxs("div",{className:c,children:[s&&e.jsx("p",{className:"sa-date-field-helper-top",children:s}),l,C]})},Sn="sa-calendar-styles";(n=>{if(!(typeof document>"u")&&!document.getElementById(Sn)){const a=document.createElement("style");a.id=Sn,a.textContent=n,document.head.appendChild(a)}})(sn);const Jn=g.forwardRef(({value:n,onChange:a,filter:r,input:o=!0,disabled:s,minDate:d,maxDate:i,placeholder:p,size:h="sm",variant:l,status:c,clearable:x,fullWidth:C=!0,withPadding:E=!0,editable:k=!1,trigger:y,renderTrigger:v,label:u,labelPosition:$,required:T,optional:w,description:M,helperText:m,errorText:N},B)=>{const H=N?"error":c,{ref:V,isComponentVisible:Y,setIsComponentVisible:D}=vn(!1),b=g.useRef(null),[S,F]=g.useState("days"),[L,I]=g.useState(new Date),W=typeof v=="function"||y!=null,O=!o&&!W,J=!O,[z,q]=g.useState({from:(n==null?void 0:n.from)??null,to:(n==null?void 0:n.to)??null}),[K,G]=g.useState(null);g.useEffect(()=>{if(n){const t=n;t.from&&I(t.from),q(t)}else I(new Date),q({from:null,to:null});G(null)},[n]),g.useEffect(()=>{r&&F(r)},[r]),g.useEffect(()=>{r||F("days")},[Y]),g.useEffect(()=>{O&&D(!0)},[O]);const Q=()=>{var t,f;if(!n)return"";if(r){if(S==="days")return`${rn(z.from)} ~ ${rn(z.to||z.from)||"-"}`;if(S==="months")return`${_[z.from.getMonth()]} ~ ${z.to?_[z.to.getMonth()]:"-"}`;if(S==="years")return`${(t=z.from)==null?void 0:t.getFullYear()} ~ ${((f=z.to)==null?void 0:f.getFullYear())||"-"}`}else return`${rn(z.from)} ~ ${rn(z.to||z.from)||"-"}`},j=()=>{if(b.current&&V.current&&J){const t=V.current.getBoundingClientRect(),f=b.current.getBoundingClientRect();window.innerWidth<t.left+f.width?b.current.style.left=`${t.left-f.width+t.width}px`:b.current.style.left=`${t.left}px`,t.top+f.height>window.innerHeight?b.current.style.top=`${t.y-(t.height+f.height-28)}px`:b.current.style.top=`${t.y+t.height}px`}};g.useEffect(()=>{b.current&&V.current&&J&&j()},[b,V,Y]),g.useEffect(()=>(window.addEventListener("scroll",j,!0),window.addEventListener("resize",j),()=>{window.removeEventListener("scroll",j,!0),window.removeEventListener("resize",j)}),[]);const on=()=>D(!0),ln=()=>D(!1),X=()=>D(t=>!t),dn=()=>{k&&G(Hn(z,r))},R=()=>{if(K===null)return;const t=K.trim();if(!t){a(void 0),G(null);return}const f=Wn(t,r),P=f&&wn(f.from,d,i)&&(!f.to||wn(f.to,d,i));f&&P&&(a(f),q(f),I(f.from)),G(null)},cn=t=>{t.key==="Enter"?(R(),D(!1)):t.key==="Escape"&&(G(null),D(!1))},un={isOpen:Y,open:on,close:ln,toggle:X,value:n,formattedValue:String(Q()??""),clear:()=>a(void 0),disabled:s,placeholder:p},nn=()=>{if(typeof v=="function")return v(un);if(g.isValidElement(y)){const t=y;return g.cloneElement(t,{onClick:f=>{var P,en;(en=(P=t.props)==null?void 0:P.onClick)==null||en.call(P,f),s||X()}})}return y},pn=e.jsxs("div",{className:`sa-calendar-wrapper${W?" sa-calendar-wrapper-custom":""}`,style:{height:O?"100%":"auto"},ref:t=>{V.current=J?t:null,typeof B=="function"?B(t):B&&(B.current=t)},children:[W?nn():o?e.jsx(Vn,{value:k&&K!==null?K:Q(),inputMode:k?"text":"none",readOnly:!k,onClick:()=>{D(!0)},onChange:k?t=>G(t.target.value):()=>{},onFocus:k?dn:void 0,onBlur:k?R:void 0,onKeyDown:k?cn:void 0,disabled:s,placeholder:p,size:h,variant:l,status:H,clearable:x,onClear:()=>a(void 0)}):null,Y?e.jsxs("div",{className:`sa-calendar sa-calendar-size-${h||"sm"} ${O?"sa-calendar-no-input":""} ${E?"":"sa-calendar-no-padding"}`,style:s?{pointerEvents:"none"}:void 0,ref:b,children:[e.jsx(An,{setViews:F,views:S,filter:r,date:L,setDate:I}),e.jsx("div",{className:"sa-calendar-body",children:S==="days"?e.jsx(Pn,{date:L,setDate:I,setIsComponentVisible:D,dateRange:z,setDateRange:q,input:o,onChange:a,minDate:d,maxDate:i}):S==="months"?e.jsx(jn,{date:L,setDate:I,filter:r,setViews:F,dateRange:z,setDateRange:q,setIsComponentVisible:D,input:o,onChange:a,minDate:d,maxDate:i}):e.jsx(On,{date:L,setDate:I,filter:r,setViews:F,dateRange:z,setDateRange:q,setIsComponentVisible:D,input:o,onChange:a,minDate:d,maxDate:i})})]}):null]});return e.jsx(xn,{label:u,labelPosition:$,required:T,optional:w,description:M,helperText:m,errorText:N,fullWidth:C,size:h,children:pn})}),Fn="sa-calendar-input-styles";(n=>{if(!(typeof document>"u")&&!document.getElementById(Fn)){const a=document.createElement("style");a.id=Fn,a.textContent=n,document.head.appendChild(a)}})(sn);const tn=n=>{if(n==="xs")return 14;if(n==="sm")return 16;if(n==="md")return 16;if(n==="lg")return 20},qn=n=>{const{size:a="sm",status:r="default",variant:o="outline",clearable:s,onClear:d,...i}=n,p=g.useRef(null),h=()=>{p.current&&i.onClick&&(p.current.focus(),i.onClick(""))},l=r==="disable"||i.disabled,c=!!i.value,x=s&&c&&!l,C=E=>{E.stopPropagation(),d==null||d()};return e.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${o} sa-calendar-input-container-${r} ${a} `,onClick:h,children:[e.jsx("div",{className:"sa-calendar-input-container-icon-left",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:tn(a),height:tn(a),viewBox:"0 0 20 20",fill:"none",children:e.jsx("path",{d:"M12.5 2.08301V5.41634M7.50002 2.08301V5.41634M17.0688 9.58301H2.93113M17.0688 9.58301C16.8953 4.82698 15.1284 3.33301 10 3.33301C4.87165 3.33301 3.10469 4.82698 2.93113 9.58301M17.0688 9.58301C17.0786 9.85037 17.0834 10.128 17.0834 10.4163C17.0834 15.833 15.4167 17.4997 10 17.4997C4.58335 17.4997 2.91669 15.833 2.91669 10.4163C2.91669 10.128 2.92138 9.85037 2.93113 9.58301",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),e.jsx("div",{className:"sa-calendar-input-preview-container",children:e.jsx("input",{className:"sa-calendar-input",...i,disabled:l,value:i.value,ref:p})}),x?e.jsx("button",{type:"button","aria-label":"Clear date",className:"sa-calendar-input-clear",onClick:C,children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:tn(a),height:tn(a),viewBox:"0 0 20 20",fill:"none",children:e.jsx("path",{d:"M5 5L15 15M15 5L5 15",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}):e.jsx("div",{className:"sa-calendar-input-container-icon-right",children:e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:tn(a),height:tn(a),viewBox:"0 0 20 20",fill:"none",children:e.jsx("path",{d:"M3.33331 7.5L9.99998 14.1667L16.6666 7.5",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]})},Kn=({date:n,setDate:a,previewDate:r,setPreviewDate:o,setIsComponentVisible:s,minDate:d,maxDate:i,input:p,onChange:h,hasValue:l})=>{let c=new Date(r.getFullYear(),r.getMonth(),1),x=c.getDay(),C=[];const E=n.toDateString(),k=new Date().toDateString(),y=r.getMonth();for(let u=0;u<42;u++){u===0&&x===0?c.setDate(c.getDate()-7):u===0?c.setDate(c.getDate()+(u-x)):c.setDate(c.getDate()+1);let $={currentMonth:c.getMonth()===y,date:new Date(c),month:c.getMonth(),number:c.getDate(),selected:l&&c.toDateString()===E,isToday:c.toDateString()===k,year:c.getFullYear(),isDisabled:d&&c<d||i&&c>i};C.push($)}const v=u=>{(!d||u>=d)&&(!i||u<=i)&&(a(u),h(u),o(u),p&&s(!1))};return e.jsxs("div",{className:"sa-calendar-days-preivew",children:[e.jsx("div",{className:"sa-calendar-days-name-preivew",children:Cn.map((u,$)=>e.jsx("p",{children:u},$))}),e.jsx("div",{className:"sa-calendar-days-number-preivew",children:C.map((u,$)=>{const T=u.isDisabled;return e.jsx("p",{className:`${u.currentMonth?"sa-calendar-days-current":"sa-calendar-days"} ${u.selected?"sa-calendar-days-active":""} ${u.isToday&&!u.selected?"sa-calendar-days-today":""}`,style:{color:T?"var(--sa-text-disable, #181a198f)":void 0,pointerEvents:T?"none":void 0,cursor:T?"not-allowed":"pointer",...p?{}:{width:"100%"}},onClick:()=>{T||v(u.date)},children:u.number},$)})})]})},Gn=({date:n,setDate:a,filter:r,setViews:o,onChange:s,previewDate:d,setPreviewDate:i,minDate:p,maxDate:h,input:l,hasValue:c})=>{const x=n.getMonth(),C=n.getFullYear(),E=d.getFullYear(),k=y=>{(!p||y>=p)&&(!h||y<=h)&&(r?(s(y),a(y),i(y)):(o("days"),i(y)))};return e.jsx("div",{className:"sa-calendar-months-preview",children:_.map((y,v)=>{const u=p&&new Date(E,v,1)<p||h&&new Date(E,v+1,0)>h;return e.jsx("p",{className:c&&v===x&&E===C?"sa-calendar-months-active":"",style:{color:u?"var(--sa-text-disable, #181a198f)":void 0,pointerEvents:u?"none":void 0,cursor:u?"not-allowed":"pointer",...l?{}:{width:"100%"}},onClick:()=>{u||k(new Date(E,v))},children:y.slice(0,3)},v)})})},kn=n=>{const a=Math.floor(n/10)*10,r=a+10;return{start:a,end:r}},Un=({date:n,filter:a,setViews:r,setDate:o,onChange:s,previewDate:d,setPreviewDate:i,minDate:p,maxDate:h,input:l,hasValue:c})=>{let x=[];const C=d.getFullYear(),{start:E,end:k}=kn(C),y=n.getFullYear();for(let u=E;u<k;u++){let $=p&&new Date(u,0,1)<p||h&&new Date(u,11,31)>h;x.push({year:u,active:!!c&&u===y,isDisabled:$})}const v=u=>{(!p||u>=p)&&(!h||u<=h)&&(a?(s(u),o(u),i(u)):(r("months"),i(u)))};return e.jsx("div",{className:"sa-calendar-years-preview",children:x.map((u,$)=>e.jsx("p",{className:u.active?"sa-calendar-months-active":"",style:{color:u.isDisabled?"var(--sa-text-disable, #181a198f)":void 0,pointerEvents:u.isDisabled?"none":void 0,cursor:u.isDisabled?"not-allowed":"pointer",...l?{}:{width:"100%"}},onClick:()=>{u.isDisabled||v(new Date(u.year,0))},children:u.year},$))})},Zn=({setViews:n,views:a,filter:r,previewDate:o,setPreviewDate:s})=>{const d=()=>{r||n(l=>l==="days"?"months":l==="months"?"years":"days")},i=()=>{if(a==="years"){s(l=>new Date(l.getFullYear()+10,0));return}if(a==="months"){s(l=>new Date(l.getFullYear()+1,l.getMonth()));return}s(l=>new Date(l.getFullYear(),l.getMonth()+1))},p=()=>{if(a==="years"){s(l=>new Date(l.getFullYear()-10,0));return}if(a==="months"){s(l=>new Date(l.getFullYear()-1,l.getMonth()));return}s(l=>new Date(l.getMonth()===0?l.getFullYear()-1:l.getFullYear(),l.getMonth()===0?11:l.getMonth()-1))},h=()=>{if(a==="days")return`${_[o.getMonth()]} ${o.getFullYear()}`;if(a==="months")return`${o.getFullYear()}`;if(a==="years")return`${kn(o.getFullYear()).start} ~ ${kn(o.getFullYear()).end}`};return e.jsxs("div",{className:"sa-calendar-header",children:[e.jsx("div",{className:"sa-calendar-header-title",onClick:d,children:h()}),e.jsxs("div",{className:"sa-calendar-header-nav",children:[e.jsx("button",{className:"sa-calendar-nav-btn",onClick:p,children:e.jsx(Dn,{})}),e.jsx("button",{className:"sa-calendar-nav-btn",onClick:i,children:e.jsx(zn,{})})]})]})},Yn="sa-calendar-styles";(n=>{if(!(typeof document>"u")&&!document.getElementById(Yn)){const a=document.createElement("style");a.id=Yn,a.textContent=n,document.head.appendChild(a)}})(sn);const _n=g.forwardRef(({value:n,onChange:a,filter:r,input:o=!0,disabled:s,minDate:d,maxDate:i,placeholder:p,size:h="sm",variant:l,status:c,clearable:x,fullWidth:C=!0,withPadding:E=!0,editable:k=!1,trigger:y,renderTrigger:v,label:u,labelPosition:$,required:T,optional:w,description:M,helperText:m,errorText:N},B)=>{const H=N?"error":c,{ref:V,isComponentVisible:Y,setIsComponentVisible:D}=vn(!1),b=g.useRef(null),[S,F]=g.useState("days"),[L,I]=g.useState(new Date),[W,O]=g.useState(new Date),[J,z]=g.useState(null),q=typeof v=="function"||y!=null,K=!o&&!q,G=!K;g.useEffect(()=>{n?(I(n),O(n)):(I(new Date),O(new Date)),z(null)},[n]),g.useEffect(()=>{r&&F(r)},[r]),g.useEffect(()=>{r||F("days")},[Y]),g.useEffect(()=>{K&&D(!0)},[K]);const Q=()=>n?r==="days"?rn(L):r==="months"?`${_[L.getMonth()]} ${L.getFullYear()}`:r==="years"?L.getFullYear():rn(L):"",j=()=>{if(b.current&&V.current&&G){const t=V.current.getBoundingClientRect(),f=b.current.getBoundingClientRect();window.innerWidth<t.left+f.width?b.current.style.left=`${t.left-f.width+t.width}px`:b.current.style.left=`${t.left}px`,t.top+f.height>window.innerHeight?b.current.style.top=`${t.y-(t.height+f.height-28)}px`:b.current.style.top=`${t.y+t.height}px`}};g.useEffect(()=>{b.current&&V.current&&G&&j()},[b,V,Y]),g.useEffect(()=>(window.addEventListener("scroll",j,!0),window.addEventListener("resize",j),()=>{window.removeEventListener("scroll",j,!0),window.removeEventListener("resize",j)}),[]);const on=()=>D(!0),ln=()=>D(!1),X=()=>D(t=>!t),dn=()=>{k&&z(n?yn(n,r):"")},R=()=>{if(J===null)return;const t=J.trim();if(!t){a(void 0),z(null);return}const f=fn(t,r);f&&wn(f,d,i)&&(a(f),I(f),O(f)),z(null)},cn=t=>{t.key==="Enter"?(R(),D(!1)):t.key==="Escape"&&(z(null),D(!1))},un={isOpen:Y,open:on,close:ln,toggle:X,value:n,formattedValue:String(Q()??""),clear:()=>a(void 0),disabled:s,placeholder:p},nn=()=>{if(typeof v=="function")return v(un);if(g.isValidElement(y)){const t=y;return g.cloneElement(t,{onClick:f=>{var P,en;(en=(P=t.props)==null?void 0:P.onClick)==null||en.call(P,f),s||X()}})}return y},pn=e.jsxs("div",{className:`sa-calendar-wrapper${q?" sa-calendar-wrapper-custom":""}`,style:{height:K?"100%":"auto"},ref:t=>{V.current=G?t:null,typeof B=="function"?B(t):B&&(B.current=t)},children:[q?nn():o?e.jsx(qn,{value:k&&J!==null?J:Q(),onClick:()=>D(!0),onChange:k?t=>z(t.target.value):()=>{},onFocus:k?dn:void 0,onBlur:k?R:void 0,onKeyDown:k?cn:void 0,placeholder:p,disabled:s,size:h,variant:l,status:H,inputMode:k?"text":"none",readOnly:!k,clearable:x,onClear:()=>a(void 0)}):null,Y?e.jsxs("div",{className:`sa-calendar sa-calendar-size-${h||"sm"} ${K?"sa-calendar-no-input":""} ${E?"":"sa-calendar-no-padding"}`,style:s?{pointerEvents:"none"}:void 0,ref:b,children:[e.jsx(Zn,{setViews:F,views:S,filter:r,previewDate:W,setPreviewDate:O,isComponentVisible:Y}),e.jsx("div",{className:"sa-calendar-body",children:S==="days"?e.jsx(Kn,{date:L,setDate:I,previewDate:W,setPreviewDate:O,setIsComponentVisible:D,input:o,minDate:d,maxDate:i,onChange:a,hasValue:n!=null}):S==="months"?e.jsx(Gn,{date:L,setDate:I,previewDate:W,setPreviewDate:O,filter:r,setViews:F,onChange:a,minDate:d,maxDate:i,input:o,hasValue:n!=null}):e.jsx(Un,{date:L,setDate:I,previewDate:W,setPreviewDate:O,filter:r,setViews:F,onChange:a,minDate:d,maxDate:i,input:o,hasValue:n!=null})})]}):null]});return e.jsx(xn,{label:u,labelPosition:$,required:T,optional:w,description:M,helperText:m,errorText:N,fullWidth:C,size:h,children:pn})}),Qn=g.forwardRef(({value:n,onChange:a,filter:r,input:o=!0,rangedDate:s,disabled:d,minDate:i,maxDate:p,placeholder:h,size:l,variant:c,status:x,clearable:C,fullWidth:E,withPadding:k,editable:y,trigger:v,renderTrigger:u,label:$,labelPosition:T,required:w,optional:M,description:m,helperText:N,errorText:B},H)=>{const V={onChange:a,value:n,input:o,filter:r,disabled:d,minDate:i,maxDate:p,placeholder:h,size:l,variant:c,status:x,clearable:C,fullWidth:E,withPadding:k,editable:y,trigger:v,renderTrigger:u,label:$,labelPosition:T,required:w,optional:M,description:m,helperText:N,errorText:B};return e.jsx(e.Fragment,{children:s?e.jsx(Jn,{...V,ref:H}):e.jsx(_n,{...V,ref:H})})}),Xn=`/* Cascade layer \`starasia.components\` — lihat @starasia/css (urutan: theme, base,
608
621
  starasia, components, utilities). CSS app/Tailwind utility selalu bisa
609
622
  menimpa aturan di sini. Isi sengaja tidak di-indent (diff minimal). */
610
623
  @layer starasia.components {
@@ -742,4 +755,4 @@
742
755
  }
743
756
 
744
757
  } /* @layer starasia.components */
745
- `,Mn=(n,a,r)=>Math.min(r,Math.max(a,n)),A=n=>String(n).padStart(2,"0"),Nn=n=>{if(!n)return null;const a=/^(\d{1,2}):(\d{2})(?::(\d{2}))?$/.exec(n.trim());if(!a)return null;const r=Number(a[1]),o=Number(a[2]),s=a[3]!=null?Number(a[3]):0;return r>23||o>59||s>59?null:{h:r,m:o,s}},Rn=(n,a)=>a?`${A(n.h)}:${A(n.m)}:${A(n.s)}`:`${A(n.h)}:${A(n.m)}`,Z=n=>n.h*60+n.m,ne=(n,a,r)=>{const o=r?`:${A(n.s)}`:"";if(a==="12h"){const s=n.h>=12?"PM":"AM",d=n.h%12===0?12:n.h%12;return`${A(d)}:${A(n.m)}${o} ${s}`}return`${A(n.h)}:${A(n.m)}${o}`},ee=(n,a,r)=>{const o=n.toLowerCase(),s=/p/.test(o)?"pm":/a/.test(o)?"am":null,d=o.replace(/[^\d]/g,"");if(!d)return null;let i=0,p=0,h=0;if(n.includes(":")){const l=n.split(":").map(c=>c.replace(/[^\d]/g,""));i=Number(l[0]||0),p=Number(l[1]||0),h=r?Number(l[2]||0):0}else d.length<=2?i=Number(d):d.length<=4?(i=Number(d.slice(0,d.length-2)),p=Number(d.slice(-2))):(i=Number(d.slice(0,d.length-4)),p=Number(d.slice(-4,-2)),h=r?Number(d.slice(-2)):0);return s&&(s==="pm"&&i<12&&(i+=12),s==="am"&&i===12&&(i=0)),i>23||p>59||h>59?null:{h:Mn(i,0,23),m:Mn(p,0,59),s:Mn(h,0,59)}},hn=(n,a=1)=>{const r=[];for(let o=0;o<n;o+=a)r.push(o);return r},Ln=(n,a)=>{if(typeof document>"u"||document.getElementById(n))return;const r=document.createElement("style");r.id=n,r.textContent=a,document.head.appendChild(r)};Ln("sa-calendar-styles",sn),Ln("sa-time-styles",Xn);const ae=n=>n==="xs"?14:n==="lg"?20:16,In=({s:n})=>e.jsx("svg",{width:n,height:n,viewBox:"0 0 20 20",fill:"none",children:e.jsx("path",{d:"M10 5v5l3 2M17.5 10a7.5 7.5 0 1 1-15 0 7.5 7.5 0 0 1 15 0Z",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),re=({s:n})=>e.jsx("svg",{width:n,height:n,viewBox:"0 0 20 20",fill:"none",children:e.jsx("path",{d:"M5 5l10 10M15 5L5 15",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round"})}),gn=({label:n,options:a,active:r,onPick:o})=>{const s=g.useRef(null),d=g.useRef(null);return g.useEffect(()=>{var i;(i=d.current)==null||i.scrollIntoView({block:"nearest"})},[r]),e.jsxs("div",{className:"sa-time-col",children:[e.jsx("div",{className:"sa-time-col-head",children:n}),e.jsx("div",{className:"sa-time-col-list",ref:s,children:a.map(i=>{const p=i.value===r;return e.jsx("button",{type:"button",ref:p?d:null,disabled:i.disabled,className:`sa-time-opt${p?" sa-time-opt-active":""}`,onClick:()=>o(i.value),children:i.label},i.value)})})]})},Tn=g.forwardRef(({value:n,onChange:a,format:r="24h",withSeconds:o=!1,step:s=1,minTime:d,maxTime:i,input:p=!0,placeholder:h="--:--",disabled:l,clearable:c,size:x="sm",variant:$="outline",status:E,fullWidth:k=!0,withPadding:y=!0,label:v,labelPosition:u,required:C,optional:T,description:w,helperText:M,errorText:m},N)=>{const B=m?"error":E,{ref:H,isComponentVisible:V,setIsComponentVisible:F}=vn(!1),D=g.useRef(null),b=g.useMemo(()=>Nn(n),[n]),S=g.useMemo(()=>Nn(d),[d]),Y=g.useMemo(()=>Nn(i),[i]),[L,I]=g.useState(null);g.useEffect(()=>{p||F(!0)},[p]);const W=()=>{if(!D.current||!H.current||!p)return;const t=H.current.getBoundingClientRect(),f=D.current.getBoundingClientRect();D.current.style.left=window.innerWidth<t.left+f.width?`${t.left-f.width+t.width}px`:`${t.left}px`,D.current.style.top=t.top+f.height>window.innerHeight?`${t.y-(t.height+f.height-28)}px`:`${t.y+t.height}px`};g.useEffect(()=>{W()},[V]),g.useEffect(()=>(window.addEventListener("scroll",W,!0),window.addEventListener("resize",W),()=>{window.removeEventListener("scroll",W,!0),window.removeEventListener("resize",W)}),[]);const O=t=>{const f=Z(t);return!(S&&f<Z(S)||Y&&f>Z(Y))},J=t=>{a(Rn(t,o)),I(null)},z=t=>{J({...b??{h:0,m:0,s:0},...t})},q=()=>{if(L==null)return;if(L.trim()===""){a(null),I(null);return}const t=ee(L,r,o);t&&O(t)?J(t):I(null)},K=b?ne(b,r,o):"",U=L??K,Q=c&&!!b&&!l,j=b&&b.h>=12?"PM":"AM",on=g.useMemo(()=>r==="12h"?hn(12).map(t=>{const f=t===0?12:t,P=j==="PM"?f%12+12:f%12;return{value:f,label:A(f),disabled:S&&P*60+59<Z(S)||Y&&P*60>Z(Y)||!1}}):hn(24).map(t=>({value:t,label:A(t),disabled:S&&t*60+59<Z(S)||Y&&t*60>Z(Y)||!1})),[r,j,S,Y]),ln=g.useMemo(()=>{const t=(b==null?void 0:b.h)??0;return hn(60,s).map(f=>({value:f,label:A(f),disabled:S&&t*60+f<Z(S)||Y&&t*60+f>Z(Y)||!1}))},[s,b==null?void 0:b.h,S,Y]),X=g.useMemo(()=>hn(60).map(t=>({value:t,label:A(t)})),[]),dn=b==null?null:r==="12h"?b.h%12===0?12:b.h%12:b.h,R=t=>{if(r==="12h"){const f=j==="PM"?t%12+12:t%12;z({h:f})}else z({h:t})},cn=t=>{const f=b??{h:0,m:0,s:0},P=f.h%12===0?12:f.h%12,en=t==="PM"?P%12+12:P%12;J({...f,h:en})},un=()=>{const t=new Date,f=Math.floor(t.getMinutes()/s)*s;J({h:t.getHours(),m:f,s:o?t.getSeconds():0})},nn=ae(x),pn=e.jsxs("div",{className:"sa-calendar-wrapper",style:{height:p?"auto":"100%"},ref:p?H:null,children:[p?e.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${$} sa-calendar-input-container-${B||"default"} ${x}`,onClick:()=>!l&&F(!0),children:[e.jsx("div",{className:"sa-calendar-input-container-icon-left",children:e.jsx(In,{s:nn})}),e.jsx("div",{className:"sa-calendar-input-preview-container",children:e.jsx("input",{className:"sa-calendar-input",value:U,placeholder:h,disabled:l,onChange:t=>I(t.target.value),onFocus:()=>F(!0),onBlur:q,onKeyDown:t=>{t.key==="Enter"&&(q(),F(!1)),t.key==="Escape"&&(I(null),F(!1))}})}),Q?e.jsx("button",{type:"button","aria-label":"Clear time",className:"sa-calendar-input-clear",onClick:t=>{t.stopPropagation(),a(null),I(null)},children:e.jsx(re,{s:nn})}):e.jsx("div",{className:"sa-calendar-input-container-icon-right",children:e.jsx(In,{s:nn})})]}):null,V?e.jsxs("div",{ref:D,className:`sa-calendar sa-calendar-size-${x} ${p?"":"sa-calendar-no-input"} ${y?"":"sa-calendar-no-padding"}`,style:l?{pointerEvents:"none"}:void 0,children:[e.jsxs("div",{className:"sa-time-columns",children:[e.jsx(gn,{label:"Jam",options:on,active:dn,onPick:R}),e.jsx("div",{className:"sa-time-divider"}),e.jsx(gn,{label:"Menit",options:ln,active:(b==null?void 0:b.m)??null,onPick:t=>z({m:t})}),o&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"sa-time-divider"}),e.jsx(gn,{label:"Detik",options:X,active:(b==null?void 0:b.s)??null,onPick:t=>z({s:t})})]}),r==="12h"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"sa-time-divider"}),e.jsx(gn,{label:"",options:[{value:0,label:"AM"},{value:1,label:"PM"}],active:b==null?null:j==="PM"?1:0,onPick:t=>cn(t===1?"PM":"AM")})]})]}),e.jsxs("div",{className:"sa-time-footer",children:[e.jsx("button",{type:"button",className:"sa-time-footer-btn",onClick:un,children:"Sekarang"}),e.jsx("button",{type:"button",className:"sa-time-footer-btn sa-time-footer-btn-muted",onClick:()=>{a(null),I(null)},children:"Hapus"})]})]}):null]});return e.jsx(xn,{label:v,labelPosition:u,required:C,optional:T,description:w,helperText:M,errorText:m,fullWidth:k,size:x,children:pn})});Tn.displayName="StarasiaTime",G.StarasiaDate=Qn,G.StarasiaTime=Tn,Object.defineProperty(G,Symbol.toStringTag,{value:"Module"})});
758
+ `,Mn=(n,a,r)=>Math.min(r,Math.max(a,n)),A=n=>String(n).padStart(2,"0"),Nn=n=>{if(!n)return null;const a=/^(\d{1,2}):(\d{2})(?::(\d{2}))?$/.exec(n.trim());if(!a)return null;const r=Number(a[1]),o=Number(a[2]),s=a[3]!=null?Number(a[3]):0;return r>23||o>59||s>59?null:{h:r,m:o,s}},Rn=(n,a)=>a?`${A(n.h)}:${A(n.m)}:${A(n.s)}`:`${A(n.h)}:${A(n.m)}`,Z=n=>n.h*60+n.m,ne=(n,a,r)=>{const o=r?`:${A(n.s)}`:"";if(a==="12h"){const s=n.h>=12?"PM":"AM",d=n.h%12===0?12:n.h%12;return`${A(d)}:${A(n.m)}${o} ${s}`}return`${A(n.h)}:${A(n.m)}${o}`},ee=(n,a,r)=>{const o=n.toLowerCase(),s=/p/.test(o)?"pm":/a/.test(o)?"am":null,d=o.replace(/[^\d]/g,"");if(!d)return null;let i=0,p=0,h=0;if(n.includes(":")){const l=n.split(":").map(c=>c.replace(/[^\d]/g,""));i=Number(l[0]||0),p=Number(l[1]||0),h=r?Number(l[2]||0):0}else d.length<=2?i=Number(d):d.length<=4?(i=Number(d.slice(0,d.length-2)),p=Number(d.slice(-2))):(i=Number(d.slice(0,d.length-4)),p=Number(d.slice(-4,-2)),h=r?Number(d.slice(-2)):0);return s&&(s==="pm"&&i<12&&(i+=12),s==="am"&&i===12&&(i=0)),i>23||p>59||h>59?null:{h:Mn(i,0,23),m:Mn(p,0,59),s:Mn(h,0,59)}},hn=(n,a=1)=>{const r=[];for(let o=0;o<n;o+=a)r.push(o);return r},Ln=(n,a)=>{if(typeof document>"u"||document.getElementById(n))return;const r=document.createElement("style");r.id=n,r.textContent=a,document.head.appendChild(r)};Ln("sa-calendar-styles",sn),Ln("sa-time-styles",Xn);const ae=n=>n==="xs"?14:n==="lg"?20:16,In=({s:n})=>e.jsx("svg",{width:n,height:n,viewBox:"0 0 20 20",fill:"none",children:e.jsx("path",{d:"M10 5v5l3 2M17.5 10a7.5 7.5 0 1 1-15 0 7.5 7.5 0 0 1 15 0Z",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),re=({s:n})=>e.jsx("svg",{width:n,height:n,viewBox:"0 0 20 20",fill:"none",children:e.jsx("path",{d:"M5 5l10 10M15 5L5 15",stroke:"var(--sa-color-gray-500, #8c8f97)",strokeWidth:"1.5",strokeLinecap:"round"})}),gn=({label:n,options:a,active:r,onPick:o})=>{const s=g.useRef(null),d=g.useRef(null);return g.useEffect(()=>{var i;(i=d.current)==null||i.scrollIntoView({block:"nearest"})},[r]),e.jsxs("div",{className:"sa-time-col",children:[e.jsx("div",{className:"sa-time-col-head",children:n}),e.jsx("div",{className:"sa-time-col-list",ref:s,children:a.map(i=>{const p=i.value===r;return e.jsx("button",{type:"button",ref:p?d:null,disabled:i.disabled,className:`sa-time-opt${p?" sa-time-opt-active":""}`,onClick:()=>o(i.value),children:i.label},i.value)})})]})},Tn=g.forwardRef(({value:n,onChange:a,format:r="24h",withSeconds:o=!1,step:s=1,minTime:d,maxTime:i,input:p=!0,placeholder:h="--:--",disabled:l,clearable:c,size:x="sm",variant:C="outline",status:E,fullWidth:k=!0,withPadding:y=!0,label:v,labelPosition:u,required:$,optional:T,description:w,helperText:M,errorText:m},N)=>{const B=m?"error":E,{ref:H,isComponentVisible:V,setIsComponentVisible:Y}=vn(!1),D=g.useRef(null),b=g.useMemo(()=>Nn(n),[n]),S=g.useMemo(()=>Nn(d),[d]),F=g.useMemo(()=>Nn(i),[i]),[L,I]=g.useState(null);g.useEffect(()=>{p||Y(!0)},[p]);const W=()=>{if(!D.current||!H.current||!p)return;const t=H.current.getBoundingClientRect(),f=D.current.getBoundingClientRect();D.current.style.left=window.innerWidth<t.left+f.width?`${t.left-f.width+t.width}px`:`${t.left}px`,D.current.style.top=t.top+f.height>window.innerHeight?`${t.y-(t.height+f.height-28)}px`:`${t.y+t.height}px`};g.useEffect(()=>{W()},[V]),g.useEffect(()=>(window.addEventListener("scroll",W,!0),window.addEventListener("resize",W),()=>{window.removeEventListener("scroll",W,!0),window.removeEventListener("resize",W)}),[]);const O=t=>{const f=Z(t);return!(S&&f<Z(S)||F&&f>Z(F))},J=t=>{a(Rn(t,o)),I(null)},z=t=>{J({...b??{h:0,m:0,s:0},...t})},q=()=>{if(L==null)return;if(L.trim()===""){a(null),I(null);return}const t=ee(L,r,o);t&&O(t)?J(t):I(null)},K=b?ne(b,r,o):"",G=L??K,Q=c&&!!b&&!l,j=b&&b.h>=12?"PM":"AM",on=g.useMemo(()=>r==="12h"?hn(12).map(t=>{const f=t===0?12:t,P=j==="PM"?f%12+12:f%12;return{value:f,label:A(f),disabled:S&&P*60+59<Z(S)||F&&P*60>Z(F)||!1}}):hn(24).map(t=>({value:t,label:A(t),disabled:S&&t*60+59<Z(S)||F&&t*60>Z(F)||!1})),[r,j,S,F]),ln=g.useMemo(()=>{const t=(b==null?void 0:b.h)??0;return hn(60,s).map(f=>({value:f,label:A(f),disabled:S&&t*60+f<Z(S)||F&&t*60+f>Z(F)||!1}))},[s,b==null?void 0:b.h,S,F]),X=g.useMemo(()=>hn(60).map(t=>({value:t,label:A(t)})),[]),dn=b==null?null:r==="12h"?b.h%12===0?12:b.h%12:b.h,R=t=>{if(r==="12h"){const f=j==="PM"?t%12+12:t%12;z({h:f})}else z({h:t})},cn=t=>{const f=b??{h:0,m:0,s:0},P=f.h%12===0?12:f.h%12,en=t==="PM"?P%12+12:P%12;J({...f,h:en})},un=()=>{const t=new Date,f=Math.floor(t.getMinutes()/s)*s;J({h:t.getHours(),m:f,s:o?t.getSeconds():0})},nn=ae(x),pn=e.jsxs("div",{className:"sa-calendar-wrapper",style:{height:p?"auto":"100%"},ref:p?H:null,children:[p?e.jsxs("div",{className:`sa-calendar-input-container sa-calendar-input-${C} sa-calendar-input-container-${B||"default"} ${x}`,onClick:()=>!l&&Y(!0),children:[e.jsx("div",{className:"sa-calendar-input-container-icon-left",children:e.jsx(In,{s:nn})}),e.jsx("div",{className:"sa-calendar-input-preview-container",children:e.jsx("input",{className:"sa-calendar-input",value:G,placeholder:h,disabled:l,onChange:t=>I(t.target.value),onFocus:()=>Y(!0),onBlur:q,onKeyDown:t=>{t.key==="Enter"&&(q(),Y(!1)),t.key==="Escape"&&(I(null),Y(!1))}})}),Q?e.jsx("button",{type:"button","aria-label":"Clear time",className:"sa-calendar-input-clear",onClick:t=>{t.stopPropagation(),a(null),I(null)},children:e.jsx(re,{s:nn})}):e.jsx("div",{className:"sa-calendar-input-container-icon-right",children:e.jsx(In,{s:nn})})]}):null,V?e.jsxs("div",{ref:D,className:`sa-calendar sa-calendar-size-${x} ${p?"":"sa-calendar-no-input"} ${y?"":"sa-calendar-no-padding"}`,style:l?{pointerEvents:"none"}:void 0,children:[e.jsxs("div",{className:"sa-time-columns",children:[e.jsx(gn,{label:"Jam",options:on,active:dn,onPick:R}),e.jsx("div",{className:"sa-time-divider"}),e.jsx(gn,{label:"Menit",options:ln,active:(b==null?void 0:b.m)??null,onPick:t=>z({m:t})}),o&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"sa-time-divider"}),e.jsx(gn,{label:"Detik",options:X,active:(b==null?void 0:b.s)??null,onPick:t=>z({s:t})})]}),r==="12h"&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"sa-time-divider"}),e.jsx(gn,{label:"",options:[{value:0,label:"AM"},{value:1,label:"PM"}],active:b==null?null:j==="PM"?1:0,onPick:t=>cn(t===1?"PM":"AM")})]})]}),e.jsxs("div",{className:"sa-time-footer",children:[e.jsx("button",{type:"button",className:"sa-time-footer-btn",onClick:un,children:"Sekarang"}),e.jsx("button",{type:"button",className:"sa-time-footer-btn sa-time-footer-btn-muted",onClick:()=>{a(null),I(null)},children:"Hapus"})]})]}):null]});return e.jsx(xn,{label:v,labelPosition:u,required:$,optional:T,description:w,helperText:M,errorText:m,fullWidth:k,size:x,children:pn})});Tn.displayName="StarasiaTime",U.StarasiaDate=Qn,U.StarasiaTime=Tn,Object.defineProperty(U,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@starasia/date",
3
- "version": "7.1.0",
3
+ "version": "7.2.0",
4
4
  "description": "date component for starasia UI",
5
5
  "author": "Prawito Hudoro",
6
6
  "main": "dist/date.umd.js",