;; Navigation data and section-nav component for sx docs.
;; Replaces Python nav tuples from content/pages.py and _nav_items_sx() from utils.py.
;; @css aria-selected:bg-violet-200 aria-selected:text-violet-900

(define docs-nav-items (list
  (dict :label "Introduction" :href "/docs/introduction")
  (dict :label "Getting Started" :href "/docs/getting-started")
  (dict :label "Components" :href "/docs/components")
  (dict :label "Evaluator" :href "/docs/evaluator")
  (dict :label "Primitives" :href "/docs/primitives")
  (dict :label "CSS" :href "/docs/css")
  (dict :label "Server Rendering" :href "/docs/server-rendering")))

(define reference-nav-items (list
  (dict :label "Attributes" :href "/reference/attributes")
  (dict :label "Headers" :href "/reference/headers")
  (dict :label "Events" :href "/reference/events")
  (dict :label "JS API" :href "/reference/js-api")))

(define protocols-nav-items (list
  (dict :label "Wire Format" :href "/protocols/wire-format")
  (dict :label "Fragments" :href "/protocols/fragments")
  (dict :label "Resolver I/O" :href "/protocols/resolver-io")
  (dict :label "Internal Services" :href "/protocols/internal-services")
  (dict :label "ActivityPub" :href "/protocols/activitypub")
  (dict :label "Future" :href "/protocols/future")))

(define examples-nav-items (list
  (dict :label "Click to Load" :href "/examples/click-to-load")
  (dict :label "Form Submission" :href "/examples/form-submission")
  (dict :label "Polling" :href "/examples/polling")
  (dict :label "Delete Row" :href "/examples/delete-row")
  (dict :label "Inline Edit" :href "/examples/inline-edit")
  (dict :label "OOB Swaps" :href "/examples/oob-swaps")
  (dict :label "Lazy Loading" :href "/examples/lazy-loading")
  (dict :label "Infinite Scroll" :href "/examples/infinite-scroll")
  (dict :label "Progress Bar" :href "/examples/progress-bar")
  (dict :label "Active Search" :href "/examples/active-search")
  (dict :label "Inline Validation" :href "/examples/inline-validation")
  (dict :label "Value Select" :href "/examples/value-select")
  (dict :label "Reset on Submit" :href "/examples/reset-on-submit")
  (dict :label "Edit Row" :href "/examples/edit-row")
  (dict :label "Bulk Update" :href "/examples/bulk-update")
  (dict :label "Swap Positions" :href "/examples/swap-positions")
  (dict :label "Select Filter" :href "/examples/select-filter")
  (dict :label "Tabs" :href "/examples/tabs")
  (dict :label "Animations" :href "/examples/animations")
  (dict :label "Dialogs" :href "/examples/dialogs")
  (dict :label "Keyboard Shortcuts" :href "/examples/keyboard-shortcuts")
  (dict :label "PUT / PATCH" :href "/examples/put-patch")
  (dict :label "JSON Encoding" :href "/examples/json-encoding")
  (dict :label "Vals & Headers" :href "/examples/vals-and-headers")
  (dict :label "Loading States" :href "/examples/loading-states")
  (dict :label "Request Abort" :href "/examples/sync-replace")
  (dict :label "Retry" :href "/examples/retry")))

(define essays-nav-items (list
  (dict :label "sx sucks" :href "/essays/sx-sucks")
  (dict :label "Why S-Expressions" :href "/essays/why-sexps")
  (dict :label "The htmx/React Hybrid" :href "/essays/htmx-react-hybrid")
  (dict :label "On-Demand CSS" :href "/essays/on-demand-css")
  (dict :label "Client Reactivity" :href "/essays/client-reactivity")
  (dict :label "SX Native" :href "/essays/sx-native")
  (dict :label "The SX Manifesto" :href "/essays/sx-manifesto")
  (dict :label "Tail-Call Optimization" :href "/essays/tail-call-optimization")
  (dict :label "Continuations" :href "/essays/continuations")
  (dict :label "Godel, Escher, Bach" :href "/essays/godel-escher-bach")
  (dict :label "The Reflexive Web" :href "/essays/reflexive-web")))

(define specs-nav-items (list
  (dict :label "Architecture" :href "/specs/")
  (dict :label "Core" :href "/specs/core")
  (dict :label "Parser" :href "/specs/parser")
  (dict :label "Evaluator" :href "/specs/evaluator")
  (dict :label "Primitives" :href "/specs/primitives")
  (dict :label "Renderer" :href "/specs/renderer")
  (dict :label "Adapters" :href "/specs/adapters")
  (dict :label "DOM Adapter" :href "/specs/adapter-dom")
  (dict :label "HTML Adapter" :href "/specs/adapter-html")
  (dict :label "SX Wire Adapter" :href "/specs/adapter-sx")
  (dict :label "SxEngine" :href "/specs/engine")))

;; Find the current nav label for a slug by matching href suffix.
;; Returns the label string or nil if no match.
(define find-current
  (fn (items slug)
    (when slug
      (some (fn (item)
        (when (ends-with? (get item "href") slug)
          (get item "label")))
        items))))

;; Generic section nav — builds nav links from a list of items.
;; Replaces _nav_items_sx() and all section-specific nav builders in utils.py.
(defcomp ~section-nav (&key items current)
  (<> (map (fn (item)
    (~nav-link
      :href (get item "href")
      :label (get item "label")
      :is-selected (when (= (get item "label") current) "true")
      :select-colours "aria-selected:bg-violet-200 aria-selected:text-violet-900"))
    items)))
