<commit_before>(ns re-demo.date
  (:require [re-demo.util         :refer  [title]]
            [cljs-time.core       :refer  [now]]
            [cljs-time.predicates :refer  [sunday? monday?]]
            [re-com.core          :refer  [label checkbox]]
            [re-com.date          :refer  [inline-picker dropdown-picker previous iso8601->date]]
            [re-com.box           :refer  [h-box v-box box gap line border]]
            [re-com.dropdown      :refer  [single-dropdown]]
            [reagent.core         :as     r]))

(defn- toggle-inclusion! [set-atom member]
  "convenience function to include/exclude member from"
  (reset! set-atom
          (if (contains? @set-atom member)
            (disj @set-atom member)
            (conj @set-atom member))))

(def days-map {:Su "S" :Mo "M" :Tu "T" :We "W" :Th "T" :Fr "F" :Sa "S"})

(defn- parameters-with
  [content enabled-days disabled? show-today? show-weeks?]
  (let [day-check (fn [day] [v-box
                       :align :center
                       :children [[:label {:class "day-enabled"} (day days-map)]
                                  [checkbox
                                   :model (@enabled-days day)
                                   :on-change #(toggle-inclusion! enabled-days day)
                                   :style {:margin-top "-2px"}]]])]
    (fn []
      [v-box
       :gap "20px"
       :align :start
       :children [[label :style {:font-style "italic"} :label "parameters:"]
                  [h-box
                   :gap "20px"
                   :align :start
                   :children [[checkbox
                               :label ":disabled"
                               :model disabled?
                               :on-change #(reset! disabled? %)]
                              [checkbox
                               :label ":show-today"
                               :model show-today?
                               :on-change #(reset! show-today? %)]
                              [checkbox
                               :label ":show-weeks"
                               :model show-weeks?
                               :on-change #(reset! show-weeks? %)]]]
                  [h-box
                   :gap "2px"
                   :align :center
                   :children [[day-check :Su]
                              [day-check :Mo]
                              [day-check :Tu]
                              [day-check :We]
                              [day-check :Th]
                              [day-check :Fr]
                              [day-check :Sa]
                              [gap :width "5px"]
                              [label :label ":enabled-days"]
                              [gap :width "15px"]
                              [:label
                               {:class "day-enabled" :style {:color "orange"}}
                               "(warning: excluding selected day causes assertion error)"]]]
                  content]])))



  (defn show-variant
    [variation]
    (let [model1       (r/atom (now))
          model2       (r/atom (iso8601->date "20140914"))
          disabled?    (r/atom false)
          show-today?  (r/atom true)
          show-weeks?  (r/atom false)
          enabled-days (r/atom (-> days-map keys set))]
      (case variation
        "1" [(fn []
               [parameters-with
                [h-box
                 :gap "20px"
                 :align :start
                 :children [[(fn []
                               [inline-picker
                                :model model1
                                :disabled disabled?
                                :show-today @show-today?
                                :show-weeks @show-weeks?
                                :enabled-days @enabled-days
                                :on-change #(reset! model1 %)])]
                            ;; restricted to both minimum & maximum date
                            [(fn []
                               [inline-picker
                                :model model2
                                :minimum (iso8601->date "20140831")
                                :maximum (iso8601->date "20141019")
                                :show-today @show-today?
                                :show-weeks @show-weeks?
                                :enabled-days @enabled-days
                                :disabled disabled?
                                :on-change #(reset! model2 %)])]]]
                enabled-days
                disabled?
                show-today?
                show-weeks?])]
        "2" [(fn []
               [parameters-with
                [h-box
                 :size "auto"
                 :align :start
                 :children [[gap :size "120px"]
                            [(fn []
                               [dropdown-picker
                                :model model1
                                :show-today @show-today?
                                :show-weeks @show-weeks?
                                :enabled-days @enabled-days
                                :format "dd MMM, yyyy"
                                :disabled disabled?
                                :on-change #(reset! model1 %)])]]]
                enabled-days
                disabled?
                show-today?
                show-weeks?])])))


(defn notes
  [selected-variation]
  [v-box
   :width "500px"
   :children [[:div.h4 "Parameters:"]
              [:div {:style {:font-size "small"}}
               [:label {:style {:font-variant "small-caps"}} "required"]
                [:ul
                 [:li.spacer [:strong ":model"]
                  " - goog.date.UtcDateTime can be reagent/atom. Represents displayed month and actual selected day. Must be one of :enabled-days"]
                 [:li.spacer [:strong ":on-change"]
                  " - callback will be passed single arg of the selected goog.date.UtcDateTime."]
                 ]
               [:label {:style {:font-variant "small-caps"}} "optional"]
                [:ul
                 [:li.spacer [:strong ":disabled"]
                  " - boolean can be reagent/atom. (default false) If true, navigation is allowed but selection is disabled."]
                 [:li.spacer [:strong ":enabled-days"]
                  " - set of any #{:Su :Mo :Tu :We :Th :Fr :Sa} If nil or empty, all days are enabled."]
                 [:li.spacer [:strong ":show-weeks"]
                  " - boolean. (default false) If true, first column shows week numbers."]
                 [:li.spacer [:strong ":show-today"]
                  " - boolean. (default false) If true, today's date is highlighted different to selection. When both today's date and selected day are the same, selected highlight takes precedence."]
                 [:li.spacer [:strong ":minimum"]
                  " - optional goog.date.UtcDateTime inclusive beyond which navigation and selection is blocked."]
                 [:li.spacer [:strong ":maximum"]
                  " - optional goog.date.UtcDateTime inclusive beyond which navigation and selection is blocked."]
                 [:li.spacer [:strong ":hide-border"]
                  " - boolean. Default false."]
                 (when (= "2" @selected-variation)
                   [:li.spacer [:strong ":format"]
                    " - string format for dropdown label showing currently selected date see cljs_time.format Default \"yyyy MMM dd\""])]]]])

(def variations [{:id "1" :label "Inline"}
                 {:id "2" :label "Dropdown"}
                 #_{:id "3" :label "Inline with min/max"}])

(defn panel
  []
  (let [selected-variation (r/atom "1")]
    (fn []
      [v-box
       :children [[:h3.page-header "Date Picker"]
                  [h-box
                   :gap "50px"
                   :children [[notes selected-variation]
                              [v-box
                               :gap "15px"
                               :size "auto"<commit_msg>date picker demo WIP - remove redundant anon function level<commit_after>(ns re-demo.date
  (:require [re-demo.util         :refer  [title]]
            [cljs-time.core       :refer  [now]]
            [cljs-time.predicates :refer  [sunday? monday?]]
            [re-com.core          :refer  [label checkbox]]
            [re-com.date          :refer  [inline-picker dropdown-picker previous iso8601->date]]
            [re-com.box           :refer  [h-box v-box box gap line border]]
            [re-com.dropdown      :refer  [single-dropdown]]
            [reagent.core         :as     r]))

(defn- toggle-inclusion! [set-atom member]
  "convenience function to include/exclude member from"
  (reset! set-atom
          (if (contains? @set-atom member)
            (disj @set-atom member)
            (conj @set-atom member))))

(def days-map {:Su "S" :Mo "M" :Tu "T" :We "W" :Th "T" :Fr "F" :Sa "S"})

(defn- parameters-with
  [content enabled-days disabled? show-today? show-weeks?]
  (let [day-check (fn [day] [v-box
                       :align :center
                       :children [[:label {:class "day-enabled"} (day days-map)]
                                  [checkbox
                                   :model (@enabled-days day)
                                   :on-change #(toggle-inclusion! enabled-days day)
                                   :style {:margin-top "-2px"}]]])]
    (fn []
      [v-box
       :gap "20px"
       :align :start
       :children [[label :style {:font-style "italic"} :label "parameters:"]
                  [h-box
                   :gap "20px"
                   :align :start
                   :children [[checkbox
                               :label ":disabled"
                               :model disabled?
                               :on-change #(reset! disabled? %)]
                              [checkbox
                               :label ":show-today"
                               :model show-today?
                               :on-change #(reset! show-today? %)]
                              [checkbox
                               :label ":show-weeks"
                               :model show-weeks?
                               :on-change #(reset! show-weeks? %)]]]
                  [h-box
                   :gap "2px"
                   :align :center
                   :children [[day-check :Su]
                              [day-check :Mo]
                              [day-check :Tu]
                              [day-check :We]
                              [day-check :Th]
                              [day-check :Fr]
                              [day-check :Sa]
                              [gap :width "5px"]
                              [label :label ":enabled-days"]
                              [gap :width "15px"]
                              [:label
                               {:class "day-enabled" :style {:color "orange"}}
                               "(warning: excluding selected day causes assertion error)"]]]
                  content]])))



  (defn show-variant
    [variation]
    (let [model1       (r/atom (now))
          model2       (r/atom (iso8601->date "20140914"))
          disabled?    (r/atom false)
          show-today?  (r/atom true)
          show-weeks?  (r/atom false)
          enabled-days (r/atom (-> days-map keys set))]
      (case variation
        "1" [parameters-with
             [h-box
              :gap "20px"
              :align :start
              :children [[(fn []
                            [inline-picker
                             :model model1
                             :disabled disabled?
                             :show-today @show-today?
                             :show-weeks @show-weeks?
                             :enabled-days @enabled-days
                             :on-change #(reset! model1 %)])]
                         ;; restricted to both minimum & maximum date
                         [(fn []
                            [inline-picker
                             :model model2
                             :minimum (iso8601->date "20140831")
                             :maximum (iso8601->date "20141019")
                             :show-today @show-today?
                             :show-weeks @show-weeks?
                             :enabled-days @enabled-days
                             :disabled disabled?
                             :on-change #(reset! model2 %)])]]]
             enabled-days
             disabled?
             show-today?
             show-weeks?]
        "2" [parameters-with
             [h-box
              :size "auto"
              :align :start
              :children [[gap :size "120px"]
                         [(fn []
                            [dropdown-picker
                             :model model1
                             :show-today @show-today?
                             :show-weeks @show-weeks?
                             :enabled-days @enabled-days
                             :format "dd MMM, yyyy"
                             :disabled disabled?
                             :on-change #(reset! model1 %)])]]]
             enabled-days
             disabled?
             show-today?
             show-weeks?])))


(defn notes
  [selected-variation]
  [v-box
   :width "500px"
   :children [[:div.h4 "Parameters:"]
              [:div {:style {:font-size "small"}}
               [:label {:style {:font-variant "small-caps"}} "required"]
                [:ul
                 [:li.spacer [:strong ":model"]
                  " - goog.date.UtcDateTime can be reagent/atom. Represents displayed month and actual selected day. Must be one of :enabled-days"]
                 [:li.spacer [:strong ":on-change"]
                  " - callback will be passed single arg of the selected goog.date.UtcDateTime."]
                 ]
               [:label {:style {:font-variant "small-caps"}} "optional"]
                [:ul
                 [:li.spacer [:strong ":disabled"]
                  " - boolean can be reagent/atom. (default false) If true, navigation is allowed but selection is disabled."]
                 [:li.spacer [:strong ":enabled-days"]
                  " - set of any #{:Su :Mo :Tu :We :Th :Fr :Sa} If nil or empty, all days are enabled."]
                 [:li.spacer [:strong ":show-weeks"]
                  " - boolean. (default false) If true, first column shows week numbers."]
                 [:li.spacer [:strong ":show-today"]
                  " - boolean. (default false) If true, today's date is highlighted different to selection. When both today's date and selected day are the same, selected highlight takes precedence."]
                 [:li.spacer [:strong ":minimum"]
                  " - optional goog.date.UtcDateTime inclusive beyond which navigation and selection is blocked."]
                 [:li.spacer [:strong ":maximum"]
                  " - optional goog.date.UtcDateTime inclusive beyond which navigation and selection is blocked."]
                 [:li.spacer [:strong ":hide-border"]
                  " - boolean. Default false."]
                 (when (= "2" @selected-variation)
                   [:li.spacer [:strong ":format"]
                    " - string format for dropdown label showing currently selected date see cljs_time.format Default \"yyyy MMM dd\""])]]]])


(def variations [{:id "1" :label "Inline"}
                 {:id "2" :label "Dropdown"}])


(defn panel
  []
  (let [selected-variation (r/atom "1")]
    (fn []
      [v-box
       :children [[:h3.page-header "Date Picker"]
                  [h-box
                   :gap "50px"
                   :children [[notes selected-variation]
                              [v-box
                               :gap "15px"
                               :size "auto"
{'fraction_non_alphanumeric': 0.11570092284512525, 'fraction_numerical': 0.009730679892020842, 'mean_word_length': 1.0496654657745754, 'pattern_counts': {'":': 28, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3268431', 'n_tokens_mistral': 4250, 'n_tokens_neox': 3916, 'n_words': 1077}