

get_dashboard_header = function() {
  shinydashboardPlus::dashboardHeader(
    title = "Druggable genome",
    titleWidth = "300pt",
    leftUi = shiny::tagList(),
    disable = FALSE
  )
}

get_dashboard_controlbar = function() {
  shinydashboardPlus::dashboardControlbar(
    id = "controlbar",
    collapsed = FALSE,
    shinydashboardPlus::controlbarMenu(
      id = "controlbarMenu",
      selected = "Filter Nodes",
      #selected = "Network",
      shinydashboardPlus::controlbarItem(
        # "Threshold",
        "Filter Nodes",
        shinyWidgets::sliderTextInput(
         inputId = "pvalue",
         label = "Filter edges by p-value (below):",
         choices = c( 5e-08,1e-09,1e-10,1e-11,1e-12,1e-13,0),
         selected = c(5e-08, 0),
         grid = TRUE,
         width = "100%"
         ),
        shiny::checkboxInput(
          inputId = "add_drugs",
          label = "Add drugs",
          value = FALSE)
      ),
#     shinydashboardPlus::controlbarItem(
#       "Network",
#       shiny::checkboxInput("hide_labels", "Hide the labels", value = FALSE),
#       htmltools::h4(tags$b("customize color")),
#       #div(
#       shiny::uiOutput("ui_color", style = "height: 300px;"),
#       # style="height: 450px; overflow-y: scroll;"),
#       htmltools::h4(tags$b("customize shape")),
#       shiny::uiOutput("ui_shape")
#     ),
    ),
    width = 700,
    skin = "light"
  )
}

get_dashboard_page = function(browse_height) {

  shinydashboardPlus::dashboardPage(
    get_dashboard_header(),
    ## Sidebar ====
    shinydashboardPlus::dashboardSidebar(
      width = "340pt",
      disable = FALSE,
      minified = FALSE,
      # sidebarMenu(
        # menuItem("Network", tabName = "Network", icon = icon("dashboard")),
      DT::dataTableOutput("table") %>% 
        shinyhelper::helper(type = "markdown",
                            title = "Input table",
                            content = "helper_input_table",
                            size = "m",
                            style = "margin-right: 5px;"), 
      htmltools::div(id = "check_box",
        shiny::checkboxGroupInput("inCheckboxGroup1", "Selected Gene:"),
        shiny::checkboxGroupInput("inCheckboxGroup2", "Selected Phenotype:",
                                  choiceValues = c("Bicarbonate_Max", "Chloride_BSP_Max"),
                                  choiceNames = c("bicarbonate (maximum)", "chloride (maximum)"),
                                  selected = c("Bicarbonate_Max", "Chloride_BSP_Max"))

        ),
        fluidRow(#column(1),
                 shiny::column(6, htmltools::div(align = "center", shiny::actionButton('refresh', 'Unselect', 
                                       icon = htmltools::tags$i(class = "fa fa-refresh", 
                                                     style="font-size: 10px;"),
                                       class = "btn-secondary"))),
                 shiny::column(6, htmltools::div(align = "center", shiny::actionButton("goButton", "Submit", 
                                       icon = htmltools::tags$i(class = "far fa-play-circle",
                                                     style="font-size: 10px"), 
                                       class = "btn-success"))))
    ),
    
    shinydashboard::dashboardBody(
      htmltools::tags$head(htmltools::tags$style(htmltools::HTML('.modal-lg {
                                width: 1200px;
                                }
                                #abs_1 {background-color: white;;}
                                #clear{background-color: turquoise3;;}
                                #disease{background-color: turquoise3;;}
                                #bleach{background-color: turquoise3;;}
                                #regionSelect{background-color: turquoise3;;}
                                #yearSelect{background-color: turquoise3;;}
                                #speciesSelect{background-color: turquoise3;;}
                                '))),
      htmltools::includeCSS("www/style.css"),
      shinyWidgets::useSweetAlert(),
      shinybrowser::detect(),
      rintrojs::introjsUI(),
      
      #shiny::fillPage(

    shiny::tabsetPanel(id = "tabs_nodeinfo",
                                    selected = "SigmaJS",
                                    #selected = "visNetwork",
               #shiny::tabPanel(title = "Significant signals with group",
               #         shiny::uiOutput("ui_signal_2")),
                shiny::tabPanel(title = "Manhattan Plot",
                         shiny::uiOutput("ui_manh_filter"),
                         plotly::plotlyOutput("manhattan", height = "550px")),
               #shiny::tabPanel(title = "visNetwork",
               #         shiny::uiOutput("network"),
               #         shiny::absolutePanel(id = "vis_groupinfo", class = "panel panel-default", fixed = TRUE,
               #                       draggable = TRUE, top = 150, left = "auto", right = 20, bottom = "auto", width = "auto", height = "auto",
               #                       shiny::uiOutput("ui_groups")
               #         )),

	shiny::tabPanel(title = "SigmaJS",
	  htmltools::br(),
	  sigmagraph::sigmagraphOutput('kg', height = '600px'),
          shiny::absolutePanel(id = "legend", class = "panel panel-default",
   	    fixed = TRUE, draggable = TRUE, top = 60,
   	    left = "auto", right = 20, bottom = "auto",
   	    width = 150, height = "auto",
            shiny::plotOutput("gglegend", height = '500px')))),
    #                      shiny::uiOutput("ui_signal_2")),
    #             shiny::tabPanel(title = "Network",
    #                      htmltools::br(),
    #                      shiny::uiOutput("network"))),
      
    
    
    shinyBS::bsModal(
      id = "instruction", title = "Instruction", trigger = FALSE,
      size = "small",
      htmltools::p('1')
    )),
    controlbar = get_dashboard_controlbar()
  )
}


htmlLegend <- function(df){
  tr_legends <- ""
  for(i in 1:nrow(df)){
    td <- sprintf('<tr><td> </td></tr><tr><td class="dot" style="color: %s;"><i class="fas fa-circle"></i></td></tr>
    <tr><td>%s</td></tr>', df$color[i], df$group[i])
    tr_legends <- paste0(tr_legends, td)
  }



  htmltools::HTML(sprintf(
      '
         <div class="table-container">
          <table id = "tb-legend">
          %s
        </table>
      </div>',
      tr_legends
    ))
}

