<% query = local_assigns[:query] || @query %>
<% if query && query.persisted? && params[:query_id].present? && User.current.logged? && query.visible?(User.current) %>
  <% favorite = UxToolkitFavoriteQuery.exists?(user_id: User.current.id, query_id: query.id) %>
  <div class="box ux-toolkit-favorite-query">
    <h3 class="icon <%= favorite ? 'icon-fav' : 'icon-bookmark' %>">
      <%= ux_toolkit_sprite_icon(favorite ? 'fav' : 'bookmark-add', l(:label_ux_toolkit_favorite_query)) %>
    </h3>
    <% if favorite %>
      <%= button_to l(:label_ux_toolkit_remove_query_from_favorites),
                    remove_ux_toolkit_favorite_query_path(query),
                    method: :delete,
                    class: 'button-small' %>
    <% else %>
      <%= button_to l(:label_ux_toolkit_add_query_to_favorites),
                    ux_toolkit_favorite_query_path(query),
                    method: :post,
                    class: 'button-small' %>
    <% end %>
  </div>
<% end %>
