 (ns figwheel-sidecar.config-check.type-check
   (:require
    [clojure.pprint :as pprint]
+
+   [fipp.visit :refer [visit]]
+   [fipp.edn :as fedn]
    [fipp.engine :refer [pprint-document]]
+
    [figwheel-sidecar.config-check.ansi :refer [color]]
    [clj-fuzzy.metrics :as metrics]
    [clojure.walk :as walk]
    [clojure.string :as string]
    [clojure.set :refer [difference]]))
+
+(def edn-printer (fedn/map->EdnPrinter {}))
+
+(defn fipp-format-data [data]
+  (visit edn-printer data))
 
 (defn log [x] (prn x) x)
 


(defn print-path [[x & xs] leaf-node edn]
  (if (and x (get edn x))
    [:group (if (and (not (map? edn)) (integer? x))
              "[{"
              (str (pr-str x ) " {"))
     [:nest 2
      :line
      (print-path xs leaf-node (get edn x))
      ]
     (if (and (not (map? edn)) (integer? x))
       "}]"
       "}")]
    leaf-node))

(defn print-path-error
  ([{:keys [path orig-config] :as error} leaf-node document]

  #_(doall (*schema-rules* [:doc-key 'Rap]))
  )

(defn print-key-doc [k key-doc]
  (cond
    (string? key-doc) key-doc
    (map? key-doc)
    (if (:example key-doc)
      (let [example (:example key-doc)
            example (if (fn? example) (example) example)]
        [:group
         (color (:content key-doc) :underline) 
         :break
         :break
         [:nest 2
          (pr-str k)
          " "
          (fipp-format-data example)]
         ])
      (color (:content key-doc) :underline) )
    :else ""))

(defn document-key [parent-type k]
  (let [{:keys [ky] :as p} (docs-for parent-type k)]
    (if ky
      [:group
       "-- Docs for key " (color (pr-str k) :bold) " --" 
       :break
       (print-key-doc k ky)
       :break]
      "")))

