(import-macros {:compile-html HTML} :macros)
(local templates (require :templates))
(local shop (require :shop))
(local lib (require :lib))
(local dicts (require :dicts))
(local texts
{:thanks
(lib.improve-typography
"Мы получили оповещение о заказе. В ближайшее время свяжемся с вами
для уточнения деталей.")})
(fn content [order-lines authenticated?]
(local total (accumulate [sum 0 _ v (ipairs order-lines)]
(+ sum (* v.quantity v.price-per))))
[(HTML [:aside {}
(templates.header "/shop/order" authenticated?)
(templates.conditions-block)
(templates.address-block)
(templates.contact-block)])
(HTML
[:div {:class "content"}
[:div {:class "back"} [:a {:href "/shop"} "⟵ Обратно к списку"]]
[:section {}
[:h2 {} "Спасибо за заказ!"]
[:p {} texts.thanks]
(templates.order-lines order-lines)
[:div {} "—"]
[:div {} [:strong {} (.. "Итого: " (lib.format-price total) "₽")]]]])])
(fn render [request db authenticated?]
(let [order-lines (shop.basket db request.params._id)]
(if (< 0 (# order-lines))
(values 200 {} (templates.base (content order-lines authenticated?)))
(values 302 {:Location "/shop"} ""))))
{: render}