#' @title Diversity indices
#'
#' @description Computes and prints all the diversity indices
#'
#' @param x Vector of dimension S (number of species) with the number of individuals observed in each species. NA values are allowed. 0 values are converted to NA.
#' @param groups Vector of dimension S of factors indicating the groups. If omitted, the decomposition of the indicators is not done.
#' @param B Number of bootstrap samples. The default is 1000.
#' @param cl Confidence level. A value between 0 and 1. The default is 0.95.
#'
#' @return{No return value. It prints the value of all indicators}
#'
#' @seealso \link{shannon}, \link{dec_shannon}, \link{dominance}, \link{equitability}, \link{evenness}, \link{margalef}, \link{menhinick}, \link{simpson_D}, \link{simpson_E}
#'
#' @references
#' "Arnaud Barat, Andreu Sansó, Maite Arilla-Osuna, Ruth Blasco, Iñaki Pérez-Fernández, Gabriel Cifuentes-Alcobenda, Rubén Llorente, Daniel Vivar-Ríos, Ella Assaf, Ran Barkai, Avi Gopher, & Jordi Rosell-Ardèvol (2026): Quantifying Diversity through Entropy Decomposition. Insights into Hominin Occupation and Carcass Processing  at Qesem cave"
#'
#' @examples
#' data(Qesem_s)
#' all_indices(Qesem_s$HU)
#' all_indices(Qesem_s$HU, Qesem_s$Group)
#'
#' @export
all_indices <- function(x, groups = NULL, B = 1000, cl = 0.95){
  cat("\n")
  b <- bs(x, ind = "shannon", B = B, cl = cl)
  if (!is.null(groups)) {
    sh <- dec_shannon(x, groups)
    cat("Shannon's diversity (Total):", sh$shannon, "  (", b$low,",", b$up,")\n")
    b <- bs_dec(x, groups, ind = "shannon", B = B, cl = cl)
    cat("Decomposing Shannon's diversity:\n")
    cat("    Within groups: ", sh$within, "  (", b$wt_low,",", b$wt_up,")\n")
    cat("    Between groups:", sh$between, "  (", b$bt_low,",", b$bt_up,")\n")
    cat("    Fraction Between/Total:", sh$between/sh$shannon,"\n")
    cat("  Entropy within each group\n")
    print(sh$g)
    cat("\n")
  } else {
    cat("Shannon's diversity:", shannon(x), "  (", b$low,",", b$up,")\n")
  }
  b <- bs(x, ind = "equitability", B = B, cl = cl)
  cat("Equitability (J Pielou):", equitability(x), "  (", b$low,",", b$up,")\n")
  b <- bs(x, ind = "simpson_D", B = B, cl = cl)
  cat("Simpson's dominance:", simpson_D(x), "  (", b$low,",", b$up,")\n")
  b <- bs(x, ind = "dominance", B = B, cl = cl)
  cat("Dominance:", dominance(x), "  (", b$low,",", b$up,")\n")
  b <- bs(x, ind = "simpson_E", B = B, cl = cl)
  cat("Simpson's evenness:", simpson_E(x), "  (", b$low,",", b$up,")\n")
  b <- bs(x, ind = "evenness", B = B, cl = cl)
  cat("Evenness:", evenness(x), "  (", b$low,",", b$up,")\n")
  b <- bs(x, ind = "menhinick", B = B, cl = cl)
  cat("Menhinick's Index:", menhinick(x), "  (", b$low,",", b$up,")\n")
  b <- bs(x, ind = "margalef", B = B, cl = cl)
  cat("Margalef's Index:", margalef(x), "  (", b$low,",", b$up,")\n\n")
  cat("Bootstrap confidence intervals at", cl,"confidence level between ()\n")
}
