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

'use strict';

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

var iconsVue = require('@ldesign/icons-vue');
var utils_dom = require('../../utils/dom.js');
var utils_renderNode = require('../../utils/render-node.js');
var utils_mixins = require('../../utils/mixins.js');
var components_configProvider_configReceiver = require('../config-provider/config-receiver.js');
var components_alert_props = require('./props.js');
require('vue');
require('raf');
require('lodash/isString');
require('../../chunks/log.js');
require('../../chunks/_commonjsHelpers-2e6815bd.js');
require('../../utils/easing.js');
require('lodash');
require('lodash/mergeWith');
require('../config-provider/context.js');
require('../../chunks/zh_CN.js');

var _Alert = utils_mixins["default"](components_configProvider_configReceiver["default"]("alert"), components_configProvider_configReceiver.getGlobalIconMixins()).extend({
  name: "LAlert",
  data() {
    return {
      visible: true,
      collapsed: true
    };
  },
  props: {
    ...components_alert_props["default"]
  },
  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() {
    utils_dom.on(this.$el, "transitionend", this.handleCloseEnd);
  },
  beforeDestroy() {
    utils_dom.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,
          CheckCircleFilledIcon,
          ErrorCircleFilledIcon
        } = this.useGlobalIcon({
          InfoCircleFilledIcon: iconsVue.InfoCircleFilledIcon,
          CheckCircleFilledIcon: iconsVue.CheckCircleFilledIcon,
          ErrorCircleFilledIcon: iconsVue.ErrorCircleFilledIcon
        });
        const component = {
          info: InfoCircleFilledIcon,
          success: CheckCircleFilledIcon,
          warning: ErrorCircleFilledIcon,
          error: ErrorCircleFilledIcon
        }[this.theme];
        iconContent = h(component);
      }
      return iconContent ? h("div", {
        "class": `${this.componentName}__icon`
      }, [iconContent]) : null;
    },
    renderClose() {
      const h = this.$createElement;
      const {
        CloseIcon
      } = this.useGlobalIcon({
        CloseIcon: iconsVue.CloseIcon
      });
      let closeContent = null;
      if (this.close === true || this.close === "") closeContent = h(CloseIcon);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 = utils_renderNode.renderLNodeJSX(this, "title");
      return titleContent ? h("div", {
        "class": `${this.componentName}__title`
      }, [" ", titleContent]) : null;
    },
    renderMessage() {
      const h = this.$createElement;
      const operationContent = utils_renderNode.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 = utils_renderNode.renderLNodeJSX(this, "default");
      if (!messageContent) messageContent = utils_renderNode.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
      });
      utils_dom.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
        });
      }
    }
  }
});

exports["default"] = _Alert;
//# sourceMappingURL=alert.js.map
