!function(t,e,a){"use strict";var i=t("#cat_protection"),n=t("#cat_passwords"),c=function(){i.toggle(t("#protected_visibility").prop("checked"))};t("#cat_visibility").on("change","input:radio",function(){c()}),i.on("change","input:checkbox",function(){t(this).parent("label").next(".cat-protection__field").toggle(t(this).prop("checked"))}),n.on("click","a.cat-password__icon",function(){var e=t(this).parents(".cat-password");if("add"===t(this).data("action")){var a=e.clone(),i=n.children(".cat-password").last().data("index")+1;a.find(".cat-password__icon--delete").length||a.children(".cat-password__icons").append('<a class="cat-password__icon cat-password__icon--delete" data-action="delete" href="#"><span class="dashicons dashicons-minus"></span></a>'),a.attr({"data-first":!1,"data-index":i}).find(".cat-password__field").attr({id:"cat_password_"+i,value:""}),a.appendTo(n)}else if("delete"===t(this).data("action")){var c=e.find("input").val();(!c||c&&confirm(ppc_params.confirm_delete))&&e.remove()}return!1}),t(function(){if(t("#addtag, #edittag").length){if(c(),"select2"in t.fn){t("#cat_user_roles").select2(),t("#cat_users").select2({minimumInputLength:3,ajax:{type:"POST",delay:250,url:PPC_Admin.ajaxUrl,data:function(t){return{action:"ppc_get_users",nonce:PPC_Admin.users_nonce,search_term:t.term}},processResults:function(t){return{results:t}}}});var i=t("#cat_users");if(i.data("users").length>0){var n={action:"ppc_preload_users",nonce:PPC_Admin.users_nonce,users:i.data("users")};t.post({url:PPC_Admin.ajaxUrl,data:n}).then(function(t){var e,a=null!==(e=i.data("users"))&&void 0!==e?e:[];Array.isArray(t)&&t.length>0&&(t.forEach((t,e)=>{var n=new Option(t.user_login,t.ID,!1,a.includes(t.ID));i.append(n).trigger("change")}),i.trigger({type:"select2:select",params:{data:t}}))})}}if(t("#addtag").length&&"MutationObserver"in a){var s=e.getElementById("the-list"),r=new MutationObserver(function(e,a){t.each(e,function(e,a){if("childList"==a.type){var i=t("#cat_protection");i.find(".cat-password__field, .cat-protection__select").val(null).change(),i.find(".cat-password").not(":eq(0)").remove(),i.find(".cat-protection__check").prop("checked",!1).change(),t("#public_visibility").prop("checked",!0).change()}})});r.observe(s,{childList:!0})}}t("#edittag").length&&t("#edittag").on("submit",function(e){t(".ppc-notice").addClass("hidden");var a,i,n=(a=t("#edittag").serializeArray(),i={},t(a).each(function(){this.name.includes("[]")?(Array.isArray(i[this.name])||(i[this.name]=[]),i[this.name].push(this.value)):i[this.name]=this.value}),i);if("protected"==n.cat_visibility){var c=!1;"cat_protection[]"in n?n["cat_protection[]"].includes("password")||(c=!0,n["cat_protection[]"].forEach(function(t){"user_role"==t&&"cat_user_roles[]"in n&&(c=!1),"user"==t&&"cat_users[]"in n&&(c=!1)})):c=!0,c&&(e.preventDefault(),t(".ppc-notice").removeClass("hidden"))}})});var s=function(t){var e,a=t.data("toggleVal"),i=t.closest(".form-table").find("."+t.data("childClass")).closest("tr");e="radio"===t.attr("type")?t.prop("checked")&&a==t.val():"checkbox"===t.attr("type")?void 0===a||1==a?t.prop("checked"):!t.prop("checked"):a==t.val(),i.toggle(e)},r=t(".form-table");r.on("change",".toggle-parent",function(){s(t(this))}),t(function(){r.find(".toggle-parent").each(function(){s(t(this))}),t.isFunction(t.fn.tipTip)&&t(".b2-help-tip").tipTip({attribute:"data-tip",fadeIn:50,fadeOut:50,delay:200,keepAlive:!0,defaultPosition:"right"})})}(jQuery,document,window);