!function(e){"function"==typeof define&&define.amd?define("myListings",e):e()}(function(){"use strict";function r(e){return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}jQuery(function(n){var t={listing_id:null,listing_name:null,package_id:null},i=n("#promo-modal .sign-in-box"),a=(n(".listing-dashboard-action-promote").click(function(e){t.listing_id=n(e.target).data("listing-id"),t.listing_name=n(e.target).data("listing-name"),n("#promo-modal .listing-name").text('"'+t.listing_name+'"')}),n("#promo-modal .promo-product-item, .promo-product-item .process-promotion").click(function(e){e.preventDefault();e=n(e.currentTarget);if(e.data("package-id")&&(t.package_id=e.data("package-id")),e.data("listing-id")&&(t.listing_id=e.data("listing-id")),e.data("process")?t.process=e.data("process"):t.process="buy-package","cancel-package"===t.process&&!confirm(CASE27.l10n.irreversible_action))return!1;i.addClass("cts-processing-login"),jQuery.ajax({url:"".concat(CASE27.mylisting_ajax_url,"&action=cts_promotions&security=").concat(CASE27.ajax_nonce),type:"POST",dataType:"json",data:{listing_id:t.listing_id,package_id:t.package_id,process:t.process},success:function(e){"object"===r(e)&&(e.redirect&&window.location.replace(e.redirect),"error"===e.status)&&e.message&&alert(e.message)},error:function(e,t,n){console.log("Failed",e,t,n)},complete:function(){i.removeClass("cts-processing-login")}})}),n(".cts-listing-action-duplicate a").on("click",function(e){e.preventDefault();var t=n(e.target);t.parents(".listing-cell").addClass("cell-busy"),n.ajax({url:"".concat(CASE27.mylisting_ajax_url,"&action=post_duplicate&security=").concat(CASE27.ajax_nonce),type:"POST",dataType:"json",data:{listing_id:t.data("listing-id")},success:function(e){t.parents(".listing-cell").removeClass("cell-busy"),e&&e.success&&e.redirect&&window.location.replace(e.redirect)},error:function(){t.parents(".listing-cell").removeClass("cell-busy")}})}),n(".cts-listing-action-status a").on("click",function(e){e.preventDefault();var t=n(e.target);t.parents(".listing-cell").addClass("cell-busy"),n.ajax({url:"".concat(CASE27.mylisting_ajax_url,"&action=post_status&security=").concat(CASE27.ajax_nonce),type:"POST",dataType:"json",data:{listing_id:t.data("listing-id")},success:function(e){t.parents(".listing-cell").removeClass("cell-busy"),e&&e.success&&e.redirect&&window.location.replace(e.redirect)},error:function(){t.parents(".listing-cell").removeClass("cell-busy")}})}),document.querySelector(".filter-listing-type-select")),c=document.querySelector(".filter-listings-select"),o=document.querySelector(".filter-stats-select"),l=document.querySelector('input[name="search"]'),e=document.querySelector(".search-my-listings form");function s(){var e=null==a?void 0:a.value,t=null==c?void 0:c.value,n=null==o?void 0:o.value,i=[];if(e&&(e=new URL(e).searchParams.get("filter_by_type"))&&i.push("filter_by_type=".concat(e)),t){var e=new URL(t).searchParams.get("status");if(e)i.push("status=".concat(e));else{e=null==c?void 0:c.options[c.selectedIndex];if(null!=e&&e.classList.contains("claim-requests"))return void(window.location.href=t)}}n&&(e=new URL(n).searchParams.get("state_type"))&&i.push("state_type=".concat(e));var t=i.join("&"),n=null==l?void 0:l.value,e=n?"search=".concat(n):"",n=(null==a||null==(i=a.querySelector(":first-child"))?void 0:i.value)||(null==o||null==(n=o.querySelector(":first-child"))?void 0:n.value)||(null==c||null==(i=c.querySelector(":first-child"))?void 0:i.value);window.location.href=t||e?"".concat(n,"?").concat(t).concat(e?"&".concat(e):""):n}a&&(a.onchange=s),o&&(o.onchange=s),c&&(c.onchange=s),e&&e.addEventListener("submit",function(e){e.preventDefault(),s()}),n(".dashboard-filter-stats").change(function(e){e.preventDefault();var t=n(this).data("url");parseInt(e.target.value,10)&&(t+="?listing="+parseInt(e.target.value,10)),window.location.href=t}),n(".job-dashboard-action-delete").click(function(){return window.confirm(CASE27.l10n.irreversible_action)})})});
