1import{a as n,j as e}from"./react.D23SOY48.js";import{n as Qe,c as Je,ax as be,j as et,q as tt,bo as st,r as at}from"./useQuery.8IHTIQJ9.js";import{A as fe}from"./AgencyFrame.oVFK3agE.js";import{B as F,s as it}from"./useNewMessageCallback.m_HWlnvU.js";import{C as ce}from"./useDirectConfig.DUGHaAyz.js";import{P as ot}from"./PageHeader.BUbjr1b1.js";import{u as Ae,d$ as Oe,i as de,dP as Ne,cH as Re,L as Ce,r as ve,e5 as nt,e6 as Fe}from"./AnchorLinkCbArticle.D7lSWlmV.js";import{b as Z,aS as _e,i as Me,I as r,ba as Be,s as rt,o as lt,O as ct}from"./LogoutPage.q4jX-R9B.js";import{showSavedToast as me,showDangerToast as J,showToastProgress as pe}from"./toasters.DTJ-JB_V.js";import{l as dt,m as pt,n as ht}from"./useGetVideoExpState.CRcw66SC.js";import{i as ut,j as Se,a as mt,k as gt,T as xt}from"./useUploadFile.BolI-Eab.js";import{g as ft}from"./main.DYJSYA6X.js";import{D as vt}from"./DialogConfirmation.Dvq4W9JZ.js";import{C as le}from"./useDashboardLeftNavWidth.xFjaja1k.js";import{F as Q}from"./FormGroup.D2AZYLS9.js";import{T as jt}from"./TextArea.DwmMHUN7.js";import{T as ze}from"./Tooltip.B4eQWZfe.js";import{l as Ue,P as je,k as bt,n as St,c as $e,b as yt,y as At,g as It}from"./domainReducers.DFwZ465J.js";import{c as y,a as Et}from"./emotion.DVT5q8IN.js";import{a as He}from"./splitPathsBySizeLoader.De2WWJPJ.js";import{D as qe}from"./dialog.Byy3mEJJ.js";import{H as ye}from"./htmlSelect.BUDFFdjl.js";import{F as wt}from"./FileInput.Dfnnwtoh.js";import{I as Dt}from"./ImageUploader.C9EDbnKi.js";import{I as Pt}from"./InputTextAreaExpand.DLCPanTU.js";import{T as Tt}from"./textArea.B20Agvxn.js";import{b as kt}from"./assetsApi.7foBVIgc.js";import{u as Le}from"./LiveDemoPage.C49VfKVL.js";import{S as Nt}from"./Switch.DgEfbGW9.js";import{a as Rt}from"./react-deps.BYJtbOYg.js";import{T as Ct,a as he}from"./tabs.dRr5NSfj.js";import"./messagesReducers.vu3QILHi.js";import"./analyticsUtil.DveZKJXV.js";import"./overlayToaster.Ot9ut2fL.js";import"./index.DWpueHCC.js";import"./overlay2.KBrsItLg.js";import"./text.BiVczX0T.js";import"./messageFlowApi.BQv3ZrKY.js";import"./buttons.Bv4saRqe.js";import"./resizeSensor.102ckI7_.js";import"./callout.cP8LNVAv.js";import"./html.BtDJszHT.js";import"./formGroup.3Ne6uUdW.js";import"./tooltip.ix_KdXro.js";import"./popoverPlacementUtils.ClvuiSYt.js";import"./popoverNextMigrationUtils.Bjr6nFI6.js";import"./small-cross.CCCKD1lS.js";function Ye(t,s,d){return Qe({path:`/api/v1/users/${t}/accounts/${s}/ai/open-request`,method:"POST"}).send(d)}const Ft=y` 2 &.${Z("button")} { 3 min-width: 30px; 4 min-height: 30px; 5 padding: 0; 6 } 7`,$t=y` 8 padding: 20px; 9`,Lt=y` 10 display: flex; 11 justify-content: flex-end; 12 gap: 10px; 13 padding: 0 20px 20px; 14`,Gt=n.forwardRef(({prompt:t,systemPrompt:s,languageCode:d,onAiComplete:i,onAiError:m,aiButtonTooltip:v,isPromptEditable:g=!1,className:S,onChange:A,value:I,disabled:l,...o},E)=>{var x,h,C;const{userId:L,accountId:Y,domain:P}=Ae(),[T,W]=n.useState(!1),G=d||((C=(h=(x=P==null?void 0:P.chipbot)==null?void 0:x.languages)==null?void 0:h[0])==null?void 0:C.code)||"en-us",[u,w]=n.useState(!1),[k,M]=n.useState(t==null?void 0:t.trim()),[N,B]=n.useState(I||""),R=I!==void 0?I:N,V=f=>{B(f.target.value),A&&A(f)},ee=async f=>{var q,_;if(!f)return;W(!0);const H=s?`${s.trim()} 15 16${f}`:f;try{const X=(_=(q=(await Ye(L,Y,{prompt:H,languageCode:G})).body)==null?void 0:q.data)==null?void 0:_.response;if(typeof X!="string")throw new Error("Invalid AI response: expected a string");B(X),A&&A({target:{value:X}}),i&&i(X),w(!1)}catch(te){m&&m(te)}finally{W(!1)}},z=()=>{if(g){M(t),w(!0);return}ee(t)},U=()=>{w(!1)},O=()=>{ee(k)},p=e.jsx(ze,{content:v||Me("Generate with AI"),position:"bottom-right",children:e.jsx(F,{className:Ft,onClick:z,loading:T,intent:"primary",disabled:T||!t||l,minimal:!0,small:!0,children:e.jsx("i",{className:_e})})});return e.jsxs(e.Fragment,{children:[e.jsx(He,{inputRef:E||void 0,className:S,type:"text",onChange:V,value:R,disabled:l,rightElement:p,...o}),g&&e.jsxs(qe,{className:Ue,isOpen:u,onClose:U,title:"Edit AI Prompt",children:[e.jsx("div",{className:$t,children:e.jsx(jt,{value:k,onChange:f=>M(f.target.value),rows:10})}),e.jsxs("div",{className:Lt,children:[e.jsx(F,{onClick:U,disabled:T,children:"Cancel"}),e.jsx(F,{intent:"primary",onClick:O,loading:T,disabled:T||!k,children:"Generate"})]})]})]})});function Vt(t,s,d,i){const m=s.length>0?`Existing preset titles for reference: 17${s.map(g=>`- ${g}`).join(` 18`)} 19 20`:"",v=i?`The category for this preset is "${i}". `:"";return`${m}${v}This is a script for an AI avatar video preset. Based on the script, generate a short intent-driven title that describes the purpose of the video (e.g. "Homepage Greeting", "Service Inquiry", "Customer Support", "Product Questions", "Call to Action"). Do not include the industry or category name in the title. The title must be written in ${d}. Do not use generic words like "untitled" or "test". Only respond with the title, nothing else. 21 22Script: 23${t}`}function Ot({title:t,languageCode:s,languageOptions:d,isSaving:i,script:m,existingTitles:v,folderName:g,onTitleChange:S,onLanguageCodeChange:A,onSubmit:I}){var o;const l=!!(m!=null&&m.trim());return e.jsx(ce,{children:e.jsxs("form",{onSubmit:I,children:[e.jsxs(Q,{label:e.jsx(r,{children:"Preset Title"}),labelFor:"preset-title",children:[l&&e.jsx(Gt,{value:t,onChange:E=>S(E.target.value),disabled:i,prompt:Vt(m||"",v||[],((o=d.find(E=>E.value===s))==null?void 0:o.label)||s,g),languageCode:s,aiButtonTooltip:"Suggest title from script"}),!l&&e.jsx(He,{id:"preset-title",value:t,onChange:E=>S(E.target.value),disabled:i})]}),e.jsx(Q,{label:e.jsx(r,{children:"Language"}),labelFor:"preset-language",children:e.jsx(ye,{id:"preset-language",value:s,onChange:E=>A(E.target.value),options:d,disabled:i})}),e.jsx(F,{type:"submit",intent:"primary",disabled:!t.trim()||i,children:e.jsx(r,{children:"Save Changes"})})]})})}function _t({uploadedFile:t,isSaving:s,onFileChange:d,onClearFile:i,onUpload:m}){return e.jsxs(ce,{children:[e.jsx("p",{children:e.jsx(r,{children:"Upload a new video to replace the current one."})}),!t&&e.jsx(Q,{label:e.jsx(r,{children:"Video File (.mp4, .mov)"}),helperText:e.jsx(r,{children:"Max file size: 500MB"}),children:e.jsx(wt,{accept:"video/*",onChange:d,label:"Click or drop files to upload",disabled:s})}),t&&e.jsxs(e.Fragment,{children:[e.jsx(Q,{label:e.jsx(r,{children:"Selected Video"}),children:e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:12},children:[e.jsx("i",{className:Be,style:{fontSize:24}}),e.jsxs("div",{style:{flex:1},children:[e.jsx("strong",{children:t.name}),e.jsx("div",{style:{fontSize:12,color:"#5c7080"},children:Oe(t.size)})]}),e.jsx(F,{minimal:!0,icon:e.jsx("i",{className:rt}),onClick:i,disabled:s})]})}),e.jsx(F,{intent:"primary",onClick:m,disabled:s,children:e.jsx(r,{children:"Upload New Video"})})]})]})}const Mt=y` 24 position: relative; 25 display: flex; 26 align-items: flex-start; 27`,Bt=y` 28 flex: 1; 29`,zt=y` 30 position: absolute; 31 right: 5px; 32 top: 5px; 33`,Ut=y` 34 &.${Z("button")} { 35 min-width: 30px; 36 min-height: 30px; 37 padding: 0; 38 39 &:not(.${Z("disabled")}) { 40 background: ${$e(je,.1)}; 41 color: ${je}; 42 43 &:hover { 44 background: ${$e(je,.2)}; 45 } 46 } 47 48 &.${Z("disabled")} { 49 background: ${bt}; 50 color: ${St}; 51 } 52 } 53`,Ht=y` 54 resize: none; 55 56 &.${Z("input")} { 57 padding-right: 45px; 58 } 59`,qt=y` 60 padding: 20px; 61`,Yt=y` 62 display: flex; 63 justify-content: flex-end; 64 gap: 10px; 65 padding: 0 20px 20px; 66`,We=n.forwardRef(({prompt:t,systemPrompt:s,languageCode:d,onAiComplete:i,onAiError:m,aiButtonTooltip:v,isPromptEditable:g=!1,className:S,onChange:A,value:I,...l},o)=>{var O,p,x;const{userId:E,accountId:L,domain:Y}=Ae(),[P,T]=n.useState(!1),W=d||((x=(p=(O=Y==null?void 0:Y.chipbot)==null?void 0:O.languages)==null?void 0:p[0])==null?void 0:x.code)||"en-us",[G,u]=n.useState(!1),[w,k]=n.useState(t==null?void 0:t.trim()),[M,N]=n.useState(I||""),B=I!==void 0?I:M,R=h=>{N(h.target.value),A&&A(h)},V=async h=>{var f,H;
66if(!h)return;T(!0);const C=s?`${s.trim()} 67 68${h}`:h;try{const _=(H=(f=(await Ye(E,L,{prompt:C,languageCode:W})).body)==null?void 0:f.data)==null?void 0:H.response;if(typeof _!="string")throw new Error("Invalid AI response: expected a string");N(_),A&&A({target:{value:_}}),i&&i(_),u(!1)}catch(q){m&&m(q)}finally{T(!1)}},ee=()=>{if(g){k(t==null?void 0:t.trim()),u(!0);return}V(t)},z=()=>{u(!1)},U=()=>{V(w)};return e.jsxs("div",{className:Mt,children:[e.jsx("div",{className:Bt,children:e.jsx(Pt,{ref:o,className:Et(`${Z("input")} ${Z("fill")}`,Ht,S),onChange:R,value:B,...l})}),e.jsx("div",{className:zt,children:e.jsx(ze,{content:v||Me("Generate with AI"),position:"bottom-right",children:e.jsx(F,{className:Ut,onClick:ee,loading:P,disabled:P||!t,minimal:!0,children:e.jsx("i",{className:_e})})})}),g&&e.jsxs(qe,{className:Ue,isOpen:G,onClose:z,title:"Edit AI Prompt",children:[e.jsx("div",{className:qt,children:e.jsx(Tt,{className:`${Z("input")} ${Z("fill")}`,value:w,onChange:h=>k(h.target.value),rows:10})}),e.jsxs("div",{className:Yt,children:[e.jsx(F,{onClick:z,disabled:P,children:"Cancel"}),e.jsx(F,{intent:"primary",onClick:U,loading:P,disabled:P||!w,children:"Generate"})]})]})]})});function Wt({referenceImageSrc:t,onReferenceImageChange:s,onReferenceImageClear:d,scenarioDescription:i,onScenarioDescriptionChange:m,languageCode:v,disabled:g=!1}){return e.jsxs(e.Fragment,{children:[e.jsx(Q,{label:e.jsx(r,{children:"Reference Image (optional)"}),helperText:e.jsx(r,{children:"Upload an image to provide visual context for the AI when generating the video."}),children:e.jsx(Dt,{value:t,onChange:s,onClear:d,maxDisplayWidth:100,maxResizeWidth:720})}),e.jsx(Q,{label:e.jsx(r,{children:"Scenario Description"}),labelFor:"scenario-description",helperText:e.jsx(r,{children:"Describe the situation or context for the AI. This helps generate more relevant content and can be reused when forking videos."}),children:e.jsx(We,{id:"scenario-description",value:i,onChange:S=>m(S.target.value),placeholder:"Describe the scenario or context for this video...",disabled:g,isPromptEditable:!0,languageCode:v,systemPrompt:` 69You are a prompt-writing assistant for AI video generation. 70 71Your job: take the user's description of what they want and output ONE final Veo prompt string (the actual prompt that will be sent to an AI video generation model). 72 73Use the format template below as the base structure. Adapt the specific details (SERVICE ROLE, APPEARANCE, DIALOGUE, etc.) to match what the user describes, but keep the production constraints and exclusions intact. 74 75FORMAT TEMPLATE: 76 77SERVICE ROLE: 78- Marketing professional 79 80APPEARANCE (lock these details exactly): 81- Race / Ethnicity: White 82- Sex / Gender: Female 83- Age Range: 25â35 84- Overall vibe: approachable, competent, trustworthy 85- Attire: modern marketing-professional attire (clean, neutral, real-world, no logos) 86 87ENVIRONMENT (keep constant, do not add new items): 88- Bright, modern studio 89- Abundant natural light 90- Minimal decor 91- Clean, uncluttered background 92 93VIDEO FORMAT: 94- Portrait orientation 95- One person only 96- One continuous clip 97- No scene changes 98 99CAMERA (strictly one setup): 100- Single static camera 101- Medium shot framing (waist to head), not a close-up 102- The top of the head should sit no higher than the 30% mark from the top of the frame, leaving generous headroom above 103- The body should occupy roughly the lower 70% of the frame 104- 12 to 20 feet away from the subject 105- No zoom 106- No pans/tilts 107- No handheld shake 108- No cuts 109- No alternate angles 110- No lens changes 111 112LIGHTING: 113- Soft, realistic lighting 114- Consistent throughout (no lighting changes) 115 116PERFORMANCE: 117- She faces the camera and speaks directly to it 118- Friendly, confident, conversational 119- Natural facial expressions and relaxed body language 120- Accurate lip-sync and clear pacing 121- No exaggerated gestures 122- After finishing speaking, she holds a natural, warm smile and remains still â she does not attempt to continue talking or mouth additional words 123 124AUDIO: 125- Natural human voice 126- Neutral pitch, grounded 127- Not robotic 128- Not announcer-like 129- No background music 130- No sound effects 131 132STRICT EXCLUSIONS (do not include any of these): 133- No text overlays 134- No subtitles/captions 135- No lower thirds 136- No logos 137- No transitions 138- No b-roll 139- No cutaways 140- No ending screen 141- No fade in 142- No fade out 143- No graphics of any kind 144 145TIMING: 146- The clip begins with her already seated and looking at the camera 147- After the final spoken word, she closes her mouth, holds a gentle smile, and remains still for the rest of the clip 148- The clip does not end abruptly â allow a brief moment of her smiling silently after speaking 149 150Hard requirements: 151- SINGLE person, SINGLE continuous take, SINGLE static camera (no cuts, no angle changes, no zooms, no movement). 152- Explicitly forbid: overlays, subtitles/captions, lower thirds, logos, transitions, b-roll, cutaways, end cards, background music, sound effects, graphics. 153- State: the clip starts with the person already seated. After the last spoken word, she stops talking, smiles warmly, and holds still until the clip ends. 154- Keep it concise, production-realistic, and deterministic. 155- Do not add any additional actions, props, scene changes, or stylistic flourishes beyond what is required. 156 `,prompt:"A woman introduces herself as a marketing expert and giving a greeting for a website."})})]})}const Xt=y` 157 margin-bottom: 16px; 158`,Ge=[{value:"google/veo-3.0-fast-audio",label:"Google Veo 3.0 Fast"},{value:"google/veo-3.0-audio",label:"Google Veo 3.0"},{value:"openai/sora-2",label:"OpenAI Sora 2"}],Ve=(t,s)=>{var d,i;return((i=(d=t==null?void 0:t.response)==null?void 0:d.body)==null?void 0:i.message)||t.message||s};function Kt({userId:t,accountId:s,domainId:d,presetId:i,currentNode:m,currentPreset:v,parentNode:g,languageCode:S,languageOptions:A,onSuccess:I}){var X,ie;const l=m.videoExpPreset,o=g==null?void 0:g.videoExpPreset,E=!!(l!=null&&l.imageSrc||l!=null&&l.promptSrc),[L,Y]=n.useState(!E),[P,T]=n.useReducer(Le(),{imageSrc:(o==null?void 0:o.imageSrc)||"",imageAssetId:(o==null?void 0:o.imageAssetId)||"",scenarioDesc:"",promptAssetId:(o==null?void 0:o.promptAssetId)||"",originalScenarioDesc:""}),[W,G]=n.useReducer(Le(),{imageSrc:(l==null?void 0:l.imageSrc)||(o==null?void 0:o.imageSrc)||"",imageAssetId:(l==null?void 0:l.imageAssetId)||(o==null?void 0:o.imageAssetId)||"",scenarioDesc:"",promptAssetId:(l==null?void 0:l.promptAssetId)||(o==null?void 0:o.promptAssetId)||"",originalScenarioDesc:""}),u=L?P:W,w=L?T:G,[k,M]=n.useState(((ie=(X=v==null?void 0:v.videoExpTemplate)==null?void 0:X.ai)==null?void 0:ie.model)||Ge[0].value),[N,B]=n.useState(S),[R,V]=n.useState("");n.useEffect(()=>{B(S)},[S]);const[ee,z]=n.useState(!1),[U,O]=n.useState(!1),[p,x]=n.useState(!1),h=U||p,C=n.useRef(!1);n.useEffect(()=>{var ae,se;if(C.current)return;C.current=!0,V(((se=(ae=v.videoExpTemplate)==null?void 0:ae.ai)==null?void 0:se.text)||"");const c=[],D=(o==null?void 0:o.promptSrc)||"",$=(l==null?void 0:l.promptSrc)||"";D&&c.push(fetch(D).then(j=>j.text()).then(j=>
158{T({scenarioDesc:j,originalScenarioDesc:j}),$||G({scenarioDesc:j,originalScenarioDesc:j})})),$&&$!==D&&c.push(fetch($).then(j=>j.text()).then(j=>{G({scenarioDesc:j,originalScenarioDesc:j})})),c.length!==0&&(z(!0),Promise.all(c).then(()=>z(!1)).catch(j=>(z(!1),Je()(j))))},[v,l,o]);const f=c=>{w({imageSrc:c.url,imageAssetId:c.id})},H=async c=>{const $=c===(g==null?void 0:g.id)?(o==null?void 0:o.promptSrc)||"":(l==null?void 0:l.promptSrc)||"";if(!u.scenarioDesc)return{promptSrc:"",promptAssetId:""};if(!(u.scenarioDesc!==u.originalScenarioDesc)&&$)return{promptSrc:$,promptAssetId:u.promptAssetId};const se=new Blob([u.scenarioDesc],{type:"text/plain"}),j=new File([se],"scenario-description.txt",{type:"text/plain"}),oe=await kt({userId:t,accountId:s,domainId:d,file:j,onProgress:()=>{},type:"prompt"});return{promptSrc:oe.body.data.url,promptAssetId:oe.body.data.id}},q=async()=>{if(L&&g){const{promptSrc:c,promptAssetId:D}=await H(g.id);await be(t,s,d,{items:[{id:g.id,"videoExpPreset.imageSrc":u.imageSrc||"","videoExpPreset.imageAssetId":u.imageAssetId||"","videoExpPreset.promptSrc":c,"videoExpPreset.promptAssetId":D},{id:m.id,"videoExpPreset.imageSrc":"","videoExpPreset.imageAssetId":"","videoExpPreset.promptSrc":"","videoExpPreset.promptAssetId":"","videoExpPreset.languageCode":N}]}),T({originalScenarioDesc:u.scenarioDesc,promptAssetId:D})}else{const{promptSrc:c,promptAssetId:D}=await H(m.id);await be(t,s,d,{items:[{id:m.id,"videoExpPreset.imageSrc":u.imageSrc||"","videoExpPreset.imageAssetId":u.imageAssetId||"","videoExpPreset.promptSrc":c,"videoExpPreset.promptAssetId":D,"videoExpPreset.languageCode":N}]}),G({originalScenarioDesc:u.scenarioDesc,promptAssetId:D})}await Se(t,s,i,{"videoExpTemplate.ai.text":R,languageCode:N})},_=async()=>{O(!0);try{await q(),me(),I()}catch(c){J(Ve(c,"Failed to save"))}finally{O(!1)}},te=async()=>{x(!0);try{await q();const c=k==="openai/sora-2";await ut(t,s,i,{model:k,script:R,prompt:u.scenarioDesc,imageSrc:c?void 0:u.imageSrc||void 0}),me(),I()}catch(c){J(Ve(c,"Failed to generate AI video"))}finally{x(!1)}};return e.jsxs(ce,{children:[e.jsx("p",{children:e.jsx(r,{children:"Generate an AI avatar video for this preset. Configure the reference image and scenario description to provide context for the AI."})}),g&&e.jsx("div",{className:Xt,children:e.jsx(Nt,{checked:L,label:"Use Folder Settings",onChange:()=>Y(!L),disabled:h})}),e.jsx(Wt,{referenceImageSrc:u.imageSrc,onReferenceImageChange:f,onReferenceImageClear:()=>w({imageSrc:"",imageAssetId:""}),scenarioDescription:u.scenarioDesc,onScenarioDescriptionChange:c=>w({scenarioDesc:c}),languageCode:N,disabled:h},ee.toString()),e.jsx(Q,{label:e.jsx(r,{children:"AI Model"}),labelFor:"ai-model",children:e.jsx(ye,{id:"ai-model",value:k,onChange:c=>M(c.target.value),options:Ge,disabled:h})}),e.jsx(Q,{label:e.jsx(r,{children:"Language"}),labelFor:"ai-language",children:e.jsx(ye,{id:"ai-language",value:N,onChange:c=>B(c.target.value),options:A,disabled:h})}),e.jsx(Q,{label:e.jsx(r,{children:"Script"}),labelFor:"ai-script",helperText:e.jsx(r,{children:"Enter what you want the AI avatar to say in the video."}),children:e.jsx(We,{id:"ai-script",value:R,onChange:c=>V(c.target.value),placeholder:"Enter the script for the AI avatar...",rows:4,disabled:h,languageCode:N,isPromptEditable:!0,systemPrompt:` 159You are a helpful assistant that writes short, natural-sounding scripts for AI avatar videos. The script should be conversational, professional, and match the user's intended tone and purpose. Keep it concise and make it sound human and approachable. Always return just the script text without quotes or formatting. 160 161Write a script for the AI avatar based on the user's intention below. The script should: 162- Be only as long as it needs to be. The max video length is about 6-8 seconds, so need to ensure proper buffer time. 163- Sound natural and conversational 164- Match the tone and purpose described in the user's intention 165- Be suitable for embedding on a website 166 167${u.scenarioDesc?`Context about the scenario: 168${u.scenarioDesc}`:""} 169 `,prompt:` 170Describe what the video should be about (e.g. product walkthrough, homepage greeting, feature announcement, FAQ answer): 171 `})}),k==="openai/sora-2"&&u.imageSrc&&e.jsx(le,{intent:"warning",style:{marginBottom:12},children:e.jsx(r,{children:"Sora 2 has a high rejection rate with reference images. The image will be omitted when generating with this model."})}),e.jsxs("div",{style:{display:"flex",gap:8},children:[e.jsx(F,{intent:"success",onClick:te,disabled:h,loading:p,children:e.jsx(r,{children:"Generate AI Video"})}),e.jsx(F,{onClick:_,disabled:h,loading:U,intent:"primary",outlined:!0,icon:e.jsx("i",{className:lt}),children:e.jsx(r,{children:"Save"})})]})]})}function Zt({onDeleteClick:t}){return e.jsx(ce,{children:e.jsxs(le,{intent:"danger",children:[e.jsx("p",{children:e.jsx("strong",{children:e.jsx(r,{children:"Delete this preset"})})}),e.jsx("p",{children:e.jsx(r,{children:"This action cannot be undone. The preset and all associated data will be permanently deleted."})}),e.jsx("br",{}),e.jsx(F,{intent:"danger",onClick:t,children:e.jsx(r,{children:"Delete Preset"})})]})})}const Qt=y` 172 max-width: 600px; 173`,Jt=y` 174 display: flex; 175 align-items: center; 176 gap: 8px; 177 margin-bottom: 16px; 178 font-size: 14px; 179 color: ${yt}; 180 181 a { 182 color: ${At}; 183 text-decoration: none; 184 185 &:hover { 186 text-decoration: underline; 187 } 188 } 189`,ue=y` 190 width: 100%; 191 max-width: 300px; 192 border-radius: 8px; 193 background: ${It}; 194 margin-bottom: 20px; 195`,es=y` 196 display: flex; 197 gap: 20px; 198 align-items: flex-start; 199 flex-wrap: wrap; 200`,ts=y` 201 flex: 1; 202 min-width: 200px; 203`;function Ks(){var ae,se,j,oe,Ie,Ee,we,De;const t=Rt(),s=t.presetId,{userId:d,accountId:i}=Ae(),m=`dom_alias_${i}`,{languages:v}=ct(),g=((ae=v.find(a=>a.language==="English"))==null?void 0:ae.code)||((se=v[0])==null?void 0:se.code)||"",S=v.map(a=>({value:a.code,label:a.language})),[A,I]=n.useState(!0),[l,o]=n.useState(!1),[E,L]=n.useState([]),[Y,P]=n.useState([]),[T,W]=n.useState(!1),[G,u]=n.useState("ai"),[w,k]=n.useState(""),[M,N]=n.useState(g),B=n.useRef(!1),[R,V]=n.useState(null),[ee,z]=n.useState(0),U=a=>{const b=[];return a.forEach(K=>{b.push(K),K.children&&K.children.length>0&&b.push(...U(K.children))}),b},O=U(E),p=Y.find(a=>a.id===s),x=O.find(a=>a.refId===s&&a.type==="videoExpPreset"),h=x?O.find(a=>a.id===x.parentId):null,C=n.useCallback((a=!1)=>{a||I(!0),mt(i).then(b=>{L(b.body.data.nodes||[]),P(b.body.data.videoExpPresets||[])}).catch(()=>{a||J("Failed to load preset")}).finally(()=>{a||I(!1)})},[i]);n.useEffect(()=>{it("Edit Video Preset"),C()},[C]),n.useEffect(()=>{B.current||(x&&k(x.title),p&&(N(p.languageCode),B.current=!0))},[x,p]);const f=(p==null?void 0:p.state)==="processing",H=(p==null?void 0:p.state)==="failed";n.useEffect(()=>{if(!f||!s)return()=>{};const a=setInterval(()=>{gt(d,i,s).then(b=>{P(K=>K.map(ne=>ne.id===s?b.body.data:ne))})},5e3);return()=>clearInterval(a)},[f,i,s]);const q=h?de(Ne,{...t,folderId:h.id}):de(Re,t),_=async a=>{if(a.preventDefault(),!(!x||!w.trim())){o(!0);try{await be(d,i,m,{items:[{id:x.id,title:w.trim()}]}),await Se(d,i,s||"",{languageCode:M}),me(),C()}catch{J("Failed to save changes")}
203finally{o(!1)}}},te=a=>{const b=a==null?void 0:a[0];if(b){if(!nt(b.type||"")){J(`Invalid video type: ${b.type}. Only .mp4 and .mov are supported.`);return}if(b.size>=Fe){J(`File too large. Max size is ${Oe(Fe)}.`);return}V(b)}},X=async()=>{var b,K,ne,Pe;if(!R||!s)return;o(!0);const a=pe(0,!0);try{const ge=(await dt(d,i,`dom_alias_${i}`)).body.data.token,Xe=await pt(R).catch(()=>{}),Ke=await ht({checksumMd5:Xe,size:R.size,data:{accountId:i,videoExpPresetId:s},topic:"white-label-preset",jobs:["video-exp-core","video-exp-extras"]},ge),xe=new FormData;xe.append("file",R),xe.append("filename","video.mp4");const Te=(K=(b=(await et({path:tt.stringifyUrl({url:`${ft()}/api/v2/utility/video-upload`,query:{token:Ke.body.data.token}}),method:"POST"}).send(xe).on("progress",Ze=>{const ke=Ze.percent||0;z(ke),pe(ke,!0,a)})).body.data)==null?void 0:b[0])==null?void 0:K.src;if(!Te)throw new Error("Failed to get uploaded video URL");await Se(d,i,s,{src:Te}),pe(100,!1,a),V(null),C()}catch(re){pe(100,!1,a);const ge=((Pe=(ne=re==null?void 0:re.response)==null?void 0:ne.body)==null?void 0:Pe.message)||re.message||"Failed to upload video";J(ge)}finally{o(!1)}},ie=async()=>{if(x)try{await st(d,i,m,{items:[{id:x.id}]}),me(),at(q)}catch{J("Failed to delete preset")}},c=de(Re,t);if(A)return e.jsx(fe,{children:e.jsx(Ce,{children:e.jsx(r,{children:"Loading preset..."})})});if(!p||!x)return e.jsxs(fe,{children:[e.jsx(le,{intent:"warning",children:e.jsx(r,{children:"Preset not found"})}),e.jsx("br",{}),e.jsx(ve,{path:c,children:e.jsx(F,{children:e.jsx(r,{children:"Back to Presets"})})})]});const D=(j=p.videoExpTemplate)==null?void 0:j.videoSrc,$=(oe=p.videoExpTemplate)==null?void 0:oe.videoPosterSrc;return e.jsxs(fe,{children:[e.jsx(ot,{headline:x.title,subheadline:"Edit preset details, replace video, or generate AI avatar."}),e.jsxs("div",{className:Jt,children:[e.jsx(ve,{path:c,children:e.jsx(r,{children:"Video Presets"})}),h&&e.jsxs(e.Fragment,{children:[e.jsx("span",{children:"/"}),e.jsx(ve,{path:de(Ne,{...t,folderId:h.id}),children:h.title})]}),e.jsx("span",{children:"/"}),e.jsx("span",{children:x.title})]}),e.jsxs("div",{className:Qt,children:[f&&e.jsx(le,{intent:"warning",style:{marginBottom:20},children:e.jsx(r,{children:"This preset is currently processing. The video will be available shortly."})}),H&&e.jsx(le,{intent:"danger",style:{marginBottom:20},children:e.jsx(r,{children:"This preset failed to process. Please try generating the video again or upload a new video."})}),e.jsx(ce,{children:e.jsxs("div",{className:es,children:[f&&e.jsx("div",{className:ue,style:{height:180,display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(Ce,{})}),!f&&D&&e.jsx("video",{className:ue,src:D,poster:$,controls:!0,muted:!1}),!f&&!D&&$&&e.jsx("img",{className:ue,src:$,alt:x.title}),!f&&!D&&!$&&e.jsx("div",{className:ue,style:{height:180,display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx("i",{className:Be,style:{fontSize:48,color:"#5c7080"}})}),e.jsxs("div",{className:ts,children:[e.jsxs("p",{children:[e.jsx("strong",{children:e.jsx(r,{children:"Status:"})})," ",e.jsx(xt,{status:(p==null?void 0:p.state)||"not started"})]}),e.jsxs("p",{children:[e.jsx("strong",{children:e.jsx(r,{children:"Language:"})})," ",((Ie=S.find(a=>a.value===p.languageCode))==null?void 0:Ie.label)||p.languageCode]}),((Ee=p.videoExpTemplate)==null?void 0:Ee.videoDurationSeconds)&&e.jsxs("p",{children:[e.jsx("strong",{children:e.jsx(r,{children:"Duration:"})})," ",`${Math.round(p.videoExpTemplate.videoDurationSeconds)}s`]})]})]})}),e.jsx("br",{}),e.jsxs(Ct,{selectedTabId:G,onChange:a=>u(a),children:[e.jsx(he,{id:"details",title:e.jsx(r,{children:"Details"}),panel:e.jsx(Ot,{title:w,languageCode:M,languageOptions:S,isSaving:l,script:(De=(we=p.videoExpTemplate)==null?void 0:we.ai)==null?void 0:De.text,folderName:h==null?void 0:h.title,existingTitles:O.filter(a=>a.type==="videoExpPreset").map(a=>a.title),onTitleChange:k,onLanguageCodeChange:N,onSubmit:_})}),e.jsx(he,{id:"ai",title:e.jsx(r,{children:"AI Avatar"}),panel:e.jsx(Kt,{userId:d,accountId:i,domainId:m,presetId:s||"",currentNode:x,currentPreset:p,parentNode:h,languageCode:M,languageOptions:S,onSuccess:C},G)}),e.jsx(he,{id:"video",title:e.jsx(r,{children:"Replace Video"}),disabled:f&&!H,panel:e.jsx(_t,{uploadedFile:R,isSaving:l,onFileChange:te,onClearFile:()=>V(null),onUpload:X})}),e.jsx(he,{id:"danger",title:e.jsx(r,{children:"Danger Zone"}),panel:e.jsx(Zt,{onDeleteClick:()=>W(!0)})})]})]}),e.jsxs(vt,{deleteDialog:T,onClose:()=>W(!1),onDelete:ie,children:[e.jsx("p",{children:e.jsx(r,{children:"Are you sure you want to delete this preset? This action cannot be undone."})}),e.jsx("p",{children:e.jsx("strong",{children:x.title})})]})]})}export{Ks as default};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.