@use '../../styles/mixins';

.Composer {
  --base-height: 3rem;

  align-items: flex-end;

  .select-mode-active + .middle-column-footer & {
    position: absolute;
    bottom: 0;
    padding-right: 2rem;

    &::before {
      right: 2.125rem;

      @media (max-width: 600px) {
        right: 1rem;
      }
    }

    .svg-appendix {
      opacity: 0;
    }

    @media (max-width: 600px) {
      bottom: env(safe-area-inset-bottom);
      padding-right: 1rem;
    }
  }

  .form-control {
    --border-width: 0;
  }

  .effect-icon {
    cursor: var(--custom-cursor, pointer);

    position: absolute;
    right: -0.25rem;
    bottom: -0.25rem;

    display: grid;
    place-items: center;

    width: 1.5rem;
    height: 1.5rem;
    border: 1px solid var(--color-borders);
    border-radius: 50%;

    font-size: 1rem;
    line-height: 1;
    color: var(--color-text);

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

    & > .emoji {
      width: 1rem !important;
      height: 1rem !important;
    }
  }

  @keyframes show-send-as-button {
    from {
      transform: scale(0);
      /* stylelint-disable-next-line plugin/no-low-performance-animation-properties */
      width: 1rem;
    }

    to {
      transform: scale(1);
      /* stylelint-disable-next-line plugin/no-low-performance-animation-properties */
      width: var(--base-height);
    }
  }

  > .Button {
    overflow: visible;
    flex-shrink: 0;

    width: var(--base-height);
    height: var(--base-height);
    margin-left: 0.5rem;

    &:not(.danger) {
      color: var(--color-composer-button);
    }

    .icon-send,
    .icon-schedule,
    .icon-forward,
    .icon-microphone-alt,
    .icon-check,
    .icon-view-once,
    .icon-one-filled {
      position: absolute;
    }

    .paidStarsBadgeText {
      display: inline-flex;
      align-items: center;

      .star-amount-icon {
        margin-inline-start: 0;
      }
    }

    &.cancel {
      position: relative;
      z-index: 1;

      &:hover,
      &.active {
        background: var(--color-chat-hover);
      }
    }

    &.recording {
      position: relative;
      z-index: 0;
      transition: box-shadow 0.1s;
    }

    &.story-reaction-button {
      --custom-emoji-size: 1.5rem;

      overflow: visible !important;

      &:hover {
        background-color: var(--color-background) !important;
      }

      .icon-heart {
        transition: color 0.2s ease-out;
      }

      .story-reaction-heart {
        color: var(--color-heart) !important;
      }
    }

    .paidStarsBadgeIcon {
      margin-inline-start: 0;
      margin-inline-end: 0.0625rem;
    }

    .paidStarsBadge {
      position: absolute;
      top: -1rem;

      height: auto;
      margin-top: 0.625rem;
      padding-block: 0.25rem;
      padding-inline: 0.375rem;

      font-size: 0.8125rem;
      font-weight: var(--font-weight-semibold) !important;
      line-height: 1;

      &.visible {
        animation: grow-icon 0.4s ease-out;
      }

      &.hiding {
        animation: hide-icon 0.4s forwards ease-out;
      }

      &.hidden {
        pointer-events: none;
        opacity: 0;
      }

      .icon {
        font-size: 0.875rem;
      }
    }

    &.send, &.sendOneTime {
      .icon-send {
        animation: grow-icon 0.4s ease-out;
      }

      .icon-microphone-alt,
      .icon-forward,
      .icon-check,
      .icon-schedule {
        animation: hide-icon 0.4s forwards ease-out;
      }
    }

    &.schedule {
      .icon-schedule {
        animation: grow-icon 0.4s ease-out;
      }

      .icon-microphone-alt,
      .icon-check,
      .icon-forward,
      .icon-send {
        animation: hide-icon 0.4s forwards ease-out;
      }
    }

    &.record {
      .icon-microphone-alt {
        animation: grow-icon 0.4s ease-out;
      }

      .icon-send,
      .icon-check,
      .icon-forward,
      .icon-schedule {
        animation: hide-icon 0.4s forwards ease-out;
      }
    }

    &.edit {
      .icon-check {
        animation: grow-icon 0.4s ease-out;
      }

      .icon-send,
      .icon-forward,
      .icon-microphone-alt,
      .icon-schedule {
        animation: hide-icon 0.4s forwards ease-out;
      }
    }

    &.forward {
      --color-primary: #212121;

      .icon-forward {
        --color-primary: #707478;

        animation: grow-icon 0.4s ease-out;
      }

      .icon-send,
      .icon-check,
      .icon-microphone-alt,
      .icon-schedule {
        animation: hide-icon 0.4s forwards ease-out;
      }
    }

    &.view-once {
      .icon-one-filled {
        animation: hide-icon 0.4s forwards ease-out;
      }
      .icon-view-once {
        animation: grow-icon 0.4s ease-out;
      }
      &.active {
        .icon-view-once {
          animation: hide-icon 0.4s forwards ease-out;
        }
        .icon-one-filled {
          animation: grow-icon 0.4s ease-out;
        }
      }
    }

    &.not-ready > .icon {
      animation-duration: 0ms !important;
    }

    @media (hover: hover) {
      &:not(:active):not(:focus):not(:hover) {
        .icon-send,
        .icon-schedule,
        .icon-forward,
        .icon-check {
          color: var(--color-primary);
        }
      }
    }

    @media (hover: none) {
      &:not(:active):not(:focus) {
        .icon-send,
        .icon-schedule,
        .icon-forward,
        .icon-check {
          color: var(--color-primary);
        }
      }
    }
  }

  &:not(.mounted) > .Button,
  body.no-message-composer-animations & > .Button {
    .icon-send,
    .icon-microphone-alt,
    .icon-check,
    .icon-schedule {
      animation-duration: 0ms !important;
    }
  }

  .send-as-button {
    z-index: 1;
  }

  body:not(.no-message-composer-animations) & .send-as-button.appear-animation {
    transform-origin: right;
    animation: 0.25s ease-in-out forwards show-send-as-button;
  }

  > .ReactionSelector {
    --color-background-compact-menu: rgba(0, 0, 0, 0.3);
    --color-interactive-element-hover: rgba(255, 255, 255, 0.1);
    --color-text: #fff;

    position: absolute;
    z-index: 1;
    top: -0.75rem;
    right: auto;
    left: 50%;
    transform: translate(-50%, -100%);

    .ReactionSelector__bubble-small,
    .ReactionSelector__bubble-big {
      display: none;
    }

    .ReactionSelector__show-more {
      transform: scaleY(-1);
      color: #fff;
    }

    .ReactionSelector__hint {
      color: #fff;
    }

    @media (max-width: 600px) {
      top: -4.25rem;
    }
  }

  .composer-action-buttons-container {
    position: relative;
    width: auto;

    + .AttachMenu {
      margin-left: var(--action-button-compact-fix);
    }
  }

  .composer-action-buttons {
    top: 0;
    right: 0;
    left: auto;

    display: flex;

    width: auto;
    height: auto;
  }
}

.mobile-symbol-menu-button {
  position: relative;
  width: 2.875rem;
  height: 2.875rem;

  .icon-smile,
  .icon-keyboard,
  .Spinner {
    position: absolute;
  }

  .Spinner {
    --spinner-size: 1.5rem;
  }

  .icon-smile {
    animation: grow-icon 0.4s ease-out;
  }

  .icon-keyboard,
  .Spinner {
    animation: hide-icon 0.4s forwards ease-out;
  }

  &.not-ready > .icon {
    animation-duration: 0ms !important;
  }

  &.is-loading {
    .Spinner {
      animation: grow-icon 0.4s ease-out;
    }

    .icon-keyboard,
    .icon-smile {
      animation: hide-icon 0.4s forwards ease-out;
    }
  }

  &.menu-opened {
    .icon-keyboard {
      animation: grow-icon 0.4s ease-out;
    }

    .icon-smile,
    .Spinner {
      animation: hide-icon 0.4s forwards ease-out;
    }
  }
}

.composer-wrapper {
  position: relative;
  z-index: 1;

  flex-grow: 1;

  max-width: calc(100% - 3.5rem);
  border-radius: var(--border-radius-messages);
  border-bottom-right-radius: 0;

  background: var(--color-background);
  box-shadow: 0 1px 2px var(--color-default-shadow);

  &.with-story-tweaks {
    border-radius: var(--border-radius-default-small);
    border-bottom-right-radius: 0;
    box-shadow: none;
    &.is-need-premium {
      border-bottom-right-radius: var(--border-radius-default-small);
    }
  }

  .svg-appendix {
    position: absolute;
    right: -0.5rem;
    bottom: -0.1875rem;

    width: 0.5625rem;
    height: 1.25rem;

    font-size: 1rem !important;

    transition: opacity 200ms;

    .corner {
      fill: var(--color-background);
    }
  }

  @media (max-width: 600px) {
    max-width: calc(100% - 3.375rem);
  }
}

.message-input-wrapper {
  --action-button-size: var(--base-height, 3rem);
  --action-button-compact-fix: -0.75rem;

  display: flex;

  .input-scroller {
    --_scroller-right-gap: calc((var(--action-button-size) + var(--action-button-compact-fix) - 0.125rem));

    scrollbar-gutter: stable;
    margin-right: calc(-1 * var(--_scroller-right-gap));
    padding-right: var(--_scroller-right-gap);
  }

  > .Spinner {
    --spinner-size: 1.5rem;

    align-self: center;
    margin-right: 0.5rem;
  }

  .composer-action-button {
    flex-shrink: 0;
    align-self: flex-end;

    width: var(--action-button-size);
    height: var(--action-button-size);
    margin: 0;
    padding: 0;

    background: none !important;

    &:not(.faded):not(.activated) {
      color: var(--color-composer-button);
    }

    + .composer-action-button {
      margin-left: var(--action-button-compact-fix);
    }

    &.bot-menu {
      --icon-width: 1.25rem;
      --icon-gap: 0.25rem;
      --padding-sides: 0.5rem;

      display: inline-flex;
      justify-content: flex-start;

      width: 2rem;
      max-width: clamp(0px, 12rem, 25vw);
      height: 2rem;
      margin: 0 0.5rem 0.5rem;
      padding: 0 var(--padding-sides);
      border-radius: 0.5rem;

      color: white !important;
      text-transform: none;

      background: var(--color-primary) !important;
      /* stylelint-disable-next-line plugin/no-low-performance-animation-properties */
      transition: 0.25s ease-out width, 0.25s ease-out border-radius;

      &.open {
        width: calc(var(--bot-menu-text-width) + var(--padding-sides) * 2 + var(--icon-gap) + var(--icon-width));
        border-radius: 1rem;
      }
    }

    .bot-menu-icon {
      transform: translateX(-0.15rem);
      margin-right: var(--icon-gap);
      font-size: 1.25rem;
      transition: 0.25s ease-out transform;

      &.open {
        transform: translateX(0);
      }
    }

    .bot-menu-text {
      --emoji-size: 1rem;

      overflow: hidden;

      font-size: 0.875rem;
      font-weight: var(--font-weight-medium);
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    &.bot-commands {
      color: var(--color-primary) !important;

      // SymbolMenu button should be accessible if BotCommandsMenu opened
      body.is-touch-env &.activated + .Button.mobile-symbol-menu-button {
        z-index: calc(var(--z-menu-backdrop) + 1);
      }
    }

    &.scheduled-button .icon::after {
      content: "";

      position: absolute;
      top: 0.75rem;
      right: 0.75rem;

      box-sizing: content-box;
      width: 0.5rem;
      height: 0.5rem;
      border-radius: 50%;

      background: var(--color-green-darker);
    }
  }

  > .input-group {
    flex-grow: 1;
    margin-bottom: 0;
  }

  .recording-state {
    position: relative;

    display: inline-block;

    height: var(--base-height);
    padding: 0 3.125rem 0 1rem;

    font-family: var(--font-family);
    font-variant-numeric: tabular-nums;
    line-height: var(--base-height);

    &::after {
      content: "";

      position: absolute;
      top: 50%;
      right: 1.3125rem;

      width: 0.75rem;
      height: 0.75rem;
      margin-top: -0.375rem;
      border-radius: 0.375rem;

      background: var(--color-error);

      animation: recording-blink-like-macos 1.5s infinite;
    }
  }
}

.symbol-menu-trigger {
  position: absolute;
  bottom: 0;
  left: -1rem;
}

@media (min-width: 600px) {
  .symbol-menu-button {
    width: 2rem !important;
    margin-left: 0.75rem !important;

    .Button + & {
      margin-left: -0.25rem !important;
    }
  }
}

.input-scroller {
  overflow: hidden;
  min-height: var(--base-height, 3rem);
  max-height: 26rem;

  /* stylelint-disable-next-line plugin/no-low-performance-animation-properties */
  transition: height 100ms ease;

  &.overflown {
    overflow-y: auto;
  }

  & > .input-scroller-content {
    position: relative;
  }

  body.no-message-composer-animations & {
    transition: none !important;
  }

  .emoji {
    pointer-events: none;

    width: 1.25rem;
    height: 1.25rem;
    margin: 0 1px -5px;

    vertical-align: 0;
  }

  .custom-emoji {
    margin: 0;
    vertical-align: text-top;

    &.colorable {
      filter: var(--input-custom-emoji-filter);
    }
  }

  // Workaround to preserve correct input height
  &.clone {
    .custom-emoji {
      vertical-align: bottom;
    }
  }

  @media (max-width: 600px) {
    max-height: 16rem;
  }
}

#message-input-text,
#story-input-text,
#caption-input-text {
  position: relative;
  flex-grow: 1;

  .form-control {
    unicode-bidi: plaintext;
    overflow: hidden;

    height: auto;
    padding: calc((var(--base-height, 3rem) - var(--composer-text-size, 1rem) * 1.375) / 2) 0.875rem;
    border: none !important;
    border-radius: 0 !important;

    font-family: var(--font-family);
    font-size: var(--composer-text-size, 1rem);
    line-height: 1.375;
    text-align: initial;

    background: transparent !important;
    box-shadow: none !important;
    caret-color: var(--color-text);

    &.touched {
      & ~ .placeholder-text {
        transform: translateX(1rem);
        opacity: 0;
      }
    }

    &.focus-disabled {
      pointer-events: none;
    }
  }

  .placeholder-star-icon {
    margin-inline-start: 0.25rem;
    margin-inline-end: 0.0625rem;
    line-height: 1;
  }
  .forced-placeholder,
  .placeholder-text {
    pointer-events: none;

    position: absolute;
    top: calc((3.25rem - var(--composer-text-size, 1rem) * 1.375) / 2);
    bottom: auto;

    unicode-bidi: plaintext;
    overflow: hidden;
    display: inline-flex;
    align-items: center;

    max-width: 100%;

    font-size: var(--composer-text-size, 1rem);
    line-height: 1.3125;
    color: var(--color-placeholders);
    text-align: initial;
    text-overflow: ellipsis;
    white-space: nowrap;

    transition: opacity 200ms ease-out, transform 200ms ease-out;

    &.with-icon {
      display: inline-flex;
      align-items: center;
    }

    .placeholder-icon {
      margin-inline-end: 0.25rem;
    }

    @media (min-width: 600px) {
      left: 0.5rem;
    }
  }

  .forced-placeholder {
    z-index: var(--z-below);
    left: 0;

    @media (min-width: 600px) {
      left: 0.5rem;
    }
  }

  &[dir="rtl"] {
    .placeholder-text {
      right: 0;
    }

    .touched ~ .placeholder-text {
      transform: translateX(-1rem);
    }
  }

  .text-entity-link {
    cursor: var(--custom-cursor, default);
    color: var(--color-links) !important;
    text-decoration: none;

    &:hover,
    &:active,
    &:visited {
      text-decoration: underline !important;
    }
  }

  .spoiler {
    padding: 0 0.3125rem 0.125rem 0.3125rem;
    border-radius: 0.5rem;

    text-shadow:
      -2px -2px 0 var(--color-background),
      2px -2px 0 var(--color-background),
      -2px 2px 0 var(--color-background),
      2px 2px 0 var(--color-background);

    background-image: url("../../assets/spoiler-dots-black.png");
    background-size: auto min(100%, 1.125rem);
  }

  html.theme-dark & .spoiler {
    background-image: url("../../assets/spoiler-dots-white.png");
  }

  .clone {
    pointer-events: none;

    position: absolute;
    z-index: -10;
    top: 0;
    right: 0;
    left: 0;

    unicode-bidi: plaintext;

    text-align: initial;

    opacity: 0;
  }
}

#message-input-text {
  .form-control {
    height: auto;
    margin-bottom: 0;
    padding: calc((var(--base-height, 3rem) - var(--composer-text-size, 1rem) * 1.3125) / 2) 0;

    line-height: 1.3125;
    white-space: pre-wrap;
  }

  .forced-placeholder,
  .placeholder-text {
    top: calc((var(--base-height, 3rem) - var(--composer-text-size, 1rem) * 1.3125) / 2);
  }

  &:not(:only-child) {
    .form-control {
      padding-right: 0;
      padding-left: 0;

      @media (min-width: 600px) {
        padding-left: 0.5rem;
      }
    }
  }

  .ComposerEmbeddedMessage + .message-input-wrapper &,
  .WebPagePreview + .message-input-wrapper & {
    .form-control.overflown {
      margin-top: 0.75rem;
    }
  }
}

#story-input-text,
#caption-input-text {
  --margin-for-scrollbar: 2rem;
  .input-scroller {
    min-height: var(--base-height, 3rem);
    max-height: 10rem;
    margin-right: calc((var(--margin-for-scrollbar) + 1rem) * -1);

    &.is-need-premium {
      margin-right: 0.5rem;
    }

    &:has(.form-control:focus) {
      border-color: var(--color-primary);
    }
  }

  .input-scroller-content {
    margin-right: calc(var(--margin-for-scrollbar) + 0.5rem);
    &.is-need-premium {
      margin-right: 0;
    }
  }

  .placeholder-text {
    top: auto;
    left: 0.875rem;
  }

  .unlock-button {
    width: auto;
    height: auto;
    margin-left: 0.4375rem;
    padding-top: 0.125rem;
    padding-right: 0.4375rem;
    padding-bottom: 0.125rem;
    padding-left: 0.4375rem;

    color: var(--color-text);
    text-transform: lowercase;
    &:hover,
    &.active {
      background: var(--color-chat-hover);
    }
  }
}

#caption-input-text .placeholder-text {
  bottom: 0.8125rem;
}

#story-input-text .placeholder-text {
  top: calc((var(--base-height, 3rem) - var(--composer-text-size, 1rem) * 1.3125) / 2);
  left: 0.875rem;

  &.is-need-premium {
    pointer-events: auto;
  }
}

.composer-tooltip {
  scrollbar-gutter: stable;

  position: absolute;
  bottom: calc(100% + 0.5rem);
  left: 0;
  transform-origin: bottom;
  transform: translateY(1.5rem);

  overflow-x: hidden;
  overflow-y: auto;

  width: 100%;
  max-height: 15rem;
  padding: 0.5rem;
  border-radius: var(--border-radius-messages);

  opacity: 0;
  background: var(--color-background);
  box-shadow: 0 1px 2px var(--color-default-shadow);

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

  @include mixins.adapt-padding-to-scrollbar(0.5rem);

  &:not(.shown) {
    display: none;
  }

  &.open {
    transform: translateY(0);
    opacity: 1;
  }

  .Loading {
    margin: 1rem 0;
  }
}

@keyframes recording-blink-like-macos {
  from {
    opacity: 1;
  }
  to {
    opacity: 0.3;
  }
}
