PageSourceSearch

https://cremi.ai/_next/static/chunks/1q28cybu7hsoh.js

js cremi.ai collected 2026-10-05 12:49:28 UTC 110,600 bytes, 9 lines download raw bytes

1;!function(){try { var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof global?global:"undefined"!=typeof window?window:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&((e._debugIds|| (e._debugIds={}))[n]="c33a0c90-3d01-c1f6-65b1-d3a6bf037319")}catch(e){}}();
2(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,56864,e=>{"use strict";var t=e.i(139736),s=e.i(286968),a=e.i(559466),r=e.i(45356),l=e.i(805125),i=e.i(602874),n=e.i(452897),o=e.i(602087),d=e.i(665745),c=e.i(810143),u=e.i(235166),m=e.i(688694),x=e.i(539921),p=e.i(992850),h=e.i(220011),f=e.i(662664),g=e.i(114624),b=e.i(285019),v=e.i(362315),j=e.i(359283),y=e.i(199647);let w={"16:9":"aspect-video","9:16":"aspect-[9/16]","4:3":"aspect-[4/3]","3:4":"aspect-[3/4]","21:9":"aspect-[21/9]","1:1":"aspect-square"};function N({template:e,isSelected:a,onOpen:r,onUse:l,style:i}){let n=(0,f.getEffectiveTemplateConfig)(e),o=e.preview_video_url||null,d=e.thumbnail_url||null,c=(0,s.useRef)(null),u=(0,s.useRef)(null),[m,p]=(0,s.useState)(!1),[h,_]=(0,s.useState)(!0),[k,C]=(0,s.useState)(!1),S=(0,s.useCallback)(e=>{e.stopPropagation(),c.current&&(c.current.muted=!c.current.muted,_(c.current.muted))},[]),T=(0,s.useCallback)(e=>{e.stopPropagation();let t=c.current;t&&(t.paused?t.play().then(()=>C(!0)).catch(()=>{}):(t.pause(),C(!1)))},[]);(0,s.useEffect)(()=>{let e=c.current;e&&o&&(e.muted=h)},[o,h]),(0,s.useEffect)(()=>{if(!o||m)return;let e=u.current;if(!e)return;if("u"<typeof IntersectionObserver)return void p(!0);let t=new IntersectionObserver(e=>{e.some(e=>e.isIntersecting)&&(p(!0),t.disconnect())},{rootMargin:"300px"});return t.observe(e),()=>t.disconnect()},[o,m]);let D=(0,s.useCallback)(()=>{let e=c.current;e&&e.play().then(()=>C(!0)).catch(()=>{})},[]),E=(0,s.useCallback)(()=>{let e=c.current;e&&(e.pause(),e.currentTime=0,C(!1))},[]),A=w[n?.default_aspect_ratio??n?.aspect_ratios?.[0]??"9:16"]??"aspect-[9/16]",L=n?.duration?.default?Math.round(n.duration.default):null;return(0,t.jsx)("div",{ref:u,role:"button",tabIndex:0,onClick:r,onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),r())},onMouseEnter:D,onMouseLeave:E,style:i,className:`group relative rounded-xl overflow-hidden border-2 transition-all duration-200 cursor-pointer ${a?"border-primary ring-2 ring-primary/20":"border-border hover:border-primary/50"}`,"aria-pressed":a,"aria-label":`Preview template ${e.title}`,children:(0,t.jsxs)("div",{className:`${A} bg-muted relative`,children:[o?(0,t.jsx)("video",{ref:c,src:o,poster:d??void 0,className:"w-full h-full object-cover",loop:!0,muted:!0,playsInline:!0,preload:m?"metadata":"none"}):d?(0,t.jsx)(g.default,{src:d,alt:e.title,fill:!0,className:"object-cover",sizes:"(min-width: 1024px) 25vw, 50vw"}):(0,t.jsx)("div",{className:"w-full h-full flex items-center justify-center text-muted-foreground text-xs bg-gradient-to-br from-muted to-card",children:"No preview"}),(0,t.jsxs)("div",{className:"absolute top-2 left-2 right-10 flex items-center gap-1",children:["draft"===e.status&&(0,t.jsx)("span",{className:"shrink-0 px-2 py-0.5 rounded-md bg-amber-500 text-white text-[10px] font-semibold tracking-wide uppercase backdrop-blur-sm",children:"Draft"}),(0,t.jsx)("span",{className:"min-w-0 truncate px-2 py-0.5 rounded-md bg-black/60 text-white text-[10px] font-medium tracking-wide uppercase backdrop-blur-sm",children:e.title})]}),a&&(0,t.jsx)("div",{className:"absolute top-2 right-2 w-7 h-7 bg-primary rounded-full flex items-center justify-center z-10 shadow ring-2 ring-background",children:(0,t.jsx)("svg",{className:"w-4 h-4 text-primary-foreground",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,t.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})}),o&&(0,t.jsx)("button",{type:"button",onClick:S,className:"absolute bottom-2 right-2 w-9 h-9 md:w-7 md:h-7 rounded-full bg-black/50 backdrop-blur-sm flex items-center justify-center text-white/80 hover:text-white hover:bg-black/70 transition-all cursor-pointer z-20","aria-label":h?"Unmute preview":"Mute preview",children:h?(0,t.jsx)(y.VolumeX,{className:"w-3.5 h-3.5"}):(0,t.jsx)(j.Volume2,{className:"w-3.5 h-3.5"})}),o&&(0,t.jsx)("button",{type:"button",onClick:T,className:"md:hidden absolute bottom-2 left-1/2 -translate-x-1/2 w-9 h-9 rounded-full bg-black/50 backdrop-blur-sm flex items-center justify-center text-white/90 active:bg-black/70 transition-all z-20","aria-label":k?"Pause preview":"Play preview",children:k?(0,t.jsx)(b.Pause,{className:"w-3.5 h-3.5"}):(0,t.jsx)(v.Play,{className:"w-3.5 h-3.5"})}),null!=L&&(0,t.jsxs)("span",{className:"absolute bottom-2 left-2 z-10 px-2 py-0.5 rounded-md bg-black/60 text-white text-[10px] font-semibold tracking-wide backdrop-blur-sm",children:[L,"s"]}),(0,t.jsxs)("div",{className:"hidden md:flex absolute inset-0 z-10 flex-col items-center justify-center gap-2 bg-black/45 opacity-0 group-hover:opacity-100 transition-opacity",children:[(0,t.jsxs)("button",{type:"button",onClick:e=>{e.stopPropagation(),l()},className:"inline-flex items-center gap-1.5 px-4 py-2 rounded-full bg-gradient-hero text-white text-sm font-semibold shadow hover:opacity-90 transition-opacity cursor-pointer",children:[(0,t.jsx)(x.Sparkles,{className:"w-4 h-4"}),"Use Template"]}),(0,t.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),r()},className:"text-xs font-medium text-white/90 underline underline-offset-2 hover:text-white transition-colors cursor-pointer",children:"Preview"})]})]})})}var _=e.i(971893),k=e.i(309943),C=e.i(630374),S=e.i(257765);function T({template:e,onClose:a,onUse:r}
2){let l=(0,p.useTranslations)("shortTemplates"),[i,n]=(0,s.useState)(!1),o=(0,s.useMemo)(()=>(0,f.getEffectiveTemplateConfig)(e),[e]),d=e?.preview_video_url||null,c=e?.thumbnail_url||null,u=(o?.isMultiScene?o.userPromptDefault:o?.scenePromptDefaults[0])?.trim()||"",m=u.length>220,x=(0,s.useMemo)(()=>{if(!e||!o)return[];let t=[],s=(s,a)=>{for(let r of s){if(r.hidden_from_user)continue;let s=r.default_asset_id?e.asset_urls?.[r.default_asset_id]??null:null;s&&t.push({kind:a,url:s})}};return s(o.image_slots,"image"),s(o.video_slots,"video"),s(o.audio_slots,"audio"),t},[e,o]);return(0,t.jsx)(C.Dialog,{open:null!==e,onOpenChange:e=>{e||(n(!1),a())},children:(0,t.jsx)(C.DialogContent,{className:"max-w-5xl p-0 gap-0 overflow-hidden",children:e&&(0,t.jsxs)("div",{className:"flex flex-col md:flex-row h-[88dvh] md:h-[82vh] md:max-h-[90vh]",children:[(0,t.jsx)("div",{className:"relative md:flex-1 bg-black flex items-center justify-center min-h-[40vh] max-h-[45vh] md:min-h-0 md:max-h-none pt-12 md:pt-0",children:d?(0,t.jsx)("video",{src:d,poster:c??void 0,className:"w-full h-full object-contain",autoPlay:!0,loop:!0,controls:!0,playsInline:!0,preload:"metadata"}):c?(0,t.jsx)("img",{src:c,alt:e.title,className:"w-full h-full object-contain"}):(0,t.jsx)("div",{className:"text-muted-foreground text-xs",children:l("previewModal.noPreview")})}),(0,t.jsxs)("div",{className:"flex flex-col flex-1 md:flex-none md:w-[340px] lg:w-[380px] min-h-0",children:[(0,t.jsxs)("div",{className:"flex-1 min-h-0 overflow-y-auto p-5 space-y-5",children:[(0,t.jsxs)("div",{className:"pr-6",children:[(0,t.jsx)(C.DialogTitle,{className:"text-lg font-semibold text-foreground",children:e.title}),e.description&&(0,t.jsx)("p",{className:"mt-1 text-sm text-muted-foreground",children:e.description})]}),u&&(0,t.jsxs)("div",{className:"space-y-1.5",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,t.jsx)("h4",{className:"text-[11px] font-semibold uppercase tracking-wide text-muted-foreground",children:l("previewModal.prompt")}),(0,t.jsx)(S.CopyButton,{value:u,label:l("previewModal.copyPrompt")})]}),(0,t.jsx)("p",{className:`text-sm text-foreground leading-relaxed whitespace-pre-wrap ${m&&!i?"line-clamp-4":""}`,children:u}),m&&(0,t.jsxs)("button",{type:"button",onClick:()=>n(e=>!e),className:"inline-flex items-center gap-1 text-xs font-medium text-primary hover:underline cursor-pointer",children:[l(i?"previewModal.showLess":"previewModal.showMore"),(0,t.jsx)(_.ChevronDown,{className:`w-3.5 h-3.5 transition-transform ${i?"rotate-180":""}`})]})]}),x.length>0&&(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)("h4",{className:"text-[11px] font-semibold uppercase tracking-wide text-muted-foreground",children:l("previewModal.references")}),(0,t.jsx)("div",{className:"flex flex-wrap gap-2",children:x.map((e,s)=>(0,t.jsx)("div",{className:"w-14 h-14 rounded-lg overflow-hidden border border-border bg-muted flex items-center justify-center",children:"image"===e.kind?(0,t.jsx)("img",{src:e.url,alt:"",className:"w-full h-full object-cover"}):"video"===e.kind?(0,t.jsx)("video",{src:e.url,muted:!0,playsInline:!0,preload:"metadata",className:"w-full h-full object-cover"}):(0,t.jsx)(k.Music2,{className:"w-5 h-5 text-muted-foreground"})},s))})]})]}),(0,t.jsx)("div",{className:"border-t border-border p-4",children:(0,t.jsx)("button",{type:"button",onClick:()=>r(e),className:"w-full rounded-lg bg-gradient-hero hover:opacity-90 text-white text-sm font-semibold py-3 transition-opacity cursor-pointer",children:l("previewModal.useTemplate")})})]})]})})})}function D({templates:e}){let s=(0,p.useTranslations)("shortTemplates"),a=e.slice(0,3);return(0,t.jsx)("div",{className:"relative rounded-2xl border border-border bg-gradient-to-br from-muted to-muted/50 dark:from-background dark:to-background p-4 sm:p-6 overflow-hidden",children:(0,t.jsxs)("div",{className:"flex items-center justify-between gap-6",children:[(0,t.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,t.jsxs)("h2",{className:"text-lg sm:text-2xl font-bold text-foreground leading-tight tracking-tight",children:[s("heroTitlePrefix")," ",(0,t.jsx)("span",{className:"text-gradient-hero",children:s("heroTitleHighlight")}),(0,t.jsx)("br",{}),s("heroTitleSuffix")]}),(0,t.jsx)("p",{className:"mt-1.5 sm:mt-2 text-xs sm:text-sm text-muted-foreground",children:s("heroSubtitle")})]}),a.length>0&&(0,t.jsx)("div",{className:"hidden md:flex items-center justify-center relative w-56 h-36 flex-shrink-0",children:a.map((e,s)=>{let a=e.preview_video_url||e.thumbnail_url||null;
2return(0,t.jsx)("div",{className:`absolute ${["w-20 h-28","w-24 h-32","w-20 h-28"][s]} rounded-xl overflow-hidden border-2 border-white dark:border-border shadow-lg transform ${["-rotate-6","rotate-0","rotate-6"][s]||""} ${["left-0 z-0","left-1/2 -translate-x-1/2 z-10","right-0 z-0"][s]||""}`,children:a&&a.endsWith(".mp4")?(0,t.jsx)("video",{src:a,className:"w-full h-full object-cover",autoPlay:!0,loop:!0,muted:!0,playsInline:!0,preload:"metadata"}):a?(0,t.jsx)("img",{src:a,alt:e.title,className:"w-full h-full object-cover"}):(0,t.jsx)("div",{className:"w-full h-full bg-muted/60 dark:bg-muted"})},e.id)})})]})})}function E({genres:e,active:s,onChange:a}){return(0,t.jsxs)("div",{className:"flex items-center gap-1.5 flex-wrap",children:[(0,t.jsx)("button",{type:"button",onClick:()=>a(null),className:`px-3 py-1 rounded-full text-xs font-medium transition-colors ${null===s?"bg-foreground text-background":"text-muted-foreground hover:text-foreground hover:bg-muted"}`,children:"All"}),e.map(e=>(0,t.jsx)("button",{type:"button",onClick:()=>a(e),className:`px-3 py-1 rounded-full text-xs font-medium transition-colors ${s===e?"bg-foreground text-background":"text-muted-foreground hover:text-foreground hover:bg-muted"}`,children:e},e))]})}function A({templates:e,isLoading:a,selectedTemplateId:r,onSelect:l,headerSlot:i,footerSlot:n}){let o=(0,p.useTranslations)("shortTemplates"),[d,c]=(0,s.useState)(null),[u,x]=(0,s.use
2State)(null),[g,b]=function(){let[e,t]=(0,s.useState)(0),a=(0,s.useRef)(null);return[(0,s.useCallback)(e=>{if(a.current?.disconnect(),!e)return;t(e.clientWidth);let s=new ResizeObserver(e=>{t(e[0].contentRect.width)});s.observe(e),a.current=s},[]),e]}(),v=(0,s.useRef)(null),j=(0,s.useMemo)(()=>{let t=new Map;for(let s of e)for(let e of s.genres??[]){let s=e.trim().toLowerCase();s&&(t.has(s)||t.set(s,e.trim()))}return Array.from(t.values()).sort((e,t)=>e.localeCompare(t))},[e]);d&&!j.some(e=>e.toLowerCase()===d.toLowerCase())&&c(null);let y=(0,s.useMemo)(()=>{if(!d)return e;let t=d.toLowerCase();return e.filter(e=>(e.genres??[]).some(e=>e.toLowerCase()===t))},[e,d]),w=Math.min(8,Math.max(b>0&&b<340?1:2,Math.round(b/240)));return((0,s.useLayoutEffect)(()=>{let e=v.current;if(e&&0!==b)for(let t of Array.from(e.children)){let e=t.getBoundingClientRect().height;t.style.gridRowEnd=`span ${Math.ceil(e)+12}`}},[b,w,y]),a&&0===e.length)?(0,t.jsx)("div",{className:"h-full flex items-center justify-center",children:(0,t.jsx)(m.Loader2,{className:"w-8 h-8 text-muted-foreground animate-spin"})}):0===e.length?(0,t.jsxs)("div",{className:"h-full overflow-y-auto p-4 space-y-4",children:[i,(0,t.jsxs)("div",{className:"flex flex-col items-center justify-center py-16 gap-2",children:[(0,t.jsx)(h.LayoutTemplate,{className:"w-12 h-12 text-muted-foreground mb-1"}),(0,t.jsx)("h3",{className:"text-lg font-medium text-foreground",children:"No templates yet"}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"Admin-curated short-video templates will appear here."})]}),n]}):(0,t.jsxs)("div",{className:"h-full overflow-y-auto p-4 space-y-4",children:[(0,t.jsx)(D,{templates:e}),i,(0,t.jsx)(E,{genres:j,active:d,onChange:c}),(0,t.jsx)("p",{className:"text-sm text-foreground",children:(0,t.jsx)("span",{className:"font-bold",children:o("pickerHeadingPick")})}),(0,t.jsx)("div",{ref:g,children:0===y.length?(0,t.jsxs)("div",{className:"flex flex-col items-center justify-center py-12 gap-2",children:[(0,t.jsx)(h.LayoutTemplate,{className:"w-8 h-8 text-muted-foreground"}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:d?`No templates in “${d}” yet.`:"No templates yet."})]}):(0,t.jsx)("div",{ref:v,className:"grid",style:{gridTemplateColumns:`repeat(${w}, minmax(0, 1fr))`,gridAutoRows:"1px",gridAutoFlow:"row dense",rowGap:0,columnGap:"12px",alignItems:"start"},children:y.map(e=>{let s;return(0,t.jsx)(N,{template:e,isSelected:r===e.id,onOpen:()=>x(e),onUse:()=>l(e),style:{gridColumn:`span ${Math.min(function(e){let[t,s]=e.split(":").map(Number);return t>s?2:1}((s=(0,f.getEffectiveTemplateConfig)(e),s?.default_aspect_ratio??s?.aspect_ratios?.[0]??"9:16")),w)}`}},e.id)})})}),n,(0,t.jsx)(T,{template:u,onClose:()=>x(null),onUse:e=>{x(null),l(e)}})]})}var L=e.i(46917),P=e.i(496028),I=e.i(552315),M=e.i(617540),R=e.i(686628),O=e.i(140424),$=e.i(278e3),F=e.i(595179),U=e.i(237979),q=e.i(230219),z=e.i(271499),V=e.i(162641),B=e.i(963074),G=e.i(335401),H=e.i(990626),X=e.i(278787),W=e.i(91069),K=e.i(771903);function Z({generation:e}){let s=e.scenes?.[0],a=(0,K.buildAssetRefsFromIds)(e.user_image_asset_ids??s?.resolved_image_asset_ids??[],e.user_video_asset_ids??s?.resolved_video_asset_ids??[],e.user_audio_asset_ids??s?.resolved_audio_asset_ids??[]);return(0,t.jsx)(K.AssetRefsGrid,{refs:a,urls:e.asset_urls??{},createdAt:e.created_at})}let J={image:"text-interactive bg-interactive/15",video:"text-blue-500 bg-blue-500/15",audio:"text-emerald-500 bg-emerald-500/15"};function Y({seg:e}){let a=[e.bold?"font-semibold":"",e.italic?"italic":"",e.underline?"underline":"",e.tag?`rounded-sm px-0.5 ${J[e.tag]}`:""].filter(Boolean).join(" ");return a?(0,t.jsx)("span",{className:a,children:e.text}):(0,t.jsx)(s.Fragment,{children:e.text})}function Q({segments:e}){return(0,t.jsx)(t.Fragment,{children:e.map((e,s)=>(0,t.jsx)(Y,{seg:e},s))})}let ee={1:"text-xl font-bold mt-1",2:"text-lg font-bold mt-1",3:"text-base font-semibold mt-1",4:"text-sm font-semibold mt-0.5",5:"text-sm font-medium mt-0.5",6:"text-xs font-semibold uppercase tracking-wide mt-0.5"};function et({level:e,segments:s}){let a=`h${Math.min(6,Math.max(1,e))}`;return(0,t.jsx)(a,{className:ee[e]??ee[6],children:(0,t.jsx)(Q,{segments:s})})}function es({value:e,className:s,emptyLabel:a="Nothing to preview yet."}){if(!e.trim())return(0,t.jsx)("div",{className:s,children:(0,t.jsx)("span",{className:"text-muted-foreground italic",children:a})});let r=(0,W.tokenizeBlocks)(e);return(0,t.jsx)("div",{className:`whitespace-pre-wrap break-words leading-relaxed ${s??""}`,children:r.map((e,s)=>"heading"===e.type?(0,t.jsx)(et,{level:e.level,segments:e.segments},s):"list"===e.type?(0,t.jsx)("ul",{className:"list-disc pl-5 my-1 space-y-0.5",children:e.items.map((e,s)=>(0,t.jsx)("li",{children:(0,t.jsx)(Q,{segments:e})},s))},s):(0,t.jsx)("div",{children:(0,t.jsx)(Q,{segments:e.segments})},s))})}var ea=e.i(209909),er=e.i(585579),el=e.i(713404),ei=e.i(303942);function en({status:e}){let s={pending:{label:"In queue",cls:"bg-warning/15 text-warning border-warning/30"},processing:{label:"Generating",cls:"bg-primary/10 text-primary border-primary/30"},completed:{label:"Completed",cls:"bg-success/15 text-success border-success/30"},failed:{label:"Failed",cls:"bg-warning/15 text-warning border-warning/30"},partial:{label:"Partial",cls:"bg-caution/15 text-caution border-caution/30"},cancelled:{label:"Cancelled",cls:"bg-muted text-muted-foreground border-border"}}[e]??{label:e,cls:"bg-muted text-muted-foreground border-border"};return(0,t.jsx)("span",{className:`inline-flex items-center gap-1 px-2 py-0.5 rounded-md border text-[11px] font-medium ${s.cls}`,children:s.label})}function eo({scenes:e,mode:s,errorMessage:a,refunded:r}){let l=e.find(e=>"completed"===e.task_status&&e.video_url),i=!!l?.video_url;return(0,t.jsxs)("div",{className:"absolute inset-0",children:[i?(0,t.jsx)("video",{src:l.video_url,className:"absolute inset-0 w-full h-full object-contain opacity-50",autoPlay:!0,muted:!0,loop:!0,playsInl
2ine:!0,preload:"metadata"},l.video_url):(0,t.jsx)("div",{className:"absolute inset-0 bg-gradient-to-br from-background to-muted"}),i&&(0,t.jsxs)("span",{className:"absolute top-3 left-3 z-10 inline-flex items-center gap-1.5 px-2 py-1 rounded-md bg-black/55 text-white/85 text-[10px] font-mono backdrop-blur-sm",children:[(0,t.jsx)(v.Play,{className:"w-2.5 h-2.5"}),"Preview"]}),(0,t.jsx)("div",{className:"absolute inset-0 bg-gradient-to-b from-background/25 via-background/40 to-background/95"}),(0,t.jsx)("div",{className:i?"absolute inset-x-0 bottom-0 p-5 text-left":"absolute inset-0 flex items-center justify-center p-6",children:(0,t.jsxs)("div",{className:i?"":"w-full max-w-md text-center",children:[(0,t.jsxs)("div",{className:`flex items-center gap-2.5 mb-1 ${i?"":"justify-center"}`,children:[(0,t.jsx)("span",{className:`w-6 h-6 rounded-full flex items-center justify-center flex-shrink-0 ${"failed"===s?"bg-warning/15 text-warning":"bg-primary/10 text-primary"}`,children:"failed"===s?(0,t.jsx)(M.AlertTriangle,{className:"w-3.5 h-3.5"}):(0,t.jsx)(m.Loader2,{className:"w-3.5 h-3.5 animate-spin"})}),(0,t.jsx)("h3",{className:"text-base font-semibold text-foreground",children:"failed"===s?"Generation failed":"Generating your video…"})]}),(0,t.jsx)("div",{className:`text-xs text-muted-foreground flex flex-wrap items-center gap-2 ${i?"":"justify-center"}`,children:"failed"===s?(0,t.jsxs)(t.Fragment,{children:[a&&(0,t.jsx)("span",{className:"break-words",children:a}),r&&(0,t.jsxs)("span",{className:"inline-flex items-center gap-1 px-2.5 py-0.5 rounded-full bg-success/15 text-success border border-success/30 text-[11px] font-medium",children:[(0,t.jsx)(R.Check,{className:"w-3 h-3"}),"Credits refunded"]})]}):(0,t.jsx)("span",{children:"Hang tight — this usually takes a few minutes."})})]})})]})}function ed({generation:e,onRetry:a,onDelete:r,onRerun:l,isSelected:i=!1,onSelect:n}){let o=e.scenes??[],d=o[0],c=o.length>1,u=(e.final_video_asset_id?e.asset_urls?.[e.final_video_asset_id]??null:null)??(c?null:d?.video_url??null),x="pending"===e.status||"processing"===e.status,h="completed"===e.status&&u,f="failed"===e.status||"cancelled"===e.status,g="partial"===e.status,b=f&&(e.estimated_cost_credits??0)>0,[v,j]=(0,s.useState)(!1),[y,w]=(0,s.useState)(!1),[N,k]=(0,s.useState)(null),{canDownload:C}=(0,ea.useUserPlan)(),S=(0,p.useTranslations)("shortTemplates.result"),[T,D]=(0,s.use
2State)(!1),[E,A]=(0,s.useState)(!1),[L,M]=(0,s.useState)(!1),[K,J]=(0,s.useState)(!1),[Y,Q]=(0,s.useState)(!1),ee=e.final_video_asset_id??d?.video_asset_id??null,et=ee?`${window.location.origin}/share/video/${ee}`:"",ec=e.user_text_prompt,eu=c?o.map(e=>e.resolved_prompt).filter(Boolean).join("\n\n")||null:d?.resolved_prompt??null,em=ec??eu,ex=async()=>{if(em)try{await navigator.clipboard.writeText((0,W.stripPromptFormatting)(em)),M(!0),setTimeout(()=>M(!1),1500)}catch(e){console.error("Copy prompt failed",e)}},ep=async()=>{if(u&&!y){if(j(!1),!C)return void D(!0);w(!0),k(null);try{let t=await (0,B.downloadVideoAsBlob)(u,void 0,e=>k(e.fraction)),s=(0,B.getFileExtension)(u,t);(0,B.triggerBlobDownload)(t,(0,H.buildCremiFileName)({feature:"short-template",baseName:e.template_id?`template-${e.template_id.slice(-6)}`:void 0,extension:s}))}catch(e){console.error("Short template video download failed",e)}finally{w(!1),k(null)}}},eh=!e.error_kind||"transient"===e.error_kind||"network"===e.error_kind||"timeout"===e.error_kind;return(0,t.jsxs)("div",{className:`bg-card rounded-lg border-2 transition-colors ${i?"border-primary":"border-border"} overflow-hidden`,children:[(0,t.jsxs)("div",{className:"flex flex-col md:flex-row gap-0 md:min-
2h-[500px]",children:[(0,t.jsx)("div",{className:"flex-1 relative bg-black min-w-0 min-h-[280px] sm:min-h-[360px] md:min-h-[500px]",children:(0,t.jsx)("div",{className:"absolute inset-0 flex items-center justify-center",children:h&&u?(0,t.jsx)("video",{src:u,className:"w-full h-full object-contain",controls:!0,controlsList:"nodownload",preload:"metadata",playsInline:!0}):x?c&&o.some(e=>"completed"===e.task_status&&e.video_url)?(0,t.jsx)(eo,{scenes:o,mode:"processing"}):(0,t.jsx)("div",{className:"w-full h-full flex items-center justify-center bg-gradient-to-br from-background to-muted",children:(0,t.jsxs)("div",{className:"text-center max-w-md px-4",children:["processing"===e.status?(0,t.jsx)(m.Loader2,{className:"w-16 h-16 text-interactive animate-spin mx-auto mb-4"}):(0,t.jsx)(O.Clock,{className:"w-16 h-16 text-warning mx-auto mb-4"}),(0,t.jsx)("h3",{className:"text-xl font-semibold text-foreground mb-2",children:"processing"===e.status?"Generating…":"In queue"}),(0,t.jsx)("p",{className:"text-muted-foreground text-sm",children:S("readyTime")})]})}):f||g?c?(0,t.jsx)(eo,{scenes:o,mode:"failed",errorMessage:e.error_message,refunded:b}):(0,t.jsx)("div",{className:"w-full h-full flex items-center justify-center bg-gradient-to-br from-background to-muted",children:(0,t.jsxs)("div",{className:"text-center max-w-md px-4",children:[(0,t.jsx)(V.XCircle,{className:"w-16 h-16 text-warning mx-auto mb-4"}),(0,t.jsx)("h3",{className:"text-xl font-semibold text-foreground mb-2",children:"Generation failed"}),e.error_message&&(0,t.jsx)("p",{className:"text-sm text-muted-foreground mb-3 break-words",children:e.error_message}),b&&(0,t.jsx)("div",{className:"mb-4",children:(0,t.jsxs)("span",{className:"inline-flex items-center gap-1.5 px-3 py-1 rounded-full bg-success/15 text-success border border-success/30 text-xs font-medium",children:[(0,t.jsx)(R.Check,{className:"w-3.5 h-3.5"}),e.estimated_cost_credits," credits refunded"]})}),eh&&a&&(0,t.jsxs)("button",{type:"button",onClick:()=>a(e.id),className:"inline-flex items-center gap-1.5 px-4 py-1.5 rounded-lg bg-interactive text-white text-sm font-medium hover:opacity-90",children:[(0,t.jsx)(I.RefreshCw,{className:"w-3.5 h-3.5"}),"Retry"]})]})}):null})}),(0,t.jsxs)("div",{className:"w-full md:w-72 flex-shrink-0 border-t md:border-t-0 md:border-l border-border bg-background flex flex-col",children:[(0,t.jsxs)("div",{className:"flex-1 overflow-y-auto p-4 space-y-3",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[!1,(0,t.jsx)(en,{status:e.status})]}),(0,t.jsx)("span",{className:"text-[11px] text-muted-foreground",children:new Date(e.created_at).toLocaleString()})]}),null!=e.estimated_cost_credits&&(0,t.jsxs)("div",{className:"flex items-center gap-2 flex-wrap text-[11px] text-muted-foreground",children:[(0,t.jsxs)("span",{children:["Cost: ",(0,t.jsxs)("span",{className:"font-medium text-foreground",children:[e.estimated_cost_credits," credits"]})]}),b&&(0,t.jsxs)("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded-full bg-success/15 text-success border border-success/30 font-medium",children:[(0,t.jsx)(R.Check,{className:"w-2.5 h-2.5"}),"Refunded"]})]}),em&&(0,t.jsxs)("div",{children:[(0,t.jsxs)("div",{className:"flex items-center justify-between gap-2 mb-1",children:[(0,t.jsx)("div",{className:"text-[11px] font-medium uppercase tracking-wide text-muted-foreground",children:"Prompt"}),(0,t.jsxs)("button",{type:"button",onClick:ex,"aria-label":"Copy prompt",className:"inline-flex items-center gap-1 text-[11px] text-muted-foreground hover:text-foreground transition-colors",children:[L?(0,t.jsx)(R.Check,{className:"w-3 h-3 text-success"}):(0,t.jsx)($.Copy,{className:"w-3 h-3"}),L?"Copied":"Copy"]})]}),(0,t.jsx)(es,{value:em,className:`text-xs text-foreground ${E?"":"max-h-28 overflow-hidden"}`}),(0,t.jsx)("button",{type:"button",onClick:()=>A(e=>!e),className:"text-[11px] text-interactive hover:underline mt-1",children:E?"Show less":"View full prompt"})]}),(0,t.jsx)(Z,{generation:e}),(0,t.jsxs)("div",{className:"grid grid-cols-2 gap-2 text-[11px]",children:[d?.resolved_duration&&(0,t.jsxs)("div",{className:"rounded-md bg-muted/60 p-2",children:[(0,t.jsx)("div",{className:"text-muted-foreground",children:"Duration"}),(0,t.jsxs)("div",{className:"text-foreground font-medium",children:[o.reduce((e,t)=>
2e+(t.resolved_duration??0),0),"s"]})]}),d?.resolved_aspect_ratio&&(0,t.jsxs)("div",{className:"rounded-md bg-muted/60 p-2",children:[(0,t.jsx)("div",{className:"text-muted-foreground",children:"Aspect"}),(0,t.jsx)("div",{className:"text-foreground font-medium",children:d.resolved_aspect_ratio})]}),d?.resolution&&(0,t.jsxs)("div",{className:"rounded-md bg-muted/60 p-2",children:[(0,t.jsx)("div",{className:"text-muted-foreground",children:"Resolution"}),(0,t.jsx)("div",{className:"text-foreground font-medium",children:d.resolution})]}),d?.model&&(0,t.jsxs)("div",{className:"rounded-md bg-muted/60 p-2",children:[(0,t.jsx)("div",{className:"text-muted-foreground",children:"Model"}),(0,t.jsxs)("div",{className:"text-foreground font-medium inline-flex items-center gap-1",children:[(0,t.jsx)(z.Wand2,{className:"w-3 h-3"}),(0,X.seedanceModelLabel)(d.model)]})]})]})]}),(0,t.jsx)("div",{className:"flex-shrink-0 p-3 border-t border-border bg-background space-y-2",children:(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[h&&(0,t.jsxs)("div",{className:"relative flex-1",children:[(0,t.jsxs)("button",{type:"button",onClick:ep,disabled:y,className:"relative overflow-hidden w-full inline-flex items-center justify-center gap-1.5 px-3 py-1.5 rounded-lg bg-interactive text-white text-xs font-medium hover:opacity-90 disabled:opacity-60 disabled:cursor-wait",children:[y?(0,t.jsx)(m.Loader2,{className:"w-3.5 h-3.5 animate-spin"}):(0,t.jsx)(F.Download,{className:"w-3.5 h-3.5"}),y?null!=N?`Downloading… ${Math.round(100*N)}%`:"Downloading…":"Download",(0,t.jsx)(_.ChevronDown,{className:"w-3 h-3 ml-auto opacity-60"}),y&&(0,t.jsx)(G.DownloadProgressBar,{fraction:N,className:"absolute inset-x-0 bottom-0 rounded-none"})]}),v&&(0,t.jsx)("div",{className:"absolute bottom-full left-0 mb-1 w-full bg-card border border-border rounded-lg shadow-lg py-1 z-20",children:(0,t.jsx)("button",{type:"button",onClick:ep,className:"w-full text-left px-3 py-1.5 text-xs text-foreground hover:bg-muted",children:"MP4 (default)"})})]}),h&&et&&(0,t.jsxs)("div",{className:"relative",children:[(0,t.jsx)("button",{type:"button",onClick:()=>J(!0),title:"Share","aria-label":"Share video",className:"inline-flex items-center justify-center gap-1 px-2 py-1.5 rounded-lg border border-border text-muted-foreground hover:text-foreground hover:bg-muted text-xs min-h-[44px] md:min-h-0",children:(0,t.jsx)(q.Share2,{className:"w-3.5 h-3.5"})}),(0,t.jsx)(el.SharePopover,{shareUrl:et,isOpen:K,onClose:()=>J(!1),billboard:ee?{assetId:ee,feature:"short-template"}:void 0,align:"right"})]}),l&&e.template_id&&(0,t.jsx)("button",{type:"button",onClick:()=>{let t=e.template_id?{template_id:e.template_id,user_image_asset_ids:e.user_image_asset_ids??[],user_video_asset_ids:e.user_video_asset_ids??[],user_audio_asset_ids:e.user_audio_asset_ids??[],user_content:e.user_text_prompt??"",user_model_choice:e.user_model_choice??null,user_resolution_choice:e.user_resolution_choice??null}:null;t&&l(t)},title:null===e.user_image_asset_ids&&null===e.user_video_asset_ids&&null===e.user_audio_asset_ids&&null===e.user_text_prompt&&null===e.user_model_choice&&null===e.user_resolution_choice?"Re-run with same template (original inputs not available)":"Re-run with same inputs",className:"inline-flex items-center justify-center gap-1 px-2 py-1.5 rounded-lg border border-border text-muted-foreground hover:text-foreground hover:bg-muted text-xs min-h-[44px] md:min-h-0","aria-label":"Re-run with same template",children:(0,t.jsx)(U.RotateCcw,{className:"w-3.5 h-3.5"})}),("failed"===e.status||"partial"===e.status)&&eh&&a&&(0,t.jsxs)("button",{type:"button",onClick:()=>a(e.id),className:"flex-1 inline-flex items-center justify-center gap-1.5 px-3 py-1.5 rounded-lg bg-interactive text-white text-xs font-medium hover:opacity-90",children:[(0,t.jsx)(I.RefreshCw,{className:"w-3.5 h-3.5"}),"Retry"]}),r&&!x&&(0,t.jsx)("button",{type:"button",onClick:()=>Q(!0),className:"inline-flex items-center justify-center gap-1 px-2 py-1.5 rounded-lg text-muted-foreground hover:text-destructive hover:bg-muted text-xs min-h-[44px] md:min-
2h-0","aria-label":"Delete generation",title:"Delete",children:(0,t.jsx)(P.Trash2,{className:"w-3.5 h-3.5"})})]})})]})]}),(0,t.jsx)(er.DownloadPassDialog,{open:T,onClose:()=>D(!1)}),(0,t.jsx)(ei.ConfirmationDialog,{isOpen:Y,onClose:()=>Q(!1),onConfirm:()=>{Q(!1),r?.(e.id)},title:"Delete this generation?",message:"This cannot be undone. The video file will be permanently removed.",confirmText:"Delete",confirmButtonVariant:"destructive",variant:"warning"})]})}let ec=[{value:"all",labelKey:"filterAll"},{value:"completed",labelKey:"filterCompleted"},{value:"failed",labelKey:"filterFailed"},{value:"processing",labelKey:"filterProcessing"}];function eu({items:e,onRetry:a,onDelete:r,onDeleteMany:l,onRerun:i,isLoading:n}){let o=(0,p.useTranslations)("shortTemplates"),[d,c]=(0,s.useState)("all"),[u,x]=(0,s.useState)(new Set),[h,f]=(0,s.useState)(!1),[g,b]=(0,s.useState)(!1),v=[...e].sort((e,t)=>new Date(t.created_at).getTime()-new Date(e.created_at).getTime()),j="all"===d?v:v.filter(e=>"processing"===d?"pending"===e.status||"processing"===e.status:e.status===d),y=v.filter(e=>"failed"===e.status),w=(e,t)=>{x(s=>{let a=new Set(s);return t?a.add(e):a.delete(e),a})};return n&&0===e.length?(0,t.jsx)("div",{className:"h-full flex items-center justify-center",children:(0,t.jsx)(m.Loader2,{className:"w-8 h-8 text-muted-foreground animate-spin"})}):0===e.length?(0,t.jsx)("div",{className:"h-full flex items-center justify-center",children:(0,t.jsxs)("div",{className:"text-center px-6",children:[(0,t.jsx)(L.History,{className:"w-12 h-12 text-muted-foreground mx-auto mb-3"}),(0,t.jsx)("h3",{className:"text-lg font-medium text-foreground mb-1",children:o("noGenerationsYet")||"No generations yet"}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:o("noGenerationsHint")||"Pick a template, fill the slots, and your generations will show up here."})]})}):(0,t.jsxs)("div",{className:"h-full overflow-y-auto flex flex-col",children:[(0,t.jsxs)("div",{className:"flex-shrink-0 px-4 pt-3 pb-2 flex items-center gap-2 flex-wrap border-b border-border",children:[ec.map(e=>(0,t.jsx)("button",{type:"button",onClick:()=>c(e.value),className:`px-3 py-1 rounded-full text-xs font-medium transition-colors min-h-[44px] md:min-h-0 ${d===e.value?"bg-foreground text-background":"text-muted-foreground hover:text-foreground hover:bg-muted"}`,children:o(e.labelKey)},e.value)),a&&y.length>=2&&(0,t.jsxs)("button",{type:"button",onClick:()=>b(!0),className:"ml-auto inline-flex items-center gap-1.5 px-3 py-1 rounded-full text-xs font-medium text-foreground border border-border hover:bg-muted min-h-[44px] md:min-h-0",children:[(0,t.jsx)(I.RefreshCw,{className:"w-3.5 h-3.5"}),o("retryAllFailed",{count:y.length})||`Retry all failed (${y.length})`]}),!1]}),(0,t.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:0===j.length?(0,t.jsx)("div",{className:"text-center text-sm text-muted-foreground py-8",children:o("noFilteredGenerations",{filter:o(ec.find(e=>e.value===d)?.labelKey??"filterAll").toLowerCase()})||`No ${d} generations.`}):(0,t.jsxs)("div",{style:{containerType:"inline-size",containerName:"genGrid"},children:[(0,t.jsx)("style",{children:`
3              .gen-grid { display: grid; gap: 1rem; grid-template-columns: 1fr; }
4              @container genGrid (min-width: 1100px) {
5                .gen-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
6              }
7            `}),(0,t.jsx)("div",{className:"gen-grid",children:j.map(e=>(0,t.jsx)(ed,{generation:e,onRetry:a,onDelete:r,onRerun:i,isSelected:u.has(e.id),onSelect:w},e.id))})]})}),!1,(0,t.jsx)(ei.ConfirmationDialog,{isOpen:g,onClose:()=>b(!1),onConfirm:()=>{y.forEach(e=>a?.(e.id)),b(!1)},title:o("retryFailedTitle")||"Retry failed generations?",message:o("retryFailedMessage",{count:y.length})||`Retry ${y.length} failed generations? This may consume credits.`,confirmText:o("retry")||"Retry",variant:"warning"})]})}var em=e.i(614997);function ex({templates:e,isLoadingTemplates:s,selectedTemplateId:a,onSelectTemplate:r,generations:l,isLoadingGenerations:i,onRetry:n,onDelete:o,onDeleteMany:d,onRerun:c,activeTab:u,onTabChange:m,templatesHeaderSlot:x,templatesFooterSlot:h}){let f=(0,p.useTranslations)("shortTemplates");return(0,t.jsxs)("div",{className:"h-full flex flex-col bg-background",children:[(0,t.jsxs)("div",{className:"flex-shrink-0 pl-14 pr-4 md:px-4 pt-4 pb-2 flex items-center justify-between gap-3 max-md:flex-wrap",children:[(0,t.jsx)("div",{className:"inline-flex rounded-lg bg-muted/80 dark:bg-card/80 p-1",children:[{key:"templates",label:"Templates"},{key:"history",label:"My Generations"}].map(e=>(0,t.jsx)("button",{onClick:()=>m(e.key),className:`px-4 py-1.5 text-sm font-medium rounded-md transition-all duration-200 cursor-pointer ${u===e.key?"bg-card text-foreground shadow-sm":"text-muted-foreground hover:text-foreground dark:hover:text-muted-foreground
7/50"}`,children:e.label},e.key))}),"templates"===u&&(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(em.TutorialVideoButton,{videoId:"AjOcJPFX3_I",title:"Short MVs",autoOpenStorageKey:"cremi:short-mv-tutorial-autoshown"}),(0,t.jsxs)("span",{className:"inline-flex items-center gap-2 rounded-md bg-brand-primary/[0.12] px-2.5 py-1 text-xs font-semibold text-brand-primary",children:[(0,t.jsxs)("span",{className:"relative flex h-2 w-2",children:[(0,t.jsx)("span",{className:"absolute inline-flex h-full w-full rounded-full bg-brand-primary opacity-75 motion-safe:animate-ping"}),(0,t.jsx)("span",{className:"relative inline-flex h-2 w-2 rounded-full bg-brand-primary"})]}),f("newTemplatesDaily")]})]})]}),(0,t.jsx)("div",{className:"flex-1 overflow-hidden",children:"templates"===u?(0,t.jsx)(A,{templates:e,isLoading:s,selectedTemplateId:a,onSelect:r,headerSlot:x,footerSlot:h}):(0,t.jsx)(eu,{items:l,isLoading:i,onRetry:n,onDelete:o,onDeleteMany:d,onRerun:c})})]})}var ep=e.i(235251);let eh=new Map;var ef=e.i(480152),eg=e.i(728231),eb=e.i(796603),ev=e.i(625959);function ej({selectedTemplate:e,onSelectTemplate:a,onClearTemplate:r,formComponent:l,templates:i,isLoadingTemplates:n,generations:o,isLoadingGenerations:c,isSubmitting:h,error:f,onSubmit:g,onRetry:b,onDelete:v,onDeleteMany:j,onRerun:y,activeTab:w,onTabChange:N,banner:_,locked:k=!1,templatesHeaderSlot:C,templatesFooterSlot:S}){let T=(0,p.useTranslations)("videoGenerator"),D=(0,p.useTranslations)("shortTemplates.generate"),E=(0,u.useIsMobile)(),[A,L]=(0,s.useState)(null),[P,I]=(0,s.use
7State)(!1),[M,R]=(0,s.useState)(!1),[O,$]=(0,s.useState)(!1),[F,U]=(0,s.useState)(!1),[q,z]=(0,s.useState)(0),{estimatedCredits:V,breakdown:B,isLoading:G}=function(e){let[t,a]=(0,s.useState)({estimatedCredits:null,breakdown:null,isLoading:!1,error:null}),r=(0,s.useRef)(null),l=(0,s.useRef)(null),i=(0,s.useCallback)(async e=>{let t,s,r=(t=(e.user_video_asset_ids??[]).join(","),s=(e.user_audio_asset_ids??[]).join(","),`${e.template_id}::${e.duration_choice??""}::${e.aspect_ratio_choice??""}::${e.model_choice??""}::${e.resolution_choice??""}::${t}::${s}`),i=eh.get(r);if(i&&Date.now()-i.fetchedAt<5e3)return void a({estimatedCredits:i.estimatedCredits,breakdown:i.breakdown,isLoading:!1,error:null});l.current?.abort(),l.current=new AbortController,a(e=>({...e,isLoading:!0,error:null}));try{let t=await (0,ep.estimateShortTemplateCost)({template_id:e.template_id,duration_choice:e.duration_choice??void 0,aspect_ratio_choice:e.aspect_ratio_choice??void 0,model_choice:e.model_choice??void 0,resolution_choice:e.resolution_choice??void 0,user_video_asset_ids:e.user_video_asset_ids??void 0,user_audio_asset_ids:e.user_audio_asset_ids??void 0}),s={estimatedCredits:t.data.estimated_credits,breakdown:t.data.breakdown,fetchedAt:Date.now()};eh.set(r,s),a({estimatedCredits:s.estimatedCredits,breakdown:s.breakdown,isLoading:!1,error:null})}catch(e){if(e instanceof Error&&"AbortError"===e.name)return;a(t=>({...t,isLoading:!1,error:e instanceof Error?e.message:"Cost estimate failed"}))}},[]);return(0,s.useEffect)(()=>e?(r.current&&clearTimeout(r.current),r.current=setTimeout(()=>void i(e),200),()=>{r.current&&clearTimeout(r.current)}):void a({estimatedCredits:null,breakdown:null,isLoading:!1,error:null}),[e?.template_id,e?.duration_choice,e?.aspect_ratio_choice,e?.model_choice,e?.resolution_choice,e?.user_video_asset_ids?.join(","),e?.user_audio_asset_ids?.join(","),i]),t}(e&&A?{template_id:e.id,duration_choice:A.duration_choice??null,aspect_ratio_choice:A.aspect_ratio_choice??null,model_choice:A.model_choice??null,resolution_choice:A.resolution_choice??null,user_video_asset_ids:A.user_video_asset_ids??null,user_audio_asset_ids:A.user_audio_asset_ids??null}:null),H=B?.credits_before_discount??null,X=B?.credits_after_discount??V,{credits:W}=(0,ef.useCredits)(),K=W?.total_credits??W?.credits??W?.credits_remaining??0,Z=W?.plan??"free",J=null!=V&&K<V,Y=l&&(0,s.isValidElement)(l)?(0,s.cloneElement)(l,{...l.props||{},onClearTemplate:r,openReplaceSignal:q,onFormDataChange:e=>{L(e);let t=l.props;t?.onFormDataChange&&t.onFormDataChange(e)}}):null,Q=!e||!A?.isValid||h,ee=(A?.untouchedStoryboardLabels?.length??0)>0||A?.isPristine===!0,et=()=>{g()},es=!!e&&"templates"===w,ea=!!e&&(!E||es),er=e?A?.missingSlotLabels&&A.missingSlotLabels.length>0?`Fill required: ${A.missingSlotLabels.join(", ")}`:A?.isValid?null:"Fill in all required fields":"Select a template first";return(0,t.jsxs)(d.AppLayout,{children:[(0,t.jsxs)("div",{className:"h-full flex flex-col bg-background",children:[_&&(0,t.jsx)("div",{className:"flex-shrink-0 px-4 pt-2",children:_}),(0,t.jsxs)("div",{className:"flex-1 min-h-0 flex overflow-hidden md:flex-row flex-col",children:[ea&&(0,t.jsxs)("div",{className:"md:w-[42%] lg:w-[38%] w-full max-md:flex-1 max-md:min-h-0 flex flex-col bg-background/80 dark:bg-background/80 backdrop-blur-sm border-r border-border/50 dark:border-border/50 overflow-hidden",children:[(0,t.jsx)("div",{className:"flex-shrink-0 p-4 pb-3 pl-14 sm:p-6 sm:pb-4 sm:pl-6",children:(0,t.jsx)("div",{className:"flex items-start justify-between gap-3",children:(0,t.jsxs)("div",{className:"min-w-0",children:[(0,t.jsx)("h1",{className:"text-xl sm:text-2xl font-bold flex items-baseline gap-1",children:(0,t.jsx)("span",{className:"text-gradient-hero",children:"Short MVs"})}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground mt-1",children:e.title})]})})}),(0,t.jsx)("div",{className:"flex-1 overflow-y-auto px-4 sm:px-6 pb-4",children:Y}),(0,t.jsxs)("div",{className:"flex-shrink-0 px-4 sm:px-6 pt-3 border-t border-border/50 dark:border-border/50 bg-background/80 dark:bg-background/80",style:{paddingBottom:"max(env(safe-area-inset-bottom), 0.75rem)"},children:[f&&(0,t.jsx)("div",{className:"mb-2 p-2 bg-destructive/10 border border-destructive/30 rounded-lg text-sm text-destructive",children:f}),!Q&&(A?.untouchedStoryboardLabels?.length??0)>0&&(0,t.jsxs)("p",{className:"mb-2 flex items-start gap-1.5 text-xs text-caution",children:[(0,t.jsx)(x.Sparkles,{className:"w-3.5 h-3.5 mt-0.5 flex-shrink-0"}),(0,t.jsx)("span",{children:D("personalizeHint")})]}),!k&&(0,t.jsxs)(eg.Tooltip,{children:[(0,t.jsx)(eg.TooltipTrigger,{asChild:!0,children:(0,t.jsx)("span",{className:"w-full block",children:(0,t.jsx)("button",{type:"button",onClick:()=>{J?I(!0):ee?U(!0):et()},disabled:Q,className:`w-full px-8 py-3 bg-gradient-hero hover:opacity-90 text-white font-semibold rounded-xl text-sm shadow-lg hover:shadow-xl transition-all duration-300 disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-3 ${!Q?"cursor-pointer":""}`,children:h?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{className:"w-4 h-4 border-2 border-white border-t-transparent roun
7ded-full animate-spin"}),(0,t.jsx)("span",{className:"uppercase",children:"Generating"})]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(x.Sparkles,{className:"w-4 h-4"}),(0,t.jsx)("span",{className:"uppercase",children:"Generate"}),G?(0,t.jsx)(m.Loader2,{className:"w-3.5 h-3.5 animate-spin opacity-70 ml-1"}):null!=V?(0,t.jsxs)("span",{className:"text-xs font-normal opacity-90 ml-1 normal-case flex items-center gap-1",children:[null!=H&&null!=X&&H>X&&(0,t.jsxs)("span",{className:"line-through opacity-60",children:["~",H]}),"· ~",X??V," credits"]}):A&&A.missingRequiredSlots>0?(0,t.jsxs)("span",{className:"text-xs font-normal opacity-90 ml-1 normal-case",children:["(",A.missingRequiredSlots," slot",1===A.missingRequiredSlots?"":"s"," missing)"]}):null]})})})}),er&&(0,t.jsx)(eg.TooltipContent,{side:"top",children:er})]})]})]}),(!E||!es)&&(0,t.jsx)("div",{className:"flex-1 overflow-hidden",children:(0,t.jsx)(ex,{templates:i,isLoadingTemplates:n,selectedTemplateId:e?.id??null,onSelectTemplate:a,generations:o,isLoadingGenerations:c,onRetry:b,onDelete:v,onDeleteMany:j,onRerun:y,activeTab:w,onTabChange:N,templatesHeaderSlot:C,templatesFooterSlot:S})})]})]}),(0,t.jsx)(ei.ConfirmationDialog,{isOpen:F,onClose:()=>U(!1),onConfirm:()=>{U(!1),z(e=>e+1)},onCancel:()=>{U(!1),et()}
7,title:D("personalizeTitle"),message:D("personalizeBody"),confirmText:D("personalizeReplace"),cancelText:D("personalizeAsIs"),variant:"warning"}),(0,t.jsx)(ei.ConfirmationDialog,{isOpen:M,onClose:()=>R(!1),onConfirm:()=>{O&&window.localStorage.setItem("cremi:music-accuracy-confirm-dismissed","true"),R(!1),g()},title:T("musicAccuracyConfirmTitle"),message:(0,t.jsxs)("div",{className:"space-y-4",children:[(0,t.jsx)("p",{children:T("musicAccuracyDisclaimer")}),(0,t.jsxs)("label",{className:"flex items-center justify-center gap-2 cursor-pointer text-sm text-foreground",children:[(0,t.jsx)(ev.Checkbox,{checked:O,onCheckedChange:e=>$(!0===e)}),T("musicAccuracyDontShowAgain")]})]}),confirmText:T("musicAccuracyConfirmProceed"),cancelText:T("cancel"),variant:"warning"}),(0,t.jsx)(eb.CreditActionModal,{isOpen:P,onClose:()=>I(!1),currentCredits:K,requiredCredits:V??0,userPlan:Z})]})}var ey=e.i(722851),ew=e.i(403618),eN=e.i(754219),e_=e.i(62870),ek=e.i(184762),eC=e.i(23750),eS=e.i(10708),eT=e.i(167881),eD=e.i(193499);let eE=["any","lofi","pop","edm","hiphop","rock","ballad","cinematic","rnb","kpop","other"],eA=["any","male","female","other"];function eL(e){let t=e.trim();return t&&!/^https?:\/\//i.test(t)?`https://${t}`:t}function eP({open:e,onOpenChange:a}){let l=(0,p.useTranslations)("shortTemplates.requestTemplate"),{locale:i}=(0,p.useLanguage)(),{user:n}=(0,r.useAuth)(),{isFreeUser:o,loading:d}=(0,ea.useUserPlan)(),c=!d&&o,[u,m]=(0,s.useState)("any"),[h,f]=(0,s.useState)("any"),[g,b]=(0,s.useState)(""),[v,j]=(0,s.useState)([""]),[y,w]=(0,s.useState)(""),[N,_]=(0,s.useState)(!1),[k,S]=(0,s.useState)(!1),T=(0,s.useRef)(!1);(0,s.useEffect)(()=>{e&&!T.current?(T.current=!0,m("any"),f("any"),j([""]),S(!1),w(n?.email??"")):e||(T.current=!1)},[e,n]);let D=async()=>{if(!g.trim())return void eN.toast.error(l("descriptionRequired"));let e=v.map(eL).filter(Boolean);if(0===e.length)return void eN.toast.error(l("referenceRequired"));_(!0);try{if(!(await (0,eD.fetchWithAuth)("/api/template-requests",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({genre:u,mainCharacter:h,description:g.trim(),referenceUrls:e,email:y.trim()||void 0,locale:i,pageUrl:window.location.href,userAgent:"u">typeof navigator?navigator.userAgent:void 0})})).ok)throw Error("Request failed");b(""),j([""]),S(!0)}catch{eN.toast.error(l("errorTitle"),{description:l("errorDescription")})}finally{_(!1)}};return(0,t.jsx)(C.Dialog,{open:e,onOpenChange:a,children:(0,t.jsx)(C.DialogContent,{className:"notranslate sm:max-w-lg",translate:"no",children:c?(0,t.jsxs)("div",{className:"flex flex-col items-center gap-5 px-2 py-4 text-center",children:[(0,t.jsxs)("div",{className:"relative mt-2",children:[(0,t.jsx)("div",{"aria-hidden":!0,className:"absolute -inset-3 rounded-full bg-gradient-hero opacity-40 blur-2xl"}),(0,t.jsx)("div",{className:"relative flex h-16 w-16 items-center justify-center rounded-2xl bg-gradient-hero shadow-brand",children:(0,t.jsx)(x.Sparkles,{className:"h-7 w-7 text-white"})})]}),(0,t.jsxs)(C.DialogHeader,{className:"items-center space-y-2",children:[(0,t.jsx)(C.DialogTitle,{className:"text-center text-xl",children:l("upgradeTitle")}),(0,t.jsx)(C.DialogDescription,{className:"max-w-sm text-center leading-relaxed",children:l("upgradeDescription")})]}),(0,t.jsxs)("div",{className:"flex w-full max-w-sm flex-col gap-2",children:[(0,t.jsxs)(ey.default,{href:"/pricing",target:"_blank",rel:"noopener noreferrer",className:"inline-flex w-full items-center justify-center gap-2 rounded-xl bg-gradient-hero px-4 py-2.5 text-sm font-semibold text-white shadow-brand transition-opacity hover:opacity-90",children:[(0,t.jsx)(x.Sparkles,{className:"h-4 w-4"}),l("upgradeCta")]}),(0,t.jsx)(eT.Button,{variant:"ghost",onClick:()=>a(!1),className:"w-full text-muted-foreground hover:text-foreground",children:l("upgradeDismiss")})]})]}):k?(0,t.jsxs)("div",{className:"flex flex-col items-center gap-5 px-2 py-4 text-center",children:[(0,t.jsxs)("div",{className:"relative mt-2",children:[(0,t.jsx)("div",{"aria-hidden":!0,className:"absolute -inset-3 rounded-full bg-gradient-hero opacity-40 blur-2xl"}),(0,t.jsx)("div",{className:"relative flex h-16 w-16 items-center justify-center rounded-2xl bg-gradient-hero shadow-brand",children:(0,t.jsx)(x.Sparkles,{className:"h-7 w-7 text-white"})})]}),(0,t.jsxs)(C.DialogHeader,{className:"items-center space-y-2",children:[(0,t.jsx)(C.DialogTitle,{className:"text-center text-xl",children:l("successTitle")}),(0,t.jsx)(C.DialogDescription,{className:"max-w-sm text-center leading-relaxed",children:l("successDescription")})]}),(0,t.jsx)(eT.Button,{onClick:()=>a(!1),className:"w-full max-w-sm rounded-xl bg-gradient-hero py-2.5 font-semibold text-white shadow-brand hover:opacity-90",children:l("successCta")})]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)(C.DialogHeader,{children:[(0,t.jsx)(C.DialogTitle,{children:l("title")}),(0,t.jsx)(C.DialogDescription,{children:l("description")})]}),(0,t.jsxs)("div",{className:"space-y-4 py-2",children:[(0,t.jsxs)("div",{className:"grid grid-cols-1 gap-4 sm:grid-cols-2",children:[(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(eS.Label,{htmlFor:"request-genre",children:l("genreLabel")}),(0,t.jsxs)(e_.Select,{value:u,onValueChange:m,children:[(0,t.jsx)(e_.SelectTrigger,{id:"request-genre",children:(0,t.jsx)(e_.SelectValue,{})}),(0,t.jsx)(e_.SelectContent,{children:eE.map(e=>(0,t.jsx)(e_.SelectItem,{value:e,children:l(`genreOptions.${e}`)},e))})]})]}),(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(eS.Label,{htmlFor:"request-character",children:l("characterLabel")}),(0,t.jsxs)(e_.Select,{value:h,onValueChange:f,children:[(0,t.jsx)(e_.SelectTrigger,{id:"request-character",children:(0,t.jsx)(e_.SelectValue,{})}),(0,t.jsx)(e_.SelectContent,{children:eA.map(e=>(0,t.jsx)(e_.SelectItem,{value:e,children:l(`characterOptions.${e}`)},e))})]})]})]}),(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(eS.Label,{htmlFor:"request-description",children:l("descriptionLabel")}),(0,t.jsx)(ek.Textarea,{id:"request-description",value:g,onChange:e=>b(e.target.value),placeholder:l("descriptionPlaceholder"),rows:5,maxLength:1e4})]}),(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(eS.Label,{htmlFor:"request-reference-0",children:l("referenceLabel")}),v.map((e,s)=>(0,t.jsx)(eC.Input,{id:`request-reference-${s}
7`,type:"url",required:0===s,value:e,onChange:e=>{var t;return t=e.target.value,void j(e=>e.map((e,a)=>a===s?t:e))},placeholder:0===s?l("referencePlaceholder"):l("extraReferencePlaceholder"),"aria-label":0===s?l("referenceLabel"):l("extraReferenceLabel")},s)),v.length<3&&(0,t.jsxs)("button",{type:"button",onClick:()=>j(e=>[...e,""]),className:"inline-flex items-center gap-1 text-xs font-medium text-brand-primary hover:underline",children:[(0,t.jsx)(ew.Plus,{className:"h-3.5 w-3.5"}),l("addReferenceLink")]})]}),(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(eS.Label,{htmlFor:"request-email",children:l("emailLabel")}),(0,t.jsx)(eC.Input,{id:"request-email",type:"email",value:y,onChange:e=>w(e.target.value),placeholder:l("emailPlaceholder")})]})]}),(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:l("submitNote")}),(0,t.jsxs)(C.DialogFooter,{children:[(0,t.jsx)(eT.Button,{variant:"outline",onClick:()=>a(!1),disabled:N,children:l("cancel")}),(0,t.jsx)(eT.Button,{onClick:D,disabled:N||d,children:N?l("submitting"):l("submit")})]})]})})})}var eI=e.i(693095),eM=e.i(990831),eR=e.i(520433);function eO({onClick:e,locked:s=!1}){let a=(0,p.useTranslations)("shortTemplates.requestTemplate");return(0,t.jsxs)("button",{type:"button",onClick:e,className:"inline-flex items-center gap-1.5 rounded-full border border-border bg-background px-3 py-1.5 text-xs font-medium text-foreground transition-colors hover:bg-muted",children:[s?(0,t.jsx)(eR.Lock,{className:"h-3.5 w-3.5 text-muted-foreground"}):(0,t.jsx)(x.Sparkles,{className:"h-3.5 w-3.5 text-brand-primary"}),a("cta")]})}function e$({onClick:e,locked:s=!1}){let a=(0,p.useTranslations)("shortTemplates.requestTemplate");return(0,t.jsxs)("div",{className:"flex flex-col items-center gap-2 rounded-2xl border border-dashed border-border bg-muted/30 px-4 py-6 text-center",children:[(0,t.jsx)("p",{className:"text-sm font-medium text-foreground",children:a("promptTitle")}),(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:a("promptSubtitle")}),(0,t.jsxs)("button",{type:"button",onClick:e,className:"mt-1 inline-flex items-center gap-2 rounded-xl bg-gradient-hero px-5 py-2 text-sm font-semibold text-white shadow-brand transition-opacity hover:opacity-90",children:[s?(0,t.jsx)(eR.Lock,{className:"h-4 w-4"}):(0,t.jsx)(x.Sparkles,{className:"h-4 w-4"}),a("cta")]})]})}let eF="dreamina-seedance-2-0-fast-260128";function eU(e){return!!e.assetId&&e.assetId!==e.defaultAssetId}var eq=e.i(865792),ez=e.i(600056);let eV=(0,e.i(710449).default)("user-plus",[["path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2",key:"1yyitq"}],["circle",{cx:"9",cy:"7",r:"4",key:"nufk8"}],["line",{x1:"19",x2:"19",y1:"8",y2:"14",key:"1bvyxn"}],["line",{x1:"22",x2:"16",y1:"11",y2:"11",key:"1shjgl"}]]);var eB=e.i(327210),eG=e.i(80236),eH=e.i(118357),eX=e.i(592093),eW=e.i(968247),eK=e.i(574974),eZ=e.i(368043),eJ=e.i(769303),eY=e.i(57370),eQ=e.i(192207);async function e0(e,t,s){if(!e)throw Error("file_id is required");if(t<0||s<=t)throw Error("Invalid time range: start_time must be >= 0 and end_time must be > start_time");try{let a,r=await (0,eD.fetchWithAuth)("/api/video-generator/cut-video",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({file_id:e,start_time:t,end_time:s})});if(!r.ok){let e=await r.json().catch(()=>({})),t=e.error||e.msg||`Video cutting failed: ${r.status} ${r.statusText}`;throw Error(t)}let l=await r.json();if(!l.success)throw Error(l.error||l.msg||l.message||"Video cutting failed");if(Array.isArray(l.data)&&l.data.length>0){let e=l.data[0];a={file_id:e.id||e.file_id,public_url:e.public_url,duration:e.duration||e.metadata?.video_segment_end-e.metadata?.video_segment_start}}else if(l.data&&"object"==typeof l.data)a=l.data;else throw Error("Invalid response: missing cut video data");if(!a||!a.file_id)throw Error("Invalid response: missing cut video file_id");return{success:!0,data:a,error:l.error,msg:l.msg||l.message}}catch(e){if(e instanceof Error)throw e;throw Error("Video cutting failed: Unknown error")}}var e1=e.i(737178);function e5({isOpen:e,onClose:a,videoUrl:r,videoFileId:l,durationLimitMax:i,onSegmentSelected:n}
7){let[o,d]=(0,s.useState)(null),[c,u]=(0,s.useState)(0),[x,p]=(0,s.useState)(!1),[h,f]=(0,s.useState)(null);(0,s.useEffect)(()=>{if(!e)return;u(0),f(null),p(!1),d(null);let t=!1;return(0,eZ.getMediaDurationFromUrl)(r,"video").then(e=>{t||d(Math.round(1e3*e))}).catch(()=>{t||f("Could not read the video duration. Please try another file.")}),()=>{t=!0}},[e,r]);let g=o?Math.min(1e3*i,o):1e3*i,b=(0,s.useCallback)(async()=>{if(!o)return;let e=c/1e3,t=Math.min(o/1e3,e+g/1e3);p(!0),f(null);try{let s=await e0(l,e,t);if(s.success&&s.data)n(s.data.file_id,s.data.public_url);else throw Error(s.error||s.msg||"Failed to cut video")}catch(e){f(e instanceof Error?e.message:"Failed to cut video. Please try again.")}finally{p(!1)}},[o,c,g,l,n]),v=(0,s.useCallback)(()=>{x||a()},[x,a]);return(0,t.jsx)(C.Dialog,{open:e,onOpenChange:v,children:(0,t.jsxs)(C.DialogContent,{className:"max-w-2xl w-[calc(100vw-1.5rem)] sm:w-full max-h-[90vh] overflow-y-auto max-sm:p-4",children:[(0,t.jsxs)(C.DialogHeader,{children:[(0,t.jsxs)(C.DialogTitle,{children:["Trim video to ",i,"s"]}),(0,t.jsxs)(C.DialogDescription,{children:["This video is longer than ",i,"s. Pick the ",i,"s segment to use as the reference."]})]}),(0,t.jsxs)("div",{className:"space-y-4 py-4",children:[h&&(0,t.jsxs)("div",{className:"flex items-center gap-2 p-3 bg-destructive/10 border border-destructive/20 rounded-lg text-destructive",children:[(0,t.jsx)(e1.AlertCircle,{className:"w-4 h-4 flex-shrink-0"}),(0,t.jsx)("span",{className:"text-sm",children:h})]}),o?(0,t.jsx)(eQ.VideoTrimmer,{videoUrl:r,videoDurationMs:o,slotDurationMs:g,trimStartMs:c,onTrimStartChange:u}):h?null:(0,t.jsxs)("div",{className:"flex items-center justify-center py-10 text-muted-foreground",children:[(0,t.jsx)(m.Loader2,{className:"w-5 h-5 animate-spin mr-2"})," Loading video…"]})]}),(0,t.jsxs)(C.DialogFooter,{children:[(0,t.jsx)(eT.Button,{type:"button",variant:"outline",onClick:v,disabled:x,children:"Cancel"}),(0,t.jsx)(eT.Button,{type:"button",onClick:b,disabled:!o||x,className:"bg-foreground text-background hover:bg-foreground
7/90",children:x?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(m.Loader2,{className:"w-4 h-4 mr-2 animate-spin"}),"Cutting…"]}):"Confirm"})]})]})})}let e2=[".mp3",".wav"];function e3(e,t){let s=(e??"").toLowerCase();if(e2.some(e=>s.endsWith(e)))return!0;let a=(t??"").toLowerCase();return"audio/mpeg"===a||"audio/wav"===a||"audio/x-wav"===a}let e4=[".mp4",".mov"];function e6(e,t){let s=(e??"").toLowerCase();if(e4.some(e=>s.endsWith(e)))return!0;let a=(t??"").toLowerCase();return"video/mp4"===a||"video/quicktime"===a}let e9={image:"image/*,.jpg,.jpeg,.png,.webp",video:".mp4,.mov,video/mp4,video/quicktime",audio:".mp3,.wav,audio/mpeg,audio/wav,audio/x-wav"},e8={image:"aspect-square",video:"aspect-square",audio:"aspect-square"};function e7({kind:e,label:a,required:r,isEmpty:l=!1,value:i,onChange:n,error:o,loading:d=!1,isStoryboard:c=!1,defaultAssetId:u,onReplaceCharacter:x,onResetDefault:h,onView:f,cumulativeRemainingSec:j,onDurationResolved:y}){let w=(0,p.useTranslations)("shortTemplates.form"),N=(0,s.useRef)(null),[_,C]=(0,s.useState)(!1),[S,T]=(0,s.useState)(!1),[D,E]=(0,s.useState)(!1),[A,L]=(0,s.useState)(null),[P,I]=(0,s.use
7State)(!1),[M,R]=(0,s.useState)(null),[O,$]=(0,s.useState)(null),F=(0,s.useRef)(y);F.current=y,(0,s.useEffect)(()=>{if("audio"!==e&&"video"!==e)return;let t=F.current;if(!t)return;let s=i?.public_url||i?.url||"";if(!s)return void t(null);let a=!1;return("audio"===e?(0,eZ.resolveAudioDuration)({url:s,metadataDuration:i?.metadata?.duration??null,getAuthHeaders:eJ.getAuthHeaders}):(0,eZ.getMediaDurationResilient)(s,e)).then(e=>{a||t(e)}),()=>{a=!0}},[i,e]);let q=(0,s.useRef)(null),[z,V]=(0,s.useState)(!1),B=(0,s.useCallback)(()=>{let e=q.current;e&&(e.paused?e.play().catch(()=>{}):e.pause())},[]),G=(0,s.useCallback)(async(t,s)=>{if("audio"!==e&&"video"!==e)return void n(t);let a=t.public_url||t.url||"",r=j??("audio"===e?X.SEEDANCE_MAX_AUDIO_CUMULATIVE_S:X.SEEDANCE_MAX_VIDEO_CUMULATIVE_S),l="audio"===e?await (0,eZ.resolveAudioDuration)({url:a,knownDuration:s,metadataDuration:t.metadata?.duration??null,getAuthHeaders:eJ.getAuthHeaders}):"number"==typeof s&&Number.isFinite(s)&&s>0?s:await (0,eZ.getMediaDurationResilient)(a,e);if(null==l)return void L(w("errorDurationUnknown",{kind:e}));if(l>r+X.SEEDANCE_CUMULATIVE_TOLERANCE_S){if(r<=0)return void L(w("errorNoBudget",{kind:e}));let s={id:t.id,url:a,fileName:t.file_name,limitSec:r};return void("audio"===e?R(s):$(s))}F.current?.(l),n(t)},[e,n,j,w]),H=(0,s.useCallback)((e,t)=>{let s=M?.fileName||"cut_audio.mp3",a=new Date().toISOString();n({id:e,user_id:"",type:"audio",file_name:s,file_path:"",public_url:t,url:t,created_at:a,updated_at:a}),R(null)},[n,M]),W=(0,s.useCallback)((e,t)=>{let s=O?.fileName||"cut_video.mp4",a=new Date().toISOString();n({id:e,user_id:"",type:"video",file_name:s,file_path:"",public_url:t,url:t,created_at:a,updated_at:a}),$(null)},[n,O]),K=(0,s.useCallback)(async t=>{N.current&&(N.current.value=""),L(null);let s="video"===e?eK.UPLOAD_LIMITS.videoMaxSize:"audio"===e?eK.UPLOAD_LIMITS.audioMaxSize??0xf00000:eK.UPLOAD_LIMITS.maxFileSize;if(t.size>s)return void L(`File exceeds size cap (${Math.round(s/1048576)} MB).`);if("audio"===e&&!e3(t.name,t.type))return void L("Only MP3 or WAV audio is supported.");if("video"===e&&!e6(t.name,t.type))return void L("Only MP4 or MOV video is supported.");let a=null;if("audio"===e||"video"===e){let s=URL.createObjectURL(t);try{a=await (0,eZ.getMediaDurationResilient)(s,e)}finally{URL.revokeObjectURL(s)}}C(!0);try{let e=(await eH.AssetService.uploadFiles([t]))[0];e?.id?await G(e,a):L("Upload failed.")}catch(e){L(e instanceof Error?e.message:"Upload failed.")}finally{C(!1)}},[e,G]),Z=(0,s.useCallback)(async t=>{E(!1),L(null);let s=(0,eW.toLipsyncAsset)(t);if("audio"===e&&!e3(s.file_name,s.mime_type))return void L("Only MP3 or WAV audio is supported.");if("video"===e&&!e6(s.file_name,s.mime_type))return void L("Only MP4 or MOV video is supported.");T(!0);try{await G(s)}finally{T(!1)}},[e,G]),J=o??A,Y=P?"border-primary bg-primary/5":J?"border-destructive bg-destructive/5":r&&l?"border-caution bg-caution/5":"border-border bg-muted/50 dark:bg-card/50 hover:border-interactive/50 hover:bg-interactive/5";return(0,t.jsxs)("div",{className:c?"relative col-span-2":void 0,children:[(0,t.jsx)("div",{onDragEnter:e=>{e.preventDefault(),e.stopPropagation(),i||I(!0)},onDragOver:e=>{e.preventDefault(),e.stopPropagation()},onDragLeave:e=>{e.preventDefault(),e.stopPropagation(),I(!1)},onDrop:e=>{e.preventDefault(),e.stopPropagation(),I(!1);let t=e.dataTransfer.files?.[0];t&&K(t)},onClick:()=>{_||d||S||!c&&(i||N.current?.click())},className:`relative rounded-xl border-2 border-dashed transition-colors flex items-center justify-center ${e8[e]} ${i?"border-interactive/50 bg-background/50 p-0 overflow-hidden":`${Y} cursor-pointer`}`,children:_||d||S?(0,t.jsxs)("div",{className:"flex flex-col items-center gap-1",children:[(0,t.jsx)(m.Loader2,{className:"w-5 h-5 text-interactive animate-spin"}),(0,t.jsx)("span",{className:"text-[10px] text-muted-foreground",children:_?"Uploading…":"Loading…"})]}):i?(0,t.jsxs)(t.Fragment,{children:["image"===e?f?(0,t.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),f()},className:"absolute inset-0 cursor-zoom-in","aria-label":`View ${a} full size`,children:(0,t.jsx)(g.default,{src:i.public_url||i.url||"",alt:a,fill:!0,className:"object-cover rounded-xl",sizes:"200px"})}):(0,t.jsx)(g.default,{src:i.public_url||i.url||"",alt:a,fill:!0,className:"object-cover rounded-xl",sizes:"200px"}):"video"===e?(0,t.jsx)("video",{src:i.public_url||i.url||"",className:"w-full h-full object-cover rounded-xl",autoPlay:!0,loop:!0,muted:!0,playsInl
7ine:!0}):(0,t.jsxs)("div",{className:"flex flex-col items-center justify-center gap-2 text-foreground",children:[(0,t.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),B()},className:"w-10 h-10 rounded-full bg-interactive/10 hover:bg-interactive/20 flex items-center justify-center text-interactive transition-colors","aria-label":z?`Pause ${a}`:`Play ${a}`,children:z?(0,t.jsx)(b.Pause,{className:"w-5 h-5"}):(0,t.jsx)(v.Play,{className:"w-5 h-5 ml-0.5"})}),(0,t.jsx)("span",{className:"text-xs font-medium truncate max-w-[120px]",title:i.file_name,children:a}),(0,t.jsx)("audio",{ref:q,src:i.public_url||i.url||"",className:"hidden",preload:"none",onPlay:()=>V(!0),onPause:()=>V(!1),onEnded:()=>V(!1)})]}),(0,t.jsx)("button",{type:"button",onClick:e=>{e.stopPropagation(),n(null)},className:"absolute top-1.5 right-1.5 w-9 h-9 md:w-6 md:h-6 bg-black/60 hover:bg-destructive text-white rounded-full flex items-center justify-center z-10","aria-label":`Remove ${a}`,children:(0,t.jsx)(eG.X,{className:"w-3.5 h-3.5"})}),c&&i.id===u&&(0,t.jsx)("span",{className:"absolute top-1.5 left-1.5 rounded-full bg-black/65 px-1.5 py-0.5 text-[9px] font-semibold uppercase tracking-wide text-white z-10",children:w("sampleBadge")})]}):P?(0,t.jsxs)("div",{className:"flex flex-col items-center gap-2 px-3 pointer-events-none",children:[(0,t.jsx)("div",{className:"w-10 h-10 rounded-full bg-primary/15 flex items-center justify-center",children:(0,t.jsx)(ew.Plus,{className:"w-5 h-5 text-primary"})}),(0,t.jsx)("p",{className:"text-sm font-medium text-primary",children:"Drop here"})]}):c?(0,t.jsxs)("div",{className:"flex flex-col items-center gap-1.5 px-2 text-center w-full",children:[(0,t.jsxs)("button",{type:"button",onClick:e=>{e.stopPropagation(),x?.()},title:w("replaceCharacterTooltip"),"aria-label":w("replaceCharacterAria",{label:a}),className:"w-full inline-flex items-center justify-center gap-1.5 rounded-md bg-interactive px-2 py-1.5 text-xs font-semibold text-white transition-colors hover:bg-interactive/90",children:[(0,t.jsx)(eV,{className:"h-3.5 w-3.5"}),w("replaceCharacter")]}),(0,t.jsxs)("div",{className:"inline-flex items-center gap-3",children:[(0,t.jsxs)("button",{type:"button",onClick:e=>{e.stopPropagation(),E(!0)},className:"inline-flex items-center gap-1 text-[11px] text-interactive hover:opacity-70 font-medium",children:[(0,t.jsx)(ez.FolderOpen,{className:"w-3 h-3"}),w("menuLibrary")]}),(0,t.jsxs)("button",{type:"button",onClick:e=>{e.stopPropagation(),N.current?.click()},className:"inline-flex items-center gap-1 text-[11px] text-interactive hover:opacity-70 font-medium",children:[(0,t.jsx)(ew.Plus,{className:"w-3 h-3"}),w("menuUpload")]})]}),u&&(0,t.jsxs)("button",{type:"button",onClick:e=>{e.stopPropagation(),h?.()},className:"inline-flex items-center gap-1 text-[11px] text-muted-foreground hover:text-foreground font-medium",children:[(0,t.jsx)(U.RotateCcw,{className:"w-3 h-3"}),"Default"]})]}):(0,t.jsxs)("div",{className:"flex flex-col items-center gap-1 px-1.5 text-center",children:[(0,t.jsx)("div",{className:"w-7 h-7 rounded-full bg-muted/80 flex items-center justify-center",children:"video"===e?(0,t.jsx)(eB.Video,{className:"w-3.5 h-3.5 text-muted-foreground"}):"audio"===e?(0,t.jsx)(k.Music2,{className:"w-3.5 h-3.5 text-muted-foreground"}):(0,t.jsx)(ew.Plus,{className:"w-3.5 h-3.5 text-muted-foreground"})}),(0,t.jsxs)("p",{className:"text-[11px] font-medium text-foreground leading-tight truncate max-w-full",children:[a,r&&(0,t.jsx)("span",{className:"text-caution ml-0.5",children:"*"})]}),(0,t.jsxs)("button",{type:"button",onClick:e=>{e.stopPropagation(),E(!0)},className:"inline-flex items-center gap-1 text-[11px] text-interactive hover:opacity-70 font-medium",children:[(0,t.jsx)(ez.FolderOpen,{className:"w-3 h-3"}),"Library"]})]})}),c&&i&&(0,t.jsx)("div",{className:"mt-1.5 flex flex-col gap-1",children:(0,t.jsxs)("button",{type:"button",onClick:e=>{e.stopPropagation(),x?.()},title:w("replaceCharacterTooltip"),"aria-label":w("replaceCharacterAria",{label:a}),className:"w-full inline-flex items-center justify-center gap-1.5 rounded-md bg-interactive px-2 py-1.5 text-xs font-medium text-white transition-colors hover:bg-interactive/90",children:[(0,t.jsx)(eV,{className:"h-3.5 w-3.5"}),w("replaceCharacter")]})}),(0,t.jsx)("input",{ref:N,type:"file",accept:e9[e],onChange:e=>{let t=e.target.files?.[0];t&&K(t),e.target&&(e.target.value="")},className:"hidden"}),J&&(0,t.jsx)("p",{className:"text-xs text-destructive mt-1.5",children:J}),(0,t.jsx)(eX.AssetPickerModal,{isOpen:D,onClose:()=>E(!1),assetType:e,onPick:Z,title:`Pick ${a}`}),M&&(0,t.jsx)(eY.AudioSegmentSelectorModal,{isOpen:!!M,onClose:()=>R(null),audioUrl:M.url,audioFileId:M.id,durationLimitMax:M.limitSec,onSegmentSelected:H}),O&&(0,t.jsx)(e5,{isOpen:!!O,onClose:()=>$(null),videoUrl:O.url,videoFileId:O.id,durationLimitMax:O.limitSec,onSegmentSelected:W})]})}var te=e.i(320655),tt=e.i(194489),ts=e.i(480276),ta=e.i(232386),tr=e.i(278133);let tl="/short-templates/replace-demo",ti=[{kind:"scene",src:`${tl}/a.jpg`},{kind:"photo",src:`${tl}/b.jpg`},{kind:"result",src:`${tl}/c.jpg`}];async function tn(e){try{let t=await (0,eD.fetchWithAuth)(`/api/assets/${e}?type=image`);if(!t.ok)return null;let s=await t.json(),a=s.asset??s.data??s;return a?.public_url||a?.url||null}catch{return null}}function to({step:e,caption:a,onZoom:r}
7){let[l,i]=(0,s.useState)(!1);return(0,t.jsx)("div",{className:"relative h-full w-full overflow-hidden rounded-lg border border-border/60 bg-muted/50",children:l?(0,t.jsx)("div",{className:"flex h-full w-full items-center justify-center text-muted-foreground/40",children:(0,t.jsx)(ta.ImageIcon,{className:"h-5 w-5"})}):r?(0,t.jsxs)("button",{type:"button",onClick:()=>r(e.src,a),className:"group relative h-full w-full cursor-zoom-in","aria-label":`Zoom ${a}`,children:[(0,t.jsx)("img",{src:e.src,alt:a,onError:()=>i(!0),className:"h-full w-full object-cover object-top"}),(0,t.jsx)("span",{className:"absolute bottom-0.5 right-0.5 inline-flex items-center rounded bg-black/55 p-0.5 text-white opacity-0 transition-opacity group-hover:opacity-100",children:(0,t.jsx)(tr.ZoomIn,{className:"h-2.5 w-2.5"})})]}):(0,t.jsx)("img",{src:e.src,alt:a,onError:()=>i(!0),className:"h-full w-full object-cover object-top"})})}function td({isOpen:e,onClose:a,template:r,sceneIndex:l,imageSlotIndex:i,onReplaced:n}){let[o,d]=(0,s.useState)(!1),[c,u]=(0,s.useState)([]),[h,f]=(0,s.useState)(!1),[b,v]=(0,s.useState)(null),j=(0,s.useRef)(null),[y,w]=(0,s.useState)(""),[N,_]=(0,s.useState)(""),[k,C]=(0,s.useState)("idle"),[S,T]=(0,s.useState)(null),[D,E]=(0,s.useState)(null),[A,L]=(0,s.useState)(null),[P,I]=(0,s.use
7State)(null),{isFreeUser:M,loading:R}=(0,ea.useUserPlan)(),O=(0,p.useTranslations)("shortTemplates.replaceModal"),[$,F]=(0,s.useState)(!1),[q,z]=(0,s.useState)(!1),[V,B]=(0,s.useState)(null),G=(0,s.useRef)(!1),H=(0,s.useRef)(null),X=(0,s.useRef)([]),W=(0,s.useRef)(""),K="submitting"===k||"polling"===k,Z=c.length>0||y.trim().length>0,J=(0,s.useMemo)(()=>V?[{id:"zoom",kind:"image",url:V.url,title:V.title,createdAt:""}]:[],[V]);(0,s.useEffect)(()=>{!e&&(u([]),w(""),_(""),C("idle"),T(null),E(null),G.current=!1,F(!1),z(!1),X.current=[],W.current="",B(null),L(null),I(null),f(!1),v(null),H.current&&clearInterval(H.current))},[e]),(0,s.useEffect)(()=>{if(!e)return;let t=!1,s=r.shared?.image_slots??r.scenes?.[l]?.image_slots,a=s?.[i]?.default_asset_id??null;if(a){let e=r.asset_urls?.[a];e?L(e):tn(a).then(e=>{t||L(e)})}return(0,ep.getStoryboardReplaceCost)().then(e=>{t||I(e.data?.credits??null)}).catch(()=>{}),(0,ep.getStoryboardReplaceDefaults)().then(e=>{!t&&e.data?.user_default&&_(e.data.user_default)}).catch(()=>{}),()=>{t=!0}},[e,r,l,i]),(0,s.useEffect)(()=>()=>{H.current&&clearInterval(H.current)},[]);let Y=(0,s.useCallback)(e=>{u([e])},[]),Q=(0,s.useCallback)(e=>{Y(e),d(!1)},[Y]),ee=(0,s.useCallback)(async e=>{if(j.current&&(j.current.value=""),v(null),e.size>eK.UPLOAD_LIMITS.maxFileSize)return void v(`Image exceeds size cap (${eK.UPLOAD_LIMITS.maxFileSizeMB} MB).`);f(!0);try{let t=(await eH.AssetService.uploadFiles([e]))[0];t?.id?Y(t):v("Upload failed.")}catch(e){v(e instanceof Error?e.message:"Upload failed.")}finally{f(!1)}},[Y]),et=(0,s.useCallback)(e=>{u(t=>t.filter(t=>t.id!==e))},[]);(0,s.useEffect)(()=>{"done"===k&&D&&!G.current&&(G.current=!0,B({url:D.image_url,title:O("resultTitle")}))},[k,D,O]);let es=(0,s.useCallback)(()=>{D&&n(D),a()},[D,n,a]),er=(0,s.useCallback)(()=>{"done"===k&&D?es():K||Z?F(!0):a()},[k,D,es,K,Z,a]),el=(0,s.useCallback)(async()=>{if(0!==c.length){X.current=c.map(e=>e.id),W.current=y.trim(),C("submitting"),T(null);try{let e=await (0,ep.replaceStoryboardCharacter)({template_id:r.id,scene_index:l,image_slot_index:i,character_asset_ids:c.map(e=>e.id),additional_prompt:y.trim()||void 0}),t=e.data?.task_id;if(!t)throw Error("No task_id returned from server");C("polling");let s=0,a=0;H.current=setInterval(async()=>{s++;
7try{let e=(await (0,ep.getStoryboardReplaceStatus)(t)).data;a=0,"completed"===e.status&&e.image_url&&e.asset_id?(clearInterval(H.current),E({asset_id:e.asset_id,image_url:e.image_url}),C("done")):"completed"!==e.status||e.asset_id?"failed"===e.status?(clearInterval(H.current),C("error"),T(e.error_message??"Character replacement failed.")):s>=120&&(clearInterval(H.current),C("error"),T("Timed out waiting for character replacement.")):(clearInterval(H.current),C("error"),T("The image was generated but could not be saved to your library. Please try again."))}catch(e){++a>=5&&(clearInterval(H.current),C("error"),T(e instanceof Error?e.message:"Polling error."))}},3e3)}catch(e){C("error"),T(e instanceof Error?e.message:"Failed to start character replacement.")}}},[r.id,l,i,c,y]),ei=(0,s.useCallback)(()=>{0===c.length||(function(e,t){if(e.length!==t.length)return!1;let s=new Set(t);return e.every(e=>s.has(e))}(c.map(e=>e.id),X.current)&&y.trim()===W.current?z(!0):el())},[c,y,el]),en=(0,s.useCallback)(()=>{z(!1),el()},[el]),eo=(0,t.jsxs)("div",{className:"mr-auto flex flex-col gap-0.5 text-xs text-muted-foreground",children:[(0,t.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,t.jsx)(ts.Coins,{className:"w-3.5 h-3.5 text-interactive"}),null===P?(0,t.jsx)("span",{className:"text-muted-foreground/60",children:"Calculating cost…"}):(0,t.jsxs)("span",{children:[(0,t.jsx)("span",{className:"font-medium text-foreground",children:P})," credit",1===P?"":"s",!R&&(0,t.jsxs)("span",{className:"text-muted-foreground",children:[" · ",M?O("qualityStandard"):O("qualityHigh")]})]})]}),null!==P&&!R&&M&&(0,t.jsxs)("span",{className:"flex items-center gap-1 text-[11px] text-muted-foreground/70",children:[(0,t.jsx)(x.Sparkles,{className:"w-3 h-3 shrink-0"}),O("upgradeNudge")]})]});return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(te.Root,{open:e,onOpenChange:e=>{e||er()},children:(0,t.jsxs)(te.Portal,{children:[(0,t.jsx)(te.Overlay,{className:"fixed inset-0 z-50 bg-black/50 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0"}),(0,t.jsxs)(te.Content,{onPointerDownOutside:e=>e.preventDefault(),onInteractOutside:e=>e.preventDefault(),onEscapeKeyDown:e=>{e.preventDefault(),V?B(null):er()},className:"fixed left-[50%] top-[50%] z-50 translate-x-[-50%] translate-y-[-50%] w-[92vw] max-w-4xl max-h-[90vh] flex flex-col bg-background rounded-xl shadow-2xl border border-border data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2 px-4 pt-4 pb-3 border-b border-border/50",children:[(0,t.jsx)(eV,{className:"w-4 h-4 text-interactive flex-shrink-0"}),(0,t.jsx)(te.Title,{className:"text-sm font-semibold text-foreground mr-auto",children:O("title")}),(0,t.jsx)("button",{type:"button",onClick:er,className:"rounded-md p-1 text-muted-foreground hover:text-foreground hover:bg-muted transition-colors","aria-label":"Close",children:(0,t.jsx)(eG.X,{className:"w-4 h-4"})})]}),(0,t.jsx)(te.Description,{className:"sr-only",children:"Select one or more character images to replace the storyboard character"}),(0,t.jsxs)("div",{className:"flex-1 overflow-y-auto p-4 space-y-3",children:[(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)("p",{className:"text-[11px] font-semibold uppercase tracking-wide text-muted-foreground",children:O("howItWorks")}),(0,t.jsx)("div",{className:"flex flex-col sm:flex-row sm:items-stretch gap-2",children:ti.map((e,a)=>{let r="scene"===e.kind?O("stepScene"):"photo"===e.kind?O("stepYourPhoto"):O("stepResult"),l="scene"===e.kind?O("stepSceneDesc"):"photo"===e.kind?O("stepPhotoDesc"):O("stepResultDesc");return(0,t.jsxs)(s.Fragment,{children:[(0,t.jsxs)("div",{className:"flex flex-1 items-center gap-2.5 rounded-xl border border-border/70 bg-card/40 p-2",children:[(0,t.jsx)("div",{className:"h-12 w-12 shrink-0 sm:h-14 sm:w-14",children:(0,t.jsx)(to,{step:e,caption:r,onZoom:(e,t)=>B({url:e,title:t})})}),(0,t.jsxs)("div",{className:"min-w-0",children:[(0,t.jsxs)("p",{className:"text-xs font-semibold text-foreground",children:[a+1,". ",r]}),(0,t.jsx)("p",{className:"text-[11px] leading-snug text-muted-foreground",children:l})]})]}),a<ti.length-1&&(0,t.jsx)("div",{className:"hidden sm:flex shrink-0 items-center text-muted-foreground
7/50",children:(0,t.jsx)(tt.ArrowRight,{className:"h-4 w-4"})})]},e.kind)})})]}),(0,t.jsxs)("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3",children:[(0,t.jsxs)("div",{className:"min-w-0",children:[(0,t.jsx)("p",{className:"mb-1.5 text-[11px] font-semibold uppercase tracking-wide text-interactive",children:O("beforeLabel")}),(0,t.jsx)("div",{className:"relative w-full aspect-[3/4] rounded-lg overflow-hidden border border-border/60 bg-muted/50 flex items-center justify-center",children:A?(0,t.jsxs)("button",{type:"button",onClick:()=>B({url:A,title:O("beforeLabel")}),className:"group relative flex h-full w-full items-center justify-center cursor-zoom-in","aria-label":"Zoom original image",children:[(0,t.jsx)("img",{src:A,alt:"Original storyboard scene",className:"h-full w-full object-contain"}),(0,t.jsx)("span",{className:"absolute bottom-1 right-1 inline-flex items-center rounded bg-black/55 p-0.5 text-white opacity-0 transition-opacity group-hover:opacity-100",children:(0,t.jsx)(tr.ZoomIn,{className:"h-3 w-3"})})]}):(0,t.jsxs)("div",{className:"flex flex-col items-center gap-1 text-muted-foreground",children:[(0,t.jsx)(ta.ImageIcon,{className:"w-5 h-5"}),(0,t.jsx)("span",{className:"text-[10px]",children:"Loading…"})]})})]}),(0,t.jsxs)("div",{className:"min-w-0",children:[(0,t.jsxs)("p",{className:"mb-1.5 text-[11px] font-semibold uppercase tracking-wide text-muted-foreground",children:[O("yourPhotoLabel")," ",(0,t.jsx)("span",{className:"text-caution",children:"*"})]}),c[0]?(0,t.jsxs)("div",{className:"relative w-full aspect-[3/4] rounded-lg overflow-hidden border border-border/60 bg-muted/50 group",children:[(0,t.jsxs)("button",{type:"button",onClick:()=>B({url:c[0].public_url||c[0].url||"",title:O("yourPhoto")}),className:"absolute inset-0 cursor-zoom-in","aria-label":"Zoom your photo",children:[(0,t.jsx)(g.default,{src:c[0].public_url||c[0].url||"",alt:c[0].file_name,fill:!0,className:"object-contain",sizes:"240px"}),(0,t.jsx)("span",{className:"absolute bottom-1 right-1 inline-flex items-center rounded bg-black/55 p-0.5 text-white opacity-0 transition-opacity group-hover:opacity-100",children:(0,t.jsx)(tr.ZoomIn,{className:"h-3 w-3"})})]}),!K&&(0,t.jsx)("button",{type:"button",onClick:()=>et(c[0].id),className:"absolute top-1 right-1 z-10 w-5 h-5 rounded-full bg-black/60 hover:bg-destructive text-white flex items-center justify-center transition-colors","aria-label":"Remove character",children:(0,t.jsx)(eG.X,{className:"w-3 h-3"})})]}):(0,t.jsx)("div",{onClick:()=>!K&&!h&&j.current?.click(),className:`w-full aspect-[3/4] rounded-lg border-2 border-dashed flex flex-col items-center justify-center gap-1.5 text-center transition-colors ${K||h?"border-border opacity-50 pointer-events-none":"border-border hover:border-interactive/60 hover:bg-interactive/5 cursor-pointer"}`,"aria-label":"Add character image",children:h?(0,t.jsx)(m.Loader2,{className:"w-6 h-6 text-interactive animate-spin"}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{className:"w-9 h-9 rounded-full bg-muted/80 flex items-center justify-center",children:(0,t.jsx)(ew.Plus,{className:"w-4 h-4 text-muted-foreground"})}),(0,t.jsx)("span",{className:"text-[11px] font-medium text-foreground",children:O("uploadPhoto")}),(0,t.jsxs)("button",{type:"button",onClick:e=>{e.stopPropagation(),d(!0)},className:"inline-flex items-center gap-1 text-[11px] text-interactive hover:opacity-70 font-medium",children:[(0,t.jsx)(ez.FolderOpen,{className:"w-3 h-3"}),"Library"]})]})}),b&&(0,t.jsx)("p",{className:"text-xs text-destructive mt-1.5",children:b}),(0,t.jsx)("input",{ref:j,type:"file",accept:"image/*,.jpg,.jpeg,.png,.webp",onChange:e=>{let t=e.target.files?.[0];t&&ee(t),e.target&&(e.target.value="")},className:"hidden"})]}),(0,t.jsxs)("div",{className:"min-w-0",children:[(0,t.jsx)("p",{className:"mb-1.5 text-[11px] font-semibold uppercase tracking-wide text-muted-foreground",children:O("afterLabel")}),(0,t.jsx)("div",{className:"relative w-full aspect-[3/4] rounded-lg overflow-hidden border border-border/60 bg-muted/50 flex items-center justify-center",children:"done"===k&&D?(0,t.jsxs)("button",{type:"button",onClick:()=>B({url:D.image_url,title:O("resultTitle")}),className:"group relative flex h-full w-full items-center justify-center cursor-zoom-in","aria-label":O("resultTitle"),children:[(0,t.jsx)("img",{src:D.image_url,alt:O("resultTitle"),className:"h-full w-full object-contain"}),(0,t.jsx)("span",{className:"absolute bottom-1 right-1 inline-flex items-center rounded bg-black/55 p-0.5 text-white opacity-0 transition-opacity group-hover:opacity-100",children:(0,t.jsx)(tr.ZoomIn,{className:"h-3 w-3"})})]}):K?(0,t.jsxs)("div",{className:"flex flex-col items-center gap-2 px-2 text-center text-muted-foreground",children:[(0,t.jsx)(m.Loader2,{className:"h-6 w-6 animate-spin text-interactive"}),(0,t.jsx)("span",{className:"text-[10px] leading-snug",children:"submitting"===k?"Submitting…":"Replacing — 1–3 min…"})]}):"error"===k&&S?(0,t.jsx)("div",{className:"px-2 text-center text-[11px] text-destructive",children:S}):(0,t.jsxs)("div",{className:"flex flex-col items-center gap-1.5 px-3 text-center text-muted-foreground
7/50",children:[(0,t.jsx)(x.Sparkles,{className:"h-6 w-6"}),(0,t.jsx)("span",{className:"text-[11px] leading-snug",children:O("resultPlaceholder")})]})})]})]}),(0,t.jsxs)("div",{children:[(0,t.jsxs)("label",{className:"text-xs font-medium text-muted-foreground mb-1.5 block uppercase tracking-wide",children:["Additional prompt ",(0,t.jsx)("span",{className:"normal-case tracking-normal text-muted-foreground/60",children:"(optional)"})]}),(0,t.jsx)("textarea",{value:y,onChange:e=>w(e.target.value),placeholder:N||"E.g. soft smile, add sunglasses, warmer lighting — leave blank to keep the original styling",disabled:K,rows:3,className:"w-full rounded-lg border border-border bg-muted/50 px-3 py-2 text-sm text-foreground placeholder:text-muted-foreground resize-none focus:outline-none focus:ring-2 focus:ring-interactive/40 disabled:opacity-50"})]})]}),(0,t.jsx)("div",{className:"flex flex-wrap items-center gap-2 px-4 py-3 border-t border-border/50",children:"done"===k&&D?(0,t.jsxs)(t.Fragment,{children:[eo,(0,t.jsxs)("button",{type:"button",onClick:ei,disabled:0===c.length,className:"inline-flex items-center gap-1.5 rounded-lg border border-border px-3 py-1.5 text-sm text-muted-foreground hover:text-foreground hover:bg-muted transition-colors disabled:opacity-40 disabled:cursor-not-allowed",children:[(0,t.jsx)(U.RotateCcw,{className:"w-3.5 h-3.5"}),O("replaceAgain")]}),(0,t.jsx)("button",{type:"button",onClick:es,className:"inline-flex items-center gap-1.5 rounded-lg bg-interactive px-3 py-1.5 text-sm font-medium text-white hover:bg-interactive-hover transition-colors",children:O("useThisImage")})]}):(0,t.jsxs)(t.Fragment,{children:[eo,"error"===k&&(0,t.jsxs)("button",{type:"button",onClick:()=>C("idle"),className:"inline-flex items-center gap-1.5 text-xs text-muted-foreground hover:text-foreground",children:[(0,t.jsx)(U.RotateCcw,{className:"w-3 h-3"}),"Try again"]}),(0,t.jsx)("button",{type:"button",onClick:er,className:"rounded-lg border border-border px-3 py-1.5 text-sm text-muted-foreground hover:text-foreground hover:bg-muted transition-colors",children:"Cancel"}),(0,t.jsxs)("button",{type:"button",onClick:el,disabled:K||0===c.length,className:"inline-flex items-center gap-1.5 rounded-lg bg-interactive px-3 py-1.5 text-sm font-medium text-white hover:bg-interactive-hover transition-colors disabled:opacity-40 disabled:cursor-not-allowed",children:[K?(0,t.jsx)(m.Loader2,{className:"w-3.5 h-3.5 animate-spin"}):(0,t.jsx)(eV,{className:"w-3.5 h-3.5"}),"Replace"]})]})}),$&&(0,t.jsx)("div",{className:"absolute inset-0 z-10 flex items-center justify-center rounded-xl bg-background/80 backdrop-blur-sm p-4",children:(0,t.jsxs)("div",{className:"w-full max-w-xs rounded-xl border border-border bg-background p-4 shadow-xl",children:[(0,t.jsx)("p",{className:"text-sm font-semibold text-foreground mb-1",children:K?"Replacement in progress":"Discard changes?"}),(0,t.jsx)("p",{className:"text-xs text-muted-foreground mb-4",children:K?"A replacement is still running. Closing now will stop tracking it here — the result may not be applied to the slot.":"Your selected images and prompt will be lost."}),(0,t.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[(0,t.jsx)("button",{type:"button",onClick:()=>F(!1),className:"rounded-lg border border-border px-3 py-1.5 text-sm text-muted-foreground hover:text-foreground hover:bg-muted transition-colors",children:"Keep editing"}),(0,t.jsx)("button",{type:"button",onClick:()=>{F(!1),a()},className:"rounded-lg bg-destructive px-3 py-1.5 text-sm font-medium text-white hover:opacity-90 transition-opacity",children:K?"Close anyway":"Discard"})]})]})}),q&&(0,t.jsx)("div",{className:"absolute inset-0 z-10 flex items-center justify-center rounded-xl bg-background/80 backdrop-blur-sm p-4",children:(0,t.jsxs)("div",{className:"w-full max-w-xs rounded-xl border border-border bg-background p-4 shadow-xl",children:[(0,t.jsx)("p",{className:"text-sm font-semibold text-foreground mb-1",children:O("replaceAgainSameTitle")}),(0,t.jsx)("p",{className:"text-xs text-muted-foreground mb-4",children:O("replaceAgainSameBody",{credits:P??"?"})}),(0,t.jsxs)("div",{className:"flex items-center justify-end gap-2",children:[(0,t.jsx)("button",{type:"button",onClick:()=>z(!1),className:"rounded-lg border border-border px-3 py-1.5 text-sm text-muted-foreground hover:text-foreground hover:bg-muted transition-colors",children:O("replaceAgainSameCancel")}),(0,t.jsxs)("button",{type:"button",onClick:en,className:"inline-flex items-center gap-1.5 rounded-lg bg-interactive px-3 py-1.5 text-sm font-medium text-white hover:bg-interactive-hover transition-colors",children:[(0,t.jsx)(U.RotateCcw,{className:"w-3.5 h-3.5"}),O("replaceAgainSameConfirm")]})]})]})})]})]})}),(0,t.jsx)(eX.AssetPickerModal,{isOpen:o,onClose:()=>d(!1),assetType:"image",onPick:Q,title:"Pick character image"}),(0,t.jsx)(eq.AssetViewer,{assets:J,index:V&&J.length>0?0:null,onClose:()=>B(null),onIndexChange:()=>{}})]})}function tc({config:e,value:s,onChange:a}){let r=e.min??4,l=e.max??15;if(!("range"===e.mode&&r<l)){let s="fixed"===e.mode?e.value??e.default:r;return(0,t.jsxs)("div",{className:"rounded-xl bg-muted/80 p-3.5",children:[(0,t.jsx)("div",{className:"text-xs text-muted-foreground mb-1.5",children:"Duration"}),(0,t.jsxs)("div",{className:"text-sm text-foreground font-medium",children:[s,"s"]})]})}return(0,t.jsxs)("div",{className:"rounded-xl bg-muted/80 p-3.5",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,t.jsx)("div",{className:"text-xs text-muted-foreground",children:"Duration"}),(0,t.jsxs)("span",{className:"text-sm font-semibold text-foreground tabular-nums",children:[s,"s"]})]}),(0,t.jsx)("input",{type:"range",min:r,max:l,step:1,value:s,onChange:e=>a(Number(e.target.value)),"aria-label":"Duration in seconds",className:"w-full accent-primary curs
7or-pointer"}),(0,t.jsxs)("div",{className:"flex justify-between mt-1 text-[10px] text-muted-foreground/60 tabular-nums",children:[(0,t.jsxs)("span",{children:[r,"s"]}),(0,t.jsxs)("span",{children:[l,"s"]})]})]})}function tu({options:e,value:s,onChange:a,stacked:r=!1,ariaLabel:l}){return(0,t.jsx)("div",{role:"radiogroup","aria-label":l,className:"flex w-full items-stretch gap-1 rounded-lg bg-muted/70 dark:bg-card/60 p-1",children:e.map(e=>{let l=e.value===s;return(0,t.jsxs)("button",{type:"button",role:"radio","aria-checked":l,disabled:e.disabled,title:e.title,onClick:()=>a(e.value),className:`flex flex-1 ${r?"flex-col":"flex-row"} items-center justify-center gap-1 rounded-md px-2 py-1.5 font-medium transition-all disabled:opacity-40 disabled:cursor-not-allowed ${l?"bg-background text-foreground shadow-sm":"text-muted-foreground hover:text-foreground"}`,children:[e.icon,(0,t.jsx)("span",{className:r?"text-[11px] leading-none":"text-sm",children:e.label})]},e.value)})})}let tm={"21:9":"w-6 h-[10px]","16:9":"w-5 h-3","4:3":"w-[18px] h-[14px]","1:1":"w-4 h-4","3:4":"w-[14px] h-[18px]","9:16":"w-3 h-5"},tx=["21:9","16:9","4:3","1:1","3:4","9:16"];function tp({options:e,value:s,onChange:a}){if(e.length<=1)return(0,t.jsxs)("div",{className:"rounded-xl bg-muted/80 p-3.5",children:[(0,t.jsx)("div",{className:"text-xs text-muted-foreground mb-1.5",children:"Aspect ratio"}),(0,t.jsx)("div",{className:"text-sm text-foreground font-medium",children:e[0]??s})]});let r=tx.filter(t=>e.includes(t)).map(e=>({value:e,label:e,icon:(0,t.jsx)("span",{className:`${tm[e]} rounded-[3px] border-[1.5px] border-current`})}));return(0,t.jsxs)("div",{className:"rounded-xl bg-muted/80 p-3.5",children:[(0,t.jsx)("div",{className:"text-xs text-muted-foreground mb-2",children:"Aspect ratio"}),(0,t.jsx)(tu,{options:r,value:s,onChange:a,stacked:!0,ariaLabel:"Aspect ratio"})]})}var th=e.i(777221);function tf({value:e,showUpgrade:s=!1}){return(0,t.jsxs)("div",{className:"rounded-xl bg-muted/80 p-3.5",children:[(0,t.jsxs)("div",{className:"flex items-center gap-1 mb-2",children:[(0,t.jsxs)("div",{className:"flex items-center gap-1 text-xs text-muted-foreground font-medium uppercase tracking-wide",children:[s&&(0,t.jsx)(eR.Lock,{className:"w-3 h-3"})," Prompt"]}),s&&(0,t.jsxs)(ey.default,{href:"/pricing",target:"_blank",rel:"noopener noreferrer","aria-label":"Upgrade to edit prompt",className:"ml-auto inline-flex items-center gap-1 rounded-full bg-gradient-hero px-2.5 py-1 text-[11px] font-semibold text-white shadow-brand transition-opacity hover:opacity-90",children:[(0,t.jsx)(eR.Lock,{className:"w-3 h-3"})," Upgrade to edit"]})]}),(0,t.jsx)(th.PromptEditor,{value:e,onChange:()=>{},readOnly:!0})]})}function tg(e,t){let s=[],a=0;for(let l=0;l<e.length;l++){let i=e[l];if(!(0,X.isHiddenFromUser)(i)){var r;s.push({userIndex:a,autoTag:(r=a,`${"image"===t?"Image":"video"===t?"Video":"Audio"}${r+1}`),required:i.required,defaultAssetId:i.default_asset_id,isStoryboard:!0===i.is_storyboard,slotIndex:l}),a++}}return s}function tb({models:e,defaultModel:s,value:a,onChange:r}){if(e.length<=1)return(0,t.jsxs)("div",{className:"rounded-xl bg-muted/80 p-3.5",children:[(0,t.jsx)("div",{className:"text-xs text-muted-foreground mb-1.5",children:"Model"}),(0,t.jsx)("div",{className:"text-sm text-foreground font-medium",children:(0,X.seedanceModelLabel)(s)})]});let l=e.map(e=>({value:e,label:(0,X.seedanceModelLabel)(e)}));return(0,t.jsxs)("div",{className:"rounded-xl bg-muted/80 p-3.5",children:[(0,t.jsx)("div",{className:"text-xs text-muted-foreground mb-2",children:"Model"}),(0,t.jsx)(tu,{options:l,value:a,onChange:r,ariaLabel:"Model"})]})}function tv({resolutions:e,defaultResolution:s,value:a,allowedByModel:r,onChange:l}){let i=e.filter(e=>tj(e,r));if(i.length<=1)return(0,t.jsxs)("div",{className:"rounded-xl bg-muted/80 p-3.5",children:[(0,t.jsx)("div",{className:"text-xs text-muted-foreground mb-1.5",children:"Resolution"}),(0,t.jsx)("div",{className:"text-sm text-foreground font-medium",children:i[0]??s})]});let n=i.map(e=>({value:e,label:e}));return(0,t.jsxs)("div",{className:"rounded-xl bg-muted/80 p-3.5",children:[(0,t.jsx)("div",{className:"text-xs text-muted-foreground mb-2",children:"Resolution"}),(0,t.jsx)(tu,{options:n,value:a,onChange:l,ariaLabel:"Resolution"})]})}function tj(e,t){let s=["480p","720p","1080p"];return s.indexOf(e)<=s.indexOf(t)}
7function ty({value:e,onChange:s}){return(0,t.jsx)("div",{className:"rounded-xl bg-muted/80 p-3.5",children:(0,t.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[(0,t.jsxs)("div",{className:"min-w-0",children:[(0,t.jsx)("div",{className:"text-sm font-medium text-foreground",children:"Output sound"}),(0,t.jsx)("div",{className:"text-xs text-muted-foreground mt-0.5",children:e?"Video will include generated audio":"Video will be silent"})]}),(0,t.jsxs)("button",{type:"button",onClick:()=>s(!e),"aria-pressed":e,className:`inline-flex flex-shrink-0 items-center gap-1.5 rounded-lg border px-3 py-2 text-sm font-medium transition-colors ${e?"border-interactive/40 bg-interactive/10 text-interactive":"border-border text-muted-foreground hover:text-foreground hover:bg-muted"}`,children:[e?(0,t.jsx)(j.Volume2,{className:"w-4 h-4"}):(0,t.jsx)(y.VolumeX,{className:"w-4 h-4"}),e?"On":"Off"]})]})})}async function tw(e,t){try{let s=await (0,eD.fetchWithAuth)(`/api/assets/${e}?type=${t}`);if(!s.ok)return null;let a=await s.json(),r=a.asset??a.data??a;return r&&r.id?r:null}catch{return null}}function tN({template:e,onFormDataChange:a,initialFill:r,onClearInitialFill:l,onClearTemplate:i,openReplaceSignal:n}){let o,d=(0,p.useTranslations)("shortTemplates.form"),{isFreeUser:c,loading:u}=(0,ea.useUserPlan)(),m=!u&&!c,x=(0,s.useMemo)(()=>(0,f.getEffectiveTemplateConfig)(e),[e]),h=x?.isMultiScene??!1,g=(0,s.useMemo)(()=>x?.models?.length?x.models:["dreamina-seedance-2-0-260128"],[x]),b=(0,s.useMemo)(()=>{var e;let t;return e=x??void 0,t=e?.default_model??e?.model??"dreamina-seedance-2-0-260128",c&&g.includes(eF)?eF:t},[c,x,g]),v=(0,s.useMemo)(()=>{var e;return e=x??void 0,c?"480p":e?.default_resolution??e?.resolution??"720p"},[c,x]),j=(0,s.useMemo)(()=>tg(x?.image_slots??[],"image"),[x]),y=(0,s.useMemo)(()=>tg(x?.video_slots??[],"video"),[x]),w=(0,s.useMemo)(()=>tg(x?.audio_slots??[],"audio"),[x]),[N,_]=(0,s.useState)(()=>j.map(()=>null)),[k,C]=(0,s.useState)(()=>y.map(()=>
7null)),[T,D]=(0,s.useState)(()=>w.map(()=>null)),[E,A]=(0,s.useState)(()=>y.map(()=>null)),[L,P]=(0,s.useState)(()=>w.map(()=>null)),[I,M]=(0,s.useState)(null),R=(0,s.useMemo)(()=>N.filter(e=>!!e).map(e=>({id:e.id,kind:"image",url:e.public_url||e.url||"",title:e.file_name||"Image",createdAt:e.created_at??""})),[N]),O=(0,s.useCallback)(e=>{let t=N[e];if(!t)return;let s=R.findIndex(e=>e.id===t.id);-1!==s&&M(s)},[N,R]),[$,F]=(0,s.useState)(()=>h?x?.userPromptDefault??"":x?.scenePromptDefaults?.[0]??""),[q,z]=(0,s.useState)(x?.duration.mode==="fixed"?x.duration.value??x.duration.default:x?.duration.default??5),[V,B]=(0,s.useState)(x?.default_aspect_ratio??"9:16"),[G,H]=(0,s.useState)(b),[W,K]=(0,s.useState)(v),[Z,J]=(0,s.useState)(!1),[Y,Q]=(0,s.useState)(!0),[ee,et]=(0,s.useState)(null);(0,s.useEffect)(()=>{if(!n)return;let e=j.findIndex(e=>e.isStoryboard);e>=0&&et(e)},[n,j]);let[es,er]=(0,s.useState)(0),el=(0,s.useMemo)(()=>X.VALID_RESOLUTIONS.filter(e=>tj(e,X.SEEDANCE_MODEL_MAX_RESOLUTION[G])),[G]);(0,s.useEffect)(()=>{H(b)},[b]),(0,s.useEffect)(()=>{K(v)},[v]),(0,s.useEffect)(()=>{_(j.map(()=>null)),C(y.map(()=>null)),D(w.map(()=>null)),A(y.map(()=>null)),P(w.map(()=>null)),F(h?x?.userPromptDefault??"":x?.scenePromptDefaults?.[0]??""),z(x?.duration.mode==="fixed"?x.duration.value??x.duration.default:x?.duration.default??5),B(x?.default_aspect_ratio??"9:16"),H(b),K(v),Q(!0),et(null)},[e.id,es]),(0,s.useEffect)(()=>{if(r||!(j.some(e=>e.defaultAssetId)||y.some(e=>e.defaultAssetId)||w.some(e=>e.defaultAssetId)))return void J(!1);let t=!1;J(!0);let s=async(s,a,r)=>{let l=s.map((e,t)=>({i:t,id:e.defaultAssetId})).filter(e=>!!e.id);if(0===l.length)return;let i=e.asset_urls??{},n=l.filter(e=>!i[e.id]),o=new Map;if(n.length>0){let e=await Promise.all(n.map(e=>tw(e.id,r)));if(t)return;n.forEach((t,s)=>o.set(t.id,e[s]))}t||a(e=>{let t=[...e];for(let{i:e,asset:s}of function(e,t,s,a){let r=[];for(let l of e){let e=t[l.id],i=e?function(e,t,s){let a=new Date().toISOString();return{id:e,url:t,public_url:t,file_name:`template-default-${e}`,file_path:t,type:s,user_id:"",created_at:a,updated_at:a}}(l.id,e,a):s.get(l.id)??null;i&&r.push({i:l.i,asset:i})}return r}(l,i,o,r))e<t.length&&(t[e]=s);return t})};return Promise.all([s(j,_,"image"),s(y,C,"video"),s(w,D,"audio")]).finally(()=>{t||J(!1)}),()=>{t=!0}},[e.id,es]),(0,s.useEffect)(()=>{let e=X.SEEDANCE_MODEL_MAX_RESOLUTION[G];tj(W,e)||K(e)},[G]);let ei=null!=r&&""===r.user_content&&0===r.user_image_asset_ids.length&&0===r.user_video_asset_ids.length&&0===r.user_audio_asset_ids.length;(0,s.useEffect)(()=>{if(!r||(F(r.user_content),r.user_model_choice&&g.includes(r.user_model_choice)&&H(r.user_model_choice),r.user_resolution_choice&&el.includes(r.user_resolution_choice)&&K(r.user_resolution_choice),ei))return;let e=async(e,t,s)=>{if(0===e.length)return;let a=await Promise.all(e.map(e=>tw(e,s)));t(e=>{let t=[...e];return a.forEach((e,s)=>{s<t.length&&(t[s]=e)}),t})};e(r.user_image_asset_ids,_,"image"),e(r.user_video_asset_ids,C,"video"),e(r.user_audio_asset_ids,D,"audio")},[r]);let en=(0,s.useRef)(a);(0,s.useEffect)(()=>{en.current=a},[a]),(0,s.useEffect)(()=>{let t=[...j.filter((e,t)=>e.required&&!N[t]).map(e=>e.autoTag),...y.filter((e,t)=>e.required&&!k[t]).map(e=>e.autoTag),...w.filter((e,t)=>e.required&&!T[t]).map(e=>e.autoTag)],s=t.length,a=h||!!$.trim(),r=0===s&&a,l=(e,t)=>e.map((e,s)=>({defaultAssetId:e.defaultAssetId,assetId:t[s]?.id??null,isStoryboard:e.isStoryboard,autoTag:e.autoTag})),{untouchedStoryboardLabels:i,isPristine:n}=function(e){let{imageSlots:t,videoSlots:s,audioSlots:a,promptText:r,promptDefault:l}=e;return{untouchedStoryboardLabels:t.filter(e=>e.isStoryboard&&!!e.defaultAssetId&&e.assetId===e.defaultAssetId).map(e=>e.autoTag),isPristine:!(r.trim()!==l.trim()||t.some(eU)||s.some(eU)||a.some(eU))}}({imageSlots:l(j,N),videoSlots:l(y,k),audioSlots:l(w,T),promptText:$,promptDefault:h?x?.userPromptDefault??"":x?.scenePromptDefaults?.[0]??""}),o={template_id:e.id,user_content:$.trim(),user_image_asset_ids:N.map(e=>e?.id??""),user_video_asset_ids:k.map(e=>e?.id??""),user_audio_asset_ids:T.map(e=>e?.id??"")};x?.duration.mode==="range"&&(o.duration_choice=q),(x?.aspect_ratios.length??0)>1&&(o.aspect_ratio_choice=V),g.length>1&&(o.model_choice=G),el.length>1&&(o.resolution_choice=W),o.generate_audio_choice=Y;let d=k.map((e,t)=>e?.id&&e.id!==y[t]?.defaultAssetId?e.id:null).filter(e=>!!e),c=T.map((e,t)=>e?.id&&e.id!==w[t]?.defaultAssetId?e.id:null).filter(e=>!!e);en.current?.({template_id:e.id,payload:r?o:void 0,isValid:r,missingRequiredSlots:s,missingSlotLabels:t,untouchedStoryboardLabels:i,isPristine:n,duration_choice:x?.duration.mode==="range"?q:null,aspect_ratio_choice:(x?.aspect_ratios.length??0)>1?V:null,model_choice:g.length>1?G:null,resolution_choice:el.length>1?W:null,user_video_asset_ids:d,user_audio_asset_ids:c})},[e.id,x,h,j,y,w,N,k,T,$,q,V,G,W,g.length,el.length,Y]);let eo=(0,s.useCallback)((e,t)=>{let s={id:t.asset_id,url:t.image_url,public_url:t.image_url,file_name:`storyboard-replaced-${t.asset_id}`,file_path:t.image_url,type:"image",user_id:"",created_at:new Date().toISOString(),updated_at:new Date().toISOString()};_(t=>t.map((t,a)=>a===e?s:t)),et(null)},[]),ed=(0,s.useCallback)((e,t,s)=>{"video"===e?A(e=>e.map((e,a)=>a===t?s:e)):"audio"===e&&P(e=>e.map((e,a)=>a===t?s:e))},[]),ec=(0,s.useCallback)((e,t)=>{let s=("video"===e?E:"audio"===e?L:[]).reduce((e,s,a)=>a!==t&&s?e+s:e,0);return Math.max(0,("audio"===e?h?q:X.SEEDANCE_MAX_AUDIO_CUMULATIVE_S:X.SEEDANCE_MAX_VIDEO_CUMULATIVE_S)-s)},[E,L,h,q]);if(!x)return(0,t.jsx)("div",{className:"p-6 text-sm text-muted-foreground",children:"Template has no scenes — please contact admin."});let eu=(e,t,s)=>{"image"===e&&_(e=>e.map((e,a)=>a===t?s:e)),"video"===e&&C(e=>e.map((e,a)=>a===t?s:e)),"audio"===e&&D(e=>e.map((e,a)=>a===t?s:e))},em=X.SEEDANCE_MODEL_MAX_RESOLUTION[G];return(0,t.jsxs)("div",{className:"space-y-5",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between gap-3",children:[i?(0,t.jsx)("button",{type:"button",onClick:i,className:"text-xs text-interactive hover:opacity-80",children:"← Browse templates"}):(0,t.jsx)("span",{}),(0,t.jsxs)("button",{type:"button",onClick:()=>{l?.(),er(e=>e+1)},className:"inline-flex items-center gap-1.5 text-xs text-muted-foreground hover:text-foreground",children:[(0,t.jsx)(U.RotateCcw,{className:"w-3.5 h-3.5"}),"Reset to default"]})]}),r&&(0,t.jsxs)("div",{className:"rounded-lg border border-interactive/30 bg-interactive/5 px-3 py-2.5 flex items-start justify-between gap-2",children:[(0,t.jsx)("p",{className:"text-xs text-muted-foreground leading-snug",children:ei?"Original inputs not available for this older generation — select new assets and click Generate.":"Re-running from a previous generation — modify any field and click Generate to create a new video."}),(0,t.jsx)("button",{type:"button",onClick:l,className:"flex-shrink-0 text-[11px] text-interactive hover:opacity-80 font-medium",children:"Clear"})]}),j.length>0&&(0,t.jsxs)("div",{children:[(0,t.jsx)("div",{className:"text-xs text-muted-foreground mb-1 font-medium uppercase tracking-wide",children:d("imagesLabel")}),j.some(e=>e.isStoryboard)&&(0,t.jsx)("p",{className:"text-[11px] italic text-muted-foreground
7/70 mb-2 leading-snug",children:d("imagesHelper")}),(0,t.jsx)("div",{className:"grid grid-cols-[repeat(auto-fill,6rem)] gap-2",children:j.map((e,s)=>(0,t.jsx)(e7,{kind:"image",label:e.autoTag,required:e.required,isEmpty:!N[s],value:N[s],onChange:e=>eu("image",s,e),loading:Z&&!!e.defaultAssetId&&!N[s],isStoryboard:e.isStoryboard,defaultAssetId:e.defaultAssetId,onView:()=>O(s),onReplaceCharacter:()=>et(s),onResetDefault:()=>{e.defaultAssetId&&tw(e.defaultAssetId,"image").then(e=>{e&&_(t=>t.map((t,a)=>a===s?e:t))})}},`img-${s}`))})]}),(0,t.jsx)(eq.AssetViewer,{assets:R,index:I,onClose:()=>M(null),onIndexChange:M}),null!==ee&&((o=j[ee])?(0,t.jsx)(td,{isOpen:!0,onClose:()=>et(null),template:e,sceneIndex:0,imageSlotIndex:o.slotIndex,onReplaced:e=>eo(ee,e)}):null),y.length>0&&(0,t.jsxs)("div",{children:[(0,t.jsx)("div",{className:"text-xs text-muted-foreground mb-2 font-medium uppercase tracking-wide",children:"Videos"}),(0,t.jsx)("div",{className:"grid grid-cols-[repeat(auto-fill,6rem)] gap-2",children:y.map((e,s)=>(0,t.jsx)(e7,{kind:"video",label:e.autoTag,required:e.required,isEmpty:!k[s],value:k[s],onChange:e=>eu("video",s,e),cumulativeRemainingSec:ec("video",s),onDurationResolved:e=>ed("video",s,e),loading:Z&&!!e.defaultAssetId&&!k[s]},`vid-${s}`))})]}),w.length>0&&(0,t.jsxs)("div",{children:[(0,t.jsx)("div",{className:"text-xs text-muted-foreground mb-2 font-medium uppercase tracking-wide",children:"Audio"}),(0,t.jsx)("div",{className:"grid grid-cols-[repeat(auto-fill,6rem)] gap-2",children:w.map((e,s)=>(0,t.jsx)(e7,{kind:"audio",label:e.autoTag,required:e.required,isEmpty:!T[s],value:T[s],onChange:e=>eu("audio",s,e),cumulativeRemainingSec:ec("audio",s),onDurationResolved:e=>ed("audio",s,e),loading:Z&&!!e.defaultAssetId&&!T[s]},`aud-${s}`))})]}),m?(0,t.jsxs)("div",{className:"rounded-xl bg-muted/80 p-3.5",children:[(0,t.jsxs)("div",{className:"flex items-center gap-1.5 mb-2",children:[(0,t.jsx)("div",{className:"text-xs text-muted-foreground font-medium uppercase tracking-wide",children:h?"Your idea — applied to the whole video":"Prompt"}),h&&(0,t.jsx)("span",{className:"text-[10px] text-muted-foreground/70",children:"(optional)"}),(0,t.jsx)(S.CopyButton,{value:$,label:"Copy prompt",className:"ml-auto"})]}),(0,t.jsx)(th.PromptEditor,{value:$,onChange:F,placeholder:h?"Optional — add your idea: a mood, setting, character or twist…":"Describe your scene…"})]}):(0,t.jsx)(tf,{value:$,showUpgrade:!u&&c}),(0,t.jsx)("div",{children:(0,t.jsx)(tc,{config:x.duration,value:q,onChange:z})}),(0,t.jsx)(tp,{options:x.aspect_ratios,value:V,onChange:B}),(0,t.jsx)(tb,{models:g,defaultModel:b,value:G,onChange:H}),(0,t.jsx)(tv,{resolutions:el,defaultResolution:v,value:W,allowedByModel:em,onChange:K}),(0,t.jsx)(ty,{value:Y,onChange:Q})]})}async function t_(e){let{initialLimit:t,pageLimit:s,fetchPage:a,onPage:r,isStale:l}=e,i=()=>!!l&&l(),n=await a(0,t);if(i()||(r(n,!0),n.length<t))return;let o=n.length;try{for(;;){let e=await a(o,s);if(i()||0===e.length||(r(e,!1),o+=e.length,e.length<s))return}}catch{}}let tk=new Map;var tC=e.i(117927);let tS="short_video:seen_completions";function tT(){try{return new Set(JSON.parse(localStorage.getItem(tS)||"[]"))}catch{return new Set}}async function tD(e,t=3,s=600){let a;for(let r=0;r<=t;r++)try{return await e()}catch(e){if(a=e,r===t)break;await new Promise(e=>setTimeout(e,s*2**r))}throw a}e.s(["default",0,function(){var e;let u,{user:m,loading:x}=(0,r.useAuth)(),p=(0,a.useRouter)(),{flags:h,rawFlags:f,loading:g}=(0,i.useFeatureFlags)(),{isAdmin:b}=(0,n.useAdmin)();e=m?.id??null,u=(0,a.useRouter)(),(0,s.useEffect)(()=>{if(!e)return;let t=tC.supabase.channel(`short_video_generations:${e}`).on("broadcast",{event:"completion"},({payload:e})=>{let t=e.generation_id;if(t&&!tT().has(t)){let s,a;(s=tT()).add(t),a=Array.from(s).slice(-50),localStorage.setItem(tS,JSON.stringify(a)),"completed"===e.status?eN.toast.success(`"${e.title}" is ready`,{description:"Click to view",action:{label:"Open",onClick:()=>u.push(`/tools/short-templates?gen=${t}`)}}
7):"failed"===e.status&&eN.toast.error(`"${e.title}" failed to generate`)}}).subscribe(e=>{("CHANNEL_ERROR"===e||"TIMED_OUT"===e)&&console.warn("[useShortVideoCompletionToast] realtime unavailable, polling fallback active")});return()=>{tC.supabase.removeChannel(t).catch(()=>{})}},[e,u]),(0,s.useEffect)(()=>{g||h.enable_short_templates||p.replace("/projects")},[p,g,h.enable_short_templates]);let[v,j]=(0,s.useState)([]),[y,w]=(0,s.useState)(!1),[N,_]=(0,s.useState)([]),[k,C]=(0,s.useState)(!1),[S,T]=(0,s.useState)(null),[D,E]=(0,s.useState)(null),[A,L]=(0,s.useState)("templates"),[P,I]=(0,s.useState)(!1),[M,R]=(0,s.useState)(null),[O,$]=(0,s.useState)("public"),{isFreeUser:F,loading:U}=(0,ea.useUserPlan)(),q=!!m&&!U&&F,z=(0,eM.usePaidToolLock)(),[V,B]=(0,s.useState)(!1),G=(0,s.useCallback)(()=>{m?B(!0):l.authGate.requestLogin()},[m]),H=(0,s.useRef)(null),X=(0,s.useCallback)(e=>{H.current=e},[]),{startPolling:W}=function({onUpdate:e,onError:t}={}){let a=(0,s.useRef)(e),r=(0,s.useRef)(t);(0,s.useEffect)(()=>{a.current=e},[e]),(0,s.useEffect)(()=>{r.current=t},[t]);let l=(0,s.useRef)(new Set),i=(0,s.useCallback)(e=>{let t=tk.get(e);t&&(clearInterval(t.intervalId),tk.delete(e)),l.current.delete(e)},[]),n=(0,s.useCallback)(e=>{if(tk.has(e))return;let t=0,s=0,n=async()=>{t+=1;try{let l=(await (0,ep.getGeneration)(e)).data;if(s=0,a.current?.(l),"completed"===l.status||"failed"===l.status||"cancelled"===l.status)return void i(e);t>=300&&(i(e),r.current?.(Error("Polling reached MAX_POLL_ATTEMPTS without terminal state")))}catch(t){(s+=1)>=10&&(i(e),r.current?.(t instanceof Error?t:Error("Polling failed: "+String(t))))}},o=setInterval(n,1e4);tk.set(e,{intervalId:o}),l.current.add(e),n()},[i]);return(0,s.useEffect)(()=>()=>{for(let e of Array.from(l.current))i(e)},[i]),{startPolling:n,stopPolling:i}}({onUpdate:(0,s.useCallback)(e=>{_(t=>{let s=t.findIndex(t=>t.id===e.id);if(-1===s)return[e,...t];let a=[...t];return a[s]=e,a})},[]),onError:e=>T(e.message)}),K=(0,s.useRef)(!1),Z=(0,s.useRef)(0);(0,s.useEffect)(()=>()=>void(Z.current+=1),[]);let J=(0,s.useCallback)(async e=>{let t=Z.current+=1,s=()=>Z.current!==t;w(!0);try{await t_({initialLimit:12,pageLimit:24,fetchPage:async(t,s)=>(0===t?await tD(()=>(0,ep.listShortTemplates)({status:e,limit:s,offset:t})):await (0,ep.listShortTemplates)({status:e,limit:s,offset:t})).data??[],onPage:(e,t)=>{s()||(t?(j(e),w(!1)):j(t=>[...t,...e]))},isStale:s})}catch(e){if(s()||!m)return;T(e instanceof Error?e.message:"Failed to load templates.")}finally{s()||w(!1)}},[m]);(0,s.useEffect)(()=>{x||g||!h.enable_short_templates||K.current||(K.current=!0,J(b?O:void 0))},[x,g,h.enable_short_templates,b,O,J]);let Y=(0,s.useCallback)(async()=>{if(m){C(!0);try{let e=await tD(()=>(0,ep.listGenerations)());for(let t of(_(e.data??[]),e.data??[]))("pending"===t.status||"processing"===t.status)&&W(t.id)}catch(e){T(e instanceof Error?e.message:"Failed to load.")}finally{C(!1)}}},[m,W]),Q=(0,s.useRef)(null);(0,s.useEffect)(()=>{if(!x){if(!m){Q.current=null;return}Q.current!==m.id&&(Q.current=m.id,Y())}},[x,m,Y]);let ee=(0,s.useRef)(!0);(0,s.useEffect)(()=>{if(ee.current){ee.current=!1;return}b&&m&&J(O)},[O,b,m,J]);let et=(0,s.useRef)(!1),es=(0,s.useCallback)(async()=>{if(m&&!et.current){et.current=!0;try{let e=await (0,ep.listGenerations)();for(let t of(_(e.data??[]),e.data??[]))("pending"===t.status||"processing"===t.status)&&W(t.id)}catch{}finally{et.current=!1}}},[m,W]);(0,s.useEffect)(()=>{if(x||!m)return;let e=setInterval(()=>{es()},3e4);return()=>clearInterval(e)},[x,m,es]);let er=(0,s.useRef)(A);(0,s.useEffect)(()=>{er.current!==A&&(er.current=A,"history"===A&&es())},[A,es]);let el=(0,s.useCallback)(e=>{m?(E(e),T(null)):l.authGate.requestLogin()},[m]),ei=(0,s.useCallback)(()=>{E(null),H.current=null,R(null)},[]),en=(0,s.useCallback)(async()=>{let e=H.current;if(e?.payload){I(!0),T(null);try{let t=await (0,ep.submitGeneration)(e.payload);_(e=>[t.data,...e]),W(t.data.id),L("history")}catch(e){T(e instanceof Error?e.message:"Submission failed.")}finally{I(!1)}}},[W]),eo=(0,s.useCallback)(async e=>{T(null);try{let t=await (0,ep.retryGeneration)(e);_(s=>s.map(s=>s.id===e?t.data:s)),W(e)}catch(e){T(e instanceof Error?e.message:"Retry failed.")}},[W]),ed=(0,s.useCallback)(async e=>{try{await (0,ep.deleteGeneration)(e),_(t=>t.filter(t=>t.id!==e))}catch(e){T(e instanceof Error?e.message:"Delete failed.")}},[]),ec=(0,s.useCallback)(async e=>{try{await Promise.all(e.map(e=>(0,ep.deleteGeneration)(e))),_(t=>t.filter(t=>!e.includes(t.id)))}catch(e){T(e instanceof Error?e.message:"Delete failed.")}},[]),eu=(0,s.useCallback)(e=>{let t=v.find(t=>
7t.id===e.template_id);t&&(E(t),R(e),L("templates"),H.current=null)},[v]);return x||g||!h.enable_short_templates?(0,t.jsx)(d.AppLayout,{children:(0,t.jsx)(c.Loading,{})}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(ej,{selectedTemplate:D,onSelectTemplate:el,onClearTemplate:ei,formComponent:D?z?(0,t.jsx)(eI.PaidToolGatePanel,{toolName:"Short MVs"}):(0,t.jsx)(tN,{template:D,onFormDataChange:X,initialFill:M,onClearInitialFill:()=>R(null)}):void 0,locked:z,templates:v,isLoadingTemplates:y,generations:N,isLoadingGenerations:k,isSubmitting:P,error:S,onSubmit:en,onRetry:z?void 0:eo,onDelete:ed,onDeleteMany:ec,onRerun:eu,activeTab:A,onTabChange:L,banner:f.enable_short_templates?void 0:(0,t.jsx)(o.FeatureDisabledBanner,{featureName:"Short MVs"}),templatesHeaderSlot:(0,t.jsxs)("div",{className:"flex items-center justify-between gap-2 flex-wrap",children:[b?(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("span",{className:"text-xs font-medium text-muted-foreground",children:"Admin view:"}),(0,t.jsxs)("select",{value:O,onChange:e=>$(e.target.value),className:"rounded-md border border-input bg-background px-2 py-1 text-xs text-foreground focus:outline-none focus:ring-1 focus:ring-ring",children:[(0,t.jsx)("option",{value:"public",children:"Public only"}),(0,t.jsx)("option",{value:"draft",children:"Draft only"}),(0,t.jsx)("option",{value:"all",children:"All (public + draft)"})]})]}):(0,t.jsx)("span",{}),(0,t.jsx)(eO,{onClick:G,locked:q})]}),templatesFooterSlot:(0,t.jsx)(e$,{onClick:G,locked:q})}),(0,t.jsx)(eP,{open:V,onOpenChange:B})]})}],56864)},600200,e=>{"use strict";var t=e.i(139736),s=e.i(286968),a=e.i(617540),r=e.i(167881);class l extends s.Component{constructor(e){super(e),this.state={hasError:!1,message:""}}static getDerivedStateFromError(e){return{hasError:!0,message:e instanceof Error?e.message:"Unknown error"}}componentDidCatch(e,t){console.error("[ShortTemplatesErrorBoundary]",e,t.componentStack)}render(){if(this.state.hasError){let e=this.state.message.slice(0,200);return(0,t.jsxs)("div",{role:"alert","aria-live":"assertive",className:"flex flex-col items-center justify-center py-20 gap-4 text-center px-6",children:[(0,t.jsx)(a.AlertTriangle,{className:"w-10 h-10 text-warning"}),(0,t.jsx)("p",{className:"text-sm font-semibold text-foreground",children:"Something went wrong loading templates"}),e&&(0,t.jsx)("p",{className:"text-xs text-muted-foreground max-w-xs",children:e}),(0,t.jsx)(r.Button,{variant:"outline",onClick:()=>this.setState({hasError:!1,message:""}),children:"Reload section"})]})}return this.props.children}}e.s(["ShortTemplatesErrorBoundary",0,l])}]);
8
9//# debugId=c33a0c90-3d01-c1f6-65b1-d3a6bf037319

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.