!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var n=t();for(var s in n)("object"==typeof exports?exports:e)[s]=n[s]}}(globalThis,()=>(()=>{"use strict";var e={n:t=>{var n=t&&t.__esModule?()=>t.default:()=>t;return e.d(n,{a:n}),n},d:(t,n)=>{for(var s in n)e.o(n,s)&&!e.o(t,s)&&Object.defineProperty(t,s,{enumerable:!0,get:n[s]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{default:()=>c});const n=require("react");var s=e.n(n);const i=require("useblocks"),r=new Set(["container","id","className","style","getAuthToken","handleHtmlChanged","handleEmailChanged","handleSaveEmail","handleReadBlocks","handleSaveBlock","handleRemoveBlock","handleTranslate","handleLoad","handleDestroy","handleChunkLoaded","handleLoadImage","handleSaveImage","handleRemoveImage","handleReadImages","handleNotification","handleReadNotifications","handleMarkNotificationRead","handleMarkAllNotificationsRead"]);function o(e,t){if(Object.is(e,t))return!0;if(typeof e!=typeof t)return!1;if(!e||!t||"object"!=typeof e)return!1;if(Array.isArray(e)!==Array.isArray(t))return!1;const n=e,s=t,i=Object.keys(n),r=Object.keys(s);return i.length===r.length&&i.every(e=>Object.prototype.hasOwnProperty.call(s,e)&&o(n[e],s[e]))}function a(e){const t={};for(const[n,s]of Object.entries(e))r.has(n)||"function"==typeof s||(t[n]=s);return t}function l(e,t){return!o(a(e),a(t))}class c extends s().Component{constructor(...e){super(...e),this._instance=void 0,this._element=null,this._runId=0,this._resetChain=Promise.resolve(),this._destroyTimer=null,this._resetDebounceTimer=null,this.state={initError:null},this.setElement=e=>{if(this._element!==e)if(this._cancelScheduledDestroy(),this._element=e,e)this._enqueueReset();else if(this._runId+=1,this._instance){const e=this._instance;this._instance=void 0,this._scheduleDestroy(e)}}}_cancelScheduledDestroy(){null!==this._destroyTimer&&(clearTimeout(this._destroyTimer),this._destroyTimer=null)}_scheduleDestroy(e){this._cancelScheduledDestroy(),this._destroyTimer=setTimeout(()=>{if(this._destroyTimer=null,null===this._element)try{e.destroy()}catch(e){console.error("[EmailMaker] destroy after embed unmount failed",e)}},120)}_enqueueReset(){null!==this._resetDebounceTimer&&clearTimeout(this._resetDebounceTimer),this._resetDebounceTimer=setTimeout(()=>{this._resetDebounceTimer=null,this._runResetNow()},80)}_runResetNow(){const{props:e,_element:t}=this,n=++this._runId;if(t)this._resetChain=this._resetChain.then(async()=>{if(n!==this._runId||t!==this._element)return;const{id:s,className:r,style:o,container:a,...l}=e,c={...l,element:t},h=this._instance?await this._instance.reset(c):await(0,i.init)(c);if(n===this._runId&&t===this._element)this._instance=h,this.setState({initError:null});else if(h!==this._instance)try{h.destroy()}catch(e){console.error("[EmailMaker] discard stale init instance failed",e)}}).catch(e=>{if(n!==this._runId||t!==this._element)return;const s=e instanceof Error?e:new Error(String(e));console.error("[EmailMaker] init/reset failed",s),this.setState({initError:s})});else if(this._instance){const e=this._instance;this._instance=void 0,this._scheduleDestroy(e)}}componentDidUpdate(e){l(e,this.props)&&this._enqueueReset()}componentWillUnmount(){if(this._runId+=1,null!==this._resetDebounceTimer&&(clearTimeout(this._resetDebounceTimer),this._resetDebounceTimer=null),this._instance){const e=this._instance;this._instance=void 0,this._scheduleDestroy(e)}}render(){const{id:e,className:t,style:n,container:i}=this.props,{initError:r}=this.state,o={id:e,className:t,style:n,...i};return r?s().createElement("div",Object.assign({},o,{ref:this.setElement,style:{...o.style,display:"flex",alignItems:"center",justifyContent:"center",padding:16,color:"#b42318",fontSize:14,textAlign:"center"}}),r.message):s().createElement("div",Object.assign({},o,{ref:this.setElement}))}}return t})());