{% extends 'modal.html.twig' %}

{% block title %}{% if mod %}Modifier{%else%}Ajouter{% endif %} une partie{% endblock %}

{% block content %}

    {% if not party.isValidated and party.getId %}
    <article class="message is-info">
        <div class="message-header">
            <p>Partie nécessitant une validation</p>
        </div>
        <div class="message-body">
            Cette partie a été proposée par {{ party.getSubmitter.fullName }} le {{ party.getSubmittedDate|date('d/m/y H:i', app_timezone) }}
        </div>
    </article>
    {% endif %}

    {{ form_errors(form) }}
    {{ form_start(form, {action: path(pathController, {id: slotStart.getId}), attr: {'data-turbo-frame': 'modal-content'}}) }}

    <div id="gamemaster-controller" class="field" {{ stimulus_controller('party_selector') }}>
        <label class="label">Meneur(euse) de jeu</label>
        <select id="party_gamemaster" name="party_gamemaster" class="input">
            <option value=""></option>
            {% for gamemaster in gamemasters %}
            <option value="{{ gamemaster.id }}" data-games="{{ gamemaster.getGamesCanMaster|map(game => game.getId)|join('|') }}"{% if party.getGamemaster == gamemaster %}selected='selected'{% endif %}>{{ gamemaster.getPreferedName() }}</option> 
            {% endfor %}
        </select>
    </div>

    <div id="game-controller" class="field">
        <label class="label">Jeu de rôle</label>
        <select id="party_game" name="party_game" class="input">
            <option value=""></option>
            {% for game in games %}
            <option value="{{ game.id }}" {% if party.getGame == game %}selected='selected'{% else %}disabled{% endif %}>{{ game.getName() }}</option> 
            {% endfor %}
        </select>
    </div>
    
{#    <div class="field">
        {{ form_widget(form.gamemasterIsAuthor) }}
        {{ form_label(form.gamemasterIsAuthor) }}
        {{ form_help(form.gamemasterIsAuthor) }}
    </div>#}
    {{ form_row(form.description) }}

    <div class="box">
        <div class="columns">
            <div class="column">
                {{ form_row(form.minParticipants) }}
            </div>
            <div class="column">
                {{ form_row(form.maxParticipants) }}
            </div>
        </div>
    </div>

    <div class="box">
         <div class="columns">
            <div class="column">
                <div class="field">
                    <label class="label">Horaire de début</label>
                    <select id="party_start_slot" name="party_start_slot" class="input">
                        <option value="{{ slotStart.id }}" selected="selected">{{ slotStart.startOn|date('d/m/Y H:i', app_timezone) }}</option>
                    </select>
                </div>
            </div>
            <div class="column">
                <div class="field">
                    <label class="label">Horaire de fin</label>
                    <select id="party_slots" name="party_slots" class="input">
                    {% set SlotC = [] %}
                    {% for slot in slotsAvailables %}
                        {% set SlotC = SlotC|merge([slot.id]) %}
                        <option value="{{ SlotC|join("|") }}" {% if slot == party.getSlots.last %}selected="selected"{% endif %}>{{ slot.endOn|date('d/m/Y H:i', app_timezone) }}</option>
                    {% endfor %}
                    </select>
                </div>
            </div>
        </div>       
    </div>

    {{ form_widget(form) }}
    
    <div class="control">
        <button class="button is-primary" type="submit">Envoyer</button>
        {% if mod %}
        <a href="#" class="button" data-turbo="false">Déplacer</a>
        <a href="#" data-id="{{ path('app_party_delete', {id: party.getId}) }}" class="button is-danger" data-turbo="false" {{ stimulus_controller('admin_confirm') }}>Supprimer</a>
        {% endif %}
        {% if not party.isValidated and party.getId %}
        <a href="{{ path('app_party_validate', {id: party.getId}) }}" class="button is-info" data-turbo="false">Valider la partie</a>
        {% endif %}
    </div>

    {{ form_end(form) }}

{% endblock %}
