
{% macro disabled(name, title, value, helpText, groupClass) %}
    <div class="form-group {{ groupClass }}">
        <label class="control-label" title="{{ helpText }}">{{ title }}</label>
        <div class="">
            <p class="form-control-static">{{ value }}</p>
        </div>
    </div>
{% endmacro %}

{% macro hidden(name, value) %}
    <input name="{{ name }}" type="hidden" id="{{ name }}" value="{{ value }}" />
{% endmacro %}

{% macro raw(text, groupClass) %}
    <div class="col-sm-12 {{ groupClass }}">
        {{ text }}
    </div>
{% endmacro %}

{% macro message(message, groupClass) %}
    <div class="row">
        <div class="col-sm-12 {{ groupClass }}">
            <p>{{ message }}</p>
        </div>
    </div>
{% endmacro %}

{% macro button(title, type, link, groupClass) %}
    <div class="form-group {{ groupClass }}">
        <div class="col-sm-offset-2 ">
            {% if type == "link" %}
                <a class="btn btn-default" href="{{ link }}">{{ title }}</a>
            {% else %}
                <button class="btn btn-default" type="{{ type }}">{{ title }}</button>
            {% endif %}
        </div>
    </div>
{% endmacro %}

{% macro input(name, title, value, helpText, groupClass, validation, accessKey) %}
    <div class="form-group {{ groupClass }}">
        <label class="control-label" title="{{ helpText }}" for="{{ name }}" accesskey="{{ accessKey }}">{{ title }}</label>
        <div class="">
            <input class="form-control" name="{{ name }}" type="text" id="{{ name }}" value="{{ value }}" {{ validation }} />
        </div>
    </div>
{% endmacro %}

{% macro inputWithTags(name, title, value, helpText, groupClass, validation, accessKey) %}
    <div class="form-group {{ groupClass }}">
        <label class="control-label" title="{{ helpText }}" for="{{ name }}" accesskey="{{ accessKey }}">{{ title }}</label>
        <div class="">
            <input class="form-control" name="{{ name }}" type="text" id="{{ name }}" value="{{ value }}" data-role="tagsinput" {{ validation }} />
        </div>
    </div>
{% endmacro %}

{% macro number(name, title, value, helpText, groupClass, validation, accessKey) %}
    <div class="form-group {{ groupClass }}">
        <label class="control-label" title="{{ helpText }}" for="{{ name }}" accesskey="{{ accessKey }}">{{ title }}</label>
        <div class="">
            <input class="form-control" name="{{ name }}" type="number" id="{{ name }}" value="{{ value }}" {{ validation }} />
        </div>
    </div>
{% endmacro %}

{% macro email(name, title, value, helpText, groupClass, validation, accessKey) %}
    <div class="form-group {{ groupClass }}">
        <label class="control-label" title="{{ helpText }}" for="{{ name }}" accesskey="{{ accessKey }}">{{ title }}</label>
        <div class="">
            <input class="form-control" name="{{ name }}" type="email" id="{{ name }}" value="{{ value }}" {{ validation }} />
        </div>
    </div>
{% endmacro %}

{% macro password(name, title, value, helpText, groupClass, validation, accessKey) %}
    <div class="form-group {{ groupClass }}">
        <label class="control-label" for="{{ name }}" title="{{ helpText }}" accesskey="{{ accessKey }}">{{ title }}</label>
        <div class="">
            <input class="form-control" name="{{ name }}" type="password" id="{{ name }}" value="{{ value }}" {{ validation }} />
        </div>
    </div>
{% endmacro %}

{% macro checkbox(name, title, value, groupClass, accessKey) %}
    <div class="form-group {{ groupClass }}">
        <div class="">
            <div class="checkbox">
                <input title="{{ title }}" class="form-control" type="checkbox" id="{{ name }}" name="{{ name }}" {% if value == 1 %}checked{% endif %}>
                <label for="{{ name }}">{{ title }}</label>
            </div>
        </div>
    </div>
{% endmacro %}

{% macro radio(name, id, title, value, helpText, groupClass, accessKey, setValue) %}
    <div class="form-group {{ groupClass }}">
        <div class="col-sm-offset-2 ">
            <div class="radio">
                <label for="{{ name }}" title="{{ helpText }}" accesskey="{{ accessKey }}">
                    <input type="radio" id="{{ id }}" name="{{ name }}" value="{{ setValue }}" {% if value == setValue %}checked{% endif %}>
                    {{ title }}
                </label>
            </div>
        </div>
    </div>
{% endmacro %}

{% macro dropdown(name, type, title, value, options, optionId, optionValue, helpText, groupClass, validation, accessKey, callBack, dataAttributes, optionGroups) %}
    <div class="form-group {{ groupClass }}">
        <label class="control-label" for="{{ name }}" title="{{ helpText }}" accesskey="{{ accessKey }}">{{ title }}</label>
        <div class="">
            <select class="form-control" {% if type == "dropdownmulti" %}multiple{% endif %} name="{{ name }}" id="{{ name }}" {{ callBack }}
            {% if dataAttributes|length > 0 %}
            {% for attribute in dataAttributes %}
                {{ attribute.name }}="{{ attribute.value }}"
            {% endfor %}
            {% endif %}>

            {% set hasGroups = optionGroups|length > 0 %}
            {% if not hasGroups %}
                {% set optionGroups = {label: "General"} %}
            {% endif %}

            {% for group in optionGroups %}
                {% if hasGroups %}
                    <optgroup label="{{ group.label }}">
                    {% set options = attribute(options, group.label) %}
                {% endif %}

                {% for option in options %}

                    {% set itemOptionId = attribute(option, optionId) %}
                    {% set itemOptionValue = attribute(option, optionValue) %}

                    {% if type == "dropdownmulti" %}
                        {% set selected = (itemOptionId in value) %}
                    {% else %}
                        {% set selected = (itemOptionId == value) %}
                    {% endif %}

                    <option value="{{ itemOptionId }}" {% if selected %}selected{% endif %}>{{ itemOptionValue }}</option>
                {% endfor %}

                {% if hasGroups %}
                    </optgroup>
                {% endif %}
            {% endfor %}

            </select>
        </div>
    </div>
{% endmacro %}

{% macro permissions(name, options) %}
    <table class="table table-bordered">
        <tr>
            <th>{% trans "Group" %}</th>
            <th>{% trans "View" %}</th>
            <th>{% trans "Edit" %}</th>
            <th>{% trans "Delete" %}</th>
        </tr>
        {% for item in options %}
            <tr>
                <td>{{ name }}</td>
                <td><input type="checkbox" name="{{ name }}" value="{{ value_view }}" {{ value_view_checked }}></td>
                <td><input type="checkbox" name="{{ name }}" value="{{ value_edit }}" {{ value_edit_checked }}></td>
                <td><input type="checkbox" name="{{ name }}" value="{{ value_del }}" {{ value_del_checked }}></td>
            </tr>
        {% endfor %}
    </table>
{% endmacro %}

{% macro date(name, title, value, helpText, groupClass, validation, accessKey) %}
    <div class="form-group {{ groupClass }}">
        <label class="control-label" title="{{ helpText }}" for="{{ name }}" accesskey="{{ accessKey }}">{{ title }}</label>
        <div class="">
            <input type="hidden" name="{{ name }}" id="{{ name }}" value="{{ value }}" />
            {% set linkedName %}{{ name }}Link{% endset %}
            <input class="form-control datePicker dateControl" name="{{ linkedName }}" type="text" id="{{ linkedName }}" {{ validation }} data-link-field="{{ name }}" data-link-format="yyyy-mm-dd hh:ii:ss" readonly/>
        </div>
    </div>
{% endmacro %}

{% macro dateMonth(name, title, value, helpText, groupClass, validation, accessKey) %}
    <div class="form-group {{ groupClass }}">
        <label class="control-label" title="{{ helpText }}" for="{{ name }}" accesskey="{{ accessKey }}">{{ title }}</label>
        <div class="">
            <input type="hidden" name="{{ name }}" id="{{ name }}" value="{{ value }}" />
            {% set linkedName %}{{ name }}Link{% endset %}
            <input class="form-control dateMonthPicker dateControl" name="{{ linkedName }}" type="text" id="{{ linkedName }}" {{ validation }} data-link-field="{{ name }}" data-link-format="yyyy-mm-dd hh:ii:ss" readonly/>
        </div>
    </div>
{% endmacro %}

{% macro time(name, title, value, helpText, groupClass, validation, accessKey) %}
    <div class="form-group {{ groupClass }}">
        <label class="control-label" title="{{ helpText }}" for="{{ name }}" accesskey="{{ accessKey }}">{{ title }}</label>
        <div class="">
            <input type="hidden" name="{{ name }}" id="{{ name }}" value="{{ value }}" />
            {% set linkedName %}{{ name }}Link{% endset %}
            <input class="form-control timePicker dateControl" name="{{ linkedName }}" type="text" id="{{ linkedName }}" {{ validation }} data-link-field="{{ name }}" data-link-format="hh:ii" readonly/>
        </div>
    </div>
{% endmacro %}

