import { defineComponent, computed, ref, createVNode, Fragment } from 'vue';
import { ClockCircleOutlined, CalendarOutlined, CloseCircleFilled } from '@ant-design/icons-vue';
import '../../../../utils/index.mjs';
import '../../../../locale/index.mjs';
import '../../../../vue-components/index.mjs';
import { getPlaceholder, transPlacement2DropdownAlign } from '../util.mjs';
import useStyle from '../../style/index.mjs';
import '../../../locale-provider/index.mjs';
import useConfigInject from '../../../config-provider/src/hooks/useConfigInject.mjs';
import { useInjectFormItemContext, FormItemInputContext } from '../../../form/src/FormItemContext.mjs';
import '../../../space/index.mjs';
import { getTimeProps, Components } from './util.mjs';
import { commonProps, datePickerProps } 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 VcPicker from '../../../../vue-components/vc-picker/src/Picker.mjs';
import { classNames } from '../../../../utils/dom/class.mjs';
import { getStatusClassNames, getMergedStatus } from '../../../../utils/statusUtils.mjs';

function generateSinglePicker(generateConfig, extraProps) {
  function getPicker(picker, displayName) {
    const comProps = {
      ...commonProps(),
      ...datePickerProps(),
      ...extraProps
    };
    return /* @__PURE__ */ defineComponent({
      compatConfig: {
        MODE: 3
      },
      name: displayName,
      inheritAttrs: false,
      props: comProps,
      slots: Object,
      setup(_props, {
        slots,
        expose,
        attrs,
        emit
      }) {
        const props = _props;
        const formItemContext = useInjectFormItemContext();
        const formItemInputContext = FormItemInputContext.useInject();
        if (process.env.NODE_ENV !== "production") {
          devWarning(picker !== "quarter", displayName || "DatePicker", `DatePicker.${displayName} is legacy usage. Please use DatePicker[picker='${picker}'] directly.`);
          devWarning(!props.dropdownClassName, displayName || "DatePicker", "`dropdownClassName` is deprecated. Please use `popupClassName` instead.");
          devWarning(!(props.monthCellContentRender || slots.monthCellContentRender), displayName || "DatePicker", '`monthCellContentRender` is deprecated. Please use `monthCellRender"` instead.');
          devWarning(!attrs.getCalendarContainer, displayName || "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 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("DatePicker", localeValues.DatePicker);
        const value = computed(() => {
          if (props.value) {
            return props.valueFormat ? generateConfig.toDate(props.value, props.valueFormat) : props.value;
          }
          return props.value === "" ? void 0 : props.value;
        });
        const defaultValue = computed(() => {
          if (props.defaultValue) {
            return props.valueFormat ? generateConfig.toDate(props.defaultValue, props.valueFormat) : props.defaultValue;
          }
          return props.defaultValue === "" ? void 0 : props.defaultValue;
        });
        const defaultPickerValue = 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 ? getTimeProps({
              format,
              picker: mergedPicker,
              ...typeof showTime === "object" ? showTime : {}
            }) : {},
            ...mergedPicker === "time" ? getTimeProps({
              format,
              ...restProps,
              picker: mergedPicker
            }) : {}
          };
          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(VcPicker, {
            "monthCellRender": monthCellRender,
            "dateRender": dateRender,
            "renderExtraFooter": renderExtraFooter,
            "ref": pickerRef,
            "placeholder": getPlaceholder(locale, mergedPicker, placeholder),
            "suffixIcon": suffixNode,
            "dropdownAlign": transPlacement2DropdownAlign(direction.value, props.placement),
            "clearIcon": clearIcon || createVNode(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": classNames({
              [`${pre}-${mergedSize.value}`]: mergedSize.value,
              [`${pre}-borderless`]: !bordered
            }, getStatusClassNames(pre, 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)) || createVNode("span", {
              "class": `${pre}-prev-icon`
            }, null),
            "nextIcon": ((_d = slots.nextIcon) == null ? void 0 : _d.call(slots)) || createVNode("span", {
              "class": `${pre}-next-icon`
            }, null),
            "superPrevIcon": ((_e = slots.superPrevIcon) == null ? void 0 : _e.call(slots)) || createVNode("span", {
              "class": `${pre}-super-prev-icon`
            }, null),
            "superNextIcon": ((_f = slots.superNextIcon) == null ? void 0 : _f.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
          }, 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
  };
}

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