@import "../variables";
@import "../theme-colors";

@mixin sidebar-scrollbar {
  &::-webkit-scrollbar {
    width: $sidebar-scrollbar-width;
  }

  &::-webkit-scrollbar-track {
    background: transparent;
  }

  &::-webkit-scrollbar-thumb {
    background: transparent;
    border-radius: $default-radius;
  }

  &:hover {
    &::-webkit-scrollbar-thumb {
      background: $sidebar-scrollbar-thumb-color;
    }
  }
}

.sidebar {
  z-index: 200;
  position: fixed;
  min-height: 100vh;
  max-height: 100vh;
  font-family: $default-font-family;
  width: $sidebar-width-lg;
  background: var(--sidebar-bg);
  box-shadow: var(--sidebar-box-shadow);
  transition: width $default-transition-duration $action-transition-timing-function;
  -moz-transition: width $default-transition-duration $action-transition-timing-function;
  -webkit-transition: width $default-transition-duration $action-transition-timing-function;

  .navbar-brand-wrapper {
    height: $navbar-height;
    width: $sidebar-width-lg;
    background: var(--navbar-brand-bg);
    transition: width $default-transition-duration $action-transition-timing-function;
    -moz-transition: width $default-transition-duration $action-transition-timing-function;
    -webkit-transition: width $default-transition-duration $action-transition-timing-function;

    .navbar-brand {
      width: 100%;
      margin-right: 0;
      padding: 0 10px !important;

      img {
        height: 45px;
        margin: auto;
        max-width: 100%;
        vertical-align: middle;
      }

      &.brand-logo-mini {
        display: none;

        img {
          max-width: 100%;
          height: 45px;
          margin: auto;
        }
      }
    }
  }

  .nav {
    overflow: hidden;
    overflow-y: auto;
    flex-wrap: nowrap;
    flex-direction: column;
    max-height: calc(100vh - #{$navbar-height});

    .nav-item {
      padding: 0 $sidebar-menu-padding-x;
      transition: all $default-transition-duration $action-transition-timing-function;

      .collapsing {
        margin: 0 -1.25rem 0 -1.25rem;
        background-color: $sidebar-submenu-bg-color;
      }

      .collapse {
        z-index: 999;
        margin: 0 -1.25rem 0 -1.25rem;
        background-color: $sidebar-submenu-bg-color;
      }

      .nav-link {
        display: flex;
        align-items: center;
        white-space: nowrap;
        color: $sidebar-dark-menu-color;
        padding: $sidebar-menu-padding-y 0 $sidebar-menu-padding-y 0;
        transition: color $default-transition-duration $action-transition-timing-function;

        .icon-wrapper {
          height: 40px;
          min-width: 40px;
          max-width: 40px;
          display: flex;
          align-items: center;
          justify-content: center;
          border-radius: 2px;
          background-color: $navbar-brand-bg;
          transition: color $default-transition-duration $action-transition-timing-function;

          svg {
            width: 20px;
            height: 20px;
            color: $sidebar-dark-menu-color;
          }
        }

        .menu-title {
          color: inherit;
          line-height: 1;
          margin-left: 0.9rem;
          display: inline-block;
          vertical-align: middle;
          font-size: $sidebar-menu-font-size;
        }

        i {
          color: $sidebar-dark-menu-color;

          &.menu-arrow {
            opacity: 0.5;
            margin-left: auto;
            display: inline-block;
            color: $sidebar-dark-menu-color;
            transition: $default-transition-duration $action-transition-timing-function;
            font: normal normal 700 $sidebar-arrow-font-size/1 'Font Awesome 5 Free';

            .rtl & {
              margin-left: 0;
              margin-right: auto;
            }

            &:before {
              content: '\f078';
              font-size: inherit;
              color: inherit;
            }

            + .menu-icon {
              margin-left: .25rem;

              .rtl & {
                margin-left: 0;
                margin-right: .25rem;
              }
            }
          }
        }

        &[aria-expanded="true"] {
          .menu-arrow {
            transform: rotate(-180deg);
          }
        }
      }

      &.active {
        .nav-link {
          .icon-wrapper {
            background-color: $brand-color;

            svg {
              color: lighten($brand-color, 35%);
            }
          }

          .menu-title {
            color: lighten($brand-color, 35%);
            font-family: $default-font-family;
          }

          i {
            color: $sidebar-dark-menu-color;

            &.menu-arrow {
              transform: rotate(-180deg);
            }
          }

          &.collapsed {
            &[aria-expanded="false"] {
              .menu-arrow {
                transform: rotate(-360deg);
              }
            }
          }
        }
      }
    }

    &:not(.sub-menu) {
      > .nav-item {
        &:hover {
          > .nav-link {
            color: lighten($brand-color, 35%);

            .icon-wrapper {
              svg {
                color: lighten($brand-color, 35%);
              }
            }
          }
        }
      }
    }

    &.sub-menu {
      list-style: none;
      margin-bottom: 0;

      .nav-item {
        padding: 0;

        .nav-link {
          height: auto;
          border-top: 0;
          line-height: 1;
          position: relative;
          color: $sidebar-dark-menu-color;
          padding: 0 1.35rem 0.75rem 1.35rem;
          font-size: $sidebar-submenu-font-size;

          &::before {
            content: '';
            display: inline-block;
            width: 7px;
            height: 7px;
            margin: 10px 14px;
            border-radius: 50%;
            background-color: $sidebar-dark-menu-color;
          }

          &.active {
            color: lighten($brand-color, 35%) !important;
            background: transparent;

            &::before {
              background-color: $brand-color;
            }
          }

          &:hover {
            color: lighten($brand-color, 35%);

            &::before {
              background-color: lighten($brand-color, 35%);
            }
          }
        }

        &:hover {
          background: transparent;
        }

        &:first-child {
          .nav-link {
            padding-top: 1.2rem;
          }
        }

        &:last-child {
          .nav-link {
            padding-bottom: 1.2rem;
          }
        }

        .collapse-multi-level {
          .sub-menu {
            padding-left: 2rem;

            .nav-item {
              .nav-link {
                padding: 0 1.35rem 0.75rem 1.35rem;
              }

              &:first-child {
                .nav-link {
                  padding-top: initial;
                }
              }

              &:last-child {
                .nav-link {
                  padding-bottom: 0.75rem;
                }
              }
            }
          }
        }
      }
    }

    &.nav-scrolling {
      padding-top: 0.75rem;

      &::-webkit-scrollbar {
        width: $sidebar-scrollbar-width;
      }

      &::-webkit-scrollbar-track {
        background: transparent;
      }

      &::-webkit-scrollbar-thumb {
        background: transparent;
        border-radius: $default-radius;
      }

      &:hover {
        &::-webkit-scrollbar-thumb {
          background: $sidebar-scrollbar-thumb-color;
        }
      }
    }
  }
}

// Style for off-canvas menu
@media screen and (max-width: 991px) {
  .sidebar {
    .navbar-brand-wrapper {
      display: none !important;
    }
  }

  .sidebar-offcanvas {
    margin-top: 0;
    position: fixed;
    top: $navbar-height;
    bottom: 0;
    left: -$sidebar-width-lg;
    max-height: calc(100vh - #{$navbar-height});
    transition: all $default-transition-duration $action-transition-timing-function;
    -moz-transition: all $default-transition-duration $action-transition-timing-function;
    -webkit-transition: all $default-transition-duration $action-transition-timing-function;

    &.active {
      left: 0;
      box-shadow: 0 5px 10px rgba(0, 0, 0, 0.5);
    }
  }
}

// Sidebar Template Setting
.setting-actions {
  padding: 0.5rem;
  position: fixed;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  border-radius: 0.75rem 0 0 0.75rem;
  background-color: var(--default-card-bg);
  box-shadow: var(--shadow-template-setting-toggler);

  .btn {
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 !important;
    border-radius: 0.75rem !important;
    background-color: var(--base-color);
    transition: all $default-transition-duration ease-in-out !important;

    svg {
      width: 16px;
      height: 16px;
      color: $brand-color;
    }

    &:hover {
      background-color: $brand-color;

      svg {
        color: $white;
      }
    }
  }
}

.sidebar-template-setting {
  position: fixed;
  top: 0;
  right: -350px;
  bottom: 0;
  z-index: 1050;
  margin-top: 0;
  min-height: 100vh;
  max-height: 100vh;
  width: 350px;
  background-color: var(--default-card-bg);
  transition: all $default-transition-duration $action-transition-timing-function;
  -moz-transition: all $default-transition-duration $action-transition-timing-function;
  -webkit-transition: all $default-transition-duration $action-transition-timing-function;

  &.active {
    right: 0;
    box-shadow: 0 5px 10px rgba(0, 0, 0, 0.5);
  }

  .template-setting-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 $default-padding-margin;
    height: $navbar-height;
    background-color: var(--modal-header-footer-bg);
    border-bottom: 1px solid var(--default-border-color);

    .close-sidebar {
      border: 0;
      padding: 0;
      background-color: transparent;
      color: var(--default-font-color);

      svg {
        width: 32px;
        height: 32px;
        padding: 0.438rem;

        &:hover {
          border-radius: 50%;
          background-color: var(--icon-hover-bg);
        }
      }
    }
  }

  .template-setting-body {
    overflow-y: auto;
    padding: $default-padding-margin;
    max-height: calc(100vh - #{$navbar-height});

    .template-demo-item {
      display: block;
      padding: 0.35rem;
      text-align: center;
      border-radius: $default-radius;
      background-color: var(--default-border-color);
      border: 2px solid var(--default-border-color);
      transition: all $default-transition-duration ease-in-out;

      img {
        margin-bottom: 0.35rem;
        border-radius: $default-radius;
      }

      .demo-title {
        font-size: 13px;
        margin-bottom: 0;
        color: var(--default-font-color);
      }

      &.active, &:hover {
        border-color: $brand-color;
      }
    }

    @include sidebar-scrollbar;
  }
}

.template-setting-sidebar-overlay {
  &.open-overlay {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 1041;
    background-color: rgba(0, 0, 0, 0.5);
  }
}

// SCSS for RTL Layout
[dir="rtl"] {
  .sidebar {
    @media (max-width: 991px) {
      right: -$sidebar-width-lg !important;

      &.active {
        right: 0 !important;
      }
    }

    .nav {
      &.nav-scrolling {
        padding-right: 0 !important;

        .nav-item {
          .nav-link {
            .menu-title {
              border-radius: 5px 0 0 5px;
              margin-right: 8px !important;
            }

            i {
              &.menu-arrow {
                margin-right: auto;
                margin-left: initial;
              }
            }
          }

          .sub-menu {
            padding-right: 0 !important;
          }
        }
      }

      &.sub-menu {
        .nav-item {
          .collapse-multi-level {
            .sub-menu {
              padding-left: 0;
              padding-right: 2rem !important;
            }
          }
        }
      }
    }
  }

  .setting-actions {
    right: unset;
    left: 0;
    border-radius: 0 0.75rem 0.75rem 0;
    box-shadow: var(--shadow-template-setting-toggler);
  }

  .sidebar-template-setting {
    left: -350px !important;

    &.active {
      right: auto;
      left: 0 !important;
    }
  }
}