(ns hoplon.app-pages._mission_DOT_html (:require [weathergen.ipc :as ipc] [weathergen.progress :as progress] [weathergen.ui :as ui] [taoensso.timbre :as log :refer-macros ^{:line 6, :column 28} (log trace debug info warn error fatal report logf tracef debugf infof warnf errorf fatalf reportf spy get-env log-env)] [javelin.core :refer [->Cell input? cell cell? destroy-cell! lift lens? set-formula! constant? cell-doseq* deref* set-cell! lens formula? alts! dosync* cell-map formula]] [hoplon.jquery :refer [set-attributes! check-val! set-styles! text-val!]] [hoplon.core :refer [form audio input menuitem hgroup do! timeout $text base h1 set-attributes! embed shadow h3 body keygen progress main cite on-page-load i p nav ruby a menu blockquote img $comment span track data u dl select html thead del fieldset aside figure figcaption q on! bdi append-child! video address caption dd rp hr tbody table html-var add-initfn! pre ul replace-child! html-time html-map sup dfn sub mark script button wbr insert-before! strong normalize-class li dt rtc td tr section th optgroup bust-cache iframe remove-child! legend em kbd spliced html-object article abbr template multicol prerendering? <!-- source output set-styles! route-cell header datalist tfoot s ins footer title h5 canvas param div option summary samp small style textarea loop-tpl* h4 head ol details col label picture rt when-dom h6 link page-load colgroup meter html-meta static-elements bdo --> b attribute? code dialog noframes do-watch noscript safe-nth h2 area br]]) (:require-macros [javelin.core :refer [with-let mx2 dosync cell= set-cell!= prop-cell cell-doseq formulet defc defc= macroexpand-all mx formula-of cell-let]] [hoplon.core :refer [definterval text elem+ cache-key with-timeout defelem+ when-tpl static sexp defelem elem def-values if-tpl cond-tpl with-page-load for-tpl with-dom case-tpl loop-tpl with-interval with-init!]]))








;; (set! *warn-on-infer* true)

(defmethod ipc/on-message "open-mission"
  [_ event installations path]
  (try
    (binding [progress/*reporter* #(ipc/send-to-main "progress-message" %)]
      (log/debug "open-mission" :installations installations :path path)
      (ui/load-mission installations path))
    (ipc/send-to-main "load-complete")
    (catch :default ^js/Error e
      (log/error e "Load failed" :stack (.-stack e))
      (ipc/send-to-main "load-failed" (.-stack e)))))

(defmethod ipc/on-message "open-briefing"
  [_ event installations path]
  (try
    (binding [progress/*reporter* #(ipc/send-to-main "progress-message" %)]
      (ui/load-briefing installations path)
      (ipc/send-to-main "load-complete"))
    (catch :default ^js/Error e
      (log/error e "Load failed" :stack (.-stack e))
      (ipc/send-to-main "load-failed" (.-stack e)))))

(reset! ui/weather-params
        ui/default-weather-params)

(when ui/safari?
  (swap! ui/messages conj
         ["Due to bugs related to downloading files in Safari, Safari
  is not recommended for use with WeatherGen. To use Safari, make use
  of the workarounds detailed below. Use of Chrome is recommended."]))

(when ui/ie?
  (swap! ui/messages conj
         ["Unfortunately, the weather design features of
         WeatherGen (i.e. this page) do not currently work correctly
         in Internet Explorer. Shared forecasts work fine, so forecast
         links can be shared with pilots using IE. Use of Chrome is
         recommended."]))

(ui/weather-page
 [{:title "Mission"
   :id :mission-info
   :sections [:mission-info-section {}
              :save-briefing-section {}]}
  {:title "Map"
   :id :map-controls
   :sections [:map-controls-section {}
              :weather-display-controls {:title "Weather Display Options"}]}
  {:title    "Air Forces"
   :id       :air-forces
   :sections [:air-forces-section {}]}
  {:title    "Flights"
   :id       :flights
   :sections [:flights-section {}]}
  {:title    "Weather"
   :id       :weather
   :sections [:serialization-controls {}
              :step-controls {}
              :weather-display-controls {}
              :weather-parameters {}
              :forecast-section {:forecast-link? false}
              ;;:flight-path-controls {}
              :weather-type-configuration {}
              :cloud-controls {}
              :wind-stability-parameters {}
              :weather-override-parameters {}
              :advanced-controls {}]}
  #_{:title    "Test and Debug"
   :id       :test
   :sections [:test-section {}]}])
