<%= form_for [:admin, @budget] do |f| %>

  <div class="small-12 medium-9 column">
    <%= f.text_field :name, maxlength: Budget.title_max_length %>
  </div>

  <div class="margin-top">
    <div class="small-12 medium-6 column">
      <%= f.select :phase, budget_phases_select_options, selected: "drafting" %>
    </div>
    <div class="small-12 medium-3 column end">
      <%= f.select :currency_symbol, budget_currency_symbol_select_options %>
    </div>
  </div>

  <% if @budget.phases.present? %>
    <div class="small-12 column">
      <table id="budget-phases-table" class="table-for-mobile">
        <thead>
          <tr>
            <th><%= t("admin.budgets.edit.phase") %></th>
            <th><%= t("admin.budgets.edit.dates") %></th>
            <th class="text-center"><%= t("admin.budgets.edit.enabled") %></th>
            <th><%= t("admin.budgets.edit.actions") %></th>
          </tr>
        </thead>

        <% @budget.phases.order(:id).each do |phase| %>
          <tr id="<%= dom_id(phase) %>" class="phase">
            <td>
              <%= t("budgets.phase.#{phase.kind}") %>
              <% if @budget.current_phase == phase %>
                <span class="label success"><strong><%= t("admin.budgets.edit.active") %></strong></span>
              <% end %>
            </td>
            <td>
              <% if phase.starts_at.present? || phase.ends_at.present? %>
                <%= l(phase.starts_at.to_date) if phase.starts_at.present? %>
                -
                <%= l(phase.ends_at.to_date) if phase.ends_at.present? %>
              <% else %>
                <em><%= t("admin.budgets.edit.blank_dates") %></em>
              <% end %>
            </td>
            <td class="text-center">
              <span class="budget-phase-enabled <%= phase.enabled? ? 'enabled' : 'disabled' %>"></span>
            </td>
            <td>
              <%= link_to t("admin.budgets.edit.edit_phase"),
                          edit_admin_budget_budget_phase_path(@budget, phase),
                          method: :get, class: "button hollow expanded" %>
            </td>
          </tr>
        <% end %>
      </table>
    </div>
  <% end %>

  <div class="small-12 column">
    <div class="clear small-12 medium-4 large-3 inline-block">
      <%= f.submit nil, class: "button success" %>
    </div>

    <div class="float-right">
      <% if @budget.balloting_process? %>
        <%= link_to t("admin.budgets.winners.calculate"),
                    calculate_winners_admin_budget_path(@budget),
                    method: :put,
                    class: "button hollow" %>
      <% end %>

      <% if @budget.has_winning_investments? %>
        <%= link_to t("budgets.show.see_results"),
                    budget_results_path(@budget),
                    class: "button hollow margin-left" %>
      <% end %>
      <% if @budget.persisted? %>
        <%= link_to t("admin.budgets.edit.delete"),
            admin_budget_path(@budget),
            method: :delete,
            class: "delete float-right margin-left" %>
      <% end %>
    </div>
  </div>

<% end %>
