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

{% block manage_content %}
    <form action="?v=role{{ role_info is not null ? '&r=' ~ role_info.id : '' }}" method="post"{% if role_info is not null %} style="--accent-colour: {{ role_info.colour }}"{% endif %}>
        {{ input_csrf() }}

        <div class="container">
            {{ container_title(role_info is not null ? 'Editing ' ~ role_info.name ~ ' (' ~ role_info.id ~ ')' : 'Creating a new role') }}

            <label class="form__label">
                <div class="form__label__text">Role Name</div>
                <div class="form__label__input">
                    {{ input_text('role[name]', '', role_info.name|default(''), 'text', '', true, {'maxlength':255}) }}
                </div>
            </label>

            <label class="form__label">
                <div class="form__label__text">Hide Rank</div>
                <div class="form__label__input">
                    {{ input_checkbox('role[secret]', '', role_info is not null and role_info.hidden) }}
                </div>
            </label>

            <label class="form__label">
                <div class="form__label__text">Hierarchy</div>
                <div class="form__label__input">
                    {{ input_text('role[hierarchy]', '', role_info.rank|default(1), 'number', '', true) }}
                </div>
            </label>

            <label class="form__label">
                <div class="form__label__text">Title</div>
                <div class="form__label__input">
                    {{ input_text('role[title]', '', role_info.title|default(''), 'text', '', false, {'maxlength':64}) }}
                </div>
            </label>

        </div>

        <div class="container">
            {{ container_title('Colour') }}

            <label class="form__label">
                <div class="form__label__text">Inherit Colour</div>
                <div class="form__label__input">
                    {{ input_checkbox('role[colour][inherit]', '', role_info is not null ? role_info.colour.shouldInherit : true) }}
                </div>
            </label>

            <label class="form__label">
                <div class="form__label__text">Red</div>
                <div class="form__label__input">
                    {{ input_text('role[colour][red]', '', role_info.colour.red|default(0), 'number', '', false, {'min':0,'max':255}) }}
                </div>
            </label>

            <label class="form__label">
                <div class="form__label__text">Green</div>
                <div class="form__label__input">
                    {{ input_text('role[colour][green]', '', role_info.colour.green|default(0), 'number', '', false, {'min':0,'max':255}) }}
                </div>
            </label>

            <label class="form__label">
                <div class="form__label__text">Blue</div>
                <div class="form__label__input">
                    {{ input_text('role[colour][blue]', '', role_info.colour.blue|default(0), 'number', '', false, {'min':0,'max':255}) }}
                </div>
            </label>

        </div>

        <div class="container">
            {{ container_title('Additional') }}

            <label class="form__label">
                <div class="form__label__text">Description</div>
                <div class="form__label__input">
                    <textarea class="input__textarea" name="role[description]" maxlength="1000">{{ role_info.description|default('') }}</textarea>
                </div>
            </label>
        </div>

        <div class="container">
            {{ container_title('Permissions') }}
            {{ permissions_table(permissions, not can_manage_perms) }}
        </div>

        <button class="input__button">{{ role_info is not null ? 'Update role' : 'Create role' }}</button>
    </form>
{% endblock %}
