import { defineComponent, ref, createVNode } from 'vue';
import '../../../utils/index.mjs';
import generatePicker from '../../date-picker/src/generatePicker/index.mjs';
import '../../date-picker/index.mjs';
import { useInjectFormItemContext } from '../../form/src/FormItemContext.mjs';
import { commonTimePickerProps } from './props.mjs';
import { commonProps, datePickerProps, rangePickerProps } from '../../date-picker/src/generatePicker/props.mjs';
import { devWarning } from '../../../utils/log.mjs';
import { omit } from '../../../utils/lang/omit.mjs';

function createTimePicker(generateConfig) {
  const DatePicker = generatePicker(generateConfig, {
    ...commonTimePickerProps(),
    order: {
      type: Boolean,
      default: true
    }
  });
  const {
    TimePicker: InternalTimePicker,
    RangePicker: InternalRangePicker
  } = DatePicker;
  const TimePicker = /* @__PURE__ */ defineComponent({
    name: "ATimePicker",
    inheritAttrs: false,
    props: {
      ...commonProps(),
      ...datePickerProps(),
      ...commonTimePickerProps(),
      addon: {
        type: Function
      }
    },
    slots: Object,
    setup(p, {
      slots,
      expose,
      emit,
      attrs
    }) {
      const props = p;
      const formItemContext = useInjectFormItemContext();
      devWarning(!(slots.addon || props.addon), "TimePicker", "`addon` is deprecated. Please use `v-slot:renderExtraFooter` instead.");
      const pickerRef = ref();
      expose({
        focus: () => {
          var _a;
          (_a = pickerRef.value) == null ? void 0 : _a.focus();
        },
        blur: () => {
          var _a;
          (_a = pickerRef.value) == null ? void 0 : _a.blur();
        }
      });
      const onChange = (value, dateString) => {
        emit("update:value", value);
        emit("change", value, dateString);
        formItemContext.onFieldChange();
      };
      const onOpenChange = (open) => {
        emit("update:open", open);
        emit("openChange", open);
      };
      const onFocus = (e) => {
        emit("focus", e);
      };
      const onBlur = (e) => {
        emit("blur", e);
        formItemContext.onFieldBlur();
      };
      const onOk = (value) => {
        emit("ok", value);
      };
      return () => {
        const {
          id = formItemContext.id.value
        } = props;
        return createVNode(InternalTimePicker, {
          ...attrs,
          ...omit(props, ["onUpdate:value", "onUpdate:open"]),
          "id": id,
          "dropdownClassName": props.popupClassName,
          "mode": void 0,
          "ref": pickerRef,
          "renderExtraFooter": props.addon || slots.addon || props.renderExtraFooter || slots.renderExtraFooter,
          "onChange": onChange,
          "onOpenChange": onOpenChange,
          "onFocus": onFocus,
          "onBlur": onBlur,
          "onOk": onOk
        }, slots);
      };
    }
  });
  const TimeRangePicker = /* @__PURE__ */ defineComponent({
    name: "ATimeRangePicker",
    inheritAttrs: false,
    props: {
      ...commonProps(),
      ...rangePickerProps(),
      ...commonTimePickerProps(),
      order: {
        type: Boolean,
        default: true
      }
    },
    slots: Object,
    setup(p, {
      slots,
      expose,
      emit,
      attrs
    }) {
      const props = p;
      const pickerRef = ref();
      const formItemContext = useInjectFormItemContext();
      expose({
        focus: () => {
          var _a;
          (_a = pickerRef.value) == null ? void 0 : _a.focus();
        },
        blur: () => {
          var _a;
          (_a = pickerRef.value) == null ? void 0 : _a.blur();
        }
      });
      const onChange = (values, dateStrings) => {
        emit("update:value", values);
        emit("change", values, dateStrings);
        formItemContext.onFieldChange();
      };
      const onOpenChange = (open) => {
        emit("update:open", open);
        emit("openChange", open);
      };
      const onFocus = (e) => {
        emit("focus", e);
      };
      const onBlur = (e) => {
        emit("blur", e);
        formItemContext.onFieldBlur();
      };
      const onPanelChange = (values, modes) => {
        emit("panelChange", values, modes);
      };
      const onOk = (values) => {
        emit("ok", values);
      };
      const onCalendarChange = (values, dateStrings, info) => {
        emit("calendarChange", values, dateStrings, info);
      };
      return () => {
        const {
          id = formItemContext.id.value
        } = props;
        return createVNode(InternalRangePicker, {
          ...attrs,
          ...omit(props, ["onUpdate:open", "onUpdate:value"]),
          "id": id,
          "dropdownClassName": props.popupClassName,
          "picker": "time",
          "mode": void 0,
          "ref": pickerRef,
          "onChange": onChange,
          "onOpenChange": onOpenChange,
          "onFocus": onFocus,
          "onBlur": onBlur,
          "onPanelChange": onPanelChange,
          "onOk": onOk,
          "onCalendarChange": onCalendarChange
        }, slots);
      };
    }
  });
  return {
    TimePicker,
    TimeRangePicker
  };
}

export { createTimePicker as default };
//# sourceMappingURL=TimePicker.mjs.map
