1import{r as o,R as l,j as r,f as me}from"./globals-BMcmkdEs.mjs";import{c as Be,u as vt,D as ue,j as Tt,L as De}from"./globals-store-D4EiKqVk.mjs";import{u as je}from"./chat-common.store-CklDEzP9.mjs";import{a as bt,A as Xe}from"./index-_qzyPtWa.mjs";import{u as i,N as Et,L as Ye,d as wt}from"./ai-templates.store-DeEry194.mjs";import{c as Qe}from"./event-listener-Cukql-bl.mjs";import{k as yt,i as Lt}from"./popup-CE9-P_o9.mjs";import{k as Je,m as At}from"./product-D7YC8M9A.mjs";import{L as Ct}from"./LoadingIcon-1WWBncQn.mjs";import{f as xt}from"./index-CjHlb4Jy.mjs";import{d as Rt,n as Fe,e as Ze,i as jt,a as Ue,o as Pt}from"./product-B2OtzBrd.mjs";import{s as Mt}from"./AutoComplete2-DDixqqzX.mjs";import{u as It}from"./useCSR-CRvbHclt.mjs";import{a as et}from"./url-kTDias0L.mjs";import{g as de,e as Nt,q as tt}from"./common-CUwVOe11.mjs";import{P as Re}from"./product-CnNEWhFW.mjs";import{f as _t}from"./category-DA_KKv8K.mjs";import{getGeneratorContent as rt}from"./generator-Bq_t_puS.mjs";import{m as kt,b as Dt}from"./generateType-EMKsp1VE.mjs";import{T as st,V as Oe,g as Ft}from"./TagItem-jLD53XeC.mjs";import{L as Ut}from"./ListAITemplatesMasonryByColumns-DeQGNNlC.mjs";import{i as Ot,g as Bt}from"./helpers-3Xu0y6_v.mjs";import{i as Ht}from"./cross-window-zqBdgh6Q.mjs";import"./index.browser-OxPLOBIU.mjs";import"./edit-online-share-aIvv9uyT.mjs";import"./hydration-VZblZgci.mjs";import"./brand-modal-bridge-CXH_fTd-.mjs";import"./LoadMoreComponent-B2a3zFPo.mjs";import"./index-CS8ZtFVE.mjs";import"./index-bn9fV1ue.mjs";import"./router-Dv8GRqFY.mjs";import"./ProductCard-APfznEq_.mjs";import"./starred.store-Cvjdcye7.mjs";import"./workspace-Bwe85snN.mjs";import"./useMasonryColumns-CiEDlfuO.mjs";import"./useVideoHasAudio-BDmC0IDQ.mjs";import"./SkeletonGrid-Bss42-yp.mjs";function qt({result:v,isOpen:G=!1,setOpen:B,search:C,isLoading:j,onResultClick:h}){const R=o.useRef(null);l.useEffect(()=>{function T(D){const P=document.querySelector('.left-sidebar-search[data-target="search-by-generator"]'),W=document.querySelector('.left-sidebar-search[data-target="search-by-templates"]'),se=document.getElementById("search-box"),H=D.target,y=R.current?.contains(H),F=P?.contains(H),n=W?.contains(H),f=se?.contains(H);!y&&!F&&!n&&!f&&B?.(!1)}return document.addEventListener("mousedown",T),()=>{document.removeEventListener("mousedown",T)}},[B]);const x=o.useMemo(()=>{if(C)return r.jsx("div",{className:"search-keyword",children:r.jsxs("a",{onClick:T=>{h&&(T.preventDefault(),h({name:C}))},children:[r.jsx("img",{width:16,loading:"lazy",src:et("search-outline.svg"),alt:"icon"}),r.jsxs("span",{children:["Search for ",r.jsx("em",{children:C})]})]})})},[C]),w=o.useMemo(()=>r.jsxs("ul",{className:"search-result list-with-icon",children:[v.map((T,D)=>r.jsx("li",{"data-value":T.title,"data-url":T.url,children:r.jsxs("a",{href:de(T.url),onClick:P=>{h&&(P.preventDefault(),h(T))},children:[T.icon&&r.jsx("img",{width:16,height:16,loading:"lazy",src:et(T.icon),alt:"icon"}),r.jsx("span",{dangerouslySetInnerHTML:{__html:T._highlightResultValue||""}})]})},D)),j&&[1,2,3,4,5,6].map(T=>r.jsx("li",{className:"skeleton1",children:r.jsx("div",{className:"content loading-image"})},`sk-${T}`))]}),[C,j,v,h]);return G?r.jsx("div",{ref:R,className:me("auto-complete-container",{loading:j}),children:r.jsxs("div",{children:[x,w]})}):null}function Vt({customClass:v="",placeHolder:G,editorType:B,scrollToElement:C="",q:j,ssr:h=!1,position:R="header",idSearchBox:x="global-search",boxId:w="search-box",willRenderSSR:T=!1,onClear:D,handleResultClick:P}){const W=It(),se=Be(u=>u.isMobile),H=l.useRef(null);l.useRef(!1);const[y,F]=l.useState(j||""),[n,f]=l.useState(!1),[I,M]=l.useState(!1),[m,J]=l.useState([]),[Z,ae]=l.useState(!1),q=o.useMemo(()=>R==="header",[R]),oe=l.useRef(0),ee=l.useRef(null),le=l.useRef(!1);l.useEffect(()=>()=>{ee.current?.abort()},[]);const U=l.useRef(),N=l.useRef(null),K=l.useCallback(async(u=1)=>{const z=++oe.current;ee.current?.abort();const b=new AbortController;ee.current=b;const te=b.signal;try{const k=pe=>[...pe].map(Se=>{const Me=Se._highlightResultValue;return{...Se,_highlightResultValue:Me}});ae(!0),u===1&&J([]);
1const Pe=await Rt({q:y,editorType:B,isFileFormat:!1,categoryType:"category"},{signal:te});z===oe.current&&J(k(Pe.searchResult))}catch(k){if(k?.name==="CanceledError"||k?.name==="AbortError"||te.aborted)return;console.log("ð ~ SearchBox1 ~ error:",k)}finally{z===oe.current&&!te.aborted&&ae(!1)}},[B,y]);l.useEffect(()=>{if(le.current){le.current=!1;return}y!==""&&y!==void 0&&K(1)},[y,K]),o.useEffect(()=>{if(n){const u=setTimeout(()=>{M(!0)},50);return()=>clearTimeout(u)}else{const u=setTimeout(()=>{M(!1)},200);return()=>clearTimeout(u)}},[n]);const O=o.useCallback((u,z,b)=>{if(u&&Mt(u,z,b),window.appData.match){xt({selectedItemSlug:window.appData.match.url||void 0}),window.location.href=window.appData.match.url;return}sessionStorage.setItem("searchQuery",u||""),window.location.href=u===""?"/free":"/editable/search"},[]),ne=l.useCallback(()=>{O(y)},[O,y]),ge=l.useCallback(u=>{f(!0)},[m]),$=l.useCallback(()=>{U.current&&clearTimeout(U.current),ee.current?.abort(),N.current&&(N.current.value=""),le.current=!0,F(""),J([]),window.appData.match="",D?.()},[D]),_=l.useCallback(u=>{if(U.current&&clearTimeout(U.current),u===""||u===void 0){$();return}U.current=setTimeout(()=>{F(u)},500)},[$]),fe=o.useCallback(()=>{const u=N.current?.value??y??"";u&&(U.current&&clearTimeout(U.current),ee.current?.abort(),F(u),P&&P({name:u}),f(!1))},[y,P]),V=o.useCallback(u=>{const z=u?.name??u?.title??"";if(U.current&&clearTimeout(U.current),le.current=!0,N.current&&(N.current.value=z),F(z),f(!1),P){P(u);return}},[P]),be=["search-box search-box-new grow",v].join(" ");return!h&&!W&&!T?null:r.jsxs("div",{id:w,className:`${be} flex justify-end`,ref:H,children:[n||!q?r.jsx(bt,{autoFocus:q&&se,ref:N,rounded:!0,size:"xl",className:"grow",id:x,name:"global-search",placeholder:G||"Search for Templates...",defaultValue:y,onChange:u=>_(u.target.value),onClick:ge,onKeyDown:u=>{u.key==="Enter"&&(u.preventDefault(),fe())},iconStart:W&&r.jsx("svg",{width:18,height:18,children:r.jsx("use",{href:"/assets/sprites/icon-commons.svg?3f6e14a6#search"})}),onClickIconStart:ne,iconEnd:y?r.jsx("svg",{width:void 0,height:void 0,children:r.jsx("use",{href:"/assets/sprites/icon-commons.svg?3f6e14a6#close"})}):null,onClickIconEnd:$,autoComplete:"off"}):"",W&&I&&!(!y&&m.length===0&&!Z)&&r.jsx("div",{className:`search-result-wrapper ${n?"search-result-show":"search-result-hide"}`,children:r.jsx(qt,{setOpen:f,isOpen:n,search:y,result:m,setSearch:F,isLoading:Z,onResultClick:V})})]})}const at=v=>v.replace("Generator","");function Gt({isLoading:v,onClick:G,defaultPageType:B}){const{tags:C}=je(),{categorySelected:j,setCategorySelected:h,selectEditorType:R}=je(),x=j?.newSlug||j?.slug,w=o.useRef(null),[T,D]=o.useState(!1),[P,W]=o.useState(!1),se=o.useRef(x),H=i(n=>n.pageType)||B;o.useEffect(()=>{const n=w.current;if(!n)return;se.current!==x&&(n.scrollLeft=0,se.current=x);const f=()=>{const m=window.innerWidth>1024;D(m&&n.scrollLeft>0),W(m&&n.scrollLeft+n.clientWidth<n.scrollWidth-1)},I=()=>requestAnimationFrame(f);I();const M=new ResizeObserver(I);return M.observe(n),n.addEventListener("scroll",f,{passive:!0}),window.addEventListener("resize",I,{passive:!0}),()=>{M.disconnect(),n.removeEventListener("scroll",f),window.removeEventListener("resize",I)}},[C?.length,x,v]),l.useEffect(()=>{Ht()},[C?.length,v]),l.useEffect(()=>{if(!w.current||!x||v)return;const n=w.current,f=n.querySelector(".btn.active");if(!f)return;const I=n.scrollLeft,M=n.clientWidth,m=f.offsetLeft,J=m+f.offsetWidth;if(m<I||J>I+M){const Z=m-(M-f.offsetWidth)/2,ae=typeof window<"u"&&window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;n.scrollTo({left:Math.max(0,Z),behavior:ae?"auto":"smooth"})}},[x,C?.length,v]);const y=o.useCallback((n,f,I,M)=>{document.dispatchEvent(new CustomEvent("chat-box-selected-tag",{detail:{slug:n,label:f,value:I}}))},[]),F=o.useCallback(n=>{h(null),R("",""),document.dispatchEvent(new CustomEvent("chat-box-selected-tag",{detail:{slug:""}})),typeof window<"u"&&window.location.pathname!=="/"&&(window.location.href="/")},[]);return v?r.jsx("div",{className:"list-tag-container loading",children:r.jsx("div",{className:"section-tags category-tags",children:r.jsx("ul",{className:"list-tags",children:Array.from({length:8}).map((n,f)=>r.jsx("li",{className:"category-tag loading1"},f))})})}):C?.length?r.jsx("div",{className:me("list-tag-container generator-tags"),onClick:G,id:"list-tag-container",children:r.jsxs("div",{className:"section-tags category-tags",children:[T&&r.jsx("div",{className:"arrow arrow-left !w-6 !h-6 !rounded-lg",style:{display:"flex"},onClick:n=>{n.preventDefault(),w.current&&(w.current.scrollLeft=Math.max(0,w.current.scrollLeft-200))},children:r.jsx("svg",{viewBox:"0 0 16 16",width:"16",height:"16",fill:"none",children:r.jsx("path",{d:"M10 13L5 8l5-5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}),r.jsxs("ul",{ref:w,className:"list-tags",children:[j&&r.jsx("li",{children:r.jsx(st,{tag:j,index:0,isActive:!0,onClick:y,handleReplaceTextTag:at,onClose:F})}),C.filter(n=>{const f=n.newSlug||n.slug;return x!==f}).map((n,f)=>r.jsx("li",{className:me("main-cat",{"home-cat":H==="HOME",active:[n.slug,n.newSlug].filter(
1Boolean).includes(x)}),children:r.jsx(st,{tag:n,index:f,isActive:[n.slug,n.newSlug].filter(Boolean).includes(x),onClick:y,handleReplaceTextTag:at})},n.slug))]}),P&&r.jsx("div",{className:"arrow arrow-right !w-6 !h-6 !rounded-lg",style:{display:"flex"},onClick:n=>{n.preventDefault(),w.current&&(w.current.scrollLeft=Math.min(w.current.scrollWidth-w.current.clientWidth,w.current.scrollLeft+200))},children:r.jsx("svg",{viewBox:"0 0 16 16",width:"16",height:"16",fill:"none",children:r.jsx("path",{d:"M6 3l5 5-5 5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})})]})}):null}const Wt=o.forwardRef(function({activeType:G,onChange:B},C){const j=o.useMemo(()=>[{id:"all",label:"All",iconHref:"#template"},...Object.keys(Oe).map(h=>({id:h,label:Oe[h].label,iconHref:Oe[h].iconHref}))],[]);return r.jsxs("div",{ref:C,className:"my-projects-filter-card",role:"tablist","aria-label":"Filter video templates",children:[r.jsx("div",{className:"my-projects-filter-card__title",children:"Filter"}),r.jsx("ul",{className:"my-projects-filter-card__list",children:j.map(h=>{const R=h.id===G;return r.jsx("li",{className:"my-projects-filter-card__item",children:r.jsxs("button",{type:"button",role:"tab","aria-selected":R,className:me("my-projects-filter-card__row",{"my-projects-filter-card__row--active":R}),onClick:()=>B(h.id),children:[r.jsx("span",{className:"my-projects-filter-card__icon",children:r.jsx("svg",{width:16,height:16,children:r.jsx("use",{href:`/assets/sprites/icon-commons.svg?3f6e14a6${h.iconHref}`})})}),r.jsx("span",{className:"my-projects-filter-card__label",children:h.label}),R&&r.jsx("span",{className:"my-projects-filter-card__check","aria-hidden":"true",children:r.jsx("svg",{width:16,height:16,children:r.jsx("use",{href:"/assets/sprites/icon-commons.svg?3f6e14a6#check"})})})]})},h.id)})})]})}),ot=["aaa"],jr=({initialTemplates:v,initialLpUrl:G,initialCategories:B,defaultPageType:C="HOME",isListLoadingDefault:j=!1,defaultSlug:h="/free",initialLoadingType:R="SSR_DATA",hasPaging:x=!0,hasListenTagClick:w=!0,currentPageProp:T=1,homeApi:D,handleClickContainerCard:P,cardTagName:W,defaultTemplateMode:se=Ye.TEMPLATES,defaultTagLoading:H=!1,initialLpName:y,selectedCategory:F,pageMetaTitle:n})=>{const[f,I]=l.useState(W),M=l.useRef(h),m=l.useRef(T),J=l.useRef(),Z=l.useRef(0),ae=l.useRef(),q=l.useRef(!1),oe=je(e=>e.isFloatingChatInStore),ee=l.useRef(oe);o.useEffect(()=>{ee.current=oe},[oe]);const le=je(e=>e.setIsFloatingExpanded),U=Be(e=>e.isMobile),N=l.useRef(""),K=i(e=>e.pageType)||C,O=i(e=>e.isPageLoading)||j,ne=i(e=>e.loadingType)||R,ge=i(e=>e.isListingLoading),$=i(e=>e.isLoadMoreLoading),_=i(e=>e.templates)||v||[],fe=i(e=>e.total)||0,V=i(e=>e.lpUrl)||G,be=i(e=>e.nbPages),u=i(e=>e.page),z=i(e=>e.templateMode),b=vt(e=>e.isLoggedIn),te=i.getState().currentSlug,k=i(e=>e.currentSlug),Pe=kt(k),pe=Dt(k),[he,Se]=o.useState("all");o.useEffect(()=>{Se("all")},[k]);const Me=o.useCallback(e=>{Se(e);const t=document.querySelector("#page-with-chat")||document.querySelector(".main-content");t&&t.scrollTop>0?t.scrollTo({top:0,behavior:"smooth"}):window.scrollY>0&&window.scrollTo({top:0,behavior:"smooth"})},[]),nt=o.useMemo(()=>!pe||he==="all"?_:_.filter(e=>Ft(e.videoFormat)===he),[_,pe,he]),it=pe?r.jsx(Wt,{activeType:he,onChange:Me}):void 0,He=l.useRef(()=>{}),Ie=o.useCallback(async e=>{i.setState({isListingLoading:!0});try{const t=await Fe(e,te||"");t&&(i.setState({templates:t.items?.map(s=>({...s,imageUrl:s.imgUrl})),total:t.total}),m.current=1)}catch(t){console.log("ð ~ searchAiModeTemplates ~ error:",t)}finally{i.setState({isListingLoading:!1})}},[te]),Ee=l.useRef(Ie);l.useEffect(()=>{Ee.current=Ie},[Ie]);const[Ne,we]=o.useState(""),qe=l.useRef(Nt(e=>Ee.current(e),400)).current,lt=o.useCallback(e=>{const t=e.target.value;we(t),qe(t)},[qe]),ct=o.useCallback(()=>{we(""),Ee.current("")},[]),_e=o.useCallback(()=>{if(N.current="",m.current=1,v&&v.length>0){i.setState({templates:v,total:v.length,page:1,nbPages:void 0,loadingType:R,isListingLoading:!1,isLoadMoreLoading:!1});return}const e=i.getState().currentSlug||h;e&&document.dispatchEvent(new CustomEvent(ue.CHAT_BOX_SELECTED_TAG,{detail:{templateSlug:e,templatesOnly:!0,notKeepHistory:!0}}))},[h,v,R]),ye=ot.includes(te),[Ve,Ge]=o.useState(0),We=l.useRef(k);o.useEffect(()=>{We.current!==k&&(We.current=k,we(""),N.current="",Ge(e=>e+1))},[k]);const ut=o.useCallback(()=>{ye?Ne&&(we(""),Ee.current("")):N.current&&_e(),Ge(e=>e+1)},[ye,Ne,_e]);He.current=ut;const Ke=O||ge,dt=o.useCallback(e=>{const t=e.target;if(t.closest(".search-relative, .search-templates-container, input, .new-home-search"))return;const s=t.closest(".category-tag-container")||t.closest("button");if(!s||!(s.tagName==="A"||s.tagName==="BUTTON"&&(s.hasAttribute("data-template-url")||s.hasAttribute("data-tag"))))return;He.current();let a,S,d;if(s.tagName==="A"){e.preventDefault();const g=s.href||"";S=s.getAttribute("data-generator-url")||void 0,a=g.replace(window.location.origin,"")}else if(s.tagName==="BUTTON"){e.preventDefault();const g=s.getAttribute("data-template-url")||"";S=s.getAttribute("data-generator-url")||void 0,a=g.replace(window.location.origin,""),d=s.getAttribute("data-tag")}if(d){document.dispatchEvent(new CustomEvent(ue.CHAT_BOX_SELECTED_TAG,{detail:{templateSlug:S,templatesOnly:!0,generatorUrl:S,tagModel:d}}));return}a&&document.dispatchEvent(new CustomEvent(ue.CHAT_BOX_SELECTED_TAG,{detail:{templateSlug:a,templatesOnly:!0,generatorUrl:S,tagModel:d}}))},[]);o.useEffect(()=>{C==="GENERATOR"&&i.setState({isPageLoading:!1})},[C]);const $e=o.useCallback(e=>{if(Xe.getState().closeModal("new-product-popup"),Je(e),ee.current){le(!0);return}if(b){const t=document.querySelector("#page-with-chat");t?t.scrollTo({top:0,behavior:"smooth"}):window.scrollTo({top:0,behavior:"smooth"})}else{const t=document.querySelector(".main-content");t?t.scrollTo({top:0,behavior:"smooth"}):window.scrollTo({top:0,behavior:"smooth"})}},[b]),mt=o.useCallback(e=>{if(Xe.getState().closeModal("ai-template"),Je(e),b){const t=document.querySelector("#page-with-chat");t?t.scrollTo({top:0,behavior:"smooth"}):window.scrollTo({top:0,behavior:"smooth"})}else{const t=document.querySelector(".main-content");t?t.scrollTo({top:0,behavior:"smooth"}):window.scrollTo({top:0,behavior:"smooth"})}},[b]);o.useEffect(()=>{const e=t=>{const s=t.detail.data.productId;(async()=>
1{if(!s)return t.detail.data;try{const a=await Ze(Number(s)),S=a.settings?.videoSettings?.format,d=t.detail.data.aiEditorCategory||a.aiEditorCategory||a.mainCategory?.aiEditorCategory||"";return{...t.detail.data,steps:Array.isArray(a.steps)?a.steps:[],videoTemplateFormat:S,isReferenceImage:!S,aiEditorCategory:d,slug:t.detail.data.slug||d}}catch{return t.detail.data}})().then($e)};return document.registerEvent("USE_TEMPLATE_POPUP",e),()=>document.unregisterEvent("USE_TEMPLATE_POPUP",e)},[]);const gt=o.useCallback(e=>{const t=e.target;if(t.closest(".action-buttons")||t.closest(".video-play-toggle")||t.closest(".video-mute-toggle")||t.closest(".shared-icon-wrapper"))return;const s=t.closest(".starred-icon-wrapper");if(s){e.preventDefault();const d=s.dataset.productId,L=s.dataset.isStarred==="true"?0:1;Tt(ue.STAR_TEMPLATE,{detail:{productId:Number(d),isStarrParam:L}});return}if(t.closest(".btn-use"))return;const a=t.closest(".product"),S=a?.querySelector(".product-url");if(a){const d=a.dataset.productId;e.preventDefault();const g=a.dataset.productType||"";if(["image","video"].includes(g||"")){const L=a.dataset.posterUrl||"",p=a.dataset.videoUrl||"",E=a.dataset.templateTitle||"",A=a.dataset.prompt||"",re=a.dataset.slug||"",X=a.dataset.requiredPhoto||"",ce=a.dataset.styleKey,ie=a.dataset.aiModel,Te=a.dataset.templateTitle||"",Y=a.dataset.f
1ileUrl||"",Q=a.dataset.isFree||"",Ce=a.dataset.isReferenceImage||!1;if(g==="video"&&(sessionStorage.setItem("GENERATE_VIDEO","true"),sessionStorage.setItem("GENERATE_VIDEO_MODEL",`${ie}`)),Be.getState().isMobile||g==="usecase"){const xe={prompt:A,slug:re,requiredPhoto:X,styleKey:ce,aiModel:ie,posterUrl:L,videoUrl:p,templateTitle:Te,fileUrl:Y,isFree:Q,type:g??"",isReferenceImage:Ce,productId:d?Number(d):void 0};$e(xe)}else{const xe=a.dataset.hasProductId||"",ht=a.dataset.productType,St={prompt:A,slug:re,requiredPhoto:X,styleKey:ce,aiModel:ie,posterUrl:L,videoUrl:p,templateTitle:Te,fileUrl:Y,isFree:Q,type:ht??"",isReferenceImage:Ce,hasProductId:xe,productId:d?Number(d):void 0};yt({posterUrl:L,videoUrl:p,title:E,onUseTemplate:()=>mt(St)})}g==="usecase"&&setTimeout(()=>{document.getElementById("generate-btn")?.click()},1500);return}if(["EDITABLE","AI_TEMPLATE"].includes(g)){const L=a.dataset.isAiTemplate?Number(a.dataset.isAiTemplate):0,p=a?.querySelector(":scope img"),E=a?.querySelector(":scope video"),A=S?.getAttribute("data-file-formats"),re=S?.getAttribute("aria-label"),X=tt(A||"",window.appData?.allFileFormats),ce=S?.getAttribute("href")||"",Te=a?.querySelector(":scope .pro-tag")?Re.PRO:Re.FREE,Y=[];E?(Y.push({imageUrl:E?.currentSrc,width:E.width?String(E.width):void 0,height:E.height?String(E.height):void 0}),E.poster&&Y.push({imageUrl:E.poster,width:E.width?String(E.width):void 0,height:E.height?String(E.height):void 0})):Y.push({imageUrl:p?.src});const Q={id:Number(d),title:re||p?.getAttribute("alt")||"",filesAvail:X||[],images:Y,isAiTemplate:L,url:ce||"",type:Te||"",productType:g};Lt({productDetail:Q});return}if(window.innerWidth>=768){const L=!!a?.closest("#single-popup"),p=a.dataset.isAiTemplate?Number(a.dataset.isAiTemplate):0,E=a?.querySelector(":scope img"),A=a?.querySelector(":scope video"),re=S?.getAttribute("data-file-formats"),X=S?.getAttribute("aria-label"),ce=tt(re||"",window.appData?.allFileFormats),ie=S?.getAttribute("href")||"",Y=a?.querySelector(":scope .pro-tag")?Re.PRO:Re.FREE,Q=[];A?(Q.push({imageUrl:A?.currentSrc,width:A.width?String(A.width):void 0,height:A.height?String(A.height):void 0}),A.poster&&Q.push({imageUrl:A.poster,width:A.width?String(A.width):void 0,height:A.height?String(A.height):void 0})):Q.push({imageUrl:E?.src});const Ce={id:Number(d),title:X||E?.getAttribute("alt")||"",filesAvail:ce||[],images:Q,isAiTemplate:p,url:ie||"",type:Y||"",productType:g};Ze(Number(d)),At({product:Ce,isPopup:L,url:ie||""});return}else{window.location.href=`/?u=ai-chat&productId=${d}`;return}}},[]);o.useEffect(()=>{async function e(t){if(!t.detail.slug&&!t.detail.templateSlug)return;const{slug:s,templateSlug:c,notKeepHistory:a,generatorUrl:S,tagModel:d}=t.detail;if(t.detail.templatesOnly===!0){i.setState({isListingLoading:!0});try{if(d){const[L]=await Promise.all([Fe("",c,d)]);L&&(i.setState({templates:L.items.map(p=>({...p,imageUrl:p.imgUrl})),total:L.total,activeTab:d}),M.current=c,m.current=1);return}const[g]=await Promise.all([Ue(1,S||c,34)]);g&&(i.setState({templates:g.items.map(L=>({...L})),total:g.total,activeTab:c}),M.current=c,m.current=1),a||history.pushState({templateSlug:c},"",de(location.pathname))}catch(g){console.log("ð ~ Load ai templates ~ error:",g)}finally{i.setState({isListingLoading:!1})}return}else{const g=Ot(s);document.body.classList.toggle("floating-chat",g),i.setState({isPageLoading:!0,templateMode:wt(s)}),I("div");let L=[rt(s),Ue(1,c||s),_t(s)];ot.includes(s)&&(L=[rt(s),Fe("",c||s),Pt(s)]),await Promise.all(L).then(([p,E,A])=>{const re=Bt(s,p.tagLine||"");i.setState({currentSlug:s,generatorNewData:p?.generatorNewData,title:p?.generatorNewData?.title||"",tagLine:re,pageType:"GENERATOR",breadcumData:p?.breadcumData||[],lpName:p?.lpData?.name||"",lpUrl:p?.lpData?.url||"",lpPageType:p?.lpData?.pageType||"",activeTab:p?.lpData?.url||c,relatedTags:p?.relatedTags||[],promptPlaceholder:p?.promptPlaceholder||"",categories:A?.data,templates:E?.items?.map(X=>({...X,imageUrl:X.imgUrl})),total:E?.total,loadingType:"SSR_DATA"}),a||history.pushState({aiSlug:s,templateSlug:c},"",de(`/${s}`))}).catch(p=>{console.log("ð ~ PageWithChat ~ error:",p)}).finally(()=>{J.current=s,m.current=1,M.current="",i.setState({isPageLoading:!1})})}}return w&&document.addEventListener(ue.CHAT_BOX_SELECTED_TAG,e),()=>{w&&document.removeEventListener(ue.CHAT_BOX_SELECTED_TAG,e)}},[ye]);const Le=o.useCallback(async({q:e,page:t})=>{e&&(t&&t>1?i.setState({isLoadMoreLoading:!0}):i.setState({isListingLoading:!0}),await jt({q:e,page:t,productType:"EDITABLE"}).then(s=>{const{searchResult:c,nbPages:a,page:S}=s;let d=[];c&&c.length>0&&(t&&t>1?d=[...i.getState().templates||[],...c]:d=c),i.setState({templates:d.map(g=>({...g,productType:g.productType})),nbPages:a,page:S,loadingType:"SEARCH"}),m.current=t+1,N.current=e}).catch(s=>{console.log("ð ~ onLpFilter ~ error:",s)}).finally(()=>{q.current=!1,i.setState({isListingLoading:!1,isLoadMoreLoading:!1})}
1))},[]);o.useEffect(()=>{const e=t=>Le(t.detail);return Qe(document,De.LP_FILTER,e),()=>{Qe(document,De.LP_FILTER,e,!1)}},[Le]);const Ae=l.useRef("DATABASE"),ke=l.useRef(null),ze=o.useCallback(e=>{if(e?.name){if(Ae.current==="DATABASE"){const s=i.getState();ke.current={templates:s.templates,total:s.total,nbPages:s.nbPages,page:s.page,loadingType:s.loadingType,nextPage:m.current},Ae.current="SEARCH"}Le({q:e.name,page:1});return}if(Ae.current==="DATABASE")return;Ae.current="DATABASE";const t=ke.current;ke.current=null,N.current="",m.current=t?.nextPage??1,i.setState({templates:t?.templates??[],total:t?.total??0,nbPages:t?.nbPages,page:t?.page,loadingType:t?.loadingType,isListingLoading:!1,isLoadMoreLoading:!1})},[Le]),ve=o.useCallback(async e=>{if(ne==="SEARCH"){e?.preventDefault(),document.dispatchEvent(new CustomEvent(De.LP_FILTER,{detail:{q:N.current,page:m.current}}));return}if(b){e?.preventDefault(),i.setState({isLoadMoreLoading:!0}),q.current=!0;const s=m.current+1;if(K==="HOME"&&D)try{const c=await D({page:s,limit:40,url:s>1?[V,s].join("/"):V}),a=c.items||c.products||[];a.length>0&&(i.setState(S=>({templates:[...S.templates||[],...a]})),m.current=s,Z.current=c.total),q.current=!1}catch(c){console.log("ð ~ PageWithChat ~ error:",c)}finally{i.setState({isLoadMoreLoading:!1})}else try{const c=await Ue(s,M.current||J.current||"",34);c.items.length>0&&(i.setState(a=>({templates:[...a.templates||[],...c.items]})),m.current=s,Z.current=c.total)}catch(c){console.log("ð ~ PageWithChat ~ error:",c)}finally{q.current=!1,i.setState({isLoadMoreLoading:!1})}}else e?.preventDefault(),document.emitEvent("toggle-modal-Auth",{isSignIn:!0,customClassName:"lite-modal",onSuccess:()=>{window.location.href=de(V)}})},[K,b,ne,$,V]),ft=o.useMemo(()=>r.jsx(Vt,{customClass:"search-relative search-templates-container new-home-search",placeHolder:"Search for Templates...",hasDropdown:!1,position:"body",willRenderSSR:!0,handleResultClick:ze,onClear:()=>{ze({name:void 0})}},`searchbox-${Ve}`),[K,ye,Ne,lt,ct,_e,b,Ve]),pt=o.useMemo(()=>{if(!x)return;const e=O||ge,t=m.current,s=$?r.jsx(Ct,{size:18}):b||ne==="SEARCH"?"View More":"Browse all templates";return ne==="SEARCH"?u+1>=be?null:r.jsx("a",{onClick:ve,id:"btn-view-all",style:{display:e&&_?.length===0?"none":"auto",pointerEvents:$?"none":"auto"},href:de(V),className:me("btn btn-light rounded-lg btn-view-all btn-common",{loading1:O}),title:"Browse all templates",children:s}):b&&_?.length>=fe||!V||b&&t>1?null:r.jsx("a",{onClick:ve,id:"btn-view-all",style:{display:e&&_?.length===0?"none":"auto",pointerEvents:$?"none":"auto"},href:de(V),className:me("btn btn-light rounded-lg btn-view-all btn-common",{loading1:O}),title:"Browse all templates",children:s})},[O,ge,_,$,V,O,b,ne,ve,u,be,fe,K,x]);if(o.useEffect(()=>{if(!b)return;const e=ae.current,t=document.querySelector("#page-with-chat"),s=.1,c="0px",a=m.current;if(b&&(!t||a===1))return;const S={root:t,rootMargin:c,threshold:s},d=new IntersectionObserver(g=>{if(q.current||_&&_.length>=Z.current)return;g[0].isIntersecting&&(q.current=!0,i.setState({isLoadMoreLoading:!0}),ve())},S);return e?d.observe(e):d.disconnect(),()=>{d.disconnect()}},[m.current,b,ve,K]),o.useEffect(()=>{const e=document.getElementById("tags-container");if(!e)return;const t=document.createElement("div");t.style.cssText="position:absolute;height:1px;width:1px;pointer-events:none;",e.parentElement?.insertBefore(t,e);const s=new IntersectionObserver(([c])=>{e.classList.toggle("is-sticky",!c.isIntersecting)},{threshold:[0]});return s.observe(t),()=>{s.disconnect(),t.remove()}},[]),!Et.includes(F?.slug||te||""))return r.jsx(r.Fragment,{children:z===Ye.TEMPLATES&&r.jsxs(r.Fragment,{children:[r.jsxs("section",{id:"free-templates-section",className:"section free-templates-section ",children:[r.jsxs("div",{style:{pointerEvents:O?"none":"auto"},onClick:dt,id:"tags-container",children:[!U&&ft,r.jsx(Gt,{isLoading:H||O,defaultPageType:K})]}),r.jsx("div",{onClick:P||gt,id:"masonry-list-section",className:"masonry-list-section show",children:!Ke&&_?.length===0?r.jsx(r.Fragment,{}):r.jsx(Ut,{loadingItemPerColumn:2,isLoading:Ke,products:nt,hasHighlight:!0,tagName:f,altCardText:n,leadingSlot:it,auto
1playInView:Pe})}),pt]}),b&&q.current===!1&&m.current>1&&_?.length<fe&&r.jsx("div",{ref:ae,className:"sentinel-infinity-scroll"})]})})};export{jr as TemplatesIsland};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.