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

$material-icons-font-family: 'Material Symbols Outlined';

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

@include b(message) {
  width: fit-content;
  max-width: calc(100% - 32px);
  box-sizing: border-box;
  border-radius: 4px;
  border-width: getCssVar('border-width');
  border-style: getCssVar('border-style');
  border-color: getCssVar('message', 'border-color');
  position: fixed;
  left: 50%;
  top: 20px;
  transform: translateX(-50%);
  background-color: getCssVar('message', 'bg-color');
  transition:
    opacity getCssVar('transition-duration'),
    transform 0.4s,
    top 0.4s;
  padding: getCssVar('message', 'padding');
  display: flex;
  align-items: center;
  gap: 4px;
  color: getCssVar('message', 'text-color');
  box-shadow: getCssVar('box-shadow-light');
  z-index: 99999 !important;

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

  @include when(plain) {
    background-color: getCssVar('bg-color', 'overlay');
    // border-color: getCssVar('bg-color', 'overlay');
    box-shadow: getCssVar('box-shadow-light');
    border-color: getCssVar('color-neutral-light-3');
  }

  p {
    margin: 0;
  }

  & .#{$namespace}-message__closeBtn {
    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');
    }
    &:hover {
      color: getCssVar('color', 'info', 'light-6');
    }
  }

  @each $type in $semantic {
    @include m($type) {
      @include css-var-from-global(('message', 'bg-color'), ('color', if(sass($type == 'info'): 'neutral' ; else: $type), 'light-1'));
      @include css-var-from-global(('message', 'border-color'), ('color', if(sass($type == 'info'): 'neutral' ; else: $type), 'light-3'));
      @include css-var-from-global(
        ('message', 'text-color'),
        ('color', if(sass($type == 'info'): 'neutral' ; else: $type), if(sass($type == 'info'): 'light-6' ; else: 'light-5'))
      );

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

      & .#{$namespace}-message__closeBtn {
        color: getCssVar('color', if(sass($type == 'info'): 'neutral' ; else: $type));

        &:hover {
          color: getCssVar('color', if(sass($type == 'info'): 'neutral' ; else: $type), 'light-4');
        }

        &:active {
          color: getCssVar('color', if(sass($type == 'info'): 'neutral' ; else: $type), 'light-6');
        }
      }
    }

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

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

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

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

.el-message {
  &::before {
    font-family: $material-icons-font-family !important;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-style: normal;
    font-variant: normal;
    font-weight: 600;
    line-height: 1;
    speak: never;
    text-transform: none;
    font-size: 12px;
  }

  &.el-message--success {
    &::before {
      content: 'check_circle';
    }
  }

  &.el-message--info {
    &::before {
      content: 'info';
    }
  }

  &.el-message--warning {
    &::before {
      content: 'warning';
    }
  }

  &.el-message--danger,
  &.el-message--error {
    &::before {
      content: 'cancel';
    }
  }

  .el-message__icon {
    display: none;
  }
}
