'use strict';

var index = require('./index-BEF5cZxd.js');
var wcag = require('./wcag-Bvzxnp5D.js');
var gov_log = require('./gov.log-C5EH15b_.js');
var template = require('./template-Cj6PcLmR.js');
var stencil_utils = require('./stencil.utils-8sCYbm34.js');
require('./string.utils-BG4pUfEi.js');
require('./helpers.types-vap8QfRH.js');
require('./utils-NnC78QR3.js');

const BreadcrumbsClass = {
    root: 'gov-breadcrumbs',
};

const GovBreadcrumbs = class {
    constructor(hostRef) {
        index.registerInstance(this, hostRef);
        this.govChange = index.createEvent(this, "gov-change");
        this.inited = false;
        /**
         * Defines whether the components can be collapsible when element doesn't fit in one row.
         */
        this.collapsible = false;
        /**
         * Defines whether the breadcrumbs are open or closed by button
         */
        this.isExpanded = false;
        /**
         * Adds an accessible label to display the full breadcrumb navigation that only screen readers can see.
         */
        this.accessibleToggleLabel = 'Zobrazit či skrýt navigaci';
        this.expanded = false;
        this.toggleOption = false;
        this.h = template.govHost(this.host);
    }
    async componentDidRender() {
        this.scheduleContentVerification();
        if (gov_log.canValidateWcagOnRender()) {
            stencil_utils.tick(() => this.validateAccessibility());
        }
    }
    scheduleContentVerification() {
        if (this.inited)
            return;
        this.inited = true;
        stencil_utils.tick(() => {
            this.calculateWidthOfItems();
            this.inited = false;
        });
    }
    calculateWidthOfItems() {
        const hostWidth = this.host.getBoundingClientRect().width;
        let sumOfWidths = 0;
        this.host.querySelectorAll('li').forEach((li) => {
            sumOfWidths += li.getBoundingClientRect().width;
        });
        this.toggleOption = sumOfWidths > hostWidth;
    }
    render() {
        return (index.h(index.Host, { key: '5a2d10c3705a0d19458ea76e65ab6e0449eb620d', class: this.h.classes(BreadcrumbsClass.root), expanded: this.expanded }, index.h("nav", { key: '41b98c6ee95ea397f9802f5ac120d2674859cb4d', "aria-label": this.accessibleLabel, "aria-labelledby": this.accessibleLabelledBy }, index.h("slot", { key: '10fed9d58caa49017c34665e4b711252854040b7' })), this.toggleOption ? (index.h("gov-button", { size: 'xs', color: 'primary', type: 'base', "aria-label": this.accessibleToggleLabel, "aria-pressed": this.expanded, "aria-expanded": this.expanded, "on-gov-click": () => this.expanded = !this.expanded }, index.h("gov-icon", { name: this.expanded ? 'chevron-up' : 'chevron-down', type: "components" }))) : null));
    }
    /**
     * Validate the WCAG attributes of the component
     */
    async validateAccessibility() {
        wcag.validateAccessibleLabel(this.accessibleLabel, this.accessibleLabelledBy, BreadcrumbsClass.root, this.host);
        wcag.validateAccessibleLabel(this.accessibleToggleLabel, undefined, BreadcrumbsClass.root, this.host);
    }
    get host() { return index.getElement(this); }
};

exports.gov_breadcrumbs = GovBreadcrumbs;
//# sourceMappingURL=gov-breadcrumbs.entry.cjs.js.map

//# sourceMappingURL=gov-breadcrumbs.cjs.entry.js.map