;; Blog layout defcomps — root header from env free variables,
;; blog-specific headers passed as &key params.

;; --- Blog layout (root + invisible blog header) ---

(defcomp ~blog-layout-full (&key blog-header)
  (<> (~root-header :cart-mini cart-mini :blog-url blog-url :site-title site-title
                     :app-label app-label :nav-tree nav-tree :auth-menu auth-menu
                     :nav-panel nav-panel :settings-url settings-url :is-admin is-admin)
    blog-header))

;; --- Settings layout (root + settings header) ---

(defcomp ~settings-layout-full (&key settings-header)
  (<> (~root-header :cart-mini cart-mini :blog-url blog-url :site-title site-title
                     :app-label app-label :nav-tree nav-tree :auth-menu auth-menu
                     :nav-panel nav-panel :settings-url settings-url :is-admin is-admin)
    settings-header))

;; --- Sub-settings layout (root + settings + sub row) ---

(defcomp ~sub-settings-layout-full (&key settings-header sub-header)
  (<> (~root-header :cart-mini cart-mini :blog-url blog-url :site-title site-title
                     :app-label app-label :nav-tree nav-tree :auth-menu auth-menu
                     :nav-panel nav-panel :settings-url settings-url :is-admin is-admin)
    settings-header sub-header))

(defcomp ~sub-settings-layout-oob (&key settings-header-oob sub-header-oob)
  (<> settings-header-oob sub-header-oob))

;; --- Settings nav links (replaces Python _settings_nav_sx loop) ---

(defcomp ~blog-settings-nav (&key select-colours)
  (let* ((links (list
           (dict :endpoint "menu_items.defpage_menu_items_page" :icon "fa fa-bars" :label "Menu Items")
           (dict :endpoint "snippets.defpage_snippets_page" :icon "fa fa-puzzle-piece" :label "Snippets")
           (dict :endpoint "blog.tag_groups_admin.defpage_tag_groups_page" :icon "fa fa-tags" :label "Tag Groups")
           (dict :endpoint "settings.defpage_cache_page" :icon "fa fa-refresh" :label "Cache"))))
    (<> (map (lambda (lnk)
      (~nav-link
        :href (url-for (get lnk "endpoint"))
        :icon (get lnk "icon")
        :label (get lnk "label")
        :select-colours (or select-colours "")))
      links))))

;; --- Editor panel wrapper ---

(defcomp ~blog-editor-panel (&key parts)
  (<> parts))
