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

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import { defineComponent, ref, onMounted, onBeforeUnmount, createVNode } from 'vue';
import { CheckCircleFilledIcon, CloseIcon, ErrorCircleFilledIcon, HelpCircleFilledIcon, InfoCircleFilledIcon } from '@ldesign/icons-vue-next';
import isString from 'lodash/isString';
import isArray from 'lodash/isArray';
import { on, off, addClass } from '../utils/dom.js';
import { useIcon } from '../hooks/icon.js';
import { useGlobalIcon } from '../hooks/useGlobalIcon.js';
import { usePrefixClass } from '../hooks/useConfig.js';
import { useTNodeJSX } from '../hooks/tnode.js';
import props from './props.js';
import { useConfig } from '../config-provider/useConfig.js';
import '../_chunks/dep-e041f5b0.js';
import 'lodash/isFunction';
import '../utils/easing.js';
import 'lodash/camelCase';
import 'lodash/kebabCase';
import '../utils/render-tnode.js';
import 'lodash/isEmpty';
import 'lodash/isObject';
import 'lodash/cloneDeep';
import '../config-provider/context.js';
import 'lodash/mergeWith';
import 'lodash/merge';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '@babel/runtime/helpers/typeof';
import 'dayjs';

var _Alert = defineComponent({
  name: "TAlert",
  props: props,
  setup: function setup(props2) {
    var _useConfig = useConfig("alert"),
      globalConfig = _useConfig.globalConfig,
      classPrefix = _useConfig.classPrefix;
    var _useGlobalIcon = useGlobalIcon({
        CheckCircleFilledIcon: CheckCircleFilledIcon,
        CloseIcon: CloseIcon,
        ErrorCircleFilledIcon: ErrorCircleFilledIcon,
        HelpCircleFilledIcon: HelpCircleFilledIcon,
        InfoCircleFilledIcon: InfoCircleFilledIcon
      }),
      CheckCircleFilledIcon$1 = _useGlobalIcon.CheckCircleFilledIcon,
      CloseIcon$1 = _useGlobalIcon.CloseIcon,
      ErrorCircleFilledIcon$1 = _useGlobalIcon.ErrorCircleFilledIcon,
      HelpCircleFilledIcon$1 = _useGlobalIcon.HelpCircleFilledIcon,
      InfoCircleFilledIcon$1 = _useGlobalIcon.InfoCircleFilledIcon;
    var COMPONENT_NAME = usePrefixClass("alert");
    var renderTNodeJSX = useTNodeJSX();
    var renderIconTNode = useIcon();
    var alertRef = ref(null);
    var descriptionRef = ref(null);
    var descHeight = ref(0);
    var visible = ref(true);
    var collapsed = ref(true);
    var renderIcon = function renderIcon() {
      var Component = {
        info: InfoCircleFilledIcon$1,
        success: CheckCircleFilledIcon$1,
        warning: ErrorCircleFilledIcon$1,
        error: ErrorCircleFilledIcon$1,
        question: HelpCircleFilledIcon$1
      };
      var iconContent = renderIconTNode("icon", Component);
      return iconContent ? 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 = createVNode(CloseIcon$1, null, null);else if (isString(close)) closeContent = close;else closeContent = renderIconTNode("close");
      return closeContent ? createVNode("div", {
        "class": "".concat(COMPONENT_NAME.value, "__close"),
        "onClick": handleClose
      }, [closeContent]) : null;
    };
    var renderTitle = function renderTitle() {
      var titleContent = renderTNodeJSX("title");
      return titleContent ? createVNode("div", {
        "class": "".concat(COMPONENT_NAME.value, "__title")
      }, [" ", titleContent]) : null;
    };
    var renderMessage = function renderMessage() {
      var operationContent = renderTNodeJSX("operation");
      return createVNode("div", {
        "class": "".concat(COMPONENT_NAME.value, "__message")
      }, [renderDescription(), operationContent ? 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(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 createVNode("div", {
        "class": "".concat(COMPONENT_NAME.value, "__description"),
        "ref": descriptionRef
      }, [hasCollapse ? messageContent.map(function (content) {
        return createVNode("div", null, [content]);
      }) : messageContent, hasCollapse ? 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 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
      });
      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
        });
      }
    };
    onMounted(function () {
      on(alertRef.value, "transitionend", handleCloseEnd);
      descHeight.value = descriptionRef.value.offsetHeight;
    });
    onBeforeUnmount(function () {
      off(alertRef.value, "transitionend", handleCloseEnd);
    });
    return function () {
      return createVNode("div", {
        "ref": alertRef,
        "class": ["".concat(COMPONENT_NAME.value), "".concat(COMPONENT_NAME.value, "--").concat(props2.theme), _defineProperty({}, "".concat(classPrefix.value, "-is-hidden"), !visible.value)]
      }, [renderIcon(), renderContent(), renderClose()]);
    };
  }
});

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