/**
 * ldesign v0.2.14
 * (c) 2022/11/2 16:16 built by swimly
 * @license MIT
 */

import { h as helper } from '../../../_chunks/dep-29915b8e.js';
import { defineComponent, computed } from '@vue/composition-api';
import { ChevronRightIcon } from '@ldesign/icons-vue';
import { getFullPathLabel } from '../utils/helper.js';
import { getCascaderItemClass, getCascaderItemIconClass } from '../utils/className.js';
import { Checkbox } from '../../checkbox/index.js';
import { Loading } from '../../loading/index.js';
import { getKeepAnimationMixins } from '../../config-provider/config-receiver.js';
import { usePrefixClass, useCommonClassName } from '../../../hooks/use-config.js';
import { useGlobalIcon } from '../../../hooks/use-global-icon.js';
import Ripple from '../../../utils/ripple.js';
import 'lodash/isEmpty';
import '../../../utils/map-props.js';
import 'vue';
import '../../../utils/with-install.js';
import 'lodash';
import '../../../config.js';
import '../../checkbox/group.js';
import 'lodash/intersection';
import '../../../_chunks/dep-70c789e5.js';
import '../../../_chunks/dep-5210251b.js';
import '../../../utils/event.js';
import '../../../utils/helper.js';
import 'lodash/camelCase';
import '../../../utils/mixins.js';
import '../../checkbox/checkbox.js';
import '../../../utils/render-node.js';
import '../../checkbox/props.js';
import 'lodash/mergeWith';
import '../../config-provider/context.js';
import '../../../_chunks/dep-def4c2ce.js';
import '../../loading/loading.js';
import '../../../utils/dom.js';
import 'raf';
import 'lodash/isString';
import '../../../utils/easing.js';
import '../../../utils/transfer-dom.js';
import '../../loading/props.js';
import '../../loading/icon/gradient.js';
import '../../../_chunks/dep-eb467ddf.js';
import '../../../_chunks/dep-cf772670.js';
import '../../../_chunks/dep-47d77fc8.js';
import '../../loading/plugin.js';
import '../../config-provider/useConfig.js';

const keepAnimationMixins = getKeepAnimationMixins();
const props = {
  node: {
    type: Object,
    default() {
      return {};
    }
  },
  cascaderContext: {
    type: Object
  },
  onChange: Function,
  onClick: Function,
  onMouseenter: Function
};
var Item = defineComponent({
  components: {
    LLoading: Loading,
    LCheckbox: Checkbox
  },
  directives: {
    Ripple
  },
  mixins: [keepAnimationMixins],
  props: {
    ...props
  },
  setup(props2) {
    const COMPONENT_NAME = usePrefixClass("cascader__item");
    const classPrefix = usePrefixClass();
    const {
      STATUS,
      SIZE
    } = useCommonClassName();
    const {
      ChevronRightIcon: ChevronRightIcon$1
    } = useGlobalIcon({
      ChevronRightIcon: ChevronRightIcon
    });
    const itemClass = computed(() => getCascaderItemClass(classPrefix.value, props2.node, SIZE.value, STATUS.value, props2.cascaderContext));
    const iconClass = computed(() => getCascaderItemIconClass(classPrefix.value, props2.node, STATUS.value, props2.cascaderContext));
    return {
      COMPONENT_NAME,
      ChevronRightIcon: ChevronRightIcon$1,
      iconClass,
      itemClass
    };
  },
  render() {
    const h = arguments[0];
    const {
      iconClass,
      cascaderContext,
      itemClass,
      node,
      COMPONENT_NAME,
      onChange,
      ChevronRightIcon
    } = this;
    function RenderLabelInner(node2, cascaderContext2) {
      const {
        inputVal
      } = cascaderContext2;
      const labelText = inputVal ? getFullPathLabel(node2) : node2.label;
      if (inputVal) {
        const texts = labelText.split(inputVal);
        const doms = [];
        for (let index = 0; index < texts.length; index++) {
          doms.push(h("span", {
            "key": index
          }, [texts[index]]));
          if (index === texts.length - 1) break;
          doms.push(h("span", {
            "key": `${index}filter`,
            "class": `${COMPONENT_NAME}-label--filter`
          }, [inputVal]));
        }
        return doms;
      }
      return labelText;
    }
    function RenderLabelContent(node2, cascaderContext2) {
      const label = RenderLabelInner(node2, cascaderContext2);
      const labelCont = h("span", {
        "attrs": {
          "title": cascaderContext2.inputVal ? getFullPathLabel(node2) : node2.label,
          "role": "label"
        },
        "class": [`${COMPONENT_NAME}-label`, `${COMPONENT_NAME}-label--ellipsis`]
      }, [label]);
      return labelCont;
    }
    function RenderCheckBox(node2, cascaderContext2) {
      const {
        checkProps,
        value,
        max,
        inputVal
      } = cascaderContext2;
      const label = RenderLabelInner(node2, cascaderContext2);
      return h("l-checkbox", helper([{
        "attrs": {
          "checked": node2.checked,
          "indeterminate": node2.indeterminate,
          "disabled": node2.isDisabled() || value.length >= max && max !== 0,
          "name": String(node2.value),
          "title": inputVal ? getFullPathLabel(node2) : node2.label,
          "stopLabelTrigger": !!node2.children
        },
        "on": {
          "change": (vale, _ref) => {
            let {
              e
            } = _ref;
            e.stopPropagation();
            onChange();
          }
        }
      }, checkProps]), [label]);
    }
    return h("li", {
      "class": itemClass,
      "on": {
        "click": e => {
          e.stopPropagation();
          this.onClick();
        },
        "mouseenter": e => {
          e.stopPropagation();
          this.onMouseenter();
        }
      }
    }, [cascaderContext.multiple ? RenderCheckBox(node, cascaderContext) : RenderLabelContent(node, cascaderContext), node.children && (node.loading ? h("l-loading", {
      "class": iconClass,
      "attrs": {
        "size": "small"
      }
    }) : h(ChevronRightIcon, {
      "class": iconClass
    }))]);
  }
});

export { Item as default };
//# sourceMappingURL=Item.js.map
