#' Save kable to files
#'
#' @param x A piece of HTML code for tables, usually generated by kable and
#' kableExtra
#' @param file save to files. If the input table is in HTML and the output file
#' ends with `.png`, `.pdf` and `.jpeg`, `webshot` will be used to do the
#' conversion.
#' @param bs_theme Which Bootstrap theme to use
#' @param self_contained Will the files be self-contained?
#' @param extra_dependencies Additional HTML dependencies. For example,
#' `list(`
#' @param ... Additional variables being passed to `webshot::webshot`. This
#' is for HTML only.
#' @param latex_header_includes A character vector of extra LaTeX header stuff.
#' Each element is a row. You can have things like
#' `c("\\\\usepackage{threeparttable}", "\\\\usepackage{icons}")`  You could
#' probably add your language package here if you use non-English text in your
#' table, such as `\\\\usepackage[magyar]{babel}`.
#' @param keep_tex A T/F option to control if the latex file that is initially created
#' should be kept. Default is `FALSE`.
#'
#' @export
save_kable <- function(x, file,
                       bs_theme = "simplex", self_contained = TRUE,
                       extra_dependencies = NULL, ...,
                       latex_header_includes = NULL, keep_tex = FALSE) {
  if (attr(x, "format") == "latex") {
    return(save_kable_latex(x, file, latex_header_includes, keep_tex))
  }
  return(save_kable_html(x, file, bs_theme, self_contained,
                         extra_dependencies, ...))
}

save_kable_html <- function(x, file, bs_theme, self_contained,
                            extra_dependencies, ...) {
  dependencies <- list(
    rmarkdown::html_dependency_jquery(),
    rmarkdown::html_dependency_bootstrap(theme = bs_theme),
    html_dependency_kePrint()
  )
  if (!is.null(extra_dependencies)) {
    dependencies <- append(dependencies, extra_dependencies)
  }

  html_header <- htmltools::tag("head", dependencies)
  html_table <- htmltools::HTML(as.character(x))
  html_result <- htmltools::tagList(html_header, html_table)

  # Use webshot if necessary
  if (tools::file_ext(file) %in% c("png", "jpg", "jpeg", "pdf")) {
    message("Putting together a HTML file...")
    file_html <- paste0(tools::file_path_sans_ext(file), ".html")
    htmltools::save_html(html_result, file = file_html)
    message("Converting HTML to ", tools::file_ext(file), "...")
    webshot::webshot(file_html, file, ...)
    message("Done. ")
    if (tools::file_ext(file) == "pdf") {
      message("Note that HTML color may not be displayed on PDF properly.")
    }
    unlink(file_html)
    unlink("lib", recursive = TRUE)
  } else {
    htmltools::save_html(html_result, file = file)
    if (self_contained) {
      rmarkdown::pandoc_self_contained_html(file, file)
      unlink("lib", recursive = TRUE)
    }
  }
}

save_kable_latex <- function(x, file, latex_header_includes, keep_tex) {
  temp_tex <- c(
    "\\documentclass[border=1mm, preview]{standalone}",
    "\\usepackage[active,tightpage]{preview}",
    "\\usepackage{varwidth}",
    "\\usepackage{amssymb, amsmath}",
    "\\usepackage{ifxetex,ifluatex}",
    "\\usepackage{fixltx2e}",
    "\\usepackage{polyglossia}",
    "\\setmainlanguage{$mainlang$}",
    latex_pkg_list(),
    "\\usepackage{graphicx}",
    "\\usepackage{mathspec}",
    "\\usepackage{xltxtra,xunicode}",
    latex_header_includes,
    "\\begin{document}",
    solve_enc(x),
    "\\end{document}"
  )
  temp_tex <- paste(temp_tex, collapse = "\n")

  temp_tex_file <- tools::file_path_sans_ext(file)
  writeLines(temp_tex, temp_tex_file, useBytes = T)
  system(paste0("xelatex -interaction=batchmode ", temp_tex_file))
  if (!keep_tex) {
    temp_file_delete <- paste0(tools::file_path_sans_ext(file),
                               c(".tex", ".aux", ".log"))
    unlink(temp_file_delete)
  }

  table_img_pdf <- try(magick::image_read(paste0(temp_file, ".pdf"),
                                          density = density),
                       silent = T)
  if (class(table_img_pdf) == "try-error") {
    stop("Ghostscript is required to read PDF on windows. ",
         "Please download it here: https://ghostscript.com/")
  }
  if (!keep_pdf) {
    unlink(paste0(temp_file, ".pdf"))
  }
  table_img <- magick::image_convert(table_img_pdf, file_format)
  if (!is.null(filename)) {
    temp_img <- paste0(filename, ".", file_format)
  } else {
    temp_img <- tempfile(fileext = paste0(".", file_format))
  }
  magick::image_write(table_img, temp_img)

  include_graphics(temp_img)
}
