 (defn sign-in [profile]
   (let [{:keys [email password]} profile]
     (swap! form-state assoc :signing-up false)
-    (if (not (or (empty? email) (empty? password)))
+    (if-not (or (empty? email) (empty? password))
       (post-sign-in profile))))
 
 (defn sign-up [profile]
   (let [{:keys [email username password]} profile]
-    (if (not (or (empty? email) (empty? username) (empty? password)))
+    (if-not (or (empty? email) (empty? username) (empty? password))
       (post-sign-up profile))))
 
-(defn reset-password [profile]
-  (if (not (empty? (:email profile)))
+(defn reset-password-email [profile]
+  (if-not (empty? (:email profile))
     (post-reset-password profile)))
 
 ;; -------------------------

  [:div [(session/get :current-page)]])

(secretary/defroute "/" []
                    (session/put! :current-page #'sign-in-component-wrapper))


(secretary/defroute "/sign-up" []
                    (session/put! :current-page #'sign-up-component-wrapper))

(secretary/defroute "/email-verified" []
                    (session/put! :current-page #'email-verified-component))

(secretary/defroute "/reset-password" []
                    (session/put! :current-page #'reset-email-component-wrapper))

;; -------------------------
;; History

  (let [profile (atom {:username ""
                       :email    ""
                       :password ""})]
    [welcome-component-wrapper
     [:div.form-group {:style {:padding "1em"}}
      [:p.text-center.bg-primary "Sign in"]
      [:label "email:"]
      [email-input-field profile]
      [:label "password:"]
      [passsword-input-field profile]
      [:br]
      [:div.checkbox
       [:label
        [:input {:type "checkbox"}] "remember me?"]
       [:p.pull-right
        [:button.btn.btn-sm {:type     "button"
                             :on-click #(secretary/dispatch! "/reset-password")}
         "forgot password?"]]]
      [:br]
      [:button.btn.btn-default {:type     "button"
                                :on-click (fn [e]
                                            (sign-in @profile)
                                            (.preventDefault e))
                                } "sign-in"]

      [:button.btn.btn-default.pull-right {:type     "button"
                                           :on-click #(secretary/dispatch! "/sign-up")
                                           } "sign-up"]]]))


(defn sign-up-component []
  (let [profile (atom {:username ""
                       :email    ""
                       :password ""})]
    [welcome-component-wrapper
     [:div.form-group {:style {:padding "1em"}}

      [:p.text-center.bg-primary "Create Account"]

      [:label "username:"]
      [username-input-field profile]
      [:label "email:"]
      [email-input-field profile]
      [:label "password:"]
      [passsword-input-field profile]

      [:br]

      [:button.btn.btn-default {:type     "button"
                                :on-click #(secretary/dispatch! "/")
                                } "sign-in"]

      [:button.btn.btn-default.pull-right {:type     "button"
                                           :on-click (fn [e]
                                                       ;; (swap! form-state assoc :signing-up true)
                                                       (sign-up @profile)
                                                       (.preventDefault e))
                                           } "sign-up"]]]
    ))

(defn reset-password-component []
  (let [profile (atom {:username ""
                       :email    ""
                       :password ""})]
    [welcome-component-wrapper
     [:div.form-group {:style {:padding "1em"}}
      [:p.text-center.bg-primary "Reset Your Password"]
      [:label "email:"]
      [email-input-field profile]
      [:br]
      [:p [:button.btn.btn-default {:type     "button"
                                    :on-click (fn [e]
                                                (reset-password-email @profile)
                                                (.preventDefault e))
                                    } "reset"]]]]
    ))

(defn new-password-component []
  (let [profile (atom {:username ""
                       :email    ""
                       :password ""})]
    (welcome-component-wrapper
      [:div.form-group {:style {:padding "1em"}}
       [:p.text-center.bg-primary "New Password"]
       [:label "password:"]
       [passsword-input-field profile]
       [:br]
       [:button.btn.btn-default {:type     "button"
                                 :on-click (fn [e]
                                             ;; (swap! form-state assoc :signing-up true)
                                             (reset-password-email @profile)
                                             (.preventDefault e))
                                 } "reset"]])))

(defn show-loading-component []
  [:p.ball-loader.text-center {:style {:left   180
                                       :bottom 69}}])
(defn email-verified-component []
  [welcome-component-wrapper [:div
                              [:h3.text-center
                               [:u "Your email has been verified"]
                               [:br]
                               [:p [:a {:on-click #(secretary/dispatch! "/")} "you may now proceed to login"]]]]])

;; -------------------------
;; Routes

