@if(!defined('LOAD_TABS'))
	@push('scripts')

		<script>
			function addTab(name, id, txt, url) {
				
				var navContainer = $('#'+name);
				var tabContainer = $('#'+name + '-tab');
				var newTab = name + '-' + id;
				var newTabId = '#' + newTab;
				// create the tab
				$('<a href="'+newTabId+'" data-toggle="tab" class="nav-item nav-link" role="tab">'+txt+'</a>').appendTo(navContainer);

				var url_open = url + id;

				$.get(url_open, function(content) {
					$('<div class="tab-pane fade pt-0 pb-0" id="'+newTab+'"><div class="card mb-0 card-outline card-info"><div class="card-body">'+content+'</div></div></div>').appendTo(tabContainer);
	
					// make the new tab active
					// console.log('#' + tabname + ' .nav-item a:last');
					// $('#' + tabname + ' .nav-item a:last').tab('show');
				});

			}

			function removeTab(name, id) {
				var tabId = '#' + name + '-' + id;
				// console.log('#' + name + "a[href='" + tabId + "'])");
				$('#' + name + " a[href='" + tabId + "']").remove();
				// console.log('remove ' + tabId);
				$(tabId).remove();

			}
		</script>

	@endpush

	@php(define('LOAD_TABS', true))
@endif