$(function() {

	// Abrie seleção de status
	$('#b_situation').on('click', function() {

		if($('.status_r').css('display') != 'flex') {
			$('.status_r').css('display', 'flex');
		} else {
			$('.status_r').css('display', 'none');
		}
	});

	// Abrie seleção de produtos
	$('#p_situation').on('click', function() {

		if($('.status_p').css('display') != 'flex') {
			$('.status_p').css('display', 'flex');
		} else {
			$('.status_p').css('display', 'none');
		}
	});

	// Pesquisar clientes
	$('input[name="filter[client_name]"]').on('keyup', function() {
		if($(this).val() != '') {
			let text = $(this).val();		
			utils.searchRequestBy('searchclient', text, 'searchresultclient');
		} else {
			$('.searchresultclient').hide();
		}
	});

	$(document).on('click', 'div.searchresultclient ul li', function() {
		let clicked = parseInt($(this).attr('data-list'));
		let text = $(this).html();

		$('input[name="filter[client]"]').val(clicked);
		$('input[name="filter[client_name]"]').val(text);
		$('div.searchresultclient').hide(100);
	});

	// Buscar e seleção de fornecedor
	$('input[name="filter[provider_name]"]').on('keyup', function() {
		if($(this).val() != '') {
			let text = $(this).val();		
			utils.searchRequestBy('searchprovider', text, 'searchresultsprov');
		} else {
			$('.searchresultsprov').hide();
		}
	});

	$(document).on('click', 'div.searchresultsprov ul li', function() {
		let clicked = parseInt($(this).attr('data-list'));
		let text = $(this).html();

		$('input[name="filter[provider]"]').val(clicked);
		$('input[name="filter[provider_name]"]').val(text);
		$('div.searchresultsprov').hide(100);
	});

	// Comissão do vendedor
	$('input[name="filter[salesman_name]"]').on('keyup', function() {
		if($(this).val() != '') {
			let text = $(this).val();		
			utils.searchRequestBy('searchsalesman', text, 'searchresultsalesman');
		} else {
			$('.searchresultsalesman').hide();
		}
	});

	$(document).on('click', 'div.searchresultsalesman ul li', function(e) {
		e.preventDefault();
		let clicked = parseInt($(this).attr('data-list'));
		let text = $(this).html();

		$('input[name="filter[salesman]"]').val(clicked);
		$('input[name="filter[salesman_name]"]').val(text);
		$('div.searchresultsalesman').hide(100);
	});

});