import { P as ne, w as K, Y as o, S, bI as le, a2 as ie, O as D, c1 as M, Z as x, c2 as re, az as se, c3 as de, N as me, c4 as ce, a3 as ue, a4 as C, U as O, c5 as r, c6 as m, F as y, c7 as T, c8 as b, bU as U, c9 as k, a6 as u, G as g, a7 as s, a8 as d, af as n, ca as q, bJ as j, a9 as N, cb as W, aa as H, cc as f, bL as L, cd as fe, ce as ye, L as he, _ as ve, cf as we, cg as ge, ch as Ve, ci as Se, cj as Te, ck as be, cl as Ze, cm as F, cn as Ce, co as xe, cp as De } from "./603b75d9.js";
import { formDataChildren as _, FormDataPropertyView as $ } from "./f9847c56.js";
import { useState as I, useEffect as B, useContext as l } from "react";
import { disabledTime as G, handleDateChange as R, dateRefMethods as J } from "./3e83ebec.js";
import { DateUIView as Re } from "./5e877a2d.js";
import { DateRangeUIView as Pe } from "./38ce1504.js";
import { timeZoneOptions as Ee } from "./d09c8993.js";
import "react-dom";
import "./32abb214.js";
const Me = [Ce, xe, De], Fe = {
  showValidationWhenEmpty: D,
  required: D,
  minDate: S,
  maxDate: S,
  minTime: S,
  maxTime: S,
  customRule: ye
}, Y = {
  label: ne,
  placeholder: K(S, o("date.placeholder")),
  format: S,
  disabled: le,
  onEvent: ie(Me),
  showTime: D,
  use12Hours: D,
  hourStep: M.closed(1, 24, 1),
  minuteStep: M.closed(1, 60, 1),
  secondStep: M.closed(1, 60, 1),
  style: x(re, "style"),
  animationStyle: x(se, "animationStyle"),
  labelStyle: x(de.filter((e) => ["accent", "validate"].includes(e.name) === !1), "labelStyle"),
  suffixIcon: K(he, "/icon:regular/calendar"),
  ...Fe,
  viewRef: me,
  inputFieldStyle: x(ce, "inputFieldStyle"),
  timeZone: ue(Ee, Intl.DateTimeFormat().resolvedOptions().timeZone)
}, Q = (e) => ve.pick(e, "format", "showTime", "use12Hours", "hourStep", "minuteStep", "secondStep", "placeholder"), X = (e, t) => [e.showTime.propertyView({
  label: o("date.showTime")
}), !t && e.use12Hours.propertyView({
  label: o("prop.use12Hours")
})], p = (e, t = !0) => {
  if (t && e.showTime.getView())
    return /* @__PURE__ */ u(s, {
      name: d.advanced,
      children: [we(e), ge(e), Ve(e)]
    });
}, ee = (e, t = "date") => {
  if (t === "date")
    return [Se(e), Te(e)];
}, te = (e, t = "date") => {
  if (t === "date" && e.showTime.getView())
    return [be(e), Ze(e)];
};
function Z(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 Ie = {
  value: C("value"),
  userTimeZone: C("userTimeZone", Intl.DateTimeFormat().resolvedOptions().timeZone),
  ...Y,
  ..._
}, Be = new O(Ie, (e) => {
  let t = null;
  e.value.value !== "" && (t = r(e.value.value, m));
  const [a, i] = I(t);
  B(() => {
    const c = e.value.value ? r(e.value.value, m) : null;
    i(c);
  }, [e.value.value]);
  const h = (c) => {
    e.userTimeZone.onChange(c);
  };
  return e.label({
    required: e.required,
    style: e.style,
    labelStyle: e.labelStyle,
    inputFieldStyle: e.inputFieldStyle,
    animationStyle: e.animationStyle,
    onMouseDown: (c) => c.stopPropagation(),
    children: /* @__PURE__ */ y(Re, {
      onClickDateTimeZone: h,
      timeZone: e.timeZone,
      viewRef: e.viewRef,
      disabledTime: () => G(e.minTime, e.maxTime),
      $style: e.inputFieldStyle,
      disabled: e.disabled,
      ...Q(e),
      hourStep: e.hourStep,
      minDate: e.minDate,
      maxDate: e.maxDate,
      placeholder: e.placeholder,
      value: a != null && a.isValid() ? a : null,
      onChange: (c) => {
        R(c && c.isValid() ? c.format(e.showTime ? T : b) : "", e.value.onChange, e.onEvent);
      },
      onPanelChange: () => {
        R("", e.value.onChange, F.noop);
      },
      onFocus: () => e.onEvent("focus"),
      onBlur: () => e.onEvent("blur"),
      suffixIcon: U(e.suffixIcon) && e.suffixIcon
    }),
    showValidationWhenEmpty: e.showValidationWhenEmpty,
    ...Z(e)
  });
}).setPropertyViewFn((e) => {
  const t = k();
  return /* @__PURE__ */ u(g, {
    children: [/* @__PURE__ */ u(s, {
      name: d.basic,
      children: [e.value.propertyView({
        label: o("prop.defaultValue"),
        placeholder: "2022-04-07 21:39:59",
        tooltip: o("date.formatTip")
      }), e.timeZone.propertyView({
        label: o("prop.timeZone")
      })]
    }), /* @__PURE__ */ y($, {
      ...e
    }), (l(n).editorModeStatus === "logic" || l(n).editorModeStatus === "both") && /* @__PURE__ */ u(g, {
      children: [/* @__PURE__ */ u(s, {
        name: d.validation,
        children: [q(e), e.showValidationWhenEmpty.propertyView({
          label: o("prop.showEmptyValidation")
        }), ee(e), te(e), e.customRule.propertyView({})]
      }), /* @__PURE__ */ u(s, {
        name: d.interaction,
        children: [e.onEvent.getPropertyView(), j(e), N(e)]
      })]
    }), (l(n).editorModeStatus === "layout" || l(n).editorModeStatus === "both") && e.label.getPropertyView(), (l(n).editorModeStatus === "layout" || l(n).editorModeStatus === "both") && /* @__PURE__ */ u(s, {
      name: d.layout,
      children: [W({
        children: e
      }), e.placeholder.propertyView({
        label: o("date.placeholderText")
      })]
    }), (l(n).editorModeStatus === "logic" || l(n).editorModeStatus === "both") && /* @__PURE__ */ y(g, {
      children: /* @__PURE__ */ u(s, {
        name: d.advanced,
        children: [X(e, t), e.suffixIcon.propertyView({
          label: o("button.suffixIcon")
        })]
      })
    }), (l(n).editorModeStatus === "logic" || l(n).editorModeStatus === "both") && !t && p(e), (l(n).editorModeStatus === "layout" || l(n).editorModeStatus === "both") && /* @__PURE__ */ u(g, {
      children: [/* @__PURE__ */ y(s, {
        name: d.style,
        children: e.style.getPropertyView()
      }), /* @__PURE__ */ y(s, {
        name: d.labelStyle,
        children: e.labelStyle.getPropertyView()
      }), /* @__PURE__ */ y(s, {
        name: d.inputFieldStyle,
        children: e.inputFieldStyle.getPropertyView()
      }), /* @__PURE__ */ y(s, {
        name: d.animationStyle,
        hasTooltip: !0,
        children: e.animationStyle.getPropertyView()
      })]
    })]
  });
}).setExposeMethodConfigs(J).build(), ze = function() {
  const e = {
    start: C("start"),
    end: C("end"),
    userRangeTimeZone: C("userRangeTimeZone", Intl.DateTimeFormat().resolvedOptions().timeZone),
    ..._,
    ...Y
  };
  return new O(e, (t) => {
    let a = null;
    t.start.value !== "" && (a = r(t.start.value, m));
    let i = null;
    t.end.value !== "" && (i = r(t.end.value, m));
    const [h, c] = I(a), [w, P] = I(i);
    B(() => {
      const v = t.start.value ? r(t.start.value, m) : null;
      c(v);
    }, [t.start.value]), B(() => {
      const v = t.end.value ? r(t.end.value, m) : null;
      P(v);
    }, [t.end.value]);
    const oe = /* @__PURE__ */ y(Pe, {
      onClickDateRangeTimeZone: (v) => {
        t.userRangeTimeZone.onChange(v);
      },
      timeZone: t == null ? void 0 : t.timeZone,
      viewRef: t.viewRef,
      $style: t.inputFieldStyle,
      disabled: t.disabled,
      ...Q(t),
      start: h != null && h.isValid() ? h : null,
      end: w != null && w.isValid() ? w : null,
      minDate: t.minDate,
      maxDate: t.maxDate,
      placeholder: [t.placeholder, t.placeholder],
      disabledTime: () => G(t.minTime, t.maxTime),
      onChange: (v, V) => {
        t.start.onChange(v && v.isValid() ? v.format(t.showTime ? T : b) : ""), t.end.onChange(V && V.isValid() ? V.format(t.showTime ? T : b) : ""), t.onEvent("change");
      },
      onPanelChange: (v, V) => {
        V[0] !== "date" && R("", t.start.onChange, F.noop), V[1] !== "date" && R("", t.end.onChange, F.noop);
      },
      onFocus: () => t.onEvent("focus"),
      onBlur: () => t.onEvent("blur"),
      suffixIcon: U(t.suffixIcon) && t.suffixIcon
    }), E = Z({
      ...t,
      value: t.start
    }), z = Z({
      ...t,
      value: t.end
    });
    return t.label({
      required: t.required,
      style: t.style,
      labelStyle: t.labelStyle,
      children: oe,
      inputFieldStyle: t.inputFieldStyle,
      onMouseDown: (v) => v.stopPropagation(),
      showValidationWhenEmpty: t.showValidationWhenEmpty,
      ...E.validateStatus !== "success" ? E : z.validateStatus !== "success" ? z : E
    });
  }).setPropertyViewFn((t) => {
    const a = k();
    return /* @__PURE__ */ u(g, {
      children: [/* @__PURE__ */ u(s, {
        name: d.basic,
        children: [t.start.propertyView({
          label: o("date.start"),
          placeholder: "2022-04-07 21:39:59",
          tooltip: o("date.formatTip")
        }), t.end.propertyView({
          label: o("date.end"),
          placeholder: "2022-04-07 21:39:59",
          tooltip: o("date.formatTip")
        }), t.timeZone.propertyView({
          label: o("prop.timeZone")
        })]
      }), /* @__PURE__ */ y($, {
        ...t
      }), (l(n).editorModeStatus === "logic" || l(n).editorModeStatus === "both") && /* @__PURE__ */ u(g, {
        children: [/* @__PURE__ */ u(s, {
          name: d.validation,
          children: [q(t), t.showValidationWhenEmpty.propertyView({
            label: o("prop.showEmptyValidation")
          }), ee(t), te(t), t.customRule.propertyView({})]
        }), /* @__PURE__ */ u(s, {
          name: d.interaction,
          children: [t.onEvent.getPropertyView(), j(t), N(t)]
        })]
      }), (l(n).editorModeStatus === "layout" || l(n).editorModeStatus === "both") && t.label.getPropertyView(), (l(n).editorModeStatus === "layout" || l(n).editorModeStatus === "both") && /* @__PURE__ */ u(s, {
        name: d.layout,
        children: [W({
          children: t
        }), t.placeholder.propertyView({
          label: o("date.placeholderText")
        })]
      }), (l(n).editorModeStatus === "logic" || l(n).editorModeStatus === "both") && /* @__PURE__ */ y(g, {
        children: /* @__PURE__ */ u(s, {
          name: d.advanced,
          children: [X(t, a), t.suffixIcon.propertyView({
            label: o("button.suffixIcon")
          })]
        })
      }), (l(n).editorModeStatus === "logic" || l(n).editorModeStatus === "both") && p(t), (l(n).editorModeStatus === "layout" || l(n).editorModeStatus === "both") && /* @__PURE__ */ u(g, {
        children: [/* @__PURE__ */ y(s, {
          name: d.style,
          children: t.style.getPropertyView()
        }), /* @__PURE__ */ y(s, {
          name: d.labelStyle,
          children: t.labelStyle.getPropertyView()
        }), /* @__PURE__ */ y(s, {
          name: d.inputFieldStyle,
          children: t.inputFieldStyle.getPropertyView()
        })]
      })]
    });
  }).build();
}(), ae = (e, t) => {
  var w;
  const a = e === "UserChoice" ? t : e, h = r().tz(a).format("Z"), c = (w = new Intl.DateTimeFormat("en-US", {
    timeZone: a,
    timeZoneName: "short"
  }).formatToParts().find((P) => P.type === "timeZoneName")) == null ? void 0 : w.value;
  return {
    TimeZone: a,
    Offset: h,
    Name: c
  };
}, Le = H(Be, [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 ? T : b) : 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, i = t == null ? void 0 : t.clone().tz(a, !0);
    return t != null && t.isValid() ? !e.format || e.format.includes("Z") || e.format.includes("z") ? i == null ? void 0 : i.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) => Z({
    ...e,
    value: {
      value: e.value
    }
  }).validateStatus !== "success"
}), f({
  name: "timeZone",
  desc: o("export.timeZoneDesc"),
  depKeys: ["timeZone", "userTimeZone"],
  func: (e) => ae(e.timeZone, e.userTimeZone)
}), ...L]);
let A = H(ze, [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 ? T : b) : 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 ? T : b) : 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, i = e.timeZone === "UserChoice" ? e.userRangeTimeZone : e.timeZone, h = t == null ? void 0 : t.clone().tz(i, !0), c = a == null ? void 0 : a.clone().tz(i, !0);
    return [t != null && t.isValid() && (!e.format || e.format.includes("Z") || e.format.includes("z")) ? h == null ? void 0 : h.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")) ? c == null ? void 0 : c.format(e == null ? void 0 : e.format) : a == null ? void 0 : a.format(e.format)].filter((w) => w).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, i = t == null ? void 0 : t.clone().tz(a, !0);
    return t != null && t.isValid() && (!e.format || e.format.includes("Z") || e.format.includes("z")) ? i == null ? void 0 : i.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, i = t == null ? void 0 : t.clone().tz(a, !0);
    return t != null && t.isValid() && (!e.format || e.format.includes("Z") || e.format.includes("z")) ? i == null ? void 0 : i.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) => ae(e.timeZone, e.userRangeTimeZone)
}), f({
  name: "invalid",
  desc: o("export.invalidDesc"),
  depKeys: ["start", "end", "required", "minTime", "maxTime", "minDate", "maxDate", "customRule"],
  func: (e) => Z({
    ...e,
    value: {
      value: e.start
    }
  }).validateStatus !== "success" || Z({
    ...e,
    value: {
      value: e.end
    }
  }).validateStatus !== "success"
}), ...L]);
A = fe(A, [...J, {
  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 {
  Le as DatePickerComp,
  A as DateRangeComp,
  Be as datePickerControl,
  ze as dateRangeControl
};
