package ru.otus.mobile.page;

import com.codeborne.selenide.Condition;
import com.codeborne.selenide.SelenideElement;
import com.google.inject.Singleton;
import ru.otus.mobile.component.GiftFormComponent;
import ru.otus.mobile.component.GiftsContentComponent;

@Singleton
public final class GiftsPage extends AbsBasePage {
    private final SelenideElement addButton = byId("add_button");
    private final GiftsContentComponent content = new GiftsContentComponent(byId("gifts_content"));
    private final GiftFormComponent form = new GiftFormComponent(byId("gift_edit_bottom_sheet"));

    public void createGift(String name) {
        addButton.click();
        form.save(name, "100");
        content.shouldBe(Condition.visible);
    }

    public void editGift(String oldName, String newName) {
        openGift(oldName);
        content.byTitle(oldName).edit();
        form.save(newName, "100");
        content.shouldBe(Condition.visible);
    }

    public void shouldSeeGift(String name) {
        content.shouldBe(Condition.visible);
        content.byTitle(name).shouldHaveTitle(name);
    }

    private void openGift(String name) {
        content.byTitle(name).open();
    }
}
