# UI

theme <- bs_theme(
  version = 4,
  bootswatch = "lumen",
  "font-size-base" = "0.75rem"
)

ui <- fluidPage(
  useShinyjs(),
  tags$style(HTML("
    .lnlt { font-size: 14px !important; padding: 5px !important; margin-left: 50px !important; }
    .tabbable > .nav > li > a[data-value='Input Files'] {background-color: rgba(0, 255, 0, 0.6); color: '#222';}
    .tabbable > .nav > li > a[data-value='Global Changes'] {background-color: rgba(0, 255, 0, 0.5); color: '#222';}
    .tabbable > .nav > li > a[data-value='Transects'] {background-color: rgba(0, 255, 0, 0.4); color: '#222';}
    .tabbable > .nav > li > a[data-value='Observations'] {background-color: rgba(0, 255, 0, 0.4); color: '#222';}
    .tabbable > .nav > li > a[data-value='User Transects'] {background-color: rgba(0, 139, 139, 0.5); color: '#222';}
    .tabbable > .nav > li > a[data-value='User Observations'] {background-color: rgba(0, 139, 139, 0.5); color: '#222';}
    .tabbable > .nav > li > a[data-value='NPPSD Transects'] {background-color: rgba(255, 140, 0, 0.5); color: '#222';}
    .tabbable > .nav > li > a[data-value='NPPSD Observations'] {background-color: rgba(255, 140, 0, 0.5); color: '#222';}
    .tabbable > .nav > li > a[data-value='Species Summary'] {background-color: rgba(64, 64, 64, 0.25); color: '#222';}
    .tabbable > .nav > li > a[data-value='Map'] {background-color: rgba(64, 64, 64, 0.25); color: '#222';}
  ")),
  shinyjs::extendShinyjs(
    text = "shinyjs.startOver = function() { location.reload(); }",
    functions = c("startOver")
  ),
  theme = theme,
  title = "Process Raw Seabird Files",
  tabsetPanel(
    type = "tabs",
    tabPanel(
      "Input Files",
      fluidRow(
        tags$h3(style = "padding-left: 15px;", "Metadata")
      ),
      fluidRow(
        column(
          4,
          selectInput(
            inputId = "modified_platform_type",
            label = "Modified Platform Type",
            selected = "Small Boat",
            choices = c(
              "Aircraft", "Land", "Large Boat",
              "Small Boat", "Fixed"
            )
          )
        ),
        column(
          4,
          selectInput(
            inputId = "modified_survey_type",
            label = "Modified Survey Type",
            selected = "Pelagic Survey-Strip",
            choices = c(
              "Pelagic Survey-Strip", "Pelagic Survey-Distance",
              "Station", "Off Transect Observation"
            )
          )
        ),
        column(
          4,
          selectInput(
            inputId = "fly_bird_method",
            label = "Fly Bird Method",
            selected = "Continuous",
            choices = c("Continuous", "Snapshot", "Unk")
          )
        )
      ),
      fluidRow(
        column(
          4,
          textInput(
            inputId = "source",
            label = "Source",
            placeholder = "Name of person submitting data",
            width = "80%"
          )
        ),
        column(
          4,
          selectInput(
            inputId = "survey_target",
            label = "Survey Target",
            selected = "All",
            choices = c(
              "All", "Marine Birds", "Marine Mammals", "Other"
            ),
            width = "80%"
          ),
          textInput(
            inputId = "survey_target_other",
            label = NULL,
            placeholder = "Other survey target",
            width = "80%"
          )
        ),
        column(
          4,
          sliderInput(
            inputId = "nps_split_km",
            label = "User-defined split length (km)",
            min = 0, max = 10, value = 1.0, step = 0.5
          )
        )
      ),
      fluidRow(
        column(
          4,
          textAreaInput(
            inputId = "pi_credit",
            label = "PI Credit",
            width = "100%",
            # cols = 500,
            # rows = 2,
            resize = "both"
          )
        ),
        column(
          4,
          textInput(
            inputId = "max_point_interval_seconds",
            label = "Maximum interval between points (seconds)",
            width = "80%",
            value = 120
          )
        ),
        column(
          4,
          fluidRow(
            checkboxInput(
              inputId = "use_nps_length_for_nppsd",
              label = "Use split length for NPPSD (normally 3.3 km)",
              value = FALSE
            ),
          )
        )
      ),
      fluidRow(
        column(
          4,
          fileInput(
            inputId = "input_files",
            label = h3("Data Files"),
            multiple = TRUE,
            accept = c(
              "text/csv",
              "text/comma-separated-values,text/plain",
              ".csv",
              "application/vnd.ms-excel",
              ".xlsx"
            )
          )
        ),
        column(
          4,
          fileInput(
            inputId = "optional_fields_json_file",
            label = h3("Optional Fields JSON File"),
            multiple = FALSE,
            accept = c(
              "application/json",
              ".json"
            )
          )
        ),
        column(
          4,
          fileInput(
            inputId = "species_json_file",
            label = h3("Species List JSON File"),
            multiple = FALSE,
            accept = c(
              "application/json",
              ".json"
            )
          )
        )
      ),
      fluidRow(
        column(
          4,
          tableOutput("file_list")
        ),
        column(
          4,
          tableOutput("optional_fields_count")
        ),
        column(
          4,
          tableOutput("valid_species_count")
        )
      ),
      fluidRow(
        column(
          4,
          fileInput(
            inputId = "nppsd_species_crosswalk_file",
            label = h3("NPPSD Species Crosswalk CSV (optional)"),
            multiple = FALSE,
            accept = c(
              "text/csv",
              "text/comma-separated-values,text/plain",
              ".csv"
            )
          )
        )
      ),
      fluidRow(
        column(
          6,
          actionButton("process_data_button",
            "Read Data",
            class = "btn-success"
          ),
          offset = 6
        )
      ),
      fluidRow(
        div(style = "margin: 20px;"),
        column(
          6,
          actionButton("refresh",
            "Start Over",
            class = "btn-warning"
          ),
          offset = 6
        )
      ),
      fluidRow(
        column(
          12,
          h3(style = "text-align: center", "Summary")
        )
      ),
      fluidRow(
        column(
          12,
          h3("Transects Summary"),
          verbatimTextOutput("transects_summary")
        )
      ),
      fluidRow(
        column(
          12,
          h3("Observations Summary"),
          verbatimTextOutput("obs_summary")
        )
      ),
    ),
    tabPanel(
      "Global Changes",
      fluidRow(
        column(
          6,
          h4("Automatically Update"),
          checkboxInput(
            "update_after_global_change",
            "Automatically update data when changing values",
            value = FALSE
          )
        )
      ),
      fluidRow(
        column(
          6,
          h4("Unique text values"),
          DT::dataTableOutput("unique_text")
        ),
        column(
          6,
          h4("NPPSD Species Crosswalk"),
          DT::dataTableOutput("nppsd_species_crosswalk")
        )
      ),
      fluidRow(
        column(2,
          offset = 8,
          downloadButton("dl_nppsd_species_crosswalk", "Download Crosswalk")
        )
      ),
      fluidRow(
        column(
          6,
          h4("Unique numeric values"),
          DT::dataTableOutput("unique_integer")
        )
      ),
    ),
    tabPanel(
      "Transects",
      fluidRow(
        column(
          12,
          h3("Data"),
          DT::dataTableOutput("raw_transects")
        )
      ),
      fluidRow(
        column(2,
          offset = 5,
          downloadButton("dl_transects", "Download Edited Data")
        )
      ),
      fluidRow(
        column(
          12,
          h3("Edited rows (original content)"),
          tableOutput("original_transects")
        )
      ),
      fluidRow(
        column(2,
          offset = 5,
          downloadButton("dl_original_transects", "Download Original Rows")
        )
      )
    ),
    tabPanel(
      "Observations",
      fluidRow(
        column(
          12,
          DT::dataTableOutput("raw_obs")
        )
      ),
      fluidRow(
        column(2,
          offset = 5,
          downloadButton("dl_obs", "Download Edited Data")
        )
      ),
      fluidRow(
        column(
          12,
          h3("Edited rows (original content)"),
          tableOutput("original_obs")
        )
      ),
      fluidRow(
        column(2,
          offset = 5,
          downloadButton("dl_original_obs", "Download Original Data")
        )
      )
    ),
    tabPanel(
      "User Transects",
      fluidRow(
        column(
          12,
          h3("Data"),
          DT::dataTableOutput("nps_transects")
        )
      ),
      fluidRow(
        column(2,
          offset = 5,
          downloadButton("dl_nps_transects", "Download User Transect Data")
        )
      )
    ),
    tabPanel(
      "User Observations",
      fluidRow(
        column(
          12,
          DT::dataTableOutput("nps_obs")
        )
      ),
      fluidRow(
        column(2,
          offset = 5,
          downloadButton("dl_nps_obs", "Download User Observation Data")
        )
      )
    ),
    tabPanel(
      "NPPSD Transects",
      fluidRow(
        column(
          12,
          DT::dataTableOutput("tbl_location")
        )
      ),
      fluidRow(
        column(2,
          offset = 5,
          downloadButton("dl_tbl_location", "Download NPPSD Transect Data")
        )
      )
    ),
    tabPanel(
      "NPPSD Observations",
      fluidRow(
        column(
          12,
          DT::dataTableOutput("tbl_data_obs")
        )
      ),
      fluidRow(
        column(2,
          offset = 5,
          downloadButton("dl_tbl_data_obs", "Download NPPSD Observation Data")
        )
      )
    ),
    tabPanel(
      "Species Summary",
      fluidRow(
        column(8,
          offset = 2,
          h3("Species totals, observations"),
          # DT::dataTableOutput("spp_summary")
          uiOutput("spp_summary")
        )
      ),
      fluidRow(
        column(2,
          offset = 5,
          downloadButton("dl_spp_summary", "Download species summary")
        )
      )
    ),
    tabPanel(
      "Map",
      tags$style(
        type = "text/css",
        "#tracks_map { height: calc(100vh - 180px) !important; }"
      ),
      fluidRow(
        column(10,
          offset = 1,
          h3("Tracks")
        )
      ),
      fluidRow(
        column(10,
          offset = 1,
          leafletOutput("tracks_map")
        )
      ),
      fluidRow(
        column(2,
          offset = 5,
          downloadButton("dl_transects_shp", "Download geopackage")
        )
      )
    )
  ),
  hr(),
  tags$footer(
    style = "text-align: center;",
    HTML('Version 2.1.3<br/>Copyright © 2022, <a href="https://www.abrinc.com/">ABR, Inc.</a>')
  )
)

# vim: set ft=r fenc=utf-8 tw=80 ts=2 sw=2 sts=2:
