!function(){"use strict";var e={n:function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,{a:n}),n},d:function(t,n){for(var o in n)e.o(n,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:n[o]})},o:function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r:function(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,{App:function(){return d}});var n=window.React,o=window.wp.apiFetch,a=e.n(o);const i="/elementor/v1/site-builder/deploy-design-system";async function r(e,t,n,o){const i=await a()({path:"/wp/v2/menus",method:"POST",data:{name:e,auto_add:!1,locations:[o]}}),r=t.map((e,t)=>{const o=n[e.pageId];return o?a()({path:"/wp/v2/menu-items",method:"POST",data:{title:e.title,object_id:o,menus:i.id,object:"page",type:"post_type",status:"publish",menu_order:t+1,parent:0}}):Promise.resolve()});await Promise.all(r)}function s(e){return"header"===e?"header":"footer"===e?"footer":"single"}async function l(e){const t=[];try{await async function(e){await a()({path:"/wp/v2/settings",method:"POST",data:{title:e.title,description:e.tagline}})}(e.siteMeta)}catch(e){t.push(`site_metadata: ${e.message}`)}if(e.logo)try{await async function(e){const t=await fetch(e.url);if(!t.ok)throw new Error(`Failed to download logo: ${t.status}`);const n=await t.blob(),o=await a()({path:"/wp/v2/media",method:"POST",body:n,headers:{"Content-Disposition":`attachment; filename="${e.filename}"`,"Content-Type":n.type||"image/png"}});await a()({path:"/wp/v2/settings",method:"POST",data:{site_logo:o.id}})}(e.logo)}catch(e){t.push(`logo: ${e.message}`)}try{await async function(e){const t=await a()({path:"/elementor/v1/settings/elementor_active_kit"}),n=t?.data?.value;if(!n)throw new Error("Could not resolve active kit ID");await a()({path:`/wp/v2/elementor_library/${n}`,method:"POST",data:{meta:{_elementor_page_settings:e}}})}(e.kitSettings)}catch(e){t.push(`kit_settings: ${e.message}`)}if(e.globalVariables)try{await async function(e){await a()({path:i,method:"POST",data:{globalVariables:e}})}(e.globalVariables)}catch(e){t.push(`global_variables: ${e.message}`)}if(e.globalClasses)try{await async function(e){await a()({path:i,method:"POST",data:{globalClasses:e}})}(e.globalClasses)}catch(e){t.push(`global_classes: ${e.message}`)}let n={};try{n=await async function(e){const t={};for(const n of e){const e=await a()({path:"/wp/v2/pages",method:"POST",data:{title:n.title,status:"publish",meta:{_elementor_edit_mode:"builder",_elementor_template_type:"wp-page",_elementor_data:JSON.stringify(n.content)}}});t[n.id]=e.id}return t}(e.pages)}catch(e){t.push(`pages: ${e.message}`)}const o=n.home;if(o)try{await async function(e){await a()({path:"/wp/v2/settings",method:"POST",data:{page_on_front:e,show_on_front:"page"}})}(o)}catch(e){t.push(`home_page: ${e.message}`)}const l=[];if(e.header&&l.push({key:"header",part:e.header}),e.footer&&l.push({key:"footer",part:e.footer}),e.error404&&l.push({key:"error404",part:e.error404}),e.singlePost&&l.push({key:"singlePost",part:e.singlePost}),l.length)try{await async function(e){const t=await async function(){try{const e=await a()({path:"/wp/v2/elementor_library",method:"OPTIONS"});return e?.schema?.properties?.meta?.properties?._elementor_template_type?.enum||[]}catch{return[]}}(),n=e.filter(({part:e})=>t.includes(e.type));if(!n.length)return;const o={};for(const{key:e,part:t}of n){const n=await a()({path:"/wp/v2/elementor_library",method:"POST",data:{title:t.title,status:"publish",meta:{_elementor_edit_mode:"builder",_elementor_template_type:t.type,_elementor_data:JSON.stringify(t.content),_elementor_conditions:t.themeBuilderCondition||"include/general"}}});o[e]=n.id}const i={};for(const{key:e,part:t}of n){const n=o[e];if(!n)continue;const a=t.themeBuilderCondition||"include/general",r=s(t.type);i[r]||(i[r]={}),i[r][n]=[a]}await a()({path:"/elementor/v1/settings/elementor_pro_theme_builder_conditions",method:"POST",data:{value:i}})}(l)}catch(e){t.push(`theme_parts: ${e.message}`)}if(e.samplePosts?.length)try{await async function(e){for(const t of e)await a()({path:"/wp/v2/posts",method:"POST",data:{title:t.title,content:t.content,status:"publish"}})}(e.samplePosts)}catch(e){t.push(`sample_posts: ${e.message}`)}try{await async function(e,t){e.header?.length&&await r(`Header-${Date.now()}`,e.header,t,"primary"),e.footer?.length&&await r(`Footer-${Date.now()}`,e.footer,t,"footer")}(e.menus,n)}catch(e){t.push(`menus: ${e.message}`)}return{status:t.length?"error":"success",homeUrl:window.location.origin,homePageId:n.home||0,...t.length?{errors:t,error:t[0]}:{}}}const c={position:"fixed",top:0,left:0,width:"100vw",height:"100vh",border:"none",zIndex:1e4};function p(){return window.elementorAppConfig?.["site-builder"]}function d(){const e=(0,n.useRef)(null),t=(0,n.useMemo)(()=>p()?.iframeUrl??"",[]),o=(0,n.useMemo)(()=>{try{return new URL(t).origin}catch{return""}},[t]),a=(0,n.useCallback)(async t=>{if(!o)return;if(t.origin!==o)return;if(t.source!==e.current?.contentWindow)return;const{type:n}=t.data??{};if("get/referrer/info"===n){const n=e.current;return void(n?.contentWindow&&function(e,t,n){const o=p();e.contentWindow?.postMessage({type:"referrer/info",instanceId:t.data?.payload?.instanceId??"",info:{connectAuth:o?.connectAuth,exitTo:o?.exitTo,page:{url:window.location.href,elementorAiCurrentContext:p()?.elementorAiCurrentContext||{}},user:{isAdmin:o?.isAdmin??!1}}},n)}(n,t,o))}if("site-planner/deploy-website"===n&&await async function(e,t){const n=t.origin||"*";try{const o=await l(t.data.payload);e?.contentWindow?.postMessage({type:"site-planner/deploy-website/result",payload:o},n),"success"===o.status&&o.homePageId&&(window.location.href=`/wp-admin/post.php?post=${o.homePageId}&action=elementor`)}catch(t){e?.contentWindow?.postMessage({type:"site-planner/deploy-website/result",payload:{status:"error",error:t instanceof Error?t.message:"Deploy failed"}},n)}}(e.current,t),"element-selector/close"===n){const e=p()?.exitTo;window.top&&e&&"string"==typeof e&&(window.top.location.href=e)}},[o]);return(0,n.useEffect)(()=>(window.addEventListener("message",a),()=>window.removeEventListener("message",a)),[a]),(0,n.useEffect)(()=>{const e=window.wpApiSettings,t=e?.nonce||"";t&&fetch(`${e?.root||"/wp-json/"}elementor/v1/site-builder/snapshot`,{method:"POST",credentials:"include",headers:{"Content-Type":"application/json","X-WP-Nonce":t},body:JSON.stringify({value:{}})}).catch(()=>{})},[]),n.createElement("iframe",{ref:e,src:t,style:c,title:"Website Planner",allow:"clipboard-read; clipboard-write"})}(window.elementorV2=window.elementorV2||{}).siteBuilder=t}(),window.elementorV2.siteBuilder?.init?.();