package com.intland.codebeamer.functionaltest.page;

import com.codeborne.selenide.Condition;
import com.codeborne.selenide.SelenideElement;
import com.intland.codebeamer.functionaltest.page.common.EditorComponent;
import org.openqa.selenium.By;

import static com.codeborne.selenide.Selenide.$;

/**
 * Copyright by Intland Software
 * <p>
 * All rights reserved.
 * <p>
 * This software is the confidential and proprietary information
 * of Intland Software. ("Confidential Information"). You
 * shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement
 * you entered into with Intland.
 */
public class SubmitWorkItemPage extends BasePage{

    public EditorComponent editorComponent = new EditorComponent();

    public void clickOnSave() {
        $(By.xpath(".//input[@value='Save']")).click();
    }

    public void clickOnCancel() {
        $(".cancelButton").click();
    }

    public void fillSummary(CharSequence text) {
        $("#summary").sendKeys(text);
    }


    public void tickTestConfigurations(boolean checked, String... labels) {
        for (String label: labels) {
            $(By.xpath(".//div[@id='testRunConfigurationsList']//label[./a[text()='" + label + "']]/preceding-sibling::input[@type='checkbox']")).setSelected(checked);
        }
    }

    public void checkIfSpentEffort(Condition condition) {
        $(By.xpath(".//td[@title='Spent Effort']/input")).shouldBe(condition);
    }

    public void clickOnAll() {
        $(By.xpath(".//a[@data-layout-mode='all']")).click();
    }
}
