(ns auto-ap.views.components.buttons
  (:require [auto-ap.views.utils :refer [dispatch-event]]
            [reagent.core :as r]))

(defn fa-icon [{:keys [event icon on-click] :as params}]
  [:a.button (cond-> params
               true (dissoc :event :icon)
               (and (not on-click)
                    event)
               (assoc :on-click (dispatch-event event)))
   (into
    [:<>
     [:span.icon [:i.fa {:class icon}]]]
    (r/children (r/current-component)))])



(defn sl-icon [{:keys [event icon on-click] :as params}]
  [:a.button  (cond-> params
                  true (dissoc :event :icon)
                  (and (not on-click)
                       event) (assoc :on-click (dispatch-event event)))
   [:span.icon [:span  {:class icon :style {:font-weight "400"}}]]])

(defn new-button [{:keys [event name class ]}]
  [:a.button.is-outlined {:class class
                          :on-click (dispatch-event event)}
   [:span.icon [:i.fa.fa-plus]]
   [:span name]])

(defn event-button [{:keys [event name class ]}]
  [:a.button.is-outlined {:class class
                          :on-click (dispatch-event event)}
   [:span name]])

(defn dropdown [{:keys [event on-click] :as params}]
  [:a.button (cond-> params
               true (dissoc :event :icon)
               (and (not on-click)
                    event)
               (assoc :on-click (dispatch-event event)))
   (conj (into
          [:<>]
          (r/children (r/current-component)))
         [:span.icon [:i.fa.fa-chevron-down]])])
