@import './variables.scss';

.el-tiptap-editor {
  $root: &;

  box-sizing: border-box;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  max-height: 100%;
  position: relative;
  width: 100%;

  * {
    box-sizing: border-box;
  }

  .border-top-radius {
    border-top-left-radius: 8px;
    border-top-right-radius: 8px;
  }

  .border-bottom-radius {
    border-bottom-left-radius: 8px;
    border-bottom-right-radius: 8px;
  }

  &__codemirror {
    display: flex;
    flex-grow: 1;
    font-size: 16px;
    line-height: 24px;
    overflow: scroll;

    .CodeMirror {
      flex-grow: 1;
      height: auto;
    }
  }

  &--fullscreen {
    border-radius: 0 !important;
    bottom: 0 !important;
    height: 100% !important;
    left: 0 !important;
    margin: 0 !important;
    position: fixed !important;
    right: 0 !important;
    top: 0 !important;
    width: 100% !important;
    z-index: 500;

    #{$root}__menu-bar,
    #{$root}__content,
    #{$root}__footer {
      border-radius: 0 !important;
    }
  }

  > #{$root}__content {
    background-color: $white-color;
    border: 1px solid $lighter-border-color;
    border-bottom: 0;
    border-top: 0;
    color: $black-color;
    flex-grow: 1;
    padding: 30px 20px;
  }

  &__menu-bar {
    background-color: $white-color;
    border: 1px solid $lighter-border-color;
    border-bottom: 0;
    display: flex;
    flex-shrink: 0;
    flex-wrap: wrap;
    padding: 5px;
    position: relative;

    &::before {
      bottom: 0;
      background-color: $lighter-border-color;
      content: '';
      height: 1px;
      left: 0;
      margin: 0 10px;
      right: 0;
      position: absolute;
    }
  }

  &__menu-bubble {
    background-color: $white-color;
    border-radius: 8px;
    box-shadow: 0 3px 5px -1px rgba(0,0,0,0.2), 0 6px 10px 0 rgba(0,0,0,0.14), 0 1px 18px 0 rgba(0,0,0,0.12);
    display: flex;
    padding: 5px;
    opacity: 0;
    position: absolute;
    transform: translateX(-50%);
    transition: opacity .3s ease-in-out;
    visibility: hidden;
    z-index: 50;

    &--active {
      opacity: 1;
      visibility: visible;
    }
  }

  &__content {
    box-sizing: border-box;
    font-family: sans-serif;
    line-height: 1.7;
    overflow-x: auto;
    text-align: left;

    > * {
      box-sizing: border-box;
    }

    p {
      margin-bottom: 0;
      margin-top: 0;
      outline: none;
    }

    h1,
    h2,
    h3,
    h4,
    h5 {
      margin-top: 20px;
      margin-bottom: 20px;

      &:first-child {
        margin-top: 0;
      }

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

    ul,
    ol {
      counter-reset: none;
      list-style-type: none;
      margin-bottom: 0;
      margin-left: 24px;
      margin-top: 0;
      padding-bottom: 5px;
      padding-left: 0;
      padding-top: 5px;
    }

    li > p {
      margin: 0;

      &:first-child::before {
        content: counter(el-tiptap-counter) '.';
        display: inline-block;
        left: -5px;
        line-height: 1;
        margin-left: -24px;
        position: relative;
        text-align: right;
        top: 0;
        width: 24px;
      }
    }

    ul li > p {
      &:first-child::before {
        content: '\2022';
        text-align: center;
      }
    }

    ol {
      counter-reset: el-tiptap-counter;

      li > p:first-child::before {
        counter-increment: el-tiptap-counter;
      }
    }

    a {
      color: $primary-color;
      cursor: pointer;
    }

    blockquote {
      border-left: 5px solid #edf2fc;
      border-radius: 2px;
      color: $regular-text-color;
      margin: 10px 0;
      padding-left: 1em;
    }

    code {
      background-color: $lighter-primary-color;
      border-radius: 4px;
      color: $primary-color;
      display: inline-block;
      font-size: 14px;
      font-weight: 700;
      padding: 0 8px;
    }

    pre {
      background-color: $primary-text-color;
      color: $lighter-primary-color;
      font-size: 16px;
      overflow-x: auto;
      padding: 14px 20px;
      margin: 10px 0;
      border-radius: 5px;

      code {
        background-color: transparent;
        border-radius: 0;
        color: inherit;
        display: block;
        font-family: 'Menlo,Monaco,Consolas,Courier,monospace';
        font-size: inherit;
        font-weight: normal;
        padding: 0;
      }
    }

    img {
      display: inline-block;
      float: none;
      margin: 12px 0;
      max-width: 100%;

      &[data-display=inline] {
        margin-left: 12px;
        margin-right: 12px;
      }

      &[data-display=block] {
        display: block;
      }

      &[data-display=left] {
        float: left;
        margin-left: 0;
        margin-right: 12px;
      }

      &[data-display=right] {
        float: right;
        margin-left: 12px;
        margin-right: 0;
      }
    }

    .image-view {
      $root: &;

      display: inline-block;
      float: none;
      line-height: 0;
      margin: 12px 0;
      max-width: 100%;
      user-select: none;
      vertical-align: baseline;

      &--inline {
        margin-left: 12px;
        margin-right: 12px;
      }

      &--block {
        display: block;
      }

      &--left {
        float: left;
        margin-left: 0;
        margin-right: 12px;
      }

      &--right {
        float: right;
        margin-left: 12px;
        margin-right: 0;
      }

      &__body {
        clear: both;
        display: inline-block;
        max-width: 100%;
        outline-color: transparent;
        outline-style: solid;
        outline-width: 2px;
        transition: all .2s ease-in;
        position: relative;

        &:hover {
          outline-color: #ffc83d;
        }

        &--focused:hover,
        &--resizing:hover {
          outline-color: transparent;
        }

        &__placeholder {
          height: 100%;
          left: 0;
          position: absolute;
          top: 0;
          width: 100%;
          z-index: -1;
        }

        &__image {
          cursor: pointer;
          margin: 0;
        }
      }
    }

    .image-resizer {
      border: 1px solid $primary-color;
      height: 100%;
      left: 0;
      position: absolute;
      top: 0;
      width: 100%;
      z-index: 1;

      &__handler {
        background-color: $primary-color;
        border: 1px solid $white-color;
        border-radius: 2px;
        box-sizing: border-box;
        display: block;
        height: 12px;
        position: absolute;
        width: 12px;
        z-index: 2;

        &--tl {
          cursor: nw-resize;
          left: -6px;
          top: -6px;
        }

        &--tr {
          cursor: ne-resize;
          right: -6px;
          top: -6px;
        }

        &--bl {
          bottom: -6px;
          cursor: sw-resize;
          left: -6px;
        }

        &--br {
          bottom: -6px;
          cursor: se-resize;
          right: -6px;
        }
      }
    }

    ul[data-type=todo_list] {
      margin-left: 5px;

      .todo-item {
        display: flex;
        flex-direction: row;
        justify-content: flex-start;
        margin-bottom: 0;

        &[data-text-align=right] {
          justify-content: flex-end !important;
        }

        &[data-text-align=center] {
          justify-content: center !important;
        }

        &[data-text-align=justify] {
          text-align: space-between !important;
        }

        .todo-content {
          padding-left: 10px;

          > p {
            font-size: 16px;

            &:last-of-type {
              margin-bottom: 0;
            }
          }
        }

        &--done {
          > .todo-checkbox {
            color: $primary-color;
          }

          > .todo-content>p {
            color: $primary-color;
            text-decoration: line-through;
          }
        }
      }
    }

    hr {
      margin-top: 20px;
      margin-bottom: 20px;
    }

    @for $i from 1 through 7 /* max-indent */ {
      $indent-margin-base: 30px;

      *[data-indent="#{$i}"] {
        margin-left: $indent-margin-base * $i !important;
      }
    }

    .tableWrapper {
      margin: 1em 0;
      overflow-x: auto;
    }

    table {
      border-collapse: collapse;
      table-layout: fixed;
      width: 100%;
      margin: 0;
      overflow: hidden;
    }

    th,
    td {
      border: 2px solid $lighter-border-color;
      box-sizing: border-box;
      min-width: 1em;
      padding: 3px 5px;
      position: relative;
      vertical-align: top;

      &.selectedCell {
        background-color: $extra-light-primary-color;
      }
    }

    th {
      font-weight: 500;
      text-align: left;
    }

    .column-resize-handle {
      background-color: $light-primary-color;
      bottom: 0;
      pointer-events: none;
      position: absolute;
      right: -2px;
      top: 0;
      width: 4px;
      z-index: 20;
    }

    .iframe {
      height: 0;
      padding-bottom: 56.25%;
      position: relative;
      width: 100%;

      &__embed {
        border: 0;
        height: 100%;
        left: 0;
        position: absolute;
        top: 0;
        width: 100%;
      }
    }

    .resize-cursor {
      cursor: ew-resize;
      cursor: col-resize;
    }
  }

  &__footer {
    align-items: center;
    background-color: $white-color;
    border: 1px solid $lighter-border-color;
    display: flex;
    font-family: sans-serif;
    font-size: 14px;
    justify-content: flex-end;
    padding: 10px;
  }

  .ProseMirror {
    outline: 0;
  }

  &__placeholder {
    &.el-tiptap-editor--empty:first-child::before {
      color: $placeholder-text-color;
      content: attr(data-empty-text);
      float: left;
      height: 0;
      pointer-events: none;
    }
  }

  &__with-title-placeholder {
    &:nth-child(1)::before,
    &:nth-child(2)::before {
      color: $placeholder-text-color;
      content: attr(data-empty-text);
      float: left;
      height: 0;
      pointer-events: none;
    }
  }

  &__characters {
    color: lighten($regular-text-color, 20%);
  }
}
