"use strict";const s=require("vue"),t=require("./Icon.js"),m=require("./CdxButton.cjs"),f=require("./constants.js"),v=require("./_plugin-vue_export-helper.js");require("./useComputedDirection.cjs");require("./useComputedLanguage.cjs");require("./useIconOnlyButton.js");require("./useSlotContents.js");require("./useWarnOnce.cjs");const p={notice:t.Y4,error:t.i4,warning:t.M3,success:t.N7},y=s.defineComponent({name:"CdxMessage",components:{CdxButton:m,CdxIcon:t.CdxIcon},props:{type:{type:String,default:"notice",validator:f.statusTypeValidator},inline:{type:Boolean,default:!1},icon:{type:[String,Object],default:null},fadeIn:{type:Boolean,default:!1},dismissButtonLabel:{type:String,default:""},autoDismiss:{type:[Boolean,Number],default:!1,validator:e=>typeof e=="boolean"||typeof e=="number"&&e>0}},emits:["user-dismissed","auto-dismissed"],setup(e,{emit:o}){const i=s.ref(!1),l=s.computed(()=>e.inline===!1&&e.dismissButtonLabel.length>0),r=s.computed(()=>e.autoDismiss===!1||e.type==="error"?!1:e.autoDismiss===!0?4e3:e.autoDismiss),u=s.computed(()=>({"cdx-message--inline":e.inline,"cdx-message--block":!e.inline,"cdx-message--user-dismissable":l.value,["cdx-message--".concat(e.type)]:!0})),n=s.computed(()=>e.icon&&e.type==="notice"?e.icon:p[e.type]),a=s.ref("");function c(d){i.value||(a.value=d==="user-dismissed"?"cdx-message-leave-active-user":"cdx-message-leave-active-system",i.value=!0,o(d))}return s.onMounted(()=>{e.type==="error"&&e.autoDismiss!==!1?s.warn('CdxMessage: Message with type="error" cannot use auto-dismiss'):r.value&&setTimeout(()=>c("auto-dismissed"),r.value)}),{dismissed:i,userDismissable:l,rootClasses:u,leaveActiveClass:a,computedIcon:n,onDismiss:c,cdxIconClose:t.X3}}});const g=["aria-live","role"],C={class:"cdx-message__content"};function b(e,o,i,l,r,u){const n=s.resolveComponent("cdx-icon"),a=s.resolveComponent("cdx-button");return s.openBlock(),s.createBlock(s.Transition,{name:"cdx-message",appear:e.fadeIn,"leave-active-class":e.leaveActiveClass},{default:s.withCtx(()=>[e.dismissed?s.createCommentVNode("",!0):(s.openBlock(),s.createElementBlock("div",{key:0,class:s.normalizeClass(["cdx-message",e.rootClasses]),"aria-live":e.type!=="error"?"polite":void 0,role:e.type==="error"?"alert":void 0},[s.createVNode(n,{class:"cdx-message__icon--vue",icon:e.computedIcon},null,8,["icon"]),s.createElementVNode("div",C,[s.renderSlot(e.$slots,"default")]),e.userDismissable?(s.openBlock(),s.createBlock(a,{key:0,class:"cdx-message__dismiss-button",weight:"quiet",type:"button","aria-label":e.dismissButtonLabel,onClick:o[0]||(o[0]=c=>e.onDismiss("user-dismissed"))},{default:s.withCtx(()=>[s.createVNode(n,{icon:e.cdxIconClose,"icon-label":e.dismissButtonLabel},null,8,["icon","icon-label"])]),_:1},8,["aria-label"])):s.createCommentVNode("",!0)],10,g))]),_:3},8,["appear","leave-active-class"])}const _=v._export_sfc(y,[["render",b]]);module.exports=_;
