@use "bulma/sass/utilities/css-variables" as cv;
@use "bulma/sass/utilities/initial-variables" as iv;
@use "bulma/sass/utilities/derived-variables" as dv;
@use "bulma/sass/utilities/mixins" as mixins;

$tabs-focused-outline: none !default;
$tabs-items-focused-outline: none !default;
$tabs-link-focus-active-border-bottom-color: cv.getVar("tabs-link-active-border-bottom-color") !default;
$tabs-link-focus-border-bottom-color: cv.getVar("tabs-link-hover-border-bottom-color") !default;
$tabs-boxed-link-focus-active-background-color: cv.getVar("tabs-boxed-link-active-background-color") !default;
$tabs-boxed-link-focus-background-color: cv.getVar("tabs-boxed-link-hover-background-color") !default;
$tabs-boxed-link-focus-active-border-bottom-color: cv.getVar("tabs-boxed-link-active-border-bottom-color") !default;
$tabs-boxed-link-focus-border-bottom-color: cv.getVar("tabs-boxed-link-hover-border-bottom-color") !default;
$tabs-toggle-link-focus-active-background-color: cv.getVar("tabs-toggle-link-active-background-color") !default;
$tabs-toggle-link-focus-background-color: cv.getVar("tabs-toggle-link-hover-background-color") !default;
$tabs-toggle-link-focus-active-border-color: cv.getVar("tabs-toggle-link-active-border-color") !default;
$tabs-toggle-link-focus-border-color: cv.getVar("tabs-toggle-link-hover-border-color") !default;

.#{iv.$class-prefix}b-tabs {
    @include cv.register-vars((
        "tabs-focused-outline": #{$tabs-focused-outline},
        "tabs-items-focused-outline": #{$tabs-items-focused-outline},
        "tabs-link-focus-active-border-bottom-color": #{$tabs-link-focus-active-border-bottom-color},
        "tabs-link-focus-border-bottom-color": #{$tabs-link-focus-border-bottom-color},
        "tabs-boxed-link-focus-active-background-color": #{$tabs-boxed-link-focus-active-background-color},
        "tabs-boxed-link-focus-background-color": #{$tabs-boxed-link-focus-background-color},
        "tabs-boxed-link-focus-active-border-bottom-color": #{$tabs-boxed-link-focus-active-border-bottom-color},
        "tabs-boxed-link-focus-border-bottom-color": #{$tabs-boxed-link-focus-border-bottom-color},
        "tabs-toggle-link-focus-active-background-color": #{$tabs-toggle-link-focus-active-background-color},
        "tabs-toggle-link-focus-background-color": #{$tabs-toggle-link-focus-background-color},
        "tabs-toggle-link-focus-active-border-color": #{$tabs-toggle-link-focus-active-border-color},
        "tabs-toggle-link-focus-border-color": #{$tabs-toggle-link-focus-border-color}
    ))
}

.#{iv.$class-prefix}b-tabs {
    .tabs {
        margin-bottom: 0;
        flex-shrink: 0;
        li {
            a:focus {
                outline: cv.getVar("tabs-focused-outline");
                border-bottom-color: cv.getVar("tabs-link-focus-active-border-bottom-color");
            }
            &:not(.is-active) {
                a:focus {
                    border-bottom-color: cv.getVar("tabs-link-focus-border-bottom-color");
                }
            }

            &.is-disabled {
                pointer-events: none;
                cursor: not-allowed;
                opacity: 0.5;
            }
        }

        // Styles
        &.is-boxed {
            li {
                a:focus {
                    background-color: cv.getVar("tabs-boxed-link-focus-active-background-color");
                    border-bottom-color: cv.getVar("tabs-boxed-link-focus-active-border-bottom-color");
                }
                &:not(.is-active) {
                    a:focus {
                        background-color: cv.getVar("tabs-boxed-link-focus-background-color");
                        border-bottom-color: cv.getVar("tabs-boxed-link-focus-border-bottom-color");
                    }
                }
            }
        }
        &.is-toggle {
            li {
                a:focus {
                    background-color: cv.getVar("tabs-toggle-link-focus-active-background-color");
                    border-color: cv.getVar("tabs-toggle-link-focus-active-border-color");
                }
                &:not(.is-active) {
                    a:focus {
                        background-color: cv.getVar("tabs-toggle-link-focus-background-color");
                        border-color: cv.getVar("tabs-toggle-link-focus-border-color");
                    }
                }
            }
        }
    }
    .tab-content {
        position: relative;
        overflow: visible;
        display: flex;
        flex-direction: column;
        padding: 1rem;
        .tab-item {
            flex-shrink: 0;
            flex-basis: auto;

            &:focus {
                outline: cv.getVar("tabs-items-focused-outline");
            }
        }
        &.is-transitioning {
            overflow: hidden;
        }
    }
    &:not(:last-child) {
        margin-bottom: 1.5rem;
    }
    &.is-fullwidth {
        width: 100%;
    }
    &.is-vertical {
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        > .tabs {
            ul {
                flex-direction: column;
                border-bottom-color: transparent;

                li {
                    width: 100%;

                    a {
                        justify-content: left;
                    }
                }
            }

            &.is-boxed {
                li {
                    a {
                        border-bottom-color: transparent !important;
                        border-right-color: cv.getVar("tabs-border-bottom-color") !important;
                        border-radius: cv.getVar("tabs-boxed-link-radius") 0 0 cv.getVar("tabs-boxed-link-radius");
                    }

                    &.is-active {
                        a {
                            border-bottom-color: cv.getVar("tabs-border-bottom-color") !important;
                            border-right-color: transparent !important;
                        }
                    }
                }
            }
            &.is-toggle {
                li {
                    + li {
                        margin-left: 0;
                    }
                    &:first-child {
                        a {
                            border-radius: cv.getVar("tabs-toggle-link-radius") cv.getVar("tabs-toggle-link-radius") 0 0;
                        }
                    }
                    &:last-child {
                        a {
                            border-radius: 0 0 cv.getVar("tabs-toggle-link-radius") cv.getVar("tabs-toggle-link-radius");
                        }
                    }
                }
            }
            &.is-fullwidth {
                li {
                    a {
                        height: 100%;
                    }
                }
            }
        }
        > .tab-content {
            flex-grow: 1;
        }

        &.is-right {
            flex-direction: row-reverse;

            > .tabs {
                ul {
                    a {
                        flex-direction: row-reverse;

                        .icon:first-child {
                            margin-right: 0;
                            margin-left: 0.5em
                        }
                    }
                }

                &.is-boxed {
                    li {
                        a {
                            border-bottom-color: transparent !important;
                            border-right-color: transparent !important;
                            border-left-color: cv.getVar("tabs-border-bottom-color") !important;
                            border-radius: 0 cv.getVar("tabs-boxed-link-radius") cv.getVar("tabs-boxed-link-radius") 0;
                        }

                        &.is-active {
                            a {
                                border-bottom-color: cv.getVar("tabs-border-bottom-color") !important;
                                border-right-color: cv.getVar("tabs-border-bottom-color") !important;
                                border-left-color: transparent !important;
                            }
                        }
                    }
                }
            }
        }
    }
    &.is-multiline {
        > .tabs {
            ul {
                flex-wrap: wrap;
                flex-shrink: 1;
            }
        }
    }
}
