PageSourceSearch

https://botify.ai/static/js/5137.15bdd37d.chunk.js

js botify.ai collected 2026-10-01 11:26:16 UTC 98,450 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunklanding_v3=self.webpackChunklanding_v3||[]).push([[5137],{69623(e,t,a){a.d(t,{h:()=>i});var l,r=a(9950);const o=["title","titleId"];function n(){return n=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var a=arguments[t];for(var l in a)({}).hasOwnProperty.call(a,l)&&(e[l]=a[l])}return e},n.apply(null,arguments)}function s(e,t){let a=e.title,s=e.titleId,i=function(e,t){if(null==e)return{};var a,l,r=function(e,t){if(null==e)return{};var a={};for(var l in e)if({}.hasOwnProperty.call(e,l)){if(-1!==t.indexOf(l))continue;a[l]=e[l]}return a}(e,t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);for(l=0;l<o.length;l++)a=o[l],-1===t.indexOf(a)&&{}.propertyIsEnumerable.call(e,a)&&(r[a]=e[a])}return r}(e,o);return r.createElement("svg",n({xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",ref:t,"aria-labelledby":s},i),a?r.createElement("title",{id:s},a):null,l||(l=r.createElement("path",{d:"M6 12C6.01104 11.4541 6.19871 11.0066 6.65133 10.5808L14.9972 2.49127C15.3395 2.16376 15.7369 2 16.2226 2C17.1941 2 18 2.78603 18 3.73581C18 4.21616 17.7902 4.66376 17.4259 5.0131L10.1509 11.9891L17.4259 18.976C17.7902 19.3362 18 19.7729 18 20.2642C18 21.2249 17.1941 22 16.2226 22C15.7369 22 15.3395 21.8362 14.9972 21.5087L6.65133 13.4192C6.19871 12.9825 6 12.5349 6 12Z",fill:"var(--secondary-color)"})))}const i=r.forwardRef(s);a.p},85137(e,t,a){a.d(t,{GeneratePage:()=>Xa});var l=a(80045),r=a(89379),o=a(5544),n=a(9950);const s=(e,t)=>{var a,l,r,o;const n=null!==(a=null!==(l=null!==(r=e.find(e=>{var a;return e.id===(null===(a=t.model)||void 0===a?void 0:a.id)}))&&void 0!==r?r:e.find(e=>{var a;return e.baseModelId===(null===(a=t.model)||void 0===a?void 0:a.baseModelId)}))&&void 0!==l?l:e[0])&&void 0!==a?a:null,s=!n||null!==t.model&&n.availableDurations.includes(t.duration)?t.duration:null!==(o=n.availableDurations[0])&&void 0!==o?o:5;return n===t.model&&s===t.duration?t:{model:n,duration:s}};var i=a(28429),d=a(42074),c=a(51096),u=a(81141),m=a(17858),v=a(46676),h=a(48738),p=a.n(h),g=a(45142),x=a(79600),y=a(35843),b=a(93818),A=a(39721);var f=a(43735);const j="CharacterPickerModal_modal__mqN22",C="CharacterPickerModal_modalInner__di6n0",_="CharacterPickerModal_title__yYAU9",N="CharacterPickerModal_closeBtn__kFdiV",k="CharacterPickerModal_searchWrapper__Z15Jj",I="CharacterPickerModal_searchInput__CEP69",w="CharacterPickerModal_tabsRow__EWuGk",M="CharacterPickerModal_filterWrapper__nka+J",S="CharacterPickerModal_filterBtn__KFlUA",P="CharacterPickerModal_filterBtnActive__3tKFk",E="CharacterPickerModal_filterIconWrapper__WAzz9",T="CharacterPickerModal_filterLabel__DE0Q0",B="CharacterPickerModal_filterDot__+YdDc",U="CharacterPickerModal_separator__R9U0v",L="CharacterPickerModal_genderDropdown__MNCPH",O="CharacterPickerModal_genderOption__SWN1h",F="CharacterPickerModal_genderOptionEmoji__JKKUm",G="CharacterPickerModal_genderOptionLabel__jPmDD",R="CharacterPickerModal_genderOptionActive__Y35Ny",D="CharacterPickerModal_genderCheck__vAlIv",V="CharacterPickerModal_scroll__Ueu8X",W="CharacterPickerModal_scrollInner__tVHtz",q="CharacterPickerModal_scrollButton__9o-SD",z="CharacterPickerModal_scrollButtonLeft__cZXdi",H="CharacterPickerModal_scrollButtonRight__dsmZW",Z="CharacterPickerModal_tab__O7Hn4",Y="CharacterPickerModal_tabActive__d0Dkc",J="CharacterPickerModal_gridWrapper__2RAJp",X="CharacterPickerModal_grid__vZWHP",Q="CharacterPickerModal_gridFade__F8IBL",K="CharacterPickerModal_skeletonCard__8-sQ8",$="CharacterPickerModal_empty__Sp5pU",ee="CharacterPickerModal_sentinel__6zOF1",te="CharacterPickerModal_botCard__peA7N",ae="CharacterPickerModal_botCardSelected__45W37",le="CharacterPickerModal_botImage__FwkDe",re="CharacterPickerModal_checkmark__loLA5",oe="CharacterPickerModal_botNameOverlay__T4Eb5",ne="CharacterPickerModal_botName__R49+Q",se="CharacterPickerModal_modalMobile__hTCOI",ie="CharacterPickerModal_modalInnerMobile__bf0Yl",de="CharacterPickerModal_gridMobile__w3MIa";var ce=a(44414);const ue=()=>(0,ce.jsxs)("svg",{width:"23",height:"23",viewBox:"0 0 23 23",fill:"none",children:[(0,ce.jsx)("rect",{x:"0.75",y:"0.75",width:"21.5",height:"21.5",rx:"10.75",fill:"#7B5DF3"}),(0,ce.jsx)("rect",{x:"0.75",y:"0.75",width:"21.5",height:"21.5",rx:"10.75",stroke:"white",strokeWidth:"1.5"}
1),(0,ce.jsx)("path",{d:"M10.359 16.1693C10.048 16.1693 9.81483 16.0575 9.60383 15.8074L6.72765 12.4125C6.56663 12.2263 6.5 12.0507 6.5 11.8644C6.5 11.4387 6.8276 11.1301 7.2829 11.1301C7.55497 11.1301 7.74375 11.2259 7.92699 11.4441L10.3368 14.3707L15.0397 7.2297C15.2285 6.94236 15.4173 6.83594 15.7282 6.83594C16.178 6.83594 16.5 7.13924 16.5 7.55962C16.5 7.72457 16.45 7.89485 16.3168 8.08641L11.1197 15.7915C10.942 16.0469 10.6866 16.1693 10.359 16.1693Z",fill:"white"})]}),me=()=>(0,ce.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,ce.jsx)("circle",{cx:"11",cy:"11",r:"7"}),(0,ce.jsx)("path",{d:"M21 21l-4.35-4.35"})]}),ve=[{value:"any",label:"Any gender",emoji:"\u2728"},{value:"female",label:"Female",emoji:"\ud83d\ude4d\u200d\u2640\ufe0f"},{value:"male",label:"Male",emoji:"\ud83d\ude4e\u200d\u2642\ufe0f"}],he=()=>(0,ce.jsx)("svg",{width:"21",height:"13",viewBox:"0 0 21 13",fill:"none",children:(0,ce.jsx)("path",{d:"M5.04883 12.4863C4.72982 12.4863 4.45964 12.3691 4.23828 12.1348C4.01693 11.8939 3.90625 11.6204 3.90625 11.3145C3.90625 10.9954 4.01693 10.7188 4.23828 10.4844C4.45964 10.25 4.72982 10.1328 5.04883 10.1328H15.4492C15.7747 10.1328 16.0482 10.25 16.2695 10.4844C16.4909 10.7122 16.6016 10.9889 16.6016 11.3145C16.6016 11.627 16.4876 11.9004 16.2598 12.1348C16.0384 12.3691 15.7682 12.4863 15.4492 12.4863H5.04883ZM3.11523 7.41797C2.79622 7.41797 2.52279 7.30078 2.29492 7.06641C2.07357 6.82552 1.96289 6.55208 1.96289 6.24609C1.96289 5.92708 2.07357 5.65039 2.29492 5.41602C2.51628 5.18164 2.78971 5.06445 3.11523 5.06445H17.3926C17.7116 5.06445 17.9818 5.18164 18.2031 5.41602C18.4245 5.64388 18.5352 5.92057 18.5352 6.24609C18.5352 6.55859 18.4245 6.83203 18.2031 7.06641C17.9818 7.30078 17.7116 7.41797 17.3926 7.41797H3.11523ZM1.14258 2.34961C0.830078 2.34961 0.559896 2.23242 0.332031 1.99805C0.110677 1.75716 0 1.48372 0 1.17773C0 0.858724 0.110677 0.582031 0.332031 0.347656C0.553385 0.113281 0.823568 -0.00390625 1.14258 -0.00390625H19.3262C19.6517 -0.00390625 19.9219 0.113281 20.1367 0.347656C20.3581 0.575521 20.4688 0.852214 20.4688 1.17773C20.4688 1.49023 20.3581 1.76367 20.1367 1.99805C19.9154 2.23242 19.6452 2.34961 19.3262 2.34961H1.14258Z",fill:"currentColor"})}),pe=e=>{var t,a;let l=e.opened,r=e.onClose,s=e.onSelect,i=e.selectedBotId,d=e.isMobile;const c=(e=>{var t;const a=(0,n.useContext)(x.BR),l=a.categories,r=a.user,s=a.visitedChats,i=a.loadMoreChats,d=a.hasMoreChats,c=a.isLoadingMoreChats,u=null!==(t=null===e||void 0===e?void 0:e.pageSize)&&void 0!==t?t:30,m=(0,g.Au)(),v=(0,n.useState)(""),h=(0,o.A)(v,2),p=h[0],f=h[1],j=(0,n.useState)(""),C=(0,o.A)(j,2),_=C[0],N=C[1],k=(0,n.useState)("any"),I=(0,o.A)(k,2),w=I[0],M=I[1],S=(0,n.useState)([]),P=(0,o.A)(S,2),E=P[0],T=P[1],B=(0,n.useState)(0),U=(0,o.A)(B,2),L=U[0],O=U[1],F=(0,n.useState)([]),G=(0,o.A)(F,2),R=G[0],D=G[1],V=(0,n.useState)(!1),W=(0,o.A)(V,2),q=W[0],z=W[1],H=(0,n.use
1State)(!1),Z=(0,o.A)(H,2),Y=Z[0],J=Z[1],X=(0,n.useState)(!1),Q=(0,o.A)(X,2),K=Q[0],$=Q[1],ee=(0,n.useState)(!1),te=(0,o.A)(ee,2),ae=te[0],le=te[1],re=(0,n.useRef)(null),oe=(0,n.useRef)(0),ne=(0,n.useRef)(0),se=(0,n.useMemo)(()=>s.filter(e=>{var t;return null===(t=e.botIds)||void 0===t?void 0:t[0]}).map(e=>({id:Number(e.botIds[0]),attributes:{name:e.name||"",avatarUrl:e.avatarUrl||"",heroPicture:"",bio:""}})),[s]),ie=(0,n.useMemo)(()=>Object.values(l).filter(e=>!e.hideInSwitch).sort((e,t)=>e.data.attributes.sort-t.data.attributes.sort).map(e=>({id:e.data.id,name:e.data.attributes.name})),[l]);(0,n.useEffect)(()=>{if(re.current&&clearTimeout(re.current),!p.trim())return D([]),void z(!1);z(!0);const e=++oe.current;return re.current=setTimeout(async()=>{try{const t=await y.r.searchByName({name:p.trim(),page:0,pageSize:u});if(e!==oe.current)return;D(t.data.map(e=>({id:e.id,attributes:{name:e.name,avatarUrl:e.avatarUrl,heroPicture:e.heroPicture,bio:e.bio}})))}catch(t){if(e!==oe.current)return;D([])}finally{e===oe.current&&z(!1)}},400),()=>{re.current&&clearTimeout(re.current)}},[p,u]);const de=(0,n.useCallback)(async function(e,t){let a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;if("mybots"===e)return++ne.current,T([]),O(0),J(!1),void $(!1);const l=++ne.current;0===a?(T([]),J(!0)):$(!0);try{const o=await y.r.getByTag(String(e),a,u,t,m);if(l!==ne.current)return;const n=(0,b.ph)(o.data,null===r||void 0===r?void 0:r.id);T(e=>0===a?n:(0,b.PZ)([...e,...n])),O(a),o.meta&&le((0,b.we)(o.meta))}catch(o){if(l!==ne.current)return;0===a&&T([])}finally{l===ne.current&&(J(!1),$(!1))}},[u,null===r||void 0===r?void 0:r.id,m]);(0,n.useEffect)(()=>{if(!_&&ie.length>0){const e=ie[0].id;N(e)}},[ie,_]),(0,n.useEffect)(()=>(_&&(le(!1),O(0),de(_,(0,A.o)(w))),()=>{++ne.current}),[_,w,de]);const ce=(0,n.useCallback)(async e=>{N(e),f(""),le(!1),O(0)},[]),ue=(0,n.useCallback)(async e=>{M(e)},[]),me=(0,n.useCallback)(()=>{p.trim()||q||("mybots"!==_?ae||Y||K||!_||de(_,(0,A.o)(w),L+1):d&&
1!c&&i())},[ae,Y,K,q,_,p,de,w,L,d,c,i]),ve=(0,n.useMemo)(()=>p.trim()?R:"mybots"===_?se:E,[p,R,_,E,se]),he=(0,n.useCallback)(()=>{f(""),N(""),M("any"),T([]),D([]),le(!1)},[]),pe="mybots"===_;return{bots:(0,b.PZ)(ve),categories:ie,activeCategory:_,searchQuery:p,genderFilter:w,hasMyBots:s.length>0,isLoading:q||Y,isLoadingMore:pe?c:K,isEnd:pe?!d:ae,setSearchQuery:f,selectCategory:ce,changeGenderFilter:ue,loadMore:me,reset:he}})(),u=c.bots,m=c.categories,h=c.activeCategory,pe=c.searchQuery,ge=c.genderFilter,xe=c.hasMyBots,ye=c.isLoading,be=c.isLoadingMore,Ae=c.isEnd,fe=c.setSearchQuery,je=c.selectCategory,Ce=c.changeGenderFilter,_e=c.loadMore,Ne=c.reset,ke=(0,n.useState)(!1),Ie=(0,o.A)(ke,2),we=Ie[0],Me=Ie[1],Se=(0,n.useState)(!1),Pe=(0,o.A)(Se,2),Ee=Pe[0],Te=Pe[1],Be=(0,n.useState)(!0),Ue=(0,o.A)(Be,2),Le=Ue[0],Oe=Ue[1],Fe=(0,n.useRef)(null),Ge=(0,n.useRef)(null),Re=(0,n.useRef)(null),De=(0,n.useRef)(null),Ve=(0,n.useRef)(null);(0,n.useEffect)(()=>{l&&(Ne(),Me(!1))},[l,Ne]),(0,n.useEffect)(()=>(l&&(document.body.style.overflow="hidden"),()=>{document.body.style.overflow=""}),[l]),(0,n.useEffect)(()=>{if(!we)return;const e=e=>{Ge.current&&!Ge.current.contains(e.target)&&Fe.current&&!Fe.current.contains(e.target)&&Me(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[we]);const We=(0,n.useCallback)(()=>{Re.current&&(Re.current.scrollLeft+=200)},[]),qe=(0,n.useCallback)(()=>{Re.current&&(Re.current.scrollLeft-=200)},[]),ze=(0,n.useCallback)(()=>{const e=Re.current;e&&(Te(e.scrollLeft>0),Oe(e.scrollLeft<e.scrollWidth-e.clientWidth-10))},[]);(0,n.useEffect)(()=>{l&&ze()},[l,m,ze]),(0,n.useEffect)(()=>{if(!l||Ae)return;const e=Ve.current,t=De.current;if(!e||!t)return;const a=new IntersectionObserver(e=>{e[0].isIntersecting&&_e()},{root:t,rootMargin:"200px"});return a.observe(e),()=>a.disconnect()},[l,Ae,_e,u.length]),(0,n.useEffect)(()=>{if(!l)return;const e=De.current;if(!e)return;e.scrollTop=0;const t=requestAnimationFrame(()=>{e.scrollTop=0});return()=>cancelAnimationFrame(t)},[l,h,ge,pe]),(0,n.useEffect)(()=>{if(!l)return;const e=De.current;e&&(e.scrollTop=0)},[l,h,ge,pe,null===(t=u[0])||void 0===t?void 0:t.id]);const He=(0,n.useCallback)(e=>{s(e),r()},[s,r]);return l?(0,ce.jsx)(v.A,{open:l,className:p()(j,{[se]:d}),onClose:r,children:(0,ce.jsxs)("div",{className:p()(C,{[ie]:d}),children:[(0,ce.jsx)("h2",{className:_,children:"Create photo with..."}),(0,ce.jsx)("button",{className:N,onClick:r,children:"\u2715"}),(0,ce.jsxs)("div",{className:k,children:[(0,ce.jsx)(me,{}),(0,ce.jsx)("input",{className:I,type:"text",placeholder:"Search...",value:pe,onChange:e=>fe(e.target.value),autoFocus:!d})]}),(0,ce.jsxs)("div",{className:w,children:[(0,ce.jsx)("div",{ref:Re,className:p()(V,"hide-scrollbar"),onScroll:ze,children:(0,ce.jsxs)("div",{className:W,children:[(0,ce.jsx)("div",{className:M,children:(0,ce.jsxs)("button",{ref:Fe,className:p()(S,{[P]:"any"!==ge}),onClick:()=>Me(!we),children:[(0,ce.jsxs)("span",{className:E,children:[(0,ce.jsx)(he,{}),"any"!==ge&&(0,ce.jsx)("span",{className:B})]}),"any"!==ge&&(0,ce.jsx)("span",{className:T,children:null===(a=ve.find(e=>e.value===ge))||void 0===a?void 0:a.label})]})}),(0,ce.jsx)("div",{className:U}),xe&&(0,ce.jsx)("button",{className:p()(Z,{[Y]:"mybots"===h&&!pe}),onClick:()=>je("mybots"),children:"My bots"}),m.map(e=>(0,ce.jsx)("button",{className:p()(Z,{[Y]:h===e.id&&!pe}),onClick:()=>je(e.id),children:e.name},e.id))]})}),Ee&&(0,ce.jsx)("button",{className:p()(q,z),onClick:qe,children:(0,ce.jsx)(f.h,{})}),Le&&(0,ce.jsx)("button",{className:p()(q,H),onClick:We,children:(0,ce.jsx)(f.h,{})}),we&&(0,ce.jsx)("div",{ref:Ge,className:L,children:ve.map(e=>(0,ce.jsxs)("button",{className:p()(O,{[R]:ge===e.value}),onClick:()=>{Ce(e.value),Me(!1)},children:[(0,ce.jsx)("span",{className:F,children:e.emoji}),(0,ce.jsx)("span",{className:G,children:e.label}),ge===e.value&&(0,ce.jsx)("span",{className:D,children:"\u2713"})]},e.value))})]}),(0,ce.jsxs)("div",{className:J,children:[(0,ce.jsx)("div",{ref:De,className:p()(X,{[de]:d},"thin-scrollbar"),children:ye&&0===u.length?(0,ce.jsx)(ce.Fragment,{children:Array.from({length:12}).map((e,t)=>(0,ce.jsx)("div",{className:K},t))}):0===u.length?(0,ce.jsx)("div",{className:$,children:"No bots found"}):(0,ce.jsxs)(ce.Fragment,{children:[u.map(e=>{const t=i===e.id;return(0,ce.jsxs)("button",{className:p()(te,{[ae]:t}),onClick:()=>He(e),children:[(0,ce.jsx)("img",{className:le,src:e.attributes.heroPicture||e.attributes.avatarUrl,alt:e.attributes.name,loading:"lazy"}),t&&(0,ce.jsx)("div",{className:re,children:(0,ce.jsx)(ue,{})}),(0,ce.jsx)("div",{className:oe,children:(0,ce.jsx)("span",{className:ne,children:e.attributes.name})})]},e.id)}),be&&Array.from({length:6}).map((e,t)=>(0,ce.jsx)("div",{className:K},"more-".concat(t))),!Ae&&(0,ce.jsx)("div",{ref:Ve,className:ee})]})}),(0,ce.jsx)("div",{className:Q})]})]})}):null},ge=(0,n.memo)(pe);var xe=a(90210);const ye="ActionPickerModal_modal__JZW3A",be="ActionPickerModal_modalInner__Eu2rS",Ae="ActionPickerModal_title__x5VgG",fe="ActionPickerModal_closeBtn__uJ25o",je="ActionPickerModal_grid__6+qrf",Ce="ActionPickerModal_gridFade__xALPy",_e="ActionPickerModal_skeletonCard__0Dk0d",Ne="ActionPickerModal_actionCard__+Snsl",ke="ActionPickerModal_actionCardSelected__XfEdL",Ie="ActionPickerModal_actionImage__lLDOt",we="ActionPickerModal_nameOverlay__ljSxP",Me="ActionPickerModal_nameText__0XFPC",Se="ActionPickerModal_actionVideo__SRoS2",Pe="ActionPickerModal_checkmark__BaDJt",Ee="ActionPickerModal_modalMobile__guOy9",Te="ActionPickerModal_modalInnerMobile__-Y6ME",Be="ActionPickerModal_gridMobile__fx+Vr",Ue=()=>(0,ce.jsxs)("svg",{width:"23",height:"23",viewBox:"0 0 23 23",fill:"none",children:[(0,ce.jsx)("rect",{x:"0.75",y:"0.75",width:"21.5",height:"21.5",rx:"10.75",fill:"#7B5DF3"}),(0,ce.jsx)("rect",{x:"0.75",y:"0.75",width:"21.5",height:"21.5",rx:"10.75",stroke:"white",strokeWidth:"1.5"}
1),(0,ce.jsx)("path",{d:"M10.359 16.1693C10.048 16.1693 9.81483 16.0575 9.60383 15.8074L6.72765 12.4125C6.56663 12.2263 6.5 12.0507 6.5 11.8644C6.5 11.4387 6.8276 11.1301 7.2829 11.1301C7.55497 11.1301 7.74375 11.2259 7.92699 11.4441L10.3368 14.3707L15.0397 7.2297C15.2285 6.94236 15.4173 6.83594 15.7282 6.83594C16.178 6.83594 16.5 7.13924 16.5 7.55962C16.5 7.72457 16.45 7.89485 16.3168 8.08641L11.1197 15.7915C10.942 16.0469 10.6866 16.1693 10.359 16.1693Z",fill:"white"})]}),Le=e=>{let t=e.opened,a=e.onClose,l=e.onSelect,r=e.selectedActionId;const s=(0,n.useContext)(x.BR).isMobile,i=(0,n.useState)([]),d=(0,o.A)(i,2),c=d[0],u=d[1],m=(0,n.useState)(!1),h=(0,o.A)(m,2),g=h[0],y=h[1],b=(0,n.useState)(null),A=(0,o.A)(b,2),f=A[0],j=A[1];(0,n.useEffect)(()=>{t&&(y(!0),xe.d.getVideoActions().then(u).catch(()=>u([])).finally(()=>y(!1)))},[t]),(0,n.useEffect)(()=>(t&&(document.body.style.overflow="hidden"),()=>{document.body.style.overflow=""}),[t]);const C=(0,n.useCallback)(e=>{l(e),a()},[l,a]);return t?(0,ce.jsx)(v.A,{open:t,className:p()(ye,{[Ee]:s}),onClose:a,children:(0,ce.jsxs)("div",{className:p()(be,{[Te]:s}),children:[(0,ce.jsx)("h2",{className:Ae,children:"Choose an action"}),(0,ce.jsx)("button",{className:fe,onClick:a,children:"\u2715"}),(0,ce.jsx)("div",{className:p()(je,{[Be]:s},"thin-scrollbar"),children:g?(0,ce.jsx)(ce.Fragment,{children:Array.from({length:12}).map((e,t)=>(0,ce.jsx)("div",{className:_e},t))}):c.map(e=>{const t=r===e.id,a=!s&&f===e.id;return(0,ce.jsxs)("button",{className:p()(Ne,{[ke]:t}),onClick:()=>C(e),onMouseEnter:()=>!s&&j(e.id),onMouseLeave:()=>!s&&j(null),children:[(0,ce.jsx)("img",{className:Ie,src:e.imagePreviewUrl,alt:e.name,loading:"lazy"}),a&&e.videoPreviewUrl&&(0,ce.jsx)("video",{className:Se,src:e.videoPreviewUrl,autoPlay:!0,loop:!0,muted:!0,playsInline:!0,onCanPlay:e=>{e.target.style.opacity="1"}}),t&&(0,ce.jsx)("div",{className:Pe,children:(0,ce.jsx)(Ue,{})}),(0,ce.jsx)("div",{className:we,children:(0,ce.jsx)("span",{className:Me,children:e.name})})]},e.id)})}),(0,ce.jsx)("div",{className:Ce})]})}):null},Oe=(0,n.memo)(Le),Fe="ImagePickerModal_modal__qhQQD",Ge="ImagePickerModal_modalInner__ulLF4",Re="ImagePickerModal_title__80mY2",De="ImagePickerModal_closeBtn__v9rKz",Ve="ImagePickerModal_searchWrapper__prbSR",We="ImagePickerModal_searchInput__6g8Xu",qe="ImagePickerModal_tabsRow__0KrMA",ze="ImagePickerModal_tabs__RCc9l",He="ImagePickerModal_scrollButton__puObs",Ze="ImagePickerModal_scrollButtonLeft__w0ydO",Ye="ImagePickerModal_scrollButtonRight__eSID9",Je="ImagePickerModal_tab__LjCSa",Xe="ImagePickerModal_tabActive__vyn5w",Qe="ImagePickerModal_tabAvatar__Ezzah",Ke="ImagePickerModal_gridWrapper__GT1nr",$e="ImagePickerModal_grid__ZphGk",et="ImagePickerModal_gridFade__y5on7",tt="ImagePickerModal_skeletonCard__TV0lE",at="ImagePickerModal_empty__GM4YT",lt="ImagePickerModal_imageCard__iNjyb",rt="ImagePickerModal_imageCardSelected__0ixbj",ot="ImagePickerModal_image__GH8fa",nt="ImagePickerModal_checkmark__jvTS3",st="ImagePickerModal_modalMobile__P5bZh",it="ImagePickerModal_modalInnerMobile__DOwxh",dt="ImagePickerModal_gridMobile__jbHZY",ct=()=>(0,ce.jsxs)("svg",{width:"23",height:"23",viewBox:"0 0 23 23",fill:"none",children:[(0,ce.jsx)("rect",{x:"0.75",y:"0.75",width:"21.5",height:"21.5",rx:"10.75",fill:"#7B5DF3"}),(0,ce.jsx)("rect",{x:"0.75",y:"0.75",width:"21.5",height:"21.5",rx:"10.75",stroke:"white",strokeWidth:"1.5"}),(0,ce.jsx)("path",{d:"M10.359 16.1693C10.048 16.1693 9.81483 16.0575 9.60383 15.8074L6.72765 12.4125C6.56663 12.2263 6.5 12.0507 6.5 11.8644C6.5 11.4387 6.8276 11.1301 7.2829 11.1301C7.55497 11.1301 7.74375 11.2259 7.92699 11.4441L10.3368 14.3707L15.0397 7.2297C15.2285 6.94236 15.4173 6.83594 15.7282 6.83594C16.178 6.83594 16.5 7.13924 16.5 7.55962C16.5 7.72457 16.45 7.89485 16.3168 8.08641L11.1197 15.7915C10.942 16.0469 10.6866 16.1693 10.359 16.1693Z",fill:"white"})]}),ut=()=>(0,ce.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,ce.jsx)("circle",{cx:"11",cy:"11",r:"7"}),(0,ce.jsx)("path",{d:"M21 21l-4.35-4.35"})]}),mt=e=>{let t=e.opened,a=e.onClose,l=e.onSelect,r=e.selectedImageUrl,s=e.isMobile,i=e.loadMoreBots,d=e.hasMoreBots;
1const c=(0,n.useContext)(x.BR).visitedChats,u=(0,n.useState)(null),m=(0,o.A)(u,2),h=m[0],g=m[1],y=(0,n.useState)([]),b=(0,o.A)(y,2),A=b[0],j=b[1],C=(0,n.useState)([]),_=(0,o.A)(C,2),N=_[0],k=_[1],I=(0,n.useState)(!1),w=(0,o.A)(I,2),M=w[0],S=w[1],P=(0,n.useState)(null),E=(0,o.A)(P,2),T=E[0],B=E[1],U=(0,n.useState)(!1),L=(0,o.A)(U,2),O=L[0],F=L[1],G=(0,n.useState)(!1),R=(0,o.A)(G,2),D=R[0],V=R[1],W=(0,n.useState)(!1),q=(0,o.A)(W,2),z=q[0],H=q[1],Z=(0,n.useState)(""),Y=(0,o.A)(Z,2),J=Y[0],X=Y[1],Q=(0,n.useState)(0),K=(0,o.A)(Q,2),$=K[0],ee=K[1],te=(0,n.useState)(1),ae=(0,o.A)(te,2),le=ae[0],re=ae[1],oe=(0,n.useRef)(null),ne=(0,n.useRef)(null),se=(0,n.useRef)(!1),ie=(0,n.useState)(!1),de=(0,o.A)(ie,2),ue=de[0],me=de[1],ve=(0,n.useState)(!0),he=(0,o.A)(ve,2),pe=he[0],ge=he[1],ye=(0,n.useRef)(null),be=(0,n.useRef)(0),Ae=(0,n.useRef)(1),fe=(0,n.useRef)(null),je=(0,n.useRef)(!1),Ce=(0,n.useRef)(null),_e=(0,n.useRef)(!1);be.current=$,Ae.current=le,fe.current=h,je.current=M,Ce.current=T,_e.current=O;const Ne=(0,n.useMemo)(()=>{const e=new Set,t=[];for(const l of c){var a;if("group-chat"===l.type||null===(a=l.botIds)||void 0===a||!a.length)continue;const r=l.botIds[0];e.has(r)||(e.add(r),t.push({botId:r,name:l.name||"",avatar:l.avatarUrl||""}))}return t},[c]),ke=(0,n.useMemo)(()=>{if(!J.trim())return Ne;const e=J.toLowerCase();return Ne.filter(t=>t.name.toLowerCase().includes(e))},[Ne,J]);(0,n.useEffect)(()=>{t&&(g(null),X(""),j([]),k([]),S(!1),B(null),F(!1),ee(0),re(1),se.current=!1)},[t]),(0,n.useEffect)(()=>{if(!t)return;const e=window.scrollY;return document.body.style.position="fixed",document.body.style.top="-".concat(e,"px"),document.body.style.width="100%",document.body.style.overflow="hidden",()=>{document.body.style.position="",document.body.style.top="",document.body.style.width="",document.body.style.overflow="",window.scrollTo(0,e)}},[t]);const Ie=(0,n.useCallback)(async e=>{const t=await xe.d.getCommunityMedia(e,20),a=t.items.filter(e=>"image"===e.type);k(t=>e?[...t,...a]:a),B(t.nextCursor),F(null!==t.nextCursor)},[]),we=(0,n.useCallback)(async(e,t)=>{if(!se.current){se.current=!0,0===e?(V(!0),j([])):H(!0);try{const l=await xe.d.getMedia({botId:null!==t?String(t):void 0,type:"image",status:"completed",page:e,size:20});if(0===e){j(l.items),ee(l.page),re(l.pages);const e=0===l.items.length&&null===t;if(S(e),e)try{await Ie()}catch(a){k([]),F(!1)}}else j(e=>[...e,...l.items]),ee(l.page),re(l.pages)}catch(l){if(0===e){j([]);const e=null===t;if(S(e),e)try{await Ie()}catch(r){k([]),F(!1)}}}finally{se.current=!1,V(!1),H(!1)}}},[Ie]),Me=(0,n.useCallback)(async()=>{if(!se.current&&_e.current&&Ce.current){se.current=!0,H(!0);try{await Ie(Ce.current)}catch(e){}finally{se.current=!1,H(!1)}}},[Ie]);(0,n.useEffect)(()=>{t&&(ee(0),re(1),S(!1),k([]),B(null),F(!1),we(0,h))},[t,h,we]),(0,n.useEffect)(()=>{const e=ye.current,a=oe.current;if(!e||!a||!t)return;const l=new IntersectionObserver(e=>{(0,o.A)(e,1)[0].isIntersecting&&(je.current?Me():be.current+1<Ae.current&&we(be.current+1,fe.current))},{root:a,threshold:0});return l.observe(e),()=>l.disconnect()},[we,Me,t,h,D,M]),(0,n.useEffect)(()=>{t&&d&&i&&i()},[t,d,i]);const Se=(0,n.useCallback)(e=>{l(e.url,e.id,e.botId),a()},[l,a]),Pe=(0,n.useCallback)(()=>{const e=ne.current;e&&(me(e.scrollLeft>0),ge(e.scrollLeft<e.scrollWidth-e.clientWidth-10))},[]),Ee=(0,n.useCallback)(()=>{ne.current&&(ne.current.scrollLeft+=200)},[]),Te=(0,n.useCallback)(()=>{ne.current&&(ne.current.scrollLeft-=200)},[]);if((0,n.useEffect)(()=>{t&&Pe()},[t,Pe,ke]),!t)return null;const Be=M?N:A;return(0,ce.jsx)(v.A,{open:t,className:p()(Fe,{[st]:s}),onClose:a,children:(0,ce.jsxs)("div",{className:p()(Ge,{[it]:s}),children:[(0,ce.jsx)("h2",{className:Re,children:"Choose image"}),(0,ce.jsx)("button",{className:De,onClick:a,children:"\u2715"}),(0,ce.jsxs)("div",{className:Ve,children:[(0,ce.jsx)(ut,{}),(0,ce.jsx)("input",{className:We,type:"text",placeholder:"Search",value:J,onChange:e=>X(e.target.value)})]}),(0,ce.jsxs)("div",{className:qe,children:[(0,ce.jsxs)("div",{ref:ne,className:p()(ze,"hide-scrollbar"),onScroll:Pe,children:[(0,ce.jsx)("button",{className:p()(Je,{[Xe]:null===h&&!J}),onClick:()=>g(null),children:"All"}),ke.map(e=>(0,ce.jsxs)("button",{className:p()(Je,{[Xe]:h===e.botId}),onClick:()=>g(e.botId),children:[(0,ce.jsx)("img",{className:Qe,src:e.avatar,alt:e.name}),(0,ce.jsx)("span",{children:e.name})]},e.botId))]}),ue&&(0,ce.jsx)("button",{className:p()(He,Ze),onClick:Te,children:(0,ce.jsx)(f.h,{})}),pe&&(0,ce.jsx)("button",{className:p()(He,Ye),onClick:Ee,children:(0,ce.jsx)(f.h,{})})]}),(0,ce.jsxs)("div",{className:Ke,children:[(0,ce.jsxs)("div",{ref:oe,className:p()($e,{[dt]:s},"thin-scrollbar"),children:[D?Array.from({length:12}).map((e,t)=>(0,ce.jsx)("div",{className:tt},t)):0===Be.length?(0,ce.jsx)("div",{className:at,children:"No images found"}):Be.map(e=>{const t=r===e.url;return(0,ce.jsxs)("button",{className:p()(lt,{[rt]:t}),onClick:()=>Se(e),children:[(0,ce.jsx)("img",{className:ot,src:e.previewUrl||e.url,alt:"",loading:"lazy",onError:t=>{const a=t.currentTarget;e.previewUrl&&a.src!==e.url&&(a.src=e.url)}}),t&&(0,ce.jsx)("div",{className:nt,children:(0,ce.jsx)(ct,{})})]},e.id)}),z&&Array.from({length:6}).map((e,t)=>(0,ce.jsx)("div",{className:tt},"more-".concat(t))),(0,ce.jsx)("div",{ref:ye,style:{height:1,gridColumn:"1 / -1"}})]}),(0,ce.jsx)("div",{className:et})]})]})})},vt=(0,n.memo)(mt),ht=()=>(0,ce.jsxs)("svg",{width:"23",height:"23",viewBox:"0 0 23 23",fill:"none",children:[(0,ce.jsx)("rect",{x:"0.75",y:"0.75",width:"21.5",height:"21.5",rx:"10.75",fill:"#7B5DF3"}),(0,ce.jsx)("rect",{x:"0.75",y:"0.75",width:"21.5",height:"21.5",rx:"10.75",stroke:"white",strokeWidth:"1.5"}
1),(0,ce.jsx)("path",{d:"M10.359 16.1693C10.048 16.1693 9.81483 16.0575 9.60383 15.8074L6.72765 12.4125C6.56663 12.2263 6.5 12.0507 6.5 11.8644C6.5 11.4387 6.8276 11.1301 7.2829 11.1301C7.55497 11.1301 7.74375 11.2259 7.92699 11.4441L10.3368 14.3707L15.0397 7.2297C15.2285 6.94236 15.4173 6.83594 15.7282 6.83594C16.178 6.83594 16.5 7.13924 16.5 7.55962C16.5 7.72457 16.45 7.89485 16.3168 8.08641L11.1197 15.7915C10.942 16.0469 10.6866 16.1693 10.359 16.1693Z",fill:"white"})]});let pt=null,gt=null;const xt=new Set,yt=()=>pt?Promise.resolve(pt):gt||(gt=xe.d.getImagePoses().then(e=>(pt=e,e.forEach(e=>{const t=new Image;t.onload=()=>xt.add(e.imagePreviewUrl),t.src=e.imagePreviewUrl}),e)).catch(e=>{throw gt=null,e}),gt),bt=e=>{let t=e.src,a=e.alt;const l=(0,n.useState)(()=>xt.has(t)),r=(0,o.A)(l,2),s=r[0],i=r[1],d=(0,n.useCallback)(()=>{xt.add(t),i(!0)},[t]);return(0,ce.jsxs)(ce.Fragment,{children:[!s&&(0,ce.jsx)("div",{className:_e,style:{position:"absolute",inset:0,zIndex:1,borderRadius:0}}),(0,ce.jsx)("img",{className:Ie,src:t,alt:a,loading:"lazy",style:{objectPosition:"top"},onLoad:d})]})},At=e=>{let t=e.opened,a=e.onClose,l=e.onSelect,r=e.selectedPoseId,s=e.isMobile;const i=(0,n.useState)(pt||[]),d=(0,o.A)(i,2),c=d[0],u=d[1],m=(0,n.useState)(!pt),h=(0,o.A)(m,2),g=h[0],x=h[1];(0,n.useEffect)(()=>{if(t){if(pt)return u(pt),void x(!1);x(!0),yt().then(e=>u(e)).catch(()=>u([])).finally(()=>x(!1))}},[t]),(0,n.useEffect)(()=>(t&&(document.body.style.overflow="hidden"),()=>{document.body.style.overflow=""}),[t]);const y=(0,n.useCallback)(e=>{l(e),a()},[l,a]);return t?(0,ce.jsx)(v.A,{open:t,className:p()(ye,{[Ee]:s}),onClose:a,children:(0,ce.jsxs)("div",{className:p()(be,{[Te]:s}),children:[(0,ce.jsx)("h2",{className:Ae,children:"Choose a pose"}),(0,ce.jsx)("button",{className:fe,onClick:a,children:"\u2715"}),(0,ce.jsx)("div",{className:p()(je,{[Be]:s},"thin-scrollbar"),children:g?(0,ce.jsx)(ce.Fragment,{children:Array.from({length:12}).map((e,t)=>(0,ce.jsx)("div",{className:_e},t))}):c.map(e=>{const t=r===e.id;return(0,ce.jsxs)("button",{className:p()(Ne,{[ke]:t}),onClick:()=>y(e),children:[(0,ce.jsx)(bt,{src:e.imagePreviewUrl,alt:e.name}),t&&(0,ce.jsx)("div",{className:Pe,children:(0,ce.jsx)(ht,{})}),(0,ce.jsx)("div",{className:we,children:(0,ce.jsx)("span",{className:Me,children:e.name})})]},e.id)})}),(0,ce.jsx)("div",{className:Ce})]})}):null},ft=(0,n.memo)(At),jt=()=>(0,ce.jsxs)("svg",{width:"23",height:"23",viewBox:"0 0 23 23",fill:"none",children:[(0,ce.jsx)("rect",{x:"0.75",y:"0.75",width:"21.5",height:"21.5",rx:"10.75",fill:"#7B5DF3"}),(0,ce.jsx)("rect",{x:"0.75",y:"0.75",width:"21.5",height:"21.5",rx:"10.75",stroke:"white",strokeWidth:"1.5"}),(0,ce.jsx)("path",{d:"M10.359 16.1693C10.048 16.1693 9.81483 16.0575 9.60383 15.8074L6.72765 12.4125C6.56663 12.2263 6.5 12.0507 6.5 11.8644C6.5 11.4387 6.8276 11.1301 7.2829 11.1301C7.55497 11.1301 7.74375 11.2259 7.92699 11.4441L10.3368 14.3707L15.0397 7.2297C15.2285 6.94236 15.4173 6.83594 15.7282 6.83594C16.178 6.83594 16.5 7.13924 16.5 7.55962C16.5 7.72457 16.45 7.89485 16.3168 8.08641L11.1197 15.7915C10.942 16.0469 10.6866 16.1693 10.359 16.1693Z",fill:"white"})]});let Ct=null,_t=null;const Nt=new Set,kt=()=>Ct?Promise.resolve(Ct):_t||(_t=xe.d.getImageOutfits().then(e=>(Ct=e,e.forEach(e=>{const t=new Image;t.onload=()=>Nt.add(e.imagePreviewUrl),t.src=e.imagePreviewUrl}),e)).catch(e=>{throw _t=null,e}),_t),It=e=>{let t=e.src,a=e.alt;const l=(0,n.useState)(()=>Nt.has(t)),r=(0,o.A)(l,2),s=r[0],i=r[1],d=(0,n.useCallback)(()=>{Nt.add(t),i(!0)},[t]);return(0,ce.jsxs)(ce.Fragment,{children:[!s&&(0,ce.jsx)("div",{className:_e,style:{position:"absolute",inset:0,zIndex:1,borderRadius:0}}),(0,ce.jsx)("img",{className:Ie,src:t,alt:a,loading:"lazy",style:{objectPosition:"top"},onLoad:d})]})},wt=e=>{let t=e.opened,a=e.onClose,l=e.onSelect,r=e.selectedOutfitId,s=e.isMobile;const i=(0,n.useState)(Ct||[]),d=(0,o.A)(i,2),c=d[0],u=d[1],m=(0,n.useState)(!Ct),h=(0,o.A)(m,2),g=h[0],x=h[1];(0,n.useEffect)(()=>{if(t){if(Ct)return u(Ct),void x(!1);x(!0),kt().then(e=>u(e)).catch(()=>u([])).finally(()=>x(!1))}},[t]);const y=(0,n.useCallback)(e=>{l(e),a()},[l,a]);return t?(0,ce.jsx)(v.A,{open:t,className:p()(ye,{[Ee]:s}),onClose:a,children:(0,ce.jsxs)("div",{className:p()(be,{[Te]:s}),children:[(0,ce.jsx)("h2",{className:Ae,children:"Choose an outfit"}),(0,ce.jsx)("button",{type:"button",className:fe,onClick:a,"aria-label":"Close",children:"\u2715"}),(0,ce.jsx)("div",{className:p()(je,{[Be]:s},"thin-scrollbar"),children:g?(0,ce.jsx)(ce.Fragment,{children:Array.from({length:12}).map((e,t)=>(0,ce.jsx)("div",{className:_e},t))}):c.map(e=>{const t=r===e.id;return(0,ce.jsxs)("button",{className:p()(Ne,{[ke]:t}),onClick:()=>y(e),children:[(0,ce.jsx)(It,{src:e.imagePreviewUrl,alt:e.name}),t&&(0,ce.jsx)("div",{className:Pe,children:(0,ce.jsx)(jt,{})}),(0,ce.jsx)("div",{className:we,children:(0,ce.jsx)("span",{className:Me,children:e.name})})]},e.id)})}),(0,ce.jsx)("div",{className:Ce})]})}):null},Mt=(0,n.memo)(wt),St=()=>(0,ce.jsxs)("svg",{width:"23",height:"23",viewBox:"0 0 23 23",fill:"none",children:[(0,ce.jsx)("rect",{x:"0.75",y:"0.75",width:"21.5",height:"21.5",rx:"10.75",fill:"#7B5DF3"}),(0,ce.jsx)("rect",{x:"0.75",y:"0.75",width:"21.5",height:"21.5",rx:"10.75",stroke:"white",strokeWidth:"1.5"}
1),(0,ce.jsx)("path",{d:"M10.359 16.1693C10.048 16.1693 9.81483 16.0575 9.60383 15.8074L6.72765 12.4125C6.56663 12.2263 6.5 12.0507 6.5 11.8644C6.5 11.4387 6.8276 11.1301 7.2829 11.1301C7.55497 11.1301 7.74375 11.2259 7.92699 11.4441L10.3368 14.3707L15.0397 7.2297C15.2285 6.94236 15.4173 6.83594 15.7282 6.83594C16.178 6.83594 16.5 7.13924 16.5 7.55962C16.5 7.72457 16.45 7.89485 16.3168 8.08641L11.1197 15.7915C10.942 16.0469 10.6866 16.1693 10.359 16.1693Z",fill:"white"})]});let Pt=null,Et=null;const Tt=new Set,Bt=()=>Pt?Promise.resolve(Pt):Et||(Et=xe.d.getImageBackgrounds().then(e=>(Pt=e,e.forEach(e=>{const t=new Image;t.onload=()=>Tt.add(e.imagePreviewUrl),t.src=e.imagePreviewUrl}),e)).catch(e=>{throw Et=null,e}),Et),Ut=e=>{let t=e.src,a=e.alt;const l=(0,n.useState)(()=>Tt.has(t)),r=(0,o.A)(l,2),s=r[0],i=r[1],d=(0,n.useCallback)(()=>{Tt.add(t),i(!0)},[t]);return(0,ce.jsxs)(ce.Fragment,{children:[!s&&(0,ce.jsx)("div",{className:_e,style:{position:"absolute",inset:0,zIndex:1,borderRadius:0}}),(0,ce.jsx)("img",{className:Ie,src:t,alt:a,loading:"lazy",style:{objectPosition:"top"},onLoad:d})]})},Lt=e=>{let t=e.opened,a=e.onClose,l=e.onSelect,r=e.selectedBackgroundId,s=e.isMobile;const i=(0,n.useState)(Pt||[]),d=(0,o.A)(i,2),c=d[0],u=d[1],m=(0,n.useState)(!Pt),h=(0,o.A)(m,2),g=h[0],x=h[1];(0,n.useEffect)(()=>{if(t){if(Pt)return u(Pt),void x(!1);x(!0),Bt().then(e=>u(e)).catch(()=>u([])).finally(()=>x(!1))}},[t]);const y=(0,n.useCallback)(e=>{l(e),a()},[l,a]);return t?(0,ce.jsx)(v.A,{open:t,className:p()(ye,{[Ee]:s}),onClose:a,children:(0,ce.jsxs)("div",{className:p()(be,{[Te]:s}),children:[(0,ce.jsx)("h2",{className:Ae,children:"Choose a background"}),(0,ce.jsx)("button",{type:"button",className:fe,onClick:a,"aria-label":"Close",children:"\u2715"}),(0,ce.jsx)("div",{className:p()(je,{[Be]:s},"thin-scrollbar"),children:g?(0,ce.jsx)(ce.Fragment,{children:Array.from({length:12}).map((e,t)=>(0,ce.jsx)("div",{className:_e},t))}):c.map(e=>{const t=r===e.id;return(0,ce.jsxs)("button",{className:p()(Ne,{[ke]:t}),onClick:()=>y(e),children:[(0,ce.jsx)(Ut,{src:e.imagePreviewUrl,alt:e.name}),t&&(0,ce.jsx)("div",{className:Pe,children:(0,ce.jsx)(St,{})}),(0,ce.jsx)("div",{className:we,children:(0,ce.jsx)("span",{className:Me,children:e.name})})]},e.id)})}),(0,ce.jsx)("div",{className:Ce})]})}):null},Ot=(0,n.memo)(Lt);var Ft=a(10126),Gt=a(98078),Rt=a(35053),Dt=a(79846),Vt=a(17992),Wt=a(68098),qt=a(59063),zt=a(8130),Ht=a(23543),Zt=a(27228),Yt=a(8881),Jt=a(34135),Xt=a(9696);const Qt=()=>{const e=(0,n.useState)(!1),t=(0,o.A)(e,2),a=t[0],l=t[1],r=(0,n.useRef)(null);return(0,n.useEffect)(()=>{if(!a)return;const e=e=>{r.current&&!r.current.contains(e.target)&&l(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[a]),(0,n.useEffect)(()=>{if(!a)return;const e=setTimeout(()=>l(!1),4e3);return()=>clearTimeout(e)},[a]),(0,ce.jsxs)("span",{ref:r,className:Jt.A.privateTooltipWrap,children:[(0,ce.jsx)("span",{className:Jt.A.privateInfoBtn,onClick:e=>{e.stopPropagation(),l(!a)},children:(0,ce.jsx)(Xt.mo,{})}),a&&(0,ce.jsx)("div",{className:Jt.A.privateTooltip,children:'When enabled, your generated content will be shared in the "Community feed"'})]})},Kt=e=>{let t=e.models,a=e.selectedModel,l=e.onSelect,r=e.isOpen,o=e.onClose,s=e.isMobile,i=e.modalTitle,d=void 0===i?"Image model":i;const c=(0,n.useRef)(null);(0,n.useEffect)(()=>(r&&s&&(document.body.style.overflow="hidden"),()=>{document.body.style.overflow=""}),[r,s]),(0,n.useEffect)(()=>{if(!r||s)return;const e=e=>{!c.current||c.current.contains(e.target)||e.target.closest("[data-model-selector]")||o()};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[r,s,o]),(0,n.useEffect)(()=>{if(!r||s)return;const e=requestAnimationFrame(()=>{var e;null===(e=c.current)||void 0===e||e.scrollIntoView({block:"nearest"})});return()=>cancelAnimationFrame(e)},[r,s]);const u=(0,ce.jsx)("div",{className:Jt.A.modelList,children:t.map(e=>{const t=(null===a||void 0===a?void 0:a.id)===e.id;return(0,ce.jsxs)("button",{className:p()(Jt.A.modelOption,{[Jt.A.modelOptionSelected]:t}),onClick:()=>{l(e),o()},children:[(0,ce.jsx)("img",{className:Jt.A.modelOptionIcon,src:e.logoUrl,alt:e.name}),(0,ce.jsxs)("div",{className:Jt.A.modelOptionInfo,children:[(0,ce.jsx)("div",{className:Jt.A.modelOptionNameRow,children:(0,ce.jsx)("span",{className:Jt.A.modelOptionName,children:e.name})}),(0,ce.jsx)("span",{className:Jt.A.modelOptionDesc,children:e.description})]}),t?(0,ce.jsx)(Xt.ZZ,{}):(0,ce.jsx)(Xt.cV,{})]},e.id)})});return r?s?(0,ce.jsx)(v.A,{open:r,className:Jt.A.modelModal,onClose:o,children:(0,ce.jsxs)("div",{className:Jt.A.modelModalInner,children:[(0,ce.jsx)("button",{className:Jt.A.modelModalClose,onClick:o,children:"\u2715"}),(0,ce.jsx)("h2",{className:Jt.A.modelModalTitle,children:d}),u]})}):(0,ce.jsx)("div",{ref:c,className:Jt.A.modelDropdown,children:u}):null},$t="DurationSlider_wrap__X40fy",ea="DurationSlider_track__eYBpb",ta="DurationSlider_trackDragging__ukHpX",aa="DurationSlider_trackBg__rf-M7",la="DurationSlider_trackFill__VHeY3",ra="DurationSlider_dot__f4q73",oa="DurationSlider_dotActive__7qEJv",na="DurationSlider_handle__mTaq1",sa="DurationSlider_labels__5yksJ",ia="DurationSlider_label__FjWaq",da="DurationSlider_labelActive__+STD9",ca=e=>{let t=e.values,a=e.value,l=e.onChange;
1const r=(0,n.useRef)(null),s=(0,n.useState)(!1),i=(0,o.A)(s,2),d=i[0],c=i[1],u=Math.max(0,t.indexOf(a)),m=Math.max(0,t.length-1),v=e=>0===m?50:e/m*100,h=(0,n.useCallback)(e=>{const a=r.current;if(!a||0===t.length)return-1;const l=a.getBoundingClientRect();if(0===l.width)return-1;const o=Math.min(1,Math.max(0,(e-l.left)/l.width));return Math.round(o*m)},[m,t.length]),g=(0,n.useCallback)(e=>{if(e<0||e>=t.length)return;const r=t[e];r!==a&&l(r)},[l,a,t]),x=e=>{c(!1);try{e.currentTarget.releasePointerCapture(e.pointerId)}catch(t){}};return(0,ce.jsxs)("div",{className:$t,children:[(0,ce.jsxs)("div",{ref:r,className:p()(ea,{[ta]:d}),role:"slider",tabIndex:0,"aria-valuemin":t[0],"aria-valuemax":t[m],"aria-valuenow":a,"aria-label":"Duration in seconds",onPointerDown:e=>{g(h(e.clientX)),c(!0),e.currentTarget.setPointerCapture(e.pointerId)},onPointerMove:e=>{d&&g(h(e.clientX))},onPointerUp:x,onPointerCancel:x,onKeyDown:e=>{"ArrowLeft"===e.key||"ArrowDown"===e.key?(e.preventDefault(),g(Math.max(0,u-1))):"ArrowRight"===e.key||"ArrowUp"===e.key?(e.preventDefault(),g(Math.min(m,u+1))):"Home"===e.key?(e.preventDefault(),g(0)):"End"===e.key&&(e.preventDefault(),g(m))},children:[(0,ce.jsx)("div",{className:aa}),(0,ce.jsx)("div",{className:la,style:{width:"".concat(v(u),"%")}}),t.map((e,t)=>(0,ce.jsx)("div",{className:p()(ra,{[oa]:t<=u}),style:{left:"".concat(v(t),"%")}},e)),(0,ce.jsx)("div",{className:na,style:{left:"".concat(v(u),"%")}})]}),(0,ce.jsx)("div",{className:sa,children:t.map((e,t)=>(0,ce.jsxs)("button",{type:"button",className:p()(ia,{[da]:t===u}),style:{left:"".concat(v(t),"%")},onClick:()=>g(t),children:[e," sec"]},e))})]})};var ua=a(86152),ma=a(82626),va=a(33508);const ha=[1,2,4,8,12],pa=[1,2,3,4],ga=e=>{const t=e.currentTarget,a=t.offsetHeight;t.style.height="auto";const l=Math.min(Math.max(t.scrollHeight,72),144);t.style.height="".concat(a,"px"),t.getBoundingClientRect(),t.style.height="".concat(l,"px")},xa=e=>{e.currentTarget.style.height=""},ya=()=>{const e=(0,n.useRef)(null),t=(0,n.useState)(!1),a=(0,o.A)(t,2),l=a[0],r=a[1],s=(0,n.useState)(!1),i=(0,o.A)(s,2),d=i[0],c=i[1],u=(0,n.useCallback)(()=>{const t=e.current;if(!t)return;const a=t.scrollTop>2,l=t.scrollTop+t.clientHeight<t.scrollHeight-2;r(e=>e===a?e:a),c(e=>e===l?e:l)},[]);return(0,n.useEffect)(u),(0,n.useEffect)(()=>{window.addEventListener("resize",u);const e=document.querySelector(".main-content-desk");return null===e||void 0===e||e.addEventListener("scroll",u,{passive:!0}),()=>{window.removeEventListener("resize",u),null===e||void 0===e||e.removeEventListener("scroll",u)}},[u]),{scrollRef:e,shadowTop:l,shadowBottom:d,updateShadows:u}},ba=e=>{let t=e.selectedCharacter,a=e.setSelectedCharacter,l=e.setIsCharacterModalOpen,r=e.numImages,o=e.setNumImages,n=e.discountsEnabled,s=e.prompt,i=e.setPrompt,d=e.energyCost,c=e.showEnergyCost,u=e.selectedModel,m=e.imageModels,v=e.isModelPickerOpen,h=e.setIsModelPickerOpen,g=e.onModelSelect,x=e.isMobile,y=e.selectedPose,b=e.setSelectedPose,A=(e.isPoseModalOpen,e.setIsPoseModalOpen),f=e.selectedOutfit,j=e.setSelectedOutfit,C=e.setIsOutfitModalOpen,_=e.selectedBackground,N=e.setSelectedBackground,k=e.setIsBackgroundModalOpen,I=e.onGenerate,w=e.isGenerating,M=e.validationErrors,S=e.onCreativeUpsell;const P=ya(),E=P.scrollRef,T=P.shadowTop,B=P.shadowBottom,U=P.updateShadows;return(0,ce.jsxs)(ce.Fragment,{children:[(0,ce.jsxs)("div",{className:Jt.A.formScrollWrap,children:[(0,ce.jsxs)("div",{className:Jt.A.formScroll,ref:E,onScroll:U,children:[(0,ce.jsxs)("div",{className:Jt.A.typeCards,children:[t?(0,ce.jsxs)("div",{className:Jt.A.typeCardSelected,children:[(0,ce.jsx)("img",{className:Jt.A.typeCardFullImage,src:t.attributes.heroPicture||t.attributes.avatarUrl,alt:t.attributes.name,onClick:()=>l(!0)}),(0,ce.jsx)("button",{className:Jt.A.typeCardRemove,onClick:()=>a(null),children:(0,ce.jsx)(Xt.YP,{})}),(0,ce.jsx)("span",{className:Jt.A.typeCardLabel,children:t.attributes.name})]}):(0,ce.jsxs)("button",{className:p()(Jt.A.typeCard,{[Jt.A.typeCardError]:null===M||void 0===M?void 0:M.character}),onClick:()=>l(!0),children:[(0,ce.jsx)(Xt.Dr,{}),(0,ce.jsx)("span",{children:"Character"}),(0,ce.jsx)("span",{className:Jt.A.typeCardSubtitle,children:"Required"})]}),y?(0,ce.jsxs)("div",{className:Jt.A.typeCardSelected,children:[(0,ce.jsx)("img",{className:Jt.A.typeCardFullImage,src:y.imagePreviewUrl,alt:y.name,onClick:()=>A(!0)}),(0,ce.jsx)("button",{className:Jt.A.typeCardRemove,onClick:()=>b(null),children:(0,ce.jsx)(Xt.YP,{})}),(0,ce.jsx)("span",{className:Jt.A.typeCardLabel,children:y.name})]}):(0,ce.jsxs)("button",{className:Jt.A.typeCard,onClick:()=>A(!0),children:[(0,ce.jsx)(Xt.x0,{}),(0,ce.jsx)("span",{children:"Pose"}),(0,ce.jsx)("span",{className:Jt.A.typeCardSubtitle,children:"Optional"})]}),_?(0,ce.jsxs)("div",{className:Jt.A.typeCardSelected,children:[(0,ce.jsx)("img",{className:Jt.A.typeCardFullImage,src:_.imagePreviewUrl,alt:_.name,onClick:()=>k(!0)}),(0,ce.jsx)("button",{className:Jt.A.typeCardRemove,onClick:()=>N(null),children:(0,ce.jsx)(Xt.YP,{})}),(0,ce.jsx)("span",{className:Jt.A.typeCardLabel,children:_.name})]}):(0,ce.jsxs)("button",{className:Jt.A.typeCard,onClick:()=>k(!0),children:[(0,ce.jsx)(Xt.Wm,{}
1),(0,ce.jsx)("span",{children:"Background"}),(0,ce.jsx)("span",{className:Jt.A.typeCardSubtitle,children:"Optional"})]}),f?(0,ce.jsxs)("div",{className:Jt.A.typeCardSelected,children:[(0,ce.jsx)("img",{className:Jt.A.typeCardFullImage,src:f.imagePreviewUrl,alt:f.name,onClick:()=>C(!0)}),(0,ce.jsx)("button",{className:Jt.A.typeCardRemove,onClick:()=>j(null),children:(0,ce.jsx)(Xt.YP,{})}),(0,ce.jsx)("span",{className:Jt.A.typeCardLabel,children:f.name})]}):(0,ce.jsxs)("button",{className:Jt.A.typeCard,onClick:()=>C(!0),children:[(0,ce.jsx)(Xt.V$,{}),(0,ce.jsx)("span",{children:"Outfit"}),(0,ce.jsx)("span",{className:Jt.A.typeCardSubtitle,children:"Optional"})]})]}),(0,ce.jsxs)("div",{className:Jt.A.section,children:[(0,ce.jsx)("div",{className:Jt.A.sectionLabel,children:"Prompt"}),(0,ce.jsxs)("div",{className:Jt.A.promptWrap,children:[(0,ce.jsx)("textarea",{className:p()(Jt.A.promptInput,{[Jt.A.promptInputError]:null===M||void 0===M?void 0:M.prompt}),placeholder:"Describe the scene you imagine",value:s,onChange:e=>i(e.target.value.slice(0,500)),onFocus:ga,onInput:ga,onBlur:xa,maxLength:500,rows:3}),(0,ce.jsxs)("span",{className:Jt.A.promptCounter,children:[s.length," / 500"]})]})]}),(0,ce.jsxs)("div",{className:p()(Jt.A.section,Jt.A.sectionRelative),children:[(0,ce.jsx)("div",{className:Jt.A.sectionLabel,children:"Generation model"}),(0,ce.jsxs)("button",{className:Jt.A.modelSelector,"data-model-selector":!0,onClick:()=>h(!v),children:[null!==u&&void 0!==u&&u.logoUrl?(0,ce.jsx)("img",{className:Jt.A.modelAvatarImg,src:u.logoUrl,alt:u.name}):(0,ce.jsx)("div",{className:Jt.A.modelAvatar}),(0,ce.jsx)("span",{className:Jt.A.modelName,children:(null===u||void 0===u?void 0:u.name)||"Basic"}),(0,ce.jsx)("span",{className:p()(Jt.A.chevron,{[Jt.A.chevronOpen]:v}),children:(0,ce.jsx)(Xt.zp,{})})]}),(0,ce.jsx)(Kt,{models:m,selectedModel:u,onSelect:g,isOpen:v,onClose:()=>h(!1),isMobile:x})]}),(0,ce.jsxs)("div",{className:Jt.A.section,children:[(0,ce.jsx)("div",{className:Jt.A.sectionLabel,children:"Number of images"}),(0,ce.jsx)("div",{className:Jt.A.numberOptions,children:ha.map(e=>{const t=n?(0,ma.y)(u,e):0;return(0,ce.jsxs)("button",{className:p()(Jt.A.numberBtn,{[Jt.A.numberBtnActive]:r===e}),onClick:()=>o(e),children:[e,t>0&&(0,ce.jsxs)("span",{className:Jt.A.numberBtnDiscount,children:["-",t,"%"]})]},e)})})]})]}),T&&(0,ce.jsx)("div",{className:Jt.A.formScrollShadowTop}),B&&(0,ce.jsx)("div",{className:Jt.A.formScrollShadowBottom})]}),(0,ce.jsx)(ua.V,{surface:"toggle_media_generator",className:Jt.A.creativeToggleRow,onBeforeOpen:S}),(0,ce.jsxs)("button",{className:p()(Jt.A.generateBtn,{[Jt.A.generateBtnDisabled]:w}),onClick:I,disabled:w,children:[w?(0,ce.jsxs)(ce.Fragment,{children:[(0,ce.jsx)(Xt.Nl,{}),(0,ce.jsx)("span",{children:"Generating..."})]}):(0,ce.jsxs)("span",{children:["Generate ",r," images"]}),c&&d>0&&(0,ce.jsxs)("span",{className:Jt.A.energyBadge,children:[(0,ce.jsx)(Xt.UE,{}),(0,ce.jsx)("span",{children:d})]})]})]})},Aa=e=>{e.selectedCharacter,e.setSelectedCharacter,e.setIsCharacterModalOpen;let t=e.numVideos,a=e.setNumVideos,l=e.duration,r=e.setDuration,o=e.isPrivate,n=e.setIsPrivate,s=e.prompt,i=e.setPrompt,d=e.energyCost,c=e.showEnergyCost,u=e.selectedVideoModel,m=e.videoModels,v=e.isVideoModelPickerOpen,h=e.setIsVideoModelPickerOpen,g=e.onVideoModelSelect,x=e.isMobile,y=e.selectedAction,b=e.setSelectedAction,A=(e.isActionModalOpen,e.setIsActionModalOpen),f=e.selectedVideoImage,j=e.setSelectedVideoImage,C=(e.isImagePickerOpen,e.setIsImagePickerOpen),_=e.onGenerate,N=e.isGenerating,k=e.videoValidationErrors,I=e.hideNumVideos,w=e.hidePrivacyToggle,M=e.imageEditable,S=void 0===M||M,P=e.generateLabel,E=e.onCreativeUpsell;const T=ya(),B=T.scrollRef,U=T.shadowTop,L=T.shadowBottom,O=T.updateShadows;return(0,ce.jsxs)(ce.Fragment,{children:[(0,ce.jsxs)("div",{className:Jt.A.formScrollWrap,children:[(0,ce.jsxs)("div",{className:Jt.A.formScroll,ref:B,onScroll:O,children:[(0,ce.jsxs)("div",{className:Jt.A.typeCards,children:[f?(0,ce.jsxs)("div",{className:Jt.A.typeCardSelected,children:[(0,ce.jsx)("img",{className:Jt.A.typeCardFullImage,src:f.url,alt:"Selected image",onClick:S?()=>C(!0):void 0}),S&&(0,ce.jsx)("button",{className:Jt.A.typeCardRemove,onClick:()=>j(null),children:(0,ce.jsx)(Xt.YP,{})})]}):(0,ce.jsxs)("button",{className:p()(Jt.A.typeCard,{[Jt.A.typeCardError]:null===k||void 0===k?void 0:k.image}),onClick:()=>C(!0),children:[(0,ce.jsx)(Xt.xf,{}),(0,ce.jsx)("span",{children:"Image"}),(0,ce.jsx)("span",{className:Jt.A.typeCardSubtitle,children:"Required"})]}),y?(0,ce.jsxs)("div",{className:Jt.A.typeCardSelected,onClick:()=>A(!0),children:[y.videoPreviewUrl?(0,ce.jsx)("video",{className:Jt.A.typeCardFullImage,src:y.videoPreviewUrl,poster:y.imagePreviewUrl,autoPlay:!0,loop:!0,muted:!0,playsInl
1ine:!0}):(0,ce.jsx)("img",{className:Jt.A.typeCardFullImage,src:y.imagePreviewUrl,alt:y.name}),(0,ce.jsx)("button",{className:Jt.A.typeCardRemove,onClick:e=>{e.stopPropagation(),b(null)},children:(0,ce.jsx)(Xt.YP,{})}),(0,ce.jsx)("span",{className:Jt.A.typeCardLabel,children:y.name})]}):(0,ce.jsxs)("button",{className:Jt.A.typeCard,onClick:()=>A(!0),children:[(0,ce.jsx)(Xt.M_,{}),(0,ce.jsx)("span",{children:"Action"}),(0,ce.jsx)("span",{className:Jt.A.typeCardSubtitle,children:"Optional"})]})]}),(0,ce.jsxs)("div",{className:Jt.A.section,children:[(0,ce.jsx)("div",{className:Jt.A.sectionLabel,children:"Prompt"}),(0,ce.jsxs)("div",{className:Jt.A.promptWrap,children:[(0,ce.jsx)("textarea",{className:Jt.A.promptInput,placeholder:"Describe the character action",value:s,onChange:e=>i(e.target.value.slice(0,500)),onFocus:ga,onInput:ga,onBlur:xa,maxLength:500,rows:3}),(0,ce.jsxs)("span",{className:Jt.A.promptCounter,children:[s.length," / 500"]})]})]}),(0,ce.jsxs)("div",{className:p()(Jt.A.section,Jt.A.sectionRelative),children:[(0,ce.jsx)("div",{className:Jt.A.sectionLabel,children:"Generation model"}),(0,ce.jsxs)("button",{className:Jt.A.modelSelector,"data-model-selector":!0,onClick:()=>h(!v),children:[null!==u&&void 0!==u&&u.logoUrl?(0,ce.jsx)("img",{className:Jt.A.modelAvatarImg,src:u.logoUrl,alt:u.name}):(0,ce.jsx)("div",{className:p()(Jt.A.modelAvatar,Jt.A.modelAvatarUltra)}),(0,ce.jsxs)("span",{className:Jt.A.modelName,children:[(null===u||void 0===u?void 0:u.name)||"Ultra model",u&&(0,ce.jsxs)("span",{className:Jt.A.modelSubtitle,children:[" ",u.description,u.isAudioSupported?" \xb7 Audio":""]})]}),(0,ce.jsx)("span",{className:p()(Jt.A.chevron,{[Jt.A.chevronOpen]:v}),children:(0,ce.jsx)(Xt.zp,{})})]}),(0,ce.jsx)(Kt,{models:m.map(e=>({id:e.id,name:e.name,description:"".concat(e.description).concat(e.isAudioSupported?" \xb7 Audio":""),logoUrl:e.logoUrl,price:e.oneSecondPrice,type:"video",accessLevel:e.accessLevel})),selectedModel:u?{id:u.id,name:u.name,description:u.description,logoUrl:u.logoUrl,price:u.oneSecondPrice,type:"video",accessLevel:u.accessLevel}:null,onSelect:e=>{const t=m.find(t=>t.id===e.id);t&&g(t)},isOpen:v,onClose:()=>h(!1),isMobile:x,modalTitle:"Video model"})]}),u&&u.availableDurations.length>0&&(0,ce.jsxs)("div",{className:Jt.A.section,children:[(0,ce.jsx)("div",{className:Jt.A.sectionLabel,children:"Duration"}),(0,ce.jsx)(ca,{values:u.availableDurations,value:l,onChange:r})]}),!I&&(0,ce.jsxs)("div",{className:Jt.A.section,children:[(0,ce.jsx)("div",{className:Jt.A.sectionLabel,children:"Number of videos"}),(0,ce.jsx)("div",{className:Jt.A.numberOptions,children:pa.map(e=>{const r=u?(0,va.oA)(u,l,e):0;return(0,ce.jsxs)("button",{className:p()(Jt.A.numberBtn,{[Jt.A.numberBtnActive]:t===e}),onClick:()=>a(e),children:[e,r>0&&(0,ce.jsxs)("span",{className:Jt.A.numberBtnDiscount,children:["-",r,"%"]})]},e)})})]}),!w&&(0,ce.jsxs)("div",{className:Jt.A.addon,children:[(0,ce.jsxs)("span",{children:["Share to Community ",(0,ce.jsx)(Qt,{})]}),(0,ce.jsx)("button",{className:p()(Jt.A.toggle,{[Jt.A.toggleActive]:!o}),onClick:()=>n(!o),children:(0,ce.jsx)("div",{className:Jt.A.toggleThumb})})]})]}),U&&(0,ce.jsx)("div",{className:Jt.A.formScrollShadowTop}),L&&(0,ce.jsx)("div",{className:Jt.A.formScrollShadowBottom})]}),(0,ce.jsx)(ua.V,{surface:"toggle_media_generator",className:Jt.A.creativeToggleRow,onBeforeOpen:E}),(0,ce.jsxs)("button",{className:p()(Jt.A.generateBtn,{[Jt.A.generateBtnDisabled]:N}),onClick:_,disabled:N,children:[N?(0,ce.jsxs)(ce.Fragment,{children:[(0,ce.jsx)(Xt.Nl,{}),(0,ce.jsx)("span",{children:"Generating..."})]}):(0,ce.jsx)("span",{children:null!==P&&void 0!==P?P:"Generate ".concat(t," video").concat(t>1?"s":"")}),c&&d>0&&(0,ce.jsxs)("span",{className:Jt.A.energyBadge,children:[(0,ce.jsx)(Xt.UE,{}),(0,ce.jsx)("span",{children:d})]})]})]})};var fa=a(41404),ja=a(6201),Ca=a(65472),_a=a(65861),Na=a(19472);const ka="media-generator-discounts",Ia=(0,_a.g)({key:ka,variants:[],readVariant:()=>{const e=(0,Ca.rl)(ka);return("string"===typeof(null===e||void 0===e?void 0:e.payload)?e.payload.trim():"")||(null===e||void 0===e?void 0:e.value)||(null===e||void 0===e?void 0:e.key)||null}});var wa=a(37131),Ma=a(40225),Sa=a(23883);const Pa=(0,n.memo)(e=>{let t=e.type,a=e.onClick,l=e.className;return(0,ce.jsx)("button",{className:p()(Jt.A.mediaActionBtn,l),onClick:a,children:"image"===t?(0,ce.jsxs)(ce.Fragment,{children:[(0,ce.jsx)(Xt.Po,{}),(0,ce.jsx)("span",{children:"Make video"})]}):(0,ce.jsxs)(ce.Fragment,{children:[(0,ce.jsx)(Xt.qI,{}),(0,ce.jsx)("span",{children:"Extend"})]})})}),Ea=(0,n.memo)(e=>{let t=e.src,a=e.alt,l=void 0===a?"":a,r=e.className;
1const s=(0,n.useState)(!1),i=(0,o.A)(s,2),d=i[0],c=i[1];return(0,ce.jsxs)(ce.Fragment,{children:[!d&&(0,ce.jsx)("div",{className:Jt.A.galleryItemSkeleton}),(0,ce.jsx)("img",{className:r||Jt.A.galleryItemImage,src:t,alt:l,loading:"lazy",decoding:"async",onLoad:()=>c(!0),onError:()=>c(!0)})]})}),Ta=[],Ba=new Set,Ua=[],La=e=>{const t=Ta.indexOf(e);for(t>=0&&Ta.splice(t,1),Ta.push(e);Ta.length>60;)Ta.shift()},Oa=e=>Ta.indexOf(e)>=0,Fa=()=>{for(;Ba.size<1&&Ua.length>0;){const e=Ua.shift();Oa(e)||Ba.has(e)||(Ba.add(e),fetch(e,{credentials:"omit",headers:{Range:"bytes=0-".concat(131071)}}).then(t=>{if(t.ok||206===t.status||200===t.status)return t.arrayBuffer().then(()=>{La(e)})}).catch(()=>{}).finally(()=>{Ba.delete(e),Fa()}))}},Ga=(0,n.memo)(e=>{let t=e.src,a=e.previewUrl;const l=(0,n.useRef)(null),r=(0,n.useRef)(null),s=(0,n.useState)(!1),i=(0,o.A)(s,2),d=i[0],c=i[1],u=(0,n.useState)(!1),m=(0,o.A)(u,2),v=m[0],h=m[1],p=(0,n.useState)(!1),g=(0,o.A)(p,2),x=g[0],y=g[1],b=(A=a)&&/\.(jpg|jpeg|png|webp|gif|avif|bmp)(\?|$)/i.test(A)?a:void 0;var A;return(0,n.useEffect)(()=>{const e=r.current;if(!e)return;const t=new IntersectionObserver(e=>{let t=(0,o.A)(e,1)[0];return c(t.isIntersecting)},{rootMargin:"600px"}),a=new IntersectionObserver(e=>{let t=(0,o.A)(e,1)[0];return h(t.isIntersecting)},{rootMargin:"200px"});return t.observe(e),a.observe(e),()=>{t.disconnect(),a.disconnect()}},[]),(0,n.useEffect)(()=>{const e=l.current;e&&(d?((e=>{Oa(e)||Ba.has(e)||Ua.includes(e)||(Ua.push(e),Fa())})(t),e.src&&e.src!==window.location.href||(e.src=t)):((e=>{const t=Ua.indexOf(e);t>=0&&Ua.splice(t,1)})(t),e.pause(),e.removeAttribute("src"),e.load(),y(!1)))},[d,t]),(0,n.useEffect)(()=>{const e=l.current;e&&(v&&d?e.play().catch(()=>{}):e.pause())},[v,d]),(0,ce.jsxs)("div",{ref:r,className:Jt.A.videoThumbWrap,children:[!x&&(b?(0,ce.jsx)(Ea,{src:b}):(0,ce.jsx)("div",{className:Jt.A.galleryItemSkeleton})),(0,ce.jsx)("video",{ref:l,className:Jt.A.galleryItemImage,loop:!0,muted:!0,playsInline:!0,preload:"auto",onLoadedData:()=>y(!0),onCanPlay:()=>y(!0),style:x?void 0:{position:"absolute",top:0,left:0,opacity:0}})]})}),Ra=(0,n.memo)(()=>(0,ce.jsx)("div",{className:Jt.A.gallerySkeletonCard})),Da=(0,n.memo)(e=>{var t;let a=e.item,l=e.onRetry,o=e.onClick,n=e.onMakeVideo,s=e.onExtendVideo;const i=e.dataFirst?{"data-first-generating":"true"}:{};if("completed"===a.status&&a.url){const e="video"===a.mediaType;return(0,ce.jsxs)("div",(0,r.A)((0,r.A)({className:Jt.A.galleryItem,onClick:o},i),{},{children:[e?(0,ce.jsx)(Ga,{src:a.url,previewUrl:a.previewUrl}):(0,ce.jsx)(Ea,{src:a.url}),a.botName&&(0,ce.jsxs)("div",{className:Jt.A.galleryItemTop,children:[a.botAvatarUrl&&(0,ce.jsx)("img",{className:Jt.A.galleryItemAvatar,src:a.botAvatarUrl,alt:""}),(0,ce.jsx)("span",{className:Jt.A.galleryItemName,children:a.botName})]}),(0,ce.jsx)("div",{className:Jt.A.galleryItemBottom,children:(0,ce.jsx)(Pa,{type:e?"video":"image",onClick:t=>{t.stopPropagation(),!e&&a.url&&n?n(a.url,a.id,!0):e&&a.url&&s&&s(a.url,a.id,!0)}})})]}))}const d=null===(t=a.errorMessage)||void 0===t?void 0:t.toLowerCase().includes("nsfw");return(0,ce.jsxs)("div",(0,r.A)((0,r.A)({className:p()(Jt.A.galleryItem,Jt.A.galleryStatusCard,{[Jt.A.galleryStatusCardError]:"error"===a.status})},i),{},{children:[(0,Wt.WV)(a.status)&&(0,ce.jsxs)(ce.Fragment,{children:[(0,ce.jsx)(Xt.jB,{}),(0,ce.jsx)("span",{className:Jt.A.statusText,children:"In the queue"})]}),(0,Wt.f8)(a.status)&&(0,ce.jsxs)(ce.Fragment,{children:[(0,ce.jsx)(Xt.Nl,{}),(0,ce.jsx)("span",{className:Jt.A.statusText,children:"video"===a.mediaType?"Generating video...":"Generating image..."})]}),"error"===a.status&&!d&&(0,ce.jsxs)(ce.Fragment,{children:[(0,ce.jsxs)("div",{className:Jt.A.statusCenter,children:[(0,ce.jsx)(Xt.hu,{}),(0,ce.jsx)("span",{className:Jt.A.statusText,children:"Generation failed!"})]}),l&&(0,ce.jsxs)("button",{className:Jt.A.retryBtn,onClick:()=>l(a.id),children:[(0,ce.jsx)(Xt.mq,{}),(0,ce.jsx)("span",{children:"Retry"})]})]}),"error"===a.status&&d&&(0,ce.jsxs)(ce.Fragment,{children:[(0,ce.jsx)(Xt.KI,{}),(0,ce.jsx)("span",{className:Jt.A.statusText,children:"NSFW prompt detected"})]})]}))}),Va=(0,n.memo)(e=>{let t=e.botId,a=e.botAvatarUrl,l=e.botName;const r=(0,i.Zp)(),o=(0,ce.jsxs)(ce.Fragment,{children:[a&&(0,ce.jsx)("img",{className:Jt.A.galleryItemAvatar,src:a,alt:l||""}),l&&(0,ce.jsx)("span",{className:Jt.A.galleryItemName,children:l})]});return t?(0,ce.jsx)("button",{type:"button",className:p()(Jt.A.galleryItemTop,Jt.A.galleryItemTopBtn),onClick:e=>{t&&(e.stopPropagation(),r("/bot_".concat(t)))},children:o}):(0,ce.jsx)("div",{className:Jt.A.galleryItemTop,children:o})}),Wa=(0,n.memo)(e=>{let t=e.galleryTab,a=e.setGalleryTab,l=e.communityMedia,r=e.isCommunityLoading,o=e.hasMoreCommunity,n=e.loadMoreRef,s=e.generatingImages,i=e.onRetry,d=e.openPreview,c=e.onMakeVideo,u=e.onExtendVideo,m=e.myGalleryImages,v=e.isMyGalleryLoading,h=e.hasMoreMyGallery,g=e.myGalleryLoadMoreRef,x=e.currentUserId,y=e.onStartGenerate;return(0,ce.jsxs)("div",{className:Jt.A.gallerySection,children:[(0,ce.jsx)("h2",{className:Jt.A.galleryTitle,children:"Explore generations"}),(0,ce.jsxs)("div",{className:Jt.A.galleryTabs,children:[(0,ce.jsx)("button",{className:p()(Jt.A.galleryTab,{[Jt.A.galleryTabActive]:"community"===t}),onClick:()=>a("community"),children:"Community"}),(0,ce.jsx)("button",{className:p()(Jt.A.galleryTab,{[Jt.A.galleryTabActive]:"my"===t}),onClick:()=>a("my"),children:"My gallery"})]}),(0,ce.jsx)("div",{className:Jt.A.galleryGrid,children:"community"===t?(0,ce.jsx)(ce.Fragment,{children:r&&0===l.length?Array.from({length:6}).map((e,t)=>(0,ce.jsx)(Ra,{},t)):0===l.length?(0,ce.jsx)("div",{className:Jt.A.galleryEmpty,children:"No items yet"}):(0,ce.jsxs)(ce.Fragment,{children:[l.map((e,t)=>(0,ce.jsxs)("div",{className:Jt.A.galleryItem,onClick:()=>d(l.map(e=>({id:e.id,url:e.url,previewUrl:e.previewUrl,type:e.type,botName:e.botName,botId:e.botId,botAvatarUrl:e.botAvatarUrl,isOwner:!(!x||e.ownerId!==x),isPrivate:!1,prompt:e.prompt,modelId:e.modelId})),t),children:["video"===e.type?(0,ce.jsx)(Ga,{src:e.url,previewUrl:e.previewUrl}):(0,ce.jsx)(Ea,{src:e.url,alt:e.botName}),(0,ce.jsx)(Va,{botId:e.botId,botAvatarUrl:e.botAvatarUrl,botName:e.botName}),(0,ce.jsx)("div",{className:Jt.A.galleryItemBottom,children:(0,ce.jsx)(Pa,{type:e.type,onClick:t=>{t.stopPropagation(),"video"===e.type?u(e.url,e.id):c(e.url,e.id)}})})]},e.id)),(0,ce.jsx)("div",{ref:n,style:{height:1,gridColumn:"1 / -1"}}),r&&Array.from({length:3}).map((e,t)=>(0,ce.jsx)(Ra,{},"load-".concat(t))),o&&(0,ce.jsx)("div",{className:Jt.A.galleryLoadTail})]})}):(0,ce.jsxs)(ce.Fragment,{children:[s.map((e,t)=>(0,ce.jsx)(Da,{item:e,onRetry:i,onClick:"completed"===e.status&&e.url?()=>{const t=[...s.filter(e=>"completed"===e.status&&e.url).map(e=>({id:e.id,url:e.url,previewUrl:e.previewUrl,type:e.mediaType||"image",botName:e.botName,botId:e.botId,botAvatarUrl:e.botAvatarUrl,isPrivate:e.isPrivate,isOwner:!0,prompt:e.prompt,modelId:e.modelId})),...m.filter(e=>"completed"===e.status&&!s.some(t=>t.id===e.id)).map(e=>({id:e.id,url:e.url,previewUrl:e.previewUrl,type:"video"===e.type?"video":"image",botName:e.botName,botId:e.botId,botAvatarUrl:e.botAvatarUrl,isPrivate:e.isPrivate,isOwner:!0,prompt:e.prompt,modelId:e.modelId}))],a=t.findIndex(t=>t.url===e.url);d(t,a>=0?a:0,!0)}:void 0,onMakeVideo:c,onExtendVideo:u,dataFirst:0===t},e.id)),m.map(e=>{if(s.some(t=>t.id===e.id))return null;const t="video"===e.type;return"completed"===e.status?(0,ce.jsxs)("div",{className:Jt.A.galleryItem,onClick:()=>{const t=[...s.filter(e=>"completed"===e.status&&e.url).map(e=>({id:e.id,url:e.url,previewUrl:e.previewUrl,type:e.mediaType||"image",botName:e.botName,botId:e.botId,botAvatarUrl:e.botAvatarUrl,isPrivate:e.isPrivate,isOwner:!0,prompt:e.prompt,modelId:e.modelId})),...m.filter(e=>"completed"===e.status&&!s.some(t=>t.id===e.id)).map(e=>({id:e.id,url:e.url,previewUrl:e.previewUrl,type:"video"===e.type?"video":"image",botName:e.botName,botId:e.botId,botAvatarUrl:e.botAvatarUrl,isPrivate:e.isPrivate,isOwner:!0,prompt:e.prompt,modelId:e.modelId}))],a=t.findIndex(t=>t.url===e.url);d(t,a>=0?a:0,!0)},children:[t?(0,ce.jsx)(Ga,{src:e.url,previewUrl:e.previewUrl}):(0,ce.jsx)(Ea,{src:e.url}),(e.botName||e.botAvatarUrl)&&(0,ce.jsx)(Va,{botId:e.botId,botAvatarUrl:e.botAvatarUrl,botName:e.botName}),(0,ce.jsx)("div",{className:Jt.A.galleryItemBottom,children:(0,ce.jsx)(Pa,{type:t?"video":"image",onClick:a=>{a.stopPropagation(),t?u(e.url,e.id,!0):c(e.url,e.id,!0)}})})]},e.id):(0,ce.jsx)(Da,{item:{id:e.id,status:e.status,url:e.url,errorMessage:"error"===e.status?"Generation failed":null,mediaType:t?"video":"image"},onRetry:i}
1,e.id)}),(0,ce.jsx)("div",{ref:g,style:{height:1,gridColumn:"1 / -1"}}),v&&Array.from({length:3}).map((e,t)=>(0,ce.jsx)(Ra,{},"mg-".concat(t))),h&&(0,ce.jsx)("div",{className:Jt.A.galleryLoadTail}),0===s.length&&0===m.length&&!v&&(0,ce.jsxs)("div",{className:Jt.A.galleryEmptyMy,children:[(0,ce.jsx)("img",{src:Sa.A,alt:"",className:Jt.A.galleryEmptyImage,"aria-hidden":!0}),(0,ce.jsx)("p",{className:Jt.A.galleryEmptyText,children:"Nothing here yet. Let's create something!"}),y&&(0,ce.jsxs)("button",{type:"button",className:Jt.A.galleryEmptyCta,onClick:y,children:[(0,ce.jsx)(Ma.h,{className:Jt.A.galleryEmptyCtaIcon}),(0,ce.jsx)("span",{children:"Generate image"})]})]})]})})]})});var qa=a(69623);const za=["media_url"],Ha=["media_url","prompt","predict_coordinates"],Za=()=>{const e=document.querySelector(".main-content-desk");e&&(e.scrollTop=0),window.scrollTo(0,0)};let Ya=null;const Ja=["mode","tab","botId","photoUrl","photoId","prompt"],Xa=()=>{var e,t,a,v,h,g,b,A,f,j,C,_,N,k,I;const w=(0,i.zy)(),M=(0,i.Zp)(),S=(0,n.useContext)(x.BR),P=S.isMobile,E=S.energy,T=S.setEnergy,B=S.decreaseEnergy,U=S.setIsEnergyPaywallOpened,L=S.user,O=S.setIsLoginOpened,F=S.loadMoreChats,G=S.hasMoreChats,R=(0,Yt.dh)().enqueueSnackbar,D=(0,d.ok)(),V=(0,o.A)(D,2),W=V[0],q=V[1],z=Boolean(w.state)||Ja.some(e=>W.has(e)),H=z?{withBack:!0}:null,Z=(0,n.useState)(()=>"video"===W.get("mode")?"video":"image"),Y=(0,o.A)(Z,2),J=Y[0],X=Y[1],Q=(0,n.useState)(()=>{const e=W.get("mode");return"image"===e||"video"===e?e:null}),K=(0,o.A)(Q,2),$=K[0],ee=K[1],te=(0,fa.x)(),ae=(0,n.useState)(null),le=(0,o.A)(ae,2),re=le[0],oe=le[1],ne=(0,n.useState)(!1),se=(0,o.A)(ne,2),ie=se[0],de=se[1],ue=(0,n.useState)(2),me=(0,o.A)(ue,2),ve=me[0],he=me[1],pe=(0,n.useState)(1),ye=(0,o.A)(pe,2),be=ye[0],Ae=ye[1],fe=(0,n.useState)(!0),je=(0,o.A)(fe,2),Ce=je[0],_e=je[1],Ne=(0,n.useState)(()=>{var e,t;const a=W.get("tab");return"my"===a||"community"===a?a:null!==(e=null===(t=Ya)||void 0===t?void 0:t.galleryTab)&&void 0!==e?e:"community"}),ke=(0,o.A)(Ne,2),Ie=ke[0],we=ke[1],Me=(0,n.useState)(()=>{var e;return null!==(e=W.get("prompt"))&&void 0!==e?e:""}),Se=(0,o.A)(Me,2),Pe=Se[0],Ee=Se[1],Te=(0,n.useState)([]),Be=(0,o.A)(Te,2),Ue=Be[0],Le=Be[1],Fe=(0,n.useState)(null),Ge=(0,o.A)(Fe,2),Re=Ge[0],De=Ge[1],Ve=(()=>{const e=(0,Na.z)(Ia,"",!1,!0),t=e.variant,a=e.isLoading,l="none"===t.toLowerCase()?"":t;return{cohort:l,enabled:!a&&""!==l,isLoading:a}})(),We=Ve.cohort,qe=Ve.enabled,ze=(0,n.useState)(null),He=(0,o.A)(ze,2),Ze=He[0],Ye=He[1],Je=(0,n.useState)(null),Xe=(0,o.A)(Je,2),Qe=Xe[0],Ke=Xe[1],$e=(0,n.useState)(null),et=(0,o.A)($e,2),tt=et[0],at=et[1],lt=(0,n.useState)(!1),rt=(0,o.A)(lt,2),ot=rt[0],nt=rt[1],st=(0,n.useMemo)(()=>{var e;return(0,va.Ep)(null!==(e=null===te||void 0===te?void 0:te.data)&&void 0!==e?e:[],{placement:"media_generator",flow:"animate"})},[te]),it=(0,n.useState)([]),dt=(0,o.A)(it,2),ct=dt[0],ut=dt[1],mt=(e=>{const t=(0,n.useState)({model:null,duration:5}),a=(0,o.A)(t,2),l=a[0],i=a[1];(0,n.useEffect)(()=>{null!==e&&i(t=>s(e,t))},[e]);const d=null===e?{model:null,duration:l.duration}:s(e,l),c=(0,n.useCallback)(e=>{var t;i({model:e,duration:null!==(t=e.availableDurations[0])&&void 0!==t?t:5})},[]),u=(0,n.useCallback)(e=>{i(t=>(0,r.A)((0,r.A)({},t),{},{duration:e}))},[]);return{selectedVideoModel:d.model,duration:d.duration,setDuration:u,handleVideoModelSelect:c}})(te?st:null),ht=mt.selectedVideoModel,pt=mt.duration,gt=mt.setDuration,xt=mt.handleVideoModelSelect,bt=(0,n.useState)(!1),At=(0,o.A)(bt,2),jt=At[0],Ct=At[1],_t=(0,n.useState)(null),Nt=(0,o.A)(_t,2),It=Nt[0],wt=Nt[1],St=(0,n.useState)(!1),Pt=(0,o.A)(St,2),Et=Pt[0],Tt=Pt[1],Ut=(0,n.useState)(()=>{const e=W.get("photoUrl"),t=W.get("photoId"),a=W.get("mode");return e&&"video"===a?(0,r.A)({url:e},t?{id:t}:{}):null}),Lt=(0,o.A)(Ut,2),Qt=Lt[0],Kt=Lt[1],$t=(0,n.useState)(!1),ea=(0,o.A)($t,2),ta=ea[0],aa=ea[1],la=(0,n.useState)(null),ra=(0,o.A)(la,2),oa=ra[0],na=ra[1],sa=(0,n.useState)(!1),ia=(0,o.A)(sa,2),da=ia[0],ca=ia[1],ua=(0,n.useState)(null),ha=(0,o.A)(ua,2),pa=ha[0],ga=ha[1],xa=(0,n.useState)(!1),ya=(0,o.A)(xa,2),Ca=ya[0],_a=ya[1],ka=(0,n.use
1State)(null),Sa=(0,o.A)(ka,2),Pa=Sa[0],Ea=Sa[1],Ta=(0,n.useState)(!1),Ba=(0,o.A)(Ta,2),Ua=Ba[0],La=Ba[1];(0,n.useEffect)(()=>{const e=document.querySelector(".main-content-desk");e&&(e.scrollTop=0),window.scrollTo(0,0)},[]);const Oa=(0,n.useRef)(null);(0,n.useEffect)(()=>{if(P)return;const e=document.querySelector(".main-content-desk");let t=0,a=0;const l=()=>e?e.scrollTop:window.scrollY,r=()=>{const e=Oa.current;if(!e)return;if(window.innerWidth<=960)return void(e.style.maxHeight&&(e.style.maxHeight=""));const r=t+Math.max(24,a-l()),o="".concat(Math.round(window.innerHeight-r-24),"px");e.style.maxHeight!==o&&(e.style.maxHeight=o)},o=()=>{var o;const n=Oa.current,s=null===n||void 0===n?void 0:n.closest(".".concat(Jt.A.content));n&&s&&(t=null!==(o=null===e||void 0===e?void 0:e.getBoundingClientRect().top)&&void 0!==o?o:0,a=s.getBoundingClientRect().top-t+l(),r())};return o(),null===e||void 0===e||e.addEventListener("scroll",r,{passive:!0}),window.addEventListener("resize",o),()=>{null===e||void 0===e||e.removeEventListener("scroll",r),window.removeEventListener("resize",o)}},[P]),(0,n.useEffect)(()=>{yt().catch(()=>{}),kt().catch(()=>{}),Bt().catch(()=>{})},[]),(0,n.useEffect)(()=>{var e;const t=null===(e=w.state)||void 0===e?void 0:e.preselectBot;if(t){if(oe(t),Va(e=>(0,r.A)((0,r.A)({},e),{},{character:!1})),X("image"),P){ee("image");const e=document.querySelector(".main-content-desk");e?e.scrollTop=0:window.scrollTo({top:0})}M(w.pathname+w.search,{replace:!0,state:H})}},[w.key]),(0,n.useEffect)(()=>{var e;const t=w.state,a=null===t||void 0===t?void 0:t.extendingVideo,l=[...null!==(e=null===t||void 0===t?void 0:t.pendingGenerations)&&void 0!==e?e:[],...a?[(0,r.A)({id:a.id,status:a.status,mediaType:"video"},a.analytics?{_analyticsBase:a.analytics.analyticsBase,_videoAnalytics:a.analytics.videoAnalytics,_stickerEnergyPerItem:a.analytics.stickerEnergyPerItem}:{})]:[]];if(!l.length)return;kl(e=>{const t=l.filter(t=>!e.some(e=>e.id===t.id));return t.length?[...t,...e]:e}),we("my"),Ya&&(Ya.scrollTop=0);const o=document.querySelector(".main-content-desk");o&&(o.scrollTop=0),window.scrollTo({top:0}),ql.current=0,M(w.pathname+w.search,{replace:!0,state:H})},[w.key]),(0,n.useEffect)(()=>{const e=W.get("botId"),t=Ja.some(e=>W.has(e));if(e&&y.r.getBot(e).then(e=>{null!==e&&void 0!==e&&e.data&&oe(e.data)}).catch(()=>{}),t){Ya&&(Ya.scrollTop=0);const e=document.querySelector(".main-content-desk");e?e.scrollTop=0:window.scrollTo({top:0}),q({},{replace:!0,state:H})}},[]),(0,n.useEffect)(()=>{zt._w.photoGeneratorBuilderAppear()},[]);const Fa=(0,n.useRef)(0),Ga=(0,n.useState)({}),Ra=(0,o.A)(Ga,2),Da=Ra[0],Va=Ra[1],Xa=(0,n.useState)({}),Qa=(0,o.A)(Xa,2),Ka=Qa[0],$a=Qa[1],el=(0,n.useState)(()=>{var e,t;return null!==(e=null===(t=Ya)||void 0===t?void 0:t.communityMedia)&&void 0!==e?e:[]}),tl=(0,o.A)(el,2),al=tl[0],ll=tl[1],rl=(0,n.useState)(()=>{var e,t;return null!==(e=null===(t=Ya)||void 0===t?void 0:t.communityCursor)&&void 0!==e?e:null}),ol=(0,o.A)(rl,2),nl=ol[0],sl=ol[1],il=(0,n.useState)(!1),dl=(0,o.A)(il,2),cl=dl[0],ul=dl[1],ml=(0,n.useState)(()=>{var e,t;return null===(e=null===(t=Ya)||void 0===t?void 0:t.hasMoreCommunity)||void 0===e||e}),vl=(0,o.A)(ml,2),hl=vl[0],pl=vl[1],gl=(0,n.useRef)(null),xl=(0,n.useRef)(!1),yl=(0,n.useRef)(null),bl=(0,n.useRef)(!0);yl.current=nl,bl.current=hl;const Al=(0,n.useCallback)(async e=>{if(!xl.current){xl.current=!0,ul(!0);try{const t=await xe.d.getCommunityMedia(e,20);ll(e?e=>{const a=new Set(e.map(e=>e.id));return[...e,...t.items.filter(e=>!a.has(e.id))]}:t.items),sl(t.nextCursor),pl(!!t.nextCursor)}catch(t){pl(!1)}finally{xl.current=!1,ul(!1)}}},[]);(0,n.useEffect)(()=>{Ya||Al()},[]),(0,n.useEffect)(()=>{const e=gl.current;if(!e)return;const t=new IntersectionObserver(e=>{(0,o.A)(e,1)[0].isIntersecting&&bl.current&&yl.current&&Al(yl.current)},{threshold:0,rootMargin:"1200px 0px"});return t.observe(e),()=>t.disconnect()},[Al,Ie,al.length>0]);const fl=(0,n.useRef)(!1),jl=(0,n.useCallback)(async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;if(!fl.current){fl.current=!0,Bl(!0);try{const t=await xe.d.getMedia({page:e,size:20});Sl(0===e?t.items:e=>{const a=new Set(e.map(e=>e.id));return[...e,...t.items.filter(e=>!a.has(e.id))]}),Fl(t.page),Vl(t.pages)}catch(t){}finally{fl.current=!1,Bl(!1)}}},[]);(0,n.useEffect)(()=>{Ya||jl(0)},[jl]);
1const Cl=(0,n.useState)(()=>{var e,t;return null!==(e=null===(t=Ya)||void 0===t?void 0:t.generatingImages)&&void 0!==e?e:[]}),_l=(0,o.A)(Cl,2),Nl=_l[0],kl=_l[1],Il=(0,n.useState)(()=>{var e,t;return null!==(e=null===(t=Ya)||void 0===t?void 0:t.myGalleryImages)&&void 0!==e?e:[]}),wl=(0,o.A)(Il,2),Ml=wl[0],Sl=wl[1],Pl=(0,n.useState)(!1),El=(0,o.A)(Pl,2),Tl=El[0],Bl=El[1],Ul=(0,n.useState)(()=>{var e,t;return null!==(e=null===(t=Ya)||void 0===t?void 0:t.myGalleryPage)&&void 0!==e?e:0}),Ll=(0,o.A)(Ul,2),Ol=Ll[0],Fl=Ll[1],Gl=(0,n.useState)(()=>{var e,t;return null!==(e=null===(t=Ya)||void 0===t?void 0:t.myGalleryPages)&&void 0!==e?e:1}),Rl=(0,o.A)(Gl,2),Dl=Rl[0],Vl=Rl[1],Wl=(0,n.useRef)({galleryTab:Ie,communityMedia:al,communityCursor:nl,hasMoreCommunity:hl,myGalleryImages:Ml,myGalleryPage:Ol,myGalleryPages:Dl,generatingImages:Nl});Wl.current={galleryTab:Ie,communityMedia:al,communityCursor:nl,hasMoreCommunity:hl,myGalleryImages:Ml,myGalleryPage:Ol,myGalleryPages:Dl,generatingImages:Nl};const ql=(0,n.useRef)(null!==(e=null===(t=Ya)||void 0===t?void 0:t.scrollTop)&&void 0!==e?e:0);(0,n.useEffect)(()=>{const e=document.querySelector(".main-content-desk");if(e){const t=()=>{ql.current=e.scrollTop};return e.addEventListener("scroll",t,{passive:!0}),()=>e.removeEventListener("scroll",t)}const t=()=>{ql.current=window.scrollY};return window.addEventListener("scroll",t,{passive:!0}),()=>window.removeEventListener("scroll",t)},[]),(0,n.useEffect)(()=>{var e,t;const a=null!==(e=null===(t=Ya)||void 0===t?void 0:t.scrollTop)&&void 0!==e?e:0;let l=null,o=!1;if(a>0){const e=Date.now()+2e3,t=()=>{if(o)return;const r=document.querySelector(".main-content-desk");r?r.scrollTop=a:window.scrollTo({top:a});const n=r?r.scrollTop:window.scrollY;Math.abs(n-a)>1&&Date.now()<e&&(l=setTimeout(t,50))};l=setTimeout(t,50)}return()=>{o=!0,null!==l&&(clearTimeout(l),l=null),Ya=(0,r.A)((0,r.A)({},Wl.current),{},{scrollTop:ql.current})}},[]);const zl=(0,n.useRef)(null),Hl=(0,n.useRef)(0),Zl=(0,n.useRef)(1);Hl.current=Ol,Zl.current=Dl,(0,n.useEffect)(()=>{const e=zl.current;if(!e)return;const t=new IntersectionObserver(e=>{(0,o.A)(e,1)[0].isIntersecting&&!fl.current&&Hl.current+1<Zl.current&&jl(Hl.current+1)},{threshold:0,rootMargin:"1200px 0px"});return t.observe(e),()=>t.disconnect()},[jl,Ie]);const Yl=(0,n.useState)(!1),Jl=(0,o.A)(Yl,2),Xl=Jl[0],Ql=Jl[1],Kl=(0,n.useState)([]),$l=(0,o.A)(Kl,2),er=$l[0],tr=$l[1],ar=(0,n.useState)(0),lr=(0,o.A)(ar,2),rr=lr[0],or=lr[1],nr=(0,n.useState)(!1),sr=(0,o.A)(nr,2),ir=sr[0],dr=sr[1],cr=(0,n.useState)(!1),ur=(0,o.A)(cr,2),mr=ur[0],vr=ur[1],hr=(0,n.useState)(null),pr=(0,o.A)(hr,2),gr=pr[0],xr=pr[1],yr=(0,n.useState)(null),br=(0,o.A)(yr,2),Ar=br[0],fr=br[1],jr=(0,n.useState)(null),Cr=(0,o.A)(jr,2),_r=Cr[0],Nr=Cr[1],kr=(0,n.useCallback)(function(e,t){let a=arguments.length>2&&void 0!==arguments[2]&&arguments[2];tr(e),or(t),vr(a),dr(!0)},[]),Ir=(0,n.useCallback)(async(e,t)=>{try{"video"===t?await xe.d.deleteVideo(e):await xe.d.deleteImage(e),Sl(t=>t.filter(t=>t.id!==e)),kl(t=>t.filter(t=>t.id!==e)),tr(t=>{const a=t.filter(t=>t.id!==e);return 0===a.length&&dr(!1),a}),R("Deleted successfully",{variant:"success"})}catch(a){R("Failed to delete",{variant:"error"})}},[R]),wr=(0,n.useCallback)(function(e,t){let a=arguments.length>2&&void 0!==arguments[2]&&arguments[2];zt._w.photoGeneratorMakeVideoTapped({my_photo:a}),dr(!1),Kt({url:e,id:t}),$a({}),X("video"),Ee(""),oe(null),na(null),P&&ee("video");const l=document.querySelector(".main-content-desk");l?l.scrollTop=0:window.scrollTo({top:0})},[P]),Mr=(0,n.useCallback)(async(e,t)=>{dr(!1),Ee(e.slice(0,500)),X("image"),P&&ee("image");const a=document.querySelector(".main-content-desk");if(a?a.scrollTop=0:window.scrollTo({top:0}),null!=t)try{const e=await y.r.getBot(t.toString());null!==e&&void 0!==e&&e.data&&(oe(e.data),Va(e=>(0,r.A)((0,r.A)({},e),{},{character:!1})))}catch(l){}},[P]),Sr={userName:(null===L||void 0===L?void 0:L.personaName)||"",context:[],cacheScope:"generate",getImageButtons:e=>{const t=e.media_url,a=(0,l.A)(e,za);return qt.FH.getSmartMediaButtons((0,r.A)((0,r.A)({},a),{},{image_url:t}))}
1,getVideoButtons:e=>{const t=e.media_url,a=(e.prompt,e.predict_coordinates,(0,l.A)(e,Ha));return qt.FH.getSmartVideoProlongButtons((0,r.A)((0,r.A)({},a),{},{video_url:t}))},onButtonClick:(e,t)=>{let a=e.title;"video"===t.type&&t.id?zr(t.url,t.id,!!t.isOwner,{initialPrompt:a}):Qe?fr({title:a,imageUrl:t.url,imageId:t.id,botId:t.botId}):Mr(a,t.botId)}},Pr=(0,n.useCallback)(async e=>{dr(!1),X("image"),P&&ee("image");const t=document.querySelector(".main-content-desk");t?t.scrollTop=0:window.scrollTo({top:0});try{const t=await y.r.getBot(e.toString());null!==t&&void 0!==t&&t.data&&(oe(t.data),Va(e=>(0,r.A)((0,r.A)({},e),{},{character:!1})))}catch(a){}},[P]),Er=(0,n.useCallback)(async(e,t)=>{dr(!1),X("video"),P&&ee("video"),Kt(e?{url:e,id:void 0}:null),Ee(""),oe(null),na(null),$a({});const a=document.querySelector(".main-content-desk");a?a.scrollTop=0:window.scrollTo({top:0});try{const e=await y.r.getBot(t.toString());null!==e&&void 0!==e&&e.data&&(oe(e.data),$a(e=>(0,r.A)((0,r.A)({},e),{},{character:!1})))}catch(l){}},[P]),Tr=(0,n.useCallback)(e=>{R(e,{variant:"error",autoHideDuration:4e3,anchorOrigin:{vertical:"top",horizontal:"right"}})},[R]),Br=null!==(a=ct[0])&&void 0!==a?a:st[0],Ur=Br?(0,va.Jl)(Br,(null===(v=Br.availableDurations)||void 0===v?void 0:v[0])||5):20,Lr=null!==Br&&void 0!==Br&&Br.availableDurations&&Br.availableDurations.length>1?Br.availableDurations:void 0,Or=Lr?null!==(h=null!==(g=Rt.k.resolve(Lr))&&void 0!==g?g:Lr[0])&&void 0!==h?h:5:void 0,Fr=e=>Br?(0,va.Jl)(Br,e):0,Gr=(0,n.useRef)(()=>{}),Rr=(0,n.useRef)(()=>{}),Dr=(0,n.useCallback)(e=>{var t;let a=e.id,l=e.url;const r=[...Nl,...Ml,...al].filter(e=>e.botId&&e.botId>0),o=null!==(t=a?r.find(e=>e.id===a):void 0)&&void 0!==t?t:l?r.find(e=>e.url===l):void 0;return null===o||void 0===o?void 0:o.botId},[Nl,Ml,al]),Vr=Qt?null!==(b=Qt.botId)&&void 0!==b?b:Dr(Qt):void 0,Wr="video"===J&&null!==Vr&&void 0!==Vr?Vr:null===re||void 0===re?void 0:re.id,qr=(0,n.useCallback)((e,t,a)=>{const l=null!==e&&void 0!==e?e:null===re||void 0===re?void 0:re.id;(0,Ht.BO)((0,r.A)((0,r.A)({},l?{botId:l}:{}),{},{surface:"generator"})),U(!0,t,a)},[null===re||void 0===re?void 0:re.id,U]),zr=(0,n.useCallback)(function(e,t){let a=arguments.length>2&&void 0!==arguments[2]&&arguments[2],l=arguments.length>3?arguments[3]:void 0;L&&!L.isAnon?E<Ur?qr(Dr({id:t}),Ur):(zt._w.photoGeneratorExtendVideoTapped({my_video:a}),xr({videoUrl:e,videoId:t,initialPrompt:null===l||void 0===l?void 0:l.initialPrompt})):O(!0)},[L,O,E,Ur,qr,Dr]),Hr=(0,n.useCallback)(async(e,t,a)=>{var l,o,n;if(!L||L.isAnon)return void O(!0);const s=null!==(l=ct[0])&&void 0!==l?l:st[0];if(!s)return;const i=null!==(o=null!==a&&void 0!==a?a:null===(n=s.availableDurations)||void 0===n?void 0:n[0])&&void 0!==o?o:5,d=(0,va.Jl)(s,i),c={mode:"extend",model_name:s.name,custom_prompt_text:t||void 0,duration:i,energy:d},u={model_name:s.name,model_id:s.id,prompt_length:(t||"").length};zt._w.photoGeneratorAnimateRequestSent({mode:"extend",model_name:s.name,custom_prompt_text:t||void 0,duration:i,content_number:1,energy:d}),(0,Ht.cP)({botId:Dr({id:e})});try{const a=(0,ja.jT)(),l=await xe.d.extendVideoV2(e,(0,r.A)((0,r.A)({botId:0,modelId:s.id,duration:i},t?{prompt:t}:{}),{},{from:"media_generator",productFeature:"extend_button"},t?{mode:"custom_prompt"}:{})),o={id:l.id,status:l.status,mediaType:"video",_analyticsBase:u,_videoAnalytics:c,_stickerEnergyPerItem:d};kl(e=>[o,...e]),we("my"),P?setTimeout(()=>Yr(),350):Za(),(0,ja.tO)(a)||B(d)}catch(m){console.error("Failed to extend video",m),Tr((null===m||void 0===m?void 0:m.message)||"Failed to extend video"),zt._w.photoGeneratorAnimateFailed({model_name:s.name,mode:"extend"})}},[ct,st,B,Tr,L,O,Dr]),Zr=(0,n.useCallback)((e,t)=>{kl(a=>a.map(a=>a.id===e?(0,r.A)((0,r.A)({},a),t):a))},[]),Yr=(0,n.useCallback)(()=>{requestAnimationFrame(()=>{requestAnimationFrame(()=>{const e=document.querySelector("[data-first-generating]");if(!e)return;const t=e.getBoundingClientRect(),a=window.scrollY+t.top-.3*window.innerHeight;window.scrollTo({top:Math.max(0,a),behavior:"smooth"})})})},[]),Jr=Re?qe?(0,ma.X)(Re,ve):ve*Re.price:2*ve,Xr="image"===J?Jr:ht?(0,va.lF)(ht,pt,be):be*pt*8,Qr=(0,n.useCallback)(async()=>
1{if(Xl)return;if(!L||L.isAnon)return void O(!0);if(E<Xr)return void qr(null,Xr,{run:()=>{Gr.current()}});const e={};if(re||(e.character=!0),e.character)return Va(e),void Tr("Please select a character");if(Va({}),!re||!Re)return;zt._w.photoGeneratorBuilderContinue({strapi_bot_id:re.id,bot_name:re.attributes.name,model_name:Re.name,model_id:Re.id,pose_name:null===oa||void 0===oa?void 0:oa.name,energy:Xr,prompt_length:Pe.length,content_number:ve,is_private:Ce}),(0,Ht.cP)({botId:re.id}),Ql(!0),we("my");const t=Date.now(),a=Pe.trim(),l=(0,r.A)((0,r.A)((0,r.A)((0,r.A)((0,r.A)((0,r.A)({botId:re.id.toString(),modelId:Re.id,isPrivate:Ce,count:ve},null!==oa&&void 0!==oa&&oa.id?{characterPoseId:oa.id}:{}),null!==pa&&void 0!==pa&&pa.id?{characterOutfitId:pa.id}:{}),null!==Pa&&void 0!==Pa&&Pa.id?{characterBackgroundId:Pa.id}:{}),a?{prompt:a}:{}),qe?{cohort:We}:{}),{},{from:"media_generator",productFeature:"photo_generator"},a?{mode:"custom_prompt"}:{}),o={strapi_bot_id:re.id,bot_name:re.attributes.name,model_name:Re.name,model_id:Re.id,pose_name:null===oa||void 0===oa?void 0:oa.name,prompt_length:Pe.length,is_private:Ce},n=ve>0?Xr/ve:Xr,s=Array.from({length:ve}).map(()=>crypto.randomUUID()),i=s.map((e,l)=>({id:e,status:"pending",botName:re.attributes.name,botAvatarUrl:re.attributes.avatarUrl,botId:re.id,mediaType:"image",isPrivate:0!==l||Ce,prompt:a||void 0,modelId:Re.id,_analyticsBase:o,_stickerEnergyPerItem:n,_genStartTime:t}));kl(e=>[...i,...e]),we("my"),P?Yr():Za();try{const e=(await xe.d.generateGalleryImageBatch(l)).items||[];kl(l=>{const r=l.filter(e=>!s.includes(e.id));return[...e.map((e,l)=>({id:e.id,status:e.status,botName:re.attributes.name,botAvatarUrl:re.attributes.avatarUrl,botId:re.id,mediaType:"image",isPrivate:0!==l||Ce,prompt:a||void 0,modelId:Re.id,_analyticsBase:o,_stickerEnergyPerItem:n,_genStartTime:t})),...r]})}catch(u){var d,c;kl(e=>e.filter(e=>!s.includes(e.id))),Tr((null===u||void 0===u?void 0:u.message)||"Failed to generate images"),zt._w.photoGeneratorGenerationFailed((0,r.A)((0,r.A)({},o),{},{price:Xr,error:(null===u||void 0===u?void 0:u.message)||"Failed to generate images",error_code:(null===u||void 0===u||null===(d=u.code)||void 0===d?void 0:d.toString())||(null===u||void 0===u||null===(c=u.status)||void 0===c?void 0:c.toString())}))}finally{Ql(!1),xe.d.getUserEnergy().then(e=>{"number"===typeof(null===e||void 0===e?void 0:e.energy)&&Number.isFinite(e.energy)&&T(e.energy)}).catch(()=>{})}},[re,Re,oa,pa,Pa,ve,Pe,Ce,Xl,Tr,L,O,T,E,Xr,qr,We,qe]),Kr=(0,n.useCallback)(async()=>{if(Xl)return;if(!L||L.isAnon)return void O(!0);if(E<Xr)return void qr(Vr,Xr,{run:()=>{Rr.current()}});if(!Qt)return $a({image:!0}),void Tr("Please select an image");if($a({}),!ht)return;zt._w.photoGeneratorBuilderContinue({model_name:ht.name,model_id:ht.id,action_name:null===It||void 0===It?void 0:It.name,energy:Xr,prompt_length:Pe.length,content_number:be,is_private:Ce}),Ql(!0),we("my");const e=Date.now();let t=Qt.id;if(!t){const e=Ml.find(e=>e.url===Qt.url);t=null===e||void 0===e?void 0:e.id}if(!t){const e=al.find(e=>e.url===Qt.url);t=null===e||void 0===e?void 0:e.id}if(!t){const e=Nl.find(e=>e.url===Qt.url);t=null===e||void 0===e?void 0:e.id}if(!t)return Tr("Could not find source image for video generation"),void Ql(!1);(0,Ht.cP)({botId:null!==Vr&&void 0!==Vr?Vr:null===re||void 0===re?void 0:re.id});const a=Pe.trim(),l=(0,r.A)((0,r.A)((0,r.A)({modelId:ht.id,duration:pt,count:be,isPrivate:Ce},null!==It&&void 0!==It&&It.id?{videoActionId:It.id}:{}),a?{prompt:a}:{}),{},{from:"media_generator",productFeature:"make_video_button"},a?{mode:"custom_prompt"}:{}),o={model_name:ht.name,model_id:ht.id,prompt_length:Pe.length},n=be>0?Xr/be:Xr,s=It?"preset":Pe.trim()?"custom_prompt":"picture_driven",i={mode:s,preset_name:null===It||void 0===It?void 0:It.name,model_name:ht.name,custom_prompt_text:Pe.trim()||void 0,duration:pt,energy:Xr},d=Array.from({length:be}).map(()=>crypto.randomUUID()),c=d.map((t,a)=>({id:t,status:"pending",mediaType:"video",isPrivate:0!==a||Ce,_analyticsBase:o,_videoAnalytics:i,_stickerEnergyPerItem:n,_genStartTime:e}));kl(e=>[...c,...e]),we("my"),P?Yr():Za();try{for(let e=0;e<be;e++)zt._w.photoGeneratorAnimateRequestSent({mode:s,preset_name:null===It||void 0===It?void 0:It.name,model_name:ht.name,custom_prompt_text:Pe.trim()||void 0,duration:pt,content_number:1,energy:n});const a=(await xe.d.animateGalleryImageBatch(t,l)).items||[];kl(t=>{const l=t.filter(e=>!d.includes(e.id));return[...a.map((t,a)=>({id:t.id,status:t.status,mediaType:"video",isPrivate:0!==a||Ce,_analyticsBase:o,_videoAnalytics:i,_stickerEnergyPerItem:n,_genStartTime:e})),...l]})}catch(v){var u,m;kl(e=>e.filter(e=>!d.includes(e.id))),Tr((null===v||void 0===v?void 0:v.message)||"Failed to generate videos"),zt._w.photoGeneratorGenerationFailed((0,r.A)((0,r.A)({},o),{},{price:Xr,error:(null===v||void 0===v?void 0:v.message)||"Failed to generate videos",error_code:(null===v||void 0===v||null===(u=v.code)||void 0===u?void 0:u.toString())||(null===v||void 0===v||null===(m=v.status)||void 0===m?void 0:m.toString())})),zt._w.photoGeneratorAnimateFailed({model_name:ht.name,mode:s})}finally{Ql(!1),xe.d.getUserEnergy().then(e=>{"number"===typeof(null===e||void 0===e?void 0:e.energy)&&Number.isFinite(e.energy)&&T(e.energy)}).catch(()=>{})}}
1,[Qt,ht,It,be,Pe,pt,Ce,Xl,Ml,al,Nl,Tr,L,O,T,E,Xr,qr,Vr,null===re||void 0===re?void 0:re.id]);Gr.current=Qr,Rr.current=Kr;const $r=(0,n.useRef)({});(0,n.useEffect)(()=>{const e=Nl.filter(e=>(0,Wt.LM)(e.status)).map(e=>e.id),t=Ml.filter(e=>(0,Wt.LM)(e.status)).map(e=>e.id),a=[...new Set([...e,...t])];if(0===a.length)return;const l=setInterval(async()=>{try{const e=await xe.d.getMedia({mediaIds:a,size:a.length}),t=new Set(e.items.map(e=>e.id));e.items.forEach(e=>{if(delete $r.current[e.id],"completed"===e.status){const l=Nl.find(t=>t.id===e.id);if(null!==l&&void 0!==l&&l._analyticsBase){var t,a;Fa.current+=1;const o=l._genStartTime?Date.now()-l._genStartTime:0,n=null!==(t=null!==(a=e.energyPaid)&&void 0!==a?a:l._stickerEnergyPerItem)&&void 0!==t?t:0;l._videoAnalytics?zt._w.photoGeneratorAnimateGenerated((0,r.A)((0,r.A)({},l._videoAnalytics),{},{energy:n})):zt._w.photoGeneratorPhotoGenerated((0,r.A)((0,r.A)({},l._analyticsBase),{},{session_count:Fa.current,latency:o,energy:n}))}}Zr(e.id,{status:e.status,url:e.url||void 0,previewUrl:e.previewUrl||void 0,mediaType:"video"===e.type?"video":"image",isPrivate:e.isPrivate,errorMessage:"error"===e.status?"Generation failed":void 0}),Sl(t=>t.map(t=>t.id===e.id?(0,r.A)((0,r.A)({},t),{},{status:e.status,url:e.url||t.url,type:e.type,isPrivate:e.isPrivate}):t))}),a.forEach(e=>{t.has(e)||($r.current[e]=($r.current[e]||0)+1,$r.current[e]>=3&&(Zr(e,{status:"error",errorMessage:"Generation failed"}),Sl(t=>t.map(t=>t.id===e?(0,r.A)((0,r.A)({},t),{},{status:"error"}):t)),delete $r.current[e]))});e.items.length>0&&e.items.every(e=>"completed"===e.status||"error"===e.status)&&jl(0)}catch(e){}},3e3);return()=>clearInterval(l)},[Nl,Ml,Zr,jl]);const eo=(0,n.useCallback)(async e=>{Zr(e,{status:"pending",errorMessage:null}),Sl(t=>t.map(t=>t.id===e?(0,r.A)((0,r.A)({},t),{},{status:"pending"}):t))},[Zr]),to=(0,n.useCallback)(()=>{const e=document.querySelector(".main-content-desk");e?e.scrollTop=0:window.scrollTo({top:0}),X("image"),P&&(ee("image"),zt._w.photoGeneratorImageTapped())},[P]);(0,n.useEffect)(()=>{xe.d.getImageModels().then(e=>{var t,a;const l=e.filter(e=>"gallery"===e.type);Le(l),l.length>0&&!Re&&De(l[0]);const r=l.find(e=>"supreme"===e.name.trim().toLowerCase()),o=l.find(e=>e.name.toLowerCase().includes("supreme"));Ye(null!==(t=null!==r&&void 0!==r?r:o)&&void 0!==t?t:null),Ke(null!==(a=e.find(e=>"smart_actions"===e.type&&!1!==e.available))&&void 0!==a?a:null)}).catch(console.error)},[]),(0,n.useEffect)(()=>{var e;if(!te)return ut([]),void at(null);const t=te.data;ut((0,va.Ep)(t,{placement:"media_generator",flow:"extend"}));const a=st.filter(e=>!1!==e.available&&e.availableDurations.includes(5)),l=a.find(e=>"aura"===e.name.trim().toLowerCase()),r=a.find(e=>e.name.toLowerCase().includes("aura"));at(null!==(e=null!==l&&void 0!==l?l:r)&&void 0!==e?e:null)},[te,st]),(0,n.useEffect)(()=>{"video"===J&&te&&(0,wa.Y)(te.params.mediaVideoCohort)},[J,te]);const ao=(0,n.useCallback)(e=>{De(e)},[]),lo=e=>{ee(e),X(e),"image"===e?zt._w.photoGeneratorImageTapped():zt._w.photoGeneratorVideoTapped()},ro=()=>{ee(null)},oo=(0,n.useCallback)(e=>{oe(e),e&&(Va(e=>(0,r.A)((0,r.A)({},e),{},{character:!1})),zt._w.photoGeneratorBotPicked({strapi_bot_id:e.id,bot_name:e.attributes.name}))},[]),no=(0,n.useCallback)(e=>{Kt(e),e&&$a(e=>(0,r.A)((0,r.A)({},e),{},{image:!1}))},[]),so=(0,n.useCallback)(()=>{zt._w.photoGeneratorPickBotAppear(),de(!0)},[]),io=(0,n.useCallback)(()=>{zt._w.photoGeneratorPoseTapped(),ca(!0)},[]),co=(0,n.useCallback)(()=>{_a(!0)},[]),uo=(0,n.useCallback)(()=>{La(!0)},[]),mo=(0,n.useCallback)(()=>{zt._w.photoGeneratorActionTapped(),Tt(!0)},[]),vo=(0,n.useCallback)(e=>{Ee(e),e.trim()&&Va(e=>(0,r.A)((0,r.A)({},e),{},{prompt:!1}))},[]),ho={selectedCharacter:re,setSelectedCharacter:oo,setIsCharacterModalOpen:so,isPrivate:Ce,setIsPrivate:_e,prompt:Pe,setPrompt:vo,energyCost:Xr,showEnergyCost:!0,selectedModel:Re,imageModels:Ue,isModelPickerOpen:ot,setIsModelPickerOpen:nt,onModelSelect:ao,isMobile:P,selectedPose:oa,setSelectedPose:na,isPoseModalOpen:da,setIsPoseModalOpen:io,selectedOutfit:pa,setSelectedOutfit:ga,isOutfitModalOpen:Ca,setIsOutfitModalOpen:co,selectedBackgroun
1d:Pa,setSelectedBackground:Ea,isBackgroundModalOpen:Ua,setIsBackgroundModalOpen:uo,onGenerate:Qr,isGenerating:Xl,validationErrors:Da,onCreativeUpsell:()=>(0,Ht.BO)((0,r.A)((0,r.A)({},Wr?{botId:Wr}:{}),{},{surface:"generator"}))},po=null!==(A=null===Ze||void 0===Ze?void 0:Ze.price)&&void 0!==A?A:0,go=tt?(0,va.Jl)(tt,5):0,xo=(0,ce.jsxs)(ce.Fragment,{children:[(0,ce.jsx)(Ft.M,{opened:ir,onClose:()=>dr(!1),items:er,startIndex:rr,onMakeVideo:wr,onExtendVideo:zr,showDelete:mr,onDelete:Ir,onPickCharacter:Pr,onNewVideo:Er,onEnhance:Ze?e=>{var t;zt._w.enhanceTapped({source:"generate_page",energy:Ze.price,bot_name:null!==(t=e.botName)&&void 0!==t?t:null}),Nr(e)}:void 0,enhanceModelId:null===Ze||void 0===Ze?void 0:Ze.id,reportSource:"generator",requireEnhancePrompt:!0,onChatClick:e=>{dr(!1),M("/bot_".concat(e,"/chat"))},smartMedia:Sr,keepOpenOnAction:!0}),(0,ce.jsx)(Gt.C,{open:!!gr,onClose:()=>xr(null),videoUrl:(null===gr||void 0===gr?void 0:gr.videoUrl)||"",videoId:(null===gr||void 0===gr?void 0:gr.videoId)||"",energyCost:Ur,durationOptions:Lr,initialDuration:Or,getEnergyCostForDuration:Fr,initialPrompt:null===gr||void 0===gr?void 0:gr.initialPrompt,getPromptSuggestions:()=>qt.FH.getSmartVideoProlongButtons({video_url:(null===gr||void 0===gr?void 0:gr.videoUrl)||"",bot_info:{name:(null===re||void 0===re?void 0:re.attributes.name)||""},user_info:{name:(null===L||void 0===L?void 0:L.personaName)||""},context:[]}).then(e=>{var t;return null!==(t=e.buttons)&&void 0!==t?t:[]}),onSubmit:async(e,t,a)=>{var l,r,o,n;void 0!==a&&Rt.k.set(a);const s=null!==(l=null!==(r=null!==a&&void 0!==a?a:Or)&&void 0!==r?r:null===(o=st[0])||void 0===o||null===(n=o.availableDurations)||void 0===n?void 0:n[0])&&void 0!==l?l:5,i=Fr(s)||Ur;E<i?qr(Dr({id:e}),i):(await Hr(e,t,a),dr(!1))}}),Ar&&(0,ce.jsx)(Dt.h,{opened:!0,onClose:()=>fr(null),onConfirm:async function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;const a=Ar;if(!a)return;if(!L||L.isAnon)return void O(!0);if("video"===e){if(!a.imageId||!tt)return;const e=5,t=(0,va.Jl)(tt,e);if(E<t)return void qr(a.botId);(0,Ht.cP)({botId:a.botId}),fr(null),dr(!1),we("my");const l=crypto.randomUUID(),o=Date.now(),n={id:l,status:"pending",mediaType:"video",isPrivate:!0,_genStartTime:o,_stickerEnergyPerItem:t};kl(e=>[n,...e]),P&&Yr();try{const t=await xe.d.animateGalleryImage(a.imageId,{modelId:tt.id,duration:e,isPrivate:!0,prompt:a.title,from:"media_generator",productFeature:"video_smart_suggestion",mode:"smart_suggestion"});kl(e=>e.map(e=>e.id===l?(0,r.A)((0,r.A)({},e),{},{id:t.id,status:t.status}):e))}catch(c){kl(e=>e.filter(e=>e.id!==l)),Tr((null===c||void 0===c?void 0:c.message)||"Failed to generate video")}finally{xe.d.getUserEnergy().then(e=>{"number"===typeof(null===e||void 0===e?void 0:e.energy)&&Number.isFinite(e.energy)&&T(e.energy)}).catch(()=>{})}return}if(!a.botId||!Qe)return;const l=(0,Zt.mT)(Qe,t);if(E<l)return void qr(a.botId);(0,Ht.cP)({botId:a.botId}),fr(null),dr(!1),we("my");let o=re&&re.id===a.botId?re:null;if(!o)try{const e=await y.r.getBot(a.botId.toString());null!==e&&void 0!==e&&e.data&&(o=e.data)}catch(u){}const n=Math.round(l/t),s=Array.from({length:t},()=>crypto.randomUUID()),i=Date.now(),d=s.map(e=>{var t,l,r;return{id:e,status:"pending",botName:null===(t=o)||void 0===t?void 0:t.attributes.name,botAvatarUrl:null===(l=o)||void 0===l?void 0:l.attributes.avatarUrl,botId:null===(r=o)||void 0===r?void 0:r.id,mediaType:"image",isPrivate:!0,prompt:a.title,modelId:Qe.id,_stickerEnergyPerItem:n,_genStartTime:i}});kl(e=>[...d,...e]),P&&Yr();try{const e=(await xe.d.generateSmartActionBatch({botSourceId:String(a.botId),modelId:Qe.id,smartAction:a.title,referenceImageUrl:a.imageUrl,numImages:t,from:"media_generator",productFeature:"photo_smart_suggestion",mode:"smart_suggestion"})).items||[];kl(t=>{const l=t.filter(e=>!s.includes(e.id));return[...e.map(e=>{var t,l,r;return{id:e.id,status:e.status,botName:null===(t=o)||void 0===t?void 0:t.attributes.name,botAvatarUrl:null===(l=o)||void 0===l?void 0:l.attributes.avatarUrl,botId:null===(r=o)||void 0===r?void 0:r.id,mediaType:"image",isPrivate:!0,prompt:a.title,modelId:Qe.id,_stickerEnergyPerItem:n,_genStartTime:i}}),...l]})}catch(c){kl(e=>e.filter(e=>!s.includes(e.id))),Tr((null===c||void 0===c?void 0:c.message)||"Failed to generate image")}finally{xe.d.getUserEnergy().then(e=>{"number"===typeof(null===e||void 0===e?void 0:e.energy)&&Number.isFinite(e.energy)&&T(e.energy)}).catch(()=>{})}},title:Ar.title,imageUrl:Ar.imageUrl,imageModel:Qe,videoPrice:go,onCreativeUpsell:()=>(0,Ht.BO)((0,r.A)((0,r.A)({},Ar.botId?{botId:Ar.botId}:{}),{},{surface:"generator"}))}),_r&&(0,ce.jsx)(Vt.e,{opened:!0,onClose:()=>Nr(null),onConfirm:()=>(async e=>{var t,a,l;if(!L||L.isAnon)return Nr(null),void O(!0);if(!e.prompt||null==e.botId||!Ze)return void Nr(null);const r=Ze.price;if(E<r)return Nr(null),void qr(e.botId);(0,Ht.cP)({botId:e.botId}),Nr(null),dr(!1),we("my");
1let o=re&&re.id===e.botId?re:null;if(!o)try{const t=await y.r.getBot(e.botId.toString());null!==t&&void 0!==t&&t.data&&(o=t.data)}catch(d){}const n=crypto.randomUUID(),s=Date.now(),i={id:n,status:"pending",botName:null===(t=o)||void 0===t?void 0:t.attributes.name,botAvatarUrl:null===(a=o)||void 0===a?void 0:a.attributes.avatarUrl,botId:null===(l=o)||void 0===l?void 0:l.id,mediaType:"image",isPrivate:!0,prompt:e.prompt,modelId:Ze.id,_stickerEnergyPerItem:r,_genStartTime:s};kl(e=>[i,...e]),P&&Yr();try{const t=(await xe.d.generateGalleryImageBatch({botId:String(e.botId),modelId:Ze.id,isPrivate:!0,count:1,prompt:e.prompt,from:"media_generator",productFeature:"photo_generator"})).items||[];kl(a=>{const l=a.filter(e=>e.id!==n);return[...t.map(t=>{var a,l,n;return{id:t.id,status:t.status,botName:null===(a=o)||void 0===a?void 0:a.attributes.name,botAvatarUrl:null===(l=o)||void 0===l?void 0:l.attributes.avatarUrl,botId:null===(n=o)||void 0===n?void 0:n.id,mediaType:"image",isPrivate:!0,prompt:e.prompt,modelId:Ze.id,_stickerEnergyPerItem:r,_genStartTime:s}}),...l]})}catch(c){kl(e=>e.filter(e=>e.id!==n)),Tr((null===c||void 0===c?void 0:c.message)||"Failed to enhance image")}finally{xe.d.getUserEnergy().then(e=>{"number"===typeof(null===e||void 0===e?void 0:e.energy)&&Number.isFinite(e.energy)&&T(e.energy)}).catch(()=>{})}})(_r),onOpenEnergyPaywall:()=>qr(_r.botId),imageUrl:_r.url,price:po})]});var yo,bo,Ao,fo,jo,Co,_o;return P?(0,ce.jsxs)(c.J,{header:z?(0,ce.jsx)(u.Y,{onBack:()=>(0,m.Tl)(M)}):void 0,children:[(0,ce.jsxs)("div",{className:Jt.A.pageMobile,children:[$?(0,ce.jsxs)(ce.Fragment,{children:[(0,ce.jsxs)("div",{className:Jt.A.mobileExpandedHeader,children:["video"===$&&(0,ce.jsx)("button",{className:Jt.A.mobileCloseBtn,onClick:ro,children:(0,ce.jsx)(Xt.US,{})}),(0,ce.jsx)("button",{className:Jt.A.mobileBtnActive,children:(0,ce.jsx)("span",{children:"image"===$?"Image":"Video"})}),"image"===$&&(0,ce.jsx)("button",{className:Jt.A.mobileCloseBtn,onClick:ro,children:(0,ce.jsx)(Xt.US,{})})]}),(0,ce.jsx)("div",{className:Jt.A.mobileForm,children:"image"===$?(0,ce.jsx)(ba,(0,r.A)((0,r.A)({},ho),{},{numImages:ve,setNumImages:he,discountsEnabled:qe})):(0,ce.jsx)(Aa,(0,r.A)((0,r.A)({},ho),{},{hidePrivacyToggle:!0,onGenerate:Kr,numVideos:be,setNumVideos:Ae,duration:pt,setDuration:gt,selectedVideoModel:ht,videoModels:st,isVideoModelPickerOpen:jt,setIsVideoModelPickerOpen:Ct,onVideoModelSelect:xt,selectedAction:It,setSelectedAction:wt,isActionModalOpen:Et,setIsActionModalOpen:mo,selectedVideoImage:Qt,setSelectedVideoImage:no,isImagePickerOpen:ta,setIsImagePickerOpen:aa,videoValidationErrors:Ka}))})]}):(0,ce.jsxs)("div",{className:Jt.A.mobileButtons,children:[(0,ce.jsxs)("button",{className:Jt.A.mobileBtn,onClick:()=>lo("image"),children:[(0,ce.jsx)(Xt.jD,{}),(0,ce.jsx)("span",{children:"Image"})]}),(0,ce.jsxs)("button",{className:Jt.A.mobileBtn,onClick:()=>lo("video"),children:[(0,ce.jsx)(Xt.Zn,{}),(0,ce.jsx)("span",{children:"Video"})]})]}),(0,ce.jsx)(Wa,{galleryTab:Ie,setGalleryTab:we,communityMedia:al,isCommunityLoading:cl,hasMoreCommunity:hl,hasMoreMyGallery:Ol+1<Dl,loadMoreRef:gl,generatingImages:Nl,onRetry:eo,openPreview:kr,onMakeVideo:wr,onExtendVideo:zr,myGalleryImages:Ml,isMyGalleryLoading:Tl,myGalleryLoadMoreRef:zl,currentUserId:null!==(yo=null===L||void 0===L?void 0:L.id)&&void 0!==yo?yo:null,onStartGenerate:to})]}),(()=>{const e="my"===Ie&&0===Ml.length&&0===Nl.length&&!Tl,t=!!$||e;return(0,ce.jsxs)("button",{type:"button",className:p()(Jt.A.mobileFloatingGenerate,{[Jt.A.mobileFloatingGenerateHidden]:t}),onClick:()=>{const e=document.querySelector(".main-content-desk");e?e.scrollTop=0:window.scrollTo({top:0}),lo("image")},"aria-hidden":t,tabIndex:t?-1:0,children:[(0,ce.jsx)(Ma.h,{className:Jt.A.mobileFloatingGenerateIcon,"aria-hidden":!0}),(0,ce.jsx)("span",{children:"Generate"})]})})(),(0,ce.jsx)(ge,{opened:ie,onClose:()=>de(!1),onSelect:e=>oo(e),selectedBotId:null!==(bo=null===re||void 0===re?void 0:re.id)&&void 0!==bo?bo:null,isMobile:P}),(0,ce.jsx)(Oe,{opened:Et,onClose:()=>Tt(!1),onSelect:e=>{wt(e),na(null),zt._w.photoGeneratorActionSelected({action_name:e.name})},selectedActionId:null!==(Ao=null===It||void 0===It?void 0:It.id)&&void 0!==Ao?Ao:null}),(0,ce.jsx)(vt,{opened:ta,onClose:()=>aa(!1),onSelect:(e,t,a)=>no({url:e,id:t,botId:a}),selectedImageUrl:null!==(fo=null===Qt||void 0===Qt?void 0:Qt.url)&&void 0!==fo?fo:null,isMobile:P,loadMoreBots:F,hasMoreBots:G}),(0,ce.jsx)(ft,{opened:da,onClose:()=>ca(!1),onSelect:e=>{na(e),wt(null),zt._w.photoGeneratorPoseSelected({pose_name:e.name})},selectedPoseId:null!==(jo=null===oa||void 0===oa?void 0:oa.id)&&void 0!==jo?jo:null,isMobile:P}),(0,ce.jsx)(Mt,{opened:Ca,onClose:()=>_a(!1),onSelect:e=>ga(e),selectedOutfitId:null!==(Co=null===pa||void 0===pa?void 0:pa.id)&&void 0!==Co?Co:null,isMobile:P}),(0,ce.jsx)(Ot,{opened:Ua,onClose:()=>La(!1),onSelect:e=>
1Ea(e),selectedBackgroundId:null!==(_o=null===Pa||void 0===Pa?void 0:Pa.id)&&void 0!==_o?_o:null,isMobile:P}),xo]}):(0,ce.jsxs)(c.J,{children:[(0,ce.jsxs)("div",{className:Jt.A.page,children:[(0,ce.jsx)("div",{className:Jt.A.header,children:(0,ce.jsxs)("div",{className:Jt.A.titleRow,children:[z&&(0,ce.jsx)(qa.h,{className:Jt.A.back,onClick:()=>(0,m.Tl)(M)}),(0,ce.jsxs)("h1",{className:Jt.A.title,children:["Generate AI ","video"===J?"Video":"Image"]})]})}),(0,ce.jsxs)("div",{className:Jt.A.content,children:[(0,ce.jsx)("div",{className:Jt.A.formPanel,children:(0,ce.jsxs)("div",{className:Jt.A.formCard,ref:Oa,children:[(0,ce.jsxs)("div",{className:Jt.A.mediaToggle,children:[(0,ce.jsx)("button",{className:p()(Jt.A.mediaToggleBtn,{[Jt.A.mediaToggleBtnActive]:"image"===J}),onClick:()=>{X("image"),zt._w.photoGeneratorImageTapped()},children:"Image"}),(0,ce.jsx)("button",{className:p()(Jt.A.mediaToggleBtn,{[Jt.A.mediaToggleBtnActive]:"video"===J}),onClick:()=>{X("video"),zt._w.photoGeneratorVideoTapped()},children:"Video"})]}),"image"===J?(0,ce.jsx)(ba,(0,r.A)((0,r.A)({},ho),{},{numImages:ve,setNumImages:he,discountsEnabled:qe})):(0,ce.jsx)(Aa,(0,r.A)((0,r.A)({},ho),{},{hidePrivacyToggle:!0,numVideos:be,setNumVideos:Ae,duration:pt,setDuration:gt,selectedVideoModel:ht,videoModels:st,isVideoModelPickerOpen:jt,setIsVideoModelPickerOpen:Ct,onVideoModelSelect:xt,selectedAction:It,setSelectedAction:wt,isActionModalOpen:Et,setIsActionModalOpen:mo,selectedVideoImage:Qt,setSelectedVideoImage:no,isImagePickerOpen:ta,setIsImagePickerOpen:aa,onGenerate:Kr,isGenerating:Xl,videoValidationErrors:Ka}))]})}),(0,ce.jsx)("div",{className:Jt.A.galleryPanel,children:(0,ce.jsx)(Wa,{galleryTab:Ie,setGalleryTab:we,communityMedia:al,isCommunityLoading:cl,hasMoreCommunity:hl,hasMoreMyGallery:Ol+1<Dl,loadMoreRef:gl,generatingImages:Nl,onRetry:eo,openPreview:kr,onMakeVideo:wr,onExtendVideo:zr,myGalleryImages:Ml,isMyGalleryLoading:Tl,myGalleryLoadMoreRef:zl,currentUserId:null!==(f=null===L||void 0===L?void 0:L.id)&&void 0!==f?f:null,onStartGenerate:to})})]})]}),(0,ce.jsx)(ge,{opened:ie,onClose:()=>de(!1),onSelect:e=>oo(e),selectedBotId:null!==(j=null===re||void 0===re?void 0:re.id)&&void 0!==j?j:null,isMobile:P}),(0,ce.jsx)(Oe,{opened:Et,onClose:()=>Tt(!1),onSelect:e=>{wt(e),na(null),zt._w.photoGeneratorActionSelected({action_name:e.name})},selectedActionId:null!==(C=null===It||void 0===It?void 0:It.id)&&void 0!==C?C:null}),(0,ce.jsx)(vt,{opened:ta,onClose:()=>aa(!1),onSelect:(e,t,a)=>Kt({url:e,id:t,botId:a}),selectedImageUrl:null!==(_=null===Qt||void 0===Qt?void 0:Qt.url)&&void 0!==_?_:null,isMobile:P,loadMoreBots:F,hasMoreBots:G}),(0,ce.jsx)(ft,{opened:da,onClose:()=>ca(!1),onSelect:e=>{na(e),wt(null),zt._w.photoGeneratorPoseSelected({pose_name:e.name})},selectedPoseId:null!==(N=null===oa||void 0===oa?void 0:oa.id)&&void 0!==N?N:null,isMobile:P}),(0,ce.jsx)(Mt,{opened:Ca,onClose:()=>_a(!1),onSelect:e=>ga(e),selectedOutfitId:null!==(k=null===pa||void 0===pa?void 0:pa.id)&&void 0!==k?k:null,isMobile:P}),(0,ce.jsx)(Ot,{opened:Ua,onClose:()=>La(!1),onSelect:e=>Ea(e),selectedBackgroundId:null!==(I=null===Pa||void 0===Pa?void 0:Pa.id)&&void 0!==I?I:null,isMobile:P}),xo]})}}}]);

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.