Liferay.Loader.define("style-book-web@2.0.76/js/style-book-editor/LayoutPreview",["module","exports","require","@frontend-taglib-clay$clayui/empty-state","@frontend-taglib-clay$clayui/loading-indicator","liferay!frontend-js-react-web$classnames","liferay!frontend-js-react-web$react","./constants/layoutTypes","./contexts/LayoutContext","./contexts/StyleBookEditorContext"],(function(e,t,r){window;{Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var n=_interopRequireDefault(r("@frontend-taglib-clay$clayui/empty-state")),a=_interopRequireDefault(r("@frontend-taglib-clay$clayui/loading-indicator")),o=_interopRequireDefault(r("liferay!frontend-js-react-web$classnames")),l=function _interopRequireWildcard(e){if(e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=_getRequireWildcardCache();if(t&&t.has(e))return t.get(e);var r={},n=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var a in e)if(Object.prototype.hasOwnProperty.call(e,a)){var o=n?Object.getOwnPropertyDescriptor(e,a):null;o&&(o.get||o.set)?Object.defineProperty(r,a,o):r[a]=e[a]}r.default=e,t&&t.set(e,r);return r}(r("liferay!frontend-js-react-web$react")),i=r("./constants/layoutTypes"),u=r("./contexts/LayoutContext"),c=r("./contexts/StyleBookEditorContext");function _getRequireWildcardCache(){if("function"!=typeof WeakMap)return null;var e=new WeakMap;return _getRequireWildcardCache=function _getRequireWildcardCache(){return e},e}function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}var s=l.default.memo((function LayoutPreview(){const e=(0,c.useFrontendTokensValues)(),t=(0,u.useLoading)(),r=(0,u.usePreviewLayout)(),s=(0,u.usePreviewLayoutType)(),d=(0,u.useSetLoading)(),f=(0,l.useRef)(),[y,p]=(0,l.useState)(!1),m=(0,l.useCallback)((()=>{if(y){const t=f.current.contentDocument.documentElement;t&&(t.removeAttribute("style"),Object.values(e).forEach((({cssVariableMapping:e,value:r})=>{t.style.setProperty("--".concat(e),r)})),d(!1))}}),[e,y,d]);return(0,l.useEffect)((()=>{m()}),[m,e]),(0,l.useEffect)((()=>{f.current&&s!==i.LAYOUT_TYPES.fragmentCollection&&(f.current.style["pointer-events"]="none")}),[r,s]),l.default.createElement(l.default.Fragment,null,l.default.createElement("div",{className:"style-book-editor__page-preview"},t&&(null==r?void 0:r.url)&&l.default.createElement("div",{className:"align-items-center d-flex h-100 justify-content-center"},l.default.createElement(a.default,null)),(null==r?void 0:r.url)?l.default.createElement(l.default.Fragment,null,l.default.createElement("iframe",{className:(0,o.default)("style-book-editor__page-preview-frame",{"d-none":t}),onLoad:()=>{!function loadOverlay(e,t){if(t===i.LAYOUT_TYPES.fragmentCollection)e.current.contentDocument.body.addEventListener("click",(e=>{e.preventDefault()}),{capture:!0});else{const t={cursor:"not-allowed",height:"100%",left:0,position:"fixed",top:0,width:"100%",zIndex:1e5};if(e.current){const r=document.createElement("div");Object.keys(t).forEach((e=>{r.style[e]=t[e]})),e.current.removeAttribute("style"),e.current.contentDocument.body.append(r)}}}(f,s),p(!0),m()},ref:f,src:null==r?void 0:r.url})):l.default.createElement(n.default,{className:"h-100 justify-content-center mt-0 style-book-editor__page-preview-empty-site-message",description:Liferay.Language.get("you-cannot-preview-the-style-book-because-your-site-is-empty"),imgSrc:"".concat(themeDisplay.getPathThemeImages(),"/states/empty_state.gif")})))}));t.default=s}}));
//# sourceMappingURL=LayoutPreview.js.map