(ns weathergen.ui.tabs (:require [weathergen.ui.common :as comm :refer [inl]] [javelin.core :refer [->Cell input? cell cell? destroy-cell! lift lens? set-formula! constant? cell-doseq* deref* set-cell! lens formula? alts! dosync* cell-map formula]] [hoplon.jquery :refer [set-attributes! check-val! set-styles! text-val!]] [hoplon.core :refer [form audio input menuitem hgroup do! timeout $text base h1 set-attributes! embed shadow h3 body keygen progress main cite on-page-load i p nav ruby a menu blockquote img $comment span track data u dl select html thead del fieldset aside figure figcaption q on! bdi append-child! video address caption dd rp hr tbody table html-var add-initfn! pre ul replace-child! html-time html-map sup dfn sub mark script button wbr insert-before! strong normalize-class li dt rtc td tr section th optgroup bust-cache iframe remove-child! legend em kbd spliced html-object article abbr template multicol prerendering? <!-- source output set-styles! route-cell header datalist tfoot s ins footer title h5 canvas param div option summary samp small style textarea loop-tpl* h4 head ol details col label picture rt when-dom h6 link page-load colgroup meter html-meta static-elements bdo --> b attribute? code dialog noframes do-watch noscript safe-nth h2 area br]]) (:require-macros [weathergen.cljs.macros :refer [with-bbox with-time formula-of]] [javelin.core :refer [with-let mx2 dosync cell= set-cell!= prop-cell cell-doseq formulet defc defc= macroexpand-all mx formula-of cell-let]] [hoplon.core :refer [definterval text elem+ cache-key with-timeout defelem+ when-tpl static sexp defelem elem def-values if-tpl cond-tpl with-page-load for-tpl with-dom case-tpl loop-tpl with-interval with-init!]]))





;; (set! *warn-on-infer* true)

(defelem tabs
  "Renders a tab control. `selected` is a cell containing the ID of
  the currently selected tab. `tabs` is a vector maps describing the
  tabs.

  Keys include:

  `:id` - Unique ID for the tab.
  `:title` - Title for the tab.
  `:ui` - Content for the tab.
  "
  [attrs _]
  (let [{:keys [selected tabs]} attrs]
    (div
     (div
      :css {:margin-bottom "7px"
            :border-bottom "1px solid lightgray"}
      (for [{:keys [title id]} tabs]
        (inl
         :click #(reset! selected id)
         :css (formula-of [selected]
                {:background (when (= selected id) "black")
                 :color      (if (= selected id)
                               "white"
                               "#737373")
                 :font-size  "120%"
                 :padding    (if (= selected id)
                               "0 10px"
                               0)
                 :margin     (if (= selected id)
                               0
                               "0 10px")
                 :cursor     "pointer"})
         title)))
     (for [{:keys [id ui]} tabs]
       (div
        :css {:padding "0 3px"}
        :toggle (cell= (= id selected))
        ui)))))
