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

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

.module-Avatar {
  display: inline-flex;
  line-height: 0;
  position: relative;
  z-index: 0;
  user-select: none;
  vertical-align: middle;

  &__contents {
    @include mixins.avatar-colors;
    & {
      position: relative;
      overflow: hidden;
      border-radius: 100%;
      width: 100%;
      height: 100%;
      border: 0;
      padding: 0;
      margin: 0;
      outline: none;
    }

    @at-root button#{&} {
      @include mixins.keyboard-mode {
        &:focus {
          box-shadow: 0 0 0 3px variables.$color-ultramarine;
        }
      }
    }
  }

  &__contents:has(.module-Avatar__image) {
    background-color: transparent;
  }

  &__image,
  &__label,
  &__icon,
  &__spinner-container,
  &__click-to-view {
    width: 100%;
    height: 100%;
  }

  &__image {
    background-position: center center;
    background-size: cover;
    transition: filter 100ms ease-out;
  }

  &__click-to-view {
    @include mixins.font-body-2;
    align-items: center;
    background: variables.$color-black-alpha-20;
    color: variables.$color-white;
    display: flex;
    flex-direction: column;
    justify-content: center;
    inset-inline-start: 0;
    position: absolute;
    top: 0;

    &::before {
      @include mixins.color-svg(
        '../images/icons/v2/click-outline-24.svg',
        variables.$color-white
      );
      & {
        content: '';
        display: block;
        height: 24px;
        margin-bottom: 8px;
        width: 24px;
      }
    }

    &:hover {
      background: variables.$color-black-alpha-40;
    }
  }

  &__label {
    align-items: center;
    display: flex;
    justify-content: center;
    text-align: center;
    transition: font-size 100ms ease-out;
  }

  &__icon {
    -webkit-mask-repeat: no-repeat;
    -webkit-mask-position: center;
    -webkit-mask-size: 62.5%;
    background-color: var(--fg);

    @media (forced-colors: active) {
      background-color: CanvasText;
    }

    &--callLink {
      -webkit-mask-image: url('../images/icons/v3/video/video-display-bold.svg');
    }

    &--direct {
      -webkit-mask-image: url('../images/icons/v3/person/person.svg');
    }

    &--group {
      -webkit-mask-image: url('../images/icons/v3/group/group.svg');
    }

    &--note-to-self {
      -webkit-mask-image: url('../images/icons/v3/note/note.svg');
    }

    &--search-result {
      -webkit-mask-image: url('../images/icons/v3/search/search.svg');
    }
  }

  &__spinner-container {
    padding: 4px;
  }

  &__badge {
    position: absolute;
    z-index: variables.$z-index-base;

    // Positioning should be overridden by JavaScript. These are set defensively.
    bottom: 0;
    inset-inline-end: 0;

    &--static {
      pointer-events: none;
    }

    &--button {
      background-color: transparent;
      background-position: center center;
      background-size: contain;
      border: 0;
      outline: none;

      @include mixins.keyboard-mode {
        &:focus {
          outline: 2px solid variables.$color-ultramarine;
          border-radius: 6px;
        }
      }
    }
  }

  &--with-story {
    border-radius: 100%;
    border: 2px solid variables.$color-black-alpha-40;
    padding: 3px;

    @include mixins.dark-theme {
      border-color: variables.$color-white-alpha-40;

      &--unread {
        border-color: variables.$color-ultramarine-dawn;
      }
    }

    &--unread {
      border-color: variables.$color-ultramarine-dawn;
    }
  }

  &--signal-official {
    .module-Avatar__contents {
      align-items: center;
      background-color: #3640fd;
      display: flex;
      justify-content: center;
    }

    .module-Avatar__image {
      height: 62%;
      width: 62%;
    }
  }
}
