<form class="form-horizontal" method="POST" action="javascript:;" id="custom-fields-form">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title">{{ tab_custom_fields }}</h4>
    </div>
    <div class="modal-body">
        <div class="form-group required">
            <label class="col-sm-3 control-label">{{ entry_name }}</label>
            <div class="col-sm-9">
                {% for language in languages %}
                    <div class="input-group"><span class="input-group-addon"><img src="language/{{ language.code }}/{{ language.code }}.png" title="{{ language.name }}" /></span>
                        <input type="text" name="custom_field_description[{{ language.language_id }}][name]" value="{{ custom_field_description[language.language_id].name }}" placeholder="{{ entry_name }}" class="form-control" />
                    </div>
                {% endfor %}
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label" for="input-location">{{ entry_location }}</label>
            <div class="col-sm-9">
                <select name="location" id="input-location" class="form-control">
                    <option value="account"{% if location == 'account' %} selected{% endif %}>{{ text_account }}</option>
                    <option value="address"{% if location == 'address' %} selected{% endif %}>{{ text_address }}</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label" for="input-edit-type">{{ entry_type }}</label>
            <div class="col-sm-9">
                <select name="type" id="input-edit-type" class="form-control">
                    <optgroup label="{{ text_input }}">
                        <option value="text"{% if type == 'text' %} selected{% endif %}>{{ text_text }}</option>
                        <option value="textarea"{% if type == 'textarea' %} selected{% endif %}>{{ text_textarea }}</option>
                    </optgroup>
                    <optgroup label="{{ text_choose }}">
                        <option value="select"{% if type == 'select' %} selected{% endif %}>{{ text_select }}</option>
                        <option value="radio"{% if type == 'radio' %} selected{% endif %}>{{ text_radio }}</option>
                        <option value="checkbox"{% if type == 'checkbox' %} selected{% endif %}>{{ text_checkbox }}</option>
                    </optgroup>
                    <optgroup label="{{ text_file }}">
                        <option value="file"{% if type == 'file' %} selected{% endif %}>{{ text_file }}</option>
                    </optgroup>
                    <optgroup label="{{ text_date }}">
                        <option value="date"{% if type == 'date' %} selected{% endif %}>{{ text_date }}</option>
                        <option value="time"{% if type == 'time' %} selected{% endif %}>{{ text_time }}</option>
                        <option value="datetime"{% if type == 'datetime' %} selected{% endif %}>{{ text_datetime }}</option>
                    </optgroup>
                </select>
            </div>
        </div>
        <div class="form-group" id="display-edit-value"{% if type == 'select' or type == 'radio' or type == 'checkbox' %} style="display: none;"{% endif %}>
            <label class="col-sm-3 control-label" for="input-edit-value">{{ entry_value }}</label>
            <div class="col-sm-9">
                <input type="text" name="value" value="{{ value }}" placeholder="{{ entry_value }}" id="input-edit-value" class="form-control" />
            </div>
        </div>
        <div class="form-group" id="display-edit-validation"{% if type == 'select' or type == 'radio' or type == 'checkbox' %} style="display: none;"{% endif %}>
            <label class="col-sm-3 control-label" for="input-edit-validation"><span data-toggle="tooltip" title="{{ help_regex }}">{{ entry_validation }}</span></label>
            <div class="col-sm-9">
                <input type="text" name="validation" id="input-edit-validation" value="{{ validation }}" placeholder="{{ text_regex }}"  class="form-control"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">{{ entry_customer_group }}</label>
            <div class="col-sm-9">
                {% set customer_group_row = 0 %}
                {% for customer_group in customer_groups %}
                    <div class="checkbox">
                        <label>
                            <input type="checkbox" name="custom_field_customer_group[{{ customer_group_row }}][customer_group_id]" value="{{ customer_group.customer_group_id }}" {% if customer_group.customer_group_id in custom_field_customer_group %}checked{% endif %} />
                            {{ customer_group.name }}
                        </label>
                    </div>
                    {% set customer_group_row = customer_group_row + 1 %}
                {% endfor %}
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">{{ entry_required }}</label>
            <div class="col-sm-9">
                {% set customer_group_row = 0 %}
                {% for customer_group in customer_groups %}
                    <div class="checkbox">
                        <label>
                            <input type="checkbox" name="custom_field_customer_group[{{ customer_group_row }}][required]" value="{{ customer_group.customer_group_id }}" {% if customer_group.customer_group_id in custom_field_required %}checked{% endif %} />
                            {{ customer_group.name }}
                        </label>
                    </div>
                    {% set customer_group_row = customer_group_row + 1 %}
                {% endfor %}
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label" for="input-status">{{ entry_status }}</label>
            <div class="col-sm-9">
                <select name="status" id="input-status" class="form-control">
                    <option value="1"{% if status == '1' %} selected{% endif %}>{{ text_enabled }}</option>
                    <option value="0"{% if status == '0' %} selected{% endif %}>{{ text_disabled }}</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label" for="input-sort-order"><span data-toggle="tooltip" title="{{ help_sort_order }}">{{ entry_sort_order }}</span></label>
            <div class="col-sm-9">
                <input type="text" name="sort_order" value="{{ sort_order }}" placeholder="{{ entry_sort_order }}" id="input-sort-order" class="form-control" />
            </div>
        </div>
        <table id="custom-field-edit-value" class="table table-striped table-bordered table-hover"{% if type != 'select' and type != 'radio' and type != 'checkbox' %} style="display: none;"{% endif %}>
            <thead>
                <tr>
                    <td class="text-left required">{{ entry_custom_value }}</td>
                    <td class="text-right">{{ entry_sort_order }}</td>
                    <td></td>
                </tr>
            </thead>
            <tbody>
            {% set custom_field_value_row = 0 %}
            {% for custom_field_value in custom_field_values %}
            <tr id="custom-field-value-row{{ custom_field_value_row }}">
                <td class="text-left" style="width: 70%;"><input type="hidden" name="custom_field_value[{{ custom_field_value_row }}][custom_field_value_id]" value="{{ custom_field_value.custom_field_value_id }}" />
                {% for language in languages %}
                <div class="input-group"> <span class="input-group-addon"><img src="language/{{ language.code }}/{{ language.code }}.png" title="{{ language.name }}" /></span>
                    <input type="text" name="custom_field_value[{{ custom_field_value_row }}][custom_field_value_description][{{ language.language_id }}][name]" value="{{ custom_field_value.custom_field_value_description[language.language_id] ? custom_field_value.custom_field_value_description[language.language_id].name }}" placeholder="{{ entry_custom_value }}" class="form-control" />
                </div>
                {% if error_custom_field_value[custom_field_value_row][language.language_id] %}
                <div class="text-danger">{{ error_custom_field_value[custom_field_value_row][language.language_id] }}</div>
                {% endif %}
                {% endfor %}</td>
                <td class="text-right"><input type="text" name="custom_field_value[{{ custom_field_value_row }}][sort_order]" value="{{ custom_field_value.sort_order }}" placeholder="{{ entry_sort_order }}" class="form-control" /></td>
                <td class="text-left"><button onclick="$('#custom-field-value-row{{ custom_field_value_row }}').remove();" data-toggle="tooltip" title="{{ button_remove }}" class="btn btn-danger"><i class="fa fa-minus-circle"></i></button></td>
            </tr>
            {% set custom_field_value_row = custom_field_value_row + 1 %}
            {% endfor %}
            </tbody>
            <tfoot>
                <tr>
                    <td colspan="2"></td>
                    <td class="text-left"><button id="addEditCustomFieldValue" type="button" data-toggle="tooltip" title="{{ button_custom_field_value_add }}" class="btn btn-primary"><i class="fa fa-plus-circle"></i></button></td>
                </tr>
            </tfoot>
        </table>
    </div>
    <div class="modal-footer">
        <i class="fa fa-circle-o-notch fa-spin add-redirect-loading hidden"></i>
        <button type="button" class="btn btn-warning" data-dismiss="modal">{{ button_cancel }}</button>
        <button type="button" id="EditCustomFieldSend" class="btn btn-primary">{{ button_create }}</button>
    </div>
    <input type="hidden" name="custom_field_id" value="{{ custom_field_id }}" />
</form>