package com.codeborne.selenide.ex;

import com.codeborne.selenide.Condition;
import com.codeborne.selenide.Configuration;
import com.codeborne.selenide.Screenshots;
import com.codeborne.selenide.impl.Cleanup;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.WebElement;

import java.util.List;

public class ErrorMessages {
  protected static String timeout(long timeoutMs) {
    if (timeoutMs < 1000) {
      return "\nTimeout: " + timeoutMs + " ms.";
    }
    if (timeoutMs % 1000 == 0) {
      return "\nTimeout: " + timeoutMs / 1000 + " s.";
    }

    return "\nTimeout: " + String.format("%.3f", timeoutMs / 1000.0) + " s.";
  }

  public static String actualValue(Condition condition, WebElement element) {
    if (element != null) {
      String actualValue = condition.actualValue(element);
      if (actualValue != null) {
        return "\nActual value: " + actualValue;
      }
    }
    return "";
  }

  public static String screenshot() {
    return screenshot(Screenshots.screenshots.formatScreenShotPath());
  }
  
  public static String screenshot(String screenshotPath) {
    if (!Configuration.screenshots) {
      return "";
    }
    if(Configuration.savePageSource) {
       if(screenshotPath == null || screenshotPath.isEmpty()) {
          return "\nScreenshot: " + screenshotPath;
       }
       return "\nScreenshot: " + screenshotPath
              + "\nHtml: " + screenshotPath.substring(0, screenshotPath.lastIndexOf('.')) + ".html";
    }else {
       return "\nScreenshot: " + screenshotPath;
    }
  }

  public static String causedBy(Throwable cause) {
    if (cause == null) {
      return "";
    }
    if (cause instanceof WebDriverException) {
      return "\nCaused by: " + Cleanup.of.webdriverExceptionMessage(cause);
    }
    return "\nCaused by: " + cause;
  }

  public static String jsErrors(List<String> jsErrors) {
    if (jsErrors == null || jsErrors.isEmpty()) {
      return "";
    }
    return "\nJavascript Errors: " + jsErrors;
  }
}

@@ -1177,16 +1177,17 @@
 %7D%0A    if
+ 
 (Configu
@@ -1217,19 +1217,19 @@
 %7B%0A      
- 
 if
+ 
 (screens
@@ -1279,26 +1279,24 @@
 ) %7B%0A        
- 
- 
 return %22%5CnSc
@@ -1331,20 +1331,18 @@
 ;%0A      
- 
 %7D%0A
- 
       re
@@ -1490,16 +1490,16 @@
    %7D
+ 
 else %7B%0A
- 
     

fix checkstyle