(function (Drupal, $, once) {
  Drupal.behaviors.searchViewButtons = {
    attach: function (context, settings) {
      var currentParams = window.location.search.substring(1);
      $(once('resourceexpand', 'button.resource-button-expand', context)).click(function () {
          currentParams = window.location.search.substring(1);
          currentParams = currentParams.replace(/=resources_all_resourcetype/g, "=resource_type");
          currentParams = currentParams.replace(/=resources_all_program/g, "=program");
          currentParams = currentParams.replace(/=resources_compact_initiatives/g, "=resources_initiatives");
          currentParams = currentParams.replace(/=resources_all_datatype/g, "=data_type");
          currentParams = currentParams.replace(/=resources_all_audience/g, "=audience");
          currentParams = currentParams.replace(/=resources_all_listtopic/g, "=topic");
          currentParams = currentParams.replace(/=resources_compact_authored_on_date/g, "=resources_authored_on_date");
          currentParams = currentParams.replace(/=resources_compact_langcode/g, "=resources_langcode");
          window.location.href = '/resources?' + currentParams;
        });

        $(once('resourcecompactexport', 'button.resource-button-compact-export', context)).click(function () {
          currentParams = window.location.search.substring(1);
          currentParams = currentParams.replace(/=resources_all_resourcetype/g, "=resources_compact_resource_type_export");
          currentParams = currentParams.replace(/=resources_all_program/g, "=resources_compact_related_programs_export");
          currentParams = currentParams.replace(/=resources_compact_initiatives/g, "=resources_compact_related_initiatives_export");
          currentParams = currentParams.replace(/=resources_all_datatype/g, "=resources_compact_data_type_export");
          currentParams = currentParams.replace(/=resources_all_audience/g, "=resources_compact_audience_export");
          currentParams = currentParams.replace(/=resources_all_listtopic/g, "=resources_compact_topic_export");
          currentParams = currentParams.replace(/=resources_compact_authored_on_date/g, "=resources_compact_export_authored_on_date");
          currentParams = currentParams.replace(/=resources_compact_langcode/g, "=	resources_compact_langcode_export");
          window.location.href = '/fns-documents-resources-compact-view-export?' + currentParams;
        });

        $(once('resourcecompact', 'button.resource-button-compact', context)).click(function () {
          var currentParams = window.location.search.substring(1);
          currentParams = currentParams.replace(/=resource_type/g, "=resources_all_resourcetype");
          currentParams = currentParams.replace(/=program/g, "=resources_all_program");
          currentParams = currentParams.replace(/=resources_initiatives/g, "=resources_compact_initiatives");
          currentParams = currentParams.replace(/=data_type/g, "=resources_all_datatype");
          currentParams = currentParams.replace(/=audience/g, "=resources_all_audience");
          currentParams = currentParams.replace(/=topic/g, "=resources_all_listtopic");
          currentParams = currentParams.replace(/=resources_authored_on_date/g, "=resources_compact_authored_on_date");
          currentParams = currentParams.replace(/=resources_langcode/g, "=resources_compact_langcode");
          window.location.href = '/fns-documents-resources-compact-view?' + currentParams;
        });

        $(window).on('load', function (event) {
          var currentParams = window.location.search.substring(1);
          if (currentParams.includes('resources_all_resourcetype%3A160') ||
              currentParams.includes('resources_compact_resource_type_export%3A160')) {
              $('.views_view__resources_view_all button.resource-button-compact-export').removeClass('hide-compact-export-btn');
          }
          else {
            $('.views_view__resources_view_all button.resource-button-compact-export').addClass('hide-compact-export-btn');
          }
        });
    }
  };
})(Drupal, jQuery, once);