import { waitForUpdatesAsync } from '../../testing/async-helpers';
import { waitTimeout } from '../../utilities/testing/component';
import { breadcrumbItemTag } from '../../breadcrumb-item';
/**
 * Page object for the `nimble-breadcrumb`
 */
export class BreadcrumbPageObject {
    constructor(breadcrumbElement) {
        this.breadcrumbElement = breadcrumbElement;
    }
    async clickBreadcrumb(index) {
        if (index >= this.breadcrumbElement.slottedBreadcrumbItems.length) {
            throw new Error(`Breadcrumb with index ${index} not found`);
        }
        this.breadcrumbElement.slottedBreadcrumbItems[index].click();
        await waitForUpdatesAsync();
    }
    async pressKeyOnBreadcrumb(index, key) {
        if (index >= this.breadcrumbElement.slottedBreadcrumbItems.length) {
            throw new Error(`Breadcrumb with index ${index} not found`);
        }
        const breadcrumb = this.breadcrumbElement.slottedBreadcrumbItems[index];
        breadcrumb.dispatchEvent(new KeyboardEvent('keydown', { key }));
        await waitForUpdatesAsync();
    }
    async setBreadcrumbWidth(width) {
        this.breadcrumbElement.style.width = `${width}px`;
        await waitForUpdatesAsync();
        await waitForUpdatesAsync(); // wait for the resize observer to fire
    }
    async clickScrollLeftButton() {
        const leftButton = this.breadcrumbElement.shadowRoot.querySelector('.scroll-button.left');
        if (!leftButton) {
            throw new Error('Scroll left button not found');
        }
        leftButton.click();
        await waitForUpdatesAsync();
        await waitTimeout(50); // let animation run
    }
    async clickScrollRightButton() {
        const rightButton = this.breadcrumbElement.shadowRoot.querySelector('.scroll-button.right');
        if (!rightButton) {
            throw new Error('Scroll right button not found');
        }
        rightButton.click();
        await waitForUpdatesAsync();
        await waitTimeout(50); // let animation run
    }
    areScrollButtonsVisible() {
        return (this.breadcrumbElement.shadowRoot.querySelectorAll('.scroll-button').length > 0);
    }
    async addBreadcrumbItem(label) {
        const breadcrumbItem = document.createElement(breadcrumbItemTag);
        breadcrumbItem.textContent = label;
        const lastBreadcrumbItem = this.breadcrumbElement.querySelector(`${breadcrumbItemTag}:last-of-type`);
        lastBreadcrumbItem.insertAdjacentElement('afterend', breadcrumbItem);
        await waitForUpdatesAsync();
    }
    async removeBreadcrumbItemByIndex(index) {
        if (index >= this.breadcrumbElement.slottedBreadcrumbItems.length) {
            throw new Error(`Breadcrumb item with index ${index} not found`);
        }
        const breadcrumbItemToRemove = this.breadcrumbElement.slottedBreadcrumbItems[index];
        breadcrumbItemToRemove?.remove();
        await waitForUpdatesAsync();
    }
    async updateBreadcrumbItemLabel(index, label) {
        if (index >= this.breadcrumbElement.slottedBreadcrumbItems.length) {
            throw new Error(`Breadcrumb item with index ${index} not found`);
        }
        const breadcrumb = this.breadcrumbElement.slottedBreadcrumbItems[index];
        breadcrumb.textContent = label;
        await waitForUpdatesAsync();
    }
    async scrollBreadcrumbItemIntoViewByIndex(index) {
        if (index >= this.breadcrumbElement.slottedBreadcrumbItems.length) {
            throw new Error(`Breadcrumb item with index ${index} not found`);
        }
        const breadcrumb = this.breadcrumbElement.slottedBreadcrumbItems[index];
        breadcrumb.scrollIntoView();
        await waitForUpdatesAsync();
    }
    getBreadcrumbViewScrollOffset() {
        return this.breadcrumbElement.shadowRoot.querySelector('.list')
            .scrollLeft;
    }
}
//# sourceMappingURL=breadcrumb.pageobject.js.map