(ns auto-ap.views.components.vendor-filter
  (:require
   [clojure.spec.alpha :as s]
   [auto-ap.entities.invoice :as invoice]
   [auto-ap.views.components.typeahead :refer [typeahead]]
   [auto-ap.views.utils :refer [bind-field]]))

(defn vendor-filter [{:keys [value on-change-event vendors]}]
  [:div.field
   [:div.control 
    [bind-field
     [typeahead {:matches (map (fn [x] [(:id x) (:name x)]) vendors)
                 :type "typeahead"
                 :auto-focus true
                 :field [:vendor-id]
                 :text-field [:vendor-name]
                 :event on-change-event
                 :spec (s/nilable ::invoice/vendor-id)
                 :subscription value}]]]])
