<!DOCTYPE html>
	<html lang="pt-br">
		<head>
			<meta charset="utf-8"/>
			<title>Gerenciador de eventos</title>
			<link rel="stylesheet" href="/mention.css">
			<meta name="viewport" content="width=device-width, initial-scale=1">
  			<link rel="stylesheet" href="//code.jquery.com/ui/1.13.0/themes/base/jquery-ui.css">
  			<link rel="stylesheet" href="/resources/demos/style.css">
		</head>
	<body>

		<br/>
		<form action="/publicar/enviar" method="post" enctype="multipart/form-data">
			<label>Texto</label>
			<textarea type="text" id="text" name="text" rows="5" cols="30"></textarea>
			<br/>
			<label>Tags:</label>
			<textarea type="text" id="tags" name="tags"></textarea>
			<br/>
			<input name="img" type="file" />
			<br/>
			<br/>
			<input type="submit" value="Enviar"/>
		</form>

	</body>
</html>

<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript" src="http://jakiestfu.github.io/Mention.js/javascripts/bootstrap-typeahead.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://code.jquery.com/jquery-3.6.0.js"></script>
<script src="https://code.jquery.com/ui/1.13.0/jquery-ui.js"></script>


<script type="text/javascript">
  $( function() {
  	var tag = {
        tag: '',
    };
    var availableTags = [
      
    ];
    function split( val ) {
      return val.split( /,\s*/ );
    }
    function extractLast( term ) {
      return split( term ).pop();
    }
 
    $( "#tags" )
      // don't navigate away from the field on tab when selecting an item
      .on( "keyup", function( event ) {
      	tag.tag = document.getElementById("tags").value;
      	$.ajax({
						url: '/search',
						async: true,
						method: "post",
						data: tag,
						success: function(data){
							console.log(data);
							availableTags = data;
						}
					});


        if ( event.keyCode === $.ui.keyCode.TAB &&
            $( this ).autocomplete( "instance" ).menu.active ) {
          event.preventDefault();
        }
      })
      .autocomplete({
        minLength: 0,
        source: function( request, response ) {
          // delegate back to autocomplete, but extract the last term
          response( $.ui.autocomplete.filter(
            availableTags, extractLast( request.term ) ) );
        },
        focus: function() {
          // prevent value inserted on focus
          return false;
        },
        select: function( event, ui ) {
          var terms = split( this.value );
          // remove the current input
          terms.pop();
          // add the selected item
          terms.push( ui.item.value );
          // add placeholder to get the comma-and-space at the end
          terms.push( "" );
          this.value = terms.join( ", " );
          return false;
        }
      });
  } );
  </script>