package ru.otus.mobile.page;

import com.codeborne.selenide.Condition;
import com.google.inject.Inject;
import ru.otus.mobile.component.BottomNavigationComponent;
import ru.otus.mobile.component.GiftsContentComponent;
import ru.otus.mobile.component.GiftFormComponent;

public final class GiftsPage extends AbsBasePage {
    private final GiftFormComponent form;
    private final com.codeborne.selenide.SelenideElement addButton = byId("add_button");

    @Inject
    public GiftsPage(BottomNavigationComponent bottomNavigation, GiftFormComponent form) {
        super(bottomNavigation);
        this.form = form;
    }

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

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

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

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

    private GiftsContentComponent content() {
        return new GiftsContentComponent(byId("gifts_content"));
    }
}
