<% if @scenario_import.dangerous? %>
This Scenario contains one or more potentially dangerous Agents. These may be able to run local commands or execute code. Please be sure that you understand the Agent configurations before importing!
<% end %> <% if @scenario_import.existing_scenario.present? %>
This Scenario already exists in your system. The import will update your existing <%= scenario_label(@scenario_import.existing_scenario) %> Scenario's title, description, and tag colors. Below you can customize how the individual agents get updated.
<% end %> <% if @scenario_import.parsed_data["description"].present? %>
<%= markdown(@scenario_import.parsed_data["description"]) %>
<% end %>
<% @scenario_import.agent_diffs.each.with_index do |agent_diff, index| %>

<%= agent_diff.name.incoming %> (<%= agent_diff.type.incoming %><% " -- WARNING: this Agent's type has been changed. This import will likely fail!" if agent_diff.type.requires_merge? %>)

<% if agent_diff.agent_exists? %>
This Agent exists in your Huginn system. <% if agent_diff.requires_merge? %> Here are the differences between the incoming version and the one you have now. For each field, please select which value you'd like to keep. <% else %> It's already up-to-date. <% end %>
<% end %>
<% agent_diff.each_field do |field, value, selection_options| %>
<%= label_tag "scenario_import[merges][#{index}][#{field}]", field.titleize %> <% if selection_options.present? %>
Your current Agent's value is: <%= selection_options.find { |s| s.last.to_s == value.current.to_s }.first %>
<%= select_tag "scenario_import[merges][#{index}][#{field}]", options_for_select(selection_options, value.updated), :class => 'form-control' %> <% else %>
Your current Agent's value is: <%= value.current.to_s %>
<%= text_field_tag "scenario_import[merges][#{index}][#{field}]", value.updated, :class => 'form-control' %> <% end %>
<% end %>
<% if agent_diff.options.requires_merge? %>
Your current options:
<%= Utils.pretty_jsonify agent_diff.options.current %>
<% end %>
<% if agent_diff.requires_service? %>
<%= label_tag "scenario_import[merges][#{index}][service_id]", 'Service' %> <%= select_tag "scenario_import[merges][#{index}][service_id]", options_for_select(agent_diff.agent_instance.valid_services_for(current_user).collect { |s| ["(#{s.provider}) #{s.name}", s.id]}, agent_diff.agent.try(:service_id)), class: 'form-control' %>
<% end %>
<% end %>
<%= f.label :do_import do %> <%= f.check_box :do_import %> I confirm that I want to import these Agents. <% end %>
<%= f.submit "Finish Import", :class => "btn btn-primary" %>