/* Copyright (c) Fortanix, Inc.
|* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of
|* the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. */

@use '../../../styling/defs.scss' as bk;

@layer baklava.components {
  .bk-toast {
    cursor: pointer;
    user-select: none; // Text selection does not make sense given that clicking the toast closes it
    touch-action: none;
    
    flex-shrink: 0;
    
    inline-size: 60ch;
    box-shadow: 0.15em 0.15em 0.4em rgb(0 0 0 / 50%);
    
    transition-duration: 400ms;
    transition-property: display, translate, opacity;
    transition-behavior: allow-discrete;
    transition-timing-function: var(--bk-toast-ease-entry);
    
    @starting-style {
      translate: 100%;
      opacity: 0;
    }
    &.bk-toast--skip-entry { // If applied, we skip the entry animation
      transition-duration: 0ms;
    }
    
    &[hidden] {
      transition-duration: 200ms;
      transition-timing-function: var(--bk-toast-ease-exit);
      opacity: 0;
      translate: 100%;
    }
  }
  
  .bk-toaster {
    // Source: `--ease-spring-1` from open-props
    --bk-toast-ease-entry: linear(
      0,
      0.006,
      0.025 2.8%,
      0.101 6.1%,
      0.539 18.9%,
      0.721 25.3%,
      0.849 31.5%,
      0.937 38.1%,
      0.968 41.8%,
      0.991 45.7%,
      1.006 50.1%,
      1.015 55%,
      1.017 63.9%,
      1.001
    );
    // Source: `--ease-elastic-out-1` from open-props
    --bk-toast-ease-exit: cubic-bezier(0.5, 0.75, 0.75, 1.25);
    
    @include bk.component-base(bk-toaster);
    
    overflow: visible; // Allow overflow, for entry/exit animation overshoot
    
    position: fixed;
    inset: 0;
    inset-inline-start: auto;
    inline-size: min-content;
    block-size: min-content;
    max-inline-size: 100vi;
    max-block-size: 90vb;
    
    &:not(:empty) {
      margin: 1rem;
    }
    
    background: transparent;
    
    display: flex;
    flex-direction: column-reverse;
    row-gap: 1lh;
    
    @media (prefers-reduced-motion: no-preference) {
      --transition-duration: 150ms;
      transition: opacity var(--transition-duration) ease-out;
    }
    
    @include bk.focus-hidden;
  }
}
