(()=>{"use strict";const e=window.wp.hooks,t=window.React,o=window.wp.compose,l=window.wp.element,n=window.wp.i18n,r=window.wp.blockEditor,s=window.wp.components;function a({attributes:e,setAttributes:o}){const{highlightColor:a,hoverHighlightColor:c}=e,[i,m]=(0,l.useState)(!1),[u,g]=(0,l.useState)(null),[h,d]=(0,l.useState)(null),b=e=>{const t=p.find(t=>t.value===e||t.color===e).value;o({highlightColor:e}),g(t)},f=e=>{const t=p.find(t=>t.value===e||t.color===e).value;o({hoverHighlightColor:e}),d(t)},[p,w]=(0,l.useState)([{color:"#3A0CA3"},{color:"#4361EE"},{color:"#4CC9F0"}]);return(0,l.useEffect)(()=>{const e=JSON.parse(localStorage.getItem("fb_global_colors"))||[],t=JSON.parse(localStorage.getItem("fb_custom_colors"))||[];let o=[];const l=e=>{e.forEach(({name:e,color:t,slug:l})=>{e&&t&&l&&o.push({name:e,color:`var(--wp--frontis--color--${l})`,value:t})})};l(e),l(t),w(o)},[]),(0,l.useEffect)(()=>{const e=()=>{if(!a)return;const e=window.getSelection();if(e&&e.rangeCount>0){const t=e.getRangeAt(0);if(0===e.toString().length)return;const o=e.anchorNode?.parentElement;if(o&&"MARK"===o.tagName)o.classList.add("fb-highlight-color"),o.style.backgroundColor=a;else{const o=document.createElement("mark");o.classList.add("fb-highlight-color"),o.style.backgroundColor=a,t.surroundContents(o),e.removeAllRanges(),e.addRange(t)}}};return document.addEventListener("mouseup",e),document.addEventListener("keyup",e),()=>{document.removeEventListener("mouseup",e),document.removeEventListener("keyup",e)}},[a]),(0,t.createElement)(r.BlockControls,{group:"block"},(0,t.createElement)(s.ToolbarGroup,null,(0,t.createElement)(s.ToolbarButton,{label:(0,n.__)("Highlight colors","frontis-blocks"),icon:()=>(0,t.createElement)("svg",{style:{fill:"#fff"},xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none"},(0,t.createElement)("path",{d:"M9 17H5C3.89543 17 3 16.1046 3 15V5C3 3.89543 3.89543 3 5 3H15C16.1046 3 17 3.89543 17 5V9M9 17V19C9 20.1046 9.89543 21 11 21H19C20.1046 21 21 20.1046 21 19V11C21 9.89543 20.1046 9 19 9H17M9 17V11C9 9.89543 9.89543 9 11 9H17",stroke:"#0B0C0E","stroke-width":"1.4"})),onClick:()=>m(!i),isPressed:i}),i&&(0,t.createElement)(s.Popover,{position:"bottom center",onClose:()=>m(!1),className:"highlight-color-popover"},(0,t.createElement)(s.TabPanel,{className:"highlight-tabs",activeClass:"active-tab",tabs:[{name:"normal",title:(0,n.__)("Normal","frontis-blocks")},{name:"hover",title:(0,n.__)("Hover","frontis-blocks")}]},e=>(0,t.createElement)("div",{style:{padding:"10px",minWidth:"220px"}},"normal"===e.name&&(0,t.createElement)(t.Fragment,null,(0,t.createElement)(r.ColorPalette,{colors:p,value:u,onChange:b})),"hover"===e.name&&(0,t.createElement)(t.Fragment,null,(0,t.createElement)(r.ColorPalette,{colors:p,value:h,onChange:f})))))))}const c=["frontis-blocks/container","frontis-blocks/fluent-form","frontis-blocks/contact-form-7","frontis-blocks/google-map"],i=(0,o.createHigherOrderComponent)(e=>o=>{const{attributes:n,setAttributes:r,name:s}=o;return(e=>!c.includes(e))(s)?(0,t.createElement)(l.Fragment,null,(0,t.createElement)(e,{...o}),(0,t.createElement)(a,{attributes:n,setAttributes:r})):(0,t.createElement)(e,{...o})},"renderFrontisHighlightColor");(0,e.addFilter)("blocks.registerBlockType","frontis-blocks/highlight-color-attributes",()=>{console.log("Call back function")}),(0,e.addFilter)("editor.BlockEdit","frontis-blocks/highlight-color",i)})();