{% set input_languages = [] %}
{% for language in languages %}
    {% if schema.get('languages') == 'all' or language.lang_code in schema.get('languages', ['en']) %}
        {{ input_languages.append(language) or '' }}
    {% endif %}
{% endfor %}
<div class="form-group row form-area" style="padding-right:0.75em" data-name="{{ id_prefix }}_parent">
    <div class="col-md-3" style="padding-right: 0px">
        {# Label #}
        <label class="col-md-12 view-label">{{ schema.title | get_translated_text }}
            {% if data.text %}
                <a href="{{ url_for('.objects', q=search_query_attribute + ' == "' + data.text | get_translated_text(metadata_language) + '"', advanced='on') }}"
                   class="search-helper"><i class="fa fa-search" aria-hidden="true"></i></a>
            {% else %}
                <a href="{{ url_for('.objects', q=search_query_attribute + ' == ""', advanced='on') }}"
                   class="search-helper"><i class="fa fa-search" aria-hidden="true"></i></a>
            {% endif %}
        </label>
        {% if input_languages | length > 1 and 'choices' not in schema %}
            <div class="form-switch">
                <div class="row col-md-offset-4">
                    <select class="selectpicker col-md-12 select-language" multiple="multiple"
                            style="padding-bottom: 5px;"
                            data-style="btn-default btn-xs" id="{{ id_prefix }}-select-language"
                            name="{{ id_prefix }}_text_languages">
                        {% for language in input_languages %}
                            <option value="{{ language.lang_code }}"
                                    {% if language.id == ENGLISH.id %}
                                    disabled="disabled" selected="selected"
                                    {% elif id_prefix + '_text_languages' in form_data or id_prefix + '_text_en' in form_data %}
                                        {% if language.lang_code in form_data[id_prefix+'_text_languages'] %}
                                    selected="selected"
                                        {% endif %}
                                    {% elif data.text is not string and data.text is defined %}
                                        {% if language.lang_code in data.text.keys() %} selected="selected"
                                        {% endif %}
                                    {% endif %}
                            >{{ language.names | get_translated_text }}</option>
                        {% endfor %}
                    </select>
                </div>
            </div>
        {% endif %}
    </div>
    {# View #}
    <div class="view-switch">
        <div class="col-md-9" style="padding-left: 15px; position: relative;">
            {% if data %}
                {% if schema.markdown and data.is_markdown %}
                    <pre style="font-family: inherit; word-wrap: break-word; white-space: normal; word-break: normal;"
                         class="object-user-content">{{ data.text | get_translated_text(metadata_language) | markdown_to_safe_html | safe }}</pre>
                    <a class="edit-helper" style="position: absolute; bottom: 10px; right: 20px;"><i
                            class="fa fa-pencil-square-o"></i></a>
                {% elif 'multiline' in schema and schema['multiline'] %}
                    {% if data.text | get_translated_text(metadata_language) %}
                        <pre style="font-family: inherit; word-wrap: break-word; white-space: pre-wrap; word-break: normal;">{{ data.text | get_translated_text(metadata_language) }}</pre>
                        <a class="edit-helper" style="position: absolute; bottom: 10px; right: 20px;"><i class="fa fa-pencil-square-o"></i></a>
                    {% else %}
                        &mdash;
                        <a class="edit-helper"><i class="fa fa-pencil-square-o"></i></a>
                    {% endif %}
                {% else %}
                    {% if data.text | get_translated_text(metadata_language) %}
                        {{ data.text | get_translated_text(metadata_language) }}
                    {% else %}
                        &mdash;
                    {% endif %}
                    <a class="edit-helper"><i class="fa fa-pencil-square-o"></i></a>
                {% endif %}
            {% else %}
                &mdash;
                <a class="edit-helper"><i class="fa fa-pencil-square-o"></i></a>
            {% endif %}
            <div class="alert-upload-failed">
                {{ _('Your input is not valid. Please check.') }}
            </div>
        </div>
    </div>
    {# Form #}
    <div class="form-switch">
        <div class="col-md-9">
            {% if 'choices' in schema %}
                <select class="form-control selectpicker" name="{{ id_prefix }}_text">
                    {% if form_data.get(id_prefix+'_text', '') != '' or (data is not none and data.get('text', '') != '') %}
                        {% if not is_required %}
                            <option value="">&mdash;</option>
                        {% endif %}
                    {% else %}
                        <option selected="selected" value="">&mdash;</option>
                    {% endif %}
                    {% for option in schema.choices %}
                        {% if id_prefix+'_text' in form_data %}
                            {% if form_data[id_prefix+'_text'] == ( option | to_string_if_dict ) %}
                                <option value="{{ option }}" data-value-base64="{{ option | base64encode }}"
                                        selected="selected">{{ option | get_translated_text }}</option>
                            {% else %}
                                <option value="{{ option }}"
                                        data-value-base64="{{ option | base64encode }}">{{ option | get_translated_text }}</option>
                            {% endif %}
                        {% elif data is not none and "text" in data %}
                            {% if data.text == option %}
                                <option value="{{ option }}" data-value-base64="{{ option | base64encode }}"
                                        selected="selected">{{ option | get_translated_text }}</option>
                            {% else %}
                                <option value="{{ option }}"
                                        data-value-base64="{{ option | base64encode }}">{{ option | get_translated_text }}</option>
                            {% endif %}
                        {% else %}
                            <option value="{{ option }}"
                                    data-value-base64="{{ option | base64encode }}">{{ option | get_translated_text }}</option>
                        {% endif %}
                    {% endfor %}
                </select>
            {% else %}
                {% for language in input_languages %}
                    <div data-sampledb-language-input-for="{{ language.lang_code }}"
                         {% if input_languages | length > 1 %}style="display: none; {% if loop.index0 %}margin-top: 15px;{% endif %}"{% endif %}
                         class="{% if input_languages | length > 1 %}input-group{% endif %} {% if not language.enabled_for_input %}has-error{% endif %}">
                        {% if schema.markdown %}
                            <textarea style="display: none; resize: vertical; min-height: 171px;" class="form-control"
                                      data-markdown-textarea="true"
                                      name="{{ id_prefix }}_text_{{ language.lang_code }}"
                                      placeholder="{{ (schema.placeholder or schema.title) | get_translated_text }}">{% if id_prefix+'_text_' + language.lang_code in form_data %}{{ form_data[id_prefix + '_text_' + language.lang_code] }}{% elif data is not none and "text" in data %}{{ data.text | get_translated_text(language.lang_code) }}{% endif %}</textarea>
                        {% elif 'multiline' in schema and schema['multiline'] %}
                            <textarea style="resize: vertical; min-height:2.5em; height:4em;" class="form-control"
                                      name="{{ id_prefix }}_text_{{ language.lang_code }}"
                                      placeholder="{{ (schema.placeholder or schema.title) | get_translated_text }}">{% if id_prefix+'_text_' + language.lang_code in form_data %}{{ form_data[id_prefix + '_text_' + language.lang_code] }}{% elif data is not none and "text" in data %}{{ data.text | get_translated_text(language.lang_code) }}{% endif %}</textarea>
                        {% else %}
                            <input type="text" class="form-control"
                                   name="{{ id_prefix }}_text_{{ language.lang_code }}"
                                   placeholder="{{ (schema.placeholder or schema.title) | get_translated_text }}"
                                   {% if id_prefix+'_text_' + language.lang_code in form_data %}value="{{ form_data[id_prefix + '_text_' + language.lang_code] }}"
                                   {% elif data is not none and "text" in data %}value="{{ data.text | get_translated_text(language.lang_code) }}"{% endif %}>
                        {% endif %}
                        {% if input_languages | length > 1 %}
                            <span class="input-group-addon language-addon">{{ language.names | get_translated_text }}</span>
                        {% endif %}
                    </div>
                {% endfor %}
            {% endif %}
            {% if id_prefix + '_text' in object_errors %}
                <span class="help-block"><strong>{{ _('Error:') }}</strong> {{ object_errors[id_prefix + '_text'] }}</span>{% endif %}
            {% if id_prefix + '_text_en' in object_errors %}
                <span class="help-block"><strong>{{ _('Error:') }}</strong> {{ object_errors[id_prefix + '_text_en'] }}</span>{% endif %}
            {% if 'note' in schema %}
                <span class="help-block"><strong>{{ _('Note:') }}</strong> {{ schema['note'] | get_translated_text }}</span>{% endif %}
        </div>
    </div>
</div>