"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const t=require("react/jsx-runtime"),f=require("react"),o=require("semantic-ui-react"),G=require("@devgateway/wp-react-lib"),N=require("./dom-to-image.js"),v=require("file-saver"),W=require("react-redux"),z=f.forwardRef((i,r)=>t.jsx("div",{ref:r,children:i.children})),H=i=>{const r=f.useRef();let{childContent:h,"data-height":K,"data-button-label":R,"data-png-label":k,"data-jpg-label":L,"data-jpg-text":q,"data-png-text":T,"data-check-png":P="true","data-check-jpg":y="true","data-title":S,"data-default-format":x="PNG","data-use-title":w="false","data-style":U="heavy","data-section-title":J="","data-download-tooltip":A="","data-include-source-url":F="false","data-source-urlmargin-left":I=70,"data-source-urlmargin-top":$=10,"data-source-urlfont-size":D=18,parent:Q,editing:s,component:V,unique:X,pageModuleProps:c}=i;const[p,g]=f.useState(x),d=P=="true"||P===!0,u=y=="true"||y===!0;f.useEffect(()=>{g(x)},[x]);const C=n=>{g(n.target.value)};function E(n){const a=n.attributes,b=[];if(a)for(let l=0;l<a.length;l++)b.push(a[l].nodeName);const e=b.filter(l=>l.startsWith("data-"));return e.length>0&&e.forEach(l=>{n.setAttribute(l,"")}),n.classList?!n.classList.contains("ignore"):!0}const m={filter:E,bgcolor:"#FFF"},M=n=>{N.domtoimage.cloneNode(r.current).then(function(a){if([...a.getElementsByTagName("input")].forEach(e=>e.remove()),[...a.querySelectorAll(".question.circle.icon")].forEach(e=>e.remove()),F==="true"){const e=document.createElement("div");e.style.marginLeft=I+"px",e.style.marginTop=$+"px",e.style.fontSize=D+"px",e.style.fontFamily="Roboto, sans-serif",e.style.fontWeight="400",e.style.color="#66676d",e.style.opacity="0.75",e.innerHTML=window.location.href,e.style.maxWidth="90%",e.style.wordWrap="break-word",e.style.overflowWrap="break-word",a.appendChild(e)}m.height=r.current.scrollHeight+90,m.width=r.current.scrollWidth+30,a.style.padding="20px",n==="PNG"&&N.domtoimage.toPng(a,m).then(function(e){v.saveAs(e,k)}),n==="JPG"&&N.domtoimage.toJpeg(a,m).then(function(e){v.saveAs(e,L)})})},j=n=>{s?alert("Not allowed when editing please preview page"):M(n)};return t.jsx(o.Container,{className:`viz download ${U} ${w?"has-title":""}
        ${d||u?"has-formats":""}
        ${s||c!=null&&c.editing?"editing":""}
        ${d&&u?"multi-format":""}
        ${d&&!u||!d&&u?"single-format":""}`,fluid:!0,children:t.jsxs(z,{ref:r,children:[t.jsxs(o.Grid,{stackable:!0,reversed:"mobile",className:"download-header",children:[!s&&w==="true"&&t.jsx(o.Grid.Column,{width:12,children:t.jsx(G.PostContent,{parentUnique:i.unique,post:{content:{rendered:decodeURIComponent(J)}}})}),t.jsx(o.Grid.Column,{className:s?"editing ignore":"ignore",width:s||w!=="true"?16:4,textAlign:"right",children:t.jsxs("div",{className:"wrapper",children:[t.jsxs(o.Button,{className:"download",onClick:()=>j(p),children:[R," ",p==="PNG"?"PNG":"JPG"]}),t.jsx(o.Dropdown,{className:"download","data-tooltip":decodeURIComponent(A),trigger:u&&d?t.jsx(o.Icon,{name:"download",className:"download-icon"}):null,children:t.jsxs(o.Dropdown.Menu,{children:[S,d===!0&&t.jsxs(o.Dropdown.Item,{onClick:()=>{g("PNG"),j("PNG")},children:[t.jsx("input",{type:"radio",value:"PNG",checked:p==="PNG",onChange:C}),t.jsx("label",{children:T})]}),u===!0&&t.jsxs(o.Dropdown.Item,{onClick:()=>{g("JPG"),j("JPG")},children:[t.jsx("input",{type:"radio",value:"JPG",checked:p==="JPG",onChange:C}),t.jsx("label",{children:q})]})]})})]})})]}),!s&&t.jsx(o.Container,{fluid:!0,className:`download area ${s||c!=null&&c.editing?"editing":""}`,children:t.jsx(G.PostContent,{parentUnique:i.unique,post:{content:{rendered:h}}})})]})})},_=i=>{const r=i.getIn(["data","pageModuleProps"]),h={};return r&&(h.pageModuleProps=r),h},B={},O=W.connect(_,B)(H);exports.default=O;
