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

;; --- cart-page layout: root + cart row + page-cart row ---

(defcomp ~cart-page-layout-full (&key cart-row page-cart-row)
  (<> (~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)
    (~header-child-sx
      :inner (<> cart-row
               (~header-child-sx :id "cart-header-child" :inner page-cart-row)))))

(defcomp ~cart-page-layout-oob (&key root-header-oob cart-row-oob page-cart-row)
  (<> (~oob-header-sx :parent-id "cart-header-child" :row page-cart-row)
    cart-row-oob
    root-header-oob))

;; --- cart-admin layout: root + post header + admin header ---

(defcomp ~cart-admin-layout-full (&key post-header admin-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)
    post-header admin-header))

;; --- orders-within-cart: root + auth-simple + orders ---

(defcomp ~cart-orders-layout-full (&key list-url)
  (<> (~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)
    (~header-child-sx
      :inner (<> (~auth-header-row-simple :account-url account-url)
               (~header-child-sx :id "auth-header-child"
                 :inner (~orders-header-row :list-url list-url))))))

(defcomp ~cart-orders-layout-oob (&key list-url)
  (<> (~auth-header-row-simple :account-url account-url :oob true)
    (~oob-header-sx
      :parent-id "auth-header-child"
      :row (~orders-header-row :list-url list-url))
    (~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
                   :oob true)))

;; --- order-detail-within-cart: root + auth-simple + orders + order ---

(defcomp ~cart-order-detail-layout-full (&key list-url detail-url order-label)
  (<> (~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)
    (~header-child-sx
      :inner (<> (~auth-header-row-simple :account-url account-url)
               (~header-child-sx :id "auth-header-child"
                 :inner (<> (~orders-header-row :list-url list-url)
                          (~header-child-sx :id "orders-header-child"
                            :inner (~menu-row-sx :id "order-row" :level 3 :colour "sky"
                                     :link-href detail-url
                                     :link-label order-label
                                     :icon "fa fa-gbp"))))))))

(defcomp ~cart-order-detail-layout-oob (&key detail-url order-label)
  (<> (~oob-header-sx
        :parent-id "orders-header-child"
        :row (~menu-row-sx :id "order-row" :level 3 :colour "sky"
               :link-href detail-url :link-label order-label
               :icon "fa fa-gbp" :oob true))
    (~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
                   :oob true)))

;; --- orders rows wrapper (for infinite scroll) ---

(defcomp ~cart-orders-rows (&key rows next-scroll)
  (<> rows next-scroll))
