@use "../../../styles/mixins";

.Chat {
  --background-color: var(--color-background);
  --thumbs-background: var(--background-color);

  --z-forum-indicator: 2;
  --z-badge: 4;
  --z-status: 8; // Avatar stories require a higher z-index than the ripple to work

  position: absolute;
  top: 0;
  left: 0;

  width: 100%;
  margin: 0;

  -webkit-touch-callout: none;

  body.is-ios &,
  body.is-macos & {
    --color-text-meta: var(--color-text-meta-apple);
  }

  &.standalone {
    position: static;

    .LastMessageMeta {
      margin-inline-end: 0;
    }
  }

  &.animate-opacity {
    will-change: opacity;
    transition: opacity 0.2s ease-out;
  }

  &.animate-transform {
    will-change: transform;
    transition: transform var(--chat-transform-transition);
  }

  &:hover,
  &.ListItem.has-menu-open {
    .avatar-badge {
      --_color-outline: var(--color-chat-hover);
    }

    .avatar-badge-wrapper {
      --outline-color: var(--color-chat-hover);
    }

    .ChatCallStatus {
      border-color: var(--color-chat-hover);
    }
  }

  &:not(.standalone):last-of-type {
    border-bottom: 0.5rem solid transparent; // `margin` does not help, and `padding` affects forum indicator height
  }

  &.selected-forum {
    &::before {
      transform: translateX(0) scaleY(1) !important;
    }
  }

  &.forum {
    --color-chat-username: var(--color-text);

    &::before {
      content: '';

      position: absolute;
      z-index: var(--z-forum-indicator);
      top: 0.625rem;
      bottom: 0.625rem;
      left: -0.4375rem; // `.chat-list` left padding
      transform: translateX(-0.375rem) scaleY(0.5);

      width: 0.3125rem;
      border-start-end-radius: var(--border-radius-default);
      border-end-end-radius: var(--border-radius-default);

      background: var(--color-primary);

      transition: transform var(--layer-transition);

      body.no-page-transitions & {
        transition: none;
      }
    }

    .ListItem-button {
      padding-top: 0.3125rem;
      padding-bottom: 0.3125rem;
    }

    .status {
      background-color: var(--background-color);
    }

    .info-row {
      line-height: 1.375;
    }

    .info.has-tags .subtitle {
      height: unset;
      line-height: inherit;
    }

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

  &.chat-item-with-tags {
    .ListItem-button {
      align-items: flex-start;
      padding: 0.375rem 0.5625rem;
    }
  }

  .ripple-container {
    z-index: var(--z-chat-ripple);
  }

  .status {
    position: relative;
    z-index: var(--z-status);

    overflow: visible !important;
    display: flex;
    align-items: center;
    align-self: stretch;
  }

  .avatar-wrapper {
    --outline-color: var(--color-background);

    position: relative;
    flex-shrink: 0;
  }

  .avatar-badge-wrapper {
    position: absolute;
    z-index: var(--z-badge);
    right: 0.5rem;
    bottom: 0;
  }

  .avatar-badge {
    --_color-outline: var(--color-background);

    position: absolute;
    right: 0.0625rem;
    bottom: 0.0625rem;
    flex-shrink: 0;
  }

  .avatar-subscription {
    font-size: 0.875rem;

    @include mixins.filter-outline(1px, var(--_color-outline));
  }

  .avatar-online {
    transform: scale(0);

    width: 0.875rem;
    height: 0.875rem;
    border: 2px solid var(--_color-outline);
    border-radius: 50%;

    opacity: 0.5;
    background-color: #0ac630;

    transition: opacity 200ms, transform 200ms;

    &.avatar-online-shown {
      transform: scale(1);
      opacity: 1;
    }
  }

  .info {
    display: flex;
    flex-direction: column;
    justify-content: center;
    transition: opacity 300ms ease, transform var(--layer-transition);

    body.no-page-transitions & {
      transition: opacity 300ms ease;
    }

    &.has-tags {
      justify-content: flex-start;
      height: 3.75rem;

      .info-row, .subtitle {
        height: 1.25rem;
        line-height: 1.25rem;
      }
    }

    .title .custom-emoji {
      color: var(--color-primary);
    }

    .icon-muted {
      margin-left: 0.25rem;
      font-size: 1.125rem;
      color: var(--color-list-icon);
    }

    .general-forum-icon {
      font-size: 1.25rem;
      color: var(--color-text-secondary);
    }

    .last-message,
    .typing-status {
      unicode-bidi: plaintext;
      flex-grow: 1;
      padding-right: 0.25rem;
      color: var(--color-text-secondary);

      &[dir="ltr"] {
        text-align: left;
      }

      .sender-name {
        color: var(--color-chat-username);

        body.is-macos &,
        body.is-ios & {
          color: var(--color-text);
        }
      }

      .draft {
        color: var(--color-error);
      }
    }

    .last-message {
      overflow: hidden;
      display: flex;
      &-summary {
        overflow: hidden;
        flex: unset;

        max-width: none;

        text-overflow: ellipsis;
        white-space: nowrap;
      }

      .draft {
        margin-inline-end: 0.5ch;
      }

      .colon, .chat-prefix-icon {
        margin-inline-end: 0.1875rem;
      }

      .chat-prefix-icon {
        display: inline-block;
        align-self: center;
        color: var(--color-list-icon);
      }

      .media-preview-spoiler {
        filter: blur(1px);
      }

      .media-preview--image {
        flex-shrink: 0;

        width: 1.25rem;
        height: 1.25rem;
        margin-inline-end: 0.25rem;
        border-radius: 0.125rem;

        vertical-align: -0.25rem;

        object-fit: cover;

        &.round {
          border-radius: 0.625rem;
        }
      }

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

      .icon-play {
        position: relative;

        display: inline-block;

        margin-inline-start: -1.25rem;
        margin-inline-end: 0.5rem;

        font-size: 0.75rem;
        color: #fff;
      }
    }
  }

  &[dir="rtl"] {
    .info {
      .LastMessageMeta {
        margin-right: auto;
        margin-left: 0;
      }

      .title,
      .subtitle {
        padding-right: 0;
        padding-left: 0.125rem;
      }

      .icon-muted {
        margin-right: 0.25rem;
        margin-left: 0;
      }

      .last-message,
      .typing-status {
        unicode-bidi: plaintext;
        padding-right: 0;
        padding-left: 0.5rem;
        text-align: right;
      }
    }
  }

  // Super specific selector to override the same in `ListItem`
  @media (min-width: 600px) {
    &:not(.has-ripple):not(.is-static),
    body.no-page-transitions & {
      .ListItem-button:active {
        --background-color: var(--color-chat-hover) !important;
      }
    }
  }

  @media (max-width: 600px) {
    &.selected {
      --background-color: var(--color-chat-hover) !important;

      .avatar-badge {
        --_color-outline: var(--color-chat-hover);
      }

      .ChatCallStatus {
        border-color: var(--color-chat-hover);
      }
    }
  }

  @media (min-width: 600px) {
    &.selected:not(.forum),
    &.selected:not(.forum):hover {
      --background-color: var(--color-chat-active) !important;

      .title .custom-emoji {
        color: var(--color-white);
      }

      .VerifiedIcon, .StarIcon {
        --color-fill: #fff;
        --color-checkmark: var(--color-primary);
      }

      .avatar-badge {
        --_color-outline: var(--color-chat-active) !important;
      }

      .avatar-online {
        background-color: var(--color-white);
      }

      .ChatCallStatus {
        border-color: var(--color-chat-active) !important;
      }

      .ListItem-button {
        --background-color: var(--color-chat-active) !important;
        --color-text: var(--color-white);
        --color-text-meta-colored: var(--color-white);
        --color-text-meta: var(--color-white);
        --color-text-secondary: var(--color-white);
        --color-error: var(--color-white);
        --color-list-icon: var(--color-white);
        --color-chat-username: var(--color-white);
      }

      .icon-muted {
        color: var(--color-white) !important;
      }

      .general-forum-icon {
        color: var(--color-white) !important;
      }

      .monoforum-badge {
        color: var(--color-chat-active);
        background-color: #fff;
      }

      .chat-tag {
        color: var(--color-chat-active);
        background-color: #ffffffab;
      }
    }
  }

  @media (max-width: 600px) {
    .ListItem-button {
      border-radius: 0 !important;
    }
  }
}
