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

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, toRefs, inject, ref, computed, createVNode, Transition, isVNode, withDirectives, vShow } from 'vue';
import FakeArrow from '../common-components/fake-arrow.js';
import { useTNodeJSX, useContent } from '../hooks/tnode.js';
import { usePrefixClass } from '../hooks/useConfig.js';
import props from './collapse-panel-props.js';
import useCollapseAnimation from './useCollapseAnimation.js';
import 'lodash/isFunction';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../utils/render-tnode.js';
import 'lodash/isEmpty';
import 'lodash/isString';
import 'lodash/isObject';
import '../config-provider/useConfig.js';
import 'lodash/cloneDeep';
import '../config-provider/context.js';
import 'lodash/mergeWith';
import 'lodash/merge';
import 'lodash/isArray';
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-e041f5b0.js';
import 'dayjs';

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.js.map
