"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const event = require("../../../constants/event.js");
const error = require("../../../utils/error.js");
const index$2 = require("../../../hooks/use-locale/index.js");
const index$1 = require("../../../hooks/use-namespace/index.js");
const index$3 = require("../../icon/index.js");
const useFormCommonProps = require("../../form/src/hooks/use-form-common-props.js");
const index = require("../../select/index.js");
const timeSelect = require("./time-select.js");
const utils = require("./utils.js");
const vue = require("vue");
const dayjs_min = require("../../../../../../../_virtual/dayjs.min.js");
const customParseFormat = require("../../../../../../../_virtual/customParseFormat.js");
var time_select_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ vue.defineComponent({
  name: "ElTimeSelect",
  __name: "time-select",
  props: timeSelect.timeSelectProps,
  emits: [
    event.CHANGE_EVENT,
    "blur",
    "focus",
    "clear",
    event.UPDATE_MODEL_EVENT
  ],
  setup(__props, { expose: __expose }) {
    dayjs_min.default.extend(customParseFormat.default);
    const { Option: ElOption } = index.ElSelect;
    const props = __props;
    const nsInput = index$1.useNamespace("input");
    const select = vue.ref();
    const _disabled = useFormCommonProps.useFormDisabled();
    const { lang } = index$2.useLocale();
    const value = vue.computed(() => props.modelValue);
    const start = vue.computed(() => {
      const time = utils.parseTime(props.start);
      return time ? utils.formatTime(time) : null;
    });
    const end = vue.computed(() => {
      const time = utils.parseTime(props.end);
      return time ? utils.formatTime(time) : null;
    });
    const minTime = vue.computed(() => {
      const time = utils.parseTime(props.minTime || "");
      return time ? utils.formatTime(time) : null;
    });
    const maxTime = vue.computed(() => {
      const time = utils.parseTime(props.maxTime || "");
      return time ? utils.formatTime(time) : null;
    });
    const step = vue.computed(() => {
      const time = utils.parseTime(props.step);
      const isInvalidStep = !time || time.hours < 0 || time.minutes < 0 || Number.isNaN(time.hours) || Number.isNaN(time.minutes) || time.hours === 0 && time.minutes === 0;
      if (isInvalidStep) error.debugWarn("ElTimeSelect", `invalid step, fallback to default step (${timeSelect.DEFAULT_STEP}).`);
      return !isInvalidStep ? utils.formatTime(time) : timeSelect.DEFAULT_STEP;
    });
    const items = vue.computed(() => {
      var _a;
      const result = [];
      const push = (formattedValue, rawValue) => {
        result.push({
          value: formattedValue,
          rawValue,
          disabled: utils.compareTime(rawValue, minTime.value || "-1:-1") <= 0 || utils.compareTime(rawValue, maxTime.value || "100:100") >= 0
        });
      };
      if (props.start && props.end && props.step) {
        let current = start.value;
        let currentTime;
        while (current && end.value && utils.compareTime(current, end.value) <= 0) {
          currentTime = dayjs_min.default(current, "HH:mm").locale(lang.value).format(props.format);
          push(currentTime, current);
          current = utils.nextTime(current, step.value);
        }
        if (props.includeEndTime && end.value && ((_a = result[result.length - 1]) == null ? void 0 : _a.rawValue) !== end.value) push(dayjs_min.default(end.value, "HH:mm").locale(lang.value).format(props.format), end.value);
      }
      return result;
    });
    const blur = () => {
      var _a, _b;
      (_b = (_a = select.value) == null ? void 0 : _a.blur) == null ? void 0 : _b.call(_a);
    };
    const focus = () => {
      var _a, _b;
      (_b = (_a = select.value) == null ? void 0 : _a.focus) == null ? void 0 : _b.call(_a);
    };
    __expose({
      blur,
      focus
    });
    return (_ctx, _cache) => {
      return vue.openBlock(), vue.createBlock(vue.unref(index.ElSelect), {
        ref_key: "select",
        ref: select,
        name: __props.name,
        "model-value": value.value,
        disabled: vue.unref(_disabled),
        clearable: __props.clearable,
        "clear-icon": __props.clearIcon,
        size: __props.size,
        effect: __props.effect,
        placeholder: __props.placeholder,
        "default-first-option": "",
        filterable: __props.editable,
        "empty-values": __props.emptyValues,
        "value-on-clear": __props.valueOnClear,
        "popper-class": __props.popperClass,
        "popper-style": __props.popperStyle,
        "onUpdate:modelValue": _cache[0] || (_cache[0] = (event$1) => _ctx.$emit(vue.unref(event.UPDATE_MODEL_EVENT), event$1)),
        onChange: _cache[1] || (_cache[1] = (event$1) => _ctx.$emit(vue.unref(event.CHANGE_EVENT), event$1)),
        onBlur: _cache[2] || (_cache[2] = (event2) => _ctx.$emit("blur", event2)),
        onFocus: _cache[3] || (_cache[3] = (event2) => _ctx.$emit("focus", event2)),
        onClear: _cache[4] || (_cache[4] = () => _ctx.$emit("clear"))
      }, {
        prefix: vue.withCtx(() => [__props.prefixIcon ? (vue.openBlock(), vue.createBlock(vue.unref(index$3.ElIcon), {
          key: 0,
          class: vue.normalizeClass(vue.unref(nsInput).e("prefix-icon"))
        }, {
          default: vue.withCtx(() => [(vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(__props.prefixIcon)))]),
          _: 1
        }, 8, ["class"])) : vue.createCommentVNode("v-if", true)]),
        default: vue.withCtx(() => [(vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(items.value, (item) => {
          return vue.openBlock(), vue.createBlock(vue.unref(ElOption), {
            key: item.value,
            label: item.value,
            value: item.value,
            disabled: item.disabled
          }, null, 8, [
            "label",
            "value",
            "disabled"
          ]);
        }), 128))]),
        _: 1
      }, 8, [
        "name",
        "model-value",
        "disabled",
        "clearable",
        "clear-icon",
        "size",
        "effect",
        "placeholder",
        "filterable",
        "empty-values",
        "value-on-clear",
        "popper-class",
        "popper-style"
      ]);
    };
  }
});
exports.default = time_select_vue_vue_type_script_setup_true_lang_default;
