(ns com.oly.static-sites.ui-hiccup.chess)

(defn square [{:keys [colour highlight selected on-click bg-colour class piece] :as sq}]
  [:div.flex.items-center.justify-around.w-8.h-8.md:w-12.lg:w-24.md:h-12.lg:h-24.tc
   {:class (str "fl bg-slate-"  (if (= bg-colour "black") "200" "800") " "
                ;;class
                highlight
                (when selected " bg-red ")
                ;;" bg-green-500 "
                (if (= (-> piece :colour) :white) " white white-80" " black black-80" )

                )
    :on-click #(on-click % sq)}
   [:p.v-mid.ma0.pa0.f2 (-> piece :character)]])

(defn board [size items]
  (loop [x-pos 1
         y-pos 1
         row [:div.h-8.md:h-12.lg:h-24]
         result [:div]]
    (if (> y-pos size ) 
      result
      (if (= size x-pos)
        (recur 1
               (inc y-pos)
               [:div.h-8.md:h-12.lg:h-24]
               (conj result (conj row (square (get items [x-pos y-pos])))))
        (recur (inc x-pos)
               y-pos
               (conj row (square (get items [x-pos y-pos])))
               result)))))


