import { W as de, w as A, a4 as o, X as Z, bX as me, a9 as ce, V as M, ce as B, a5 as P, cf as ue, aG as fe, cg as ye, S as he, ch as Ve, aa as ge, ab as w, ci as q, U, cj as r, ck as m, H as V, cl as C, cm as x, c5 as j, cn as W, ad as c, I as v, ae as s, af as d, co as H, am as l, cp as N, c0 as _, ag as L, cq as X, c3 as $, cr as Se, ah as G, cs as f, c1 as J, ct as we, cu as ve, P as Te, _ as Ze, cv as be, cw as Ce, cx as xe, cy as De, cz as Re, cA as Ee, cB as Pe, cC as z, cD as Me, cE as Fe, cF as Ie } from "./56c67d3b.js";
import { useState as K, useEffect as b, useContext as i } from "react";
import { disabledTime as Q, handleDateChange as F, dateRefMethods as Y } from "./85fb0bcf.js";
import { DateUIView as Be } from "./d9000f33.js";
import { DateRangeUIView as ze } from "./3aa1b662.js";
import { timeZoneOptions as Ke } from "./381f866e.js";
import "react-dom";
import "./4cac7a5d.js";
const Oe = [Me, Fe, Ie], Ae = {
  showValidationWhenEmpty: M,
  required: M,
  minDate: Z,
  maxDate: Z,
  minTime: Z,
  maxTime: Z,
  customRule: ve
}, p = {
  label: de,
  placeholder: A(Z, o("date.placeholder")),
  format: Z,
  disabled: me,
  onEvent: ce(Oe),
  showTime: M,
  use12Hours: M,
  hourStep: B.closed(1, 24, 1),
  minuteStep: B.closed(1, 60, 1),
  secondStep: B.closed(1, 60, 1),
  style: P(ue, "style"),
  animationStyle: P(fe, "animationStyle"),
  labelStyle: P(ye.filter((e) => ["accent", "validate"].includes(e.name) === !1), "labelStyle"),
  suffixIcon: A(Te, "/icon:regular/calendar"),
  ...Ae,
  viewRef: he,
  inputFieldStyle: P(Ve, "inputFieldStyle"),
  timeZone: ge(Ke, Intl.DateTimeFormat().resolvedOptions().timeZone)
}, ee = (e) => Ze.pick(e, "format", "showTime", "use12Hours", "hourStep", "minuteStep", "secondStep", "placeholder"), te = (e, t) => [e.showTime.propertyView({
  label: o("date.showTime")
}), !t && e.use12Hours.propertyView({
  label: o("prop.use12Hours")
})], ae = (e, t = !0) => {
  if (t && e.showTime.getView())
    return /* @__PURE__ */ c(s, {
      name: d.advanced,
      children: [be(e), Ce(e), xe(e)]
    });
}, oe = (e, t = "date") => {
  if (t === "date")
    return [De(e), Re(e)];
}, ne = (e, t = "date") => {
  if (t === "date" && e.showTime.getView())
    return [Ee(e), Pe(e)];
};
function D(e) {
  if (e.customRule)
    return {
      validateStatus: "error",
      help: e.customRule
    };
  const t = r(e.value.value, m);
  return e.required && (e.value.value === "" || !t.isValid()) ? {
    validateStatus: "error",
    help: o("prop.required")
  } : {
    validateStatus: "success"
  };
}
const ke = {
  defaultValue: w("defaultValue"),
  value: w("value"),
  userTimeZone: w("userTimeZone", Intl.DateTimeFormat().resolvedOptions().timeZone),
  ...p,
  ...q
}, qe = new U(ke, (e) => {
  const t = {
    ...e.defaultValue
  }.value, a = {
    ...e.value
  }.value;
  let n = null;
  a !== "" && (n = r(a, m));
  const [y, h] = K(n);
  b(() => {
    e.value.onChange(t);
  }, [t]), b(() => {
    const u = a ? r(a, m) : null;
    h(u);
  }, [a]);
  const S = (u) => {
    e.userTimeZone.onChange(u);
  };
  return e.label({
    required: e.required,
    style: e.style,
    labelStyle: e.labelStyle,
    inputFieldStyle: e.inputFieldStyle,
    animationStyle: e.animationStyle,
    onMouseDown: (u) => u.stopPropagation(),
    children: /* @__PURE__ */ V(Be, {
      onClickDateTimeZone: S,
      timeZone: e.timeZone,
      viewRef: e.viewRef,
      disabledTime: () => Q(e.minTime, e.maxTime),
      $style: e.inputFieldStyle,
      disabled: e.disabled,
      ...ee(e),
      hourStep: e.hourStep,
      minDate: e.minDate,
      maxDate: e.maxDate,
      placeholder: e.placeholder,
      value: y != null && y.isValid() ? y : null,
      onChange: (u) => {
        F(u && u.isValid() ? u.format(e.showTime ? C : x) : "", e.value.onChange, e.onEvent);
      },
      onPanelChange: () => {
        F("", e.value.onChange, z.noop);
      },
      onFocus: () => e.onEvent("focus"),
      onBlur: () => e.onEvent("blur"),
      suffixIcon: j(e.suffixIcon) && e.suffixIcon
    }),
    showValidationWhenEmpty: e.showValidationWhenEmpty,
    ...D(e)
  });
}).setPropertyViewFn((e) => {
  const t = W();
  return /* @__PURE__ */ c(v, {
    children: [/* @__PURE__ */ c(s, {
      name: d.basic,
      children: [e.defaultValue.propertyView({
        label: o("prop.defaultValue"),
        placeholder: "2022-04-07 21:39:59",
        tooltip: o("date.formatTip")
      }), e.timeZone.propertyView({
        label: o("prop.timeZone")
      })]
    }), /* @__PURE__ */ V(H, {
      ...e
    }), (i(l).editorModeStatus === "logic" || i(l).editorModeStatus === "both") && /* @__PURE__ */ c(v, {
      children: [/* @__PURE__ */ c(s, {
        name: d.validation,
        children: [N(e), e.showValidationWhenEmpty.propertyView({
          label: o("prop.showEmptyValidation")
        }), oe(e), ne(e), e.customRule.propertyView({})]
      }), /* @__PURE__ */ c(s, {
        name: d.interaction,
        children: [e.onEvent.getPropertyView(), _(e), L(e)]
      })]
    }), (i(l).editorModeStatus === "layout" || i(l).editorModeStatus === "both") && e.label.getPropertyView(), (i(l).editorModeStatus === "layout" || i(l).editorModeStatus === "both") && /* @__PURE__ */ c(s, {
      name: d.layout,
      children: [X({
        children: e
      }), e.placeholder.propertyView({
        label: o("date.placeholderText")
      })]
    }), (i(l).editorModeStatus === "logic" || i(l).editorModeStatus === "both") && /* @__PURE__ */ V(v, {
      children: /* @__PURE__ */ c(s, {
        name: d.advanced,
        children: [te(e, t), e.suffixIcon.propertyView({
          label: o("button.suffixIcon")
        })]
      })
    }), (i(l).editorModeStatus === "logic" || i(l).editorModeStatus === "both") && !t && ae(e), (i(l).editorModeStatus === "layout" || i(l).editorModeStatus === "both") && /* @__PURE__ */ c(v, {
      children: [/* @__PURE__ */ V(s, {
        name: d.style,
        children: e.style.getPropertyView()
      }), /* @__PURE__ */ V(s, {
        name: d.labelStyle,
        children: e.labelStyle.getPropertyView()
      }), /* @__PURE__ */ V(s, {
        name: d.inputFieldStyle,
        children: e.inputFieldStyle.getPropertyView()
      }), /* @__PURE__ */ V(s, {
        name: d.animationStyle,
        hasTooltip: !0,
        children: e.animationStyle.getPropertyView()
      })]
    })]
  });
}).setExposeMethodConfigs(Y).build(), Ue = $(qe, Se);
function je(e) {
  if (!e)
    return e;
  let {
    defaultStart: t,
    defaultEnd: a
  } = e;
  return e.start && !e.defaultStart && (t = e.start), e.end && !e.defaultEnd && (a = e.end), {
    ...e,
    defaultStart: t,
    defaultEnd: a,
    start: "",
    end: ""
  };
}
let We = function() {
  const e = {
    defaultStart: w("defaultStart"),
    start: w("start"),
    defaultEnd: w("defaultEnd"),
    end: w("end"),
    userRangeTimeZone: w("userRangeTimeZone", Intl.DateTimeFormat().resolvedOptions().timeZone),
    ...q,
    ...p
  };
  return new U(e, (t) => {
    const a = {
      ...t.defaultStart
    }.value, n = {
      ...t.start
    }.value, y = {
      ...t.defaultEnd
    }.value, h = {
      ...t.end
    }.value;
    let S = null;
    n !== "" && (S = r(n, m));
    let u = null;
    h !== "" && (u = r(h, m));
    const [R, ie] = K(S), [E, re] = K(u);
    b(() => {
      t.start.onChange(a);
    }, [a]), b(() => {
      t.end.onChange(y);
    }, [y]), b(() => {
      const g = n ? r(n, m) : null;
      ie(g);
    }, [n]), b(() => {
      const g = h ? r(h, m) : null;
      re(g);
    }, [h]);
    const se = /* @__PURE__ */ V(ze, {
      onClickDateRangeTimeZone: (g) => {
        t.userRangeTimeZone.onChange(g);
      },
      timeZone: t == null ? void 0 : t.timeZone,
      viewRef: t.viewRef,
      $style: t.inputFieldStyle,
      disabled: t.disabled,
      ...ee(t),
      start: R != null && R.isValid() ? R : null,
      end: E != null && E.isValid() ? E : null,
      minDate: t.minDate,
      maxDate: t.maxDate,
      placeholder: [t.placeholder, t.placeholder],
      disabledTime: () => Q(t.minTime, t.maxTime),
      onChange: (g, T) => {
        t.start.onChange(g && g.isValid() ? g.format(t.showTime ? C : x) : ""), t.end.onChange(T && T.isValid() ? T.format(t.showTime ? C : x) : ""), t.onEvent("change");
      },
      onPanelChange: (g, T) => {
        T[0] !== "date" && F("", t.start.onChange, z.noop), T[1] !== "date" && F("", t.end.onChange, z.noop);
      },
      onFocus: () => t.onEvent("focus"),
      onBlur: () => t.onEvent("blur"),
      suffixIcon: j(t.suffixIcon) && t.suffixIcon
    }), I = D({
      ...t,
      value: t.start
    }), O = D({
      ...t,
      value: t.end
    });
    return t.label({
      required: t.required,
      style: t.style,
      labelStyle: t.labelStyle,
      children: se,
      inputFieldStyle: t.inputFieldStyle,
      onMouseDown: (g) => g.stopPropagation(),
      showValidationWhenEmpty: t.showValidationWhenEmpty,
      ...I.validateStatus !== "success" ? I : O.validateStatus !== "success" ? O : I
    });
  }).setPropertyViewFn((t) => {
    const a = W();
    return /* @__PURE__ */ c(v, {
      children: [/* @__PURE__ */ c(s, {
        name: d.basic,
        children: [t.defaultStart.propertyView({
          label: o("date.start"),
          placeholder: "2022-04-07 21:39:59",
          tooltip: o("date.formatTip")
        }), t.defaultEnd.propertyView({
          label: o("date.end"),
          placeholder: "2022-04-07 21:39:59",
          tooltip: o("date.formatTip")
        }), t.timeZone.propertyView({
          label: o("prop.timeZone")
        })]
      }), /* @__PURE__ */ V(H, {
        ...t
      }), (i(l).editorModeStatus === "logic" || i(l).editorModeStatus === "both") && /* @__PURE__ */ c(v, {
        children: [/* @__PURE__ */ c(s, {
          name: d.validation,
          children: [N(t), t.showValidationWhenEmpty.propertyView({
            label: o("prop.showEmptyValidation")
          }), oe(t), ne(t), t.customRule.propertyView({})]
        }), /* @__PURE__ */ c(s, {
          name: d.interaction,
          children: [t.onEvent.getPropertyView(), _(t), L(t)]
        })]
      }), (i(l).editorModeStatus === "layout" || i(l).editorModeStatus === "both") && t.label.getPropertyView(), (i(l).editorModeStatus === "layout" || i(l).editorModeStatus === "both") && /* @__PURE__ */ c(s, {
        name: d.layout,
        children: [X({
          children: t
        }), t.placeholder.propertyView({
          label: o("date.placeholderText")
        })]
      }), (i(l).editorModeStatus === "logic" || i(l).editorModeStatus === "both") && /* @__PURE__ */ V(v, {
        children: /* @__PURE__ */ c(s, {
          name: d.advanced,
          children: [te(t, a), t.suffixIcon.propertyView({
            label: o("button.suffixIcon")
          })]
        })
      }), (i(l).editorModeStatus === "logic" || i(l).editorModeStatus === "both") && ae(t), (i(l).editorModeStatus === "layout" || i(l).editorModeStatus === "both") && /* @__PURE__ */ c(v, {
        children: [/* @__PURE__ */ V(s, {
          name: d.style,
          children: t.style.getPropertyView()
        }), /* @__PURE__ */ V(s, {
          name: d.labelStyle,
          children: t.labelStyle.getPropertyView()
        }), /* @__PURE__ */ V(s, {
          name: d.inputFieldStyle,
          children: t.inputFieldStyle.getPropertyView()
        })]
      })]
    });
  }).build();
}();
const He = $(We, je), le = (e, t) => {
  var S;
  const a = e === "UserChoice" ? t : e, y = r().tz(a).format("Z"), h = (S = new Intl.DateTimeFormat("en-US", {
    timeZone: a,
    timeZoneName: "short"
  }).formatToParts().find((u) => u.type === "timeZoneName")) == null ? void 0 : S.value;
  return {
    TimeZone: a,
    Offset: y,
    Name: h
  };
}, pe = G(Ue, [f({
  name: "value",
  desc: o("export.datePickerValueDesc"),
  depKeys: ["value", "showTime"],
  func: (e) => {
    const t = e.value ? r(e.value, m) : null;
    return t != null && t.isValid() ? t.format(e.showTime ? C : x) : null;
  }
}), f({
  name: "formattedValue",
  desc: o("export.datePickerFormattedValueDesc"),
  depKeys: ["value", "format", "timeZone", "userTimeZone"],
  func: (e) => {
    const t = e.value ? r(e.value, m) : null, a = e.timeZone === "UserChoice" ? e.userTimeZone : e.timeZone, n = t == null ? void 0 : t.clone().tz(a, !0);
    return t != null && t.isValid() ? !e.format || e.format.includes("Z") || e.format.includes("z") ? n == null ? void 0 : n.format(e == null ? void 0 : e.format) : t.format(e.format) : "";
  }
}), f({
  name: "timestamp",
  desc: o("export.datePickerTimestampDesc"),
  depKeys: ["value"],
  func: (e) => {
    const t = e.value ? r(e.value, m) : null;
    return t != null && t.isValid() ? t.unix() : "";
  }
}), f({
  name: "invalid",
  desc: o("export.invalidDesc"),
  depKeys: ["value", "required", "minTime", "maxTime", "minDate", "maxDate", "customRule"],
  func: (e) => D({
    ...e,
    value: {
      value: e.value
    }
  }).validateStatus !== "success"
}), f({
  name: "timeZone",
  desc: o("export.timeZoneDesc"),
  depKeys: ["timeZone", "userTimeZone"],
  func: (e) => le(e.timeZone, e.userTimeZone)
}), ...J]);
let k = G(He, [f({
  name: "start",
  desc: o("export.dateRangeStartDesc"),
  depKeys: ["start", "showTime"],
  func: (e) => {
    const t = e.start ? r(e.start, m) : null;
    return t != null && t.isValid() ? t.format(e.showTime ? C : x) : null;
  }
}), f({
  name: "end",
  desc: o("export.dateRangeEndDesc"),
  depKeys: ["end", "showTime"],
  func: (e) => {
    const t = e.end ? r(e.end, m) : null;
    return t != null && t.isValid() ? t.format(e.showTime ? C : x) : null;
  }
}), f({
  name: "startTimestamp",
  desc: o("export.dateRangeStartTimestampDesc"),
  depKeys: ["start"],
  func: (e) => {
    const t = e.start ? r(e.start, m) : null;
    return t != null && t.isValid() ? t.unix() : "";
  }
}), f({
  name: "endTimestamp",
  desc: o("export.dateRangeEndTimestampDesc"),
  depKeys: ["end"],
  func: (e) => {
    const t = e.end ? r(e.end, m) : null;
    return t != null && t.isValid() ? t.unix() : "";
  }
}), f({
  name: "formattedValue",
  desc: o("export.dateRangeFormattedValueDesc"),
  depKeys: ["start", "end", "format", "timeZone", "userRangeTimeZone"],
  func: (e) => {
    const t = e.start ? r(e.start, m) : null, a = e.end ? r(e.end, m) : null, n = e.timeZone === "UserChoice" ? e.userRangeTimeZone : e.timeZone, y = t == null ? void 0 : t.clone().tz(n, !0), h = a == null ? void 0 : a.clone().tz(n, !0);
    return [t != null && t.isValid() && (!e.format || e.format.includes("Z") || e.format.includes("z")) ? y == null ? void 0 : y.format(e == null ? void 0 : e.format) : t == null ? void 0 : t.format(e.format), a != null && a.isValid() && (!e.format || e.format.includes("Z") || e.format.includes("z")) ? h == null ? void 0 : h.format(e == null ? void 0 : e.format) : a == null ? void 0 : a.format(e.format)].filter((S) => S).join(" - ");
  }
}), f({
  name: "formattedStartValue",
  desc: o("export.dateRangeFormattedStartValueDesc"),
  depKeys: ["start", "format", "timeZone", "userRangeTimeZone"],
  func: (e) => {
    const t = e.start ? r(e.start, m) : null, a = e.timeZone === "UserChoice" ? e.userRangeTimeZone : e.timeZone, n = t == null ? void 0 : t.clone().tz(a, !0);
    return t != null && t.isValid() && (!e.format || e.format.includes("Z") || e.format.includes("z")) ? n == null ? void 0 : n.format(e == null ? void 0 : e.format) : t == null ? void 0 : t.format(e.format);
  }
}), f({
  name: "formattedEndValue",
  desc: o("export.dateRangeFormattedEndValueDesc"),
  depKeys: ["end", "format", "timeZone", "userRangeTimeZone"],
  func: (e) => {
    const t = e.end ? r(e.end, m) : null, a = e.timeZone === "UserChoice" ? e.userRangeTimeZone : e.timeZone, n = t == null ? void 0 : t.clone().tz(a, !0);
    return t != null && t.isValid() && (!e.format || e.format.includes("Z") || e.format.includes("z")) ? n == null ? void 0 : n.format(e == null ? void 0 : e.format) : t == null ? void 0 : t.format(e.format);
  }
}), f({
  name: "timeZone",
  desc: o("export.timeZoneDesc"),
  depKeys: ["timeZone", "userRangeTimeZone"],
  func: (e) => le(e.timeZone, e.userRangeTimeZone)
}), f({
  name: "invalid",
  desc: o("export.invalidDesc"),
  depKeys: ["start", "end", "required", "minTime", "maxTime", "minDate", "maxDate", "customRule"],
  func: (e) => D({
    ...e,
    value: {
      value: e.start
    }
  }).validateStatus !== "success" || D({
    ...e,
    value: {
      value: e.end
    }
  }).validateStatus !== "success"
}), ...J]);
k = we(k, [...Y, {
  method: {
    name: "clearAll",
    description: o("date.clearAllDesc"),
    params: []
  },
  execute: (e) => {
    e.children.start.getView().onChange(""), e.children.end.getView().onChange("");
  }
}, {
  method: {
    name: "resetAll",
    description: o("date.resetAllDesc"),
    params: []
  },
  execute: (e) => {
    e.children.start.getView().reset(), e.children.end.getView().reset();
  }
}, {
  method: {
    name: "setRange",
    params: []
  },
  execute: (e, t) => {
    if (t.length !== 1)
      return Promise.reject(o("formComp.valuesLengthError"));
    const a = t[0];
    if (typeof a != "object" || a === null || Array.isArray(a) || !a.hasOwnProperty("start") || !a.hasOwnProperty("end"))
      return Promise.reject(o("formComp.valueTypeError"));
    e.children.start.getView().onChange(a.start), e.children.end.getView().onChange(a.end);
  }
}]);
export {
  pe as DatePickerComp,
  k as DateRangeComp,
  Ue as datePickerControl,
  He as dateRangeControl,
  je as fixOldDateOrTimeRangeData
};
