(ns wanijo.tag.forms
  (:require [clojure.spec.alpha :as spec]
            [clojure.string :refer [split trim]]))

(defn contains-whitespace? [s]
  (re-matches #".*\s.*" s))

(defn tag-names-from-input [s]
  (map trim (split s #",")))

(defn any-tag-name-contains-whitespace [s]
  (some contains-whitespace? (tag-names-from-input s)))

(spec/def ::new-names
  (spec/and string?
            (complement empty?)
            (complement any-tag-name-contains-whitespace)))

(def new-tag
  {:fields {:newnames {:label "Tag Name(s)"
                        :required true
                        :spec ::new-names
                        :from-req tag-names-from-input}}})
