import { defineComponent as R, toRefs as O, computed as t, resolveComponent as w, createElementBlock as j, openBlock as d, normalizeClass as A, unref as o, createBlock as r, createCommentVNode as m, createElementVNode as F, mergeProps as G, withCtx as x, renderSlot as J, normalizeProps as K, guardReactiveProps as Q, createTextVNode as y, toDisplayString as B, nextTick as W } from "vue";
import { B as X, z as Y, C as Z, M as ee, _ as le } from "./install-DJFUeaKV.js";
const ae = { class: "wt-timepicker__wrapper" }, c = 3600, M = 60, te = /* @__PURE__ */ R({
  __name: "wt-timepicker",
  props: {
    modelValue: { default: 0 },
    dateMode: { type: Boolean, default: !1 },
    label: { default: "" },
    format: { default: "hh:mm:ss" },
    disabled: { type: Boolean, default: !1 },
    labelProps: { default: () => ({}) },
    noLabel: { type: Boolean, default: !1 },
    required: { type: Boolean, default: !1 },
    v: { default: null },
    regleValidation: { default: null },
    customValidators: { default: () => [] },
    noMaxHours: { type: Boolean, default: !1 }
  },
  emits: ["update:modelValue"],
  setup(u, { emit: S }) {
    const e = u, s = S, { t: b } = X(), { v, customValidators: C, regleValidation: H } = O(e), { isValidation: _, invalid: k, validationText: g, validationTextColor: h } = Y({
      v,
      customValidators: C,
      regleValidation: H
    }), I = t(() => e.format.includes("hh")), D = t(() => e.format.includes("mm")), L = t(() => e.format.includes("ss")), U = t(() => e.noMaxHours || e.dateMode ? null : 23), z = t(() => e.noLabel || e.label ? null : b("webitelUI.timepicker.hour")), E = t(() => e.noLabel || e.label ? null : b("webitelUI.timepicker.min")), N = t(() => e.noLabel || e.label ? null : b("webitelUI.timepicker.sec")), n = t({
      get() {
        return e.dateMode ? (/* @__PURE__ */ new Date(+e.modelValue)).getHours() : Math.floor(+e.modelValue / c);
      },
      set(l) {
        const a = e.dateMode ? (/* @__PURE__ */ new Date(+e.modelValue)).setHours(l) : +e.modelValue - n.value * c + l * c;
        s("update:modelValue", a);
      }
    }), f = t({
      get() {
        return e.dateMode ? (/* @__PURE__ */ new Date(+e.modelValue)).getMinutes() : Math.floor(+e.modelValue / M % 60);
      },
      set(l) {
        const a = e.dateMode ? (/* @__PURE__ */ new Date(+e.modelValue)).setMinutes(l) : +e.modelValue - f.value * M + l * M;
        s("update:modelValue", a);
      }
    }), p = t({
      get() {
        return e.dateMode ? (/* @__PURE__ */ new Date(+e.modelValue)).getSeconds() : Math.floor(+e.modelValue % 60);
      },
      set(l) {
        const a = e.dateMode ? (/* @__PURE__ */ new Date(+e.modelValue)).setSeconds(l) : +e.modelValue - p.value + +l;
        s("update:modelValue", a);
      }
    }), P = t(() => e.required ? `${e.label} (${e.format})*` : `${e.label} (${e.format})`), T = () => {
      const l = e.dateMode ? (/* @__PURE__ */ new Date(+e.modelValue)).setHours(n.value) : +e.modelValue - n.value * c + n.value * c;
      s("update:modelValue", 0), W(() => {
        s("update:modelValue", l);
      });
    };
    return (l, a) => {
      const $ = w("wt-label"), V = w("wt-time-input"), q = w("wt-message");
      return d(), j("div", {
        class: A([{ "wt-timepicker--invalid": o(k) }, "wt-timepicker"])
      }, [
        u.label || !u.noLabel ? (d(), r($, G({ key: 0 }, u.labelProps, { invalid: o(k) }), {
          default: x(() => [
            J(l.$slots, "label", K(Q({ label: u.label })), () => [
              y(B(P.value), 1)
            ], !0)
          ], void 0, !0),
          _: 3
        }, 16, ["invalid"])) : m("", !0),
        F("div", ae, [
          I.value ? (d(), r(V, {
            key: 0,
            "model-value": n.value,
            "onUpdate:modelValue": a[0] || (a[0] = (i) => n.value = i),
            disabled: u.disabled,
            label: z.value,
            "max-value": U.value,
            v: o(v),
            "hide-input-info": "",
            onBlur: T
          }, null, 8, ["model-value", "disabled", "label", "max-value", "v"])) : m("", !0),
          D.value ? (d(), r(V, {
            key: 1,
            "model-value": f.value,
            "onUpdate:modelValue": a[1] || (a[1] = (i) => f.value = i),
            disabled: u.disabled,
            label: E.value,
            "max-value": 59,
            v: o(v),
            "hide-input-info": ""
          }, null, 8, ["model-value", "disabled", "label", "v"])) : m("", !0),
          L.value ? (d(), r(V, {
            key: 2,
            "model-value": p.value,
            "onUpdate:modelValue": a[2] || (a[2] = (i) => p.value = i),
            disabled: u.disabled,
            label: N.value,
            "max-value": 59,
            v: o(v),
            "hide-input-info": ""
          }, null, 8, ["model-value", "disabled", "label", "v"])) : m("", !0)
        ]),
        o(_) && o(g) ? (d(), r(q, {
          key: 1,
          color: o(h),
          variant: o(ee).SIMPLE,
          size: o(Z).SM
        }, {
          default: x(() => [
            y(B(o(g)), 1)
          ], void 0, !0),
          _: 1
        }, 8, ["color", "variant", "size"])) : m("", !0)
      ], 2);
    };
  }
}), ne = /* @__PURE__ */ le(te, [["__scopeId", "data-v-3b807528"]]);
export {
  ne as default
};
