(()=>{"use strict";$(function(){$.fn.serializeObject=function(){var e={},t=this.serializeArray();return $.each(t,function(){e[this.name]?(e[this.name].push||(e[this.name]=[e[this.name]]),e[this.name].push(this.value||"")):e[this.name]=this.value||""}),e};var e=$("#shortcode-list-modal"),t=$("#shortcode-modal");function o(e){a({href:e.attr("href"),key:e.data("key"),name:e.data("name"),description:e.data("description")})}function a(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},o=e.href,a=e.key,d=e.name,r=e.description,n=void 0===r?null:r,i=e.data,c=void 0===i?{}:i,s=e.update,l=void 0!==s&&s,h=e.previewImage,u=void 0===h?null:h;$(".shortcode-admin-config").html("");var m=$('.shortcode-modal button[data-bb-toggle="shortcode-add-single"]');m.text(m.data(l?"update-text":"add-text")),$(".shortcode-modal .modal-title").text(d),null!=u&&""!==u?$(".shortcode-modal .shortcode-preview-image-link").attr("href",u).show():$(".shortcode-modal .shortcode-preview-image-link").hide(),$(".shortcode-modal").modal("show");var p=t.find(".modal-content");Botble.showLoading(p),$httpClient.make().post(o,c).then(function(e){var t=e.data;$(".shortcode-data-form").trigger("reset"),$(".shortcode-input-key").val(a),$(".shortcode-admin-config").html(t.data),Botble.hideLoading(p),Botble.initResources(),Botble.initMediaIntegrate(),Botble.initFieldCollapse();var o={shortcode:a,name:d,description:n,update:l,element:t.data};document.dispatchEvent(new CustomEvent("core-shortcode-config-loaded",{detail:o}))})}$('[data-bb-toggle="shortcode-item-radio"]').on("change",function(){$('[data-bb-toggle="shortcode-use"]').prop("disabled",!1).removeClass("disabled")}),$('[data-bb-toggle="shortcode-add-single"]').on("click",function(e){e.preventDefault();var t=$(".shortcode-modal").find(".shortcode-data-form"),o=t.serializeObject(),a="";$.each(o,function(e,o){var d=t.find('*[name="'+e+'"]'),r=d.data("shortcode-attribute");r&&"content"===r||!o||(e=e.replace("[]",""),o&&"string"==typeof o&&(o=(o=(o=o.replace(/"([^"]*)"/g,"“$1”")).replace(/"/g,"“")).replace(/\r\n/g,"{{NEWLINE}}").replace(/\n/g,"{{NEWLINE}}").replace(/\r/g,"{{NEWLINE}}")),"content"!==d.data("shortcode-attribute")&&(e=e.replace("[]",""),a+=" "+e+'="'+o+'"'))});var d="",r=t.find("*[data-shortcode-attribute=content]");null!=r&&null!=r.val()&&""!==r.val()&&(d=r.val());var n=$(this).closest(".shortcode-modal").find(".shortcode-input-key").val(),i=$(".add_shortcode_btn_trigger").data("result"),c="["+n+a+"]"+d+"[/"+n+"]";if(window.EDITOR&&window.EDITOR.CKEDITOR&&$(".editor-ckeditor").length>0)window.EDITOR.CKEDITOR[i].commands.execute("shortcode",c);else if($(".editor-tinymce").length>0)c="["+n+a+"]"+function(e){if("string"!=typeof e)return e;var t={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#039;"};return e.replace(/[&<>"']/g,function(e){return t[e]})}(d)+"[/"+n+"]",tinymce.get(i).execCommand("mceInsertContent",!1,c);else{var s=new CustomEvent("core-insert-shortcode",{detail:{shortcode:c}});document.dispatchEvent(s)}$(this).closest(".modal").modal("hide")}),$(document).on("click",'[data-bb-toggle="shortcode-list-modal"]',function(){e.modal("show")}),$('[data-bb-toggle="shortcode-select"]').on("dblclick",function(e){o($(e.currentTarget))}),$('[data-bb-toggle="shortcode-use"]').on("click",function(){o(e.find(".shortcode-item-input:checked").closest(".shortcode-item-wrapper")),$('[data-bb-toggle="shortcode-item-radio"]').prop("checked",!1),$('[data-bb-toggle="shortcode-use"]').prop("disabled",!0).addClass("disabled")}),$('[data-bb-toggle="shortcode-button-use"]').on("click",function(e){o($(e.currentTarget).closest(".shortcode-item-wrapper"))}),t.on("show.bs.modal",function(){e.modal("hide"),$('[data-bb-toggle="shortcode-item-radio"]').prop("checked",!1),$('[data-bb-toggle="shortcode-use"]').prop("disabled",!0).addClass("disabled")}),$(document).on("ckeditor-bb-shortcode-callback",function(e){var t=e.detail;a({key:t.shortcode,href:t.options.url,previewImage:""})}),$(document).on("ckeditor-bb-shortcode-edit",function(e){var t=e.detail,o=t.shortcode,d=t.name,r=$('[data-bb-toggle="shortcode-select"][data-key="'.concat(d,'"]')),n=r.length>0?r.data("description"):"";a({key:d,href:r.data("url"),data:{key:d,code:o},name:r.data("name"),description:n,previewImage:"",update:!0})}),$(".shortcode-list-modal").on("keyup",'input[type="search"]',function(e){e.preventDefault();var t=$(this).val().toLowerCase();$(".shortcode-item-wrapper").each(function(e,o){var a=$(o),d=a.data("name").toLowerCase(),r=a.data("description").toLowerCase();d.includes(t)||r.includes(t)?a.parent().show():a.parent().hide()}),0===$(".shortcode-item-wrapper:visible").length?$(".shortcode-empty").show():$(".shortcode-empty").hide()}).on("click",'[data-bb-toggle="shortcode-clear-search"]',function(e){e.preventDefault(),$(this).closest(".shortcode-list-modal").find('input[type="search"]').val("").trigger("keyup").trigger("focus")})})})();