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

'use strict';

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

var _defineProperty = require('@babel/runtime/helpers/defineProperty');
var vue = require('vue');
var iconsVueNext = require('@ldesign/icons-vue-next');
var isString = require('lodash/isString');
var isArray = require('lodash/isArray');
var utils_dom = require('../utils/dom.js');
var hooks_icon = require('../hooks/icon.js');
var hooks_useGlobalIcon = require('../hooks/useGlobalIcon.js');
var hooks_useConfig = require('../hooks/useConfig.js');
var hooks_tnode = require('../hooks/tnode.js');
var alert_props = require('./props.js');
var configProvider_useConfig = require('../config-provider/useConfig.js');
require('../_chunks/dep-7f0559c3.js');
require('lodash/isFunction');
require('../utils/easing.js');
require('lodash/camelCase');
require('lodash/kebabCase');
require('../utils/render-tnode.js');
require('lodash/isEmpty');
require('lodash/isObject');
require('lodash/cloneDeep');
require('../config-provider/context.js');
require('lodash/mergeWith');
require('lodash/merge');
require('../_common/js/global-config/default-config.js');
require('../_common/js/global-config/locale/zh_CN.js');
require('@babel/runtime/helpers/typeof');
require('dayjs');

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

var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
var isString__default = /*#__PURE__*/_interopDefaultLegacy(isString);
var isArray__default = /*#__PURE__*/_interopDefaultLegacy(isArray);

var _Alert = vue.defineComponent({
  name: "TAlert",
  props: alert_props["default"],
  setup: function setup(props2) {
    var _useConfig = configProvider_useConfig.useConfig("alert"),
      globalConfig = _useConfig.globalConfig,
      classPrefix = _useConfig.classPrefix;
    var _useGlobalIcon = hooks_useGlobalIcon.useGlobalIcon({
        CheckCircleFilledIcon: iconsVueNext.CheckCircleFilledIcon,
        CloseIcon: iconsVueNext.CloseIcon,
        ErrorCircleFilledIcon: iconsVueNext.ErrorCircleFilledIcon,
        HelpCircleFilledIcon: iconsVueNext.HelpCircleFilledIcon,
        InfoCircleFilledIcon: iconsVueNext.InfoCircleFilledIcon
      }),
      CheckCircleFilledIcon = _useGlobalIcon.CheckCircleFilledIcon,
      CloseIcon = _useGlobalIcon.CloseIcon,
      ErrorCircleFilledIcon = _useGlobalIcon.ErrorCircleFilledIcon,
      HelpCircleFilledIcon = _useGlobalIcon.HelpCircleFilledIcon,
      InfoCircleFilledIcon = _useGlobalIcon.InfoCircleFilledIcon;
    var COMPONENT_NAME = hooks_useConfig.usePrefixClass("alert");
    var renderTNodeJSX = hooks_tnode.useTNodeJSX();
    var renderIconTNode = hooks_icon.useIcon();
    var alertRef = vue.ref(null);
    var descriptionRef = vue.ref(null);
    var descHeight = vue.ref(0);
    var visible = vue.ref(true);
    var collapsed = vue.ref(true);
    var renderIcon = function renderIcon() {
      var Component = {
        info: InfoCircleFilledIcon,
        success: CheckCircleFilledIcon,
        warning: ErrorCircleFilledIcon,
        error: ErrorCircleFilledIcon,
        question: HelpCircleFilledIcon
      };
      var iconContent = renderIconTNode("icon", Component);
      return iconContent ? vue.createVNode("div", {
        "class": "".concat(COMPONENT_NAME.value, "__icon")
      }, [iconContent]) : null;
    };
    var renderClose = function renderClose() {
      var close = props2.close;
      var closeContent = null;
      if (close === true || close === "") closeContent = vue.createVNode(CloseIcon, null, null);else if (isString__default["default"](close)) closeContent = close;else closeContent = renderIconTNode("close");
      return closeContent ? vue.createVNode("div", {
        "class": "".concat(COMPONENT_NAME.value, "__close"),
        "onClick": handleClose
      }, [closeContent]) : null;
    };
    var renderTitle = function renderTitle() {
      var titleContent = renderTNodeJSX("title");
      return titleContent ? vue.createVNode("div", {
        "class": "".concat(COMPONENT_NAME.value, "__title")
      }, [" ", titleContent]) : null;
    };
    var renderMessage = function renderMessage() {
      var operationContent = renderTNodeJSX("operation");
      return vue.createVNode("div", {
        "class": "".concat(COMPONENT_NAME.value, "__message")
      }, [renderDescription(), operationContent ? vue.createVNode("div", {
        "class": "".concat(COMPONENT_NAME.value, "__operation")
      }, [operationContent]) : null]);
    };
    var renderDescription = function renderDescription() {
      var _descriptionRef$value, _descriptionRef$value2;
      var messageContent;
      messageContent = renderTNodeJSX("default");
      if (!messageContent) messageContent = renderTNodeJSX("message");
      var contentLength = isArray__default["default"](messageContent) ? messageContent.length : 1;
      var hasCollapse = props2.maxLine > 0 && props2.maxLine < contentLength;
      var height = (_descriptionRef$value = descriptionRef.value) === null || _descriptionRef$value === void 0 ? void 0 : (_descriptionRef$value2 = _descriptionRef$value.children[0]) === null || _descriptionRef$value2 === void 0 ? void 0 : _descriptionRef$value2.offsetHeight;
      if (hasCollapse && collapsed.value) {
        messageContent = messageContent.slice(0, props2.maxLine);
        height && (descriptionRef.value.style.height = "".concat(descHeight.value, "px"));
      } else if (hasCollapse) {
        height && (descriptionRef.value.style.height = "".concat(height * (contentLength - props2.maxLine) + descHeight.value, "px"));
      }
      return vue.createVNode("div", {
        "class": "".concat(COMPONENT_NAME.value, "__description"),
        "ref": descriptionRef
      }, [hasCollapse ? messageContent.map(function (content) {
        return vue.createVNode("div", null, [content]);
      }) : messageContent, hasCollapse ? vue.createVNode("div", {
        "class": "".concat(COMPONENT_NAME.value, "__collapse"),
        "onClick": function onClick() {
          collapsed.value = !collapsed.value;
        }
      }, [collapsed.value ? globalConfig.value.expandText : globalConfig.value.collapseText]) : null]);
    };
    var renderContent = function renderContent() {
      return vue.createVNode("div", {
        "class": "".concat(COMPONENT_NAME.value, "__content")
      }, [renderTitle(), renderMessage()]);
    };
    var handleClose = function handleClose(e) {
      var _props2$onClose;
      (_props2$onClose = props2.onClose) === null || _props2$onClose === void 0 ? void 0 : _props2$onClose.call(props2, {
        e: e
      });
      utils_dom.addClass(alertRef.value, "".concat(COMPONENT_NAME.value, "--closing"));
    };
    var handleCloseEnd = function handleCloseEnd(e) {
      var isTransitionTarget = e.target === alertRef.value;
      if (e.propertyName === "opacity" && isTransitionTarget) {
        var _props2$onClosed;
        visible.value = false;
        (_props2$onClosed = props2.onClosed) === null || _props2$onClosed === void 0 ? void 0 : _props2$onClosed.call(props2, {
          e: e
        });
      }
    };
    vue.onMounted(function () {
      utils_dom.on(alertRef.value, "transitionend", handleCloseEnd);
      descHeight.value = descriptionRef.value.offsetHeight;
    });
    vue.onBeforeUnmount(function () {
      utils_dom.off(alertRef.value, "transitionend", handleCloseEnd);
    });
    return function () {
      return vue.createVNode("div", {
        "ref": alertRef,
        "class": ["".concat(COMPONENT_NAME.value), "".concat(COMPONENT_NAME.value, "--").concat(props2.theme), _defineProperty__default["default"]({}, "".concat(classPrefix.value, "-is-hidden"), !visible.value)]
      }, [renderIcon(), renderContent(), renderClose()]);
    };
  }
});

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