
# This file is automatically generated, you probably don't want to edit this

gtsummaryOptions <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
    "gtsummaryOptions",
    inherit = jmvcore::Options,
    public = list(
        initialize = function(
            dep = NULL,
            group = NULL,
            alt = "notequal",
            varEq = TRUE, ...) {

            super$initialize(
                package="ClinicoPath",
                name="gtsummary",
                requiresData=TRUE,
                ...)

            private$..dep <- jmvcore::OptionVariable$new(
                "dep",
                dep)
            private$..group <- jmvcore::OptionVariable$new(
                "group",
                group)
            private$..alt <- jmvcore::OptionList$new(
                "alt",
                alt,
                options=list(
                    "notequal",
                    "onegreater",
                    "twogreater"),
                default="notequal")
            private$..varEq <- jmvcore::OptionBool$new(
                "varEq",
                varEq,
                default=TRUE)

            self$.addOption(private$..dep)
            self$.addOption(private$..group)
            self$.addOption(private$..alt)
            self$.addOption(private$..varEq)
        }),
    active = list(
        dep = function() private$..dep$value,
        group = function() private$..group$value,
        alt = function() private$..alt$value,
        varEq = function() private$..varEq$value),
    private = list(
        ..dep = NA,
        ..group = NA,
        ..alt = NA,
        ..varEq = NA)
)

gtsummaryResults <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
    "gtsummaryResults",
    inherit = jmvcore::Group,
    active = list(
        gtsum1 = function() private$.items[["gtsum1"]]),
    private = list(),
    public=list(
        initialize=function(options) {
            super$initialize(
                options=options,
                name="",
                title="Tables via gtsummary",
                refs=list(
                    "ClinicoPathJamoviModule"))
            self$add(jmvcore::Html$new(
                options=options,
                name="gtsum1",
                title="Tables via gtsummary"))}))

gtsummaryBase <- if (requireNamespace("jmvcore", quietly=TRUE)) R6::R6Class(
    "gtsummaryBase",
    inherit = jmvcore::Analysis,
    public = list(
        initialize = function(options, data=NULL, datasetId="", analysisId="", revision=0) {
            super$initialize(
                package = "ClinicoPath",
                name = "gtsummary",
                version = c(1,0,0),
                options = options,
                results = gtsummaryResults$new(options=options),
                data = data,
                datasetId = datasetId,
                analysisId = analysisId,
                revision = revision,
                pause = NULL,
                completeWhenFilled = FALSE,
                requiresMissings = FALSE,
                weightsSupport = 'auto')
        }))

#' Tables via gtsummary
#'
#' 
#' @param data .
#' @param dep .
#' @param group .
#' @param alt .
#' @param varEq .
#' @return A results object containing:
#' \tabular{llllll}{
#'   \code{results$gtsum1} \tab \tab \tab \tab \tab a html \cr
#' }
#'
#' @export
gtsummary <- function(
    data,
    dep,
    group,
    alt = "notequal",
    varEq = TRUE) {

    if ( ! requireNamespace("jmvcore", quietly=TRUE))
        stop("gtsummary requires jmvcore to be installed (restart may be required)")

    if ( ! missing(dep)) dep <- jmvcore::resolveQuo(jmvcore::enquo(dep))
    if ( ! missing(group)) group <- jmvcore::resolveQuo(jmvcore::enquo(group))
    if (missing(data))
        data <- jmvcore::marshalData(
            parent.frame(),
            `if`( ! missing(dep), dep, NULL),
            `if`( ! missing(group), group, NULL))


    options <- gtsummaryOptions$new(
        dep = dep,
        group = group,
        alt = alt,
        varEq = varEq)

    analysis <- gtsummaryClass$new(
        options = options,
        data = data)

    analysis$run()

    analysis$results
}

