package cz.moneta.test.dsl.ufo.operations.recorder.panels;

import cz.moneta.test.dsl.ufo.operations.recorder.CRC710_S001_RecorderMainPage;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.ufo.UfoEndpoint;
import cz.moneta.test.harness.support.web.CustomAction;
import cz.moneta.test.harness.support.web.Wait;

import static cz.moneta.test.dsl.ufo.operations.recorder.panels.CRC710_S001_SelectedWritingsRecorderPanel.WRITTEN_LINE_INNER_TAB_DIV;
import static cz.moneta.test.harness.support.web.Lookup.XPATH;
import static cz.moneta.test.harness.support.web.Until.VISIBLE;

@Wait(WRITTEN_LINE_INNER_TAB_DIV)
public interface CRC710_S001_SelectedWritingsRecorderPanel extends StoreAccessor {

    String WRITTEN_LINE_INNER_TAB_DIV = "CRC710_S001_I004_innerTab";
    String WRITTEN_LINE_GENERAL_XPATH = "//tr[@id='ufo-et-CRC710_S001_F001_row_%s']";
    String WRITTEN_LINE_FILLED_CONTENT_GENERAL_XPATH = "//div[contains(@id,'CRC710_S001_L07%s') and text()]";

    @CustomAction
    default CRC710_S001_RecorderMainPage waitForReasonInsertion(int reasonNumber) {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        String xpath = String.format(WRITTEN_LINE_GENERAL_XPATH, reasonNumber) + String.format(WRITTEN_LINE_FILLED_CONTENT_GENERAL_XPATH, "2");
        endpoint.waitForElementsToLoad(20, XPATH, VISIBLE, xpath);
        return null;
    }

    @CustomAction
    default CRC710_S001_RecorderMainPage waitForNextRecordInsertion(int currentRecordNumber) {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        endpoint.waitForElementsToLoad(20, XPATH, String.format(WRITTEN_LINE_GENERAL_XPATH, currentRecordNumber));
        return null;
    }
}
