/**
 * @license
 * Copyright Endlessjs. All Rights Reserved.
 * Licensed under the MIT License. See License.txt in the project root for license information.
 */

@mixin window-mode($padding-top) {
  padding-top: $padding-top;

  el-layout-header.fixed {
    top: $padding-top;
  }

  el-layout-header.fixed ~ .layout-container el-sidebar .main-container-fixed {
    height: calc(100vh - #{$padding-top} - #{el-theme(header-height)});
    top: calc(#{$padding-top} + #{el-theme(header-height)});
  }

  el-sidebar.fixed {
    left: calc((100vw - #{el-theme(layout-window-mode-max-width)}) / 2);
  }

  .layout .layout-container {
    el-sidebar.fixed.right {
      right: calc((100vw - #{el-theme(layout-window-mode-max-width)}) / 2);
    }

    el-sidebar.fixed {
      top: calc(#{el-theme(header-height)} + #{$padding-top});
    }
  }

  .scrollable-container {
    height: calc(100vh - #{$padding-top});
    box-shadow: el-theme(layout-window-shadow);
  }
}

@mixin el-layout-theme() {

  el-layout .scrollable-container {
    @include el-scrollbars(
        el-theme(layout-scrollbar-color),
        el-theme(layout-scrollbar-background-color),
        el-theme(layout-scrollbar-width));
  }


  el-layout.with-scroll .scrollable-container {
    overflow: auto;
    height: 100vh;
    display: block;

    @include media-breakpoint-down(sm) {
      overflow-y: scroll;
      -webkit-overflow-scrolling: touch;
    }
  }

  .layout {
    min-width: el-theme(layout-window-mode-min-width);
  }

  el-layout.window-mode {

    background: el-theme(layout-window-mode-background-color);
    display: block;

    .scrollable-container {
      max-width: el-theme(layout-window-mode-max-width);
      margin: 0 auto;
    }

    .layout el-layout-header {
      max-width: el-theme(layout-window-mode-max-width);
      margin-left: auto;
      margin-right: auto;
      width: 100%;

      nav {
        max-width: el-theme(layout-window-mode-max-width);
        margin: 0 auto;
      }
    }

    @media screen and (min-width: el-theme(layout-window-mode-max-width) + 20px) {
      $padding-top: el-theme(layout-window-mode-padding-top) / 4;

      @include window-mode($padding-top);

      el-layout.with-scroll {
        .scrollable-container {
          height: calc(100vh - #{$padding-top});
        }
      }
    }

    @media screen and (min-width: el-theme(layout-window-mode-max-width) + 150px) {
      $padding-top: el-theme(layout-window-mode-padding-top) / 2;

      @include window-mode($padding-top);

      el-layout.with-scroll {
        .scrollable-container {
          height: calc(100vh - #{$padding-top});
        }
      }
    }

    @media screen and (min-width: el-theme(layout-window-mode-max-width) + 300px) {
      $padding-top: el-theme(layout-window-mode-padding-top);

      @include window-mode($padding-top);

      el-layout.with-scroll {
        .scrollable-container {
          height: calc(100vh - #{$padding-top});
        }
      }
    }
  }

  el-layout .layout {
    background-color: el-theme(layout-background-color);
    color: el-theme(layout-text-color);
    font-family: el-theme(layout-text-font-family);
    font-size: el-theme(layout-text-font-size);
    font-weight: el-theme(layout-text-font-weight);
    line-height: el-theme(layout-text-line-height);
    min-height: el-theme(layout-min-height);

    .layout-container {

      el-sidebar {
        &.fixed,
        .main-container-fixed {
          top: el-theme(header-height);
        }
      }

      .content {

        el-layout-footer {
          box-shadow: el-theme(footer-shadow);

          nav {
            background-color: el-theme(footer-background-color);
            border-top: el-theme(footer-divider-width) el-theme(footer-divider-style) el-theme(footer-divider-color);
            color: el-theme(footer-text-color);
            font-family: el-theme(footer-text-font-family);
            font-size: el-theme(footer-text-font-size);
            font-weight: el-theme(footer-text-font-weight);
            line-height: el-theme(footer-text-line-height);
            padding: el-theme(footer-padding);

            a {
              color: el-theme(footer-text-highlight-color);

              @include hover-focus-active {
                color: el-theme(footer-text-highlight-color);
              }
            }
          }
        }

        &.center {
          width: el-theme(layout-content-width);
          flex: 0 100 el-theme(layout-content-width) !important;
        }

        .columns el-layout-column {
          padding: el-theme(layout-padding);

          @include media-breakpoint-down(md) {
            padding: el-theme(layout-medium-padding);
          }

          @include media-breakpoint-down(sm) {
            padding: el-theme(layout-small-padding);
          }
        }
      }
    }
  }

  el-layout-header {
    background-color: el-theme(header-background-color);
    color: el-theme(header-text-color);
    font-family: el-theme(header-text-font-family);
    font-size: el-theme(header-text-font-size);
    font-weight: el-theme(header-text-font-weight);
    line-height: el-theme(header-text-line-height);

    nav {
      color: el-theme(header-text-color);
      box-shadow: el-theme(header-shadow);
      height: el-theme(header-height);
      padding: el-theme(header-padding);

      a {
        color: el-theme(header-text-color);

        @include hover-focus-active {
          color: el-theme(header-text-color);
        }
      }
    }

    & ~ .layout-container {
      min-height: calc(#{el-theme(layout-min-height)} - #{el-theme(header-height)});
    }

    &.fixed ~ .layout-container {
      padding-top: el-theme(header-height);
      min-height: el-theme(layout-min-height);
    }

    &.fixed ~ .layout-container el-sidebar .main-container {
      height: calc(#{el-theme(sidebar-height)} - #{el-theme(header-height)});
    }
  }

  el-layout.with-subheader {
    el-sidebar .main-container {
      box-shadow: none; // so that we don't have a shadow over the header in this mode
    }
  }
}
