import { P as p, w as z, Y as o, S as b, bI as ee, a2 as te, O as T, c1 as P, Z, c2 as ae, az as oe, c3 as le, c4 as ne, a3 as ie, N as re, a4 as w, U, c5 as c, dK as y, F as f, dL as E, bU as q, a6 as u, G as g, a7 as r, a8 as s, af as n, ca as O, ck as A, cl as K, bJ as k, a9 as N, aa as W, ac as F, cc as h, bL as j, cd as se, ce as me, L as de, _ as ue, cf as ce, cg as fe, ch as ye, cn as Se, co as ve, cp as he } from "./603b75d9.js";
import { formDataChildren as H, FormDataPropertyView as L } from "./f9847c56.js";
import { useState as M, useEffect as D, useContext as i } from "react";
import { disabledTime as _, handleDateChange as ge, dateRefMethods as $ } from "./3e83ebec.js";
import { TimeUIView as Ve } from "./da47580c.js";
import { TimeRangeUIView as we } from "./aec4efa8.js";
import { timeZoneOptions as Ze } from "./d09c8993.js";
import "react-dom";
import "./32abb214.js";
const be = [Se, ve, he], Te = {
  showValidationWhenEmpty: T,
  required: T,
  minTime: b,
  maxTime: b,
  customRule: me
}, G = {
  label: p,
  placeholder: z(b, o("time.placeholder")),
  format: b,
  disabled: ee,
  onEvent: te(be),
  showTime: T,
  use12Hours: T,
  hourStep: P.closed(1, 24, 1),
  minuteStep: P.closed(1, 60, 1),
  secondStep: P.closed(1, 60, 1),
  style: Z(ae, "style"),
  animationStyle: Z(oe, "animationStyle"),
  labelStyle: Z(le.filter((e) => ["accent", "validate"].includes(e.name) === !1), "labelStyle"),
  inputFieldStyle: Z(ne, "inputFieldStyle"),
  suffixIcon: z(de, "/icon:regular/clock"),
  timeZone: ie(Ze, Intl.DateTimeFormat().resolvedOptions().timeZone),
  viewRef: re,
  ...Te
}, J = (e) => ue.pick(e, "format", "use12Hours", "minuteStep", "secondStep", "placeholder"), Y = (e) => [ce(e), fe(e), ye(e)];
function V(e) {
  if (e.customRule)
    return {
      validateStatus: "error",
      help: e.customRule
    };
  const t = c(e.value.value, y);
  return e.required && (!e.value.value || !t.isValid()) ? {
    validateStatus: "error",
    help: o("prop.required")
  } : {
    validateStatus: "success"
  };
}
const Ce = {
  value: w("value"),
  userTimeZone: w("userTimeZone", Intl.DateTimeFormat().resolvedOptions().timeZone),
  ...G,
  ...H
}, xe = new U(Ce, (e) => {
  let t = null;
  e.value.value !== "" && (t = c(e.value.value, y));
  const [a, l] = M(t);
  D(() => {
    const m = e.value.value ? c(e.value.value, y) : null;
    l(m);
  }, [e.value.value]);
  const d = (m) => {
    e.userTimeZone.onChange(m);
  };
  return e.label({
    required: e.required,
    style: e.style,
    labelStyle: e.labelStyle,
    inputFieldStyle: e.inputFieldStyle,
    animationStyle: e.animationStyle,
    onMouseDown: (m) => m.stopPropagation(),
    children: /* @__PURE__ */ f(Ve, {
      handleTimeZoneChange: d,
      timeZone: e == null ? void 0 : e.timeZone,
      viewRef: e.viewRef,
      $style: e.inputFieldStyle,
      disabled: e.disabled,
      value: a != null && a.isValid() ? a : null,
      disabledTime: () => _(e.minTime, e.maxTime),
      ...J(e),
      hourStep: e.hourStep,
      minuteStep: e.minuteStep,
      secondStep: e.secondStep,
      placeholder: e.placeholder,
      onChange: (m) => {
        ge(m && m.isValid() ? m.format(E) : "", e.value.onChange, e.onEvent);
      },
      onFocus: () => e.onEvent("focus"),
      onBlur: () => e.onEvent("blur"),
      suffixIcon: q(e.suffixIcon) && e.suffixIcon
    }),
    showValidationWhenEmpty: e.showValidationWhenEmpty,
    ...V(e)
  });
}).setPropertyViewFn((e) => /* @__PURE__ */ u(g, {
  children: [/* @__PURE__ */ u(r, {
    name: s.basic,
    children: [e.value.propertyView({
      label: o("prop.defaultValue"),
      tooltip: o("time.formatTip")
    }), e.timeZone.propertyView({
      label: o("prop.timeZone")
    })]
  }), /* @__PURE__ */ f(L, {
    ...e
  }), (i(n).editorModeStatus === "logic" || i(n).editorModeStatus === "both") && /* @__PURE__ */ u(g, {
    children: [/* @__PURE__ */ u(r, {
      name: s.validation,
      children: [O(e), e.showValidationWhenEmpty.propertyView({
        label: o("prop.showEmptyValidation")
      }), A(e), K(e), e.customRule.propertyView({})]
    }), /* @__PURE__ */ u(r, {
      name: s.interaction,
      children: [e.onEvent.getPropertyView(), k(e), N(e)]
    })]
  }), (i(n).editorModeStatus === "layout" || i(n).editorModeStatus === "both") && e.label.getPropertyView(), (i(n).editorModeStatus === "layout" || i(n).editorModeStatus === "both") && /* @__PURE__ */ u(r, {
    name: s.layout,
    children: [e.format.propertyView({
      label: o("time.format")
    }), e.placeholder.propertyView({
      label: o("time.placeholderText")
    })]
  }), (i(n).editorModeStatus === "logic" || i(n).editorModeStatus === "both") && /* @__PURE__ */ u(r, {
    name: s.advanced,
    children: [Y(e), e.use12Hours.propertyView({
      label: o("prop.use12Hours")
    }), e.suffixIcon.propertyView({
      label: o("button.suffixIcon")
    })]
  }), (i(n).editorModeStatus === "layout" || i(n).editorModeStatus === "both") && /* @__PURE__ */ u(g, {
    children: [/* @__PURE__ */ f(r, {
      name: s.style,
      children: e.style.getPropertyView()
    }), /* @__PURE__ */ f(r, {
      name: s.labelStyle,
      children: e.labelStyle.getPropertyView()
    }), /* @__PURE__ */ f(r, {
      name: s.inputFieldStyle,
      children: e.inputFieldStyle.getPropertyView()
    }), /* @__PURE__ */ f(r, {
      name: s.animationStyle,
      hasTooltip: !0,
      children: e.animationStyle.getPropertyView()
    })]
  })]
})).setExposeMethodConfigs($).build(), Re = function() {
  const e = {
    start: w("start"),
    end: w("end"),
    userRangeTimeZone: w("userRangeTimeZone", Intl.DateTimeFormat().resolvedOptions().timeZone),
    ...H,
    ...G
  };
  return new U(e, (t) => {
    let a = null;
    t.start.value !== "" && (a = c(t.start.value, y));
    let l = null;
    t.end.value !== "" && (l = c(t.end.value, y));
    const [d, m] = M(a), [v, C] = M(l);
    D(() => {
      const S = t.start.value ? c(t.start.value, y) : null;
      m(S);
    }, [t.start.value]), D(() => {
      const S = t.end.value ? c(t.end.value, y) : null;
      C(S);
    }, [t.end.value]);
    const X = /* @__PURE__ */ f(we, {
      handleTimeRangeZoneChange: (S) => {
        t.userRangeTimeZone.onChange(S);
      },
      timeZone: t == null ? void 0 : t.timeZone,
      viewRef: t.viewRef,
      $style: t.inputFieldStyle,
      disabled: t.disabled,
      start: d != null && d.isValid() ? d : null,
      end: v != null && v.isValid() ? v : null,
      disabledTime: () => _(t.minTime, t.maxTime),
      ...J(t),
      hourStep: t.hourStep,
      minuteStep: t.minuteStep,
      secondStep: t.secondStep,
      placeholder: [t.placeholder, t.placeholder],
      onChange: (S, R) => {
        t.start.onChange(S && S.isValid() ? S.format(E) : ""), t.end.onChange(R && R.isValid() ? R.format(E) : ""), t.onEvent("change");
      },
      onFocus: () => t.onEvent("focus"),
      onBlur: () => t.onEvent("blur"),
      suffixIcon: q(t.suffixIcon) && t.suffixIcon
    }), x = V({
      ...t,
      value: t.start
    }), I = V({
      ...t,
      value: t.end
    });
    return t.label({
      required: t.required,
      style: t.style,
      labelStyle: t.labelStyle,
      inputFieldStyle: t.inputFieldStyle,
      animationStyle: t.animationStyle,
      children: X,
      onMouseDown: (S) => S.stopPropagation(),
      showValidationWhenEmpty: t.showValidationWhenEmpty,
      ...x.validateStatus !== "success" ? x : I.validateStatus !== "success" ? I : x
    });
  }).setPropertyViewFn((t) => /* @__PURE__ */ u(g, {
    children: [/* @__PURE__ */ u(r, {
      name: s.basic,
      children: [t.start.propertyView({
        label: o("time.start"),
        tooltip: o("time.formatTip")
      }), t.end.propertyView({
        label: o("time.end"),
        tooltip: o("time.formatTip")
      }), t.timeZone.propertyView({
        label: o("prop.timeZone")
      })]
    }), /* @__PURE__ */ f(L, {
      ...t
    }), (i(n).editorModeStatus === "logic" || i(n).editorModeStatus === "both") && /* @__PURE__ */ u(g, {
      children: [/* @__PURE__ */ u(r, {
        name: s.validation,
        children: [O(t), t.showValidationWhenEmpty.propertyView({
          label: o("prop.showEmptyValidation")
        }), A(t), K(t), t.customRule.propertyView({})]
      }), /* @__PURE__ */ u(r, {
        name: s.interaction,
        children: [t.onEvent.getPropertyView(), k(t), N(t)]
      })]
    }), (i(n).editorModeStatus === "layout" || i(n).editorModeStatus === "both") && t.label.getPropertyView(), (i(n).editorModeStatus === "layout" || i(n).editorModeStatus === "both") && /* @__PURE__ */ u(r, {
      name: s.layout,
      children: [t.format.propertyView({
        label: o("time.format")
      }), t.placeholder.propertyView({
        label: o("time.placeholderText")
      })]
    }), (i(n).editorModeStatus === "logic" || i(n).editorModeStatus === "both") && /* @__PURE__ */ u(r, {
      name: s.advanced,
      children: [Y(t), t.use12Hours.propertyView({
        label: o("prop.use12Hours")
      }), t.suffixIcon.propertyView({
        label: o("button.suffixIcon")
      })]
    }), (i(n).editorModeStatus === "layout" || i(n).editorModeStatus === "both") && /* @__PURE__ */ u(g, {
      children: [/* @__PURE__ */ f(r, {
        name: s.style,
        children: t.style.getPropertyView()
      }), /* @__PURE__ */ f(r, {
        name: s.labelStyle,
        children: t.labelStyle.getPropertyView()
      }), /* @__PURE__ */ f(r, {
        name: s.inputFieldStyle,
        children: t.inputFieldStyle.getPropertyView()
      }), /* @__PURE__ */ f(r, {
        name: s.animationStyle,
        hasTooltip: !0,
        children: t.animationStyle.getPropertyView()
      })]
    })]
  })).build();
}(), Q = (e, t) => {
  var v;
  const a = e === "UserChoice" ? t : e, d = c().tz(a).format("Z"), m = (v = new Intl.DateTimeFormat("en-US", {
    timeZone: a,
    timeZoneName: "short"
  }).formatToParts().find((C) => C.type === "timeZoneName")) == null ? void 0 : v.value;
  return {
    TimeZone: a,
    Offset: d,
    Name: m
  };
}, Oe = W(xe, [new F("value", o("export.timePickerValueDesc")), h({
  name: "formattedValue",
  desc: o("export.timePickerFormattedValueDesc"),
  depKeys: ["value", "format", "timeZone", "userTimeZone"],
  func: (e) => {
    const t = e.value ? c(e.value, y) : null, a = e.timeZone === "UserChoice" ? e.userTimeZone : e.timeZone, l = t == null ? void 0 : t.clone().tz(a, !0), d = l == null ? void 0 : l.format(e == null ? void 0 : e.format);
    return t != null && t.isValid() ? !e.format || e.format.includes("Z") || e.format.includes("z") ? d : t.format(e.format) : "";
  }
}), h({
  name: "timeZone",
  desc: o("export.timeZoneDesc"),
  depKeys: ["timeZone", "userTimeZone"],
  func: (e) => Q(e.timeZone, e.userTimeZone)
}), h({
  name: "invalid",
  desc: o("export.invalidDesc"),
  depKeys: ["value", "required", "minTime", "maxTime", "customRule"],
  func: (e) => V({
    ...e,
    value: {
      value: e.value
    }
  }).validateStatus !== "success"
}), ...j]);
let B = W(Re, [new F("start", o("export.timeRangeStartDesc")), new F("end", o("export.timeRangeEndDesc")), h({
  name: "formattedValue",
  desc: o("export.timeRangeFormattedValueDesc"),
  depKeys: ["start", "end", "format", "timeZone", "userRangeTimeZone"],
  func: (e) => {
    const t = e.start ? c(e.start, y) : null, a = e.end ? c(e.end, y) : null, l = e.timeZone === "UserChoice" ? e.userRangeTimeZone : e.timeZone, d = t == null ? void 0 : t.clone().tz(l, !0), m = a == null ? void 0 : a.clone().tz(l, !0);
    return [t != null && t.isValid() && (!e.format || e.format.includes("Z") || e.format.includes("z")) ? d == null ? void 0 : d.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")) ? m == null ? void 0 : m.format(e == null ? void 0 : e.format) : a == null ? void 0 : a.format(e.format)].filter((v) => v).join(" - ");
  }
}), h({
  name: "formattedStartValue",
  desc: o("export.timeRangeFormattedStartValueDesc"),
  depKeys: ["start", "format", "timeZone", "userRangeTimeZone"],
  func: (e) => {
    const t = e.start ? c(e.start, y) : null, a = e.timeZone === "UserChoice" ? e.userRangeTimeZone : e.timeZone, l = t == null ? void 0 : t.clone().tz(a, !0), d = l == null ? void 0 : l.format(e == null ? void 0 : e.format);
    return t != null && t.isValid() && (!e.format || e.format.includes("Z") || e.format.includes("z")) ? d : t == null ? void 0 : t.format(e.format);
  }
}), h({
  name: "formattedEndValue",
  desc: o("export.timeRangeFormattedEndValueDesc"),
  depKeys: ["end", "format", "timeZone", "userRangeTimeZone"],
  func: (e) => {
    const t = e.end ? c(e.end, y) : null, a = e.timeZone === "UserChoice" ? e.userRangeTimeZone : e.timeZone, l = t == null ? void 0 : t.clone().tz(a, !0);
    return t != null && t.isValid() && (!e.format || e.format.includes("Z") || e.format.includes("z")) ? l == null ? void 0 : l.format(e == null ? void 0 : e.format) : t == null ? void 0 : t.format(e.format);
  }
}), h({
  name: "timeZone",
  desc: o("export.timeZoneDesc"),
  depKeys: ["timeZone", "userRangeTimeZone"],
  func: (e) => Q(e.timeZone, e.userRangeTimeZone)
}), h({
  name: "invalid",
  desc: o("export.invalidDesc"),
  depKeys: ["start", "end", "required", "minTime", "maxTime", "customRule"],
  func: (e) => V({
    ...e,
    value: {
      value: e.start
    }
  }).validateStatus !== "success" || V({
    ...e,
    value: {
      value: e.end
    }
  }).validateStatus !== "success"
}), ...j]);
B = se(B, [...$, {
  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 {
  Oe as TimePickerComp,
  B as TimeRangeComp,
  xe as timePickerControl,
  Re as timeRangeControl
};
