{% extends 'layouts/admin.twig' %}

{% block content %}

    <ul class="breadcrumbs el">
        <li><a href="/admin/">Home</a> /</li>
        <li class="end">{{ page_meta.title }}</li>
    </ul>

    <h1>{{ page_meta.title }}</h1>
    {% include 'admin/roles/tabnav.twig' %}

    {% include 'admin/messages.twig' %}

    <form action="{{ self }}"
          method="post"
          class="style"
          enctype="multipart/form-data"
    >
        <div class="row">
            <label for="name">
                Name
            </label>
            <input type="text"
                   class="text"
                   name="name"
                   id="name"
                   value="{{ request.name is not empty ? request.name : role.name }}"
            />
        </div>


        {% for title, permissions in all %}
        <fieldset class="" id="permissions{% if loop.index > 1 %}{{ loop.index }}{% endif %}">
                <h1>
                    <a class="show el">
                        {{ title }} <i class="fa fa-caret-right"></i>
                    </a>
                </h1>
                {% for permission in permissions %}

                <div class="row checkboxes bottomSeparator">
                    <input
                            type="checkbox"
                            name="permissions[{{ permission.id }}]"
                            value="{{ permission.id }}"
                            id="permissions-{{ permission.id }}"
                            {{ role.hasPermission(permission.id) ? 'checked' : '' }}
                            class="parent"
                            data-id="{{ permission.id }}"/>
                    <label for="permissions-{{ permission.id }}">
                        {{ permission.title }} (All)
                    </label>


                    <div class="row checkboxes">
                        {% for sub_menu in permission.subItems %}
                            <div class="row" style="padding-left: 30px;">
                                <input type="checkbox"
                                       name="permissions[{{ sub_menu.id }}]"
                                       value="{{ sub_menu.id }}"
                                       id="permissions-{{ sub_menu.id }}"
                                       {{ role.hasPermission(sub_menu.id) ? 'checked' : '' }}
                                       class="child"
                                       data-parent="{{ permission.id }}"/>
                                <label for="permissions-{{ sub_menu.id }}">
                                    {{ sub_menu.title }}
                                </label>
                            </div>
                        {% endfor %}
                    </div>
                </div>
                {% endfor %}
        </fieldset>
        {% endfor %}

        <div class="row">
            <input type="hidden"
                   name="action"
                   value="update"
            />
            <input type="hidden"
                   name="id"
                   value="{{ id }}"
            />
            <button type="submit"
                    name="submit"
                    class="btn"
                    value="update"
            >
                Save
            </button>
        </div>
    </form>

{% endblock %}