!function(){"use strict";var e={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,{init:function(){return se}});var n=window.elementorV2.editor,o=window.elementorV2.editorDocuments,a=window.elementorV2.editorElementsPanel,r=window.elementorV2.editorStylesRepository,l=window.elementorV2.editorV1Adapters,i=window.elementorV2.store,s=window.wp.i18n,c=window.React,m=window.elementorV2.editorUi,d=window.elementorV2.icons,p=window.elementorV2.ui,u=window.elementorV2.utils;const h=(0,c.createContext)(void 0),g=({children:e,localStorageKey:t})=>{const{debouncedValue:n,handleChange:o,inputValue:a}=(0,u.useSearchState)({localStorageKey:t});return c.createElement(h.Provider,{value:{handleChange:o,clearSearch:()=>{o("")},searchValue:n,inputValue:a}},e)},y=()=>{const e=(0,c.useContext)(h);if(!e)throw new Error("useSearch must be used within a SearchProvider");return e},f=()=>{const{inputValue:e,handleChange:t}=y();return c.createElement(p.Stack,{direction:"row",gap:.5,sx:{width:"100%",px:2,py:1.5}},c.createElement(p.Box,{sx:{flexGrow:1}},c.createElement(p.TextField,{role:"search",fullWidth:!0,size:"tiny",value:e,placeholder:(0,s.__)("Search","elementor"),onChange:e=>t(e.target.value),InputProps:{startAdornment:c.createElement(p.InputAdornment,{position:"start"},c.createElement(d.SearchIcon,{fontSize:"tiny"}))}})))};var _=window.elementorV2.httpClient;const w="elementor/v1/components",E=e=>({action:"get_document_config",unique_id:`document-config-${e}`,data:{id:e}}),S={get:()=>(0,_.httpService)().get(`${w}`).then(e=>e.data.data),create:e=>(0,_.httpService)().post(`${w}`,e).then(e=>e.data.data),getComponentConfig:e=>l.ajax.load(E(e)),invalidateComponentConfigCache:e=>l.ajax.invalidateCache(E(e))},v=(0,i.__createAsyncThunk)("components/create",async e=>({...await S.create(e),name:e.name})),x=(0,i.__createAsyncThunk)("components/load",async()=>await S.get()),C="components",b=(0,i.__createSlice)({name:C,initialState:{data:[],loadStatus:"idle",createStatus:"idle",styles:{}},reducers:{add:(e,{payload:t})=>{e.data={...t}},load:(e,{payload:t})=>{e.data=t},removeStyles(e,{payload:t}){const{[t.id]:n,...o}=e.styles;e.styles=o},addStyles:(e,{payload:t})=>{e.styles={...e.styles,...t}}},extraReducers:e=>{e.addCase(x.fulfilled,(e,{payload:t})=>{e.data=t,e.loadStatus="idle"}),e.addCase(x.pending,e=>{e.loadStatus="pending"}),e.addCase(x.rejected,e=>{e.loadStatus="error"}),e.addCase(v.fulfilled,(e,{payload:t,meta:n})=>{e.createStatus="idle",e.data.push({id:t.component_id,name:n.arg.name})}),e.addCase(v.pending,e=>{e.createStatus="pending"}),e.addCase(v.rejected,e=>{e.createStatus="error"})}}),V=e=>e[C].loadStatus,T=e=>e[C].createStatus,P=(0,i.__createSelector)(e=>e[C].data,e=>e),k=(0,i.__createSelector)(V,e=>"pending"===e),I=((0,i.__createSelector)(V,e=>"error"===e),(0,i.__createSelector)(T,e=>"pending"===e)),j=(0,i.__createSelector)(T,e=>"error"===e),L=e=>e[C].styles??{},O=(0,i.__createSelector)(e=>e[C].styles??{},e=>Object.values(e).flat()),z=()=>({components:(0,i.__useSelector)(P),isLoading:(0,i.__useSelector)(k)});var N=window.elementorV2.editorCanvas,D=window.elementorV2.editorElements;var B=window.elementorV2.editorProps;const F=async(e,t)=>{(0,D.replaceElement)({currentElement:e,newElement:A(t),withHistory:!1})},A=e=>({elType:"widget",widgetType:"e-component",settings:{component_id:B.numberPropTypeUtil.create(e.id)},editor_settings:{title:e.name}}),M=({component:e})=>{const t=A({id:e.id,name:e.name});return c.createElement(p.ListItemButton,{draggable:!0,onDragStart:()=>(0,N.startDragElementFromPanel)(t),onDragEnd:N.endDragElementFromPanel,shape:"rounded",sx:{border:"solid 1px",borderColor:"divider",py:.5,px:1}},c.createElement(p.Box,{sx:{display:"flex",width:"100%",alignItems:"center",gap:1},onClick:()=>{W(t)}},c.createElement(p.ListItemIcon,{size:"tiny"},c.createElement(d.ComponentsIcon,{fontSize:"tiny"})),c.createElement(p.ListItemText,{primary:c.createElement(p.Typography,{variant:"caption",sx:{color:"text.primary"}},e.name)})))},W=e=>{const{container:t,options:n}=(()=>{const e=(0,D.getCurrentDocumentContainer)(),t=function(){const e=(0,D.getSelectedElements)();if(1===e.length)return(0,D.getContainer)(e[0].id)}();let n,o;if(t)switch(t.model.get("elType")){case"widget":{n=t?.parent;const e=t.view?._index??-1;e>-1&&(o={at:e+1});break}case"section":n=t?.children?.[0];break;default:n=t}return{container:n??e,options:o}})();if(!t)throw new Error("Can't find container to drop new component instance at");(0,D.dropElement)({containerId:t.id,model:e,options:{...n,useHistory:!1,scrollIntoView:!0}})},$=Array.from({length:6},(e,t)=>t),R=()=>c.createElement(p.Stack,{"aria-label":"Loading components",gap:1,sx:{pointerEvents:"none",position:"relative",maxHeight:"300px",overflow:"hidden","&:after":{position:"absolute",top:0,content:'""',left:0,width:"100%",height:"300px",background:"linear-gradient(to top, white, transparent)",pointerEvents:"none"}}},$.map(e=>c.createElement(p.ListItemButton,{key:e,sx:{border:"solid 1px",borderColor:"divider",py:.5,px:1},shape:"rounded"},c.createElement(p.Box,{display:"flex",gap:1,width:"100%"},c.createElement(p.Skeleton,{variant:"text",width:"24px",height:"36px"}),c.createElement(p.Skeleton,{variant:"text",width:"100%",height:"36px"})))));function G(){const{components:e,isLoading:t,searchValue:n}=K();return t?c.createElement(R,null):e&&0!==e.length?c.createElement(p.List,{sx:{display:"flex",flexDirection:"column",gap:1,px:2}},e.map(e=>c.createElement(M,{key:e.id,component:e}))):n.length>0?c.createElement(U,null):c.createElement(H,null)}const H=()=>c.createElement(p.Stack,{alignItems:"center",justifyContent:"center",height:"100%",sx:{px:2.5,pt:10},gap:1.75,overflow:"hidden"},c.createElement(p.Icon,{fontSize:"large"},c.createElement(d.EyeIcon,{fontSize:"large"})),c.createElement(p.Typography,{align:"center",variant:"subtitle2",color:"text.secondary",fontWeight:"bold"},(0,s.__)("Text that explains that there are no Components yet.","elementor")),c.createElement(p.Typography,{variant:"caption",align:"center",color:"text.secondary"},(0,s.__)("Once you have Components, this is where you can manage them—rearrange, duplicate, rename and delete irrelevant classes.","elementor")),c.createElement(p.Divider,{sx:{width:"100%"},color:"text.secondary"}),c.createElement(p.Typography,{align:"left",variant:"caption",color:"text.secondary"},(0,s.__)("To create a component, first design it, then choose one of three options:","elementor")),c.createElement(p.Typography,{align:"left",variant:"caption",color:"text.secondary",sx:{display:"flex",flexDirection:"column"}},c.createElement("span",null,(0,s.__)("1. Right-click and select Create Component","elementor")),c.createElement("span",null,(0,s.__)("2. Use the component icon in the Structure panel","elementor")),c.createElement("span",null,(0,s.__)("3. Use the component icon in the Edit panel header","elementor")))),U=()=>{const{searchValue:e,clearSearch:t}=y();return c.createElement(p.Stack,{color:"text.secondary",pt:5,alignItems:"center",gap:1,overflow:"hidden",justifySelf:"center"},c.createElement(d.ComponentsIcon,null),c.createElement(p.Box,{sx:{width:"100%"}},c.createElement(p.Typography,{align:"center",variant:"subtitle2",color:"inherit"},(0,s.__)("Sorry, nothing matched","elementor")),e&&c.createElement(p.Typography,{variant:"subtitle2",color:"inherit",sx:{display:"flex",width:"100%",justifyContent:"center"}},c.createElement("span",null,"“"),c.createElement("span",{style:{maxWidth:"80%",overflow:"hidden",textOverflow:"ellipsis"}},e),c.createElement("span",null,"”."))),c.createElement(p.Typography,{align:"center",variant:"caption",color:"inherit"},(0,s.__)("Try something else.","elementor")),c.createElement(p.Typography,{align:"center",variant:"caption",color:"inherit"},c.createElement(p.Link,{color:"secondary",variant:"caption",component:"button",onClick:t},(0,s.__)("Clear & try again","elementor"))))},K=()=>{const{components:e,isLoading:t}=z(),{searchValue:n}=y();return{components:e.filter(e=>e.name.toLowerCase().includes(n.toLowerCase())),isLoading:t,searchValue:n}},q=()=>c.createElement(m.ThemeProvider,null,c.createElement(g,{localStorageKey:"elementor-components-search"},c.createElement(f,null),c.createElement(G,null))),J=()=>{const e=(0,i.__useDispatch)();return{createComponent:async t=>(await e(v(t))).payload,isPending:(0,i.__useSelector)(I),isError:(0,i.__useSelector)(j)}},Q=e=>{const[t,n]=(0,c.useState)(e),[o,a]=(0,c.useState)({}),r=(0,c.useMemo)(()=>!Object.values(o).some(e=>e),[o]);return{values:t,errors:o,isValid:r,handleChange:(e,o,r)=>{const l={...t,[o]:e.target.value};n(l);const{success:i,errors:s}=X(l,r);a(i?{}:s)},validateForm:e=>{const{success:n,errors:o,parsedValues:r}=X(t,e);return n?(a({}),{success:n,parsedValues:r}):(a(o),{success:n})}}},X=(e,t)=>{const n=t.safeParse(e);if(n.success)return{success:!0,parsedValues:n.data};const o={};return Object.entries(n.error.formErrors.fieldErrors).forEach(([e,t])=>{o[e]=t[0]}),{success:!1,errors:o}};var Y=window.elementorV2.schema;const Z=e=>Y.z.object({componentName:Y.z.string().trim().max(50,(0,s.__)("Component name is too long. Please keep it under 50 characters.","elementor")).refine(t=>!e.includes(t),{message:(0,s.__)("Component name already exists","elementor")})});function ee(){const[e,t]=(0,c.useState)(null),[n,o]=(0,c.useState)(),[a,r]=(0,c.useState)(null),{createComponent:l,isPending:i}=J();(0,c.useEffect)(()=>{const e="elementor/editor/open-save-as-component-form",n=e=>{t({element:e.detail.element,elementLabel:(0,D.getElementLabel)(e.detail.element.id)}),o(e.detail.anchorPosition)};return window.addEventListener(e,n),()=>{window.removeEventListener(e,n)}},[]);const d=()=>{t(null),o(void 0)};return c.createElement(m.ThemeProvider,null,c.createElement(p.Popover,{open:null!==e,onClose:d,anchorReference:"anchorPosition",anchorPosition:n},null!==e&&c.createElement(ne,{initialValues:{componentName:e.elementLabel},handleSave:async t=>{if(!e)throw new Error("Can't save element as component: element not found");try{const n=await l({name:t.componentName,content:[e.element.model.toJSON({remove:["default"]})]});if(!e)throw new Error("Can't replace element with component: element not found");F(e.element,{id:n.component_id,name:t.componentName}),r({show:!0,message:(0,s.__)("Component saved successfully as: %1$s (ID: %2$s)","elementor").replace("%1$s",t.componentName).replace("%2$s",n.component_id.toString()),type:"success"}),d()}catch{const e=(0,s.__)("Failed to save component. Please try again.","elementor");r({show:!0,message:e,type:"error"})}},isSubmitting:i,closePopup:d})),c.createElement(p.Snackbar,{open:a?.show,onClose:()=>r(null)},c.createElement(p.Alert,{onClose:()=>r(null),severity:a?.type,sx:{width:"100%"}},a?.message)))}const te="tiny",ne=({initialValues:e,handleSave:t,isSubmitting:n,closePopup:o})=>{const{values:a,errors:r,isValid:l,handleChange:i,validateForm:m}=Q(e),{components:u}=z(),h=(0,c.useMemo)(()=>u?.map(e=>e.name)??[],[u]),g=(0,c.useMemo)(()=>Z(h),[h]),y=(0,c.useMemo)(()=>(e=>{const t=Z(e);return t.extend({componentName:t.shape.componentName.refine(e=>e.length>0,{message:(0,s.__)("Component name is required.","elementor")}).refine(e=>e.length>=2,{message:(0,s.__)("Component name is too short. Please enter at least 2 characters.","elementor")})})})(h),[h]);return c.createElement(p.Stack,{alignItems:"start",width:"268px"},c.createElement(p.Stack,{direction:"row",alignItems:"center",py:1,px:1.5,sx:{columnGap:.5,borderBottom:"1px solid",borderColor:"divider",width:"100%"}},c.createElement(d.StarIcon,{fontSize:te}),c.createElement(p.Typography,{variant:"caption",sx:{color:"text.primary",fontWeight:"500",lineHeight:1}},(0,s.__)("Save as a component","elementor"))),c.createElement(p.Grid,{container:!0,gap:.75,alignItems:"start",p:1.5},c.createElement(p.Grid,{item:!0,xs:12},c.createElement(p.FormLabel,{htmlFor:"component-name",size:"tiny"},(0,s.__)("Name","elementor"))),c.createElement(p.Grid,{item:!0,xs:12},c.createElement(p.TextField,{id:"component-name",size:te,fullWidth:!0,value:a.componentName,onChange:e=>i(e,"componentName",g),inputProps:{style:{color:"text.primary",fontWeight:"600"}},error:Boolean(r.componentName),helperText:r.componentName}))),c.createElement(p.Stack,{direction:"row",justifyContent:"flex-end",alignSelf:"end",py:1,px:1.5},c.createElement(p.Button,{onClick:o,disabled:n,color:"secondary",variant:"text",size:"small"},(0,s.__)("Cancel","elementor")),c.createElement(p.Button,{onClick:()=>{const{success:e,parsedValues:n}=m(y);e&&t(n)},disabled:n||!l,variant:"contained",color:"primary",size:"small"},n?(0,s.__)("Creating…","elementor"):(0,s.__)("Create","elementor"))))};function oe(){return(0,c.useEffect)(()=>{(0,i.__dispatch)(x())},[]),null}const ae=(0,r.createStylesProvider)({key:"components-styles",priority:100,subscribe:e=>(0,i.__subscribeWithSelector)(e=>e[C],()=>{e()}),actions:{all:()=>O((0,i.__getState)()),get:e=>O((0,i.__getState)()).find(t=>t.id===e)??null}}),re=e=>e.flatMap(e=>{const t=[];return"e-component"===(e.widgetType||e.elType)&&e.settings?.component_id&&(0,B.isTransformable)(e.settings?.component_id)&&t.push(e.settings.component_id.value),e.elements&&t.push(...re(e.elements)),t});async function le(e){const t=Array.from(new Set(re(e)));if(!t.length)return;const n=L((0,i.__getState)()),o=t.filter(e=>!n[e]);o.length&&async function(e){const t=await async function(e){return Promise.all(e.map(async e=>[e,await S.getComponentConfig(e)]))}(e);(function(e){const t=Object.fromEntries(e.map(([e,t])=>[e,ie(t)]));(0,i.__dispatch)(b.actions.addStyles(t))})(t),Object.values(t).forEach(([,e])=>{le(e.elements)})}(o)}function ie(e){return[...Object.values(e.styles??{}),...(e.elements??[]).flatMap(ie)]}function se(){r.stylesRepository.register(ae),(0,i.__registerSlice)(b),(0,a.injectTab)({id:"components",label:(0,s.__)("Components","elementor"),component:q}),(0,n.injectIntoTop)({id:"create-component-popup",component:ee}),(0,n.injectIntoLogic)({id:"components-populate-store",component:oe}),(0,l.__privateListenTo)((0,l.commandStartEvent)("editor/documents/attach-preview"),()=>{const{id:e,config:t}=(0,o.getV1CurrentDocument)();e&&function(e){S.invalidateComponentConfigCache(e),(0,i.__dispatch)(b.actions.removeStyles({id:e}))}(e),le(t?.elements??[])})}(window.elementorV2=window.elementorV2||{}).editorComponents=t}(),window.elementorV2.editorComponents?.init?.();