/**
 * Site Header EC
 * @define site-header
 */

@use 'sass:map';
@use '@ecl/vanilla-layout-grid/mixins/breakpoints';

// Exposed variables
$theme: null !default;
$site-header: null !default;
$language-list: null !default;

@use 'site-header-dropdown' with (
  $theme: $theme,
  $language-switcher: map.get($site-header, 'language-switcher'),
  $language-list: $language-list
);

.ecl-site-header {
  margin: 0;
  position: relative;
  z-index: map.get($theme, 'z-index', 'modal');

  .ecl-site-header__inner {
    box-shadow: var(--sh-6);
  }

  .ecl-site-header__background {
    background-color: map.get($site-header, 'background-color');
    background-image: url('data:image/svg+xml;base64,' + map.get(
        $site-header,
        'background-image'
      ));
    background-position: right bottom;
    background-repeat: no-repeat;
    background-size: auto 100%;
  }

  &.ecl-site-header--rtl .ecl-site-header__background {
    background-position: left bottom;
  }

  .ecl-menu,
  .ecl-mega-menu {
    bottom: 0;
    padding: 0;
    position: absolute;
    right: 0;
    width: 100%;
  }

  .ecl-menu__open,
  .ecl-mega-menu__open {
    position: relative;
    top: calc(-1 * var(--s-2xs));
    z-index: 54;
  }

  .ecl-mega-menu--rtl .ecl-mega-menu__open {
    margin-inline-start: var(--s-m);
  }

  .ecl-site-header__cta {
    margin-top: var(--s-s);
    position: relative;
    width: max-content;
    z-index: 1;
  }

  .ecl-site-header__cta:only-child {
    margin-top: 0;
  }
}

.ecl-site-header__header {
  box-shadow: var(--sh-6);
  position: relative;
  z-index: 54;
}

.ecl-site-header__container {
  display: flex;
  flex-direction: column;
  padding-bottom: var(--s-m);
  padding-top: var(--s-m);
  position: static;
}

.ecl-site-header__top {
  align-items: center;
  display: flex;
  flex-grow: 1;
  justify-content: space-between;
}

.ecl-site-header__logo-image {
  display: block;
  height: map.get($site-header, 'logo-height-xs');
}

.ecl-site-header__logo-link {
  z-index: map.get($theme, 'z-index', 'modal') + 2;
}

.ecl-search-form__button {
  color: map.get($site-header, 'toggle-color');

  &:hover {
    border-left: none;
    color: var(--c-d);
  }

  &:focus-visible {
    color: var(--c-d);
  }

  &:active {
    background-color: var(--c-n);
  }
}

.ecl-site-header__action {
  align-self: flex-end;
  display: flex;
  padding-bottom: var(--s-2xs);

  .ecl-button {
    box-sizing: border-box;
    margin-inline-start: var(--s-2xs);
  }

  > :first-child .ecl-button,
  .ecl-search-form__button {
    margin-inline-start: 0;
  }

  .ecl-site-header--has-menu &,
  .ecl-site-header--has-mega-menu & {
    margin-inline-end: calc(44px + var(--s-2xs));
  }
}

.ecl-site-header__language-selector {
  text-transform: uppercase;
}

.ecl-site-header__custom-action-toggle,
.ecl-site-header__login-toggle,
.ecl-site-header__search-toggle,
.ecl-site-header__language-selector {
  align-items: center;
  box-sizing: border-box;
  color: map.get($site-header, 'toggle-color');
  display: flex;
  flex-direction: column;
  margin-inline-start: var(--s-xs);
  position: relative;
  z-index: map.get($theme, 'z-index', 'modal') + 2;

  &:focus-visible {
    color: map.get($site-header, 'toggle-color');
  }

  &:active,
  &[aria-expanded='true'] {
    background-color: var(--c-n-80);
  }
}

.ecl-site-header__custom-action-toggle {
  &:hover {
    text-decoration: none;
    color: map.get($site-header, 'toggle-color');
  }

  .ecl-link__icon-container {
    .ecl-site-header__icon {
      margin-inline-end: 0;
    }
  }

  .ecl-indicator:not(:empty) {
    left: -18px;
    right: auto;
  }
}

.ecl-site-header__login-box,
.ecl-site-header__search {
  background-color: map.get($theme, 'color', 'white');
  box-shadow: var(--sh-12);
  box-sizing: border-box;
  color: var(--c-d);
  display: none;
  font: var(--f-m);
  left: 0;
  margin-top: var(--s-l);
  padding: var(--s-3xl) var(--s-m);
  position: absolute;
  z-index: map.get($theme, 'z-index', 'modal') + 1;
}

.ecl-site-header__login-box {
  border-radius: map.get($theme, 'border-radius', 's');
  box-sizing: border-box;
  left: 0;
  width: 100%;

  &::before {
    @include site-header-dropdown.arrow-up;

    left: auto;
    right: var(--ecl-login-arrow-position);
  }

  &.ecl-site-header__login-box--active {
    display: block;
  }
}

.ecl-site-header__login-description {
  margin: 0;
  max-width: var(--max-w);
}

.ecl-site-header__login-separator {
  background-color: var(--c-n);
  border-width: 0;
  height: 1px;
  margin-bottom: var(--s-m);
  margin-top: var(--s-m);
}

.ecl-site-header__custom-action-icon,
.ecl-site-header__language-icon {
  align-items: center;
  display: flex;
  justify-content: center;
  position: relative;
}

.ecl-site-header__search--active {
  display: flex;

  &::before {
    @include site-header-dropdown.arrow-up;

    left: auto;
    right: var(--ecl-search-arrow-position);
  }
}

.ecl-site-header__notification {
  background-color: var(--c-bg);
  border-top: 1px solid var(--c-n-60);
  display: flex;

  .ecl-notification {
    background: map.get($theme, 'color', 'white');
    margin: var(--s-xl) 0;
  }
}

.ecl-site-header__banner-top {
  background: var(--c-n-40);
  border-top: 1px solid var(--c-n);
  font: var(--f-m);
  padding: var(--s-xs) 0;
}

.ecl-site-header__banner {
  background-color: map.get($site-header, 'banner-background');
  color: map.get($site-header, 'banner-text-color');
  display: block;
  font: var(--f-l);
  min-height: 1.75rem;
  padding: var(--s-m) 0;

  .ecl-container {
    display: flex;
    flex-direction: column;
  }
}

.ecl-site-header__site-name {
  margin-inline-end: var(--s-3xl);
}

// Menu display and position
$menu-top: calc(44px + 2 * var(--s-xs));

// stylelint-disable-next-line no-duplicate-selectors
.ecl-site-header .ecl-menu,
.ecl-site-header .ecl-mega-menu {
  bottom: auto;
  padding: 0;
  position: absolute;
  right: 0;
  top: 2.5rem;
  width: calc(44px + var(--s-m) * 2);
}

.ecl-site-header .ecl-mega-menu {
  right: calc(-1 * var(--s-xs));
}

.ecl-site-header .ecl-mega-menu--rtl,
.ecl-site-header .ecl-menu--rtl {
  left: 0;
  right: auto;
}

.ecl-site-header .ecl-menu__overlay,
.ecl-site-header .ecl-menu__inner,
.ecl-site-header .ecl-mega-menu__overlay,
.ecl-site-header .ecl-mega-menu__inner {
  top: $menu-top;
}

@include breakpoints.down('m') {
  .ecl-site-header__custom-action-toggle,
  .ecl-site-header__login-toggle,
  .ecl-site-header__search-toggle,
  .ecl-site-header__language-selector {
    align-items: center;
    display: flex;
    font-size: 0;
    justify-content: center;
    line-height: 0;
    padding: var(--s-xs) 0;

    .ecl-link__icon-container {
      margin-inline-start: 0;
    }

    .ecl-icon {
      width: 1.5rem;
      height: 1.5rem;
    }
  }
}

@include breakpoints.up('m') {
  .ecl-site-header__logo-link {
    margin-top: 0;
  }
  /* stylelint-disable-next-line plugin/selector-bem-pattern */
  .ecl-site-header {
    .ecl-search-form__text-input {
      width: map.get($site-header, 'search-width');
    }

    .ecl-search-form {
      max-width: 100%;
    }
  }
}

@include breakpoints.up('l') {
  .ecl-site-header {
    box-shadow: var(--sh-6);

    .ecl-site-header__cta {
      align-self: center;
      margin: 0;

      &:only-child {
        margin: var(--s-xs) 0;
      }
    }

    .ecl-menu {
      position: static;
      width: 100%;

      .ecl-menu__mega {
        box-shadow: var(--sh-6);
      }
    }

    .ecl-mega-menu {
      position: relative;
      right: 0;
      top: 0;
      width: 100%;
    }

    .ecl-menu__overlay,
    .ecl-menu__inner,
    .ecl-mega-menu__overlay,
    .ecl-mega-menu__inner {
      top: 0;
    }
  }

  .ecl-site-header__container {
    align-items: flex-end;
    flex-direction: row;
    padding-bottom: var(--s-xl);
    padding-top: var(--s-2xl);
  }

  .ecl-site-header__header {
    box-shadow: none;
  }

  .ecl-site-header__site-name {
    align-self: center;
    flex-grow: 1;
    margin-inline-end: 0;
    padding: var(--s-m) 0;
  }

  .ecl-site-header__top {
    align-items: flex-end;
  }

  .ecl-site-header__action {
    align-items: center;

    .ecl-button--icon-only .ecl-button__icon {
      height: map.get($theme, 'icon', 'xs');
      width: map.get($theme, 'icon', 'xs');
    }
  }

  .ecl-site-header--has-menu,
  .ecl-site-header--has-mega-menu {
    .ecl-site-header__action {
      margin-inline-end: 0;
    }
  }

  .ecl-site-header__logo-link {
    margin-bottom: 0;
  }

  .ecl-site-header__search--active::before {
    display: none;
  }

  .ecl-site-header__logo-image--s {
    height: map.get($site-header, 'logo-height-lg-s');
  }

  .ecl-site-header__logo-image--m {
    height: map.get($site-header, 'logo-height-lg-m');
  }

  .ecl-site-header__logo-image--l {
    height: map.get($site-header, 'logo-height-lg-l');
  }

  .ecl-site-header__login-container {
    position: relative;
  }

  .ecl-site-header__login-box {
    left: 50%;
    margin-top: var(--s-l);
    min-width: 22rem;
    padding: var(--s-3xl);
    transform: translateX(-50%);
    width: auto;

    &::before {
      left: 50%;
    }
  }

  .ecl-site-header__custom-action-toggle,
  .ecl-site-header__login-toggle,
  .ecl-site-header__language-selector {
    align-items: center;
    display: flex;
    flex-direction: row;
    font: var(--f-m);

    .ecl-site-header__icon {
      flex-shrink: 0;
      height: 1rem;
      margin-inline-end: var(--s-xs);
      width: 1rem;
    }
  }

  .ecl-site-header__search-toggle {
    display: none;
  }

  .ecl-site-header__language-code {
    font: var(--f-xs);
    margin-inline-end: var(--s-xs);
    transform: translateX(-50%) translateX(-0.22rem) translateY(-50%)
      translateY(-0.08rem);
  }

  .ecl-site-header__search-container {
    flex-grow: 1;
    margin-inline-start: var(--s-xl);

    .ecl-search-form__button {
      min-width: 100px;
      color: map.get($site-header, 'toggle-color');
    }

    .ecl-search-form__text-input {
      width: map.get($site-header, 'search-width-l');
    }
  }

  .ecl-site-header__search {
    background-color: map.get($theme, 'color', 'white');
    border-width: 0;
    box-shadow: none;
    display: flex;
    margin: 0;
    padding: 0;
    position: relative;
    top: 0;
  }

  .ecl-site-header__banner {
    box-shadow: none;
    font: var(--f-l);
    min-height: 0;
    padding: 0;

    .ecl-container {
      flex-direction: row;
    }
  }
}

@include breakpoints.up('xl') {
  .ecl-site-header__action .ecl-search-form__text-input {
    width: map.get($site-header, 'search-width-xl');
  }
}
