(ns com.oly.static-sites.do-blog.pages.home
  (:require [reagent.core :as r]
            [reitit.frontend.easy :as rfe]
            [com.oly.static-sites.do-blog.pages.helpers.utils :refer [format-date]]
            [com.oly.static-sites.do-blog.pages.helpers.database :refer [search-articles state]]
            [com.oly.static-sites.do-blog.pages.components.core :refer [ui-tags title-text-image article-list-author-media-flipped]]))

(defn home-page [{:keys [path] :as route}]
  (let [search (r/cursor state [:search :terms])
        latest (r/cursor state [:document])]
    (fn []
      [:<>
       [:div
        (if (empty? @search)
          [title-text-image
           {:title (-> @latest :details :title)
            :content  (-> @latest :hiccup)}
           (-> @latest :details)]
          [article-list-author-media-flipped
           "Articles"
           (search-articles {:search @search})])]])))
