(ns auto-ap.views.components.search
  (:require
   [auto-ap.views.utils :refer [dispatch-event]]
   [auto-ap.views.components.modal :as modal]
   [reagent.core :as reagent]))

(defn search-dialog-body []
  (let [a (atom nil)]
    (reagent/create-class
      {
       :component-did-mount
       (fn [this]
         (.process js/htmx @a))
       :should-component-update
       (fn [this]
         false)
       :reagent-render
       (fn []
         [:div {:ref (fn [x] (reset! a x))
                "hx-get" "/search"
                "hx-trigger" "load"}
          ""])})))

(defn search-button []
  [:i.fa.fa-search.button {:on-click
                   (dispatch-event [::modal/modal-requested
                                    {:title       "Search"
                                     :body        [search-dialog-body]
                                     :class       "semi-wide"}])}
   #_[:i.fa.fa-search]])
