import { W as ne, w as B, a4 as o, X as R, bX as le, a9 as ie, V as E, ce as F, a5 as x, cf as re, aG as se, cg as me, ch as de, aa as ue, S as ce, ab as g, ci as q, U as A, cj as f, dT as S, H as y, dU as M, c5 as j, ad as d, I as Z, ae as r, af as s, co as W, am as l, cp as k, cA as H, cB as K, c0 as N, ag as L, c3 as X, cr as fe, ah as _, aj as I, cs as w, c1 as $, ct as ye, cu as Se, P as he, _ as Ve, cv as ge, cw as we, cx as ve, cD as Ze, cE as be, cF as Te } from "./56c67d3b.js";
import { useState as z, useEffect as v, useContext as i } from "react";
import { disabledTime as G, handleDateChange as Ce, dateRefMethods as J } from "./85fb0bcf.js";
import { TimeUIView as xe } from "./5f75d4d9.js";
import { TimeRangeUIView as Re } from "./9574b978.js";
import { timeZoneOptions as Ee } from "./381f866e.js";
import { fixOldDateOrTimeRangeData as Pe } from "./f146bb7b.js";
import "react-dom";
import "./4cac7a5d.js";
import "./d9000f33.js";
import "./3aa1b662.js";
const De = [Ze, be, Te], Fe = {
  showValidationWhenEmpty: E,
  required: E,
  minTime: R,
  maxTime: R,
  customRule: Se
}, Q = {
  label: ne,
  placeholder: B(R, o("time.placeholder")),
  format: R,
  disabled: le,
  onEvent: ie(De),
  showTime: E,
  use12Hours: E,
  hourStep: F.closed(1, 24, 1),
  minuteStep: F.closed(1, 60, 1),
  secondStep: F.closed(1, 60, 1),
  style: x(re, "style"),
  animationStyle: x(se, "animationStyle"),
  labelStyle: x(me.filter((e) => ["accent", "validate"].includes(e.name) === !1), "labelStyle"),
  inputFieldStyle: x(de, "inputFieldStyle"),
  suffixIcon: B(he, "/icon:regular/clock"),
  timeZone: ue(Ee, Intl.DateTimeFormat().resolvedOptions().timeZone),
  viewRef: ce,
  ...Fe
}, Y = (e) => Ve.pick(e, "format", "use12Hours", "minuteStep", "secondStep", "placeholder"), p = (e) => [ge(e), we(e), ve(e)];
function b(e) {
  if (e.customRule)
    return {
      validateStatus: "error",
      help: e.customRule
    };
  const t = f(e.value.value, S);
  return e.required && (!e.value.value || !t.isValid()) ? {
    validateStatus: "error",
    help: o("prop.required")
  } : {
    validateStatus: "success"
  };
}
const Me = {
  defaultValue: g("defaultValue"),
  value: g("value"),
  userTimeZone: g("userTimeZone", Intl.DateTimeFormat().resolvedOptions().timeZone),
  ...Q,
  ...q
}, Ie = new A(Me, (e) => {
  const t = {
    ...e.defaultValue
  }.value, a = {
    ...e.value
  }.value;
  let n = null;
  a !== "" && (n = f(a, S));
  const [m, c] = z(n);
  v(() => {
    e.value.onChange(t);
  }, [t]), v(() => {
    const u = a ? f(a, S) : null;
    c(u);
  }, [a]);
  const V = (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__ */ y(xe, {
      handleTimeZoneChange: V,
      timeZone: e == null ? void 0 : e.timeZone,
      viewRef: e.viewRef,
      $style: e.inputFieldStyle,
      disabled: e.disabled,
      value: m != null && m.isValid() ? m : null,
      disabledTime: () => G(e.minTime, e.maxTime),
      ...Y(e),
      hourStep: e.hourStep,
      minuteStep: e.minuteStep,
      secondStep: e.secondStep,
      placeholder: e.placeholder,
      onChange: (u) => {
        Ce(u && u.isValid() ? u.format(M) : "", e.value.onChange, e.onEvent);
      },
      onFocus: () => e.onEvent("focus"),
      onBlur: () => e.onEvent("blur"),
      suffixIcon: j(e.suffixIcon) && e.suffixIcon
    }),
    showValidationWhenEmpty: e.showValidationWhenEmpty,
    ...b(e)
  });
}).setPropertyViewFn((e) => /* @__PURE__ */ d(Z, {
  children: [/* @__PURE__ */ d(r, {
    name: s.basic,
    children: [e.defaultValue.propertyView({
      label: o("prop.defaultValue"),
      tooltip: o("time.formatTip")
    }), e.timeZone.propertyView({
      label: o("prop.timeZone")
    })]
  }), /* @__PURE__ */ y(W, {
    ...e
  }), (i(l).editorModeStatus === "logic" || i(l).editorModeStatus === "both") && /* @__PURE__ */ d(Z, {
    children: [/* @__PURE__ */ d(r, {
      name: s.validation,
      children: [k(e), e.showValidationWhenEmpty.propertyView({
        label: o("prop.showEmptyValidation")
      }), H(e), K(e), e.customRule.propertyView({})]
    }), /* @__PURE__ */ d(r, {
      name: s.interaction,
      children: [e.onEvent.getPropertyView(), N(e), L(e)]
    })]
  }), (i(l).editorModeStatus === "layout" || i(l).editorModeStatus === "both") && e.label.getPropertyView(), (i(l).editorModeStatus === "layout" || i(l).editorModeStatus === "both") && /* @__PURE__ */ d(r, {
    name: s.layout,
    children: [e.format.propertyView({
      label: o("time.format")
    }), e.placeholder.propertyView({
      label: o("time.placeholderText")
    })]
  }), (i(l).editorModeStatus === "logic" || i(l).editorModeStatus === "both") && /* @__PURE__ */ d(r, {
    name: s.advanced,
    children: [p(e), e.use12Hours.propertyView({
      label: o("prop.use12Hours")
    }), e.suffixIcon.propertyView({
      label: o("button.suffixIcon")
    })]
  }), (i(l).editorModeStatus === "layout" || i(l).editorModeStatus === "both") && /* @__PURE__ */ d(Z, {
    children: [/* @__PURE__ */ y(r, {
      name: s.style,
      children: e.style.getPropertyView()
    }), /* @__PURE__ */ y(r, {
      name: s.labelStyle,
      children: e.labelStyle.getPropertyView()
    }), /* @__PURE__ */ y(r, {
      name: s.inputFieldStyle,
      children: e.inputFieldStyle.getPropertyView()
    }), /* @__PURE__ */ y(r, {
      name: s.animationStyle,
      hasTooltip: !0,
      children: e.animationStyle.getPropertyView()
    })]
  })]
})).setExposeMethodConfigs(J).build(), ze = X(Ie, fe), Oe = function() {
  const e = {
    defaultStart: g("defaultStart"),
    start: g("start"),
    defaultEnd: g("defaultEnd"),
    end: g("end"),
    userRangeTimeZone: g("userRangeTimeZone", Intl.DateTimeFormat().resolvedOptions().timeZone),
    ...q,
    ...Q
  };
  return new A(e, (t) => {
    const a = {
      ...t.defaultStart
    }.value, n = {
      ...t.start
    }.value, m = {
      ...t.defaultEnd
    }.value, c = {
      ...t.end
    }.value;
    let V = null;
    n !== "" && (V = f(n, S));
    let u = null;
    c !== "" && (u = f(c, S));
    const [T, te] = z(V), [C, ae] = z(u);
    v(() => {
      t.start.onChange(a);
    }, [a]), v(() => {
      t.end.onChange(m);
    }, [m]), v(() => {
      const h = n ? f(n, S) : null;
      te(h);
    }, [n]), v(() => {
      const h = c ? f(c, S) : null;
      ae(h);
    }, [c]);
    const oe = /* @__PURE__ */ y(Re, {
      handleTimeRangeZoneChange: (h) => {
        t.userRangeTimeZone.onChange(h);
      },
      timeZone: t == null ? void 0 : t.timeZone,
      viewRef: t.viewRef,
      $style: t.inputFieldStyle,
      disabled: t.disabled,
      start: T != null && T.isValid() ? T : null,
      end: C != null && C.isValid() ? C : null,
      disabledTime: () => G(t.minTime, t.maxTime),
      ...Y(t),
      hourStep: t.hourStep,
      minuteStep: t.minuteStep,
      secondStep: t.secondStep,
      placeholder: [t.placeholder, t.placeholder],
      onChange: (h, D) => {
        t.start.onChange(h && h.isValid() ? h.format(M) : ""), t.end.onChange(D && D.isValid() ? D.format(M) : ""), t.onEvent("change");
      },
      onFocus: () => t.onEvent("focus"),
      onBlur: () => t.onEvent("blur"),
      suffixIcon: j(t.suffixIcon) && t.suffixIcon
    }), P = b({
      ...t,
      value: t.start
    }), O = b({
      ...t,
      value: t.end
    });
    return t.label({
      required: t.required,
      style: t.style,
      labelStyle: t.labelStyle,
      inputFieldStyle: t.inputFieldStyle,
      animationStyle: t.animationStyle,
      children: oe,
      onMouseDown: (h) => h.stopPropagation(),
      showValidationWhenEmpty: t.showValidationWhenEmpty,
      ...P.validateStatus !== "success" ? P : O.validateStatus !== "success" ? O : P
    });
  }).setPropertyViewFn((t) => /* @__PURE__ */ d(Z, {
    children: [/* @__PURE__ */ d(r, {
      name: s.basic,
      children: [t.defaultStart.propertyView({
        label: o("time.start"),
        tooltip: o("time.formatTip")
      }), t.defaultEnd.propertyView({
        label: o("time.end"),
        tooltip: o("time.formatTip")
      }), t.timeZone.propertyView({
        label: o("prop.timeZone")
      })]
    }), /* @__PURE__ */ y(W, {
      ...t
    }), (i(l).editorModeStatus === "logic" || i(l).editorModeStatus === "both") && /* @__PURE__ */ d(Z, {
      children: [/* @__PURE__ */ d(r, {
        name: s.validation,
        children: [k(t), t.showValidationWhenEmpty.propertyView({
          label: o("prop.showEmptyValidation")
        }), H(t), K(t), t.customRule.propertyView({})]
      }), /* @__PURE__ */ d(r, {
        name: s.interaction,
        children: [t.onEvent.getPropertyView(), N(t), L(t)]
      })]
    }), (i(l).editorModeStatus === "layout" || i(l).editorModeStatus === "both") && t.label.getPropertyView(), (i(l).editorModeStatus === "layout" || i(l).editorModeStatus === "both") && /* @__PURE__ */ d(r, {
      name: s.layout,
      children: [t.format.propertyView({
        label: o("time.format")
      }), t.placeholder.propertyView({
        label: o("time.placeholderText")
      })]
    }), (i(l).editorModeStatus === "logic" || i(l).editorModeStatus === "both") && /* @__PURE__ */ d(r, {
      name: s.advanced,
      children: [p(t), t.use12Hours.propertyView({
        label: o("prop.use12Hours")
      }), t.suffixIcon.propertyView({
        label: o("button.suffixIcon")
      })]
    }), (i(l).editorModeStatus === "layout" || i(l).editorModeStatus === "both") && /* @__PURE__ */ d(Z, {
      children: [/* @__PURE__ */ y(r, {
        name: s.style,
        children: t.style.getPropertyView()
      }), /* @__PURE__ */ y(r, {
        name: s.labelStyle,
        children: t.labelStyle.getPropertyView()
      }), /* @__PURE__ */ y(r, {
        name: s.inputFieldStyle,
        children: t.inputFieldStyle.getPropertyView()
      }), /* @__PURE__ */ y(r, {
        name: s.animationStyle,
        hasTooltip: !0,
        children: t.animationStyle.getPropertyView()
      })]
    })]
  })).build();
}(), Be = X(Oe, Pe), ee = (e, t) => {
  var V;
  const a = e === "UserChoice" ? t : e, m = f().tz(a).format("Z"), c = (V = new Intl.DateTimeFormat("en-US", {
    timeZone: a,
    timeZoneName: "short"
  }).formatToParts().find((u) => u.type === "timeZoneName")) == null ? void 0 : V.value;
  return {
    TimeZone: a,
    Offset: m,
    Name: c
  };
}, $e = _(ze, [new I("value", o("export.timePickerValueDesc")), w({
  name: "formattedValue",
  desc: o("export.timePickerFormattedValueDesc"),
  depKeys: ["value", "format", "timeZone", "userTimeZone"],
  func: (e) => {
    const t = e.value ? f(e.value, S) : null, a = e.timeZone === "UserChoice" ? e.userTimeZone : e.timeZone, n = t == null ? void 0 : t.clone().tz(a, !0), m = n == null ? void 0 : n.format(e == null ? void 0 : e.format);
    return t != null && t.isValid() ? !e.format || e.format.includes("Z") || e.format.includes("z") ? m : t.format(e.format) : "";
  }
}), w({
  name: "timeZone",
  desc: o("export.timeZoneDesc"),
  depKeys: ["timeZone", "userTimeZone"],
  func: (e) => ee(e.timeZone, e.userTimeZone)
}), w({
  name: "invalid",
  desc: o("export.invalidDesc"),
  depKeys: ["value", "required", "minTime", "maxTime", "customRule"],
  func: (e) => b({
    ...e,
    value: {
      value: e.value
    }
  }).validateStatus !== "success"
}), ...$]);
let U = _(Be, [new I("start", o("export.timeRangeStartDesc")), new I("end", o("export.timeRangeEndDesc")), w({
  name: "formattedValue",
  desc: o("export.timeRangeFormattedValueDesc"),
  depKeys: ["start", "end", "format", "timeZone", "userRangeTimeZone"],
  func: (e) => {
    const t = e.start ? f(e.start, S) : null, a = e.end ? f(e.end, S) : null, n = e.timeZone === "UserChoice" ? e.userRangeTimeZone : e.timeZone, m = t == null ? void 0 : t.clone().tz(n, !0), c = a == null ? void 0 : a.clone().tz(n, !0);
    return [t != null && t.isValid() && (!e.format || e.format.includes("Z") || e.format.includes("z")) ? m == null ? void 0 : m.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((V) => V).join(" - ");
  }
}), w({
  name: "formattedStartValue",
  desc: o("export.timeRangeFormattedStartValueDesc"),
  depKeys: ["start", "format", "timeZone", "userRangeTimeZone"],
  func: (e) => {
    const t = e.start ? f(e.start, S) : null, a = e.timeZone === "UserChoice" ? e.userRangeTimeZone : e.timeZone, n = t == null ? void 0 : t.clone().tz(a, !0), m = n == null ? void 0 : n.format(e == null ? void 0 : e.format);
    return t != null && t.isValid() && (!e.format || e.format.includes("Z") || e.format.includes("z")) ? m : t == null ? void 0 : t.format(e.format);
  }
}), w({
  name: "formattedEndValue",
  desc: o("export.timeRangeFormattedEndValueDesc"),
  depKeys: ["end", "format", "timeZone", "userRangeTimeZone"],
  func: (e) => {
    const t = e.end ? f(e.end, S) : 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);
  }
}), w({
  name: "timeZone",
  desc: o("export.timeZoneDesc"),
  depKeys: ["timeZone", "userRangeTimeZone"],
  func: (e) => ee(e.timeZone, e.userRangeTimeZone)
}), w({
  name: "invalid",
  desc: o("export.invalidDesc"),
  depKeys: ["start", "end", "required", "minTime", "maxTime", "customRule"],
  func: (e) => b({
    ...e,
    value: {
      value: e.start
    }
  }).validateStatus !== "success" || b({
    ...e,
    value: {
      value: e.end
    }
  }).validateStatus !== "success"
}), ...$]);
U = ye(U, [...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 {
  $e as TimePickerComp,
  U as TimeRangeComp,
  ze as timePickerControl,
  Be as timeRangeControl
};
