/**
 * ldesign v0.4.6
 * (c) 2023 ldesign
 * @license MIT
 */

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var iconsVue = require('@ldesign/icons-vue');
var utils_dom = require('../utils/dom.js');
var utils_renderTnode = require('../utils/render-tnode.js');
var utils_mixins = require('../utils/mixins.js');
var configProvider_configReceiver = require('../config-provider/config-receiver.js');
var alert_props = require('./props.js');
require('vue');
require('raf');
require('lodash/isString');
require('../utils/easing.js');
require('@babel/runtime/helpers/typeof');
require('@vue/composition-api');
require('lodash/camelCase');
require('lodash/kebabCase');
require('lodash/mergeWith');
require('../config-provider/context.js');
require('lodash/merge');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');
require('../_chunks/dep-7c884501.js');
require('dayjs');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
var _Alert = utils_mixins["default"](configProvider_configReceiver["default"]("alert"), configProvider_configReceiver.getGlobalIconMixins()).extend({
  name: "TAlert",
  data: function data() {
    return {
      visible: true,
      collapsed: true
    };
  },
  props: _objectSpread({}, alert_props["default"]),
  render: function render() {
    var h = arguments[0];
    var compClass = [this.componentName, "".concat(this.componentName, "--").concat(this.theme), _defineProperty__default["default"]({}, "".concat(this.classPrefix, "-is-hidden"), !this.visible)];
    return h("div", {
      "class": compClass
    }, [this.renderIcon(), this.renderContent(), this.renderClose()]);
  },
  mounted: function mounted() {
    utils_dom.on(this.$el, "transitionend", this.handleCloseEnd);
  },
  beforeDestroy: function beforeDestroy() {
    utils_dom.off(this.$el, "transitionend", this.handleCloseEnd);
  },
  methods: {
    renderIcon: function renderIcon() {
      var h = this.$createElement;
      var 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 {
        var _this$useGlobalIcon = this.useGlobalIcon({
            InfoCircleFilledIcon: iconsVue.InfoCircleFilledIcon,
            CheckCircleFilledIcon: iconsVue.CheckCircleFilledIcon,
            ErrorCircleFilledIcon: iconsVue.ErrorCircleFilledIcon
          }),
          InfoCircleFilledIcon = _this$useGlobalIcon.InfoCircleFilledIcon,
          CheckCircleFilledIcon = _this$useGlobalIcon.CheckCircleFilledIcon,
          ErrorCircleFilledIcon = _this$useGlobalIcon.ErrorCircleFilledIcon;
        var component = {
          info: InfoCircleFilledIcon,
          success: CheckCircleFilledIcon,
          warning: ErrorCircleFilledIcon,
          error: ErrorCircleFilledIcon
        }[this.theme];
        iconContent = h(component);
      }
      return iconContent ? h("div", {
        "class": "".concat(this.componentName, "__icon")
      }, [iconContent]) : null;
    },
    renderClose: function renderClose() {
      var h = this.$createElement;
      var _this$useGlobalIcon2 = this.useGlobalIcon({
          CloseIcon: iconsVue.CloseIcon
        }),
        CloseIcon = _this$useGlobalIcon2.CloseIcon;
      var 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": "".concat(this.componentName, "__close"),
        "on": {
          "click": this.handleClose
        }
      }, [closeContent]) : null;
    },
    renderContent: function renderContent() {
      var h = this.$createElement;
      return h("div", {
        "class": "".concat(this.componentName, "__content")
      }, [this.renderTitle(), this.renderMessage()]);
    },
    renderTitle: function renderTitle() {
      var h = this.$createElement;
      var titleContent = utils_renderTnode.renderTNodeJSX(this, "title");
      return titleContent ? h("div", {
        "class": "".concat(this.componentName, "__title")
      }, [" ", titleContent]) : null;
    },
    renderMessage: function renderMessage() {
      var h = this.$createElement;
      var operationContent = utils_renderTnode.renderTNodeJSX(this, "operation");
      return h("div", {
        "class": "".concat(this.componentName, "__message")
      }, [this.renderDescription(), operationContent ? h("div", {
        "class": "".concat(this.componentName, "__operation")
      }, [operationContent]) : null]);
    },
    renderDescription: function renderDescription() {
      var _this = this;
      var h = this.$createElement;
      var messageContent;
      messageContent = utils_renderTnode.renderTNodeJSX(this, "default");
      if (!messageContent) messageContent = utils_renderTnode.renderTNodeJSX(this, "message");
      var contentLength = Object.prototype.toString.call(messageContent) === "[object Array]" ? messageContent.length : 1;
      var hasCollapse = this.maxLine > 0 && this.maxLine < contentLength;
      if (hasCollapse && this.collapsed) messageContent = messageContent.slice(0, this.maxLine);
      return h("div", {
        "class": "".concat(this.componentName, "__description")
      }, [hasCollapse ? messageContent.map(function (content) {
        return h("div", [content]);
      }) : messageContent, hasCollapse ? h("div", {
        "class": "".concat(this.componentName, "__collapse"),
        "on": {
          "click": function click() {
            _this.collapsed = !_this.collapsed;
          }
        }
      }, [this.collapsed ? this.global.expandText : this.global.collapseText]) : null]);
    },
    handleClose: function handleClose(e) {
      this.$emit("close", {
        e: e
      });
      if (this.onClose) this.onClose({
        e: e
      });
      utils_dom.addClass(this.$el, "".concat(this.componentName, "--closing"));
    },
    handleCloseEnd: function handleCloseEnd(e) {
      if (e.propertyName === "opacity") {
        this.visible = false;
        this.$emit("closed", {
          e: e
        });
        if (this.onClosed) this.onClosed({
          e: e
        });
      }
    }
  }
});

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