@use './variables';
@use './mixins/clearfix';
@use './mixins/nav-size';
@use './mixins/nav-divider';
@use './mixins/border-radius' as br;

//
// Navs
// --------------------------------------------------

// Base class
// --------------------------------------------------

.nav {
    margin-bottom: 0;
    padding-left: 0; // Override default ul/ol
    list-style: none;
    @include clearfix.clearfix;

    > li {
        position: relative;
        display: inline-block;

        > a,
        > button:not(.btn) {
            position: relative;
            display: block;
            @include nav-size.nav-size(variables.$padding-base-vertical, variables.$padding-base-horizontal, 14px, 1);
            color: variables.$text-color-secondary;
            background: none;
            border: none;
            width: 100%;
            text-align: left;
            cursor: pointer;
            &:hover,
            &:focus {
                text-decoration: none;
                color: variables.$text-color;
            }
        }

        // Disabled state sets text to gray and nukes hover/tab effects
        &.disabled > a,
        &.disabled > button:not(.btn) {
            color: variables.$nav-disabled-link-color;

            &:hover,
            &:focus {
                color: variables.$nav-disabled-link-hover-color;
                text-decoration: none;
                background-color: transparent;
                cursor: variables.$cursor-disabled;
            }
        }
    }

    // Open dropdowns
    .open > a,
    .open > button:not(.btn) {
        &,
        &:hover,
        &:focus {
            background-color: variables.$nav-link-hover-bg;
            border-color: variables.$link-color;
        }
    }

    // Nav dividers (deprecated with v3.0.1)
    //
    // This should have been removed in v3 with the dropping of `.nav-list`, but
    // we missed it. We don't currently support this anywhere, but in the interest
    // of maintaining backward compatibility in case you use it, it's deprecated.
    .nav-divider {
        @include nav-divider.nav-divider;
    }

    // Prevent IE8 from misplacing imgs
    //
    // See https://github.com/h5bp/html5-boilerplate/issues/984#issuecomment-3985989
    > li > a > img {
        max-width: none;
    }
}

// Tabs
// -------------------------

// Give the tabs something to sit on
.nav-tabs {
    > li {
        margin: 0 12px;
        display: inline-flex;
        align-items: center;
        vertical-align: middle;

        // Actual tabs (as links or buttons)
        > a,
        > button:not(.btn) {
            width: auto;
            min-width: 0;
            color: variables.$text-color-secondary;
        }
        &:first-child {
            margin-left: 0;
        }
        &:last-child {
            margin-right: 0;
        }

        // Active state, and its :hover to override normal :hover
        &.active > a,
        &.active > button:not(.btn) {
            &,
            &:hover,
            &:focus {
                color: variables.$nav-tabs-active-link-hover-color;
                cursor: default;
            }
        }
    }
    // pulling this in mainly for less shorthand
    &.nav-justified {
        @extend .nav-justified;
        @extend .nav-tabs-justified;
    }
    &.nav-sm > li > a,
    &.nav-sm > li > button:not(.btn) {
        @include nav-size.nav-size(
            variables.$padding-small-vertical + 1,
            0,
            variables.$font-size-small,
            variables.$line-height-small
        );
    }
    &.nav-md > li > a,
    &.nav-md > li > button:not(.btn) {
        @include nav-size.nav-size(variables.$padding-base-vertical + 1, 0, 14px, variables.$line-height-base);
    }
    &.nav-lg > li > a,
    &.nav-lg > li > button:not(.btn) {
        @include nav-size.nav-size(
            variables.$padding-large-vertical + 1,
            0,
            variables.$font-size-large,
            variables.$line-height-large
        );
    }
}

nw-tabs {
    .scroll-container {
        white-space: nowrap;
        overflow-x: auto;
        // To account for active-tab element
        padding-bottom: 3px;
        scroll-behavior: smooth;

        -ms-overflow-style: none;
        scrollbar-width: none;

        &::-webkit-scrollbar {
            display: none;
        }
    }
    .pagination-container {
        position: absolute;
        height: 100%;
        width: 100%;
        top: 0;
        left: 0;
        pointer-events: none;

        .prev-page,
        .next-page {
            position: absolute;
            top: 0;
            height: 100%;
            display: flex;
            flex-direction: column;
            justify-content: center;
            align-items: center;
            pointer-events: all;
        }
        .next-page {
            right: 0;
            transform: rotate(180deg);
        }
    }
    .nav-tabs-active-bar {
        margin: 0;
        display: block;
        height: 3px;
        position: absolute;
        bottom: 0;
        left: 0;
        background-color: variables.get-color('primary', base);
        transition: all ease-in-out 200ms;
    }
}

// Pills
// -------------------------
.nav-pills {
    > li {
        float: left;

        // Links rendered as pills
        > a,
        > button {
            border-radius: variables.$nav-pills-border-radius;
            background-color: variables.$level1;
            text-decoration: none;

            &:hover,
            &:focus {
                background-color: variables.$nav-link-hover-bg;
            }
        }
        &:not(:first-child):not(:last-child) {
            > a,
            > button {
                border-radius: 0;
            }
        }
        &:first-child:not(:last-child) {
            > a,
            > button {
                @include br.border-right-radius(0);
            }
        }
        &:last-child:not(:first-child) {
            > a,
            > button {
                @include br.border-left-radius(0);
            }
        }
        + li {
            margin-left: 2px;
        }

        // Active state
        &.active > a,
        &.active > button {
            &,
            &:hover,
            &:focus {
                color: variables.$nav-pills-active-link-hover-color;
                background-color: variables.$nav-pills-active-link-hover-bg;
            }
        }
        &.disabled > a,
        &.disabled > button {
            color: variables.$nav-disabled-link-color;
            background-color: rgba(variables.$level1, 0.5);

            &:hover,
            &:focus {
                color: variables.$nav-disabled-link-hover-color;
                background-color: rgba(variables.$level1, 0.5);
                cursor: variables.$cursor-disabled;
            }
        }
    }
}

// Stacked pills
.nav-stacked {
    > li {
        float: none;
        + li {
            margin-top: 2px;
            margin-left: 0; // no need for this gap between nav items
        }
    }
}

// Nav variations
// --------------------------------------------------

// Justified nav links
// -------------------------

.nav-justified {
    width: 100%;

    > li {
        float: none;
        > a,
        > button {
            text-align: center;
            margin-bottom: 5px;
        }
    }

    > .dropdown .dropdown-menu {
        top: auto;
        left: auto;
    }

    @media (min-width: variables.$screen-sm-min) {
        > li {
            display: table-cell;
            width: 1%;
            > a,
            > button {
                margin-bottom: 0;
            }
        }
    }
}

// Move borders to anchors instead of bottom of list
//
// Mixin for adding on top the shared `.nav-justified` styles for our tabs
.nav-tabs-justified {
    border-bottom: 0;

    > li > a,
    > li > button {
        // Override margin from .nav-tabs
        margin-right: 0;
        border-radius: variables.$border-radius-base;
    }

    > .active > a,
    > .active > a:hover,
    > .active > a:focus,
    > .active > button,
    > .active > button:hover,
    > .active > button:focus {
        border: 1px solid variables.$nav-tabs-justified-link-border-color;
    }

    @media (min-width: variables.$screen-sm-min) {
        > li > a,
        > li > button {
            border-bottom: 1px solid variables.$nav-tabs-justified-link-border-color;
            border-radius: variables.$border-radius-base variables.$border-radius-base 0 0;
        }
        > .active > a,
        > .active > a:hover,
        > .active > a:focus,
        > .active > button,
        > .active > button:hover,
        > .active > button:focus {
            border-bottom-color: variables.$nav-tabs-justified-active-link-border-color;
        }
    }
}

// Tabbable tabs
// -------------------------

// Hide tabbable panes to start, show them when `.active`
.tab-content {
    > .tab-pane {
        display: none;
    }
    > .active {
        display: block;
    }
}

// Dropdowns
// -------------------------

// Specific dropdowns
.nav-tabs .dropdown-menu {
    // make dropdown border overlap tab border
    margin-top: -1px;
    // Remove the top rounded corners here since there is a hard edge above the menu
    @include br.border-top-radius(0);
}
