import { Atom } from "../../atom";
import { Helpers } from "../../setup";
import { ButtonAtom } from "../button/button.atom";
import { CheckboxAtom } from "../checkbox/checkbox.atom";
import { MenuPopupAtom } from "../menu-popup/menu-popup.atom";
import { PopupAtom } from "../popup/popup.atom";
export var SelectionType;
(function (SelectionType) {
    SelectionType["All"] = "Select all items on this page";
    SelectionType["UnselectAll"] = "Unselect all items on this page";
    SelectionType["None"] = "Unselect all items";
    SelectionType["AllPages"] = "Select all items on all pages";
})(SelectionType || (SelectionType = {}));
export class SelectorAtom extends Atom {
    static { this.CSS_CLASS = "nui-selector"; }
    static findIn(atomClass, parentLocator, root = true) {
        return Atom.findIn(atomClass, parentLocator, root);
    }
    get getPopupAtom() {
        return Atom.findIn(PopupAtom, this.getLocator());
    }
    async select(selectionType) {
        if (!((await this.getPopupAtom.getPopupBox.count()) > 0)) {
            await this.getToggle.click();
        }
        await this.itemByText(selectionType).isVisible();
        // https://playwright.dev/docs/actionability#receives-events
        await this.itemByText(selectionType).click({ force: true });
    }
    async selectAppendedToBodyItem(selectionType) {
        if (!((await this.getPopupAtom.getPopupBoxDetached.count()) > 0)) {
            await this.getToggle.click();
        }
        await this.appendedToBodyItemByText(selectionType).isVisible();
        // https://playwright.dev/docs/actionability#receives-events
        await this.appendedToBodyItemByText(selectionType).click({
            force: true,
        });
    }
    get getCheckbox() {
        return Atom.findIn(CheckboxAtom, this.getLocator());
    }
    get getSelectorButton() {
        const buttonContainer = super
            .getLocator()
            .locator(".nui-selector__checkbox-button");
        return Atom.findIn(ButtonAtom, buttonContainer, true);
    }
    itemByText(title) {
        return Atom.findIn(MenuPopupAtom, this.getLocator()).itemByText(title);
    }
    appendedToBodyItemByText(title) {
        return Atom.findIn(MenuPopupAtom, Helpers.page.locator("body .nui-overlay")).itemByText(title);
    }
    get getToggle() {
        return this.getLocator().locator(".nui-selector__toggle");
    }
    async isOpened() {
        await this.getPopupAtom.isOpened();
    }
}
//# sourceMappingURL=selector.atom.js.map