'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var vue = require('vue');
var iconsVue = require('@ant-design/icons-vue');
require('../../../../utils/index.cjs');
require('../../../../locale/index.cjs');
require('../../../../vue-components/index.cjs');
var util$1 = require('../util.cjs');
var index = require('../../style/index.cjs');
var useConfigInject = require('../../../config-provider/src/hooks/useConfigInject.cjs');
var FormItemContext = require('../../../form/src/FormItemContext.cjs');
require('../../../space/index.cjs');
require('../../../locale-provider/index.cjs');
var util = require('./util.cjs');
var props = require('./props.cjs');
var log = require('../../../../utils/log.cjs');
var context = require('../../../space/src/context.cjs');
var useLocaleReceiver = require('../../../locale-provider/src/useLocaleReceiver.cjs');
var en_US = require('../../../../locale/lang/en_US.cjs');
var omit = require('../../../../utils/lang/omit.cjs');
var RangePicker = require('../../../../vue-components/vc-picker/src/RangePicker.cjs');
var _class = require('../../../../utils/dom/class.cjs');
var statusUtils = require('../../../../utils/statusUtils.cjs');

function generateRangePicker(generateConfig, extraProps) {
  const RangePicker$1 = /* @__PURE__ */ vue.defineComponent({
    compatConfig: {
      MODE: 3
    },
    name: "ARangePicker",
    inheritAttrs: false,
    props: {
      ...props.commonProps(),
      ...props.rangePickerProps(),
      ...extraProps
    },
    slots: Object,
    setup(_props, {
      expose,
      slots,
      attrs,
      emit
    }) {
      const props = _props;
      const formItemContext = FormItemContext.useInjectFormItemContext();
      const formItemInputContext = FormItemContext.FormItemInputContext.useInject();
      if (process.env.NODE_ENV !== "production") {
        log.devWarning(!props.dropdownClassName, "RangePicker", "`dropdownClassName` is deprecated. Please use `popupClassName` instead.");
        log.devWarning(!attrs.getCalendarContainer, "DatePicker", '`getCalendarContainer` is deprecated. Please use `getPopupContainer"` instead.');
      }
      const {
        prefixCls,
        direction,
        getPopupContainer,
        size,
        rootPrefixCls,
        disabled
      } = useConfigInject.default("picker", props);
      const {
        compactSize,
        compactItemClassnames
      } = context.useCompactItemContext(prefixCls, direction);
      const mergedSize = vue.computed(() => compactSize.value || size.value);
      const [wrapSSR, hashId] = index.default(prefixCls);
      const pickerRef = vue.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.useLocaleReceiver("DatePicker", en_US.default.DatePicker);
      const value = vue.computed(() => {
        if (props.value) {
          return props.valueFormat ? generateConfig.toDate(props.value, props.valueFormat) : props.value;
        }
        return props.value;
      });
      const defaultValue = vue.computed(() => {
        if (props.defaultValue) {
          return props.valueFormat ? generateConfig.toDate(props.defaultValue, props.valueFormat) : props.defaultValue;
        }
        return props.defaultValue;
      });
      const defaultPickerValue = vue.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 ? util.getTimeProps({
            format,
            picker,
            ...showTime
          }) : {},
          ...picker === "time" ? util.getTimeProps({
            format,
            ...omit.omit(restProps, ["disabledTime"]),
            picker
          }) : {}
        };
        const pre = prefixCls.value;
        const suffixNode = vue.createVNode(vue.Fragment, null, [suffixIcon || (picker === "time" ? vue.createVNode(iconsVue.ClockCircleOutlined, null, null) : vue.createVNode(iconsVue.CalendarOutlined, null, null)), formItemInputContext.hasFeedback && formItemInputContext.feedbackIcon]);
        return wrapSSR(vue.createVNode(RangePicker.default, {
          "dateRender": dateRender,
          "renderExtraFooter": renderExtraFooter,
          "separator": separator || vue.createVNode("span", {
            "aria-label": "to",
            "class": `${pre}-separator`
          }, [vue.createVNode(iconsVue.SwapRightOutlined, null, null)]),
          "ref": pickerRef,
          "dropdownAlign": util$1.transPlacement2DropdownAlign(direction.value, props.placement),
          "placeholder": util$1.getRangePlaceholder(locale, picker, placeholder),
          "suffixIcon": suffixNode,
          "clearIcon": clearIcon || vue.createVNode(iconsVue.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": _class.classNames({
            [`${pre}-${mergedSize.value}`]: mergedSize.value,
            [`${pre}-borderless`]: !bordered
          }, statusUtils.getStatusClassNames(pre, statusUtils.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)) || vue.createVNode("span", {
            "class": `${pre}-prev-icon`
          }, null),
          "nextIcon": ((_e = slots.nextIcon) == null ? void 0 : _e.call(slots)) || vue.createVNode("span", {
            "class": `${pre}-next-icon`
          }, null),
          "superPrevIcon": ((_f = slots.superPrevIcon) == null ? void 0 : _f.call(slots)) || vue.createVNode("span", {
            "class": `${pre}-super-prev-icon`
          }, null),
          "superNextIcon": ((_g = slots.superNextIcon) == null ? void 0 : _g.call(slots)) || vue.createVNode("span", {
            "class": `${pre}-super-next-icon`
          }, null),
          "components": util.Components,
          "direction": direction.value,
          "dropdownClassName": _class.classNames(hashId.value, props.popupClassName, props.dropdownClassName),
          "onChange": onChange,
          "onOpenChange": onOpenChange,
          "onFocus": onFocus,
          "onBlur": onBlur,
          "onPanelChange": onPanelChange,
          "onOk": onOk,
          "onCalendarChange": onCalendarChange
        }, null));
      };
    }
  });
  return RangePicker$1;
}

exports.default = generateRangePicker;
//# sourceMappingURL=generateRangePicker.cjs.map
