export { Form, useAction, wrapComponentWithLoader, submitAction } from "./clientHelpers"
export { nanoRemix } from "./nanoRemix"

export type Loader<Data extends object> = (
  req: Request,
  params: Record<string, string>
) => Promise<Data> | Data
export type LoaderProps<T> = T extends Loader<infer R> ? Awaited<R> : never

export type Action<Data = unknown> = (req: Request, params: any) => Promise<Response | Data>

// I'd rather have used HTMLLinkElement and HTMLScriptElement, but onload didn't work with those because
// it expected a function, not a string.
type LinkAttributes = {
  rel?: string
  href?: string
  type?: string
  media?: string
  sizes?: string
  hreflang?: string
  crossOrigin?: HTMLLinkElement["crossOrigin"]
  integrity?: string
  referrerPolicy?: HTMLLinkElement["referrerPolicy"]
  onload?: string
  onerror?: string
}

type ScriptAttributes = {
  src?: string
  type?: string
  async?: boolean
  defer?: boolean
  crossOrigin?: HTMLScriptElement["crossOrigin"]
  integrity?: string
  referrerPolicy?: HTMLScriptElement["referrerPolicy"]
  onload?: string
  onerror?: string
}

export type Head = {
  title?: string
  links?: LinkAttributes[]
  scripts?: ScriptAttributes[]
}
