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

import { InfoCircleFilledIcon, CheckCircleFilledIcon, ErrorCircleFilledIcon, CloseIcon } from '@ldesign/icons-vue';
import { on, off, addClass } from '../../utils/dom.js';
import { renderLNodeJSX } from '../../utils/render-node.js';
import mixins from '../../utils/mixins.js';
import getConfigReceiverMixins, { getGlobalIconMixins } from '../config-provider/config-receiver.js';
import props from './props.js';
import 'vue';
import 'raf';
import 'lodash/isString';
import '../../_chunks/dep-70c789e5.js';
import '../../_chunks/dep-5210251b.js';
import '../../utils/easing.js';
import 'lodash';
import 'lodash/mergeWith';
import '../config-provider/context.js';
import '../../_chunks/dep-def4c2ce.js';

var _Alert = mixins(getConfigReceiverMixins("alert"), getGlobalIconMixins()).extend({
  name: "LAlert",
  data() {
    return {
      visible: true,
      collapsed: true
    };
  },
  props: {
    ...props
  },
  render() {
    const h = arguments[0];
    const compClass = [this.componentName, `${this.componentName}--${this.theme}`, {
      [`${this.classPrefix}-is-hidden`]: !this.visible
    }];
    return h("div", {
      "class": compClass
    }, [this.renderIcon(), this.renderContent(), this.renderClose()]);
  },
  mounted() {
    on(this.$el, "transitionend", this.handleCloseEnd);
  },
  beforeDestroy() {
    off(this.$el, "transitionend", this.handleCloseEnd);
  },
  methods: {
    renderIcon() {
      const h = this.$createElement;
      let iconContent;
      if (typeof this.icon === "function") {
        iconContent = this.icon(this.$createElement);
      } else if (this.$scopedSlots.icon) {
        iconContent = this.$scopedSlots.icon && this.$scopedSlots.icon(null)[0];
      } else {
        const {
          InfoCircleFilledIcon: InfoCircleFilledIcon$1,
          CheckCircleFilledIcon: CheckCircleFilledIcon$1,
          ErrorCircleFilledIcon: ErrorCircleFilledIcon$1
        } = this.useGlobalIcon({
          InfoCircleFilledIcon: InfoCircleFilledIcon,
          CheckCircleFilledIcon: CheckCircleFilledIcon,
          ErrorCircleFilledIcon: ErrorCircleFilledIcon
        });
        const component = {
          info: InfoCircleFilledIcon$1,
          success: CheckCircleFilledIcon$1,
          warning: ErrorCircleFilledIcon$1,
          error: ErrorCircleFilledIcon$1
        }[this.theme];
        iconContent = h(component);
      }
      return iconContent ? h("div", {
        "class": `${this.componentName}__icon`
      }, [iconContent]) : null;
    },
    renderClose() {
      const h = this.$createElement;
      const {
        CloseIcon: CloseIcon$1
      } = this.useGlobalIcon({
        CloseIcon: CloseIcon
      });
      let closeContent = null;
      if (this.close === true || this.close === "") closeContent = h(CloseIcon$1);else if (typeof this.close === "string") closeContent = this.close;else if (typeof this.close === "function") closeContent = this.close(this.$createElement);else closeContent = this.$scopedSlots.close && this.$scopedSlots.close(null)[0];
      return closeContent ? h("div", {
        "class": `${this.componentName}__close`,
        "on": {
          "click": this.handleClose
        }
      }, [closeContent]) : null;
    },
    renderContent() {
      const h = this.$createElement;
      return h("div", {
        "class": `${this.componentName}__content`
      }, [this.renderTitle(), this.renderMessage()]);
    },
    renderTitle() {
      const h = this.$createElement;
      const titleContent = renderLNodeJSX(this, "title");
      return titleContent ? h("div", {
        "class": `${this.componentName}__title`
      }, [" ", titleContent]) : null;
    },
    renderMessage() {
      const h = this.$createElement;
      const operationContent = renderLNodeJSX(this, "operation");
      return h("div", {
        "class": `${this.componentName}__message`
      }, [this.renderDescription(), operationContent ? h("div", {
        "class": `${this.componentName}__operation`
      }, [operationContent]) : null]);
    },
    renderDescription() {
      const h = this.$createElement;
      let messageContent;
      messageContent = renderLNodeJSX(this, "default");
      if (!messageContent) messageContent = renderLNodeJSX(this, "message");
      const contentLength = Object.prototype.toString.call(messageContent) === "[object Array]" ? messageContent.length : 1;
      const hasCollapse = this.maxLine > 0 && this.maxLine < contentLength;
      if (hasCollapse && this.collapsed) messageContent = messageContent.slice(0, this.maxLine);
      return h("div", {
        "class": `${this.componentName}__description`
      }, [hasCollapse ? messageContent.map(content => h("div", [content])) : messageContent, hasCollapse ? h("div", {
        "class": `${this.componentName}__collapse`,
        "on": {
          "click": () => {
            this.collapsed = !this.collapsed;
          }
        }
      }, [this.collapsed ? this.global.expandText : this.global.collapseText]) : null]);
    },
    handleClose(e) {
      this.$emit("close", {
        e
      });
      if (this.onClose) this.onClose({
        e
      });
      addClass(this.$el, `${this.componentName}--closing`);
    },
    handleCloseEnd(e) {
      if (e.propertyName === "opacity") {
        this.visible = false;
        this.$emit("closed", {
          e
        });
        if (this.onClosed) this.onClosed({
          e
        });
      }
    }
  }
});

export { _Alert as default };
//# sourceMappingURL=alert.js.map
