{{ header }}{{ column_left }}
<div id="content">
	<div class="page-header">
		<div class="container-fluid">
			<div class="float-end">
				<button type="submit" form="form-event" formaction="{{ delete }}" data-bs-toggle="tooltip" title="{{ button_delete }}" onclick="return confirm('{{ text_confirm }}');" class="btn btn-danger"><i class="fa-regular fa-trash-can"></i></button>
			</div>
			<h1>{{ heading_title }}</h1>
			<ol class="breadcrumb">
				{% for breadcrumb in breadcrumbs %}
					<li class="breadcrumb-item"><a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a></li>
				{% endfor %}
			</ol>
		</div>
	</div>
	<div class="container-fluid">
		<div class="alert alert-info"><i class="fa-solid fa-info-circle"></i> {{ text_event }}</div>
		<div class="card">
			<div class="card-header"><i class="fa-solid fa-list"></i> {{ text_list }}</div>
			<div id="event" class="card-body">{{ list }}</div>
		</div>
	</div>
</div>
<script type="text/javascript"><!--
$('#event').on('click', 'thead a, .pagination a', function (e) {
    e.preventDefault();

    $('#event').load(this.href);
});

$('#event').on('click', '.btn-success, .btn-danger', function (e) {
    e.preventDefault();

    var element = this;

    $.ajax({
        url: $(element).val(),
        type: 'post',
        data: $('#event input[name=\'selected[]\']:checked'),
        dataType: 'json',
        beforeSend: function () {
            $(element).button('loading');
        },
        complete: function () {
            $(element).button('reset');
        },
        success: function (json) {
            if (json['error']) {
                $('#alert').prepend('<div class="alert alert-danger alert-dismissible"><i class="fa-solid fa-circle-exclamation"></i> ' + json['error'] + ' <button type="button" class="btn-close" data-bs-dismiss="alert"></button></div>');
            }

            if (json['success']) {
                $('#alert').prepend('<div class="alert alert-success alert-dismissible"><i class="fa-solid fa-check-circle"></i> ' + json['success'] + ' <button type="button" class="btn-close" data-bs-dismiss="alert"></button></div>');

                $('#event').load($('#form-event').attr('data-oc-load'));
            }
        },
        error: function (xhr, ajaxOptions, thrownError) {
            console.log(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
        }
    });
});

$('#event').on('click', '.btn-info', function () {
    var element = this;

    $('#modal-event').remove();

    html = '<div id="modal-event" class="modal">';
    html += '  <div class="modal-dialog">';
    html += '    <div class="modal-content">';
    html += '      <div class="modal-header">';
    html += '        <h5 class="modal-title">{{ text_info|escape('js') }}</h5>';
    html += '        <button type="button" class="btn-close" data-bs-dismiss="modal"></button>';
    html += '      </div>';
    html += '      <div class="modal-body">';
    html += '        <div class="mb-3">';
    html += '          <label for="input-description" class="form-label">{{ entry_description|escape('js') }}</label> <textarea placeholder="{{ entry_description|escape('js') }}" id="input-description" rows="5" class="form-control" disabled>' + $(element).attr('data-oc-description') + '</textarea>';
    html += '        </div>';
    html += '        <div class="mb-3">';
    html += '          <label for="input-trigger" class="form-label">{{ entry_trigger|escape('js') }}</label> <textarea placeholder="{{ entry_trigger|escape('js') }}" id="input-trigger" class="form-control" disabled>' + $(element).attr('data-oc-trigger') + '</textarea>';
    html += '        </div>';
    html += '        <div class="mb-3">';
    html += '          <label for="input-action" class="form-label">{{ entry_action|escape('js') }}</label> <textarea placeholder="{{ entry_action|escape('js') }}" id="input-action" class="form-control" disabled>' + $(element).attr('data-oc-action') + '</textarea>';
    html += '        </div>';
    html += '      </div>';
    html += '      </div>';
    html += '    </div>';
    html += '  </div>';
    html += '</div>';

    $('body').append(html);

    var modal = new bootstrap.Modal(document.querySelector('#modal-event'));

    modal.show();
});
//--></script>
{{ footer }}
