import{j as e}from"./client-By3tlFYA.js";import{r as t}from"./index-TEHZzOO_.js";import{a5 as g,u as j,a8 as y}from"./useSelectableClick-BxxGQli3.js";import{a as C}from"./api-C8Dh2R2O.js";import{J as b}from"./status_quoted-B4XDAzAW.js";import{c as w}from"./index-DkCxcZFY.js";import{S as _}from"./content_copy-DVR8BuWm.js";import{u as k}from"./useTimeout-BP4Egvtt.js";import{M as l}from"./message-CVkQtbZv.js";import"./relative_timestamp-BOUL06oe.js";import"./ready-DpOgoWSg.js";import"./short_number-C9zm8Jg6.js";import"./numbers-BLyy7tyF.js";import"./index-DUY7J2K7.js";import"./skeleton-CwYXpOUk.js";import"./load_locale-CF-OtRm0.js";import"./index-DiPYjm3h.js";const M=({value:o})=>{const a=t.useRef(null),[i,s]=t.useState(!1),[u,n]=t.useState(!1),[c]=k(),m=t.useCallback(()=>{s(!1),a.current&&(a.current.focus(),a.current.select(),a.current.setSelectionRange(0,o.length))},[s,o]),p=t.useCallback(d=>{var h;d.stopPropagation(),navigator.clipboard.writeText(o),(h=a.current)==null||h.blur(),s(!0),c(()=>{s(!1)},700)},[s,c,o]),f=t.useCallback(d=>{d.key===" "&&(navigator.clipboard.writeText(o),s(!0),c(()=>{s(!1)},700))},[s,c,o]),r=t.useCallback(()=>{n(!0)},[n]),x=t.useCallback(()=>{n(!1)},[n]);return e.jsxs("div",{className:w("copy-paste-text",{copied:i,focused:u}),tabIndex:0,role:"button",onClick:m,onKeyUp:f,children:[e.jsx("textarea",{readOnly:!0,value:o,ref:a,onClick:m,onFocus:r,onBlur:x}),e.jsxs("button",{className:"button",onClick:p,children:[e.jsx(g,{id:"copy",icon:_})," ",i?e.jsx(l,{id:"copypaste.copied",defaultMessage:"Copied"}):e.jsx(l,{id:"copypaste.copy_to_clipboard",defaultMessage:"Copy to clipboard"})]})]})},W=({id:o,onClose:a})=>{var m;const i=t.useRef(null),s=t.useRef(),[u,n]=t.useState(null),c=j();return t.useEffect(()=>{C().get("/api/web/embeds/".concat(o)).then(p=>{var x,d;const f=p.data;n(f);const r=(d=(x=i.current)==null?void 0:x.contentWindow)==null?void 0:d.document;return r&&(r.open(),r.write(f.html),r.close(),r.body.style.margin="0px",s.current=setInterval(()=>window.requestAnimationFrame(()=>{i.current&&(i.current.width="".concat(r.body.scrollWidth,"px"),i.current.height="".concat(r.body.scrollHeight,"px"))}),100)),""}).catch(p=>{c(y(p))})},[c,o,n]),t.useEffect(()=>()=>{s.current&&clearInterval(s.current)},[]),e.jsxs("div",{className:"modal-root__modal dialog-modal",children:[e.jsxs("div",{className:"dialog-modal__header",children:[e.jsx(b,{onClick:a,children:e.jsx(l,{id:"report.close",defaultMessage:"Done"})}),e.jsx("span",{className:"dialog-modal__header__title",children:e.jsx(l,{id:"status.embed",defaultMessage:"Get embed code"})}),e.jsx(b,{secondary:!0,onClick:a,children:e.jsx(l,{id:"confirmation_modal.cancel",defaultMessage:"Cancel"})})]}),e.jsx("div",{className:"dialog-modal__content",children:e.jsxs("div",{className:"dialog-modal__content__form",children:[e.jsx(l,{id:"embed.instructions",defaultMessage:"Embed this status on your website by copying the code below."}),e.jsx(M,{value:(m=u==null?void 0:u.html)!=null?m:""}),e.jsx(l,{id:"embed.preview",defaultMessage:"Here is what it will look like:"}),e.jsx("iframe",{frameBorder:"0",ref:i,sandbox:"allow-scripts allow-same-origin",title:"Preview"})]})})]})};export{W as default};
//# sourceMappingURL=embed_modal-CHSfeOry.js.map
