/*
 * https://github.com/morethanwords/tweb
 * Copyright (C) 2019-2021 Eduard Kuzmenko
 * https://github.com/morethanwords/tweb/blob/master/LICENSE
 */

/* @keyframes reaction-activate {
  0% {
    opacity: 1;
    transform: scale(1.75);
  }

  95% {
    opacity: 1;
  }

  to {
    opacity: 0;
    transform: scale(1.25);
  }
} */

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

  &-sticker {
    --custom-emoji-size: var(--reaction-size);
    position: relative;
    width: var(--reaction-size);
    height: var(--reaction-size);
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    overflow: hidden;
    
    &-activate {
      position: absolute;
      inset: var(--reaction-offset);
      z-index: 1;
      // animation: reaction-activate 2s linear forwards;
    }

    &.has-animation {
      > .media-sticker {
        opacity: 0;
      }
    }

    &.is-regular {
      .media-sticker {
        --size: calc(var(--reaction-size) + var(--reaction-offset) * -2);
        width: var(--size) !important;
        height: var(--size) !important;
        max-width: var(--size);
        max-height: var(--size);
        inset: auto;
      }
    }

    &.is-custom {
      border-radius: .3125rem;

      .custom-emoji,
      .media-sticker {
        border-radius: inherit;
      }
    }
  }

  &-inline {
    --reaction-size: .875rem;
    --reaction-offset: -.4375rem;
    min-width: var(--reaction-size);
    min-height: var(--reaction-size);
  }

  &-inline &-counter {
    font-size: inherit !important;
    order: -1;
    margin-right: .0625rem !important;
  }

  &-block {
    --additional-height: .5rem;
    // --padding-horizontal: .5rem;
    // --reaction-size: 1.0625rem;
    --reaction-size: 1.375rem;
    --reaction-offset: -.5625rem;
    --background-color: var(--message-highlighting-color);
    --counter-color: #fff;
    --reaction-total-size: calc(var(--reaction-size) + var(--additional-height));
    border-radius: var(--reaction-total-size);
    // padding: 0 .375rem 0 .625rem;
    // padding: 0 var(--padding-horizontal) 0 calc(var(--padding-horizontal) + var(--reaction-size));
    // padding: 0 var(--padding-horizontal);
    padding: 0 .5rem;
    background-color: var(--background-color);
    color: var(--counter-color);

    @include hover() {
      &:after {
        position: absolute;
        inset: 0;
        content: " ";
        background-color: var(--chosen-background-color);
        border-radius: inherit;
        opacity: $hover-alpha;
      }
    }

    .reaction-sticker,
    .reaction-counter {
      z-index: 1;
      pointer-events: none;
    }

    &:before {
      content: " ";
      position: absolute;
      inset: 0;
      background-color: var(--chosen-background-color);
      // visibility: hidden;
      border-radius: inherit;
      // transform: scale3d(.2, .2, .2);
      transform: scale(0, 0);
      opacity: 0;
    }

    &.is-chosen {
      &:not(.backwards) {
        &:before {
          transform: scale(1, 1);
          opacity: 1;
          // visibility: visible;
        }

        .stacked-avatars {
          --border-color: var(--chosen-background-color);
        }
      }

      &.animating {
        &:before {
          transition: transform var(--transition-standard-in), opacity var(--transition-standard-in);
          // transition: transform var(--transition-standard-in);
        }

        .reaction-counter {
          transition: color var(--transition-standard-in);
          // transition: color 1s linear;
        }

        .stacked-avatars-avatar-container {
          transition: border-color var(--transition-standard-in);
        }
      }
    }

    .stacked-avatars {
      --border-color: transparent;
      --border-size: .125rem;
      --margin-right: -.875rem;
      margin-inline-start: .1875rem;
      // margin-right: .0625rem;
    }

    &.is-paid {
      --chosen-background-color: #FFBC2E !important;
      --background-color: rgba(255, 188, 46, .2) !important;
      color: #E98111;
      transition: transform var(--reaction-paid-transition);
      z-index: 2;

      .currency-star-icon {
        transform: translateX(1px);
      }

      .reaction-sticker {
        overflow: visible;
        z-index: 2;
      }

      .reaction-sticker-activate {
        width: 4rem;
        height: 4rem;
        inset: -1.25rem;
        z-index: 2;
      }

      &.is-chosen:not(.backwards) {
        color: #fff;
      }

      &.effect-active {
        // filter: drop-shadow(0 0 .25rem 0 rgba(0, 0, 0, .25));
        box-shadow: 0 0 .25rem 0 rgba(0, 0, 0, .2), 0 0 1.25rem 0 rgba(0, 0, 0, .2);
        transform: scale3d(1.5, 1.5, 1.5);

        .reaction-paid-counter {
          opacity: 1;
          transform: translate(-50%, 0);
        }
      }

      .reaction-counter {
        transition: color var(--reaction-paid-transition);
      }
    }
  }

  &-block &-counter {
    font-size: .9375rem !important;
    font-weight: var(--font-weight-bold);
    margin-block: 0;
    margin-inline: .375rem .0625rem;
    line-height: 1.125rem;
    position: relative;
  }

  &-like-block {
    --chosen-background-color: var(--message-primary-color);
    height: var(--reaction-total-size);
    margin-top: var(--margin-vertical);
    margin-inline-end: var(--margin-horizontal);
    cursor: pointer;
    position: relative;
    user-select: none !important;

    &.is-last {
      margin-inline-end: 0 !important;
    }
  }

  &-tag {
    --additional-height: .625rem;
    --reaction-size: 1.25rem;
    --reaction-offset: -.5625rem;
    --reaction-total-size: calc(var(--reaction-size) + var(--additional-height));
    --counter-color: #9BA0A5;
    --background-color: var(--old-input-background-color);
    --dot-color: rgba(155, 160, 165, .4);
    min-width: 2.6875rem;
    padding-inline: .375rem;

    &.is-chosen {
      &:not(.backwards) {
        --counter-color: var(--message-icon-text-color);
        --background-color: var(--chosen-background-color);
        --dot-color: var(--message-reaction-tag-dot-color);
  
        // .reaction-tag-svg-circle {
        //   fill: var(--message-reaction-tag-dot-color);
        // }
      }

      &.animating {
        .reaction-tag-svg {
          transition: fill var(--transition-standard-in);
        }

        .reaction-tag-dot,
        .reaction-tag-background {
          transition: background-color var(--transition-standard-in);
        }

        .reaction-counter {
          transition: color var(--transition-standard-in);
          // transition: color 1s linear;
        }
      }
    }

    &-svg {
      position: absolute;
      top: 0;
      inset-inline-end: 0;
      width: 43px;
      height: 30px;
      fill: var(--background-color);

      // &-circle {
      //   fill: rgba(155, 160, 165, .4);
      // }
    }

    &-dot {
      position: relative;
      margin-left: 5px;
      width: .375rem;
      height: .375rem;
      background-color: var(--dot-color);
      border-radius: 50%;
      order: 999;
    }

    &-background {
      position: absolute;
      inset: 0;
      background-color: var(--background-color);
      border-radius: inherit;
      margin-inline-end: 18px;
      border-radius: 7px;
    }

    &-svg,
    &-dot,
    &-background {
      pointer-events: none;
    }

    &-lock {
      --background-color: var(--light-filled-primary-color);
      --dot-color: rgba(var(--primary-color-rgb), .4);
      --counter-color: currentColor;
      color: var(--primary-color);
      opacity: 1 !important;

      .reaction-sticker-icon {
        font-size: 1.25rem;
      }
    }

    // .reaction-sticker {
    //   z-index: 1;
    // }
  }

  &-tag &-counter {
    font-size: var(--font-size-16) !important;
    font-weight: var(--font-weight-bold);
    margin-inline: .3125rem .0625rem;
    line-height: 21px;
    position: relative;
    color: var(--counter-color);
    pointer-events: none;
    white-space: nowrap;

    // &-title {
    //   font-size: var(--font-size-14);
    // }
  }

  &-paid-background {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    fill: #E78510;
  }

  &-paid-counter {
    width: auto !important;
    position: absolute;
    top: -2rem;
    left: 50%;
    transform: translate(-50%, 0.5rem);
    z-index: 2;

    opacity: 0;
    transition: opacity var(--reaction-paid-transition), transform var(--reaction-paid-transition), max-width var(--reaction-paid-transition) !important;

    font-family: var(--font-rounded);
    font-size: 1.625rem;
    line-height: 1.75rem;

    filter: drop-shadow(0 0 1.25rem rgba(0, 0, 0, .5));
    pointer-events: none;

    .animated-super-row,
    .animated-counter-decimal-prefix {
      -webkit-text-stroke: 1px #E58E0D;
      background: linear-gradient(180deg, #FFD55D 0%, #FFBF3E 100%);
      color: transparent;
      -webkit-background-clip: text;
      -moz-background-clip: text;
      background-clip: text;
    }
  }
}
