import templateOnly from '@ember/component/template-only';
import { setComponentTemplate } from '@ember/component';
import { precompileTemplate } from '@ember/template-compilation';
import { modifier } from 'ember-modifier';
import argOrDefault from '../helpers/arg-or-default.js';
import classNames from '../helpers/class-names.js';
import EuiHeaderBreadcrumbs from './eui-header-breadcrumbs.js';
import EuiHeaderSection from './eui-header-section.js';
import EuiHeaderSectionItem from './eui-header-section-item.js';

let euiHeaderFixedCounter = 0;
const fixedHeaderModifier = modifier(function fixedHeader(_, [position]) {
  if (position === 'fixed') {
    // Increment fixed header counter for each fixed header
    euiHeaderFixedCounter++;
    document.body.classList.add('euiBody--headerIsFixed');
    return () => {
      // Both decrement the fixed counter AND then check if there are none
      if (--euiHeaderFixedCounter === 0) {
        // If there are none, THEN remove class
        document.body.classList.remove('euiBody--headerIsFixed');
      }
    };
  }
});
const EuiHeader = setComponentTemplate(precompileTemplate(`
  <div
    {{fixedHeaderModifier @position}}
    class={{classNames
      componentName="EuiHeader"
      theme=(argOrDefault @theme "default")
      position=(argOrDefault @position "static")
    }}
    ...attributes
  >
    {{#if @sections}}
      {{#each @sections as |section|}}
        {{#each section.items as |itemSection|}}
          <EuiHeaderSection>
            <EuiHeaderSectionItem @border={{section.border}}>
              {{itemSection.text}}
            </EuiHeaderSectionItem>
          </EuiHeaderSection>
        {{/each}}
        <EuiHeaderBreadcrumbs @breadcrumbs={{section.breadcrumbs}} />
      {{/each}}
    {{else}}
      {{yield}}
    {{/if}}
  </div>
`, {
  strictMode: true,
  scope: () => ({
    classNames,
    argOrDefault,
    fixedHeaderModifier,
    EuiHeaderSection,
    EuiHeaderSectionItem,
    EuiHeaderBreadcrumbs
  })
}), templateOnly("eui-header", "EuiHeader"));

export { EuiHeader as default };
//# sourceMappingURL=eui-header.js.map
