uiReports <-
  tabPanel("Reports",
           h3("Download report"),
           h4("Settings of report"),
           p(code("ShinyItemAnalysis"), " offers an option to download a report in HTML or PDF format. PDF report
             creation requires latest version of", a("MiKTeX", href = "https://miktex.org/howto/install-miktex",
                                                     target = "_blank"),
             "(or other TeX distribution). If you don't have the latest installation, please, use the HTML report."),
           p("There is an option to use customized settings. When checking the", strong("Customize settings"),
             "local settings will be offered and used for each selected section of the report. Otherwise, the settings
             will be taken from sections of the application. You may also include your name into the report, as well as the name
             of analyzed dataset. "),
           fluidRow(
             column(2, radioButtons(inputId = "report_format",
                                    label = "Format of report",
                                    choices = c("HTML" = "html", "PDF" = "pdf"))),
             column(2, checkboxInput(inputId = "customizeCheck",
                                     label = "Customize settings",
                                     value = FALSE)),
             column(2, textInput(inputId = "reportAuthor",
                                 label = "Author")),
             column(2, textInput(inputId = "reportDataName",
                                 label = "Dataset"))
           ),
           h4("Content of report"),
           p("Reports by default contain summary of total scores, table of standard scores, item analysis,
             distractor plots for each item and multinomial regression plots for each item. Other analyses
             can be selected below. "),
           tags$hr(),
           fluidRow(
             column(9,
                    p(strong("Validity")),
                    checkboxInput(inputId = "corr_report",
                                  label = "Correlation structure",
                                  value = FALSE),
                    conditionalPanel(condition = "input.customizeCheck",
                                     conditionalPanel(condition = "input.corr_report",
                                                      fluidPage(column(3,
                                                                       numericInput(inputId = 'corr_plot_clust_report',
                                                                                    label = 'Number of clusters',
                                                                                    value = 1,
                                                                                    min = 1,
                                                                                    max = 1)),
                                                                column(3,
                                                                       selectInput(inputId = 'corr_plot_clustmethod_report',
                                                                                   label = 'Clustering method',
                                                                                   choices = list("None" = "none",
                                                                                                  "Ward's"  = "ward.D",
                                                                                                  "Ward's n. 2" = "ward.D2",
                                                                                                  "Single" = "single",
                                                                                                  "Complete" = "complete",
                                                                                                  "Average" = "average",
                                                                                                  "McQuitty" = "mcquitty",
                                                                                                  "Median" = "median",
                                                                                                  "Centroid" = "centroid"))),
                                                                column(3,
                                                                       selectInput(inputId = 'corr_plot_type_of_corr_report',
                                                                                   label = 'Choose correlation',
                                                                                   choices = c("Polychoric" = "polychoric",
                                                                                               "Pearson" = "pearson",
                                                                                               "Spearman"  = "spearman"),
                                                                                   selected = "Polychoric" ))))),
                    checkboxInput(inputId = "predict_report",
                                  label = "Predictive validity",
                                  value = FALSE)
             )
           ),
           tags$hr(),
           conditionalPanel(condition = "input.customizeCheck",
                            fluidRow(column(9,
                                            p(strong("Difficulty/discrimination plot")),
                                            column(3,
                                                   selectInput(inputId = "DDplotDiscriminationDifficulty_report",
                                                               label = "Difficulty type:",
                                                               choices = c("Average scaled score" = "AVGSS",
                                                                           "Average item score" = "AVGS"),
                                                               selected = "AVGSS")),
                                            column(3,
                                                   selectInput(inputId = "DDplotDiscriminationSelect_report",
                                                               label = "Discrimination type:",
                                                               choices = c("ULI" = "ULI",
                                                                           "RIT" = "RIT",
                                                                           "RIR" = "RIR",
                                                                           "none" = "none"),
                                                               selected = "ULI")),
                                            conditionalPanel(condition = "input.DDplotDiscriminationSelect_report == 'ULI'",
                                                             column(3,
                                                                    sliderInput(inputId = 'DDplotNumGroupsSlider_report',
                                                                                label = 'Number of groups:',
                                                                                min = 2,
                                                                                max = 5,
                                                                                value = 3)),
                                                             column(3,
                                                                    sliderInput(inputId = "DDplotRangeSlider_report",
                                                                                label = "Which two groups to compare:",
                                                                                min = 1,
                                                                                max = 3,
                                                                                step = 1,
                                                                                value = c(1, 3))))
                            )),
                            tags$hr()
           ),
           conditionalPanel(condition = "input.customizeCheck",
                            fluidRow(column(9,
                                            p(strong("Distractors plots")),
                                            column(3,
                                                   radioButtons(inputId = 'type_combinations_distractor_report',
                                                                label = 'Type',
                                                                choices = list("Combinations", "Distractors"))),
                                            column(3,
                                                   sliderInput(inputId = 'distractor_group_report',
                                                               label = 'Number of groups:',
                                                               min = 1,
                                                               max = 5,
                                                               value = 3)),
                                            column(3,
                                                   uiOutput("distractor_report_groups_alert")))),
                            uiOutput("distractor_groups_alert_report"),
                            tags$hr()),

           fluidRow(
             column(2,
                    radioButtons(inputId = "irt_type_report",
                                 label = "IRT model selection",
                                 choices = c("None" = "none",
                                             "Rasch" = "rasch",
                                             "1PL" = "1pl",
                                             "2PL" = "2pl",
                                             "3PL" = "3pl",
                                             "4PL" = "4pl"),
                                 selected = "1pl")
             )
           ),
           tags$hr(),
           fluidRow(
             column(2,
                    p(strong("DIF method selection")),
                    checkboxInput(inputId = "histCheck",
                                  label = "None - histograms by group",
                                  value = FALSE),
                    checkboxInput(inputId = "deltaplotCheck",
                                  label = "Delta plot",
                                  value = FALSE),
                    checkboxInput(inputId = "MHCheck",
                                  label = "Mantel-Haenszel test",
                                  value = FALSE),
                    checkboxInput(inputId = "logregCheck",
                                  label = "Logistic regression",
                                  value = FALSE),
                    checkboxInput(inputId = "multiCheck",
                                  label = "Multinomial regression",
                                  value = FALSE)
             ),
             conditionalPanel(condition = "input.customizeCheck",
                              conditionalPanel(condition = "input.deltaplotCheck",
                                               column(2,
                                                      p(strong("Delta plot settings")),
                                                      radioButtons(inputId = 'type_threshold_report',
                                                                   label = 'Threshold',
                                                                   choices = list("Fixed", "Normal")),
                                                      checkboxInput(inputId = 'puri_DP_report',
                                                                    label = 'Item purification',
                                                                    value = FALSE),
                                                      conditionalPanel(
                                                        condition = "input.puri_DP_report",
                                                        selectInput(inputId = "puri_DP_type_report",
                                                                    label = "Purification method",
                                                                    choices = c("IPP1" = "IPP1",
                                                                                "IPP2" = "IPP2",
                                                                                "IPP3" = "IPP3"),
                                                                    selected = "IPP1")
                                                      )
                                               )
                              ),
                              conditionalPanel(condition = "input.MHCheck",
                                               column(2,
                                                      p(strong("Mantel-Haenszel test settings")),
                                                      # selectInput(inputId = "matching_MH_report",
                                                      #             label = "DIF matching variable",
                                                      #             choices = c("Total score" = "total_score",
                                                      #                         "Standardized total score" = "zscore"
                                                      #             ),
                                                      #             selected = "score",
                                                      #             width = "85%"),
                                                      selectInput(inputId = "correction_method_MH_report",
                                                                  label = "Correction method",
                                                                  choices = c("Benjamini-Hochberg" = "BH",
                                                                              "Benjamini-Yekutieli" = "BY",
                                                                              "Bonferroni" = "bonferroni",
                                                                              "Holm" = "holm",
                                                                              "Hochberg" = "hochberg",
                                                                              "Hommel" = "hommel",
                                                                              "None" = "none"),
                                                                  selected = "none",
                                                                  width = "85%"),
                                                      checkboxInput(inputId = 'puri_MH_report',
                                                                    label = 'Item purification',
                                                                    value = FALSE)
                                               )
                              ),
                              conditionalPanel(condition = "input.logregCheck",
                                               column(3, p(strong("Logistic regression settings")),
                                                      withMathJax(),
                                                      radioButtons(inputId = 'type_print_DIF_logistic_report',
                                                                   label = 'Type',
                                                                   choices = c("\\(H_{0}\\): No DIF vs. \\(H_{1}\\): Any DIF" = 'both',
                                                                               "\\(H_{0}\\): No DIF vs. \\(H_{1}\\): Uniform DIF" = 'udif',
                                                                               "\\(H_{0}\\): Uniform DIF vs. \\(H_{1}\\): Non-uniform DIF" = 'nudif'),
                                                                   selected = 'both'),
                                                      # selectInput(inputId = "matching_logistic_report",
                                                      #             label = "DIF matching variable",
                                                      #             choices = c("Total score" = "total_score",
                                                      #                         "Standardized total score" = "zscore"
                                                      #             ),
                                                      #             selected = "score",
                                                      #             width = "85%"),
                                                      selectInput(inputId = "correction_method_log_report",
                                                                  label = "Correction method",
                                                                  choices = c("Benjamini-Hochberg" = "BH",
                                                                              "Benjamini-Yekutieli" = "BY",
                                                                              "Bonferroni" = "bonferroni",
                                                                              "Holm" = "holm",
                                                                              "Hochberg" = "hochberg",
                                                                              "Hommel" = "hommel",
                                                                              "None" = "none"),
                                                                  selected = "none",
                                                                  width = "57%"),
                                                      checkboxInput(inputId = 'puri_LR_report',
                                                                    label = 'Item purification',
                                                                    value = FALSE)
                                               )
                              ),
                              conditionalPanel(condition = "input.multiCheck",
                                               column(3, p(strong("Multinomial regression settings")),
                                                      withMathJax(),
                                                      radioButtons(inputId = 'type_DDF_report',
                                                                   label = 'Type',
                                                                   choices = c("\\(H_{0}\\): No DIF vs. \\(H_{1}\\): Any DIF" = 'both',
                                                                               "\\(H_{0}\\): No DIF vs. \\(H_{1}\\): Uniform DIF" = 'udif',
                                                                               "\\(H_{0}\\): Uniform DIF vs. \\(H_{1}\\): Non-uniform DIF" = 'nudif'),
                                                                   selected = 'both'),
                                                      # selectInput(inputId = "matching_DDF_report",
                                                      #                    label = "DIF matching variable",
                                                      #                    choices = c("Total score" = "score",
                                                      #                                "Standardized total score" = "zscore"
                                                      #                    ),
                                                      #                    selected = "score",
                                                      #                    width = "57%"),
                                                      selectInput(inputId = "correction_method_DDF_report",
                                                                  label = "Correction method",
                                                                  choices = c("Benjamini-Hochberg" = "BH",
                                                                              "Benjamini-Yekutieli" = "BY",
                                                                              "Bonferroni" = "bonferroni",
                                                                              "Holm" = "holm",
                                                                              "Hochberg" = "hochberg",
                                                                              "Hommel" = "hommel",
                                                                              "None" = "none"),
                                                                  selected = "none",
                                                                  width = "57%"),
                                                      checkboxInput(inputId = 'puri_DDF_report',
                                                                    label = 'Item purification',
                                                                    value = FALSE)
                                               )
                              )
             )
           ),
           tags$hr(),
           radioButtons(inputId = "include_session",
                        label = "Include session info",
                        choices = c("Yes" = "yes", "No" = "no"),
                        selected = "no",
                        inline = TRUE),
           tags$hr(),
           p(strong("Recommendation: "), "Report generation can be faster and more reliable when you first check
             sections of intended contents. For example, if you wish to include a ", strong("3PL IRT"),
             " model, you can first visit ", strong("IRT models"), "section and ", strong("3PL"), " subsection."),
           uiOutput("report_na_alert"),
           br(),
           div(style = "display:inline-block", actionButton(inputId = "generate",
                                                            label = "Generate report",
                                                            class = "btn btn-primary",
                                                            icon = icon("bar-chart-o"))),
           tags$style(HTML('#download_report_button { margin-left: 25px }')),
           div(style = "display:inline-block", uiOutput("download_report_button")),
           br(),
           br(),
           br()
  )
