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

.CommentButton {
  --background-color: var(--color-background);
  --hover-color: var(--color-chat-hover);

  cursor: var(--custom-cursor, pointer);
  user-select: none;

  display: flex;
  align-items: center;

  width: 100%;
  padding: 0.5rem 0.25rem 0.5rem 0.625rem;
  padding-inline-start: 0.625rem;
  padding-inline-end: 0.25rem;
  border-bottom-right-radius: var(--border-bottom-right-radius);
  border-bottom-left-radius: var(--border-bottom-left-radius);

  font-size: 0.9375rem;
  font-weight: var(--font-weight-medium);
  line-height: 2.125rem;
  color: var(--accent-color);
  white-space: nowrap;

  background: var(--background-color);

  transition: background-color 0.15s, color 0.15s, opacity 150ms, backdrop-filter 150ms, filter 150ms;

  .label {
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .Message .has-appendix &::before {
    content: "";

    position: absolute;
    bottom: -0.1875rem;
    left: -0.5625rem;

    display: block;

    width: 0.5625rem;
    height: 1.25rem;

    opacity: 0;
    background-image: url('data:image/svg+xml,%3Csvg width="9" height="20" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"%3E%3Cdefs%3E%3Cfilter x="-50%25" y="-14.7%25" width="200%25" height="141.2%25" filterUnits="objectBoundingBox" id="a"%3E%3CfeOffset dy="1" in="SourceAlpha" result="shadowOffsetOuter1"/%3E%3CfeGaussianBlur stdDeviation="1" in="shadowOffsetOuter1" result="shadowBlurOuter1"/%3E%3CfeColorMatrix values="0 0 0 0 0.0621962482 0 0 0 0 0.138574144 0 0 0 0 0.185037364 0 0 0 0.15 0" in="shadowBlurOuter1"/%3E%3C/filter%3E%3Cpath d="M3 17h6V0c-.193 2.84-.876 5.767-2.05 8.782-.904 2.325-2.446 4.485-4.625 6.48A1 1 0 003 17z" id="b"/%3E%3C/defs%3E%3Cg fill="none" fill-rule="evenodd"%3E%3Cuse fill="%23000" filter="url(%23a)" xlink:href="%23b"/%3E%3Cuse fill="%23FFF" xlink:href="%23b"/%3E%3C/g%3E%3C/svg%3E');
    background-position: bottom left;

    transition: opacity 0.15s, filter 0.15s;

    .theme-dark #root & {
      filter: invert(0.83);
    }
  }

  .custom-shape & {
    position: relative;

    align-items: flex-start;

    width: 2.25rem;
    height: 3.375rem;
    padding: 0.375rem;
    border-radius: 1.375rem;

    color: white;

    opacity: 0;

    @include mixins.action-message-bg;

    &::after {
      content: attr(data-cnt);

      position: absolute;
      bottom: -0.0625rem;
      left: 0;

      display: block;

      width: 100%;

      font-size: 0.75rem;
      text-align: center;
    }

    &:hover {
      opacity: 0.85;
      background-color: var(--action-message-bg);
    }

    &.disabled {
      background-color: var(--action-message-bg);
    }

    .Message:hover &, &.loading {
      opacity: 1;
    }

    &[data-cnt="0"] {
      height: 2.25rem;
      &::after {
        display: none;
      }
    }

    .icon-comments-sticker {
      display: block;
      margin: 0 auto;
      font-size: 1.5rem;
    }

    .recent-repliers,
    .icon-comments,
    .label,
    .CommentButton_icon-open {
      display: none;
    }

    @media (pointer: coarse) {
      opacity: 1 !important;
    }
  }

  &.CommentButton-custom-shape {
    background-color: transparent;

    &::after {
      top: 1.5rem;
      bottom: auto;
    }

    &:hover {
      background-color: rgba(255, 255, 255, 0.08);
      filter: none;
      backdrop-filter: none;
    }

    &.disabled {
      background-color: rgba(255, 255, 255, 0.08);
    }
  }

  &:hover {
    background: var(--hover-color);

    .Message .has-appendix &::before {
      opacity: 1;
    }

    .Avatar {
      border-color: var(--hover-color) !important;
    }
  }

  .is-forwarded:not(.custom-shape) &,
  .document &,
  .audio &,
  .voice &,
  .poll &,
  .text &,
  .giveaway &,
  .unsupported & {
    border-top: 1px solid var(--color-borders);
  }

  .message-content.has-solid-background & {
    margin: 0.375rem -0.5rem -0.375rem;
  }

  .message-content.document &,
  .message-content.audio &,
  .message-content.voice &,
  .message-content.poll &,
  .message-content.giveaway &,
  .message-content.has-solid-background.text &,
  .message-content.has-solid-background.is-forwarded &,
  .message-content.unsupported & {
    width: calc(100% + 1rem);
  }

  .icon-comments-sticker {
    display: none;
  }

  .icon-comments {
    margin-inline-end: 0.875rem;
    font-size: 1.5625rem;
    line-height: 2rem;
  }

  .CommentButton_icon-open {
    position: absolute;
    font-size: 1.5rem;
  }

  .recent-repliers {
    display: inline-flex;
    align-items: center;
    margin-inline-start: -0.125rem;
    margin-inline-end: 0.5rem;

    .Avatar {
      z-index: 3;

      overflow: hidden;

      margin-inline-end: 0;
      border: 2px solid var(--color-background);
      /* stylelint-disable-next-line plugin/no-low-performance-animation-properties */
      transition: border 0.15s;

      .emoji {
        width: 1rem;
        background-size: 1rem;
      }

      + .Avatar {
        z-index: 2;

        + .Avatar {
          z-index: 1;
        }
      }

      &:not(:first-child) {
        margin-inline-start: -0.75rem;
      }
    }
  }

  &.has-unread .label {
    &::after {
      content: "";

      display: inline-block;

      width: 0.375rem;
      height: 0.375rem;
      margin-inline-start: 0.375rem;
      border-radius: 50%;

      vertical-align: middle;

      background-color: var(--accent-color);
    }
  }

  &.disabled {
    pointer-events: none;
    cursor: var(--custom-cursor, default);
    opacity: 0.65;
    background-color: var(--hover-color);
  }
}

.CommentButton_loading, .CommentButton_icon-open, .CommentButton_icon-comments {
  transition: transform 250ms ease-in-out, opacity 250ms ease-in-out;
}

.CommentButton_icon-open {
  right: 0;
}

.CommentButton_loading {
  --spinner-size: 1.5rem;

  position: absolute;
  right: 0.5rem;
  flex-shrink: 0;

  .CommentButton-custom-shape & {
    right: 0;
  }
}

.CommentButton_right {
  position: relative;
  width: 2.5rem;
  height: 1.5rem;
  margin-inline-start: auto;
}

.CommentButton_hidden {
  transform: scale(0.4);
  opacity: 0;
}
