jQuery(document).ready(function(){var e,a;"undefined"!=typeof hot&&(e=hot.getSettings(),a=null,e)&&e.contextMenu&&e.contextMenu.items&&(e.contextMenu.items.find_same_value={name:vgse_editor_settings.texts.find_rows_with_same_value,hidden:function(){var e=hot.getSelected();if(!e||1<e.length||e[0][0]!==e[0][2]||e[0][1]!==e[0][3])return!0;var t=hot.getDataAtCell(e[0][0],e[0][1]);if(null===t||""===t)return!0;null===a&&(a=jQuery(".wpse-advanced-filters-field-selector option").map(function(){return jQuery(this).val()}).get());t=hot.colToProp(e[0][1]);return-1===a.indexOf(t)},callback:function(e,t,a){var i=t[0].start.row,t=t[0].start.col,n=hot.colToProp(t),i=hot.getDataAtCell(i,t),t=(t=jQuery('.wpse-advanced-filters-field-selector option[value="'+n+'"]').data("source"))||"meta";beAddRowsFilter({meta_query:[{key:n,compare:"=",value:i,source:t}]},!0),vgseReloadSpreadsheet(!0)}},hot.updateSettings({contextMenu:e.contextMenu}))}),jQuery(document).ready(function(){window.vgseCachedAdvancedFilters=jQuery("#be-filters .advanced-filters-list").clone(!0)}),wp.hooks.addAction("vgseFilters_afterInit","vgseAdvancedFilters",function(e){if(!window.vgseFavoriteFiltersInitialized){window.vgseFavoriteFiltersInitialized=!0;var a=jQuery("#be-filters");if(!a.length)return!0;var i=jQuery(".vg-toolbar .button-container.run_filters-container .toolbar-submenu-holder");a.find("li").each(function(){var e,t=jQuery(this),a=t.find("input,select,textarea").first();a.length&&(a=a.attr("name"))&&"keyword"!==a&&(e=-1<vgse_editor_settings.favorite_search_fields.indexOf(a)?"fa-star":"fa-star-o",t.append('<button class="wpse-favorite-search-field" type="button" data-key="'+a+'"><i class="fa '+e+'"></i></button>'),"fa-star"==e)&&s(t,a)}),jQuery("body").on("click",".wpse-favorite-search-field",function(e){e.preventDefault();var e=jQuery(this),t=(e.find("i").toggleClass("fa-star fa-star-o"),e.find(".fa-star").length?s(e.parents("li"),e.data("key")):(e.parents("li"),n(e.data("key")).remove(),r()),[]);a.find(".wpse-favorite-search-field .fa-star").each(function(){t.push(jQuery(this).parent().data("key"))}),t=[...new Set(t)],jQuery.post(vgse_global_data.ajax_url,{action:"vgse_mark_search_fields_as_favorite",post_type:vgse_editor_settings.post_type,fields:t,nonce:vgse_editor_settings.nonce})})}function n(e){return i.find("ul").filter(function(){return jQuery(this).data("key")===e})}function r(){setTimeout(()=>{1<i.find("input,select,textarea").length?i.find(".wpse-start-quick-search").show():i.find(".wpse-start-quick-search").hide(),i.find(".wpse-start-quick-search").appendTo(i)},200)}function s(e,t){var a;n(t).length||(e.find(".select2").each(function(){jQuery(this).data("select2")&&jQuery(this).select2("destroy")}),a=e.hasClass("advanced-field")&&window.vgseCachedAdvancedFilters?window.vgseCachedAdvancedFilters:e.clone(!0),i.append('<ul data-key="'+t+'"></ul>'),t=a.find(".wpse-advanced-filters-field-selector").length?(a.prepend("<span>"+wp.i18n.__("Search by specific field","vg_sheet_editor")+"</span>"),vgse_editor_settings.default_advanced_filter_field&&a.find(".wpse-advanced-filters-field-selector").val(vgse_editor_settings.default_advanced_filter_field),a.find(".wpse-advanced-filters-value-selector").remove(),a.get(0).outerHTML.replace(/index ?\)/g,"0)").replace(/\( ?filter ?\)/g,"(activeFilters.meta_query[0])").replace(/"index"/g,'"0"').replace(/filter\./g,"activeFilters.meta_query[0].").replace(/\'\+index\+\'/g,"0").replace(/"index /g,'"0 ')):a.get(0).outerHTML,i.find("ul").last().append(t),vgseInitSelect2(e.find(".select2")),vgseInitSelect2(i.find("ul").last().find(".select2")),r())}}),document.addEventListener("alpine:init",()=>{Alpine.data("vgseSavedSearches",()=>({get saved_searches(){return Alpine.store("vgseFilters").savedSearches},loadSearch(e){beAddRowsFilter(e.filters,!0),vgseReloadSpreadsheet()},deleteSearch(e,t){var a=vgse_editor_settings.texts.confirm_delete_saved_search;confirm(a)&&Alpine.store("vgseFilters").deleteSavedSearch(t)}}))});