import { waitForUpdatesAsync } from '../../testing/async-helpers';
import { waitTimeout } from '../../utilities/testing/component';
import { stepTag } from '../../step';
import { StepperOrientation } from '../types';
/**
 * Page object for the `nimble-stepper`
 */
export class StepperPageObject {
    constructor(element) {
        this.element = element;
    }
    async setStepperScrollAxisSize(size) {
        if (this.element.orientation === StepperOrientation.horizontal) {
            this.element.style.width = `${size}px`;
        }
        else {
            this.element.style.height = `${size}px`;
        }
        await waitForUpdatesAsync();
        await waitForUpdatesAsync(); // wait for the resize observer to fire
    }
    async clickScrollStartButton() {
        const startButton = this.element.shadowRoot.querySelector('.scroll-button.start');
        if (!startButton) {
            throw new Error('Scroll start button not found');
        }
        startButton.click();
        await waitForUpdatesAsync();
        await waitTimeout(50); // let animation run
    }
    async clickScrollEndButton() {
        const endButton = this.element.shadowRoot.querySelector('.scroll-button.end');
        if (!endButton) {
            throw new Error('Scroll end button not found');
        }
        endButton.click();
        await waitForUpdatesAsync();
        await waitTimeout(50); // let animation run
    }
    areScrollButtonsVisible() {
        return (this.element.shadowRoot.querySelectorAll('.scroll-button').length > 0);
    }
    getStepperViewScrollOffset() {
        const list = this.element.shadowRoot.querySelector('.list');
        return this.element.orientation === 'horizontal'
            ? list.scrollLeft
            : list.scrollTop;
    }
    async scrollStepIntoViewByIndex(index) {
        const steps = this.element.steps;
        if (!steps || index >= steps.length) {
            throw new Error(`Step with index ${index} not found`);
        }
        steps[index].scrollIntoView();
        await waitForUpdatesAsync();
    }
    async addStep(title) {
        const step = document.createElement(stepTag);
        step.appendChild(Object.assign(document.createElement('span'), {
            slot: 'title',
            textContent: title ?? ''
        }));
        this.element.appendChild(step);
        await waitForUpdatesAsync();
        await waitForUpdatesAsync(); // wait for overflow check queued by stepsChanged
    }
    async removeStepByIndex(index) {
        const steps = this.element.steps;
        if (!steps || index >= steps.length) {
            throw new Error(`Step with index ${index} not found`);
        }
        steps[index].remove();
        await waitForUpdatesAsync();
        await waitForUpdatesAsync(); // wait for overflow check queued by stepsChanged
    }
    async updateStepTitle(index, title) {
        const steps = this.element.steps;
        if (!steps || index >= steps.length) {
            throw new Error(`Step with index ${index} not found`);
        }
        const step = steps[index];
        const titleSlot = step.querySelector('[slot="title"]');
        if (!titleSlot) {
            throw new Error(`No slot="title" element found to update for step with index ${index}`);
        }
        titleSlot.textContent = title;
        await waitForUpdatesAsync();
        await waitForUpdatesAsync();
    }
}
//# sourceMappingURL=stepper.pageobject.js.map