@import "../../../styles/mixins";

.Composer {
  align-items: flex-end;

  .select-mode-active + .middle-column-footer & {
    position: absolute;
    padding-right: 2rem;
    bottom: env(safe-area-inset-bottom);

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

    &::before {
      right: 2.125rem;

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

    .svg-appendix {
      opacity: 0;
    }
  }

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

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

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

  > .Button {
    flex-shrink: 0;
    margin-left: 0.5rem;

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

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

    .icon-send,
    .icon-schedule,
    .icon-microphone-alt,
    .icon-check {
      position: absolute;
    }

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

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

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

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

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

      .icon-microphone-alt,
      .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-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-schedule {
        animation: hide-icon 0.4s forwards ease-out;
      }
    }

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

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

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

    body.animation-level-0 &,
    body.animation-level-1 & {
      .icon-send,
      .icon-microphone-alt,
      .icon-check,
      .icon-schedule {
        animation-duration: 0ms !important;
      }
    }
  }

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

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

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

    .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 > i {
      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;
      }
    }
  }
}

#message-compose {
  flex-grow: 1;
  max-width: calc(100% - 4rem);
  background: var(--color-background);
  border-radius: var(--border-radius-messages);
  border-bottom-right-radius: 0;
  box-shadow: 0 1px 2px var(--color-default-shadow);
  position: relative;
  z-index: 1;

  .svg-appendix {
    position: absolute;
    bottom: -0.1875rem;
    /* stylelint-disable-next-line plugin/whole-pixel */
    right: -0.551rem; // This value is correct. Safari fix
    width: 0.5625rem;
    height: 1.25rem;
    transition: opacity 200ms;
    font-size: 1rem !important;

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

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

.message-input-wrapper {
  display: flex;

  > .Spinner {
    align-self: center;
    --spinner-size: 1.5rem;
    margin-right: -0.5rem;
  }

  > .AttachMenu > .Button,
  > .Button {
    flex-shrink: 0;
    background: none !important;
    width: 3.5rem;
    height: 3.5rem;
    margin: 0;
    padding: 0;
    align-self: flex-end;

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

    + .Button, + .AttachMenu {
      margin-left: -1rem;
    }

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

      + .Button, + .AttachMenu {
        margin-left: -0.6875rem;
      }
    }

    &.bot-menu {
      --icon-width: 1.25rem;
      --icon-gap: 0.25rem;
      --padding-sides: 0.5rem;
      background: var(--color-primary) !important;
      height: 2rem;
      margin: 0 0.5rem 0.75rem;
      color: white !important;
      text-transform: none;
      display: inline-flex;
      padding: 0 var(--padding-sides);
      width: 2rem;
      max-width: clamp(0px, 12rem, 25vw);
      /* stylelint-disable-next-line plugin/no-low-performance-animation-properties */
      transition: 0.25s ease-out width, 0.25s ease-out border-radius;
      border-radius: 0.5rem;
      justify-content: flex-start;

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

      @media (max-width: 600px) {
        margin-bottom: 0.4375rem;
      }
    }

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

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

    .bot-menu-text {
      font-size: 0.875rem;
      font-weight: 500;
      white-space: nowrap;
      text-overflow: ellipsis;
      overflow: hidden;
    }

    &.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 i::after {
      content: "";
      position: absolute;
      top: 0.75rem;
      right: 0.875rem;
      border: 0.1875rem solid var(--color-background);
      box-sizing: content-box;
      width: 0.5rem;
      height: 0.5rem;
      border-radius: 50%;
      background: var(--color-green-darker);
      box-shadow: -0.375rem -0.25rem 0 -0.1875rem var(--color-background);
      @media (max-width: 600px) {
        top: 0.5rem;
        right: 0.5rem;
      }
    }
  }

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

  .recording-state {
    display: inline-block;
    position: relative;
    line-height: 3.5rem;
    height: 3.5rem;
    padding: 0 3.125rem 0 1rem;
    font-family: var(--font-family);

    &::after {
      content: "";
      width: 0.75rem;
      height: 0.75rem;
      background: var(--color-error);
      border-radius: 0.375rem;
      position: absolute;
      top: 50%;
      margin-top: -0.375rem;
      right: 1.3125rem;
      animation: recording-blink-like-macos 1.5s infinite;
    }

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

#message-input-text,
#caption-input-text {
  position: relative;

  .form-control {
    padding: calc((3.25rem - var(--composer-text-size, 1rem) * 1.375) / 2 - var(--border-width, 0) * 2)
      calc(0.9rem - var(--border-width));
    overflow: hidden;
    line-height: 1.375;
    font-family: var(--font-family);
    unicode-bidi: plaintext;
    text-align: initial;
    font-size: var(--composer-text-size, 1rem);

    &.overflown {
      overflow-y: auto;
      overflow-x: hidden;
    }

    &.touched,
    &:focus {
      & + .placeholder-text {
        display: none;
      }
    }

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

  .forced-placeholder,
  .placeholder-text {
    position: absolute;
    color: var(--color-placeholders);
    pointer-events: none;
    unicode-bidi: plaintext;
    text-align: initial;
    line-height: 1.3125;
    font-size: var(--composer-text-size, 1rem);
    top: calc((3.25rem - var(--composer-text-size, 1rem) * 1.375) / 2);
    bottom: auto;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
  }

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

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

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

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

  .spoiler {
    background-image: url("../../../assets/spoiler-dots-black.png");
    background-size: auto min(100%, 1.125rem);
    border-radius: 0.5rem;
    padding: 0 0.3125rem 0.125rem 0.3125rem;
    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);
  }

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

  .clone {
    position: absolute;
    top: 0;
    left: 0;
    opacity: 0;
    pointer-events: none;
    z-index: -10;
    unicode-bidi: plaintext;
    text-align: initial;
  }
}

#message-input-text {
  flex-grow: 1;

  .form-control {
    margin-bottom: 0;
    background: transparent !important;
    border: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    caret-color: var(--color-text);
    min-height: 3.5rem;
    max-height: 26rem;
    line-height: 1.3125;
    padding: calc((3.5rem - var(--composer-text-size, 1rem) * 1.3125) / 2) 0;
    white-space: pre-wrap;

    @media (max-width: 600px) {
      height: 2.875rem;
      min-height: 2.875rem;
      max-height: 16rem;
      padding: calc((2.875rem - var(--composer-text-size, 1rem) * 1.3125) / 2) 0;
      overflow: auto;
    }

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

    body.animation-level-0 & {
      transition: none !important;
    }
  }

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

    @media (max-width: 600px) {
      top: calc((2.875rem - var(--composer-text-size, 1rem) * 1.3125) / 2);
    }
  }

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

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

  .emoji {
    width: 1.25rem;
    height: 1.25rem;
    margin: 0 1px -5px;
    vertical-align: 0;
    pointer-events: none;
  }
}

#caption-input-text {
  .form-control {
    height: 3.25rem;
    min-height: 3.25rem;
    max-height: 15rem;
  }

  .placeholder-text {
    bottom: 0.8125rem;
    left: 0.9375rem;
  }
}

.composer-tooltip {
  position: absolute;
  bottom: calc(100% + 0.5rem);
  left: 0;
  width: 100%;
  background: var(--color-background);
  border-radius: var(--border-radius-messages);
  padding: 0.5rem 0;
  max-height: 15rem;

  overflow-x: hidden;
  overflow-y: auto;
  @include overflow-y-overlay();

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

  opacity: 0;
  transform: translateY(1.5rem);
  transform-origin: bottom;
  transition: opacity var(--layer-transition), transform var(--layer-transition);

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

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

  .Loading {
    margin: 1rem 0;
  }
}

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