1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[5118],{1461:(e,t,a)=>{(window.__NEXT_P=window.__NEXT_P||[]).push(["/templates/[projectId]",function(){return a(90721)}])},12845:(e,t,a)=>{"use strict";a.d(t,{E:()=>l});var r=a(88017);a(44109);var i=a(70810),s=a(56783),n=a(57031);let o=(0,s.F)("inline-flex items-center justify-center rounded-md border px-2 py-0.5 text-xs font-medium w-fit whitespace-nowrap shrink-0 [&>svg]:size-3 gap-1 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-[color,box-shadow] overflow-hidden",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground [a&]:hover:bg-primary/90",secondary:"border-transparent bg-secondary text-secondary-foreground [a&]:hover:bg-secondary/90",destructive:"border-transparent bg-destructive text-white [a&]:hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/70",outline:"text-foreground [a&]:hover:bg-accent [a&]:hover:text-accent-foreground"}},defaultVariants:{variant:"default"}});function l(e){let{className:t,variant:a,asChild:s=!1,...l}=e,d=s?i.DX:"span";return(0,r.jsx)(d,{"data-slot":"badge",className:(0,n.cn)(o({variant:a}),t),...l})}},21822:(e,t,a)=>{"use strict";a.d(t,{K:()=>d,X:()=>c});var r=a(82998),i=a(82922),s=a(85339),n=a(21995),o=a(91590);let l=()=>{var e;return(null===(e=navigator.languages)||void 0===e?void 0:e[0])||navigator.language||"en-US"},d="user_model_preference",c=(0,r.v)()((0,n.Zr)((e,t)=>({isAgentMode:"true"===localStorage.getItem("isAgentMode"),isLoading:!1,isAgentModeEnabled:!1,isCheckingFeatureAccess:!1,showInsufficientCreditsDialog:!1,insufficientCreditsDialogType:"insufficient_credits",showRechargeSubscriptionDialog:!1,storyboardType:"scene",setStoryboardType:t=>{e({storyboardType:t})},setAgentMode:t=>{localStorage.setItem("isAgentMode",String(t)),e({isAgentMode:t})},fetchAgentTasks:async(e,t)=>{try{return await (0,s.VR)("execute_agent",e,t)}catch(e){return console.error("è·åAgentä»»å¡å¤±è´¥:",e),[]}},sendAgentRequest:async function(t,a,r){let s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:[],n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:[],o=arguments.length>5&&void 0!==arguments[5]?arguments[5]:[],d=arguments.length>6&&void 0!==arguments[6]?arguments[6]:"agent",c=arguments.length>7?arguments[7]:void 0,u=arguments.length>8?arguments[8]:void 0;e({isLoading:!0});try{let m=l(),p=await (0,i.bE)("/tasks/execute-agent",{prompt:t,provider:"claude",model:r,...a&&{project_id:a},...s&&s.length>0&&{image_ids:s},...n&&n.length>0&&{audio_ids:n},...o&&o.length>0&&{video_ids:o},task_mode:d,...c&&{storyboard_id:c},...void 0!==u&&{storyboard_type:u},language:m});return e({isLoading:!1}),p.data}catch(t){throw e({isLoading:!1}),console.error("Agent请æ±å¤±è´¥:",t),t}},cancelAgentTask:async e=>{try{return(await (0,i.bE)("/tasks/cancel-task",{task_id:e})).data}catch(e){throw console.error("åæ¶Agentä»»å¡å¤±è´¥:",e),e}},checkFeatureAccess:async(t,a)=>{e({isCheckingFeatureAccess:!0});try{var r,i,s,n;let l=new URLSearchParams(window.location.search).get("source");if(window.location.pathname.includes("script")&&(null===(r=t.feature_access)||void 0===r?void 0:r.script_agent)===!0||window.location.pathname.includes("analysis")&&(null===(i=t.feature_access)||void 0===i?void 0:i.drama_agent)===!0||"Template"===l){e({isAgentModeEnabled:!0,isCheckingFeatureAccess:!1});return}let d=o.J.getState(),c=null===(s=d.baseConfig)||void 0===s?void 0:s.agent_free_enabled;if(!0===c||(null==a?void 0:a.has_agent_access)===!0){e({isAgentModeEnabled:!0,isCheckingFeatureAccess:!1});return}if(!t){e({isAgentModeEnabled:!1,isCheckingFeatureAccess:!1});return}let u=(null==t?void 0:null===(n=t.feature_access)||void 0===n?void 0:n.video_agent)===!0,m=(null==t?void 0:t.subscription)&&Object.keys(t.subscription).length>0&&"active"===t.subscription.status;t&&(u||m)?e({isAgentModeEnabled:!0,isCheckingFeatureAccess:!1}):e({isAgentModeEnabled:!1,isCheckingFeatureAccess:!1})}catch(t){console.error("æ£æ¥ç¹æ§è®¿é®æé失败:",t),e({isAgentModeEnabled:!1,isCheckingFeatureAccess:!1})}},setShowInsufficientCreditsDialog:t=>{e({showInsufficientCreditsDialog:t})},setInsufficientCreditsDialogType:t=>{e({insufficientCreditsDialogType:t})},setShowRechargeSubscriptionDialog:t=>{e({showRechargeSubscriptionDialog:t})},getModelOptions:e=>{var t,a;let r,i=null===(t=o.J.getState().baseConfig)||void 0===t?void 0:t.agent_model;if(!i||0===i.length)return[];let s=i.filter(e=>!0!==e.hidden);if(0===s.length)return[];r=(null==e?void 0:null===(a=e.subscription)||void 0===a?void 0:a.status)==="active"?s[0]:s.find(e=>e.is_free)||s[0];let n=s.filter(e=>e.model!==r.model);return[r,...n].map(e=>({value:e.model,label:e.label||e.model,isFree:e.is_free}))},getDefaultModel:e=>{var a;return null===(a=t().getModelOptions(e)[0])||void 0===a?void 0:a.value},validateModelChange:(t,a)=>{var r;let{baseConfig:i}=o.J.getState();if(!i||!i.agent_model||0===i.agent_model.length)return console.warn("â ï¸ baseConfig æªå è½½æ agent_model ä¸ºç©ºï¼ææ¶å
许模åéªè¯éè¿"),!0;let s=i.agent_model.find(e=>e.model===t);if(!s)return console.warn("â æ¨¡å ".concat(t," ä¸åå¨äºå½åé
ç½®ä¸")),!1;let n=(null==a?void 0:null===(r=a.subscription)||void 0===r?void 0:r.status)==="active",l=s.is_free;return!!n||!!l||(e({insufficientCreditsDialogType:"no_permission"}),e({showInsufficientCreditsDialog:!0}),!1)},initializeModelSelection:function(e,a){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",i=r?"".concat(r,": "):"",{baseConfig:s}=o.J.getState();if(!s||!s.agent_model||0===s.agent_model.length)return console.warn("â ï¸ ".concat(i,"baseConfig æªå è½½ï¼è·³è¿æ¨¡ååå§åï¼çå¾
é
ç½®å è½½å®æ")),!1;let n=null;if(n=localStorage.getItem(d)){if(t().validateModelChange(n,e))return a(n),!0;localStorage.removeItem(d)}let l=t().getDefaultModel(e);return l?(a(l),localStorage.setItem(d,l),!0):(console.warn("".concat(i,"åå§åå¤±è´¥ï¼æ æ³
1è·åé»è®¤æ¨¡å")),!1)}}),{name:"agent-mode-storage",partialize:e=>({isAgentMode:e.isAgentMode})}))},24077:(e,t,a)=>{"use strict";a.d(t,{JQ:()=>j,LG:()=>m,Mi:()=>c,Tr:()=>y,_n:()=>_,oW:()=>l,qZ:()=>p,t3:()=>b,updateImageTable:()=>d,uploadImageToAliyun:()=>x});var r=a(82922),i=a(91490),s=a(59537),n=a(34062),o=a(67255);class l extends Error{constructor(e,t){super(e),this.code=e,this.params=t,this.name="UploadError"}}let d=async e=>{let{data:t,error:a}=await i.supabase.from("images").insert(e).select("id");return{data:t,error:a}},c=async e=>{let{data:t,error:a}=await i.supabase.from("audios").insert(e).select("id");return{data:t,error:a}},u=e=>new Promise((t,a)=>{let r=new Image;r.onload=()=>{t({width:r.width,height:r.height}),URL.revokeObjectURL(r.src)},r.onerror=()=>{a(Error("è·åå¾çå辨ç失败")),URL.revokeObjectURL(r.src)},r.src=URL.createObjectURL(e)}),m=e=>new Promise((t,a)=>{let r=new Audio;r.onloadedmetadata=()=>{t(r.duration),URL.revokeObjectURL(r.src)},r.onerror=()=>{a(Error("è·åé³é¢æ¶é¿å¤±è´¥")),URL.revokeObjectURL(r.src)},r.src=URL.createObjectURL(e)}),p=e=>new Promise((t,a)=>{let r=document.createElement("video");r.onloadedmetadata=()=>{t(r.duration),URL.revokeObjectURL(r.src)},r.onerror=()=>{a(Error("è·åè§é¢æ¶é¿å¤±è´¥")),URL.revokeObjectURL(r.src)},r.src=URL.createObjectURL(e)}),h=e=>new Promise((t,a)=>{let r=document.createElement("video");r.onloadedmetadata=()=>{t({width:r.videoWidth,height:r.videoHeight}),URL.revokeObjectURL(r.src)},r.onerror=()=>{a(Error("è·åè§é¢å辨ç失败")),URL.revokeObjectURL(r.src)},r.src=URL.createObjectURL(e)}),g=async function(e,t){let a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"image",i=arguments.length>3?arguments[3]:void 0,n=arguments.length>4?arguments[4]:void 0;try{let o,l={fileName:n||e.name,type:a,projectId:t,contentType:e.type};i&&(l.storyboardId=i);let{data:d}=await (0,r.bE)("/storage/upload-url",l);if(!d||!d.url)throw Error("è·åä¸ä¼ URL失败");await s.A.put(d.url,e,{headers:{"Content-Type":e.type}});let c="https://cdn.aipai.cloud";if(c){let e=c.endsWith("/")?c.slice(0,-1):c;o="".concat(e,"/").concat(d.objectKey)}else o=(d.publicUrl.startsWith("http://")?"http://":"https://")+d.publicUrl+"/"+d.objectKey;
1let g={storage:{size:null==e?void 0:e.size,bucket:"aipai-ai-tools",region:"oss-cn-beijing",provider:"default",object_key:d.objectKey,content_type:null==e?void 0:e.type,original_name:null==e?void 0:e.name}};if("image"===a&&e.type.startsWith("image/"))try{let t=await u(e);g.storage.width=t.width,g.storage.height=t.height}catch(e){console.error("è·åå¾çå辨ç失败:",e)}else if("audio"===a&&e.type.startsWith("audio/"))try{let t=await m(e);g.storage.duration=t,g.storage.is_actual_duration=!0}catch(e){console.error("è·åé³é¢æ¶é¿å¤±è´¥:",e)}else if("video"===a&&e.type.startsWith("video/"))try{let[t,a]=await Promise.all([p(e),h(e)]);g.storage.duration=t,g.storage.width=a.width,g.storage.height=a.height,g.storage.is_actual_duration=!0}catch(e){console.error("è·åè§é¢ä¿¡æ¯å¤±è´¥:",e)}return{file_url:o,metadata:g}}catch(e){throw console.error("ä¸ä¼ ".concat(a,"失败:"),e),Error(e instanceof Error?e.message:"ä¸ä¼ ".concat(a,"失败"))}},f=(e,t)=>{let a=e.size/1024/1024,r=Math.max(t.width,t.height);return"image/jpeg"===e.type&&!!(a<.1)&&!!(r<=1920)},v=e=>({maxWidthOrHeight:1920,initialQuality:.85,preserveExif:!0,useWebWorker:!0,fileType:"image/jpeg"}),x=async function(e,t){let a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;try{let r,i=e;e.size;try{if((r=await u(e)).width,r.height,f(e,r))i=e;else{let t=v(e);if(e.type.startsWith("image/"))try{let a=await (0,n.A)(e,t),r=e.name.replace(/\.[^.]+$/,"");(i=new File([a],"".concat(r,".jpg"),{type:"image/jpeg"})).size,((1-a.size/e.size)*100).toFixed(1)}catch(t){console.error("â å¾çå¤ç失败ï¼å°ä½¿ç¨åå§å¾ç:",t),i=e}}}catch(t){console.error("â è·åå¾ç尺寸失败ï¼ç´æ¥ä¸ä¼ åå¾:",t),i=e}let s="".concat((0,o.A)(),".jpg"),l=await g(i,t,"image",a,s);return{image_url:l.file_url,metadata:l.metadata}}catch(e){throw console.error("ä¸ä¼ å¾ç失败:",e),e}},b=async(e,t,a)=>{try{let r=await g(e,t,"audio",a);return{audio_url:r.file_url,metadata:r.metadata}}catch(e){throw console.error("ä¸ä¼ é³é¢å¤±è´¥:",e),Error(e instanceof Error?e.message:"ä¸ä¼ é³é¢å¤±è´¥")}},y=async e=>{let{data:t,error:a}=await i.supabase.from("videos").insert(e).select("id");return{data:t,error:a}},_=async(e,t,a)=>{try{let r=await g(e,t,"video",a);return{video_url:r.file_url,metadata:r.metadata}}catch(e){throw console.error("ä¸ä¼ è§é¢å¤±è´¥:",e),e}},j=async(e,t)=>{try{let a=await g(e,t,"text");return{file_url:a.file_url,metadata:a.metadata}}catch(e){throw console.error("ä¸ä¼ ææ¬æä»¶å¤±è´¥:",e),e}}},34042:(e,t,a)=>{"use strict";a.d(t,{I:()=>u});var r=a(82998);let i=(e,t)=>({activeStoryboard:{id:null,visual_description:"",camera_movement:"",shot_size:"",candidate_images:[],candidate_videos:[],candidate_tts_audios:[],candidate_images_data:[],candidate_videos_data:[],candidate_tts_audios_data:[],candidate_images_id:void 0,reference_images:[],dialogue:""},storyboards:[],sortedStoryboards:[],isLoading:!1,error:null,isGenerating:!1,aspectRatio:"16:9",isProjectDataPolling:!1,pendingStoryboard:null,storyboardGenFeedback:null,isPublishProjectOpen:"",isShowPublishProjectBtn:!1,setIsGenerating:t=>e({isGenerating:t}),setActiveStoryboardId:a=>
1{if(!a){e({activeStoryboard:{id:null,visual_description:"",camera_movement:"",shot_size:"",candidate_images:[],candidate_videos:[],candidate_tts_audios:[],candidate_images_data:[],candidate_videos_data:[],candidate_tts_audios_data:[],candidate_images_id:void 0,reference_images:[],dialogue:""}});return}let r=t().storyboards.find(e=>e.id===a);r&&e({activeStoryboard:{id:r.id,visual_description:r.visual_description||"",camera_movement:r.camera_movement||"",shot_size:r.shot_size||"",candidate_images:r.candidate_images||[],candidate_videos:r.candidate_videos||[],candidate_tts_audios:r.candidate_tts_audios||[],candidate_images_data:r.candidate_images_data||[],candidate_videos_data:r.candidate_videos_data||[],candidate_tts_audios_data:r.candidate_tts_audios_data||[],candidate_images_id:r.candidate_images_id,reference_images:r.reference_images||[],dialogue:r.dialogue||""}})},updateLocalStoryboardDetails:t=>{e(e=>({activeStoryboard:{...e.activeStoryboard,...t}}))},clearStoryboard:()=>{e({activeStoryboard:{id:null,visual_description:"",camera_movement:"",shot_size:"",candidate_images:[],candidate_videos:[],candidate_images_data:[],candidate_videos_data:[],candidate_images_id:void 0,reference_images:[],dialogue:""},storyboards:[],sortedStoryboards:[],isGenerating:!1,error:null})},isMediaInCandidate:(e,a,r)=>{if(!e)return!1;if(!r)return t().storyboards.some(t=>{var r,i,s;return"image"===a?(null===(r=t.candidate_images)||void 0===r?void 0:r.includes(e))||!1:"video"===a?(null===(i=t.candidate_videos)||void 0===i?void 0:i.includes(e))||!1:"audio"===a&&((null===(s=t.candidate_tts_audios)||void 0===s?void 0:s.includes(e))||!1)});{var i,s,n;let o=t().storyboards.find(e=>e.id===r);return!!o&&("image"===a?(null===(i=o.candidate_images)||void 0===i?void 0:i.includes(e))||!1:"video"===a?(null===(s=o.candidate_videos)||void 0===s?void 0:s.includes(e))||!1:"audio"===a&&((null===(n=o.candidate_tts_audios)||void 0===n?void 0:n.includes(e))||!1))}},setAspectRatio:t=>{e({aspectRatio:t})},setIsProjectDataPolling:t=>e({isProjectDataPolling:t}),markStoryboardGenerationPending:(t,a)=>{e({pendingStoryboard:{startedAt:t,projectId:a}})},clearStoryboardGenerationPending:()=>{e({pendingStoryboard:null})},setStoryboardGenFeedback:t=>{e({storyboardGenFeedback:t})},clearStoryboardGenFeedback:()=>{e({storyboardGenFeedback:null})},setIsPublishProjectOpen:t=>e({isPublishProjectOpen:t}),setIsShowPublishProjectBtn:t=>e({isShowPublishProjectBtn:t})});var s=a(91490),n=a(3966);let o=(e,t)=>({fetchProjectStoryboards:async(a,r)=>{try{let{data:i,error:n}=await s.supabase.from("storyboards").select("id, visual_description, candidate_images, candidate_videos, candidate_tts_audios, main_characters, main_scenes,main_characters_tags, main_scenes_tags, shot_size, camera_movement, duration, dialogue, created_at,reference_images,order_index,status,project_id,updated_at").eq("project_id",a).eq("deleted_flag",0).order("order_index",{ascending:!0});if(n)throw n;let o={enrichedStoryboards:[],timeOrderedStoryboards:[]};if(i&&i.length>0){let a=i.flatMap(e=>e.candidate_images||[]),n=i.flatMap(e=>e.candidate_videos||[]),l=i.flatMap(e=>e.candidate_tts_audios||[]),[d,c,u]=await Promise.all([a.length>0?s.supabase.from("images").select("id, image_url").in("id",a).order("created_at",{ascending:!0}):{data:[],error:null},n.length>0?s.supabase.from("videos").select("id, video_url").in("id",n).order("created_at",{ascending:!0}):{data:[],error:null},l.length>0?s.supabase.from("audios").select("id, audio_url, metadata").in("id",l).order("created_at",{ascending:!0}):{data:[],error:null}]);if(d.error)throw d.error;if(c.error)throw c.error;if(u.error)throw u.error;let m=i.map(e=>{var t,a,r;let i=(null===(t=d.data)||void 0===t?void 0:t.filter(t=>{var a;return null===(a=e.candidate_images)||void 0===a?void 0:a.includes(t.id)}))||[],s=(null===(a=c.data)||void 0===a?void 0:a.filter(t=>{var a;return null===(a=e.candidate_videos)||void 0===a?void 0:a.includes(t.id)}))||[],n=(null===(r=u.data)||void 0===r?void 0:r.filter(t=>{var a;return null===(a=e.candidate_tts_audios)||void 0===a?void 0:a.includes(t.id)}))||[];return{...e,candidate_images_data:i,candidate_videos_data:s,candidate_tts_audios_data:n,candidate_images_id:i.length>0?i[0].id:void 0}}),p=[...m].sort((e,t)=>
1new Date(t.created_at).getTime()-new Date(e.created_at).getTime());e({storyboards:m,sortedStoryboards:p,error:null}),o.enrichedStoryboards=m,o.timeOrderedStoryboards=p,null===t().activeStoryboard.id&&("quickstart"===r?t().setActiveStoryboardId(m[m.length-1].id):t().setActiveStoryboardId(m[0].id))}else e({storyboards:[],sortedStoryboards:[],error:null});return o}catch(t){return console.error("Error fetching storyboards:",t),e({error:"è·ååé失败",isLoading:!1}),{enrichedStoryboards:[],timeOrderedStoryboards:[]}}},createStoryboard:async t=>{if(!t){e({error:"å建åé失败ï¼ç¼ºå°é¡¹ç®ID"});return}let a=(0,n.xd)();try{e({isLoading:!0,error:null});let{data:r,error:i}=await s.supabase.from("storyboards").insert([{project_id:t,visual_description:"zh"===a?"æ°å¯¹è¯":"New Conversation",status:"draft"}]).select();if(i)throw i;if(r&&r[0]){let t=r[0];return e(e=>{let a=[...e.sortedStoryboards,t].sort((e,t)=>new Date(t.created_at).getTime()-new Date(e.created_at).getTime());return{storyboards:[...e.storyboards,t],sortedStoryboards:a,isLoading:!1}}),t.id}}catch(t){console.error("å建storyboard失败:",t),e({error:"å建åé失败",isLoading:!1})}},updateStoryboardDetails:async(a,r)=>{let i=r||t().activeStoryboard.id;if(i)try{let{error:t}=await s.supabase.from("storyboards").update(a).eq("id",i);if(t)throw t;e(e=>{let t={...e.activeStoryboard,...a},r=e.storyboards.map(e=>e.id===i?{...e,...a}:e);return{activeStoryboard:t,storyboards:r}})}catch(t){throw e({error:t instanceof Error?t.message:"æ´æ°åé详æ
失败"}),t}},deleteStoryboard:async t=>{try{let{error:a}=await s.supabase.from("storyboards").update({deleted_flag:1}).eq("id",t);if(a)throw a;e(e=>{var a;let r=e.storyboards.filter(e=>e.id!==t),i={...e,storyboards:r};if((null===(a=e.activeStoryboard)||void 0===a?void 0:a.id)===t)if(r.length>0){let a=e.storyboards.findIndex(e=>e.id===t),s=Math.min(a,r.length-1),n=r[s];i.activeStoryboard={...n,candidate_images_data:n.candidate_images_data||[],candidate_videos_data:n.candidate_videos_data||[],candidate_images_id:n.candidate_images_id,reference_images:n.reference_images||[]}}else i.activeStoryboard={id:null,visual_description:"",camera_movement:"",shot_size:"",candidate_images:[],candidate_videos:[],candidate_images_data:[],candidate_videos_data:[],candidate_images_id:void 0,reference_images:[],dialogue:""};return i})}catch(e){throw console.error("å é¤åé失败:",e),e}},addStoryboard:async(t,a)=>{try{let n,{data:o}=await s.supabase.from("storyboards").select("order_index").eq("project_id",t).eq("deleted_flag",0).order("order_index",{ascending:!0});if(null==o?void 0:o.length){var r,i;let e=a>0?null===(r=o[a-1])||void 0===r?void 0:r.order_index:0,t=null===(i=o[a])||void 0===i?void 0:i.order_index;n=t?(e+t)/2:e+1}else n=1;let{data:l,error:d}=await s.supabase.from("storyboards").insert([{project_id:t,order_index:n,duration:3,status:"draft",created_at:new Date().toISOString(),updated_at:new Date().toISOString()}]).select();if(d)throw d;e(e=>({storyboards:[...e.storyboards,l[0]].sort((e,t)=>e.order_index-t.order_index)}))}catch(e){throw console.error("å建åé失败:",e),e}},updateStoryboardOrder:async(a,r)=>{try{let i,n=t(),o=n.storyboards.find(e=>e.id===a);if(!o)return;let l=[...n.storyboards].sort((e,t)=>e.order_index-t.order_index),d=l.findIndex(e=>e.id===a);if(d===r)return;if(r>d)if(r>=l.length-1)i=l[l.length-1].order_index+1;else{let e=l[r],t=l[r+1];i=e.order_index+(t.order_index-e.order_index)/2}else if(0===r)i=l[0].order_index/2;else{let e=l[r-1],t=l[r];i=e.order_index+(t.order_index-e.order_index)/2}e(e=>{let t=e.storyboards.map(e=>e.id===a?{...e,order_index:i}:e);return{...e,storyboards:t.sort((e,t)=>e.order_index-t.order_index)}});try{let{error:e}=await s.supabase.from("storyboards").update({order_index:i}).eq("id",a);if(e)throw e}catch(t){throw e(e=>{let t=e.storyboards.map(e=>e.id===a?{...e,order_index:o.order_index}:e);return{...e,storyboards:t.sort((e,t)=>e.order_index-t.order_index)}}),t}}catch(e){throw console.error("æ´æ°åé顺åºå¤±è´¥:",e),e}}}),l={image:{candidateField:"candidate_images",dataField:"candidate_images_data",tableName:"images",errorMessage:"该å¾çå·²å¨åéå表ä¸"},video:{candidateField:"candidate_videos",dataField:"candidate_videos_data",tableName:"videos",errorMessage:"该è§é¢å·²å¨åéå表ä¸"},audio:{candidateField:"candidate_tts_audios",dataField:"candidate_tts_audios_data",tableName:"audios",errorMessage:"该é³é¢å·²å¨åéå表ä¸"}},d=(e,t)=>({updateCandidate:async(a,r)=>{let i=a.storyboardId||t().activeStoryboard.id;if(!i)return;let n=t().storyboards.find(e=>e.id===i);if(!n)return;let o=l[r];try{let t=n[o.candidateField]||[],l=t.includes(a.id),d=l?t.filter(e=>e!==a.id):[...t,a.id],c=null;l||(c={id:a.id,["image"===r?"image_url":"video"===r?"video_url":"audio_url"]:a.url,storyboard_id:i});let{error:u}=await s.supabase.from("storyboards").update({[o.candidateField]:d,updated_at:new Date().toISOString()}).eq("id",i);if(u)throw console.error("æ°æ®åºæ´æ°å¤±è´¥ (".concat(r,"):"),u),u;e(e=>{var t;let r={...e.activeStoryboard,[o.candidateField]:d,[o.dataField]:l?null===(t=e.activeStoryboard[o.dataField])||void 0===t?void 0:t.filter(e=>e.id!==a.id):[...e.activeStoryboard[o.dataField]||[],c]},s=e.storyboards.map(e=>{var t;return e.id===i?{...e,[o.candidateField]:d,[o.dataField]:l?null===(t=e[o.dataField])||void 0===t?void 0:t.filter(e=>e.id!==a.id):[...e[o.dataField]||[],c]}:e});return{activeStoryboard:r,storyboards:s}})}catch(e){throw console.error("æ´æ°åé".concat(r,"失败:"),e),e}},updateCandidateImage:async e=>t().updateCandidate(e,"image"),updateCandidateVideo:async e=>t().updateCandidate(e,"video"),updateCandidateAudio:async e=>t().updateCandidate(e,"audio")}),c=(e,t)=>({updateReferenceImageConfig:async(a,r,i)=>{let{activeStoryboard:n}=t();
1if(null==n?void 0:n.id)try{if(e(e=>{if(!e.activeStoryboard)return e;let t=e.activeStoryboard.reference_images.map(e=>e.id===a?{...e,...r}:e);return{...e,activeStoryboard:{...e.activeStoryboard,reference_images:t},storyboards:e.storyboards.map(a=>a.id===e.activeStoryboard.id?{...a,reference_images:t}:a)}}),null==i?void 0:i.skipDatabaseUpdate)return;let{error:o}=await s.supabase.from("storyboards").update({reference_images:t().activeStoryboard.reference_images}).eq("id",n.id);if(o)throw o}catch(e){throw console.error("æ´æ°åèå¾çé
置失败:",e),e}},addReferenceImage:async(t,a,r)=>{let i="ref_".concat(Date.now(),"_").concat(Math.random().toString(36).substr(2,9));try{let{data:n,error:o}=await s.supabase.from("storyboards").select("reference_images").eq("id",t).single();if(o)throw o;let l=[];l=r?[...r.map(e=>(e.id="ref_".concat(Date.now(),"_").concat(Math.random().toString(36).substr(2,9)),e))]:[...(null==n?void 0:n.reference_images)||[],{id:i,url:a,overall:!1,style_reference:!1,character:!0}];let{error:d}=await s.supabase.from("storyboards").update({reference_images:l}).eq("id",t);if(d)throw d;e(e=>{let a=e.activeStoryboard&&e.activeStoryboard.id===t;return{...e,activeStoryboard:a?{...e.activeStoryboard,reference_images:l}:e.activeStoryboard,storyboards:e.storyboards.map(e=>e.id===t?{...e,reference_images:l}:e)}})}catch(e){throw console.error("æ·»å åèå¾ç失败:",e),e}},removeReferenceImage:async a=>{let{id:r}=t().activeStoryboard;if(r)try{e(e=>({activeStoryboard:{...e.activeStoryboard,reference_images:e.activeStoryboard.reference_images.filter(e=>e.id!==a)},storyboards:e.storyboards.map(e=>{var t;return e.id===r?{...e,reference_images:(null===(t=e.reference_images)||void 0===t?void 0:t.filter(e=>e.id!==a))||[]}:e})}));let{error:i}=await s.supabase.from("storyboards").update({reference_images:t().activeStoryboard.reference_images}).eq("id",r);if(i)throw i}catch(e){throw console.error("å é¤åèå¾ç失败:",e),e}}}),u=(0,r.v)((e,t)=>({...i(e,t),...o(e,t),...d(e,t),...c(e,t)}))},46687:(e,t,a)=>{"use strict";a.d(t,{HK:()=>o,WM:()=>d,wV:()=>l});var r=a(88017);a(44109);var i=a(35091),s=a(33824),n=a(57031);function o(e){let{className:t,...a}=e;return(0,r.jsx)(s.YZ,{"data-slot":"resizable-panel-group",className:(0,n.cn)("flex h-full w-full data-[panel-group-direction=vertical]:flex-col",t),...a})}function l(e){let{...t}=e;return(0,r.jsx)(s.Zk,{"data-slot":"resizable-panel",...t})}function d(e){let{withHandle:t,className:a,...o}=e;return(0,r.jsx)(s.TW,{"data-slot":"resizable-handle",className:(0,n.cn)("bg-border focus-visible:ring-ring relative flex w-px items-center justify-center after:absolute after:inset-y-0 after:left-1/2 after:w-1 after:-translate-x-1/2 focus-visible:ring-1 focus-visible:ring-offset-1 focus-visible:outline-hidden data-[panel-group-direction=vertical]:h-px data-[panel-group-direction=vertical]:w-full data-[panel-group-direction=vertical]:after:left-0 data-[panel-group-direction=vertical]:after:h-1 data-[panel-group-direction=vertical]:after:w-full data-[panel-group-direction=vertical]:after:-translate-y-1/2 data-[panel-group-direction=vertical]:after:translate-x-0 [&[data-panel-group-direction=vertical]>div]:rotate-90",a),...o,children:t&&(0,r.jsx)("div",{className:"bg-border z-10 flex h-4 w-3 items-center justify-center rounded-xs border",children:(0,r.jsx)(i.A,{className:"size-2.5"})})})}},49571:(e,t,a)=>{"use strict";a.d(t,{J:()=>f});var r=a(88017),i=a(44109),s=a(98476),n=a(97990),o=a(82600),l=a(35952),d=a(22270),c=(a(12845),a(36888)),u=a(82922),m=a(68036),p=a(82421),h=a(76164),g=a(54963);function f(e){let{open:t,onOpenChange:a,minRechargeAmount:f=1,defaultRechargeAmount:v=1,onRechargeComplete:x,subscriptionPlan:b,onSubscribeComplete:y}=e,_=(0,s.c3)("billing.rechargeDialog"),{locale:j}=(0,n.o)(),{checkAndShowDialog:w,redirectToCheckout:N,dialogProps:k}=(0,g.Z)(),[S,R]=(0,i.useState)((0,p.Rr)(j)),[C,I]=(0,i.useState)((0,p.z0)(j)),[P,A]=(0,i.useState)((0,p.LH)((0,p.Rr)(j))),[F,T]=(0,i.useState)(!1),[U,D]=(0,i.useState)(!1),[L,E]=(0,i.useState)([]),[O,M]=(0,i.useState)(null),[q,z]=(0,i.useState)(!1);(0,i.useEffect)(()=>{let e=(0,p.Rr)(j),t=(0,p.z0)(j),a=(0,p.LH)(e);R(e),I(t),A(a)},[j]);let V=async()=>{z(!0);try{let e=await (0,u.bE)("/payment/products");if(e.data.success&&e.data.data){let t=e.data.data,a=t.filter(e=>e.discount&&"string"==typeof e.discount).filter(e=>e.currency.toUpperCase()===S).map(e=>{let a=t.find(t=>t.priceId===e.discount);if(!a)return console.error("â æªæ¾å°å价产åï¼",{discountPriceId:e.priceId,originalPriceId:e.discount,currency:e.currency}),null;let r=a.price,i=e.price,s="CNY"===e.currency.toUpperCase(),n=s?Math.ceil(r):r,o=s?Math.ceil(i):i,l=
1Math.round((1-o/n)*100);return{priceId:e.priceId,name:e.name,price:o,originalPrice:n,credits:e.monthlyPoints,discount:l,currency:e.currency.toUpperCase(),interval:e.interval,description:e.description,originalPriceId:e.discount}}).filter(Boolean);E(a),a.length>0?M(a[0]):M(null)}}catch(e){console.error("è·åææ£äº§å失败:",e),m.oR.error(_("loadPlansFailed")||"å è½½ææ£äº§å失败")}finally{z(!1)}};(0,i.useEffect)(()=>{t&&V()},[S,t]);let W=(e,t)=>{R(e),I(t),A((0,p.LH)(e))},G=async()=>{if(w()){a(!1);return}T(!0);try{var e;let{data:t,error:r}=await (0,u.bE)("/payment/create-checkout",{amount:P,currency:S.toLowerCase(),callback:encodeURIComponent(window.location.href),source:"template"});if(r)throw r;if(!(null==t?void 0:t.sessionId))throw Error(_("noSessionId"));let{data:i,error:s}=await (0,u.Jt)("/payment/session-details",{sessionId:t.sessionId});if(s)throw Error(s.message||_("sessionDetailsFailed"));if(!(null==i?void 0:null===(e=i.data)||void 0===e?void 0:e.url))throw Error(_("noCheckoutUrl"));a(!1),N(i.data.url),x&&x()}catch(e){if(console.error("Recharge error:",e),e&&"object"==typeof e&&"errorCode"in e&&500===e.errorCode){let t=e.errorMsg||e.error||e.message;m.oR.error(t)}else e&&"object"==typeof e&&"message"in e?m.oR.error(e.message):m.oR.error(_("rechargeFailed"))}finally{T(!1)}};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(h.I,{...k}),(0,r.jsx)(c.lG,{open:t,onOpenChange:a,children:(0,r.jsxs)(c.Cf,{className:"sm:max-w-[700px] py-2",children:[(0,r.jsx)("div",{className:"hidden md:block absolute top-4 right-12 z-10",children:(0,r.jsx)(p.JH,{onCurrencyChange:W})}),(0,r.jsx)(c.c7,{className:"space-y-0.5 pb-1",children:(0,r.jsx)(c.L3,{className:"text-lg",children:_("title")})}),(0,r.jsx)("div",{className:"md:hidden flex justify-center",children:(0,r.jsx)(p.JH,{onCurrencyChange:W})}),(0,r.jsx)("div",{className:"py-2",children:(0,r.jsxs)("div",{className:"grid grid-cols-1 gap-5 auto-rows-fr",children:[!1,(0,r.jsx)("div",{className:"order-2 md:order-1",children:(0,r.jsx)(d.Zp,{className:"cursor-pointer transition-all pt-3 pb-3 mb-3 dark:bg-slate-800/50 bg-slate-50 border-2 border-slate-200 dark:border-slate-700 hover:border-slate-400 dark:hover:border-slate-500 hover:shadow-lg hover:shadow-slate-500/10 dark:hover:shadow-slate-400/20 hover:scale-[1.02]",onClick:G,children:(0,r.jsxs)(d.Wu,{className:"pt-3 pb-3 flex flex-col min-h-[130px]",children:[(0,r.jsx)("div",{className:"flex-1 flex flex-col justify-center text-center space-y-1.5",children:(0,r.jsx)("div",{children:(0,r.jsx)("p",{className:"text-base font-semibold",children:_("rechargeTitle",{symbol:C,amount:P,credits:(0,p.hL)(P,S)})})})}),(0,r.jsx)("div",{className:"mt-3",children:(0,r.jsx)(l.$,{className:"w-full",disabled:F,onClick:e=>{e.stopPropagation(),G()},children:F?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(o.A,{className:"mr-2 h-4 w-4 animate-spin"}),_("processing")]}):_("rechargeButton")})})]})})})]})})]})})]})}},51720:(e,t,a)=>{"use strict";a.d(t,{M:()=>i});var r=a(44109);let i=()=>{let[e,t]=(0,r.useState)(!1),[a,i]=(0,r.useState)(!1),s=(0,r.useRef)(null);return(0,r.useEffect)(()=>{let e=s.current;if(!e)return;let a=new IntersectionObserver(e=>{let[r]=e;r.isIntersecting&&r.intersectionRatio>=.1&&(t(!0),a.disconnect())},{threshold:.1,rootMargin:"0px"}),r=new IntersectionObserver(e=>{let[t]=e;t.isIntersecting&&(i(!0),r.disconnect())},{threshold:0,rootMargin:"600px"});return a.observe(e),r.observe(e),()=>{a.disconnect(),r.disconnect()}},[]),{ref:s,isVisible:e,nearVisible:a}}},56413:(e,t,a)=>{"use strict";a.d(t,{A:()=>d});var r=a(88017),i=a(44109),s=a(82600),n=a(52592),o=a(35952),l=a(98476);let d=e=>{let{src:t,poster:a,className:d="",width:c="100%",height:u="100%",onError:m,actionButton:p,onActionClick:h}=e,[g,f]=(0,i.useState)(!1),[v,x]=(0,i.useState)(!1),b=(0,i.useRef)(null),y=(0,l.c3)("videoPreview");return(0,i.useEffect)(()=>{let e=()=>{document.fullscreenElement||document.webkitFullscreenElement||document.msFullscreenElement||!b.current||b.current.paused||b.current.pause()};return document.addEventListener("fullscreenchange",e),document.addEventListener("webkitfullscreenchange",e),document.addEventListener("msfullscreenchange",e),()=>{document.removeEventListener("fullscreenchange",e),document.removeEventListener("webkitfullscreenchange",e),document.removeEventListener("msfullscreenchange",e)}},[]),(0,r.jsxs)("div",{className:"relative bg-muted rounded-sm overflow-hidden ".concat(d),style:{width:c,height:u},children:[(0,r.jsx)("video",{ref:b,src:t,poster:a,className:"w-full h-full",onLoadedData:()=>{f(!1),x(!1)},onError:e=>{f(!1),x(!0),m&&m(Error(y("loadFailed")))},controls:!1}),g&&(0,r.jsx)("div",{className:"absolute inset-0 flex items-center justify-center bg-background/30",children:(0,r.jsx)(s.A,{className:"h-8 w-8 animate-spin text-primary"})}),v&&(0,r.jsx)("div",{className:"absolute inset-0 flex items-center justify-center bg-background/30",children:(0,r.jsx)("p",{className:"text-sm text-destructive",children:y("loadFailed")})}),!g&&!v&&(0,r.jsx)("div",{className:"absolute inset-0 flex items-center justify-center cursor-pointer bg-black/20 hover:bg-black/30 transition-all",onClick:()=>{b.current&&(b.current.requestFullscreen?b.current.requestFullscreen():b.current.webkitRequestFullscreen?b.current.webkitRequestFullscreen():b.current.msRequestFullscreen&&b.current.msRequestFullscreen(),b.current.play().catch(e=>{x(!0),m&&m(e)}))},children:(0,r.jsx)("div",{className:"rounded-full bg-primary/80 hover:bg-primary transition-all flex items-center justify-center",style:{width:"clamp(28px, 15%, 48px)",as
1pectRatio:"1/1",padding:"0"},children:(0,r.jsx)(n.A,{className:"text-white",style:{width:"60%",height:"60%"}})})}),p&&(0,r.jsx)(o.$,{variant:"ghost",size:"icon",className:"absolute top-1 right-1 h-5 w-5 rounded-full bg-background/40 hover:bg-background",onClick:h,children:p})]})}},59750:(e,t,a)=>{"use strict";a.d(t,{w:()=>o});var r=a(44109),i=a(73800),s=a(91490),n=a(34042);function o(e){let{fetchProjectStoryboards:t,setAspectRatio:a}=(0,n.I)(),{data:o,error:l,mutate:d}=(0,i.Ay)(e?"project/".concat(e):null,async()=>{var t;if(!e)return null;let{data:r,error:i}=await s.supabase.from("projects").select("name,settings,character_ids,scene_ids,voice,seo_summary_settings,collection_id,has_agent_access,credits,type,share_code,user_id").eq("id",e).eq("deleted_flag",0).single();if(i)throw i;return a((null===(t=r.settings)||void 0===t?void 0:t.aspect_ratio)||"16/9"),r},{refreshInterval:0,dedupingInterval:2e3,revalidateOnFocus:!1,revalidateOnReconnect:!0,onErrorRetry:(e,t,a,r,i)=>{var s;let{retryCount:n}=i;!((null==e?void 0:e.code)==="PGRST116"||(null==e?void 0:null===(s=e.message)||void 0===s?void 0:s.includes("not found")))&&!(n>=3)&&setTimeout(()=>r({retryCount:n}),Math.min(1e3*2**n,3e4))}}),{data:c,error:u,mutate:m}=(0,i.Ay)(e&&!l?"storyboards/".concat(e):null,()=>e?t(e,"project"):null,{refreshInterval:0,dedupingInterval:2e3,revalidateOnFocus:!1,revalidateOnReconnect:!0}),{data:p,error:h,mutate:g}=(0,i.Ay)(o&&!l&&o.character_ids&&o.character_ids.length>0?["characters",o.character_ids]:null,async()=>{if(!o||!o.character_ids)return[];let{data:e,error:t}=await s.supabase.from("characters").select("id, name, images, settings, voice, is_public, tag").in("id",o.character_ids);if(t)throw t;return e},{dedupingInterval:2e3,revalidateOnFocus:!1,refreshInterval:0}),{data:f,error:v,mutate:x}=(0,i.Ay)(o&&!l&&o.scene_ids&&o.scene_ids.length>0?["scenes",o.scene_ids]:null,async()=>{if(!o||!o.scene_ids)return[];let{data:e,error:t}=await s.supabase.from("scenes").select("id, name, images, settings, is_public, tag").in("id",o.scene_ids);if(t)throw t;return e},{dedupingInterval:2e3,revalidateOnFocus:!1,refreshInterval:0});return{projectData:o,characters:p,scenes:f,storyboardsData:c,isLoading:!o,error:l||u||h||v,isProjectError:!!l,refreshAllData:(0,r.useCallback)(async()=>{await Promise.all([d(),m(),g(),x()])},[d,m,g,x]),refreshSelected:(0,r.useCallback)(async e=>{let t=[];e.includes("projects")&&t.push(d()),e.includes("storyboards")&&t.push(m()),e.includes("characters")&&t.push(g()),e.includes("scenes")&&t.push(x()),await Promise.all(t)},[d,m,g,x]),mutateProject:d,mutateStoryboards:m,mutateCharacters:g,mutateScenes:x}}},82421:(e,t,a)=>{"use strict";a.d(t,{JH:()=>p,LH:()=>m,Rr:()=>c,hL:()=>h,z0:()=>u});var r=a(88017),i=a(44109),s=a(97990),n=a(35952),o=a(11392),l=a(49554),d=a(57031);function c(e){return"zh"===e?"CNY":"USD"}function u(e){return"zh"===e?"\xa5":"$"}function m(e){return"CNY"===e?10:1}function p(e){let{className:t,onCurrencyChange:a}=e,{locale:u}=(0,s.o)(),[m,p]=(0,i.useState)(c(u)),h=e=>{p(e);let t="USD"===e?"$":"\xa5";null==a||a(e,t)};return(0,r.jsxs)("div",{className:(0,d.cn)("flex rounded-md overflow-hidden border",t),children:[(0,r.jsxs)(n.$,{variant:"USD"===m?"default":"ghost",onClick:()=>h("USD"),className:"rounded-none px-3 py-1 h-8 flex items-center gap-1",children:[(0,r.jsx)(o.A,{className:"h-4 w-4"}),"USD"]}),(0,r.jsxs)(n.$,{variant:"CNY"===m?"default":"ghost",onClick:()=>h("CNY"),className:"rounded-none px-3 py-1 h-8 flex items-center gap-1",children:[(0,r.jsx)(l.A,{className:"h-4 w-4"}),"CNY"]})]})}function h(e,t){let a=parseFloat("7.1");return"USD"===t?Math.floor(100*e):Math.floor(100*e/a)}},85339:(e,t,a)=>{"use strict";a.d(t,{JY:()=>v,OJ:()=>x,VR:()=>h,e5:()=>f,iV:()=>g,r9:()=>p});var r=a(91490);async function i(e){let{data:t,error:a}=await r.supabase.from("tasks").select("id,image_id,input_data,output_data,priority,project_id,status,storyboard_id,task_type,billing_info,updated_at,user_id,error_log,created_at,feedback").eq("storyboard_id",e).neq("task_type","execute_agent").order("created_at",{ascending:!0});if(a)throw a;return t}let s=null,n=0,o=null,l=null,d=null,c=0,u=null,m=null;async function p(e){let t=Date.now();return e===s&&t-n<500?o||Promise.resolve(null!=l?l:[]):(s=e,n=t,o=i(e).then(e=>(l=e,e)).finally(()=>{}))}async function h(e,t,a){let r="".concat(e,":").concat(t||"no-project",":").concat(a||"no-storyboard"),i=Date.now();return r===d&&i-c<500?u||Promise.resolve(null!=m?m:[]):(d=r,c=i,u=f(e,t,a).then(e=>(m=e,e)).finally(()=>{}))}async function g(e){let{data:t,error:a}=await r.supabase.from("tasks").select("id,image_id,input_data,output_data,priority,project_id,status,storyboard_id,task_type,billing_info,updated_at,user_id,error_log,created_at,feedback").eq("id",e).single();if(a)throw a;return t}async function f(e,t,a){let i=r.supabase.from("tasks").select("id,image_id,input_data,output_data,priority,project_id,status,storyboard_id,task_type,billing_info,updated_at,user_id,error_log,created_at,feedback").eq("task_type",e);t&&(i=i.eq("project_id",t)),a&&(i=i.eq("storyboard_id",a));let{data:s,error:n}=await i.order("created_at",{ascending:!0});if(n)throw n;return s}async function v(e,t,a){let i=r.supabase.from("tasks").select("id,image_id,input_data,output_data,priority,project_id,status,storyboard_id,task_type,billing_info,updated_at,user_id,error_log,created_at,feedback");e&&(i=i.eq("project_id",e)),t&&(i=i.eq("task_type",t)),a&&(i=i.eq("storyboard_id",a));let{data:s,error:n}=await i.order("created_at",{ascending:!1}).limit(1).maybeSingle();if(n&&"PGRST116"!==n.code)throw n;return s}async function x(e,t,a){let{data:i,error:s}=await r.supabase.rpc("update_task_feedback",{task_id:e,new_feedback:"other"===t&&a?a:t});if(s)throw s;return i}},90613:(e,t,a)=>{"use strict";a.d(t,{A:()=>f});var r=a(88017),i=a(44109),s=a(26584),n=a.n(s),o=a(33743),l=a(19614),d=a(14416),c=a(52592),u=a(57031),m=a(70008),p=a(56413),h=a(98476),g=a(68036);let f=e=>{let{title:t,onImageUpload:a,onAudioUpload:s,onVideoUpload:f,onSlotClick:v,className:x,imageData:b=[],audioData:y=[],videoData:_=[],onImageRemove:j,onAudioRemove:w,onVideoRemove:N,onFileDrop:k,allowedMediaTypes:S}=e,R=(0,i.useRef)(null),[C,I]=(0,i.useState)(!1),P=(0,h.c3)("upload-errors"),A=()=>b&&b.length>0||y&&y.length>0||_&&_.length>0,F=()=>b&&b.length>0?{type:"image",data:b[0]}:y&&y.length>0?{type:"audio",data:y[0]}:_&&_.length>0?{type:"video",data:_[0]}:null,T=e=>{if(!A()){if(S&&S.length>0){let t=null;if(e.type.startsWith("image/")?t="image":e.type.startsWith("video/")?t="video":e.type.startsWith("audio/")&&(t="audio"),!t||!S.includes(t)){let e=S.map(e=>P(e.toUpperCase())).join("å¾ç"===P("IMAGE")?"ã":", ");g.oR.error(P("TEMPLATE_FILE_TYPE_RESTRICTED",{allowedTypes:e}),{position:"top-center"});return}}e.type.startsWith("image/")?a(e):e.type.startsWith("audio/")?s(e):e.type.startsWith("video/")&&f(e)}},U=e=>{e.stopPropagation();let t=F();if(!t||"audio"!==t.type)return;let a=t.data;
1R.current||(R.current=new Audio(a.url),R.current.onended=()=>I(!1)),C?(R.current.pause(),I(!1)):(R.current.play(),I(!0))},D=()=>{let e=F();if(e)switch("audio"===e.type&&C&&R.current&&(R.current.pause(),I(!1),R.current=null),e.type){case"image":null==j||j();break;case"audio":null==w||w();break;case"video":null==N||N()}},L=()=>S&&0!==S.length?S.map(e=>P(e.toUpperCase())).join("/"):"";return(0,r.jsx)("div",{className:(0,u.cn)("relative border-2 border-dashed rounded-lg w-[65px] h-[65px]","flex flex-col items-center justify-center","transition-colors duration-200",!A()&&"hover:border-primary/30 hover:bg-primary/5 cursor-pointer",A()&&"border-primary/20 bg-primary/5","bg-background/50",x),onDragOver:e=>{e.preventDefault(),A()||e.currentTarget.classList.add("border-primary/50","bg-primary/5")},onDragLeave:e=>{e.currentTarget.classList.remove("border-primary/50","bg-primary/5")},onDrop:e=>{if(e.preventDefault(),e.stopPropagation(),e.currentTarget.classList.remove("border-primary/50","bg-primary/5"),e.dataTransfer.files&&e.dataTransfer.files.length>0){let t=e.dataTransfer.files[0];k?k(t):T(t)}},onClick:()=>{A()||v()},children:(()=>{let e=F();if(!e)return L(),(0,r.jsxs)("div",{className:"flex flex-col items-center justify-center",children:[(0,r.jsx)(o.A,{className:"h-4 w-4 mb-1 text-muted-foreground"}),(0,r.jsx)("span",{className:"text-xs text-muted-foreground text-center",children:t})]});switch(e.type){case"image":return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(n(),{src:(0,m.VG)(e.data.url,"min"),alt:"Image",width:55,height:55,className:"aspect-square object-cover rounded-lg"}),(0,r.jsx)("button",{onClick:e=>{e.stopPropagation(),D()},className:"absolute -top-2 -right-2 p-1 rounded-full bg-background shadow-sm hover:bg-primary/10",children:(0,r.jsx)(l.A,{className:"h-4 w-4"})})]});case"audio":return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"relative w-full h-full flex items-center justify-center",children:(0,r.jsx)("button",{className:"bg-primary/20 hover:bg-primary/30 rounded-full p-1.5 transition-colors",onClick:U,children:C?(0,r.jsx)(d.A,{className:"h-4 w-4 text-primary"}):(0,r.jsx)(c.A,{className:"h-4 w-4 text-primary"})})}),(0,r.jsx)("button",{onClick:e=>{e.stopPropagation(),D()},className:"absolute -top-2 -right-2 p-1 rounded-full bg-background shadow-sm hover:bg-primary/10",children:(0,r.jsx)(l.A,{className:"h-4 w-4"})})]});case"video":return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"relative w-full h-full",children:(0,r.jsx)(p.A,{src:e.data.url,className:"w-full h-full",width:"100%",height:"100%",actionButton:null})}),(0,r.jsx)("button",{onClick:e=>{e.stopPropagation(),D()},className:"absolute -top-2 -right-2 p-1 rounded-full bg-background shadow-sm hover:bg-primary/10",children:(0,r.jsx)(l.A,{className:"h-4 w-4"})})]});default:return null}})()})}},90721:(e,t,a)=>{"use strict";a.r(t),a.d(t,{default:()=>eh});var r=a(88017),i=a(44109),s=a(65802),n=a(66535),o=a(46687),l=a(35099),d=a(68036),c=a(98476),u=a(26584),m=a.n(u),p=a(94661),h=a(35952),g=a(61579),f=a(95699),v=a(49571),x=a(97452),b=a(21822),y=a(29965),_=a(91490),j=a(59750);let w=e=>{let t=(0,s.useRouter)(),a=(0,c.c3)("quickstart"),[r,n]=(0,i.useState)(void 0),[o,l]=(0,i.useState)(!0),[d,u]=(0,i.useState)(null),[m,p]=(0,i.useState)("fused"),[h,g]=(0,i.useState)(["image","video","audio"]),[f,v]=(0,i.useState)({title:"",subtitle:"",fusedLabel:"",separatedLabel:"",placeholder:""}),[x,b]=(0,i.useState)("normal"),[y,w]=(0,i.useState)(""),[N,k]=(0,i.useState)("");(0,i.useEffect)(()=>{(async()=>{if(l(!0),u(null),n(void 0),t.isReady){if(!e||"string"!=typeof e){console.error("â 项ç®IDåæ°æ æ:",e),l(!1),u("åæ°æ æ");return}if(/^[a-z0-9]{4}$/.test(e.toLowerCase())){let t=e.toLowerCase();try{let{data:a,error:r}=await _.supabase.from("projects").select("id").eq("share_code",t).eq("deleted_flag",0).eq("is_public",!0).single();r||!a?(console.error("â åäº«ç æ¥è¯¢å¤±è´¥:",r),u('å享ç "'.concat(e,'" ä¸å卿æªå
¬å¼')),n(void 0)):(n(a.id),u(null))}catch(e){console.error("â ï¸ åäº«ç æ¥è¯¢å¼å¸¸:",e),u("æ¥è¯¢å¤±è´¥ï¼è¯·ç¨åéè¯"),n(void 0)}}else n(e),u(null);l(!1)}})()},[t.isReady,e]);let{projectData:S,characters:R,scenes:C,isLoading:I,error:P,isProjectError:A,refreshAllData:F}=(0,j.w)(r);return(0,i.useEffect)(()=>
1{if(null==S?void 0:S.seo_summary_settings){let e=S.seo_summary_settings,t={};if(e)if("string"==typeof e&&e.trim())try{t=JSON.parse(e)}catch(e){console.error("è§£ææ¨¡æ¿seo_summary_settings JSON失败:",e)}else"object"==typeof e&&null!==e&&(t=e);w(t.prompt||""),k(t.noticeText||"");let r=(t.subtitle||"").trim();p("transition"===t.type?"separated":"fused");let i=t.type;b(i||"normal");let s=[];switch(i){case"transition":s=["video"];break;case"reset":s=["video","image","audio"];break;default:s=["image","video","audio"]}g(s);let n={title:"",subtitle:"",fusedLabel:"",separatedLabel:"",placeholder:""};switch(i){case"transition":n={title:(null==S?void 0:S.name)||a("aiTransitionVideo"),subtitle:r,fusedLabel:a("inputOrUpload"),separatedLabel:a("enterTransitionPrompt"),placeholder:a("transitionIntTips")};break;case"reset":n={title:a("aiRemake"),subtitle:r,fusedLabel:a("inputOrUpload"),separatedLabel:a("fillRequirements"),placeholder:a("resetIntTips")};break;default:n={title:(null==S?void 0:S.name)||a("aiTransitionVideo"),subtitle:r,fusedLabel:a("enterReplaceContent"),separatedLabel:a("enterReplaceContent"),placeholder:a("fillRequirementsTips")}}v(n)}},[S,a]),{realProjectId:r,isLoadingProjectId:o,shareCodeError:d,projectData:S,characters:R,scenes:C,isLoading:I,dataError:P,isProjectError:A,layoutMode:m,allowedMediaTypes:h,panelContent:f,templateType:x,promptContent:y,noticeTextContent:N,refreshAllData:F}};var N=a(24077),k=a(95839);let S=e=>{let{allowedMediaTypes:t,onAuthRequired:a}=e,r=(0,c.c3)("dashboard"),s=(0,c.c3)("quickstart"),n=(0,c.c3)("upload-errors"),{user:o,isLoading:l}=(0,g.A)(),[u,m]=(0,i.useState)([]),[p,h]=(0,i.useState)([]),[f,v]=(0,i.useState)([]),[x,b]=(0,i.useState)(null),[y,_]=(0,i.useState)(!1),j=(0,i.useRef)(null),w=e=>o||l?(e(),!0):(null==a||a(),!1),S=async e=>{try{let t=await (0,k.validateImageForVideoMode)(e,s);if(!t.valid){d.oR.error(t.message,{position:"top-center"});return}let a=URL.createObjectURL(e);b({file:e,type:"image",url:a}),m([]),h([]),v([])}catch(e){console.error("å¾çé¢è§å¤±è´¥:",e),d.oR.error(r("imageProcessingFailed"),{position:"top-center"})}},R=async e=>{let t=await (0,k.MP)(e,void 0,90);if(!t.valid){t.message&&d.oR.error(s(t.message,t.params||{}),{position:"top-center"});return}let a=URL.createObjectURL(e);b({file:e,type:"video",url:a}),m([]),h([]),v([])},C=async e=>{let t=await (0,k.PW)(e,0xa00000,180);if(!t.valid){t.message&&d.oR.error(s(t.message,t.params||{}),{position:"top-center"});return}let a=URL.createObjectURL(e);b({file:e,type:"audio",url:a}),m([]),h([]),v([])};return{imageData:u,videoData:p,audioData:f,previewFile:x,isUploading:y,fileInputRef:j,handleImagePreview:S,handleVideoPreview:R,handleAudioPreview:C,handleImageUpload:async(e,t)=>{if(!e||!t)return d.oR.error(r("missingParameters")),null;try{var a;_(!0);let{image_url:r,metadata:i}=await (0,N.uploadImageToAliyun)(e,t),s={image_url:r,metadata:i,is_candidate:!1,created_at:new Date().toISOString(),updated_at:new Date().toISOString(),project_id:t},{data:n,error:o}=await (0,N.updateImageTable)([s]);if(o)throw o;if(n&&(null===(a=n[0])||void 0===a?void 0:a.id))return m([{id:n[0].id,url:r}]),n[0].id;return null}catch(t){let e;return console.error("å¾çå¤ç失败",t),e=t instanceof N.oW?n(t.code,t.params||{}):t instanceof Error?t.message:r("imageProcessingFailed"),d.oR.error(e),null}finally{_(!1)}},handleVideoUpload:async(e,t)=>{if(!e||!t)return d.oR.error(r("missingParameters")),null;let a=await (0,k.MP)(e,void 0,90);if(!a.valid)return a.message&&d.oR.error(s(a.message,a.params||{}),{position:"top-center"}),null;try{var i;_(!0);let{video_url:a,metadata:r}=await (0,N._n)(e,t),s={video_url:a,status:"completed",metadata:r,created_at:new Date().toISOString(),updated_at:new Date().toISOString(),project_id:t},{data:n,error:o}=await (0,N.Tr)([s]);if(o)throw o;if(n&&(null===(i=n[0])||void 0===i?void 0:i.id))return h([{id:n[0].id,url:a}]),n[0].id;return null}catch(e){return console.error("è§é¢å¤ç失败",e),d.oR.error(e instanceof Error?e.message:r("videoProcessingFailed")),null}finally{_(!1)}},handleAudioUpload:async(e,t)=>{if(!e||!t)return d.oR.error(r("missingParameters")),null;if(e.size>0xa00000)return d.oR.error(s("audioFileTooLarge")||"é³é¢æä»¶å¤§å°ä¸è½è¶
è¿10MB",{position:"top-center"}),null;try{var a;_(!0);let{audio_url:r,metadata:i}=await (0,N.t3)(e,t),s={audio_url:r,metadata:i,created_at:new Date().toISOString(),updated_at:new Date().toISOString(),project_id:t},{data:n,error:o}=await (0,N.Mi)([s]);if(o)throw o;if(n&&(null===(a=n[0])||void 0===a?void 0:a.id))return v([{id:n[0].id,url:r}]),n[0].id;return null}catch(e){return console.error("é³é¢å¤ç失败",e),d.oR.error(e instanceof Error?e.message:r("audioProcessingFailed")||"é³é¢å¤ç失败"),null}finally{_(!1)}},handleFileSelect:()=>{w(()=>{var e;null===(e=j.current)||void 0===e||e.click()})},handleFileChange:e=>{var a;let i=null===(a=e.target.files)||void 0===a?void 0:a[0];i&&w(()=>{let e=null;if(i.type.startsWith("image/")?e="image":i.type.startsWith("video/")?e="video":i.type.startsWith("audio/")&&(e="audio"),e&&!t.includes(e)){let e=t.map(e=>n(e.toUpperCase())).join("å¾ç"===n("IMAGE")?"ã":", ");d.oR.error(n("TEMPLATE_FILE_TYPE_RESTRICTED",{allowedTypes:e}),{position:"top-center"});return}i.type.startsWith("image/")?S(i):i.type.startsWith("video/")?R(i):i.type.startsWith("audio/")?C(i):d.oR.error(r("onlyImageVideoAudioAllowed")||"åªæ¯æå¾çãè§é¢åé³é¢æä»¶")})},handleRemoveFile:()=>{b(null),m([]),h([]),v([])},hasAnyFile:()=>u.length>0||p.length>0||f.length>0||null!==x,setImageData:m,setVideoData:h,setAudioData:v,setPreviewFile:b}};var R=a(73800),C=a(82922),I=a(91590),P=a(85339);let A=["douyin.com","tiktok.com","youtube.com","youtu.be","aipai-dev.oss-cn-beijing.aliyuncs.com","aipai-ai-tools.oss-accelerate.aliyuncs.com","aipai-ai-tools.oss-cn-beijing.aliyuncs.com"],F=e=>e.match(/(https?:\/\/[^\s]+)/g)||[],T=e=>{try{let t=new URL(e).hostname.toLowerCase();
1return A.some(e=>t===e||t.endsWith(".".concat(e)))}catch(e){return!1}},U=e=>{let t=F(e);if(0===t.length)return{valid:!0,invalidUrls:[]};let a=t.filter(e=>!T(e));return{valid:0===a.length,invalidUrls:a}},D=(e,t,a,r,i)=>{if(a){let e=U(r);if(!e.valid)return{valid:!1,message:i("invalidVideoUrls",{count:e.invalidUrls.length})}}return"transition"===e?t||a?t?a?{valid:!0,message:""}:{valid:!1,message:i("transitionRequiresPrompt")}:{valid:!1,message:i("transitionRequiresFile")}:{valid:!1,message:i("transitionRequiresBoth")}:t||a?{valid:!0,message:""}:{valid:!1,message:i("requiresFileOrPrompt")}},L=e=>{try{let t=new Date(e).getTime(),a=Date.now(),r=Math.max(0,(a-t)/1e3),i=Math.min(r/60*99,99);return Math.round(i)}catch(e){return console.error("计ç®è¿åº¦å¤±è´¥:",e),0}},E=e=>{let{realProjectId:t,projectData:r,templateType:n,userPrompt:o,imageData:l,videoData:u,audioData:m,previewFile:p,onImageUpload:h,onVideoUpload:g,onAudioUpload:f,onRemoveFile:v,onSetUserPrompt:x,user:_,isAuthLoading:j,onAuthRequired:w}=e,N=(0,s.useRouter)(),k=(0,c.c3)("dashboard"),S=(0,c.c3)("agentTaskContent"),{sendAgentRequest:A,getDefaultModel:F}=(0,b.X)(),{fetchBalance:T,walletData:U}=(0,y.G)(),{baseConfig:E}=(0,I.J)(),[O,M]=(0,i.useState)(!1),[q,z]=(0,i.useState)(0),[V,W]=(0,i.useState)(null),[G,$]=(0,i.useState)(null),[J,H]=(0,i.useState)(null),[B,Y]=(0,i.useState)(""),[Z,K]=(0,i.useState)(!1),X=(0,i.useRef)(null),Q=(0,i.useRef)(!1),ee=(0,i.useRef)(0),et=(0,i.useRef)(""),ea=e=>{try{let t=e.replace(/<tool_call[^>]*>[\s\S]*?<\/tool_call>/gi,"");return(t=(t=(t=(t=t.replace(/<video[\s\S]*?<\/video>/gi,"")).replace(/<img[\s\S]*?<\/img>/gi,"")).replace(/<img[^>]*>/gi,"")).replace(/<audio[\s\S]*?<\/audio>/gi,"")).trim()}catch(t){return e}},er=async e=>{try{let{supabase:r}=await Promise.resolve().then(a.bind(a,91490)),{data:i,error:s}=await r.from("videos").select("id, video_url, metadata").eq("project_id",e).order("created_at",{ascending:!1}).limit(1);if(s)return console.error("æ¥è¯¢è§é¢è¡¨å¤±è´¥:",s),null;if(i&&i.length>0){var t;let e=i[0],a=e.metadata;if((null==a?void 0:null===(t=a.storage)||void 0===t?void 0:t.type)==="clips")return e.video_url}}catch(e){console.error("æ¥è¯¢æåè§é¢å¤±è´¥:",e)}return null},ei=async e=>{let[t,a]=e;if(!a)return null;try{var r;let e=await (0,P.iV)(a);if(!e)return null;let t=null;"completed"===e.status&&e.project_id&&(t=await er(e.project_id));let i="";return(null===(r=e.output_data)||void 0===r?void 0:r.chunks)&&Array.isArray(e.output_data.chunks)&&e.output_data.chunks.length>0&&(i=e.output_data.chunks[e.output_data.chunks.length-1]),{status:e.status,video_url:t,current_chunk:i,task:e}}catch(e){return console.error("æ¥è¯¢ä»»å¡ç¶æå¤±è´¥:",e),null}},{data:es}=(0,R.Ay)(G?["/api/tasks/status",G]:null,ei,{refreshInterval:3e3*!!O,revalidateOnFocus:!1});(0,i.useEffect)(()=>{var e,t,a;if(es){try{let a=null===(t=es.task)||void 0===t?void 0:null===(e=t.output_data)||void 0===e?void 0:e.chunks;if(Array.isArray(a)){let e=ee.current;if(e<a.length){let t=a.slice(e).join("");et.current=(et.current||"")+t;let r=et.current.replace(/<tool_call\s+tool="([^"]+)"[^>]*>[\s\S]*?<\/tool_call>/gi,(e,t)=>{let a=S(t);return a&&a!==t?"|||TOOL_SEP|||".concat(a,"|||TOOL_SEP|||"):"|||TOOL_SEP|||"}),i=r.split(RegExp("\\r?\\n|[ã]|(?<!\\d)\\.(?=\\s|$)|\\|\\|\\|TOOL_SEP\\|\\|\\|")),s=RegExp("\\r?\\n|[ã]|(?<!\\d)\\.(?=\\s|$)|\\|\\|\\|TOOL_SEP\\|\\|\\|$").test(r),n=[],o="";s?(n=i.slice(0,-1),o=""):(i.length>1&&(n=i.slice(0,-1)),o=i[i.length-1]||"");let l=ea(o);if(l.length>0)Y(l);else{let e=null;for(let t of n){let a=ea(t);a.length>0&&(e=a)}null!==e&&Y(e)}et.current=o,ee.current=a.length}}}catch(e){console.error("å¤ç chunks 段è½å¤±è´¥:",e)}if("completed"===es.status)z(100),M(!1),H(es.video_url||null),X.current&&(clearInterval(X.current),X.current=null),T();else if("failed"===es.status||"canceled"===es.status){M(!1),z(0),Y(""),ee.current=0,et.current="",X.current&&(clearInterval(X.current),X.current=null);let{task_id:e,new_project_id:t,...r}=N.query;N.replace({pathname:N.pathname,query:r},void 0,{shallow:!0});let i=(null===(a=es.task)||void 0===a?void 0:a.error_log)||k("operationFailed");d.oR.error(i,{position:"top-center"})}}},[es,N,k,T,S]),(0,i.useEffect)(()=>{let e=N.query.task_id,t=N.query.new_project_id;if(e){if(j)return;if(!_){w();return}if(Q.current){Q.current=!1;return}$(e),W(t||null),M(!0),z(0),ee.current=0,et.current="",Y(""),(0,P.iV)(e).then(async e=>{if(!e){console.error("â ä»»å¡ä¸åå¨ï¼æ¸
ç URL åæ°"),d.oR.error(k("taskNotFound")||"ä»»å¡ä¸åå¨");let{task_id:e,new_project_id:t,...a}=N.query;N.replace({pathname:N.pathname,query:a},void 0,{shallow:!0}),M(!1);return}if("completed"===e.status){let t=e.project_id?await er(e.project_id):null;z(100),M(!1),H(t)}else if("failed"===e.status||"canceled"===e.status){d.oR.error(k("taskFailed")||"ä»»å¡å·²å¤±è´¥");let{task_id:e,new_project_id:t,...a}=N.query;N.replace({pathname:N.pathname,query:a},void 0,{shallow:!0}),M(!1)}else z(L(e.created_at)),X.current=setInterval(()=>{z(e=>e>=99?99:Math.min(e+.825,99))},500)}).catch(e=>{console.error("â æ¥è¯¢ä»»å¡ç¶æå¤±è´¥:",e),d.oR.error(k("operationFailed")),M(!1)})}},[N.query.task_id,k,null==_?void 0:_.id]),(0,i.useEffect)(()=>()=>{X.current&&clearInterval(X.current)},[]);let en=async()=>{let e=D(n,p||l.length>0||u.length>0||m.length>0,o.trim().length>0,o,k);if(!e.valid){d.oR.error(e.message,{position:"top-center"});return}let a={type:"",id:""},i="";if(p?a.type=p.type:l.length>0?(a.type="image",a.id=l[0].id):u.length>0?(a.type="video",a.id=u[0].id):m.length>0&&(a.type="audio",a.id=m[0].id),null==r?void 0:r.seo_summary_settings){let e=r.seo_summary_settings,t={};if(e)if("string"==typeof e&&e.trim())try{t=JSON.parse(e)}catch(e){console.error("è§£ææ¨¡æ¿seo_summary_settings JSON失败:",e)}else"object"==typeof e&&null!==e&&(t=e);let a=t.defaultPrompt||"";i=o.trim()?a+(a?" ":"")+o.trim():a}try{K(!0);let e=await (0,C.bE)("/projects/copy",{original_project_id:t,characters_mode:"copy",scenes_mode:"copy"});if(!e.data.success){d.oR.error(k("operationFailed"));return}Y(""),ee.current=0,et.current="",H(null),M(!0),z(0);let r=e.data.data.new_project_id;if(W(r),p)try{let e=null;"image"===p.type?e=await h(p.file,r):"video"===p.type?e=await g(p.file,r):"audio"===p.type&&(e=await f(p.file,r)),e&&(a.id=e)}catch(e){console.error("åªä½ä¸ä¼ 失败:",e),d.oR.error(k("mediaUploadFailed"))}let s=[],n=[],o=[];p&&a.id?"image"===a.type?s=[a.id]:"video"===a.type?n=[a.id]:"audio"===a.type&&(o=[a.id]):(l.length>0&&(s=[l[0].id]),u.length>0&&(n=[u[0].id]),m.length>0&&(o=[m[0].id]));let c=F(U)||"claude-3-5-sonnet",v=await A(i,r,c,s,o,n,"template",void 0,void 0);if(!v.success){d.oR.error(v.message||k("operationFailed")),M(!1);return}let x=v.task_id;if(!x){d.oR.error(k("operationFailed")),M(!1);return}$(x),Q.current=!0,N.replace({pathname:N.pathname,query:{...N.query,task_id:x,new_project_id:r}},void 0,{shallow:!0}),M(!0),z(0),X.current=setInterval(()=>{z(e=>e>=99?99:Math.min(e+.825,99))},500),d.oR.success(k("generationStarted"),{position:"top-center"})}catch(e){console.error("å
èçæå¤±è´¥:",e),d.oR.error(k("operationFailed")),M(!1)}finally{K(!1)}},eo=async()=>{let e=D(n,p||l.length>0||u.length>0||m.length>0,o.trim().length>0,o,k);if(!e.valid){d.oR.error(e.message,{position:"top-center"});return}let a={type:"",id:""},i="";if(p?a.type=p.type:l.length>0?(a.type="image",a.id=l[0].id):u.length>0?(a.type="video",a.id=u[0].id):m.length>0&&(a.type="audio",a.id=m[0].id),null==r?void 0:r.seo_summary_settings){let e=r.seo_summary_settings,t={};if(e)if("string"==typeof e&&e.trim())try{t=JSON.parse(e)}catch(e){console.error("è§£ææ¨¡æ¿seo_summary_settings JSON失败:",e)}else"object"==typeof e&&null!==e&&(t=e);let a=t.defaultPrompt||"";i=o.trim()?a+(a?" ":"")+o.trim():a}try{K(!0);let e=await (0,C.bE)("/projects/copy",{original_project_id:t,characters_mode:"copy",scenes_mode:"copy"});if(e.data.success){let t=e.data.data.new_project_id;if(p)try{let e=null;"image"===p.type?e=await h(p.file,t):"video"===p.type?e=await g(p.file,t):"audio"===p.type&&(e=await f(p.file,t)),e&&(a.id=e)}catch(e){console.error("åªä½ä¸ä¼ 失败:",e),d.oR.error("åªä½ä¸ä¼ 失败ï¼ä½é¡¹ç®å·²å建")}d.oR.success(k("success"));let r={...a,defaultPrompt:i,task_mode:"template"};window.sessionStorage.setItem("template",JSON.stringify(r)),v(),N.push("/project/".concat(t,"?source=Template"))}else d.oR.error(k("operationFailed"))}catch(e){d.oR.error(k("operationFailed"))}finally{K(!1)}};return{isInlineGenerating:O,inlineProgress:q,inlineProjectId:V,inl
1ineTaskId:G,inlineResultVideoUrl:J,inlineCurrentChunk:B,isUploading:Z,handleGenerateContent:async()=>{"transition"===n&&(null==E?void 0:E.template_inline_mode)===!0?await en():await eo()},handleRetryGeneration:()=>{M(!1),z(0),W(null),$(null),Y(""),H(null),ee.current=0,et.current="",X.current&&(clearInterval(X.current),X.current=null);let{task_id:e,new_project_id:t,...a}=N.query;N.replace({pathname:N.pathname,query:a},void 0,{shallow:!0}),x(""),v()},handleViewProject:()=>{V&&N.push("/project/".concat(V))}}};var O=a(82600),M=a(23769);let q=e=>{let{message:t}=e;return(0,r.jsx)("div",{className:"flex-1 flex items-center justify-center",children:(0,r.jsxs)("div",{className:"flex flex-col items-center gap-3",children:[(0,r.jsx)(O.A,{className:"h-8 w-8 animate-spin text-primary"}),t&&(0,r.jsx)("p",{className:"text-sm text-muted-foreground",children:t})]})})},z=()=>{let e=(0,s.useRouter)(),t=(0,c.c3)("dashboard");return(0,r.jsx)("div",{className:"flex-1 flex flex-col items-center justify-center p-8",children:(0,r.jsxs)("div",{className:"text-center",children:[(0,r.jsx)(M.A,{size:120,className:"mx-auto mb-4 text-muted-foreground opacity-50"}),(0,r.jsx)("h2",{className:"text-xl font-semibold mb-2",children:t("projectNotFound")}),(0,r.jsx)("p",{className:"text-muted-foreground mb-4",children:t("projectNotFoundDesc")}),(0,r.jsx)(h.$,{onClick:()=>e.push("/dashboard"),className:"mx-auto",children:t("backToDashboard")})]})})},V=e=>{let{shareCode:t}=e,a=(0,s.useRouter)(),i=(0,c.c3)("dashboard"),n=(0,c.c3)("template"),o=n("shareCodeNotFoundMessage",{shareCode:t}).split(t);return(0,r.jsx)("div",{className:"flex-1 flex flex-col items-center justify-center p-8",children:(0,r.jsxs)("div",{className:"text-center",children:[(0,r.jsx)(M.A,{size:120,className:"mx-auto mb-4 text-muted-foreground opacity-50"}),(0,r.jsx)("h2",{className:"text-xl font-semibold mb-2",children:n("shareCodeNotFound")}),(0,r.jsxs)("p",{className:"text-muted-foreground mb-2",children:[o[0],(0,r.jsx)("span",{className:"font-mono font-semibold text-foreground",children:t}),o[1]]}),(0,r.jsx)("p",{className:"text-sm text-muted-foreground mb-4",children:n("shareCodeCaseSensitive")}),(0,r.jsx)("div",{className:"flex gap-3 justify-center",children:(0,r.jsx)(h.$,{onClick:()=>a.push("/dashboard"),children:i("backToDashboard")})})]})})};var W=a(82890),G=a.n(W),$=a(67365),J=a(75342),H=a(52592),B=a(57031);let Y={"af5c1df8-d0ff-4df6-8acb-d00004eda550":[{id:"mv_case_1",name:"MV Cases",videoId:"mv_case_1",videoUrl:(0,B.jm)("/banner/templates/mv_cases1.mp4"),videoPosterUrl:(0,B.jm)("/banner/templates/mv_cases1.png")},{id:"mv_case_2",name:"MV Cases",videoId:"mv_case_2",videoUrl:(0,B.jm)("/banner/templates/mv_cases2.mp4"),videoPosterUrl:(0,B.jm)("/banner/templates/mv_cases2.png")}],"0c990246-146d-4cd8-86f0-88b3d4f8eb0c":[{id:"reset_case_3",name:"Reset Cases",videoId:"reset_case_3",videoUrl:(0,B.jm)("/banner/templates/reset_cases3.mp4"),videoPosterUrl:(0,B.jm)("/banner/templates/reset_cases3.png")},{id:"reset_case_1",name:"Reset Cases",videoId:"reset_case_1",videoUrl:(0,B.jm)("/banner/templates/reset_cases1.mp4"),videoPosterUrl:(0,B.jm)("/banner/templates/reset_cases1.png")}]},Z=e=>{var t,a;let{templateProjectId:s,projectName:n,defaultVideoUrl:o,className:l}=e,d=(0,c.c3)("dashboard"),u=(0,i.useRef)(null),m=(0,i.useRef)(null),p=Y[s]||[],[g,f]=(0,i.useState)(0),[v,x]=(0,i.useState)(!0),b=p.length>0?null===(t=p[g])||void 0===t?void 0:t.videoUrl:o,y=e=>{e!==g&&(f(e),x(!0),_(e))},_=e=>{let t=m.current;if(!t)return;let a=t.querySelectorAll("[data-thumbnail]")[e];if(!a)return;let r=t.offsetWidth,i=a.offsetLeft,s=a.offsetWidth;t.scrollTo({left:i-r/2+s/2,behavior:"smooth"})};return((0,i.useEffect)(()=>{let e=u.current;if(e&&b){let t=()=>{x(!1);let t=e.play();void 0!==t&&t.then(()=>{}).catch(e=>{})};return e.addEventListener("canplay",t),e.addEventListener("loadstart",()=>x(!0)),()=>{e.removeEventListener("canplay",t),e.removeEventListener("loadstart",()=>x(!0))}}},[b]),0===p.length)?o?(0,r.jsx)("div",{className:(0,B.cn)("h-full flex items-center justify-center",l),children:(0,r.jsx)("div",{className:"w-full h-full max-w-4xl",children:(0,r.jsx)("video",{ref:u,autoPlay:!0,muted:!0,loop:!0,controls:!0,playsInl
1ine:!0,className:"w-full max-h-[calc(100vh-24rem)] md:max-h-[65vh] object-contain rounded-lg",preload:"metadata",children:(0,r.jsx)("source",{src:o,type:"video/mp4"})})})}):(0,r.jsx)("div",{className:(0,B.cn)("h-full flex items-center justify-center bg-muted/20",l),children:(0,r.jsxs)("div",{className:"text-center text-muted-foreground",children:[(0,r.jsx)("div",{className:"text-4xl mb-4",children:"\uD83C\uDFAC"}),(0,r.jsx)("p",{className:"text-lg",children:d("noVideoAvailable")||"ææ è§é¢"})]})}):(0,r.jsxs)("div",{className:"jsx-d1e1d09fdfc6c76b "+((0,B.cn)("h-full flex flex-col bg-background",l)||""),children:[(0,r.jsxs)("div",{className:"jsx-d1e1d09fdfc6c76b flex-1 min-h-0 flex items-center justify-center relative overflow-hidden",children:[v&&(0,r.jsx)("div",{className:"jsx-d1e1d09fdfc6c76b absolute inset-0 flex items-center justify-center bg-muted/20 z-10",children:(0,r.jsx)(O.A,{className:"w-8 h-8 animate-spin text-primary"})}),(0,r.jsx)("div",{className:"jsx-d1e1d09fdfc6c76b w-full max-w-3xl px-4",children:(0,r.jsx)("video",{ref:u,autoPlay:!0,muted:!0,loop:!0,controls:!0,playsInline:!0,preload:"metadata",poster:null===(a=p[g])||void 0===a?void 0:a.videoPosterUrl,className:"jsx-d1e1d09fdfc6c76b w-full max-h-[calc(100vh-24rem)] md:max-h-[65vh] object-contain rounded-lg",children:(0,r.jsx)("source",{src:b,type:"video/mp4",className:"jsx-d1e1d09fdfc6c76b"})},b)})]}),(0,r.jsx)("div",{className:"jsx-d1e1d09fdfc6c76b flex-shrink-0 h-28 md:h-32 border-t bg-background/95 backdrop-blur-sm",children:(0,r.jsxs)("div",{className:"jsx-d1e1d09fdfc6c76b relative h-full flex items-center",children:[(0,r.jsx)(h.$,{variant:"ghost",size:"icon",onClick:()=>{g>0&&y(g-1)},disabled:0===g,className:"hidden md:flex absolute left-2 z-10 bg-background/80 hover:bg-background shadow-md w-10 h-10",children:(0,r.jsx)($.A,{className:"!w-8 !h-8",strokeWidth:2.5})}),(0,r.jsx)("div",{ref:m,style:{scrollbarWidth:"none",msOverflowStyle:"none",WebkitOverflowScrolling:"touch"},className:"jsx-d1e1d09fdfc6c76b flex-1 overflow-x-auto scroll-smooth hide-scrollbar px-2 md:px-12",children:(0,r.jsx)("div",{className:"jsx-d1e1d09fdfc6c76b flex gap-2 md:gap-3 py-2 justify-start md:justify-center",children:p.map((e,t)=>(0,r.jsx)(K,{case:e,isSelected:t===g,onClick:()=>y(t)},e.id))})}),(0,r.jsx)(h.$,{variant:"ghost",size:"icon",onClick:()=>{g<p.length-1&&y(g+1)},disabled:g===p.length-1,className:"hidden md:flex absolute right-2 z-10 bg-background/80 hover:bg-background shadow-md w-10 h-10",children:(0,r.jsx)(J.A,{className:"!w-8 !h-8",strokeWidth:2.5})})]})}),(0,r.jsx)(G(),{id:"d1e1d09fdfc6c76b",children:".hide-scrollbar.jsx-d1e1d09fdfc6c76b::-webkit-scrollbar{display:none}"})]})},K=e=>{let{case:t,isSelected:a,onClick:i}=e;return(0,r.jsxs)("div",{"data-thumbnail":!0,onClick:i,className:(0,B.cn)("relative flex-shrink-0 rounded-lg overflow-hidden cursor-pointer transition-all duration-300","border-2 hover:scale-105 active:scale-95","w-32 h-20","md:w-40 md:h-24",a?"border-primary ring-2 ring-primary/30 scale-105":"border-transparent hover:border-primary/50"),children:[t.videoPosterUrl?(0,r.jsx)("img",{src:t.videoPosterUrl,alt:t.name,className:"w-full h-full object-cover"}):(0,r.jsx)("video",{src:t.videoUrl,className:"w-full h-full object-cover",muted:!0,playsInline:!0,preload:"none"}),(0,r.jsx)("div",{className:"absolute inset-0 bg-gradient-to-t from-black/60 via-trans
1parent to-transparent"}),a&&(0,r.jsx)("div",{className:"absolute inset-0 flex items-center justify-center",children:(0,r.jsx)("div",{className:"bg-primary/90 rounded-full p-1.5 md:p-2 shadow-lg",children:(0,r.jsx)(H.A,{className:"w-3 h-3 md:w-4 md:h-4 text-white fill-white"})})}),!a&&(0,r.jsx)("div",{className:"absolute inset-0 flex items-center justify-center opacity-0 hover:opacity-100 transition-opacity",children:(0,r.jsx)("div",{className:"bg-white/80 rounded-full p-1.5 md:p-2",children:(0,r.jsx)(H.A,{className:"w-3 h-3 md:w-4 md:h-4 text-black"})})})]})};var X=a(77654),Q=a(71447);let ee=i.forwardRef((e,t)=>{let{className:a,value:i,...s}=e;return(0,r.jsx)(Q.bL,{ref:t,className:(0,B.cn)("relative h-4 w-full overflow-hidden rounded-full bg-secondary",a),...s,children:(0,r.jsx)(Q.C1,{className:(0,B.cn)("h-full w-full flex-1 bg-primary transition-all","animate-progress-stripes"),style:{transform:"translateX(-".concat(100-(i||0),"%)"),backgroundImage:"repeating-linear-gradient(45deg, rgba(0,0,0,0.30) 0, rgba(0,0,0,0.30) 0.5rem, rgba(255,255,255,0.30) 0.5rem, rgba(255,255,255,0.30) 1rem)",backgroundSize:"1rem 1rem"}})})});ee.displayName="AnimatedProgress";var et=a(19614),ea=a(65009),er=a(19556),ei=a(22934),es=a(33743),en=a(30006),eo=a(90613),el=a(15158);let ed=e=>{let{value:t,onChange:a,placeholder:s,maxLength:n=500,imageData:o,videoData:l,audioData:u,onImageUpload:m,onVideoUpload:p,onAudioUpload:g,onImageRemove:f,onVideoRemove:v,onAudioRemove:x,onSlotClick:b,isUploading:y,fileInputRef:_,uploadSlotClassName:j,showCharCount:w=!0,uploadMediaText:N="ä¸ä¼ åªä½",uploadingText:k="ä¸ä¼ ä¸...",allowedMediaTypes:S}=e,{isMobile:R}=(0,el.F)(),[C,I]=(0,i.useState)(!1),[P,A]=(0,i.useState)(!1),F=(0,c.c3)("upload-errors"),T=()=>o.length>0||l.length>0||u.length>0,U=e=>e.type.startsWith("image/")?"image":e.type.startsWith("video/")?"video":e.type.startsWith("audio/")?"audio":null,D=e=>{if(!S||0===S.length)return!0;let t=U(e);return!!t&&S.includes(t)},L=e=>{m(e),R&&I(!0)},E=e=>{p(e),R&&I(!0)},M=e=>{g(e),R&&I(!0)};return(0,r.jsxs)("div",{className:(0,B.cn)("relative border rounded-md overflow-hidden transition-all",P&&"border-primary border-2 bg-primary/5"),onDragEnter:e=>{e.preventDefault(),e.stopPropagation(),A(!0)},onDragLeave:e=>{e.preventDefault(),e.stopPropagation(),e.currentTarget===e.target&&A(!1)},onDragOver:e=>{e.preventDefault(),e.stopPropagation()},onDrop:e=>{e.preventDefault(),e.stopPropagation(),A(!1);let t=Array.from(e.dataTransfer.files);if(0===t.length)return;let a=t[0];if(!D(a)){if(U(a)&&S){let e=S.map(e=>F(e.toUpperCase())).join("å¾ç"===F("IMAGE")?"ã":", ");d.oR.error(F("TEMPLATE_FILE_TYPE_RESTRICTED",{allowedTypes:e}),{position:"top-center"})}return}let r=U(a);if(!r){console.warn("䏿¯æçæä»¶ç±»å:",a.type);return}switch(r){case"image":L(a);break;case"video":E(a);break;case"audio":M(a)}},children:[P&&(0,r.jsx)("div",{className:"absolute inset-0 bg-primary/10 backdrop-blur-sm flex items-center justify-center z-40 pointer-events-none",children:(0,r.jsxs)("div",{className:"flex flex-col items-center gap-2 text-primary",children:[(0,r.jsx)(es.A,{className:"h-12 w-12"}),(0,r.jsx)("p",{className:"text-sm font-medium",children:F("DROP_FILE_TO_UPLOAD")}),(0,r.jsx)("p",{className:"text-xs text-muted-foreground",children:S&&S.length>0?F("SUPPORT_MEDIA_TYPES",{types:S.map(e=>F(e.toUpperCase())).join("å¾ç"===F("IMAGE")?"ã":", ")}):F("SUPPORT_MEDIA_TYPES",{types:[F("IMAGE"),F("VIDEO"),F("AUDIO")].join("å¾ç"===F("IMAGE")?"ã":", ")})})]})}),y&&(0,r.jsx)("div",{className:"absolute inset-0 bg-background/70 backdrop-blur-sm flex items-center justify-center z-50",children:(0,r.jsxs)("div",{className:"flex flex-col items-center gap-1.5",children:[(0,r.jsx)(O.A,{className:"h-6 w-6 animate-spin text-primary"}),(0,r.jsx)("p",{className:"text-sm text-muted-foreground",children:k})]})}),(0,r.jsxs)("div",{className:"flex flex-col lg:flex-row gap-1.5 min-h-[80px]",children:[(!R||C||T())&&(0,r.jsx)("div",{className:"flex items-start p-1 lg:p-1.5",children:(0,r.jsx)(eo.A,{title:N,onImageUpload:L,onAudioUpload:M,onVideoUpload:E,onSlotClick:b,imageData:o,audioData:u,videoData:l,onImageRemove:()=>{f(),R&&0===l.length&&0===u.length&&I(!1)},onAudioRemove:()=>{x(),R&&0===o.length&&0===l.length&&I(!1)},onVideoRemove:()=>{v(),R&&0===o.length&&0===u.length&&I(!1)},allowedMediaTypes:S,className:(0,B.cn)("w-24 h-20 sm:w-24 sm:h-20",j)})}),(0,r.jsx)(X.T,{value:t,onChange:e=>a(e.target.value),placeholder:s,className:"flex-1 min-h-[80px] resize-none border-0 focus-visible:ring-0 pb-[30px] pt-1.5",maxLength:n})]}),w&&(0,r.jsxs)("div",{className:"text-xs text-muted-foreground pl-2 pt-0.5 bg-background",children:[t.length,"/",n]}),R&&!T()&&(0,r.jsx)("div",{className:"absolute right-2 bottom-2",children:(0,r.jsx)(h.$,{onClick:()=>{var e;return null===(e=_.current)||void 0===e?void 0:e.click()},size:"sm",variant:"outline",className:"flex items-center gap-1 px-2 py-1",title:N,children:(0,r.jsx)(en.A,{className:"h-4 w-4"})})})]})};var ec=a(62255),eu=a(94935);let em=e=>{let{projectData:t,userPrompt:a,imageData:s,videoData:n,audioData:o,previewFile:l,prompt:u,noticeText:m,panelContent:p,isUploading:f,onUserPromptChange:v,onImagePreview:x,onVideoPreview:b,onAudioPreview:y,onFileSelect:j,onFileChange:w,onRemoveFile:N,onGenerateContent:k,hasAnyFile:S,variant:R="desktop",layoutMode:C="fused",showNotice:P=!0,allowedMediaTypes:A,templateType:F="normal",isInlineGenerating:T=!1,inlineProgress:U=0,inlineResultVideoUrl:D=null,inlineCurrentChunk:L="",inlineProjectId:E=null,inlineTaskId:M=null,onViewProject:q,currentProjectId:z,fileInputRef:V}=e,W=(0,c.c3)("dashboard"),G=(0,c.c3)("quickstart"),$=(0,c.c3)("template"),J=(0,c.c3)("videoPreview"),{theme:H,setTheme:Y}=(0,ec.D)(),{user:Z}=(0,g.A)(),{baseConfig:K}=(0,I.U)(),Q=null==K?void 0:K.initial_amount,[es,en]=(0,i.useState)(!1),[el,em]=(0,i.useState)(!1),[ep,eh]=(0,i.useState)([]),eg=(0,i.useRef)(!1),ef="desktop"===R,ev="fused"===C,ex=async()=>
1{if(!D){d.oR.error($("noVideoToShare")||"没æå¯å享çè§é¢");return}em(!0);try{if(navigator.share){var e,t,a,r;try{let a=await fetch(D);if(!a.ok)throw Error("Failed to fetch video");let r=await a.blob(),i=new File([r],"ai-generated-video.mp4",{type:"video/mp4"}),s={title:$("shareVideoTitle")||"æç¨AIçæçè§é¢",text:$("shareVideoText")||"å¿«æ¥ççæç¨AIçæçè§é¢ï¼",files:[i]};if(null===(e=(t=navigator).canShare)||void 0===e?void 0:e.call(t,s)){await navigator.share(s),d.oR.success($("shareSuccess")||"å享æå");return}}catch(e){}try{let e={title:$("shareVideoTitle")||"æç¨AIçæçè§é¢",text:$("shareVideoText")||"å¿«æ¥ççæç¨AIçæçè§é¢ï¼",url:D};if(null===(a=(r=navigator).canShare)||void 0===a?void 0:a.call(r,e)){await navigator.share(e),d.oR.success($("shareSuccess")||"å享æå");return}}catch(e){}}await navigator.clipboard.writeText(D),d.oR.success($("linkCopied")||"龿¥å·²å¤å¶å°åªè´´æ¿")}catch(e){if(e instanceof Error&&"AbortError"===e.name)return;console.error("å享失败:",e)}finally{em(!1)}},{title:eb=G("aiTransitionVideo"),subtitle:ey=G("uploadShortVideo"),fusedLabel:e_=G("inputOrUpload"),separatedLabel:ej=G("enterTransitionPrompt"),placeholder:ew=G("fillRequirementsTips")}=p||{},eN=()=>"transition"===F?G("uploadReal"):G("uploadMedia"),ek=!T&&M;(0,i.useEffect)(()=>{ek&&!eg.current&&(eg.current=!0,eS())},[ek]);let eS=async()=>{try{let{data:e,error:t}=await _.supabase.from("projects").select("id, name, description, status, settings, character_ids, seo_summary_settings, created_at, share_code, copy_count").eq("is_public",!0).eq("deleted_flag",0).neq("id",z||"").order("copy_count",{ascending:!1}).limit(20);if(t)throw t;let a=(e||[]).filter(e=>{try{let t="string"==typeof e.seo_summary_settings?JSON.parse(e.seo_summary_settings):e.seo_summary_settings;return(null==t?void 0:t.type)==="transition"}catch(e){return console.error("è§£æ seo_summary_settings 失败:",e),!1}}).slice(0,4);eh(a)}catch(e){console.error("å è½½æ¨è模æ¿å¤±è´¥:",e)}};return(0,r.jsxs)("div",{className:(0,B.cn)("flex flex-col gap-4",ef?"pt-6 px-4 pb-4":"p-4"),children:[eb&&(0,r.jsx)("div",{className:(0,B.cn)("text-center px-2"),children:(0,r.jsx)("h2",{className:(0,B.cn)("font-bold text-primary",ef?"text-xl":"text-lg"),children:eb})}),ey&&(0,r.jsx)("div",{className:(0,B.cn)("text-center px-2",ef?"pb-3":"pb-2"),children:(0,r.jsx)("h3",{className:(0,B.cn)("font-semibold whitespace-pre-line leading-relaxed",ef?"text-base":"text-sm"),children:ey})}),ev?(0,r.jsxs)("div",{children:[(0,r.jsx)("div",{className:"text-xs mb-2",children:e_}),(0,r.jsx)("div",{className:(0,B.cn)("rounded-lg","border-2","border-muted","dark:border-primary/40","bg-background/50","dark:bg-muted/30","transition-all","duration-200","hover:border-primary/60","dark:hover:border-primary/60","focus-within:border-primary","dark:focus-within:border-primary/80","focus-within:ring-2","focus-within:ring-primary/20"),children:(0,r.jsx)(ed,{value:a,onChange:v,placeholder:ew,maxLength:500,imageData:s,videoData:n,audioData:o,onImageUpload:x,onVideoUpload:b,onAudioUpload:y,onImageRemove:N,onVideoRemove:N,onAudioRemove:N,onSlotClick:j,isUploading:f,fileInputRef:V,uploadMediaText:eN(),uploadingText:G("uploading"),allowedMediaTypes:A})})]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)("div",{className:"text-xs mb-2",children:G("uploadRealVideo")}),S()&&l?(0,r.jsxs)("div",{className:"relative h-[120px] border rounded-lg overflow-hidden bg-muted/30 transition-all duration-200 inline-block",children:["image"===l.type&&(0,r.jsx)("img",{src:l.url,className:" h-full object-cover",alt:"Preview"}),"video"===l.type&&(0,r.jsx)("video",{src:l.url,className:"h-full object-cover",controls:!0}),"audio"===l.type&&(0,r.jsx)("div",{className:"flex items-center justify-center h-full px-4",children:(0,r.jsx)("audio",{src:l.url,controls:!0})}),(0,r.jsx)(h.$,{variant:"ghost",size:"sm",className:"absolute top-2 right-2 bg-background/80 hover:bg-background",onClick:N,children:(0,r.jsx)(et.A,{className:"w-4 h-4"})}),f&&(0,r.jsx)("div",{className:"absolute inset-0 bg-background/80 flex items-center justify-center",children:(0,r.jsx)(O.A,{className:"w-6 h-6 animate-spin text-primary"})})]}):(0,r.jsx)("div",{className:(0,B.cn)("rounded-lg","border-2","border-dashed","border-muted","dark:border-primary/40","bg-muted/20","dark:bg-muted/30","transition-all","duration-200","hover:border-primary/60","dark:hover:border-primary/60","hover:bg-muted/30","dark:hover:bg-muted/40"),children:(0,r.jsx)(eo.A,{title:eN(),imageData:s,videoData:n,audioData:o,onImageUpload:x,onVideoUpload:b,onAudioUpload:y,onImageRemove:N,onVideoRemove:N,onAudioRemove:N,onSlotClick:j,allowedMediaTypes:A,className:"!w-full !h-[60px]"})})]}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsx)("div",{className:"text-xs mb-2",children:ej}),(0,r.jsx)("div",{className:(0,B.cn)("rounded-lg","border-2","border-muted","dark:border-primary/40","bg-background/50","dark:bg-muted/30","transition-all","duration-200","focus-within:border-primary","dark:focus-within:border-primary/80","focus-within:ring-2","focus-within:ring-primary/20"),children:(0,r.jsx)(X.T,{value:a,onChange:e=>v(e.target.value),placeholder:ew,maxLength:500,className:"min-h-[100px] resize-none border-0 bg-transparent focus-visible:ring-0 focus-visible:ring-offset-0"})}),(0,r.jsx)("div",{className:"flex justify-end",children:(0,r.jsxs)("span",{className:"text-xs text-muted-foreground",children:[a.length,"/500"]})})]})]}),(0,r.jsx)("input",{ref:V,type:"file",accept:A&&0!==A.length?A.map(e=>{switch(e){case"image":return"image/*";case"video":return"video/*";case"audio":return"audio/*"}}).join(","):"image/*,video/*,audio/*",onChange:w,className:"hidden"}),ev&&S()&&l&&(0,r.jsx)("div",{className:"space-y-3",children:(0,r.jsxs)("div",{className:"relative inline-block",children:["image"===l.type&&(0,r.jsx)("div",{className:"border rounded-lg overflow-hidden",children:(0,r.jsx)("img",{src:l.url,className:(0,B.cn)("object-contain",ev?" max-h-[120px]":"w-full max-h-[300px]"),alt:"Preview"})}),"video"===l.type&&(0,r.jsx)("div",{className:"border rounded-lg overflow-hidden",children:(0,r.jsx)("video",{src:l.url,className:(0,B.cn)("object-contain",ev?"max-h-[120px]":"w-full max-h-[300px]"),controls:!0})}),"audio"===l.type&&(0,r.jsx)("div",{className:(0,B.cn)("border rounded-lg","p-4"),children:(0,r.jsx)("audio",{src:l.url,controls:!0})}),(0,r.jsx)(h.$,{variant:"ghost",size:"sm",className:(0,B.cn)("absolute bg-background/80 hover:bg-background",ef?"top-2 right-2":"top-1 right-1"),onClick:N,children:(0,r.jsx)(et.A,{className:"w-4 h-4"})})]})}),!T&&!D&&(0,r.jsxs)("div",{children:[(0,r.jsxs)(h.$,{className:"w-full",size:"lg",disabled:(()=>{let e=S(),t=a.trim().length>0;return!!f||("transition"===F?!e||!t:!e&&!t)})(),onClick:k,children:[f?(0,r.jsx)(O.A,{className:"w-4 h-4 mr-2 animate-spin"}):(0,r.jsx)(ea.A,{className:"w-4 h-4 mr-2"}),f?W("uploading"):(0,r.jsxs)("div",{children:[W(Z?"generateContent":"startGenerate"),Z&&(null==t?void 0:t.credits)&&(0,r.jsxs)("span",{className:"ml-2 text-xs opacity-75",children:["(",t.credits," ",W("credits"),")"]}),Z&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("br",{}),(0,r.jsx)("span",{className:"text-[10px] opacity-60",children:W("noPointsDeductedOnFail")})]})]})]}),Q&&(0,r.jsx)("p",{className:"text-center text-sm font-semibold text-gray-800 dark:text-gray-100 mt-2",children:W("templateCreditsInfo.newUserBonus",{amount:Q})})]}),T&&M&&(0,r.jsx)("div",{className:(0,B.cn)("bg-muted/50 rounded-lg border-2 border-primary/30",ef?"p-4":"p-3"),children:(0,r.jsxs)("div",{className:"space-y-3",children:[(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsxs)("div",{className:"flex items-center justify-between text-sm",children:[(0,r.jsx)("span",{className:"font-medium text-foreground",children:W("quickGenerating")}),(0,r.jsxs)("span",{className:"text-primary font-semibold",children:[Math.round(U),"%"]})]}),(0,r.jsx)(ee,{value:U,className:"h-2"}),L&&(0,r.jsx)("div",{className:"mt-3 p-3 bg-muted/50 rounded-md",children:(0,r.jsx)("p",{className:"text-xs text-muted-foreground whitespace-pre-wrap break-words",children:L})})]}),(0,r.jsx)("p",{className:"text-xs text-muted-foreground",children:W("noPointsDeductedOnFail")})]})}),D&&!T&&(0,r.jsx)("div",{className:(0,B.cn)("bg-muted/50 rounded-lg border-2 border-green-500/30",ef?"p-4":"p-3"),children:(0,r.jsxs)("div",{className:"space-y-3",children:[(0,r.jsx)("div",{className:"flex items-center gap-2 text-sm font-medium text-green-600 dark:text-green-400",children:(0,r.jsx)("span",{children:W("generationCompleted")})}),(0,r.jsx)("div",{className:"relative rounded-lg overflow-hidden bg-black",children:(0,r.jsx)("video",{src:D,controls:!0,className:"w-full",style:{maxHeight:"300px"}})}),(0,r.jsxs)("div",{className:"space-y-2",children:[(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsxs)(h.$,{variant:"outline",className:"flex-1",onClick:q,children:[(0,r.jsx)(er.A,{className:"w-4 h-4 mr-2"}),W("viewProjectDetail")]}),(0,r.jsxs)(h.$,{variant:"outline",className:"flex-1",onClick:k,children:[(0,r.jsx)(ea.A,{className:"w-4 h-4 mr-2"}),W("generateAgain")]})]}),(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsx)(h.$,{variant:"outline",className:"flex-1",disabled:es,onClick:()=>
1{(0,B.Ep)({url:D,filename:"aipai-video-".concat(Date.now(),".mp4"),onStart:()=>en(!0),onFinally:()=>en(!1),t:J})},children:es?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(O.A,{className:"w-4 h-4 mr-2 animate-spin"}),J("downloading")]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(ei.A,{className:"w-4 h-4 mr-2"}),$("downloadVideo")]})}),(0,r.jsx)(h.$,{variant:"outline",className:"flex-1",onClick:ex,disabled:el,children:el?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(O.A,{className:"w-4 h-4 mr-2 animate-spin"}),$("sharing")||"å享ä¸..."]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("svg",{"data-t":"1762851611846",className:"icon w-6 h-6",viewBox:"0 0 1236 1024",version:"1.1",xmlns:"http://www.w3.org/2000/svg","p-id":"4976",children:(0,r.jsx)("path",{d:"M741.743 1018.343c-28.287 0-50.917-11.315-73.547-28.288-22.63-22.63-39.602-50.917-39.602-84.862V792.044c-124.464 0-328.133 33.945-435.624 181.039-16.973 28.287-56.575 45.26-90.52 50.917H85.478C28.903 1012.685-5.042 961.768 0.616 905.193c28.287-243.27 113.15-418.652 260.243-537.458 107.492-84.862 231.956-130.122 367.735-141.437V118.807c0-50.917 22.63-96.177 67.89-113.15C736.086-5.657 781.345 0 815.29 33.945l362.077 367.735c28.288 22.63 45.26 56.574 50.918 96.176 5.657 39.603-5.658 79.205-33.945 107.492-5.658 5.658-11.315 16.972-22.63 22.63l-350.762 356.42c-22.63 22.63-50.918 33.945-79.205 33.945z m-90.52-339.448h90.52v226.298l356.42-367.734 5.658-5.658c5.657-5.657 5.657-16.972 5.657-22.63 0-11.315-5.657-16.972-11.315-22.63l-5.657-5.657-356.42-362.077V333.79l-79.205 5.658c-118.806 0-231.956 39.602-328.132 113.149-113.15 90.519-186.696 237.613-209.326 429.967 141.436-175.382 390.364-203.669 531.8-203.669z","p-id":"4977",fill:"dark"===H?"#ffffff":"#374151"})}),$("shareVideo")]})})]})]})]})}),!T&&!D&&E&&M&&(0,r.jsx)("div",{className:(0,B.cn)("bg-muted/50 rounded-lg border-2 border-primary/30",ef?"p-4":"p-3"),children:(0,r.jsxs)("div",{className:"space-y-3",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 text-sm font-medium text-primary",children:[(0,r.jsx)(er.A,{className:"w-4 h-4"}),(0,r.jsx)("span",{children:W("taskCompletedNoVideo")})]}),(0,r.jsx)("p",{className:"text-sm text-muted-foreground",children:W("taskCompletedNoVideoDesc")}),(0,r.jsxs)("div",{className:"flex gap-2",children:[(0,r.jsxs)(h.$,{variant:"outline",className:"flex-1",onClick:q,children:[(0,r.jsx)(er.A,{className:"w-4 h-4 mr-2"}),W("viewDetail")]}),(0,r.jsxs)(h.$,{variant:"outline",className:"flex-1",onClick:k,children:[(0,r.jsx)(ea.A,{className:"w-4 h-4 mr-2"}),W("generateAgain")]})]})]})}),ek&&ep.length>0&&(0,r.jsxs)("div",{className:"space-y-3 pt-2",children:[(0,r.jsx)("div",{className:"flex items-center justify-between",children:(0,r.jsx)("h3",{className:(0,B.cn)("font-semibold text-foreground",ef?"text-base":"text-sm"),children:W("recommendedTemplates")})}),(0,r.jsx)("div",{className:(0,B.cn)("grid gap-3",ef?"grid-cols-2":"grid-cols-1"),children:ep.map(e=>(0,r.jsx)(eu.x,{project:e},e.id))})]}),P&&(0,r.jsx)("div",{className:(0,B.cn)("bg-muted/50 rounded-lg",ef?"p-3":"p-2.5"),children:(0,r.jsxs)("p",{className:(0,B.cn)("text-muted-foreground",ef?"text-sm":"text-xs leading-relaxed"),children:[m&&(()=>{let e=["bg-blue-500","bg-green-500","bg-purple-500","bg-orange-500","bg-pink-500","bg-cyan-500"],t=m.split("\n").map(e=>e.trim()).filter(e=>e.length>0);return(0,r.jsx)("div",{className:"space-y-2 pb-2",children:t.map((t,a)=>(0,r.jsxs)("span",{className:"flex items-baseline w-full",children:[(0,r.jsx)("span",{className:(0,B.cn)("w-1.5 h-1.5 rounded-full mr-2 mt-[0.1875rem] flex-shrink-0",e[a%e.length])}),(0,r.jsx)("span",{className:"flex-1 break-words",children:t})]},a))})})(),(null==t?void 0:t.credits)&&(0,r.jsxs)(r.Fragment,{children:[" ",(0,r.jsxs)("span",{className:"inline-flex items-baseline ",children:[(0,r.jsx)("span",{className:"w-1.5 h-1.5 bg-indigo-500 rounded-full mr-2 mt-[0.1875rem] flex-shrink-0"}),(0,r.jsxs)("span",{children:[W("templateCreditsInfo.baseConsumption"),(0,r.jsx)("span",{children:t.credits}),W("credits"),",",W("templateCreditsInfo.additionalCharges")]})]}),(0,r.jsx)("br",{})]}),(0,r.jsxs)("span",{className:"inline-flex items-center",children:[(0,r.jsx)("span",{className:"w-1.5 h-1.5 bg-teal-500 rounded-full mr-2 flex-shrink-0"}),(0,r.jsx)("span",{className:"text-xs",children:W("templateCreditsInfo.estimatedTime")})]})]})})]})}
1,ep=e=>{var t,a;let{projectData:i,imageData:s,videoData:n,audioData:o,previewFile:l,isUploading:d,userPrompt:c,fileInputRef:u,onImagePreview:m,onVideoPreview:p,onAudioPreview:h,onFileSelect:g,onFileChange:f,onRemoveFile:v,onGenerateContent:x,onUserPromptChange:b,hasAnyFile:y,templateProjectId:_,prompt:j,noticeText:w,layoutMode:N="fused",panelContent:k,allowedMediaTypes:S,templateType:R="normal",isInlineGenerating:C,inlineProgress:I,inlineResultVideoUrl:P,inlineCurrentChunk:A,inlineProjectId:F,inlineTaskId:T,onViewProject:U}=e;return(0,r.jsx)("div",{className:"md:hidden flex flex-col flex-1 overflow-hidden",children:(0,r.jsxs)("div",{className:"flex-1 overflow-y-auto transition-all duration-300 ease-in-out",children:[(0,r.jsx)("div",{className:"pb-4",children:(0,r.jsx)(em,{projectData:i,userPrompt:c,imageData:s,videoData:n,audioData:o,previewFile:l,prompt:j,noticeText:w,isUploading:d,onUserPromptChange:b,onImagePreview:m,onVideoPreview:p,onAudioPreview:h,onFileSelect:g,onFileChange:f,onRemoveFile:v,onGenerateContent:x,hasAnyFile:y,variant:"mobile",layoutMode:N,panelContent:k,allowedMediaTypes:S,templateType:R,fileInputRef:u,isInlineGenerating:C,inlineProgress:I,inlineResultVideoUrl:P,inlineCurrentChunk:A,inlineProjectId:F,inlineTaskId:T,onViewProject:U,currentProjectId:_})}),(0,r.jsx)("div",{className:"flex-shrink-0 h-[calc(60vh+7rem)] min-h-[500px]",children:(0,r.jsx)(Z,{templateProjectId:_,projectName:null==i?void 0:i.name,defaultVideoUrl:(null==i?void 0:i.seo_summary_settings)&&"string"==typeof i.seo_summary_settings?null===(t=JSON.parse(i.seo_summary_settings))||void 0===t?void 0:t.videoUrl:null==i?void 0:null===(a=i.seo_summary_settings)||void 0===a?void 0:a.videoUrl})})]})})},eh=()=>{var e,t;let a=(0,s.useRouter)(),{projectId:u}=a.query,_=(0,c.c3)("dashboard"),j=(0,c.c3)("template"),N=(0,c.c3)("auth"),k=(0,c.c3)("meta"),{showInsufficientCreditsDialog:R,setShowInsufficientCreditsDialog:C,insufficientCreditsDialogType:I,checkFeatureAccess:P}=(0,b.X)(),{fetchBalance:A,walletData:F,hasEverSubscribed:T}=(0,y.G)(),{user:U,isLoading:D}=(0,g.A)(),[L,O]=(0,i.useState)(""),[M,W]=(0,i.useState)(!1),[G,$]=(0,i.useState)(!1),{realProjectId:J,isLoadingProjectId:H,shareCodeError:B,projectData:Y,isLoading:K,isProjectError:X,layoutMode:Q,allowedMediaTypes:ee,panelContent:et,templateType:ea,promptContent:er,noticeTextContent:ei}=w(u),es=S({allowedMediaTypes:ee,onAuthRequired:()=>W(!0)}),en=E({realProjectId:J,projectData:Y,templateType:ea,userPrompt:L,imageData:es.imageData,videoData:es.videoData,audioData:es.audioData,previewFile:es.previewFile,onImageUpload:es.handleImageUpload,onVideoUpload:es.handleVideoUpload,onAudioUpload:es.handleAudioUpload,onRemoveFile:es.handleRemoveFile,onSetUserPrompt:O,user:U,isAuthLoading:D,onAuthRequired:()=>{W(!0)}});(0,i.useEffect)(()=>{F&&Y&&P(F,Y)},[F,Y,P]),(0,i.useEffect)(()=>{er&&!L&&O(er)},[er,L]);let eo=e=>U||D?(e(),!0):(W(!0),!1),el=()=>{let e=(null==F?void 0:F.balance)||0,t=(null==Y?void 0:Y.credits)||0;return{sufficient:e>=t,userCredits:e,requiredCredits:t,hasSubscription:T}},ed=async()=>{if(!eo(()=>{}))return;let e=el();if(!e.sufficient){e.hasSubscription?d.oR.error(_("insufficientCreditsSubscriber",{current:e.userCredits,required:e.requiredCredits}),{position:"top-center",duration:5e3}):$(!0);return}await en.handleGenerateContent()};return(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(p.A,{pageKey:"project",dynamicDescription:k("project.description",{projectTitle:null==Y?void 0:Y.name}),dynamicTitle:k("project.title",{projectTitle:null==Y?void 0:Y.name})}),(0,r.jsx)(x.o,{open:R,onOpenChange:C,type:I}),(0,r.jsx)(f.H,{open:M,onOpenChange:W,onSuccess:()=>{W(!1)},title:N("loginRequired"),description:N("pleaseLoginToContinue")}),(0,r.jsx)(v.J,{open:G,onOpenChange:$,onRechargeComplete:()=>{A()},onSubscribeComplete:()=>{A()}}),(0,r.jsx)(n.A,{projectId:J,showProjectControls:!0,shareCode:null==Y?void 0:Y.share_code,showShareButton:!0,renderLeftSection:()=>(0,r.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,r.jsx)(h.$,{variant:"ghost",size:"icon",className:"h-9 w-9 mr-0",onClick:()=>{window.history.length>1&&document.referrer?a.back():a.push("/")},children:(0,r.jsx)(l.A,{className:"h-5 w-5"})}),(0,r.jsxs)("div",{className:"flex items-center cursor-pointer",onClick:()=>
1a.push("/dashboard"),title:_("backToDashboard"),children:[(0,r.jsx)("div",{className:"relative w-8 h-8 overflow-hidden rounded-md mr-2",children:(0,r.jsx)(m(),{src:"/aipai.png",alt:"AI Pai Logo",fill:!0,className:"object-cover",priority:!0})}),(0,r.jsx)("span",{className:"text-base md:text-xl font-medium truncate block max-w-[130px]",title:(null==Y?void 0:Y.name)||_("project"),children:(null==Y?void 0:Y.name)||_("project")})]})]})}),(0,r.jsx)("div",{className:"flex flex-col h-[calc(100vh-4rem)] overflow-hidden bg-background ",children:H||K&&J?(0,r.jsx)(q,{message:j(H?"loadingShareCode":"loadingTemplateData")}):B?(0,r.jsx)(V,{shareCode:u}):X?(0,r.jsx)(z,{}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"hidden md:block flex-1 overflow-hidden",children:(0,r.jsxs)(o.HK,{direction:"horizontal",className:"h-full",children:[(0,r.jsx)(o.wV,{defaultSize:50,minSize:30,children:(0,r.jsx)(Z,{templateProjectId:J,projectName:null==Y?void 0:Y.name,defaultVideoUrl:(null==Y?void 0:Y.seo_summary_settings)&&"string"==typeof Y.seo_summary_settings?null===(e=JSON.parse(Y.seo_summary_settings))||void 0===e?void 0:e.videoUrl:null==Y?void 0:null===(t=Y.seo_summary_settings)||void 0===t?void 0:t.videoUrl})}),(0,r.jsx)(o.WM,{withHandle:!0}),(0,r.jsx)(o.wV,{defaultSize:50,minSize:30,children:(0,r.jsx)("div",{className:"h-full flex flex-col overflow-y-auto",children:(0,r.jsx)(em,{projectData:Y,userPrompt:L,imageData:es.imageData,videoData:es.videoData,audioData:es.audioData,previewFile:es.previewFile,prompt:er,noticeText:ei,isUploading:es.isUploading||en.isUploading,onUserPromptChange:O,onImagePreview:es.handleImagePreview,onVideoPreview:es.handleVideoPreview,onAudioPreview:es.handleAudioPreview,onFileSelect:es.handleFileSelect,onFileChange:es.handleFileChange,onRemoveFile:es.handleRemoveFile,onGenerateContent:ed,hasAnyFile:es.hasAnyFile,variant:"desktop",layoutMode:Q,panelContent:et,allowedMediaTypes:ee,templateType:ea,fileInputRef:es.fileInputRef,isInlineGenerating:en.isInlineGenerating,inlineProgress:en.inlineProgress,inlineResultVideoUrl:en.inlineResultVideoUrl,inlineCurrentChunk:en.inlineCurrentChunk,inlineProjectId:en.inlineProjectId,inlineTaskId:en.inlineTaskId,onViewProject:en.handleViewProject,currentProjectId:J})})})]})}),(0,r.jsx)(ep,{projectData:Y,imageData:es.imageData,videoData:es.videoData,audioData:es.audioData,previewFile:es.previewFile,isUploading:es.isUploading||en.isUploading,userPrompt:L,fileInputRef:es.fileInputRef,onImagePreview:es.handleImagePreview,onVideoPreview:es.handleVideoPreview,onAudioPreview:es.handleAudioPreview,onFileSelect:es.handleFileSelect,onFileChange:es.handleFileChange,onRemoveFile:es.handleRemoveFile,onGenerateContent:ed,onUserPromptChange:O,hasAnyFile:es.hasAnyFile,templateProjectId:J,prompt:er,noticeText:ei,layoutMode:Q,panelContent:et,allowedMediaTypes:ee,templateType:ea,isInlineGenerating:en.isInlineGenerating,inlineProgress:en.inlineProgress,inlineResultVideoUrl:en.inlineResultVideoUrl,inlineCurrentChunk:en.inlineCurrentChunk,inlineProjectId:en.inlineProjectId,inlineTaskId:en.inlineTaskId,onViewProject:en.handleViewProject})]})})]})}},94661:(e,t,a)=>{"use strict";a.d(t,{A:()=>l});var r=a(88017),i=a(67729),s=a.n(i),n=a(98476),o=a(65802);let l=e=>{let{pageKey:t,dynamicTitle:a,dynamicDescription:i,imageUrl:l,extraMeta:d}=e,c=(0,n.c3)("meta"),u=(0,o.useRouter)(),m=window.location.origin,p="".concat(m).concat(u.asPath),h=a||c("".concat(t,".title")),g=i||c("".concat(t,".description")),f="".concat(m).concat(l||"/aipai.png");return(0,r.jsxs)(s(),{children:[(0,r.jsx)("title",{children:h}),(0,r.jsx)("meta",{name:"description",content:g}),(0,r.jsx)("link",{rel:"canonical",href:p}),(0,r.jsx)("meta",{property:"og:title",content:h}),(0,r.jsx)("meta",{property:"og:description",content:g}),(0,r.jsx)("meta",{property:"og:url",content:p}),(0,r.jsx)("meta",{property:"og:type",content:"website"}),(0,r.jsx)("meta",{property:"og:site_name",content:"AIpai"}),(0,r.jsx)("meta",{property:"og:image",content:f}),(0,r.jsx)("meta",{name:"twitter:card",content:"summary_large_image"}),(0,r.jsx)("meta",{name:"twitter:title",content:h}),(0,r.jsx)("meta",{name:"twitter:description",content:g}),(0,r.jsx)("meta",{name:"twitter:image",content:f}),d]})}},94935:(e,t,a)=>{"use strict";a.d(t,{x:()=>g});var r=a(88017),i=a(44109),s=a(70247),n=a.n(s),o=a(65802),l=a(22270),d=a(35952),c=a(51720),u=a(98476),m=a(53972),p=a(15158);let h=e=>{if(!e||!(e.includes(".aliyuncs.com")||e.includes("oss-")||e.includes("cdn.aipai.cloud")))return"";let t=e.includes("?")?"&":"?";
1return"".concat(e).concat(t).concat("x-oss-process=video/snapshot,t_0,f_jpg,w_0,h_0,m_fast")},g=e=>{var t;let{project:a,onSize:s}=e,g=(0,o.useRouter)(),f=(0,u.c3)("template"),[v,x]=i.useState(!1),b=i.useRef(null),y=i.useRef(null),{ref:_,isVisible:j,nearVisible:w}=(0,c.M)(),{isMobile:N}=(0,p.F)(),k="string"==typeof a.seo_summary_settings?JSON.parse(a.seo_summary_settings):a.seo_summary_settings,S=null==k?void 0:k.videoUrl,R=null===(t=a.settings)||void 0===t?void 0:t.cover_url,C=null==k?void 0:k.description,I=(S?h(S):"")||R,P=!N&&!!S;i.useEffect(()=>()=>{b.current&&clearTimeout(b.current),y.current&&clearTimeout(y.current)},[]);let A=e=>{e.preventDefault(),e.stopPropagation();let t=g.query.projectId,r="/templates/[projectId]"===g.pathname;t&&r?window.location.href="/templates/".concat(a.id):g.push("/templates/".concat(a.id))};return(0,r.jsx)(n(),{href:"/templates/".concat(a.id),onClick:A,children:(0,r.jsxs)(l.Zp,{className:"overflow-hidden border transition-all hover:border-primary/50 hover:shadow-md relative p-0 gap-0 group cursor-pointer",children:[(0,r.jsx)(l.aR,{className:"p-0",children:(0,r.jsxs)("div",{ref:_,className:"w-full bg-muted relative overflow-hidden",onMouseEnter:()=>{P&&(y.current&&(clearTimeout(y.current),y.current=null),b.current&&clearTimeout(b.current),b.current=setTimeout(()=>{x(!0),b.current=null},200))},onMouseLeave:()=>{P&&(b.current&&(clearTimeout(b.current),b.current=null),y.current&&clearTimeout(y.current),y.current=setTimeout(()=>{x(!1),y.current=null},120))},children:[I?(0,r.jsx)("img",{src:I,alt:a.name,className:"w-full object-cover transition-transform group-hover:scale-105",style:{height:"auto",minHeight:"200px"},onLoad:e=>{if(!s)return;let t=e.currentTarget,r=t.naturalWidth,i=t.naturalHeight;r>0&&i>0&&s(a.id,{width:r,height:i})},onError:e=>{R&&e.currentTarget.src!==R&&(e.currentTarget.src=R)}}):(0,r.jsx)("div",{className:"flex items-center justify-center bg-gradient-to-br from-muted to-muted-foreground/20",style:{minHeight:"200px"},children:(0,r.jsx)("p",{className:"text-xl font-semibold text-muted-foreground/70",children:a.name.substring(0,2)})}),P&&v&&(0,r.jsx)("video",{src:S,className:"absolute inset-0 h-full w-full object-cover transition-transform group-hover:scale-105 pointer-events-none",loop:!0,muted:!0,playsInline:!0,autoPlay:!0,preload:j?"auto":w?"metadata":"none",onLoadedMetadata:e=>{if(!s)return;let t=e.currentTarget,r=t.videoWidth,i=t.videoHeight;r>0&&i>0&&s(a.id,{width:r,height:i})}})]})}),(0,r.jsx)(l.Wu,{className:"p-3",children:(0,r.jsxs)("div",{className:"flex items-center gap-3 text-sm min-h-[36px]",children:[(0,r.jsxs)("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[(0,r.jsx)("h3",{className:"font-semibold line-clamp-1 group-hover:text-primary transition-colors flex-shrink-0",children:a.name}),C&&(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("span",{className:"text-muted-foreground flex-shrink-0",children:"|"}),(0,r.jsx)("p",{className:"text-muted-foreground line-clamp-1 flex-1",children:C})]})]}),(0,r.jsxs)(d.$,{variant:"default",size:"sm",className:"h-8 px-3 bg-gradient-to-r from-purple-500 to-blue-500 hover:from-purple-600 hover:to-blue-600 text-white border-0 shadow-md hover:shadow-lg transition-all duration-200 flex items-center gap-1.5 flex-shrink-0",onClick:A,children:[(0,r.jsx)("span",{className:"text-sm font-medium",children:f("tryTemplate")}),(0,r.jsx)(m.A,{className:"h-4 w-4"})]})]})})]})})}},95699:(e,t,a)=>{"use strict";a.d(t,{H:()=>c});var r=a(88017),i=a(44109),s=a(98476),n=a(36888),o=a(99100),l=a(61579),d=a(91590);function c(e){let{open:t,onOpenChange:a,onSuccess:c,title:u,description:m}=e,p=(0,s.c3)("auth"),{user:h}=(0,l.A)(),{baseConfig:g}=(0,d.U)(),[f,v]=(0,i.useState)(h);(0,i.useEffect)(()=>{!f&&h&&(null==c||c(h),a(!1)),v(h)},[h,f,c,a]);let x=null==g?void 0:g.initial_amount,b=null==g?void 0:g.sender_credits,y=null==g?void 0:g.receiver_credits;return(0,r.jsx)(n.lG,{open:t,onOpenChange:a,children:(0,r.jsxs)(n.Cf,{className:"max-w-md max-h-[90vh] overflow-y-auto",children:[(0,r.jsxs)(n.c7,{children:[(0,r.jsx)(n.L3,{className:"text-xl font-bold",children:u||p("loginRequired")}),m&&(0,r.jsx)(n.rr,{className:"text-sm text-muted-foreground",children:m})]}),(0,r.jsx)("div",{className:"mt-4",children:(0,r.jsx)(o.T,{invitationBonusData:{initial_amount:x,sender_credits:b,receiver_credits:y},onAuthSuccess:e=>{null==c||c(e)},disableAutoRedirect:!0})})]})})}},95839:(e,t,a)=>{"use strict";a.d(t,{MP:()=>i,PW:()=>n,validateImageForVideoMode:()=>s});var r=a(24077);let i=async function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0x1400000,a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:120;if(!e.type.startsWith("video/"))return{valid:!1,message:"videoFileTypeError"};if(e.size>t)return{valid:!1,message:"videoFileSizeError"};try{if(await (0,r.qZ)(e)>a)return{valid:!1,message:"videoTooLong",params:{maxDuration:a}}}catch(e){console.error("è·åè§é¢æ¶é¿å¤±è´¥:",e)}return{valid:!0}},s=(e,t)=>new Promise(a=>{let r=t||(e=>e);if(e.size>0xa00000){a({valid:!1,message:r("validation.fileTooLarge",{maxSizeMB:"10"})});return}if(!["image/jpeg","image/jpg","image/png","image/webp"].includes(e.type)){a({valid:!1,message:r("validation.unsupportedImageFormat",{format:e.type||r("validation.unknown")})});return}let i=new Image,s=URL.createObjectURL(e);i.onload=()=>{URL.revokeObjectURL(s);
1let e=i.naturalWidth,t=i.naturalHeight,n=Math.min(e,t),o=e/t;if(n<300){a({valid:!1,message:r("validation.minSideLength",{length:n})});return}if(o<.5||o>2){a({valid:!1,message:r("validation.aspectRatioLimit",{ratio:o.toFixed(2)})});return}a({valid:!0})},i.onerror=()=>{URL.revokeObjectURL(s),a({valid:!1,message:r("validation.invalidImage")})},i.src=s}),n=async function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0xa00000,a=arguments.length>2?arguments[2]:void 0;if(!e.type.startsWith("audio/"))return{valid:!1,message:"audioFileTypeError"};if(e.size>t)return{valid:!1,message:"audioFileSizeError",params:{maxSizeMB:(t/1048576).toFixed(0)}};if(void 0!==a&&a>0)try{let t=await (0,r.LG)(e);if(t>a)return{valid:!1,message:"audioTooLong",params:{maxDuration:a,actualDuration:Math.round(t)}}}catch(e){console.error("è·åé³é¢æ¶é¿å¤±è´¥:",e)}return{valid:!0}}},97452:(e,t,a)=>{"use strict";a.d(t,{o:()=>d});var r=a(88017);a(44109);var i=a(98476),s=a(36888),n=a(35952),o=a(81329),l=a(29965);function d(e){let{open:t,onOpenChange:a,type:d="insufficient_credits",source:c="agent"}=e,u=(0,i.c3)("billing"),{walletData:m}=(0,l.G)();return(0,r.jsx)(s.lG,{open:t,onOpenChange:a,children:(0,r.jsxs)(s.Cf,{className:" max-w-[1350px] max-h-[80vh] overflow-y-auto overflow-x-auto p-4",children:[(0,r.jsxs)(s.c7,{children:[(0,r.jsx)(s.L3,{children:"".concat(u("noAgentPermissionTitle"),"/").concat(u("insufficientCreditsTitle"))}),(0,r.jsx)(s.rr,{children:u("noAgentPermissionDescription")})]}),(0,r.jsx)("div",{className:"py-2 overflow-x-auto",children:(0,r.jsx)(o.b,{walletData:m,compact:!0,source:c,onSubscriptionComplete:()=>a(!1)})}),(0,r.jsx)(s.Es,{className:"flex justify-end gap-2",children:(0,r.jsx)(n.$,{variant:"outline",onClick:()=>a(!1),children:u("cancel")})})]})})}}},e=>{var t=t=>e(e.s=t);e.O(0,[6113,3256,4833,6474,3861,7304,9460,247,4821,6187,2886,7694,3119,4062,1463,5064,1658,5228,6510,6535,1329,9100,636,8974,8792],()=>t(1461)),_N_E=e.O()}]);
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.