   (reagent/render [current-page] (.getElementById js/document "app")))
 
 (defn init! []
-  (load-hyphenation-patterns! @spelling @search)
+  (load-hyphenation-patterns! @spelling @word)
   (accountant/configure-navigation!
     {:nav-handler
      (fn [path]

  (update-hyphenations! (fn [hs] (vec (remove #(= % h) hs))) h))

(defn load-hyphenation-patterns!
  [spelling search]
  (ajax/GET "/api/words"
            :params {:spelling spelling :search search}
            :handler (fn [hyphenations] (swap! app-state assoc :hyphenations hyphenations))
            :error-handler (fn [details]
                             (.warn js/console

     {:on-click #(remove-hyphenation-pattern! pattern)}
     [:span.glyphicon.glyphicon-remove {:aria-hidden true}] " Delete"]]])

(defn word-field []
  [:div.form-group
   [:label.sr-only {:for "wordInput"} "Word"]
   [:input.form-control
    {:id "wordInput"
     :type "text"
     :placeholder "Word"
     :value @word
     :on-change (fn [e]
                  (reset! word (-> e .-target .-value))
                  (load-hyphenation-patterns! @spelling @word))
     :on-blur #(lookup-hyphenation-pattern! @spelling @word)}]])

(defn- hyphenation-valid? [s]
  (and (not (string/blank? s))
       (re-find #"\S-\S" s)))

(defn hyphenation-field []
  [:div
   {:class (if (or (string/blank? @hyphenation)
                   (hyphenation-valid? @hyphenation))
             "form-group" "form-group has-error")}
   [:label.sr-only {:for "hyphenationInput"} "Hyphenation"]
   [:input.form-control
    {:type "text"
     :placeholder "Hyphenation"
     :value @hyphenation
     :on-change #(reset! hyphenation (-> % .-target .-value))}]
   #_[:p.help-block "If the hyphenation is as you would expect it then the problem lies with the liblouis tables. Please contact Christian or Mischa."]])

(defn- hyphenation-add-button []
  [:button.btn.btn-default
   {:on-click #(when (and @word (hyphenation-valid? @hyphenation))
                 (add-hyphenation-pattern! {:word @word :hyphenation @hyphenation :spelling @spelling})
                 (reset! word "")
                 (reset! hyphenation ""))
    :disabled (when (or (string/blank? @word)
                        (not (hyphenation-valid? @hyphenation))
                        (= @hyphenation @official-hyphenation))
                "disabled")}
   "Add"])

(defn spelling-filter []
  [:div.form-group
   [:select {:value @spelling
             :on-change (fn [e]
                          (reset! spelling (-> e .-target .-value))
                          (load-hyphenation-patterns! @spelling @word)
                          (lookup-hyphenation-pattern! @spelling @word))}
    [:option {:value 0} "Old Spelling"]
    [:option {:value 1} "New Spelling"]]])

(defn new-hyphenation []
  [:div.form
   [spelling-filter]
   [word-field]
   [hyphenation-field]
   [hyphenation-add-button]])

(defn hyphenation-list []
  [:div.container
   [:h1 "Hyphenation"]
   [:div.row
    [:div.col-md-6
     [new-hyphenation]]]
   [:h1 "Similar words"]
   [:div.row
    [:table#hyphenations.table.table-striped
     [:thead [:tr [:th "Word"] [:th "Hyphenation"]]]
     [:tbody
      (for [h (sort-by :word (:hyphenations @app-state))]
        ^{:key (:word h)} [hyphenation-pattern h])]]]])

;; -------------------------
;; Views
