 ; (prepare-word-test "aaabbbccc111aaabbbccc111")
 ; (prepare-word-test "aaabbbccc111aaabbbccc111aaabbbccc111")
 
-(defn- badness
-  "given line and page width returns measurement how `pretty` the line is"
-  [line page-width]
-  (let [total-length (utils/line-length line)]
-    (if (> total-length page-width)
-      js/Infinity
-      (let [a (- page-width total-length)] (* a a a)) )))
-
-
-;; cache results (memo)
-;; f.e. result for 'justify text after X word is: [lines]'
-(def tj-memo (atom {}))
-(defn- clear-memo [] (reset! tj-memo {}))
-(defn- add-memo   [arg-val return-val] (swap! tj-memo #(assoc % arg-val return-val)))
-(defn- has-memo?  [arg-val] (contains? @tj-memo arg-val))
-(defn- get-memo   [arg-val] (get @tj-memo arg-val))
-
-(defn- text-justification-inner
-  "fits words into lines so that whole text looks pretty
-  @return [`pretty` metric value, [justified lines]]"
-  ([words page-width]
-    (clear-memo)
-    (second (text-justification-inner words page-width 0)))
-  ([words page-width word-idx]
-    (cond
-      (empty? words) [0.0 []]
-      (has-memo? word-idx) (get-memo word-idx)
-      :else
-        (reduce
-          (fn [acc word-id]
-             (let [line (subvec words 0 word-id) rest-words (subvec words word-id)
-                   next-word-idx (+ word-idx word-id)
-                   [sub-prob-badness sub-prob-lines] (text-justification-inner rest-words page-width next-word-idx)
-                   ugliness (+ (badness line page-width) sub-prob-badness)
-                   solution-proposal (cons line sub-prob-lines)]
-              ; (print "sub" line "|words in line" (count words))
-              (add-memo next-word-idx [sub-prob-badness sub-prob-lines]) ;; write to memo
-              (if (< ugliness (first acc)) [ugliness solution-proposal] acc)))
-          [js/Infinity []]
-          (map inc (range (count words))) )))) ;; TODO (dec (count words)) ?
-
-
-(defn- prepare-text
-  "split by paragraphs or treat text as single text flow"
-  [text separate-paragraphs]
-  (if separate-paragraphs
-    (seq (.split text "\n"))
-    [(clojure.string/replace text #"\n" " ")]
-    ))
-
-
+(defn- word-lens-to-text [])
 ;;;;
 ;;;; public interface
 ;;;;
+
 (defn text-justification
   "justify text provided as a collection of words to given page width"
   [text separate-paragraphs page-width]

  (clear-state)
  (doseq [paragraph (prepare-text text separate-paragraphs)]
    ; (println "PARAGRAPH:" paragraph)
    ; (.profile js.console "text-justification")
    (let [words-raw (.split paragraph #" ")
          words (vec (flatten (map #(prepare-word page-width %) words-raw)))
          justified-text (text-justification-inner words page-width)]
        ; (.log js/console "words" (count words) ":" words)
        ; (.log js/console "state" (count justified-text) ":" justified-text)
        (update-state justified-text)
      )
    ; (.profileEnd js.console)
  ))

(ns ^:figwheel-always text-justification.model
    (:require [reagent.core :as reagent :refer [atom]]
              [goog.string :as gstring]))

(enable-console-print!)

;;;; TODO filter out empty words
;;;; TODO precalc badness to hash ?
;;;; TODO remove has-memo?

;;;;
;;;; consts
