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