 
             [clojure.set :as clojset]
             [clojure.string :as clojstr]
+
+            [goog.i18n.DateTimeFormat :as dtf]
             )
 
   (:import [goog.dom query]))

;; END Common functions and tools
;;..................................................................................................



;;**************************************************************************************************
;;* BEGIN icons

;; END input
;;..................................................................................................

;;**************************************************************************************************
;;* BEGIN input select
;;* tag: <input select>
;;*
;;* description: Выбор из списка
;;*
;;**************************************************************************************************

(def select-app-init
  {:selected nil
   :list []})

(def no-select-v "NO-SELECT")

(defn select-app-list-set! [app new-list]
  (assoc app :list new-list))

(defn select-app-selected-set! [app selected]
  (assoc app :selected (str selected)))

(defn select-app-selected [app]
  (let [sv (app :selected)]
    (if (= sv no-select-v) nil sv)))


(defn select [app _ {:keys [on-change-fn]}]
  (reify
    om/IRender
    (render [_]
      (println "SELECT APP:" @app)
      (dom/select
       #js {:value (@app :selected)
            :className "form-control"
            :onChange
            (fn [e]
              (let [v (-> e .-target .-value)]
                (om/update! app :selected v)
                (when on-change-fn (on-change-fn v))))}

       (doall
        (map (fn [{:keys [id title keyname]}]
               (println id title keyname)
               (dom/option #js {:value (str id)} keyname " " title))
             (into [{:id no-select-v :title "Выбрать..."}] (@app :list)))) ))))

(defn select-form-group  [app _ {:keys [label
                                        type
                                        spec-select]
                                 :or {label "Метка"
                                      spec-select {}}}]
  (reify
    om/IRender
    (render [_]
      (dom/div #js {:className (str "form-group " (input-css-string-has? app))}
               (dom/label #js {:className "control-label col-sm-4 col-md-4 col-lg-4"} label)
               (dom/div #js {:className "col-sm-8 col-md-8 col-lg-8"}
                        (om/build select app {:opts spec-select})
                        (om/build helper-p app {})
                        )))))


;; END input select
;;..................................................................................................



;;**************************************************************************************************
