{% extends "layout.html" %}
{% set active_id = "settings" %}
{% from "_macros.html" import render_manage_form_styles, render_manage_form_scripts, render_admin_unit_form_script, render_jquery_steps_header, render_cropper_logo_block, render_crop_image_form_section, render_google_place_autocomplete_header, render_google_place_autocomplete_field, render_field_with_errors, render_field %}

{%- block title -%}
{{ _('Settings') }}
{%- endblock -%}

{% block styles %}
{{ render_manage_form_styles() }}
{% endblock %}

{% block header %}
{{ render_manage_form_scripts() }}
{{ render_jquery_steps_header() }}
{{ render_google_place_autocomplete_header() }}
{{ render_cropper_logo_block() }}
{{ render_admin_unit_form_script(admin_unit) }}
{% endblock %}

{% block content %}

{% if admin_unit.deletion_requested_at %}
    <div class="alert alert-danger" role="alert">
      {{ _('The organization is scheduled for deletion.') }}
      <a class="alert-link" href="{{ url_for('admin_unit_cancel_deletion', id=admin_unit.id) }}" role="button">{{ _('Cancel deletion') }}</a>
    </div>
{% endif %}

<h1>{{ _('Settings') }}</h1>
<form id="main-form" action="" method="POST" enctype="multipart/form-data">
  {{ form.hidden_tag() }}

  <div class="card mb-4">
    <div class="card-header">
      {{ _('Organization') }}
    </div>
    <div class="card-body">
      {{ render_field_with_errors(form.name) }}
      {{ render_field_with_errors(form.short_name) }}
      {{ render_field_with_errors(form.description) }}
    </div>
  </div>

  <div class="card mb-4">
    <div class="card-header">
      {{ _('Location') }}
    </div>
    <div class="card-body">

      {{ render_google_place_autocomplete_field(True) }}

      {{ form.location.hidden_tag() }}
      {{ render_field_with_errors(form.location.street) }}
      {{ render_field_with_errors(form.location.postalCode) }}
      {{ render_field_with_errors(form.location.city) }}
      {{ render_field_with_errors(form.location.state) }}
      {{ render_field_with_errors(form.location.latitude) }}
      {{ render_field_with_errors(form.location.longitude) }}
    </div>
  </div>

  {{ render_crop_image_form_section(form.logo) }}

  <div class="card mb-4">
    <div class="card-header">
      {{ _('Additional information') }}
    </div>
    <div class="card-body">
    {{ render_field_with_errors(form.url) }}
    {{ render_field_with_errors(form.email) }}
    {{ render_field_with_errors(form.phone) }}
    {{ render_field_with_errors(form.fax) }}
    </div>
  </div>

  {% if admin_unit.can_verify_other %}
  <div class="card mb-4">
    <div class="card-header">
      {{ _('Verification requests') }}
    </div>
    <div class="card-body">
    {{ render_field_with_errors(form.incoming_verification_requests_allowed, ri="checkbox") }}
    {{ render_field_with_errors(form.incoming_verification_requests_text) }}
    </div>
  </div>
  {% endif %}

  {{ render_field(form.submit) }}
</form>

{% if not admin_unit.deletion_requested_at %}
<div class="my-4">
  <a class="btn btn-danger" href="{{ url_for('admin_unit_request_deletion', id=admin_unit.id) }}" role="button">{{ _('Delete organization') }}&hellip;</a>
</div>
{% endif %}

{% endblock %}
