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

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { InfoCircleFilledIcon, CheckCircleFilledIcon, ErrorCircleFilledIcon, CloseIcon } from '@ldesign/icons-vue';
import { on, off, addClass } from '../utils/dom.js';
import { renderTNodeJSX } from '../utils/render-tnode.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 '../utils/easing.js';
import '@babel/runtime/helpers/typeof';
import '@vue/composition-api';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import 'lodash/mergeWith';
import '../config-provider/context.js';
import 'lodash/merge';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '../_chunks/dep-2cb61c79.js';
import 'dayjs';

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(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 = mixins(getConfigReceiverMixins("alert"), getGlobalIconMixins()).extend({
  name: "TAlert",
  data: function data() {
    return {
      visible: true,
      collapsed: true
    };
  },
  props: _objectSpread({}, props),
  render: function render() {
    var h = arguments[0];
    var compClass = [this.componentName, "".concat(this.componentName, "--").concat(this.theme), _defineProperty({}, "".concat(this.classPrefix, "-is-hidden"), !this.visible)];
    return h("div", {
      "class": compClass
    }, [this.renderIcon(), this.renderContent(), this.renderClose()]);
  },
  mounted: function mounted() {
    on(this.$el, "transitionend", this.handleCloseEnd);
  },
  beforeDestroy: function beforeDestroy() {
    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: InfoCircleFilledIcon,
            CheckCircleFilledIcon: CheckCircleFilledIcon,
            ErrorCircleFilledIcon: ErrorCircleFilledIcon
          }),
          InfoCircleFilledIcon$1 = _this$useGlobalIcon.InfoCircleFilledIcon,
          CheckCircleFilledIcon$1 = _this$useGlobalIcon.CheckCircleFilledIcon,
          ErrorCircleFilledIcon$1 = _this$useGlobalIcon.ErrorCircleFilledIcon;
        var component = {
          info: InfoCircleFilledIcon$1,
          success: CheckCircleFilledIcon$1,
          warning: ErrorCircleFilledIcon$1,
          error: ErrorCircleFilledIcon$1
        }[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: CloseIcon
        }),
        CloseIcon$1 = _this$useGlobalIcon2.CloseIcon;
      var 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": "".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 = renderTNodeJSX(this, "title");
      return titleContent ? h("div", {
        "class": "".concat(this.componentName, "__title")
      }, [" ", titleContent]) : null;
    },
    renderMessage: function renderMessage() {
      var h = this.$createElement;
      var operationContent = 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 = renderTNodeJSX(this, "default");
      if (!messageContent) messageContent = 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
      });
      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
        });
      }
    }
  }
});

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