((e,t,i,o)=>{"use strict";const n=t=>{e.RightClick.t(t)},s=t=>{const i=e.RightClick;0!==t.button||i.el.contains(t.target)||t.target===i.el.getRootNode().host||i.hide()},l=t=>{e.RightClick.i(t)},c=t=>{e.RightClick.o(t)};e.RightClick={l(){const i=o.tfId("tb_builder_right_click_root"),n=i.firstElementChild;n&&(i.attachShadow({mode:n.getAttribute("shadowrootmode")}).appendChild(n.content),n.remove()),this.el=i.shadowRoot.tfId("menu");const s=new Promise((i=>{t.on("tb_toolbar_loaded",(()=>{const t=o.createDocumentFragment();t.append(e.ToolBar.getBaseCss(),e.LightBox.el.querySelector("#module_breadcrumbs_style").cloneNode(!0)),this.el.getRootNode().prepend(t),i()}),!0,!0===e.ToolBar?.isLoaded)}));Promise.all([t.loadCss(t.builder_url+"css/editor/components/right-click",null,null,this.el),s]).then((()=>{this.bind()}))},bind(){t.on("themify_builder_ready",(()=>{const _=e.Builder.get(0).el,d=this.el,r=e.isFrontend?i.top.document:i.document;localStorage.getItem("tb_right_click")?(this.hide(),_.tfOff("contextmenu",n),o.tfOff("pointerdown",s,{passive:!0}),e.isFrontend&&r.tfOff("pointerdown",s,{passive:!0}),d.tfOff(t.click,l).tfOff("pointerover",c,{passive:!0})):(_.tfOn("contextmenu",n),o.tfOn("pointerdown",s,{passive:!0}),e.isFrontend&&r.tfOn("pointerdown",s,{passive:!0}),d.tfOn(t.click,l).tfOn("pointerover",c,{passive:!0}))}),!0,e.is_builder_ready)},t(n){const s=n.target.closest("[data-cid]");if(!s||e.isPreview||e.isFrontend&&o.activeElement.isContentEditable&&e.liveStylingInstance.el?.contains(o.activeElement))return void this.hide();const l=e.Registry.get(s.dataset.cid);if(!0===l.isEmpty)return;n.stopImmediatePropagation(),n.preventDefault();const c=l.type,_=this.el,d=i.scrollY,r=_.classList,a=_.tfClass("name")[0];_.getRootNode().host.classList.remove("tf_hide"),o.body.classList.add("tb_right_click_open");let b,{pageX:m,pageY:h}=n,u=e.isFrontend||t.isRTL?parseInt(getComputedStyle(o.querySelector(":root")).getPropertyValue("--tb_toolbar_h")):0,f=_.tfClass("tb_action_breadcrumb")[0];if(isNaN(u)&&(u=0),_.className="tf_abs_t tf_hidden "+c,e.undoManager.hasUndo()||r.add("undo_disabled"),e.undoManager.hasRedo()||r.add("redo_disabled"),"column"===c?r.add("visibility_disabled"):"module"===c&&r.add("tb_module_"+l.get("mod_name")),!0===n.ctrlKey||!0===n.metaKey)s.classList.add("tb_element_clicked");else if(!s.classList.contains("tb_element_clicked")){b=e.Builder.get().el.tfClass("tb_element_clicked");for(let e=b.length-1;e>-1;--e)b[e].classList.remove("tb_element_clicked");s.classList.add("tb_element_clicked")}if(b=e.Builder.get().el.tfClass("tb_element_clicked").length,b>1?(r.add("is_multiply"),a.textContent=themifyBuilder.i18n.label.multiSelected,f.replaceChildren()):(a.textContent="module"===c?l.getName():c,l.setBreadCrumbs(_)),m<0)m=0;else{const e=o.documentElement.offsetWidth,t=_.offsetWidth;m+t>e&&(m=e-t-5)}if(h<0)h=0;else if(h<d)h=d+5;else{const i=d+t.h,o=_.offsetHeight;h+o+5>i&&(h=i-o-e.ToolBar.el.offsetHeight-5)}_.style.transform="translate("+m+"px,"+(h-u-f.offsetHeight)+"px)",r.add("tb_show_context")},hide(){this.el.getRootNode().host.classList.add("tf_hide"),this.el.style.transform="",o.body.classList.remove("tb_right_click_open")},async i(i){i.stopPropagation(),i.preventDefault();const o=i.target.closest(".tb_bread");if(o){const i=e.Registry.get(o.dataset.id);return void t.triggerEvent(i.el,"contextmenu",null,!0)}const n=i.target.closest("[data-action]");if(!n)return;const s=n.dataset.action;if("undo"===s||"redo"===s)e.undoManager.changes("undo"===s);else{const t=e.Builder.get().el.tfClass("tb_element_clicked"),i=e.Registry.get(t[0].dataset.cid);if(i)if("reset"===s){e.undoManager.start("resetStyling");for(let i=t.length-1;i>-1;--i){let o=e.Registry.get(t[i].dataset.cid);o&&await ThemifyConstructor.resetStyling(o)}e.undoManager.end("resetStyling")}else"save"===s?i.save(this.el.getBoundingClientRect()):"edit"===s||"styling"===s||"visibility"===s?i.edit(s):e.ActionBar.actions({action:s,target:this.el,shiftKey:n.classList.contains("style")})}this.hide()},o(t){if(t.stopPropagation(),t.target.classList.contains("inner_more")){const i=t.target.tfTag("ul")[0];i&&e.Utils.addViewPortClass(i)}}},e.RightClick.l()})(tb_app,Themify,window,document);