/**
 * ldesign v0.2.2
 * (c) 2022年9月20日 swimly
 * @license MIT
 */

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, computed } from '@vue/composition-api';
import Item from './Item.js';
import props from '../props.js';
import { usePrefixClass } from '../../../hooks/use-config.js';
import { useLNodeDefault } from '../../../hooks/lnode.js';
import { getPanels } from '../utils/helper.js';
import { expendClickEffect, valueChangeEffect } from '../utils/effect.js';
import { useConfig } from '../../config-provider/useConfig.js';
import '../../../chunks/helper.js';
import '../../../chunks/_commonjsHelpers.js';
import '@ldesign/icons-vue';
import '../utils/className.js';
import '@babel/runtime/helpers/toConsumableArray';
import '../../checkbox/index.js';
import '../../checkbox/group.js';
import '@babel/runtime/helpers/typeof';
import 'lodash/intersection';
import '../../checkbox/checkbox.js';
import 'vue';
import '../../../utils/render-node.js';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../../checkbox/props.js';
import '../../../utils/helper.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import '@babel/runtime/helpers/slicedToArray';
import '../../../utils/event.js';
import '../../config-provider/config-receiver.js';
import 'lodash/mergeWith';
import 'lodash';
import '../../config-provider/context.js';
import '../../../chunks/zh_CN.js';
import '../../config-provider/type.js';
import '../../../utils/mixins.js';
import '../../../utils/map-props.js';
import '../../../utils/with-install.js';
import '../../../config.js';
import '../../checkbox/style/css.js';
import '../../checkbox/type.js';
import '../../loading/index.js';
import '../../loading/loading.js';
import '../../loading/icon/gradient.js';
import '../../../chunks/defineProperty-28395935.js';
import '../../../chunks/set-style.js';
import '../../../chunks/helper2.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/style/css.js';
import '../../loading/type.js';
import '../../loading/plugin.js';
import '../../../hooks/use-global-icon.js';
import '../../../utils/ripple.js';
import 'lodash/isEmpty';
import 'lodash/isFunction';
import '../../../hooks/render-lnode.js';
import 'lodash/isObject';
import 'lodash/isNumber';
import 'lodash/cloneDeep';

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(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 Panel = defineComponent({
  name: "LCascaderSubPanel",
  props: {
    empty: props.empty,
    trigger: props.trigger,
    onChange: props.onChange,
    cascaderContext: {
      type: Object
    }
  },
  setup: function setup(props, _ref) {
    var emit = _ref.emit;
    var renderTNodeJSXDefault = useLNodeDefault();
    var COMPONENT_NAME = usePrefixClass("cascader");

    var _useConfig = useConfig("cascader"),
        global = _useConfig.global;

    var panels = computed(function () {
      return getPanels(props.cascaderContext.treeNodes);
    });

    var handleExpand = function handleExpand(node, trigger) {
      var propsTrigger = props.trigger,
          cascaderContext = props.cascaderContext;
      expendClickEffect(propsTrigger, trigger, node, cascaderContext);
    };

    return {
      global: global,
      panels: panels,
      handleExpand: handleExpand,
      renderTNodeJSXDefault: renderTNodeJSXDefault,
      COMPONENT_NAME: COMPONENT_NAME,
      emit: emit
    };
  },
  render: function render() {
    var h = arguments[0];
    var global = this.global,
        COMPONENT_NAME = this.COMPONENT_NAME,
        handleExpand = this.handleExpand,
        renderTNodeJSXDefault = this.renderTNodeJSXDefault,
        cascaderContext = this.cascaderContext,
        panels = this.panels,
        emit = this.emit;

    var renderItem = function renderItem(node) {
      return h(Item, {
        "key": node.value,
        "attrs": {
          "node": node,
          "cascaderContext": cascaderContext
        },
        "props": _objectSpread({}, {
          node: node,
          cascaderContext: cascaderContext,
          onClick: function onClick() {
            emit("click", node.value, node);
            handleExpand(node, "click");
          },
          onMouseenter: function onMouseenter() {
            handleExpand(node, "hover");
          },
          onChange: function onChange() {
            valueChangeEffect(node, cascaderContext);
          }
        })
      });
    };

    var renderList = function renderList(treeNodes) {
      var _ref2;

      var isFilter = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
      var segment = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
      var key = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : "1";
      return h("ul", {
        "class": ["".concat(COMPONENT_NAME, "__menu"), "narrow-scrollbar", (_ref2 = {}, _defineProperty(_ref2, "".concat(COMPONENT_NAME, "__menu--segment"), segment), _defineProperty(_ref2, "".concat(COMPONENT_NAME, "__menu--filter"), isFilter), _ref2)],
        "key": key
      }, [treeNodes.map(function (node) {
        return renderItem(node);
      })]);
    };

    var renderPanels = function renderPanels() {
      var inputVal = cascaderContext.inputVal,
          treeNodes = cascaderContext.treeNodes;
      return inputVal ? renderList(treeNodes, true) : panels.map(function (treeNodes2, index) {
        return renderList(treeNodes2, false, index !== panels.length - 1, "".concat(COMPONENT_NAME, "__menu").concat(index));
      });
    };

    var content;

    if (this.loading) {
      content = renderTNodeJSXDefault("loadingText", h("div", {
        "class": "".concat(COMPONENT_NAME, "__panel--empty")
      }, [global.loadingText]));
    } else {
      content = panels.length ? renderPanels() : renderTNodeJSXDefault("empty", h("div", {
        "class": "".concat(COMPONENT_NAME, "__panel--empty")
      }, [global.empty]));
    }

    return h("div", {
      "class": ["".concat(COMPONENT_NAME, "__panel"), _defineProperty({}, "".concat(COMPONENT_NAME, "--normal"), panels.length && !this.loading)]
    }, [content]);
  }
});

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