;; Market container-nav fragment handler
;; returns: sx
;;
;; Renders marketplace link nav items for blog post pages.

(defhandler container-nav (&key container_type container_id post_slug)
  (let ((ct       (or container_type "page"))
        (cid      (parse-int (or container_id "0")))
        (slug     (or post_slug ""))
        (markets  (service "market" "marketplaces-for-container"
                    :container-type ct :container-id cid)))
    (when (not (empty? markets))
      (let ((styles       (or (jinja-global "styles") (dict)))
            (nav-class    (or (get styles "nav_button") ""))
            (sel-colours  (or (jinja-global "select_colours") "")))
        (<> (map (fn (m)
          (let ((href (app-url "market" (str "/" slug "/" (get m "slug") "/"))))
            (~shared:navigation/market-link-nav
              :href href
              :name (get m "name")
              :nav-class nav-class
              :select-colours sel-colours))) markets))))))
