<%= javascript "lookup_keys" %>

<%= form_for @puppetclass, :url => (@puppetclass.new_record? ? puppetclasses_path : puppetclass_path(:id => @puppetclass)) do |f| %>
  <%= base_errors_for @puppetclass %>
  <ul class="nav nav-tabs" data-tabs="tabs">
    <li class="active"><a href="#primary" data-toggle="tab"><%= _('Puppet Class') %></a></li>
    <li><a href="#smart_class_param" data-toggle="tab"><%= _('Smart Class Parameter') %></a></li>
    <li><a href="#smart_vars" data-toggle="tab"><%= _('Smart Variables') %></a></li>
  </ul>

  <div class="tab-content">
    <div class="tab-pane active" id="primary">
      <%= text_f f, :name, :disabled => true %>
      <%= text_f f, :environments, :value => @puppetclass.environments.to_sentence, :label=> _('Puppet environments'), :disabled => true %>
      <%= multiple_checkboxes f, :hostgroups,   @puppetclass, Hostgroup,   :label => _("Host groups") %>
    </div>
    <div class="tab-pane lookup-keys-container" id="smart_class_param">
      <% if @puppetclass.class_params.empty? %>
        <div class="alert alert-success alert-dismissable">
          <%= alert_close %>
          <p><strong>
            <%= _('This Puppet class has no parameters in its signature.') %>
          </strong><br><%= _('To update the class signature, go to the Puppet Classes page and select "Import".') %></p>
        </div>
      <% else %>
        <div class="undo-smart-vars alert alert-info hide">
          <%= _('Undo remove') %>
        </div>
        <div class="row">
          <div class='col-md-3'>
            <input placeholder="<%= _('Filter by name') %>" onkeyup="filterByClassParam(this);" type='text' class="form-control">
          </div>
          <div class="form-group col-md-3">
            <div class='input-group'>
              <span class="input-group-addon">@</span>
              <%= select_tag "environment_filter", options_from_collection_for_select(@puppetclass.environments, "id", "name"),
                             :include_blank => "All Environments - (Not filtered)",:class=>'form-control', :onchange=>'filterByEnvironment(this)'%>
            </div>
          </div>
          <div class='col-md-6 text-right'>
            <%= documentation_button('4.2.5ParameterizedClasses') %>
          </div>
        </div>
        <div class="smart-var-left col-md-3">
          <ul class="nav nav-pills nav-stacked smart-var-tabs" data-tabs="pills">
            <% @puppetclass.class_params.includes(:environments, :environment_classes, :lookup_values).each do |key| %>
              <li data-used-environments=<%= key.environments.map(&:to_s).to_json %> >
                <a data-toggle="tab" id="pill_<%= key.to_s.gsub(' ','_') + '_' + key.id.to_s %>" href="#<%= key.to_s.gsub(' ','_') + '_' + key.id.to_s %>" title="<%= key %>">
                  <div class="clip"><%= icon_text((key.override ? "flag": ""), key.to_s.gsub('_',' ')) %></div>
                  <span class="close pull-right">&times;</span>
                </a>
              </li>
            <% end %>
          </ul>
        </div>
        <div class="tab-content col-md-9 stacked-content">
          <%= f.fields_for :class_params do |lookup_keys_form| %>
            <%= render 'lookup_keys/fields', :f => lookup_keys_form  %>
          <% end %>
        </div>
      <% end %>
    </div>
    <div class="tab-pane lookup-keys-container" id="smart_vars">
      <div class="undo-smart-vars alert alert-info hide">
        <%= _('Undo remove') %>
      </div>
      <div class='row'>
        <div class='form-group col-md-12 text-right'>
          <%= documentation_button('4.2.4SmartVariables') %>
        </div>
      </div>
      <div class="smart-var-left col-md-3">
        <ul class="nav nav-pills nav-stacked smart-var-tabs" data-tabs="pills">
          <% @puppetclass.lookup_keys.includes(:lookup_values).each do |key| %>
            <li>
              <a data-toggle="tab" id="pill_<%= key.to_s.gsub(' ','_') + '_' + key.id.to_s %>" href="#<%= key.to_s.gsub(' ','_') + '_' + key.id.to_s %>" title="<%= key %>">
                <div class="clip"><%= key %></div><span class="close pull-right">&times;</span>
              </a>
            </li>
          <% end %>
          <li><%= link_to_function '+ ' + _("Add Variable"), "add_child_node(this);" ,:class=>"btn btn-success",:style=>":hover{}", :"data-association" => :lookup_keys %></li>
        </ul>
      </div>
      <div class="tab-content col-md-9 stacked-content">
        <%= f.fields_for :lookup_keys do |lookup_keys_form| %>
          <%= render 'lookup_keys/fields', :f => lookup_keys_form  %>
        <% end %>
      </div>
    </div>
    <%= new_child_fields_template(f, :lookup_keys, {:partial => "lookup_keys/fields"})%>
  </div>

  <%= submit_or_cancel f %>
<% end %>
