import { expect, Helpers } from "./setup";
export class Atom {
    /**
     * Create atom from the css id
     */
    static find(atomClass, id, root) {
        return atomClass.findIn(atomClass, Helpers.page.locator(`#${id}`), root);
    }
    /**
     * Create atom from the css
     */
    static findIn(atomClass, parentLocator, root = false) {
        const create = (locator) => new atomClass(locator);
        const selector = Atom.getSelector(atomClass);
        if (!selector) {
            return create(parentLocator ?? Atom.getFromRoot("body"));
        }
        if (!parentLocator) {
            return create(Atom.getFromRoot(selector));
        }
        if (root) {
            const sibling = Helpers.page.locator(selector);
            return create(parentLocator.and(sibling));
        }
        return create(parentLocator.locator(selector));
    }
    static getFromRoot(selector) {
        return Helpers.page.locator("body").locator(selector);
    }
    static getSelector(atomClass) {
        if (atomClass.CSS_CLASS) {
            return `.${atomClass.CSS_CLASS}`;
        }
        if (atomClass.CSS_SELECTOR) {
            return atomClass.CSS_SELECTOR;
        }
        return null;
    }
    constructor(locator) {
        this.locator = locator;
    }
    async toNotContainClass(className) {
        return await expect(this.locator).not.toContainClass(className);
    }
    async toContainClass(className) {
        return await expect(this.locator).toContainClass(className);
    }
    /**
     * @Deprecated: use Atom.toContainClass.
     * see ../../ASSERTING_VALUE.md
     */
    async hasClass(cls) {
        const classList = await this.locator.getAttribute("class");
        return (classList || "").split(" ").includes(cls);
    }
    async toBeDisabled() {
        return await expect(this.locator).toBeDisabled();
    }
    async toBeVisible() {
        return await expect(this.locator).toBeVisible();
    }
    async toBeHidden() {
        return await expect(this.locator).toBeHidden();
    }
    getLocator() {
        return this.locator;
    }
    nth(atomClass, index) {
        // it should take existing class and return the class which will be limited to the index
        // this.limit it and for example the click will be perfomed agains the only on insance
        // this.getLocator(); // all of them
        const locator = this.getLocator().nth(index); // the locator of the only one item
        return new atomClass(locator);
        // how to return the atom
    }
    first(atomClass) {
        return this.nth(atomClass, 0);
    }
    // function spawnWrapper (...params: [
    //     Parameters<typeof spawn>[0],
    //     Parameters<typeof spawn>[1],
    // ]) {
    //     return spawn(...params);
    // }
    filter(atomClass, ...filter) {
        // it should take existing class and return the class which will be limited to the index
        // this.limit it and for example the click will be perfomed agains the only on insance
        // this.getLocator(); // all of them
        const locator = this.getLocator().filter(...filter); // the locator of the only one item
        return new atomClass(locator);
        // how to return the atom
    }
    async click() {
        await this.locator.click();
    }
    async hover(target, force = false) {
        if (target) {
            await target.hover({ force });
            return;
        }
        await this.locator.hover({ force });
    }
}
//# sourceMappingURL=atom.js.map