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.WishlistsContentComponent;
import ru.otus.mobile.component.WishlistFormComponent;

import java.time.Duration;

@Singleton
public final class WishlistsPage extends AbsBasePage {
    private final SelenideElement addButton = byId("add_button");
    private final WishlistsContentComponent content = new WishlistsContentComponent(byId("wishlists_content"));
    private final WishlistFormComponent form = new WishlistFormComponent(byId("wishlist_edit_bottom_sheet"));

    public void open() {
        bottomNavigation.openWishlists();
        content.shouldBe(Condition.visible, Duration.ofSeconds(15));
    }

    public void createWishlist(String name) {
        addButton.click();
        form.save(name);
    }

    public void editWishlist(String oldName, String newName) {
        content.byTitle(oldName).edit();
        form.save(newName);
    }

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

    public void openWishlist(String name) {
        content.byTitle(name).open();
    }

    public void openFirstWishlist() {
        content.first().open();
    }
}
