package com.intland.codebeamer.functionaltest.page.common;

import com.codeborne.selenide.SelenideElement;
import com.intland.codebeamer.functionaltest.helper.Helper;
import org.openqa.selenium.By;

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

/**
 * 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 WYSIWYGTab {

    //private final SelenideElement parentElement;

//    public WYSIWYGTab(SelenideElement parentElement){
//        this.parentElement = parentElement;
//    }

    public void clickOnSave() {
        $(".mce-ico.mce-i-save").click();
    }

    public void fillSummary(String text) {
        SelenideElement e = $(".nested-summary-editor");
        e.clear();
        e.sendKeys(text);
    }

    public void fillDescription(boolean clear, CharSequence... text) {
        String currentFrame = Helper.getCurrentFrame();
        String currentWindow = Helper.getCurrentWindow();
        switchTo().frame(0);
        SelenideElement e = $(By.xpath(".//body"));
        if(clear) {
            e.clear();
        }
        e.sendKeys(text);
        if (!currentFrame.isEmpty()){
            switchTo().defaultContent();
            switchTo().frame(currentFrame);
        }
        else if (!currentWindow.isEmpty()) switchTo().window(currentWindow);
    }

}
