<commit_before>(ns early-vote-site.early-vote-site-detail.views
  (:require [re-frame.core :as re-frame]
            [cljs-pikaday.reagent :as pikaday]
            [early-vote-site.utils :as utils]))

(def schedules-header
  [:thead
    [:tr {:key "schedules-list-head-row"}
      [:th {:name "schedules-start-date"} "Start Date"]
      [:th {:name "schedules-end-date"} "End Date"]
      [:th {:name "schedules-start-time"} "Start Time"]
      [:th {:name "schedules-end-time"} "End Time"]
      [:th {:name "assigned"} "Assigned to this Early Vote Site"]]])

(defn schedule->row
  [schedule]
  [:tr {:key (:id schedule)}
   [:td (utils/format-date (:start-date schedule))]
   [:td (utils/format-date (:end-date schedule))]
   [:td (:start-time schedule)]
   [:td (:end-time schedule)]
   [:td [:input {:type "checkbox"
                 :checked (not (nil? (:assignment-id schedule)))
                 :value (:id schedule)
                 :on-change #(if (not (nil? (:assignment-id schedule)))
                              (re-frame/dispatch [:unassign-schedule (:assignment-id schedule)])
                              (re-frame/dispatch [:assign-schedule (:id schedule)]))}]]])

(defn schedule-form []
  (let [start-date (re-frame/subscribe [:schedule-form/start-date])
        end-date (re-frame/subscribe [:schedule-form/end-date])]
    [:tr {:key "schedule-form"}
     [:td [pikaday/date-selector {:class "form-control"
                                  :date-atom start-date
                                  :max-date-atom end-date
                                  :pikaday-attrs
                                  {:min-date (js/Date.)
                                   :max-date @end-date
                                   :on-select #(re-frame/dispatch [:schedule-form/start-date-selected %])}}]]
     [:td [pikaday/date-selector {:class "form-control"
                                  :date-atom end-date
                                  :min-date-atom start-date
                                  :pikaday-attrs
                                  {:min-date (or @start-date (js/Date.))
                                   :on-select #(re-frame/dispatch [:schedule-form/end-date-selected %])}}]]
     [:td]
     [:td]
     [:td [:button.button {:on-click #(re-frame/dispatch [:schedule-form/save])} "save new schedule"]]]))

(defn schedules-list [selected-early-vote-site-id]
  (let [schedules @(re-frame/subscribe [:selected-early-vote-site-schedules])]
    [:table {:name "schedules-list"}
      schedules-header<commit_msg>change schedule-form to form-2 style, use r/atoms<commit_after>(ns early-vote-site.early-vote-site-detail.views
  (:require [re-frame.core :as re-frame]
            [reagent.ratom :as r]
            [cljs-pikaday.reagent :as pikaday]
            [early-vote-site.utils :as utils]))

(enable-console-print!)

(def schedules-header
  [:thead
    [:tr {:key "schedules-list-head-row"}
      [:th {:name "schedules-start-date"} "Start Date"]
      [:th {:name "schedules-end-date"} "End Date"]
      [:th {:name "schedules-start-time"} "Start Time"]
      [:th {:name "schedules-end-time"} "End Time"]
      [:th {:name "assigned"} "Assigned to this Early Vote Site"]]])

(defn schedule->row
  [schedule]
  [:tr {:key (:id schedule)}
   [:td (utils/format-date (:start-date schedule))]
   [:td (utils/format-date (:end-date schedule))]
   [:td (:start-time schedule)]
   [:td (:end-time schedule)]
   [:td [:input {:type "checkbox"
                 :checked (not (nil? (:assignment-id schedule)))
                 :value (:id schedule)
                 :on-change #(if (not (nil? (:assignment-id schedule)))
                              (re-frame/dispatch [:unassign-schedule (:assignment-id schedule)])
                              (re-frame/dispatch [:assign-schedule (:id schedule)]))}]]])

(defn update-date
  [key _ _ newvalue]
  (re-frame/dispatch [key newvalue]))

(defn schedule-form []
  (let [start-date (r/atom (js/Date.))
        end-date (r/atom nil)]
    (add-watch start-date :schedule-form/start-date-selected update-date)
    (add-watch end-date :schedule-form/end-date-selected update-date)
    (fn []
      [:tr {:key "schedule-form"}
       [:td [pikaday/date-selector {:class "form-control"
                                    :date-atom start-date
                                    :max-date-atom end-date
                                    :pikaday-attrs
                                    {:min-date (js/Date.)
                                     :max-date @end-date}}]]
       [:td [pikaday/date-selector {:class "form-control"
                                    :date-atom end-date
                                    :min-date-atom start-date
                                    :pikaday-attrs
                                    {:min-date (or @start-date (js/Date.))}}]]
       [:td]
       [:td]
       [:td [:button.button {:on-click #(re-frame/dispatch [:schedule-form/save])} "save new schedule"]]])))

(defn schedules-list [selected-early-vote-site-id]
  (let [schedules @(re-frame/subscribe [:selected-early-vote-site-schedules])]
    [:table {:name "schedules-list"}
      schedules-header
{'fraction_non_alphanumeric': 0.16357308584686775, 'fraction_numerical': 0.00019334880123743234, 'mean_word_length': 1.8345205479452056, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1561628', 'n_tokens_mistral': 1680, 'n_tokens_neox': 1548, 'n_words': 337}