####################################################################

# Function to determine which bioregion a specified MPA belongs to
# 

# GENERAL FORMAT OF FILENAMES:
#   (note: the Shiny app will treat the working directory as the one where server.R is located)
#   For Shiny, filename = "../data/[variable_name]/[variable name]_[spatial_scale].csv"  
#   For prototype, filename = "CeNCOOS Data Views/dataview-prototype/data/[variable_name]/[variable name]_[spatial_scale].csv"  

findBioregion <- function(mpa_name, site_ref = "../data/MPA_list.csv") {
  
  # load reference list
  mpa_list = read_csv(site_ref)
  
  # identify MPA bioregion
  bioregion_name = mpa_list$BIOREGION[mpa_list$MPA_NAME == mpa_name] %>%
    gsub("Co", " Co", .) %>% 
    gsub("I", " I", .) %>%
    paste0(.," Bioregion")
    
  # output bioregion name
  return(bioregion_name)

  
}