/**
 * ldesign v0.2.14
 * (c) 2022/11/2 16:16 built by swimly
 * @license MIT
 */

'use strict';

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

var VueCompositionAPI = require('@vue/composition-api');
var components_common_fakeArrow = require('../common/fake-arrow.js');
var hooks_useConfig = require('../../hooks/use-config.js');
var hooks_lnode = require('../../hooks/lnode.js');
var components_collapse_props = require('./props.js');
var components_collapse_hooks_index = require('./hooks/index.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/isEmpty');
require('lodash/isFunction');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../../hooks/render-lnode.js');

var _CollapsePanel = VueCompositionAPI.defineComponent({
  name: "LCollapsePanel",
  props: components_collapse_props.CollapsePanelProps,
  setup(props2, _ref) {
    let {
      slots
    } = _ref;
    const {
      value,
      disabled
    } = 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
    } = VueCompositionAPI.inject("collapseProps");
    const renderParentTNode = VueCompositionAPI.inject("renderParentTNode");
    const innerValue = value.value || getUniqId();
    if (defaultExpandAll.value) updateCollapseValue(innerValue);
    const isDisabled = VueCompositionAPI.computed(() => disabled.value || disableAll.value);
    const isActive = VueCompositionAPI.computed(() => Array.isArray(collapseValue.value) ? collapseValue.value.includes(innerValue) : collapseValue.value === innerValue);
    const classes = VueCompositionAPI.computed(() => [componentName.value, {
      [disableClass.value]: isDisabled.value
    }]);
    const panelExpandIcon = VueCompositionAPI.computed(() => slots.expandIcon || props2.expandIcon);
    const renderTNodeJSX = hooks_lnode.useLNodeJSX();
    const renderContent = hooks_lnode.useContent();
    return {
      isDisabled,
      classes,
      isActive,
      updateCollapseValue,
      innerValue,
      expandIconPlacement,
      expandOnRowClick,
      componentName,
      clickableClass,
      transitionClass,
      panelExpandIcon,
      renderParentTNode,
      renderTNodeJSX,
      renderContent
    };
  },
  methods: {
    renderDefaultIcon() {
      const h = this.$createElement;
      const {
        componentName
      } = this;
      return h(components_common_fakeArrow["default"], {
        "attrs": {
          "overlayClassName": `${componentName}__icon--default`
        }
      });
    },
    renderIcon() {
      const h = this.$createElement;
      const {
        panelExpandIcon,
        renderParentTNode,
        componentName,
        expandIconPlacement,
        isActive,
        handleClick,
        renderDefaultIcon,
        renderTNodeJSX
      } = this;
      const tNodeRender = panelExpandIcon === void 0 ? renderParentTNode : renderTNodeJSX;
      return h("div", {
        "ref": "iconRef",
        "class": `${componentName}__icon ${componentName}__icon--${expandIconPlacement} ${isActive ? `${componentName}__icon--active` : ""}`,
        "on": {
          "click": handleClick
        }
      }, [tNodeRender("expandIcon", renderDefaultIcon())]);
    },
    renderHeader() {
      const h = this.$createElement;
      const {
        isDisabled,
        handleClick,
        renderIcon,
        renderBlank
      } = this;
      const cls = [`${this.componentName}__header`, {
        [this.clickableClass]: this.expandOnRowClick && !isDisabled
      }];
      return h("div", {
        "class": cls,
        "on": {
          "click": handleClick
        }
      }, [h("div", {
        "class": `${this.componentName}__header-left`
      }, [this.expandIconPlacement === "left" && renderIcon()]), h("div", {
        "class": `${this.componentName}__header-content`
      }, [this.renderTNodeJSX("header")]), renderBlank(), h("div", {
        "class": `${this.componentName}__header-right`
      }, [h("div", {
        "class": `${this.componentName}__header-right-content`,
        "on": {
          "click": e => e.stopPropagation()
        }
      }, [this.renderTNodeJSX("headerRightContent")]), this.expandIconPlacement === "right" && renderIcon()])]);
    },
    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`
      }, [this.renderContent("default", "content")])]);
    },
    renderBodyDestroyOnCollapse() {
      const h = this.$createElement;
      return this.isActive ? h("div", {
        "class": `${this.componentName}__body`
      }, [h("div", {
        "class": `${this.componentName}__content`
      }, [this.renderContent("default", "content")])]) : null;
    },
    handleClick(e) {
      const {
        expandOnRowClick,
        updateCollapseValue,
        innerValue,
        isDisabled
      } = this;
      const canExpand = expandOnRowClick || e.currentTarget === this.$refs.iconRef;
      if (canExpand && !isDisabled) updateCollapseValue(innerValue);
      e.stopPropagation();
    }
  },
  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
