@import '../../styles/mixins';

@mixin mobile-header-styles() {
  .HeaderPinnedMessage-wrapper,
  .AudioPlayer {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    height: 2.875rem;
    overflow: hidden;
    box-shadow: 0 2px 2px var(--color-light-shadow);

    display: flex;
    flex-direction: row-reverse;
    padding: 0.375rem 0.5rem;
    padding-left: 0.75rem;
    background: var(--color-background);

    &::before {
      content: "";
      display: block;
      position: absolute;
      top: -.1875rem;
      left: 0;
      right: 0;
      height: .125rem;
      box-shadow: 0 .125rem .125rem var(--color-light-shadow);
    }

    .HeaderPinnedMessage {
      max-width: unset;
      margin-top: -0.1875rem;
    }
  }

  .AudioPlayer {
    height: 3.25rem;

    flex-direction: row;
    padding: 0.375rem 0.5rem;

    &-content {
      padding: 0 0.5rem;
      flex-grow: 1
    }

    > .Button {
      margin: 0;
    }

    > .player-close {
      margin-left: auto;
    }
  }

  .HeaderPinnedMessage {
    flex-grow: 1;
    padding-top: 0;
    padding-bottom: 0;

    &::before {
      top: 0.125rem;
      bottom: 0.125rem;
    }

    .message-text {
      max-width: none;
    }
  }
}

.MiddleHeader {
  display: flex;
  align-items: center;
  width: 100%;
  box-shadow: 0 2px 2px var(--color-light-shadow);
  background: var(--color-background);
  padding: .5rem .8125rem .5rem 1.5rem;
  position: relative;
  z-index: var(--z-middle-header);

  @media (max-width: 600px) {
    padding: 0.5rem;
    position: relative;
    // Force rendering in the composite layer to fix the z-index rendering issue
    transform: translate3d(0, 0, 10px);
    transform-style: preserve-3d;
  }

  .Transition {
    width: 100%;
    // https://dfmcphee.com/flex-items-and-min-width-0/
    // https://stackoverflow.com/questions/36247140/why-dont-flex-items-shrink-past-content-size
    min-width: 0;

    > div {
      display: flex;
      align-items: center;
      width: 100%;
    }
  }

  .back-button {
    margin-left: -0.5rem;
    margin-right: 0.5rem;
    position: relative;

    @media (max-width: 600px) {
      margin-left: 0;
    }

    .unread-count {
      min-width: 1.25rem;
      height: 1.25rem;
      padding: 0 0.375rem;
      border-radius: 0.625rem;
      font-size: 0.75rem;
      line-height: 1.25rem;
      font-weight: 500;
      text-align: center;

      position: absolute;
      top: -0.25rem;
      right: -0.5rem;

      background: var(--color-gray);
      color: white;
      pointer-events: none;

      &.active {
        background: var(--color-primary);
      }
    }
  }

  .chat-info-wrapper {
    flex-grow: 1;
    overflow: hidden;
  }

  .header-tools {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    margin-left: auto;
    flex-shrink: 0;

    body.animation-level-0 & {
      &,
      .HeaderPinnedMessage-wrapper,
      .AudioPlayer,
      .HeaderActions {
        transition: none !important;
      }
    }

    @media (min-width: 1276px) and (max-width: 1439px) {
      .HeaderActions {
        transform: translate3d(0, 0, 0);
        transition: transform var(--layer-transition);

        #Main.right-column-open & {
          transform: translate3d(calc(var(--right-column-width) * -1), 0, 0);
        }
      }
    }

    @media (min-width: 1440px) {
      transform: translate3d(0, 0, 0);
      transition: transform var(--layer-transition);

      #Main.right-column-open & {
        transform: translate3d(calc(var(--right-column-width) * -1), 0, 0);
      }
    }

    // @optimization
    @include while-transition() {
      pointer-events: none;
    }
  }

  @media (min-width: 1276px) and (max-width: 1439px) {
    &:not(.tools-stacked) .header-tools {
      .HeaderPinnedMessage-wrapper,
      .AudioPlayer {
        opacity: 1;

        #Main.right-column-open & {
          opacity: 0;
        }
      }
    }
  }

  &.tools-stacked .header-tools {
    @include mobile-header-styles();

    @media (min-width: 1150px) {
      #Main.right-column-open & {
        .HeaderPinnedMessage-wrapper,
        .AudioPlayer {
          padding-right: calc(0.5rem + var(--right-column-width));
        }
      }
    }
  }

  &.tools-stacked.animated .header-tools {
    .HeaderPinnedMessage-wrapper,
    .AudioPlayer {
      animation: fade-in var(--layer-transition) forwards;

      body.animation-level-0 & {
        animation: none;
      }
    }
  }

  h3 {
    font-weight: 500;
    font-size: 1.125rem;
    line-height: 1.375rem;
    white-space: pre;
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    unicode-bidi: plaintext;

    @media (max-width: 600px) {
      display: block;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    @media (min-width: 1275px) {
      #Main.right-column-open & {
        max-width: calc(100% - var(--right-column-width));
      }
    }
  }

  .ChatInfo {
    cursor: pointer;
    display: flex;
    align-items: center;

    .info {
      display: flex;
      flex-direction: column;
      justify-content: center;
      flex-grow: 1;
      overflow: hidden;
    }

    .title {
      display: flex;
      align-items: center;

      .VerifiedIcon {
        width: 1.25rem;
        height: 1.25rem;
        margin-left: 0.25rem;
        margin-top: 0.05rem;
      }
    }

    .user-status, .status {
      unicode-bidi: plaintext;
    }
  }

  .Avatar {
    margin-right: .625rem;
    width: 2.5rem;
    height: 2.5rem;
    font-size: 1.0625rem;
  }

  .status, .typing-status {
    font-size: 0.875rem;
    line-height: 1.125rem;
    margin: 0;
    color: var(--color-text-secondary);
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    display: inline-block;

    .ellipsis {
      display: inline-flex;
    }

    &.online {
      color: var(--color-primary);
    }

    .font-emoji {
      line-height: 1rem;
    }
  }

  .Button.smaller {
    width: 2.5rem;
    height: 2.5rem;
  }

  .HeaderPinnedMessage-wrapper {
    display: flex;
    align-items: center;
    margin-left: auto;
    cursor: default;
    flex-direction: row-reverse;

    body.animation-level-1 & {
      .ripple-container {
        display: none;
      }
    }

    .HeaderPinnedMessage {
      min-width: 16rem;
    }

    > .Button {
      flex-shrink: 0;
    }
  }

  .HeaderPinnedMessage {
    display: flex;
    flex-shrink: 1;
    margin-top: -0.25rem;
    margin-bottom: -0.25rem;
    padding: 0.25rem;
    padding-left: 0.375rem;
    border-radius: var(--border-radius-messages-small);
    position: relative;
    overflow: hidden;
    cursor: pointer;

    &:hover {
      background-color: var(--color-interactive-element-hover);
    }

    .pinned-message-border {
      position: relative;
      height: 2.25rem;
      margin: 0.125rem 0;
      width: 0.125rem;
      min-width: 0.125rem;
      overflow: hidden;

      .pinned-message-border-wrapper-1 {
        height: 2.25rem;
        width: 0.125rem;
        border-radius: 0.0625rem;
        background: var(--color-primary);
      }

      .pinned-message-border-wrapper {
        background-color: var(--color-primary-opacity);
        position: relative;
        will-change: transform;
        transition: transform .25s ease-in-out;
      }

      .pinned-message-border-mark {
        position: absolute;
        left: 0;
        top: 0;
        width: 0.125rem;
        background: var(--color-primary);
        border-radius: 0.0625rem;
        will-change: transform;
        transition: transform .25s ease-in-out;
      }
    }

    .message-text {
      overflow: hidden;
      margin-inline-start: 0.375rem;
      margin-top: 0.125rem;
      max-width: 15rem;

      @media (min-width: 1440px) and (max-width: 1500px) {
        max-width: 14rem;
      }

      .title {
        font-weight: 500;
        font-size: 0.875rem;
        line-height: 1rem;
        height: 1rem;
        color: var(--color-primary);
        margin-bottom: 0.125rem;
        white-space: pre;
        text-align: initial;
      }

      p {
        font-size: 0.875rem;
        line-height: 1.125rem;
        height: 1.125rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        margin: 0;
      }
    }

    .emoji-small {
      width: 1rem;
      height: 1rem;
    }

    & > img {
      width: 2.25rem;
      height: 2.25rem;
      object-fit: cover;
      border-radius: 0.25rem;
      margin-inline-start: 0.375rem;
      margin-top: 0.125rem;
      flex-shrink: 0;

      & + .message-text {
        max-width: 12rem;
      }
    }
  }

  .HeaderActions {
    flex-shrink: 0;
    margin-left: auto;
    display: flex;
    align-items: center;
    justify-content: flex-end;

    .toggle-right-pane-button {
      &.active {
        color: var(--color-primary);
        opacity: 1;
      }
    }
  }

  .HeaderPinnedMessage-wrapper, .HeaderActions {
    .Button {
      margin-left: 0.25rem;

      &.tiny {
        margin-right: .625rem;
      }
    }
  }

  @media (max-width: 600px) {
    @include mobile-header-styles();

    .HeaderPinnedMessage-wrapper,
    .AudioPlayer {
      // Force rendering in the composite layer to fix the z-index rendering issue
      transform: translate3d(0, 0, 0);
    }
  }

  @media (min-width: 925px) and (max-width: 1149.9px) {
    .HeaderPinnedMessage-wrapper,
    .AudioPlayer {
      position: absolute;
    }
  }
}

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