import { createVNode } from 'vue';
import { isLeaf, toPathKey } from '../utils/commonUtil.mjs';
import { SEARCH_MARK } from '../hooks/useSearchOptions.mjs';
import { useInjectCascader } from '../context.mjs';
import Checkbox from './Checkbox.mjs';

const FIX_LABEL = "__cascader_fix_label__";
function Column({
  prefixCls,
  multiple,
  options,
  activeValue,
  prevValuePath,
  onToggleOpen,
  onSelect,
  onActive,
  checkedSet,
  halfCheckedSet,
  loadingKeys,
  isSelectable
}) {
  var _a, _b, _c, _d, _e, _f;
  const menuPrefixCls = `${prefixCls}-menu`;
  const menuItemPrefixCls = `${prefixCls}-menu-item`;
  const {
    fieldNames,
    changeOnSelect,
    expandTrigger,
    expandIcon: expandIconRef,
    loadingIcon: loadingIconRef,
    dropdownMenuColumnStyle,
    customSlots
  } = useInjectCascader();
  const expandIcon = (_c = expandIconRef.value) != null ? _c : (_b = (_a = customSlots.value).expandIcon) == null ? void 0 : _b.call(_a);
  const loadingIcon = (_f = loadingIconRef.value) != null ? _f : (_e = (_d = customSlots.value).loadingIcon) == null ? void 0 : _e.call(_d);
  const hoverOpen = expandTrigger.value === "hover";
  return createVNode("ul", {
    "class": menuPrefixCls,
    "role": "menu"
  }, [options.map((option) => {
    var _a2;
    const {
      disabled
    } = option;
    const searchOptions = option[SEARCH_MARK];
    const label = (_a2 = option[FIX_LABEL]) != null ? _a2 : option[fieldNames.value.label];
    const value = option[fieldNames.value.value];
    const isMergedLeaf = isLeaf(option, fieldNames.value);
    const fullPath = searchOptions ? searchOptions.map((opt) => opt[fieldNames.value.value]) : [...prevValuePath, value];
    const fullPathKey = toPathKey(fullPath);
    const isLoading = loadingKeys.includes(fullPathKey);
    const checked = checkedSet.has(fullPathKey);
    const halfChecked = halfCheckedSet.has(fullPathKey);
    const triggerOpenPath = () => {
      if (!disabled && (!hoverOpen || !isMergedLeaf))
        onActive(fullPath);
    };
    const triggerSelect = () => {
      if (isSelectable(option))
        onSelect(fullPath, isMergedLeaf);
    };
    let title;
    if (typeof option.title === "string")
      title = option.title;
    else if (typeof label === "string")
      title = label;
    return createVNode("li", {
      "key": fullPathKey,
      "class": [menuItemPrefixCls, {
        [`${menuItemPrefixCls}-expand`]: !isMergedLeaf,
        [`${menuItemPrefixCls}-active`]: activeValue === value,
        [`${menuItemPrefixCls}-disabled`]: disabled,
        [`${menuItemPrefixCls}-loading`]: isLoading
      }],
      "style": dropdownMenuColumnStyle.value,
      "role": "menuitemcheckbox",
      "title": title,
      "aria-checked": checked,
      "data-path-key": fullPathKey,
      "onClick": () => {
        triggerOpenPath();
        if (!multiple || isMergedLeaf)
          triggerSelect();
      },
      "onDblclick": () => {
        if (changeOnSelect.value)
          onToggleOpen(false);
      },
      "onMouseenter": () => {
        if (hoverOpen)
          triggerOpenPath();
      },
      "onMousedown": (e) => {
        e.preventDefault();
      }
    }, [multiple && createVNode(Checkbox, {
      "prefixCls": `${prefixCls}-checkbox`,
      "checked": checked,
      "halfChecked": halfChecked,
      "disabled": disabled,
      "onClick": (e) => {
        e.stopPropagation();
        triggerSelect();
      }
    }, null), createVNode("div", {
      "class": `${menuItemPrefixCls}-content`
    }, [label]), !isLoading && expandIcon && !isMergedLeaf && createVNode("div", {
      "class": `${menuItemPrefixCls}-expand-icon`
    }, [expandIcon]), isLoading && loadingIcon && createVNode("div", {
      "class": `${menuItemPrefixCls}-loading-icon`
    }, [loadingIcon])]);
  })]);
}
Column.props = ["prefixCls", "multiple", "options", "activeValue", "prevValuePath", "onToggleOpen", "onSelect", "onActive", "checkedSet", "halfCheckedSet", "loadingKeys", "isSelectable"];
Column.displayName = "Column";
Column.inheritAttrs = false;

export { FIX_LABEL, Column as default };
//# sourceMappingURL=Column.mjs.map
