{% extends 'manage/users/master.twig' %}
{% from 'macros.twig' import pagination, container_title %}
{% from '_layout/input.twig' import input_csrf, input_text %}

{% set redirs_pagination = pagination(manage_redirs_pagination, 'manage-forum-topic-redirs') %}

{% block manage_content %}
    <div class="container">
        {{ container_title('<i class="fas fa-share fa-fw"></i> Topic Redirects') }}

        <div class="manage__description">
            Allows you to set redirects for deleted forum topics.
        </div>

        <form method="post" action="{{ url('manage-forum-topic-redirs-create') }}" class="manage-setting">
            {{ input_csrf() }}

            <label class="manage-setting-field">
                <div class="manage-setting-field-name">Topic #</div>
                {{ input_text('topic_redir_id', 'manage__emote__field__value', '', 'number') }}
            </label>

            <label class="manage-setting-field">
                <div class="manage-setting-field-name">Target URL</div>
                {{ input_text('topic_redir_url', 'manage__emote__field__value', '', 'text') }}
            </label>

            <div class="manage-setting-actions">
                <button class="input__button input__button--save">Create</button>
            </div>
        </form>

        {% if redirs_pagination|trim|length > 0 %}
            <div class="manage__users__pagination">
                {{ redirs_pagination }}
            </div>
        {% endif %}

        <div class="manage-settings-list-container">
            <table class="manage-settings-list">
                <thead>
                    <tr class="manage-settings-list-header">
                        <th class="manage-settings-list-header-name">Topic #</th>
                        <th class="manage-settings-list-header-name">User #</th>
                        <th class="manage-settings-list-header-value">Target URL</th>
                        <th class="manage-settings-list-header-value">Created</th>
                        <th class="manage-settings-list-header-options">Options</th>
                    </tr>
                </thead>
                <tbody>
                {% for redir in manage_redirs %}
                    <tr class="manage-list-setting">
                        <td class="manage-list-setting-key">
                            <div class="manage-list-setting-key-text">{{ redir.topicId }}</div>
                        </td>
                        <td class="manage-list-setting-key">
                            <div class="manage-list-setting-key-text">{{ redir.hasUserId ? redir.userId : 'System' }}</div>
                        </td>
                        <td class="manage-list-setting-value">
                            <div class="manage-list-setting-value-text">{{ redir.linkTarget }}</div>
                        </td>
                        <td class="manage-list-setting-value">
                            <div class="manage-list-setting-value-text">
                                <time datetime="{{ redir.createdTime|date('c') }}" title="{{ redir.createdTime|date('r') }}">
                                    {{ redir.createdTime|time_format }}
                                </time>
                            </div>
                        </td>
                        <td class="manage-list-setting-options">
                            <a class="input__button input__button--autosize input__button--destroy" href="{{ url('manage-forum-topic-redirs-nuke', { topic: redir.topicId, csrf: csrf_token() }) }}" title="Delete"><i class="fas fa-times fa-fw"></i></a>
                        </td>
                    </tr>
                {% endfor %}
                </tbody>
            </table>
        </div>

        {% if redirs_pagination|trim|length > 0 %}
            <div class="manage__users__pagination">
                {{ redirs_pagination }}
            </div>
        {% endif %}
    </div>
{% endblock %}
