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

import cz.moneta.test.dsl.exevido.ExevidoWebFlow;
import cz.moneta.test.dsl.exevido.pages.DetailIncomingMessagePage;
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.inheritance.DetailFolderPage.PAGE_LABEL_XPATH;

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

    String PAGE_LABEL_XPATH = "//b[contains(text(),'Spis:')]";
    String OUTGOING_MESSAGES_LABEL_XPATH = "//a[contains(text(),'Odchozí zprávy')]";
    String ROW_BY_MESSAGE_ID = "//tr[contains(@class,'clickable-row')]//td[2]/div[normalize-space()='%s']/ancestor::tr";

    @CustomAction
    default DetailIncomingMessagePage openMessageById(String messageId) {
        ExevidoEndpoint endpoint = getEndpoint(ExevidoEndpoint.class);
        endpoint.moveToElement(OUTGOING_MESSAGES_LABEL_XPATH, Lookup.XPATH);
        endpoint.click(() -> String.format(ROW_BY_MESSAGE_ID, messageId), Lookup.XPATH);
        return null;
    }
}