//
// Copyright IBM Corp. 2016, 2018
//
// This source code is licensed under the Apache-2.0 license found in the
// LICENSE file in the root directory of this source tree.
//

@import '../../globals/scss/functions';
@import '../../globals/scss/helper-classes';
@import '../../globals/scss/helper-mixins';
@import '../../globals/scss/layout';
@import '../../globals/scss/vars';
@import '../../globals/scss/typography';
@import 'theme';
@import 'functions';

/// UI shell header
/// @access private
/// @group ui-shell
@mixin carbon-header {
  .#{$prefix}--header {
    position: fixed;
    top: 0;
    right: 0;
    left: 0;
    z-index: z('header');
    display: flex;
    align-items: center;
    height: mini-units(6);
    background-color: $shell-header-bg-01;
    border-bottom: 1px solid $shell-header-border-01;
  }

  .#{$prefix}--header__action {
    @include button-reset();

    width: mini-units(6);
    height: mini-units(6);
    border: rem(2px) solid transparent;
    transition: background-color $duration--fast-02,
      border-color $duration--fast-02;
  }

  .#{$prefix}--header__action
    > svg.#{$prefix}--navigation-menu-panel-collapse-icon,
  .#{$prefix}--header__action--active
    > svg.#{$prefix}--navigation-menu-panel-expand-icon {
    display: none;
  }

  .#{$prefix}--header__action--active
    > svg.#{$prefix}--navigation-menu-panel-collapse-icon {
    display: inline;
  }

  .#{$prefix}--header__action:hover {
    background-color: $shell-header-bg-04;
  }

  .#{$prefix}--header__action--active {
    border-right: 1px solid $shell-header-border-01;
    border-bottom: 1px solid $shell-header-bg-01;
    border-left: 1px solid $shell-header-border-01;
  }

  .#{$prefix}--header__action:focus {
    border-color: $shell-header-focus;
    outline: none;

    // Firefox HCM Fix
    @media screen and (prefers-contrast) {
      border-style: dotted;
    }
  }

  .#{$prefix}--header__action:active {
    background-color: $shell-header-bg-03;
  }

  .#{$prefix}--header__action.#{$prefix}--btn--icon-only.#{$prefix}--tooltip__trigger {
    justify-content: center;
  }

  .#{$prefix}--header__action > svg {
    fill: $shell-header-icon-02;
  }

  .#{$prefix}--header__menu-trigger > svg {
    fill: $shell-header-icon-01;
  }

  .#{$prefix}--header__menu-trigger:hover {
    fill: $shell-header-bg-02;
  }

  .#{$prefix}--header__menu-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .#{$prefix}--header__menu-toggle__hidden {
    @include carbon--breakpoint('lg') {
      display: none;
    }
  }

  //--------------------------------------------------------------------------
  // Header - Name
  //--------------------------------------------------------------------------
  a.#{$prefix}--header__name {
    @include type-style('body-short-01');

    display: flex;
    align-items: center;
    height: 100%;
    padding: 0 mini-units(4) 0 mini-units(2);
    font-weight: 600;
    line-height: 1.25rem;
    letter-spacing: 0.1px;
    text-decoration: none;
    border: rem(2px) solid transparent;
    outline: none;
    transition: border-color $duration--fast-02;
    user-select: none;
  }

  a.#{$prefix}--header__name:focus {
    border-color: $shell-header-focus;

    // Windows, Firefox HCM Fix
    @media screen and (-ms-high-contrast: active),
      screen and (prefers-contrast) {
      // `ButtonText` is a CSS2 system color to help improve colors in HCM
      border-style: dotted;
    }
  }

  .#{$prefix}--header__name--prefix {
    font-weight: 400;
  }

  a.#{$prefix}--header__name,
  a.#{$prefix}--header__name:hover {
    color: $shell-header-text-01;
  }

  .#{$prefix}--header__menu-toggle:not(.#{$prefix}--header__menu-toggle__hidden)
    ~ .#{$prefix}--header__name {
    padding-left: rem(8px);
  }

  //--------------------------------------------------------------------------
  // Header - Navigation
  //--------------------------------------------------------------------------
  .#{$prefix}--header__nav {
    position: relative;
    display: none;
    height: 100%;
    padding-left: mini-units(2);

    @include carbon--breakpoint('lg') {
      display: block;
    }

    &::before {
      position: absolute;
      top: 50%;
      left: 0;
      display: block;
      width: rem(1px);
      height: rem(24px);
      background-color: $shell-header-border-01;
      transform: translateY(-50%);
      content: '';
    }
  }

  .#{$prefix}--header__menu-bar {
    display: flex;
    height: 100%;
    margin: 0;
    padding: 0;
    list-style: none;
  }

  a.#{$prefix}--header__menu-item {
    position: relative;
    display: flex;
    align-items: center;
    // Used for links that are directly in the menubar to span the full height
    height: 100%;
    padding: 0 mini-units(2);
    color: $shell-header-text-02;
    font-weight: 400;
    // Text styles
    font-size: rem(14px);
    line-height: 1.125rem;
    letter-spacing: 0;
    // Reset link styles and make sure the text isn't selectable
    text-decoration: none;
    // Used for focus styles
    border: 2px solid transparent;
    transition: background-color $duration--fast-02,
      border-color $duration--fast-02, color $duration--fast-02;
    user-select: none;
  }

  a.#{$prefix}--header__menu-item:hover {
    color: $shell-header-text-01;
    background-color: $shell-header-bg-02;
  }

  .#{$prefix}--header__action:active,
  a.#{$prefix}--header__menu-item:active {
    color: $shell-header-text-01;
    background-color: $shell-header-bg-03;
  }

  a.#{$prefix}--header__menu-item:focus {
    color: $shell-header-text-01;
    border-color: $shell-header-focus;
    outline: none;

    // Windows, Firefox HCM Fix
    @media screen and (-ms-high-contrast: active),
      screen and (prefers-contrast) {
      border-style: dotted;
    }
  }

  a.#{$prefix}--header__menu-item:hover > svg,
  a.#{$prefix}--header__menu-item:active > svg,
  a.#{$prefix}--header__menu-item:focus > svg {
    fill: $shell-header-icon-01;
  }

  // Styles for selected state

  a.#{$prefix}--header__menu-item[aria-current='page']::after,
  .#{$prefix}--header__menu-item--current::after {
    position: absolute;
    top: 0;
    right: 0;
    bottom: -2px;
    left: 0;
    width: 100%;
    border-bottom: 3px solid $inverse-support-04;
    content: '';
  }

  a.#{$prefix}--header__menu-item[aria-current='page']:focus::after,
  .#{$prefix}--header__menu-item--current:focus::after {
    border: 0;
  }

  a.#{$prefix}--header__menu-item[aria-current='page']:focus,
  a.#{$prefix}--header__menu-item.#{$prefix}--header__menu-item--current:focus {
    border: 2px solid $shell-header-focus;
  }

  .#{$prefix}--header__submenu {
    position: relative;
  }

  .#{$prefix}--header__menu-title[aria-haspopup='true'] {
    position: relative;
  }

  .#{$prefix}--header__menu-title[aria-expanded='true'] {
    // Note: needs to be higher than menu. Adding 1 here instead of moving to
    // the next level.
    z-index: #{z('header') + 1};
    color: $shell-header-focus;
    background-color: $shell-header-bg-06;
  }

  .#{$prefix}--header__menu-title[aria-expanded='true']
    > .#{$prefix}--header__menu-arrow {
    transform: rotate(180deg);
  }

  .#{$prefix}--header__menu {
    display: none;
    margin: 0;
    padding: 0;
    list-style: none;
  }

  .#{$prefix}--header__menu-title[aria-expanded='true']
    + .#{$prefix}--header__menu {
    position: absolute;
    bottom: 0;
    left: 0;
    z-index: z('header');
    display: flex;
    flex-direction: column;
    width: mini-units(25);
    background-color: $shell-header-bg-06;
    box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.5);
    transform: translateY(100%);
  }

  .#{$prefix}--header__menu-title[aria-expanded='true']
    + .#{$prefix}--header__menu
    .#{$prefix}--header__menu-item:hover {
    background-color: $shell-header-bg-04;
  }

  .#{$prefix}--header__menu-title[aria-expanded='true']
    + .#{$prefix}--header__menu
    .#{$prefix}--header__menu-item:active {
    background-color: $shell-header-bg-03;
  }

  .#{$prefix}--header__menu .#{$prefix}--header__menu-item {
    height: mini-units(6);
  }

  .#{$prefix}--header__menu .#{$prefix}--header__menu-item:hover {
    color: $shell-header-text-01;
    background-color: $shell-header-bg-06;
  }

  .#{$prefix}--header__menu-arrow {
    margin-left: mini-units(1);
    transition: transform $duration--fast-02, fill $duration--fast-02;
    fill: $shell-header-icon-03;
  }

  //--------------------------------------------------------------------------
  // Header - Global
  //--------------------------------------------------------------------------
  .#{$prefix}--header__global {
    display: flex;
    flex: 1 1 0%;
    justify-content: flex-end;
    height: 100%;
  }

  //--------------------------------------------------------------------------
  // Header - Skip to content
  //--------------------------------------------------------------------------
  .#{$prefix}--skip-to-content {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    white-space: nowrap;
    border: 0;
    visibility: inherit;
    clip: rect(0, 0, 0, 0);
  }

  .#{$prefix}--skip-to-content:focus {
    top: 0;
    left: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    width: auto;
    height: 3rem;
    padding: 0 1rem;
    color: $shell-header-text-01;
    background-color: $shell-header-bg-01;
    border: 4px solid $ibm-color__blue-60;
    outline: none;
    clip: auto;
  }
}

@include exports('carbon-header') {
  @if feature-flag-enabled('ui-shell') {
    @include carbon-header;
  }
}
