
filterUI <- function(i, data_reactive) {
  filter_id <- function(id) paste0(id, "_", i)
  # ns <- function(id) paste0(NS(id), "_", i)
  column_choices <- if (!is.null(data_reactive)) names(data_reactive) else ""
  fluidRow(
    column(3,
      selectInput(filter_id("col"), "Column", choices = column_choices)
    ),
    column(2,
      selectInput(filter_id("type"), "Format:",
                  choices = c("numeric", "Date", "character"),
                  selected = character(0))
    ),
    column(3, uiOutput(filter_id("cond_ui"))
    )#,
    # column(4, uiOutput(ns("dynamic_ui"))
    # )
  )
}

# filterUI <- function(id, df) {
#   ns <- NS(id)

#   fluidRow(
#     column(3,
#       selectInput(ns("col"), "Column", choices = names(df))
#     ),
#     column(2,
#       selectInput(ns("type"), "Type",
#                   choices = c("numeric", "Date", "character"))
#     ),
#     column(3,
#       uiOutput(ns("cond_ui"))
#     ),
#     column(4,
#       uiOutput(ns("dynamic_ui"))
#     )
#   )
# }

format_vector <- function(x) {
  if (length(x) == 1) {
    shQuote(x)  # single value → 'element1'
  } else {
    paste0("c(", paste(shQuote(x), collapse = ", "), ")")  # multiple values
  }
}

is_named_char <- function(x) {
  is.character(x) && !is.null(names(x)) && all(nzchar(names(x)))
}

make_clean_code <- function(inner_code) {
  paste0("df <- d4h_clean(data = df", inner_code, ")")
}
