;; SX docs app — page definitions (metadata for client routing registry)
;; Routing is handled by page-functions.sx + sx_router.py catch-all.
;; These defpages provide: path patterns, content expressions, data flags,
;; and component deps for the client-side page registry.

;; ---------------------------------------------------------------------------
;; Home page
;; ---------------------------------------------------------------------------

(defpage home
  :path "/"
  :auth :public
  :layout :sx-docs
  :content (~layouts/doc :path "/" (~docs-content/home-content)))

;; ---------------------------------------------------------------------------
;; Language section (parent of Docs, Specs, Bootstrappers, Testing)
;; ---------------------------------------------------------------------------

(defpage language-index
  :path "/language/"
  :auth :public
  :layout :sx-docs
  :content (~layouts/doc :path "/sx/(language)"))

;; ---------------------------------------------------------------------------
;; Docs section (under Language)
;; ---------------------------------------------------------------------------

(defpage docs-index
  :path "/language/docs/"
  :auth :public
  :layout :sx-docs
  :content (~layouts/doc :path "/sx/(language.(doc))" (~docs-content/docs-introduction-content)))

(defpage docs-page
  :path "/language/docs/<slug>"
  :auth :public
  :layout :sx-docs
  :content (~layouts/doc :path (str "/sx/(language.(doc." slug "))")
    (case slug
      "introduction" (~docs-content/docs-introduction-content)
      "getting-started" (~docs-content/docs-getting-started-content)
      "components" (~docs-content/docs-components-content)
      "evaluator" (~docs-content/docs-evaluator-content)
      "primitives" (~docs-content/docs-primitives-content
                     :prims (~docs/primitives-tables :primitives (primitives-data)))
      "special-forms" (~docs-content/docs-special-forms-content
                        :forms (~docs/special-forms-tables :forms (special-forms-data)))
      "server-rendering" (~docs-content/docs-server-rendering-content)
      :else (~docs-content/docs-introduction-content))))

;; ---------------------------------------------------------------------------
;; Reference section
;; ---------------------------------------------------------------------------

(defpage hypermedia-index
  :path "/geography/hypermedia/"
  :auth :public
  :layout :sx-docs
  :content (~layouts/doc :path "/sx/(geography.(hypermedia))"))

(defpage reference-index
  :path "/geography/hypermedia/reference/"
  :auth :public
  :layout :sx-docs
  :content (~layouts/doc :path "/sx/(geography.(hypermedia.(reference)))" (~examples/reference-index-content)))

(defpage reference-page
  :path "/geography/hypermedia/reference/<slug>"
  :auth :public
  :layout :sx-docs
  :data (reference-data slug)
  :content (~layouts/doc :path (str "/sx/(geography.(hypermedia.(reference." slug ")))")
    (case slug
      "attributes" (~reference/attrs-content
        :req-table (~docs/attr-table-from-data :title "Request Attributes" :attrs req-attrs)
        :beh-table (~docs/attr-table-from-data :title "Behavior Attributes" :attrs beh-attrs)
        :uniq-table (~docs/attr-table-from-data :title "Unique to sx" :attrs uniq-attrs))
      "headers" (~reference/headers-content
        :req-table (~docs/headers-table-from-data :title "Request Headers" :headers req-headers)
        :resp-table (~docs/headers-table-from-data :title "Response Headers" :headers resp-headers))
      "events" (~reference/events-content
        :table (~docs/two-col-table-from-data
          :intro "sx fires custom DOM events at various points in the request lifecycle."
          :col1 "Event" :col2 "Description" :items events-list))
      "js-api" (~reference/js-api-content
        :table (~docs/two-col-table-from-data
          :intro "The client-side sx.js library exposes a public API for programmatic use."
          :col1 "Method" :col2 "Description" :items js-api-list))
      :else (~reference/attrs-content
        :req-table (~docs/attr-table-from-data :title "Request Attributes" :attrs req-attrs)
        :beh-table (~docs/attr-table-from-data :title "Behavior Attributes" :attrs beh-attrs)
        :uniq-table (~docs/attr-table-from-data :title "Unique to sx" :attrs uniq-attrs)))))

(defpage reference-attr-detail
  :path "/geography/hypermedia/reference/attributes/<slug>"
  :auth :public
  :layout :sx-docs
  :data (attr-detail-data slug)
  :content (~layouts/doc :path (str "/sx/(geography.(hypermedia.(reference-detail.attributes." slug ")))")
    (if attr-not-found
      (~reference/attr-not-found :slug slug)
      (~reference/attr-detail-content
        :title attr-title
        :description attr-description
        :demo attr-demo
        :example-code attr-example
        :handler-code attr-handler
        :wire-placeholder-id attr-wire-id))))

(defpage reference-header-detail
  :path "/geography/hypermedia/reference/headers/<slug>"
  :auth :public
  :layout :sx-docs
  :data (header-detail-data slug)
  :content (~layouts/doc :path (str "/sx/(geography.(hypermedia.(reference-detail.headers." slug ")))")
    (if header-not-found
      (~reference/attr-not-found :slug slug)
      (~reference/header-detail-content
        :title header-title
        :direction header-direction
        :description header-description
        :example-code header-example
        :demo header-demo))))

(defpage reference-event-detail
  :path "/geography/hypermedia/reference/events/<slug>"
  :auth :public
  :layout :sx-docs
  :data (event-detail-data slug)
  :content (~layouts/doc :path (str "/sx/(geography.(hypermedia.(reference-detail.events." slug ")))")
    (if event-not-found
      (~reference/attr-not-found :slug slug)
      (~reference/event-detail-content
        :title event-title
        :description event-description
        :example-code event-example
        :demo event-demo))))

;; ---------------------------------------------------------------------------
;; Applications section (parent of CSSX, Protocols)
;; ---------------------------------------------------------------------------

(defpage applications-index
  :path "/applications/"
  :auth :public
  :layout :sx-docs
  :content (~layouts/doc :path "/sx/(applications)"))

;; ---------------------------------------------------------------------------
;; Protocols section (under Applications)
;; ---------------------------------------------------------------------------

(defpage
  pretext-demo
  :path "/applications/pretext"
  :auth :public
  :layout :sx-docs
  :content (~layouts/doc :path "/sx/(applications.(pretext))" (~pretext-demo/content)))

(defpage
  protocols-index
  :path "/applications/protocols/"
  :auth :public
  :layout :sx-docs
  :content (~layouts/doc
    :path "/sx/(applications.(protocol))"
    (~protocols/wire-format-content)))

;; ---------------------------------------------------------------------------
;; Examples section
;; ---------------------------------------------------------------------------

(defpage
  protocol-page
  :path "/applications/protocols/<slug>"
  :auth :public
  :layout :sx-docs
  :content (~layouts/doc
    :path (str "/sx/(applications.(protocol." slug "))")
    (case
      slug
      "wire-format"
      (~protocols/wire-format-content)
      "fragments"
      (~protocols/fragments-content)
      "resolver-io"
      (~protocols/resolver-io-content)
      "internal-services"
      (~protocols/internal-services-content)
      "activitypub"
      (~protocols/activitypub-content)
      "future"
      (~protocols/future-content)
      :else (~protocols/wire-format-content))))

(defpage
  examples-index
  :path "/geography/hypermedia/examples/"
  :auth :public
  :layout :sx-docs
  :content (~layouts/doc :path "/sx/(geography.(hypermedia.(example)))"))

;; ---------------------------------------------------------------------------
;; Etc section (parent of Essays, Philosophy, Plans)
;; ---------------------------------------------------------------------------

(defpage
  examples-page
  :path "/geography/hypermedia/examples/<slug>"
  :auth :public
  :layout :sx-docs
  :content (~layouts/doc
    :path (str "/sx/(geography.(hypermedia.(example." slug ")))")
    (case
      slug
      "click-to-load"
      (~examples-content/example-click-to-load)
      "form-submission"
      (~examples-content/example-form-submission)
      "polling"
      (~examples-content/example-polling)
      "delete-row"
      (~examples-content/example-delete-row)
      "inline-edit"
      (~examples-content/example-inline-edit)
      "oob-swaps"
      (~examples-content/example-oob-swaps)
      "lazy-loading"
      (~examples-content/example-lazy-loading)
      "infinite-scroll"
      (~examples-content/example-infinite-scroll)
      "progress-bar"
      (~examples-content/example-progress-bar)
      "active-search"
      (~examples-content/example-active-search)
      "inline-validation"
      (~examples-content/example-inline-validation)
      "value-select"
      (~examples-content/example-value-select)
      "reset-on-submit"
      (~examples-content/example-reset-on-submit)
      "edit-row"
      (~examples-content/example-edit-row)
      "bulk-update"
      (~examples-content/example-bulk-update)
      "swap-positions"
      (~examples-content/example-swap-positions)
      "select-filter"
      (~examples-content/example-select-filter)
      "tabs"
      (~examples-content/example-tabs)
      "animations"
      (~examples-content/example-animations)
      "dialogs"
      (~examples-content/example-dialogs)
      "keyboard-shortcuts"
      (~examples-content/example-keyboard-shortcuts)
      "put-patch"
      (~examples-content/example-put-patch)
      "json-encoding"
      (~examples-content/example-json-encoding)
      "vals-and-headers"
      (~examples-content/example-vals-and-headers)
      "loading-states"
      (~examples-content/example-loading-states)
      "sync-replace"
      (~examples-content/example-sync-replace)
      "retry"
      (~examples-content/example-retry)
      :else (~examples-content/example-click-to-load))))

;; ---------------------------------------------------------------------------
;; Essays section (under Etc)
;; ---------------------------------------------------------------------------

(defpage
  etc-index
  :path "/etc/"
  :auth :public
  :layout :sx-docs
  :content (~layouts/doc :path "/sx/(etc)"))

(defpage
  essays-index
  :path "/etc/essays/"
  :auth :public
  :layout :sx-docs
  :content (~layouts/doc
    :path "/sx/(etc.(essay))"
    (~essays/index/essays-index-content)))

;; ---------------------------------------------------------------------------
;; Philosophy section
;; ---------------------------------------------------------------------------

(defpage
  essay-page
  :path "/etc/essays/<slug>"
  :auth :public
  :layout :sx-docs
  :content (~layouts/doc
    :path (str "/sx/(etc.(essay." slug "))")
    (case
      slug
      "sx-sucks"
      (~essays/sx-sucks/essay-sx-sucks)
      "why-sexps"
      (~essays/why-sexps/essay-why-sexps)
      "htmx-react-hybrid"
      (~essays/htmx-react-hybrid/essay-htmx-react-hybrid)
      "on-demand-css"
      (~essays/on-demand-css/essay-on-demand-css)
      "client-reactivity"
      (~essays/client-reactivity/essay-client-reactivity)
      "sx-native"
      (~essays/sx-native/essay-sx-native)
      "tail-call-optimization"
      (~essays/tail-call-optimization/essay-tail-call-optimization)
      "continuations"
      (~essays/continuations/essay-continuations)
      "reflexive-web"
      (~essays/reflexive-web/essay-reflexive-web)
      "server-architecture"
      (~essays/server-architecture/essay-server-architecture)
      "separation-of-concerns"
      (~essays/separation-of-concerns/essay-separation-of-concerns)
      "sx-and-ai"
      (~essays/sx-and-ai/essay-sx-and-ai)
      "no-alternative"
      (~essays/no-alternative/essay-no-alternative)
      "zero-tooling"
      (~essays/zero-tooling/essay-zero-tooling)
      "react-is-hypermedia"
      (~essays/react-is-hypermedia/essay-react-is-hypermedia)
      "hegelian-synthesis"
      (~essays/hegelian-synthesis/essay-hegelian-synthesis)
      "the-art-chain"
      (~essays/the-art-chain/essay-the-art-chain)
      "self-defining-medium"
      (~essays/self-defining-medium/essay-self-defining-medium)
      :else (~essays/index/essays-index-content))))

(defpage
  philosophy-index
  :path "/etc/philosophy/"
  :auth :public
  :layout :sx-docs
  :content (~layouts/doc
    :path "/sx/(etc.(philosophy))"
    (~essays/philosophy-index/content)))

;; ---------------------------------------------------------------------------
;; CSSX section
;; ---------------------------------------------------------------------------

(defpage
  philosophy-page
  :path "/etc/philosophy/<slug>"
  :auth :public
  :layout :sx-docs
  :content (~layouts/doc
    :path (str "/sx/(etc.(philosophy." slug "))")
    (case
      slug
      "sx-manifesto"
      (~essay-sx-manifesto)
      "godel-escher-bach"
      (~essays/godel-escher-bach/essay-godel-escher-bach)
      "wittgenstein"
      (~essays/sx-and-wittgenstein/essay-sx-and-wittgenstein)
      "dennett"
      (~essays/sx-and-dennett/essay-sx-and-dennett)
      "existentialism"
      (~essays/s-existentialism/essay-s-existentialism)
      :else (~essays/philosophy-index/content))))

(defpage
  cssx-index
  :path "/applications/cssx/"
  :auth :public
  :layout :sx-docs
  :content (~layouts/doc :path "/sx/(applications.(cssx))" (~cssx/overview-content)))

;; ---------------------------------------------------------------------------
;; Specs section
;; ---------------------------------------------------------------------------

(defpage
  cssx-page
  :path "/applications/cssx/<slug>"
  :auth :public
  :layout :sx-docs
  :content (~layouts/doc
    :path (str "/sx/(applications.(cssx." slug "))")
    (case
      slug
      "patterns"
      (~cssx/patterns-content)
      "delivery"
      (~cssx/delivery-content)
      "async"
      (~cssx/async-content)
      "live"
      (~cssx/live-content)
      "comparisons"
      (~cssx/comparison-content)
      "philosophy"
      (~cssx/philosophy-content)
      :else (~cssx/overview-content))))

(defpage
  specs-index
  :path "/language/specs/"
  :auth :public
  :layout :sx-docs
  :content (~layouts/doc :path "/sx/(language.(spec))" (~specs/architecture-content)))

;; ---------------------------------------------------------------------------
;; Spec Explorer — structured interactive view of spec files
;; ---------------------------------------------------------------------------

(defpage
  specs-page
  :path "/language/specs/<slug>"
  :auth :public
  :layout :sx-docs
  :content (~layouts/doc
    :path (str "/sx/(language.(spec." slug "))")
    (let
      ((make-spec-files (fn (items) (map (fn (item) (dict :title (get item "title") :desc (get item "desc") :prose (get item "prose") :filename (get item "filename") :href (str "/sx/(language.(spec." (get item "slug") "))") :source (read-spec-file (get item "filename")))) items))))
      (case
        slug
        "core"
        (~specs/overview-content
          :spec-title "Core Language"
          :spec-files (make-spec-files core-spec-items))
        "adapters"
        (~specs/overview-content
          :spec-title "Adapters"
          :spec-files (make-spec-files adapter-spec-items))
        "browser"
        (~specs/overview-content
          :spec-title "Browser Runtime"
          :spec-files (make-spec-files browser-spec-items))
        "reactive"
        (~specs/overview-content
          :spec-title "Reactive System"
          :spec-files (make-spec-files reactive-spec-items))
        "host"
        (~specs/overview-content
          :spec-title "Host Interface"
          :spec-files (make-spec-files host-spec-items))
        "extensions"
        (~specs/overview-content
          :spec-title "Extensions"
          :spec-files (make-spec-files extension-spec-items))
        :else (let
          ((spec (find-spec slug)))
          (if
            spec
            (~specs/detail-content
              :spec-title (get spec "title")
              :spec-desc (get spec "desc")
              :spec-filename (get spec "filename")
              :spec-source (read-spec-file (get spec "filename"))
              :spec-prose (get spec "prose"))
            (~specs/not-found :slug slug)))))))

;; ---------------------------------------------------------------------------
;; Bootstrappers section
;; ---------------------------------------------------------------------------

(defpage
  specs-explore-page
  :path "/language/specs/explore/<slug>"
  :auth :public
  :layout :sx-docs
  :data (helper "spec-explorer-data-by-slug" slug)
  :content (~layouts/doc
    :path (str "/sx/(language.(spec.(explore." slug ")))")
    (if
      data
      (~specs-explorer/spec-explorer-content :data data)
      (~specs/not-found :slug slug))))

(defpage
  bootstrappers-index
  :path "/language/bootstrappers/"
  :auth :public
  :layout :sx-docs
  :content (~layouts/doc
    :path "/sx/(language.(bootstrapper))"
    (~specs/bootstrappers-index-content)))

;; ---------------------------------------------------------------------------
;; Isomorphism section
;; ---------------------------------------------------------------------------

(defpage
  bootstrapper-page
  :path "/language/bootstrappers/<slug>"
  :auth :public
  :layout :sx-docs
  :data (bootstrapper-data slug)
  :content (~layouts/doc
    :path (str "/sx/(language.(bootstrapper." slug "))")
    (if
      bootstrapper-not-found
      (~specs/not-found :slug slug)
      (case
        slug
        "self-hosting"
        (~specs/bootstrapper-self-hosting-content
          :py-sx-source py-sx-source
          :g0-output g0-output
          :g1-output g1-output
          :defines-matched defines-matched
          :defines-total defines-total
          :g0-lines g0-lines
          :g0-bytes g0-bytes
          :verification-status verification-status)
        "self-hosting-js"
        (~specs/bootstrapper-self-hosting-js-content
          :js-sx-source js-sx-source
          :defines-matched defines-matched
          :defines-total defines-total
          :js-sx-lines js-sx-lines
          :verification-status verification-status)
        "python"
        (~specs/bootstrapper-py-content
          :bootstrapper-source bootstrapper-source
          :bootstrapped-output bootstrapped-output)
        :else (~specs/bootstrapper-js-content
          :bootstrapper-source bootstrapper-source
          :bootstrapped-output bootstrapped-output)))))

(defpage
  isomorphism-index
  :path "/geography/isomorphism/"
  :auth :public
  :layout :sx-docs
  :content (~layouts/doc
    :path "/sx/(geography.(isomorphism))"
    (~plans/isomorphic/plan-isomorphic-content)))

(defpage
  bundle-analyzer
  :path "/geography/isomorphism/bundle-analyzer"
  :auth :public
  :layout :sx-docs
  :data (bundle-analyzer-data)
  :content (~layouts/doc
    :path "/sx/(geography.(isomorphism.bundle-analyzer))"
    (~analyzer/bundle-analyzer-content
      :pages pages
      :total-components total-components
      :total-macros total-macros
      :pure-count pure-count
      :io-count io-count)))

(defpage
  routing-analyzer
  :path "/geography/isomorphism/routing-analyzer"
  :auth :public
  :layout :sx-docs
  :data (routing-analyzer-data)
  :content (~layouts/doc
    :path "/sx/(geography.(isomorphism.routing-analyzer))"
    (~routing-analyzer/content
      :pages pages
      :total-pages total-pages
      :client-count client-count
      :server-count server-count
      :registry-sample registry-sample)))

(defpage
  data-test
  :path "/geography/isomorphism/data-test"
  :auth :public
  :layout :sx-docs
  :data (data-test-data)
  :content (~layouts/doc
    :path "/sx/(geography.(isomorphism.data-test))"
    (~data-test/content
      :server-time server-time
      :items items
      :phase phase
      :transport transport)))

(defpage
  async-io-demo
  :path "/geography/isomorphism/async-io"
  :auth :public
  :layout :sx-docs
  :content (~layouts/doc
    :path "/sx/(geography.(isomorphism.async-io))"
    (~async-io-demo/content)))

(defpage
  streaming-demo
  :path "/geography/isomorphism/streaming"
  :auth :public
  :stream true
  :layout :sx-docs
  :shell (~layouts/doc
    :path "/sx/(geography.(isomorphism.streaming))"
    (~streaming-demo/layout
      (~shared:pages/suspense
        :id "stream-fast"
        :fallback (~streaming-demo/stream-skeleton))
      (~shared:pages/suspense
        :id "stream-medium"
        :fallback (~streaming-demo/stream-skeleton))
      (~shared:pages/suspense
        :id "stream-slow"
        :fallback (~streaming-demo/stream-skeleton))))
  :data (streaming-demo-data)
  :content (~streaming-demo/chunk
    :stream-label stream-label
    :stream-color stream-color
    :stream-message stream-message
    :stream-time stream-time))

(defpage
  affinity-demo
  :path "/geography/isomorphism/affinity"
  :auth :public
  :layout :sx-docs
  :data (affinity-demo-data)
  :content (~layouts/doc
    :path "/sx/(geography.(isomorphism.affinity))"
    (~affinity-demo/content :components components :page-plans page-plans)))

(defpage
  optimistic-demo
  :path "/geography/isomorphism/optimistic"
  :auth :public
  :layout :sx-docs
  :data (optimistic-demo-data)
  :content (~layouts/doc
    :path "/sx/(geography.(isomorphism.optimistic))"
    (~optimistic-demo/content :items items :server-time server-time)))

;; Wildcard must come AFTER specific routes (first-match routing)
(defpage
  offline-demo
  :path "/geography/isomorphism/offline"
  :auth :public
  :layout :sx-docs
  :data (offline-demo-data)
  :content (~layouts/doc
    :path "/sx/(geography.(isomorphism.offline))"
    (~offline-demo/content :notes notes :server-time server-time)))

;; ---------------------------------------------------------------------------
;; Plans section
;; ---------------------------------------------------------------------------

(defpage
  isomorphism-page
  :path "/geography/isomorphism/<slug>"
  :auth :public
  :layout :sx-docs
  :content (~layouts/doc
    :path (str "/sx/(geography.(isomorphism." slug "))")
    (case
      slug
      "bundle-analyzer"
      (~analyzer/bundle-analyzer-content
        :pages pages
        :total-components total-components
        :total-macros total-macros
        :pure-count pure-count
        :io-count io-count)
      "routing-analyzer"
      (~routing-analyzer/content
        :pages pages
        :total-pages total-pages
        :client-count client-count
        :server-count server-count
        :registry-sample registry-sample)
      :else (~plans/isomorphic/plan-isomorphic-content))))

(defpage
  plans-index
  :path "/etc/plans/"
  :auth :public
  :layout :sx-docs
  :content (~layouts/doc :path "/sx/(etc.(plan))" (~plans/index/plans-index-content)))

;; ---------------------------------------------------------------------------
;; Geography section (parent of Reactive Islands, Hypermedia Lakes, Marshes)
;; ---------------------------------------------------------------------------

(defpage
  plan-page
  :path "/etc/plans/<slug>"
  :auth :public
  :layout :sx-docs
  :data (case slug "theorem-prover" (prove-data) :else nil)
  :content (~layouts/doc
    :path (str "/sx/(etc.(plan." slug "))")
    (case
      slug
      "status"
      (~plans/status/plan-status-content)
      "reader-macros"
      (~plans/reader-macros/plan-reader-macros-content)
      "reader-macro-demo"
      (~plans/reader-macro-demo/plan-reader-macro-demo-content)
      "theorem-prover"
      (~plans/theorem-prover/plan-theorem-prover-content)
      "self-hosting-bootstrapper"
      (~plans/self-hosting-bootstrapper/plan-self-hosting-bootstrapper-content)
      "js-bootstrapper"
      (~plans/js-bootstrapper/plan-js-bootstrapper-content)
      "sx-activity"
      (~plans/sx-activity/plan-sx-activity-content)
      "predictive-prefetch"
      (~plans/predictive-prefetch/plan-predictive-prefetch-content)
      "content-addressed-components"
      (~plans/content-addressed-components/plan-content-addressed-components-content)
      "environment-images"
      (~plans/environment-images/plan-environment-images-content)
      "runtime-slicing"
      (~plans/runtime-slicing/plan-runtime-slicing-content)
      "typed-sx"
      (~plans/typed-sx/plan-typed-sx-content)
      "nav-redesign"
      (~plans/nav-redesign/plan-nav-redesign-content)
      "fragment-protocol"
      (~plans/fragment-protocol/plan-fragment-protocol-content)
      "glue-decoupling"
      (~plans/glue-decoupling/plan-glue-decoupling-content)
      "social-sharing"
      (~plans/social-sharing/plan-social-sharing-content)
      "sx-ci"
      (~plans/sx-ci/plan-sx-ci-content)
      "live-streaming"
      (~plans/live-streaming/plan-live-streaming-content)
      "sx-web-platform"
      (~plans/sx-web-platform/plan-sx-web-platform-content)
      "sx-forge"
      (~plans/sx-forge/plan-sx-forge-content)
      "sx-swarm"
      (~plans/sx-swarm/plan-sx-swarm-content)
      "sx-proxy"
      (~plans/sx-proxy/plan-sx-proxy-content)
      "mother-language"
      (~plans/mother-language/plan-mother-language-content)
      "isolated-evaluator"
      (~plans/isolated-evaluator/plan-isolated-evaluator-content)
      "rust-wasm-host"
      (~plans/rust-wasm-host/plan-rust-wasm-host-content)
      "async-eval-convergence"
      (~plans/async-eval-convergence/plan-async-eval-convergence-content)
      "wasm-bytecode-vm"
      (~plans/wasm-bytecode-vm/plan-wasm-bytecode-vm-content)
      "generative-sx"
      (~plans/generative-sx/plan-generative-sx-content)
      "art-dag-sx"
      (~plans/art-dag-sx/plan-art-dag-sx-content)
      "spec-explorer"
      (~plans/spec-explorer/plan-spec-explorer-content)
      "sx-urls"
      (~plans/sx-urls/plan-sx-urls-content)
      "sx-protocol"
      (~plans/sx-protocol/plan-sx-protocol-content)
      "scoped-effects"
      (~plans/scoped-effects/plan-scoped-effects-content)
      "foundations"
      (~plans/foundations/plan-foundations-content)
      "cek-reactive"
      (~plans/cek-reactive/plan-cek-reactive-content)
      "reactive-runtime"
      (~plans/reactive-runtime/plan-reactive-runtime-content)
      :else (~plans/index/plans-index-content))))

;; ---------------------------------------------------------------------------
;; Reactive Islands section (under Geography)
;; ---------------------------------------------------------------------------

(defpage
  geography-index
  :path "/geography/"
  :auth :public
  :layout :sx-docs
  :content (~layouts/doc :path "/sx/(geography)" (~geography/index-content)))

(defpage
  reactive-islands-index
  :path "/geography/reactive/"
  :auth :public
  :layout :sx-docs
  :content (~layouts/doc
    :path "/sx/(geography.(reactive))"
    (~reactive-islands/index/reactive-islands-index-content)))

;; ---------------------------------------------------------------------------
;; Provide / Emit! section (under Geography)
;; ---------------------------------------------------------------------------

(defpage
  reactive-islands-page
  :path "/geography/reactive/<slug>"
  :auth :public
  :layout :sx-docs
  :content (~layouts/doc
    :path (str "/sx/(geography.(reactive." slug "))")
    (case
      slug
      "examples"
      (~reactive-islands/demo/reactive-islands-demo-content)
      "demo"
      (~reactive-islands/demo/reactive-islands-demo-content)
      "event-bridge"
      (~reactive-islands/event-bridge/reactive-islands-event-bridge-content)
      "named-stores"
      (~reactive-islands/named-stores/reactive-islands-named-stores-content)
      "marshes"
      (~reactive-islands/marshes/reactive-islands-marshes-content)
      :else (~reactive-islands/index/reactive-islands-index-content))))

(defpage
  scopes-index
  :path "/geography/scopes/"
  :auth :public
  :layout :sx-docs
  :content (~layouts/doc :path "/sx/(geography.(scopes))" (~geography/scopes-content)))

;; ---------------------------------------------------------------------------
;; Spreads section (under Geography)
;; ---------------------------------------------------------------------------

(defpage
  provide-index
  :path "/geography/provide/"
  :auth :public
  :layout :sx-docs
  :content (~layouts/doc
    :path "/sx/(geography.(provide))"
    (~geography/provide-content)))

;; ---------------------------------------------------------------------------
;; Marshes section (under Geography)
;; ---------------------------------------------------------------------------

(defpage
  spreads-index
  :path "/geography/spreads/"
  :auth :public
  :layout :sx-docs
  :content (~layouts/doc
    :path "/sx/(geography.(spreads))"
    (~geography/spreads-content)))

;; ---------------------------------------------------------------------------
;; CEK Machine section (under Geography)
;; ---------------------------------------------------------------------------

(defpage
  marshes-index
  :path "/geography/marshes/"
  :auth :public
  :layout :sx-docs
  :content (~layouts/doc
    :path "/sx/(geography.(marshes))"
    (~reactive-islands/marshes/reactive-islands-marshes-content)))

(defpage
  cek-index
  :path "/geography/cek/"
  :auth :public
  :layout :sx-docs
  :content (~layouts/doc :path "/sx/(geography.(cek))" (~geography/cek)))

;; ---------------------------------------------------------------------------
;; Bootstrapped page helpers demo
;; ---------------------------------------------------------------------------

(defpage
  cek-page
  :path "/geography/cek/<slug>"
  :auth :public
  :layout :sx-docs
  :content (~layouts/doc
    :path (str "/sx/(geography.(cek." slug "))")
    (case
      slug
      "demo"
      (~geography/cek/demo)
      "freeze"
      (~geography/cek/freeze)
      "content"
      (~geography/cek/content)
      :else (~geography/cek))))

;; ---------------------------------------------------------------------------
;; Testing section
;; ---------------------------------------------------------------------------

(defpage
  page-helpers-demo
  :path "/language/bootstrappers/page-helpers"
  :auth :public
  :layout :sx-docs
  :data (page-helpers-demo-data)
  :content (~layouts/doc
    :path "/sx/(language.(bootstrapper.page-helpers))"
    (~page-helpers-demo/content
      :sf-categories sf-categories
      :sf-total sf-total
      :sf-ms sf-ms
      :ref-sample ref-sample
      :ref-ms ref-ms
      :attr-result attr-result
      :attr-ms attr-ms
      :comp-source comp-source
      :comp-ms comp-ms
      :routing-result routing-result
      :routing-ms routing-ms
      :server-total-ms server-total-ms
      :sf-source sf-source
      :attr-detail attr-detail
      :req-attrs req-attrs
      :attr-keys attr-keys)))

(defpage
  testing-index
  :path "/language/testing/"
  :auth :public
  :layout :sx-docs
  :data (run-modular-tests "all")
  :content (~layouts/doc
    :path "/sx/(language.(test))"
    (~testing/overview-content
      :server-results server-results
      :framework-source framework-source
      :eval-source eval-source
      :parser-source parser-source
      :router-source router-source
      :render-source render-source
      :deps-source deps-source
      :engine-source engine-source)))

(defpage
  testing-page
  :path "/language/testing/<slug>"
  :auth :public
  :layout :sx-docs
  :data (case
    slug
    "eval"
    (run-modular-tests "eval")
    "parser"
    (run-modular-tests "parser")
    "router"
    (run-modular-tests "router")
    "render"
    (run-modular-tests "render")
    "deps"
    (run-modular-tests "deps")
    "engine"
    (run-modular-tests "engine")
    "orchestration"
    (run-modular-tests "orchestration")
    :else (dict))
  :content (~layouts/doc
    :path (str "/sx/(language.(test." slug "))")
    (case
      slug
      "eval"
      (~testing/spec-content
        :spec-name "eval"
        :spec-title "Evaluator Tests"
        :spec-desc "81 tests covering the core evaluator and all primitives — literals, arithmetic, comparison, strings, lists, dicts, predicates, special forms, lambdas, higher-order functions, components, macros, threading, and edge cases."
        :spec-source spec-source
        :framework-source framework-source
        :server-results server-results)
      "parser"
      (~testing/spec-content
        :spec-name "parser"
        :spec-title "Parser Tests"
        :spec-desc "39 tests covering tokenization and parsing — integers, floats, strings, escape sequences, booleans, nil, keywords, symbols, lists, dicts, whitespace, comments, quote sugar, serialization, and round-trips."
        :spec-source spec-source
        :framework-source framework-source
        :server-results server-results)
      "router"
      (~testing/spec-content
        :spec-name "router"
        :spec-title "Router Tests"
        :spec-desc "18 tests covering client-side route matching — path splitting, pattern parsing, segment matching, parameter extraction, and route table search."
        :spec-source spec-source
        :framework-source framework-source
        :server-results server-results)
      "render"
      (~testing/spec-content
        :spec-name "render"
        :spec-title "Renderer Tests"
        :spec-desc "23 tests covering HTML rendering — elements, attributes, void elements, boolean attributes, fragments, escaping, control flow, and component rendering."
        :spec-source spec-source
        :framework-source framework-source
        :server-results server-results)
      "deps"
      (~testing/spec-content
        :spec-name "deps"
        :spec-title "Dependency Analysis Tests"
        :spec-desc "33 tests covering component dependency analysis — scan-refs, scan-components-from-source, transitive-deps, components-needed, scan-io-refs, and component-pure? classification."
        :spec-source spec-source
        :framework-source framework-source
        :server-results server-results)
      "engine"
      (~testing/spec-content
        :spec-name "engine"
        :spec-title "Engine Tests"
        :spec-desc "37 tests covering engine pure functions — parse-time, parse-trigger-spec, default-trigger, parse-swap-spec, parse-retry-spec, next-retry-ms, and filter-params."
        :spec-source spec-source
        :framework-source framework-source
        :server-results server-results)
      "orchestration"
      (~testing/spec-content
        :spec-name "orchestration"
        :spec-title "Orchestration Tests"
        :spec-desc "17 tests covering Phase 7c+7d orchestration — page data cache, optimistic cache update/revert/confirm, offline connectivity, offline queue mutation, and offline-aware routing."
        :spec-source spec-source
        :framework-source framework-source
        :server-results server-results)
      "runners"
      (~testing/runners-content)
      :else (~testing/overview-content :server-results server-results))))
