<% if show_configuration_form? %>
  <div class="widget-body no-padding">
    <%= simple_form_for @ieducar_api_configuration,
      url: ieducar_api_configurations_path, method: :patch, html: { class: "smart-form" } do |f| %>
      <%= f.error_notification %>

      <fieldset>
        <div class="row">
          <div class="col col-sm-6">
            <%= f.input :url %>
          </div>

          <div class="col col-sm-6">
            <%= f.input :unity_code %>
          </div>
        </div>

        <div class="row">
          <div class="col col-sm-6">
            <%= f.input :token %>
          </div>

          <div class="col col-sm-6">
            <%= f.input :secret_token %>
          </div>
        </div>

         <div class="row">
          <div class="col col-sm-6">
            <%= f.input :api_security_token, readonly: true %>
          </div>
         </div>
      </fieldset>

      <footer>
        <% if @ieducar_api_configuration.persisted? %>
          <%= link_to t('.history'), history_ieducar_api_configurations_path, class: 'btn btn-info' %>
        <% end %>

        <button type="submit" class="btn btn-primary">
          <%= t('.save') %>
        </button>
      </footer>
    <% end %>
  </div>
<% end %>

<div class="row">
  <div class="col col-sm-12">
    <% if @ieducar_api_configuration.persisted? %>
      <% if @ieducar_api_configuration.synchronization_in_progress? %>
        <%= link_to "#",
          class: 'btn bg-color-red txt-color-white pull-right', style: 'margin-top: 20px;' do %>
          <i class="fa fa-cog fa-spin"></i>
          Sincronizando
        <% end %>
      <% else %>
        <%= link_to t('.synchronize'), ieducar_api_configurations_synchronizations_path, method: 'post',
          class: 'btn bg-color-red txt-color-white pull-right', style: 'margin-top: 20px; margin-left: 10px;',
          data: { disable_with: t('.sending') } %>

        <% if current_user.admin? || current_user.can_change?(:full_synchronization) %>
          <%= link_to t('.synchronize_last_two_years'), 
            ieducar_api_configurations_synchronizations_path(period: SynchronizationPeriods::LAST_TWO_YEARS),
            method: 'post', 
            class: 'btn bg-color-orange txt-color-white pull-right',
            style: 'margin-top: 20px; margin-left: 10px;',
            data: { disable_with: t('.sending') } %>
            
          <%= link_to t('.synchronize_current_year'), 
            ieducar_api_configurations_synchronizations_path(period: SynchronizationPeriods::CURRENT_YEAR),
            method: 'post', 
            class: 'btn bg-color-blue txt-color-white pull-right',
            style: 'margin-top: 20px; margin-left: 10px;',
            data: { disable_with: t('.sending') } %>
        <% end %>
      <% end %>
    <% end %>

    <h2><%= t('ieducar_api_configuration.sync_title') %></h2>

    <%= render 'synchronizations', syncs: IeducarApiSynchronization.order(id: :desc).limit(10) %>
  </div>
</div>

<%= javascript_pack_tag 'sync_status' %>