;; Reference data for sx-docs pages
;; Auto-generated from sx/content/pages.py

(define request-attrs
  (list
    (list "sx-get" "Issue a GET request to the given URL" true)
    (list "sx-post" "Issue a POST request to the given URL" true)
    (list "sx-put" "Issue a PUT request to the given URL" true)
    (list "sx-delete" "Issue a DELETE request to the given URL" true)
    (list "sx-patch" "Issue a PATCH request to the given URL" true)
  ))

(define behavior-attrs
  (list
    (list "sx-trigger" "Specifies the event that triggers the request. Modifiers: once, changed, delay:<time>, from:<selector>, intersect, revealed, load, every:<time>" true)
    (list "sx-target" "CSS selector for the target element to update" true)
    (list "sx-swap" "How to swap the response: outerHTML, innerHTML, afterend, beforeend, afterbegin, beforebegin, delete, none" true)
    (list "sx-swap-oob" "Out-of-band swap — update elements elsewhere in the DOM by ID" true)
    (list "sx-select" "CSS selector to pick a fragment from the response" true)
    (list "sx-confirm" "Shows a confirmation dialog before issuing the request" true)
    (list "sx-push-url" "Push the request URL into the browser location bar" true)
    (list "sx-sync" "Synchronization strategy for requests from this element" true)
    (list "sx-encoding" "Set the encoding for the request (e.g. multipart/form-data)" true)
    (list "sx-headers" "Add headers to the request as a JSON string" true)
    (list "sx-include" "Include additional element values in the request" true)
    (list "sx-vals" "Add values to the request as a JSON string" true)
    (list "sx-media" "Only enable this element when the media query matches" true)
    (list "sx-disable" "Disable sx processing on this element and its children" true)
    (list "sx-on:*" "Inline event handler — e.g. sx-on:click runs JavaScript on event" true)
    (list "sx-boost" "Progressively enhance all links and forms in a container with AJAX navigation. Value can be a target selector." true)
    (list "sx-preload" "Preload content on hover/focus for instant response on click" true)
    (list "sx-preserve" "Preserve element across swaps — keeps DOM state, event listeners, and scroll position" true)
    (list "sx-indicator" "CSS selector for a loading indicator element to show/hide during requests" true)
    (list "sx-validate" "Run browser constraint validation (or custom validator) before sending the request" true)
    (list "sx-ignore" "Ignore element and its subtree during morph/swap — no updates applied" true)
    (list "sx-optimistic" "Apply optimistic UI updates immediately, reconcile on server response" true)
    (list "sx-replace-url" "Replace the current URL in the browser location bar (replaceState instead of pushState)" true)
    (list "sx-disabled-elt" "CSS selector for elements to disable during the request" true)
    (list "sx-prompt" "Show a prompt dialog before the request — input is sent as SX-Prompt header" true)
    (list "sx-params" "Filter which form parameters are sent: \"*\" (all), \"none\", \"not x,y\", or \"x,y\"" true)
    (list "sx-sse" "Connect to a Server-Sent Events endpoint for real-time server push" true)
    (list "sx-sse-swap" "SSE event name to listen for and swap into the target (default: message)" true)
  ))

(define sx-unique-attrs
  (list
    (list "sx-retry" "Exponential backoff retry on request failure" true)
    (list "data-sx" "Client-side rendering — evaluate the sx source in this attribute and render into the element" true)
    (list "data-sx-env" "Provide environment variables as JSON for data-sx rendering" true)
  ))

(define request-headers
  (list
    (list "SX-Request" "true" "Set on every sx-initiated request")
    (list "SX-Current-URL" "URL" "The current URL of the browser")
    (list "SX-Target" "CSS selector" "The target element for the response")
    (list "SX-Components" "~comp1,~comp2,..." "Component names the client already has cached")
    (list "SX-Css" "hash or class list" "CSS classes/hash the client already has")
    (list "SX-History-Restore" "true" "Set when restoring from browser history")
    (list "SX-Css-Hash" "8-char hash" "Hash of the client's known CSS class set")
    (list "SX-Prompt" "string" "Value entered by the user in a window.prompt dialog (from sx-prompt)")
  ))

(define response-headers
  (list
    (list "SX-Css-Hash" "8-char hash" "Hash of the cumulative CSS class set after this response")
    (list "SX-Css-Add" "class1,class2,..." "New CSS classes added by this response")
    (list "SX-Trigger" "event or JSON" "Dispatch custom event(s) on the target element after the request")
    (list "SX-Trigger-After-Swap" "event or JSON" "Dispatch custom event(s) after the swap completes")
    (list "SX-Trigger-After-Settle" "event or JSON" "Dispatch custom event(s) after the DOM settles")
    (list "SX-Retarget" "CSS selector" "Override the target element for this response")
    (list "SX-Reswap" "swap strategy" "Override the swap strategy for this response")
    (list "SX-Redirect" "URL" "Redirect the browser to a new URL (full navigation)")
    (list "SX-Refresh" "true" "Reload the current page")
    (list "SX-Location" "URL or JSON" "Client-side navigation — fetch URL, swap into #main-panel, pushState")
    (list "SX-Replace-Url" "URL" "Replace the current URL using replaceState (server-side override)")
  ))

(define events-list
  (list
    (list "sx:beforeRequest" "Fired before an sx request is issued. Call preventDefault() to cancel.")
    (list "sx:afterRequest" "Fired after a successful sx response is received.")
    (list "sx:afterSwap" "Fired after the response has been swapped into the DOM.")
    (list "sx:responseError" "Fired on HTTP error responses (4xx, 5xx).")
    (list "sx:requestError" "Fired when the request fails to send (network error, abort).")
    (list "sx:validationFailed" "Fired when sx-validate blocks a request due to invalid form data.")
    (list "sx:clientRoute" "Fired after successful client-side routing (no server request).")
    (list "sx:sseOpen" "Fired when an SSE connection is established.")
    (list "sx:sseMessage" "Fired when an SSE message is received and swapped.")
    (list "sx:sseError" "Fired when an SSE connection encounters an error.")
  ))

(define js-api-list
  (list
    (list "Sx.parse(text)" "Parse a single s-expression from text")
    (list "Sx.parseAll(text)" "Parse multiple s-expressions from text")
    (list "Sx.eval(expr, env)" "Evaluate an expression in the given environment")
    (list "Sx.render(expr, env)" "Render an expression to DOM nodes")
    (list "Sx.renderToString(expr, env)" "Render an expression to an HTML string (requires sx-test.js)")
    (list "Sx.renderComponent(name, kwargs, env)" "Render a named component with keyword arguments")
    (list "Sx.loadComponents(text)" "Parse and register component definitions")
    (list "Sx.getEnv()" "Get the current component environment")
    (list "Sx.mount(target, expr, env)" "Mount an expression into a DOM element")
    (list "Sx.update(target, newEnv)" "Re-render an element with new environment data")
    (list "Sx.hydrate(root)" "Find and render all [data-sx] elements within root")
    (list "SxEngine.process(root)" "Process all sx attributes in the DOM subtree")
    (list "SxEngine.executeRequest(elt, verb, url)" "Programmatically trigger an sx request")
    (list "SxEngine.config.globalViewTransitions" "Enable View Transitions API globally for all swaps (default: false)")
  ))

(define primitives-by-category
  {:Arithmetic (list "+" "-" "*" "/" "mod" "sqrt" "pow" "abs" "floor" "ceil" "round" "min" "max")
   :Comparison (list "=" "!=" "<" ">" "<=" ">=")
   :Logic (list "not" "and" "or")
   :String (list "str" "upper" "lower" "trim" "split" "join" "index-of" "starts-with?" "ends-with?" "replace" "substring")
   :Collections (list "list" "dict" "len" "first" "last" "rest" "nth" "cons" "append" "keys" "vals" "merge" "assoc" "range" "concat" "reverse" "sort" "flatten" "zip")
   :Higher-Order (list "map" "map-indexed" "filter" "reduce" "some" "every?" "for-each")
   :Predicates (list "nil?" "number?" "string?" "list?" "dict?" "empty?" "contains?" "odd?" "even?" "zero?")
   :Type-Conversion (list "int" "float" "number")
  })
