{% extends 'gird-gallery.twig' %}

{% block content %}

    {% set selectValues = { 'yes': environment.translate('Yes'), 'no': environment.translate('No') } %}

    <div class="gg-item gg-gallery-panel">

        {#{% if message is defined %}#}

        {#<p>{{ message }}</p>#}

        {% if validator is defined %}
            <p>{{ validator.getErrors()|join('<br />') }}</p>
        {% endif %}

        {#{% endif %}#}

        <form
                method="{{ form.method|default('POST') }}"
                action="{{ form.action|default(environment.generateUrl('settings')) }}"
                accept-charset="{{ form.accept_charset|default('UTF-8') }}"
                id="gg-save-settings"
                >
            <fieldset>

                <table class="form-table">
                    <tbody>
                    <tr>
                        <th scope="row">
                            <label for="gg-cache-enabled">Use build-in caching:</label>
                        </th>
                        <td>
                            <select name="cache_enabled" id="cacheEnabled" style="width: 100px;"
                                    {% if environment.config.get('uploads_rw') == false %}disabled="disabled"{% endif %}>
                                <option value="0"
                                        {% if registry.get('cache_enabled') == 0 %}selected{% endif %}>{{ selectValues.no }}</option>
                                <option value="1"
                                        {% if registry.get('cache_enabled') == 1 %}selected{% endif %}>{{ selectValues.yes }}</option>
                            </select>

                            <p class="description">{{ environment.translate('<strong>%s</strong> has its own caching system in order to significantly reduce the load on the database.')|format('Ready! Grid Gallery')|raw }}</p>
                            <p class="description">{{ environment.translate('Use this option only if all your galleries are setting correctly and you dont need to change settings soon') }}</p>
                            {% if environment.config.get('uploads_rw') == false %}
                                <p class="description">
                                    <strong>
                                        {{ environment.translate('Caching is not available because your uploads directory is not writable.') }}
                                    </strong>
                                </p>
                            {% endif %}
                        </td>
                    </tr>
                    <tr id="cacheTtlRow">
                        <th scope="row">
                            <label for="gg-cache-ttl">Lifetime for cached data:</label>
                        </th>
                        <td>
                            <input type="text" name="cache_ttl" id="gg-cache-ttl"
                                   value="{{ registry.get('cache_ttl')|default('86400') }}"/>

                            <p class="description">
                                {{ environment.translate('The time in seconds after which the cache will be considered obsolete. Default: 86400 (24 hours).') }}
                            </p>
                        </td>
                    </tr>
                    <tr id="cacheClearRow">
                        <th scope="row">
                            &nbsp;
                        </th>
                        <td>
                            <button class="button" id="clearCache">{{ environment.translate('Clear cache') }}</button>
                        </td>
                    </tr>
                    <tr>
                        <th scope="row">
                            <label for="gg-send-stats">Allow plugin to send anonymous usage statistics:</label>
                        </th>
                        <td>
                            <select name="send_stats" id="gg-sens-stats" style="width: 100px;">
                                <option value="0"
                                        {% if registry.get('send_stats') == 0 %}selected{% endif %}>{{ selectValues.no }}</option>
                                <option value="1"
                                        {% if registry.get('send_stats') == 1 %}selected{% endif %}>{{ selectValues.yes }}</option>
                            </select>

                            <p class="description">{{ environment.translate('We don\'t collect statistics on you, we only collect the errors encountered during use in order to improve our product.') }}</p>
                        </td>
                    </tr>
                    </tbody>
                </table>

                <input type="submit" value="{{ environment.translate('Save') }}" class="button button-primary"/>

            </fieldset>
        </form>
    </div>

{% endblock %}
