@use './overlay';

$animation-duration: var(--ods-semantic-motion-duration-slow);
$drawer-size: 320px;
$drawer-max-height: calc(100% - calc(var(--ods-semantic-size-space-inset-block) * 6));
$drawer-max-width: calc(100% - calc(var(--ods-semantic-size-space-inset-inline) * 6));

@mixin ods-drawer() {
  --ods-drawer-padding-horizontal: calc(var(--ods-semantic-size-space-inset-inline) * 2);
  --ods-drawer-padding-vertical: calc(var(--ods-semantic-size-space-inset-block) * 2);
  // Only effective without `backdrop`: with a backdrop the positioner carries an inline z-index
  // (modal-like stacking) and creates a stacking context, so this variable only reorders content
  // inside it — use the `positionerStyle`/`backdropStyle` props to override stacking in that case.
  --ods-drawer-z-index: #{overlay.$ods-overlay-drawer-z-index};

  display: block;
  position: fixed;
  inset-block: auto;
  inset-inline: auto;
  z-index: var(--ods-drawer-z-index);
  margin: 0;
  outline: none;
  border: none;
  box-shadow: var(--ods-semantic-shadow-overlay);
  background: var(--ods-semantic-color-surface-overlay);
  padding: var(--ods-drawer-padding-vertical) var(--ods-drawer-padding-horizontal);
  width: auto;
  overflow: auto;
}

@mixin ods-drawer-position($position) {
  @if $position == 'bottom' {
    right: 0;
    bottom: 0;
    left: 0;
    animation: drawer-open-bottom $animation-duration var(--ods-semantic-motion-easing);
    width: 100%;
    height: $drawer-size;
    max-height: $drawer-max-height;

    @keyframes drawer-open-bottom {
      from {
       transform: translateY(100%);
      }

      to {
       transform: translateY(0);
      }
    }

    @keyframes drawer-close-bottom {
      from {
       transform: translateY(0);
      }

      to {
       transform: translateY(100%);
      }
    }
  } @else if $position == 'left' {
    top: 0;
    bottom: 0;
    left: 0;
    animation: drawer-open-left $animation-duration var(--ods-semantic-motion-easing);
    width: $drawer-size;
    max-width: $drawer-max-width;
    height: 100%;

    @keyframes drawer-open-left {
      from {
       transform: translateX(-100%);
      }

      to {
       transform: translateX(0);
      }
    }

    @keyframes drawer-close-left {
      from {
       transform: translateX(0);
      }

      to {
       transform: translateX(-100%);
      }
    }
  } @else if $position == 'right' {
    top: 0;
    right: 0;
    bottom: 0;
    animation: drawer-open-right $animation-duration var(--ods-semantic-motion-easing);
    width: $drawer-size;
    max-width: $drawer-max-width;
    height: 100%;

    @keyframes drawer-open-right {
      from {
       transform: translateX(100%);
      }

      to {
       transform: translateX(0);
      }
    }

    @keyframes drawer-close-right {
      from {
       transform: translateX(0);
      }

      to {
       transform: translateX(100%);
      }
    }
  } @else if $position == 'top' {
    top: 0;
    right: 0;
    left: 0;
    animation: drawer-open-top $animation-duration var(--ods-semantic-motion-easing);
    width: 100%;
    height: $drawer-size;
    max-height: $drawer-max-height;

    @keyframes drawer-open-top {
      from {
       transform: translateY(-100%);
      }

      to {
       transform: translateY(0);
      }
    }

    @keyframes drawer-close-top {
      from {
       transform: translateY(0);
      }

      to {
       transform: translateY(-100%);
      }
    }
  }
}
