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


(defn rule-side-bar [{:keys [data-page]}]
  [:div
   [:p.menu-label "Vendor"]
   [:div
    [typeahead-v3 {:entities-by-id @(re-frame/subscribe [::subs/vendors-by-id])
                   :entity-index  @(re-frame/subscribe [::subs/searchable-vendors-index])
                   :on-change #(re-frame/dispatch [::data-page/filter-changed data-page :vendor (some-> % (select-keys [:name :id]))])
                   :entity->text :name
                   :type "typeahead-v3"
                   :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])} ]]]]])

