/**
 * 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 VueCompositionAPI = require('@vue/composition-api');
var collapse_collapsePanelProps = require('./collapse-panel-props.js');
var commonComponents_fakeArrow = require('../common-components/fake-arrow.js');
var collapse_useCollapseAnimation = require('./useCollapseAnimation.js');
var utils_renderTnode = require('../utils/render-tnode.js');
var configProvider_useConfig = require('../config-provider/useConfig.js');
require('vue');
require('../config.js');
require('@babel/runtime/helpers/typeof');
require('lodash/cloneDeep');
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');

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) {
    var _toRefs = VueCompositionAPI.toRefs(props2),
        value = _toRefs.value,
        disabled = _toRefs.disabled,
        expandIcon = _toRefs.expandIcon;

    var componentName = configProvider_useConfig.usePrefixClass("collapse-panel");
    var disableClass = configProvider_useConfig.usePrefixClass("is-disabled");
    var clickableClass = configProvider_useConfig.usePrefixClass("is-clickable");
    var transitionClass = configProvider_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,
        expandIconAll = _inject.expandIcon;

    var innerValue = value.value || getUniqId();
    var showExpandIcon = VueCompositionAPI.computed(function () {
      return expandIcon.value === void 0 ? expandIconAll.value : expandIcon.value;
    });

    if (defaultExpandAll.value) {
      updateCollapseValue(innerValue);
    }

    var isDisabled = VueCompositionAPI.computed(function () {
      return disabled.value || disableAll.value;
    });
    var isActive = VueCompositionAPI.computed(function () {
      return collapseValue.value instanceof Array ? collapseValue.value.includes(innerValue) : collapseValue.value === innerValue;
    });
    var classes = VueCompositionAPI.computed(function () {
      return [componentName.value, _defineProperty__default["default"]({}, disableClass.value, isDisabled.value)];
    });
    return {
      isDisabled: isDisabled,
      classes: classes,
      isActive: isActive,
      updateCollapseValue: updateCollapseValue,
      innerValue: innerValue,
      expandIconPlacement: expandIconPlacement,
      expandOnRowClick: expandOnRowClick,
      componentName: componentName,
      clickableClass: clickableClass,
      transitionClass: transitionClass,
      showExpandIcon: showExpandIcon
    };
  },
  methods: {
    renderIcon: function renderIcon(direction) {
      var h = this.$createElement;
      return h(commonComponents_fakeArrow["default"], {
        "attrs": {
          "name": "arrow",
          "isActive": this.isActive,
          "overlayClassName": "".concat(this.componentName, "__icon ").concat(this.componentName, "__icon--").concat(direction)
        }
      });
    },
    renderHeader: function renderHeader() {
      var h = this.$createElement;
      var showExpandIcon = this.showExpandIcon,
          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", {
        "ref": "headRef",
        "class": cls,
        "on": {
          "click": handleClick
        }
      }, [showExpandIcon && this.expandIconPlacement === "left" ? renderIcon(this.expandIconPlacement) : null, utils_renderTnode.renderTNodeJSX(this, "header"), renderBlank(), utils_renderTnode.renderTNodeJSX(this, "headerRightContent"), showExpandIcon && this.expandIconPlacement === "right" ? renderIcon(this.expandIconPlacement) : null]);
    },
    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")
      }, [utils_renderTnode.renderTNodeJSX(this, "default")])]);
    },
    renderBodyDestroyOnCollapse: function renderBodyDestroyOnCollapse() {
      var h = this.$createElement;
      return this.isActive ? h("div", {
        "class": "".concat(this.componentName, "__body")
      }, [h("div", {
        "class": "".concat(this.componentName, "__content")
      }, [utils_renderTnode.renderTNodeJSX(this, "default")])]) : null;
    },
    handleClick: function handleClick(e) {
      var canExpand = this.expandOnRowClick && e.target === this.$refs.headRef || e.target.getAttribute("name") === "arrow";

      if (canExpand && !this.isDisabled) {
        this.updateCollapseValue(this.innerValue);
      }
    }
  },
  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
