@import "./icons";
@import "./selection";

trix-editor {
  [data-trix-mutable],
  [data-trix-cursor-target] {
    @extend %invisible-selection;
  }

  [data-trix-mutable] {
    * {
      @extend %invisible-selection;
    }

    &:not(.attachment__caption-editor) {
      @extend %disable-selection;
    }

    &.attachment__caption-editor:focus {
      @extend %visible-selection;
    }

    &.attachment {
      &.attachment--file {
        box-shadow: 0 0 0 2px highlight;
        border-color: transparent;
      }

      img {
        box-shadow: 0 0 0 2px highlight;
      }
    }
  }

  .attachment {
    position: relative;

    &:hover {
      cursor: default;
    }
  }

  .attachment--preview {
    .attachment__caption:hover {
      cursor: text;
    }
  }

  .attachment__progress {
    position: absolute;
    z-index: 1;
    height: 20px;
    top: calc(50% - 10px);
    left: 5%;
    width: 90%;
    opacity: 0.9;
    transition: opacity 200ms ease-in;

    &[value="100"] {
      opacity: 0;
    }
  }

  .attachment__caption-editor {
    display: inline-block;
    width: 100%;
    margin: 0;
    padding: 0;
    font-size: inherit;
    font-family: inherit;
    line-height: inherit;
    color: inherit;
    text-align: center;
    vertical-align: top;
    border: none;
    outline: none;
    -webkit-appearance: none;
    -moz-appearance: none;
  }

  .attachment__toolbar {
    position: absolute;
    z-index: 1;
    top: -0.9em;
    left: 0;
    width: 100%;
    text-align: center;
  }

  .trix-button-group {
    display: inline-flex;
  }

  .trix-button {
    position: relative;
    float: left; // Collapse whitespace between elements
    color: #666;
    white-space: nowrap;
    font-size: 80%;
    padding: 0 0.8em;
    margin: 0;
    outline: none;
    border: none;
    border-radius: 0;
    background: transparent;

    &:not(:first-child) {
      border-left: 1px solid #ccc;
    }

    &.trix-active {
      background: #cbeefa;
    }

    &:not(:disabled) {
      cursor: pointer;
    }
  }

  .trix-button--remove {
    text-indent: -9999px;
    display: inline-block;
    padding: 0;
    outline: none;
    width: 1.8em;
    height: 1.8em;
    line-height: 1.8em;
    border-radius: 50%;
    background-color: #fff;
    border: 2px solid highlight;
    box-shadow: 1px 1px 6px rgba(0, 0, 0, 0.25);

    &::before {
      display: inline-block;
      position: absolute;
      top: 0;
      right: 0;
      bottom: 0;
      left: 0;
      opacity: 0.7;
      content: "";
      background-image: $icon-remove;
      background-position: center;
      background-repeat: no-repeat;
      background-size: 90%;
    }

    &:hover {
      border-color: #333;

      &::before {
        opacity: 1;
      }
    }
  }

  .attachment__metadata-container {
    position: relative;
  }

  .attachment__metadata {
    position: absolute;
    left: 50%;
    top: 2em;
    transform: translate(-50%, 0);
    max-width: 90%;
    padding: 0.1em 0.6em;
    font-size: 0.8em;
    color: #fff;
    background-color: rgba(0, 0, 0, 0.7);
    border-radius: 3px;

    .attachment__name {
      display: inline-block;
      max-width: 100%;
      vertical-align: bottom;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }

    .attachment__size {
      margin-left: 0.2em;
      white-space: nowrap;
    }
  }
}
