// Copyright 2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only

@use '../mixins';
@use '../variables';

.StoryViewer {
  &__overlay {
    background-size: contain;
    height: 100%;
    inset-inline-start: 0;
    position: absolute;
    top: 0;
    width: 100%;
    z-index: variables.$z-index-popup-overlay;
  }

  &__content {
    align-items: center;
    backdrop-filter: blur(90px);
    background: variables.$color-black-alpha-20;
    display: flex;
    flex-direction: column;
    height: 100%;
    justify-content: center;
    inset-inline-start: 0;
    position: absolute;
    top: 0;
    width: 100%;
    z-index: variables.$z-index-popup-overlay;
  }

  &__close-button {
    @include mixins.button-reset;
    & {
      @include mixins.modal-close-button;
    }
    @include mixins.light-theme {
      @include mixins.color-svg(
        '../images/icons/v3/x/x.svg',
        variables.$color-gray-15
      );
    }
    & {
      width: 20px;
      height: 20px;
      top: var(--title-bar-drag-area-height);
      inset-inline-end: 28px;
      z-index: variables.$z-index-above-above-base;
    }
  }

  &__container {
    flex-grow: 1;
    overflow: hidden;
    outline: none;
  }

  &__story {
    max-height: 100%;
    outline: none;
    width: auto;

    &__image {
      object-fit: contain;
    }
  }

  &__meta {
    @include mixins.position-absolute-center-x;
    bottom: 0;
    min-width: 284px;
    padding-block: 0;
    padding-inline: 16px;
    width: clamp(0vh, 56.25vh, 100vw);
    z-index: variables.$z-index-story-meta;

    &__list {
      @include mixins.font-body-2;
      align-items: center;
      display: flex;
      color: variables.$color-white-alpha-80;

      &::before {
        @include mixins.color-svg(
          '../images/icons/v3/stories/stories-fill-compact.svg',
          variables.$color-white-alpha-80
        );
        & {
          content: '';
          display: block;
          height: 14px;
          margin-inline-end: 6px;
          width: 14px;
        }
      }
    }

    &--group-avatar {
      margin-inline-start: -8px;
    }

    &--title-container {
      padding-inline-start: 8px;
    }

    &--title {
      @include mixins.font-body-1-bold;
      color: variables.$color-white;
      display: inline;
      margin-inline-end: 8px;
    }

    &--timestamp {
      @include mixins.font-body-2;
      color: variables.$color-white-alpha-60;
    }

    &__playback-bar {
      display: flex;
      justify-content: space-between;
      user-select: none;

      &__container {
        align-items: center;
        display: flex;
      }
    }

    &__playback-controls {
      align-items: center;
      display: flex;
    }
  }

  &__caption {
    @include mixins.font-body-1;
    color: variables.$color-white;
    padding-block: 4px;
    padding-inline: 0;
    margin-bottom: 24px;
    text-shadow: 0px 0px 48px 0px variables.$color-black-alpha-80;

    &__overlay {
      @include mixins.button-reset;
      & {
        background: variables.$color-black-alpha-60;
        height: 100%;
        inset-inline-start: 0;
        position: absolute;
        top: 0;
        width: 100%;
        z-index: variables.$z-index-base;
      }
    }
  }

  &__actions {
    display: flex;
    justify-content: center;
    min-height: 60px;

    &__failed {
      @include mixins.button-reset;
      & {
        @include mixins.font-body-1;
        align-items: center;
        color: variables.$color-white;
        display: flex;
      }

      &::before {
        content: '';
        display: block;
        height: 18px;
        margin-inline-end: 12px;
        width: 18px;
        @include mixins.color-svg(
          '../images/icons/v3/error/error-circle.svg',
          variables.$color-accent-red
        );
      }
    }
  }

  &__reply {
    @include mixins.button-reset;
    & {
      color: variables.$color-gray-05;
    }
    @include mixins.keyboard-mode {
      &:focus {
        color: variables.$color-ultramarine;
      }
    }

    &__arrow {
      display: flex;
      align-items: center;

      &::before {
        content: '';
        height: 20px;
        margin-inline-end: 12px;
        width: 20px;
        @include mixins.color-svg(
          '../images/icons/v3/reply/reply.svg',
          variables.$color-white
        );
      }
    }

    &__chevron {
      display: flex;
      align-items: center;

      &::after {
        content: '';
        display: inline-block;
        height: 16px;
        margin-inline-start: 4px;
        vertical-align: middle;
        width: 16px;
        @include mixins.color-svg(
          '../images/icons/v3/chevron/chevron-right.svg',
          variables.$color-white
        );
      }
    }
  }

  &__more__button {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 24px;
    width: 24px;

    &::after {
      @include mixins.color-svg(
        '../images/icons/v3/more/more.svg',
        variables.$color-white
      );
      & {
        content: '';
        height: 20px;
        width: 20px;
      }

      @include mixins.keyboard-mode {
        &:focus {
          background-color: variables.$color-black;
        }
      }
    }
  }

  &__mute {
    @include mixins.button-reset;
    & {
      height: 20px;
      margin-block: 0;
      margin-inline: 24px;
      width: 20px;
    }
    @include mixins.color-svg(
      '../images/icons/v3/speaker/speaker.svg',
      variables.$color-white
    );
    @include mixins.keyboard-mode {
      &:focus {
        background-color: variables.$color-white-alpha-80;
      }
    }
  }

  &__pause {
    @include mixins.button-reset;
    & {
      height: 20px;
      width: 20px;
    }
    @include mixins.color-svg(
      '../images/icons/v3/pause/pause.svg',
      variables.$color-white
    );
    @include mixins.keyboard-mode {
      &:focus {
        background-color: variables.$color-white-alpha-80;
      }
    }
  }

  &__play {
    @include mixins.button-reset;
    & {
      height: 20px;
      width: 20px;
    }
    @include mixins.color-svg(
      '../images/icons/v3/play/play-fill.svg',
      variables.$color-white
    );
    @include mixins.keyboard-mode {
      &:focus {
        background-color: variables.$color-white-alpha-80;
      }
    }
  }

  &__unmute {
    @include mixins.button-reset;
    & {
      height: 20px;
      margin-block: 0;
      margin-inline: 24px;
      width: 20px;
    }
    @include mixins.color-svg(
      '../images/icons/v3/speaker/speaker-slash.svg',
      variables.$color-white
    );
    @include mixins.keyboard-mode {
      &:focus {
        background-color: variables.$color-white-alpha-80;
      }
    }
  }

  &__soundless {
    @include mixins.button-reset;
    & {
      height: 20px;
      margin-block: 0;
      margin-inline: 24px;
      width: 20px;
    }
    @include mixins.color-svg(
      '../images/icons/v3/speaker/speaker-x.svg',
      variables.$color-white
    );
    @include mixins.keyboard-mode {
      &:focus {
        background-color: variables.$color-white-alpha-80;
      }
    }
  }

  &__progress {
    display: flex;
  }

  &__animated-emojis {
    height: 100%;
    position: absolute;
    width: 100%;
    z-index: variables.$z-index-above-base;
  }

  &__arrow {
    @include mixins.button-reset;
    & {
      align-items: center;
      display: flex;
      height: 100%;
      position: absolute;
      width: 25%;
      z-index: variables.$z-index-above-above-base;
    }

    &::before {
      content: '';
      height: 28px;
      opacity: 0;
      width: 28px;
      transition: opacity 200ms ease-in-out;
    }

    &--left {
      justify-content: flex-start;
      inset-inline-start: 0;

      &::before {
        margin-inline-start: 16px;
        @include mixins.color-svg(
          '../images/icons/v3/chevron/chevron-left.svg',
          variables.$color-white
        );
      }
    }

    &--right {
      justify-content: flex-end;
      inset-inline-end: 0;

      &::before {
        margin-inline-end: 16px;
        @include mixins.color-svg(
          '../images/icons/v3/chevron/chevron-right.svg',
          variables.$color-white
        );
      }
    }

    &--visible::before {
      opacity: 1;
    }
  }

  &__protection {
    position: absolute;
    width: 100%;
    z-index: variables.$z-index-base;

    &--top {
      background: linear-gradient(
        variables.$color-black-alpha-16,
        variables.$color-transparent
      );
      top: 0;
      height: 80px;
    }

    &--bottom {
      background: linear-gradient(
        variables.$color-transparent,
        variables.$color-black-alpha-60
      );
      bottom: 0;
      height: 140px;
    }
    &--bottom.StoryViewer__protection--has-caption {
      background: linear-gradient(
        variables.$color-transparent,
        variables.$color-black-alpha-80
      );
      height: 280px;
    }

    &--whole {
      top: 0;
      bottom: 0;
      background: linear-gradient(
        variables.$color-transparent,
        variables.$color-black-alpha-40
      );
    }
  }

  &__sending {
    align-items: center;
    display: flex;

    &__spinner__container {
      margin-inline: 0 12px;
    }
  }
}
