1import{dj as Ae,h as y,i as Me,dS as Te,k as ke,m as Ne,g as ze,u as Re,aR as Oe,fS as Ue,r as i,d1 as Ve,f3 as K,f2 as S,or as A,js as ie,nt as H,fW as ce,cc as ue,j as s,_ as $e,B as Q,at as X,ap as O,a as m,C as de,fV as J,A as M,aI as pe,e as Ee,ar as me,ct as Fe,ka as Le,aS as We,fT as qe,nw as Be,a9 as Y}from"./index-hM02A4WV.js";import{A as Ge}from"./adsCentralGenerateCtaStyles-D-2HLj8m.js";import{a as De,u as Ke}from"./briefVariationItem-Cv7PVLWC.js";import{C as He}from"./CloneVideoAnalysisChat-DzS9BNQF.js";import{S as Qe}from"./SelectProductModal-CkP0zovd.js";function he(e){return e?`${Ae.staging}/${e}`:""}function Xe(e){return e.replace(/_compressed(\.[^./]+)$/i,"$1")}function Je(e){return e?he(Xe(e)):""}function wt(e){const c=he(e);if(!c)return"";const r=e==null?void 0:e.split(".").pop();return!r||r===e?c:c.replace(new RegExp(`\\.${r}$`),`_compressed.${r}`)}function Ye(e){var u;const d=((e==null?void 0:e.name)||((u=e==null?void 0:e.storageKey)==null?void 0:u.split("/").pop())||"").trim().replace(/\.[a-z0-9]+$/i,"").replace(/[_-]*[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,"").replace(/__[0-9a-f]{6,}$/i,"").replace(/[_-]+/g," ").replace(/\s+/g," ").trim();return d?d.replace(/\b\w/g,a=>a.toUpperCase()):""}const Ze="_body_1lu6b_1",et="_previewPane_1lu6b_8",tt="_preview_1lu6b_8",st="_previewPortrait_1lu6b_31",at="_previewLandscape_1lu6b_36",rt="_previewSquare_1lu6b_41",ot="_previewMedia_1lu6b_50",nt="_panel_1lu6b_57",lt="_panelChat_1lu6b_75",it="_panelBody_1lu6b_80",ct="_selectionRow_1lu6b_89",ut="_selectionChip_1lu6b_97",dt="_selectionThumb_1lu6b_114",pt="_composer_1lu6b_123",l={body:Ze,previewPane:et,preview:tt,previewPortrait:st,previewLandscape:at,previewSquare:rt,previewMedia:ot,panel:nt,panelChat:lt,panelBody:it,selectionRow:ct,selectionChip:ut,selectionThumb:dt,composer:pt};function fe(e,c){return!e||!c?null:e===c?"square":e>c?"landscape":"portrait"}function mt(e){return e==="landscape"||e==="square"?e:"portrait"}function ft(e){return e==="landscape"?"16:9":e==="square"?"1:1":"9:16"}const ht=()=>{var le;const e=y(t=>t.homepageSlice.selectedTopAd),c=y(t=>t.homepageSlice.topPerformingAdModalOpened),r=y(t=>t.adGallery.selectedProductImages),f=y(t=>t.adGallery.selectedProductId),d=y(t=>t.adGallery.selectedProductDetails),u=y(t=>t.adGallery.customAvatar.selectedAvatar),a=Me(),Z=Te(),ge=ke(),U=Ne(),{brandId:v}=ze(),{t:o}=Re(),{checkIfSufficientCredits:xe}=Oe(),ve=De(U),{data:j}=Ue(c?v:void 0),_e=i.useMemo(()=>{if(!f||!(j!=null&&j.length))return(d==null?void 0:d.productName)??"";const t=j.find(n=>n.id===f);return(t==null?void 0:t.name)??(d==null?void 0:d.productName)??""},[f,j,d==null?void 0:d.productName]),[be,x]=i.useState(!1),[V,_]=i.useState(!1),[T,C]=i.useState(!1),[$,ee]=i.useState(""),[E,te]=i.useState(0),[we,F]=i.useState(null),[ye,se]=i.useState(!1),[ae,h]=i.useState(null),L=Ve(e==null?void 0:e.storageKey),b=Je(e==null?void 0:e.storageKey),re=Ye(e),k=we??mt(e==null?void 0:e.orientation),je=ft(k),g=k==="landscape"&&(u==null?void 0:u.landscapeUrl)||(u==null?void 0:u.portraitUrl),W=(le=r==null?void 0:r[0])==null?void 0:le.url,N=!!(W||f),z=!!g,Ce=i.useMemo(()=>!c||!(e!=null&&e.storageKey)||!L?null:K(e.storageKey),[c,e==null?void 0:e.storageKey,L]),{data:w}=Ke(Ce),q=i.useMemo(()=>{const t=Math.round(Number(w==null?void 0:w.duration)||0);return t>0?t:E>0?E:0},[w==null?void 0:w.duration,E]);i.useEffect(()=>{!V||!g||ae==="avatar"&&(_(!1),h(null))},[V,ae,g]);const Pe=i.useMemo(()=>({brandId:parseInt(v||"0",10),videoUrl:K((e==null?void 0:e.storageKey)||""),productImageUrls:r!=null&&r.length?r.map(t=>t.url):void 0,personaImageUrl:g||void 0,productId:f||""}),[e==null?void 0:e.storageKey,v,f,r,g]),B=i.useRef(null),G=i.useCallback(()=>{h(null),ee(""),te(0),F(null),x(!1),_(!1),C(!1)},[]),R=i.useCallback(()=>{a(S([])),a(A("")),a(ie({productId:"",productName:"",productDescription:""})),a(H(null)),a(ce())},[a]),Ie=i.useCallback(()=>{const t=B.current;if(B.current=null,!t){R();return}a(S(t.selectedProductImages)),a(ie(t.selectedProductDetails)),a(A(t.selectedProductId)),a(H(t.selectedAvatar)),t.uploadedAdFromMarketTrend?a(ue(t.uploadedAdFromMarketTrend)):a(ce())},[R,a]),oe=()=>{G(),Ie(),a(Be(!1))},ne=i.useRef(!1);i.useEffect(()=>{const t=c&&!ne.current;if(ne.current=c,!t)return;const{adGallery:n}=Z.getState();B.current={selectedProductImages:n.selectedProductImages,selectedProductId:n.selectedProductId,selectedProductDetails:n.selectedProductDetails,selectedAvatar:n.customAvatar.selectedAvatar,uploadedAdFromMarketTrend:n.uploadedAdFromMarketTrend},G(),R(),e!=null&&e.storageKey&&a(ue({storageKey:e.storageKey,id:e.id}))},[c,e==null?void 0:e.id,e==null?void 0:e.storageKey,a,Z,G,R]);const D=t=>{if(t==="avatar"&&!g){h("avatar"),_(!0);return}if(!f||t==="product"&&!(r!=null&&r.length)){h(t),x(!0);return}if(q<=0){Y.show({title:o("common.error",{defaultValue:"Error"}),message:o("adsCentral.cloneVideo.durationPending",{defaultValue:"Wait for the video duration to load, then try again."}),color:"yellow"});return}const n=Ge.CLONE_VIDEO*q;xe(n)&&(h(null),C(!0))},Se=async t=>{var p,P;if(!(e!=null&&e.storageKey))return;se(!0);const n=$.trim();try{await ve.mutateAsync({brandId:v||"",video_url:K(e.storageKey),aspect_ratio:je,locale:"en-us",product_image_urls:r!=null&&r.length?r.map(I=>I.url):[],product_id:f,persona_image_url:g,user_answers_for_cloning:n?[...t,{question:o("homepage.templates.customResponseLabel"),answer:n}]:t}),await Promise.all([U.invalidateQueries({queryKey:["get-brandId-loader","by","brandId",v]}
1),U.invalidateQueries({queryKey:["adInstanceItemsIndex"]})]),Y.show({title:o("common.success",{defaultValue:"Success"}),message:o("homepage.templates.cloneStarted"),color:"green"}),C(!1),oe(),ge(`/brands/${v}/ads-central`)}catch(I){Y.show({title:o("common.error",{defaultValue:"Error"}),message:(P=(p=I==null?void 0:I.response)==null?void 0:p.data)==null?void 0:P.detail,color:"red"})}finally{se(!1)}};return s.jsxs(s.Fragment,{children:[s.jsx($e,{opened:c,onClose:oe,radius:"md",centered:!0,size:"min(1180px, 95vw)",title:T?s.jsxs(me,{gap:"xs",children:[s.jsx(M,{variant:"subtle",color:"gray",size:"sm","aria-label":o("common.back",{defaultValue:"Back"}),onClick:()=>C(!1),children:s.jsx(We,{size:16})}),s.jsx(m,{fw:600,size:"sm",children:o("adsCentral.cloneVideo.analysisModal.title")})]}):s.jsx(m,{fw:600,size:"sm",children:re}),styles:{header:{padding:"14px 16px",minHeight:"unset",borderBottom:"1px solid var(--mantine-color-default-border)"},title:{lineHeight:1.2},body:{padding:0}},children:s.jsxs("div",{className:l.body,children:[s.jsx("div",{className:l.previewPane,children:s.jsx(Q,{className:`${l.preview} ${k==="landscape"?l.previewLandscape:k==="square"?l.previewSquare:l.previewPortrait}`,children:L&&b?s.jsx("video",{src:b,autoPlay:!0,muted:!0,loop:!0,controls:!0,playsInline:!0,className:l.previewMedia,onLoadedMetadata:t=>{const n=t.currentTarget,p=Math.round(n.duration);Number.isFinite(p)&&p>0&&te(p);const P=fe(n.videoWidth,n.videoHeight);P&&F(P)}},b):b?s.jsx(X,{src:b,alt:re,className:l.previewMedia,onLoad:t=>{const n=t.currentTarget,p=fe(n.naturalWidth,n.naturalHeight);p&&F(p)}},b):null})}),s.jsx("div",{className:T?`${l.panel} ${l.panelChat}`:l.panel,children:T?s.jsx(He,{active:T,preAssessmentInput:Pe,duration:q,isGenerating:ye,onGenerate:Se,onClose:()=>C(!1),fillHeight:!0}):s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:l.panelBody,children:[s.jsxs(O,{gap:4,align:"center",mb:"md",children:[s.jsx(m,{fw:600,size:"md",ta:"center",children:o("homepage.templates.recreateTitle")}),s.jsx(m,{size:"xs",c:"dimmed",ta:"center",children:o("homepage.templates.recreateSubtitle")})]}),s.jsxs(O,{gap:"xs",children:[s.jsx(de,{radius:"sm",h:48,fullWidth:!0,color:"indigo.9",onClick:()=>D("product"),children:s.jsxs(O,{gap:0,align:"center",children:[s.jsx(m,{size:"sm",fw:600,children:o("homepage.templates.recreateWithProduct")}),s.jsx(m,{size:"xs",opacity:.75,children:o("homepage.templates.recreateWithProductHint")})]})}),s.jsx(de,{radius:"sm",h:48,fullWidth:!0,variant:"default",onClick:()=>{a(J("select")),D("avatar")},children:s.jsxs(O,{gap:0,align:"center",children:[s.jsx(m,{size:"sm",fw:600,children:o("homepage.templates.recreateWithAvatar")}),s.jsx(m,{size:"xs",c:"dimmed",children:o("homepage.templates.recreateWithAvatarHint")})]})})]})]}),(N||z)&&s.jsxs("div",{className:l.selectionRow,children:[N&&s.jsxs("div",{className:l.selectionChip,onClick:()=>x(!0),onKeyDown:t=>{(t.key==="Enter"||t.key===" ")&&(t.preventDefault(),x(!0))},role:"button",tabIndex:0,children:[W?s.jsx(X,{src:W,alt:"",className:l.selectionThumb}):s.jsx(Q,{className:l.selectionThumb}),s.jsx(m,{size:"xs",fw:500,lineClamp:1,style:{minWidth:0},children:_e||o("homepage.templates.selectedProduct")}),s.jsx(M,{size:"xs",variant:"subtle",color:"gray","aria-label":o("homepage.templates.clearProduct"),onClick:t=>{t.stopPropagation(),a(S([])),a(A(null))},children:s.jsx(pe,{size:12})})]}),z&&s.jsxs("div",{className:l.selectionChip,onClick:()=>{a(J("select")),_(!0)},onKeyDown:t=>{(t.key==="Enter"||t.key===" ")&&(t.preventDefault(),a(J("select")),_(!0))},role:"button",tabIndex:0,children:[g?s.jsx(X,{src:g,alt:"",className:l.selectionThumb}):s.jsx(Q,{className:l.selectionThumb}),s.jsx(m,{size:"xs",fw:500,lineClamp:1,style:{minWidth:0},children:(u==null?void 0:u.name)||o("homepage.templates.selectedAvatar")}),s.jsx(M,{size:"xs",variant:"subtle",color:"gray","aria-label":o("homepage.templates.clearAvatar"),onClick:t=>{t.stopPropagation(),a(H(null))},children:s.jsx(pe,{size:12})})]})]}),s.jsxs("div",{className:l.composer,children:[s.jsx(Ee,{variant:"unstyled",autosize:!0,minRows:1,maxRows:4,placeholder:o("homepage.templates.customResponsePlaceholder"),value:$,onChange:t=>ee(t.currentTarget.value)}),s.jsxs(me,{justify:"space-between",mt:4,children:[s.jsx(M,{variant:"subtle",color:"gray","aria-label":o("homepage.templates.recreateWithProduct"),onClick:()=>x(!0),children:s.jsx(Fe,{size:16})}),s.jsx(M,{variant:"filled",color:"dark",radius:"xl","aria-label":o("homepage.templates.customResponseLabel"),disabled:!$.trim()&&!N&&!z,onClick:()=>D(z&&!N?"avatar":"product"),children:s.jsx(Le,{size:16})})]})]})]})})]})}),be&&s.jsx(Qe,{opened:!0,onClose:()=>{x(!1),h(null)},onSelect:t=>{a(S(t?[t]:[])),t!=null&&t.parentProductId&&a(A(t.parentProductId)),t&&(x(!1),h(null))},selectedProductImage:(r==null?void 0:r[0])??null,groupByCompatibility:!0,onUrlImportProductReady:({productId:t,images:n})=>{const p=n[0];a(S(p?[p]:[])),t&&a(A(t)),x(!1),h(null)}}),V&&s.jsx(qe,{opened:!0,onClose:()=>{_(!1),h(null)},brandId:v})]})},yt=Object.freeze(Object.defineProperty({__proto__:null,TopPerformingAdModal:ht},Symbol.toStringTag,{value:"Module"}));
1export{ht as T,yt as a,wt as h}; 2//# sourceMappingURL=TopPerformingAdModal-D8cddTUv.js.map
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.