 (ns wines.gui
   (:require [seesaw.dev :as dev]
             [seesaw.core :as ss]
-            [wines.util :refer [parse-json]]))
+            [wines.util :refer [parse-json]]
+            [clojure.pprint :refer [pprint]]))
 
 (defn call-ui []
   (println "Calling ui soon!")
   nil)
 
 (def bg-color "#fdfdfd")
-
 (def max-height 530)
 (def app-height 600)
+(def wine-results-size [370 :by max-height])
+(def wine-properties-size [400 :by (- max-height 30)])
+(def main-search-size [210 :by max-height])
 
 (ss/native!)
 
+
+;;;; TODO: development, mocking. remove!
+(def mocked-body
+  (take 35
+    (cycle
+      (:List
+        (:Products
+          (parse-json
+            (slurp (clojure.java.io/resource "body.seed.json")) "testing"))))))
+
+(def results-model
+  (for [product mocked-body]
+    (let [simpler-product (select-keys product [:Name :Id])]
+      (clojure.string/join
+        " "
+        [(format "%-8d" (:Id simpler-product))
+         (:Name simpler-product)]
+        ))))
+
+;;;;;
+
+
+;; todo: prompt user for api key?
+
+; TODO: why menubar wont show?
+(def main-menu
+  (ss/menubar
+    :items [(ss/menu
+              :text "File"
+              :items [(ss/action
+                        :name "Open..."
+                        :key "menu O"
+                        :handler (fn [e] (println "Open something")))])
+            (ss/menu
+              :text "Edit"
+              :items [(ss/action
+                        :name "Undo"
+                        :key "menu Z"
+                        :handler (fn [e] (println "Undo something")))])
+            (ss/menu
+              :text "Help"
+              :items [(ss/action
+                        :name "About"
+                        :key "menu H"
+                        :handler (fn [e] (println "Show about dialog")))])]))
+
 (def window (ss/frame :title "Wine Finder",
+                      :menubar main-menu
 ;;            :on-close :exit,    ; add this when done...?
 ;;                       :resizable? false  ; todo: resizable false
                       :size [950 :by app-height]

   :class :label-input))


(def mocked-body
  (reduce
    into
    (replicate
      5
      (:List
        (:Products
          (parse-json (slurp (clojure.java.io/resource "body.seed.json")) "w.e"))))))



;; (prn (:Name (first mocked-body)))

(def results-model (for [product mocked-body]
  [(:Name (select-keys product [:Name]))]))



(def results (ss/scrollable (ss/listbox :model results-model
                         :id :results
                         :border [2 "Results" 10]
                         :background :white
                         :foreground :black
                         :size [(- 300 20) :by (- max-height 30)]
                         ; todo: change color when selecting items form box,
;;                          using renderer/ :listen :selection
                         :listen [:selection
                                  (fn [event]
                                    (println "You selected " (ss/selection event)))]
                         )
                            :size [300 :by max-height]
                            :border nil
                            ))


(defn render-property [renderer {:keys [value]}]
  ; todo clean this keys / value implementation
  (ss/config! renderer :background :white :foreground :black :border nil))

(def result-properties
  (ss/scrollable (ss/listbox
                   :id :result-properties
                   :model ["Description: Hello World" "Location: left right"]
                   :border [1 14]
                   :size [(- 400 20) :by (- max-height 30)]
                   :background :white
                   :renderer render-property)

                 :size [400 :by max-height]
                 :border nil
                 )
  )


(def container

(defn display [content]
  (ss/config! window :content content)   ; config! used to configuer frame, lbls etc
  content)

(def title-lbl (ss/label "Catalog Search"))

