 (ns re-com.validate
   (:require  [clojure.set           :refer [superset?]]
              [re-com.util           :refer [deref-or-value]]
-             [reagent.impl.template :refer [valid-tag?]]))
+             [reagent.impl.template :refer [valid-tag?]]
+             [goog.string :as gstring]))
 
 
 ;; -- Global Switch ------------------------------------------------------------------------------------

(defn validate-arg-against-set
  "Validates the passed argument against the expected set."
  [arg arg-type valid-args]
  (if (contains? valid-args arg)
    true
    (str "Invalid " arg-type ". Expected one of " valid-args ". Got '" (left-string arg 40) "'")))

(defn justify-style?
  [arg]
  (validate-arg-against-set arg "justify-style" #{:start :end :center :between :around}))

(defn align-style?
  [arg]
  (validate-arg-against-set arg "align-style"   #{:start :end :center :baseline :stretch}))

(defn scroll-style?
  [arg]
  (validate-arg-against-set arg "scroll-style"  #{:auto :off :on :spill}))

(defn alert-type?
  [arg]
  (validate-arg-against-set arg "alert-type"    #{"info" "warning" "danger"}))

;; ----------------------------------------------------------------------------
;; Custom :validate-fn functions

  "Converts obj to a string and truncates it to max-len chars if necessary.
   When truncation is necessary, adds an elipsis to the end."
  [obj max-len]
  (gstring/truncate (str obj) max-len))

(defn log-error
  "Sends a message to the DeV Tools console as an error."
