import { defineComponent, computed, ref, createVNode, Fragment } from 'vue';
import { ClockCircleOutlined, CalendarOutlined, SwapRightOutlined, CloseCircleFilled } from '@ant-design/icons-vue';
import '../../../../utils/index.mjs';
import '../../../../locale/index.mjs';
import '../../../../vue-components/index.mjs';
import { transPlacement2DropdownAlign, getRangePlaceholder } from '../util.mjs';
import useStyle from '../../style/index.mjs';
import useConfigInject from '../../../config-provider/src/hooks/useConfigInject.mjs';
import { useInjectFormItemContext, FormItemInputContext } from '../../../form/src/FormItemContext.mjs';
import '../../../space/index.mjs';
import '../../../locale-provider/index.mjs';
import { getTimeProps, Components } from './util.mjs';
import { commonProps, rangePickerProps } from './props.mjs';
import { devWarning } from '../../../../utils/log.mjs';
import { useCompactItemContext } from '../../../space/src/context.mjs';
import { useLocaleReceiver } from '../../../locale-provider/src/useLocaleReceiver.mjs';
import localeValues from '../../../../locale/lang/en_US.mjs';
import { omit } from '../../../../utils/lang/omit.mjs';
import InterRangerPicker from '../../../../vue-components/vc-picker/src/RangePicker.mjs';
import { classNames } from '../../../../utils/dom/class.mjs';
import { getStatusClassNames, getMergedStatus } from '../../../../utils/statusUtils.mjs';

function generateRangePicker(generateConfig, extraProps) {
  const RangePicker = /* @__PURE__ */ defineComponent({
    compatConfig: {
      MODE: 3
    },
    name: "ARangePicker",
    inheritAttrs: false,
    props: {
      ...commonProps(),
      ...rangePickerProps(),
      ...extraProps
    },
    slots: Object,
    setup(_props, {
      expose,
      slots,
      attrs,
      emit
    }) {
      const props = _props;
      const formItemContext = useInjectFormItemContext();
      const formItemInputContext = FormItemInputContext.useInject();
      if (process.env.NODE_ENV !== "production") {
        devWarning(!props.dropdownClassName, "RangePicker", "`dropdownClassName` is deprecated. Please use `popupClassName` instead.");
        devWarning(!attrs.getCalendarContainer, "DatePicker", '`getCalendarContainer` is deprecated. Please use `getPopupContainer"` instead.');
      }
      const {
        prefixCls,
        direction,
        getPopupContainer,
        size,
        rootPrefixCls,
        disabled
      } = useConfigInject("picker", props);
      const {
        compactSize,
        compactItemClassnames
      } = useCompactItemContext(prefixCls, direction);
      const mergedSize = computed(() => compactSize.value || size.value);
      const [wrapSSR, hashId] = useStyle(prefixCls);
      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 maybeToStrings = (dates) => {
        return props.valueFormat ? generateConfig.toString(dates, props.valueFormat) : dates;
      };
      const onChange = (dates, dateStrings) => {
        const values = maybeToStrings(dates);
        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 = (dates, modes) => {
        const values = maybeToStrings(dates);
        emit("panelChange", values, modes);
      };
      const onOk = (dates) => {
        const value2 = maybeToStrings(dates);
        emit("ok", value2);
      };
      const onCalendarChange = (dates, dateStrings, info) => {
        const values = maybeToStrings(dates);
        emit("calendarChange", values, dateStrings, info);
      };
      const [contextLocale] = useLocaleReceiver("DatePicker", localeValues.DatePicker);
      const value = computed(() => {
        if (props.value) {
          return props.valueFormat ? generateConfig.toDate(props.value, props.valueFormat) : props.value;
        }
        return props.value;
      });
      const defaultValue = computed(() => {
        if (props.defaultValue) {
          return props.valueFormat ? generateConfig.toDate(props.defaultValue, props.valueFormat) : props.defaultValue;
        }
        return props.defaultValue;
      });
      const defaultPickerValue = computed(() => {
        if (props.defaultPickerValue) {
          return props.valueFormat ? generateConfig.toDate(props.defaultPickerValue, props.valueFormat) : props.defaultPickerValue;
        }
        return props.defaultPickerValue;
      });
      return () => {
        var _a, _b, _c, _d, _e, _f, _g;
        const locale = {
          ...contextLocale.value,
          ...props.locale
        };
        const p = {
          ...props,
          ...attrs
        };
        const {
          bordered = true,
          placeholder,
          suffixIcon = (_a = slots.suffixIcon) == null ? void 0 : _a.call(slots),
          picker = "date",
          transitionName,
          allowClear = true,
          dateRender = slots.dateRender,
          renderExtraFooter = slots.renderExtraFooter,
          separator = (_b = slots.separator) == null ? void 0 : _b.call(slots),
          clearIcon = (_c = slots.clearIcon) == null ? void 0 : _c.call(slots),
          id = formItemContext.id.value,
          ...restProps
        } = p;
        delete restProps["onUpdate:value"];
        delete restProps["onUpdate:open"];
        const {
          format,
          showTime
        } = p;
        let additionalOverrideProps = {};
        additionalOverrideProps = {
          ...additionalOverrideProps,
          ...showTime ? getTimeProps({
            format,
            picker,
            ...showTime
          }) : {},
          ...picker === "time" ? getTimeProps({
            format,
            ...omit(restProps, ["disabledTime"]),
            picker
          }) : {}
        };
        const pre = prefixCls.value;
        const suffixNode = createVNode(Fragment, null, [suffixIcon || (picker === "time" ? createVNode(ClockCircleOutlined, null, null) : createVNode(CalendarOutlined, null, null)), formItemInputContext.hasFeedback && formItemInputContext.feedbackIcon]);
        return wrapSSR(createVNode(InterRangerPicker, {
          "dateRender": dateRender,
          "renderExtraFooter": renderExtraFooter,
          "separator": separator || createVNode("span", {
            "aria-label": "to",
            "class": `${pre}-separator`
          }, [createVNode(SwapRightOutlined, null, null)]),
          "ref": pickerRef,
          "dropdownAlign": transPlacement2DropdownAlign(direction.value, props.placement),
          "placeholder": getRangePlaceholder(locale, picker, placeholder),
          "suffixIcon": suffixNode,
          "clearIcon": clearIcon || createVNode(CloseCircleFilled, null, null),
          "allowClear": allowClear,
          "transitionName": transitionName || `${rootPrefixCls.value}-slide-up`,
          ...restProps,
          ...additionalOverrideProps,
          "disabled": disabled.value,
          "id": id,
          "value": value.value,
          "defaultValue": defaultValue.value,
          "defaultPickerValue": defaultPickerValue.value,
          "picker": picker,
          "class": classNames({
            [`${pre}-${mergedSize.value}`]: mergedSize.value,
            [`${pre}-borderless`]: !bordered
          }, getStatusClassNames(pre, getMergedStatus(formItemInputContext.status, props.status), formItemInputContext.hasFeedback), attrs.class, hashId.value, compactItemClassnames.value),
          "locale": locale.lang,
          "prefixCls": pre,
          "getPopupContainer": attrs.getCalendarContainer || getPopupContainer.value,
          "generateConfig": generateConfig,
          "prevIcon": ((_d = slots.prevIcon) == null ? void 0 : _d.call(slots)) || createVNode("span", {
            "class": `${pre}-prev-icon`
          }, null),
          "nextIcon": ((_e = slots.nextIcon) == null ? void 0 : _e.call(slots)) || createVNode("span", {
            "class": `${pre}-next-icon`
          }, null),
          "superPrevIcon": ((_f = slots.superPrevIcon) == null ? void 0 : _f.call(slots)) || createVNode("span", {
            "class": `${pre}-super-prev-icon`
          }, null),
          "superNextIcon": ((_g = slots.superNextIcon) == null ? void 0 : _g.call(slots)) || createVNode("span", {
            "class": `${pre}-super-next-icon`
          }, null),
          "components": Components,
          "direction": direction.value,
          "dropdownClassName": classNames(hashId.value, props.popupClassName, props.dropdownClassName),
          "onChange": onChange,
          "onOpenChange": onOpenChange,
          "onFocus": onFocus,
          "onBlur": onBlur,
          "onPanelChange": onPanelChange,
          "onOk": onOk,
          "onCalendarChange": onCalendarChange
        }, null));
      };
    }
  });
  return RangePicker;
}

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