/**
 * @license
 * Copyright Endlessjs. All Rights Reserved.
 * Licensed under the MIT License. See License.txt in the project root for license information.
 */

@mixin el-chat-theme() {

  el-chat {
    background-color: el-theme(chat-background-color);
    border: el-theme(chat-border);
    border-radius: el-theme(chat-border-radius);
    box-shadow: el-theme(chat-shadow);

    color: el-theme(chat-text-color);
    font-family: el-theme(chat-text-font-family);
    font-size: el-theme(chat-text-font-size);
    font-weight: el-theme(chat-text-font-weight);
    line-height: el-theme(chat-text-line-height);

    el-icon {
      font-size: inherit;
    }

    .header {
      border-bottom: el-theme(chat-divider-width) el-theme(chat-divider-style) el-theme(chat-divider-color);
      border-top-left-radius: el-theme(chat-border-radius);
      border-top-right-radius: el-theme(chat-border-radius);
      padding: el-theme(chat-padding);

      color: el-theme(chat-header-text-color);
      font-family: el-theme(chat-header-text-font-family);
      font-size: el-theme(chat-header-text-font-size);
      font-weight: el-theme(chat-header-text-font-weight);
      line-height: el-theme(chat-header-text-line-height);
    }

    .scrollable {
      overflow: auto;
      flex: 1;
      @include el-scrollbars(
          el-theme(chart-scrollbar-color),
          el-theme(chart-scrollbar-background-color),
          el-theme(chart-scrollbar-width));
    }

    .messages {
      padding: el-theme(chat-padding);
      overflow-y: auto;
      overflow-x: hidden;
      display: flex;
      flex-shrink: 0;
      flex-direction: column;
    }

    .no-messages {
      text-align: center;
    }
  }

  @each $size in el-get-sizes() {
    el-chat.size-#{$size} {
      height: el-theme(chat-#{$size}-height);
    }
  }

  @each $status in el-get-statuses() {
    el-chat.status-#{$status} {
      .header {
        background-color: el-theme(chat-#{$status}-background-color);
        color: el-theme(chat-#{$status}-text-color);
      }
    }
  }

  el-chat-message {
    margin-bottom: 1.5rem;
    display: flex;
    flex-direction: row;

    .message {
      flex: 1;
    }

    .avatar {
      border-radius: 50%;
      flex-shrink: 0;
      background: el-theme(chat-message-avatar-background-color);
      background-position: center;
      background-size: cover;
      background-repeat: no-repeat;
      width: 2.5rem;
      height: 2.5rem;
      text-align: center;
      line-height: 2.5rem;
      font-size: 0.875rem;
      color: white;
    }

    el-chat-message-text {

      display: flex;
      flex-direction: column;

      .sender {
        font-size: 0.875rem;
        color: el-theme(chat-message-sender-text-color);
        margin-bottom: 0.5rem;
      }

      p {
        word-break: break-word;
        white-space: pre-wrap;
        max-width: 100%;
        margin-bottom: 0;
      }

      .text {
        padding: 1rem;
        border-radius: 0.5rem;
      }
    }

    el-chat-message-file {
      display: flex;
      flex-direction: column;

      a {
        color: el-theme(chat-message-file-text-color);
        background: el-theme(chat-message-file-background-color);
        font-size: 4rem;
        text-align: center;
        border: 1px solid el-theme(chat-message-file-text-color);
        width: 10rem;
        height: 10rem;
        overflow: hidden;
        display: flex;
        justify-content: center;
        align-items: center;
        flex-shrink: 0;
        border-radius: 0.5rem;
        &:hover, &:focus {
          text-decoration: none;
          color: el-theme(chat-message-file-text-color);
        }
        div {
          background-size: cover;
          width: 100%;
          height: 100%;
        }
      }

      el-chat-message-text {
        display: block;
        margin-bottom: 0.5rem;
      }

      .message-content-group {
        display: flex;
        flex-direction: row;
        justify-content: flex-end;
        flex-wrap: wrap;

        a {
          @include el-ltr(margin-right, 1rem);
          @include el-rtl(margin-left, 1rem);
          margin-bottom: 1rem;
          width: 5rem;
          height: 5rem;
        }
      }
    }

    el-chat-message-quote {

      p.quote {
        font-style: italic;
        font-size: 0.875rem;
        background: el-theme(chat-message-quote-background-color);
        color: el-theme(chat-message-quote-text-color);
        padding: 1rem;
        border-radius: 0.5rem;
        margin-bottom: 0.5rem;
      }

      .sender {
        font-size: 0.875rem;
        color: el-theme(chat-message-sender-text-color);
        margin-bottom: 0.5rem;
      }
    }

    &.not-reply {
      .message {
        @include el-ltr(margin-left, 0.5rem);
        @include el-rtl(margin-right, 0.5rem);

        @include el-ltr(margin-right, 3rem);
        @include el-rtl(margin-left, 3rem);
      }

      el-chat-message-text {
        align-items: flex-start;

        .text {
          @include el-ltr(border-top-left-radius, 0);
          @include el-rtl(border-top-right-radius, 0);
          background: el-theme(chat-message-background);
          color: el-theme(chat-message-text-color);
        }
      }

      el-chat-message-file {
        align-items: flex-start;
      }
    }

    &.reply {
      flex-direction: row-reverse;

      .message {
        margin-left: 0;

        @include el-ltr(margin-right, 0.5rem);
        @include el-rtl(margin-left, 0.5rem);

        @include el-ltr(margin-left, 3rem);
        @include el-rtl(margin-right, 3rem);
      }

      el-chat-message-text {
        align-items: flex-end;
        .sender {
          @include el-ltr(text-align, right);
          @include el-rtl(text-align, left);
        }

        .text {
          @include el-ltr(border-top-right-radius, 0);
          @include el-rtl(border-top-left-radius, 0);
          background: el-theme(chat-message-reply-background-color);
          color: el-theme(chat-message-reply-text-color);
        }
      }

      el-chat-message-file {
        align-items: flex-end;
      }
    }
  }

  el-chat-form {
    display: flex;
    flex-direction: column;
    padding: el-theme(chat-padding);
    border-top: el-theme(chat-divider-width) el-theme(chat-divider-style) el-theme(chat-divider-color);

    .message-row {
      flex-direction: row;
      display: flex;
    }

    input {
      flex: 1;

      &.with-button {
        border-bottom-right-radius: 0;
        border-top-right-radius: 0;
        @include el-ltr(border-bottom-right-radius, 0);
        @include el-ltr(border-top-right-radius, 0);
        @include el-rtl(border-bottom-left-radius, 0);
        @include el-rtl(border-top-left-radius, 0);
      }
    }

    .send-button {
      el-icon {
        font-size: 1.5rem;
      }

      @include el-ltr {
        border-bottom-left-radius: 0;
        border-top-left-radius: 0;
      }
      @include el-rtl {
        border-bottom-right-radius: 0;
        border-top-right-radius: 0;
      }
    }

    .dropped-files {
      display: flex;
      flex-direction: row;
      margin-bottom: 0.5rem;
      flex-wrap: wrap;

      div {
        background-size: cover;
        width: 3rem;
        height: 3rem;
        border-radius: 0.5rem;
        @include el-ltr(margin-right, 0.5rem);
        @include el-rtl(margin-left, 0.5rem);
        margin-bottom: 0.5rem;
        border: 1px solid currentColor;
        text-align: center;
        font-size: 2rem;
        position: relative;

        .remove {
          position: absolute;
          right: -0.5rem;
          top: -0.875rem;
          font-size: 0.875rem;
          line-height: 1;
          cursor: pointer;
        }

        el-icon {
          width: 65%;
          height: 100%;
        }
      }
    }
  }
}

