"use strict";window.XdUtils=window.XdUtils||{extend:function(e,t){var n,i=t||{};for(n in e)e.hasOwnProperty(n)&&(i[n]=e[n]);return i}},window.ekitXdLocalStorage=window.ekitXdLocalStorage||function(){var e="cross-domain-local-message",t={iframeId:"cross-domain-iframe-id",iframeUrl:undefined,initCallback:function(){}},n=-1,i=null,o={},a=!1,r=!0;function s(n){var i;try{i=JSON.parse(n.data)}catch(a){}i&&i.namespace===e&&("iframe-ready"===i.id?(r=!0,t.initCallback()):function(e){o[e.id]&&(o[e.id](e),delete o[e.id])}(i))}function l(t,a,r,s){n++,o[n]=s;var l={namespace:e,id:n,action:t,key:a,value:r};null!==i&&i.contentWindow.postMessage(JSON.stringify(l),"*")}function c(e){t=XdUtils.extend(e,t);var n=document.createElement("div");window.addEventListener?window.addEventListener("message",s,!1):window.attachEvent("onmessage",s),n.innerHTML='<iframe id="'+t.iframeId+'" src="'+t.iframeUrl+'" style="display: none;"></iframe>',document.body.appendChild(n),i=document.getElementById(t.iframeId)}function d(){return!!a&&!!r}function m(){return"complete"===document.readyState}return{init:function(e){if(!e.iframeUrl)throw"You must specify iframeUrl [CP]";a||(a=!0,m()?c(e):document.addEventListener?document.addEventListener("readystatechange",(function(){m()&&c(e)})):document.attachEvent("readystatechange",(function(){m()&&c(e)})))},setItem:function(e,t,n){d()&&l("set",e,t,n)},getItem:function(e,t){d()&&l("get",e,null,t)},removeItem:function(e,t){d()&&l("remove",e,null,t)},key:function(e,t){d()&&l("key",e,null,t)},getSize:function(e){d()&&l("size",null,null,e)},getLength:function(e){d()&&l("length",null,null,e)},clear:function(e){d()&&l("clear",null,null,e)},wasInit:function(){return a}}}(),function(e){ekitXdLocalStorage.init({iframeId:"ekit-xd-iframe",iframeUrl:"https://api.wpmet.com/public/copy-paste/",initCallback:function(){}});var t={elementTypes:["widget","column","section","container"],storageKey:ekit_cp_xd.storage_key,lastCopiedJson:"",lastPastedModel:{},sameServer:!1,widget:null,container:null,option:{},msg:ekit_cp_xd.message};function n(){elementor.notifications.showToast({message:elementor.translate(t.msg.paste)})}t.elementTypes.forEach((function(i,o){let a=t.elementTypes[o];elementor.hooks.addFilter("elements/"+a+"/contextMenuGroups",(function(i,o){return i.push({name:"ekit_"+a,actions:[{name:"ekit_copy",title:"Ekit Copy",callback:function(){var e={};e.elementType="widget"===a?o.model.get("widgetType"):null,e.elementCode=o.model.toJSON(),navigator.clipboard.writeText(JSON.stringify(e)).then((function(){console.log("Copied to clipboard successfully!"),elementor.notifications.showToast({message:elementor.translate(t.msg.copy)})}))["catch"]((function(e){console.error("Could not copy text: ",e),elementor.notifications.showToast({message:elementor.translate(t.msg.error)})}))}},{name:"ekit_paste",title:"Ekit Paste",callback:function(){navigator.clipboard.readText().then((function(i){!function(i,o){if(null===i||""===i||Array.isArray(i)&&0===i.length)return elementor.notifications.showToast({message:elementor.translate(t.msg.empty_copy)}),!1;let a=o.model.get("elType"),r=i.elementCode.elType,s=i.elementCode;if(t.widget={elType:r,settings:s.settings},"section"===r||"container"===r)t.widget.elements=s.elements,t.container=elementor.getPreviewContainer();else if("column"===r)//!sameElement ? changeElementID(elementCode.elements) : elementCode.elements;
switch(t.widget.elements=s.elements,a){case"widget":t.container=o.getContainer().parent.parent;break;case"column":t.container=o.getContainer().parent;break;case"section":case"container":t.container=o.getContainer();break;default:t.container=elementor.getPreviewContainer()}else if("widget"===r)switch(t.widget.widgetType=i.elementType,a){case"widget":t.container=o.getContainer().parent,t.option.at=o.getOption("_index")+1;break;case"column":case"container":t.container=o.getContainer();break;case"section":t.container=o.children.findByIndex(0).getContainer();break;default:t.container=elementor.getPreviewContainer()}!function(i){var o=JSON.stringify(i),a=/\.(gif|jpg|jpeg|svg|png|tiff|bmp|pdf)/gi.test(o);if(e.isEmptyObject(t.lastPastedModel)||o!==t.lastCopiedJson)if(a&&!t.sameServer){let e=elementor.notifications.getToast(),i=e.getSettings();"hide"in i&&(i=Object.assign(i.hide,{auto:!1}),e.setSettings(i)),elementor.notifications.showToast({message:elementor.translate(t.msg.import_wait)}),elementorCommon.ajax.addRequest("ekit_copy_paste",{data:{type:"single",template:o},success:function(a){var r=a;r.hasOwnProperty("data")&&(r=r.data),"hide"in i?(i=Object.assign(i.hide,{auto:!0}),e.setSettings(i)):"auto"in i&&(i.auto=!0,e.setSettings(i)),t.widget.elType=r.elType,t.widget.settings=r.settings,"widget"===r.elType?t.widget.widgetType=r.widgetType:t.widget.elements=r.elements,$e.run("document/elements/create",{model:t.widget,container:t.container,options:t.option}),n(),t.lastPastedModel=t.widget,t.lastCopiedJson=o},error:function(e){elementor.notifications.showToast({message:elementor.translate(t.msg.error)})}})}else $e.run("document/elements/create",{model:t.widget,container:t.container,options:t.option}),n();else t.option.clone=!0,$e.run("document/elements/create",{model:t.lastPastedModel,container:t.container,options:t.option}),n()}(s)}(JSON.parse(i),o)}))["catch"]((function(e){console.error("Failed to read clipboard contents: ",e)}))}}]}),i}))}))}(jQuery);