 #_(reset! app-state init-state)
 #_(swap! app-state assoc :turn :black)
 
+;;-------------
+;;--DYNAMIC CSS
 (defn board-style
   [data]
   {:border "1px solid black"

        (string-mapping
         (range 6 8)
         (range 8)
         (map char (range 97 113)))
        init-black-bindings
        (string-mapping
         (reverse (range 2))
         (range 8)
         (map char (range 97 113)))]
      {:width 500
       :height 500
       :board
       (mapv
        (fn [row-pieces row-colors]
          (mapv
           (fn [piece color]
             {:piece piece :color color})
           row-pieces row-colors))
        init-pieces init-colors)     
       :string-map
       {:white {:str->pos
                init-white-bindings
                :pos->str
                (s/map-invert init-white-bindings)}
        :black {:str->pos
                init-black-bindings
                :pos->str
                (s/map-invert init-black-bindings)}}
       :turn :white}))

(defonce black #{\u265F \u265C \u265E \u265D \u265B \u265A})

    (filter #(not (out-of-board? %)) [[(+ row 2) col]])
    (filter #(not (out-of-board? %)) [[(- row 2) col]])))

(defn change-color
  [[row col] color]
  (fn [state]
    (assoc-in state [:board row col :color] color)))

(defn change-positions-to-color
  [positions color]
  (fn [state]
    (let [pos->str
          (map #(vector %1 %2)
               positions
               default-keybindings)]
      (reduce
       (fn [hmap [[row col] char]]
         (update-in hmap [:board row col] assoc :color color :text char))
       state
       pos->str))))

(defn positions-to-default-color
  [positions]
  (fn [state]
    (reduce
     (fn [hmap [row col]]
       (let [color (get-in init-colors [row col])]
         (update-in hmap [:board row col] assoc :color color :text "")))
     state
     positions)))

(defn handle-deselection
  [[row col :as pos] positions]
  (comp
   (change-color pos (get-in init-colors [row col]))
   (positions-to-default-color positions)))

;;can almost certainly be abstracted more
;;so highlighting and unhighling can use
;;majority of the same functions
(defn handle-selection
  [pos turn]
  (comp
   (change-positions-to-color
    (possible-placements pos turn) highlight-color)
   (change-color pos highlight-color)))

(defn deselect-piece
  "changes the board it its normal no-piece selected
  state were the board colors are default"
  [state text-state old positions]
  (let [[row col :as pos]
        (get-in
         state
         [:string-map (:turn state) old])
        color (get-in init-colors [row col])
        pos-colors (map
                    (fn [[row col]]
                      (get-in
                       state
                       [:board row col :color]))
                    positions)]
    (swap! app-state (handle-deselection pos positions))
    (swap! text-state assoc :move-to {})))

(defn deselected?
  "returns true if the input signifies the user deselected a piece"
  [state old new] 
  (and
   (get-in state
           [:string-map (:turn state) old])
   (> (count old) (count new))))

(defn select-piece
  [state text-state [row col :as pos]]
  (swap! text-state
         assoc :move-to (zipmap
                         default-keybindings
                         (vec (possible-placements pos (:turn state)))))
  (swap! app-state (handle-selection pos (:turn state))))

(defn handle-text-input
