(ns auto-ap.views.components.number-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 date-picker date->str local-now standard]]
   [cljs-time.core :as t]
   [re-frame.core :as re-frame]))

(defn dispatch-change [on-change-event start end]
  (fn [_]
    (re-frame/dispatch (into on-change-event [[:start] start]) )
    (re-frame/dispatch (into on-change-event [[:end] end]))))

(defn number-filter [{:keys [value on-change-event]}]
  [:div
   [:div.field.has-addons
    [:div.control 
     [bind-field
      [date-picker {:class-name "input is-fullwidth"
                    :class "input"
                    :format-week-number (fn [] "")
                    :previous-month-button-label ""
                    :placeholder-text "Start"
                    :next-month-button-label ""
                    :next-month-label ""
                    :event on-change-event
                    :type "date"
                    :field [:start]
                    :subscription value}]]]
    [:div.control
     [bind-field
      [date-picker {:class-name "input is-fullwidth"
                    :class "input"
                    :format-week-number (fn [] "")
                    :previous-month-button-label ""
                    :placeholder-text "End"
                    :next-month-button-label ""
                    :event on-change-event
                    :next-month-label ""
                    :type "date"
                    :field [:end]
                    :subscription value}]]]]])
