// Copyright (c) 2016-2018 VMware, Inc. All Rights Reserved.
// This software is released under MIT license.
// The full license information can be found in LICENSE in the root directory of this project.

@include exports('stack-view.clarity') {
    .stack-header {
        font-weight: $clr-stack-font-weight;
        display: flex;
        align-items: flex-end;

        .stack-title {
            display: block;
            flex: 1 1 auto;
            padding: 0.25rem 0;
        }

        .stack-actions {
            display: block;
            flex: 0 0 auto;

            .stack-action {
                margin: 0 0 0.25rem 0.5rem;

                &.btn {
                    min-width: 0;
                    padding: 0 0.5rem;
                }

                &.btn-link {
                    // Weird negative margin to make the button aligned with the stack view
                    // in its default state. It then looks unaligned on hover only.
                    margin-right: -0.5rem;
                }
            }
        }
    }

    .stack-view {
        @include clr-getTypePropertiesForDomElement(stackview_text, (color, font-size, font-weight, line-height, letter-spacing));
        margin-top: 0;
        border: $clr-default-borderwidth solid $clr-stack-view-border-color;
        border-radius: $clr-global-borderradius;
        overflow-y: auto;
        background-color: $clr-stack-view-bg-color;
        word-wrap: break-word;

        /* this fixes the overflow problem of children elements in a wrapper with a border-radius in Chrome */
        -webkit-mask-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAA5JREFUeNpiYGBgAAgwAAAEAAGbA+oJAAAAAElFTkSuQmCC);

        dd, dt {
            // One of the caveats of using definition lists here. Browsers automatically style them in unpredictable ways... :(
            -webkit-margin-start: 0;
            margin-inline-start: 0;
            margin-left: 0;
        }

        .stack-block {
            display: flex;
            // Wrapping for nested stack-blocks
            flex-flow: row wrap;
            border-bottom: 1px solid $clr-stack-view-stack-block-border-bottom;
        }

        // We have to handle potential nested elements, typically for web components
        > .stack-block:last-child, > :last-child .stack-block:last-of-type {
            // This way we keep a border-bottom on the last element if the stack view is higher
            // than the total height of the  blocks it contains, but we do not have a
            // weird 1px scroll when both heights match exactly.
            border-bottom: none;
            box-shadow: 0 1px 0 $clr-stack-view-border-box-color;
        }

        .stack-block-changed {
            > .stack-block-label {
                margin-left: -0.375rem;
            }
            &::before {
                content: " ";
                position: relative;
                width: 0;
                height: 0;
                border-top: 0.375rem solid $clr-stack-block-changed-border-top-color;
                border-right: 0.375rem solid transparent;
            }
        }

        .stack-block-label, .stack-block-content {
            padding: 0.25rem 0.5rem;
            background-color: $clr-stack-view-stack-block-label-and-content-bg-color;
        }

        .stack-block-label {
            @include clr-getTypePropertiesForDomElement(stackview_header, (font-size, font-weight, line-height, letter-spacing));
            color: $clr-stack-view-stack-block-label-text-color;

            // We're doing a non-flexible item.
            // It's just easier to align and stretch everything vertically this way than with
            // floats or inline-blocks.
            flex: 0 0 40%;
            max-width: 40%;

            &::before {
                display: inline-block;
                content: "";
                float: left;
                height: $clr-dropdown-caret-icon-dimension;
                width: $clr-dropdown-caret-icon-dimension;
                margin: (0.25rem + $clr-rem-1px) 0.25rem 0 0;
                text-align: center;
            }
        }

        .stack-block-content {
            color: $clr-stack-view-stack-block-content-text-color;
            flex: 1 1 auto;
            width: 60%;
            margin-bottom: 0;
            font-weight: $clr-stack-font-weight;

            @include clr-container;
        }

        .stack-children {
            flex: 0 0 auto;
            width: 100%;

            .stack-block {
                border-bottom-color: $clr-stack-view-stack-children-stack-block-border-bottom-color;
            }
            > .stack-block:last-child, > :last-child .stack-block:last-of-type {
                // This way we keep a border-bottom on the last element if the stack view is higher
                // than the total height of the  blocks it contains, but we do not have a
                // weird 1px scroll when both heights match exactly.
                border-bottom: none;
                box-shadow: 0 1px 0 $clr-stack-view-border-box-color;
            }

            .stack-block-label, .stack-block-content {
                background-color: $clr-stack-view-stack-children-stack-block-label-and-content-bg-color;
            }

            .stack-block-label {
                padding-left: 1rem;
            }
        }

        .stack-block-expandable {
            > .stack-block-label {
                cursor: pointer;

                &::before {
                    background-image: generateCaretIcon();
                    @include icon-background-styles();
                    transform: rotate(-90deg);
                }
            }
            > .stack-block-label, > .stack-block-content {
                transition: background-color 0.2s ease-in-out, color 0.2s ease-in-out;
            }

            &:hover:not(.stack-block-expanded) {
                > .stack-block-label, > .stack-block-content {
                    background-color: $clr-stack-view-stack-block-expandable-hover;
                }
            }
        }

        .stack-block-expanded {
            > .stack-block-label::before {
                transform: rotate(0deg);
            }

            > .stack-block-label, > .stack-block-content {
                background-color: $clr-stack-view-stack-block-expanded-bg-color;
                color: $clr-stack-view-stack-block-expanded-text-color;
            }
        }

        /*
         * Styles specific to inputs used in a stack view
         */
        #{$styledInputs}, .select {
            display: inline-block;
            vertical-align: top;
            margin-right: 0.5rem;
            // We need to account for the border at the bottom of inputs
            // Or the stack view blocks all move 1px when going in edit mode.
            // Inputs are 24px high but 25px total when you include the border.
            margin-bottom: -1 + $clr-default-borderwidth;
        }

        // Fix for Firefox and IE, which are throwing line-height for inputs in the air,
        // like they just don't care.
        // Yes, hard-coding the height isn't great. Haven't found anything better cross-browser.
        #{$styledInputs}, .select select {
            height: 1rem;
        }

        // TODO: Clean up if not being used
        .stack-block-expandable > .stack-block-content {
            #{$styledInputs} {
                transition: background-size 0.2s ease, border-bottom-color 0.2s ease-in-out;
            }
            .select {
                select {
                    transition: border-bottom-color 0.2s ease-in-out;
                }
                &::after {
                    transition: color 0.2s ease-in-out;
                }
            }
        }
        // TODO: Clean up if not being used
        .stack-block-expanded > .stack-block-content {
            #{$styledInputs} {
                border-bottom-color: $gray-dark;
                @include input-border-bottom-animation($action-blues-dark-midtone);
            }

            .select {
                select {
                    border-bottom-color: $gray-dark;
                }

                &::after {
                    color: $gray-dark;
                }
            }
        }

        /*
         * Styles specific to stack views used in a modal
         */
        .modal & {
            height: 55vh;
            margin-bottom: 0;
        }
    }
}
