// (C) Copyright 2014-2016 Hewlett Packard Enterprise Development LP

.#{$grommet-namespace}video {
  position: relative;
  max-width: 100%;
  height: auto;

  @include media-query(palm) {
    max-width: 100%;
    width: 100vw;
  }

  video {
    max-width: 100%;
    display: block;
  }

}

.#{$grommet-namespace}video--small {
  width: $size-small;

  video {
    width: $size-small;
  }
}

.#{$grommet-namespace}video--medium {
  width: $size-medium;

  video {
    width: $size-medium;
  }
}

.#{$grommet-namespace}video--large {
  width: $size-large;

  video {
    width: $size-large;
  }
}

.#{$grommet-namespace}video--full {
  width: 100%;
  height: 100%;
  min-width: 100%;
  min-height: 100%;

  video {
    width: 100%;
    height: 100%;
    min-width: 100%;
    min-height: 100%;
  }
}

.#{$grommet-namespace}video--align-top.#{$grommet-namespace}video--align-left {
  video {
    object-position: 0 0;
  }
}

.#{$grommet-namespace}video--align-top.#{$grommet-namespace}video--align-right {
  video {
    object-position: 100% 0;
  }
}

.#{$grommet-namespace}video--align-top:not(.#{$grommet-namespace}video--align-left):not(.#{$grommet-namespace}video--align-right) {
  video {
    object-position: 50% 0%;
  }
}

.#{$grommet-namespace}video--align-bottom.#{$grommet-namespace}video--align-left {
  video {
    object-position: 0 100%;
  }
}

.#{$grommet-namespace}video--align-bottom.#{$grommet-namespace}video--align-right {
  video {
    object-position: 100% 100%;
  }
}

.#{$grommet-namespace}video--align-bottom:not(.#{$grommet-namespace}video--align-left):not(.#{$grommet-namespace}video--align-right) {
  video {
    object-position: 50% 100%;
  }
}

.#{$grommet-namespace}video--align-left:not(.#{$grommet-namespace}video--align-top):not(.#{$grommet-namespace}video--align-bottom) {
  video {
    object-position: 0 50%;
  }
}

.#{$grommet-namespace}video--align-right:not(.#{$grommet-namespace}video--align-top):not(.#{$grommet-namespace}video--align-bottom) {
  video {
    object-position: 100% 50%;
  }
}

.#{$grommet-namespace}video--cover {
  video {
    object-fit: cover;
  }
}

.#{$grommet-namespace}video--contain {
  video {
    object-fit: contain;
  }
}

.#{$grommet-namespace}video__button:hover .#{$grommet-namespace}video__button__icon {
  fill: $brand-color;
  stroke: $brand-color;
}

@include media-query(palm) {
  .#{$grommet-namespace}video__timeline {
    visibility: hidden;
  }

  .#{$grommet-namespace}video__progress,
  .#{$grommet-namespace}video--has-timeline {
    bottom: 0px;
  }

  .#{$grommet-namespace}video__controls,
  .#{$grommet-namespace}video__replay {
    display: none;
  }
}

@include media-query(lap-and-up) {
  .#{$grommet-namespace}video--has-timeline {
    bottom: round($inuit-base-spacing-unit * 3);
  }

  .#{$grommet-namespace}video--has-played:not(.#{$grommet-namespace}video--small):not(.#{$grommet-namespace}video--ended) .#{$grommet-namespace}video__play,
  .#{$grommet-namespace}video--small .#{$grommet-namespace}video__controls,
  .#{$grommet-namespace}video--small .#{$grommet-namespace}video__replay {
    display: none;
  }
}

.#{$grommet-namespace}video__overlay {
  position: absolute;
  top: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  padding: $inuit-base-spacing-unit;
}

.#{$grommet-namespace}video__controls {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
}

.#{$grommet-namespace}video__controls-primary {
  height: round($inuit-base-spacing-unit * 3);
  background-color: rgba(nth($brand-grey-colors, 1), 0.9);
  color: $inverse-color;

  h3 {
    font-weight: $text-strong-font-weight;
  }
}

.#{$grommet-namespace}video__progress {
  position: absolute;
  left: 0px;
  right: 0px;
  bottom: round($inuit-base-spacing-unit * 3);
  height: quarter($inuit-base-spacing-unit);
  background-color: lighten(rgba(nth($brand-grey-colors, 3), 0.7), 20%);
  transition: height 0.3s;

  & + .#{$grommet-namespace}video__chapter-labels,
  & ~ .#{$grommet-namespace}video__controls-primary {
    transition: ease-in-out 0.3s;
  }

  input[type=range] {
    opacity: 0;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    padding: 0;
    margin: 0;
    border: none;
    cursor: pointer;
    outline: none;
    z-index: 30;
  }
}

.#{$grommet-namespace}video--interacting .#{$grommet-namespace}video__progress:hover {
  height: halve($inuit-base-spacing-unit);

  .#{$grommet-namespace}video__progress-bar-fill:after {
    opacity: 1;
  }

  & + .#{$grommet-namespace}video__chapter-labels {
    visibility: visible;
  }
}

.#{$grommet-namespace}video__progress-bar-fill {
  width: 100%;
  height: 100%;
  background-color: $brand-color;
  position: absolute;
  bottom: 0;
  left: 0;
  transition: width 0.3s;
  z-index: 10;

  &:after {
    content: '';
    display: block;
    position: absolute;
    right: -1 * halve($inuit-base-spacing-unit);
    top: -1 * quarter($inuit-base-spacing-unit);
    width: $inuit-base-spacing-unit;
    height: $inuit-base-spacing-unit;
    background-color: $brand-color;
    border-radius: double($inuit-base-spacing-unit);
    opacity: 0;
    transition: opacity 0.4s ease-in-out;
    z-index: 20;
  }
}

.#{$grommet-namespace}video__chapter-labels {
  position: absolute;
  bottom: 0px;
  width: 100%;
  height: round($inuit-base-spacing-unit * 3);
  visibility: hidden;
  background-color: rgba(nth($brand-grey-colors, 1), 0.9);
  transition: 0.4s ease-in-out;

  span {
    display: block;
    color: $colored-text-color;
  }
}

.#{$grommet-namespace}video__chapter-label {
  position: absolute;
  top: halve($inuit-base-spacing-unit);
}

.#{$grommet-namespace}video__chapter-label-start {
  span {
    margin-left: halve($inuit-base-spacing-unit);
  }
}

.#{$grommet-namespace}video__chapter-label-active {
  span {
    $brand-accent-color-index: 3;
    @if ($brand-accent-color-index <= length($brand-accent-colors)) {
      $chapter-current-color: nth($brand-accent-colors, $brand-accent-color-index);
      color: $chapter-current-color;
    } @else {
      color: $inverse-color;
    }

    transition: ease-in-out 0.3s;
  }
}

.#{$grommet-namespace}video__chapter-marker {
  position: absolute;
  height: 100%;
  left: 0px;
}

.#{$grommet-namespace}video__chapter-marker-track {
  position: absolute;
  width: 100%;
  height: 100%;
  transition: ease-in-out 0.3s;
}

.#{$grommet-namespace}video__chapter-marker-tick:hover + .#{$grommet-namespace}video__chapter-marker-track {
  background-color: lighten(rgba(nth($brand-grey-colors, 3), 0.7), 40%);
}

.#{$grommet-namespace}video__chapter-marker-tick {
  position: absolute;
  right: -3px;
  width: 3px;
  height: 100%;
  z-index: 40;
  transition: ease-in-out 0.3s;
  cursor: pointer;

  $brand-accent-color-index: 3;
  @if ($brand-accent-color-index <= length($brand-accent-colors)) {
    $chapter-current-color: nth($brand-accent-colors, $brand-accent-color-index);
    background-color: $chapter-current-color;
  } @else {
    background-color: $inverse-color;
  }
}

.#{$grommet-namespace}video__chapter-marker-tick-start {
  right: auto;
  left: 0px;
}

.#{$grommet-namespace}video__chapter-marker-tickhover {
  width: 8px;
  right: -8px;
}

.#{$grommet-namespace}video--playing {
  &:not(.#{$grommet-namespace}video--interacting) {
    .#{$grommet-namespace}video__controls-primary,
    .#{$grommet-namespace}video__chapter-labels,
    .#{$grommet-namespace}video__overlay {
      opacity: 0;
      transition: opacity 1s ease-in-out;
    }

    .#{$grommet-namespace}video__progress {
      bottom: 0px;
      transition: ease-in-out 1s;
    }
  }
}

.#{$grommet-namespace}video--ended {
  &:not(.#{$grommet-namespace}video--interacting) {
    .#{$grommet-namespace}video__controls-primary,
    .#{$grommet-namespace}video__chapter-labels {
      opacity: 0;
      transition: opacity 1s ease-in-out;
    }

    .#{$grommet-namespace}video__progress {
      bottom: 0px;
      transition: ease-in-out 1s;
    }
  }

  .#{$grommet-namespace}video__overlay {
    background-color: rgba(nth($brand-grey-colors, 1), 0.7);
    color: $colored-text-color;

    .#{$grommet-namespace}form {
      width: auto;
    }

    .#{$grommet-namespace}form-field {
      background-color: transparent;
      border: 2px solid rgba($colored-text-color, 0.5);
    }

    .#{$grommet-namespace}form-field__contents input {
      @include inuit-font-size($control-font-size);
      color: $colored-text-color;
      text-align: center;
    }
  }
}

// IE11 doesn't support object-fit :(
@mixin ie-video-hack () {
  .#{$grommet-namespace}video--full {
    video {
      width: auto;
      height: auto;
      max-width: none;
      position: relative;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
    }
  }

  .#{$grommet-namespace}video--align-top.#{$grommet-namespace}video--align-left {
    video {
      top: 0%;
      left: 0%;
      transform: none;
    }
  }

  .#{$grommet-namespace}video--align-top.#{$grommet-namespace}video--align-right {
    video {
      top: 0%;
      left: 100%;
      transform: translate(-100%, 0%);
    }
  }

  .#{$grommet-namespace}video--align-top:not(.#{$grommet-namespace}video--align-left):not(.#{$grommet-namespace}video--align-right) {
    video {
      top: 0%;
      left: 50%;
      transform: translateX(-50%);
    }
  }

  .#{$grommet-namespace}video--align-bottom.#{$grommet-namespace}video--align-left {
    video {
      top: 100%;
      left: 0%;
      transform: translate(0%, -100%);
    }
  }

  .#{$grommet-namespace}video--align-bottom.#{$grommet-namespace}video--align-right {
    video {
      top: 100%;
      left: 100%;
      transform: translate(-100%, -100%);
    }
  }

  .#{$grommet-namespace}video--align-bottom:not(.#{$grommet-namespace}video--align-left):not(.#{$grommet-namespace}video--align-right) {
    video {
      top: 100%;
      left: 50%;
      transform: translate(-50%, -100%);
    }
  }

  .#{$grommet-namespace}video--align-left:not(.#{$grommet-namespace}video--align-top):not(.#{$grommet-namespace}video--align-bottom) {
    video {
      top: 50%;
      left: 0%;
      transform: translate(0%, -50%);
    }
  }

  .#{$grommet-namespace}video--align-right:not(.#{$grommet-namespace}video--align-top):not(.#{$grommet-namespace}video--align-bottom) {
    video {
      top: 50%;
      left: 100%;
      transform: translate(-100%, -50%);
    }
  }
}

@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {
  @include ie-video-hack();
}

@supports (-ms-ime-align: auto) {
  @include ie-video-hack();
}
