{% sw_extends '@Storefront/storefront/page/product-detail/buy-widget-form.html.twig' %}
{% block page_product_detail_buy_container %}
{% set eventmain = page.product.extension('event') %}
{% set eventparent = page.product.extension('eventparent') %}
{% if eventmain %}
{% set event = eventmain %}
{% else %}
{% set event = eventparent %}
{% endif %}
{% set maxPlaces = 0 %}
{% set atLeastOneSlotWithPlaces = false %}
{% if event.bookable %}
{% if event.slots|length > 0 %}
{% block events_product_event_title %}
<h4 class="d-inline">{{ event.translated.title }}</h4>
{% endblock %}
{% block events_product_event_badge %}
<div class="badge badge-success float-right mt-1">
{{ 'netzp.events.eventsBadge'|trans }}
</div>
{% endblock %}
<ul class="list-group mt-2 mb-3" style="max-height: 23rem; overflow-y: auto">
{% for slot in event.slots %}
{% set ticketsAvailable = slot.ticketsAvailable - slot.ticketsBooked %}
{% if ticketsAvailable > 0 %}
{% set atLeastOneSlotWithPlaces = true %}
{% endif %}
{% if event.slots|length == 1 or app.request.get('slotId') == slot.id %}
{% set maxPlaces = ticketsAvailable %}
{% elseif maxPlaces == 0 %}
{% set maxPlaces = 1 %}
{% endif %}
{% set showSlot = true %}
{% if app.request.get('only') == 1 %}
{% set showSlot = app.request.get('slotId') == slot.id %}
{% endif %}
{% block events_product_event_slots %}
{% if showSlot %}
<li class="list-group-item list-group-item-light">
<div class="form-check mb-2">
<input type="radio" required
class="form-check-input"
id="netzpEvent_{{ slot.id }}"
name="netzpEventId"
value="{{ slot.id }}"
onchange="reloadPageWithSlot('{{ slot.id }}')"
{% if ticketsAvailable <= 0 %}disabled{% endif %}
{% if ticketsAvailable > 0 and ((event.slots|length == 1) or (app.request.get('slotId') == slot.id)) %}checked{% endif %}
>
<label class="form-check-label" for="netzpEvent_{{ slot.id }}">
{% sw_include "@Storefront/storefront/event.html.twig" with { 'event': event, 'slot': slot, 'showTitle': false } only %}
</label>
</div>
</li>
{% endif %}
{% endblock %}
{% endfor %}
</ul>
{% endif %}
{% if not atLeastOneSlotWithPlaces %}
<span class="badge badge-warning mb-3">
{{ "netzp.events.msg.noslots"|trans }}
</span>
{% else %}
{% do product.setCalculatedMaxPurchase(min(100, maxPlaces)) %}
{{ parent() }}
{% endif %}
{% else %}
{{ parent() }}
{% endif %}
<script>
function reloadPageWithSlot(id) {
var url = location.protocol + '//' + location.host + location.pathname + '?slotId=' + id;
window.location.href = url;
}
</script>
{% endblock %}