(ns todo.app
  (:require [reagent.core :as r]
            [re-frame.core :as rf]
            ["react-native" :as rn]
            ["react-native-gesture-handler" :refer [GestureHandlerRootView]]
            [expo.root :as expo-root]
            [todo.events]
            [todo.subs]
            [todo.views.main :as main]
            [todo.views.add-todo :as add-todo]))

(defn root []
  (let [show-form? @(rf/subscribe [:show-form?])]
    [:> GestureHandlerRootView {:style {:flex 1}}
     [:> rn/StatusBar {:bar-style "light-content" :background-color "#6200EE"}]
     [main/main-screen]
     (when show-form?
       [add-todo/add-todo-form])]))

(defn start
  {:dev/after-load true}
  []
  (expo-root/render-root (r/as-element [root])))

(defn init []
  (rf/dispatch-sync [:initialize-db])
  (start))
