# only when we have src code
# useDynLib("lavaan")

importFrom("graphics",
           "abline", "axis", "box", "hist", "pairs", "par",
           # generics
           "plot")

importFrom("methods",
           "is", "new", "slot", "slotNames", ".hasSlot",
           "setClass", "representation", "setGeneric",  
           "setRefClass", "setMethod",
           # generics,
           "show", "signature")

importFrom("stats",
           "as.formula", "complete.cases", "cor", "cov", "cov2cor", "cov.wt",
           "dnorm", "lm.fit", "na.omit", "nlminb", "optim", "pchisq",
           "plogis", "pnorm", "qchisq", "qnorm", "quantile", "rnorm", "runif",
           "sd", "terms", "uniroot", "var", "weighted.mean", "aggregate",
           # generics
           "coef", "residuals", "resid", "fitted.values", "fitted",
           "predict", "update", "anova", "vcov")

importFrom("utils",
           "combn", "modifyList", "packageDescription", "read.table",
           "str", "write.table", "write.csv", "packageVersion")

#importFrom("quadprog",
#           "solve.QP")

importFrom("mnormt",
           "dmnorm",
           "sadmvn")

importFrom("pbivnorm",
           "pbivnorm")

# AIC and friends...
if(getRversion() >= "2.13.0") {
    importFrom("stats4",AIC, BIC, logLik, nobs)
    export(logLik, nobs) # not AIC, BIC?
} else {
    importFrom("stats4",AIC, BIC, logLik)
    export(logLik, BIC, nobs) # not AIC?
}


# export ordinary functions defined in this package
export("lavaan", "cfa", "sem", "growth",
       "lavaanList", "cfaList", "semList",
       #"fsr", "twostep",
       # new name           # old name
       "lavParTable",       "lavaanify",
       "lavNames",          "lavaanNames",
       "lavParseModelString", # "parseModelString",
       "lavInspect",        "inspect",
       "lavTech",
       "lavListInspect",    "lavListTech",
       "lavResiduals",
       # utilities
       "getCov", "char2num", "cor2cov",
       # options,
       "lavOptions",

       "modindices", "modificationIndices", "modificationindices",
       "standardizedSolution", "standardizedsolution",
       "parameterEstimates", "parameterestimates",
       "parameterTable", "parametertable", "parTable", "partable",
       "varTable", "vartable",
       "fitMeasures", "fitmeasures",
       "inspectSampleCov",
       "bootstrapLavaan", "bootstrapLRT", "InformativeTesting",
       "simulateData",
       "estfun.lavaan", "lavScores",
       "lavTables",
       "lavTablesFitCp", "lavTablesFitCf", "lavTablesFitCm",
       "lavExport",
       "lavTestLRT", "lavTestWald", "lavTestScore",
       "lavMatrixRepresentation",
       "mplus2lavaan",
       "mplus2lavaan.modelSyntax",
       #"prelav",
       #"lavData",
       "lavPredict",
       "lavCor",

       # API functions

       # lav_matrix
       "lav_matrix_vec",
       "lav_matrix_vecr",
       "lav_matrix_vech",
       "lav_matrix_vechr",
       "lav_matrix_vechu",
       "lav_matrix_vechru",
       "lav_matrix_vech_idx",
       "lav_matrix_vech_row_idx",
       "lav_matrix_vech_col_idx",
       "lav_matrix_vechr_idx",
       "lav_matrix_vechu_idx",
       "lav_matrix_vechru_idx",
       "lav_matrix_diag_idx",
       "lav_matrix_diagh_idx",
       "lav_matrix_antidiag_idx",
       "lav_matrix_vech_reverse",
       "lav_matrix_vechru_reverse",
       "lav_matrix_upper2full",
       "lav_matrix_vechr_reverse",
       "lav_matrix_vechu_reverse",
       "lav_matrix_lower2full",
       "lav_matrix_duplication",
       "lav_matrix_duplication_pre",
       "lav_matrix_duplication_post",
       "lav_matrix_duplication_pre_post",
       "lav_matrix_duplication_ginv",
       "lav_matrix_duplication_ginv_pre",
       "lav_matrix_duplication_ginv_post",
       "lav_matrix_duplication_ginv_pre_post",
       "lav_matrix_commutation",
       "lav_matrix_commutation_pre",
       "lav_matrix_commutation_mn_pre",
       "lav_matrix_symmetric_sqrt",
       "lav_matrix_orthogonal_complement",
       "lav_matrix_bdiag",
       "lav_matrix_trace",
       "lav_matrix_cov",

       # lav_partable
       "lav_partable_independence",   # used by semTools!
       "lav_partable_unrestricted",
       "lav_partable_npar",
       "lav_partable_ndat",
       "lav_partable_df",
       "lav_partable_labels",
       "lav_partable_from_lm",
       "lav_partable_complete",
       "lav_partable_attributes",
       "lav_partable_merge",
       "lav_partable_constraints_def",
       "lav_partable_constraints_ceq",
       "lav_partable_constraints_ciq",

       # lav_constraints
       "lav_constraints_parse",

       # lav_func
       "lav_func_gradient_complex",
       "lav_func_gradient_simple",
       "lav_func_jacobian_complex",
       "lav_func_jacobian_simple",    # used by semTools!

       # lav_model
       "lav_model_get_parameters",
       "lav_model_set_parameters",
       "lav_model_implied",
       "lav_model_vcov_se",

       # deprecated functions
       "vech", "vech.reverse", "vechru", "vechru.reverse", "lower2full",
       "vechr", "vechr.reverse", "vechu", "vechu.reverse", "upper2full",
       "duplicationMatrix", "commutationMatrix", "sqrtSymmetricMatrix"
      )

# export Classes
exportClasses(
              "lavaan",
              "lavaanList"
             )

# export Methods
exportMethods(
              "predict",
              "update",
              "anova",
              "coef",
              "residuals", "resid",
              "vcov",
              "logLik",
              "fitted.values", "fitted",
              "summary"
             )

S3method(print, lavaan.data.frame)
S3method(print, lavaan.list)
S3method(print, lavaan.matrix)
S3method(print, lavaan.matrix.symmetric)
S3method(print, lavaan.vector)
S3method(print, lavaan.parameterEstimates)
S3method(print, prelav)
S3method(print, lavaan.fsr)
S3method(summary, lavaan.fsr)
S3method(pairs, lavaan)
S3method(print, InformativeTesting)
S3method(plot, InformativeTesting)
S3method(print, lavaan.tables.fit.Cf)
S3method(print, lavaan.tables.fit.Cp)
S3method(print, lavaan.tables.fit.Cm)
S3method(inspect,    lavaan)
S3method(inspect,    lavaanList)
S3method(lavInspect, lavaan)
S3method(lavTech,    lavaan)
S3method(lavInspect, lavaanList)
S3method(lavTech,    lavaanList)
if(getRversion() >= "3.6.0") {
    S3method(sandwich::estfun, lavaan)
}
