<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
		<meta http-equiv="X-UA-Compatible" content="chrome=1" />
		<meta name="apple-mobile-web-app-capable" content="yes" />
    <title>Spontaneous: Loading...</title>
		<link REL="SHORTCUT ICON" HREF="/@spontaneous/static/favicon.ico" />

      <link rel="stylesheet" href="<%= style_url("spontaneous") %>" type="text/css" media="screen" charset="utf-8" />
      <script type="text/javascript" charset="utf-8" src="<%= script_url("vendor/jquery") %>"></script>
    <script type="text/javascript">
      var Spontaneous = {};
    </script>
    <script type="text/javascript">
      function _confirm(id) {
        var t = 200;
        $('.actions li p:visible').slideUp(t);
        $(id).slideDown(t)
      }
      function _cancel(id) {
        $(id).slideUp(200)
      }
      function solution(action, source, dest) {
        console.log(action, source, dest);
      }
    </script>
  </head>
  <body id="schema-error">
    <div id="container">

      <%
          types = modification.actions.map { |a| a.source.owner}.uniq
      %>

    <h1>There are unresolved changes to <%= types.length > 1 ? "s" : "" %> <%= types.map { |o| "<strong>&lsquo;#{o}&rsquo;</strong>"}.join(', ')%></h1>
    <% source_file = modification.actions[0].source.source_file %>
    <p class="src"><a href="mvim://open?url=file://<%= source_file %>"><%= source_file %></a></p>

    <p>Please choose one of the following solutions:</p>

    <ul class="actions">
      <% modification.actions.each do |action|
        id = "#{action.action}-#{action.source.name.to_s.gsub('::', '__')}#{action.dest ? "-#{action.dest.name.to_s.gsub('::', '__')}" : ""}"
      %>
    <li>
    <form action="/@spontaneous/schema/<%= action.action %>" method="post">
      <input type="hidden" name="origin" value="<%= env['SCRIPT_NAME'] %>" />
      <input type="hidden" name="__token" value="<%= env[S::Rack::CSRF_TOKEN] %>" />
      <input type="hidden" name="uid" value="<%= action.source.to_s %>" />
      <% if action.dest %>
        <input type="hidden" name="ref" value="<%= action.dest.schema_name %>" />
      <% end %>
    <a onclick="_confirm('#<%= id %>')"><strong><%= action.action.capitalize %></strong> <%= action.category %> &lsquo;<em><%= action.source.name %></em>&rsquo; <% if action.dest %>
          to &lsquo;<em><%= action.dest.name %></em>&rsquo;
          <% end %>
        </a>
        <p id="<%= id %>" style="display: none">Are you sure? <a class="button cancel" onclick="_cancel('#<%= id %>')">No</a> <button class="button" onclick="solution('<%= action.action %>', '<%= action.source.name %>', '<%= action.dest ? action.dest.name : '' %>')">Yes</button></p>
        </form>
        </li>
      <% end %>
    </ul>
    </div>
  </body>
</html>