<%
# Copyright (C) 2015 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
%>

<div class="content-box auth-form-container--new"
     id="<%= "#{aac.auth_type}_form" if aac.new_record? %>"
     <%= hidden(true) if aac.new_record? %>>
  <div class="grid-row">
    <div class="col-xs-12 col-lg-11 off-lg-1">
      <% url = aac.new_record? ? account_authentication_providers_url(account) :
              account_authentication_provider_url(account, aac) %>

      <%= form_for(aac,
                   as: :authentication_provider,
                   url: url,
                   html: {
                           id: "#{aac.new_record? ? 'new' : 'edit'}_#{presenter.id_suffix(aac)}",
                           class: "ic-Form-group ic-Form-group--horizontal authentication_provider_form"
                   }) do |f| %>
      <%= f.hidden_field :auth_type, value: aac.auth_type, id: nil %>
      <%= f.hidden_field :id, id: nil %>
        <h3 tabindex="0"><%= aac.class.display_name %></h3>
        <% if !aac.new_record? %>
          <p><%= mt "You can log in directly with this provider by going to %{url}",
                    url: url_for(presenter.login_url_options(aac)) %></p>
        <% end %>

        <%= render partial: "#{aac.auth_type}_fields",
                 locals: {aac: aac, presenter: presenter, f: f}%>

        <% if aac.class.recognized_federated_attributes != [] %>
          <%= render partial: "federated_attributes", locals: { aac: aac, presenter: presenter, f: f } %>
        <% end %>

        <% if !aac.new_record? && aac.class.supports_debugging? %>
          <%= render partial: "debugging", locals: { provider: aac } %>
        <% end %>

        <% if presenter.configs.length > 1 %>
          <div class="ic-Form-control">
            <%= f.label(:position,
                        t('Position'),
                        class: 'ic-Label',
                        for: "aac_position_#{presenter.id_suffix(aac)}") %>
            <%= f.select(:position,
                         presenter.position_options(aac),
                         {},
                         class: "ic-Input",
                         id: "aac_position_#{presenter.id_suffix(aac)}") %>
          </div>
        <% end %>

        <div class="ic-Form-actions">
          <% if !aac.new_record? && @current_pseudonym.authentication_provider != aac %>
              <%= link_to(account_authentication_provider_url(account, aac),
                method: "delete",
                rel: 'nofollow',
                id: "delete-aac-#{aac.id}",
                data: {
                  confirm: t('Are you sure?'),
                  disable_with: t('deleting...')
                },
                class: 'Button Button--danger') do %>
                <%= t("Delete") %>
              <% end %>
          <% end %>
          <%= f.button t('Save'), class: "Button Button--primary" %>
        </div>
      <% end %>
    </div>
  </div>
</div>
