@use "lib/viewport";

.topic-map.--op {
  // topic map under OP
  border-top: 1px solid var(--content-border-color);
  border-bottom: none;
  padding-left: calc(
    var(--topic-body-width-padding) + var(--topic-avatar-width)
  );
}

.topic-map.--bottom {
  // topic map at bottom of topic
  grid-area: posts;
  grid-row: 2;
  max-width: calc(
    var(--topic-avatar-width) + var(--topic-body-width) +
      (var(--topic-body-width-padding) * 2)
  );
}

body:not(.archetype-private_message) {
  .topic-map {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    column-gap: 0.75em;
  }
}

.topic-map {
  // both topic maps
  --chart-line-color: var(--tertiary);
  --chart-point-color: var(--tertiary-medium);
  --chart-prediction-color: var(--primary-low-mid);
  border-bottom: 1px solid var(--content-border-color);
  box-sizing: border-box;
  max-width: calc(
    var(--topic-avatar-width) + var(--topic-body-width) +
      (var(--topic-body-width-padding) * 2)
  );
  padding-block: 0.5em;
  overflow-anchor: none;

  @include viewport.until(sm) {
    font-size: var(--font-down-1);
  }

  &.--op,
  &.--bottom {
    @media screen and (width <= 500px) {
      padding-left: 0;
    }
  }

  .--users-summary {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    overflow: hidden;
    height: 2em;
    align-self: center;
    flex: 1 2 0;
    gap: 0.25em;
    min-width: 2em;
    width: 0;

    .avatar {
      width: 2em;
      height: 2em;
      margin-right: 0;
    }

    .avatar-flair,
    .post-count {
      display: none;
    }
  }

  &__stats {
    display: flex;
    flex-wrap: wrap;
    margin: 0;
    list-style: none;
  }

  a {
    overflow-wrap: anywhere;
  }

  &__contents {
    flex-grow: 1;

    .number {
      font-size: var(--font-up-1);
      line-height: 1.2;
    }

    .topic-map__stats {
      gap: 0.75em;

      &.--single-stat {
        .fk-d-menu__trigger {
          flex-direction: row;
          gap: 0.25em;

          span {
            font-size: var(--font-0);
            color: var(--primary-700);
            min-width: unset;
            overflow: visible;
          }
        }
      }

      .fk-d-menu__trigger {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        padding: 0;
        background: transparent;
        min-width: 0;

        .number {
          color: var(--tertiary);
          white-space: nowrap;
        }

        .topic-map__stat-label {
          display: block;
          min-width: 0;
          font-size: var(--font-down-1);
          color: var(--primary-medium);
          width: 100%;

          @include ellipsis;
        }
      }
    }
  }

  .controls {
    display: flex;
    align-items: center;

    .btn {
      margin-right: 0.5em;

      &:last-child {
        margin: 0;
      }
    }
  }

  .participants {
    // PMs
    display: flex;
    flex-wrap: wrap;
    align-items: center;

    & + .controls {
      margin-top: 0.5em;
    }

    &.hide-names .user {
      .username,
      .group-name {
        display: none;
      }
    }

    .user {
      @include ellipsis;
      border: 1px solid var(--content-border-color);
      border-radius: 0.25em;
      padding: 0;
      margin: 0.125em 0.25em 0.125em 0;
      display: flex;
      align-items: center;
      height: 26px;

      .user-link,
      .group-link {
        @include ellipsis;
        color: var(--primary-high);

        &:hover {
          color: var(--primary);
        }
      }

      .avatar,
      .d-icon-users {
        margin-left: 0.25em;
        margin-right: 0.25em;
      }

      .username,
      .group-name {
        margin-right: 0.25em;
      }

      &:last-child {
        margin-right: 0;
      }

      .remove-invited {
        display: flex;
        flex: 1 0 0px;
        align-items: center;
        justify-content: center;
        box-sizing: border-box;
        border-radius: 0 var(--border-radius) var(--border-radius) 0;
        padding-top: 0;
        padding-bottom: 0;
        height: calc(100% + 0.25em);
        margin-right: -4px;
      }
    }
  }

  .add-remove-participant-btn {
    .d-icon {
      margin-left: 0.25em;
    }
  }

  &__buttons {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 0.75em;
  }

  .view-explainer {
    color: var(--primary-700);
    font-size: var(--font-down-1);
  }

  .estimated-read-time {
    display: flex;
    flex-direction: column-reverse;
    align-items: end;
    line-height: 1.2;
    color: var(--primary-high);
    white-space: nowrap;

    span:first-child {
      font-size: var(--font-down-1);
      color: var(--primary-medium);
    }

    @media screen and (width <= 475px) {
      display: none;
    }
  }
}

.mobile-view {
  .d-modal[class*="topic-map__"] {
    h3 {
      font-size: var(--font-up-2);
      padding-inline: 1rem;
    }

    p {
      overflow-wrap: break-word;
    }
  }

  .topic-owner .onscreen-post {
    padding-bottom: 0;
  }
}

// DMenu popups
.fk-d-menu,
.fk-d-menu-modal {
  // shared
  &__inner-content {
    .topic-map__likes-content &,
    .topic-map__links-content &,
    .topic-map__users-content &,
    .topic-map__views-content & {
      flex-direction: column;
      padding-block: 0.75em;
    }
  }

  &.topic-map__likes-content,
  &.topic-map__links-content,
  &.topic-map__users-content,
  &.topic-map__views-content {
    h3 {
      padding-inline: 1rem;
      padding-bottom: 0.5em;
      font-size: var(--font-up-1);
      border-bottom: 1px solid var(--content-border-color);
    }

    .loading-container {
      width: 100%;
    }
  }

  &.topic-map__likes-content,
  &.topic-map__links-content {
    ul {
      margin: 0;
      padding: 0;
      list-style-type: none;
      max-height: 80dvh;
    }
  }

  // per type
  &.topic-map__likes-content {
    li > a {
      display: grid;
      grid-template-areas: "user likes" "post post";
      grid-template-columns: auto 1fr;
      gap: 0.25em;
      padding: 0.75em 1rem;

      .discourse-no-touch & {
        &:hover,
        &:focus-visible {
          outline: 0;
          background: var(--d-hover);
        }
      }
    }

    li:not(:last-of-type) {
      a {
        border-bottom: 1px solid var(--content-border-color);
      }
    }

    .like-section {
      &__user {
        grid-area: user;
        color: var(--primary-high);
        display: flex;
        align-items: center;
        font-weight: bold;
        gap: 0.5em;
      }

      &__likes {
        grid-area: likes;
        display: flex;
        gap: 0.25em;
        color: var(--primary-medium);
        justify-content: end;
        align-items: center;

        .d-icon {
          font-size: var(--font-down-1);
          color: var(--love);
          position: relative;
        }
      }
    }

    p {
      grid-area: post;
      overflow-wrap: anywhere;
      color: var(--primary-high);
      text-align: left;
      margin: 0;
      padding-left: 2em;
    }
  }

  &.topic-map__links-content {
    li {
      display: grid;
      grid-template-columns: auto 1fr;
      grid-template-areas:
        "counter link"
        "counter domain";
      padding: 0.75em 1rem;
      gap: 0.25em;

      &:not(:last-of-type) {
        border-bottom: 1px solid var(--content-border-color);
      }

      .discourse-no-touch & {
        &:hover,
        &:focus-within {
          background: var(--d-hover);

          a {
            outline: 0;
          }
        }
      }
    }

    .topic-link {
      display: grid;
      grid-template-columns: subgrid;
      grid-row: 1;
      grid-column: 1 / -1;

      .content {
        grid-row: 1;
        grid-column: 2;
      }
    }

    .topic-link[data-clicks]::before {
      @include click-counter-badge;
      grid-row: 1;
      grid-column: 1;
      align-self: start;
      margin-top: 0.35em;
    }

    .topic-link[data-clicks]::after {
      display: none;
    }

    .domain {
      grid-row: 2;
      grid-column: 2;
      font-size: var(--font-down-2);
      color: var(--primary-medium);
    }

    .link-summary {
      width: 100%;

      .d-icon {
        color: var(--primary-high);
      }
    }
  }

  &.topic-map__users-content {
    .topic-map__users-list {
      display: flex;
      flex-wrap: wrap;
      gap: 0.5em;
      padding: 0.75em 1rem;
    }

    .poster {
      display: block;
      position: relative;

      img {
        width: 2.25em;
        height: 2.25em;
      }
    }

    .post-count,
    .avatar-flair {
      position: absolute;
      border-radius: 1em;
      display: flex;
      align-items: center;
      justify-content: center;
    }

    .post-count {
      top: -0.15em;
      right: -0.25em;
      padding: 0.15em 0.4em 0.2em;
      font-size: var(--font-down-2);
      line-height: var(--line-height-small);
    }

    .avatar-flair {
      right: -0.25em;
      bottom: -0.15em;
      font-size: var(--font-down-3);
      width: 1.5em;
      height: 1.5em;
      background-size: contain;
    }
  }

  &.topic-map__views-content {
    .topic-views {
      display: flex;
      flex-direction: column;
      align-items: center;

      &__wrapper {
        display: flex;
        justify-content: space-evenly;
        padding: 0 1rem;
      }

      &__count {
        font-size: var(--font-up-4);
        color: var(--primary-high);
      }

      &__date {
        font-size: var(--font-down-1);
        color: var(--primary-medium);
      }
    }

    canvas {
      padding: 0.75em 1rem;
    }

    .view-explainer {
      padding: 0 1rem;
    }

    &:has(.topic-views) {
      min-width: unset;
    }
  }
}
