'use strict';

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

var vue = require('vue');
var iconsVue = require('@ant-design/icons-vue');
require('../../../vue-components/index.cjs');
require('../../../utils/index.cjs');
var context = require('../../space/src/context.cjs');
var iconUtil = require('../../select/src/iconUtil.cjs');
var useConfigInject = require('../../config-provider/src/hooks/useConfigInject.cjs');
require('../../form/index.cjs');
var FormItemContext = require('../../form/src/FormItemContext.cjs');
var index = require('../../select/style/index.cjs');
require('../../config-provider/src/context/index.cjs');
var index$1 = require('../style/index.cjs');
var props = require('./props.cjs');
var initDefaultProps = require('../../../utils/vue/initDefaultProps.cjs');
var log = require('../../../utils/log.cjs');
var statusUtils = require('../../../utils/statusUtils.cjs');
var disabledContext = require('../../config-provider/src/context/disabledContext.cjs');
var _class = require('../../../utils/dom/class.cjs');
var Cascader = require('../../../vue-components/vc-cascader/src/Cascader.cjs');
var transition = require('../../../vue-components/transition/src/transition.cjs');

function highlightKeyword(str, lowerKeyword, prefixCls) {
  const cells = str.toLowerCase().split(lowerKeyword).reduce((list, cur, index) => index === 0 ? [cur] : [...list, lowerKeyword, cur], []);
  const fillCells = [];
  let start = 0;
  cells.forEach((cell, index) => {
    const end = start + cell.length;
    let originWorld = str.slice(start, end);
    start = end;
    if (index % 2 === 1) {
      const _originWorld = function() {
        return originWorld;
      }();
      originWorld = vue.createVNode("span", {
        "class": `${prefixCls}-menu-item-keyword`,
        "key": "seperator"
      }, [originWorld]);
    }
    fillCells.push(originWorld);
  });
  return fillCells;
}
const defaultSearchRender = ({
  inputValue,
  path,
  prefixCls,
  fieldNames
}) => {
  const optionList = [];
  const lower = inputValue.toLowerCase();
  path.forEach((node, index) => {
    if (index !== 0)
      optionList.push(" / ");
    let label = node[fieldNames.label];
    const type = typeof label;
    if (type === "string" || type === "number")
      label = highlightKeyword(String(label), lower, prefixCls);
    optionList.push(label);
  });
  return optionList;
};
var ACascader = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "ACascader",
  inheritAttrs: false,
  props: initDefaultProps.initDefaultProps(props.cascaderProps(), {
    bordered: true,
    choiceTransitionName: "",
    allowClear: true
  }),
  setup(props, {
    attrs,
    expose,
    slots,
    emit
  }) {
    if (process.env.NODE_ENV !== "production") {
      log.devWarning(!props.dropdownClassName, "Cascader", "`dropdownClassName` is deprecated. Please use `popupClassName` instead.");
    }
    const formItemContext = FormItemContext.useInjectFormItemContext();
    const formItemInputContext = FormItemContext.FormItemInputContext.useInject();
    const mergedStatus = vue.computed(() => statusUtils.getMergedStatus(formItemInputContext.status, props.status));
    const {
      prefixCls: cascaderPrefixCls,
      rootPrefixCls,
      getPrefixCls,
      direction,
      getPopupContainer,
      renderEmpty,
      size: contextSize,
      disabled
    } = useConfigInject.default("cascader", props);
    const prefixCls = vue.computed(() => getPrefixCls("select", props.prefixCls));
    const {
      compactSize,
      compactItemClassnames
    } = context.useCompactItemContext(prefixCls, direction);
    const mergedSize = vue.computed(() => compactSize.value || contextSize.value);
    const contextDisabled = disabledContext.useInjectDisabled();
    const mergedDisabled = vue.computed(() => {
      var _a;
      return (_a = disabled.value) != null ? _a : contextDisabled.value;
    });
    const [wrapSelectSSR, hashId] = index.default(prefixCls);
    const [wrapCascaderSSR] = index$1.default(cascaderPrefixCls);
    const isRtl = vue.computed(() => direction.value === "rtl");
    if (process.env.NODE_ENV !== "production") {
      vue.watchEffect(() => {
        log.devWarning(!props.multiple || !props.displayRender || !slots.displayRender, "Cascader", "`displayRender` not work on `multiple`. Please use `tagRender` instead.");
      });
    }
    const mergedShowSearch = vue.computed(() => {
      if (!props.showSearch)
        return props.showSearch;
      let searchConfig = {
        render: defaultSearchRender
      };
      if (typeof props.showSearch === "object") {
        searchConfig = {
          ...searchConfig,
          ...props.showSearch
        };
      }
      return searchConfig;
    });
    const mergedDropdownClassName = vue.computed(() => _class.classNames(props.popupClassName || props.dropdownClassName, `${cascaderPrefixCls.value}-dropdown`, {
      [`${cascaderPrefixCls.value}-dropdown-rtl`]: isRtl.value
    }, hashId.value));
    const selectRef = vue.ref();
    expose({
      focus() {
        var _a;
        (_a = selectRef.value) == null ? void 0 : _a.focus();
      },
      blur() {
        var _a;
        (_a = selectRef.value) == null ? void 0 : _a.blur();
      }
    });
    const handleChange = (...args) => {
      emit("update:value", args[0]);
      emit("change", ...args);
      formItemContext.onFieldChange();
    };
    const handleBlur = (...args) => {
      emit("blur", ...args);
      formItemContext.onFieldBlur();
    };
    const mergedShowArrow = vue.computed(() => props.showArrow !== void 0 ? props.showArrow : props.loading || !props.multiple);
    const placement = vue.computed(() => {
      if (props.placement !== void 0)
        return props.placement;
      return direction.value === "rtl" ? "bottomRight" : "bottomLeft";
    });
    return () => {
      var _a, _b;
      const {
        notFoundContent = (_a = slots.notFoundContent) == null ? void 0 : _a.call(slots),
        expandIcon = (_b = slots.expandIcon) == null ? void 0 : _b.call(slots),
        multiple,
        bordered,
        allowClear,
        choiceTransitionName,
        transitionName,
        id = formItemContext.id.value,
        ...restProps
      } = props;
      const mergedNotFoundContent = notFoundContent || renderEmpty("Cascader");
      let mergedExpandIcon = expandIcon;
      if (!expandIcon)
        mergedExpandIcon = isRtl.value ? vue.createVNode(iconsVue.LeftOutlined, null, null) : vue.createVNode(iconsVue.RightOutlined, null, null);
      const loadingIcon = vue.createVNode("span", {
        "class": `${prefixCls.value}-menu-item-loading-icon`
      }, [vue.createVNode(iconsVue.LoadingOutlined, {
        "spin": true
      }, null)]);
      const {
        suffixIcon,
        removeIcon,
        clearIcon
      } = iconUtil.default({
        ...props,
        hasFeedback: formItemInputContext.hasFeedback,
        feedbackIcon: formItemInputContext.feedbackIcon,
        multiple,
        prefixCls: prefixCls.value,
        showArrow: mergedShowArrow.value
      }, slots);
      return wrapCascaderSSR(wrapSelectSSR(vue.createVNode(Cascader.default, {
        ...restProps,
        ...attrs,
        "id": id,
        "prefixCls": prefixCls.value,
        "class": [cascaderPrefixCls.value, {
          [`${prefixCls.value}-lg`]: mergedSize.value === "large",
          [`${prefixCls.value}-sm`]: mergedSize.value === "small",
          [`${prefixCls.value}-rtl`]: isRtl.value,
          [`${prefixCls.value}-borderless`]: !bordered,
          [`${prefixCls.value}-in-form-item`]: formItemInputContext.isFormItemInput
        }, statusUtils.getStatusClassNames(prefixCls.value, mergedStatus.value, formItemInputContext.hasFeedback), compactItemClassnames.value, attrs.class, hashId.value],
        "disabled": mergedDisabled.value,
        "direction": direction.value,
        "placement": placement.value,
        "notFoundContent": mergedNotFoundContent,
        "allowClear": allowClear,
        "showSearch": mergedShowSearch.value,
        "expandIcon": mergedExpandIcon,
        "inputIcon": suffixIcon,
        "removeIcon": removeIcon,
        "clearIcon": clearIcon,
        "loadingIcon": loadingIcon,
        "checkable": !!multiple,
        "dropdownClassName": mergedDropdownClassName.value,
        "dropdownPrefixCls": cascaderPrefixCls.value,
        "choiceTransitionName": transition.getTransitionName(rootPrefixCls.value, "", choiceTransitionName),
        "transitionName": transition.getTransitionName(rootPrefixCls.value, transition.getTransitionDirection(placement.value), transitionName),
        "getPopupContainer": getPopupContainer == null ? void 0 : getPopupContainer.value,
        "customSlots": {
          ...slots,
          checkable: () => vue.createVNode("span", {
            "class": `${cascaderPrefixCls.value}-checkbox-inner`
          }, null)
        },
        "tagRender": props.tagRender || slots.tagRender,
        "displayRender": props.displayRender || slots.displayRender,
        "maxTagPlaceholder": props.maxTagPlaceholder || slots.maxTagPlaceholder,
        "showArrow": formItemInputContext.hasFeedback || props.showArrow,
        "onChange": handleChange,
        "onBlur": handleBlur,
        "ref": selectRef
      }, slots)));
    };
  }
});

exports.default = ACascader;
//# sourceMappingURL=Cascader.cjs.map
