package com.atlassian.webdriver.bitbucket.element;

import com.atlassian.pageobjects.elements.timeout.TimeoutType;
import org.openqa.selenium.By;

import java.util.List;

public class CodeMirrorSourceFileContent extends SourceFileContent {
    public CodeMirrorSourceFileContent(By locator, TimeoutType timeoutType) {
        super(locator, timeoutType);
    }

    public List<String> getSourceLines() {
        waitUntilFileContentLoaded();
        return (List<String>) javascript().execute(
                "return jQuery('.CodeMirror')[0].CodeMirror.getValue().split(/\\r?\\n/);");
    }

    @Override
    public List<Line> getHighlightedLines() {
        // ensure that all CodeMirror lines are loaded.
        waitUntilFileContentLoaded();

        return waitForSourceContainer(() -> findAll(By.cssSelector(".source-view .line"), Line.class));
    }
}
