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

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var vue = require('vue');
var commonComponents_fakeArrow = require('../common-components/fake-arrow.js');
var hooks_tnode = require('../hooks/tnode.js');
var hooks_useConfig = require('../hooks/useConfig.js');
var collapse_collapsePanelProps = require('./collapse-panel-props.js');
var collapse_useCollapseAnimation = require('./useCollapseAnimation.js');
require('lodash/isFunction');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../utils/render-tnode.js');
require('lodash/isEmpty');
require('lodash/isString');
require('lodash/isObject');
require('../config-provider/useConfig.js');
require('lodash/cloneDeep');
require('../config-provider/context.js');
require('lodash/mergeWith');
require('lodash/merge');
require('lodash/isArray');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');
require('@babel/runtime/helpers/typeof');
require('../_chunks/dep-7f0559c3.js');
require('dayjs');

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

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

function _isSlot(s) {
  return typeof s === 'function' || Object.prototype.toString.call(s) === '[object Object]' && !vue.isVNode(s);
}
var _CollapsePanel = vue.defineComponent({
  name: "TCollapsePanel",
  props: collapse_collapsePanelProps["default"],
  setup: function setup(props2, _ref) {
    var slots = _ref.slots;
    var renderTNodeJSX = hooks_tnode.useTNodeJSX();
    var renderContent = hooks_tnode.useContent();
    var componentName = hooks_useConfig.usePrefixClass("collapse-panel");
    var disableClass = hooks_useConfig.usePrefixClass("is-disabled");
    var clickableClass = hooks_useConfig.usePrefixClass("is-clickable");
    var transitionClass = hooks_useConfig.usePrefixClass("slide-down");
    var _toRefs = vue.toRefs(props2),
      value = _toRefs.value,
      disabled = _toRefs.disabled,
      destroyOnCollapse = _toRefs.destroyOnCollapse;
    var collapseValue = vue.inject("collapseValue");
    var updateCollapseValue = vue.inject("updateCollapseValue");
    var getUniqId = vue.inject("getUniqId", function () {
      return void 0;
    }, false);
    var _inject = vue.inject("collapseProps"),
      defaultExpandAll = _inject.defaultExpandAll,
      disableAll = _inject.disabled,
      expandIconPlacement = _inject.expandIconPlacement,
      expandOnRowClick = _inject.expandOnRowClick;
    var renderParentTNode = vue.inject("renderParentTNode");
    var innerValue = value.value || getUniqId();
    if (defaultExpandAll.value) updateCollapseValue(innerValue);
    var _useCollapseAnimation = collapse_useCollapseAnimation["default"](),
      beforeEnter = _useCollapseAnimation.beforeEnter,
      enter = _useCollapseAnimation.enter,
      afterEnter = _useCollapseAnimation.afterEnter,
      beforeLeave = _useCollapseAnimation.beforeLeave,
      leave = _useCollapseAnimation.leave,
      afterLeave = _useCollapseAnimation.afterLeave;
    var iconRef = vue.ref();
    var isDisabled = vue.computed(function () {
      return disabled.value || disableAll.value;
    });
    var isActive = vue.computed(function () {
      return Array.isArray(collapseValue.value) ? collapseValue.value.includes(innerValue) : collapseValue.value === innerValue;
    });
    var classes = vue.computed(function () {
      return [componentName.value, _defineProperty__default["default"]({}, disableClass.value, isDisabled.value)];
    });
    var panelExpandIcon = vue.computed(function () {
      return slots.expandIcon || props2.expandIcon;
    });
    var handleClick = function handleClick(e) {
      var canExpand = expandOnRowClick.value || e.currentTarget === iconRef.value;
      if (canExpand && !isDisabled.value) updateCollapseValue(innerValue);
      e.stopPropagation();
    };
    var renderDefaultIcon = function renderDefaultIcon() {
      return vue.createVNode(commonComponents_fakeArrow["default"], {
        "overlayClassName": "".concat(componentName.value, "__icon--default")
      }, null);
    };
    var renderIcon = function renderIcon() {
      var tNodeRender = panelExpandIcon.value === void 0 ? renderParentTNode : renderTNodeJSX;
      return vue.createVNode("div", {
        "ref": iconRef,
        "class": "".concat(componentName.value, "__icon ").concat(componentName.value, "__icon--").concat(expandIconPlacement.value, " ").concat(isActive.value ? "".concat(componentName.value, "__icon--active") : ""),
        "onClick": handleClick
      }, [tNodeRender("expandIcon", renderDefaultIcon())]);
    };
    var renderBlank = function renderBlank() {
      return vue.createVNode("div", {
        "class": "".concat(componentName.value, "__header--blank")
      }, null);
    };
    var renderHeader = function renderHeader() {
      var cls = ["".concat(componentName.value, "__header"), _defineProperty__default["default"]({}, clickableClass.value, expandOnRowClick.value && !isDisabled.value)];
      return vue.createVNode("div", {
        "class": cls,
        "onClick": handleClick
      }, [expandIconPlacement.value === "left" && renderIcon(), renderTNodeJSX("header"), renderBlank(), renderTNodeJSX("headerRightContent"), expandIconPlacement.value === "right" && renderIcon()]);
    };
    var renderBodyByNormal = function renderBodyByNormal() {
      return vue.withDirectives(vue.createVNode("div", {
        "class": "".concat(componentName.value, "__body")
      }, [vue.createVNode("div", {
        "class": "".concat(componentName.value, "__content")
      }, [renderContent("default", "content")])]), [[vue.vShow, isActive.value]]);
    };
    var renderBodyDestroyOnCollapse = function renderBodyDestroyOnCollapse() {
      return isActive.value ? vue.createVNode("div", {
        "class": "".concat(componentName.value, "__body")
      }, [vue.createVNode("div", {
        "class": "".concat(componentName.value, "__content")
      }, [renderContent("default", "content")])]) : null;
    };
    var renderBody = function renderBody() {
      return destroyOnCollapse.value ? renderBodyDestroyOnCollapse() : renderBodyByNormal();
    };
    return function () {
      var _slot;
      return vue.createVNode("div", {
        "class": classes.value
      }, [vue.createVNode("div", {
        "class": "".concat(componentName.value, "__wrapper")
      }, [renderHeader(), vue.createVNode(vue.Transition, {
        "name": transitionClass.value,
        "onBeforeEnter": beforeEnter,
        "onEnter": enter,
        "onAfterEnter": afterEnter,
        "onBeforeLeave": beforeLeave,
        "onLeave": leave,
        "onAfterLeave": afterLeave
      }, _isSlot(_slot = renderBody()) ? _slot : {
        "default": function _default() {
          return [_slot];
        }
      })])]);
    };
  }
});

exports["default"] = _CollapsePanel;
//# sourceMappingURL=collapse-panel.js.map
