{- |
Module      : Htmx.Event
Description : Enumerates htmx specific events

This module defines a type that represents events that originate from the HTMX
library itself
<https://htmx.org/reference/#events>
-}
module Htmx.Event where

import Data.Text (Text)
import Htmx.Render

-- | <https://htmx.org/reference/#events>
-- A sum type that represents possible events originating from the HTMX
-- javascript library
data HtmxEvent
    = -- | send this event to an element to abort a request
      Abort
    | -- | triggered after an AJAX request has completed processing a successful
      -- response
      AfterOnLoad
    | -- | triggered after htmx has initialized a node
      AfterProcessNode
    | -- | triggered after an AJAX request has completed
      AfterRequest
    | -- | triggered after the DOM has settled
      AfterSettle
    | -- | triggered after new content has been swapped in
      AfterSwap
    | -- | triggered before htmx disables an element or removes it from the DOM
      BeforeCleanupElement
    | -- | triggered before any response processing occurs
      BeforeOnLoad
    | -- | triggered before htmx initializes a node
      BeforeProcessNode
    | -- | triggered before an AJAX request is made
      BeforeRequest
    | -- | triggered before a swap is done, allows you to configure the swap
      BeforeSwap
    | -- | triggered just before an ajax request is sent
      BeforeSend
    | -- | triggered before the request, allows you to customize parameters,
      -- headers
      ConfigRequest
    | -- | triggered after a trigger occurs on an element, allows you to cancel
      -- (or delay) issuing the AJAX request
      Confirm
    | -- | triggered on an error during cache writing
      HistoryCacheError
    | -- | triggered on a cache miss in the history subsystem
      HistoryCacheMiss
    | -- | triggered on a unsuccessful remote retrieval
      HistoryCacheMissError
    | -- | triggered on a successful remote retrieval
      HistoryCacheMissLoad
    | -- | triggered when htmx handles a history restoration action
      HistoryRestore
    | -- | triggered before content is saved to the history cache
      BeforeHistorySave
    | -- | triggered when new content is added to the DOM
      Load
    | -- | triggered when an element refers to a SSE event in its trigger, but
      -- no parent SSE source has been defined
      NoSSESourceError
    | -- | triggered when an exception occurs during the onLoad handling in htmx
      OnLoadError
    | -- | triggered after an out of band element as been swapped in
      OobAfterSwap
    | -- | triggered before an out of band element swap is done, allows you to
      -- configure the swap
      OobBeforeSwap
    | -- | triggered when an out of band element does not have a matching ID in
      -- the current DOM
      OobErrorNoTarget
    | -- | triggered after a prompt is shown
      Prompt
    | -- | triggered after an url is pushed into history
      PushedIntoHistory
    | -- | triggered when an HTTP response error (non-200 or 300 response code)
      -- occurs
      ResponseError
    | -- | triggered when a network error prevents an HTTP request from happening
      SendError
    | -- | triggered when an error occurs with a SSE source
      SseError
    | -- | triggered when a SSE source is opened
      SseOpen
    | -- | triggered when an error occurs during the swap phase
      SwapError
    | -- | triggered when an invalid target is specified
      TargetError
    | -- | triggered when a request timeout occurs
      Timeout
    | -- | triggered before an element is validated
      ValidationValidate
    | -- | triggered when an element fails validation
      ValidationFailed
    | -- | triggered when a request is halted due to validation errors
      ValidationHalted
    | -- | triggered when an ajax request aborts
      XhrAbort
    | -- | triggered when an ajax request ends
      XhrLoadend
    | -- | triggered when an ajax request starts
      XhrLoadstart
    | -- | triggered periodically during an ajax request that supports progress
      -- events
      XhrProgress

instance Render HtmxEvent where
    render :: HtmxEvent -> Text
render = \case
        HtmxEvent
Abort -> Text
"abort"
        HtmxEvent
AfterOnLoad -> Text
"afterOnLoad"
        HtmxEvent
AfterProcessNode -> Text
"afterProcessNode"
        HtmxEvent
AfterRequest -> Text
"afterRequest"
        HtmxEvent
AfterSettle -> Text
"afterSettle"
        HtmxEvent
AfterSwap -> Text
"afterSwap"
        HtmxEvent
BeforeCleanupElement -> Text
"beforeCleanupElement"
        HtmxEvent
BeforeOnLoad -> Text
"beforeOnLoad"
        HtmxEvent
BeforeProcessNode -> Text
"beforeProcessNode"
        HtmxEvent
BeforeRequest -> Text
"beforeRequest"
        HtmxEvent
BeforeSwap -> Text
"beforeSwap"
        HtmxEvent
BeforeSend -> Text
"beforeSend"
        HtmxEvent
ConfigRequest -> Text
"configRequest"
        HtmxEvent
Confirm -> Text
"confirm"
        HtmxEvent
HistoryCacheError -> Text
"historyCacheError"
        HtmxEvent
HistoryCacheMiss -> Text
"historyCacheMiss"
        HtmxEvent
HistoryCacheMissError -> Text
"historyCacheMissError"
        HtmxEvent
HistoryCacheMissLoad -> Text
"historyCacheMissLoad"
        HtmxEvent
HistoryRestore -> Text
"historyRestore"
        HtmxEvent
BeforeHistorySave -> Text
"beforeHistorySave"
        HtmxEvent
Load -> Text
"load"
        HtmxEvent
NoSSESourceError -> Text
"noSSESourceError"
        HtmxEvent
OnLoadError -> Text
"onLoadError"
        HtmxEvent
OobAfterSwap -> Text
"oobAfterSwap"
        HtmxEvent
OobBeforeSwap -> Text
"oobBeforeSwap"
        HtmxEvent
OobErrorNoTarget -> Text
"oobErrorNoTarget"
        HtmxEvent
Prompt -> Text
"prompt"
        HtmxEvent
PushedIntoHistory -> Text
"pushedIntoHistory"
        HtmxEvent
ResponseError -> Text
"responseError"
        HtmxEvent
SendError -> Text
"sendError"
        HtmxEvent
SseError -> Text
"sseError"
        HtmxEvent
SseOpen -> Text
"sseOpen"
        HtmxEvent
SwapError -> Text
"swapError"
        HtmxEvent
TargetError -> Text
"targetError"
        HtmxEvent
Timeout -> Text
"timeout"
        HtmxEvent
ValidationValidate -> Text
"validation:validate"
        HtmxEvent
ValidationFailed -> Text
"validation:failed"
        HtmxEvent
ValidationHalted -> Text
"validation:halted"
        HtmxEvent
XhrAbort -> Text
"xhr:abort"
        HtmxEvent
XhrLoadend -> Text
"xhr:loadend"
        HtmxEvent
XhrLoadstart -> Text
"xhr:loadstart"
        HtmxEvent
XhrProgress -> Text
"xhr:progress"