{% load custom_tags_and_filters %}
<div class="tab-pane" id="osticket"></div>
<script>
	function load_tickets(tool_id)
	{
        $('#loading-div').show();
		let failure_dialog = ajax_complete_callback("Unable to find tickets", "There was a problem retrieving tickets for this tool.");
		$("#osticket").load("{% url 'osticket_tool_status_tickets' 999 %}".replace('999', tool_id), function (){$('#loading-div').hide();}, failure_dialog);
	}

	$(document).ready(function() {
        {% if replace_problems_tab %}
        $('a[href="#problem"]').replaceWith(`<a href="#osticket" {% if device == 'mobile' %}style="padding: 10px 5px;"{% endif %} onclick="load_tickets('{{ tool_id }}');">{{ tab_name }}</a>`);
        {% else %}
		$('#tabs').append(`<li {% if device == 'mobile' %}style="width: 48%; text-align: center"{% endif %}><a href="#osticket" onclick="load_tickets('{{ tool_id }}');">{{ tab_name }}</a></li>`);
        {% endif %}
        $("#osticket").insertAfter("#summary");
        // we need to call this again so it works with our new tab
        $("#tabs").find("a").click(switch_tab);
    })
</script>
