/**
 * ldesign v0.4.6
 * (c) 2023 ldesign
 * @license MIT
 */

'use strict';

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

var helper = require('../../_chunks/dep-c3e1ffac.js');
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var VueCompositionAPI = require('@vue/composition-api');
var iconsVue = require('@ldesign/icons-vue');
var cascader_core_helper = require('../core/helper.js');
var cascader_core_className = require('../core/className.js');
var checkbox_index = require('../../checkbox/index.js');
var loading_index = require('../../loading/index.js');
var configProvider_configReceiver = require('../../config-provider/config-receiver.js');
var hooks_useConfig = require('../../hooks/useConfig.js');
var hooks_useGlobalIcon = require('../../hooks/useGlobalIcon.js');
var utils_ripple = require('../../utils/ripple.js');
require('@babel/runtime/helpers/typeof');
require('lodash/isEmpty');
require('@babel/runtime/helpers/toConsumableArray');
require('../../utils/map-props.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('vue');
require('../../utils/withInstall.js');
require('lodash/capitalize');
require('../../checkbox/group.js');
require('lodash/intersection');
require('../../utils/event.js');
require('../../utils/helper.js');
require('@babel/runtime/helpers/slicedToArray');
require('lodash/camelCase');
require('../../utils/mixins.js');
require('../../checkbox/checkbox.js');
require('../../utils/render-tnode.js');
require('lodash/kebabCase');
require('../../checkbox/props.js');
require('lodash/mergeWith');
require('../../config-provider/context.js');
require('lodash/merge');
require('../../_common/js/global-config/default-config.js');
require('../../_common/js/global-config/locale/zh_CN.js');
require('../../_chunks/dep-7c884501.js');
require('dayjs');
require('../../checkbox/checkbox-group-props.js');
require('../../loading/directive.js');
require('lodash/isObject');
require('lodash/mapKeys');
require('lodash/isEqual');
require('../../loading/plugin.js');
require('../../config.js');
require('../../utils/dom.js');
require('raf');
require('lodash/isString');
require('../../utils/easing.js');
require('../../loading/loading.js');
require('../../utils/transfer-dom.js');
require('../../loading/props.js');
require('../../loading/icon/gradient.js');
require('../../_common/js/loading/circle-adapter.js');
require('../../_common/js/utils/set-style.js');
require('../../_common/js/utils/helper.js');
require('lodash/isNull');
require('lodash/isUndefined');
require('lodash/isNumber');
require('lodash/isArray');
require('../../config-provider/useConfig.js');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
var keepAnimationMixins = configProvider_configReceiver.getKeepAnimationMixins();
var props = {
  node: {
    type: Object,
    "default": function _default() {
      return {};
    }
  },
  cascaderContext: {
    type: Object
  },
  onChange: Function,
  onClick: Function,
  onMouseenter: Function
};
var Item = VueCompositionAPI.defineComponent({
  directives: {
    Ripple: utils_ripple["default"]
  },
  mixins: [keepAnimationMixins],
  props: _objectSpread({}, props),
  setup: function setup(props2) {
    var COMPONENT_NAME = hooks_useConfig.usePrefixClass("cascader__item");
    var classPrefix = hooks_useConfig.usePrefixClass();
    var _useCommonClassName = hooks_useConfig.useCommonClassName(),
      STATUS = _useCommonClassName.STATUS,
      SIZE = _useCommonClassName.SIZE;
    var _useGlobalIcon = hooks_useGlobalIcon.useGlobalIcon({
        ChevronRightIcon: iconsVue.ChevronRightIcon
      }),
      ChevronRightIcon = _useGlobalIcon.ChevronRightIcon;
    var itemClass = VueCompositionAPI.computed(function () {
      return cascader_core_className.getCascaderItemClass(classPrefix.value, props2.node, SIZE.value, STATUS.value, props2.cascaderContext);
    });
    var iconClass = VueCompositionAPI.computed(function () {
      return cascader_core_className.getCascaderItemIconClass(classPrefix.value, props2.node, STATUS.value, props2.cascaderContext);
    });
    return {
      COMPONENT_NAME: COMPONENT_NAME,
      ChevronRightIcon: ChevronRightIcon,
      iconClass: iconClass,
      itemClass: itemClass
    };
  },
  render: function render() {
    var _this = this;
    var h = arguments[0];
    var iconClass = this.iconClass,
      cascaderContext = this.cascaderContext,
      itemClass = this.itemClass,
      node = this.node,
      COMPONENT_NAME = this.COMPONENT_NAME,
      onChange = this.onChange,
      ChevronRightIcon = this.ChevronRightIcon;
    function RenderLabelInner(node2, cascaderContext2) {
      var inputVal = cascaderContext2.inputVal;
      var labelText = inputVal ? cascader_core_helper.getFullPathLabel(node2) : node2.label;
      if (inputVal) {
        var texts = labelText.split(inputVal);
        var doms = [];
        for (var 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": "".concat(index, "filter"),
            "class": "".concat(COMPONENT_NAME, "-label--filter")
          }, [inputVal]));
        }
        return doms;
      }
      return labelText;
    }
    function RenderLabelContent(node2, cascaderContext2) {
      var label = RenderLabelInner(node2, cascaderContext2);
      var labelCont = h("span", {
        "attrs": {
          "title": cascaderContext2.inputVal ? cascader_core_helper.getFullPathLabel(node2) : node2.label,
          "role": "label"
        },
        "class": ["".concat(COMPONENT_NAME, "-label"), "".concat(COMPONENT_NAME, "-label--ellipsis")]
      }, [label]);
      return labelCont;
    }
    function RenderCheckBox(node2, cascaderContext2) {
      var checkProps = cascaderContext2.checkProps,
        value = cascaderContext2.value,
        max = cascaderContext2.max,
        inputVal = cascaderContext2.inputVal;
      var label = RenderLabelInner(node2, cascaderContext2);
      return h(checkbox_index.Checkbox, helper.helper([{
        "attrs": {
          "checked": node2.checked,
          "indeterminate": node2.indeterminate,
          "disabled": node2.isDisabled() || value.length >= max && max !== 0,
          "name": String(node2.value),
          "title": inputVal ? cascader_core_helper.getFullPathLabel(node2) : node2.label,
          "stopLabelTrigger": !!node2.children
        },
        "on": {
          "change": function change(vale, _ref) {
            var e = _ref.e;
            e.stopPropagation();
            onChange();
          }
        }
      }, checkProps]), [label]);
    }
    return h("li", {
      "class": itemClass,
      "on": {
        "click": function click(e) {
          e.stopPropagation();
          _this.onClick();
        },
        "mouseenter": function mouseenter(e) {
          e.stopPropagation();
          _this.onMouseenter();
        }
      }
    }, [cascaderContext.multiple ? RenderCheckBox(node, cascaderContext) : RenderLabelContent(node, cascaderContext), node.children && (node.loading ? h(loading_index.Loading, {
      "class": iconClass,
      "attrs": {
        "size": "small"
      }
    }) : h(ChevronRightIcon, {
      "class": iconClass
    }))]);
  }
});

exports["default"] = Item;
//# sourceMappingURL=Item.js.map
