(ns auto-ap.views.pages.admin.rules.side-bar
  (:require
   [auto-ap.views.components.typeahead.vendor
    :refer [search-backed-typeahead]]
   [auto-ap.views.pages.data-page :as data-page]
   [auto-ap.views.utils :refer [dispatch-value-change]]
   [re-frame.core :as re-frame]))

(defn rule-side-bar [{:keys [data-page]}]
  [:div
   [:p.menu-label "Vendor"]
   [:div
    [search-backed-typeahead {:search-query (fn [i]
                                              [:search_vendor
                                               {:query i}
                                               [:name :id]])
                              :type         "typeahead-v3"
                              :on-change    #(re-frame/dispatch [::data-page/filter-changed data-page :vendor %])
                              :value        @(re-frame/subscribe [::data-page/filter data-page :vendor])}]]

   [:p.menu-label "Note"]
   [:div
    [:div.field
     [:div.control [:input.input {:placeholder "HOME DEPOT"
                                  :value @(re-frame/subscribe [::data-page/filter data-page :note])
                                  :on-change (dispatch-value-change [::data-page/filter-changed data-page :note])} ]]]]
   [:p.menu-label "Description"]
   [:div
    [:div.field
     [:div.control [:input.input {:placeholder "HOME DEPOT"
                                  :value @(re-frame/subscribe [::data-page/filter data-page :description])
                                  :on-change (dispatch-value-change [::data-page/filter-changed data-page :description])} ]]]]])

