@import '../../../styles/core.scss';

$modalOffset: #{ms(10) * 2};

.TutorialModal {
  border: 0;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  height: calc(100vh - (#{ms(10)} * 2));
  max-width: 1200px;
  overflow: hidden;
  padding: 0;
  width: 100%;

  @media (max-width: 1240px) {
    width: calc(100% - 40px);
  }

  @media (max-width: 768px) {
    height: calc(100vh - (#{ms(1)} * 2));
    margin-bottom: ms(1);
    margin-top: ms(1);
  }

  &_created {
    height: auto;
    max-width: 580px; // same as obstacle
    width: auto;
  }

  * {
    box-sizing: border-box;
  }

  &-Obstacle {
    margin: 0;
  }

  &-Form {
    display: flex;
    flex-direction: column;
    height: 100%;
  }

  &-Row {
    display: flex;
    flex: 1 1 auto;
    overflow: hidden;

    @media (max-width: 768px) {
      flex-direction: column;
    }
  }

  &-Col {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    overflow: hidden;

    &_steps {
      background: #242e34;
      border-right: 1px solid get(color 'graphite');
      overflow-y: auto;
      padding: 20px;

      @media (min-width: 1029px) {
        flex: 0 0 400px;
      }

      @media (max-width: 1028px) {
        flex: 0 0 300px;
      }

      @media (max-width: 768px) {
        border-bottom: 1px solid get(color 'graphite');
      }
    }

    &_review {
      background: #242e34;
      padding: 20px;

      &:first-child {
        border-right: 1px solid get(color 'graphite');
        overflow-y: auto;
      }

      @media (min-width: 1029px) {
        &:first-child {
          flex: 0 0 400px;
        }
      }

      @media (max-width: 1028px) {
        &:first-child {
          flex: 0 0 300px;
        }
      }

      @media (max-width: 768px) {
        &:first-child {
          border-bottom: 1px solid get(color 'graphite');
        }
      }
    }

    &_singleEditor :global(.CodeEditor.CodeEditor.CodeEditor) {
      border-top: 0;
      max-height: none;

      :global(.CodeMirror) {
        height: calc((100vh - #{$modalOffset} - 150px));

        @media (max-width: 768px) {
          height: calc((100vh - #{$modalOffset} - 150px));
        }
      }
    }

    &-Input {
      background: rgba(#fff, 0.1);
      border-color: transparent;
      color: #fff;
      font-weight: 600;
      margin-bottom: 10px;
      padding-left: 10px;
      padding-right: 10px;
      width: 100%;

      &:hover,
      &:active,
      &:focus {
        background: rgba(#fff, 0.15);
      }

      &:focus {
        background: rgba(#fff, 0.2);
        border-color: transparent;
        box-shadow: none;
        color: #fff;
      }
    }

    &-Wrapper {
      background: get(color 'slate');
      border-radius: 6px;
      padding: 30px;
      pointer-events: none;

      + .TutorialModal-Col-Wrapper {
        margin-top: 10px;
      }

      &-Caption {
        color: get(color 'shale');
      }

      &-Card {
        width: 100%;
      }
    }
  }

  &-Nav {
    background: #242e34;
    border-bottom: 1px solid get(color 'graphite');
    color: #fff;
    flex: 0 0 60px;
    overflow-x: auto;
    padding-left: 20px;
    padding-right: 10px;

    :global(.Title) {
      margin-bottom: 0;
      margin-top: 0;
    }

    &-Close {
      align-items: center;
      background: none;
      border: 0;
      box-shadow: none;
      color: get(color 'shale');
      cursor: pointer;
      display: flex;
      font-size: ms(1);
      margin-left: 10px;

      &:hover,
      &:active,
      &:focus {
        color: get(color 'ivory');
      }

      &:focus {
        outline: 0;
      }
    }

    &-Tab {
      align-items: center;
      border: 0;
      background: none;
      color: #fff;
      display: flex;
      font-size: ms(1);
      font-weight: 600;
      height: 59px;
      opacity: 0.5;
      padding: 0;
      position: relative;

      @media (max-width: 520px) {
        font-size: ms(0);
      }

      &:not(.TutorialModal-Nav-Tab_active) {
        cursor: pointer;

        &:hover,
        &:active,
        &:focus {
          opacity: 0.75;
        }
      }

      &:focus {
        outline: 0;
      }

      &_active {
        box-shadow: inset 0 -3px 0 get(color 'graphite');
        opacity: 1;
      }

      &-Icon {
        align-items: center;
        background: get(color 'graphite');
        border-radius: 6px;
        color: #fff;
        display: flex;
        font-size: 12px;
        height: 20px;
        justify-content: center;
        margin-right: 10px;
        width: 20px;
      }
    }
  }
}

.TutorialModal {
  // override menu to fit within modal
  :global(.Dropdown-content .Dropdown-content) {
    border-radius: 6px;
    max-height: calc(50vh);
    overflow-y: auto;
  }

  // override code editor
  // theming and layout
  :global {
    .CodeEditor {
      background: #242e34;
      flex: 1 1 auto;
      font-size: 14px;
      max-height: calc(50% - 50px);
      overflow: auto;
      white-space: pre;

      &:last-child {
        border-top: 1px solid #4f5a66;
        max-height: 50%;
        padding-top: 10px;
      }

      .cm-s-material-palenight.CodeMirror,
      .cm-s-material-palenight .CodeMirror-gutters {
        background: #242e34;
      }

      .CodeMirror {
        height: calc((100vh - #{$modalOffset} - 195px) / 2);

        @media (max-width: 768px) {
          height: calc((100vh - #{$modalOffset} - 195px) / 2);
        }
      }
    }
  }
}

// highlight styles
// only apply these styles to the input editor (top view)
:global {
  .TutorialEditor-Nav + .CodeEditor {
    .CodeMirror-focused .CodeMirror-code > div:first-child .CodeMirror-line > span::after {
      opacity: 0;
    }

    // this removes what would’ve been the relative parent for the overlay
    .CodeMirror-line,
    .CodeMirror-code > div {
      position: static !important;
    }

    .CodeMirror {
      overflow: visible;
    }

    // this is to provide a new (higher-level) relative parent for the overlay
    // :first-child b/c we only need one overlay
    // ::after must be at this level to match the depth of the next selector for z-index to work
    .CodeMirror-code {
      position: relative;
    }

    // overlay make everything less bright
    // :first-child b/c we only need one overlay
    // ::after must be at this level to match the depth of the next selector for z-index to work
    .CodeMirror-code > div:first-child .CodeMirror-line > span::after {
      background: rgba(#242e34, 0.5);
      bottom: 0;
      content: '';
      display: block;
      height: 100%;
      left: 0;
      pointer-events: none;
      position: absolute;
      right: 0;
      top:0;
      transition: opacity 0.15s cubic-bezier(0.16, 1, 0.3, 1);
      width: 100%;
    }

    // be on top of the overlay
    .CodeEditor-Highlight {
      position: relative;
      z-index: 1;
    }
  }
}
