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

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var VueCompositionAPI = require('@vue/composition-api');
var commonComponents_fakeArrow = require('../common-components/fake-arrow.js');
var hooks_useConfig = require('../hooks/useConfig.js');
var hooks_tnode = require('../hooks/tnode.js');
var collapse_collapsePanelProps = require('./collapse-panel-props.js');
var collapse_useCollapseAnimation = require('./useCollapseAnimation.js');
require('../config-provider/config-receiver.js');
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/typeof');
require('../_chunks/dep-7c884501.js');
require('dayjs');
require('../utils/mixins.js');
require('../config-provider/useConfig.js');
require('lodash/isEmpty');
require('lodash/isFunction');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../hooks/render-tnode.js');
require('lodash/isString');
require('lodash/isObject');

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

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

var _CollapsePanel = VueCompositionAPI.defineComponent({
  name: "TCollapsePanel",
  props: collapse_collapsePanelProps["default"],
  setup: function setup(props2, _ref) {
    var slots = _ref.slots;
    var _toRefs = VueCompositionAPI.toRefs(props2),
      value = _toRefs.value,
      disabled = _toRefs.disabled;
    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 collapseValue = VueCompositionAPI.inject("collapseValue");
    var updateCollapseValue = VueCompositionAPI.inject("updateCollapseValue");
    var getUniqId = VueCompositionAPI.inject("getUniqId", function () {
      return void 0;
    }, false);
    var _inject = VueCompositionAPI.inject("collapseProps"),
      defaultExpandAll = _inject.defaultExpandAll,
      disableAll = _inject.disabled,
      expandIconPlacement = _inject.expandIconPlacement,
      expandOnRowClick = _inject.expandOnRowClick;
    var renderParentTNode = VueCompositionAPI.inject("renderParentTNode");
    var innerValue = value.value === void 0 ? getUniqId() : value.value;
    if (defaultExpandAll.value) updateCollapseValue(innerValue);
    var isDisabled = VueCompositionAPI.computed(function () {
      return disabled.value || disableAll.value;
    });
    var isActive = VueCompositionAPI.computed(function () {
      return Array.isArray(collapseValue.value) ? collapseValue.value.includes(innerValue) : collapseValue.value === innerValue;
    });
    var classes = VueCompositionAPI.computed(function () {
      return [componentName.value, _defineProperty__default["default"]({}, disableClass.value, isDisabled.value)];
    });
    var panelExpandIcon = VueCompositionAPI.computed(function () {
      return slots.expandIcon || props2.expandIcon;
    });
    var renderTNodeJSX = hooks_tnode.useTNodeJSX();
    var renderContent = hooks_tnode.useContent();
    return {
      isDisabled: isDisabled,
      classes: classes,
      isActive: isActive,
      updateCollapseValue: updateCollapseValue,
      innerValue: innerValue,
      expandIconPlacement: expandIconPlacement,
      expandOnRowClick: expandOnRowClick,
      componentName: componentName,
      clickableClass: clickableClass,
      transitionClass: transitionClass,
      panelExpandIcon: panelExpandIcon,
      renderParentTNode: renderParentTNode,
      renderTNodeJSX: renderTNodeJSX,
      renderContent: renderContent
    };
  },
  methods: {
    renderDefaultIcon: function renderDefaultIcon() {
      var h = this.$createElement;
      var componentName = this.componentName;
      return h(commonComponents_fakeArrow["default"], {
        "attrs": {
          "overlayClassName": "".concat(componentName, "__icon--default")
        }
      });
    },
    renderIcon: function renderIcon() {
      var h = this.$createElement;
      var panelExpandIcon = this.panelExpandIcon,
        renderParentTNode = this.renderParentTNode,
        componentName = this.componentName,
        expandIconPlacement = this.expandIconPlacement,
        isActive = this.isActive,
        handleClick = this.handleClick,
        renderDefaultIcon = this.renderDefaultIcon,
        renderTNodeJSX = this.renderTNodeJSX;
      var tNodeRender = panelExpandIcon === void 0 ? renderParentTNode : renderTNodeJSX;
      return h("div", {
        "ref": "iconRef",
        "class": "".concat(componentName, "__icon ").concat(componentName, "__icon--").concat(expandIconPlacement, " ").concat(isActive ? "".concat(componentName, "__icon--active") : ""),
        "on": {
          "click": handleClick
        }
      }, [tNodeRender("expandIcon", renderDefaultIcon())]);
    },
    renderHeader: function renderHeader() {
      var h = this.$createElement;
      var isDisabled = this.isDisabled,
        handleClick = this.handleClick,
        renderIcon = this.renderIcon,
        renderBlank = this.renderBlank;
      var cls = ["".concat(this.componentName, "__header"), _defineProperty__default["default"]({}, this.clickableClass, this.expandOnRowClick && !isDisabled)];
      return h("div", {
        "class": cls,
        "on": {
          "click": handleClick
        }
      }, [h("div", {
        "class": "".concat(this.componentName, "__header-left")
      }, [this.expandIconPlacement === "left" && renderIcon()]), h("div", {
        "class": "".concat(this.componentName, "__header-content")
      }, [this.renderTNodeJSX("header")]), renderBlank(), h("div", {
        "class": "".concat(this.componentName, "__header-right")
      }, [h("div", {
        "class": "".concat(this.componentName, "__header-right-content"),
        "on": {
          "click": function click(e) {
            return e.stopPropagation();
          }
        }
      }, [this.renderTNodeJSX("headerRightContent")]), this.expandIconPlacement === "right" && renderIcon()])]);
    },
    renderBlank: function renderBlank() {
      var h = this.$createElement;
      return h("div", {
        "class": "".concat(this.componentName, "__header--blank")
      });
    },
    renderBody: function renderBody() {
      return this.destroyOnCollapse ? this.renderBodyDestroyOnCollapse() : this.renderBodyByNormal();
    },
    renderBodyByNormal: function renderBodyByNormal() {
      var h = this.$createElement;
      return h("div", {
        "directives": [{
          name: "show",
          value: this.isActive
        }],
        "class": "".concat(this.componentName, "__body")
      }, [h("div", {
        "class": "".concat(this.componentName, "__content")
      }, [this.renderContent("default", "content")])]);
    },
    renderBodyDestroyOnCollapse: function renderBodyDestroyOnCollapse() {
      var h = this.$createElement;
      return this.isActive ? h("div", {
        "class": "".concat(this.componentName, "__body")
      }, [h("div", {
        "class": "".concat(this.componentName, "__content")
      }, [this.renderContent("default", "content")])]) : null;
    },
    handleClick: function handleClick(e) {
      var expandOnRowClick = this.expandOnRowClick,
        updateCollapseValue = this.updateCollapseValue,
        innerValue = this.innerValue,
        isDisabled = this.isDisabled;
      var canExpand = expandOnRowClick || e.currentTarget === this.$refs.iconRef;
      if (canExpand && !isDisabled) updateCollapseValue(innerValue);
      e.stopPropagation();
    }
  },
  render: function render() {
    var h = arguments[0];
    var _useCollapseAnimation = collapse_useCollapseAnimation["default"](),
      beforeEnter = _useCollapseAnimation.beforeEnter,
      enter = _useCollapseAnimation.enter,
      afterEnter = _useCollapseAnimation.afterEnter,
      beforeLeave = _useCollapseAnimation.beforeLeave,
      leave = _useCollapseAnimation.leave,
      afterLeave = _useCollapseAnimation.afterLeave;
    var classes = this.classes;
    return h("div", {
      "class": classes
    }, [h("div", {
      "class": "".concat(this.componentName, "__wrapper")
    }, [this.renderHeader(), h("transition", {
      "attrs": {
        "name": this.transitionClass
      },
      "on": {
        "beforeEnter": beforeEnter,
        "enter": enter,
        "afterEnter": afterEnter,
        "beforeLeave": beforeLeave,
        "leave": leave,
        "afterLeave": afterLeave
      }
    }, [this.renderBody()])])]);
  }
});

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