/*
 * Copyright (C) 2015 - present Instructure, Inc.
 *
 * This file is part of Canvas.
 *
 * Canvas is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Affero General Public License as published by the Free
 * Software Foundation, version 3 of the License.
 *
 * Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
 * details.
 *
 * You should have received a copy of the GNU Affero General Public License along
 * with this program. If not, see <http://www.gnu.org/licenses/>.
 */

@import 'base/environment';
@import 'pages/wiki_animations.scss';
@import 'pages/shared/menu_tools.scss';

$subdued-text-color: #696969;
$darkened-text-color: #4d4d4d;

$published-text-color: $ic-color-success;
$unpublished-text-color: $ic-font-color--subdued;
$published-icon-color: $ic-color-success;
$unpublished-icon-color: $ic-font-color--subdued;

$border-color: $ic-border-light;
$border-radius: $baseBorderRadius;

$pages-border: 1px solid $ic-border-light;
$pages-dashed-border: 1px dashed $ic-border-light;
$pages-inner-border: 1px solid $ic-border-light;

$index-background: $ic-color-light;
$item-background: $lightBackground;

$shadow: 0 1px 0 rgba(0, 0, 0, 0.15);
$table-shadow: 0 1px 0 #dde0e4;

$revision-sidebar-width: 270px;
$revision-sidebar-background-color: $ic-body-background-color;
$revision-sidebar-selected-color: #ffffff;
$revision-sidebar-hover-color: lighten($ic-color-neutral, 10);
$revision-sidebar-dimmed-color: $ic-dim-helper-text;
$revision-button-color: $ic-color-dark;

.pages .sticky-toolbar .sticky {
  position: fixed;
  z-index: 1000;
  top: 0px;
  #{direction(left)}: 0px;
  #{direction(right)}: 0px;
  margin-#{direction(left)}: 1px;
  background: white;
  height: 33px;
  max-width: $max_main_width;
  border-color: darken($ic-border-color, 10);
}

.pages.with-left-side .sticky-toolbar .sticky {
  margin-#{direction(left)}: $left_side_width + 1px;
}

.pages.with-right-side .sticky-toolbar .sticky {
  margin-#{direction(right)}: $right_side_width + 1px;
}

.delete_criterion_link {
  border: none;
  background: none;
  padding: 0px;
}

.add_prerequisite_or_requirement_link {
  color: var(--ic-link-color);
  border: none;
  background: none;
  padding: 0px;
  &:hover {
    color: var(--ic-link-color-darkened-10);
    background: none;
    text-decoration: underline;
  }
}

.pages {
  .header-bar-outer-container {
    min-height: 64px;
    clear: direction(right);
    .header-bar-container {
      min-width: $min_main_width - 2px;
      min-height: 64px;
      body.responsive_misc & {
        @include mobile-only {
          min-width: 100%;
        }
      }
      .page-changed-alert {
        overflow: hidden;
        height: 0;
      }
      .page-changed-alert .alert {
        border-radius: 0;
      }
      .header-left-flex {
        flex: 1;
        float: none;
        white-space: nowrap;
        overflow: hidden;
        .course-title {
          text-overflow: ellipsis;
          overflow: hidden;
        }
      }
      .header-right-flex {
        padding-#{direction(left)}: $ic-sp;
      }
      .flex-container {
        display: flex;
        align-items:center {
        }
      }
    }
  }
  .header-bar-outer-container.page-changed {
    height: 103px;
    animation: page-changed-header-bar 1.15s;
    .header-bar-container {
      height: 103px;
      animation: page-changed-header-bar 1.15s;
      .page-changed-alert {
        margin: direction-sides((-1px) 0 0 0);
        border-bottom: $pages-border;
        box-shadow: $shadow;
        height: 39px;
        animation: page-changed-alert 1.15s;
      }
    }
  }
}
.pages.index {
  .index-content-container {
    margin-top: 1px;
  }
  .page-edit-dialog .edit-content {
    margin: 8px 5px;
    .edit-label {
      padding-top: 8px;
      width: 75px;
      float: direction(left);
      text-align: direction(right);
      @include mobile-only {
        width: auto;
      }
    }
    .edit-controls {
      margin-#{direction(left)}: 85px;
      @include mobile-only {
        float: direction(right);
        margin-#{direction(left)}: 0px;
      }
    }
    .edit-control-text {
      width: 270px;
      @include mobile-only {
        width: 140px;
      }
    }
  }
  .index-content {
    .table {
      margin-bottom: 0;
      border-collapse: separate;
      border-spacing: 0;
      td,
      th {
        &:first-child {
          padding-#{direction(left)}: 12px;
        }
        &:last-child {
          padding-#{direction(right)}: 12px;
        }
      }
    }
    .table thead {
      background: $index-background;
      tr {
        height: 40px;
      }
      th {
        vertical-align: middle;
        font-weight: bold;
      }
    }
    .table tbody {
      .page_title {
        font-weight: bold;
      }
      .front-page {
        margin: auto 0.5em;
      }
      tr {
        background: $item-background;
        text-decoration: inherit;
        color: inherit;
        &.clickable:hover {
          background: $ic-list-item-background--hover;
          text-decoration: inherit;
          color: inherit;
        }
        td:first-child {
          border-#{direction(left)}: $pages-border;
        }
        td:last-child {
          border-#{direction(right)}: $pages-border;
        }
      }
      tr:first-child {
        td {
          border-top: $pages-border;
        }
        td:first-child {
          border-top-#{direction(left)}-radius: $border-radius;
        }
        td:last-child {
          border-top-#{direction(right)}-radius: $border-radius;
        }
      }
      tr:last-child {
        td {
          border-bottom: $pages-border;
        }
        td:first-child {
          border-bottom-#{direction(left)}-radius: $border-radius;
        }
        td:last-child {
          border-bottom-#{direction(right)}-radius: $border-radius;
        }
      }
      td {
        @include fontSize(11px);
        color: $subdued-text-color;
        border-top: $pages-inner-border;
        vertical-align: middle;
        line-height: 1.5;
        .wiki-page-link {
          @include fontSize(13px);
          color: $darkened-text-color;
          font-weight: bold;
        }
        .wiki-page-link.published {
          color: $published-text-color;
        }
        .wiki-page-link.unpublished {
          color: $unpublished-text-color;
        }
        .icon-publish {
          color: $published-icon-color;
        }
        .icon-unpublished {
          color: $ic-icon-link-color;
        }
      }
    }
    .table .no-pages .no-pages-cell {
      border: $pages-dashed-border;
    }
    .loading {
      text-align: center;
      color: #8f9295;
      img {
        margin-top: -3px;
        opacity: 0.75;
      }
      &.loading {
        border: 1px solid transparent;
      }
      &.loading-more {
        border: $pages-dashed-border;
        border-top-width: 0;
        border-bottom-#{direction(left)}-radius: $border-radius;
        border-bottom-#{direction(right)}-radius: $border-radius;
        margin-top: 1px;
        padding: 4px 12px;
        background: #f4f6f8;
      }
    }
  }
}
/// pulled out of the specific table class so the new UI could take advantage of the header sorting
.header-row {
  a.sort-field {
    cursor: pointer;
    user-select: none;
    color: inherit;
    white-space: nowrap;
    i {
      color: #ccc;
    }
  }
  a.sort-field:hover {
    text-decoration: none;
    i {
      color: #0088cc;
    }
  }
  a.sort-field-active {
    i {
      color: black;
    }
  }
}

.pages.show {
  .course-title {
    display: none;
    font-size: 1.8em;
    font-weight: bold;
    margin: 0;
    color: #666;
  }
  .page-title {
    font-size: 2.5em;
    font-weight: 200;
    margin: 15px 0;
    color: #666;
  }
  .header-bar {
    .front-page.label {
      margin: direction-sides(11px 12px 11px 0);
    }
  }
  .locked-alert ul {
    margin: direction-sides(4px 0 6px 25px);
  }
  .show-content {
    word-wrap: break-word;
    overflow-x: auto;
    box-sizing: border-box;
    padding: 0 $ic-sp;
    @include breakpoint(desktop) {
      padding: direction-sides(0 $ic-sp * 2 0 $ic-sp);
    }
  }
  .floating_links {
    margin-#{direction(right)}: 15px;
  }
  .public-license {
    margin-#{direction(left)}: 15px;
    margin-bottom: 15px;
  }
}

.pages.show.home {
  .course-title {
    display: block;
  }
  .page-title {
    display: none;
  }
  .show-content {
    padding-top: 25px;
  }
}

.pages.edit {
  .form-actions {
    padding-#{direction(left)}: 1em;
  }
  &.responsive_misc {
    .form-actions label {
      @include mobile-only {
        text-align: direction(left);
      }
    }
    .edit-content #title {
      @include mobile-only {
        max-width: 90%;
      }
    }
    .page-edit__action_buttons {
      width: 100%;
      display: flex;
      flex-direction: column-reverse;
      align-items: flex-start;
      button {
        margin-top: 10px;
      }
      @include breakpoint(mini-tablet) {
        display: inline-block;
        width: unset;
        button {
          margin-top: 0px;
        }
      }
    }
    .control-group.options {
      @include mobile-only {
        .controls {
          margin-#{direction(left)}: 0;
        }
        .control-label {
          float: none;
          text-align: direction(left);
          width: 100%;
        }
      }
    }
  }
  .edit-form {
    margin: 0;
    .edit-content {
      padding: 1em;
      .edit-header {
        position: relative;
        margin-bottom: 1em;
      }
      .edit-header h2 {
        margin: 0;
      }
      .switch_views_container {
        display: flex;
        justify-content: flex-end;
      }
      .body {
        width: 98.5%;
      }
      .mceLayout {
        margin: 0;
      }
      .options {
        margin-top: 1em;
      }
    }
    .form-actions {
      margin-top: 0;
      margin-bottom: 0;
    }
  }
}

.pages.show.revisions {
  #wiki_page_revisions {
    position: relative;
    @include breakpoint(desktop) {
      min-height: 502px;
    }
  }
  .show-content {
    @include breakpoint(desktop) {
      margin-#{direction(right)}: $revision-sidebar-width;
    }
  }
  .show-revisions {
    border-bottom: 1px solid $ic-border-light;
    @include breakpoint(desktop) {
      border-bottom: none;
      position: absolute;
      top: 0;
      #{direction(right)}: 0;
      width: $revision-sidebar-width;
      aside {
        width: $revision-sidebar-width;
        position: fixed;
        padding-top: $ic-sp * 2;
      }
    }

    .revision-history {
      @include fontSize($ic-font-size--small);
      position: relative;
      font-weight: bold;
      margin-bottom: $ic-sp;
      @include fontSize($ic-font-size--small);
    }
    .revision-history .close-button {
      position: absolute;
      top: 3px;
      bottom: 3px;
      #{direction(right)}: 3px;
      width: 42px;
      text-align: center;
      color: dimgrey;
      &:hover {
        color: var(--ic-brand-primary);
      }
      i.icon-x {
        position: absolute;
        top: 50%;
        margin-top: -8px;
        #{direction(right)}: 13px;
      }
    }
    ul.revisions-list {
      margin: 0;
      overflow-y: auto;
    }
  }
  .revision {
    list-style-type: none;
    overflow: hidden;

    border-#{direction(left)}: 2px solid transparent;

    .revision-content {
      padding: 7px 8px;
      @include fontSize($ic-font-size--xsmall);

      .revision-details {
        padding-#{direction(left)}: 3px;
        text-align: #{direction(left)};
        font-size: 12px;
        color: #333;
      }

      .revision-actions {
        padding-#{direction(left)}: 3px;
      }
    }
    &:not(.selected):hover {
      border-#{direction(left)}-color: var(--ic-link-color);
      .revision-content {
        cursor: pointer;
      }
    }

    .revision-actions {
      margin-top: 2px;
      font-style: italic;
      color: $revision-sidebar-dimmed-color;
    }
    .revision-actions a.restore-link {
      font-style: normal;
      cursor: pointer;
    }
    &.selected {
      border-#{direction(left)}-color: var(--ic-link-color);
      background: $ic-bg-light-primary;
    }
  }
  .revision-nav-buttons {
    position: relative;
    height: $ic-sp * 3;

    a {
      user-select: none;
      text-transform: uppercase;
      font-weight: bold;
    }
    a:hover {
      text-decoration: none;
      cursor: pointer;
      color: var(--revision-button-hover-color);
      border-radius: 3px;
    }
    .prev-button {
      position: absolute;
      #{direction(left)}: 0;
      top: 0;
    }
    .next-button {
      position: absolute;
      #{direction(right)}: 0;
      top: 0;
    }
  }
}

@media print {
  #breadcrumbs,
  .header-bar-outer-container {
    display: none;
  }
  .pages.show.revisions {
    .show-revisions {
      display: none;
    }
    .show-content {
      margin-#{direction(right)}: 0;
    }
  }
}

#wiki_show_view_main {
  overflow: auto;
}

#last_edited_by {
  border: solid #eee;
  border-width: 0 0 1px;
  font-size: 0.8em;
  margin-bottom: 10px;
  margin-#{direction(right)}: 2px;
  h3,
  .h3 {
    margin: 0px 20px 10px;
    font-size: 1.5em;
    color: #444;
  }
}

#page_history {
  float: direction(right);
}

// this is to fix a bug that was reported that if you shrink your browser window width to something small
// that it would just cut off the right side of the tiny WYSIWYG editor box and make it dissapear beind the right side.
#wiki_page_body_parent.mceEditor {
  display: block;
  overflow: auto;
}

.page-toolbar {
  display: flex;
  align-items: stretch;

  &.header-bar {
    padding-bottom: 6px;
  }

  .page-toolbar-start {
    display: flex;
    flex-grow: 1;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: stretch;
    align-content: stretch;

    & > div {
      padding-bottom: 6px;
    }
  }

  .page-toolbar-end {
    display: flex;
    flex-grow: 0;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: stretch;
    align-content: center;
    white-space: nowrap;

    & > div {
      padding-bottom: 6px;
    }
  }

  .publishing {
    display: flex;

    & > div {
      padding-#{direction(left)}: 4px;
    }
  }

  .buttons {
    margin-#{direction(left)}: 12px;
  }

  @include breakpoint(mini-tablet, $maximum: true) {
    .hide-when-small, .publish-text {
      @include screenreader-only
    }

    .btn-published {
      padding-#{direction(right)}: 9px;
    }

    .publish-button button {
      padding-#{direction(left)}: 9px;
    }

    .btn.edit-wiki {
      padding-#{direction(left)}: 0.5rem;
      padding-#{direction(right)}: 0.5rem;
    }
  }
}
