/**
 * Component: Float
 */
@include comp('float') {
  $animation-duration: 240ms;

  display: none;
  z-index: $z-index-popover;
  position: fixed; // the popover should be appended into body directly.

  flex-wrap: row nowrap;

  @include when('visible') {
    display: flex;
  }

  & > * {
    position: relative;
  }

  @include prop(
    (
      'position': 'top',
    )
  ) {
    & > * {
      bottom: 0;
    }
  }
  @include prop(
    (
      'position': 'bottom',
    )
  ) {
    & > * {
      top: 0;
    }
  }
  @include prop(
    (
      'position': 'left',
    )
  ) {
    & > * {
      right: 0;
    }
  }
  @include prop(
    (
      'position': 'right',
    )
  ) {
    & > * {
      left: 0;
    }
  }

  @include prop(
    (
      'align': 'start',
    )
  ) {
    justify-content: flex-start;
  }
  @include prop(
    (
      'align': 'end',
    )
  ) {
    justify-content: flex-end;
  }
  @include prop(
    (
      'align': 'center',
    )
  ) {
    justify-content: center;
  }
  @each $position in ('left', 'right') {
    @include prop(
      (
        'position': $position,
      )
    ) {
      flex-direction: column;
    }
    @include prop(
      (
        'position': $position,
        'align': 'center',
      )
    ) {
      transform: translateY(-50%);
    }
  }
  @each $position in ('top', 'bottom') {
    @include prop(
      (
        'position': $position,
      )
    ) {
      flex-direction: row;
    }
    @include prop(
      (
        'position': $position,
        'align': 'center',
      )
    ) {
      transform: translateX(-50%);
    }
  }

  @keyframes vd-float-fade-in {
    from {
      opacity: 0;
    }
    to {
      opacity: 1;
    }
  }

  @include when('showing') {
    & > * {
      animation: $animation-duration ease;
    }
  }
  @include when('closing') {
    & > * {
      animation: $animation-duration ease reverse;
    }
  }

  @each $position in ('left', 'right', 'top', 'bottom') {
    @each $align in ('start', 'end', 'center') {
      $animation-name: 'vd-float-fade-in-#{$position}-#{$align}';
      $parallel: if($position == 'left' or $position == 'top', 15%, -15%);
      $cross: if($align == 'start', -15%, if($align == 'end', 15%, 0));
      @keyframes '#{$animation-name}' {
        from {
          transform: scale(0.7)
            translateX(if($position == 'left' or $position == 'right', $parallel, $cross))
            translateY(if($position == 'left' or $position == 'right', $cross, $parallel));
        }
        to {
          transform: scale(1) translateX(0) translateY(0);
        }
      }

      @include prop(
        (
          'position': $position,
          'align': $align,
        )
      ) {
        @include when('showing') {
          & > * {
            animation-name: vd-float-fade-in, $animation-name;
          }
        }
        @include when('closing') {
          & > * {
            animation-name: vd-float-fade-in, $animation-name;
          }
        }
        // & > * {
        //   animation-name: vd-float-fade-in, $animation-name;
        // }
      }
    }
  }

  transition: ease 100ms;
  transition-property: top bottom left right;
}
