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

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, computed } from '@vue/composition-api';
import props from '../props.js';
import { usePrefixClass } from '../../hooks/useConfig.js';
import { useTNodeDefault } from '../../hooks/tnode.js';
import { getPanels } from '../core/helper.js';
import { expendClickEffect, valueChangeEffect } from '../core/effect.js';
import Item from './Item.js';
import { useConfig } from '../../config-provider/useConfig.js';
import '../../config-provider/context.js';
import 'lodash/merge';
import 'lodash/mergeWith';
import '../../_common/js/global-config/default-config.js';
import '../../_common/js/global-config/locale/zh_CN.js';
import '@babel/runtime/helpers/typeof';
import '../../_chunks/dep-be599ec8.js';
import 'dayjs';
import '../../_chunks/dep-67ff4010.js';
import '../../config-provider/type.js';
import 'lodash/isEmpty';
import 'lodash/isFunction';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../../hooks/render-tnode.js';
import 'lodash/isString';
import 'lodash/isObject';
import '@babel/runtime/helpers/slicedToArray';
import 'lodash/isNumber';
import 'lodash/cloneDeep';
import '../../_chunks/dep-c89aafbb.js';
import '@ldesign/icons-vue';
import '../core/className.js';
import '@babel/runtime/helpers/toConsumableArray';
import '../../checkbox/index.js';
import '../../utils/map-props.js';
import '@babel/runtime/helpers/objectWithoutProperties';
import 'vue';
import '../../utils/withInstall.js';
import 'lodash/capitalize';
import '../../checkbox/group.js';
import 'lodash/intersection';
import '../../utils/event.js';
import '../../utils/helper.js';
import '../../config-provider/config-receiver.js';
import '../../utils/mixins.js';
import '../../checkbox/checkbox.js';
import '../../utils/render-tnode.js';
import '../../checkbox/props.js';
import '../../checkbox/checkbox-group-props.js';
import '../../checkbox/style/css.js';
import '../../checkbox/type.js';
import '../../loading/index.js';
import '../../loading/directive.js';
import 'lodash/mapKeys';
import 'lodash/isEqual';
import '../../loading/plugin.js';
import '../../config.js';
import '../../utils/dom.js';
import 'raf';
import '../../utils/easing.js';
import '../../loading/loading.js';
import '../../utils/transfer-dom.js';
import '../../loading/props.js';
import '../../loading/icon/gradient.js';
import '../../_common/js/loading/circle-adapter.js';
import '../../_common/js/utils/set-style.js';
import '../../_common/js/utils/helper.js';
import 'lodash/isNull';
import 'lodash/isUndefined';
import 'lodash/isArray';
import '../../loading/style/css.js';
import '../../loading/type.js';
import '../../hooks/useGlobalIcon.js';
import '../../utils/ripple.js';

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: "TCascaderSubPanel",
  props: {
    empty: props.empty,
    trigger: props.trigger,
    onChange: props.onChange,
    loading: props.loading,
    loadingText: props.loadingText,
    cascaderContext: {
      type: Object
    }
  },
  setup: function setup(props, _ref) {
    var emit = _ref.emit;
    var renderTNodeJSXDefault = useTNodeDefault();
    var COMPONENT_NAME = usePrefixClass("cascader");
    var _useConfig = useConfig("cascader"),
      global = _useConfig.global;
    var _props$cascaderContex = props.cascaderContext,
      valueType = _props$cascaderContex.valueType,
      cascaderValue = _props$cascaderContex.cascaderValue,
      treeStore = _props$cascaderContex.treeStore,
      multiple = _props$cascaderContex.multiple;
    var config = treeStore.config;
    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);
    };
    if (config.load && valueType === "full" && cascaderValue.length > 0) {
      var firstValue = multiple ? cascaderValue[0][0] : cascaderValue[0];
      var firstExpandNode = treeStore.nodes.find(function (node) {
        return node.value === firstValue;
      });
      handleExpand(firstExpandNode, "click");
    }
    return {
      global: global,
      panels: panels,
      handleExpand: handleExpand,
      renderTNodeJSXDefault: renderTNodeJSXDefault,
      COMPONENT_NAME: COMPONENT_NAME,
      emit: emit
    };
  },
  render: function render() {
    var _this = this;
    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 renderEmpty = function renderEmpty() {
      if (_this.empty && typeof _this.empty === "string") return h("div", {
        "class": "".concat(COMPONENT_NAME, "__panel--empty")
      }, [_this.empty]);
      return renderTNodeJSXDefault("empty", h("div", {
        "class": "".concat(COMPONENT_NAME, "__panel--empty")
      }, [global.empty]));
    };
    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() : renderEmpty();
    }
    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
