{% extends "layout.html" %}
{% 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 -%}
{{ _('Create organization') }}
{%- 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() }}
{% endblock %}

{% block content %}

<h1>{{ _('Create organization') }}</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) }}
    </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 embedded_relation_enabled %}
  <div class="card mb-4">
    <div class="card-header">
      {{ _('Relation to %(admin_unit_name)s', admin_unit_name=current_admin_unit.name) }}
    </div>
    <div class="card-body">
      {% if current_admin_unit.can_verify_other %}
        {{ render_field_with_errors(form.embedded_relation.verify, ri="switch") }}
      {% endif %}
      {% if current_admin_unit.incoming_reference_requests_allowed %}
        {{ render_field_with_errors(form.embedded_relation.auto_verify_event_reference_requests, ri="switch") }}
      {% endif %}
    </div>
  </div>
  {% endif %}

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

{% endblock %}
