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.CheckElementPresent;
import cz.moneta.test.harness.support.web.CustomAction;
import cz.moneta.test.harness.support.web.Lookup;
import cz.moneta.test.harness.support.web.Wait;

import static cz.moneta.test.dsl.ufo.operations.recorder.CRC710_S001_RecorderMainPage.GENERAL_TREE_ITEM_XPATH;
import static cz.moneta.test.dsl.ufo.operations.recorder.panels.CRC710_S001_SolutionRecorderPanel.SOLUTION_RECORDER_PANEL_DIV;
import static cz.moneta.test.harness.support.web.Lookup.XPATH;

@Wait(value = SOLUTION_RECORDER_PANEL_DIV, by = Lookup.XPATH)
public interface CRC710_S001_SolutionRecorderPanel extends StoreAccessor {

    String SOLUTION_RECORDER_PANEL_DIV = "//div[@id='CRC710_S001_Y001_innerPanel']";
    String SOLUTIONS_DIV_XPATH = "//div[@id='CRC710_S001_T001']//div[@class='gwt-TreeItemChildSpanLast']";

    @CustomAction
    default CRC710_S001_RecorderMainPage addSolution(String reasonName) {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        String treeItemXpath = String.format(GENERAL_TREE_ITEM_XPATH, reasonName);
        endpoint.waitForElementsToLoad(20, XPATH, treeItemXpath);
        endpoint.jsClick(() -> SOLUTION_RECORDER_PANEL_DIV + treeItemXpath, XPATH);
        endpoint.jsDoubleClick(() -> SOLUTION_RECORDER_PANEL_DIV + treeItemXpath, XPATH);
        return null;
    }

    @CheckElementPresent(value = SOLUTIONS_DIV_XPATH, by = Lookup.XPATH)
    CRC710_S001_RecorderMainPage checkSolutionsDiv();
}