'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');
require('../../../locale-provider/index.cjs');
var useConfigInject = require('../../../config-provider/src/hooks/useConfigInject.cjs');
var FormItemContext = require('../../../form/src/FormItemContext.cjs');
require('../../../space/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 Picker = require('../../../../vue-components/vc-picker/src/Picker.cjs');
var _class = require('../../../../utils/dom/class.cjs');
var statusUtils = require('../../../../utils/statusUtils.cjs');

function generateSinglePicker(generateConfig, extraProps) {
  function getPicker(picker, displayName) {
    const comProps = {
      ...props.commonProps(),
      ...props.datePickerProps(),
      ...extraProps
    };
    return /* @__PURE__ */ vue.defineComponent({
      compatConfig: {
        MODE: 3
      },
      name: displayName,
      inheritAttrs: false,
      props: comProps,
      slots: Object,
      setup(_props, {
        slots,
        expose,
        attrs,
        emit
      }) {
        const props = _props;
        const formItemContext = FormItemContext.useInjectFormItemContext();
        const formItemInputContext = FormItemContext.FormItemInputContext.useInject();
        if (process.env.NODE_ENV !== "production") {
          log.devWarning(picker !== "quarter", displayName || "DatePicker", `DatePicker.${displayName} is legacy usage. Please use DatePicker[picker='${picker}'] directly.`);
          log.devWarning(!props.dropdownClassName, displayName || "DatePicker", "`dropdownClassName` is deprecated. Please use `popupClassName` instead.");
          log.devWarning(!(props.monthCellContentRender || slots.monthCellContentRender), displayName || "DatePicker", '`monthCellContentRender` is deprecated. Please use `monthCellRender"` instead.');
          log.devWarning(!attrs.getCalendarContainer, displayName || "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 maybeToString = (date) => {
          return props.valueFormat ? generateConfig.toString(date, props.valueFormat) : date;
        };
        const onChange = (date, dateString) => {
          const value2 = maybeToString(date);
          emit("update:value", value2);
          emit("change", value2, 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 onPanelChange = (date, mode) => {
          const value2 = maybeToString(date);
          emit("panelChange", value2, mode);
        };
        const onOk = (date) => {
          const value2 = maybeToString(date);
          emit("ok", value2);
        };
        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 === "" ? void 0 : props.value;
        });
        const defaultValue = vue.computed(() => {
          if (props.defaultValue) {
            return props.valueFormat ? generateConfig.toDate(props.defaultValue, props.valueFormat) : props.defaultValue;
          }
          return props.defaultValue === "" ? void 0 : props.defaultValue;
        });
        const defaultPickerValue = vue.computed(() => {
          if (props.defaultPickerValue) {
            return props.valueFormat ? generateConfig.toDate(props.defaultPickerValue, props.valueFormat) : props.defaultPickerValue;
          }
          return props.defaultPickerValue === "" ? void 0 : props.defaultPickerValue;
        });
        return () => {
          var _a, _b, _c, _d, _e, _f;
          const locale = {
            ...contextLocale.value,
            ...props.locale
          };
          const p = {
            ...props,
            ...attrs
          };
          const {
            bordered = true,
            placeholder,
            suffixIcon = (_a = slots.suffixIcon) == null ? void 0 : _a.call(slots),
            showToday = true,
            transitionName,
            allowClear = true,
            dateRender = slots.dateRender,
            renderExtraFooter = slots.renderExtraFooter,
            monthCellRender = slots.monthCellRender || props.monthCellContentRender || slots.monthCellContentRender,
            clearIcon = (_b = slots.clearIcon) == null ? void 0 : _b.call(slots),
            id = formItemContext.id.value,
            ...restProps
          } = p;
          const showTime = p.showTime === "" ? true : p.showTime;
          const {
            format
          } = p;
          let additionalOverrideProps = {};
          if (picker)
            additionalOverrideProps.picker = picker;
          const mergedPicker = picker || p.picker || "date";
          additionalOverrideProps = {
            ...additionalOverrideProps,
            ...showTime ? util.getTimeProps({
              format,
              picker: mergedPicker,
              ...typeof showTime === "object" ? showTime : {}
            }) : {},
            ...mergedPicker === "time" ? util.getTimeProps({
              format,
              ...restProps,
              picker: mergedPicker
            }) : {}
          };
          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(Picker.default, {
            "monthCellRender": monthCellRender,
            "dateRender": dateRender,
            "renderExtraFooter": renderExtraFooter,
            "ref": pickerRef,
            "placeholder": util$1.getPlaceholder(locale, mergedPicker, placeholder),
            "suffixIcon": suffixNode,
            "dropdownAlign": util$1.transPlacement2DropdownAlign(direction.value, props.placement),
            "clearIcon": clearIcon || vue.createVNode(iconsVue.CloseCircleFilled, null, null),
            "allowClear": allowClear,
            "transitionName": transitionName || `${rootPrefixCls.value}-slide-up`,
            ...restProps,
            ...additionalOverrideProps,
            "id": id,
            "picker": mergedPicker,
            "value": value.value,
            "defaultValue": defaultValue.value,
            "defaultPickerValue": defaultPickerValue.value,
            "showToday": showToday,
            "locale": locale.lang,
            "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),
            "disabled": disabled.value,
            "prefixCls": pre,
            "getPopupContainer": attrs.getCalendarContainer || getPopupContainer.value,
            "generateConfig": generateConfig,
            "prevIcon": ((_c = slots.prevIcon) == null ? void 0 : _c.call(slots)) || vue.createVNode("span", {
              "class": `${pre}-prev-icon`
            }, null),
            "nextIcon": ((_d = slots.nextIcon) == null ? void 0 : _d.call(slots)) || vue.createVNode("span", {
              "class": `${pre}-next-icon`
            }, null),
            "superPrevIcon": ((_e = slots.superPrevIcon) == null ? void 0 : _e.call(slots)) || vue.createVNode("span", {
              "class": `${pre}-super-prev-icon`
            }, null),
            "superNextIcon": ((_f = slots.superNextIcon) == null ? void 0 : _f.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
          }, null));
        };
      }
    });
  }
  const DatePicker = getPicker(void 0, "ADatePicker");
  const WeekPicker = getPicker("week", "AWeekPicker");
  const MonthPicker = getPicker("month", "AMonthPicker");
  const YearPicker = getPicker("year", "AYearPicker");
  const TimePicker = getPicker("time", "TimePicker");
  const QuarterPicker = getPicker("quarter", "AQuarterPicker");
  return {
    DatePicker,
    WeekPicker,
    MonthPicker,
    YearPicker,
    TimePicker,
    QuarterPicker
  };
}

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