<commit_before>(ns re-com.tabs
   (:require [clojure.set  :refer [superset?]]
             [re-com.util  :refer [deref-or-value]]
             [reagent.core :as    reagent]))


(defn find-tab
  "utility function for finding a tab definition with a given id
  'tab-defs' in a vector of definitions
  'id' is the id of one of them
  returns nil if no definition found otherwise returns the first match found"
  [id tab-defs]
  (first (filter #(= id (:id %)) tab-defs)))


;;--------------------------------------------------------------------------------------------------
;; Component: horizontal-tabs
;;--------------------------------------------------------------------------------------------------

(def tabs-args
  #{:model      ;; Sets/holds/returns the currently selected tab - model can be atom
    :tabs       ;; The tabs object defined as a vector of maps (can be literal/variable/atom):
                ;;   [{:id ::tab1  :label "Tab1"}
                ;;    {:id ::tab2  :label "Tab2"}
                ;;    {:id ::tab3  :label "Tab3"}]
    })


(defn horizontal-tabs
  [& {:keys [model tabs]
      :as   args}]
  {:pre [(superset? tabs-args (keys args))]}
  (let [current  (deref-or-value model)
        tabs     (deref-or-value tabs)
        _        (assert (not-empty (filter #(= current (:id %)) tabs)) "model not found in tabs vector")]
    [:ul
     {:class "rc-tabs nav nav-tabs"
      :style {:flex                "none"
              :-webkit-user-select "none"}}
     (for [t tabs]
       (let [id        (:id t)
             label     (:label t)
             selected? (= id current)]                   ;; must use current instead of @model to avoid reagent warnings
         [:li
          {:class  (if selected? "active")
           :key    (str id)}
          [:a
           {:style     {:cursor "pointer"}
            :on-click  #(reset! model id)}
           label]]))]))


;;--------------------------------------------------------------------------------------------------
;; Component: horizontal-bar-tabs
;;--------------------------------------------------------------------------------------------------

(defn horizontal-bar-tabs
  [& {:keys [model tabs]
      :as   args}]
  {:pre [(superset? tabs-args (keys args))]}
  (let [current  (deref-or-value model)
        tabs     (deref-or-value tabs)
        _        (assert (not-empty (filter #(= current (:id %)) tabs)) "model not found in tabs vector")]
    [:div
     {:class "rc-tabs btn-group"
      :style {:flex                "none"
              :-webkit-user-select "none"}}
     (for [t tabs]
       (let [id        (:id t)
             label     (:label t)
             selected? (= id current)]                    ;; must use current instead of @model to avoid reagent warnings
         [:button.btn.btn-default
          {:type     "button"
           :key      (str id)
           :style    (if selected? {:background-color "#aaa"  :color "white"} {})
           :on-click #(reset! model id)}
          label]))]))


;;--------------------------------------------------------------------------------------------------
;; Component: pill-tabs
;;--------------------------------------------------------------------------------------------------

(defn- pill-tabs    ;; tabs-like in action
  [& {:keys [model tabs vertical?]}]
  (let [current  (deref-or-value model)
        tabs     (deref-or-value tabs)
        _        (assert (not-empty (filter #(= current (:id %)) tabs)) "model not found in tabs vector")]
    [:ul
     {:class (str "rc-tabs nav nav-pills" (when vertical? " nav-stacked"))<commit_msg>Fix class issue on tabs.  Looks much better now.<commit_after>(ns re-com.tabs
   (:require [clojure.set  :refer [superset?]]
             [re-com.util  :refer [deref-or-value]]
             [reagent.core :as    reagent]))


(defn find-tab
  "utility function for finding a tab definition with a given id
  'tab-defs' in a vector of definitions
  'id' is the id of one of them
  returns nil if no definition found otherwise returns the first match found"
  [id tab-defs]
  (first (filter #(= id (:id %)) tab-defs)))


;;--------------------------------------------------------------------------------------------------
;; Component: horizontal-tabs
;;--------------------------------------------------------------------------------------------------

(def tabs-args
  #{:model      ;; Sets/holds/returns the currently selected tab - model can be atom
    :tabs       ;; The tabs object defined as a vector of maps (can be literal/variable/atom):
                ;;   [{:id ::tab1  :label "Tab1"}
                ;;    {:id ::tab2  :label "Tab2"}
                ;;    {:id ::tab3  :label "Tab3"}]
    })


(defn horizontal-tabs
  [& {:keys [model tabs]
      :as   args}]
  {:pre [(superset? tabs-args (keys args))]}
  (let [current  (deref-or-value model)
        tabs     (deref-or-value tabs)
        _        (assert (not-empty (filter #(= current (:id %)) tabs)) "model not found in tabs vector")]
    [:ul
     {:class "rc-tabs nav nav-tabs"
      :style {:flex                "none"
              :-webkit-user-select "none"}}
     (for [t tabs]
       (let [id        (:id t)
             label     (:label t)
             selected? (= id current)]                   ;; must use current instead of @model to avoid reagent warnings
         [:li
          {:class  (if selected? "active")
           :key    (str id)}
          [:a
           {:style     {:cursor "pointer"}
            :on-click  #(reset! model id)}
           label]]))]))


;;--------------------------------------------------------------------------------------------------
;; Component: horizontal-bar-tabs
;;--------------------------------------------------------------------------------------------------

(defn horizontal-bar-tabs
  [& {:keys [model tabs]
      :as   args}]
  {:pre [(superset? tabs-args (keys args))]}
  (let [current  (deref-or-value model)
        tabs     (deref-or-value tabs)
        _        (assert (not-empty (filter #(= current (:id %)) tabs)) "model not found in tabs vector")]
    [:div
     {:class "rc-tabs btn-group"
      :style {:flex                "none"
              :-webkit-user-select "none"}}
     (for [t tabs]
       (let [id        (:id t)
             label     (:label t)
             selected? (= id current)]                    ;; must use current instead of @model to avoid reagent warnings
         [:button.btn.btn-default
          {:type     "button"
           :key      (str id)
           :class    (str "btn btn-default "  (if selected? "active"))
           ;;:style    (if selected? {:background-color "#aaa"  :color "white"} {})
           :on-click #(reset! model id)}
          label]))]))


;;--------------------------------------------------------------------------------------------------
;; Component: pill-tabs
;;--------------------------------------------------------------------------------------------------

(defn- pill-tabs    ;; tabs-like in action
  [& {:keys [model tabs vertical?]}]
  (let [current  (deref-or-value model)
        tabs     (deref-or-value tabs)
        _        (assert (not-empty (filter #(= current (:id %)) tabs)) "model not found in tabs vector")]
    [:ul
     {:class (str "rc-tabs nav nav-pills" (when vertical? " nav-stacked"))
{'fraction_non_alphanumeric': 0.28573380705110685, 'fraction_numerical': 0.001639792292976223, 'mean_word_length': 1.212515114873035, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3997284', 'n_tokens_mistral': 2067, 'n_tokens_neox': 1916, 'n_words': 614}