package cz.moneta.test.dsl.exevido.pages;

import cz.moneta.test.dsl.exevido.ExevidoWebFlow;
import cz.moneta.test.dsl.exevido.components.ExevidoPanels;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.exevido.ExevidoEndpoint;
import cz.moneta.test.harness.support.web.*;

import static cz.moneta.test.dsl.exevido.pages.OutgoingMessagesPage.PAGE_LABEL_XPATH;

@Wait(value = PAGE_LABEL_XPATH, by = Lookup.XPATH)
public interface OutgoingMessagesPage extends ExevidoWebFlow<OutgoingMessagesPage>, StoreAccessor {

    String PAGE_LABEL_XPATH = "//b[contains(text(), 'Odchozí zprávy dle stavu')]";
    String CREATE_NEW_OUTGOING_MESSAGE_BUTTON = "create_new_outgoing_message";
    String ID_MESSAGE_INPUT = "text_message_id";
    String OUTGOING_MESSAGE_ROW = "outgoing_message_0_row";

    @Click(CREATE_NEW_OUTGOING_MESSAGE_BUTTON)
    NewOutgoingMessagePage clickCreateNewOutgoingMessage();

    @TypeInto(value = ID_MESSAGE_INPUT, clear = true)
    @KeyPress(value = Key.ENTER, andWait = @Wait(value = ExevidoPanels.LOADER_DIV, until = Until.GONE))
    OutgoingMessagesPage searchByMessageId(String id);

    @CustomAction
    default DetailOutgoingMessagePage clickOutgoingMessageRow(int timeout) {
        ExevidoEndpoint endpoint = getEndpoint(ExevidoEndpoint.class);
        endpoint.waitForElementAndRefresh(OUTGOING_MESSAGE_ROW, Lookup.ID, endpoint::refeshPage, timeout, 2);
        endpoint.click(() -> OUTGOING_MESSAGE_ROW, Lookup.ID);
        return null;
    }

}