@use '../../mixins/media';
@use '../../functions/tokens';
@use '../../tokens/components';

@use './mixins' as *;
@use './placeholders' as *;

body:has(post-header) {
  scroll-padding-top: var(--post-header-height);
}

[data-post-scroll-locked] {
  overflow: hidden !important;
}

// Added to prevent Back-to-top button from showing up before header is hydrated
body:has(post-header:not([data-hydrated])) post-back-to-top {
  visibility: hidden !important;
}

post-header {
  &:not(:defined),
  &:not([data-hydrated]) {
    display: block;
    height: var(--post-header-height);
  }

  // all header lists
  > ul {
    @extend %header-list;
  }

  // all slotted links and buttons
  > * {
    @include interactive-elements {
      @extend %header-control;
    }
  }

  // links and buttons remaining in the global and local headers on tablet and mobile
  > :is([slot='global-nav-primary'], [slot='post-login'], [slot='local-nav']) {
    @include media.max(desktop) {
      flex-direction: row;
    }

    @include media.only(mobile) {
      @include interactive-elements {
        @include nav-item-icon-only;
      }
    }
  }

  // links and buttons remaining in the global header on tablet and mobile
  > :is([slot='global-nav-primary'], [slot='post-login']) {
    @include media.only(mobile) {
      @include interactive-elements {
        padding: 10px;
      }
    }
  }

  // links and buttons in the local header
  > [slot='local-nav'] {
    grid-area: local-nav;

    &:where(ul) {
      align-items: center;
    }
  }

  // audience
  > [slot='audience'] {
    &:where(ul) {
      @include media.only(tablet) {
        flex-direction: row;
        margin-block: 16px;
      }

      @include media.only(mobile) {
        gap: 8px;
      }
    }

    @include interactive-elements {
      padding-inline: 16px;
    }
  }

  // meta navigation on desktop
  > [slot='global-nav-secondary'] {
    @include media.max(desktop) {
      &:where(ul) {
        flex-direction: column;
      }

      @include interactive-elements {
        flex-direction: row-reverse;
        @include nav-item-block-layout;

        > post-icon {
          margin: unset;
        }
      }
    }
  }

  // title
  [slot='title'] {
    grid-area: title;
    flex-grow: 1;
    margin: 0;
    font-size: 1.25rem;
    font-weight: 950;

    @include media.only(desktop) {
      font-size: 1.75rem;
      line-height: 34px;
    }
  }

  // side navigation trigger
  > [slot='side-nav'] {
    grid-area: side-nav;
    flex-shrink: 0;

    @include media.only(desktop) {
      display: none;
    }

    > button {
      @include nav-item-base;

      @include media.only(mobile) {
        @include nav-item-icon-only;
        padding: 10px;
      }
    }
  }

  .local-login {
    margin-block: -4px;
  }

  // language menu
  &:has(post-mainnavigation) post-language-menu[variant='menu'] {
    @include media.max(desktop) {
      display: none;
    }
  }
}
