{#
 * Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop>
 *
 * This program 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, either version 3 of the
 *  License, or (at your option) any later version.
 *
 * This program 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/>.
#}
{% extends "@ChillPerson/Person/layout.html.twig"  %}

{% set activeRouteKey = '' %}

{% block title %}{{ 'Update details for %name%'|trans({ '%name%': person|chill_entity_render_string } ) }}{% endblock %}

{% block content %}
<div class="person-edit">

    <h1>{{ block('title') }}</h1>

    {% form_theme form '@ChillMain/Form/fields.html.twig' %}
    {{ form_start(form) }}

    {% if form.memo is defined %}
    <fieldset>
        <legend><h2>{{ 'Memo'|trans }}</h2></legend>
        {{ form_widget(form.memo, {'label' : 'Memo'} ) }}
    </fieldset>
    {% endif %}

    <fieldset>
        <legend><h2>{{ 'General information'|trans }}</h2></legend>
        {%- if form.civility is defined -%}
        {{ form_row(form.civility, {'label' : 'Civility'}) }}
        {% endif %}
        {{ form_row(form.firstName, {'label' : 'First name'}) }}
        {{ form_row(form.lastName, {'label' : 'Last name'}) }}
        {% if form.altNames is defined %}
            {{ form_widget(form.altNames, { 'label': 'Alternative names'}) }}
        {% endif %}
        {{ form_row(form.gender, {'label' : 'Gender'}) }}
        {{ form_row(form.genderComment, { 'label' : 'Comment on the gender'} ) }}
    </fieldset>

    <fieldset>
        <legend><h2>{{ 'Birth information'|trans }}</h2></legend>
        {{ form_row(form.birthdate, {'label': 'Date of birth'} ) }}
        {%- if form.placeOfBirth is defined -%}
        {{ form_row(form.placeOfBirth, { 'label' : 'Place of birth'} ) }}
        {%- endif -%}
        {%- if form.countryOfBirth is defined -%}
        {{ form_row(form.countryOfBirth, { 'label' : 'Country of birth' } ) }}
        {%- endif -%}
        {%- if form.deathdate is defined -%}
        {{ form_row(form.deathdate, { 'label' : 'Date of death' } ) }}
        {%- endif -%}
    </fieldset>

    {%- if form.email is defined or form.phonenumber is defined or form.mobilenumber is defined or form.contactInfo is defined-%}
        <fieldset>
            <legend><h2>{{ 'Contact information'|trans }}</h2></legend>
            {%- if form.email is defined -%}
                <div id="personEmail">
                    {{ form_row(form.email, {'label': 'Email'}) }}
                </div>
            {% endif %}
            {%- if form.acceptEmail is defined -%}
                <div id="personAcceptEmail">
                    {{ form_row(form.acceptEmail, {'label' : 'Accept emails ?'}) }}
                </div>
            {%- endif -%}

            {%- if form.phonenumber is defined -%}
                {{ form_row(form.phonenumber, {'label': 'Phonenumber'}) }}
            {%- endif -%}
            {%- if form.mobilenumber is defined -%}
                <div id="personPhoneNumber">
                    {{ form_row(form.mobilenumber, {'label': 'Mobilenumber'}) }}
                </div>
                <div id="personAcceptSMS">
                    {{ form_row(form.acceptSms, {'label' : 'Accept short text message ?'}) }}
                </div>
            {%- endif -%}
            {%- if form.otherPhonenumbers is defined -%}
                {{ form_widget(form.otherPhonenumbers) }}
                {{ form_errors(form.otherPhonenumbers) }}
            {%- endif -%}
            {%- if form.contactInfo is defined -%}
                {{ form_label(form.contactInfo) }}
                {{ form_widget(form.contactInfo) }}
                {{ form_errors(form.contactInfo) }}
            {%- endif -%}
        </fieldset>
    {%- endif -%}

    {%- if form.nationality is defined or form.spokenLanguages is defined -%}
    <fieldset>
        <legend><h2>{{ 'Administrative information'|trans }}</h2></legend>
        {%- if form.nationality is defined -%}
        {{ form_row(form.nationality, { 'label' : 'Nationality'|trans} ) }}
        {%- endif -%}
        {%- if form.spokenLanguages is defined -%}
        {{ form_row(form.spokenLanguages, {'label' : 'Spoken languages'}) }}
        {%- endif -%}
        {%- if form.administrativeStatus is defined -%}
        {{ form_row(form.administrativeStatus, {'label' : 'Administrative status'}) }}
        {%- endif -%}
        {%- if form.employmentStatus is defined -%}
        {{ form_row(form.employmentStatus, {'label' : 'Employment status'}) }}
        {%- endif -%}
    </fieldset>
    {%- endif -%}

    {%- if form.numberOfChildren is defined or form.maritalStatus is defined -%}
    <fieldset>
        <legend><h2>{{ 'Marital status'|trans }}</h2></legend>
        {{ form_row(form.numberOfChildren, {'label' : 'Number of children'}) }}
        {%- if form.maritalStatus is defined -%}
        <div id="maritalStatus">
            {{ form_row(form.maritalStatus, { 'label' : 'Marital status'} ) }}
        </div>
        <div id="maritalStatusDate">
            {{ form_row(form.maritalStatusDate, { 'label' : 'Date of last marital status change'} ) }}
        </div>
        {%- endif -%}
        <div id="maritalStatusComment">
            {{ form_row(form.maritalStatusComment, { 'label' : 'Comment on the marital status'} ) }}
        </div>
    </fieldset>
    {%- endif -%}

    {% if form.identifiers|length > 0 %}
        <fieldset>
            <legend><h2>{{ 'person.Identifiers'|trans }}</h2></legend>
            <div>
                {{ form_widget(form.identifiers) }}
            </div>
        </fieldset>
    {% else %}
        {{ form_widget(form.identifiers) }}
    {% endif %}


    {{ form_rest(form) }}

    <ul class="record_actions sticky-form-buttons">
        <li class="cancel">
            <a href="{{ path('chill_person_view',  {'person_id' : person.id}) }}" class="btn btn-cancel">
                {{ 'Return'|trans }}
            </a>
        </li>
        <li>
            <button class="btn btn-save" type="submit">
                {{ 'Save'|trans }}
            </button>
        </li>
    </ul>
    {{ form_end(form) }}

</div>
{% endblock %}

{% block js %}
    {{ encore_entry_script_tags('page_person') }}
{% endblock %}
