/*
 * Backpack - Skyscanner's Design System
 *
 * Copyright 2016-2021 Skyscanner Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

@import '~bpk-mixins';

$bpk-spacing-v2: true;

$arrow-size: bpk-spacing-base();

.bpk-popover-portal {
  z-index: $bpk-zindex-popover;

  @include bpk-breakpoint-mobile {
    margin-right: bpk-spacing-base();
    margin-left: bpk-spacing-base();
  }

  &[x-placement='top'] {
    margin-bottom: $arrow-size;
  }

  &[x-placement='right'] {
    margin-left: $arrow-size;
  }

  &[x-placement='bottom'] {
    margin-top: $arrow-size;
  }

  &[x-placement='left'] {
    margin-right: $arrow-size;
  }
}

.bpk-popover {
  transition: opacity $bpk-duration-sm ease-in-out;
  outline: 0;
  opacity: 1;

  @include bpk-layer;

  @include bpk-breakpoint-above-mobile {
    max-width: $bpk-breakpoint-mobile;
    transition: opacity $bpk-duration-xs ease-in-out;
  }

  &--appear {
    opacity: 0;
  }

  &--appear-active {
    opacity: 1;
  }

  &__arrow {
    @include bpk-layer-arrow($arrow-size);

    .bpk-popover-portal[x-placement='top'] & {
      @include bpk-layer-arrow-bottom($arrow-size);
    }

    .bpk-popover-portal[x-placement='right'] & {
      @include bpk-layer-arrow-left($arrow-size);
    }

    .bpk-popover-portal[x-placement='bottom'] & {
      @include bpk-layer-arrow-top($arrow-size);
    }

    .bpk-popover-portal[x-placement='left'] & {
      @include bpk-layer-arrow-right($arrow-size);
    }
  }

  &__body {
    &--padded {
      padding: bpk-spacing-base();
    }
  }

  &__header {
    display: flex;
    padding: bpk-spacing-base();
    justify-content: space-between;

    @include bpk-border-bottom-sm($bpk-color-sky-gray-tint-06);
  }

  &__label {
    @include bpk-visually-hidden;
  }

  &__close-button {
    float: right;

    @include bpk-rtl {
      float: left;
    }
  }

  &__footer {
    padding: bpk-spacing-md() bpk-spacing-base();
    text-align: right;

    @include bpk-border-top-sm($bpk-color-sky-gray-tint-06);

    @include bpk-rtl {
      text-align: left;
    }
  }
}
