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.GiftFormComponent;
import ru.otus.mobile.config.MobileConfig;

public final class GiftsPage extends AbsBasePage {
    private final GiftFormComponent form;

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

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

    public void editGift(String oldName, String newName) {
        openGift(oldName);
        tap("edit_button");
        form.save(newName, "100");
    }

    public void shouldSeeGift(String name) {
        scrollToText(name).shouldBe(Condition.visible);
    }

    private void openGift(String name) {
        scrollToText(name).click();
    }
}
