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

  (let [total-length (utils/line-length line)]
    (if (> total-length page-width)
      js/Infinity
      (utils/exp (- page-width total-length) 3))))

(defn- text-justification-inner
  "fits words into lines so that whole text looks pretty
  @return [`pretty` metric value, [justified lines]]"
  [words page-width]
  (if (empty? words)
    [0.0 []]
    (reduce
      (fn [acc word-id]
         (let [line (subvec words 0 word-id) rest-words (subvec words word-id)
               sub-problem-solution (text-justification-inner rest-words page-width)
               ugliness (+ (badness line page-width) (first sub-problem-solution))
               solution-proposal (cons line (second sub-problem-solution))]
          ; (print "sub" line "|words in line" (count words))
          (if (< ugliness (first acc)) [ugliness solution-proposal] acc)))
      [js/Infinity []]
      (map inc (range (count words))) )))

(defn- prepare-text
  "split by paragraphs or treat text as single text flow"


(enable-console-print!)

;;;; TODO filter out empty words

;;;;
;;;; consts
