/*
    Currently it does not work to set the carbon vars before the include of
    the library component because the include reset the vars again to the
    default values. For this reason we need to overwrite colors again in our
    own rule patches.
*/

@use "sass:color";

/// Header bar background
$shell-header-bg-01: var(
    --#{$eccgui}-appheader-color-background,
    #{$eccgui-color-applicationheader-background}
) !default;

/// Header menu trigger hover, Header nav link hover
$shell-header-bg-02: eccgui-color-mix($shell-header-bg-01, black 5%) !default;

/// Header action active background
$shell-header-bg-03: eccgui-color-mix($shell-header-bg-01, black 10%) !default;

/// Header submenu link hover
$shell-header-bg-04: $shell-header-bg-02 !default;

/// Header nav link active and focus background
$shell-header-bg-05: $shell-header-bg-02 !default;

/// Header nav link submenu
$shell-header-bg-06: $shell-header-bg-03 !default;

/// Header border bottom
$shell-header-border-01: transparent !default;

/// Header focus
$shell-header-focus: eccgui-color-mix($eccgui-color-applicationheader-text, white 39%) !default;

/// Primary text in header, Title text
$shell-header-text-01: eccgui-color-mix($eccgui-color-applicationheader-text, black 5%) !default;

/// Secondary text in header, Menu item nav text
$shell-header-text-02: $eccgui-color-applicationheader-text !default;

/// Header menu trigger
$shell-header-icon-01: $eccgui-color-applicationheader-text !default;

/// Header bar icons
$shell-header-icon-02: $eccgui-color-applicationheader-text !default;

/// Header bar icons
$shell-header-icon-03: $eccgui-color-applicationheader-text !default;

/// Item link
$shell-header-link: $blue-60 !default;

/// Height
$shell-header-height: mini-units(8) !default;

// load library sub component
@import "~@carbon/react/scss/components/ui-shell/header/index";

// tweak original layout

.#{$prefix}--header {
    height: $shell-header-height;
}

.#{$prefix}--header__action,
.#{$prefix}--header__action.#{$prefix}--btn--icon-only {
    width: $shell-header-height;
    height: $shell-header-height;
    padding-block-start: 0;
    background-color: transparent;

    // $shell-header-icon-02
    & > svg {
        fill: $eccgui-color-applicationheader-text;
    }
}

.#{$prefix}--header__menu-trigger {
    flex-shrink: 0;
    margin-right: 0;
}

span.#{$prefix}--header__name {
    // @extend a.#{$prefix}--header__name;
    @extend .#{$prefix}--header__name;
}

.#{$prefix}--header__name {
    &.#{$eccgui}-application__title--withsidebar {
        padding-right: $eccgui-size-block-whitespace * 0.5;
    }
}

.#{$eccgui}-application__title--withsidebar {
    flex-shrink: 0;
    width: mini-units(40 - 8);
}

.#{$eccgui}-application__title--content {
    display: inline-block;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: $eccgui-size-typo-caption;
    font-weight: $eccgui-font-weight-bold;
    line-height: $eccgui-size-typo-caption-lineheight;
    letter-spacing: $eccgui-font-spacing-wide;
    white-space: nowrap;
}

.#{$eccgui}-application__title--depiction {
    display: inline-block;
    margin-right: $eccgui-size-block-whitespace * 0.5;

    & > * {
        display: none;
    }

    & > img,
    & > svg {
        display: inline;
        width: auto;
        max-width: mini-units(5);
        height: auto;
        max-height: mini-units(5);
        padding: 0;
        margin: mini-units(1.4) 0 mini-units(1.6);
        vertical-align: middle;
    }
}

.#{$prefix}--header__menu .#{$prefix}--header__menu-item {
    height: $shell-header-height;
}

// tweak original colors (as long as config does not work properly)

// $shell-header-bg-01
.#{$prefix}--header,
.#{$prefix}--skip-to-content:focus {
    background-color: $shell-header-bg-01;
}

// $shell-header-bg-02
a.#{$prefix}--header__menu-item:hover {
    background-color: $shell-header-bg-02;
}
.#{$prefix}--header__menu-trigger:hover {
    fill: $shell-header-bg-02;
}

// $shell-header-bg-03
.#{$prefix}--header__action:active,
.#{$prefix}--header__action.#{$prefix}--btn--icon-only:active,
.#{$prefix}--header__menu-title[aria-expanded="true"] + .#{$prefix}--header__menu .#{$prefix}--header__menu-item:active,
a.#{$prefix}--header__menu-item:active {
    background-color: $shell-header-bg-03;
}

// $shell-header-bg-04
.#{$prefix}--header__action:hover,
.#{$prefix}--header__action.#{$prefix}--btn--icon-only:hover,
.#{$prefix}--header__menu-title[aria-expanded="true"] + .#{$prefix}--header__menu .#{$prefix}--header__menu-item:hover {
    background-color: $shell-header-bg-04;
}

// $shell-header-bg-05
.#{$prefix}--header__action--active,
.#{$prefix}--header__action--active.#{$prefix}--btn--icon-only {
    background-color: $shell-header-bg-05;
    border-right-color: transparent;
    border-bottom-color: $shell-header-bg-05;
    border-left-color: transparent;
}

// $shell-header-bg-06
.#{$prefix}--header__menu-title[aria-expanded="true"],
.#{$prefix}--header__menu .#{$prefix}--header__menu-item:hover {
    background-color: $shell-header-bg-06;
}

// $shell-header-border-01
.#{$prefix}--header,
.#{$prefix}--header__action,
.#{$prefix}--header__action.#{$prefix}--btn--icon-only {
    border-bottom: none;
}
.#{$prefix}--header__nav {
    &::before {
        background-color: transparent;
    }
}

// $shell-header-focus
.#{$prefix}--header__action,
.#{$prefix}--header__action.#{$prefix}--btn--icon-only,
.#{$prefix}--header__action.#{$prefix}--btn--primary,
a.#{$prefix}--header__name,
a.#{$prefix}--header__menu-item {
    &:focus {
        @extend .#{$eccgui}-a11y-focus-by-pointer;

        border: none;
        box-shadow: none;
    }

    &,
    .#{$prefix}--popover--open & {
        &:focus-visible {
            @extend .#{$eccgui}-a11y-focus-by-keyboard-animated;

            border: none;
            box-shadow: none;
        }
    }
}
.#{$prefix}--header__menu-title[aria-expanded="true"] {
    color: $shell-header-focus;
}

// $shell-header-text-01
a.#{$prefix}--header__name,
a.#{$prefix}--header__name:hover,
a.#{$prefix}--header__menu-item:hover,
.#{$prefix}--header__action:active,
.#{$prefix}--header__action.#{$prefix}--btn--icon-only:active,
a.#{$prefix}--header__menu-item:active,
a.#{$prefix}--header__menu-item:focus,
.#{$prefix}--header__menu .#{$prefix}--header__menu-item:hover,
.#{$prefix}--skip-to-content:focus {
    color: $shell-header-text-01;
}

// $shell-header-text-02
a.#{$prefix}--header__menu-item {
    color: $eccgui-color-applicationheader-text;
}

// $shell-header-icon-01
.#{$prefix}--header__action,
.#{$prefix}--header__action:hover,
.#{$prefix}--header__action:active,
.#{$prefix}--header__action:focus {
    color: $eccgui-color-applicationheader-text;

    &.#{$prefix}--btn--icon-only {
        color: $eccgui-color-applicationheader-text;
    }
}
.#{$prefix}--header__menu-trigger > svg,
a.#{$prefix}--header__menu-item:hover > svg,
a.#{$prefix}--header__menu-item:active > svg,
a.#{$prefix}--header__menu-item:focus > svg {
    fill: $eccgui-color-applicationheader-text;
}

// $shell-header-icon-03
.#{$prefix}--header__menu-arrow {
    fill: $eccgui-color-applicationheader-text;
}

.#{$eccgui}-application--topheader {
    // put application header over all overlays

    .#{$eccgui}-application__header {
        z-index: $eccgui-zindex-overlays - 2;
    }

    // adjust position of all other modal dialogs

    .#{$ns}-dialog-container {
        top: $shell-header-height;
        left: $shell-header-height;
        width: calc(100% - #{$shell-header-height});
        min-height: calc(100% - #{$shell-header-height});
    }

    .#{$eccgui}-dialog__wrapper {
        max-width: calc(100vw - #{$shell-header-height} - #{2 * $eccgui-size-block-whitespace});
        max-height: calc(100vh - #{$shell-header-height} - #{2 * $eccgui-size-block-whitespace});
        margin: 0;
    }
}

@media print {
    .#{$eccgui}-application__header {
        position: relative;
        & > :not(.#{$eccgui}-workspace__header) {
            display: none;
        }
    }
}
