/**
 * ldesign v0.2.2
 * (c) 2022年9月20日 swimly
 * @license MIT
 */

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, toRefs, inject, computed } from '@vue/composition-api';
import { CollapsePanelProps } from './props.js';
import LFakeArrow from '../common/fake-arrow.js';
import { usePrefixClass } from '../../hooks/use-config.js';
import useCollapseAnimation from './hooks/index.js';
import { renderLNodeJSX } from '../../utils/render-node.js';
import '../config-provider/config-receiver.js';
import 'vue';
import 'lodash/mergeWith';
import 'lodash';
import '../config-provider/context.js';
import '../../_chunks/dep-a0f2090c.js';
import '../../utils/mixins.js';
import '../config-provider/useConfig.js';
import '@babel/runtime/helpers/typeof';
import 'lodash/camelCase';
import 'lodash/kebabCase';

var _CollapsePanel = defineComponent({
  name: "LCollapsePanel",
  props: CollapsePanelProps,
  components: {
    LFakeArrow: LFakeArrow
  },
  setup: function setup(props2) {
    var _toRefs = toRefs(props2),
        value = _toRefs.value,
        disabled = _toRefs.disabled,
        expandIcon = _toRefs.expandIcon;

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

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

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

    var isDisabled = computed(function () {
      return disabled.value || disableAll.value;
    });
    var isActive = computed(function () {
      return collapseValue.value instanceof Array ? collapseValue.value.includes(innerValue) : collapseValue.value === innerValue;
    });
    var classes = computed(function () {
      return [componentName.value, _defineProperty({}, 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("l-fake-arrow", {
        "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({}, this.clickableClass, this.expandOnRowClick && !isDisabled)];
      return h("div", {
        "ref": "headRef",
        "class": cls,
        "on": {
          "click": handleClick
        }
      }, [showExpandIcon && this.expandIconPlacement === "left" ? renderIcon(this.expandIconPlacement) : null, renderLNodeJSX(this, "header"), renderBlank(), renderLNodeJSX(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")
      }, [renderLNodeJSX(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")
      }, [renderLNodeJSX(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 = useCollapseAnimation(),
        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()])])]);
  }
});

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