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

import { _ as _defineProperty } from '../_chunks/dep-2db7b3ec.mjs';
import { isVNode, defineComponent, toRefs, inject, ref, computed, createVNode, withDirectives, vShow, Transition } from 'vue';
import FakeArrow from '../common-components/fake-arrow.mjs';
import { useTNodeJSX, useContent } from '../hooks/tnode.mjs';
import { usePrefixClass } from '../hooks/useConfig.mjs';
import props from './collapse-panel-props.mjs';
import useCollapseAnimation from './useCollapseAnimation.mjs';
import '../_chunks/dep-255303ba.mjs';
import '../_chunks/dep-5717e263.mjs';
import '../_chunks/dep-eba0ea6e.mjs';
import '../_chunks/dep-469b4ae0.mjs';
import '../_chunks/dep-a8bcacea.mjs';
import '../_chunks/dep-406cd044.mjs';
import '../_chunks/dep-42cc3015.mjs';
import '../_chunks/dep-b57180d0.mjs';
import '../_chunks/dep-c8d7b6b4.mjs';
import '../_chunks/dep-2bc37d52.mjs';
import '../_chunks/dep-3da99438.mjs';
import '../_chunks/dep-327559e8.mjs';
import '../_chunks/dep-b2235f26.mjs';
import '../_chunks/dep-8b989474.mjs';
import '../_chunks/dep-1372b2d3.mjs';
import '../_chunks/dep-9a85dac1.mjs';
import '../utils/render-tnode.mjs';
import '../_chunks/dep-888e80c4.mjs';
import '../_chunks/dep-334a4f6b.mjs';
import '../_chunks/dep-e5eb9f23.mjs';
import '../_chunks/dep-9fe2ef12.mjs';
import '../_chunks/dep-672e7d1a.mjs';
import '../_chunks/dep-4d7a675b.mjs';
import '../_chunks/dep-2e7f59b1.mjs';
import '../_chunks/dep-1434aa15.mjs';
import '../_chunks/dep-9262ee2f.mjs';
import '../_chunks/dep-876fb3ec.mjs';
import '../config-provider/useConfig.mjs';
import '../_chunks/dep-095107f7.mjs';
import '../_chunks/dep-c989dff3.mjs';
import '../_chunks/dep-9cf86cf1.mjs';
import '../_chunks/dep-bc1d737a.mjs';
import '../_chunks/dep-855db8bc.mjs';
import '../_chunks/dep-a87f3e4c.mjs';
import '../_chunks/dep-1e566bb5.mjs';
import '../_chunks/dep-42a19209.mjs';
import '../_chunks/dep-8d3e9aa3.mjs';
import '../_chunks/dep-40d69a9c.mjs';
import '../_chunks/dep-dcc83161.mjs';
import '../_chunks/dep-0fc02184.mjs';
import '../_chunks/dep-f1994936.mjs';
import '../_chunks/dep-345e1be3.mjs';
import '../_common/js/global-config/default-config.mjs';
import '../_common/js/global-config/locale/zh_CN.mjs';
import '../_chunks/dep-9888611c.mjs';
import '../_chunks/dep-697a1365.mjs';
import '../config-provider/type.mjs';

function _isSlot(s) {
  return typeof s === 'function' || Object.prototype.toString.call(s) === '[object Object]' && !isVNode(s);
}
var _CollapsePanel = defineComponent({
  name: "TCollapsePanel",
  props: props,
  setup: function setup(props2, _ref) {
    var slots = _ref.slots;
    var renderTNodeJSX = useTNodeJSX();
    var renderContent = useContent();
    var componentName = usePrefixClass("collapse-panel");
    var disableClass = usePrefixClass("is-disabled");
    var clickableClass = usePrefixClass("is-clickable");
    var transitionClass = usePrefixClass("slide-down");
    var _toRefs = toRefs(props2),
      value = _toRefs.value,
      disabled = _toRefs.disabled,
      destroyOnCollapse = _toRefs.destroyOnCollapse;
    var collapseValue = inject("collapseValue");
    var updateCollapseValue = inject("updateCollapseValue");
    var getUniqId = inject("getUniqId", function () {
      return void 0;
    }, false);
    var _inject = inject("collapseProps"),
      defaultExpandAll = _inject.defaultExpandAll,
      disableAll = _inject.disabled,
      expandIconPlacement = _inject.expandIconPlacement,
      expandOnRowClick = _inject.expandOnRowClick;
    var renderParentTNode = inject("renderParentTNode");
    var innerValue = value.value || getUniqId();
    if (defaultExpandAll.value) updateCollapseValue(innerValue);
    var _useCollapseAnimation = useCollapseAnimation(),
      beforeEnter = _useCollapseAnimation.beforeEnter,
      enter = _useCollapseAnimation.enter,
      afterEnter = _useCollapseAnimation.afterEnter,
      beforeLeave = _useCollapseAnimation.beforeLeave,
      leave = _useCollapseAnimation.leave,
      afterLeave = _useCollapseAnimation.afterLeave;
    var iconRef = ref();
    var isDisabled = computed(function () {
      return disabled.value || disableAll.value;
    });
    var isActive = computed(function () {
      return Array.isArray(collapseValue.value) ? collapseValue.value.includes(innerValue) : collapseValue.value === innerValue;
    });
    var classes = computed(function () {
      return [componentName.value, _defineProperty({}, disableClass.value, isDisabled.value)];
    });
    var panelExpandIcon = 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 createVNode(FakeArrow, {
        "overlayClassName": "".concat(componentName.value, "__icon--default")
      }, null);
    };
    var renderIcon = function renderIcon() {
      var tNodeRender = panelExpandIcon.value === void 0 ? renderParentTNode : renderTNodeJSX;
      return 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 createVNode("div", {
        "class": "".concat(componentName.value, "__header--blank")
      }, null);
    };
    var renderHeader = function renderHeader() {
      var cls = ["".concat(componentName.value, "__header"), _defineProperty({}, clickableClass.value, expandOnRowClick.value && !isDisabled.value)];
      return createVNode("div", {
        "class": cls,
        "onClick": handleClick
      }, [expandIconPlacement.value === "left" && renderIcon(), renderTNodeJSX("header"), renderBlank(), renderTNodeJSX("headerRightContent"), expandIconPlacement.value === "right" && renderIcon()]);
    };
    var renderBodyByNormal = function renderBodyByNormal() {
      return withDirectives(createVNode("div", {
        "class": "".concat(componentName.value, "__body")
      }, [createVNode("div", {
        "class": "".concat(componentName.value, "__content")
      }, [renderContent("default", "content")])]), [[vShow, isActive.value]]);
    };
    var renderBodyDestroyOnCollapse = function renderBodyDestroyOnCollapse() {
      return isActive.value ? createVNode("div", {
        "class": "".concat(componentName.value, "__body")
      }, [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 createVNode("div", {
        "class": classes.value
      }, [createVNode("div", {
        "class": "".concat(componentName.value, "__wrapper")
      }, [renderHeader(), createVNode(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];
        }
      })])]);
    };
  }
});

export { _CollapsePanel as default };
//# sourceMappingURL=collapse-panel.mjs.map
