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

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var config = require('../../config.js');
var utils_renderTnode = require('../../utils/render-tnode.js');
var configProvider_configReceiver = require('../../config-provider/config-receiver.js');
var utils_mixins = require('../../utils/mixins.js');
var cascader_utils_panel = require('../utils/panel.js');
var cascader_components_Item = require('./Item.js');
var cascader_props = require('../props.js');
require('@babel/runtime/helpers/typeof');
require('vue');
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('@babel/runtime/helpers/slicedToArray');
require('lodash/isNumber');
require('../../_chunks/dep-99705d51.js');
require('tdesign-icons-vue');
require('../../utils/classnames.js');
require('../../utils/ripple.js');
require('../../_common/js/utils/set-style.js');
require('../utils/helper.js');
require('lodash/isEmpty');
require('../utils/item.js');
require('@babel/runtime/helpers/toConsumableArray');
require('../../loading/index.js');
require('../../loading/loading.js');
require('../../loading/icon/gradient.js');
require('../../_common/js/loading/circle-adapter.js');
require('../../_common/js/utils/helper.js');
require('@babel/runtime/helpers/objectWithoutProperties');
require('../../utils/dom.js');
require('raf');
require('lodash/isString');
require('../../utils/easing.js');
require('../../utils/transfer-dom.js');
require('../../loading/props.js');
require('../../utils/withInstall.js');
require('lodash/capitalize');
require('../../loading/plugin.js');
require('../../checkbox/index.js');
require('../../checkbox/group.js');
require('lodash/intersection');
require('../../checkbox/checkbox.js');
require('../../checkbox/props.js');
require('../../utils/helper.js');
require('lodash/camelCase');
require('../../utils/event.js');
require('../../checkbox/checkbox-group-props.js');
require('../../utils/map-props.js');
require('../../tooltip/index.js');
require('../../tooltip/tooltip.js');
require('lodash/isFunction');
require('../../tooltip/props.js');
require('../../popup/props.js');
require('../../popup/popup.js');
require('@popperjs/core');
require('../../popup/container.js');

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

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

var name = "".concat(config.prefix, "-cascader");
var Panel = utils_mixins["default"](configProvider_configReceiver["default"]("cascader")).extend({
  name: "".concat(name, "-panel"),
  props: {
    empty: cascader_props["default"].empty,
    trigger: cascader_props["default"].trigger,
    onChange: cascader_props["default"].onChange,
    cascaderContext: {
      type: Object
    }
  },
  computed: {
    panels: function panels() {
      return cascader_utils_panel.getPanels(this.cascaderContext.treeNodes);
    }
  },
  render: function render() {
    var _this = this;

    var h = arguments[0];
    var _this$cascaderContext = this.cascaderContext,
        filterActive = _this$cascaderContext.filterActive,
        treeNodes = _this$cascaderContext.treeNodes,
        inputWidth = _this$cascaderContext.inputWidth,
        cascaderContext = this.cascaderContext,
        panels = this.panels;

    var handleExpand = function handleExpand(ctx, trigger) {
      var node = ctx.node;
      var propsTrigger = _this.trigger,
          cascaderContext2 = _this.cascaderContext;
      cascader_utils_panel.expendClickEffect(propsTrigger, trigger, node, cascaderContext2);
    };

    var handleChange = function handleChange(ctx) {
      var node = ctx.node;
      var cascaderContext2 = _this.cascaderContext;
      cascader_utils_panel.valueChangeEffect(node, cascaderContext2);
    };

    var renderEmpty = utils_renderTnode.renderTNodeJSXDefault(this, "empty", h("div", {
      "class": "".concat(name, "__panel--empty")
    }, [this.t(this.global.empty)]));

    var renderItem = function renderItem(node) {
      return h(cascader_components_Item["default"], {
        "key": node.value,
        "attrs": {
          "node": node,
          "cascaderContext": cascaderContext
        },
        "on": {
          "click": function click(ctx) {
            handleExpand(ctx, "click");
          },
          "mouseenter": function mouseenter(ctx) {
            handleExpand(ctx, "hover");
          },
          "change": handleChange
        }
      });
    };

    var panelsContainer = panels.map(function (panel, index) {
      return h("ul", {
        "class": ["".concat(name, "__menu"), "narrow-scrollbar", _defineProperty__default["default"]({}, "".concat(name, "__menu--segment"), index !== panels.length - 1)],
        "key": index
      }, [panel.map(function (node) {
        return renderItem(node);
      })]);
    });
    var filterPanelsContainer = h("ul", {
      "class": ["".concat(name, "__menu"), "narrow-scrollbar", "".concat(name, "__menu--segment"), "".concat(name, "__menu--filter")]
    }, [treeNodes.map(function (node) {
      return renderItem(node);
    })]);
    var renderPanels = filterActive ? filterPanelsContainer : panelsContainer;
    return h("div", {
      "class": ["".concat(name, "__panel"), _defineProperty__default["default"]({}, "".concat(name, "--normal"), panels.length)],
      "style": {
        width: panels.length === 0 ? "".concat(inputWidth, "px") : null
      }
    }, [panels && panels.length ? renderPanels : renderEmpty]);
  }
});

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