/*!
 * KoliBri - The accessible HTML-Standard
 */
import { r as registerInstance, h } from './index-Brmny3Vg.js';
import { e as watchBoolean, c as a11yHintLabelingLandmarks, j as devHint } from './common-DEEjER7G.js';
import { v as validateHideLabel } from './hide-label-CWFMK5Iz.js';
import { v as validateLabel } from './label-Cg7TG_7b.js';
import { c as KolLinkWcTag, b as KolButtonWcTag } from './component-names-Dy77vq43.js';
import { t as translate } from './i18n-CaL2ODdQ.js';
import { c as clsx } from './clsx-COFh-Vc8.js';
import { c as createUniqueId, a as createRelatedUniqueId } from './dev.utils-HhhlYW_9.js';
import { r as removeNavLabel, a as addNavLabel } from './unique-nav-labels-7ifGcuBZ.js';
import { w as watchNavLinks } from './validation-B8MhupBp.js';
import './i18n-B2d_exHc.js';

const validateCollapsible = (component, value) => {
    watchBoolean(component, '_collapsible', value);
};

const validateHasCompactButton = (component, value) => {
    watchBoolean(component, '_hasCompactButton', value);
};

const validateHasIconsWhenExpanded = (component, value) => {
    watchBoolean(component, '_hasIconsWhenExpanded', value);
};

const defaultStyleCss = "/* forward the rem function */\n/*\n* This file defines the layer order for all CSS layers used in KoliBri.\n* The order is important as it determines the cascade priority.\n*\n* Layer order (lowest to highest priority):\n* 1. kol-a11y - Accessibility defaults and requirements\n* 2. kol-global - Global component styles and resets\n* 3. kol-component - Component-specific styles\n* 4. kol-theme-global - Theme-specific global styles\n* 5. kol-theme-component - Theme-specific component styles\n*/\n@layer kol-a11y, kol-global, kol-component, kol-theme-global, kol-theme-component;\n/*\n * This file contains all rules for accessibility.\n */\n@layer kol-a11y {\n  :host {\n    /*\n                   * Minimum size of interactive elements.\n                   */\n    --a11y-min-size: calc(44 * 1rem / var(--kolibri-root-font-size, 16));\n    /*\n     * No element should be used without verifying the contrast ratio of its background and font colors.\n     * By initially setting the background color to white and the font color to black,\n     * the contrast ratio is ensured and explicit adjustment is forced.\n     */\n    color: black;\n    background-color: white;\n    /*\n     * Verdana is an accessible font that can be used without requiring additional loading time.\n     */\n    font-family: Verdana;\n    /*\n     * Letter spacing is required for all texts.\n     */\n    letter-spacing: inherit;\n    /*\n     * Word spacing is required for all texts.\n     */\n    word-spacing: inherit;\n    /*\n     * Text should be aligned left by default to provide a predictable starting point.\n     */\n    text-align: left;\n  }\n  * {\n    /*\n     * This rule enables the word dividing for all texts. That is important for high zoom levels.\n     */\n    hyphens: auto;\n    /*\n     * This rule enables the word dividing for all texts. That is important for high zoom levels.\n     */\n    word-break: break-word;\n  }\n  /*\n   * All interactive elements should have a minimum size of to-rem(44).\n   */\n  /* input:not([type='checkbox'], [type='radio'], [type='range']), */\n  /* option, */\n  /* select, */\n  /* textarea, */\n  button,\n  .kol-input .input {\n    min-width: var(--a11y-min-size);\n    min-height: var(--a11y-min-size);\n  }\n  /*\n   * Some interactive elements should not inherit the font-family and font-size.\n   */\n  a,\n  button,\n  h1,\n  h2,\n  h3,\n  h4,\n  h5,\n  h6,\n  input,\n  option,\n  select,\n  textarea {\n    /*\n     * All elements should inherit the text color from his parent element.\n     */\n    color: inherit;\n    /*\n     * All elements should inherit the font family from his parent element.\n     */\n    font-family: inherit;\n    /*\n     * All elements should inherit the font size from his parent element.\n     */\n    font-size: inherit;\n    /*\n     * Letter spacing is required for all texts.\n     */\n    letter-spacing: inherit;\n    /*\n     * Word spacing is required for all texts.\n     */\n    word-spacing: inherit;\n  }\n  /**\n  * Sometimes we need the semantic element for accessibility reasons,\n  * but we don't want to show it.\n  *\n  * - https://www.a11yproject.com/posts/how-to-hide-content/\n  */\n  .visually-hidden {\n    position: fixed;\n    top: 0;\n    left: 0;\n    width: 1px;\n    height: 1px;\n    overflow: hidden;\n    white-space: nowrap;\n    clip-path: inset(50%);\n  }\n}\n@layer kol-global {\n  /*\n   * Dieses CSS stellt sicher, dass der Standard-Style\n   * von A und Button resettet werden.\n   */\n  :is(a, button) {\n    background-color: transparent;\n    width: 100%;\n    margin: 0;\n    padding: 0;\n    border: none;\n    /* 100% needed for custom width from outside */\n  }\n  /*\n   * Ensure elements with hidden attribute to be actually not visible\n   * @see https://meowni.ca/hidden.is.a.lie.html\n   */\n  [hidden] {\n    display: none !important;\n  }\n  .badge-text-hint {\n    color: black;\n    background-color: white;\n  }\n}\n@layer kol-global {\n  :host {\n    /*\n     * The max-width is needed to prevent the table from overflowing the\n     * parent node, if the table is wider than the parent node.\n     */\n    max-width: 100%;\n    font-size: calc(16 * 1rem / var(--kolibri-root-font-size, 16));\n  }\n  * {\n    /*\n     * We prefer to box-sizing: border-box for all elements.\n     */\n    box-sizing: border-box;\n  }\n  .kol-span {\n    /* KolSpan is a layout component with icons in all directions and a label text in the middle. */\n    display: flex;\n    flex-flow: column;\n    align-items: center;\n    justify-content: center;\n    /* The sub span in KolSpan is the horizontal span with icon left and right and the label text in the middle. */\n  }\n  .kol-span__container {\n    display: flex;\n    align-items: center;\n  }\n  a,\n  button {\n    cursor: pointer;\n  }\n  .kol-span .kol-span__label--hide-label .kol-span__label {\n    display: none;\n  }\n  /* Reset browser agent style. */\n  button:disabled {\n    color: unset;\n  }\n  .disabled label,\n  .disabled:focus-within label,\n  [aria-disabled=true],\n  [aria-disabled=true]:focus,\n  [disabled],\n  [disabled]:focus {\n    outline: none;\n    cursor: not-allowed;\n  }\n  [aria-disabled=true]:focus .kol-span,\n  [disabled]:focus .kol-span {\n    outline: none !important;\n  }\n  .hastooltip {\n    z-index: 900 !important;\n  }\n}\n@font-face {\n  font-family: \"kolicons\";\n  src: url(\"kolicons.eot?t=1780914078349\"); /* IE9*/\n  src: url(\"kolicons.eot?t=1780914078349#iefix\") format(\"embedded-opentype\"), url(\"kolicons.woff2?t=1780914078349\") format(\"woff2\"), url(\"kolicons.woff?t=1780914078349\") format(\"woff\"), url(\"kolicons.ttf?t=1780914078349\") format(\"truetype\"), url(\"kolicons.svg?t=1780914078349#kolicons\") format(\"svg\"); /* iOS 4.1- */\n}\n@layer kol-component {\n  [class^=kolicon-], [class*=\" kolicon-\"] {\n    font-family: \"kolicons\";\n    font-style: normal;\n    font-weight: 400;\n    line-height: 1em;\n    -webkit-font-smoothing: antialiased;\n    -moz-osx-font-smoothing: grayscale;\n  }\n  .kolicon-alert-error::before {\n    content: \"\\ea01\";\n  }\n  .kolicon-alert-info::before {\n    content: \"\\ea02\";\n  }\n  .kolicon-alert-success::before {\n    content: \"\\ea03\";\n  }\n  .kolicon-alert-warning::before {\n    content: \"\\ea04\";\n  }\n  .kolicon-check::before {\n    content: \"\\ea05\";\n  }\n  .kolicon-chevron-double-left::before {\n    content: \"\\ea06\";\n  }\n  .kolicon-chevron-double-right::before {\n    content: \"\\ea07\";\n  }\n  .kolicon-chevron-down::before {\n    content: \"\\ea08\";\n  }\n  .kolicon-chevron-left::before {\n    content: \"\\ea09\";\n  }\n  .kolicon-chevron-right::before {\n    content: \"\\ea0a\";\n  }\n  .kolicon-chevron-up::before {\n    content: \"\\ea0b\";\n  }\n  .kolicon-cogwheel::before {\n    content: \"\\ea0c\";\n  }\n  .kolicon-cross::before {\n    content: \"\\ea0d\";\n  }\n  .kolicon-eye-closed::before {\n    content: \"\\ea0e\";\n  }\n  .kolicon-eye::before {\n    content: \"\\ea0f\";\n  }\n  .kolicon-house::before {\n    content: \"\\ea10\";\n  }\n  .kolicon-kolibri::before {\n    content: \"\\ea11\";\n  }\n  .kolicon-link-external::before {\n    content: \"\\ea12\";\n  }\n  .kolicon-link::before {\n    content: \"\\ea13\";\n  }\n  .kolicon-minus::before {\n    content: \"\\ea14\";\n  }\n  .kolicon-plus::before {\n    content: \"\\ea15\";\n  }\n  .kolicon-settings::before {\n    content: \"\\ea16\";\n  }\n  .kolicon-sort-asc::before {\n    content: \"\\ea17\";\n  }\n  .kolicon-sort-desc::before {\n    content: \"\\ea18\";\n  }\n  .kolicon-sort-neutral::before {\n    content: \"\\ea19\";\n  }\n  .kolicon-up::before {\n    content: \"\\ea1a\";\n  }\n  .kolicon-version::before {\n    content: \"\\ea1b\";\n  }\n}\n@layer kol-component {\n  .kol-icon {\n    color: inherit;\n    display: inline-block;\n    font-size: inherit;\n    font-weight: inherit;\n    line-height: inherit;\n  }\n  .kol-tooltip {\n    display: contents;\n  }\n  .kol-tooltip__floating {\n    opacity: 0;\n    display: none;\n    position: fixed;\n    /* Avoid layout interference - see https://floating-ui.com/docs/computePosition */\n    top: 0;\n    left: 0;\n    /* Can be used to specify the tooltip-width from the outside. Unset by default.  */\n    width: var(--kol-tooltip-width, max-content);\n    min-width: calc(8 * 1rem / var(--kolibri-root-font-size, 16));\n    max-width: 90vw;\n    max-height: 90vh;\n    animation-direction: normal;\n    /* Can be used to specify the animation duration from the outside. 250ms by default. */\n    animation-duration: var(--kolibri-tooltip-animation-duration, 250ms);\n    animation-fill-mode: forwards;\n    animation-iteration-count: 1;\n    animation-timing-function: ease-in;\n  }\n  .kol-tooltip__floating.hide {\n    animation-name: hideTooltip;\n  }\n  .kol-tooltip__floating.show {\n    animation-name: showTooltip;\n  }\n  .kol-tooltip__arrow {\n    transform: rotate(45deg);\n    color: black;\n    background-color: white;\n    position: absolute;\n    z-index: 999;\n    width: calc(10 * 1rem / var(--kolibri-root-font-size, 16));\n    height: calc(10 * 1rem / var(--kolibri-root-font-size, 16));\n  }\n  .kol-tooltip__content {\n    color: black;\n    background-color: white;\n    position: relative;\n    z-index: 1000;\n  }\n  @keyframes hideTooltip {\n    0% {\n      opacity: 1;\n    }\n    100% {\n      opacity: 0;\n      display: none;\n    }\n  }\n  @keyframes showTooltip {\n    0% {\n      opacity: 0;\n    }\n    100% {\n      opacity: 1;\n    }\n  }\n}\n@layer kol-component {\n  .kol-icon {\n    color: inherit;\n    display: inline-block;\n    font-size: inherit;\n    font-weight: inherit;\n    line-height: inherit;\n  }\n  .kol-nav {\n    display: grid;\n    place-items: center;\n  }\n  .kol-nav:not(.kol-nav--is-compact) .kol-nav__navigation {\n    width: 100%;\n  }\n  .kol-nav__navigation .kol-span {\n    width: 100%;\n    justify-content: flex-start;\n  }\n  .kol-nav__navigation .kol-span__container {\n    width: 100%;\n  }\n  .kol-nav__navigation .kol-span__container .kol-span__label {\n    flex: 1;\n  }\n  .kol-nav__list {\n    display: flex;\n    margin: 0;\n    padding: 0;\n    flex-direction: column;\n    list-style: none;\n  }\n  .kol-nav__entry-wrapper {\n    display: flex;\n  }\n  .kol-nav__entry {\n    flex-grow: 1;\n  }\n  .kol-button {\n    text-align: left;\n  }\n}";

const entryIsLink = (entryProps) => {
    return typeof entryProps._href === 'string';
};
const entryIsButton = (entryProps) => {
    var _a;
    return entryProps._href === undefined && typeof ((_a = entryProps._on) === null || _a === void 0 ? void 0 : _a.onClick) === 'function';
};
const KolNav = class {
    constructor(hostRef) {
        registerInstance(this, hostRef);
        this.navId = createUniqueId('kol-nav');
        this.listId = createRelatedUniqueId(this.navId, 'list');
        this.handleToggleExpansionClick = (children) => {
            if (children) {
                if (this.state._expandedChildren.includes(children)) {
                    this.collapseChildren(children);
                }
                else {
                    this.expandChildren(children);
                }
            }
        };
        this.linkList = (props) => {
            return (h("ul", { class: clsx('kol-nav__list', {
                    'kol-nav__list--nested': props.deep > 0,
                    'kol-nav__list--vertical': props.deep !== 0,
                }), id: props.deep > 0 ? props.id : undefined }, props.links.map((link, index) => {
                return this.li(props.collapsible, props.deep, index, link, props.id);
            })));
        };
        this._collapsible = true;
        this._hasCompactButton = false;
        this._hasIconsWhenExpanded = false;
        this._hideLabel = false;
        this.state = {
            _collapsible: true,
            _hasCompactButton: false,
            _hasIconsWhenExpanded: false,
            _hideLabel: false,
            _label: '',
            _links: [],
            _expandedChildren: [],
        };
    }
    expandChildren(children) {
        this.state = Object.assign(Object.assign({}, this.state), { _expandedChildren: [...this.state._expandedChildren, children] });
    }
    collapseChildren(children) {
        this.state = Object.assign(Object.assign({}, this.state), { _expandedChildren: this.state._expandedChildren.filter((searchChildren) => searchChildren !== children) });
    }
    buildIconObject(collapsible, expanded, leftIcon) {
        const icon = {
            left: '',
            right: '',
        };
        if (this.state._hasIconsWhenExpanded && leftIcon) {
            icon.left = leftIcon;
        }
        if (this.state._hideLabel) {
            if (leftIcon) {
                icon.left = leftIcon;
            }
            else {
                icon.left = 'kolicon-link';
            }
        }
        if (collapsible) {
            if (expanded) {
                icon.right = 'kolicon-minus';
            }
            else {
                icon.right = 'kolicon-plus';
            }
        }
        return icon;
    }
    entry(collapsible, hasChildren, entry, expanded, ariaID) {
        var _a;
        const leftIcon = typeof entry._icons === 'string' ? entry._icons : typeof ((_a = entry._icons) === null || _a === void 0 ? void 0 : _a.left) === 'string' ? entry._icons.left : undefined;
        const icons = this.buildIconObject(collapsible && hasChildren, expanded, leftIcon);
        return (h("div", { class: "kol-nav__entry-wrapper" }, entryIsLink(entry) ? (h(KolLinkWcTag, Object.assign({ class: clsx('kol-nav__entry kol-nav__entry--link', {
                'kol-nav__entry--collapsible': collapsible,
            }) }, entry, { _hideLabel: this.state._hideLabel, _icons: icons, _ariaControls: collapsible && hasChildren && expanded ? ariaID : undefined, _ariaExpanded: collapsible && hasChildren ? expanded : undefined }))) : (h(KolButtonWcTag, { class: clsx('kol-nav__entry kol-nav__entry--button', {
                'kol-nav__entry--collapsible': collapsible,
            }), _label: entry._label, _hideLabel: this.state._hideLabel, _icons: icons, _ariaControls: collapsible && hasChildren && expanded ? ariaID : undefined, _ariaExpanded: collapsible && hasChildren ? expanded : undefined, _on: {
                onClick: (event, value) => {
                    if (entryIsButton(entry) && typeof entry._on.onClick === 'function') {
                        entry._on.onClick(event, value);
                    }
                    this.handleToggleExpansionClick(entry._children);
                },
            } }))));
    }
    li(collapsible, deep, index, link, ariaIDparent) {
        const active = !!link._active;
        const hasChildren = Array.isArray(link._children) && link._children.length > 0;
        const expanded = Boolean(link._children && this.state._expandedChildren.includes(link._children));
        const ariaID = createRelatedUniqueId(ariaIDparent, `${deep}-${index}`);
        return (h("li", { class: clsx('kol-nav__list-item', {
                'kol-nav__list-item--active': active,
                'kol-nav__list-item--expanded': expanded,
                'kol-nav__list-item--has-children': hasChildren,
            }), key: index }, this.entry(collapsible, hasChildren, link, expanded, ariaID), expanded && h(this.linkList, { collapsible: collapsible, deep: deep + 1, links: link._children || [], id: ariaID })));
    }
    initializeExpandedChildren() {
        this.state = Object.assign(Object.assign({}, this.state), { _expandedChildren: [] });
        const handleBranch = (branch) => {
            if (branch._active) {
                if (branch._children) {
                    this.expandChildren(branch._children);
                }
                return true;
            }
            else if (branch._children) {
                for (const childBranch of branch._children) {
                    if (handleBranch(childBranch)) {
                        this.expandChildren(branch._children);
                        return true;
                    }
                }
            }
            return false;
        };
        this.state._links.forEach(handleBranch);
    }
    render() {
        const collapsible = this.state._collapsible === true;
        return (h("div", { key: '168e77bd4e310d31ec72afcc5dc4633df3a5852c', class: clsx('kol-nav', {
                'kol-nav--is-compact': this.state._hideLabel,
            }) }, h("nav", { key: 'd27ea32253853f5ab13df4cceec8245a69564179', "aria-label": this.state._label, class: "kol-nav__navigation", id: this.navId }, h(this.linkList, { key: '43080dfc66978e4161adb904094f8b7a4585798c', collapsible: collapsible, deep: 0, links: this.state._links, id: this.listId })), this.state._hasCompactButton && (h("div", { key: '917c25c8c29c3f980dd95c19cac2b3857c9f06fd', class: "kol-nav__compact" }, h(KolButtonWcTag, { key: 'c08ed259ed0721edaa769a44e7b9b96c50091f30', class: "kol-nav__toggle-button", _ariaControls: this.navId, _ariaExpanded: !this.state._hideLabel, _icons: this.state._hideLabel ? 'kolicon-chevron-right' : 'kolicon-chevron-left', _hideLabel: true, _label: translate(this.state._hideLabel ? 'kol-nav-maximize' : 'kol-nav-minimize'), _on: {
                onClick: () => {
                    this.state = Object.assign(Object.assign({}, this.state), { _hideLabel: !this.state._hideLabel });
                },
            }, _tooltipAlign: "right" })))));
    }
    validateCollapsible(value) {
        validateCollapsible(this, value);
    }
    validateHasCompactButton(value) {
        validateHasCompactButton(this, value);
    }
    validateHasIconsWhenExpanded(value) {
        validateHasIconsWhenExpanded(this, value);
    }
    validateHideLabel(value) {
        validateHideLabel(this, value);
    }
    validateLabel(value, _oldValue, initial = false) {
        if (!initial) {
            removeNavLabel(this.state._label);
        }
        validateLabel(this, value, {
            required: true,
        });
        a11yHintLabelingLandmarks(value);
        addNavLabel(this.state._label);
    }
    validateLinks(value) {
        watchNavLinks('KolNav', this, value);
        devHint(`[KolNav] The navigation structure is not yet validated recursively.`);
        this.initializeExpandedChildren();
    }
    componentWillLoad() {
        this.validateCollapsible(this._collapsible);
        this.validateHideLabel(this._hideLabel);
        this.validateHasCompactButton(this._hasCompactButton);
        this.validateHasIconsWhenExpanded(this._hasIconsWhenExpanded);
        this.validateLabel(this._label, undefined, true);
        this.validateLinks(this._links);
        this.initializeExpandedChildren();
    }
    disconnectedCallback() {
        removeNavLabel(this.state._label);
    }
    static get watchers() { return {
        "_collapsible": ["validateCollapsible"],
        "_hasCompactButton": ["validateHasCompactButton"],
        "_hasIconsWhenExpanded": ["validateHasIconsWhenExpanded"],
        "_hideLabel": ["validateHideLabel"],
        "_label": ["validateLabel"],
        "_links": ["validateLinks"]
    }; }
};
KolNav.style = {
    default: defaultStyleCss
};

export { KolNav as kol_nav };
//# sourceMappingURL=kol-nav.entry.js.map
