1import{j as e}from"./ui-vendor-C-1KqH15.js";import{M as Q}from"./ModelBannerHeader-CKcGNTGw.js";import{a as w}from"./react-vendor-ByDWXJvr.js";import{a5 as A,s as I,t as l,V as M,B as L,bd as G,I as X,z as J,W as $,Y as B,Z as H,_ as W,$ as v,bq as ee,a_ as K,C as Z,aS as se,al as te,bm as re,bp as oe}from"./index-DMraBsI-.js";import{L as ae}from"./link-CowX54RN.js";import{D as le}from"./download-92urkXwW.js";import{L as ne}from"./library-snIrNC1d.js";import"./three-vendor-CfDQ9C4v.js";import"./pdf-vendor-BLM9xNEA.js";import"./stream-vendor-CoRm0Xqa.js";const ie="/assets/topaz-banner-gold-Bjx5xFl6.jpg",de="/assets/topaz-banner-purple-DRDWwzDV.jpg",ce=({isExpanded:n})=>e.jsx(Q,{bannerGold:ie,bannerPurple:de,title:"TOPAZ VIDEO",subtitle:"Upscale your videos with Topaz Labs AI technology",badgeLabel:"UPSCALER",isExpanded:n}),ue=()=>{const[n,s]=w.useState(!1),[t,h]=w.useState(null),[b,f]=w.useState(0),[j,y]=A("mvp_video_result_url",""),[c,a]=w.useState(0),[S,i]=w.useState(null),[x,u]=w.useState(null),D=1800,C=1e3;return w.useEffect(()=>{let N;return n&&t&&(a(0),N=setInterval(async()=>{try{const U=Date.now();console.log("ð Polling video upscale status...",{upscaleId:t,attempt:c+1,maxAttempts:D,timestamp:new Date().toISOString()});const{data:o,error:R}=await I.from("mvp_video_upscales").select("status, progress, upscaled_url, error_message, estimated_completion_time").eq("id",t).single(),T=Date.now()-U;if(R){console.error("â Database polling error:",{error:R,upscaleId:t,attempt:c+1,pollDuration:T,timestamp:new Date().toISOString()});return}if(o){if(console.log("ð Video upscale status update:",{...o,upscaleId:t,attempt:c+1,pollDuration:T,timestamp:new Date().toISOString()}),o.estimated_completion_time&&!S&&i(o.estimated_completion_time),o.estimated_completion_time){const P=new Date(o.estimated_completion_time).getTime(),p=Date.now(),V=Math.max(0,Math.round((P-p)/1e3/60));u(V)}if(o.progress!==null&&o.progress!==void 0){const P=b,p=Math.min(o.progress,99);console.log("ð Progress update:",{from:P,to:p,raw:o.progress,upscaleId:t,timeRemaining:x?`${x}min`:"unknown",timestamp:new Date().toISOString()}),f(p)}if(o.status==="completed"&&o.upscaled_url){console.log("ð VIDEO UPSCALE COMPLETED!",{upscaleId:t,resultUrl:o.upscaled_url,finalProgress:100,attempt:c+1,timestamp:new Date().toISOString()}),f(100),s(!1),y(o.upscaled_url),clearInterval(N),l.success("Video upscaled successfully!");return}else if(o.status==="failed"){console.error("ð¥ VIDEO UPSCALE FAILED:",{upscaleId:t,errorMessage:o.error_message,attempt:c+1,finalProgress:o.progress,timestamp:new Date().toISOString()}),s(!1),clearInterval(N),l.error(o.error_message||"Failed to upscale video");return}a(P=>{const p=P+1,V=p*C/1e3,z=p/D*100;return console.log("â±ï¸ Polling progress:",{attempt:p,maxAttempts:D,timeElapsed:`${V}s`,percentComplete:`${z.toFixed(1)}%`,upscaleId:t,currentStatus:o.status,currentProgress:o.progress,timestamp:new Date().toISOString()}),p>=D&&(console.error("â° VIDEO UPSCALE TIMEOUT:",{upscaleId:t,totalAttempts:p,totalTime:`${V}s`,lastStatus:o.status,lastProgress:o.progress,timestamp:new Date().toISOString()}),s(!1),clearInterval(N),l.error("Video upscaling timed out. Please try again.")),p})}}catch(U){console.error("ð¥ CRITICAL POLLING ERROR:",{error:U,message:U.message,stack:U.stack,upscaleId:t,attempt:c+1,timestamp:new Date().toISOString()})}},C)),()=>{N&&clearInterval(N)}},[n,t,y]),{isProcessing:n,setIsProcessing:s,upscaleId:t,setUpscaleId:h,progress:b,resetProcess:()=>{console.log("ð Resetting video upscale process:",{previousUpscaleId:t,previousProgress:b,previousResultUrl:j?"present":"none",previousPollingAttempts:c,timestamp:new Date().toISOString()}),s(!1),h(null),f(0),y(""),a(0),i(null),u(null)},resultUrl:j,timeRemaining:x,estimatedCompletionTime:S}},me=({videoUrl:n,settings:s,onVideoUrlChange:t,onSettingsChange:h,isDragging:b,onDragOver:f,onDragLeave:j,onDrop:y,onFileSelect:c,isUploading:a=!1})=>{const[S,i]=w.useState("url"),x=u=>{var C;const D=(C=u.target.files)==null?void 0:C[0];D&&c&&c(D)};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx(M,{className:"text-base font-medium",children:"Video Input"}),e.jsxs("div",{className:"flex gap-2 mt-2 mb-4",children:[e.jsxs(L,{type:"button",variant:S==="url"?"default":"outline",size:"sm",onClick:()=>i("url"),className:"flex items-center gap-2",children:[e.jsx(ae,{className:"h-4 w-4"}),"URL"]}),e.jsxs(L,{type:"button",variant:S==="upload"?"default":"outline",size:"sm",onClick:()=>i("upload"),className:"flex items-center gap-2",children:[e.jsx(G,{className:"h-4 w-4"}),"Upload"]})]}),S==="url"?e.jsx(X,{type:"url",placeholder:"Enter video URL (https://...)",value:n,onChange:u=>t(u.target.value),className:"w-full"}):e.jsxs("div",{className:J("border-2 border-dashed rounded-lg p-8 text-center transition-colors",b?"border-primary bg-primary/5":"border-muted-foreground
1/25"),onDragOver:f,onDragLeave:j,onDrop:y,children:[e.jsx(G,{className:"h-12 w-12 mx-auto mb-4 text-muted-foreground"}),e.jsx("p",{className:"text-lg font-medium mb-2",children:a?"Uploading video...":"Drop your video file here"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:a?"Please wait...":"Supports MP4, MOV, AVI, WebM, MKV (max 100MB)"}),e.jsx("input",{type:"file",accept:"video/mp4,video/quicktime,video/x-msvideo,video/webm,video/x-matroska",onChange:x,className:"hidden",id:"video-file-input",disabled:a}),e.jsx(L,{type:"button",variant:"outline",className:"mt-4",onClick:()=>{var u;return(u=document.getElementById("video-file-input"))==null?void 0:u.click()},disabled:a,children:a?"Uploading...":"Choose Video File"})]})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{children:[e.jsx(M,{htmlFor:"target_fps",children:"Target FPS"}),e.jsxs($,{value:s.target_fps.toString(),onValueChange:u=>h({...s,target_fps:u}),children:[e.jsx(B,{children:e.jsx(H,{})}),e.jsxs(W,{children:[e.jsx(v,{value:"24",children:"24 FPS (Cinema)"}),e.jsx(v,{value:"30",children:"30 FPS (Standard)"}),e.jsx(v,{value:"60",children:"60 FPS (Smooth)"}),e.jsx(v,{value:"120",children:"120 FPS (High Frame Rate)"})]})]})]}),e.jsxs("div",{children:[e.jsx(M,{htmlFor:"target_resolution",children:"Target Resolution"}),e.jsxs($,{value:s.target_resolution,onValueChange:u=>h({...s,target_resolution:u}),children:[e.jsx(B,{children:e.jsx(H,{})}),e.jsxs(W,{children:[e.jsx(v,{value:"720p",children:"HD (720p)"}),e.jsx(v,{value:"1080p",children:"Full HD (1080p)"}),e.jsx(v,{value:"1440p",children:"QHD (1440p)"}),e.jsx(v,{value:"4k",children:"4K (2160p)"})]})]})]})]})]})},pe=({videoUrl:n,resultUrl:s,isProcessing:t,progress:h,selectedCategory:b,timeRemaining:f,estimatedCompletionTime:j,onCategoryChange:y,onUpscale:c,onSaveToLibrary:a})=>{console.log("VideoUpscalePreview render:",{videoUrl:n,resultUrl:s,isProcessing:t,progress:h});const S=()=>{if(s){const i=document.createElement("a");i.href=s,i.download="upscaled-video.mp4",i.click()}};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold mb-4",children:"Video Preview & Controls"}),t&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"animate-spin rounded-full h-6 w-6 border-b-2 border-primary"}),e.jsx("span",{className:"text-sm font-medium",children:"Processing video..."}),e.jsxs("span",{className:"text-sm text-muted-foreground",children:[h,"%"]})]}),e.jsx(ee,{value:h,className:"w-full"}),e.jsxs("div",{className:"space-y-2 text-xs text-muted-foreground",children:[e.jsx("p",{children:"Video upscaling is running in the background. This process typically takes several minutes."}),f!==null&&f>0&&e.jsxs("p",{className:"font-medium text-primary",children:["â±ï¸ Estimated time remaining: ~",f," minutes"]}),j&&e.jsxs("p",{children:["Expected completion: ",new Date(j).toLocaleTimeString()]}),e.jsx("p",{className:"text-xs opacity-75",children:"ð¡ You can safely close this tab and return later. We'll save your progress."})]}),n&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"Original Video:"}),e.jsx("div",{className:"aspect-video bg-muted rounded-lg overflow-hidden",children:e.jsx("video",{src:n,controls:!0,className:"w-full h-full object-contain",preload:"metadata",onError:i=>console.error("Original video load error:",i),onLoadStart:()=>console.log("Original video load started"),onCanPlay:()=>console.log("Original video can play"),children:"Your browser does not support video playback."})})]})]}),s&&!t&&e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"Upscaled Result:"}),e.jsx("div",{className:"aspect-video bg-muted rounded-lg overflow-hidden",children:e.jsx("video",{src:s,controls:!0,className:"w-full h-full object-contain",preload:"metadata",onError:i=>console.error("Result video load error:",i),onLoadStart:()=>console.log("Result video load started"),onCanPlay:()=>console.log("Result video can play"),children:"Your browser does not support video playback."})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(L,{onClick:S,variant:"outline",size:"sm",children:[e.jsx(le,{className:"h-4 w-4 mr-2"}),"Download"]}),e.jsxs(L,{onClick:a,variant:"outline",size:"sm",children:[e.jsx(ne,{className:"h-4 w-4 mr-2"}),"Save to Library"]})]})]}),n&&!s&&!t&&e.jsxs("div",{className:"space-y-4",children:[e.jsx("p",{className:"text-sm font-medium text-muted-foreground",children:"Input Video:"}),e.jsx("div",{className:"aspect-video bg-muted rounded-lg overflow-hidden",children:e.jsx("video",{src:n,controls:!0,className:"w-full h-full object-contain",preload:"metadata",onError:i=>console.error("Input video load error:",i),onLoadStart:()=>console.log("Input video load started"),onCanPlay:()=>console.log("Input video can play"),children:"Your browser does not support video playback."})}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Ready to upscale. Click the button below to start processing."})]}),!n&&!s&&!t&&e.jsx("div",{className:"aspect-video bg-muted/20 rounded-lg flex items-center justify-center border-2 border-dashed border-muted-foreground
1/25",children:e.jsxs("div",{className:"text-center",children:[e.jsx(K,{className:"h-12 w-12 mx-auto mb-4 text-muted-foreground"}),e.jsx("p",{className:"text-lg font-medium text-muted-foreground",children:"No video to preview"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Upload a video to see preview and start upscaling"})]})})]}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(M,{htmlFor:"category",children:"Save Category"}),e.jsxs($,{value:b,onValueChange:y,children:[e.jsx(B,{children:e.jsx(H,{})}),e.jsxs(W,{children:[e.jsx(v,{value:"character",children:"Character"}),e.jsx(v,{value:"set",children:"Set"}),e.jsx(v,{value:"prop",children:"Prop"}),e.jsx(v,{value:"background",children:"Background"}),e.jsx(v,{value:"effect",children:"Effect"}),e.jsx(v,{value:"other",children:"Other"})]})]})]}),e.jsx(L,{onClick:c,disabled:t,className:"w-full",size:"lg",children:t?e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"animate-spin rounded-full h-4 w-4 border-b-2 border-white mr-2"}),"Processing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(K,{className:"h-4 w-4 mr-2"}),"Upscale Video"]})})]})]})},ge=({projectId:n})=>{const[s,t]=A("mvp_video_url",""),[h,b]=A("mvp_video_category","character"),[f,j]=w.useState(!1),[y,c]=w.useState(!1),[a,S]=A("mvp_video_settings",{target_fps:"60",target_resolution:"1080p"}),{isProcessing:i,setIsProcessing:x,setUpscaleId:u,progress:D,resetProcess:C,resultUrl:k,timeRemaining:N,estimatedCompletionTime:U}=ue(),o=r=>{r.preventDefault(),j(!0)},R=()=>{j(!1)},T=r=>{r.preventDefault(),j(!1);const m=Array.from(r.dataTransfer.files);if(m.length>0){const g=m[0];g.type.startsWith("video/")?P(g):l.error("Please upload a video file")}},P=async r=>{try{c(!0);const{data:{user:m}}=await I.auth.getUser();if(!m){l.error("Please sign in to upload videos");return}if(!["video/mp4","video/quicktime","video/x-msvideo","video/webm","video/x-matroska"].includes(r.type)){l.error("Unsupported video format. Please use MP4, MOV, AVI, WebM, or MKV files.");return}const O=100*1024*1024;if(r.size>O){l.error("File size must be less than 100MB");return}const d=r.name.split(".").pop(),E=`${m.id}/${crypto.randomUUID()}.${d}`,{data:Y,error:F}=await I.storage.from("video_inputs").upload(E,r,{contentType:r.type,cacheControl:"3600"});if(F){console.error("Upload error:",F),l.error("Failed to upload video");return}const{data:{publicUrl:_}}=I.storage.from("video_inputs").getPublicUrl(E);t(_),l.success("Video uploaded successfully")}catch(m){console.error("File upload error:",m),l.error("Failed to upload video")}finally{c(!1)}},p=async r=>{try{if(r.includes("supabase.co")||r.includes("youtube.com")||r.includes("vimeo.com")||r.includes("amazonaws.com"))return!0;try{const m=await fetch(r,{method:"HEAD",mode:"no-cors"});return!0}catch{return!0}}catch(m){return console.error("Error validating video URL:",m),!0}},V=async()=>{const r=Date.now();if(console.log("ð¬ VIDEO UPSCALE STARTED",{timestamp:new Date().toISOString(),videoUrl:s,settings:a,projectId:n}),!s){console.warn("â No video URL provided"),l.error("Please provide a video URL");return}if(console.log("ð Resetting previous upscale state"),C(),console.log("ð Validating video URL:",s),!await p(s)){console.error("â Video URL validation failed:",s),l.error("Failed to load video. Please check the URL.");return}console.log("â
Video URL validation passed"),x(!0),console.log("â¡ Processing state set to true");try{console.log("ð Checking user authentication...");const{data:{user:g},error:O}=await I.auth.getUser();if(O||!g){console.error("â Authentication failed:",{error:O,timestamp:new Date().toISOString(),duration:Date.now()-r}),l.error("Please sign in to upscale videos"),x(!1);return}console.log("â
User authenticated successfully:",{userId:g.id,email:g.email,timestamp:new Date().toISOString()}),console.log("ð¾ Creating database record...",{user_id:g.id,original_url:s,target_fps:parseInt(a.target_fps),target_resolution:a.target_resolution,timestamp:new Date().toISOString()});const{data:d,error:E}=await I.from("mvp_video_upscales").insert({user_id:g.id,original_url:s,target_fps:parseInt(a.target_fps),target_resolution:a.target_resolution,status:"processing",progress:0}).select().single();if(E){console.error("â Database record creation failed:",{error:E,code:E.code,message:E.message,timestamp:new Date().toISOString(),duration:Date.now()-r}),l.error("Failed to create upscale record"),x(!1);return}if(!(d!=null&&d.id)){console.error("â Database record missing ID:",d),l.error("Failed to create upscale record"),x(!1);return}console.log("â
Database record created successfully:",{recordId:d.id,status:d.status,progress:d.progress,timestamp:new Date().toISOString(),dbDuration:Date.now()-r}),u(d.id),console.log("ð Upscale ID set:",d.id),console.log("ð Calling topaz-video-upscaler edge function...",{video_url:s,target_fps:a.target_fps,target_resolution:a.target_resolution,record_id:d.id,timestamp:new Date().toISOString()});const Y=Date.now(),{data:F,error:_}=await se("topaz-video-upscaler",{body:{video_url:s,target_fps:a.target_fps,target_resolution:a.target_resolution,record_id:d.id,video_duration:30}}),q=Date.now()-Y;if(_){console.error("â Edge function failed:",{error:_,message:_.message,details:_.details,code:_.code,recordId:d.id,duration:q,totalDuration:Date.now()-r,timestamp:new Date().toISOString()}),l.error(`Upscale error: ${_.message||"Unknown error"}
1`),console.log("ð Updating database record to failed state..."),await I.from("mvp_video_upscales").update({status:"failed",error_message:_.message||"Unknown error"}).eq("id",d.id),x(!1);return}console.log("â
Edge function completed successfully:",{response:F,duration:q,totalDuration:Date.now()-r,recordId:d.id,timestamp:new Date().toISOString()}),console.log("ð Video upscale process initiated successfully!",{totalDuration:Date.now()-r,recordId:d.id,timestamp:new Date().toISOString()})}catch(g){const O=Date.now()-r;console.error("ð¥ CRITICAL ERROR in video upscaling:",{error:g,message:g.message,stack:g.stack,videoUrl:s,settings:a,totalDuration:O,timestamp:new Date().toISOString()}),te(g.message,"VideoUpscaleImage"),x(!1)}},z=async()=>{if(!k){l.error("No video to save");return}try{const{data:{user:r}}=await I.auth.getUser();if(!r){l.error("Please sign in to save videos");return}const{error:m}=await I.from("project_videos").insert({video_url:k,description:"Upscaled video",category:h,video_model:"Upscale",user_id:r.id,project_id:n});if(m)throw console.error("Database error:",m),m;l.success(`Video saved as ${h}`)}catch(r){console.error("Error saving to library:",r),l.error("Failed to save to library")}};return e.jsx("div",{className:"space-y-6",children:e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-8",children:[e.jsx(Z,{className:"p-6",children:e.jsx(me,{videoUrl:s,settings:a,onVideoUrlChange:t,onSettingsChange:S,isDragging:f,onDragOver:o,onDragLeave:R,onDrop:T,onFileSelect:P,isUploading:y})}),e.jsx(Z,{className:"p-6",children:e.jsx(pe,{videoUrl:s,resultUrl:k,isProcessing:i,progress:D,selectedCategory:h,timeRemaining:N,estimatedCompletionTime:U,onCategoryChange:b,onUpscale:V,onSaveToLibrary:z})})]})})},_e=({projectId:n})=>{const[s,t]=w.useState(!0);return e.jsxs(re,{open:s,onOpenChange:t,className:"w-full space-y-2",children:[e.jsx("div",{className:"cursor-pointer w-full",onClick:()=>t(!s),children:e.jsx(ce,{isExpanded:s})}),e.jsx(oe,{className:"space-y-4",children:e.jsx("div",{className:"p-6",children:e.jsx(ge,{projectId:n})})})]})};export{_e as VideoUpscaleSection};
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.