(ns auto-ap.views.components.bank-account-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 bank-account-filter [{:keys [value on-change-event bank-accounts]}]
  [:div.field
   [:div.control 
    [bind-field
     [typeahead {:matches (map (fn [x] [(:id x) (:name x)]) bank-accounts)
                 :type "typeahead"
                 :auto-focus true
                 :field [:id]
                 :text-field [:name]
                 :event on-change-event
                 :spec (s/nilable ::invoice/vendor-id)
                 :subscription value}]]]])
