{% extends 'manage/changelog/master.twig' %}
{% from 'macros.twig' import container_title %}
{% from '_layout/input.twig' import input_csrf, input_text, input_select, input_checkbox %}

{% if change is not null %}
    {% set site_link = url('changelog-change', {'change': change.id}) %}
{% endif %}

{% block manage_content %}
    <div class="container">
        <form action="{{ url('manage-changelog-change', {'change': change.id|default(0)}) }}" method="post">
            {{ input_csrf() }}

            {{ container_title(change is not null ? 'Editing #' ~ change.id : 'Adding a new change') }}

            <div style="display: flex; margin: 2px 5px;">
                {{ input_select('change[action]', change_actions, change.action|default(0), 'action_name', 'action_id') }}
                {{ input_text('change[log]', '', change.header|default(''), 'text', '', true, {'maxlength':255,'style':'flex-grow:1'}) }}
            </div>

            <label class="form__label">
                <div class="form__label__text">Text</div>
                <div class="form__label__input">
                    <textarea class="input__textarea" name="change[text]" maxlength="65535">{{ change.body|default('') }}</textarea>
                </div>
            </label>

            <label class="form__label">
                <div class="form__label__text">Contributor Id</div>
                <div class="form__label__input">
                    {{ input_text('change[user]', '', change.userId|default(current_user.id), 'number', '', false, {'min':1}) }}
                </div>
            </label>

            <label class="form__label">
                <div class="form__label__text">Created</div>
                <div class="form__label__input">
                    {{ input_text('change[created]', '', change.createdTime|default(null)|date('Y-m-d H:i:s'), 'text', '', true) }}
                </div>
            </label>

            <div class="manage__tags">
                {% for tag in change_tags %}
                    <label class="manage__tag">
                        <div class="manage__tag__background"></div>
                        <div class="manage__tag__content">
                            {{ input_checkbox('tags[]', '', change.hasTag(tag)|default(false), 'manage__tag__checkbox', tag.id) }}
                            <div class="manage__tag__title">
                                {{ tag.name }}
                            </div>
                        </div>
                    </label>
                {% endfor %}
            </div>

            <div>
                <button class="input__button">Save</button>
            </div>
        </form>
    </div>
{% endblock %}
