package ru.otus.mobile.component;

import com.codeborne.selenide.Condition;
import com.codeborne.selenide.SelenideElement;

import static com.codeborne.selenide.Condition.text;

public final class GiftItemComponent extends BaseMobileComponent {
    private final SelenideElement title = byIdInRoot("title");
    private final SelenideElement editButton = byIdInRoot("edit_button");
    private final SelenideElement reservedToggle = byIdInRoot("reserved");

    public GiftItemComponent(SelenideElement root) {
        super(root);
    }

    public String titleText() {
        return title.getText();
    }

    public void shouldHaveTitle(String value) {
        title.shouldHave(text(value));
    }

    public void open() {
        title.click();
    }

    public void edit() {
        editButton.click();
    }

    public boolean isReserved() {
        return Boolean.parseBoolean(reservedToggle.shouldBe(Condition.visible).getAttribute("checked"));
    }

    public void toggleReservation() {
        reservedToggle.shouldBe(Condition.visible).click();
    }
}
