   (clear-state)
   (doseq [paragraph (prepare-text text separate-paragraphs)]
     ; (println "PARAGRAPH:" paragraph)
-    ; (.profile js.console "text-justification")
-    (let [words-raw (.split paragraph #" ")
+    (.profile js.console "text-justification")
+    (let [words-raw (.split paragraph #" +")
+          ;;words (vec (filter .blank? (flatten (map #(prepare-word page-width %) words-raw))))
           words (vec (flatten (map #(prepare-word page-width %) words-raw)))
-          justified-text (text-justification-inner words page-width)]
+          word-lens (vec (map count words))
+          justified-text (tj-inner word-lens page-width)]
         ; (.log js/console "words" (count words) ":" words)
         ; (.log js/console "state" (count justified-text) ":" justified-text)
-        (update-state justified-text)
+        (update-state
+        (second (reduce
+          (fn [[start-word-idx lines-atm] words-in-line]
+            (let [next-word-start-idx (+ start-word-idx words-in-line)
+                  words-in-this-line (subvec words start-word-idx next-word-start-idx)]
+              ; (println words-in-this-line)
+              [next-word-start-idx (conj lines-atm words-in-this-line)]
+              ))
+          [0 []]
+          justified-text)))
       )
-    ; (.profileEnd js.console)
+    (.profileEnd js.console)
   ))

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

(enable-console-print!)

;;;; TODO filter out empty words

;;;;
;;;; consts

; (prepare-word-test "aaabbbccc111aaabbbccc111")
; (prepare-word-test "aaabbbccc111aaabbbccc111aaabbbccc111")

(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]
