@use 'sass:map';

@use 'mixins/mixins' as *;
@use 'mixins/var' as *;
@use 'common/var' as *;

@include b(message) {
  @include set-component-css-var('message', $message);
}

@include b(message) {
  min-width: getCssVar('message', 'min-width');
  box-sizing: border-box;
  border-radius: var(--el-border-radius-base);
  border-width: var(--el-border-width-base);
  border-style: var(--el-border-style-base);
  border-color: getCssVar('border-color-light');
  position: fixed;
  left: 50%;
  top: 20px;
  transform: translateX(-50%);
  transition: opacity 0.3s, transform 0.4s, top 0.4s;
  background-color: getCssVar('message', 'bg-color');
  transition: opacity var(--el-transition-duration), transform 0.4s, top 0.4s;
  padding: getCssVar('message', 'padding');
  display: flex;
  align-items: center;

  @include when(center) {
    justify-content: center;
  }

  @include when(closable) {
    .#{$namespace}-message__content {
      padding-right: 16px;
    }
  }

  p {
    margin: 0;
  }

  @each $type in (success, info, warning, error) {
    @include m($type) {
      @include css-var-from-global(
        ('message', 'bg-color'),
        ('color', $type, 'light-9')
      );
      @include css-var-from-global(
        ('message', 'border-color'),
        ('color', $type, 'light-8')
      );
      @include css-var-from-global(('message', 'text-color'), ('color', $type));

      .#{$namespace}-message__content {
        color: getCssVar('message', 'text-color');
      }
    }

    & .#{$namespace}-message-icon--#{$type} {
      color: getCssVar('message', 'text-color');
    }
  }

  @include e(icon) {
    margin-right: 10px;
  }

  .#{$namespace}-message__badge {
    position: absolute;
    top: -8px;
    right: -8px;
  }

  @include e(content) {
    padding: 0;
    font-size: 14px;
    line-height: 1;
    &:focus {
      outline-width: 0;
    }
  }

  & .#{$namespace}-message__closeBtn {
    position: absolute;
    top: 50%;
    right: 15px;
    transform: translateY(-50%);
    cursor: pointer;
    color: getCssVar('message', 'close-icon-color');
    font-size: getCssVar('message', 'close-size');

    &:focus {
      outline-width: 0;
    }
    &:hover {
      color: getCssVar('message', 'close-hover-color');
    }
  }
}

.#{$namespace}-message-fade-enter-from,
.#{$namespace}-message-fade-leave-to {
  opacity: 0;
  transform: translate(-50%, -100%);
}
