/**
 * tdesign v0.46.4
 * (c) 2022 tdesign
 * @license MIT
 */

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var VueCompositionAPI = require('@vue/composition-api');
var cascader_components_Item = require('./Item.js');
var cascader_props = require('../props.js');
var hooks_useConfig = require('../../hooks/useConfig.js');
var hooks_tnode = require('../../hooks/tnode.js');
var cascader_core_helper = require('../core/helper.js');
var cascader_core_effect = require('../core/effect.js');
var configProvider_useConfig = require('../../config-provider/useConfig.js');
require('../../_chunks/dep-d7a1e02c.js');
require('tdesign-icons-vue');
require('../core/className.js');
require('@babel/runtime/helpers/toConsumableArray');
require('../../checkbox/index.js');
require('../../checkbox/group.js');
require('@babel/runtime/helpers/typeof');
require('lodash/intersection');
require('../../checkbox/checkbox.js');
require('vue');
require('../../utils/render-tnode.js');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../../checkbox/props.js');
require('../../utils/helper.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('@babel/runtime/helpers/slicedToArray');
require('../../utils/event.js');
require('../../config-provider/config-receiver.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('../../utils/mixins.js');
require('../../checkbox/checkbox-group-props.js');
require('../../utils/map-props.js');
require('../../utils/withInstall.js');
require('lodash/capitalize');
require('../../loading/index.js');
require('../../loading/loading.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('../../utils/dom.js');
require('raf');
require('lodash/isString');
require('../../utils/easing.js');
require('../../utils/transfer-dom.js');
require('../../loading/props.js');
require('../../loading/plugin.js');
require('../../config.js');
require('../../hooks/useGlobalIcon.js');
require('../../utils/ripple.js');
require('lodash/isEmpty');
require('lodash/isFunction');
require('../../hooks/render-tnode.js');
require('lodash/isObject');
require('lodash/isNumber');
require('lodash/cloneDeep');

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 Panel = VueCompositionAPI.defineComponent({
  name: "TCascaderSubPanel",
  props: {
    empty: cascader_props["default"].empty,
    trigger: cascader_props["default"].trigger,
    onChange: cascader_props["default"].onChange,
    loading: cascader_props["default"].loading,
    loadingText: cascader_props["default"].loadingText,
    cascaderContext: {
      type: Object
    }
  },
  setup: function setup(props, _ref) {
    var emit = _ref.emit;
    var renderTNodeJSXDefault = hooks_tnode.useTNodeDefault();
    var COMPONENT_NAME = hooks_useConfig.usePrefixClass("cascader");

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

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

    var handleExpand = function handleExpand(node, trigger) {
      var propsTrigger = props.trigger,
          cascaderContext = props.cascaderContext;
      cascader_core_effect.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(cascader_components_Item["default"], {
        "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() {
            cascader_core_effect.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__default["default"](_ref2, "".concat(COMPONENT_NAME, "__menu--segment"), segment), _defineProperty__default["default"](_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__default["default"]({}, "".concat(COMPONENT_NAME, "--normal"), panels.length && !this.loading)]
    }, [content]);
  }
});

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