@use 'sass:math';
@use '_variables' as *;
@use '_mixins' as *;
@use '_bootstrap-variables';
@use '_miniature' as *;

$video-height: 66vh;

@function getPlayerHeight ($width) {
  @return calc(#{$width} / #{$video-watch-player-factor});
}

@function getPlayerWidth ($height) {
  @return calc(#{$height} * #{$video-watch-player-factor});
}

@mixin playlist-below-player {
  width: 100% !important;
  height: auto !important;
  max-height: 300px !important;
  max-width: initial;
  border-bottom: 1px solid $separator-border-color !important;
}

.blocked-label {
  font-weight: $font-semibold;
}

.placeholder-image {
  height: 100%;
  max-width: 100%;
  object-fit: contain;
}

.flex-direction-column {
  flex-direction: column;
}

.root {
  &.theater-enabled #video-wrapper {
    $height: calc(100vh - #{$header-height} - #{$theater-bottom-space});

    flex-direction: column;
    justify-content: center;

    #videojs-wrapper {
      width: 100%;
      height: $height;
    }

    ::ng-deep .video-js {
      height: $height;
      width: 100%;
      max-width: initial;
    }

    my-video-watch-playlist ::ng-deep .playlist {
      @include playlist-below-player;
    }
  }
}

#video-wrapper {
  background-color: #000;
  display: flex;
  justify-content: center;

  ::ng-deep .video-js {
    width: 100%;
    max-width: getPlayerWidth($video-height);
    height: $video-height;

    // VideoJS create an inner video player
    video {
      outline: 0;
      position: relative !important;
    }
  }
}

#videojs-wrapper {
  display: flex;
  justify-content: center;
  flex-grow: 1;
  height: $video-height;
}

.remote-server-down {
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  justify-content: center;
  background-color: #141313;
  width: 100%;
  font-size: 24px;
  height: 500px;

  @media screen and (max-width: 1000px) {
    font-size: 20px;
  }

  @media screen and (max-width: 600px) {
    font-size: 16px;
  }
}

#video-not-found {
  height: 300px;
  line-height: 300px;
  margin-top: 50px;
  text-align: center;
  font-weight: $font-semibold;
}

.video-bottom {
  display: flex;
  margin-top: 1.5rem;
}

.video-info {
  flex-grow: 1;
  // Set min width for flex item
  min-width: 1px;
  max-width: 100%;
}

.video-info-first-row {
  display: flex;

  > div:first-child {
    flex-grow: 1;
  }
}

.video-info-name {
  @include peertube-word-wrap;

  @include margin-right(30px);

  min-height: 40px; // Align with the action buttons
  font-size: 27px;
  font-weight: $font-semibold;
  flex-grow: 1;
}

.video-info-first-row-bottom {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  width: 100%;
}

.video-info-date-views {
  @include margin-right(10px);

  margin-bottom: 10px;
  align-self: start;
  font-size: 14px;
}

.video-info-channel {
  font-weight: $font-semibold;

  a {
    @include disable-default-a-behaviour;
    @include peertube-word-wrap;

    color: pvar(--mainForegroundColor);

    &:hover {
      opacity: 0.8;
    }
  }
}

.video-info-channel-left {
  flex-grow: 1;

  .video-info-channel-left-links {
    display: flex;
    flex-direction: column;
    position: relative;
    line-height: 1.37;

    a:nth-of-type(2) {
      font-weight: $font-regular;
      font-size: 90%;
    }

    a.single-link {
      margin-top: 7px;
    }
  }
}

my-subscribe-button {
  @include margin-left(5px);
}

my-video-attributes {
  @include margin-left($video-watch-info-margin-left);

  display: block;
  margin-bottom: 15px;
}

my-action-buttons {
  @include margin-left(auto);
  @include margin-right(0);

  display: block;
  margin-top: 0;
  margin-bottom: 10px;

  align-items: start;
  width: max-content;
}

my-recommended-videos {
  @include padding-left(15px);

  display: block;
  min-width: 250px;
}

my-video-comments {
  display: inline-block;
  width: 100%;
  margin-bottom: 20px;
}

// Use the same breakpoint than in the typescript component to display the other video miniatures as row
@media screen and (max-width: 1100px) {
  #video-wrapper {
    flex-direction: column;
    justify-content: center;

    my-video-watch-playlist ::ng-deep .playlist {
      @include playlist-below-player;
    }
  }

  .video-bottom {
    flex-direction: column;
  }

  my-recommended-videos {
    @include padding-left(0);
  }
}

@media screen and (max-width: 600px) {
  #videojs-wrapper {
    height: getPlayerHeight(100vw) !important;

    .remote-server-down,
    ::ng-deep .video-js {
      width: 100vw;
      height: getPlayerHeight(100vw) !important;
    }
  }

  .video-bottom {
    margin-top: 20px !important;
    padding-bottom: 20px !important;
  }

  .video-info {
    padding: 0;
  }

  .video-info-name {
    font-size: 20px;
    height: auto;
  }
}

@media screen and (max-width: 450px) {
  .video-info-name {
    font-size: 18px;
  }

  .video-info-date-views {
    font-size: 14px;
  }

  my-action-buttons {
    margin-top: 10px;
  }
}

// Special case for iOS, that takes into account the width for fullscreens
#video-wrapper ::ng-deep .video-js.vjs-fullscreen {
  max-width: unset;
}
