/*
 * Copyright 2019 dialog LLC <info@dlg.im>
 */

@import '../../styles/variables.css';

:root {
  --sidebar-recent-item-font-family: var(--default-font-family);
  --sidebar-recent-item-font-size: var(--default-recent-item-font-size);
  --sidebar-recent-item-item-height: 60px;
  --sidebar-recent-item-top-padding: 12px;
  --sidebar-recent-item-right-padding: 12px;
  --sidebar-recent-item-bottom-padding: 12px;
  --sidebar-recent-item-left-padding: 10px;
  --sidebar-recent-item-background: #fafafa;
  --sidebar-recent-item-default-color: color-mod(
    var(--sidebar-recent-item-background) blend(#000 40%)
  );
  --sidebar-recent-item-hover-color: #000;
  --sidebar-recent-item-unread-color: var(--sidebar-recent-item-hover-color);
  --sidebar-recent-item-hover-background-color: #e6e6e6;
  --sidebar-recent-item-pressed-background-color: color-mod(
    var(--sidebar-recent-item-hover-background-color) shade(2%)
  );
  --sidebar-recent-item-message-color: color-mod(
    var(--sidebar-recent-item-background) blend(#000 40%)
  );
  --sidebar-recent-item-hover-message-color: color-mod(
    var(--sidebar-recent-item-message-color) shade(20%)
  );
  --sidebar-recent-item-counter-size: 24px;
  --sidebar-recent-item-counter-background: var(--color-primary);
  --sidebar-recent-item-counter-font-size: 13px;
  --sidebar-recent-item-counter-color: #fff;
  --sidebar-recent-item-counter-muted-color: var(
    --sidebar-recent-item-counter-color
  );
  --sidebar-recent-item-counter-muted-background: #a4a4a4;
  --sidebar-recent-item-active-background-color: var(--violet-blue);
  --sidebar-recent-item-active-background-gradient: var(--default-gradient);
  --sidebar-recent-item-active-color: #fff;
  --sidebar-recent-item-active-hover-color: var(
    --sidebar-recent-item-active-color
  );
  --sidebar-recent-item-active-message-color: color-mod(
    var(--sidebar-recent-item-active-background-color) blend(#fff 80%)
  );
  --sidebar-recent-item-active-counter-color: color-mod(#fff alpha(50%));
  --sidebar-recent-item-active-hover-background-color: var(
    --sidebar-recent-item-active-background-color
  );
  --sidebar-recent-item-active-hover-background-gradient: var(
    --sidebar-recent-item-active-background-gradient
  );
  --sidebar-recent-item-icon-color: var(--sidebar-recent-item-default-color);
  --sidebar-recent-item-active-icon-color: var(
    --sidebar-recent-item-active-color
  );
  --sidebar-recent-item-highlight-color: var(--color-primary);
  --sidebar-recent-item-draft-color: var(--color-danger);
}

/* Styles */
.container {
  all: initial;
  display: flex;
  flex-direction: row;
  box-sizing: border-box;
  height: var(--sidebar-recent-item-item-height);
  padding-top: var(--sidebar-recent-item-top-padding);
  padding-right: var(--sidebar-recent-item-right-padding);
  padding-bottom: var(--sidebar-recent-item-top-padding);
  padding-left: var(--sidebar-recent-item-left-padding);
  cursor: pointer;
  user-select: none;
  font-family: var(--sidebar-recent-item-font-family);
  flex-wrap: nowrap;
  justify-content: flex-start;
  align-content: stretch;
  align-items: flex-start;
  color: var(--sidebar-recent-item-default-color);
  background-color: var(--sidebar-recent-item-background);

  &:hover {
    background-color: var(--sidebar-recent-item-hover-background-color);
    color: var(--sidebar-recent-item-hover-color);

    & .message {
      color: var(--sidebar-recent-item-hover-message-color);
    }
    & .icon {
      color: currentColor;
    }
  }

  &:active {
    background-color: var(--sidebar-recent-item-pressed-background-color);
  }
}

.avatar {
  margin-right: 10px;
  flex: 0 0 auto;
  align-self: auto;
}

.text {
  display: flex;
  flex-flow: column;
  vertical-align: middle;
  flex: 1 1 auto;
  position: relative;
  @mixin flex-fix;
}

.title {
  display: inline-block;
  letter-spacing: -0.27px;
  font-size: var(--sidebar-recent-item-font-size);
  font-weight: 500;
  line-height: 20px;
  flex: 0 1 auto;
  @mixin flex-fix;
  @mixin text-overflow-ellipsis;
}

.header {
  height: 20px;
  display: flex;
  flex-flow: row nowrap;
  align-items: center;
  align-content: center;
  justify-content: flex-start;
}

.icon {
  flex: 0 0 auto;
  display: inline-block;
  margin-right: 2px;
  color: currentColor;
}

.favIcon {
  composes: icon;
  /* margin-top: -2px; */
}

.groupIcon {
  composes: icon;
}

.channelIcon {
  composes: icon;
}

.muteIcon {
  color: currentColor;
  margin-left: 4px;
}

.message {
  letter-spacing: -0.25px;
  font-size: 13px;
  line-height: 16px;
  height: 16px;
  color: var(--sidebar-recent-item-message-color);
  @mixin text-overflow-ellipsis;
}

.sender,
.service,
.highlight {
  height: 17px;
  line-height: 17px;
  color: var(--sidebar-recent-item-highlight-color);
}

.draft {
  color: var(--sidebar-recent-item-draft-color);
}

.counter {
  display: flex;
  min-width: var(--sidebar-recent-item-counter-size);
  padding: 2px 4px;
  box-sizing: border-box;
  height: var(--sidebar-recent-item-counter-size);
  line-height: var(--sidebar-recent-item-counter-size);
  border-radius: calc(var(--sidebar-recent-item-counter-size) / 2);
  background-color: var(--sidebar-recent-item-counter-background);
  font-family: var(--sidebar-recent-item-font-family);
  font-size: var(--sidebar-recent-item-counter-font-size);
  font-weight: 400;
  flex: 0 0 auto;
  justify-content: center;
  align-items: center;
  align-content: center;
  align-self: center;
  margin-left: 4px;
  color: var(--sidebar-recent-item-counter-color);
}

.muted {
  color: var(--sidebar-recent-item-counter-muted-color);
  background-color: var(--sidebar-recent-item-counter-muted-background);
}

.unread {
  color: var(--sidebar-recent-item-unread-color);
}

.typing {
  height: 6px !important;
  margin-right: 6px;
}

/* State */
.active {
  background-color: var(--sidebar-recent-item-active-background-color);
  background-image: var(--sidebar-recent-item-active-background-gradient);
  color: var(--sidebar-recent-item-active-color);

  &:hover {
    color: var(--sidebar-recent-item-active-hover-color);
    background-color: var(--sidebar-recent-item-active-hover-background-color);
    background-image: var(
      --sidebar-recent-item-active-hover-background-gradient
    );

    & .message {
      color: var(--sidebar-recent-item-active-message-color);
    }
  }

  & .counter {
    background-color: var(--sidebar-recent-item-active-counter-color);
  }

  /* TODO: shitty code, remove this ASAP */
  & .typing > div {
    background-color: var(--sidebar-recent-item-active-message-color);
  }

  & .draft,
  & .sender,
  & .message,
  & .service,
  & .highlight {
    color: var(--sidebar-recent-item-active-message-color);
  }
}

.preview {
  overflow: hidden;
  height: 17px;
}
