import{_ as __rest,a as __assign}from"./tslib.es6-bjGg6Bxl.js";import React__default,{useState,useRef,useEffect}from"react";import{I as Icon,K as KnownIconsEnum}from"./Icon.component-7-ap-6Ys.js";var messageBaseStyles="\n    jn-text-theme-high\n    jn-flex\n    jn-rounded\n    jn-leading-5\n    jn-overflow-hidden\n    jn-items-center\n",messageHeadingStyles="\n    jn-font-bold\n",messageContentStyles="\n    jn-py-3\n    jn-pr-4\n    jn-ml-7\n",messageBorderStyles="\n    jn-w-[4px]\n    jn-self-stretch\n    jn-border-l-4\n    jn-mr-6\n    jn-shrink-0\n",dismissButtonStyles="\n    jn-ml-auto\n    jn-self-stretch\n    jn-flex\n    jn-flex-col\n    jn-py-2.5\n    jn-pr-2.5\n",messageVariantStyles={default:"jn-border-theme-message-default",defaultBg:"jn-bg-theme-message-default",error:"jn-border-theme-message-error",errorBg:"jn-bg-theme-message-error",warning:"jn-border-theme-message-warning",warningBg:"jn-bg-theme-message-warning",danger:"jn-border-theme-message-danger",dangerBg:"jn-bg-theme-message-danger",success:"jn-border-theme-message-success",successBg:"jn-bg-theme-message-success"},getBackgroundStyle=function(a){return"error"===a?messageVariantStyles.errorBg:"warning"===a?messageVariantStyles.warningBg:"success"===a?messageVariantStyles.successBg:"info"===a?messageVariantStyles.defaultBg:"danger"===a?messageVariantStyles.dangerBg:messageVariantStyles.defaultBg},getVariantStyle=function(a){return"error"===a?messageVariantStyles.error:"warning"===a?messageVariantStyles.warning:"success"===a?messageVariantStyles.success:"info"===a?messageVariantStyles.default:"danger"===a?messageVariantStyles.danger:messageVariantStyles.default},isValidIcon=function(a){var b=new Set(Object.values(KnownIconsEnum));return b.has(a)},getIcon=function(a){return"error"===a?"dangerous":isValidIcon(a)?a:"default"},initiateAutoDismiss=function(a,b,c,d){!a||1>b||(null!==d.current&&clearTimeout(d.current),d.current=window.setTimeout(function(){c()},b))},clearAutoDismissTimeout=function(a){null!==a.current&&(clearTimeout(a.current),a.current=null)},Message=function(a){var b=a.title,c=void 0===b?null:b,d=a.text,e=void 0===d?null:d,f=a.variant,g=void 0===f?"info":f,h=a.dismissible,i=a.autoDismiss,j=void 0!==i&&i,k=a.autoDismissTimeout,l=void 0===k?1e4:k,m=a.onDismiss,n=a.className,o=void 0===n?"":n,p=a.children,q=__rest(a,["title","text","variant","dismissible","autoDismiss","autoDismissTimeout","onDismiss","className","children"]),r=useState(!0),s=r[0],t=r[1],u=useRef(null),v=function(){t(!1),m&&m()};if(useEffect(function(){return function(){clearAutoDismissTimeout(u)}},[]),useEffect(function(){initiateAutoDismiss(j,l,v,u)},[j,l]),!s)return null;var w=getIcon(g),x=getBackgroundStyle(g),y=getVariantStyle(g);return React__default.createElement("div",__assign({className:"juno-message juno-message-".concat(g," ").concat(messageBaseStyles," ").concat(x," ").concat(o)},q),React__default.createElement("div",{className:"juno-message-border ".concat(messageBorderStyles," ").concat(y)}),React__default.createElement(Icon,{icon:w,color:"jn-text-theme-".concat(g),className:"jn-shrink-0"}),React__default.createElement("div",{className:"juno-message-content ".concat(messageContentStyles)},c&&React__default.createElement("h1",{className:messageHeadingStyles},c),React__default.createElement("div",null,p||e)),void 0!==h&&h&&(React__default.createElement("div",{className:dismissButtonStyles},React__default.createElement(Icon,{icon:"close",onClick:v,className:"juno-message-close-button jn-opacity-50 hover:jn-opacity-100"}))))};export{Message as M};