@use 'sass:list';
@use 'sass:map';

@use './../mixins/notification' as notification-mx;
@use './../mixins/icons' as icons-mx;
@use './../mixins/utilities' as utilities-mx;

@use './../placeholders/button';
@use './../variables/commons';
@use './../variables/components/notification';
@use '../functions/env';
@use './../tokens/components';
@use './../tokens/utilities';
@use './../functions/tokens';
@use '../mixins/media';
@use '../mixins/icon-button' as icon-button-mx;
@use '../mixins/button' as button-mx;

tokens.$default-map: components.$post-banner;

$spacer: 1.5rem;

.toast {
  @include notification-mx.notification-size(toast);
  @include notification-mx.notification-body(toast);

  .toast-title {
    font-weight: tokens.get('utility-font-weight-bold', utilities.$post-typo);
  }
}

.toast-dismissible {
  $padding-x: map.get(notification.$notification-padding-x-map, toast);
  $gap: map.get(notification.$notification-gap-map, toast);
  pointer-events: auto;
  position: relative;

  &:not(.alert-action) {
    padding-inline-end: calc(
      #{$padding-x} + #{$gap} + #{tokens.get('utility-gap-24', utilities.$post-spacing)}
    );
  }
}

@each $variant in notification.$notification-variants {
  $name: list.nth($variant, 1);
  .toast-#{$name} {
    background-color: tokens.get('toast-color-#{$name}-bg', components.$post-toast);
    border-color: tokens.get('toast-color-#{$name}-stroke', components.$post-toast);
    --post-current-fg: #{tokens.get('toast-color-#{$name}-fg', components.$post-toast)};

    &::before {
      background-image: var(--post-signal-icon-#{$name});
    }
  }
}

// For ngx-toastr
// Positioning
.toast-container {
  position: fixed;
  z-index: commons.$zindex-toast;
  display: flex;
  flex-direction: column-reverse;
  gap: $spacer;

  .toast {
    width: 25rem;
    background-image: unset;

    button.toast-close-button {
      @extend %btn;
      position: absolute;
      inset-block-start: 0;
      inset-inline-end: 0;
      transform: translate(50%, -50%);
      background-color: tokens.get('close-enabled-bg', components.$post-close);

      // Add .btn-secondary, .btn-icon and .btn-sm styles
      @include button-mx.button-variant-def('enabled', 'secondary');
      @include icon-button-mx.icon-button();
      @include icon-button-mx.icon-button('sm');

      &:hover,
      &:focus {
        opacity: 1;
      }

      @include utilities-mx.not-disabled-hover() {
        background-color: tokens.get('close-hover-bg', components.$post-close);
        @include button-mx.button-variant-def('hover', 'secondary');
      }

      // Remove default icon
      span {
        display: none;
      }

      // Add close post-icon
      &::before {
        content: '';
        display: block;
        width: tokens.get('icon-button-small-icon', components.$post-icon-button);
        height: tokens.get('icon-button-small-icon', components.$post-icon-button);
        @include icons-mx.mask-image('closex');
      }
    }
  }

  @include media.max(md) {
    .toast {
      max-width: 25rem;
    }
  }

  @include media.max(md) {
    right: $spacer;
    left: $spacer;

    .toast {
      width: 100%;
    }
  }
}

.toast-top-center,
.toast-top-full-width,
.toast-top-left,
.toast-top-right {
  top: $spacer;
}

.toast-bottom-center,
.toast-bottom-full-width,
.toast-bottom-right,
.toast-bottom-left {
  bottom: env.safe-area-inset(bottom, $spacer);
}

.toast-top-left,
.toast-bottom-left,
.toast-top-full-width,
.toast-bottom-full-width,
.toast-center-left {
  left: $spacer;
}

.toast-top-right,
.toast-bottom-right,
.toast-top-full-width,
.toast-bottom-full-width,
.toast-center-right {
  right: $spacer;
}

.toast-top-center,
.toast-bottom-center {
  left: 50%;
  transform: translateX(-50%);
}

.toast-center-left,
.toast-center-right {
  top: 50%;
  transform: translateY(-50%);
}

.toast-center-center {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.toast-top-full-width,
.toast-bottom-full-width {
  .toast {
    width: 100% !important;
  }
}
