<% content_for :head do %>
  <%= vite_javascript_tag 'cocoon' %>
<% end %>

<%= form_with(model: warehouse_template) do |form| %>
  <% if warehouse_template.errors.any? %>
    <div style="color: red">
      <h2><%= pluralize(warehouse_template.errors.count, "error") %> prohibited this template from being saved:</h2>

      <ul>
        <% warehouse_template.errors.each do |error| %>
          <li><%= error.full_message %></li>
        <% end %>
      </ul>
    </div>
  <% end %>

  <div>
    <%= form.label :name, style: "display: block" %>
    <%= form.text_field :name %>
  </div>

  <div>
    <%= form.label :public, "share this template with all users?" %>
    <%= form.check_box :public %>
  </div>

  <h4>contents:</h4>
  <div id='line_items'>
    <%= form.fields_for :line_items do |line_item| %>
      <%= render 'line_item_fields', :f => line_item %>
    <% end %>
    <div class='links'>
      <%= link_to_add_association 'add item', form, :line_items %>
    </div>
  </div>

  <div>
    <%= form.submit class: 'btn success btn-small' %>
  </div>
<% end %>
