1import{j as e,A as ut,m as ve}from"./vendor-ui-BRVg3_iW.js";import{r,d as qt}from"./vendor-react-fhnP-ZxB.js";import{a as Jt}from"./ToolLayout-Bc2WyZbj.js";import{_ as k,aC as Yt,Z as Qt,aD as Re,bh as Nt,S as wt,P as Zt,al as Xt,am as Kt,an as es,ao as ts,a7 as M,az as I,ai as Be,$ as je,ad as te,x as ss,j as kt,w as as,u as rs,ae as os,v as l,o as T,b8 as is,y as ee,a5 as ht,ak as xt,at as xe,aZ as pt,av as ls,bL as gt,a6 as ft,R as ns,aX as Le}from"./index-BTZS4ZAF.js";import{G as cs}from"./generate-button-DIINowSl.js";import{T as ds}from"./textarea-D-Y40bXc.js";import{L as _}from"./label-BPIIQwcF.js";import{S as Me,a as De,b as $e,c as Ve,d as D}from"./select-Djh3zId3.js";import{S as Ge}from"./skeleton-CccIXJL7.js";import{T as vt,a as jt,b as H,c as W}from"./tabs-B-u7iS49.js";import{S as Ct}from"./scroll-area-DqwOcre8.js";import{S as ms}from"./star-CcfTLwr2.js";import{G as us}from"./gift-BMLKMgm1.js";import{M as hs}from"./message-square-BP5RKd48.js";import{T as xs}from"./thumbs-up-Ccdwku38.js";import{u as ps}from"./usePlanRestrictions-sAzuqAso.js";import{L as gs}from"./lock-DeRcLZvT.js";import{g as q}from"./getAuthHeaders-BiSJ4AkO.js";import{U as fs}from"./upload-blZ-ZbK1.js";import{T as vs}from"./trash-2-4FJWEhhy.js";import{M as js}from"./mic-CF1Xk4wD.js";import{C as bt}from"./clapperboard-CiDPoDpi.js";import{I as bs}
1from"./info-BFYLvu4e.js";import{C as yt}from"./circle-check-big-B4TBZX_F.js";import{D as ys}from"./download-DVZYklFy.js";import"./sheet-BF2okP4S.js";import"./vendor-radix-B2hiDlNL.js";import"./collapsible-CSOUtSE9.js";import"./vendor-three-BixXOMS4.js";import"./vendor-charts-CM-rxR9X.js";import"./vendor-query-fmpM_ONB.js";import"./vendor-supabase-BDcQUG0T.js";import"./vendor-date-D8Ds2zcx.js";const Ns=[{id:"product-review",name:"Product Review",category:"Reviews",icon:e.jsx(ms,{className:"h-4 w-4"}),description:"Authentic product testimonial",script:`Hey everyone! I just have to share my experience with this amazing product. 2 3I've been using it for about two weeks now, and honestly? I'm impressed. 4 5Just look at this quality - the finish, the details, everything about it is premium. 6 7What I love most is how well it works. It's made such a difference in my daily routine. 8 9And the results? Absolutely game changing. I wish I'd found this sooner. 10 11If you're on the fence about trying it, I'd say go for it. Link is in the bio!`},{id:"unboxing",name:"Unboxing Reaction",category:"Unboxing",icon:e.jsx(us,{className:"h-4 w-4"}),description:"Excited first impressions",script:`Oh my gosh, it's finally here! I've been waiting for this to arrive and I'm so excited to show you. 12 13Let's open it up together and see what we've got! 14 15Okay wow, the packaging is already amazing. You can tell they really care about the details. 16 17And here it is... just look at this. This is even better than I expected! 18 19The quality is incredible, the design is beautiful. I cannot wait to start using this! 20 21Definitely worth every penny. Go check it out, link in my bio!`},{id:"testimonial",name:"Customer Testimonial",category:"Testimonials",icon:e.jsx(hs,{className:"h-4 w-4"}),description:"Genuine customer story",script:`I have to be honest with you - I was skeptical at first. I'd tried so many products before and nothing really worked. 22 23But then I discovered this, and everything changed. 24 25Look at the difference! Within just a few weeks, I noticed amazing results. 26 27Now I use it every single day and I can't imagine my routine without it. 28 29If you're struggling like I was, you need to try this. Trust me, it works. Link below!`},{id:"promo-announcement",name:"Sale Announcement",category:"Promotional",icon:e.jsx(Yt,{className:"h-4 w-4"}),description:"Limited time offer",script:`Stop scrolling! You need to hear this. 30 31[BRAND NAME] is having their biggest sale of the year, and you don't want to miss it. 32 33Right now you can get [DISCOUNT]% off everything, including their best-seller [PRODUCT NAME]. 34 35But hurry, this deal ends [END DATE]. 36 37Click the link in bio before it's gone!`},{id:"how-to",name:"Quick Tutorial",category:"Educational",icon:e.jsx(Qt,{className:"h-4 w-4"}),description:"Product demonstration",script:`Let me show you how easy it is to use [PRODUCT NAME]. 38 39Step one: [FIRST STEP] 40 41Step two: [SECOND STEP] 42 43And that's literally it! In just [TIME], you get [RESULT]. 44 45It's become part of my daily routine and I think you'll love it too. 46 47Link in bio if you want to try it yourself!`},{id:"comparison",name:"Before & After",category:"Testimonials",icon:e.jsx(xs,{className:"h-4 w-4"}),description:"Transformation story",script:`I have to show you my results with [PRODUCT NAME]. 48 49Before I started using it, [DESCRIBE BEFORE STATE]. 50 51But after just [TIMEFRAME] of consistent use, look at the difference! 52 53[DESCRIBE AFTER STATE] 54 55I'm honestly so happy I gave it a try. If you're thinking about it, do it!`},{id:"problem-solution",name:"Problem Solver",category:"Educational",icon:e.jsx(Re,{className:"h-4 w-4"}),description:"Address pain points",script:`Are you tired of [COMMON PROBLEM]? 56 57I used to deal with this all the time until I discovered [PRODUCT NAME]. 58 59What makes it different is [UNIQUE FEATURE]. 60 61Now instead of [OLD FRUSTRATION], I get to enjoy [NEW BENEFIT]. 62 63If this sounds like you, check out the link in my bio!`},{id:"lifestyle",name:"Day in My Life",category:"Lifestyle",icon:e.jsx(Nt,{className:"h-4 w-4"}),description:"Natural product integration",script:`Good morning everyone! Starting my day with [PRODUCT NAME] as usual. 64 65I love how it fits perfectly into my morning routine. 66 67It helps me [BENEFIT], which sets me up for a productive day. 68
69What I appreciate most is [SPECIFIC FEATURE]. 70 71If you want to upgrade your routine too, link is in bio!`}];function ws({onSelectTemplate:m}){return e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-xs text-muted-foreground",children:"Quick-start with a template:"}),e.jsx(Ct,{className:"h-[200px]",children:e.jsx("div",{className:"grid grid-cols-2 gap-2 pr-2",children:Ns.map(d=>e.jsxs(k,{variant:"outline",size:"sm",onClick:()=>m(d.script),className:"h-auto py-2 px-3 flex flex-col items-start text-left gap-1",children:[e.jsxs("div",{className:"flex items-center gap-2 w-full",children:[d.icon,e.jsx("span",{className:"text-xs font-medium truncate",children:d.name})]}),e.jsx("span",{className:"text-[10px] text-muted-foreground line-clamp-1",children:d.description})]},d.id))})})]})}const ks=({avatars:m,interval:d=2500,onSelectAvatar:h,selectedAvatar:x})=>{const[j,y]=r.useState(0),[N,C]=r.useState(!1);r.useEffect(()=>{if(x)return;const w=m.filter(F=>F.preview_image_url);if(w.length===0||N)return;const n=setInterval(()=>{y(F=>(F+1)%w.length)},d);return()=>clearInterval(n)},[m,d,N,x]);const f=m.filter(w=>w.preview_image_url);if(f.length===0)return null;const p=x||f[j%f.length];return e.jsxs("div",{className:"relative w-full max-w-md mx-auto",children:[e.jsxs("div",{className:"relative aspect-[9/16] rounded-2xl overflow-hidden bg-gradient-to-b from-muted/30 to-background border border-border/40 shadow-2xl",onMouseEnter:()=>C(!0),onMouseLeave:()=>C(!1),children:[e.jsx("div",{className:"absolute inset-0 bg-gradient-to-br from-primary/5 via-transparent to-accent/5"}),e.jsx(ut,{mode:"wait",children:e.jsxs(ve.div,{initial:{opacity:0,scale:1.02},animate:{opacity:1,scale:1},exit:{opacity:0,scale:.98},transition:{duration:.4,ease:"easeOut"},className:"absolute inset-0",children:[e.jsx("img",{src:p.preview_image_url,alt:p.avatar_name,className:"w-full h-full object-cover"}),e.jsx("div",{className:"absolute inset-0 bg-gradient-to-t from-black/90 via-black/20 to-transparent"})]},p.avatar_id)}),e.jsxs("div",{className:"absolute top-4 left-4 right-4 flex items-center justify-between z-10",children:[e.jsxs("div",{className:"flex items-center gap-2 bg-black/60 backdrop-blur-md rounded-full px-3 py-1.5",children:[e.jsx(wt,{className:"w-3.5 h-3.5 text-primary"}),e.jsx("span",{className:"text-xs font-medium text-white",children:x?"Selected Avatar":"AI Avatar Preview"})]}),!x&&e.jsx("div",{className:"bg-black/60 backdrop-blur-md rounded-full px-3 py-1.5",children:e.jsxs("span",{className:"text-xs font-medium text-white/80",children:[j%f.length+1," / ",f.length]})})]}),e.jsxs(ve.div,{initial:{opacity:0,y:10},animate:{opacity:1,y:0},transition:{duration:.3,delay:.1},className:"absolute bottom-0 left-0 right-0 p-5 z-10",children:[e.jsxs("div",{className:"text-center mb-3",children:[e.jsx("h3",{className:"text-xl font-semibold text-white",children:p.avatar_name}),p.gender&&e.jsxs("p",{className:"text-sm text-white/70 capitalize mt-0.5",children:[p.gender," Avatar"]})]}),!x&&e.jsxs("div",{className:"flex justify-center items-center gap-1.5 mb-4",children:[f.slice(0,5).map((w,n)=>e.jsx("button",{onClick:()=>y(n),className:`h-2 rounded-full transition-all duration-300 ${n===j%f.length?"bg-primary w-6":"bg-white/40 hover:bg-white/60 w-2"}`},n)),f.length>5&&e.jsxs("span",{className:"text-white/50 text-xs font-medium ml-1",children:["+",f.length-5]})]}),h&&e.jsxs("button",{onClick:()=>h(p),className:"w-full flex items-center justify-center gap-2 bg-primary hover:bg-primary/90 text-primary-foreground rounded-xl px-4 py-2.5 text-sm font-medium transition-all hover:scale-[1.02] active:scale-[0.98]",children:[e.jsx(Zt,{className:"w-4 h-4"}),"Use This Avatar"]})]},`info-${p.avatar_id}`),e.jsx(ut,{children:N&&!x&&e.jsx(ve.div,{initial:{opacity:0}
71,animate:{opacity:1},exit:{opacity:0},className:"absolute inset-0 flex items-center justify-center bg-black/20 z-20 pointer-events-none",children:e.jsx("div",{className:"bg-black/60 backdrop-blur-sm rounded-full p-4",children:e.jsx("div",{className:"w-4 h-4 border-l-2 border-r-2 border-white"})})})})]}),e.jsxs("p",{className:"text-center text-sm text-muted-foreground mt-4",children:["Choose from ",e.jsx("span",{className:"text-primary font-semibold",children:"500+"})," professional AI avatars"]})]})};function Cs({open:m,onOpenChange:d,avatars:h,selectedAvatarId:x,onSelectAvatar:j}){const[y,N]=r.useState(""),[C,f]=r.useState("all"),p=r.useMemo(()=>h.filter(n=>{var se;const F=n.avatar_name.toLowerCase().includes(y.toLowerCase()),be=C==="all"||((se=n.gender)==null?void 0:se.toLowerCase())===C;return F&&be}),[h,y,C]),w=n=>{j(n),d(!1)};return e.jsx(Xt,{open:m,onOpenChange:d,children:e.jsxs(Kt,{className:"max-w-4xl h-[85vh] flex flex-col p-0 gap-0",children:[e.jsx(es,{className:"px-6 py-4 border-b",children:e.jsxs(ts,{className:"flex items-center gap-3",children:[e.jsx(M,{className:"h-5 w-5"}),"Browse All Avatars",e.jsxs(I,{variant:"secondary",className:"ml-2",children:[p.length," of ",h.length]})]})}),e.jsxs("div",{className:"px-6 py-4 border-b bg-muted/30 flex gap-3",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(Be,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(je,{placeholder:"Search avatars by name...",value:y,onChange:n=>N(n.target.value),className:"pl-9"})]}),e.jsxs(Me,{value:C,onValueChange:f,children:[e.jsx(De,{className:"w-32",children:e.jsx($e,{placeholder:"Gender"})}),e.jsxs(Ve,{children:[e.jsx(D,{value:"all",children:"All Genders"}),e.jsx(D,{value:"male",children:"Male"}),e.jsx(D,{value:"female",children:"Female"})]})]}),(y||C!=="all")&&e.jsx(k,{variant:"ghost",size:"icon",onClick:()=>{N(""),f("all")},children:e.jsx(te,{className:"h-4 w-4"})})]}),e.jsxs(Ct,{className:"flex-1 px-6 py-4",children:[e.jsx("div",{className:"grid grid-cols-4 sm:grid-cols-5 md:grid-cols-6 lg:grid-cols-7 gap-3",children:p.map(n=>e.jsxs("button",{onClick:()=>w(n.avatar_id),className:ss("relative aspect-[3/4] rounded-xl overflow-hidden border-2 transition-all hover:scale-105",x===n.avatar_id?"border-primary ring-2 ring-primary/30 scale-105":"border-border hover:border-primary/50"),children:[n.preview_image_url?e.jsx("img",{src:n.preview_image_url,alt:n.avatar_name,className:"w-full h-full object-cover",loading:"lazy"}):e.jsx("div",{className:"w-full h-full bg-muted flex items-center justify-center",children:e.jsx(M,{className:"h-8 w-8 text-muted-foreground"})}),e.jsxs("div",{className:"absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/90 via-black/60 to-transparent p-2",children:[e.jsx("p",{className:"text-xs text-white font-medium truncate",children:n.avatar_name}),n.gender&&e.jsx("p",{className:"text-[10px] text-white/70 capitalize",children:n.gender})]}),x===n.avatar_id&&e.jsx("div",{className:"absolute top-2 right-2 w-6 h-6 bg-primary rounded-full flex items-center justify-center shadow-lg",children:e.jsx(kt,{className:"h-4 w-4 text-primary-foreground"})})]},n.avatar_id))}),p.length===0&&e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-muted-foreground",children:[e.jsx(M,{className:"h-12 w-12 mb-3 opacity-50"}),e.jsx("p",{children:"No avatars found matching your search"})]})]}),e.jsxs("div",{className:"px-6 py-4 border-t bg-muted/30 flex items-center justify-between",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Click an avatar to select and close"}),e.jsx(k,{variant:"outline",onClick:()=>d(!1),children:"Close"})]})]})})}function Ss({toolName:m,minimumPlanDisplayName:d,currentPlanDisplayName:h,description:x}){const j=qt();return e.jsxs(ve.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:"flex flex-col items-center justify-center min-h-[400px] p-8 text-center",children:[e.jsxs("div",{className:"relative mb-6",children:[e.jsx("div",{className:"w-20 h-20 rounded-full bg-gradient-to-br from-violet-500/20 to-purple-500/20 flex items-center justify-center",children:e.jsx(gs,{className:"w-10 h-10 text-violet-400"})}),e.jsx("div",{className:"absolute -top-1 -right-1 w-6 h-6 rounded-full bg-primary flex items-center justify-center",children:e.jsx(wt,{className:"w-3 h-3 text-primary-foreground"})})]}),e.jsxs("h2",{className:"text-2xl font-bold text-foreground mb-2",children:[m," Requires ",d,"+"]}),e.jsx("p",{className:"text-muted-foreground max-w-md mb-2",children:x||`Upgrade to ${d} or higher to unlock ${m} and create stunning AI-powered content.`}
71),h&&e.jsxs("p",{className:"text-sm text-muted-foreground/70 mb-6",children:["Your current plan: ",e.jsx("span",{className:"font-medium text-foreground",children:h})]}),e.jsxs("div",{className:"flex flex-col sm:flex-row gap-3",children:[e.jsxs(k,{onClick:()=>j("/pricing"),className:"bg-gradient-to-r from-violet-500 to-purple-500 hover:from-violet-600 hover:to-purple-600",children:["Upgrade to ",d,e.jsx(as,{className:"ml-2 h-4 w-4"})]}),e.jsx(k,{variant:"outline",onClick:()=>j("/dashboard"),children:"Browse Other Tools"})]}),e.jsx("div",{className:"mt-8 p-4 rounded-xl bg-muted/30 border border-border max-w-sm",children:e.jsxs("p",{className:"text-sm text-muted-foreground",children:[e.jsxs("span",{className:"font-medium text-foreground",children:[d," includes:"]})," ","300 credits/mo, UGC video creation, HD exports, and priority support."]})})]})}const pe="generate-ugc-video";function Is(m){const d=m.split(` 72`).filter(N=>N.trim()),h=d.length;if(h<=2)return[{type:"intro",text:m}];const x=Math.ceil(h*.4),j=Math.ceil(h*.7);return[{type:"intro",text:d.slice(0,x).join(` 73`)},{type:"product",text:d.slice(x,j).join(` 74`)},{type:"cta",text:d.slice(j).join(` 75`)}].filter(N=>N.text.trim())}const ge=[{min:0,label:"Initializing",icon:"â³"},{min:30,label:"Generating voice",icon:"ðï¸"},{min:90,label:"Animating avatar",icon:"ð"},{min:180,label:"Syncing lips",icon:"ð"},{min:300,label:"Rendering video",icon:"ð¬"},{min:480,label:"Final processing",icon:"â¨"},{min:600,label:"Complex script - still processing",icon:"â³"},{min:900,label:"Almost done - hang tight!",icon:"ð¯"}],fe=m=>{for(let d=ge.length-1;d>=0;d--)if(m>=ge[d].min)return ge[d];return ge[0]},Ts=[{name:"White",value:"#FFFFFF"},{name:"Off-White",value:"#FAFAFA"},{name:"Light Gray",value:"#F5F5F5"},{name:"Black",value:"#000000"},{name:"Green Screen",value:"#00FF00"},{name:"Blue",value:"#1E40AF"}];function ca(){const{user:m}=rs(),{deductCredits:d,refundCredits:h,getToolCost:x,hasEnoughCredits:j,balance:y}=os(),{canAccessUGC:N,getToolRestriction:C,isLoading:f}=ps(),[p,w]=r.useState(null),[n,F]=r.useState([]),[be,se]=r.useState([]),[St,It]=r.useState([]),[ye,Ne]=r.useState([]),[U,J]=r.useState(""),[L,Y]=r.useState(""),[A,$]=r.useState("avatar"),[we,ze]=r.useState(""),[G,Oe]=r.useState(""),[R,Tt]=r.useState("16:9"),[P,ae]=r.useState(!1),[re,_t]=r.useState(!0),[Ut,At]=r.useState(!0),[He,We]=r.useState(!1),[ke,Ce]=r.useState(null),[Se,Ie]=r.useState(null),[qe,Q]=r.useState(""),[S,Je]=r.useState(0),[Pt,oe]=r.useState("preset"),[Te,Et]=r.useState(""),[_e,Ft]=r.useState("all"),[Lt,_s]=r.useState(50),[Gt,Ye]=r.useState(!1),[Ue,Z]=r.useState("color"),[X,Ae]=r.useState("#FFFFFF"),[b,ie]=r.useState(null),[le,Qe]=r.useState(null),[ne,Ze]=r.useState(!1),[V,Xe]=r.useState(null),[Ke,et]=r.useState(!1),[B,tt]=r.useState(null),[ce,Rt]=r.useState("top-right"),[st,at]=r.useState(!1),[E,Pe]=r.useState("background"),de=r.useRef(null),rt=r.useRef(null),ot=r.useRef(null),Ee=C(pe);if(!f&&Ee.isRestricted)return e.jsx("div",{className:"min-h-screen bg-background",children:e.jsx(Ss,{toolName:"UGC Video Studio",minimumPlanDisplayName:Ee.minimumPlanDisplayName||"Pro",currentPlanDisplayName:Ee.currentPlanDisplayName,description:"Create stunning AI avatar videos that showcase your products with realistic presenters, voice-overs, and natural gestures."})});const Fe=j(pe),it=x(pe);r.useEffect(()=>{const t=async()=>{var o;try{const i=await q(),u=await fetch("https://uemglyheqrjfpanjsjkh.supabase.co/functions/v1/generate-ugc-video?action=avatars",{method:"GET",headers:i});if(!u.ok)throw new Error("Failed to fetch avatars");const c=await u.json();F(c.avatars||[]),((o=c.avatars)==null?void 0:o.length)>0&&J(c.avatars[0].avatar_id)}catch(i){console.error("Error fetching avatars:",i),l.error("Failed to load avatars")}finally{_t(!1)}},s=async()=>{try{const o=await q(),i=await fetch("https://uemglyheqrjfpanjsjkh.supabase.co/functions/v1/generate-ugc-video?action=voices",{method:"GET",headers:o});if(!i.ok)throw new Error("Failed to fetch voices");const c=((await i.json()).voices||[]).filter(v=>{var g;return((g=v.language)==null?void 0:g.toLowerCase().includes("english"))||!v.language});se(c.slice(0,30)),c.length>0&&ze(c[0].voice_id)}catch(o){console.error("Error fetching voices:",o),l.error("Failed to load voices")}finally{At(!1)}},a=async()=>{try{const o=await q(),i=await fetch("https://uemglyheqrjfpanjsjkh.supabase.co/functions/v1/generate-ugc-video?action=talking-photos",{method:"GET",headers:o});if(!i.ok)throw new Error("Failed to fetch talking photos");const u=await i.json();It(u.talkingPhotos||[])}catch(o){console.error("Error fetching talking photos:",o)}};t(),s(),a()},[]),r.useEffect(()=>{if(!m)return;(async()=>{const{data:s,error:a}=await T.from("user_talking_photos").select("*").eq("user_id",m.id).order("created_at",{ascending:!1});if(a){console.error("Error fetching user talking photos:",a);return}Ne(s||[])})()},[m]),r.useEffect(()=>{if(!Se)return;const t=setInterval(async()=>{var s,a,o;try{const i=await q(),u=await fetch(`https://uemglyheqrjfpanjsjkh.supabase.co/functions/v1/generate-ugc-video?action=status&videoId=${Se}`,{method:"GET",headers:i});if(!u.ok){console.warn("Status check returned:",u.status);return}const c=await u.json(),v=typeof c.status=="string"?c.status:"processing";if(Q(v),c.status==="completed"&&c.videoUrl){Ce(c.videoUrl),ae(!1),Ie(null),l.success("UGC video generated successfully!");const{data:g}=await T.auth.getSession();(a=(s=g==null?void 0:g.session)==null?void 0:s.user)!=null&&a.id&&is({userId:g.session.user.id,name:`UGC Video - ${new Date().toLocaleDateString()}`,content:c.videoUrl,type:"video_prompt",tags:["ugc-studio","video"],metadata:{}})}else if(c.status==="failed"){ae(!1),Ie(null);const g=typeof c.error=="string"?c.error:((o=c.error)==null?void 0:o.message)||"Video generation failed";l.error(g),p&&(await h(p),w(null))}}catch(i){console.error("Status poll error:",i)}},5e3);return()=>clearInterval(t)},[Se,p,h]),r.useEffect(()=>{if(!P){Je(0);return}const t=setInterval(()=>{Je(s=>s+1)},1e3);return()=>clearInterval(t)},[P]);const Bt=r.useCallback(async t=>{if(!m){l.error("Please sign in to upload custom avatars");return}if(!t.type.startsWith("image/")){l.error("Please upload an image file (JPEG or PNG)");return}if(t.size>10*1024*1024){l.error("File size must be under 10MB");return}We(!0);try{const s=t.name.split(".").pop(),a=`${m.id}/${crypto.randomUUID()}.${s}`,{data:o,error:i}=await T.storage.from("motion-video-uploads").upload(a,t,{contentType:t.type});if(i)throw i;const{data:{publicUrl:u}}=T.storage.from("motion-video-uploads").getPublicUrl(a),c=await q(),v=await fetch("https://uemglyheqrjfpanjsjkh.supabase.co/functions/v1/generate-ugc-video?action=upload-talking-photo",{method:"POST",headers:{...c,"Content-Type":"application/json"},body:JSON.stringify({imageUrl:u})});if(!v.ok){const O=await v.json();throw new Error(O.error||"Failed to create talking photo")}const g=await v.json(),{data:z,error:K}
75=await T.from("user_talking_photos").insert({user_id:m.id,talking_photo_id:g.talking_photo_id,preview_url:g.preview_url||u,name:t.name.replace(/\.[^/.]+$/,"")}).select().single();if(K)throw K;Ne(O=>[z,...O]),Y(g.talking_photo_id),$("talking_photo"),oe("my-avatars"),l.success("Custom avatar created successfully!")}catch(s){console.error("Upload error:",s);const a=s instanceof Error?s.message:"Failed to upload photo";a.toLowerCase().includes("face")?l.error("No face detected. Please upload a clear, front-facing portrait photo.",{duration:5e3}):a.toLowerCase().includes("storage")||a.toLowerCase().includes("upload")?l.error("Upload failed. Please check your connection and try again."):a.toLowerCase().includes("network")?l.error("Network error. Please check your connection and try again."):l.error(a)}finally{We(!1)}},[m]),Mt=async t=>{if(confirm("Are you sure you want to delete this avatar?"))try{const s=await q();await fetch(`https://uemglyheqrjfpanjsjkh.supabase.co/functions/v1/generate-ugc-video?action=delete-talking-photo&id=${t.talking_photo_id}`,{method:"DELETE",headers:s}),await T.from("user_talking_photos").delete().eq("id",t.id),Ne(a=>a.filter(o=>o.id!==t.id)),L===t.talking_photo_id&&(Y(""),$("avatar")),l.success("Avatar deleted")}catch(s){console.error("Delete error:",s),l.error("Failed to delete avatar")}},me=async(t,s)=>{const a=t.name.split(".").pop(),o=`${s}/${crypto.randomUUID()}.${a}`,{error:i}=await T.storage.from("motion-video-uploads").upload(o,t,{contentType:t.type});if(i)throw i;const{data:{publicUrl:u}}=T.storage.from("motion-video-uploads").getPublicUrl(o);return u},lt=r.useCallback(async(t,s)=>{if(s==="image"&&!t.type.startsWith("image/")){l.error("Please upload an image file");return}if(s==="video"&&!t.type.startsWith("video/")){l.error("Please upload a video file");return}if(t.size>50*1024*1024){l.error("File size must be under 50MB");return}Ze(!0);try{const a=await me(t,"ugc-backgrounds");s==="image"?(ie(a),Z("image")):(Qe(a),Z("video")),l.success(`Background ${s} uploaded`)}catch(a){console.error("Upload error:",a),l.error("Failed to upload background")}finally{Ze(!1)}},[]),Dt=r.useCallback(async t=>{if(!t.type.startsWith("image/")){l.error("Please upload an image file");return}if(t.size>10*1024*1024){l.error("File size must be under 10MB");return}et(!0);try{const s=await me(t,"ugc-products");Xe(s),ie(s),Z("image"),l.success("Product photo uploaded - using as background")}catch(s){console.error("Upload error:",s),l.error("Failed to upload product photo")}finally{et(!1)}},[]),$t=r.useCallback(async t=>{if(!t.type.startsWith("image/")){l.error("Please upload an image file");return}if(t.size>5*1024*1024){l.error("File size must be under 5MB");return}at(!0);try{const s=await me(t,"ugc-logos");tt(s),l.success("Logo uploaded")}catch(s){console.error("Upload error:",s),l.error("Failed to upload logo")}finally{at(!1)}},[]),Vt=async()=>!B||!b?b:new Promise(t=>{const s=document.createElement("canvas"),a=s.getContext("2d");if(!a){t(b);return}const o=new window.Image;o.crossOrigin="anonymous",o.onload=()=>{s.width=o.width,s.height=o.height,a.drawImage(o,0,0);const i=new window.Image;i.crossOrigin="anonymous",i.onload=async()=>{const u=s.width*.15,c=Math.min(1,u/i.width),v=i.width*c,g=i.height*c,z=s.width*.02;let K=z,O=z;ce.includes("right")&&(K=s.width-v-z),ce.includes("bottom")&&(O=s.height-g-z),a.drawImage(i,K,O,v,g),s.toBlob(async mt=>{if(!mt){t(b);return}try{const Ht=new File([mt],"composed-background.png",{type:"image/png"}),Wt=await me(Ht,"ugc-composed");t(Wt)}catch{t(b)}},"image/png")},i.onerror=()=>t(b),i.src=B},o.onerror=()=>t(b),o.src=b}),nt=async()=>{if(!(A==="avatar"?U:L)||!G.trim()){l.error("Please select an avatar and enter a script");return}const s=await d(pe);if(s.success){w(s.transactionId||null),ae(!0),Ce(null),Q("starting");try{let a={type:"color",value:X};if(Ue==="image"&&b){let c=b;if(B){Q("composing logo");const v=await Vt();v&&(c=v)}a={type:"image",url:c}}else Ue==="video"&&le&&(a={type:"video",url:le,play_style:"loop"});const o={voiceId:we||void 0,aspectRatio:R,test:!1};if(A==="avatar"?o.avatarId=U:o.talkingPhotoId=L,V&&E!=="background"){Q("preparing multi-scene video");const c=Is(G.trim());o.multiScene=!0,o.productImageUrl=V,o.displayMode=E,o.scriptSections=c,o.backgroundColor=X,B&&(o.logoUrl=B,o.logoPosition=ce)}else o.script=G.trim(),o.background=a;const{data:i,error:u}=await T.functions.invoke("generate-ugc-video",{body:o});if(u){const c=typeof u=="object"&&u!==null&&"message"in u?String(u.message):"Failed to start generation";throw new Error(c)}if(i!=null&&i.error)throw new Error(String(i.error));Ie(i.videoId),Q("queued"),l.info(E!=="background"&&V?"Multi-scene video generation started. This may take 3-6 minutes...":"Video generation started. This may take 2-5 minutes...")}catch(a){console.error("Generation error:",a);const o=a instanceof Error?a.message:"Failed to start generation";l.error(o),s.transactionId&&(await h(s.transactionId),w(null)),ae(!1)}}},ct=t=>{const s=Math.floor(t/60),a=t%60;return`${s}:${a.toString().padStart(2,"0")}`},ue=n.filter(t=>{var o,i;const s=!Te||((o=t.avatar_name)==null?void 0:o.toLowerCase().includes(Te.toLowerCase())),a=_e==="all"||((i=t.gender)==null?void 0:i.toLowerCase())===_e.toLowerCase();return s&&a}),he=n.find(t=>t.avatar_id===U),dt=[...St,...ye.map(t=>({talking_photo_id:t.talking_photo_id,talking_photo_name:t.name,talking_photo_url:t.preview_url,preview_image_url:t.preview_url}))].find(t=>
75t.talking_photo_id===L),zt=e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs(_,{className:"flex items-center gap-2",children:[e.jsx(M,{className:"h-4 w-4"}),"Select Avatar"]}),e.jsxs(vt,{value:Pt,onValueChange:t=>oe(t),children:[e.jsxs(jt,{className:"grid w-full grid-cols-3",children:[e.jsx(H,{value:"preset",className:"text-xs",children:"Preset"}),e.jsx(H,{value:"upload",className:"text-xs",children:"Upload"}),e.jsx(H,{value:"my-avatars",className:"text-xs",children:"My Avatars"})]}),e.jsxs(W,{value:"preset",className:"space-y-3 mt-3",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(Be,{className:"absolute left-2 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(je,{placeholder:"Search avatars...",value:Te,onChange:t=>Et(t.target.value),className:"pl-8 h-8 text-sm"})]}),e.jsxs(Me,{value:_e,onValueChange:Ft,children:[e.jsx(De,{className:"w-24 h-8",children:e.jsx($e,{})}),e.jsxs(Ve,{children:[e.jsx(D,{value:"all",children:"All"}),e.jsx(D,{value:"male",children:"Male"}),e.jsx(D,{value:"female",children:"Female"})]})]})]}),e.jsx("div",{className:"flex items-center justify-between mb-2",children:e.jsxs(I,{variant:"secondary",className:"text-xs",children:[ue.length," avatars available"]})}),re?e.jsx("div",{className:"grid grid-cols-4 gap-2",children:[...Array(16)].map((t,s)=>e.jsx(Ge,{className:"aspect-[3/4] rounded-lg"},s))}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"grid grid-cols-4 gap-2 max-h-[400px] overflow-y-auto pr-1",children:ue.slice(0,Lt).map(t=>e.jsxs("button",{onClick:()=>{J(t.avatar_id),$("avatar"),Y("")},className:`relative aspect-[3/4] rounded-lg overflow-hidden border-2 transition-all ${U===t.avatar_id&&A==="avatar"?"border-primary ring-2 ring-primary/30":"border-border hover:border-primary/50"}`,children:[t.preview_image_url?e.jsx("img",{src:t.preview_image_url,alt:t.avatar_name,className:"w-full h-full object-cover",loading:"lazy"}):e.jsx("div",{className:"w-full h-full bg-muted flex items-center justify-center",children:e.jsx(M,{className:"h-6 w-6 text-muted-foreground"})}),e.jsxs("div",{className:"absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/80 via-black/50 to-transparent p-1.5",children:[e.jsx("p",{className:"text-[10px] text-white font-medium truncate",children:t.avatar_name}),t.gender&&e.jsx("p",{className:"text-[8px] text-white/60 capitalize",children:t.gender})]}),U===t.avatar_id&&A==="avatar"&&e.jsx("div",{className:"absolute top-1 right-1 w-4 h-4 bg-primary rounded-full flex items-center justify-center",children:e.jsx(kt,{className:"h-2.5 w-2.5 text-primary-foreground"})})]},t.avatar_id))}),e.jsxs(k,{variant:"outline",size:"sm",onClick:()=>Ye(!0),className:"w-full mt-3 gap-2",children:[e.jsx(Be,{className:"h-4 w-4"}),"Browse All Avatars (",ue.length," available)"]}),e.jsx(Cs,{open:Gt,onOpenChange:Ye,avatars:n,selectedAvatarId:U,onSelectAvatar:t=>{J(t),$("avatar"),Y("")}})]}),ue.length===0&&!re&&e.jsx("p",{className:"text-sm text-muted-foreground text-center py-4",children:"No avatars found"})]}),e.jsxs(W,{value:"upload",className:"space-y-3 mt-3",children:[e.jsx("div",{className:`border-2 border-dashed rounded-lg p-6 text-center transition-colors ${He?"border-primary bg-primary/5":"border-border hover:border-primary/50"}`,children:He?e.jsxs("div",{className:"space-y-2",children:[e.jsx(ee,{className:"h-8 w-8 animate-spin mx-auto text-primary"}),e.jsx("p",{className:"text-sm",children:"Creating your avatar..."})]}):e.jsxs("label",{className:"cursor-pointer block",children:[e.jsx("input",{type:"file",accept:"image/jpeg,image/png,image/webp",className:"hidden",onChange:t=>{var a;const s=(a=t.target.files)==null?void 0:a[0];s&&Bt(s)}}),e.jsx(ht,{className:"h-10 w-10 mx-auto text-muted-foreground mb-2"}),e.jsx("p",{className:"text-sm font-medium",children:"Upload a photo"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"JPEG or PNG, face clearly visible"})]})}),e.jsxs("div",{className:"bg-muted/50 rounded-lg p-3 space-y-1",children:[e.jsx("p",{className:"text-xs font-medium",children:"Tips for best results:"}),e.jsxs("ul",{className:"text-xs text-muted-foreground space-y-0.5",children:[e.jsx("li",{children:"⢠Use a clear, front-facing portrait"}),e.jsx("li",{children:"⢠Good lighting, no shadows on face"}),e.jsx("li",{children:"⢠Neutral expression works best"}),e.jsx("li",{children:"⢠One person only in the photo"})]})]})]}),e.jsx(W,{value:"my-avatars",className:"space-y-3 mt-3",children:m?ye.length===0?e.jsxs("div",{className:"text-center py-6",children:[e.jsx(fs,{className:"h-10 w-10 mx-auto text-muted-foreground mb-2"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"No custom avatars yet"}),e.jsx(k,{variant:"link",size:"sm",onClick:()=>oe("upload"),children:"Upload your first one"})]}):e.jsx("div",{className:"grid grid-cols-3 gap-2 max-h-[240px] overflow-y-auto",children:ye.map(t=>e.jsxs("div",{className:`relative aspect-square rounded-lg overflow-hidden border-2 transition-all group ${L===t.talking_photo_id&&A==="talking_photo"?"border-primary ring-2 ring-primary/30":"border-border hover:border-primary/50"}`,children:[e.jsx("button",{onClick:()=>{Y(t.talking_photo_id),$("talking_photo"),J("")},className:"w-full h-full",children:t.preview_url?e.jsx("img",{src:t.preview_url,alt:t.name||"Custom avatar",className:"w-full h-full object-cover"}):e.jsx("div",{className:"w-full h-full bg-muted flex items-center justify-center",children:e.jsx(M,{className:"h-6 w-6 text-muted-foreground"})})}),e.jsx("button",{onClick:()=>Mt(t),className:"absolute top-1 right-1 p-1 rounded-full bg-destructive/90 text-destructive-foreground opacity-0 group-hover:opacity-100 transition-opacity",children:e.jsx(vs,{className:"h-3 w-3"})}),e.jsx(I,{variant:"secondary",className:"absolute bottom-1 left-1 text-[9px] px-1 py-0",children:"Custom"})]},t.id))}):e.jsxs("div",{className:"text-center py-6",children:[e.jsx(M,{className:"h-10 w-10 mx-auto text-muted-foreground mb-2"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Sign in to save custom avatars"})]})})]}),A==="avatar"&&he&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Selected: ",he.avatar_name]}),A==="talking_photo"&&dt&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Selected: ",dt.talking_photo_name||"Custom Avatar"]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(_,{className:"flex items-center gap-2",children:[e.jsx(js,{className:"h-4 w-4"}),"Voice"]}),Ut?e.jsx(Ge,{className:"h-10 w-full"}):e.jsxs(Me,{value:we,onValueChange:ze,children:[e.jsx(De,{children:e.jsx($e,{placeholder:"Select a voice"})}),e.jsx(Ve,{children:be.map(t=>e.jsxs(D,{value:t.voice_id,children:[t.name," ",t.gender&&`(${t.gender})`]},t.voice_id))})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs(_,{className:"flex items-center gap-2",children:[e.jsx(xt,{className:"h-4 w-4"}
75),"Background"]}),e.jsxs(vt,{value:Ue,onValueChange:t=>Z(t),children:[e.jsxs(jt,{className:"grid w-full grid-cols-3",children:[e.jsxs(H,{value:"color",className:"text-xs gap-1",children:[e.jsx(xt,{className:"h-3 w-3"}),"Color"]}),e.jsxs(H,{value:"image",className:"text-xs gap-1",children:[e.jsx(xe,{className:"h-3 w-3"}),"Image"]}),e.jsxs(H,{value:"video",className:"text-xs gap-1",children:[e.jsx(pt,{className:"h-3 w-3"}),"Video"]})]}),e.jsxs(W,{value:"color",className:"space-y-3 mt-3",children:[e.jsx("div",{className:"grid grid-cols-6 gap-2",children:Ts.map(t=>e.jsx("button",{onClick:()=>Ae(t.value),className:`aspect-square rounded-lg border-2 transition-all ${X===t.value?"border-primary ring-2 ring-primary/30":"border-border hover:border-primary/50"}`,style:{backgroundColor:t.value},title:t.name},t.value))}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_,{className:"text-xs text-muted-foreground",children:"Custom:"}),e.jsx(je,{type:"color",value:X,onChange:t=>Ae(t.target.value),className:"w-10 h-8 p-0.5 cursor-pointer"}),e.jsx(je,{value:X,onChange:t=>Ae(t.target.value),placeholder:"#FFFFFF",className:"flex-1 h-8 text-xs font-mono"})]})]}),e.jsxs(W,{value:"image",className:"space-y-3 mt-3",children:[e.jsx("input",{ref:de,type:"file",accept:"image/*",className:"hidden",onChange:t=>{var a;const s=(a=t.target.files)==null?void 0:a[0];s&<(s,"image")}}),b?e.jsxs("div",{className:"relative rounded-lg overflow-hidden border border-border",children:[e.jsx("img",{src:b,alt:"Background",className:"w-full h-24 object-cover"}),e.jsx("button",{onClick:()=>ie(null),className:"absolute top-1 right-1 p-1 rounded-full bg-destructive text-destructive-foreground",children:e.jsx(te,{className:"h-3 w-3"})})]}):e.jsx("button",{onClick:()=>{var t;return(t=de.current)==null?void 0:t.click()},disabled:ne,className:"w-full border-2 border-dashed rounded-lg p-4 text-center transition-colors border-border hover:border-primary/50",children:ne?e.jsx(ee,{className:"h-6 w-6 animate-spin mx-auto text-primary"}):e.jsxs(e.Fragment,{children:[e.jsx(ht,{className:"h-6 w-6 mx-auto text-muted-foreground mb-1"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Upload background image"})]})})]}),e.jsxs(W,{value:"video",className:"space-y-3 mt-3",children:[e.jsx("input",{ref:de,type:"file",accept:"video/*",className:"hidden",onChange:t=>{var a;const s=(a=t.target.files)==null?void 0:a[0];s&<(s,"video")}}),le?e.jsxs("div",{className:"relative rounded-lg overflow-hidden border border-border",children:[e.jsx("video",{src:le,className:"w-full h-24 object-cover",muted:!0,loop:!0,autoPlay:!0}),e.jsx("button",{onClick:()=>Qe(null),className:"absolute top-1 right-1 p-1 rounded-full bg-destructive text-destructive-foreground",children:e.jsx(te,{className:"h-3 w-3"})})]}):e.jsx("button",{onClick:()=>{var t;return(t=de.current)==null?void 0:t.click()},disabled:ne,className:"w-full border-2 border-dashed rounded-lg p-4 text-center transition-colors border-border hover:border-primary/50",children:ne?e.jsx(ee,{className:"h-6 w-6 animate-spin mx-auto text-primary"}):e.jsxs(e.Fragment,{children:[e.jsx(pt,{className:"h-6 w-6 mx-auto text-muted-foreground mb-1"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Upload background video"})]})})]})]})]}),e.jsxs("div",{className:"space-y-3 p-3 rounded-lg border-2 border-primary/20 bg-primary/5",children:[e.jsx("div",{className:"flex items-start justify-between",children:e.jsxs(_,{className:"flex items-center gap-2 text-primary",children:[e.jsx(Re,{className:"h-4 w-4"}),"Product Photo",e.jsx(I,{variant:"secondary",className:"text-[10px]",children:"Recommended"})]})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Upload your product to show it in the video"}),e.jsx("input",{ref:rt,type:"file",accept:"image/*",className:"hidden",onChange:t=>{var a;const s=(a=t.target.files)==null?void 0:a[0];s&&Dt(s)}}),V?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"relative rounded-lg overflow-hidden border border-border",children:[e.jsx("img",{src:V,alt:"Product",className:"w-full h-24 object-contain bg-muted"}),e.jsx("button",{onClick:()=>{Xe(null),b===V&&(ie(null),Z("color"))},className:"absolute top-1 right-1 p-1 rounded-full bg-destructive text-destructive-foreground",children:e.jsx(te,{className:"h-3 w-3"})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(_,{className:"text-xs flex items-center gap-1.5",children:[e.jsx(bt,{className:"h-3.5 w-3.5"}),"How to show product"]}),e.jsxs("div",{className:"grid grid-cols-3 gap-1.5",children:[e.jsxs("button",{onClick:()=>Pe("background"),className:`p-2 rounded-lg border-2 text-center transition-all ${E==="background"?"border-primary bg-primary/10":"border-border hover:border-primary/50"}`,children:[e.jsx(xe,{className:"h-4 w-4 mx-auto mb-1"}),e.jsx("p",{className:"text-[10px] font-medium",children:"Backgroun
75d"}),e.jsx("p",{className:"text-[8px] text-muted-foreground",children:"Behind avatar"})]}),e.jsxs("button",{onClick:()=>Pe("broll"),className:`p-2 rounded-lg border-2 text-center transition-all ${E==="broll"?"border-primary bg-primary/10":"border-border hover:border-primary/50"}`,children:[e.jsx(bt,{className:"h-4 w-4 mx-auto mb-1"}),e.jsx("p",{className:"text-[10px] font-medium",children:"B-Roll"}),e.jsx("p",{className:"text-[8px] text-muted-foreground",children:"Product shots"})]}),e.jsxs("button",{onClick:()=>Pe("split"),className:`p-2 rounded-lg border-2 text-center transition-all ${E==="split"?"border-primary bg-primary/10":"border-border hover:border-primary/50"}`,children:[e.jsx(ls,{className:"h-4 w-4 mx-auto mb-1"}),e.jsx("p",{className:"text-[10px] font-medium",children:"Split"}),e.jsx("p",{className:"text-[8px] text-muted-foreground",children:"Intro + Product"})]})]}),E!=="background"&&e.jsxs("div",{className:"flex items-start gap-2 p-2 rounded-md bg-accent/50 text-xs",children:[e.jsx(bs,{className:"h-3.5 w-3.5 text-primary shrink-0 mt-0.5"}),e.jsxs("div",{className:"text-muted-foreground space-y-1",children:[e.jsx("p",{children:E==="broll"?"Video will cut to product close-ups as scene backgrounds":"Video starts with avatar intro, then shows product as background"}),e.jsx("p",{className:"text-[10px] text-amber-500",children:"â±ï¸ Multi-scene videos take 8-15 minutes to generate"})]})]})]})]}):e.jsx("button",{onClick:()=>{var t;return(t=rt.current)==null?void 0:t.click()},disabled:Ke,className:"w-full border-2 border-dashed rounded-lg p-4 text-center transition-colors border-primary/30 hover:border-primary/60 bg-background",children:Ke?e.jsx(ee,{className:"h-5 w-5 animate-spin mx-auto text-primary"}):e.jsxs(e.Fragment,{children:[e.jsx(Re,{className:"h-6 w-6 mx-auto text-primary mb-1"}),e.jsx("p",{className:"text-sm font-medium",children:"Upload your product"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-0.5",children:"PNG or JPEG with clear product shot"})]})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(_,{className:"flex items-center gap-2",children:[e.jsx(xe,{className:"h-4 w-4"}),"Logo",e.jsx("span",{className:"text-xs text-muted-foreground font-normal",children:"(optional)"})]}),e.jsx("input",{ref:ot,type:"file",accept:"image/*",className:"hidden",onChange:t=>{var a;const s=(a=t.target.files)==null?void 0:a[0];s&&$t(s)}}),B?e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"relative rounded-lg overflow-hidden border border-border bg-muted p-2",children:[e.jsx("img",{src:B,alt:"Logo",className:"h-12 mx-auto object-contain"}),e.jsx("button",{onClick:()=>tt(null),className:"absolute top-1 right-1 p-1 rounded-full bg-destructive text-destructive-foreground",children:e.jsx(te,{className:"h-3 w-3"})})]}),e.jsx("div",{className:"grid grid-cols-4 gap-1",children:["top-left","top-right","bottom-left","bottom-right"].map(t=>e.jsx(k,{variant:ce===t?"default":"outline",size:"sm",onClick:()=>Rt(t),className:"text-[10px] px-1 h-7",children:t.split("-").map(s=>s[0].toUpperCase()).join("")},t))}),e.jsx("p",{className:"text-[10px] text-muted-foreground text-center",children:"Logo will be overlaid on image backgrounds"})]}):e.jsx("button",{onClick:()=>{var t;return(t=ot.current)==null?void 0:t.click()},disabled:st,className:"w-full border-2 border-dashed rounded-lg p-3 text-center transition-colors border-border hover:border-primary/50",children:st?e.jsx(ee,{className:"h-5 w-5 animate-spin mx-auto text-primary"}):e.jsxs(e.Fragment,{children:[e.jsx(xe,{className:"h-5 w-5 mx-auto text-muted-foreground mb-1"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Upload your logo"})]})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(_,{children:"Aspect Ratio"}),e.jsx("div",{className:"flex gap-2",children:["16:9","9:16","1:1"].map(t=>e.jsx(k,{variant:R===t?"default":"outline",size:"sm",onClick:()=>Tt(t),className:"flex-1",children:t},t))}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[R==="16:9"&&"YouTube, Website",R==="9:16"&&"TikTok, Reels, Stories",R==="1:1"&&"Instagram, Facebook"]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs(_,{className:"flex items-center gap-2",children:[e.jsx(Nt,{className:"h-4 w-4"}),"Script"]}),e.jsx(ws,{onSelectTemplate:t=>Oe(t)}),e.jsx(ds,{value:G,onChange:t=>Oe(t.target.value),placeholder:"Write your script here... The avatar will speak this text naturally. Or select a template above to get started.",className:"min-h-[150px] resize-none",maxLength:1500}),e.jsxs("p",{className:"text-xs text-muted-foreground text-right",children:[G.length,"/1500 characters"]})]}),e.jsx(cs,{onClick:nt,disabled:!U&&!L||!G.trim(),isLoading:P,canAfford:Fe,creditCost:it,creditBalance:y,label:"Generate UGC Video",loadingLabel:`${fe(S).icon} ${fe(S).label}... (${ct(S)})`,size:"lg",className:"w-full"}),P&&e.jsxs("div",{className:"space-y-3",children:[e.jsx(gt,{value:Math.min(S/360*100,95),className:"h-1.5"}),e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"text-muted-foreground",children:"HeyGen Status:"}),e.jsx(I,{variant:"outline",className:"capitalize",children:qe})]}),e.jsx("div",{className:"bg-muted/50 rounded-lg p-3",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(yt,{className:"h-4 w-4 text-green-500 mt-0.5 shrink-0"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Generation in progress. AI avatar videos typically take 3-6 minutes. Don't close this page."})]})}),S>600&&e.jsx("div",{className:"bg-yellow-500/10 border border-yellow-500/20 rounded-lg p-3",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(ft,{className:"h-4 w-4 text-yellow-500 mt-0.5 shrink-0"}),e.jsx("p",{className:"text-xs text-yellow-600",children:"Taking longer than usual. Complex scripts may take up to 12 minutes."})]})})]})]}),Ot=e.jsx("div",{className:"flex flex-col items-center justify-center h-full min-h-[400px]",children:ke?e.jsxs("div",{className:"w-full space-y-4",children:[e.jsx("div",{className:`relative rounded-xl overflow-hidden bg-black mx-auto ${R==="9:16"?"max-w-[300px]":R==="1:1"?"max-w-[400px]":"w-full"}`,children:e.jsx("video",{src:ke,controls:!0,autoPlay:!0,className:"w-full"})}),e.jsxs("div",{className:"flex justify-center gap-3",children:[e.jsx(k,{variant:"outline",asChild:!0,children:e.jsxs("a",{href:ke,download:!0,target:"_blank",rel:"noopener noreferrer",children:[e.jsx(ys,{className:"h-4 w-4 mr-2"}),"Download"]})}),e.jsxs(k,{variant:"outline",onClick:()=>Ce(null),children:[e.jsx(ns,{className:"h-4 w-4 mr-2"}),"Create New"]})]})]}):P?e.jsxs("div",{className:"text-center space-y-6",children:[e.jsxs("div",{className:"relative",children:[e.jsx("div",{className:"w-24 h-24 rounded-full border-4 border-primary/20 border-t-primary animate-spin mx-auto"}),e.jsx(Le,{className:"h-8 w-8 text-primary absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-center gap-2",children:[e.jsx("span",{className:"text-2xl",children:fe(S).icon}),e.jsxs("p",{className:"font-medium text-lg",children:[fe(S).label,"..."]})]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[ct(S)," elapsed"]})]}),e.jsx("div",{className:"w-full max-w-xs mx-auto",children:e.jsx(gt,{value:Math.min(S/360*100,95),className:"h-2"})}),e.jsx("div",{className:"bg-muted/50 rounded-lg p-4 max-w-sm mx-auto",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(yt,{className:"h-5 w-5 text-green-500 mt-0.5 shrink-0"}),e.jsxs("div",{className:"text-left",children:[e.jsx("p",{className:"font-medium text-sm",children:"Generation in progress"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"AI avatar videos typically take 3-6 minutes. Your video is being processed by HeyGen's servers â please don't close this page."})]})]})}),e.jsxs(I,{variant:"outline",className:"capitalize",children:["HeyGen Status: ",qe]}),S>600&&e.jsx("div",{className:"bg-yellow-500/10 border border-yellow-500/20 rounded-lg p-4 max-w-sm mx-auto",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(ft,{className:"h-5 w-5 text-yellow-500 mt-0.5 shrink-0"}),e.jsxs("div",{className:"text-left",children:[e.jsx("p",{className:"font-medium text-sm text-yellow-600",children:"Taking longer than usual"}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"This is taking longer than expected. The generation is still running â complex scripts may take up to 12 minutes."})]})]})})]}):e.jsxs("div",{className:"flex flex-col items-center justify-center space-y-6 py-4",children:[n.length>0&&e.jsx(ks,{avatars:n.filter(t=>t.preview_image_url).slice(0,15),interval:2500,selectedAvatar:he&&A==="avatar"?he:null,onSelectAvatar:t=>{J(t.avatar_id),$("avatar"),oe("preset"),l.success(`Selected ${t.avatar_name}`)}}),n.length===0&&!re&&e.jsxs("div",{className:"text-center space-y-4 max-w-md",children:[e.jsx("div",{className:"w-20 h-20 rounded-2xl bg-primary/10 flex items-center justify-center mx-auto",children:e.jsx(Le,{className:"h-10 w-10 text-primary"})}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-lg",children:"AI UGC Video Studio"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-2",children:"Create professional spokesperson videos with AI avatars or upload your own photo."})]})]}),re&&e.jsxs("div",{className:"text-center space-y-4",children:[e.jsx(Ge,{className:"w-64 h-96 rounded-2xl mx-auto"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Loading avatars..."})]}),e.jsxs("div",{className:"flex flex-wrap justify-center gap-2 max-w-sm",children:[e.jsx(I,{variant:"secondary",children:"Product Reviews"}),e.jsx(I,{variant:"secondary",children:"Testimonials"}),e.jsx(I,{variant:"secondary",children:"Social Ads"}),e.jsx(I,{variant:"secondary",children:"1,200+ Avatars"})]})]})});return e.jsx(Jt,{title:"AI UGC Video",description:"Create professional AI avatar videos for e-commerce",icon:e.jsx(Le,{className:"h-5 w-5 text-primary"}),sidebar:zt,onGenerate:nt,generateLabel:P?"Generating...":"Generate Video",generateDisabled:!U&&!L||!we||!G.trim()||P||!Fe,isLoading:P,credit
75Cost:it,canAfford:Fe,creditBalance:y,children:Ot})}export{ca as default};
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.