1import{b as le,J as Ze,O as h,i as R,s as w,j as e,a4 as ce,B as q,ab as es,aC as ss,a5 as de,a6 as me,aD as ts,X as B,aq as ae,v as as,a7 as ue,aF as rs,aK as _e,aL as ke,aM as O,aW as is,k as fe,aN as Q,as as $,l as ve,o as F,q as V,y as H,r as E,p as z,S as re,aB as ns,V as Y,m as he,bB as os,aX as Ae,K as Pe,R as b,e as oe,aa as qe,x as Te,bt as ls,a$ as cs,ac as ye,ba as ds}from"./index-BpbZi-vK.js";import{u as L}from"./useMutation-C7CZk7Z3.js";import{T as Ie}from"./textarea-DXy5H-U4.js";import{S as ms}from"./slider-miO_4B6T.js";import{A as De,a as Fe,b as Ve,c as Ee,d as ze,e as Ke,f as Re,g as Me,h as Ue}from"./alert-dialog-C973xiDE.js";import{C as us}from"./CameraPresets-ChohF_HX.js";import{V as Ge}from"./VideoPlayer-CCBjZXCw.js";import{u as be}from"./index-B-2OP8Nr.js";import{S as Ne}from"./scroll-area-Ba0g78jD.js";import{S as hs,a as gs,b as xs,c as ps,d as js}from"./select-DPGXVhwY.js";import{C as fs,a as vs,b as ys}from"./collapsible-DY4vkzea.js";import{C as bs,a as Ns}from"./chevron-up-Cip4inou.js";import{C as ws}from"./circle-alert-CE389uTO.js";import{C as Z}from"./circle-check-x60O5XqR.js";import{g as Ss,a as Cs}from"./creditCosts-BHyvhMwf.js";import{T as Oe}from"./trash-2-CR0XjFBq.js";import"./index-BdQq_4o_.js";import"./move-Y-Z9z_h1.js";import"./play-BwI12jaI.js";import"./maximize-2-BjceEJ1v.js";import"./index-CkRk1qin.js";const we=[{label:"Primary",tooltip:"Main view - e.g., front elevation"},{label:"Reference 1",tooltip:"Additional perspective - e.g., side view"},{label:"Reference 2",tooltip:"Additional perspective - e.g., aerial view"}],_s=({images:r,onImagesChange:l,onUpload:n,isUploading:m,uploadingSlot:x})=>{const{user:d}=le(),{activeCompany:a,isPersonalMode:o}=Ze(),[f,p]=h.useState(null),[y,j]=h.useState(null),{data:S=[]}=R({queryKey:["projects-for-selector",d?.id,a?.id,o],queryFn:async()=>{let i=w.from("projects").select("id, name").order("name");o?i=i.is("company_id",null):a&&(i=i.eq("company_id",a.id));const{data:c,error:N}=await i;if(N)throw N;return c||[]},enabled:!!d}),{data:C,isLoading:P}=R({queryKey:["generations-images",d?.id,a?.id],queryFn:async()=>{let i=w.from("generations").select("id, generated_image_url, workflow_type, created_at").not("generated_image_url","is",null).order("created_at",{ascending:!1}).limit(30);a?i=i.eq("company_id",a.id):i=i.is("company_id",null);const{data:c,error:N}=await i;if(N)throw N;return c},enabled:!!d}),{data:_,isLoading:k}=R({queryKey:["project-images",y],queryFn:async()=>{const{data:i,error:c}=await w.from("project_files").select("id, file_name, storage_url, thumbnail_url, project_id, file_extension").eq("project_id",y).in("file_extension",["jpg","jpeg","png","webp","gif","JPG","JPEG","PNG","WEBP","GIF"]).order("created_at",{ascending:!1});if(c)throw c;return i},enabled:!!y}),T=i=>{const c=[...r];c[i]=null,l(c)},t=(i,c)=>{const N=[...r];N[c]=i,l(N),p(null)},u=(i,c)=>{const N=[...r];N[c]=i,l(N),p(null)};return e.jsx(ce,{children:e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"Upload or select images from history or projects"})}),e.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3",children:[0,1,2].map(i=>e.jsx(ks,{slotIndex:i,image:r[i],label:we[i].label,tooltip:we[i].tooltip,isRequired:i===0,isUploading:m&&x===i,onRemove:()=>T(i),onUpload:c=>n(c,i),disabled:m,hasFirstImage:!!r[0],isOpen:f===i,onOpenChange:c=>p(c?i:null),historyImages:C||[],historyLoading:P,projects:S,projectImages:_||[],projectLoading:k,selectedProjectId:y,onProjectSelect:j,onHistorySelect:c=>t(c,i),onProjectImageSelect:c=>u(c,i)},i))})]})})},ks=({slotIndex:r,image:l,label:n,tooltip:m,isRequired:x,isUploading:d,onRemove:a,onUpload:o,disabled:f,hasFirstImage:p,isOpen:y,onOpenChange:j,historyImages:S,historyLoading:C,projects:P,projectImages:_,projectLoading:k,selectedProjectId:T,onProjectSelect:t,onHistorySelect:u,onProjectImageSelect:i})=>{const c=h.useCallback(async g=>{const U=g[0];U&&(j(!1),await o(U))},[o,j]),{getRootProps:N,getInputProps:J,isDragActive:W}=be({onDrop:c,accept:{"image/*":[".png",".jpg",".jpeg",".webp"]},maxFiles:1,disabled:f}),{getRootProps:A,getInputProps:M,isDragActive:K}=be({onDrop:c,accept:{"image/*":[".png",".jpg",".jpeg",".webp"]},maxFiles:1,disabled:f,noClick:!0,noKeyboard:!0}),I=!x&&!p;return l?e.jsxs("div",{className:"relative group",children:[e.jsx("div",{className:"absolute -top-2 -left-2 z-10 w-6 h-6 rounded-full bg-gold text-background text-xs font-bold flex items-center justify-center",children:r+1}),e.jsx("div",{className:"aspect-video rounded-lg overflow-hidden bg-secondary border border-border",children:e.jsx("img",{src:l,alt:`${n} view`,className:"w-full h-full object-cover"})}),e.jsx(q,{variant:"secondary",size:"icon",className:"absolute top-1 right-1 h-6 w-6 opacity-0 group-hover:opacity-100 transition-opacity bg-background/80 hover:bg-background",onClick:a,children:e.jsx(es,{className:"h-3 w-3"})}),e.jsx("p",{className:"text-xs text-muted-foreground text-center mt-1",children:n})]}):e.jsxs(ss,{open:y,onOpenChange:j,children:[e.jsxs(de,{children:[e.jsx(me,{asChild:!0,children:e.jsx(ts,{asChild:!0,children:e.jsxs("div",{...A(),className:B("relative aspect-video rounded-lg border-2 border-dashed transition-all cursor-pointer flex flex-col items-center justify-center gap-2",K&&"border-gold bg-gold/10",y?"border-gold bg-gold/10":I?"border-border bg-secondary/30 opacity-50":"border-border hover:border-gold/50 bg-secondary/50",d&&"pointer-events-none"),children:[e.jsx("input",{...M()}),e.jsx("div",{className:"absolute -top-2 -left-2 z-10 w-6 h-6 rounded-full bg-muted text-muted-foreground text-xs font-bold flex items-center justify-center border border-border",children:r+1}),d?e.jsxs("div",{className:"flex flex-col items-center gap-2",children:[e.jsx("div",{className:"w-5 h-5 border-2 border-gold border-t-transparent roun
1ded-full animate-spin"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Uploading..."})]}):x?e.jsxs(e.Fragment,{children:[e.jsx(ae,{className:"w-6 h-6 text-muted-foreground"}),e.jsx("p",{className:"text-xs text-muted-foreground text-center px-2",children:"Required â click or drop an image"})]}):e.jsxs(e.Fragment,{children:[e.jsx(as,{className:"w-5 h-5 text-muted-foreground"}),e.jsx("p",{className:"text-xs text-muted-foreground text-center px-2",children:"Optional â click or drop an image"})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:n})]})})}),e.jsx(ue,{side:"bottom",children:e.jsx("p",{children:m})})]}),e.jsx(rs,{className:"w-80 p-0",align:"start",children:e.jsxs(_e,{defaultValue:"upload",className:"w-full",children:[e.jsxs(ke,{className:"w-full grid grid-cols-3 h-9 rounded-b-none",children:[e.jsxs(O,{value:"upload",className:"text-xs gap-1.5",children:[e.jsx(ae,{className:"w-3.5 h-3.5"}),"Upload"]}),e.jsxs(O,{value:"history",className:"text-xs gap-1.5",children:[e.jsx(is,{className:"w-3.5 h-3.5"}),"History"]}),e.jsxs(O,{value:"project",className:"text-xs gap-1.5",children:[e.jsx(fe,{className:"w-3.5 h-3.5"}),"Project"]})]}),e.jsxs("div",{className:"p-3",children:[e.jsx(Q,{value:"upload",className:"mt-0",children:e.jsxs("div",{...N(),className:B("border-2 border-dashed rounded-lg p-6 text-center cursor-pointer transition-colors",W?"border-gold bg-gold/10":"border-border hover:border-gold/50"),children:[e.jsx("input",{...J()}),e.jsx(ae,{className:"w-8 h-8 mx-auto text-muted-foreground mb-2"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:W?"Drop image here":"Drop image or click to upload"})]})}),e.jsx(Q,{value:"history",className:"mt-0",children:C?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx($,{className:"w-5 h-5 animate-spin text-muted-foreground"})}):S&&S.length>0?e.jsx(Ne,{className:"h-48",children:e.jsx("div",{className:"grid grid-cols-3 gap-2",children:S.map(g=>e.jsx("button",{onClick:()=>u(g.generated_image_url),className:"aspect-square rounded-md overflow-hidden border border-border hover:border-gold transition-colors focus:outline-none focus:ring-2 focus:ring-gold",children:e.jsx("img",{src:g.generated_image_url,alt:g.workflow_type,className:"w-full h-full object-cover"})},g.id))})}):e.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-muted-foreground",children:[e.jsx(ve,{className:"w-8 h-8 mb-2 opacity-50"}),e.jsx("p",{className:"text-sm",children:"No images in history"})]})}),e.jsxs(Q,{value:"project",className:"mt-0 space-y-3",children:[e.jsxs(hs,{value:T||"",onValueChange:t,children:[e.jsx(gs,{className:"w-full bg-secondary/50 border-border",children:e.jsx(xs,{placeholder:"Select a project"})}),e.jsx(ps,{children:P.map(g=>e.jsx(js,{value:g.id,children:g.name},g.id))})]}),T?k?e.jsx("div",{className:"flex items-center justify-center py-8",children:e.jsx($,{className:"w-5 h-5 animate-spin text-muted-foreground"})}):_&&_.length>0?e.jsx(Ne,{className:"h-40",children:e.jsx("div",{className:"grid grid-cols-3 gap-2",children:_.map(g=>e.jsx("button",{onClick:()=>i(g.storage_url),className:"aspect-square rounded-md overflow-hidden border border-border hover:border-gold transition-colors focus:outline-none focus:ring-2 focus:ring-gold",children:e.jsx("img",{src:g.thumbnail_url||g.storage_url,alt:g.file_name,className:"w-full h-full object-cover"})},g.id))})}):e.jsxs("div",{className:"flex flex-col items-center justify-center py-6 text-muted-foreground",children:[e.jsx(ve,{className:"w-8 h-8 mb-2 opacity-50"}),e.jsx("p",{className:"text-sm",children:"No images in this project"})]}):e.jsxs("div",{className:"flex flex-col items-center justify-center py-6 text-muted-foreground",children:[e.jsx(fe,{className:"w-8 h-8 mb-2 opacity-50"}),e.jsx("p",{className:"text-sm",children:"Select a project to view images"})]})]})]})]})})]})},As=({analysis:r,isAnalyzing:l,onAnalyze:n,onAnalysisChange:m,imageCount:x,hasImagesChanged:d,error:a})=>{const[o,f]=h.useState(!0),[p,y]=h.useState(!1),j=!r&&!l,S=r&&d;return e.jsx(F,{className:"glass-card border-white/10",children:e.jsxs(fs,{open:o,onOpenChange:f,children:[e.jsxs(V,{className:"pb-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(H,{className:"w-4 h-4 text-gold"}),e.jsx(E,{className:"text-lg",children:"AI Scene Analysis"})]}),e.jsx(vs,{asChild:!0,children:e.jsx(q,{variant:"ghost",size:"sm",className:"h-8 w-8 p-0",children:o?e.jsx(bs,{className:"h-4 w-4"}):e.jsx(Ns,{className:"h-4 w-4"})})})]}),x>1&&e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Analyzing ",x," images to understand spatial relationships"]})]}),e.jsx(ys,{children:e.jsxs(z,{className:"space-y-4",children:[a&&e.jsxs("div",{className:"flex items-start gap-2 p-3 bg-destructive/10 border border-destructive/20 rounded-lg text-sm",children:[e.jsx(ws,{className:"w-4 h-4 text-destructive mt-0.5 flex-shrink-0"}),e.jsx("p",{className:"text-destructive",children:a})]}),l?e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx($,{className:"w-4 h-4 animate-spin"}),e.jsx("span",{children:"Analyzing perspectives and spatial relationships..."})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(re,{className:"h-4 w-full"}),e.jsx(re,{className:"h-4 w-[90%]"}),e.jsx(re,{className:"h-4 w-[80%]"})]})]}
1):j?e.jsxs("div",{className:"text-center py-4",children:[e.jsx("p",{className:"text-sm text-muted-foreground mb-3",children:x===1?"Analyze the image to understand the scene and recommend camera movements":`Analyze ${x} images to understand how perspectives relate`}),e.jsxs(q,{onClick:n,className:"bg-gold/20 hover:bg-gold/30 text-gold border border-gold/30",children:[e.jsx(H,{className:"w-4 h-4 mr-2"}),"Analyze Images"]})]}):r?e.jsxs("div",{className:"space-y-3",children:[p?e.jsxs("div",{className:"space-y-2",children:[e.jsx(Ie,{value:r,onChange:C=>m(C.target.value),rows:5,className:"text-sm"}),e.jsx("div",{className:"flex justify-end",children:e.jsx(q,{size:"sm",variant:"outline",onClick:()=>y(!1),children:"Done Editing"})})]}):e.jsxs("div",{className:B("p-3 bg-secondary/50 rounded-lg text-sm leading-relaxed cursor-pointer hover:bg-secondary/70 transition-colors",d&&"border border-gold/30 bg-gold/5"),onClick:()=>y(!0),children:[e.jsx("p",{className:"whitespace-pre-wrap",children:r}),e.jsx("p",{className:"text-xs text-muted-foreground mt-2",children:"Click to edit"})]}),S&&e.jsxs("div",{className:"flex items-center justify-between p-2 bg-gold/10 rounded-lg border border-gold/20",children:[e.jsx("p",{className:"text-xs text-gold",children:"Images changed - regenerate analysis?"}),e.jsxs(q,{size:"sm",variant:"outline",onClick:n,className:"h-7 text-xs",children:[e.jsx(ns,{className:"w-3 h-3 mr-1"}),"Regenerate"]})]})]}):null]})})]})})},ie=[{id:"none",name:"None",description:"Simple join â clips play back to back",icon:"â¡ï¸",category:"none"},{id:"smooth-morph",name:"Smooth Morph",description:"Gradual blend between scenes",icon:"ð",category:"ai",aiPrompt:"Create a single smooth intermediate image that visually morphs between these two architectural scenes. The result should look like a natural halfway point between both views, blending geometry, lighting, and materials seamlessly."},{id:"time-of-day",name:"Time of Day",description:"Golden hour / dusk lighting shift",icon:"ð
",category:"ai",aiPrompt:"Create a single intermediate image transitioning the time of day between these two architectural scenes, passing through golden hour lighting. Keep the architecture consistent while shifting the sky, shadows, and ambient light."},{id:"seasonal-change",name:"Seasonal Change",description:"Scene morphs between seasons",icon:"ð",category:"ai",aiPrompt:"Create a single intermediate image showing a seasonal transition between these two architectural views. Blend vegetation, sky conditions, and ground textures to suggest a shift between seasons."},{id:"weather-shift",name:"Weather Shift",description:"Clear sky to overcast transition",icon:"ð¦ï¸",category:"ai",aiPrompt:"Create a single intermediate image showing a weather transition between these two architectural scenes. Gradually shift cloud cover, lighting intensity, and atmospheric conditions."},{id:"material-dissolve",name:"Material Dissolve",description:"Surfaces transform between materials",icon:"ð§±",category:"ai",aiPrompt:"Create a single intermediate image where the materials and surfaces morph from the first architectural scene into the second. Show materials mid-transformation â wood becoming concrete, glass shifting to stone, etc."},{id:"sketch-to-reality",name:"Sketch to Reality",description:"Wireframe to finished render",icon:"âï¸",category:"ai",aiPrompt:"Create a single intermediate image that transitions from an architectural sketch or wireframe version of the first scene toward the photorealistic second scene. Show a half-rendered state with visible construction lines fading into materials."}],Se="none",D=2,ne=6,Ps=1,qs=({videos:r,selectedIds:l,onSelectionChange:n})=>{const m=h.useMemo(()=>r.filter(a=>a.video_url),[r]),x=a=>{l.includes(a)?n(l.filter(o=>o!==a)):l.length<ne&&n([...l,a])},d=a=>{const o=l.indexOf(a);return o>=0?o+1:null};return m.length===0?e.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[e.jsx(Y,{className:"w-12 h-12 mx-auto mb-4 opacity-50"}),e.jsx("p",{children:"No completed videos available"}),e.jsx("p",{className:"text-sm mt-1",children:"Generate some videos first to stitch them together"})]}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("label",{className:"text-sm font-medium",children:["Select Videos (",l.length,"/",ne,")"]}),l.length>0&&e.jsx("button",{type:"button",onClick:()=>n([]),className:"text-xs text-muted-foreground hover:text-foreground",children:"Clear selection"})]}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-3",children:m.map(a=>{const o=d(a.id),f=o!==null,p=!f&&l.length>=ne;return e.jsxs(he.button,{type:"button",onClick:()=>!p&&x(a.id),disabled:p,className:B("relative aspect-video rounded-lg overflow-hidden border-2 transition-all group",f?"border-gold ring-2 ring-gold/30":p?"border-border opacity-50 cursor-not-allowed":"border-border hover:border-gold/50"),whileHover:p?{}:{scale:1.02},whileTap:p?{}:{scale:.98},children:[e.jsx("img",{src:a.source_image_url,alt:"Video thumbnail",className:"w-full h-full object-cover"}),f&&e.jsx("div",{className:"absolute inset-0 bg-gold/20 flex items-center justify-center",children:e.jsx("div",{className:"bg-gold text-background rounded-full w-8 h-8 flex items-center justify-center font-bold text-sm",children:o})}),!f&&!p&&e.jsx("div",{className:"absolute inset-0 bg-black/50 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center",children:e.jsx(Z,{className:"w-8 h-8 text-white"})}),a.duration&&e.jsxs("div",{className:"absolute bottom-1 right-1 bg-black/70 text-white text-xs px-1.5 py-0.5 rounded",children:[a.duration,"s"]})]},a.id)})}),l.length>=2&&e.jsxs("div",{className:"flex items-center gap-2 p-3 bg-secondary/50 rounded-lg",children:[e.jsx(os,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:"Order:"}),e.jsx("div",{className:"flex gap-1",children:l.map((a,o)=>e.jsx("span",{className:"bg-gold/20 text-gold text-xs px-2 py-1 rounded",children:o+1},a))})]})]})},Ts=({selected:r,onSelect:l,videoCount:n})=>{const m=ie.find(o=>o.category==="none"),x=ie.filter(o=>o.category==="ai"),d=ie.find(o=>o.id===r),a=Math.max(0,n-1);return e.jsxs("div",{className:"space-y-4",children:[e.jsx("label",{className:"text-sm font-medium",children:"Transition Style"}),e.jsx(Ce,{transition:m,isSelected:r===m.id,onClick:()=>l(m.id)}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(H,{className:"w-3.5 h-3.5 text-gold"}),e.jsx("span",{className:"text-xs font-medium text-muted-foreground uppercase tracking-wide",children:"AI-Powered"})]}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-2",children:x.map(o=>e.jsx(Ce,{transition:o,isSelected:r===o.id,onClick:()=>l(o.id),isAI:!0},o.id))})]}),d?.category==="ai"&&a>0&&e.jsxs("p",{className:"text-xs text-muted-foreground flex items-center gap-1.5",children:[e.jsx(H,{className:"w-3 h-3 text-gold shrink-0"}),"+",a*Ps," credit",a>1?"s":""," for"," ",a," AI transition",a>1?"s":""]})]})},Ce=({transition:r,isSelected:l,onClick:n,isAI:m})=>e.jsxs("button",{type:"button",onClick:n,className:B("flex flex-col items-center gap-1.5 p-3 rounded-lg border transition-all relative","hover:border-gold/50 hover:bg-gold/5",l?"border-gold bg-gold/10 ring-1 ring-gold/30":"border-border bg-card"),children:[m&&e.jsx("span",{className:"absolute top-1 right-1",children:e.jsx(H,{className:"w-2.5 h-2.5 text-gold/60"})}),e.jsx("span",{className:"text-xl",children:r.icon}),e.jsx("span",{className:"text-xs font-medium text-center leading-tight",children:r.name})]}),Is=()=>{const{user:r}=le(),{activeProject:l}=Ae(),n=Pe(),[m,x]=h.useState([]),[d,a]=h.useState(null),[o,f]=h.useState(Se),p=Ss(m.length,o),{data:y}=R({queryKey:["video-generations-for-stitch",r?.id],queryFn:async()=>{const{data:t,error:u}=await w.from("video_generations").select("id, video_url, source_image_url, duration, created_at, status").eq("user_id",r?.id).eq("status","completed").order("created_at",{ascending:!1}).limit(20);if(u)throw u;return t},enabled:!!r}),{data:j}=R({queryKey:["video-stitches",r?.id],queryFn:async()=>{const{data:t,error:u}=await w.from("video_stitches").select("*").eq("user_id",r?.id).order("created_at",{ascending:!1}).limit(10);if(u)throw u;return t},enabled:!!r}),S=m.map(t=>y?.find(u=>
1u.id===t)?.video_url).filter(Boolean),C=L({mutationFn:async()=>{if(S.length<D)throw new Error(`Select at least ${D} videos to stitch`);const{data:t,error:u}=await w.functions.invoke("stitch-videos",{body:{action:"stitch",videoUrls:S,videoIds:m,transitionType:o,transitionDuration:0,projectId:l?.id||null}});if(u)throw u;if(!t.success)throw new Error(t.error||"Stitching failed");return t},onSuccess:t=>{a(t.stitchId);const u=o!=="none"?"Generating AI transitions & stitching â this may take a minute...":"Video stitching started!";b.success(u),n.invalidateQueries({queryKey:["video-stitches"]}),x([]),f(Se)},onError:t=>{b.error(t.message||"Failed to start stitching")}}),P=h.useCallback(async()=>{if(d)try{const{data:t,error:u}=await w.functions.invoke("stitch-videos",{body:{action:"check-status",stitchId:d}});if(u)throw u;if(t.status==="completed")b.success("Videos stitched successfully!"),a(null),n.invalidateQueries({queryKey:["video-stitches"]}),n.invalidateQueries({queryKey:["credits"]}),n.invalidateQueries({queryKey:["dashboard-stats"]});else if(t.status==="failed"){const i=t.creditsRefunded?" Credits have been refunded.":"";b.error((t.error||"Stitching failed")+i),a(null),n.invalidateQueries({queryKey:["video-stitches"]}),t.creditsRefunded&&(n.invalidateQueries({queryKey:["credits"]}),n.invalidateQueries({queryKey:["dashboard-stats"]}))}}catch(t){console.error("Status check error:",t)}},[d,n]);h.useEffect(()=>{if(d){const t=setInterval(P,5e3);return()=>clearInterval(t)}},[d,P]);const _=L({mutationFn:async t=>{const{error:u}=await w.from("video_stitches").delete().eq("id",t).eq("user_id",r?.id);if(u)throw u},onSuccess:()=>{b.success("Stitch deleted"),n.invalidateQueries({queryKey:["video-stitches"]})},onError:()=>{b.error("Failed to delete stitch")}}),k=t=>{switch(t){case"completed":return e.jsx(Z,{className:"w-4 h-4 text-green-500"});case"processing":case"pending":return e.jsx(Te,{className:"w-4 h-4 text-gold animate-pulse"});case"failed":return e.jsx(qe,{className:"w-4 h-4 text-destructive"});default:return null}},T=m.length>=D&&!C.isPending&&!d;return e.jsxs("div",{className:"grid lg:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"space-y-6",children:[e.jsxs(F,{className:"glass-card border-border",children:[e.jsx(V,{children:e.jsx(E,{className:"text-lg",children:"Select Videos to Stitch"})}),e.jsx(z,{children:e.jsx(qs,{videos:y||[],selectedIds:m,onSelectionChange:x})})]}),e.jsxs(F,{className:"glass-card border-border",children:[e.jsx(V,{children:e.jsx(E,{className:"text-lg",children:"Stitch Options"})}),e.jsxs(z,{className:"space-y-4",children:[e.jsx(Ts,{selected:o,onSelect:f,videoCount:m.length}),e.jsx(q,{className:"w-full bg-gold hover:bg-gold/90 text-background gap-2",disabled:!T,onClick:()=>C.mutate(),children:C.isPending||d?e.jsxs(e.Fragment,{children:[e.jsx($,{className:"w-4 h-4 animate-spin"}),d?"Processing...":"Starting..."]}):e.jsxs(e.Fragment,{children:[e.jsx(oe,{className:"w-4 h-4"}),m.length>=D?`Stitch Videos (${p} credits)`:`Select ${D} videos to stitch`]})}),m.length>0&&m.length<D&&e.jsxs("p",{className:"text-xs text-muted-foreground text-center",children:["Select at least ",D," videos to stitch"]})]})]})]}),e.jsx("div",{className:"space-y-6",children:e.jsxs(F,{className:"glass-card border-border",children:[e.jsx(V,{children:e.jsx(E,{className:"text-lg",children:"Stitched Videos"})}),e.jsx(z,{children:!j||j.length===0?e.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[e.jsx(oe,{className:"w-12 h-12 mx-auto mb-4 opacity-50"}),e.jsx("p",{children:"Your stitched videos will appear here"})]}):e.jsx("div",{className:"space-y-4",children:j.map(t=>e.jsxs(he.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:"rounded-lg border border-border overflow-hidden",children:[t.status==="completed"&&t.output_video_url?e.jsx(Ge,{src:t.output_video_url,poster:t.source_video_urls[0],className:"aspect-video"}):e.jsx("div",{className:"aspect-video bg-secondary flex items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[k(t.status),e.jsx("p",{className:"text-sm text-muted-foreground mt-2 capitalize",children:t.status}),t.error_message&&e.jsx("p",{className:"text-xs text-destructive mt-1",children:t.error_message})]})}),e.jsx("div",{className:"p-3 bg-card",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-xs text-muted-foreground capitalize",children:[t.transition_type," ⢠",t.transition_duration,"s ⢠",t.s
1ource_video_urls.length," videos"]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ce,{children:e.jsxs(de,{children:[e.jsxs(De,{children:[e.jsx(Fe,{asChild:!0,children:e.jsx(me,{asChild:!0,children:e.jsx(q,{variant:"ghost",size:"icon",className:"h-6 w-6 text-muted-foreground hover:text-destructive",disabled:_.isPending,children:e.jsx(Oe,{className:"w-3.5 h-3.5"})})})}),e.jsxs(Ve,{children:[e.jsxs(Ee,{children:[e.jsx(ze,{children:t.status==="failed"?"Delete failed stitch?":t.status==="completed"?"Delete stitched video?":"Cancel and delete stitch?"}),e.jsx(Ke,{children:t.status==="failed"?"This will permanently remove this failed stitch from your history.":t.status==="completed"?"This will permanently remove this video from your history.":"This stitch is still processing. Deleting it will cancel the operation."})]}),e.jsxs(Re,{children:[e.jsx(Me,{children:"Cancel"}),e.jsx(Ue,{onClick:()=>_.mutate(t.id),className:"bg-destructive hover:bg-destructive/90",children:"Delete"})]})]})]}),e.jsx(ue,{children:"Delete"})]})}),k(t.status)]})]})})]},t.id))})})]})})]})},et=()=>{const{user:r}=le(),{activeProject:l}=Ae(),n=Pe(),x=ls().state?.imageUrl,[d,a]=h.useState([x||null,null,null]),[o,f]=h.useState(null),[p,y]=h.useState(!1),[j,S]=h.useState(null),[C,P]=h.useState(!1),[_,k]=h.useState(null),[T,t]=h.useState(""),[u,i]=h.useState("orbit"),[c,N]=h.useState(6),[J,W]=h.useState(""),[A,M]=h.useState(null),K=h.useMemo(()=>d.filter(Boolean),[d]),I=K.length,g=I>0,U=K.join("|"),Qe=j!==null&&U!==T,Le=Cs(c),ee=I===2?1:I>=3?2:0,Be=Le+ee,{data:se}=R({queryKey:["video-generations",r?.id],queryFn:async()=>{const{data:s,error:v}=await w.from("video_generations").select("*").eq("user_id",r?.id).order("created_at",{ascending:!1}).limit(10);if(v)throw v;return s},enabled:!!r}),$e=async(s,v)=>{if(r){y(!0),f(v);try{const G=Math.random().toString(36).substring(2,10),X=`${r.id}/${G}/${Date.now()}-${ds(s.name)}`,{error:Xe}=await w.storage.from("uploads").upload(X,s);if(Xe){b.error("Failed to upload image");return}const{data:Ye}=w.storage.from("uploads").getPublicUrl(X),je=[...d];je[v]=Ye.publicUrl,a(je)}catch(G){console.error("Upload error:",G),b.error("Failed to upload image")}finally{y(!1),f(null)}}},He=L({mutationFn:async()=>{const{data:s,error:v}=await w.functions.invoke("generate-video",{body:{action:"analyze-images",imageUrls:K}});if(v)throw v;if(!s.success)throw new Error(s.error||"Analysis failed");return s.analysis},onSuccess:s=>{S(s),t(U),k(null),b.success("Scene analysis complete!")},onError:s=>{k(s.message),b.error("Failed to analyze images")}}),Je=()=>{P(!0),k(null),He.mutate(void 0,{onSettled:()=>P(!1)})},te=L({mutationFn:async()=>{if(!g)throw new Error("Please upload at least one image");const{data:s,error:v}=await w.functions.invoke("generate-video",{body:{imageUrls:K,cameraPreset:u,duration:c,prompt:J,aiAnalysis:j||void 0,projectId:l?.id||null}});if(v)throw v;if(!s.success)throw new Error(s.error||"Failed to start video generation");return s},onSuccess:s=>{M(s.videoGenerationId),b.success("Video generation started! This may take 1-2 minutes."),n.invalidateQueries({queryKey:["video-generations"]})},onError:s=>{b.error(s.message||"Failed to generate video")}}),ge=h.useCallback(async()=>{if(A)try{const{data:s,error:v}=await w.functions.invoke("generate-video",{body:{action:"check-status",videoGenerationId:A}});if(v)throw v;if(s.status==="completed")b.success("Video generated successfully!"),M(null),n.invalidateQueries({queryKey:["video-generations"]}),n.invalidateQueries({queryKey:["credits"]}),n.invalidateQueries({queryKey:["dashboard-stats"]});else if(s.status==="failed"){const G=s.error||"Video generation failed",X=s.creditsRefunded?" Credits have been refunded.":"";b.error(G+X),M(null),n.invalidateQueries({queryKey:["video-generations"]}),s.creditsRefunded&&(n.invalidateQueries({queryKey:["credits"]}),n.invalidateQueries({queryKey:["dashboard-stats"]}))}}catch(s){console.error("Status check error:",s)}},[A,n]);h.useEffect(()=>{if(A){const s=setInterval(ge,5e3);return()=>clearInterval(s)}},[A,ge]);const xe=s=>
1{switch(s){case"completed":return e.jsx(Z,{className:"w-4 h-4 text-green-500"});case"processing":case"pending":return e.jsx(Te,{className:"w-4 h-4 text-gold animate-pulse"});case"failed":return e.jsx(qe,{className:"w-4 h-4 text-destructive"});default:return null}},pe=L({mutationFn:async s=>{const{error:v}=await w.from("video_generations").delete().eq("id",s).eq("user_id",r?.id);if(v)throw v},onSuccess:()=>{b.success("Video deleted"),n.invalidateQueries({queryKey:["video-generations"]})},onError:()=>{b.error("Failed to delete video")}}),We=g&&!te.isPending&&!A;return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-3 rounded-lg bg-gradient-to-br from-purple-500/20 to-pink-500/20",children:e.jsx(cs,{className:"w-6 h-6 text-purple-400"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold",children:"Video Animation"}),e.jsx("p",{className:"text-muted-foreground",children:"Transform still architectural renders into cinematic video clips"})]})]}),e.jsxs(_e,{defaultValue:"generate",className:"w-full",children:[e.jsxs(ke,{className:"grid w-full max-w-md grid-cols-2",children:[e.jsxs(O,{value:"generate",className:"gap-2",children:[e.jsx(Y,{className:"w-4 h-4"}),"Generate"]}),e.jsxs(O,{value:"stitch",className:"gap-2",children:[e.jsx(oe,{className:"w-4 h-4"}),"Stitch Videos"]})]}),e.jsx(Q,{value:"generate",className:"mt-6",children:e.jsxs("div",{className:"grid lg:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"space-y-6",children:[e.jsxs(F,{className:"glass-card border-border",children:[e.jsx(V,{children:e.jsx(E,{className:"text-lg",children:"Source Images"})}),e.jsx(z,{children:e.jsx(_s,{images:d,onImagesChange:a,onUpload:$e,isUploading:p,uploadingSlot:o})})]}),g&&e.jsx(As,{analysis:j,isAnalyzing:C,onAnalyze:Je,onAnalysisChange:S,imageCount:I,hasImagesChanged:Qe,error:_}),e.jsxs(F,{className:"glass-card border-border",children:[e.jsx(V,{children:e.jsx(E,{className:"text-lg",children:"Animation Settings"})}),e.jsxs(z,{className:"space-y-6",children:[!j&&e.jsx(us,{selected:u,onSelect:i}),j&&e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground bg-muted/50 rounded-lg px-3 py-2",children:[e.jsx(Z,{className:"w-4 h-4 text-green-500 shrink-0"}),e.jsx("span",{children:"Camera movement guided by AI analysis"})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(ye,{children:"Duration"}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[c," seconds"]})]}),e.jsx(ms,{value:[c],onValueChange:([s])=>N(s),min:4,max:8,step:2})]}),!j&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(ye,{children:"Additional Prompt (optional)"}),e.jsx(Ie,{value:J,onChange:s=>W(s.target.value),placeholder:"Add specific instructions for the animation...",rows:3})]}),e.jsx(q,{className:"w-full bg-gold hover:bg-gold/90 text-background gap-2",disabled:!We,onClick:()=>te.mutate(),children:te.isPending||A?e.jsxs(e.Fragment,{children:[e.jsx($,{className:"w-4 h-4 animate-spin"}),A?"Processing...":"Starting..."]}):e.jsxs(e.Fragment,{children:[e.jsx(Y,{className:"w-4 h-4"}),"Generate Video (",Be," credits)"]})}),I>1&&e.jsxs("p",{className:"text-xs text-muted-foreground text-center",children:["+",ee," credit",ee!==1?"s":""," for multi-perspective processing"]})]})]})]}),e.jsx("div",{className:"space-y-6",children:e.jsxs(F,{className:"glass-card border-border",children:[e.jsx(V,{children:e.jsx(E,{className:"text-lg",children:"Generated Videos"})}),e.jsx(z,{children:!se||se.length===0?e.jsxs("div",{className:"text-center py-12 text-muted-foreground",children:[e.jsx(Y,{className:"w-12 h-12 mx-auto mb-4 opacity-50"}),e.jsx("p",{children:"Your generated videos will appear here"})]}):e.jsx("div",{className:"space-y-4",children:se.map(s=>e.jsxs(he.div,{initial:{opacity:0,y:20},animate:{opacity:1,y:0},className:"rounded-lg border border-border overflow-hidden",children:[s.status==="completed"&&s.video_url?e.jsx(Ge,{src:s.video_url,poster:s.source_image_url,className:"aspect-video"}):e.jsx("div",{className:"aspect-video bg-secondary flex items-center justify-center",children:e.jsxs("div",{className:"text-center",children:[xe(s.status),e.jsx("p",{className:"text-sm text-muted-foreground mt-2 capitalize",children:s.status})]})}),e.jsx("div",{className:"p-3 bg-card",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("span",{className:"text-xs text-muted-foreground capitalize",children:[s.camera_preset," ⢠",s.duration,"s",s.source_image_urls&&s.source_image_urls.length>1&&e.jsxs(e.Fragment,{children:[" ⢠",s.source_image_urls.length," images"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[s.status==="failed"&&e.jsx(ce,{children:e.jsxs(de,{children:[e.jsxs(De,{children:[e.jsx(Fe,{asChild:!0,children:e.jsx(me,{asChild:!0,children:e.jsx(q,{variant:"ghost",size:"icon",className:"h-6 w-6 text-muted-foreground hover:text-destructive",disabled:pe.isPending,children:e.jsx(Oe,{className:"w-3.5 h-3.5"})})})}),e.jsxs(Ve,{children:[e.jsxs(Ee,{children:[e.jsx(ze,{children:"Delete failed video?"}),e.jsx(Ke,{children:"This will permanently remove this failed generation from your history."})]}),e.jsxs(Re,{children:[e.jsx(Me,{children:"Cancel"}),e.jsx(Ue,{onClick:()=>pe.mutate(s.id),className:"bg-destructive hover:bg-destructive/90",children:"Delete"})]})]})]}),e.jsx(ue,{children:"Delete"})]})}),xe(s.status)]})]})})]},s.id))})})]})})]})}),e.jsx(Q,{value:"stitch",className:"mt-6",children:e.jsx(Is,{})})]})]})};export{et 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.