#' @title idfeez
#' @description This function allows you to identify location in which EEZ from a numeric vector.
#' @param lon A numeric vector of longitudes.
#' @param lat A numeric vector of latitudes.
#' @param ac logical. If \code{TRUE} will return full name of EEZ.
#' @export
#' @import sf
#' @examples
#' idfeez(141,23)

idfeez <- function(lon, lat, ac = TRUE) {
  # Convert directly without unnecessary sf reloading
  sptacsat <- st_as_sf(data.frame(x = as.numeric(lon), y = as.numeric(lat)), 
                       coords = c("x", "y"), crs = 4326)
  
  # Intesect with pre-computed eez_sf from sysdata.rda
  idx_list <- st_intersects(sptacsat, eez_sf)
  
  res <- sapply(idx_list, function(i) {
    if (length(i) > 0) {
      if (ac) {
        as.character(eez_sf$EEZ[i[1]])
      } else {
        as.character(eez_sf$ISO_3digit[i[1]])
      }
    } else {
      NA_character_
    }
  })
  
  return(res)
}
