package ru.otus.mobile.component;

import com.codeborne.selenide.SelenideElement;
import com.google.inject.Inject;
import io.appium.java_client.AppiumBy;

import static com.codeborne.selenide.appium.SelenideAppium.$;

public final class AlertDialogComponent extends BaseMobileComponent {
    private final SelenideElement positiveButton;

    @Inject
    public AlertDialogComponent() {
        this($(AppiumBy.id("android:id/content")));
    }

    public AlertDialogComponent(SelenideElement root) {
        super(root);
        this.positiveButton = byIdInRoot("android:id/button1");
    }

    public void acceptIfVisible() {
        if (positiveButton.exists()) {
            positiveButton.click();
        }
    }
}
