@import '../../_variables.scss';
@import '../../_logical.scss';

.Attachment {
  display: inline-flex;
  flex-direction: column;
  position: relative;
  align-self: flex-start;
  line-height: 0;
  block-size: 100%;
  border-style: solid;
  border-width: 1px;
  border-radius: $fallback--attachmentRadius;
  border-radius: var(--attachmentRadius, $fallback--attachmentRadius);
  border-color: $fallback--border;
  border-color: var(--border, $fallback--border);

  .attachment-wrapper {
    flex: 1 1 auto;
    block-size: 200px;
    position: relative;
    overflow: hidden;
  }

  .description-container {
    flex: 0 1 0;
    display: flex;
    padding-block-start: 0.5em;
    z-index: 1;
    max-block-size: 50%;

    p {
      flex: 1;
      text-align: center;
      line-height: 1.5;
      padding: 0.5em;
      margin: 0;
      white-space: pre-line;
      word-break: break-word;
      text-overflow: ellipsis;
      overflow: scroll;
    }

    &.-static {
      position: absolute;
      inset-inline-start: 0;
      inset-inline-end: 0;
      inset-block-end: 0;
      padding-block-start: 0;
      background: var(--popover);
      box-shadow: var(--popupShadow);
    }
  }

  .description-field {
    flex: 1;
    min-inline-size: 0;

    box-sizing: content-box;
    overflow: hidden;
    transition: min-block-size 200ms 100ms;

    padding-block-end: var(--_padding);
    block-size: calc(var(--post-line-height) * 1em);
    min-block-size: calc(var(--post-line-height) * 1em);
    resize: none;

    &.scrollable-form {
      @include overflow-block(auto);
    }
  }

  & .placeholder-container,
  & .image-container,
  & .audio-container,
  & .video-container,
  & .flash-container,
  & .oembed-container {
    display: flex;
    justify-content: center;
    inline-size: 100%;
    block-size: 100%;
  }

  .image-container {
    .image {
      inline-size: 100%;
      block-size: 100%;
    }
  }

  & .flash-container,
  & .video-container {
    & .flash,
    & video {
      inline-size: 100%;
      block-size: 100%;
      object-fit: contain;
      align-self: center;
    }
  }

  .audio-container {
    display: flex;
    align-items: flex-end;

    audio {
      inline-size: 100%;
      block-size: 100%;
    }
  }

  .placeholder-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding-block-start: 0.5em;
  }


  .play-icon {
    position: absolute;
    font-size: 64px;
    inset-block-start: calc(50% - 32px);
    inset-inline-start: calc(50% - 32px);
    color: rgba(255, 255, 255, 0.75);
    text-shadow: 0 0 2px rgba(0, 0, 0, 0.4);

    &::before {
      margin: 0;
    }
  }

  .attachment-buttons {
    display: flex;
    position: absolute;
    inset-inline-end: 0;
    inset-block-start: 0;
    margin-block-start: 0.5em;
    margin-inline-end: 0.5em;
    z-index: 1;

    .attachment-button {
      padding: 0;
      border-radius: $fallback--tooltipRadius;
      border-radius: var(--tooltipRadius, $fallback--tooltipRadius);
      text-align: center;
      inline-size: 2em;
      block-size: 2em;
      margin-inline-start: 0.5em;
      font-size: 1.25em;
      // TODO: theming? hard to theme with unknown background image color
      background: rgba(230, 230, 230, 0.7);

      .svg-inline--fa {
        color: rgba(0, 0, 0, 0.6);
      }

      &:hover .svg-inline--fa {
        color: rgba(0, 0, 0, 0.9);
      }
    }
  }

  .oembed-container {
    line-height: 1.2em;
    flex: 1 0 100%;
    inline-size: 100%;
    margin-inline-end: 15px;
    display: flex;

    img {
      inline-size: 100%;
    }

    .image {
      flex: 1;
      img {
        border: 0px;
        border-radius: 5px;
        block-size: 100%;
        object-fit: cover;
      }
    }

    .text {
      flex: 2;
      margin: 8px;
      word-break: break-all;
      h1 {
        font-size: 1rem;
        margin: 0px;
      }
    }
  }

  &.-size-small {
    .play-icon {
      zoom: 0.5;
      opacity: 0.7;
    }

    .attachment-buttons {
      zoom: 0.7;
      opacity: 0.5;
    }
  }

  &.-editable {
    padding: 0.5em;

    & .description-container,
    & .attachment-buttons {
      margin: 0;
    }
  }

  &.-placeholder {
    display: inline-block;
    color: $fallback--link;
    color: var(--postLink, $fallback--link);
    overflow: hidden;
    white-space: nowrap;
    block-size: auto;
    line-height: 1.5;

    &:not(.-editable) {
      border: none;
    }

    &.-editable {
      display: flex;
      flex-direction: row;
      align-items: baseline;

      & .description-container,
      & .attachment-buttons {
        margin: 0;
        padding: 0;
        position: relative;
      }

      .description-container {
        flex: 1;
        padding-inline-start: 0.5em;
      }

      .attachment-buttons {
        order: 99;
        align-self: center;
      }
    }

    a {
      display: inline-block;
      max-inline-size: 100%;
      overflow: hidden;
      text-overflow: ellipsis;
    }

    svg {
      color: inherit;
    }
  }

  &.-loading {
    cursor: progress;
  }

  &.-contain-fit {
    img,
    canvas {
      object-fit: contain;
    }
  }

  &.-cover-fit {
    img,
    canvas {
      object-fit: cover;
    }
  }
}
