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

'use strict';

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

var VueCompositionAPI = require('@vue/composition-api');
var components_collapse_props = require('./props.js');
var components_common_fakeArrow = require('../common/fake-arrow.js');
var hooks_useConfig = require('../../hooks/use-config.js');
var components_collapse_hooks_index = require('./hooks/index.js');
var utils_renderNode = require('../../utils/render-node.js');
require('../config-provider/config-receiver.js');
require('vue');
require('lodash/mergeWith');
require('lodash');
require('../config-provider/context.js');
require('../../chunks/zh_CN.js');
require('../../utils/mixins.js');
require('../config-provider/useConfig.js');
require('lodash/camelCase');
require('lodash/kebabCase');

var _CollapsePanel = VueCompositionAPI.defineComponent({
  name: "LCollapsePanel",
  props: components_collapse_props.CollapsePanelProps,
  components: {
    LFakeArrow: components_common_fakeArrow["default"]
  },

  setup(props2) {
    const {
      value,
      disabled,
      expandIcon
    } = VueCompositionAPI.toRefs(props2);
    const componentName = hooks_useConfig.usePrefixClass("collapse-panel");
    const disableClass = hooks_useConfig.usePrefixClass("is-disabled");
    const clickableClass = hooks_useConfig.usePrefixClass("is-clickable");
    const transitionClass = hooks_useConfig.usePrefixClass("slide-down");
    const collapseValue = VueCompositionAPI.inject("collapseValue");
    const updateCollapseValue = VueCompositionAPI.inject("updateCollapseValue");
    const getUniqId = VueCompositionAPI.inject("getUniqId", () => void 0, false);
    const {
      defaultExpandAll,
      disabled: disableAll,
      expandIconPlacement,
      expandOnRowClick,
      expandIcon: expandIconAll
    } = VueCompositionAPI.inject("collapseProps");
    const innerValue = value.value || getUniqId();
    const showExpandIcon = VueCompositionAPI.computed(() => expandIcon.value === void 0 ? expandIconAll.value : expandIcon.value);

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

    const isDisabled = VueCompositionAPI.computed(() => disabled.value || disableAll.value);
    const isActive = VueCompositionAPI.computed(() => collapseValue.value instanceof Array ? collapseValue.value.includes(innerValue) : collapseValue.value === innerValue);
    const classes = VueCompositionAPI.computed(() => [componentName.value, {
      [disableClass.value]: isDisabled.value
    }]);
    return {
      isDisabled,
      classes,
      isActive,
      updateCollapseValue,
      innerValue,
      expandIconPlacement,
      expandOnRowClick,
      componentName,
      clickableClass,
      transitionClass,
      showExpandIcon
    };
  },

  methods: {
    renderIcon(direction) {
      const h = this.$createElement;
      return h("l-fake-arrow", {
        "attrs": {
          "name": "arrow",
          "isActive": this.isActive,
          "overlayClassName": `${this.componentName}__icon ${this.componentName}__icon--${direction}`
        }
      });
    },

    renderHeader() {
      const h = this.$createElement;
      const {
        showExpandIcon,
        isDisabled,
        handleClick,
        renderIcon,
        renderBlank
      } = this;
      const cls = [`${this.componentName}__header`, {
        [this.clickableClass]: this.expandOnRowClick && !isDisabled
      }];
      return h("div", {
        "ref": "headRef",
        "class": cls,
        "on": {
          "click": handleClick
        }
      }, [h("div", {
        "class": `${this.componentName}__header-left`
      }, [showExpandIcon && this.expandIconPlacement === "left" ? renderIcon(this.expandIconPlacement) : null]), h("div", {
        "class": `${this.componentName}__header-content`
      }, [utils_renderNode.renderLNodeJSX(this, "header")]), renderBlank(), h("div", {
        "class": `${this.componentName}__header-right`
      }, [utils_renderNode.renderLNodeJSX(this, "headerRightContent"), showExpandIcon && this.expandIconPlacement === "right" ? renderIcon(this.expandIconPlacement) : null])]);
    },

    renderBlank() {
      const h = this.$createElement;
      return h("div", {
        "class": `${this.componentName}__header--blank`
      });
    },

    renderBody() {
      return this.destroyOnCollapse ? this.renderBodyDestroyOnCollapse() : this.renderBodyByNormal();
    },

    renderBodyByNormal() {
      const h = this.$createElement;
      return h("div", {
        "directives": [{
          name: "show",
          value: this.isActive
        }],
        "class": `${this.componentName}__body`
      }, [h("div", {
        "class": `${this.componentName}__content`
      }, [utils_renderNode.renderLNodeJSX(this, "default")])]);
    },

    renderBodyDestroyOnCollapse() {
      const h = this.$createElement;
      return this.isActive ? h("div", {
        "class": `${this.componentName}__body`
      }, [h("div", {
        "class": `${this.componentName}__content`
      }, [utils_renderNode.renderLNodeJSX(this, "default")])]) : null;
    },

    handleClick(e) {
      const canExpand = this.expandOnRowClick && e.target === this.$refs.headRef || e.target.getAttribute("name") === "arrow";

      if (canExpand && !this.isDisabled) {
        this.updateCollapseValue(this.innerValue);
      }
    }

  },

  render() {
    const h = arguments[0];
    const {
      beforeEnter,
      enter,
      afterEnter,
      beforeLeave,
      leave,
      afterLeave
    } = components_collapse_hooks_index["default"]();
    const {
      classes
    } = this;
    return h("div", {
      "class": classes
    }, [h("div", {
      "class": `${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
