//
//== Apply to Bootstrap
//

// determine optional variables
$border-image-navbar: linear-gradient(to right, $gray-300 0%, $gray-300 100%) !default;
$bgcolor-search-top-dropdown: $secondary !default;
$bgcolor-sidebar-nav-item-active: darken($bgcolor-sidebar, 10%) !default;
$text-shadow-sidebar-nav-item-active: 1px 1px 2px $primary !default;
$bgcolor-inline-code: $gray-100 !default;
$color-inline-code: darken($red, 15%) !default;
$bordercolor-inline-code: $gray-400 !default;
$bordercolor-nav-tabs: $gray-300 !default;
$bordercolor-nav-tabs-hover: $gray-200 $gray-200 $bordercolor-nav-tabs !default;
$color-nav-tabs-link-active: $gray-600 !default;
$bordercolor-nav-tabs-active: $bordercolor-nav-tabs $bordercolor-nav-tabs $bgcolor-global !default;
$color-seen-user: #549c79 !default;

// override bootstrap variables
$body-bg: $bgcolor-global;
$body-color: $color-global;
$link-color: $color-link;
$link-hover-color: $color-link-hover;
$input-focus-color: $color-global;
$nav-tabs-border-color: $bordercolor-nav-tabs;
$nav-tabs-link-hover-border-color: $bordercolor-nav-tabs-hover;
$nav-tabs-link-active-color: $color-nav-tabs-link-active;
$nav-tabs-link-active-bg: $bgcolor-global;
$nav-tabs-link-active-border-color: $bordercolor-nav-tabs-active;

@import '~bootstrap/scss/functions';
@import '~bootstrap/scss/variables';
@import '~bootstrap/scss/mixins';
@import '../mixins';
@import 'mixins/list-group';
@import 'mixins/page-editor-mode-manager';
@import 'mixins/tables'; // comment out and use _reboot-bootstrap-tables instead -- 2020.05.28 Yuki Takei
@import 'reboot-bootstrap-buttons';
@import 'reboot-bootstrap-colors';
@import 'reboot-bootstrap-theme-colors';
@import 'reboot-bootstrap-nav';
@import 'reboot-toastr-colors';

// determine variables with　bootstrap function (These variables can be used after importing bootstrap above)
$color-modal-header: color-yiq($primary) !default;

:not(pre) {
  > code {
    color: $color-inline-code;
    background-color: $bgcolor-inline-code;
    border-color: $bordercolor-inline-code;
  }
}

pre:not(.hljs):not(.CodeMirror-line) {
  background-color: $bgcolor-inline-code;
  border-color: $bordercolor-inline-code;
}

//
//== Apply to Bootstrap Elements
//

// Alert link
@each $color, $value in $theme-colors {
  .alert.alert-#{$color} {
    a,
    a:hover {
      color: theme-color-level($color, $alert-color-level - 2);
    }
  }
}

// Dropdown
.dropdown-menu {
  color: $color-global;
}

.grw-personal-dropdown {
  .grw-icon-container svg {
    fill: $color-global;
  }
  .grw-icon-container-muted svg {
    fill: $secondary;
  }
}

.dropdown-item {
  color: $color-global;

  svg {
    fill: $color-global;
  }

  &:active,
  &.active,
  &:active:hover,
  &.active:hover {
    color: $color-dropdown-link-active;
    background-color: $bgcolor-dropdown-link-active;

    svg {
      fill: $color-dropdown-link-active;
    }
  }
  &:hover {
    background-color: $light;
  }
}

// Form
.form-control {
  @include form-control-focus();
}

// Tabs
.nav.nav-tabs .nav-link.active {
  color: $color-link !important;
  background: transparent;

  &:hover,
  &:focus {
    color: $color-link-hover !important;
  }
}

// Pagination
ul.pagination {
  li.page-item.disabled {
    button.page-link {
      color: $gray-400;
    }
  }
  li.page-item.active {
    button.page-link {
      color: color-yiq($primary);
      background-color: $primary;
      &:hover,
      &:focus {
        color: color-yiq($primary);
        background-color: $primary;
      }
    }
  }
  li.page-item {
    button.page-link {
      color: $primary;
      border-color: $secondary;
      &:hover,
      &:active,
      &:focus {
        color: $primary;
      }
    }
  }
}

//
//== Apply to Handsontable
//
.handsontable {
  color: initial;
}

//
//== Apply to GROWI Elements
//

.grw-logo {
  // set transition for fill
  svg * {
    transition: fill 0.8s ease-out;
  }

  svg {
    fill: $fillcolor-logo-mark;
  }

  &:hover {
    svg {
      .group1 {
        fill: $growi-green;
      }

      .group2 {
        fill: $growi-blue;
      }
    }
  }
}

.grw-navbar {
  background: $bgcolor-navbar;
  .nav-item > .nav-link {
    color: $color-link-nabvar;
  }

  border-image: $border-image-navbar;
  border-image-slice: 1;

  .grw-app-title {
    color: $fillcolor-logo-mark;
  }
}

.grw-global-search {
  .btn-secondary.dropdown-toggle {
    @include button-variant($bgcolor-search-top-dropdown, $bgcolor-search-top-dropdown);
  }

  // for https://youtrack.weseek.co.jp/issue/GW-2603
  .search-typeahead {
    background-color: rgba($bgcolor-global, 0.9);
  }
}

.grw-sidebar {
  // override @atlaskit/navigation-next styles
  .ak-navigation-resize-button {
    $color-resize-button: $color-global !default;
    $bgcolor-resize-button: white !default;
    $color-resize-button-hover: $color-reversal !default;
    $bgcolor-resize-button-hover: lighten($bgcolor-resize-button, 5%) !default;

    @include override-hexagon-color($color-resize-button, $bgcolor-resize-button);

    &:hover {
      @include override-hexagon-color($color-resize-button-hover, $bgcolor-resize-button-hover);
    }
  }
  div[data-testid='GlobalNavigation'] {
    > div {
      background-color: $bgcolor-sidebar;
    }
  }
  div[data-testid='ContextualNavigation'] {
    > div {
      color: $color-sidebar-context;
      background-color: $bgcolor-sidebar-context;
    }
  }

  .grw-sidebar-nav {
    .btn {
      @include button-variant(
        $bgcolor-sidebar,
        $bgcolor-sidebar,
        darken($bgcolor-sidebar, 7.5%),
        darken($bgcolor-sidebar, 10%),
        $bgcolor-sidebar-nav-item-active,
        $bgcolor-sidebar-nav-item-active
      );
    }
  }
  .grw-sidebar-nav-primary-container {
    .btn.active {
      i {
        text-shadow: $text-shadow-sidebar-nav-item-active;
      }
      // fukidashi
      &:after {
        border-right-color: $bgcolor-sidebar-context;
      }
    }
  }
}

/*
 * Icon
 */
.editor-container .navbar-editor svg {
  fill: $color-editor-icons;
}

// page preview button in link form
.btn-page-preview svg {
  fill: white;
}

/*
 * Modal
 */
.modal {
  .modal-header {
    border-bottom-color: $border-color-theme;
    .modal-title {
      color: $color-modal-header;
    }
    .close {
      color: $color-modal-header;
      opacity: 0.5;
      &:hover {
        opacity: 0.9;
      }
    }
  }

  .modal-content {
    background-color: $bgcolor-global;
  }

  .modal-footer {
    border-top-color: $border-color-theme;
  }
}

.grw-page-accessories-control {
  .grw-seen-user-info {
    .btn {
      color: $color-seen-user;
      &:active {
        color: $color-seen-user;
      }
      .footstamp-icon {
        fill: $color-seen-user;
      }
    }
  }
}

.grw-custom-nav-tab {
  .nav-item {
    &:hover,
    &:focus {
      background-color: rgba($color-link, 0.08);
    }
    .nav-link {
      -webkit-appearance: none;
      color: $color-link;
      svg {
        fill: $color-link;
      }

      // Disabled state lightens text
      &.disabled {
        color: $nav-link-disabled-color;
        svg {
          fill: $nav-link-disabled-color;
        }
      }
    }
  }

  .grw-nav-slide-hr {
    border-color: $color-link;
  }
}

.grw-page-accessories-modal {
  .modal-header {
    .close {
      color: $secondary;
    }
  }
}

/*
 * cards
 */
.card.well {
  color: $color-global;
  background-color: $bgcolor-card;
  border-color: $light;
  box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.05);
}

.admin-bot-card {
  .grw-botcard-title-active {
    color: $gray-200;
  }
}

/*
 * Form Slider
 */
.admin-page {
  span.slider {
    background-color: $gray-300;

    &:before {
      background-color: white;
    }
  }

  input:checked + .slider {
    background-color: #007bff;
  }

  input:focus + .slider {
    box-shadow: 0 0 1px #007bff;
  }
}

/*
 * GROWI wiki
 */
.wiki {
  .highlighted {
    @include highlighted($bgcolor-highlighted);
  }

  a {
    color: $color-link-wiki;

    &:hover {
      color: $color-link-wiki-hover;
    }
  }

  // table with handsontable modal button
  .editable-with-handsontable {
    button {
      color: $color-link-wiki;
    }

    button:hover {
      color: $color-link-wiki-hover;
    }
  }
}

/*
 * GROWI on-edit
 */
body.on-edit {
  .main {
    background-color: darken($bgcolor-global, 2%);

    .page-editor-editor-container {
      border-right-color: $border-color-theme;

      .navbar-editor {
        background-color: $bgcolor-global; // same color with active tab
        border-bottom-color: $border-color-theme;
      }
    }

    .page-editor-preview-container {
      background-color: $bgcolor-global;
    }

    .page-editor-footer {
      border-top-color: $border-color-theme;
    }
  }
}

/*
 * Preview for editing /Sidebar
 */
body.pathname-sidebar {
  .page-editor-preview-body {
    color: $color-sidebar-context;
    background-color: $bgcolor-sidebar-context;
  }
}

/*
 * GROWI Grid Edit Modal
 */
.grw-grid-edit-preview {
  .desktop-preview,
  .tablet-preview,
  .mobile-preview {
    background: $bgcolor-global;
  }
  .grid-edit-border-for-each-cols {
    border: 2px solid $bgcolor-global;
  }
}

.grid-preview-col-0 {
  background: $growi-blue;
}

.grid-preview-col-1 {
  background: $info;
}

.grid-preview-col-2 {
  background: $success;
}

.grid-preview-col-3 {
  background: $growi-green;
}

/*
 * GROWI comment
 */
.page-comment-meta .page-comment-revision svg {
  fill: $color-link;

  &:hover() {
    fill: $color-link-hover;
  }
}

/*
 * GROWI comment form
 */
.page-comments {
  .page-comment .page-comment-main,
  .page-comment-form .comment-form-main {
    background-color: $bgcolor-global;

    &:before {
      border-right-color: $bgcolor-global;
    }

    .nav.nav-tabs {
      > li > a.active {
        background: transparent;
        border-bottom: solid 1px darken($bgcolor-global, 4%);
        border-bottom-color: darken($bgcolor-global, 4%);
      }
    }
  }
}

/*
 * GROWI search result
 */
.search-result {
  .search-result-list {
    .page-list {
      .page-list-ul {
        > li.nav-item > a.nav-link {
          color: inherit;
        }
        a {
          &.hover {
            background-color: darken($bgcolor-global, 4%);
          }
          &.active {
            background-color: darken($bgcolor-global, 8%);
            border-color: theme-color('primary');
          }
        }
      }
    }
  }
}

/*
 * react bootstrap typeahead
 */
mark.rbt-highlight-text {
  // Temporarily the highlight color is black
  color: black;
}

/*
 * GROWI page content footer
 */
.page-content-footer {
  background-color: darken($bgcolor-global, 2%);
  border-top-color: $border-color-theme;
}

/*
 * GROWI admin page #layoutOptions #themeOptions
 */
.admin-page {
  #layoutOptions {
    .customize-layout-card {
      &.border-active {
        border-color: $color-theme-color-box;
      }
    }
  }

  #themeOptions {
    .theme-option-container.active {
      .theme-option-name {
        color: $color-global;
      }
      a {
        background-color: $color-theme-color-box;
        border-color: $color-theme-color-box;
      }
    }
  }
}

/*
 * HackMd
 */
.bg-box {
  background-color: $bgcolor-global;
}

.grw-fab {
  .btn-create-page {
    fill: color-yiq($primary);
  }

  .btn-scroll-to-top {
    fill: $gray-900;
  }
}

// Page Management Dropdown icon
.grw-btn-page-management:hover,
.grw-btn-page-management:focus {
  background-color: rgba($color-link, 0.15);
}

/*
  Slack Integration
*/
.selecting-bot-type {
  .bot-type-disc {
    width: 20px;
  }
}
