{% load inventree_extras %}
{% load i18n %}

{% if plugin %}
{% setting_object key plugin=plugin as setting %}
{% elif user_setting %}
{% setting_object key user=request.user as setting %}
{% elif notification_setting %}
{% setting_object key method=method user=request.user as setting %}
{% else %}
{% setting_object key as setting %}
{% endif %}

<tr>
    <td>
        {% if icon %}
        <span class='fas {{ icon }}'></span>
        {% endif %}
    </td>
    <td><strong>{{ setting.name }}</strong></td>
    <td>
        {{ setting.description }}
    </td>
    <td>
        {% if setting.is_bool %}
        <div class='form-check form-switch'>
            <input class='form-check-input boolean-setting' fieldname='{{ setting.key.upper }}' pk='{{ setting.pk }}' setting='{{ setting.key.upper }}' id='setting-value-{{ setting.key.upper }}' type='checkbox' {% if setting.as_bool %}checked=''{% endif %} {% if plugin %}plugin='{{ plugin.slug }}'{% endif %}{% if user_setting %}user='{{request.user.id}}'{% endif %}{% if notification_setting %}notification='{{request.user.id}}'{% endif %}>
        </div>
        {% else %}
        <div id='setting-{{ setting.pk }}'>
            <span id='setting-value-{{ setting.key.upper }}' fieldname='{{ setting.key.upper }}'>
                {% if setting.value %}
                {% if setting.is_choice %}
                <strong>{{ setting.as_choice }}</strong>
                {% else %}
                <strong>{{ setting.value }}</strong>
                {% endif %}
                {% else %}
                <em style='color: #855;'>{% trans "No value set" %}</em>
                {% endif %}
            </span>
            {{ setting.units }}
            <div class='btn-group float-right'>
                <button class='btn btn-outline-secondary btn-small btn-edit-setting' pk='{{ setting.pk }}' setting='{{ setting.key.upper }}' title='{% trans "Edit setting" %}' {% if plugin %}plugin='{{ plugin.slug }}'{% endif %}{% if user_setting %}user='{{request.user.id}}'{% endif %}>
                    <span class='fas fa-edit icon-green'></span>
                </button>
            </div>
        </div>
        {% endif %}
    </td>
</tr>
