#' @title idfocean
#' @description Return The Pacific Ocean(PAC), Indian Ocean(IND) or Atlantic Ocean(ATL) of your coordinate.
#' @import sf
#' @param lon A numeric vector of longitudes.
#' @param lat A numeric vector of latitudes.
#' @return A character vector of the ocean ("PAC", "IND", "ATL", or "-") for each coordinate.
#' @export
#' @examples
#' idfocean(125,20)
#' idfocean(c(125, 40), c(20, -10))

idfocean <- function(lon, lat){
  d <- data.frame(x = as.numeric(lon), y = as.numeric(lat))
  d <- st_as_sf(d, coords = c("x", "y"), crs = 4326)
  
  # intersect with the globally pre-computed glb_sf (loaded via sysdata.rda)
  idx <- st_intersects(d, glb_sf)
  
  # Ensure we only pick 1 ocean per point, even if points lie perfectly on a boundary
  res <- sapply(idx, function(i) {
    if (length(i) > 0) {
      as.character(glb_sf$name[i[1]])
    } else {
      "-"
    }
  })
  
  return(res)
}
