<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><%= content_for?(:title) ? yield(:title) : "Huginn" %></title>
    <meta name="description" content="">
    <meta name="author" content="">
    <%= stylesheet_link_tag    "application", :media => "all" %>
    <%= javascript_include_tag "application" %>
    <%= csrf_meta_tags %>
    <%= yield(:head) %>
  </head>
  <body>
    <nav class="navbar navbar-default navbar-fixed-top" role="navigation">
      <div class="container">
        <%= render 'layouts/navigation' %>
      </div>
    </nav>

    <div id="main" role="main">
      <div class="container">
        <div class="row">
          <%= render 'layouts/messages' %>
        </div>
      </div>
      <% if user_signed_in? %>
        <%= render "upgrade_warning" %>
      <% end %>

      <div id="main-content">
        <%= yield %>
      </div>
      
    </div>

    <script>
      var agentPaths = {};
      var agentNames = [];
      <% if current_user.present? -%>
        var myAgents = <%= Utils.jsonify(current_user.agents.pluck(:name, :id).inject({}) {|m, a| m[a.first] = agent_path(a.last); m }) %>;
        var myScenarios = <%= Utils.jsonify(current_user.scenarios.pluck(:name, :id).inject({}) {|m, s| m[s.first + " Scenario"] = scenario_path(s.last); m }) %>;
        $.extend(agentPaths, myAgents);
        $.extend(agentPaths, myScenarios);
        agentPaths["All Agents Index"] = <%= Utils.jsonify agents_path %>;
        agentPaths["New Agent"] = <%= Utils.jsonify new_agent_path %>;
        agentPaths["Account"] = <%= Utils.jsonify edit_user_registration_path %>;
        agentPaths["Events Index"] = <%= Utils.jsonify events_path %>;
        agentPaths["View Agent Diagram"] = <%= Utils.jsonify diagram_path %>;
        agentPaths["Run Event Propagation"] = { url: <%= Utils.jsonify propagate_agents_path %>, method: 'POST' };


        $.each(agentPaths, function(name, v) { agentNames.push(name); });
      <% end -%>
    </script>
  </body>
</html>
