$(() => {
  $("#searchDesktop").on("click", () => {
    var texto = $("#searchDesktop").val();
    if (texto === "") {
      $(".dropdown-search").dropdown('toggle');
    }
  });
  
  $("#searchDesktop").keyup(function (e) {
    var currentInput = $("#searchDesktop").val();
    $(".text-search-input").text(currentInput);
    $(".text-search-input-2").text(currentInput);
    $(".dropdown-search").addClass("show open");
    $(".dropdown-search-menu").addClass("show open");
    
    $("#linkFazendaRJ").attr('href', `https://www.google.com.br/search?q=${encodeURIComponent(currentInput)}+site:portal.fazenda.rj.gov.br OR site:portal2.fazenda.rj.gov.br OR site:legislacao.fazenda.rj.gov.br`);

    if (e.keyCode === 13) {
      $(".dropdown-search").dropdown('toggle');
      $(".text-search-input").text(currentInput);
      $(".text-search-input-2").text(currentInput);
    }
  });
});

/* Search mobile */
$(() => {
  $("#searchMobile").on("click", () => {
    var texto2 = $("#searchMobile").val();
    if (texto2 === "") {
      $(".dropdown-search2").dropdown('toggle');
    }
  });
  
  $("#searchMobile").keyup(function (e) {
    var currentInput2 = $("#searchMobile").val();
    $(".text-search-input3").text(currentInput2);
    $(".text-search-input4").text(currentInput2);
    $(".dropdown-search2").addClass("show open");
    $(".dropdown-search-menu2").addClass("show open");
    
    $("#linkFazendaRJ2").attr('href', `https://www.google.com.br/search?q=${encodeURIComponent(currentInput2)}+site:portal.fazenda.rj.gov.br OR site:portal2.fazenda.rj.gov.br OR site:legislacao.fazenda.rj.gov.br`);

    if (e.keyCode === 13) {
      $(".dropdown-search2").dropdown('toggle');
      $(".text-search-input3").text(currentInput2);
      $(".text-search-input4").text(currentInput2);
    }
  });
});
