```{r renv.ignore = TRUE}
####################### #
# MISC #
####################### #
#' @title printVecAsis
#' @description For internal use. Print objects as character string
#' @param x object to print
#' @return A character string to reproduce the object
#' @keywords internal
#' @export
printVecAsis <- function(x) {
  if (is.numeric(x) && length(x) == 1){
    return(x)
  } else {
    utils::capture.output(dput(x))
  }
}

#' @title Spurious package call to avoid note of functions outside R folder
#' @description For internal use.
#' @param x x
#' @keywords internal
#' @export
spurious <- function(x) {
  DT::renderDataTable(x)
  glue::glue(x)
  R6::R6Class(x)
  markdown::html_format(x)
```
```{r renv.ignore = TRUE, purl = {{async}}}
  mirai::mirai(x)
```
```{r renv.ignore = TRUE}
  renv::activate(x)
  rmarkdown::github_document(x)
```
```{r renv.ignore = TRUE, purl = {{include_code}}}
  shinyAce::aceEditor(x)
```
```{r renv.ignore = TRUE}
  shinyWidgets::pickerInput(x)
  shinyjs::disable(x)
  tools::add_datalist(x)
  return()
}

####################### #
# SHINY LOG #
####################### #

#' @title writeLog
#' @description For internal use. Add text to a logger
#' @param logger The logger to write the text to. Can be NULL or a function
#' @param ... Messages to write to the logger
#' @param type One of "default", "info", "error", "warning"
#' @keywords internal
#' @export
writeLog <- function(logger, ..., type = "default") {
  if (is.null(logger)) {
    if (type == "error") {
      stop(paste0(..., collapse = ""), call. = FALSE)
    } else if (type == "warning") {
      warning(paste0(..., collapse = ""), call. = FALSE)
    } else {
      message(paste0(..., collapse = ""))
    }
  } else if (is.function(logger)) {
    if (type == "default") {
      pre <- "> "
    } else if (type == "starting") {
      pre <- paste0(shiny::icon("clock", class = "log_start"), " ")
    } else if (type == "complete") {
      pre <- paste0(shiny::icon("check", class = "log_end"), " ")
    } else if (type == "info") {
      if (nchar(...) < 80){
        shinyalert::shinyalert(..., type = "info")
      } else {
        shinyalert::shinyalert("Please, check Log window for more information ",
                               type = "info")
      }
      pre <- paste0(shiny::icon("info", class = "log_info"), " ")
    } else if (type == "error") {
      if (nchar(...) < 80){
        shinyalert::shinyalert(...,
                               type = "error")
      } else {
        shinyalert::shinyalert("Please, check Log window for more information ",
                               type = "error")
      }
      pre <- paste0(shiny::icon("xmark", class = "log_error"), " ")
    } else if (type == "warning") {
      if (nchar(...) < 80){
        shinyalert::shinyalert(...,
                               type = "warning")
      } else {
        shinyalert::shinyalert("Please, check Log window for more information ",
                               type = "warning")

      }
      pre <- paste0(shiny::icon("triangle-exclamation", class = "log_warn"), " ")
    }
    newEntries <- paste0("<br>", pre, ..., collapse = "")
    logger(paste0(logger(), newEntries))
  } else {
    warning("Invalid logger type")
  }
  invisible()
}

#' @title asyncLog
#' @description For internal use. Similar to writeLog but for use inside async
#' functions
#' @param async Whether the function is being used asynchronously
#' @param message The message to write to the logger
#' @param type One of "default", "info", "error", "warning"
#' @keywords internal
#' @export
asyncLog <- function(async, message, type = "default"){
  if (!async) {
    if (type == "error") {
      stop(paste0(message, collapse = ""), call. = FALSE)
    } else if (type == "warning") {
      warning(paste0(message, collapse = ""), call. = FALSE)
    } else {
      message(paste0(message, collapse = ""))
    }
  } else {
    return(message)
  }
}
```
