/** Client-safe helpers for CMS page upload URLs (no server imports). */

export function appendCmsPageUploadQuery(
  endpoint: string,
  input?: { fileIndex?: number; slot?: string }
): string {
  if (input?.fileIndex === undefined && !input?.slot) return endpoint
  const q = endpoint.indexOf("?")
  const path = q >= 0 ? endpoint.slice(0, q) : endpoint
  const params = new URLSearchParams(q >= 0 ? endpoint.slice(q + 1) : "")
  if (input?.fileIndex !== undefined) params.set("index", String(input.fileIndex))
  if (input?.slot) params.set("slot", input.slot)
  const qs = params.toString()
  return qs ? `${path}?${qs}` : path
}
